@vxrn/compiler 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { dirname, extname, join, relative, sep } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { resolvePath } from \"@vxrn/utils\";\nimport { cssToReactNativeRuntime } from \"react-native-css-interop/css-to-rn/index.js\";\nimport { configuration, isNativeWorkletsEnabled } from \"./configure\";\nimport { debug, runtimePublicPath, validParsers } from \"./constants\";\nimport {\n getBabelOptions,\n transformBabel,\n transformOxcReactCompiler\n} from \"./transformBabel\";\nimport { shouldSourceMap } from \"./transformSWC\";\nimport {\n prepareWorkletsForReactCompiler,\n shouldTransformWorklets,\n transformWorklets\n} from \"./transformWorklets\";\nimport { getCachedTransform, logCacheStats, setCachedTransform } from \"./cache\";\nexport * from \"./configure\";\nexport * from \"./transformBabel\";\nexport * from \"./transformFlow\";\nexport * from \"./transformSWC\";\nexport * from \"./transformWorklets\";\nexport * from \"./reactNativeCodegen\";\nexport * from \"./transformHermesLoops\";\nexport * from \"./transformHermesAsync\";\nexport * from \"./transformHermesClasses\";\nimport { clearTransformCache } from \"./cache\";\nimport { JS_GLOBALS } from \"./worklets/globals\";\nimport { getClosureVariables } from \"./worklets/scope\";\nconst perfStats = {\n babel: {\n totalCalls: 0,\n totalTransforms: 0,\n totalTime: 0,\n byEnvironment: {}\n },\n optimizeDeps: {\n byEnvironment: {}\n }\n};\nfunction logPerfSummary() {\n if (!process.env.DEBUG_COMPILER_PERF) {\n return;\n }\n console.info(\"\\n\\u{1F4CA} [Compiler Performance Summary]\");\n console.info(\n `Babel: ${perfStats.babel.totalTransforms} transforms / ${perfStats.babel.totalCalls} calls (${(perfStats.babel.totalTransforms / Math.max(perfStats.babel.totalCalls, 1) * 100).toFixed(1)}% transform rate)`\n );\n console.info(`Babel total time: ${perfStats.babel.totalTime}ms`);\n for (const [env, stats] of Object.entries(perfStats.babel.byEnvironment)) {\n if (stats.transforms > 0) {\n console.info(\n ` ${env}: ${stats.transforms} transforms, ${stats.time}ms (${(stats.time / stats.transforms).toFixed(1)}ms avg)`\n );\n }\n }\n for (const [env, stats] of Object.entries(perfStats.optimizeDeps.byEnvironment)) {\n const elapsed = Date.now() - stats.startTime;\n console.info(\n `optimizeDeps ${env}: checked ${stats.filesChecked} files, transformed ${stats.filesTransformed} (${elapsed}ms)`\n );\n }\n}\nconst compilerLog = {\n compiled: 0,\n cached: 0,\n time: 0,\n // typed loose because the dom lib types setTimeout as number, but node gives\n // us a Timeout we need to unref so the debounce never holds the process open\n timer: null\n};\nfunction logCompiled(cached, ms) {\n if (cached) {\n compilerLog.cached++;\n } else {\n compilerLog.compiled++;\n compilerLog.time += ms;\n }\n if (compilerLog.timer) clearTimeout(compilerLog.timer);\n compilerLog.timer = setTimeout(() => {\n const total = compilerLog.compiled + compilerLog.cached;\n const detail = compilerLog.compiled ? `${compilerLog.compiled} compiled in ${compilerLog.time}ms${compilerLog.cached ? `, ${compilerLog.cached} cached` : \"\"}` : `all cached`;\n console.info(` \\u{1FA84} [compiler] ${total} file${total === 1 ? \"\" : \"s\"} (${detail})`);\n compilerLog.compiled = 0;\n compilerLog.cached = 0;\n compilerLog.time = 0;\n compilerLog.timer = null;\n }, 500);\n compilerLog.timer.unref?.();\n}\nasync function performBabelTransform({\n id,\n code,\n projectRoot,\n environment,\n production,\n reactForRNVersion,\n optionsIn\n}) {\n perfStats.babel.totalCalls++;\n if (!perfStats.babel.byEnvironment[environment]) {\n perfStats.babel.byEnvironment[environment] = { calls: 0, transforms: 0, time: 0 };\n }\n perfStats.babel.byEnvironment[environment].calls++;\n const transformProps = {\n id,\n code,\n projectRoot,\n development: !production,\n environment,\n reactForRNVersion\n };\n const userTransform = optionsIn?.transform?.(transformProps);\n if (userTransform === false) {\n return null;\n }\n if (userTransform !== \"swc\" && userTransform !== \"oxc\") {\n let babelOptions = getBabelOptions({\n ...transformProps,\n userSetting: userTransform\n });\n if (!babelOptions && shouldTransformWorklets({ id, code })) {\n babelOptions = { plugins: [] };\n }\n if (babelOptions) {\n const hasCompilerPlugin = babelOptions.plugins?.some(\n (x) => Array.isArray(x) && x[0] === \"babel-plugin-react-compiler\"\n );\n const userBabelConfigPath = typeof babelOptions.configFile === \"string\" ? babelOptions.configFile : null;\n const cached = getCachedTransform(id, code, environment, userBabelConfigPath);\n if (cached) {\n perfStats.babel.byEnvironment[environment].transforms++;\n if (hasCompilerPlugin && (cached.code.includes(\"react/compiler-runtime\") || cached.code.includes(\"react-compiler-runtime\"))) {\n debug?.(` \\u{1FA84} [compiler] ${relative(process.cwd(), id)} (cached)`);\n logCompiled(true, 0);\n }\n debug?.(`[babel/cached] ${id}`);\n return cached;\n }\n const isWorkletPlugin = (entry) => {\n if (!entry) return false;\n const name = typeof entry === \"string\" ? entry : Array.isArray(entry) ? entry[0] : null;\n return typeof name === \"string\" && (name.includes(\"react-native-worklets\") || name.includes(\"react-native-reanimated\"));\n };\n const workletEntry = babelOptions.plugins?.find(isWorkletPlugin);\n const workletPluginOptions = Array.isArray(workletEntry) ? workletEntry[1] : void 0;\n const useWorklets = isNativeWorkletsEnabled() && (Boolean(workletEntry) || shouldTransformWorklets({ id, code }));\n let curCode = code;\n let workletPreparation = null;\n let compilerOut = null;\n const compilerPluginIndex = babelOptions.plugins?.findIndex(\n (x) => Array.isArray(x) && x[0] === \"babel-plugin-react-compiler\"\n ) ?? -1;\n if (compilerPluginIndex !== -1) {\n const compilerPluginConfig = babelOptions.plugins[compilerPluginIndex];\n const compilerPluginOptions = compilerPluginConfig[1] || {};\n const useBabelCompiler = compilerPluginOptions.compiler === \"babel\" || process.env.ONE_REACT_COMPILER === \"babel\" || process.env.VXRN_REACT_COMPILER === \"babel\";\n if (!useBabelCompiler) {\n if (useWorklets) {\n workletPreparation = prepareWorkletsForReactCompiler(\n id,\n curCode,\n shouldSourceMap()\n );\n if (workletPreparation) curCode = workletPreparation.code;\n }\n compilerOut = await transformOxcReactCompiler(\n id,\n curCode,\n compilerPluginOptions,\n shouldSourceMap()\n );\n if (compilerOut) curCode = compilerOut.code;\n babelOptions.plugins.splice(compilerPluginIndex, 1);\n }\n }\n let workletsOut = null;\n if (useWorklets) {\n workletsOut = await transformWorklets(id, curCode, shouldSourceMap(), {\n projectRoot,\n ...workletPluginOptions\n });\n babelOptions.plugins = babelOptions.plugins?.filter(\n (entry) => !isWorkletPlugin(entry)\n );\n curCode = workletsOut.code;\n }\n const startTime = Date.now();\n let babelOut = null;\n if (babelOptions.plugins?.length === 0 && !babelOptions.configFile && !babelOptions.babelrc) {\n let finalMap = void 0;\n if (shouldSourceMap()) {\n const intermediateMaps = [\n workletPreparation?.map,\n compilerOut?.map,\n workletsOut?.map\n ].filter(Boolean);\n if (intermediateMaps.length === 1) {\n finalMap = intermediateMaps[0];\n } else if (intermediateMaps.length > 1) {\n const remapping = (await import(\"@jridgewell/remapping\")).default;\n finalMap = remapping(intermediateMaps.slice().reverse(), () => null);\n }\n }\n babelOut = { code: curCode, map: finalMap };\n } else {\n const babelOptsWithMap = shouldSourceMap() && (workletsOut?.map || compilerOut?.map || workletPreparation?.map) ? { ...babelOptions, sourceMaps: true } : babelOptions;\n babelOut = await transformBabel(id, curCode, babelOptsWithMap);\n if (shouldSourceMap() && babelOut?.map) {\n const priorMaps = [\n workletPreparation?.map,\n compilerOut?.map,\n workletsOut?.map\n ].filter(Boolean);\n if (priorMaps.length > 0) {\n const remapping = (await import(\"@jridgewell/remapping\")).default;\n babelOut.map = remapping(\n [babelOut.map, ...priorMaps.slice().reverse()],\n () => null\n );\n }\n }\n }\n const babelTime = Date.now() - startTime;\n if (babelOut?.code) {\n perfStats.babel.totalTransforms++;\n perfStats.babel.totalTime += babelTime;\n perfStats.babel.byEnvironment[environment].transforms++;\n perfStats.babel.byEnvironment[environment].time += babelTime;\n if (hasCompilerPlugin && (babelOut.code.includes(\"react/compiler-runtime\") || babelOut.code.includes(\"react-compiler-runtime\"))) {\n debug?.(` \\u{1FA84} [compiler] ${relative(process.cwd(), id)} (${babelTime}ms)`);\n logCompiled(false, babelTime);\n }\n debug?.(`[babel] ${id}`);\n const outCode = `${babelOut.code}\n// vxrn-did-babel`;\n const result = { code: outCode, map: babelOut.map };\n setCachedTransform(id, code, result, environment, userBabelConfigPath);\n return result;\n }\n }\n }\n return null;\n}\nasync function createVXRNCompilerPlugin(optionsIn) {\n const reactVersion = await (async () => {\n const path = resolvePath(\"react/package.json\");\n const json = JSON.parse(await readFile(path, \"utf-8\"));\n return json.version;\n })();\n const envNames = {\n ios: true,\n android: true,\n client: true,\n ssr: true\n };\n function getEnvName(name) {\n if (name === \"worker\") return \"ssr\";\n if (!envNames[name]) throw new Error(`Invalid env: ${name}`);\n return name;\n }\n const reactForRNVersion = reactVersion.split(\".\")[0];\n const cssTransformCache = /* @__PURE__ */ new Map();\n const rolldownPath = resolvePath(\"rolldown\");\n const rolldownNodeMods = rolldownPath.slice(\n 0,\n rolldownPath.indexOf(sep + \"node_modules\")\n );\n let config;\n return [\n {\n name: \"one:compiler-resolve-refresh-runtime\",\n apply: \"serve\",\n enforce: \"pre\",\n // Run before Vite default resolve to avoid syscalls\n resolveId: (id) => id === runtimePublicPath || id === `${runtimePublicPath}.map` ? id : void 0,\n load: (id) => {\n const basePath = dirname(fileURLToPath(import.meta.url));\n if (id === runtimePublicPath) {\n return readFileSync(join(basePath, \"refresh-runtime.mjs\"), \"utf-8\").replace(\n /\\/\\/# sourceMappingURL=.*/,\n \"\"\n );\n }\n if (id === `${runtimePublicPath}.map`) {\n return JSON.stringify({ version: 3, sources: [], mappings: \"\" });\n }\n return void 0;\n }\n },\n {\n name: `one:compiler-css-to-js`,\n // only .css files can match, so let rust reject everything else\n transform: {\n filter: { id: /\\.css$/ },\n handler(codeIn, id) {\n const environment = getEnvName(this.environment.name);\n if (configuration.enableNativeCSS && (environment === \"ios\" || environment === \"android\")) {\n {\n const data = JSON.stringify(\n cssToReactNativeRuntime(codeIn, { inlineRem: 16 })\n );\n const code = `require(\"nativewind/dist/index.js\").require().StyleSheet.registerCompiled(${data})`;\n const newId = `${id}.js`;\n const cssId = newId.replace(rolldownNodeMods + sep, \"\");\n cssTransformCache.set(cssId, code);\n return {\n code,\n id: newId,\n map: null\n };\n }\n }\n }\n },\n generateBundle(_, bundle) {\n const environment = getEnvName(this.environment.name);\n if (configuration.enableNativeCSS && (environment === \"ios\" || environment === \"android\")) {\n const rootJSName = Object.keys(bundle).find((i) => {\n const chunk = bundle[i];\n return chunk.type == \"chunk\" && chunk.fileName.match(/.[cm]?js(?:\\?.+)?$/) != null;\n });\n if (!rootJSName) {\n throw new Error(`Can't find root js, internal one error`);\n }\n const rootJS = bundle[rootJSName];\n const cssAssets = Object.keys(bundle).filter(\n (i) => bundle[i].fileName.endsWith(\".css.js\")\n );\n for (const name of cssAssets) {\n delete bundle[name];\n const jsCSS = cssTransformCache.get(name);\n rootJS.code = `\n${jsCSS}\n${rootJS.code}\n`;\n }\n }\n }\n },\n {\n name: \"one:compiler\",\n enforce: \"pre\",\n config: () => {\n const nodeModulesFilter = /node_modules[/\\\\].*\\.(tsx?|jsx?|mjs|cjs)$/;\n const createEnvironmentConfig = (environment) => {\n if (!perfStats.optimizeDeps.byEnvironment[environment]) {\n perfStats.optimizeDeps.byEnvironment[environment] = {\n filesChecked: 0,\n filesTransformed: 0,\n startTime: Date.now()\n };\n }\n return {\n optimizeDeps: {\n rolldownOptions: {\n plugins: [\n {\n name: `transform-before-optimize-deps-${environment}`,\n async transform(code, id) {\n if (!nodeModulesFilter.test(id)) {\n return null;\n }\n perfStats.optimizeDeps.byEnvironment[environment].filesChecked++;\n const production = process.env.NODE_ENV === \"production\" || process.env.NODE_ENV === \"test\";\n debug?.(`[rolldown optimizeDeps] ${id}`);\n const result = await performBabelTransform({\n id,\n code,\n projectRoot: config.root,\n environment,\n production,\n reactForRNVersion,\n optionsIn\n });\n if (!result) {\n return null;\n }\n perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++;\n return {\n code: result.code,\n map: result.map\n };\n },\n buildEnd() {\n if (process.env.DEBUG_COMPILER_PERF) {\n const stats = perfStats.optimizeDeps.byEnvironment[environment];\n const elapsed = Date.now() - stats.startTime;\n console.info(\n `[optimizeDeps ${environment}] Done: ${stats.filesChecked} files checked, ${stats.filesTransformed} transformed (${elapsed}ms)`\n );\n }\n const allDone = Object.keys(perfStats.optimizeDeps.byEnvironment).length >= 2;\n if (allDone) {\n logCacheStats();\n logPerfSummary();\n }\n }\n }\n ]\n }\n },\n define: {\n \"process.env.NATIVEWIND_OS\": JSON.stringify(\n environment === \"ios\" || environment === \"android\" ? \"native\" : \"web\"\n )\n }\n };\n };\n return {\n environments: {\n ios: createEnvironmentConfig(\"ios\"),\n android: createEnvironmentConfig(\"android\"),\n client: createEnvironmentConfig(\"client\"),\n ssr: createEnvironmentConfig(\"ssr\")\n }\n };\n },\n configResolved(resolvedConfig) {\n config = resolvedConfig;\n },\n async transform(codeIn, _id) {\n let code = codeIn;\n const environment = getEnvName(this.environment.name);\n const isNative = environment === \"ios\" || environment === \"android\";\n const production = config.command === \"build\" || process.env.NODE_ENV === \"production\" || JSON.parse(\n this.environment.config?.define?.[\"process.env.NODE_ENV\"] || '\"\"'\n ) === \"production\";\n const isEntry = _id.includes(\"one-entry-native\");\n if (isEntry) {\n if (isNative && !production) {\n code = `import '@vxrn/vite-native-client'\n${code}`;\n }\n if (isNative && configuration.enableNativewind) {\n code = `import * as x from 'nativewind'\n${code}`;\n }\n return code;\n }\n const id = _id.split(\"?\")[0];\n const extension = extname(id);\n if (extension === \".css\" || !validParsers.has(extension)) {\n return;\n }\n if (id.includes(`virtual:`)) {\n return;\n }\n if (codeIn.endsWith(`// vxrn-did-babel`)) {\n debug?.(`[skip babel] ${id}`);\n return;\n }\n return performBabelTransform({\n id,\n code: codeIn,\n projectRoot: config.root,\n environment,\n production,\n reactForRNVersion,\n optionsIn\n });\n }\n },\n // wraps client-side TSX/JSX with React Refresh preamble + import.meta.hot.accept\n // runs after vite:oxc (no enforce:'pre') so it sees the already-transformed code\n {\n name: \"one:react-refresh-web\",\n apply: \"serve\",\n transform(code, _id) {\n if (this.environment.name !== \"client\") return;\n if (code.includes(runtimePublicPath)) return;\n if (/[?&](?:worker|sharedworker|raw|url)\\b/.test(_id)) return;\n const id = _id.split(\"?\")[0];\n if (id.includes(\"node_modules\")) return;\n if (id.includes(\"virtual:\")) return;\n if (id === runtimePublicPath) return;\n const ext = extname(id);\n if (ext !== \".tsx\" && ext !== \".jsx\") return;\n const hasRefreshCalls = /\\$RefreshReg\\$\\(/.test(code);\n let out = `import * as RefreshRuntime from \"${runtimePublicPath}\";\n\n`;\n if (hasRefreshCalls) {\n out += `if (!window.$RefreshReg$) throw new Error(\"React refresh preamble was not loaded. Something is wrong.\");\nconst prevRefreshReg = window.$RefreshReg$;\nconst prevRefreshSig = window.$RefreshSig$;\nwindow.$RefreshReg$ = RefreshRuntime.getRefreshReg(\"${id}\");\nwindow.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;\n\n`;\n }\n out += code;\n if (hasRefreshCalls) {\n out += `\n\nwindow.$RefreshReg$ = prevRefreshReg;\nwindow.$RefreshSig$ = prevRefreshSig;\n`;\n }\n out += `\nRefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {\n RefreshRuntime.registerExportsForReactRefresh(\"${id}\", currentExports);\n import.meta.hot.accept((nextExports) => {\n if (!nextExports) return;\n const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(\"${id}\", currentExports, nextExports);\n if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);\n });\n});\n`;\n return { code: out, map: null };\n }\n }\n ];\n}\nexport {\n JS_GLOBALS,\n clearTransformCache,\n createVXRNCompilerPlugin,\n getClosureVariables\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;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,IAAI,KAAK,SAAS,iBAAiB,GAAG;IACtC,IAAI,wCAAwC,KAAK,GAAG,GAAG;IACvD,MAAM,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC;IAC1B,IAAI,GAAG,SAAS,cAAc,GAAG;IACjC,IAAI,GAAG,SAAS,UAAU,GAAG;IAC7B,IAAI,OAAO,mBAAmB;IAC9B,MAAM,MAAM,QAAQ,EAAE;IACtB,IAAI,QAAQ,UAAU,QAAQ,QAAQ;IACtC,MAAM,kBAAkB,mBAAmB,KAAK,IAAI;IACpD,IAAI,MAAM,oCAAoC,kBAAkB;;;IAGhE,IAAI,iBAAiB;KACnB,OAAO;;;sDAGqC,GAAG;;;;IAIjD;IACA,OAAO;IACP,IAAI,iBAAiB;KACnB,OAAO;;;;;IAKT;IACA,OAAO;;mDAEoC,GAAG;;;wFAGkC,GAAG;;;;;IAKnF,OAAO;KAAE,MAAM;KAAK,KAAK;IAAK;GAChC;EACF;CACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { dirname, extname, join, relative, sep } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { resolvePath } from \"@vxrn/utils\";\nimport { cssToReactNativeRuntime } from \"react-native-css-interop/css-to-rn/index.js\";\nimport { configuration, isNativeWorkletsEnabled } from \"./configure\";\nimport { debug, runtimePublicPath, validParsers } from \"./constants\";\nimport {\n getBabelOptions,\n transformBabel,\n transformOxcReactCompiler\n} from \"./transformBabel\";\nimport { shouldSourceMap } from \"./transformSWC\";\nimport {\n prepareWorkletsForReactCompiler,\n shouldTransformWorklets,\n transformWorklets\n} from \"./transformWorklets\";\nimport { getCachedTransform, logCacheStats, setCachedTransform } from \"./cache\";\nexport * from \"./configure\";\nexport * from \"./transformBabel\";\nexport * from \"./transformFlow\";\nexport * from \"./transformSWC\";\nexport * from \"./transformWorklets\";\nexport * from \"./reactNativeCodegen\";\nexport * from \"./transformHermesLoops\";\nexport * from \"./transformHermesAsync\";\nexport * from \"./transformHermesClasses\";\nimport { clearTransformCache } from \"./cache\";\nimport { JS_GLOBALS } from \"./worklets/globals\";\nimport { getClosureVariables } from \"./worklets/scope\";\nexport * from \"./transformMixedNativeModule\";\nconst perfStats = {\n babel: {\n totalCalls: 0,\n totalTransforms: 0,\n totalTime: 0,\n byEnvironment: {}\n },\n optimizeDeps: {\n byEnvironment: {}\n }\n};\nfunction logPerfSummary() {\n if (!process.env.DEBUG_COMPILER_PERF) {\n return;\n }\n console.info(\"\\n\\u{1F4CA} [Compiler Performance Summary]\");\n console.info(\n `Babel: ${perfStats.babel.totalTransforms} transforms / ${perfStats.babel.totalCalls} calls (${(perfStats.babel.totalTransforms / Math.max(perfStats.babel.totalCalls, 1) * 100).toFixed(1)}% transform rate)`\n );\n console.info(`Babel total time: ${perfStats.babel.totalTime}ms`);\n for (const [env, stats] of Object.entries(perfStats.babel.byEnvironment)) {\n if (stats.transforms > 0) {\n console.info(\n ` ${env}: ${stats.transforms} transforms, ${stats.time}ms (${(stats.time / stats.transforms).toFixed(1)}ms avg)`\n );\n }\n }\n for (const [env, stats] of Object.entries(perfStats.optimizeDeps.byEnvironment)) {\n const elapsed = Date.now() - stats.startTime;\n console.info(\n `optimizeDeps ${env}: checked ${stats.filesChecked} files, transformed ${stats.filesTransformed} (${elapsed}ms)`\n );\n }\n}\nconst compilerLog = {\n compiled: 0,\n cached: 0,\n time: 0,\n // typed loose because the dom lib types setTimeout as number, but node gives\n // us a Timeout we need to unref so the debounce never holds the process open\n timer: null\n};\nfunction logCompiled(cached, ms) {\n if (cached) {\n compilerLog.cached++;\n } else {\n compilerLog.compiled++;\n compilerLog.time += ms;\n }\n if (compilerLog.timer) clearTimeout(compilerLog.timer);\n compilerLog.timer = setTimeout(() => {\n const total = compilerLog.compiled + compilerLog.cached;\n const detail = compilerLog.compiled ? `${compilerLog.compiled} compiled in ${compilerLog.time}ms${compilerLog.cached ? `, ${compilerLog.cached} cached` : \"\"}` : `all cached`;\n console.info(` \\u{1FA84} [compiler] ${total} file${total === 1 ? \"\" : \"s\"} (${detail})`);\n compilerLog.compiled = 0;\n compilerLog.cached = 0;\n compilerLog.time = 0;\n compilerLog.timer = null;\n }, 500);\n compilerLog.timer.unref?.();\n}\nasync function performBabelTransform({\n id,\n code,\n projectRoot,\n environment,\n production,\n reactForRNVersion,\n optionsIn\n}) {\n perfStats.babel.totalCalls++;\n if (!perfStats.babel.byEnvironment[environment]) {\n perfStats.babel.byEnvironment[environment] = { calls: 0, transforms: 0, time: 0 };\n }\n perfStats.babel.byEnvironment[environment].calls++;\n const transformProps = {\n id,\n code,\n projectRoot,\n development: !production,\n environment,\n reactForRNVersion\n };\n const userTransform = optionsIn?.transform?.(transformProps);\n if (userTransform === false) {\n return null;\n }\n if (userTransform !== \"swc\" && userTransform !== \"oxc\") {\n let babelOptions = getBabelOptions({\n ...transformProps,\n userSetting: userTransform\n });\n if (!babelOptions && shouldTransformWorklets({ id, code })) {\n babelOptions = { plugins: [] };\n }\n if (babelOptions) {\n const hasCompilerPlugin = babelOptions.plugins?.some(\n (x) => Array.isArray(x) && x[0] === \"babel-plugin-react-compiler\"\n );\n const userBabelConfigPath = typeof babelOptions.configFile === \"string\" ? babelOptions.configFile : null;\n const cached = getCachedTransform(id, code, environment, userBabelConfigPath);\n if (cached) {\n perfStats.babel.byEnvironment[environment].transforms++;\n if (hasCompilerPlugin && (cached.code.includes(\"react/compiler-runtime\") || cached.code.includes(\"react-compiler-runtime\"))) {\n debug?.(` \\u{1FA84} [compiler] ${relative(process.cwd(), id)} (cached)`);\n logCompiled(true, 0);\n }\n debug?.(`[babel/cached] ${id}`);\n return cached;\n }\n const isWorkletPlugin = (entry) => {\n if (!entry) return false;\n const name = typeof entry === \"string\" ? entry : Array.isArray(entry) ? entry[0] : null;\n return typeof name === \"string\" && (name.includes(\"react-native-worklets\") || name.includes(\"react-native-reanimated\"));\n };\n const workletEntry = babelOptions.plugins?.find(isWorkletPlugin);\n const workletPluginOptions = Array.isArray(workletEntry) ? workletEntry[1] : void 0;\n const useWorklets = isNativeWorkletsEnabled() && (Boolean(workletEntry) || shouldTransformWorklets({ id, code }));\n let curCode = code;\n let workletPreparation = null;\n let compilerOut = null;\n const compilerPluginIndex = babelOptions.plugins?.findIndex(\n (x) => Array.isArray(x) && x[0] === \"babel-plugin-react-compiler\"\n ) ?? -1;\n if (compilerPluginIndex !== -1) {\n const compilerPluginConfig = babelOptions.plugins[compilerPluginIndex];\n const compilerPluginOptions = compilerPluginConfig[1] || {};\n const useBabelCompiler = compilerPluginOptions.compiler === \"babel\" || process.env.ONE_REACT_COMPILER === \"babel\" || process.env.VXRN_REACT_COMPILER === \"babel\";\n if (!useBabelCompiler) {\n if (useWorklets) {\n workletPreparation = prepareWorkletsForReactCompiler(\n id,\n curCode,\n shouldSourceMap()\n );\n if (workletPreparation) curCode = workletPreparation.code;\n }\n compilerOut = await transformOxcReactCompiler(\n id,\n curCode,\n compilerPluginOptions,\n shouldSourceMap()\n );\n if (compilerOut) curCode = compilerOut.code;\n babelOptions.plugins.splice(compilerPluginIndex, 1);\n }\n }\n let workletsOut = null;\n if (useWorklets) {\n workletsOut = await transformWorklets(id, curCode, shouldSourceMap(), {\n projectRoot,\n ...workletPluginOptions\n });\n babelOptions.plugins = babelOptions.plugins?.filter(\n (entry) => !isWorkletPlugin(entry)\n );\n curCode = workletsOut.code;\n }\n const startTime = Date.now();\n let babelOut = null;\n if (babelOptions.plugins?.length === 0 && !babelOptions.configFile && !babelOptions.babelrc) {\n let finalMap = void 0;\n if (shouldSourceMap()) {\n const intermediateMaps = [\n workletPreparation?.map,\n compilerOut?.map,\n workletsOut?.map\n ].filter(Boolean);\n if (intermediateMaps.length === 1) {\n finalMap = intermediateMaps[0];\n } else if (intermediateMaps.length > 1) {\n const remapping = (await import(\"@jridgewell/remapping\")).default;\n finalMap = remapping(intermediateMaps.slice().reverse(), () => null);\n }\n }\n babelOut = { code: curCode, map: finalMap };\n } else {\n const babelOptsWithMap = shouldSourceMap() && (workletsOut?.map || compilerOut?.map || workletPreparation?.map) ? { ...babelOptions, sourceMaps: true } : babelOptions;\n babelOut = await transformBabel(id, curCode, babelOptsWithMap);\n if (shouldSourceMap() && babelOut?.map) {\n const priorMaps = [\n workletPreparation?.map,\n compilerOut?.map,\n workletsOut?.map\n ].filter(Boolean);\n if (priorMaps.length > 0) {\n const remapping = (await import(\"@jridgewell/remapping\")).default;\n babelOut.map = remapping(\n [babelOut.map, ...priorMaps.slice().reverse()],\n () => null\n );\n }\n }\n }\n const babelTime = Date.now() - startTime;\n if (babelOut?.code) {\n perfStats.babel.totalTransforms++;\n perfStats.babel.totalTime += babelTime;\n perfStats.babel.byEnvironment[environment].transforms++;\n perfStats.babel.byEnvironment[environment].time += babelTime;\n if (hasCompilerPlugin && (babelOut.code.includes(\"react/compiler-runtime\") || babelOut.code.includes(\"react-compiler-runtime\"))) {\n debug?.(` \\u{1FA84} [compiler] ${relative(process.cwd(), id)} (${babelTime}ms)`);\n logCompiled(false, babelTime);\n }\n debug?.(`[babel] ${id}`);\n const outCode = `${babelOut.code}\n// vxrn-did-babel`;\n const result = { code: outCode, map: babelOut.map };\n setCachedTransform(id, code, result, environment, userBabelConfigPath);\n return result;\n }\n }\n }\n return null;\n}\nasync function createVXRNCompilerPlugin(optionsIn) {\n const reactVersion = await (async () => {\n const path = resolvePath(\"react/package.json\");\n const json = JSON.parse(await readFile(path, \"utf-8\"));\n return json.version;\n })();\n const envNames = {\n ios: true,\n android: true,\n client: true,\n ssr: true\n };\n function getEnvName(name) {\n if (name === \"worker\") return \"ssr\";\n if (!envNames[name]) throw new Error(`Invalid env: ${name}`);\n return name;\n }\n const reactForRNVersion = reactVersion.split(\".\")[0];\n const cssTransformCache = /* @__PURE__ */ new Map();\n const rolldownPath = resolvePath(\"rolldown\");\n const rolldownNodeMods = rolldownPath.slice(\n 0,\n rolldownPath.indexOf(sep + \"node_modules\")\n );\n let config;\n return [\n {\n name: \"one:compiler-resolve-refresh-runtime\",\n apply: \"serve\",\n enforce: \"pre\",\n // Run before Vite default resolve to avoid syscalls\n resolveId: (id) => id === runtimePublicPath || id === `${runtimePublicPath}.map` ? id : void 0,\n load: (id) => {\n const basePath = dirname(fileURLToPath(import.meta.url));\n if (id === runtimePublicPath) {\n return readFileSync(join(basePath, \"refresh-runtime.mjs\"), \"utf-8\").replace(\n /\\/\\/# sourceMappingURL=.*/,\n \"\"\n );\n }\n if (id === `${runtimePublicPath}.map`) {\n return JSON.stringify({ version: 3, sources: [], mappings: \"\" });\n }\n return void 0;\n }\n },\n {\n name: `one:compiler-css-to-js`,\n // only .css files can match, so let rust reject everything else\n transform: {\n filter: { id: /\\.css$/ },\n handler(codeIn, id) {\n const environment = getEnvName(this.environment.name);\n if (configuration.enableNativeCSS && (environment === \"ios\" || environment === \"android\")) {\n {\n const data = JSON.stringify(\n cssToReactNativeRuntime(codeIn, { inlineRem: 16 })\n );\n const code = `require(\"nativewind/dist/index.js\").require().StyleSheet.registerCompiled(${data})`;\n const newId = `${id}.js`;\n const cssId = newId.replace(rolldownNodeMods + sep, \"\");\n cssTransformCache.set(cssId, code);\n return {\n code,\n id: newId,\n map: null\n };\n }\n }\n }\n },\n generateBundle(_, bundle) {\n const environment = getEnvName(this.environment.name);\n if (configuration.enableNativeCSS && (environment === \"ios\" || environment === \"android\")) {\n const rootJSName = Object.keys(bundle).find((i) => {\n const chunk = bundle[i];\n return chunk.type == \"chunk\" && chunk.fileName.match(/.[cm]?js(?:\\?.+)?$/) != null;\n });\n if (!rootJSName) {\n throw new Error(`Can't find root js, internal one error`);\n }\n const rootJS = bundle[rootJSName];\n const cssAssets = Object.keys(bundle).filter(\n (i) => bundle[i].fileName.endsWith(\".css.js\")\n );\n for (const name of cssAssets) {\n delete bundle[name];\n const jsCSS = cssTransformCache.get(name);\n rootJS.code = `\n${jsCSS}\n${rootJS.code}\n`;\n }\n }\n }\n },\n {\n name: \"one:compiler\",\n enforce: \"pre\",\n config: () => {\n const nodeModulesFilter = /node_modules[/\\\\].*\\.(tsx?|jsx?|mjs|cjs)$/;\n const createEnvironmentConfig = (environment) => {\n if (!perfStats.optimizeDeps.byEnvironment[environment]) {\n perfStats.optimizeDeps.byEnvironment[environment] = {\n filesChecked: 0,\n filesTransformed: 0,\n startTime: Date.now()\n };\n }\n return {\n optimizeDeps: {\n rolldownOptions: {\n plugins: [\n {\n name: `transform-before-optimize-deps-${environment}`,\n async transform(code, id) {\n if (!nodeModulesFilter.test(id)) {\n return null;\n }\n perfStats.optimizeDeps.byEnvironment[environment].filesChecked++;\n const production = process.env.NODE_ENV === \"production\" || process.env.NODE_ENV === \"test\";\n debug?.(`[rolldown optimizeDeps] ${id}`);\n const result = await performBabelTransform({\n id,\n code,\n projectRoot: config.root,\n environment,\n production,\n reactForRNVersion,\n optionsIn\n });\n if (!result) {\n return null;\n }\n perfStats.optimizeDeps.byEnvironment[environment].filesTransformed++;\n return {\n code: result.code,\n map: result.map\n };\n },\n buildEnd() {\n if (process.env.DEBUG_COMPILER_PERF) {\n const stats = perfStats.optimizeDeps.byEnvironment[environment];\n const elapsed = Date.now() - stats.startTime;\n console.info(\n `[optimizeDeps ${environment}] Done: ${stats.filesChecked} files checked, ${stats.filesTransformed} transformed (${elapsed}ms)`\n );\n }\n const allDone = Object.keys(perfStats.optimizeDeps.byEnvironment).length >= 2;\n if (allDone) {\n logCacheStats();\n logPerfSummary();\n }\n }\n }\n ]\n }\n },\n define: {\n \"process.env.NATIVEWIND_OS\": JSON.stringify(\n environment === \"ios\" || environment === \"android\" ? \"native\" : \"web\"\n )\n }\n };\n };\n return {\n environments: {\n ios: createEnvironmentConfig(\"ios\"),\n android: createEnvironmentConfig(\"android\"),\n client: createEnvironmentConfig(\"client\"),\n ssr: createEnvironmentConfig(\"ssr\")\n }\n };\n },\n configResolved(resolvedConfig) {\n config = resolvedConfig;\n },\n async transform(codeIn, _id) {\n let code = codeIn;\n const environment = getEnvName(this.environment.name);\n const isNative = environment === \"ios\" || environment === \"android\";\n const production = config.command === \"build\" || process.env.NODE_ENV === \"production\" || JSON.parse(\n this.environment.config?.define?.[\"process.env.NODE_ENV\"] || '\"\"'\n ) === \"production\";\n const isEntry = _id.includes(\"one-entry-native\");\n if (isEntry) {\n if (isNative && !production) {\n code = `import '@vxrn/vite-native-client'\n${code}`;\n }\n if (isNative && configuration.enableNativewind) {\n code = `import * as x from 'nativewind'\n${code}`;\n }\n return code;\n }\n const id = _id.split(\"?\")[0];\n const extension = extname(id);\n if (extension === \".css\" || !validParsers.has(extension)) {\n return;\n }\n if (id.includes(`virtual:`)) {\n return;\n }\n if (codeIn.endsWith(`// vxrn-did-babel`)) {\n debug?.(`[skip babel] ${id}`);\n return;\n }\n return performBabelTransform({\n id,\n code: codeIn,\n projectRoot: config.root,\n environment,\n production,\n reactForRNVersion,\n optionsIn\n });\n }\n },\n // wraps client-side TSX/JSX with React Refresh preamble + import.meta.hot.accept\n // runs after vite:oxc (no enforce:'pre') so it sees the already-transformed code\n {\n name: \"one:react-refresh-web\",\n apply: \"serve\",\n transform(code, _id) {\n if (this.environment.name !== \"client\") return;\n if (code.includes(runtimePublicPath)) return;\n if (/[?&](?:worker|sharedworker|raw|url)\\b/.test(_id)) return;\n const id = _id.split(\"?\")[0];\n if (id.includes(\"node_modules\")) return;\n if (id.includes(\"virtual:\")) return;\n if (id === runtimePublicPath) return;\n const ext = extname(id);\n if (ext !== \".tsx\" && ext !== \".jsx\") return;\n const hasRefreshCalls = /\\$RefreshReg\\$\\(/.test(code);\n let out = `import * as RefreshRuntime from \"${runtimePublicPath}\";\n\n`;\n if (hasRefreshCalls) {\n out += `if (!window.$RefreshReg$) throw new Error(\"React refresh preamble was not loaded. Something is wrong.\");\nconst prevRefreshReg = window.$RefreshReg$;\nconst prevRefreshSig = window.$RefreshSig$;\nwindow.$RefreshReg$ = RefreshRuntime.getRefreshReg(\"${id}\");\nwindow.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;\n\n`;\n }\n out += code;\n if (hasRefreshCalls) {\n out += `\n\nwindow.$RefreshReg$ = prevRefreshReg;\nwindow.$RefreshSig$ = prevRefreshSig;\n`;\n }\n out += `\nRefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {\n RefreshRuntime.registerExportsForReactRefresh(\"${id}\", currentExports);\n import.meta.hot.accept((nextExports) => {\n if (!nextExports) return;\n const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(\"${id}\", currentExports, nextExports);\n if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);\n });\n});\n`;\n return { code: out, map: null };\n }\n }\n ];\n}\nexport {\n JS_GLOBALS,\n clearTransformCache,\n createVXRNCompilerPlugin,\n getClosureVariables\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,YAAY;CAChB,OAAO;EACL,YAAY;EACZ,iBAAiB;EACjB,WAAW;EACX,eAAe,CAAC;CAClB;CACA,cAAc,EACZ,eAAe,CAAC,EAClB;AACF;AACA,SAAS,iBAAiB;CACxB,IAAI,CAAC,QAAQ,IAAI,qBAAqB;EACpC;CACF;CACA,QAAQ,KAAK,qCAA4C;CACzD,QAAQ,KACN,UAAU,UAAU,MAAM,gBAAgB,gBAAgB,UAAU,MAAM,WAAW,WAAW,UAAU,MAAM,kBAAkB,KAAK,IAAI,UAAU,MAAM,YAAY,CAAC,IAAI,IAAG,CAAE,QAAQ,CAAC,EAAE,kBAC9L;CACA,QAAQ,KAAK,qBAAqB,UAAU,MAAM,UAAU,GAAG;CAC/D,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,MAAM,aAAa,GAAG;EACxE,IAAI,MAAM,aAAa,GAAG;GACxB,QAAQ,KACN,KAAK,IAAI,IAAI,MAAM,WAAW,eAAe,MAAM,KAAK,OAAO,MAAM,OAAO,MAAM,WAAU,CAAE,QAAQ,CAAC,EAAE,QAC3G;E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AAkB;MAC9C,OAAO;EACjB;KACQ;KACA,OAAO;IACT;IACA,MAAM,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC;IAC1B,MAAM,YAAY,QAAQ,EAAE;IAC5B,IAAI,cAAc,UAAU,CAAC,aAAa,IAAI,SAAS,GAAG;KACxD;IACF;IACA,IAAI,GAAG,SAAS,UAAU,GAAG;KAC3B;IACF;IACA,IAAI,OAAO,SAAS,mBAAmB,GAAG;KACxC,QAAQ,gBAAgB,IAAI;KAC5B;IACF;IACA,OAAO,sBAAsB;KAC3B;KACA,MAAM;KACN,aAAa,OAAO;KACpB;KACA;KACA;KACA;IACF,CAAC;GACH;EACF;EAGA;GACE,MAAM;GACN,OAAO;GACP,UAAU,MAAM,KAAK;IACnB,IAAI,KAAK,YAAY,SAAS,UAAU;IACxC,IAAI,KAAK,SAAS,iBAAiB,GAAG;IACtC,IAAI,wCAAwC,KAAK,GAAG,GAAG;IACvD,MAAM,KAAK,IAAI,MAAM,GAAG,CAAC,CAAC;IAC1B,IAAI,GAAG,SAAS,cAAc,GAAG;IACjC,IAAI,GAAG,SAAS,UAAU,GAAG;IAC7B,IAAI,OAAO,mBAAmB;IAC9B,MAAM,MAAM,QAAQ,EAAE;IACtB,IAAI,QAAQ,UAAU,QAAQ,QAAQ;IACtC,MAAM,kBAAkB,mBAAmB,KAAK,IAAI;IACpD,IAAI,MAAM,oCAAoC,kBAAkB;;;IAGhE,IAAI,iBAAiB;KACnB,OAAO;;;sDAGqC,GAAG;;;;IAIjD;IACA,OAAO;IACP,IAAI,iBAAiB;KACnB,OAAO;;;;;IAKT;IACA,OAAO;;mDAEoC,GAAG;;;wFAGkC,GAAG;;;;;IAKnF,OAAO;KAAE,MAAM;KAAK,KAAK;IAAK;GAChC;EACF;CACF;AACF"}
@@ -33,12 +33,12 @@ function isCodegenNativeCommandsDeclaration(declaration) {
33
33
  const unwrapped = unwrapExpression(declaration);
34
34
  return unwrapped?.type === "CallExpression" && unwrapped.callee?.type === "Identifier" && unwrapped.callee.name === "codegenNativeCommands";
35
35
  }
36
+ function isReactNativeCodegenSpec(id, code) {
37
+ return CODEGEN_FILE_RE.test(normalizePath(id.split("?")[0])) && CODEGEN_CALL_RE.test(code);
38
+ }
36
39
  function transformReactNativeCodegen(code, id, projectRoot) {
37
40
  const cleanId = normalizePath(id.split("?")[0]);
38
- if (!CODEGEN_FILE_RE.test(cleanId)) {
39
- return;
40
- }
41
- if (!CODEGEN_CALL_RE.test(code)) {
41
+ if (!isReactNativeCodegenSpec(id, code)) {
42
42
  return;
43
43
  }
44
44
  const program = parseSpec(code, cleanId, projectRoot);
@@ -102,5 +102,5 @@ function transformReactNativeCodegen(code, id, projectRoot) {
102
102
  };
103
103
  }
104
104
 
105
- export { transformReactNativeCodegen };
105
+ export { isReactNativeCodegenSpec, transformReactNativeCodegen };
106
106
  //# sourceMappingURL=reactNativeCodegen.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"reactNativeCodegen.js","names":[],"sources":["esm/reactNativeCodegen.js"],"sourcesContent":["import MagicString from \"magic-string\";\nimport {\n generateViewConfig,\n parseSpec,\n renderViewConfigModule\n} from \"./reactNativeViewConfig\";\nfunction normalizePath(id) {\n return id.replace(/\\\\/g, \"/\");\n}\nconst CODEGEN_FILE_RE = /(?:NativeComponent\\.[cm]?[jt]sx?$|[/\\\\]specs?[/\\\\])/;\nconst CODEGEN_CALL_RE = /codegenNativeComponent\\s*[<(]/;\nconst startOf = (node) => node.start ?? node.range[0];\nconst endOf = (node) => node.end ?? node.range[1];\nfunction unwrapExpression(node) {\n while (node) {\n if (node.type === \"TSAsExpression\" || node.type === \"TSSatisfiesExpression\" || node.type === \"TSTypeAssertion\" || node.type === \"TypeCastExpression\" || node.type === \"AsExpression\" || node.type === \"ParenthesizedExpression\") {\n node = node.expression;\n } else if (node.type === \"SequenceExpression\" && Array.isArray(node.expressions) && node.expressions.length > 0) {\n node = node.expressions[node.expressions.length - 1];\n } else {\n break;\n }\n }\n return node;\n}\nfunction isCodegenDeclaration(declaration) {\n if (!declaration) return false;\n if (declaration.left && declaration.left.left && declaration.left.left.name === \"codegenNativeComponent\") {\n return true;\n }\n const unwrapped = unwrapExpression(declaration);\n return unwrapped?.type === \"CallExpression\" && unwrapped.callee?.type === \"Identifier\" && unwrapped.callee.name === \"codegenNativeComponent\";\n}\nfunction isCodegenNativeCommandsDeclaration(declaration) {\n if (!declaration) return false;\n const unwrapped = unwrapExpression(declaration);\n return unwrapped?.type === \"CallExpression\" && unwrapped.callee?.type === \"Identifier\" && unwrapped.callee.name === \"codegenNativeCommands\";\n}\nfunction transformReactNativeCodegen(code, id, projectRoot) {\n const cleanId = normalizePath(id.split(\"?\")[0]);\n if (!CODEGEN_FILE_RE.test(cleanId)) {\n return;\n }\n if (!CODEGEN_CALL_RE.test(code)) {\n return;\n }\n const program = parseSpec(code, cleanId, projectRoot);\n const body = program?.body;\n if (!body) {\n return;\n }\n let defaultExport = null;\n let commandsExport = null;\n for (const node of body) {\n if (node.type === \"ExportDefaultDeclaration\") {\n if (isCodegenDeclaration(node.declaration)) {\n defaultExport = node;\n }\n } else if (node.type === \"ExportNamedDeclaration\") {\n if (node.declaration && node.declaration.declarations) {\n const firstDeclaration = node.declaration.declarations[0];\n if (firstDeclaration?.type === \"VariableDeclarator\") {\n const isValidCommandsExport = isCodegenNativeCommandsDeclaration(\n firstDeclaration.init\n );\n if (isValidCommandsExport) {\n if (firstDeclaration.id?.type === \"Identifier\" && firstDeclaration.id.name !== \"Commands\") {\n throw new Error(\"Native commands must be exported with the name 'Commands'\");\n }\n commandsExport = node;\n } else {\n if (firstDeclaration.id?.type === \"Identifier\" && firstDeclaration.id.name === \"Commands\") {\n throw new Error(\n \"'Commands' is a reserved export and may only be used to export the result of codegenNativeCommands.\"\n );\n }\n }\n }\n } else if (node.specifiers && node.specifiers.length > 0) {\n for (const specifier of node.specifiers) {\n if (specifier.type === \"ExportSpecifier\" && (specifier.local?.type === \"Identifier\" && specifier.local.name === \"Commands\" || specifier.exported?.type === \"Identifier\" && specifier.exported.name === \"Commands\")) {\n throw new Error(\n \"'Commands' is a reserved export and may only be used to export the result of codegenNativeCommands.\"\n );\n }\n }\n }\n }\n }\n if (!defaultExport) {\n return;\n }\n const generated = generateViewConfig(program);\n if (!generated) {\n return;\n }\n const s = new MagicString(code);\n if (commandsExport) {\n let removeEnd = endOf(commandsExport);\n if (code[removeEnd] === \"\\r\") removeEnd++;\n if (code[removeEnd] === \"\\n\") removeEnd++;\n s.remove(startOf(commandsExport), removeEnd);\n }\n s.overwrite(\n startOf(defaultExport),\n endOf(defaultExport),\n renderViewConfigModule(generated)\n );\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: cleanId })\n };\n}\nexport {\n transformReactNativeCodegen\n};\n//# sourceMappingURL=reactNativeCodegen.js.map\n"],"mappings":";;;;AAMA,SAAS,cAAc,IAAI;CACzB,OAAO,GAAG,QAAQ,OAAO,GAAG;AAC9B;AACA,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,WAAW,SAAS,KAAK,SAAS,KAAK,MAAM;AACnD,MAAM,SAAS,SAAS,KAAK,OAAO,KAAK,MAAM;AAC/C,SAAS,iBAAiB,MAAM;CAC9B,OAAO,MAAM;EACX,IAAI,KAAK,SAAS,oBAAoB,KAAK,SAAS,2BAA2B,KAAK,SAAS,qBAAqB,KAAK,SAAS,wBAAwB,KAAK,SAAS,kBAAkB,KAAK,SAAS,2BAA2B;GAC/N,OAAO,KAAK;EACd,OAAO,IAAI,KAAK,SAAS,wBAAwB,MAAM,QAAQ,KAAK,WAAW,KAAK,KAAK,YAAY,SAAS,GAAG;GAC/G,OAAO,KAAK,YAAY,KAAK,YAAY,SAAS;EACpD,OAAO;GACL;EACF;CACF;CACA,OAAO;AACT;AACA,SAAS,qBAAqB,aAAa;CACzC,IAAI,CAAC,aAAa,OAAO;CACzB,IAAI,YAAY,QAAQ,YAAY,KAAK,QAAQ,YAAY,KAAK,KAAK,SAAS,0BAA0B;EACxG,O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ACF,OAAO,IAAI,KAAK,cAAc,KAAK,WAAW,SAAS,GAAG;IACxD,KAAK,MAAM,aAAa,KAAK,YAAY;KACvC,IAAI,UAAU,SAAS,sBAAsB,UAAU,OAAO,SAAS,gBAAgB,UAAU,MAAM,SAAS,cAAc,UAAU,UAAU,SAAS,gBAAgB,UAAU,SAAS,SAAS,aAAa;MAClN,MAAM,IAAI,MACR,qGACF;KACF;IACF;GACF;EACF;CACF;CACA,IAAI,CAAC,eAAe;EAClB;CACF;CACA,MAAM,YAAY,mBAAmB,OAAO;CAC5C,IAAI,CAAC,WAAW;EACd;CACF;CACA,MAAM,IAAI,IAAI,YAAY,IAAI;CAC9B,IAAI,gBAAgB;EAClB,IAAI,YAAY,MAAM,cAAc;EACpC,IAAI,KAAK,eAAe,MAAM;EAC9B,IAAI,KAAK,eAAe,MAAM;EAC9B,EAAE,OAAO,QAAQ,cAAc,GAAG,SAAS;CAC7C;CACA,EAAE,UACA,QAAQ,aAAa,GACrB,MAAM,aAAa,GACnB,uBAAuB,SAAS,CAClC;CACA,OAAO;EACL,MAAM,EAAE,SAAS;EACjB,KAAK,EAAE,YAAY;GAAE,OAAO;GAAM,QAAQ;EAAQ,CAAC;CACrD;AACF"}
1
+ {"version":3,"file":"reactNativeCodegen.js","names":[],"sources":["esm/reactNativeCodegen.js"],"sourcesContent":["import MagicString from \"magic-string\";\nimport {\n generateViewConfig,\n parseSpec,\n renderViewConfigModule\n} from \"./reactNativeViewConfig\";\nfunction normalizePath(id) {\n return id.replace(/\\\\/g, \"/\");\n}\nconst CODEGEN_FILE_RE = /(?:NativeComponent\\.[cm]?[jt]sx?$|[/\\\\]specs?[/\\\\])/;\nconst CODEGEN_CALL_RE = /codegenNativeComponent\\s*[<(]/;\nconst startOf = (node) => node.start ?? node.range[0];\nconst endOf = (node) => node.end ?? node.range[1];\nfunction unwrapExpression(node) {\n while (node) {\n if (node.type === \"TSAsExpression\" || node.type === \"TSSatisfiesExpression\" || node.type === \"TSTypeAssertion\" || node.type === \"TypeCastExpression\" || node.type === \"AsExpression\" || node.type === \"ParenthesizedExpression\") {\n node = node.expression;\n } else if (node.type === \"SequenceExpression\" && Array.isArray(node.expressions) && node.expressions.length > 0) {\n node = node.expressions[node.expressions.length - 1];\n } else {\n break;\n }\n }\n return node;\n}\nfunction isCodegenDeclaration(declaration) {\n if (!declaration) return false;\n if (declaration.left && declaration.left.left && declaration.left.left.name === \"codegenNativeComponent\") {\n return true;\n }\n const unwrapped = unwrapExpression(declaration);\n return unwrapped?.type === \"CallExpression\" && unwrapped.callee?.type === \"Identifier\" && unwrapped.callee.name === \"codegenNativeComponent\";\n}\nfunction isCodegenNativeCommandsDeclaration(declaration) {\n if (!declaration) return false;\n const unwrapped = unwrapExpression(declaration);\n return unwrapped?.type === \"CallExpression\" && unwrapped.callee?.type === \"Identifier\" && unwrapped.callee.name === \"codegenNativeCommands\";\n}\nfunction isReactNativeCodegenSpec(id, code) {\n return CODEGEN_FILE_RE.test(normalizePath(id.split(\"?\")[0])) && CODEGEN_CALL_RE.test(code);\n}\nfunction transformReactNativeCodegen(code, id, projectRoot) {\n const cleanId = normalizePath(id.split(\"?\")[0]);\n if (!isReactNativeCodegenSpec(id, code)) {\n return;\n }\n const program = parseSpec(code, cleanId, projectRoot);\n const body = program?.body;\n if (!body) {\n return;\n }\n let defaultExport = null;\n let commandsExport = null;\n for (const node of body) {\n if (node.type === \"ExportDefaultDeclaration\") {\n if (isCodegenDeclaration(node.declaration)) {\n defaultExport = node;\n }\n } else if (node.type === \"ExportNamedDeclaration\") {\n if (node.declaration && node.declaration.declarations) {\n const firstDeclaration = node.declaration.declarations[0];\n if (firstDeclaration?.type === \"VariableDeclarator\") {\n const isValidCommandsExport = isCodegenNativeCommandsDeclaration(\n firstDeclaration.init\n );\n if (isValidCommandsExport) {\n if (firstDeclaration.id?.type === \"Identifier\" && firstDeclaration.id.name !== \"Commands\") {\n throw new Error(\"Native commands must be exported with the name 'Commands'\");\n }\n commandsExport = node;\n } else {\n if (firstDeclaration.id?.type === \"Identifier\" && firstDeclaration.id.name === \"Commands\") {\n throw new Error(\n \"'Commands' is a reserved export and may only be used to export the result of codegenNativeCommands.\"\n );\n }\n }\n }\n } else if (node.specifiers && node.specifiers.length > 0) {\n for (const specifier of node.specifiers) {\n if (specifier.type === \"ExportSpecifier\" && (specifier.local?.type === \"Identifier\" && specifier.local.name === \"Commands\" || specifier.exported?.type === \"Identifier\" && specifier.exported.name === \"Commands\")) {\n throw new Error(\n \"'Commands' is a reserved export and may only be used to export the result of codegenNativeCommands.\"\n );\n }\n }\n }\n }\n }\n if (!defaultExport) {\n return;\n }\n const generated = generateViewConfig(program);\n if (!generated) {\n return;\n }\n const s = new MagicString(code);\n if (commandsExport) {\n let removeEnd = endOf(commandsExport);\n if (code[removeEnd] === \"\\r\") removeEnd++;\n if (code[removeEnd] === \"\\n\") removeEnd++;\n s.remove(startOf(commandsExport), removeEnd);\n }\n s.overwrite(\n startOf(defaultExport),\n endOf(defaultExport),\n renderViewConfigModule(generated)\n );\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: cleanId })\n };\n}\nexport {\n isReactNativeCodegenSpec,\n transformReactNativeCodegen\n};\n//# sourceMappingURL=reactNativeCodegen.js.map\n"],"mappings":";;;;AAMA,SAAS,cAAc,IAAI;CACzB,OAAO,GAAG,QAAQ,OAAO,GAAG;AAC9B;AACA,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AACxB,MAAM,WAAW,SAAS,KAAK,SAAS,KAAK,MAAM;AACnD,MAAM,SAAS,SAAS,KAAK,OAAO,KAAK,MAAM;AAC/C,SAAS,iBAAiB,MAAM;CAC9B,OAAO,MAAM;EACX,IAAI,KAAK,SAAS,oBAAoB,KAAK,SAAS,2BAA2B,KAAK,SAAS,qBAAqB,KAAK,SAAS,wBAAwB,KAAK,SAAS,kBAAkB,KAAK,SAAS,2BAA2B;GAC/N,OAAO,KAAK;EACd,OAAO,IAAI,KAAK,SAAS,wBAAwB,MAAM,QAAQ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,YAAY,aAAa;IACvD,IAAI,kBAAkB,SAAS,sBAAsB;KACnD,MAAM,wBAAwB,mCAC5B,iBAAiB,IACnB;KACA,IAAI,uBAAuB;MACzB,IAAI,iBAAiB,IAAI,SAAS,gBAAgB,iBAAiB,GAAG,SAAS,YAAY;OACzF,MAAM,IAAI,MAAM,2DAA2D;MAC7E;MACA,iBAAiB;KACnB,OAAO;MACL,IAAI,iBAAiB,IAAI,SAAS,gBAAgB,iBAAiB,GAAG,SAAS,YAAY;OACzF,MAAM,IAAI,MACR,qGACF;MACF;KACF;IACF;GACF,OAAO,IAAI,KAAK,cAAc,KAAK,WAAW,SAAS,GAAG;IACxD,KAAK,MAAM,aAAa,KAAK,YAAY;KACvC,IAAI,UAAU,SAAS,sBAAsB,UAAU,OAAO,SAAS,gBAAgB,UAAU,MAAM,SAAS,cAAc,UAAU,UAAU,SAAS,gBAAgB,UAAU,SAAS,SAAS,aAAa;MAClN,MAAM,IAAI,MACR,qGACF;KACF;IACF;GACF;EACF;CACF;CACA,IAAI,CAAC,eAAe;EAClB;CACF;CACA,MAAM,YAAY,mBAAmB,OAAO;CAC5C,IAAI,CAAC,WAAW;EACd;CACF;CACA,MAAM,IAAI,IAAI,YAAY,IAAI;CAC9B,IAAI,gBAAgB;EAClB,IAAI,YAAY,MAAM,cAAc;EACpC,IAAI,KAAK,eAAe,MAAM;EAC9B,IAAI,KAAK,eAAe,MAAM;EAC9B,EAAE,OAAO,QAAQ,cAAc,GAAG,SAAS;CAC7C;CACA,EAAE,UACA,QAAQ,aAAa,GACrB,MAAM,aAAa,GACnB,uBAAuB,SAAS,CAClC;CACA,OAAO;EACL,MAAM,EAAE,SAAS;EACjB,KAAK,EAAE,YAAY;GAAE,OAAO;GAAM,QAAQ;EAAQ,CAAC;CACrD;AACF"}
@@ -1,4 +1,4 @@
1
- async function transformHermesAsync(code, filename, sourceMaps = false, format) {
1
+ async function transformHermesAsync(code, filename, sourceMaps = false, format, keepNames = false) {
2
2
  if (!format && !code.includes("async")) return;
3
3
  const { transformSync } = await import("esbuild");
4
4
  const cleanId = filename.split("?")[0];
@@ -6,6 +6,7 @@ async function transformHermesAsync(code, filename, sourceMaps = false, format)
6
6
  loader: /\.[cm]?ts$/.test(cleanId) ? "ts" : cleanId.endsWith(".tsx") ? "tsx" : "jsx",
7
7
  jsx: "preserve",
8
8
  format,
9
+ keepNames,
9
10
  supported: {
10
11
  "async-await": false,
11
12
  "async-generator": false,
@@ -1 +1 @@
1
- {"version":3,"file":"transformHermesAsync.js","names":[],"sources":["esm/transformHermesAsync.js"],"sourcesContent":["async function transformHermesAsync(code, filename, sourceMaps = false, format) {\n if (!format && !code.includes(\"async\")) return;\n const { transformSync } = await import(\"esbuild\");\n const cleanId = filename.split(\"?\")[0];\n const result = transformSync(code, {\n loader: /\\.[cm]?ts$/.test(cleanId) ? \"ts\" : cleanId.endsWith(\".tsx\") ? \"tsx\" : \"jsx\",\n jsx: \"preserve\",\n format,\n supported: {\n \"async-await\": false,\n \"async-generator\": false,\n \"for-await\": false\n },\n sourcefile: filename,\n sourcemap: sourceMaps ? \"external\" : false\n });\n return {\n code: result.code,\n map: result.map ? JSON.parse(result.map) : void 0\n };\n}\nexport {\n transformHermesAsync\n};\n//# sourceMappingURL=transformHermesAsync.js.map\n"],"mappings":";AAAA,eAAe,qBAAqB,MAAM,UAAU,aAAa,OAAO,QAAQ;CAC9E,IAAI,CAAC,UAAU,CAAC,KAAK,SAAS,OAAO,GAAG;CACxC,MAAM,EAAE,kBAAkB,MAAM,OAAO;CACvC,MAAM,UAAU,SAAS,MAAM,GAAG,CAAC,CAAC;CACpC,MAAM,SAAS,cAAc,MAAM;EACjC,QAAQ,aAAa,KAAK,OAAO,IAAI,OAAO,QAAQ,SAAS,MAAM,IAAI,QAAQ;EAC/E,KAAK;EACL;EACA,WAAW;GACT,eAAe;GACf,mBAAmB;GACnB,aAAa;EACf;EACA,YAAY;EACZ,WAAW,aAAa,aAAa;CACvC,CAAC;CACD,OAAO;EACL,MAAM,OAAO;EACb,KAAK,OAAO,MAAM,KAAK,MAAM,OAAO,GAAG,IAAI,KAAK;CAClD;AACF"}
1
+ {"version":3,"file":"transformHermesAsync.js","names":[],"sources":["esm/transformHermesAsync.js"],"sourcesContent":["async function transformHermesAsync(code, filename, sourceMaps = false, format, keepNames = false) {\n if (!format && !code.includes(\"async\")) return;\n const { transformSync } = await import(\"esbuild\");\n const cleanId = filename.split(\"?\")[0];\n const result = transformSync(code, {\n loader: /\\.[cm]?ts$/.test(cleanId) ? \"ts\" : cleanId.endsWith(\".tsx\") ? \"tsx\" : \"jsx\",\n jsx: \"preserve\",\n format,\n keepNames,\n supported: {\n \"async-await\": false,\n \"async-generator\": false,\n \"for-await\": false\n },\n sourcefile: filename,\n sourcemap: sourceMaps ? \"external\" : false\n });\n return {\n code: result.code,\n map: result.map ? JSON.parse(result.map) : void 0\n };\n}\nexport {\n transformHermesAsync\n};\n//# sourceMappingURL=transformHermesAsync.js.map\n"],"mappings":";AAAA,eAAe,qBAAqB,MAAM,UAAU,aAAa,OAAO,QAAQ,YAAY,OAAO;CACjG,IAAI,CAAC,UAAU,CAAC,KAAK,SAAS,OAAO,GAAG;CACxC,MAAM,EAAE,kBAAkB,MAAM,OAAO;CACvC,MAAM,UAAU,SAAS,MAAM,GAAG,CAAC,CAAC;CACpC,MAAM,SAAS,cAAc,MAAM;EACjC,QAAQ,aAAa,KAAK,OAAO,IAAI,OAAO,QAAQ,SAAS,MAAM,IAAI,QAAQ;EAC/E,KAAK;EACL;EACA;EACA,WAAW;GACT,eAAe;GACf,mBAAmB;GACnB,aAAa;EACf;EACA,YAAY;EACZ,WAAW,aAAa,aAAa;CACvC,CAAC;CACD,OAAO;EACL,MAAM,OAAO;EACb,KAAK,OAAO,MAAM,KAAK,MAAM,OAAO,GAAG,IAAI,KAAK;CAClD;AACF"}
@@ -0,0 +1,272 @@
1
+ import { parseSync } from "oxc-parser";
2
+ import MagicString from "magic-string";
3
+ import remapping from "@jridgewell/remapping";
4
+
5
+ function analyze(program) {
6
+ const scopes = /* @__PURE__ */ new WeakMap();
7
+ const bindings = /* @__PURE__ */ new WeakSet();
8
+ const root = {
9
+ bindings: /* @__PURE__ */ new Set(),
10
+ function: true
11
+ };
12
+ function bind(pattern, scope) {
13
+ if (!pattern) return;
14
+ if (pattern.type === "Identifier") {
15
+ scope.bindings.add(pattern.name);
16
+ bindings.add(pattern);
17
+ } else if (pattern.type === "RestElement") bind(pattern.argument, scope);
18
+ else if (pattern.type === "AssignmentPattern") bind(pattern.left, scope);
19
+ else if (pattern.type === "ArrayPattern") {
20
+ for (const item of pattern.elements) bind(item, scope);
21
+ } else if (pattern.type === "ObjectPattern") {
22
+ for (const item of pattern.properties) bind(item.type === "RestElement" ? item.argument : item.value, scope);
23
+ }
24
+ }
25
+ function visit(node, parentScope) {
26
+ let scope = parentScope;
27
+ const fn = /^(?:FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/.test(node.type);
28
+ if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") bind(node.id, parentScope);
29
+ if (fn || /^(?:BlockStatement|CatchClause|ForStatement|ForInStatement|ForOfStatement|SwitchStatement|ClassExpression|ClassDeclaration|StaticBlock)$/.test(node.type)) {
30
+ scope = {
31
+ parent: parentScope,
32
+ bindings: /* @__PURE__ */ new Set(),
33
+ function: fn || node.type === "StaticBlock"
34
+ };
35
+ }
36
+ scopes.set(node, scope);
37
+ if (fn) {
38
+ if (node.type === "FunctionExpression") bind(node.id, scope);
39
+ for (const param of node.params) bind(param, scope);
40
+ }
41
+ if (node.type === "ClassExpression" || node.type === "ClassDeclaration") bind(node.id, scope);
42
+ if (node.type === "CatchClause") bind(node.param, scope);
43
+ if (node.type === "VariableDeclaration") {
44
+ let target = scope;
45
+ if (node.kind === "var") while (!target.function) target = target.parent;
46
+ for (const declaration of node.declarations) bind(declaration.id, target);
47
+ }
48
+ if (node.type === "ImportDeclaration") for (const specifier of node.specifiers) bind(specifier.local, scope);
49
+ children(node, (child) => visit(child, scope));
50
+ if ((node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") && node.id) scopes.set(node.id, parentScope);
51
+ }
52
+ visit(program, root);
53
+ function binding(node) {
54
+ let scope = scopes.get(node);
55
+ while (scope && !scope.bindings.has(node.name)) scope = scope.parent;
56
+ return scope;
57
+ }
58
+ return {
59
+ bindings,
60
+ binding,
61
+ rootBindings: root.bindings
62
+ };
63
+ }
64
+ function children(node, visit) {
65
+ for (const key of Object.keys(node)) {
66
+ if (key === "parent") continue;
67
+ const value = node[key];
68
+ if (Array.isArray(value)) {
69
+ for (const child of value) if (child?.type) visit(child, key);
70
+ } else if (value?.type) visit(value, key);
71
+ }
72
+ }
73
+ function isReference(node, parent, key, bindings) {
74
+ if (bindings.has(node)) return false;
75
+ if ((parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression") && key === "property" && !parent.computed) return false;
76
+ if (/^(?:Property|MethodDefinition|PropertyDefinition)$/.test(parent.type) && key === "key" && !parent.computed) return false;
77
+ if (/^(?:Import.*Specifier|ExportSpecifier|LabeledStatement|BreakStatement|ContinueStatement|MetaProperty)$/.test(parent.type)) return false;
78
+ return true;
79
+ }
80
+ function lowerLocalExports(program, code, analysis) {
81
+ const edited = new MagicString(code);
82
+ let exportAccess = "__mixedExports";
83
+ while (code.includes(exportAccess)) exportAccess += "_";
84
+ const exportBinding = analysis.rootBindings.has("exports") ? `const ${exportAccess} = module.exports;` : `const ${exportAccess} = () => exports;`;
85
+ const exportObject = analysis.rootBindings.has("exports") ? exportAccess : `${exportAccess}()`;
86
+ const exported = /* @__PURE__ */ new Map();
87
+ const imported = /* @__PURE__ */ new Set();
88
+ for (const node of program.body) if (node.type === "ImportDeclaration") for (const specifier of node.specifiers) imported.add(specifier.local.name);
89
+ const hoisted = [];
90
+ const defaultFunctions = [];
91
+ function names(pattern) {
92
+ if (!pattern) return [];
93
+ if (pattern.type === "Identifier") return [pattern];
94
+ if (pattern.type === "RestElement") return names(pattern.argument);
95
+ if (pattern.type === "AssignmentPattern") return names(pattern.left);
96
+ if (pattern.type === "ArrayPattern") return pattern.elements.flatMap(names);
97
+ if (pattern.type === "ObjectPattern") return pattern.properties.flatMap((item) => names(item.type === "RestElement" ? item.argument : item.value));
98
+ return [];
99
+ }
100
+ function add(id, name) {
101
+ const entry = exported.get(id.name) || {
102
+ scope: analysis.binding(id),
103
+ names: []
104
+ };
105
+ entry.names.push(name);
106
+ exported.set(id.name, entry);
107
+ }
108
+ const assignments = (id) => exported.get(id).names.map((name) => `${exportObject}[${JSON.stringify(name)}] = `).join("") + id;
109
+ for (const node of program.body) {
110
+ if (node.type === "ExportDefaultDeclaration") {
111
+ const declaration = node.declaration;
112
+ if (declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration" && declaration.id) {
113
+ edited.remove(node.start, declaration.start);
114
+ if (declaration.id) {
115
+ add(declaration.id, "default");
116
+ if (declaration.type === "FunctionDeclaration") hoisted.push(declaration.id.name);
117
+ else edited.appendLeft(node.end, `;${exportObject}.default = ${declaration.id.name};`);
118
+ } else {
119
+ let name = "__mixedDefault";
120
+ while (code.includes(name)) name += "_";
121
+ const prefix = code.slice(declaration.start, declaration.body.start).match(/^(?:async\s+)?function\s*\*?/)[0];
122
+ edited.prependRight(declaration.start + prefix.length, ` ${name}`);
123
+ defaultFunctions.push(`${exportObject}.default = ${name};`);
124
+ }
125
+ } else if (declaration.type !== "TSInterfaceDeclaration") {
126
+ edited.overwrite(node.start, declaration.start, `${exportObject}.default = (`);
127
+ edited.appendLeft(declaration.end, ")");
128
+ }
129
+ }
130
+ if (node.type === "ExportNamedDeclaration" && !node.source && node.exportKind !== "type") {
131
+ const declaration = node.declaration;
132
+ if (declaration) {
133
+ if (/^(?:TS|Interface|Type)/.test(declaration.type)) continue;
134
+ const ids = declaration.type === "VariableDeclaration" ? declaration.declarations.flatMap((item) => names(item.id)) : names(declaration.id);
135
+ for (const id of ids) add(id, id.name);
136
+ edited.remove(node.start, declaration.start);
137
+ if (declaration.type === "FunctionDeclaration") hoisted.push(...ids.map((id) => id.name));
138
+ } else {
139
+ const locals = node.specifiers.filter((item) => item.exportKind !== "type" && !imported.has(item.local.name));
140
+ for (const item of locals) add(item.local, item.exported.name ?? item.exported.value);
141
+ if (locals.length === node.specifiers.length) edited.remove(node.start, node.end);
142
+ else if (locals.length) {
143
+ const retained = node.specifiers.filter((other) => !locals.includes(other));
144
+ edited.overwrite(node.start, node.end, `export { ${retained.map((other) => code.slice(other.start, other.end)).join(", ")} };`);
145
+ }
146
+ }
147
+ }
148
+ }
149
+ for (const node of program.body) {
150
+ const declaration = node.type === "ExportNamedDeclaration" ? node.declaration : node;
151
+ if (!declaration) continue;
152
+ if (declaration.type === "VariableDeclaration") {
153
+ for (const item of declaration.declarations) for (const id of names(item.id)) {
154
+ if (exported.has(id.name)) {
155
+ if (item.id.type === "Identifier" && item.init) {
156
+ const prefix = exported.get(id.name).names.map((name) => `${exportObject}[${JSON.stringify(name)}] = `).join("");
157
+ edited.prependRight(item.init.start, prefix + "(");
158
+ edited.appendLeft(item.init.end, ")");
159
+ } else if (item.id.type !== "Identifier") edited.appendLeft(node.end, `;${assignments(id.name)};`);
160
+ }
161
+ }
162
+ } else if (declaration.type === "FunctionDeclaration" && exported.has(declaration.id?.name)) {
163
+ if (!hoisted.includes(declaration.id.name)) hoisted.push(declaration.id.name);
164
+ } else if (declaration.type === "ClassDeclaration" && exported.has(declaration.id?.name)) {
165
+ edited.appendLeft(node.end, `;${assignments(declaration.id.name)};`);
166
+ }
167
+ }
168
+ let temporary = "__mixedExportResult";
169
+ while (code.includes(temporary)) temporary += "_";
170
+ function mutations(node) {
171
+ if (node.type === "ForOfStatement" || node.type === "ForInStatement") {
172
+ const ids = (node.left.type === "VariableDeclaration" ? node.left.declarations.flatMap((item) => names(item.id)) : names(node.left)).filter((id) => exported.has(id.name) && analysis.binding(id) === exported.get(id.name).scope);
173
+ if (ids.length) {
174
+ const publish = ids.map((id) => assignments(id.name) + ";").join("");
175
+ if (node.body.type === "BlockStatement") edited.prependRight(node.body.start + 1, publish);
176
+ else {
177
+ edited.prependRight(node.body.start, "{" + publish);
178
+ edited.appendLeft(node.body.end, "}");
179
+ }
180
+ }
181
+ }
182
+ if (node.type === "AssignmentExpression" || node.type === "UpdateExpression") {
183
+ const ids = names(node.type === "AssignmentExpression" ? node.left : node.argument).filter((id) => exported.has(id.name) && analysis.binding(id) === exported.get(id.name).scope);
184
+ if (ids.length) {
185
+ edited.prependRight(node.start, `((${temporary}) => (${ids.map((id) => assignments(id.name)).join(", ")}, ${temporary}))(`);
186
+ edited.appendLeft(node.end, ")");
187
+ }
188
+ }
189
+ children(node, (child) => mutations(child));
190
+ }
191
+ mutations(program);
192
+ const first = program.body.find((node) => !(node.type === "ExpressionStatement" && node.directive));
193
+ const initialization = [...exported.values()].flatMap((entry) => entry.names).map((name) => `${exportObject}[${JSON.stringify(name)}] = void 0;`).join("");
194
+ edited.prependRight(first?.start ?? code.length, `export {};${exportBinding}${initialization}${hoisted.map((id) => assignments(id) + ";").join("")}${defaultFunctions.join("")}`);
195
+ return edited;
196
+ }
197
+ async function transformMixedNativeModule(code, filename, sourceMaps = false) {
198
+ if (!/\b(?:module|exports)\b/.test(code) || !/\b(?:import|export)\b/.test(code)) return;
199
+ const typescript = /\.[cm]?tsx?$/.test(filename);
200
+ const parsed = parseSync(filename, code, { lang: typescript ? filename.endsWith("tsx") ? "tsx" : "ts" : "jsx" });
201
+ if (parsed.errors.length) throw new Error(parsed.errors[0].message);
202
+ let program = parsed.program;
203
+ if (!program.body.some((node) => /^(?:Import|Export)/.test(node.type))) return;
204
+ let analysis = analyze(program);
205
+ let mixed = false;
206
+ function inspect(node, parent, key) {
207
+ if (node.type === "Identifier" && /^(?:module|exports)$/.test(node.name) && isReference(node, parent, key, analysis.bindings) && !analysis.binding(node)) mixed = true;
208
+ children(node, (child, key2) => inspect(child, node, key2));
209
+ }
210
+ inspect(program, program, "");
211
+ if (!mixed) return;
212
+ const { transform } = await import("@swc/core");
213
+ let typeMap;
214
+ if (typescript) {
215
+ const stripped = await transform(code, {
216
+ filename,
217
+ swcrc: false,
218
+ configFile: false,
219
+ sourceMaps,
220
+ jsc: {
221
+ target: "esnext",
222
+ parser: {
223
+ syntax: "typescript",
224
+ tsx: filename.endsWith(".tsx")
225
+ },
226
+ transform: { react: { runtime: "preserve" } }
227
+ },
228
+ module: { type: "es6" }
229
+ });
230
+ code = stripped.code;
231
+ typeMap = stripped.map ? JSON.parse(stripped.map) : void 0;
232
+ const javascript = parseSync(filename, code, { lang: "jsx" });
233
+ if (javascript.errors.length) throw new Error(javascript.errors[0].message);
234
+ program = javascript.program;
235
+ analysis = analyze(program);
236
+ }
237
+ const edited = lowerLocalExports(program, code, analysis);
238
+ const result = await transform(edited.toString(), {
239
+ filename,
240
+ swcrc: false,
241
+ configFile: false,
242
+ sourceMaps,
243
+ jsc: {
244
+ target: "esnext",
245
+ parser: {
246
+ syntax: "ecmascript",
247
+ jsx: true
248
+ },
249
+ transform: { react: { runtime: "preserve" } }
250
+ },
251
+ module: {
252
+ type: "commonjs",
253
+ strictMode: false,
254
+ allowTopLevelThis: true
255
+ }
256
+ });
257
+ return {
258
+ code: result.code,
259
+ map: result.map ? remapping([
260
+ JSON.parse(result.map),
261
+ edited.generateMap({
262
+ source: filename,
263
+ includeContent: true,
264
+ hires: true
265
+ }),
266
+ ...typeMap ? [typeMap] : []
267
+ ], () => null) : void 0
268
+ };
269
+ }
270
+
271
+ export { transformMixedNativeModule };
272
+ //# sourceMappingURL=transformMixedNativeModule.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformMixedNativeModule.js","names":[],"sources":["esm/transformMixedNativeModule.js"],"sourcesContent":["import { parseSync } from \"oxc-parser\";\nimport MagicString from \"magic-string\";\nimport remapping from \"@jridgewell/remapping\";\nfunction analyze(program) {\n const scopes = /* @__PURE__ */ new WeakMap();\n const bindings = /* @__PURE__ */ new WeakSet();\n const root = { bindings: /* @__PURE__ */ new Set(), function: true };\n function bind(pattern, scope) {\n if (!pattern) return;\n if (pattern.type === \"Identifier\") {\n scope.bindings.add(pattern.name);\n bindings.add(pattern);\n } else if (pattern.type === \"RestElement\") bind(pattern.argument, scope);\n else if (pattern.type === \"AssignmentPattern\") bind(pattern.left, scope);\n else if (pattern.type === \"ArrayPattern\") {\n for (const item of pattern.elements) bind(item, scope);\n } else if (pattern.type === \"ObjectPattern\") {\n for (const item of pattern.properties)\n bind(item.type === \"RestElement\" ? item.argument : item.value, scope);\n }\n }\n function visit(node, parentScope) {\n let scope = parentScope;\n const fn = /^(?:FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/.test(\n node.type\n );\n if (node.type === \"FunctionDeclaration\" || node.type === \"ClassDeclaration\")\n bind(node.id, parentScope);\n if (fn || /^(?:BlockStatement|CatchClause|ForStatement|ForInStatement|ForOfStatement|SwitchStatement|ClassExpression|ClassDeclaration|StaticBlock)$/.test(\n node.type\n )) {\n scope = {\n parent: parentScope,\n bindings: /* @__PURE__ */ new Set(),\n function: fn || node.type === \"StaticBlock\"\n };\n }\n scopes.set(node, scope);\n if (fn) {\n if (node.type === \"FunctionExpression\") bind(node.id, scope);\n for (const param of node.params) bind(param, scope);\n }\n if (node.type === \"ClassExpression\" || node.type === \"ClassDeclaration\")\n bind(node.id, scope);\n if (node.type === \"CatchClause\") bind(node.param, scope);\n if (node.type === \"VariableDeclaration\") {\n let target = scope;\n if (node.kind === \"var\") while (!target.function) target = target.parent;\n for (const declaration of node.declarations) bind(declaration.id, target);\n }\n if (node.type === \"ImportDeclaration\")\n for (const specifier of node.specifiers) bind(specifier.local, scope);\n children(node, (child) => visit(child, scope));\n if ((node.type === \"FunctionDeclaration\" || node.type === \"ClassDeclaration\") && node.id)\n scopes.set(node.id, parentScope);\n }\n visit(program, root);\n function binding(node) {\n let scope = scopes.get(node);\n while (scope && !scope.bindings.has(node.name)) scope = scope.parent;\n return scope;\n }\n return { bindings, binding, rootBindings: root.bindings };\n}\nfunction children(node, visit) {\n for (const key of Object.keys(node)) {\n if (key === \"parent\") continue;\n const value = node[key];\n if (Array.isArray(value)) {\n for (const child of value) if (child?.type) visit(child, key);\n } else if (value?.type) visit(value, key);\n }\n}\nfunction isReference(node, parent, key, bindings) {\n if (bindings.has(node)) return false;\n if ((parent.type === \"MemberExpression\" || parent.type === \"OptionalMemberExpression\") && key === \"property\" && !parent.computed)\n return false;\n if (/^(?:Property|MethodDefinition|PropertyDefinition)$/.test(parent.type) && key === \"key\" && !parent.computed)\n return false;\n if (/^(?:Import.*Specifier|ExportSpecifier|LabeledStatement|BreakStatement|ContinueStatement|MetaProperty)$/.test(\n parent.type\n ))\n return false;\n return true;\n}\nfunction lowerLocalExports(program, code, analysis) {\n const edited = new MagicString(code);\n let exportAccess = \"__mixedExports\";\n while (code.includes(exportAccess)) exportAccess += \"_\";\n const exportBinding = analysis.rootBindings.has(\"exports\") ? `const ${exportAccess} = module.exports;` : `const ${exportAccess} = () => exports;`;\n const exportObject = analysis.rootBindings.has(\"exports\") ? exportAccess : `${exportAccess}()`;\n const exported = /* @__PURE__ */ new Map();\n const imported = /* @__PURE__ */ new Set();\n for (const node of program.body)\n if (node.type === \"ImportDeclaration\")\n for (const specifier of node.specifiers) imported.add(specifier.local.name);\n const hoisted = [];\n const defaultFunctions = [];\n function names(pattern) {\n if (!pattern) return [];\n if (pattern.type === \"Identifier\") return [pattern];\n if (pattern.type === \"RestElement\") return names(pattern.argument);\n if (pattern.type === \"AssignmentPattern\") return names(pattern.left);\n if (pattern.type === \"ArrayPattern\") return pattern.elements.flatMap(names);\n if (pattern.type === \"ObjectPattern\")\n return pattern.properties.flatMap(\n (item) => names(item.type === \"RestElement\" ? item.argument : item.value)\n );\n return [];\n }\n function add(id, name) {\n const entry = exported.get(id.name) || {\n scope: analysis.binding(id),\n names: []\n };\n entry.names.push(name);\n exported.set(id.name, entry);\n }\n const assignments = (id) => exported.get(id).names.map((name) => `${exportObject}[${JSON.stringify(name)}] = `).join(\"\") + id;\n for (const node of program.body) {\n if (node.type === \"ExportDefaultDeclaration\") {\n const declaration = node.declaration;\n if (declaration.type === \"FunctionDeclaration\" || declaration.type === \"ClassDeclaration\" && declaration.id) {\n edited.remove(node.start, declaration.start);\n if (declaration.id) {\n add(declaration.id, \"default\");\n if (declaration.type === \"FunctionDeclaration\")\n hoisted.push(declaration.id.name);\n else\n edited.appendLeft(\n node.end,\n `;${exportObject}.default = ${declaration.id.name};`\n );\n } else {\n let name = \"__mixedDefault\";\n while (code.includes(name)) name += \"_\";\n const prefix = code.slice(declaration.start, declaration.body.start).match(/^(?:async\\s+)?function\\s*\\*?/)[0];\n edited.prependRight(declaration.start + prefix.length, ` ${name}`);\n defaultFunctions.push(`${exportObject}.default = ${name};`);\n }\n } else if (declaration.type !== \"TSInterfaceDeclaration\") {\n edited.overwrite(node.start, declaration.start, `${exportObject}.default = (`);\n edited.appendLeft(declaration.end, \")\");\n }\n }\n if (node.type === \"ExportNamedDeclaration\" && !node.source && node.exportKind !== \"type\") {\n const declaration = node.declaration;\n if (declaration) {\n if (/^(?:TS|Interface|Type)/.test(declaration.type)) continue;\n const ids = declaration.type === \"VariableDeclaration\" ? declaration.declarations.flatMap((item) => names(item.id)) : names(declaration.id);\n for (const id of ids) add(id, id.name);\n edited.remove(node.start, declaration.start);\n if (declaration.type === \"FunctionDeclaration\")\n hoisted.push(...ids.map((id) => id.name));\n } else {\n const locals = node.specifiers.filter(\n (item) => item.exportKind !== \"type\" && !imported.has(item.local.name)\n );\n for (const item of locals)\n add(item.local, item.exported.name ?? item.exported.value);\n if (locals.length === node.specifiers.length) edited.remove(node.start, node.end);\n else if (locals.length) {\n const retained = node.specifiers.filter(\n (other) => !locals.includes(other)\n );\n edited.overwrite(\n node.start,\n node.end,\n `export { ${retained.map((other) => code.slice(other.start, other.end)).join(\", \")} };`\n );\n }\n }\n }\n }\n for (const node of program.body) {\n const declaration = node.type === \"ExportNamedDeclaration\" ? node.declaration : node;\n if (!declaration) continue;\n if (declaration.type === \"VariableDeclaration\") {\n for (const item of declaration.declarations)\n for (const id of names(item.id)) {\n if (exported.has(id.name)) {\n if (item.id.type === \"Identifier\" && item.init) {\n const prefix = exported.get(id.name).names.map((name) => `${exportObject}[${JSON.stringify(name)}] = `).join(\"\");\n edited.prependRight(item.init.start, prefix + \"(\");\n edited.appendLeft(item.init.end, \")\");\n } else if (item.id.type !== \"Identifier\")\n edited.appendLeft(node.end, `;${assignments(id.name)};`);\n }\n }\n } else if (declaration.type === \"FunctionDeclaration\" && exported.has(declaration.id?.name)) {\n if (!hoisted.includes(declaration.id.name)) hoisted.push(declaration.id.name);\n } else if (declaration.type === \"ClassDeclaration\" && exported.has(declaration.id?.name)) {\n edited.appendLeft(node.end, `;${assignments(declaration.id.name)};`);\n }\n }\n let temporary = \"__mixedExportResult\";\n while (code.includes(temporary)) temporary += \"_\";\n function mutations(node) {\n if (node.type === \"ForOfStatement\" || node.type === \"ForInStatement\") {\n const ids = (node.left.type === \"VariableDeclaration\" ? node.left.declarations.flatMap((item) => names(item.id)) : names(node.left)).filter(\n (id) => exported.has(id.name) && analysis.binding(id) === exported.get(id.name).scope\n );\n if (ids.length) {\n const publish = ids.map((id) => assignments(id.name) + \";\").join(\"\");\n if (node.body.type === \"BlockStatement\")\n edited.prependRight(node.body.start + 1, publish);\n else {\n edited.prependRight(node.body.start, \"{\" + publish);\n edited.appendLeft(node.body.end, \"}\");\n }\n }\n }\n if (node.type === \"AssignmentExpression\" || node.type === \"UpdateExpression\") {\n const ids = names(\n node.type === \"AssignmentExpression\" ? node.left : node.argument\n ).filter(\n (id) => exported.has(id.name) && analysis.binding(id) === exported.get(id.name).scope\n );\n if (ids.length) {\n edited.prependRight(\n node.start,\n `((${temporary}) => (${ids.map((id) => assignments(id.name)).join(\", \")}, ${temporary}))(`\n );\n edited.appendLeft(node.end, \")\");\n }\n }\n children(node, (child) => mutations(child));\n }\n mutations(program);\n const first = program.body.find(\n (node) => !(node.type === \"ExpressionStatement\" && node.directive)\n );\n const initialization = [...exported.values()].flatMap((entry) => entry.names).map((name) => `${exportObject}[${JSON.stringify(name)}] = void 0;`).join(\"\");\n edited.prependRight(\n first?.start ?? code.length,\n `export {};${exportBinding}${initialization}${hoisted.map((id) => assignments(id) + \";\").join(\"\")}${defaultFunctions.join(\"\")}`\n );\n return edited;\n}\nasync function transformMixedNativeModule(code, filename, sourceMaps = false) {\n if (!/\\b(?:module|exports)\\b/.test(code) || !/\\b(?:import|export)\\b/.test(code)) return;\n const typescript = /\\.[cm]?tsx?$/.test(filename);\n const parsed = parseSync(filename, code, {\n lang: typescript ? filename.endsWith(\"tsx\") ? \"tsx\" : \"ts\" : \"jsx\"\n });\n if (parsed.errors.length) throw new Error(parsed.errors[0].message);\n let program = parsed.program;\n if (!program.body.some((node) => /^(?:Import|Export)/.test(node.type))) return;\n let analysis = analyze(program);\n let mixed = false;\n function inspect(node, parent, key) {\n if (node.type === \"Identifier\" && /^(?:module|exports)$/.test(node.name) && isReference(node, parent, key, analysis.bindings) && !analysis.binding(node))\n mixed = true;\n children(node, (child, key2) => inspect(child, node, key2));\n }\n inspect(program, program, \"\");\n if (!mixed) return;\n const { transform } = await import(\"@swc/core\");\n let typeMap;\n if (typescript) {\n const stripped = await transform(code, {\n filename,\n swcrc: false,\n configFile: false,\n sourceMaps,\n jsc: {\n target: \"esnext\",\n parser: { syntax: \"typescript\", tsx: filename.endsWith(\".tsx\") },\n transform: { react: { runtime: \"preserve\" } }\n },\n module: { type: \"es6\" }\n });\n code = stripped.code;\n typeMap = stripped.map ? JSON.parse(stripped.map) : void 0;\n const javascript = parseSync(filename, code, { lang: \"jsx\" });\n if (javascript.errors.length) throw new Error(javascript.errors[0].message);\n program = javascript.program;\n analysis = analyze(program);\n }\n const edited = lowerLocalExports(program, code, analysis);\n const result = await transform(edited.toString(), {\n filename,\n swcrc: false,\n configFile: false,\n sourceMaps,\n jsc: {\n target: \"esnext\",\n parser: { syntax: \"ecmascript\", jsx: true },\n transform: { react: { runtime: \"preserve\" } }\n },\n module: { type: \"commonjs\", strictMode: false, allowTopLevelThis: true }\n });\n return {\n code: result.code,\n map: result.map ? remapping(\n [\n JSON.parse(result.map),\n edited.generateMap({\n source: filename,\n includeContent: true,\n hires: true\n }),\n ...typeMap ? [typeMap] : []\n ],\n () => null\n ) : void 0\n };\n}\nexport {\n transformMixedNativeModule\n};\n//# sourceMappingURL=transformMixedNativeModule.js.map\n"],"mappings":";;;;;AAGA,SAAS,QAAQ,SAAS;CACxB,MAAM,yBAAyB,IAAI,QAAQ;CAC3C,MAAM,2BAA2B,IAAI,QAAQ;CAC7C,MAAM,OAAO;EAAE,0BAA0B,IAAI,IAAI;EAAG,UAAU;CAAK;CACnE,SAAS,KAAK,SAAS,OAAO;EAC5B,IAAI,CAAC,SAAS;EACd,IAAI,QAAQ,SAAS,cAAc;GACjC,MAAM,SAAS,IAAI,QAAQ,IAAI;GAC/B,SAAS,IAAI,OAAO;EACtB,OAAO,IAAI,QAAQ,SAAS,eAAe,KAAK,QAAQ,UAAU,KAAK;OAClE,IAAI,QAAQ,SAAS,qBAAqB,KAAK,QAAQ,MAAM,KAAK;OAClE,IAAI,QAAQ,SAAS,gBAAgB;GACxC,KAAK,MAAM,QAAQ,QAAQ,UAAU,KAAK,MAAM,KAAK;EACvD,OAAO,IAAI,QAAQ,SAAS,iBAAiB;GAC3C,KAAK,MAAM,QAAQ,QAAQ,YACzB,KAAK,KAAK,SAAS,gBAAgB,KAAK,WAAW,KAAK,OAAO,KAAK;EACxE;CACF;CACA,SAAS,MAAM,MAAM,aAAa;EAChC,IAAI,QAAQ;EACZ,MAAM,KAAK,uEAAuE,KAChF,KAAK,IACP;EACA,IAAI,KAAK,SAAS,yBAAyB,KAAK,SAAS,oBACvD,KAAK,KAAK,IAAI,WAAW;EAC3B,IAAI,MAAM,2IAA2I,KACnJ,KAAK,IACP,GAAG;GACD,QAAQ;IACN,QAAQ;IACR,0BAA0B,IAAI,IAAI;IAClC,UAAU,MAAM,KAAK,SAAS;GAChC;EACF;EACA,OAAO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,MAAM,IAAI,MAAM,WAAW,OAAO,EAAE,CAAC,OAAO;EAC1E,UAAU,WAAW;EACrB,WAAW,QAAQ,OAAO;CAC5B;CACA,MAAM,SAAS,kBAAkB,SAAS,MAAM,QAAQ;CACxD,MAAM,SAAS,MAAM,UAAU,OAAO,SAAS,GAAG;EAChD;EACA,OAAO;EACP,YAAY;EACZ;EACA,KAAK;GACH,QAAQ;GACR,QAAQ;IAAE,QAAQ;IAAc,KAAK;GAAK;GAC1C,WAAW,EAAE,OAAO,EAAE,SAAS,WAAW,EAAE;EAC9C;EACA,QAAQ;GAAE,MAAM;GAAY,YAAY;GAAO,mBAAmB;EAAK;CACzE,CAAC;CACD,OAAO;EACL,MAAM,OAAO;EACb,KAAK,OAAO,MAAM,UAChB;GACE,KAAK,MAAM,OAAO,GAAG;GACrB,OAAO,YAAY;IACjB,QAAQ;IACR,gBAAgB;IAChB,OAAO;GACT,CAAC;GACD,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC;EAC5B,SACM,IACR,IAAI,KAAK;CACX;AACF"}
@@ -3,6 +3,10 @@ import { createRequire } from "node:module";
3
3
  import path from "node:path";
4
4
  import { configuration, isNativeWorkletsEnabled } from "./configure.mjs";
5
5
  import { AUTOWORKLET_FUNCTION_ARGS, GESTURE_BUILDER_METHODS } from "./worklets/autoworklet.mjs";
6
+ import remapping from "@jridgewell/remapping";
7
+ import { isReactNativeCodegenSpec } from "./reactNativeCodegen.mjs";
8
+ import { stripFlowTypes } from "./transformFlow.mjs";
9
+ import { shouldStripFlow } from "./transformSWC.mjs";
6
10
  import { executeWorkletTransform, prepareWorkletsForReactCompiler } from "./worklets/transform.mjs";
7
11
 
8
12
  const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
@@ -95,6 +99,16 @@ function getWorkletsVersion(projectRoot, filename) {
95
99
  throw new Error(`[@vxrn/compiler] Unable to resolve "react-native-worklets" or "react-native-reanimated" version from "${target}". Please ensure react-native-worklets is installed in your project.`);
96
100
  }
97
101
  async function transformWorklets(id, code, sourceMaps = false, options) {
102
+ if (shouldStripFlow(id, code)) {
103
+ if (isReactNativeCodegenSpec(id, code)) return { code };
104
+ const stripped = await stripFlowTypes(id, code, sourceMaps);
105
+ const result = executeWorkletTransform(id, stripped.code, sourceMaps, options, getWorkletsVersion);
106
+ if (!sourceMaps || !stripped.map) return result;
107
+ return {
108
+ code: result.code,
109
+ map: result.map ? remapping([result.map, stripped.map], () => null) : stripped.map
110
+ };
111
+ }
98
112
  return executeWorkletTransform(id, code, sourceMaps, options, getWorkletsVersion);
99
113
  }
100
114