Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align regenerator-transform import with native ESM #13086

Merged
merged 2 commits into from Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, is there anything else other than regenerator-transform that would need to be added? Would we need to update this if we added another similar dep?

Oh so via #13017, it's only esm/cjs packages that have been transformed with babel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the only problem is dependencies that have been transformed with Babel.

I managed to create a working build just with this change so I think it's the only one (also I tried looking for other export ... from of dependencies and this is the only one), but if we'll ever find a new one we can always add it to this list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok was just worried it would break without us knowing and whether one could verify!


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