Align regenerator-transform import with native ESM (#13086)

* Align `regenerator-transform` import with native ESM

* Add `regenerator` test to `@babel/standalone`
This commit is contained in:
Nicolò Ribaudo 2021-04-07 17:25:46 +02:00 committed by GitHub
parent 42e630e8a2
commit 6d89daf064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -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;
}

View File

@ -1 +1,2 @@
export { default } from "regenerator-transform";
import regeneratorTransform from "regenerator-transform";
export default regeneratorTransform.default;

View File

@ -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", () => {