* Extract JS/TS import mappings
(content: string)
| 796 | * Extract JS/TS import mappings |
| 797 | */ |
| 798 | function extractJSImports(content: string): ImportMapping[] { |
| 799 | const mappings: ImportMapping[] = []; |
| 800 | |
| 801 | // ES6 imports |
| 802 | const importRegex = /import\s+(?:(\w+)\s*,?\s*)?(?:\{([^}]+)\})?\s*(?:(\*)\s+as\s+(\w+))?\s*from\s*['"]([^'"]+)['"]/g; |
| 803 | |
| 804 | let match; |
| 805 | while ((match = importRegex.exec(content)) !== null) { |
| 806 | const [, defaultImport, namedImports, star, namespaceAlias, source] = match; |
| 807 | |
| 808 | // Default import |
| 809 | if (defaultImport) { |
| 810 | mappings.push({ |
| 811 | localName: defaultImport, |
| 812 | exportedName: 'default', |
| 813 | source: source!, |
| 814 | isDefault: true, |
| 815 | isNamespace: false, |
| 816 | }); |
| 817 | } |
| 818 | |
| 819 | // Named imports |
| 820 | if (namedImports) { |
| 821 | const names = namedImports.split(',').map((s) => s.trim()); |
| 822 | for (const name of names) { |
| 823 | const aliasMatch = name.match(/(\w+)\s+as\s+(\w+)/); |
| 824 | if (aliasMatch) { |
| 825 | mappings.push({ |
| 826 | localName: aliasMatch[2]!, |
| 827 | exportedName: aliasMatch[1]!, |
| 828 | source: source!, |
| 829 | isDefault: false, |
| 830 | isNamespace: false, |
| 831 | }); |
| 832 | } else if (name) { |
| 833 | mappings.push({ |
| 834 | localName: name, |
| 835 | exportedName: name, |
| 836 | source: source!, |
| 837 | isDefault: false, |
| 838 | isNamespace: false, |
| 839 | }); |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | // Namespace import |
| 845 | if (star && namespaceAlias) { |
| 846 | mappings.push({ |
| 847 | localName: namespaceAlias, |
| 848 | exportedName: '*', |
| 849 | source: source!, |
| 850 | isDefault: false, |
| 851 | isNamespace: true, |
| 852 | }); |
| 853 | } |
| 854 | } |
| 855 |
no test coverage detected