Better error for export * as ns without the correct plugin (#13296)
This commit is contained in:
parent
cca97d1e78
commit
9e241fc180
@ -189,6 +189,20 @@ function getExportSpecifierName(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function assertExportSpecifier(
|
||||||
|
path: NodePath,
|
||||||
|
): asserts path is NodePath<t.ExportSpecifier> {
|
||||||
|
if (path.isExportSpecifier()) {
|
||||||
|
return;
|
||||||
|
} else if (path.isExportNamespaceSpecifier()) {
|
||||||
|
throw path.buildCodeFrameError(
|
||||||
|
"Export namespace should be first transformed by `@babel/plugin-proposal-export-namespace-from`.",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw path.buildCodeFrameError("Unexpected export specifier type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get metadata about the imports and exports present in this module.
|
* Get metadata about the imports and exports present in this module.
|
||||||
*/
|
*/
|
||||||
@ -307,9 +321,7 @@ function getModuleMetadata(
|
|||||||
if (!data.loc) data.loc = child.node.loc;
|
if (!data.loc) data.loc = child.node.loc;
|
||||||
|
|
||||||
child.get("specifiers").forEach(spec => {
|
child.get("specifiers").forEach(spec => {
|
||||||
if (!spec.isExportSpecifier()) {
|
assertExportSpecifier(spec);
|
||||||
throw spec.buildCodeFrameError("Unexpected export specifier type");
|
|
||||||
}
|
|
||||||
const importName = getExportSpecifierName(
|
const importName = getExportSpecifierName(
|
||||||
spec.get("local"),
|
spec.get("local"),
|
||||||
stringSpecifiers,
|
stringSpecifiers,
|
||||||
@ -415,8 +427,9 @@ function getLocalExportMetadata(
|
|||||||
child.node.source &&
|
child.node.source &&
|
||||||
child.get("source").isStringLiteral()
|
child.get("source").isStringLiteral()
|
||||||
) {
|
) {
|
||||||
child.node.specifiers.forEach(specifier => {
|
child.get("specifiers").forEach(spec => {
|
||||||
bindingKindLookup.set(specifier.local.name, "block");
|
assertExportSpecifier(spec);
|
||||||
|
bindingKindLookup.set(spec.get("local").node.name, "block");
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,2 @@
|
|||||||
|
export * as ns from "./foo";
|
||||||
|
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Export namespace should be first transformed by `@babel/plugin-proposal-export-namespace-from`."
|
||||||
|
}
|
||||||
5
packages/babel-plugin-transform-modules-commonjs/test/fixtures/noInterop-loose/options.json
vendored
Normal file
5
packages/babel-plugin-transform-modules-commonjs/test/fixtures/noInterop-loose/options.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
["transform-modules-commonjs", { "noInterop": true, "loose": true }]
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user