(content: string, language: Language)
| 1172 | * fall through silently; resolution simply skips the broken file. |
| 1173 | */ |
| 1174 | export function extractReExports(content: string, language: Language): ReExport[] { |
| 1175 | if ( |
| 1176 | language !== 'typescript' && |
| 1177 | language !== 'javascript' && |
| 1178 | language !== 'tsx' && |
| 1179 | language !== 'jsx' && |
| 1180 | language !== 'arkts' |
| 1181 | ) { |
| 1182 | return []; |
| 1183 | } |
| 1184 | const out: ReExport[] = []; |
| 1185 | |
| 1186 | // Pre-strip block comments + line comments so a commented-out |
| 1187 | // `// export { x } from '...'` doesn't produce a phantom edge. |
| 1188 | // (Template literals are still a possible source of false positives; |
| 1189 | // a project that builds export statements as runtime strings is |
| 1190 | // out of scope.) |
| 1191 | const cleaned = stripJsComments(content); |
| 1192 | |
| 1193 | // Wildcard: `export * from '...'` or `export * as ns from '...'` |
| 1194 | const wildcardRe = /export\s*\*(?:\s+as\s+\w+)?\s*from\s*['"]([^'"]+)['"]/g; |
| 1195 | let m: RegExpExecArray | null; |
| 1196 | while ((m = wildcardRe.exec(cleaned)) !== null) { |
| 1197 | out.push({ kind: 'wildcard', source: m[1]! }); |
| 1198 | } |
| 1199 | |
| 1200 | // Named: `export { a, b as c } from '...'` |
| 1201 | const namedRe = /export\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/g; |
| 1202 | while ((m = namedRe.exec(cleaned)) !== null) { |
| 1203 | const inner = m[1]!; |
| 1204 | const source = m[2]!; |
| 1205 | for (const raw of inner.split(',')) { |
| 1206 | const item = raw.trim(); |
| 1207 | if (!item) continue; |
| 1208 | const aliasMatch = item.match(/^(\w+)\s+as\s+(\w+)$/); |
| 1209 | if (aliasMatch) { |
| 1210 | out.push({ |
| 1211 | kind: 'named', |
| 1212 | exportedName: aliasMatch[2]!, |
| 1213 | originalName: aliasMatch[1]!, |
| 1214 | source, |
| 1215 | }); |
| 1216 | } else if (/^\w+$/.test(item)) { |
| 1217 | out.push({ |
| 1218 | kind: 'named', |
| 1219 | exportedName: item, |
| 1220 | originalName: item, |
| 1221 | source, |
| 1222 | }); |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | return out; |
| 1228 | } |
| 1229 | |
| 1230 | /** |
| 1231 | * Resolve a reference using import mappings |
no test coverage detected