breaking: throw on missing dynamic import when import() is seen in systemjs (#12700)
This commit is contained in:
parent
3d69dc9471
commit
f8fe8eaab1
@ -0,0 +1,3 @@
|
|||||||
|
import "a";
|
||||||
|
|
||||||
|
import("b");
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"validateLogs": true,
|
||||||
|
"plugins": [
|
||||||
|
"transform-modules-systemjs",
|
||||||
|
"external-helpers"
|
||||||
|
],
|
||||||
|
"BABEL_8_BREAKING": false
|
||||||
|
}
|
||||||
@ -4,7 +4,6 @@ System.register(["a"], function (_export, _context) {
|
|||||||
return {
|
return {
|
||||||
setters: [function (_a) {}],
|
setters: [function (_a) {}],
|
||||||
execute: function () {
|
execute: function () {
|
||||||
// TODO: This should throw in Babel 8
|
|
||||||
_context.import("b");
|
_context.import("b");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1,5 +1,3 @@
|
|||||||
// TODO: This should throw in Babel 8
|
|
||||||
|
|
||||||
import "a";
|
import "a";
|
||||||
|
|
||||||
import("b");
|
import("b");
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"validateLogs": true,
|
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"transform-modules-systemjs",
|
"transform-modules-systemjs",
|
||||||
"external-helpers"
|
"external-helpers"
|
||||||
]
|
],
|
||||||
|
"BABEL_8_BREAKING": true,
|
||||||
|
"throws": "ERROR: Dynamic import() transformation must be enabled using the\n @babel/plugin-proposal-dynamic-import plugin. Babel 8\n no longer transforms import() without using that plugin."
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,12 @@ WARNING: Dynamic import() transformation must be enabled using the
|
|||||||
no longer transform import() without using that plugin.
|
no longer transform import() without using that plugin.
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const MISSING_PLUGIN_ERROR = `\
|
||||||
|
ERROR: Dynamic import() transformation must be enabled using the
|
||||||
|
@babel/plugin-proposal-dynamic-import plugin. Babel 8
|
||||||
|
no longer transforms import() without using that plugin.
|
||||||
|
`;
|
||||||
|
|
||||||
//todo: use getExportSpecifierName in `helper-module-transforms` when this library is refactored to NodePath usage.
|
//todo: use getExportSpecifierName in `helper-module-transforms` when this library is refactored to NodePath usage.
|
||||||
|
|
||||||
export function getExportSpecifierName(
|
export function getExportSpecifierName(
|
||||||
@ -226,8 +232,12 @@ export default declare((api, options) => {
|
|||||||
CallExpression(path, state: PluginState) {
|
CallExpression(path, state: PluginState) {
|
||||||
if (t.isImport(path.node.callee)) {
|
if (t.isImport(path.node.callee)) {
|
||||||
if (!this.file.has("@babel/plugin-proposal-dynamic-import")) {
|
if (!this.file.has("@babel/plugin-proposal-dynamic-import")) {
|
||||||
|
if (process.env.BABEL_8_BREAKING) {
|
||||||
|
throw new Error(MISSING_PLUGIN_ERROR);
|
||||||
|
} else {
|
||||||
console.warn(MISSING_PLUGIN_WARNING);
|
console.warn(MISSING_PLUGIN_WARNING);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
path.replaceWith(
|
path.replaceWith(
|
||||||
t.callExpression(
|
t.callExpression(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user