MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / stripModuleSyntax

Function stripModuleSyntax

src/artifacts/preview.ts:73–89  ·  view source on GitHub ↗
(src: string)

Source from the content-addressed store, hash-verified

71 * - re-export / named export statements (`export { A, B };`, `export { x } from '…';`)
72 */
73export 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"). */
92export function detectReactComponent(src: string): string {

Callers 2

reactHarnessFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected