Improve @babel/runtime esm stability (#12883)

This commit is contained in:
Nicolò Ribaudo
2021-02-24 20:04:03 +01:00
committed by GitHub
parent c9da9650eb
commit 6a471decc3
47 changed files with 2535 additions and 159 deletions

View File

@@ -248,6 +248,7 @@ function buildHelper(
[transformRuntime, { corejs, version: runtimeVersion }],
buildRuntimeRewritePlugin(runtimeName, helperName),
esm ? null : addDefaultCJSExport,
esm ? useRelativeImports : null,
].filter(Boolean),
overrides: [
{
@@ -318,3 +319,18 @@ function addDefaultCJSExport({ template }) {
},
};
}
function useRelativeImports() {
const RE = /^@babel\/runtime(?:-corejs[23])?\/helpers\/(?<name>.+)$/;
return {
visitor: {
ImportDeclaration(path) {
path.node.source.value = path.node.source.value.replace(
RE,
"../$<name>/_index.mjs"
);
},
},
};
}

View File

@@ -88,13 +88,6 @@ export default declare((api, options, dirname) => {
// TODO(Babel 8): Remove this check, it's always true
const DUAL_MODE_RUNTIME = "7.13.0";
const supportsCJSDefault = hasMinVersion(DUAL_MODE_RUNTIME, runtimeVersion);
if (supportsCJSDefault && useESModules && !absoluteRuntime) {
console.warn(
`[@babel/plugin-transform-runtime] The 'useESModules' option is not necessary when using` +
` a @babel/runtime version >= ${DUAL_MODE_RUNTIME} and not using the 'absoluteRuntime'` +
` option, because it automatically detects the necessary module format.`,
);
}
function has(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);

View File

@@ -1 +0,0 @@
[@babel/plugin-transform-runtime] The 'useESModules' option is not necessary when using a @babel/runtime version >= 7.13.0 and not using the 'absoluteRuntime' option, because it automatically detects the necessary module format.