Skip to content

Commit

Permalink
Align regenerator-transform import with native ESM (#13086)
Browse files Browse the repository at this point in the history
* Align `regenerator-transform` import with native ESM

* Add `regenerator` test to `@babel/standalone`
  • Loading branch information
nicolo-ribaudo committed Apr 7, 2021
1 parent 42e630e commit 6d89daf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 3 additions & 4 deletions babel.config.js
Expand Up @@ -475,15 +475,14 @@ function pluginNodeImportInteropBabel({ template }) {
}

function pluginNodeImportInteropRollup({ types: t }) {
const depsUsing__esModuleAndDefaultExport = [
src => src.startsWith("babel-plugin-polyfill-"),
];
const depsUsing__esModuleAndDefaultExport = src =>
src.startsWith("babel-plugin-polyfill-") || src === "regenerator-transform";

return {
visitor: {
ImportDeclaration(path) {
const { value: source } = path.node.source;
if (depsUsing__esModuleAndDefaultExport.every(test => !test(source))) {
if (!depsUsing__esModuleAndDefaultExport(source)) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/babel-plugin-transform-regenerator/src/index.js
@@ -1 +1,2 @@
export { default } from "regenerator-transform";
import regeneratorTransform from "regenerator-transform";
export default regeneratorTransform.default;
10 changes: 10 additions & 0 deletions packages/babel-standalone/test/babel.js
Expand Up @@ -181,6 +181,16 @@ const require = createRequire(import.meta.url);
[].includes(2);"
`);
});

it("regenerator works", () => {
const output = Babel.transform("function* fn() {}", {
sourceType: "module",
targets: { ie: 11 },
presets: ["env"],
}).code;

expect(output).toMatch("regeneratorRuntime.mark(fn)");
});
});

describe("custom plugins and presets", () => {
Expand Down

0 comments on commit 6d89daf

Please sign in to comment.