MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extractImportMappings

Function extractImportMappings

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

Source from the content-addressed store, hash-verified

758 * Extract import mappings from a file
759 */
760export function extractImportMappings(
761 _filePath: string,
762 content: string,
763 language: Language
764): ImportMapping[] {
765 const mappings: ImportMapping[] = [];
766
767 if (language === 'typescript' || language === 'javascript' || language === 'tsx' || language === 'jsx' || language === 'arkts') {
768 mappings.push(...extractJSImports(content));
769 } else if (language === 'svelte' || language === 'vue' || language === 'astro') {
770 // Svelte/Vue single-file components import via plain ES6 inside their
771 // `<script>` block (Astro: the `---` frontmatter). Without this, a
772 // `.svelte`/`.vue`/`.astro` consumer produces
773 // zero import mappings, so `resolveViaImport` can't run and a barrel
774 // import (`import { Foo } from './lib'`) falls back to name-matching —
775 // which silently fails whenever the re-export alias differs from the
776 // component's real name, yielding a false 0 callers (#629). The ES6
777 // import regex only matches `import … from '…'`, so running it over the
778 // whole SFC (markup + styles included) is safe.
779 mappings.push(...extractJSImports(content));
780 } else if (language === 'python') {
781 mappings.push(...extractPythonImports(content));
782 } else if (language === 'go') {
783 mappings.push(...extractGoImports(content));
784 } else if (language === 'java' || language === 'kotlin') {
785 mappings.push(...extractJavaImports(content));
786 } else if (language === 'php') {
787 mappings.push(...extractPHPImports(content));
788 } else if (language === 'c' || language === 'cpp') {
789 mappings.push(...extractCppImports(content));
790 }
791
792 return mappings;
793}
794
795/**
796 * 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