MCPcopy Index your code
hub / github.com/microsoft/typescript-go / parseImportOrExportSpecifier

Method parseImportOrExportSpecifier

internal/parser/parser.go:2413–2483  ·  view source on GitHub ↗
(kind ast.Kind)

Source from the content-addressed store, hash-verified

2411}
2412
2413func (p *Parser) parseImportOrExportSpecifier(kind ast.Kind) (isTypeOnly bool, propertyName *ast.Node, name *ast.Node) {
2414 // ImportSpecifier:
2415 // BindingIdentifier
2416 // ModuleExportName as BindingIdentifier
2417 // ExportSpecifier:
2418 // ModuleExportName
2419 // ModuleExportName as ModuleExportName
2420 // let checkIdentifierIsKeyword = isKeyword(token()) && !isIdentifier();
2421 // let checkIdentifierStart = scanner.getTokenStart();
2422 // let checkIdentifierEnd = scanner.getTokenEnd();
2423 canParseAsKeyword := true
2424 disallowKeywords := kind == ast.KindImportSpecifier
2425 var nameOk bool
2426 name, nameOk = p.parseModuleExportName(disallowKeywords)
2427 if name.Kind == ast.KindIdentifier && name.Text() == "type" {
2428 // If the first token of an import specifier is 'type', there are a lot of possibilities,
2429 // especially if we see 'as' afterwards:
2430 //
2431 // import { type } from "mod"; - isTypeOnly: false, name: type
2432 // import { type as } from "mod"; - isTypeOnly: true, name: as
2433 // import { type as as } from "mod"; - isTypeOnly: false, name: as, propertyName: type
2434 // import { type as as as } from "mod"; - isTypeOnly: true, name: as, propertyName: as
2435 if p.token == ast.KindAsKeyword {
2436 // { type as ...? }
2437 firstAs := p.parseIdentifierName()
2438 if p.token == ast.KindAsKeyword {
2439 // { type as as ...? }
2440 secondAs := p.parseIdentifierName()
2441 if p.canParseModuleExportName() {
2442 // { type as as something }
2443 // { type as as "something" }
2444 isTypeOnly = true
2445 propertyName = firstAs
2446 name, nameOk = p.parseModuleExportName(disallowKeywords)
2447 canParseAsKeyword = false
2448 } else {
2449 // { type as as }
2450 propertyName = name
2451 name = secondAs
2452 canParseAsKeyword = false
2453 }
2454 } else if p.canParseModuleExportName() {
2455 // { type as something }
2456 // { type as "something" }
2457 propertyName = name
2458 canParseAsKeyword = false
2459 name, nameOk = p.parseModuleExportName(disallowKeywords)
2460 } else {
2461 // { type as }
2462 isTypeOnly = true
2463 name = firstAs
2464 }
2465 } else if p.canParseModuleExportName() {
2466 // { type something ...? }
2467 // { type "something" ...? }
2468 isTypeOnly = true
2469 name, nameOk = p.parseModuleExportName(disallowKeywords)
2470 }

Callers 2

parseImportSpecifierMethod · 0.95
parseExportSpecifierMethod · 0.95

Calls 7

parseModuleExportNameMethod · 0.95
parseIdentifierNameMethod · 0.95
parseExpectedMethod · 0.95
parseErrorAtRangeMethod · 0.95
skipRangeTriviaMethod · 0.95
TextMethod · 0.65

Tested by

no test coverage detected