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

Function applyImportPhase

packages/babel-parser/src/parser/statement.ts:2953–2986  ·  view source on GitHub ↗
(
    node: Undone<N.ImportDeclaration | N.ExportNamedDeclaration>,
    isExport: boolean,
    phase: string | null,
    loc?: number,
  )

Source from the content-addressed store, hash-verified

2951 }
2952
2953 applyImportPhase(
2954 node: Undone<N.ImportDeclaration | N.ExportNamedDeclaration>,
2955 isExport: boolean,
2956 phase: string | null,
2957 loc?: number,
2958 ): void {
2959 if (isExport) {
2960 if (!process.env.IS_PUBLISH) {
2961 if (phase === "source") {
2962 throw new Error(
2963 `Assertion failure: export declarations do not support the '${phase}' phase.`,
2964 );
2965 }
2966 }
2967 if (phase === "defer") {
2968 this.expectPlugin("deferredReexports", loc);
2969 (node as N.ExportNamedDeclaration).phase = "defer";
2970 }
2971 return;
2972 }
2973
2974 if (phase === "source") {
2975 this.expectPlugin("sourcePhaseImports", loc);
2976 (node as N.ImportDeclaration).phase = "source";
2977 } else if (phase === "defer") {
2978 this.expectPlugin("deferredImportEvaluation", loc);
2979 (node as N.ImportDeclaration).phase = "defer";
2980 } else if (
2981 this.hasPlugin("sourcePhaseImports") ||
2982 this.hasPlugin("deferredImportEvaluation")
2983 ) {
2984 (node as N.ImportDeclaration).phase = null;
2985 }
2986 }
2987
2988 /*
2989 * Parse `source` in `import source x from "x"`, disambiguating

Callers

nothing calls this directly

Calls 1

hasPluginMethod · 0.80

Tested by

no test coverage detected