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