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

Function isExportDefaultSpecifier

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

tokenIsIdentifierFunction · 0.90
matchMethod · 0.80
hasPluginMethod · 0.80

Tested by

no test coverage detected