(src: string)
| 71 | * - re-export / named export statements (`export { A, B };`, `export { x } from '…';`) |
| 72 | */ |
| 73 | export function stripModuleSyntax(src: string): string { |
| 74 | return src |
| 75 | // multi-line or single-line `import ... from '...';` (non-greedy up to the first ;) |
| 76 | .replace(/\bimport\b[\s\S]*?\bfrom\b\s*['"][^'"]+['"]\s*;?/g, '') |
| 77 | // bare side-effect import: `import 'x';` |
| 78 | .replace(/\bimport\s+['"][^'"]+['"]\s*;?/g, '') |
| 79 | // dynamic-ish default export of an expression: `export default <expr>;` |
| 80 | // (run BEFORE the keyword-strip so `export default function` is handled by the next rule) |
| 81 | .replace(/^\s*export\s+default\s+(?=(function|class)\b)/gm, '') |
| 82 | .replace(/^\s*export\s+default\s+/gm, 'window.__art_default = ') |
| 83 | // `export const/let/var/function/class` -> drop just the `export ` |
| 84 | .replace(/^\s*export\s+(?=(const|let|var|function|class|async)\b)/gm, '') |
| 85 | // standalone named export / re-export statements: `export { A, B };` or `export { A } from '…';` |
| 86 | .replace(/^\s*export\s*\{[^}]*\}\s*(from\s*['"][^'"]+['"])?\s*;?\s*$/gm, '') |
| 87 | // CommonJS: `const X = require('…');` / `var X = require('…')` — drop the whole line |
| 88 | .replace(/^\s*(?:const|let|var)\s+[^;\n]*=\s*require\s*\([^)]*\)\s*;?\s*$/gm, ''); |
| 89 | } |
| 90 | |
| 91 | /** Best-effort: find the root React component name to mount (defaults to "App"). */ |
| 92 | export function detectReactComponent(src: string): string { |
no outgoing calls
no test coverage detected