( node: SyntaxNode, fileDir: string, knownFiles: Set<string>, internal: Record<string, string>, external: Record<string, string>, )
| 447 | } |
| 448 | |
| 449 | function parseTsImport( |
| 450 | node: SyntaxNode, |
| 451 | fileDir: string, |
| 452 | knownFiles: Set<string>, |
| 453 | internal: Record<string, string>, |
| 454 | external: Record<string, string>, |
| 455 | ): void { |
| 456 | const sourceNode = node.childForFieldName('source'); |
| 457 | if (!sourceNode) return; |
| 458 | |
| 459 | const sourceText = sourceNode.text.replace(/^["']|["']$/g, ''); |
| 460 | |
| 461 | // Non-relative import → external package |
| 462 | if (!sourceText.startsWith('.')) { |
| 463 | const pkgName = npmPackageName(sourceText); |
| 464 | external[pkgName] = packageId('npm', pkgName); |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | const resolved = resolveRelativePath(fileDir, sourceText); |
| 469 | const extensions = [ |
| 470 | '', |
| 471 | '.ts', |
| 472 | '.tsx', |
| 473 | '.js', |
| 474 | '.jsx', |
| 475 | '/index.ts', |
| 476 | '/index.tsx', |
| 477 | '/index.js', |
| 478 | ]; |
| 479 | for (const ext of extensions) { |
| 480 | const candidate = resolved + ext; |
| 481 | if (knownFiles.has(candidate)) { |
| 482 | // Map each local binding name (not the file basename) to the file, so |
| 483 | // call resolution can match the identifier actually used in code. |
| 484 | for (const binding of tsImportBindings(node)) { |
| 485 | internal[binding] = candidate; |
| 486 | } |
| 487 | break; |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | function parseTsReexport( |
| 493 | node: SyntaxNode, |
no test coverage detected