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

Function parseImportSpecifiersAndAfter

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Tested by

no test coverage detected