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

Respect moduleName for @babel/runtime/regenerator imports #16329

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
2 changes: 1 addition & 1 deletion packages/babel-plugin-proposal-decorators/package.json
Expand Up @@ -32,7 +32,7 @@
"@babel/helper-plugin-test-runner": "workspace:^",
"@babel/traverse": "workspace:^",
"array.prototype.concat": "^1.0.2",
"babel-plugin-polyfill-es-shims": "^0.10.2",
"babel-plugin-polyfill-es-shims": "^0.10.4",
"object.getownpropertydescriptors": "^2.1.1"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-proposal-json-modules/package.json
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@babel/core": "workspace:^",
"@babel/helper-plugin-test-runner": "workspace:^",
"babel-plugin-polyfill-corejs3": "^0.8.7"
"babel-plugin-polyfill-corejs3": "^0.10.1"
},
"engines": {
"node": ">=6.9.0"
Expand Down
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@babel/core": "workspace:^",
"@babel/helper-plugin-test-runner": "workspace:^",
"babel-plugin-polyfill-corejs3": "^0.9.0",
"babel-plugin-polyfill-corejs3": "^0.10.1",
"core-js-pure": "^3.30.2"
},
"engines": {
Expand Down
11 changes: 7 additions & 4 deletions packages/babel-plugin-transform-regenerator/src/index.ts
Expand Up @@ -11,9 +11,9 @@ export default declare(({ types: t, assertVersion }) => {
inherits: regeneratorTransform.default,

visitor: {
// We visit MemberExpression so that we always transform
// regeneratorRuntime before babel-plugin-polyfill-regenerator.
MemberExpression(path) {
// We visit CallExpression so that we always transform
// regeneratorRuntime.*() before babel-plugin-polyfill-regenerator.
CallExpression(path) {
if (!process.env.BABEL_8_BREAKING) {
if (!this.availableHelper?.("regeneratorRuntime")) {
// When using an older @babel/helpers version, fallback
Expand All @@ -23,7 +23,10 @@ export default declare(({ types: t, assertVersion }) => {
}
}

const obj = path.get("object");
const callee = path.get("callee");
if (!callee.isMemberExpression()) return;

const obj = callee.get("object");
if (obj.isIdentifier({ name: "regeneratorRuntime" })) {
const helper = this.addHelper("regeneratorRuntime") as
| t.Identifier
Expand Down
8 changes: 4 additions & 4 deletions packages/babel-plugin-transform-runtime/package.json
Expand Up @@ -22,9 +22,9 @@
"dependencies": {
"@babel/helper-module-imports": "workspace:^",
"@babel/helper-plugin-utils": "workspace:^",
"babel-plugin-polyfill-corejs2": "condition:BABEL_8_BREAKING ? : ^0.4.8 (peer:@babel/core)",
"babel-plugin-polyfill-corejs3": "condition:BABEL_8_BREAKING ? : ^0.9.0 (peer:@babel/core)",
"babel-plugin-polyfill-regenerator": "condition:BABEL_8_BREAKING ? : ^0.5.5 (peer:@babel/core)",
"babel-plugin-polyfill-corejs2": "condition:BABEL_8_BREAKING ? : ^0.4.10 (peer:@babel/core)",
"babel-plugin-polyfill-corejs3": "condition:BABEL_8_BREAKING ? : ^0.10.1 (peer:@babel/core)",
"babel-plugin-polyfill-regenerator": "condition:BABEL_8_BREAKING ? : ^0.6.1 (peer:@babel/core)",
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.1"
},
"peerDependencies": {
Expand All @@ -37,7 +37,7 @@
"@babel/preset-env": "workspace:^",
"@babel/runtime": "workspace:^",
"@babel/runtime-corejs3": "workspace:^",
"babel-plugin-polyfill-corejs3": "^0.9.0",
"babel-plugin-polyfill-corejs3": "^0.10.1",
"make-dir": "condition:BABEL_8_BREAKING ? : ^2.1.0"
},
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-runtime",
Expand Down
Expand Up @@ -30,7 +30,7 @@ function createRegeneratorPlugin(options, useRuntimeRegenerator, corejsPlugin) {
}

module.exports = function createBasePolyfillsPlugin(
{ corejs, regenerator = true },
{ corejs, regenerator = true, moduleName },
runtimeVersion,
absoluteImports,
) {
Expand Down Expand Up @@ -70,7 +70,12 @@ module.exports = function createBasePolyfillsPlugin(
method: "usage-pure",
absoluteImports,
proposals,
[pluginsCompat]: { useBabelRuntime: true, runtimeVersion, ext: "" },
[pluginsCompat]: {
useBabelRuntime: true,
runtimeVersion,
ext: "",
moduleName,
},
};

return createRegeneratorPlugin(
Expand Down
@@ -0,0 +1 @@
regeneratorRuntime.mark(function () {});
@@ -0,0 +1,11 @@
{
"plugins": [
"transform-regenerator",
[
"transform-runtime",
{ "moduleName": "@babel/runtime", "regenerator": false }
],
["babel-plugin-polyfill-corejs3", { "method": "usage-global" }],
["babel-plugin-polyfill-regenerator", { "method": "usage-global" }]
]
}
@@ -0,0 +1,2 @@
import "regenerator-runtime/runtime.js";
regeneratorRuntime.mark(function () {});
@@ -0,0 +1 @@
regeneratorRuntime.mark(function () {});
@@ -0,0 +1,7 @@
{
"plugins": [
"transform-regenerator",
["transform-runtime", { "moduleName": "@babel/runtime" }],
["babel-plugin-polyfill-corejs3", { "method": "usage-global" }]
]
}
@@ -0,0 +1,2 @@
import _regeneratorRuntime from "@babel/runtime/regenerator";
_regeneratorRuntime.mark(function () {});
6 changes: 3 additions & 3 deletions packages/babel-preset-env/package.json
Expand Up @@ -91,9 +91,9 @@
"@babel/plugin-transform-unicode-regex": "workspace:^",
"@babel/plugin-transform-unicode-sets-regex": "workspace:^",
"@babel/preset-modules": "0.1.6-no-external-plugins",
"babel-plugin-polyfill-corejs2": "condition:BABEL_8_BREAKING ? : ^0.4.8 (peer:@babel/core) (esm:default)",
"babel-plugin-polyfill-corejs3": "^0.9.0",
"babel-plugin-polyfill-regenerator": "condition:BABEL_8_BREAKING ? : ^0.5.5 (peer:@babel/core) (esm:default)",
"babel-plugin-polyfill-corejs2": "condition:BABEL_8_BREAKING ? : ^0.4.10 (peer:@babel/core) (esm:default)",
"babel-plugin-polyfill-corejs3": "^0.10.1",
"babel-plugin-polyfill-regenerator": "condition:BABEL_8_BREAKING ? : ^0.6.1 (peer:@babel/core) (esm:default)",
"core-js-compat": "^3.31.0",
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.1"
},
Expand Down
@@ -1,4 +1,3 @@
import "core-js/modules/es.number.constructor.js";
import "core-js/modules/es.number.parse-float.js";
import "core-js/modules/es.number.parse-int.js";
Number.parseFloat("3.14");
Expand Down
@@ -1,5 +1,3 @@
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.object.to-string.js";
Expand Down
@@ -1,5 +1,3 @@
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.object.to-string.js";
Expand Down
@@ -1,5 +1,6 @@
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.array-buffer.slice.js";
import "core-js/modules/es.data-view.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.typed-array.int8-array.js";
import "core-js/modules/es.typed-array.copy-within.js";
Expand Down
@@ -1,5 +1,6 @@
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.array-buffer.slice.js";
import "core-js/modules/es.data-view.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.typed-array.int8-array.js";
import "core-js/modules/es.typed-array.copy-within.js";
Expand Down
@@ -1,4 +1,3 @@
import "core-js/modules/es.number.constructor.js";
import "core-js/modules/es.number.parse-float.js";
import "core-js/modules/es.number.parse-int.js";
Number.parseFloat("3.14");
Expand Down
@@ -1,5 +1,6 @@
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.array-buffer.slice.js";
import "core-js/modules/es.data-view.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.typed-array.int8-array.js";
import "core-js/modules/es.typed-array.copy-within.js";
Expand Down
@@ -1,5 +1,6 @@
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.array-buffer.slice.js";
import "core-js/modules/es.data-view.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.typed-array.int8-array.js";
import "core-js/modules/es.typed-array.copy-within.js";
Expand Down