Skip to content

Commit

Permalink
Extract parseExportSpecifier
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed Oct 26, 2021
1 parent d5c69eb commit d459c8b
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -2167,31 +2167,35 @@ export default class StatementParser extends ExpressionParser {
this.expect(tt.comma);
if (this.eat(tt.braceR)) break;
}

const node = this.startNode();
const isMaybeTypeOnly = this.isContextual(tt._type);
const isString = this.match(tt.string);
node.local = this.parseModuleExportName();
const canParseAsKeyword = this.parseTypeOnlyImportExportSpecifier(
node,
/* isImport */ false,
isString,
isInTypeExport,
isMaybeTypeOnly,
);
if (canParseAsKeyword && this.eatContextual(tt._as)) {
node.exported = this.parseModuleExportName();
} else if (isString) {
node.exported = cloneStringLiteral(node.local);
} else if (!node.exported) {
node.exported = cloneIdentifier(node.local);
}
nodes.push(this.finishNode(node, "ExportSpecifier"));
const node = this.parseExportSpecifier(isInTypeExport);
nodes.push(node);
}

return nodes;
}

parseExportSpecifier(isInTypeExport: boolean): N.ExportSpecifier {
const node = this.startNode();
const isMaybeTypeOnly = this.isContextual(tt._type);
const isString = this.match(tt.string);
node.local = this.parseModuleExportName();
const canParseAsKeyword = this.parseTypeOnlyImportExportSpecifier(
node,
/* isImport */ false,
isString,
isInTypeExport,
isMaybeTypeOnly,
);
if (canParseAsKeyword && this.eatContextual(tt._as)) {
node.exported = this.parseModuleExportName();
} else if (isString) {
node.exported = cloneStringLiteral(node.local);
} else if (!node.exported) {
node.exported = cloneIdentifier(node.local);
}
return this.finishNode<N.ExportSpecifier>(node, "ExportSpecifier");
}

// https://tc39.es/ecma262/#prod-ModuleExportName
parseModuleExportName(): N.StringLiteral | N.Identifier {
if (this.match(tt.string)) {
Expand Down

0 comments on commit d459c8b

Please sign in to comment.