@vxrn/compiler 1.27.1 → 2.0.0-beta.45.1
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.
- package/dist/cjs/cache.cjs +106 -117
- package/dist/cjs/configure.cjs +26 -28
- package/dist/cjs/constants.cjs +56 -60
- package/dist/cjs/index.cjs +420 -443
- package/dist/cjs/reactNativeCodegen.cjs +105 -114
- package/dist/cjs/reactNativeViewConfig.cjs +362 -381
- package/dist/cjs/refresh-runtime.cjs +390 -397
- package/dist/cjs/transformBabel.cjs +273 -263
- package/dist/cjs/transformHermesAsync.cjs +36 -47
- package/dist/cjs/transformHermesLoops.cjs +279 -281
- package/dist/cjs/transformSWC.cjs +183 -200
- package/dist/cjs/transformWorklets.cjs +107 -95
- package/dist/cjs/types.cjs +9 -11
- package/dist/cjs/worklets/autoworklet.cjs +277 -222
- package/dist/cjs/worklets/globals.cjs +124 -60
- package/dist/cjs/worklets/hash.cjs +23 -27
- package/dist/cjs/worklets/scope.cjs +338 -359
- package/dist/cjs/worklets/serialize.cjs +73 -75
- package/dist/cjs/worklets/transform.cjs +217 -222
- package/dist/cjs/worklets/types.cjs +9 -11
- package/dist/esm/cache.mjs +90 -97
- package/dist/esm/cache.mjs.map +1 -1
- package/dist/esm/configure.mjs +11 -10
- package/dist/esm/configure.mjs.map +1 -1
- package/dist/esm/constants.mjs +41 -41
- package/dist/esm/constants.mjs.map +1 -1
- package/dist/esm/index.js +417 -425
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +417 -425
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/reactNativeCodegen.mjs +90 -88
- package/dist/esm/reactNativeCodegen.mjs.map +1 -1
- package/dist/esm/reactNativeViewConfig.mjs +347 -362
- package/dist/esm/reactNativeViewConfig.mjs.map +1 -1
- package/dist/esm/refresh-runtime.mjs +372 -376
- package/dist/esm/refresh-runtime.mjs.map +1 -1
- package/dist/esm/transformBabel.mjs +255 -237
- package/dist/esm/transformBabel.mjs.map +1 -1
- package/dist/esm/transformHermesAsync.mjs +20 -21
- package/dist/esm/transformHermesAsync.mjs.map +1 -1
- package/dist/esm/transformHermesLoops.mjs +264 -255
- package/dist/esm/transformHermesLoops.mjs.map +1 -1
- package/dist/esm/transformSWC.mjs +163 -171
- package/dist/esm/transformSWC.mjs.map +1 -1
- package/dist/esm/transformWorklets.mjs +89 -69
- package/dist/esm/transformWorklets.mjs.map +1 -1
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/worklets/autoworklet.mjs +258 -200
- package/dist/esm/worklets/autoworklet.mjs.map +1 -1
- package/dist/esm/worklets/globals.mjs +109 -42
- package/dist/esm/worklets/globals.mjs.map +1 -1
- package/dist/esm/worklets/hash.mjs +10 -9
- package/dist/esm/worklets/hash.mjs.map +1 -1
- package/dist/esm/worklets/scope.mjs +325 -341
- package/dist/esm/worklets/scope.mjs.map +1 -1
- package/dist/esm/worklets/serialize.mjs +60 -58
- package/dist/esm/worklets/serialize.mjs.map +1 -1
- package/dist/esm/worklets/transform.mjs +201 -197
- package/dist/esm/worklets/transform.mjs.map +1 -1
- package/dist/esm/worklets/types.mjs +0 -2
- package/package.json +7 -6
- package/src/transformBabel.test.ts +77 -17
- package/src/transformBabel.ts +28 -12
- package/types/transformBabel.d.ts +12 -0
- package/types/transformBabel.d.ts.map +1 -1
- package/types/transformSWC.d.ts +1 -4
- package/types/transformSWC.d.ts.map +1 -1
- package/dist/cjs/transformBabel.test.cjs +0 -652
- package/dist/cjs/transformHermesLoops.test.cjs +0 -257
- package/dist/cjs/transformSWC.test.cjs +0 -117
- package/dist/cjs/transformWorklets.test.cjs +0 -604
- package/dist/esm/transformBabel.test.mjs +0 -629
- package/dist/esm/transformBabel.test.mjs.map +0 -1
- package/dist/esm/transformHermesLoops.test.mjs +0 -234
- package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
- package/dist/esm/transformSWC.test.mjs +0 -118
- package/dist/esm/transformSWC.test.mjs.map +0 -1
- package/dist/esm/transformWorklets.test.mjs +0 -581
- package/dist/esm/transformWorklets.test.mjs.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
- package/dist/esm/worklets/types.mjs.map +0 -1
- package/types/transformBabel.test.d.ts +0 -2
- package/types/transformBabel.test.d.ts.map +0 -1
- package/types/transformHermesLoops.test.d.ts +0 -2
- package/types/transformHermesLoops.test.d.ts.map +0 -1
- package/types/transformSWC.test.d.ts +0 -2
- package/types/transformSWC.test.d.ts.map +0 -1
- package/types/transformWorklets.test.d.ts +0 -2
- package/types/transformWorklets.test.d.ts.map +0 -1
|
@@ -2,129 +2,126 @@ import { extname } from "node:path";
|
|
|
2
2
|
import { normalizePath } from "vite";
|
|
3
3
|
import { configuration } from "./configure.mjs";
|
|
4
4
|
import { asyncGeneratorRegex, debug, runtimePublicPath } from "./constants.mjs";
|
|
5
|
+
|
|
5
6
|
const ignoreId = /node_modules\/(\.vite|vite)\//;
|
|
6
7
|
function shouldStripFlow(id, code) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const filename = id.split("?")[0];
|
|
9
|
+
if (!/\.jsx?$/.test(filename)) return false;
|
|
10
|
+
if (/node_modules[\\/](?:react-native|@react-native)[\\/].*\.js$/.test(filename)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
const header = code.match(/^(?:#![^\r\n]*(?:\r?\n|$))?(?:\s|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*)*/)?.[0] || "";
|
|
14
|
+
return /@flow\b/.test(header) || /\b(?:import|export)\s+type\b/.test(code);
|
|
14
15
|
}
|
|
15
16
|
async function transformSWC(id, code, options, swcOptions) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
debug?.(`transformSWC (oxc) ${id} using options:
|
|
17
|
+
id = normalizePath(id.split("?")[0]).replace(normalizePath(process.cwd()), "");
|
|
18
|
+
if (ignoreId.test(id)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (id === runtimePublicPath) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const lang = getLang(id, options.forceJSX);
|
|
25
|
+
if (!lang) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const refresh = options.environment !== "ssr" && !options.production && !options.noHMR && !options.forceJSX && !id.includes("node_modules");
|
|
29
|
+
const importSource = configuration.enableNativewind && !id.includes("node_modules") ? "nativewind" : "react";
|
|
30
|
+
const shouldEs5Transform = options.es5 || !process.env.VXRN_USE_BABEL_FOR_GENERATORS && asyncGeneratorRegex.test(code);
|
|
31
|
+
const target = shouldEs5Transform ? "es2015" : "es2020";
|
|
32
|
+
const sourceMaps = swcOptions?.sourceMaps !== void 0 ? Boolean(swcOptions.sourceMaps) : shouldSourceMap();
|
|
33
|
+
const oxcOptions = {
|
|
34
|
+
lang,
|
|
35
|
+
target,
|
|
36
|
+
assumptions: {
|
|
37
|
+
setPublicClassFields: true,
|
|
38
|
+
...swcOptions?.assumptions || {}
|
|
39
|
+
},
|
|
40
|
+
sourcemap: sourceMaps,
|
|
41
|
+
jsx: {
|
|
42
|
+
runtime: "automatic",
|
|
43
|
+
development: !options.forceJSX && !options.production,
|
|
44
|
+
refresh: Boolean(refresh),
|
|
45
|
+
importSource
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const { transformSync } = await import("oxc-transform");
|
|
49
|
+
const result = (() => {
|
|
50
|
+
try {
|
|
51
|
+
debug?.(`transformSWC (oxc) ${id} using options:
|
|
53
52
|
${JSON.stringify(oxcOptions, null, 2)}`);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
const res = transformSync(id, code, oxcOptions);
|
|
54
|
+
if (res.errors?.length) {
|
|
55
|
+
const err = res.errors[0];
|
|
56
|
+
const error = new Error(err.message + (err.codeframe ? `
|
|
58
57
|
${err.codeframe}` : ""));
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
58
|
+
if (err.labels?.[0]) {
|
|
59
|
+
error.start = err.labels[0].start;
|
|
60
|
+
error.end = err.labels[0].end;
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
code: res.code,
|
|
66
|
+
map: res.map
|
|
67
|
+
};
|
|
68
|
+
} catch (e) {
|
|
69
|
+
throw e;
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
if (configuration.enableNativeCSS) {
|
|
73
|
+
if (result.code.includes(`createInteropElement(`)) {
|
|
74
|
+
result.code = `import { createInteropElement, Fragment as _InteropFragment } from 'react-native-css-interop/jsx-dev-runtime'
|
|
76
75
|
${result.code}`;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const hasRefreshRuntime = refresh && refreshContentRE.test(result.code);
|
|
79
|
+
if (options.fixNonTypeSpecificImports || id.includes("node_modules") && (lang === "ts" || lang === "tsx")) {
|
|
80
|
+
const typeExportsMatch = code.match(/^\s*export\s+type\s+([^\s]+)/gi);
|
|
81
|
+
if (typeExportsMatch) {
|
|
82
|
+
for (const typeExport of Array.from(typeExportsMatch)) {
|
|
83
|
+
const [_export, _type, name] = typeExport.split(/\s+/);
|
|
84
|
+
if (name.startsWith("{")) continue;
|
|
85
|
+
if (name.includes("<")) continue;
|
|
86
|
+
const alreadyExported = new RegExp(`export (const|let|class|function) ${name}\\s+`).test(result.code);
|
|
87
|
+
if (!alreadyExported) {
|
|
88
|
+
const fakeExport = `export let ${name} = {};`;
|
|
89
|
+
console.info(` \u26A0\uFE0F Fixing non-type-specific import in node_module, this should be fixed upstream: ${fakeExport} in ${id}`);
|
|
90
|
+
result.code += `
|
|
92
91
|
${fakeExport}
|
|
93
92
|
`;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (result && !options.production && !options.noHMR) {
|
|
98
|
+
return wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
102
101
|
}
|
|
103
102
|
const transformOxc = transformSWC;
|
|
104
103
|
function wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
104
|
+
if (options.environment === "ssr") {
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
if (options.environment === "client") {
|
|
108
|
+
return wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime);
|
|
109
|
+
}
|
|
110
|
+
return wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime);
|
|
112
111
|
}
|
|
113
112
|
function wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
result.code = `import * as RefreshRuntime from "${runtimePublicPath}";
|
|
113
|
+
const sourceMap = result.map ? typeof result.map === "string" ? JSON.parse(result.map) : { ...result.map } : void 0;
|
|
114
|
+
if (sourceMap) {
|
|
115
|
+
sourceMap.mappings = ";;" + sourceMap.mappings;
|
|
116
|
+
}
|
|
117
|
+
result.code = `import * as RefreshRuntime from "${runtimePublicPath}";
|
|
121
118
|
|
|
122
119
|
${result.code}`;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
if (hasRefreshRuntime) {
|
|
121
|
+
if (sourceMap) {
|
|
122
|
+
sourceMap.mappings = ";;;;;;" + sourceMap.mappings;
|
|
123
|
+
}
|
|
124
|
+
result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
128
125
|
const prevRefreshReg = window.$RefreshReg$;
|
|
129
126
|
const prevRefreshSig = window.$RefreshSig$;
|
|
130
127
|
window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
|
|
@@ -135,8 +132,8 @@ ${result.code}
|
|
|
135
132
|
window.$RefreshReg$ = prevRefreshReg;
|
|
136
133
|
window.$RefreshSig$ = prevRefreshSig;
|
|
137
134
|
`;
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
}
|
|
136
|
+
result.code += `
|
|
140
137
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
141
138
|
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
142
139
|
import.meta.hot.accept((nextExports) => {
|
|
@@ -146,21 +143,21 @@ RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
|
146
143
|
});
|
|
147
144
|
});
|
|
148
145
|
`;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
146
|
+
return {
|
|
147
|
+
code: result.code,
|
|
148
|
+
map: sourceMap
|
|
149
|
+
};
|
|
153
150
|
}
|
|
154
151
|
function wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime) {
|
|
155
|
-
|
|
152
|
+
const postfixCode = `if (module.hot) {
|
|
156
153
|
if (module.hot.accept) {
|
|
157
154
|
module.hot.accept((nextExports) => {
|
|
158
155
|
RefreshRuntime.performReactRefresh()
|
|
159
156
|
});
|
|
160
157
|
}
|
|
161
158
|
}`;
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
if (hasRefreshRuntime) {
|
|
160
|
+
const prefixCode = `const RefreshRuntime = __cachedModules["react-refresh/cjs/react-refresh-runtime.development"];
|
|
164
161
|
const prevRefreshReg = globalThis.$RefreshReg$;
|
|
165
162
|
const prevRefreshSig = globalThis.$RefreshSig$ || (() => {
|
|
166
163
|
console.info("no react refresh setup!")
|
|
@@ -170,15 +167,13 @@ globalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, "${id}" +
|
|
|
170
167
|
globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
171
168
|
module.url = '${id}'
|
|
172
169
|
module.hot = createHotContext(module.url)`;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
code: `${prefixCode}
|
|
170
|
+
const sourceMap = result.map ? typeof result.map === "string" ? JSON.parse(result.map) : { ...result.map } : void 0;
|
|
171
|
+
if (sourceMap) {
|
|
172
|
+
const prefixLen = prefixCode.split("\n").length + 1;
|
|
173
|
+
sourceMap.mappings = new Array(prefixLen).fill(";").join("") + sourceMap.mappings;
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
code: `${prefixCode}
|
|
182
177
|
${result.code}
|
|
183
178
|
|
|
184
179
|
if (module.hot) {
|
|
@@ -189,61 +184,58 @@ if (module.hot) {
|
|
|
189
184
|
|
|
190
185
|
${postfixCode}
|
|
191
186
|
`,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
187
|
+
map: sourceMap
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
result.code += postfixCode;
|
|
191
|
+
return result;
|
|
197
192
|
}
|
|
198
193
|
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
199
194
|
function shouldSourceMap() {
|
|
200
|
-
|
|
195
|
+
return process.env.VXRN_ENABLE_SOURCE_MAP === "1";
|
|
201
196
|
}
|
|
202
197
|
function getLang(id, forceJSX = false) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
198
|
+
if (id.endsWith("one-entry-native")) {
|
|
199
|
+
return "tsx";
|
|
200
|
+
}
|
|
201
|
+
const extension = extname(id);
|
|
202
|
+
if (extension === ".tsx") return "tsx";
|
|
203
|
+
if (extension === ".ts") return "ts";
|
|
204
|
+
if (extension === ".jsx" || extension === ".mdx") return "jsx";
|
|
205
|
+
if (extension === ".js" || extension === ".mjs" || extension === ".cjs") {
|
|
206
|
+
return "jsx";
|
|
207
|
+
}
|
|
208
|
+
if (!extension) {
|
|
209
|
+
return forceJSX ? "jsx" : "js";
|
|
210
|
+
}
|
|
211
|
+
return void 0;
|
|
217
212
|
}
|
|
218
213
|
const transformSWCStripJSX = async (id, code) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
});
|
|
237
|
-
if (res.errors?.length) {
|
|
238
|
-
const err = res.errors[0];
|
|
239
|
-
throw new Error(err.message + (err.codeframe ? `
|
|
214
|
+
const lang = getLang(id);
|
|
215
|
+
if (!lang) return;
|
|
216
|
+
const { transformSync } = await import("oxc-transform");
|
|
217
|
+
const res = transformSync(id, code, {
|
|
218
|
+
lang,
|
|
219
|
+
target: "es2020",
|
|
220
|
+
assumptions: { setPublicClassFields: true },
|
|
221
|
+
sourcemap: shouldSourceMap(),
|
|
222
|
+
jsx: {
|
|
223
|
+
runtime: "automatic",
|
|
224
|
+
development: true,
|
|
225
|
+
refresh: false
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
if (res.errors?.length) {
|
|
229
|
+
const err = res.errors[0];
|
|
230
|
+
throw new Error(err.message + (err.codeframe ? `
|
|
240
231
|
${err.codeframe}` : ""));
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
code: res.code,
|
|
235
|
+
map: res.map
|
|
236
|
+
};
|
|
246
237
|
};
|
|
247
238
|
const transformOxcStripJSX = transformSWCStripJSX;
|
|
239
|
+
|
|
248
240
|
export { shouldSourceMap, shouldStripFlow, transformOxc, transformOxcStripJSX, transformSWC, transformSWCStripJSX };
|
|
249
241
|
//# sourceMappingURL=transformSWC.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["extname","normalizePath","configuration","asyncGeneratorRegex","debug","runtimePublicPath","ignoreId","shouldStripFlow","id","code","filename","split","test","header","match","transformSWC","options","swcOptions","replace","process","cwd","lang","getLang","forceJSX","refresh","environment","production","noHMR","includes","importSource","enableNativewind","shouldEs5Transform","es5","env","VXRN_USE_BABEL_FOR_GENERATORS","target","sourceMaps","Boolean","shouldSourceMap","oxcOptions","assumptions","setPublicClassFields","sourcemap","jsx","runtime","development","transformSync","result","JSON","stringify","res","errors","length","err","error","Error","message","codeframe","labels","start","end","map","e","enableNativeCSS","hasRefreshRuntime","refreshContentRE","fixNonTypeSpecificImports","typeExportsMatch","typeExport","Array","from","_export","_type","name","startsWith","alreadyExported","RegExp","fakeExport","console","info","wrapSourceInRefreshRuntime","transformOxc","wrapSourceInRefreshRuntimeWeb","wrapSourceInRefreshRuntimeNative","sourceMap","parse","mappings","postfixCode","prefixCode","prefixLen","fill","join","VXRN_ENABLE_SOURCE_MAP","endsWith","extension","transformSWCStripJSX","transformOxcStripJSX"],"sources":["../../src/transformSWC.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,OAAA,QAAe;AACxB,SAASC,aAAA,QAAqB;AAC9B,SAASC,aAAA,QAAqB;AAC9B,SAASC,mBAAA,EAAqBC,KAAA,EAAOC,iBAAA,QAAyB;AAS9D,MAAMC,QAAA,GAAW;AAEV,SAASC,gBAAgBC,EAAA,EAAYC,IAAA,EAAuB;EACjE,MAAMC,QAAA,GAAWF,EAAA,CAAGG,KAAA,CAAM,GAAG,EAAE,CAAC;EAChC,IAAI,CAAC,UAAUC,IAAA,CAAKF,QAAQ,GAAG,OAAO;EACtC,IAAI,8DAA8DE,IAAA,CAAKF,QAAQ,GAAG;IAChF,OAAO;EACT;EAEA,MAAMG,MAAA,GACJJ,IAAA,CAAKK,KAAA,CAAM,kEAAkE,IAAI,CAAC,KAClF;EACF,OAAO,UAAUF,IAAA,CAAKC,MAAM,KAAK,+BAA+BD,IAAA,CAAKH,IAAI;AAC3E;AAEA,eAAsBM,aACpBP,EAAA,EACAC,IAAA,EACAO,OAAA,EACAC,UAAA,EAC6B;EAE7BT,EAAA,GAAKP,aAAA,CAAcO,EAAA,CAAGG,KAAA,CAAM,GAAG,EAAE,CAAC,CAAC,EAAEO,OAAA,CAAQjB,aAAA,CAAckB,OAAA,CAAQC,GAAA,CAAI,CAAC,GAAG,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AA,KAAc,QAAQ;IAGvE,OAAO;EACT;EAEA,IAAI,CAACA,SAAA,EAAW;IACd,OAAOvE,QAAA,GAAW,QAAQ;EAC5B;EAEA,OAAO;AACT;AAEO,MAAMwE,oBAAA,GAAuB,MAAAA,CAAOvF,EAAA,EAAYC,IAAA,KAAiB;EACtE,MAAMY,IAAA,GAAOC,OAAA,CAAQd,EAAE;EACvB,IAAI,CAACa,IAAA,EAAM;EAEX,MAAM;IAAEyB;EAAc,IAAI,MAAM,OAAO,eAAe;EACtD,MAAMI,GAAA,GAAMJ,aAAA,CAActC,EAAA,EAAIC,IAAA,EAAM;IAClCY,IAAA;IACAc,MAAA,EAAQ;IACRK,WAAA,EAAa;MACXC,oBAAA,EAAsB;IACxB;IACAC,SAAA,EAAWJ,eAAA,CAAgB;IAC3BK,GAAA,EAAK;MACHC,OAAA,EAAS;MACTC,WAAA,EAAa;MACbrB,OAAA,EAAS;IACX;EACF,CAAC;EAED,IAAI0B,GAAA,CAAIC,MAAA,EAAQC,MAAA,EAAQ;IACtB,MAAMC,GAAA,GAAMH,GAAA,CAAIC,MAAA,CAAO,CAAC;IACxB,MAAM,IAAII,KAAA,CAAMF,GAAA,CAAIG,OAAA,IAAWH,GAAA,CAAII,SAAA,GAAY;AAAA,EAAKJ,GAAA,CAAII,SAAS,KAAK,GAAG;EAC3E;EAEA,OAAO;IAAEhD,IAAA,EAAMyC,GAAA,CAAIzC,IAAA;IAAMoD,GAAA,EAAKX,GAAA,CAAIW;EAAW;AAC/C;AAEO,MAAMmC,oBAAA,GAAuBD,oBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"transformSWC.js","names":[],"sources":["esm/transformSWC.js"],"sourcesContent":["import { extname } from \"node:path\";\nimport { normalizePath } from \"vite\";\nimport { configuration } from \"./configure\";\nimport { asyncGeneratorRegex, debug, runtimePublicPath } from \"./constants\";\nconst ignoreId = /node_modules\\/(\\.vite|vite)\\//;\nfunction shouldStripFlow(id, code) {\n const filename = id.split(\"?\")[0];\n if (!/\\.jsx?$/.test(filename)) return false;\n if (/node_modules[\\\\/](?:react-native|@react-native)[\\\\/].*\\.js$/.test(filename)) {\n return true;\n }\n const header = code.match(/^(?:#![^\\r\\n]*(?:\\r?\\n|$))?(?:\\s|\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\r\\n]*)*/)?.[0] || \"\";\n return /@flow\\b/.test(header) || /\\b(?:import|export)\\s+type\\b/.test(code);\n}\nasync function transformSWC(id, code, options, swcOptions) {\n id = normalizePath(id.split(\"?\")[0]).replace(normalizePath(process.cwd()), \"\");\n if (ignoreId.test(id)) {\n return;\n }\n if (id === runtimePublicPath) {\n return;\n }\n const lang = getLang(id, options.forceJSX);\n if (!lang) {\n return;\n }\n const refresh = options.environment !== \"ssr\" && !options.production && !options.noHMR && !options.forceJSX && !id.includes(\"node_modules\");\n const importSource = configuration.enableNativewind && !id.includes(\"node_modules\") ? \"nativewind\" : \"react\";\n const shouldEs5Transform = options.es5 || !process.env.VXRN_USE_BABEL_FOR_GENERATORS && asyncGeneratorRegex.test(code);\n const target = shouldEs5Transform ? \"es2015\" : \"es2020\";\n const sourceMaps = swcOptions?.sourceMaps !== void 0 ? Boolean(swcOptions.sourceMaps) : shouldSourceMap();\n const oxcOptions = {\n lang,\n target,\n assumptions: {\n setPublicClassFields: true,\n ...swcOptions?.assumptions || {}\n },\n sourcemap: sourceMaps,\n jsx: {\n runtime: \"automatic\",\n development: !options.forceJSX && !options.production,\n refresh: Boolean(refresh),\n importSource\n }\n };\n const { transformSync } = await import(\"oxc-transform\");\n const result = (() => {\n try {\n debug?.(\n `transformSWC (oxc) ${id} using options:\n${JSON.stringify(oxcOptions, null, 2)}`\n );\n const res = transformSync(id, code, oxcOptions);\n if (res.errors?.length) {\n const err = res.errors[0];\n const error = new Error(\n err.message + (err.codeframe ? `\n${err.codeframe}` : \"\")\n );\n if (err.labels?.[0]) {\n error.start = err.labels[0].start;\n error.end = err.labels[0].end;\n }\n throw error;\n }\n return {\n code: res.code,\n map: res.map\n };\n } catch (e) {\n throw e;\n }\n })();\n if (configuration.enableNativeCSS) {\n if (result.code.includes(`createInteropElement(`)) {\n result.code = `import { createInteropElement, Fragment as _InteropFragment } from 'react-native-css-interop/jsx-dev-runtime'\n${result.code}`;\n }\n }\n const hasRefreshRuntime = refresh && refreshContentRE.test(result.code);\n if (options.fixNonTypeSpecificImports || id.includes(\"node_modules\") && (lang === \"ts\" || lang === \"tsx\")) {\n const typeExportsMatch = code.match(/^\\s*export\\s+type\\s+([^\\s]+)/gi);\n if (typeExportsMatch) {\n for (const typeExport of Array.from(typeExportsMatch)) {\n const [_export, _type, name] = typeExport.split(/\\s+/);\n if (name.startsWith(\"{\")) continue;\n if (name.includes(\"<\")) continue;\n const alreadyExported = new RegExp(\n `export (const|let|class|function) ${name}\\\\s+`\n ).test(result.code);\n if (!alreadyExported) {\n const fakeExport = `export let ${name} = {};`;\n console.info(\n ` \\u26A0\\uFE0F Fixing non-type-specific import in node_module, this should be fixed upstream: ${fakeExport} in ${id}`\n );\n result.code += `\n${fakeExport}\n`;\n }\n }\n }\n }\n if (result && !options.production && !options.noHMR) {\n return wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime);\n }\n return result;\n}\nconst transformOxc = transformSWC;\nfunction wrapSourceInRefreshRuntime(id, result, options, hasRefreshRuntime) {\n if (options.environment === \"ssr\") {\n return result;\n }\n if (options.environment === \"client\") {\n return wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime);\n }\n return wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime);\n}\nfunction wrapSourceInRefreshRuntimeWeb(id, result, hasRefreshRuntime) {\n const sourceMap = result.map ? typeof result.map === \"string\" ? JSON.parse(result.map) : { ...result.map } : void 0;\n if (sourceMap) {\n sourceMap.mappings = \";;\" + sourceMap.mappings;\n }\n result.code = `import * as RefreshRuntime from \"${runtimePublicPath}\";\n\n${result.code}`;\n if (hasRefreshRuntime) {\n if (sourceMap) {\n sourceMap.mappings = \";;;;;;\" + sourceMap.mappings;\n }\n result.code = `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${result.code}\n\nwindow.$RefreshReg$ = prevRefreshReg;\nwindow.$RefreshSig$ = prevRefreshSig;\n`;\n }\n result.code += `\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: result.code, map: sourceMap };\n}\nfunction wrapSourceInRefreshRuntimeNative(id, result, options, hasRefreshRuntime) {\n const postfixCode = `if (module.hot) {\n if (module.hot.accept) {\n module.hot.accept((nextExports) => {\n RefreshRuntime.performReactRefresh()\n });\n }\n}`;\n if (hasRefreshRuntime) {\n const prefixCode = `const RefreshRuntime = __cachedModules[\"react-refresh/cjs/react-refresh-runtime.development\"];\nconst prevRefreshReg = globalThis.$RefreshReg$;\nconst prevRefreshSig = globalThis.$RefreshSig$ || (() => {\n console.info(\"no react refresh setup!\")\n return (x) => x\n});\nglobalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, \"${id}\" + \" \" + id);\nglobalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;\nmodule.url = '${id}'\nmodule.hot = createHotContext(module.url)`;\n const sourceMap = result.map ? typeof result.map === \"string\" ? JSON.parse(result.map) : { ...result.map } : void 0;\n if (sourceMap) {\n const prefixLen = prefixCode.split(\"\\n\").length + 1;\n sourceMap.mappings = new Array(prefixLen).fill(\";\").join(\"\") + sourceMap.mappings;\n }\n return {\n code: `${prefixCode}\n${result.code}\n\nif (module.hot) {\n globalThis.$RefreshReg$ = prevRefreshReg;\n globalThis.$RefreshSig$ = prevRefreshSig;\n globalThis['lastHmrExports'] = JSON.stringify(Object.keys(exports))\n}\n\n${postfixCode}\n`,\n map: sourceMap\n };\n }\n result.code += postfixCode;\n return result;\n}\nconst refreshContentRE = /\\$Refresh(?:Reg|Sig)\\$\\(/;\nfunction shouldSourceMap() {\n return process.env.VXRN_ENABLE_SOURCE_MAP === \"1\";\n}\nfunction getLang(id, forceJSX = false) {\n if (id.endsWith(\"one-entry-native\")) {\n return \"tsx\";\n }\n const extension = extname(id);\n if (extension === \".tsx\") return \"tsx\";\n if (extension === \".ts\") return \"ts\";\n if (extension === \".jsx\" || extension === \".mdx\") return \"jsx\";\n if (extension === \".js\" || extension === \".mjs\" || extension === \".cjs\") {\n return \"jsx\";\n }\n if (!extension) {\n return forceJSX ? \"jsx\" : \"js\";\n }\n return void 0;\n}\nconst transformSWCStripJSX = async (id, code) => {\n const lang = getLang(id);\n if (!lang) return;\n const { transformSync } = await import(\"oxc-transform\");\n const res = transformSync(id, code, {\n lang,\n target: \"es2020\",\n assumptions: {\n setPublicClassFields: true\n },\n sourcemap: shouldSourceMap(),\n jsx: {\n runtime: \"automatic\",\n development: true,\n refresh: false\n }\n });\n if (res.errors?.length) {\n const err = res.errors[0];\n throw new Error(err.message + (err.codeframe ? `\n${err.codeframe}` : \"\"));\n }\n return { code: res.code, map: res.map };\n};\nconst transformOxcStripJSX = transformSWCStripJSX;\nexport {\n shouldSourceMap,\n shouldStripFlow,\n transformOxc,\n transformOxcStripJSX,\n transformSWC,\n transformSWCStripJSX\n};\n//# sourceMappingURL=transformSWC.js.map\n"],"mappings":";;;;;;AAIA,MAAM,WAAW;AACjB,SAAS,gBAAgB,IAAI,MAAM;CACjC,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,CAAC;CAC/B,IAAI,CAAC,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AAK,EAAE,IAAI,UAAU;EAC3E;EACA,OAAO;GACL,MAAM,GAAG,WAAW;EACxB,OAAO,KAAK;;;;;;;;EAQZ,YAAY;;GAER,KAAK;EACP;CACF;CACA,OAAO,QAAQ;CACf,OAAO;AACT;AACA,MAAM,mBAAmB;AACzB,SAAS,kBAAkB;CACzB,OAAO,QAAQ,IAAI,2BAA2B;AAChD;AACA,SAAS,QAAQ,IAAI,WAAW,OAAO;CACrC,IAAI,GAAG,SAAS,kBAAkB,GAAG;EACnC,OAAO;CACT;CACA,MAAM,YAAY,QAAQ,EAAE;CAC5B,IAAI,cAAc,QAAQ,OAAO;CACjC,IAAI,cAAc,OAAO,OAAO;CAChC,IAAI,cAAc,UAAU,cAAc,QAAQ,OAAO;CACzD,IAAI,cAAc,SAAS,cAAc,UAAU,cAAc,QAAQ;EACvE,OAAO;CACT;CACA,IAAI,CAAC,WAAW;EACd,OAAO,WAAW,QAAQ;CAC5B;CACA,OAAO,KAAK;AACd;AACA,MAAM,uBAAuB,OAAO,IAAI,SAAS;CAC/C,MAAM,OAAO,QAAQ,EAAE;CACvB,IAAI,CAAC,MAAM;CACX,MAAM,EAAE,kBAAkB,MAAM,OAAO;CACvC,MAAM,MAAM,cAAc,IAAI,MAAM;EAClC;EACA,QAAQ;EACR,aAAa,EACX,sBAAsB,KACxB;EACA,WAAW,gBAAgB;EAC3B,KAAK;GACH,SAAS;GACT,aAAa;GACb,SAAS;EACX;CACF,CAAC;CACD,IAAI,IAAI,QAAQ,QAAQ;EACtB,MAAM,MAAM,IAAI,OAAO;EACvB,MAAM,IAAI,MAAM,IAAI,WAAW,IAAI,YAAY;EACjD,IAAI,cAAc,GAAG;CACrB;CACA,OAAO;EAAE,MAAM,IAAI;EAAM,KAAK,IAAI;CAAI;AACxC;AACA,MAAM,uBAAuB"}
|
|
@@ -3,80 +3,100 @@ 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 { executeWorkletTransform } from "./worklets/transform.mjs";
|
|
7
|
-
|
|
8
|
-
const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
6
|
+
import { executeWorkletTransform, prepareWorkletsForReactCompiler } from "./worklets/transform.mjs";
|
|
7
|
+
|
|
8
|
+
const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
|
|
9
|
+
"worklet",
|
|
10
|
+
"useAnimatedGestureHandler",
|
|
11
|
+
"useAnimatedScrollHandler",
|
|
12
|
+
"useFrameCallback",
|
|
13
|
+
"useAnimatedStyle",
|
|
14
|
+
"useAnimatedProps",
|
|
15
|
+
"createAnimatedPropAdapter",
|
|
16
|
+
"useDerivedValue",
|
|
17
|
+
"useAnimatedReaction",
|
|
18
|
+
"useWorkletCallback",
|
|
19
|
+
"withTiming",
|
|
20
|
+
"withSpring",
|
|
21
|
+
"withDecay",
|
|
22
|
+
"withRepeat",
|
|
23
|
+
"runOnUI",
|
|
24
|
+
"executeOnUIRuntimeSync"
|
|
25
|
+
];
|
|
26
|
+
const REANIMATED_REGEX = new RegExp([.../* @__PURE__ */ new Set([
|
|
27
|
+
...REANIMATED_AUTOWORKLETIZATION_KEYWORDS,
|
|
28
|
+
...Object.keys(AUTOWORKLET_FUNCTION_ARGS),
|
|
29
|
+
...GESTURE_BUILDER_METHODS,
|
|
30
|
+
"withCallback"
|
|
31
|
+
])].map((name) => `\\b${name}\\b`).join("|"));
|
|
32
|
+
const REANIMATED_IGNORED_PATHS = [
|
|
33
|
+
"react-native-prebuilt",
|
|
34
|
+
"node_modules/.vxrn/react-native",
|
|
35
|
+
"node_modules/react/",
|
|
36
|
+
"node_modules/react-dom/",
|
|
37
|
+
"node_modules/react-native/",
|
|
38
|
+
"node_modules/@react-native/",
|
|
39
|
+
"node_modules/react-native-web/"
|
|
40
|
+
];
|
|
19
41
|
const REANIMATED_IGNORED_PATHS_REGEX = new RegExp(REANIMATED_IGNORED_PATHS.join("|"));
|
|
20
|
-
function shouldTransformWorklets({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
return REANIMATED_REGEX.test(code);
|
|
42
|
+
function shouldTransformWorklets({ id, code }) {
|
|
43
|
+
if (!isNativeWorkletsEnabled() || !configuration.enableReanimated) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const normalizedId = id.replace(/\\/g, "/");
|
|
47
|
+
if (REANIMATED_IGNORED_PATHS_REGEX.test(normalizedId)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return REANIMATED_REGEX.test(code);
|
|
32
51
|
}
|
|
33
52
|
function getWorkletsVersion(projectRoot, filename) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
53
|
+
if (projectRoot) {
|
|
54
|
+
try {
|
|
55
|
+
const req = createRequire(path.resolve(projectRoot, "package.json"));
|
|
56
|
+
try {
|
|
57
|
+
const ver = req("react-native-worklets/package.json")?.version;
|
|
58
|
+
if (ver) return ver;
|
|
59
|
+
} catch {}
|
|
60
|
+
try {
|
|
61
|
+
const ver = req("react-native-reanimated/package.json")?.version;
|
|
62
|
+
if (ver) return ver;
|
|
63
|
+
} catch {}
|
|
64
|
+
} catch {}
|
|
65
|
+
throw new Error(`[@vxrn/compiler] Unable to resolve "react-native-worklets" or "react-native-reanimated" version from project root "${projectRoot}". Please ensure react-native-worklets is installed in your project.`);
|
|
66
|
+
}
|
|
67
|
+
if (filename && !filename.startsWith("\0") && fs.existsSync(filename)) {
|
|
68
|
+
try {
|
|
69
|
+
const req = createRequire(filename);
|
|
70
|
+
try {
|
|
71
|
+
const ver = req("react-native-worklets/package.json")?.version;
|
|
72
|
+
if (ver) return ver;
|
|
73
|
+
} catch {}
|
|
74
|
+
try {
|
|
75
|
+
const ver = req("react-native-reanimated/package.json")?.version;
|
|
76
|
+
if (ver) return ver;
|
|
77
|
+
} catch {}
|
|
78
|
+
} catch {}
|
|
79
|
+
}
|
|
80
|
+
const fallbacks = [() => createRequire(path.resolve(process.cwd(), "package.json")), () => createRequire(import.meta.url)];
|
|
81
|
+
for (const getReq of fallbacks) {
|
|
82
|
+
try {
|
|
83
|
+
const req = getReq();
|
|
84
|
+
try {
|
|
85
|
+
const ver = req("react-native-worklets/package.json")?.version;
|
|
86
|
+
if (ver) return ver;
|
|
87
|
+
} catch {}
|
|
88
|
+
try {
|
|
89
|
+
const ver = req("react-native-reanimated/package.json")?.version;
|
|
90
|
+
if (ver) return ver;
|
|
91
|
+
} catch {}
|
|
92
|
+
} catch {}
|
|
93
|
+
}
|
|
94
|
+
const target = filename || process.cwd();
|
|
95
|
+
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.`);
|
|
77
96
|
}
|
|
78
97
|
async function transformWorklets(id, code, sourceMaps = false, options) {
|
|
79
|
-
|
|
98
|
+
return executeWorkletTransform(id, code, sourceMaps, options, getWorkletsVersion);
|
|
80
99
|
}
|
|
100
|
+
|
|
81
101
|
export { REANIMATED_AUTOWORKLETIZATION_KEYWORDS, getWorkletsVersion, prepareWorkletsForReactCompiler, shouldTransformWorklets, transformWorklets };
|
|
82
102
|
//# sourceMappingURL=transformWorklets.mjs.map
|