(source: string)
| 129 | } |
| 130 | |
| 131 | function importUses(source: string): Array<SpecifierUse> { |
| 132 | const parseSource = stripComments(source) |
| 133 | const uses: Array<SpecifierUse> = [] |
| 134 | const importPattern = |
| 135 | /import\s+(?:type\s+)?([\s\S]*?)\s+from\s+['"]([^'"]+)['"]/g |
| 136 | const sideEffectPattern = /import\s+['"]([^'"]+)['"]/g |
| 137 | const dynamicPattern = /import\(\s*['"]([^'"]+)['"]\s*\)/g |
| 138 | |
| 139 | for (const match of parseSource.matchAll(importPattern)) { |
| 140 | const clause = match[1]?.trim() ?? '' |
| 141 | const specifier = match[2] |
| 142 | if (!specifier) continue |
| 143 | |
| 144 | const named = clause.match(/\{([\s\S]*?)\}/) |
| 145 | mergeUse(uses, specifier, named ? parseNames(named[1] ?? '') : undefined) |
| 146 | } |
| 147 | |
| 148 | for (const match of parseSource.matchAll(sideEffectPattern)) { |
| 149 | if (match[1]) mergeUse(uses, match[1], undefined) |
| 150 | } |
| 151 | |
| 152 | for (const match of parseSource.matchAll(dynamicPattern)) { |
| 153 | if (match[1]) mergeUse(uses, match[1], undefined) |
| 154 | } |
| 155 | |
| 156 | return uses |
| 157 | } |
| 158 | |
| 159 | function exportUsesForNames( |
| 160 | source: string, |
no test coverage detected