MCPcopy Create free account
hub / github.com/babel/babel / isExportDefaultSpecifier

Function isExportDefaultSpecifier

packages/babel-parser/src/parser/statement.ts:2608–2662  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2606 }
2607
2608 isExportDefaultSpecifier(): boolean {
2609 const { type } = this.state;
2610 if (tokenIsIdentifier(type)) {
2611 if ((type === tt._async && !this.state.containsEsc) || type === tt._let) {
2612 return false;
2613 }
2614 if (
2615 (type === tt._type || type === tt._interface || type === tt._struct) &&
2616 !this.state.containsEsc
2617 ) {
2618 // If we see any variable name other than `from` after `type` keyword,
2619 // we consider it as flow/typescript type exports
2620 // note that this approach may fail on some pedantic cases
2621 // export type from = number
2622 const next = this.nextTokenStart();
2623 const nextChar = this.input.charCodeAt(next);
2624 if (
2625 nextChar === charCodes.leftCurlyBrace ||
2626 (this.chStartsBindingIdentifier(nextChar, next) &&
2627 !this.isUnparsedContextual(next, "from"))
2628 ) {
2629 if (type !== tt._struct) {
2630 this.expectOnePlugin(["flow", "typescript"]);
2631 }
2632 return false;
2633 }
2634 }
2635 } else if (!this.match(tt._default)) {
2636 return false;
2637 }
2638
2639 const next = this.nextTokenStart();
2640 const hasFrom = this.isUnparsedContextual(next, "from");
2641 if (
2642 this.input.charCodeAt(next) === charCodes.comma ||
2643 (tokenIsIdentifier(this.state.type) && hasFrom)
2644 ) {
2645 return true;
2646 }
2647 // lookahead again when `export default from` is seen
2648 if (this.match(tt._default) && hasFrom) {
2649 // Without the plugin, `export default from\n"x"` is valid: ASI applies
2650 // after the `from` identifier reference, so don't look past line breaks.
2651 const nextAfterFrom = this.input.charCodeAt(
2652 this.hasPlugin("exportDefaultFrom")
2653 ? this.nextTokenStartSince(next + 4)
2654 : this.nextTokenInLineStartSince(next + 4),
2655 );
2656 return (
2657 nextAfterFrom === charCodes.quotationMark ||
2658 nextAfterFrom === charCodes.apostrophe
2659 );
2660 }
2661 return false;
2662 }
2663
2664 parseExportFrom(
2665 this: Parser,

Callers

nothing calls this directly

Calls 4

tokenIsIdentifierFunction · 0.90
matchMethod · 0.80
hasPluginMethod · 0.80

Tested by

no test coverage detected