Put back ESM helpers in a folder where we can use .js (#12919)
This commit is contained in:
@@ -3,7 +3,7 @@ typeof objectWithoutProperties: function
|
||||
typeof objectWithoutProperties.default: function
|
||||
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
|
||||
================= require - esm =====================
|
||||
Error: Unexpected token export
|
||||
Error: Unexpected identifier
|
||||
=============== require - corejs ====================
|
||||
typeof Set: function
|
||||
arr: 1,2,3
|
||||
|
||||
9
test/runtime-integration/expected-cjs-13.0.txt
Normal file
9
test/runtime-integration/expected-cjs-13.0.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
================= require - auto ====================
|
||||
typeof objectWithoutProperties: function
|
||||
typeof objectWithoutProperties.default: function
|
||||
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
|
||||
================= require - esm =====================
|
||||
Error: Cannot use import statement outside a module
|
||||
=============== require - corejs ====================
|
||||
typeof Set: function
|
||||
arr: 1,2,3
|
||||
9
test/runtime-integration/expected-cjs-13.2.txt
Normal file
9
test/runtime-integration/expected-cjs-13.2.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
================= require - auto ====================
|
||||
typeof objectWithoutProperties: function
|
||||
typeof objectWithoutProperties.default: function
|
||||
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
|
||||
================= require - esm =====================
|
||||
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js
|
||||
=============== require - corejs ====================
|
||||
typeof Set: function
|
||||
arr: 1,2,3
|
||||
@@ -3,7 +3,7 @@ typeof objectWithoutProperties: function
|
||||
typeof objectWithoutProperties.default: function
|
||||
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
|
||||
================= require - esm =====================
|
||||
Error: Unexpected token export
|
||||
Error: Unexpected identifier
|
||||
=============== require - corejs ====================
|
||||
typeof Set: function
|
||||
arr: 1,2,3
|
||||
|
||||
@@ -3,7 +3,7 @@ typeof objectWithoutProperties: function
|
||||
typeof objectWithoutProperties.default: function
|
||||
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
|
||||
================= require - esm =====================
|
||||
Error: Unexpected token 'export'
|
||||
Error: Cannot use import statement outside a module
|
||||
=============== require - corejs ====================
|
||||
typeof Set: function
|
||||
arr: 1,2,3
|
||||
|
||||
@@ -3,7 +3,11 @@ typeof objectWithoutProperties: function
|
||||
typeof objectWithoutProperties.default: function
|
||||
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
|
||||
================= require - esm =====================
|
||||
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/toPrimitive/_index.mjs
|
||||
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js
|
||||
require() of ES modules is not supported.
|
||||
require() of <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js from <ROOT>/test/runtime-integration/src/require-esm.cjs is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
|
||||
Instead rename toPrimitive.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from <ROOT>/packages/babel-runtime/helpers/esm/package.json.
|
||||
|
||||
=============== require - corejs ====================
|
||||
typeof Set: function
|
||||
arr: 1,2,3
|
||||
|
||||
18
test/runtime-integration/expected-esm-13.2.txt
Normal file
18
test/runtime-integration/expected-esm-13.2.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
================== import - auto ====================
|
||||
typeof inheritsLoose: function
|
||||
A.__proto__ === B true
|
||||
================= import - esm ======================
|
||||
typeof toArray: function
|
||||
arr: 1,2,3
|
||||
=============== import - corejs ====================
|
||||
typeof Set: function
|
||||
arr: 1,2,3
|
||||
================= require - auto ====================
|
||||
typeof objectWithoutProperties: function
|
||||
typeof objectWithoutProperties.default: function
|
||||
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
|
||||
================= require - esm =====================
|
||||
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js
|
||||
=============== require - corejs ====================
|
||||
typeof Set: function
|
||||
arr: 1,2,3
|
||||
@@ -12,7 +12,11 @@ typeof objectWithoutProperties: function
|
||||
typeof objectWithoutProperties.default: function
|
||||
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
|
||||
================= require - esm =====================
|
||||
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/toPrimitive/_index.mjs
|
||||
Error: Must use import to load ES Module: <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js
|
||||
require() of ES modules is not supported.
|
||||
require() of <ROOT>/packages/babel-runtime/helpers/esm/toPrimitive.js from <ROOT>/test/runtime-integration/src/require-esm.cjs is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
|
||||
Instead rename toPrimitive.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from <ROOT>/packages/babel-runtime/helpers/esm/package.json.
|
||||
|
||||
=============== require - corejs ====================
|
||||
typeof Set: function
|
||||
arr: 1,2,3
|
||||
|
||||
@@ -4,8 +4,15 @@ const fs = require("fs");
|
||||
|
||||
const [major, minor] = process.versions.node.split(".").map(n => +n);
|
||||
|
||||
if (major > 12 || (major === 12 && minor >= 17)) {
|
||||
test("ESM", "--experimental-modules ./src/main-esm.mjs", "expected-esm.txt");
|
||||
if (
|
||||
major > 13 ||
|
||||
(major === 12 && minor >= 17) ||
|
||||
(major === 13 && minor >= 2)
|
||||
) {
|
||||
const expectedEsm =
|
||||
major === 13 && minor <= 3 ? "expected-esm-13.2.txt" : "expected-esm.txt";
|
||||
|
||||
test("ESM", "./src/main-esm.mjs", expectedEsm);
|
||||
// TODO: This never worked in any Babel version
|
||||
// test("ESM - absoluteRuntime", "--esperimental-modules ./src/absolute/main-esm.mjs", "expected-esm-absolute.txt");
|
||||
}
|
||||
@@ -13,6 +20,10 @@ if (major > 12 || (major === 12 && minor >= 17)) {
|
||||
const expectedCjs =
|
||||
major === 10 || (major === 12 && minor < 12.17)
|
||||
? "expected-cjs-10.txt"
|
||||
: major === 13 && minor <= 1
|
||||
? "expected-cjs-13.0.txt"
|
||||
: major === 13 && minor <= 3
|
||||
? "expected-cjs-13.2.txt"
|
||||
: "expected-cjs.txt";
|
||||
|
||||
test("CJS", "./src/main-cjs.cjs", expectedCjs);
|
||||
|
||||
Reference in New Issue
Block a user