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

Function parseMaybeImportPhase

packages/babel-parser/src/parser/statement.ts:2999–3050  ·  view source on GitHub ↗
(
    node: Undone<N.ImportDeclaration | N.TSImportEqualsDeclaration>,
    isExport: boolean,
  )

Source from the content-addressed store, hash-verified

2997 * in the TS and Flow plugins, and for parsing `import defer`.
2998 */
2999 parseMaybeImportPhase(
3000 node: Undone<N.ImportDeclaration | N.TSImportEqualsDeclaration>,
3001 isExport: boolean,
3002 ): N.Identifier | null {
3003 if (!this.isPotentialImportPhase(isExport)) {
3004 this.applyImportPhase(
3005 node as Undone<N.ImportDeclaration>,
3006 isExport,
3007 null,
3008 );
3009 return null;
3010 }
3011
3012 const phaseIdentifier = this.startNode<N.Identifier>();
3013 const phaseIdentifierName = this.parseIdentifierName(true);
3014
3015 const { type } = this.state;
3016 const isImportPhase = tokenIsKeywordOrIdentifier(type)
3017 ? // OK: import <phase> x from "foo";
3018 // OK: import <phase> from from "foo";
3019 // NO: import <phase> from "foo";
3020 // NO: import <phase> from 'foo';
3021 // With the module declarations proposals, we will need further disambiguation
3022 // for `import module from from;`.
3023 type !== tt._from || this.lookaheadCharCode() === charCodes.lowercaseF
3024 : // OK: import <phase> { x } from "foo";
3025 // OK: import <phase> x from "foo";
3026 // OK: import <phase> * as T from "foo";
3027 // NO: import <phase> from "foo";
3028 // OK: import <phase> "foo";
3029 // The last one is invalid, we will continue parsing and throw
3030 // an error later
3031 type !== tt.comma;
3032
3033 if (isImportPhase) {
3034 this.applyImportPhase(
3035 node as Undone<N.ImportDeclaration>,
3036 isExport,
3037 phaseIdentifierName,
3038 phaseIdentifier.start!,
3039 );
3040 return null;
3041 } else {
3042 this.applyImportPhase(
3043 node as Undone<N.ImportDeclaration>,
3044 isExport,
3045 null,
3046 );
3047 // `<phase>` is a default binding, return it to the main import declaration parser
3048 return this.createIdentifier(phaseIdentifier, phaseIdentifierName);
3049 }
3050 }
3051
3052 isPrecedingIdImportPhase(
3053 // eslint-disable-next-line @typescript-eslint/no-unused-vars

Callers

nothing calls this directly

Calls 3

applyImportPhaseMethod · 0.45

Tested by

no test coverage detected