( _filePath: string, content: string, language: Language )
| 758 | * Extract import mappings from a file |
| 759 | */ |
| 760 | export 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 |
no test coverage detected