Skip to content

Commit

Permalink
Use a proper assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 24, 2023
1 parent 0cbe9fc commit db3a97a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/babel-parser/src/parser/statement.ts
Expand Up @@ -2944,7 +2944,13 @@ export default abstract class StatementParser extends ExpressionParser {
loc?: Position,
): void {
if (isExport) {
// This will never happen
if (!process.env.IS_PUBLISH) {
if (phase === "module") {
throw new Error(
"Assertion failure: export declarations do not support the 'module' phase.",
);
}
}
return;
}
if (phase === "module") {
Expand Down
5 changes: 1 addition & 4 deletions packages/babel-parser/src/plugins/placeholders.ts
Expand Up @@ -310,10 +310,7 @@ export default (superClass: typeof Parser) =>
>,
maybeDefaultIdentifier: N.Identifier | null,
): node is Undone<N.ExportNamedDeclaration> {
if (
(node as N.ExportNamedDeclaration).specifiers &&
(node as N.ExportNamedDeclaration).specifiers.length > 0
) {
if ((node as N.ExportNamedDeclaration).specifiers?.length) {
// "export %%NAME%%" has already been parsed by #parseExport.
return true;
}
Expand Down

0 comments on commit db3a97a

Please sign in to comment.