MCPcopy
hub / github.com/colbymchenry/codegraph / extractImportMappings

Function extractImportMappings

src/resolution/import-resolver.ts:577–610  ·  view source on GitHub ↗
(
  _filePath: string,
  content: string,
  language: Language
)

Source from the content-addressed store, hash-verified

575 * Extract import mappings from a file
576 */
577export function extractImportMappings(
578 _filePath: string,
579 content: string,
580 language: Language
581): ImportMapping[] {
582 const mappings: ImportMapping[] = [];
583
584 if (language === 'typescript' || language === 'javascript' || language === 'tsx' || language === 'jsx') {
585 mappings.push(...extractJSImports(content));
586 } else if (language === 'svelte' || language === 'vue' || language === 'astro') {
587 // Svelte/Vue single-file components import via plain ES6 inside their
588 // `<script>` block (Astro: the `---` frontmatter). Without this, a
589 // `.svelte`/`.vue`/`.astro` consumer produces
590 // zero import mappings, so `resolveViaImport` can't run and a barrel
591 // import (`import { Foo } from './lib'`) falls back to name-matching —
592 // which silently fails whenever the re-export alias differs from the
593 // component's real name, yielding a false 0 callers (#629). The ES6
594 // import regex only matches `import … from '…'`, so running it over the
595 // whole SFC (markup + styles included) is safe.
596 mappings.push(...extractJSImports(content));
597 } else if (language === 'python') {
598 mappings.push(...extractPythonImports(content));
599 } else if (language === 'go') {
600 mappings.push(...extractGoImports(content));
601 } else if (language === 'java' || language === 'kotlin') {
602 mappings.push(...extractJavaImports(content));
603 } else if (language === 'php') {
604 mappings.push(...extractPHPImports(content));
605 } else if (language === 'c' || language === 'cpp') {
606 mappings.push(...extractCppImports(content));
607 }
608
609 return mappings;
610}
611
612/**
613 * Extract JS/TS import mappings

Callers 2

createContextMethod · 0.90
resolution.test.tsFile · 0.90

Calls 6

extractJSImportsFunction · 0.85
extractPythonImportsFunction · 0.85
extractGoImportsFunction · 0.85
extractJavaImportsFunction · 0.85
extractPHPImportsFunction · 0.85
extractCppImportsFunction · 0.85

Tested by

no test coverage detected