Skip to content

Commit

Permalink
Better error for export * as ns without the correct plugin (#13296)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 11, 2021
1 parent cca97d1 commit 9e241fc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -307,9 +321,7 @@ function getModuleMetadata(
if (!data.loc) data.loc = child.node.loc;

child.get("specifiers").forEach(spec => {
if (!spec.isExportSpecifier()) {
throw spec.buildCodeFrameError("Unexpected export specifier type");
}
assertExportSpecifier(spec);
const importName = getExportSpecifierName(
spec.get("local"),
stringSpecifiers,
Expand Down Expand Up @@ -415,8 +427,9 @@ function getLocalExportMetadata(
child.node.source &&
child.get("source").isStringLiteral()
) {
child.node.specifiers.forEach(specifier => {
bindingKindLookup.set(specifier.local.name, "block");
child.get("specifiers").forEach(spec => {
assertExportSpecifier(spec);
bindingKindLookup.set(spec.get("local").node.name, "block");
});
return;
}
Expand Down
@@ -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`."
}
@@ -0,0 +1,5 @@
{
"plugins": [
["transform-modules-commonjs", { "noInterop": true, "loose": true }]
]
}

0 comments on commit 9e241fc

Please sign in to comment.