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

Function parseImportSpecifiersAndAfter

packages/babel-parser/src/parser/statement.ts:3090–3119  ·  view source on GitHub ↗
(
    this: Parser,
    node: Undone<N.ImportDeclaration>,
    maybeDefaultIdentifier: N.Identifier | null,
  )

Source from the content-addressed store, hash-verified

3088 }
3089
3090 parseImportSpecifiersAndAfter(
3091 this: Parser,
3092 node: Undone<N.ImportDeclaration>,
3093 maybeDefaultIdentifier: N.Identifier | null,
3094 ): N.ImportDeclaration {
3095 node.specifiers = [];
3096
3097 // check if we have a default import like
3098 // import React from "react";
3099 const hasDefault = this.maybeParseDefaultImportSpecifier(
3100 node,
3101 maybeDefaultIdentifier,
3102 );
3103 /* we are checking if we do not have a default import, then it is obvious that we need named imports
3104 * import { get } from "axios";
3105 * but if we do have a default import
3106 * we need to check if we have a comma after that and
3107 * that is where this `|| this.eat` condition comes into play
3108 */
3109 const parseNext = !hasDefault || this.eat(tt.comma);
3110 // if we do have to parse the next set of specifiers, we first check for star imports
3111 // import React, * from "react";
3112 const hasStar = parseNext && this.maybeParseStarImportSpecifier(node);
3113 // now we check if we need to parse the next imports
3114 // but only if they are not importing * (everything)
3115 if (parseNext && !hasStar) this.parseNamedOrFilteredImportSpecifiers(node);
3116 this.expectContextual(tt._from);
3117
3118 return this.parseImportSourceAndAttributes(node);
3119 }
3120
3121 parseImportSourceAndAttributes(
3122 this: Parser,

Callers

nothing calls this directly

Tested by

no test coverage detected