Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82a936c

Browse files
Add back moduleName option to plugin-transform-runtime (#16241)
1 parent e44d8d7 commit 82a936c

16 files changed

Lines changed: 64 additions & 10 deletions

File tree

packages/babel-plugin-transform-runtime/src/index.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Options {
1414
corejs?: string | number | { version: string | number; proposals?: boolean };
1515
helpers?: boolean;
1616
version?: string;
17+
moduleName?: null | string;
1718
}
1819

1920
export default declare((api, options: Options, dirname) => {
@@ -27,6 +28,7 @@ export default declare((api, options: Options, dirname) => {
2728
helpers: useRuntimeHelpers = true,
2829
version: runtimeVersion = "7.0.0-beta.0",
2930
absoluteRuntime = false,
31+
moduleName = null,
3032
} = options;
3133

3234
if (typeof useRuntimeHelpers !== "boolean") {
@@ -46,6 +48,10 @@ export default declare((api, options: Options, dirname) => {
4648
throw new Error(`The 'version' option must be a version string.`);
4749
}
4850

51+
if (moduleName !== null && typeof moduleName !== "string") {
52+
throw new Error("The 'moduleName' option must be null or a string.");
53+
}
54+
4955
if (!process.env.BABEL_8_BREAKING) {
5056
// In recent @babel/runtime versions, we can use require("helper").default
5157
// instead of require("helper") so that it has the same interface as the
@@ -85,15 +91,6 @@ export default declare((api, options: Options, dirname) => {
8591
}
8692
}
8793

88-
if (Object.hasOwn(options, "moduleName")) {
89-
throw new Error(
90-
"The 'moduleName' option has been removed. @babel/transform-runtime " +
91-
"no longer supports arbitrary runtimes. If you were using this to " +
92-
"set an absolute path for Babel's standard runtimes, please use the " +
93-
"'absoluteRuntime' option.",
94-
);
95-
}
96-
9794
if (process.env.BABEL_8_BREAKING) {
9895
if (Object.hasOwn(options, "regenerator")) {
9996
throw new Error(
@@ -157,7 +154,9 @@ export default declare((api, options: Options, dirname) => {
157154

158155
file.set("helperGenerator", (name: string) => {
159156
modulePath ??= getRuntimePath(
160-
file.get("runtimeHelpersModuleName") ?? "@babel/runtime",
157+
moduleName ??
158+
file.get("runtimeHelpersModuleName") ??
159+
"@babel/runtime",
161160
dirname,
162161
absoluteRuntime,
163162
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class A {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sourceType": "module",
3+
"plugins": [
4+
"transform-classes",
5+
["transform-runtime", { "moduleName": "lol" }]
6+
]
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import _createClass from "lol/helpers/createClass";
2+
import _classCallCheck from "lol/helpers/classCallCheck";
3+
let A = /*#__PURE__*/_createClass(function A() {
4+
_classCallCheck(this, A);
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class A {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"sourceType": "module",
3+
"plugins": [
4+
"transform-classes",
5+
["transform-runtime", { "moduleName": null }],
6+
["babel-plugin-polyfill-corejs3", { "method": "usage-pure" }]
7+
]
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import _createClass from "@babel/runtime-corejs3/helpers/createClass";
2+
import _classCallCheck from "@babel/runtime-corejs3/helpers/classCallCheck";
3+
let A = /*#__PURE__*/_createClass(function A() {
4+
_classCallCheck(this, A);
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class A {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"sourceType": "module",
3+
"plugins": [
4+
"transform-classes",
5+
["transform-runtime", { "moduleName": "lol" }],
6+
["babel-plugin-polyfill-corejs3", { "method": "usage-pure" }]
7+
]
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import _createClass from "lol/helpers/createClass";
2+
import _classCallCheck from "lol/helpers/classCallCheck";
3+
let A = /*#__PURE__*/_createClass(function A() {
4+
_classCallCheck(this, A);
5+
});

0 commit comments

Comments
 (0)