Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error for export * as ns without the correct plugin #13296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 }]
]
}