MCPcopy
hub / github.com/opentrace/opentrace / parseTsImport

Function parseTsImport

ui/src/components/pipeline/parser/importAnalyzer.ts:449–490  ·  view source on GitHub ↗
(
  node: SyntaxNode,
  fileDir: string,
  knownFiles: Set<string>,
  internal: Record<string, string>,
  external: Record<string, string>,
)

Source from the content-addressed store, hash-verified

447}
448
449function 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
492function parseTsReexport(
493 node: SyntaxNode,

Callers 1

analyzeTypeScriptImportsFunction · 0.85

Calls 4

npmPackageNameFunction · 0.90
packageIdFunction · 0.90
resolveRelativePathFunction · 0.85
tsImportBindingsFunction · 0.85

Tested by

no test coverage detected