@vxrn/compiler 2.0.0-beta.33.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.
Files changed (94) hide show
  1. package/dist/cjs/cache.cjs +112 -109
  2. package/dist/cjs/configure.cjs +26 -28
  3. package/dist/cjs/constants.cjs +56 -60
  4. package/dist/cjs/index.cjs +420 -438
  5. package/dist/cjs/reactNativeCodegen.cjs +105 -114
  6. package/dist/cjs/reactNativeViewConfig.cjs +362 -381
  7. package/dist/cjs/refresh-runtime.cjs +390 -397
  8. package/dist/cjs/transformBabel.cjs +278 -218
  9. package/dist/cjs/transformHermesAsync.cjs +36 -47
  10. package/dist/cjs/transformHermesLoops.cjs +279 -281
  11. package/dist/cjs/transformSWC.cjs +183 -200
  12. package/dist/cjs/transformWorklets.cjs +107 -95
  13. package/dist/cjs/types.cjs +9 -11
  14. package/dist/cjs/worklets/autoworklet.cjs +277 -222
  15. package/dist/cjs/worklets/globals.cjs +124 -60
  16. package/dist/cjs/worklets/hash.cjs +23 -27
  17. package/dist/cjs/worklets/scope.cjs +338 -359
  18. package/dist/cjs/worklets/serialize.cjs +73 -75
  19. package/dist/cjs/worklets/transform.cjs +217 -222
  20. package/dist/cjs/worklets/types.cjs +9 -11
  21. package/dist/esm/cache.mjs +96 -89
  22. package/dist/esm/cache.mjs.map +1 -1
  23. package/dist/esm/configure.mjs +11 -10
  24. package/dist/esm/configure.mjs.map +1 -1
  25. package/dist/esm/constants.mjs +41 -41
  26. package/dist/esm/constants.mjs.map +1 -1
  27. package/dist/esm/index.js +417 -420
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/index.mjs +417 -420
  30. package/dist/esm/index.mjs.map +1 -1
  31. package/dist/esm/reactNativeCodegen.mjs +90 -88
  32. package/dist/esm/reactNativeCodegen.mjs.map +1 -1
  33. package/dist/esm/reactNativeViewConfig.mjs +347 -362
  34. package/dist/esm/reactNativeViewConfig.mjs.map +1 -1
  35. package/dist/esm/refresh-runtime.mjs +372 -376
  36. package/dist/esm/refresh-runtime.mjs.map +1 -1
  37. package/dist/esm/transformBabel.mjs +261 -194
  38. package/dist/esm/transformBabel.mjs.map +1 -1
  39. package/dist/esm/transformHermesAsync.mjs +20 -21
  40. package/dist/esm/transformHermesAsync.mjs.map +1 -1
  41. package/dist/esm/transformHermesLoops.mjs +264 -255
  42. package/dist/esm/transformHermesLoops.mjs.map +1 -1
  43. package/dist/esm/transformSWC.mjs +163 -171
  44. package/dist/esm/transformSWC.mjs.map +1 -1
  45. package/dist/esm/transformWorklets.mjs +89 -69
  46. package/dist/esm/transformWorklets.mjs.map +1 -1
  47. package/dist/esm/types.mjs +0 -2
  48. package/dist/esm/worklets/autoworklet.mjs +258 -200
  49. package/dist/esm/worklets/autoworklet.mjs.map +1 -1
  50. package/dist/esm/worklets/globals.mjs +109 -42
  51. package/dist/esm/worklets/globals.mjs.map +1 -1
  52. package/dist/esm/worklets/hash.mjs +10 -9
  53. package/dist/esm/worklets/hash.mjs.map +1 -1
  54. package/dist/esm/worklets/scope.mjs +325 -341
  55. package/dist/esm/worklets/scope.mjs.map +1 -1
  56. package/dist/esm/worklets/serialize.mjs +60 -58
  57. package/dist/esm/worklets/serialize.mjs.map +1 -1
  58. package/dist/esm/worklets/transform.mjs +201 -197
  59. package/dist/esm/worklets/transform.mjs.map +1 -1
  60. package/dist/esm/worklets/types.mjs +0 -2
  61. package/package.json +7 -6
  62. package/src/cache.ts +37 -7
  63. package/src/index.ts +33 -18
  64. package/src/transformBabel.test.ts +311 -1
  65. package/src/transformBabel.ts +110 -13
  66. package/types/cache.d.ts +2 -2
  67. package/types/cache.d.ts.map +1 -1
  68. package/types/index.d.ts.map +1 -1
  69. package/types/transformBabel.d.ts +16 -1
  70. package/types/transformBabel.d.ts.map +1 -1
  71. package/types/transformSWC.d.ts +1 -4
  72. package/types/transformSWC.d.ts.map +1 -1
  73. package/dist/cjs/transformBabel.test.cjs +0 -360
  74. package/dist/cjs/transformHermesLoops.test.cjs +0 -257
  75. package/dist/cjs/transformSWC.test.cjs +0 -117
  76. package/dist/cjs/transformWorklets.test.cjs +0 -604
  77. package/dist/esm/transformBabel.test.mjs +0 -337
  78. package/dist/esm/transformBabel.test.mjs.map +0 -1
  79. package/dist/esm/transformHermesLoops.test.mjs +0 -234
  80. package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
  81. package/dist/esm/transformSWC.test.mjs +0 -118
  82. package/dist/esm/transformSWC.test.mjs.map +0 -1
  83. package/dist/esm/transformWorklets.test.mjs +0 -581
  84. package/dist/esm/transformWorklets.test.mjs.map +0 -1
  85. package/dist/esm/types.mjs.map +0 -1
  86. package/dist/esm/worklets/types.mjs.map +0 -1
  87. package/types/transformBabel.test.d.ts +0 -2
  88. package/types/transformBabel.test.d.ts.map +0 -1
  89. package/types/transformHermesLoops.test.d.ts +0 -2
  90. package/types/transformHermesLoops.test.d.ts.map +0 -1
  91. package/types/transformSWC.test.d.ts +0 -2
  92. package/types/transformSWC.test.d.ts.map +0 -1
  93. package/types/transformWorklets.test.d.ts +0 -2
  94. package/types/transformWorklets.test.d.ts.map +0 -1
@@ -7,151 +7,154 @@ import { createGlobalsSet } from "./globals.mjs";
7
7
  import { calculateWorkletHash } from "./hash.mjs";
8
8
  import { getClosureVariables } from "./scope.mjs";
9
9
  import { buildLocalFunction, serializeWorkletForUI } from "./serialize.mjs";
10
- const FUNCTION_TYPES = /* @__PURE__ */new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"]);
10
+
11
+ const FUNCTION_TYPES = /* @__PURE__ */ new Set([
12
+ "FunctionDeclaration",
13
+ "FunctionExpression",
14
+ "ArrowFunctionExpression"
15
+ ]);
11
16
  function prepareWorkletsForReactCompiler(id, code, sourceMaps = false) {
12
- const cleanId = id.split("?")[0];
13
- const parsed = parseSync(cleanId, code, {
14
- sourceType: "module",
15
- lang: /\.[cm]?ts$/.test(cleanId) ? "ts" : cleanId.endsWith(".tsx") ? "tsx" : "jsx"
16
- });
17
- if (parsed.errors.length) {
18
- const error = parsed.errors[0];
19
- throw new Error(error.codeframe || error.message || "Syntax Error while parsing worklet");
20
- }
21
- const candidates = findWorkletCandidates(parsed.program).filter(candidate => candidate.isAutoWorklet && !hasDirective(candidate.fnNode, "worklet"));
22
- if (!candidates.length) return null;
23
- const output = new MagicString(code);
24
- for (const {
25
- fnNode
26
- } of candidates) {
27
- const body = fnNode.body;
28
- if (body.type === "BlockStatement") {
29
- output.appendLeft(body.start + 1, "'worklet';");
30
- } else {
31
- output.appendLeft(body.start, "{ 'worklet'; return (");
32
- output.appendLeft(body.end, "); }");
33
- }
34
- }
35
- return {
36
- code: output.toString(),
37
- map: sourceMaps ? output.generateMap({
38
- source: cleanId,
39
- hires: true,
40
- includeContent: true
41
- }) : void 0
42
- };
17
+ const cleanId = id.split("?")[0];
18
+ const parsed = parseSync(cleanId, code, {
19
+ sourceType: "module",
20
+ lang: /\.[cm]?ts$/.test(cleanId) ? "ts" : cleanId.endsWith(".tsx") ? "tsx" : "jsx"
21
+ });
22
+ if (parsed.errors.length) {
23
+ const error = parsed.errors[0];
24
+ throw new Error(error.codeframe || error.message || "Syntax Error while parsing worklet");
25
+ }
26
+ const candidates = findWorkletCandidates(parsed.program).filter((candidate) => candidate.isAutoWorklet && !hasDirective(candidate.fnNode, "worklet"));
27
+ if (!candidates.length) return null;
28
+ const output = new MagicString(code);
29
+ for (const { fnNode } of candidates) {
30
+ const body = fnNode.body;
31
+ if (body.type === "BlockStatement") {
32
+ output.appendLeft(body.start + 1, "'worklet';");
33
+ } else {
34
+ output.appendLeft(body.start, "{ 'worklet'; return (");
35
+ output.appendLeft(body.end, "); }");
36
+ }
37
+ }
38
+ return {
39
+ code: output.toString(),
40
+ map: sourceMaps ? output.generateMap({
41
+ source: cleanId,
42
+ hires: true,
43
+ includeContent: true
44
+ }) : void 0
45
+ };
43
46
  }
44
47
  function findEnclosingFunction(program, node) {
45
- let best = void 0;
46
- const walk = n => {
47
- if (!n || typeof n !== "object") return;
48
- if (Array.isArray(n)) {
49
- for (const c of n) walk(c);
50
- return;
51
- }
52
- if (typeof n.type !== "string") return;
53
- if (typeof n.start === "number" && (n.start > node.start || n.end < node.end)) return;
54
- if (FUNCTION_TYPES.has(n.type) && n !== node && n.body?.type === "BlockStatement" && n.body.start < node.start && n.body.end > node.end && (!best || n.body.start > best.body.start)) {
55
- best = n;
56
- }
57
- for (const key in n) {
58
- if (key === "parent") continue;
59
- walk(n[key]);
60
- }
61
- };
62
- walk(program);
63
- return best;
48
+ let best = void 0;
49
+ const walk = (n) => {
50
+ if (!n || typeof n !== "object") return;
51
+ if (Array.isArray(n)) {
52
+ for (const c of n) walk(c);
53
+ return;
54
+ }
55
+ if (typeof n.type !== "string") return;
56
+ if (typeof n.start === "number" && (n.start > node.start || n.end < node.end)) return;
57
+ if (FUNCTION_TYPES.has(n.type) && n !== node && n.body?.type === "BlockStatement" && n.body.start < node.start && n.body.end > node.end && (!best || n.body.start > best.body.start)) {
58
+ best = n;
59
+ }
60
+ for (const key in n) {
61
+ if (key === "parent") continue;
62
+ walk(n[key]);
63
+ }
64
+ };
65
+ walk(program);
66
+ return best;
64
67
  }
65
68
  function executeWorkletTransform(id, code, sourceMaps = false, options, resolveVersionFn) {
66
- const cleanId = id.split("?")[0];
67
- const lang = /\.[cm]?ts$/.test(cleanId) ? "ts" : cleanId.endsWith(".tsx") ? "tsx" : "jsx";
68
- const initialParse = parseSync(cleanId, code, {
69
- sourceType: "module",
70
- lang
71
- });
72
- if (initialParse.errors && initialParse.errors.length > 0) {
73
- const err = initialParse.errors[0];
74
- throw new Error(err.codeframe || err.message || "Syntax Error while parsing worklet");
75
- }
76
- const initialCandidates = findWorkletCandidates(initialParse.program);
77
- if (initialCandidates.length === 0) {
78
- let map2 = void 0;
79
- if (sourceMaps) {
80
- const ms = new MagicString(code);
81
- map2 = ms.generateMap({
82
- source: cleanId,
83
- file: cleanId,
84
- hires: true,
85
- includeContent: true
86
- });
87
- }
88
- return {
89
- code,
90
- map: map2
91
- };
92
- }
93
- const pluginVersion = options?.pluginVersion || (resolveVersionFn ? resolveVersionFn(options?.projectRoot, cleanId) : "0.0.0");
94
- const globals = createGlobalsSet(options?.globals, options?.strictGlobal);
95
- let location = cleanId;
96
- if (options?.relativeSourceLocation && options?.projectRoot) {
97
- location = path.relative(options.projectRoot, cleanId).replace(/\\/g, "/");
98
- }
99
- let currentCode = code;
100
- const initDataDefs = /* @__PURE__ */new Map();
101
- const passMaps = [];
102
- let remainingPassBudget = 100;
103
- while (remainingPassBudget-- > 0) {
104
- const parseResult = parseSync(cleanId, currentCode, {
105
- sourceType: "module",
106
- lang
107
- });
108
- if (parseResult.errors && parseResult.errors.length > 0) {
109
- const err = parseResult.errors[0];
110
- throw new Error(err.codeframe || err.message || "Syntax Error while parsing worklet");
111
- }
112
- const candidates = findWorkletCandidates(parseResult.program);
113
- if (candidates.length === 0) {
114
- break;
115
- }
116
- const innermostCandidates = candidates.filter(c => {
117
- return !candidates.some(other => other !== c && other.fnNode.start >= c.fnNode.start && other.fnNode.end <= c.fnNode.end);
118
- });
119
- if (innermostCandidates.length === 0) {
120
- throw new Error(`[worklets] Cyclic or unresolvable worklet nesting detected in ${cleanId}`);
121
- }
122
- const ms = new MagicString(currentCode);
123
- const inlinedInitData = /* @__PURE__ */new Map();
124
- for (const candidate of innermostCandidates) {
125
- const closureVars = hasDirective(candidate.fnNode, "no-worklet-closure") ? [] : getClosureVariables(candidate.fnNode, globals);
126
- const fnName = candidate.name;
127
- const serializedCode = serializeWorkletForUI(candidate.fnNode, currentCode, fnName, closureVars);
128
- const workletHash = calculateWorkletHash(serializedCode);
129
- const initDataVar = `_worklet_${workletHash}_init_data`;
130
- const initDataDecl = `var ${initDataVar} = {
69
+ const cleanId = id.split("?")[0];
70
+ const lang = /\.[cm]?ts$/.test(cleanId) ? "ts" : cleanId.endsWith(".tsx") ? "tsx" : "jsx";
71
+ const initialParse = parseSync(cleanId, code, {
72
+ sourceType: "module",
73
+ lang
74
+ });
75
+ if (initialParse.errors && initialParse.errors.length > 0) {
76
+ const err = initialParse.errors[0];
77
+ throw new Error(err.codeframe || err.message || "Syntax Error while parsing worklet");
78
+ }
79
+ const initialCandidates = findWorkletCandidates(initialParse.program);
80
+ if (initialCandidates.length === 0) {
81
+ let map2 = void 0;
82
+ if (sourceMaps) {
83
+ const ms = new MagicString(code);
84
+ map2 = ms.generateMap({
85
+ source: cleanId,
86
+ file: cleanId,
87
+ hires: true,
88
+ includeContent: true
89
+ });
90
+ }
91
+ return {
92
+ code,
93
+ map: map2
94
+ };
95
+ }
96
+ const pluginVersion = options?.pluginVersion || (resolveVersionFn ? resolveVersionFn(options?.projectRoot, cleanId) : "0.0.0");
97
+ const globals = createGlobalsSet(options?.globals, options?.strictGlobal);
98
+ let location = cleanId;
99
+ if (options?.relativeSourceLocation && options?.projectRoot) {
100
+ location = path.relative(options.projectRoot, cleanId).replace(/\\/g, "/");
101
+ }
102
+ let currentCode = code;
103
+ const initDataDefs = /* @__PURE__ */ new Map();
104
+ const passMaps = [];
105
+ let remainingPassBudget = 100;
106
+ while (remainingPassBudget-- > 0) {
107
+ const parseResult = parseSync(cleanId, currentCode, {
108
+ sourceType: "module",
109
+ lang
110
+ });
111
+ if (parseResult.errors && parseResult.errors.length > 0) {
112
+ const err = parseResult.errors[0];
113
+ throw new Error(err.codeframe || err.message || "Syntax Error while parsing worklet");
114
+ }
115
+ const candidates = findWorkletCandidates(parseResult.program);
116
+ if (candidates.length === 0) {
117
+ break;
118
+ }
119
+ const innermostCandidates = candidates.filter((c) => {
120
+ return !candidates.some((other) => other !== c && other.fnNode.start >= c.fnNode.start && other.fnNode.end <= c.fnNode.end);
121
+ });
122
+ if (innermostCandidates.length === 0) {
123
+ throw new Error(`[worklets] Cyclic or unresolvable worklet nesting detected in ${cleanId}`);
124
+ }
125
+ const ms = new MagicString(currentCode);
126
+ const inlinedInitData = /* @__PURE__ */ new Map();
127
+ for (const candidate of innermostCandidates) {
128
+ const closureVars = hasDirective(candidate.fnNode, "no-worklet-closure") ? [] : getClosureVariables(candidate.fnNode, globals);
129
+ const fnName = candidate.name;
130
+ const serializedCode = serializeWorkletForUI(candidate.fnNode, currentCode, fnName, closureVars);
131
+ const workletHash = calculateWorkletHash(serializedCode);
132
+ const initDataVar = `_worklet_${workletHash}_init_data`;
133
+ const initDataDecl = `var ${initDataVar} = {
131
134
  code: ${JSON.stringify(serializedCode)},
132
135
  location: ${JSON.stringify(location)}
133
136
  };`;
134
- const enclosingFn = hasDirective(candidate.fnNode, "limit-init-data-hoisting") ? findEnclosingFunction(parseResult.program, candidate.fnNode) : void 0;
135
- if (enclosingFn) {
136
- const insertAt = bodyStartAfterDirectives(enclosingFn, currentCode);
137
- let declared = inlinedInitData.get(insertAt);
138
- if (!declared) {
139
- declared = /* @__PURE__ */new Set();
140
- inlinedInitData.set(insertAt, declared);
141
- }
142
- if (!declared.has(initDataVar)) {
143
- declared.add(initDataVar);
144
- ms.appendLeft(insertAt, `
137
+ const enclosingFn = hasDirective(candidate.fnNode, "limit-init-data-hoisting") ? findEnclosingFunction(parseResult.program, candidate.fnNode) : void 0;
138
+ if (enclosingFn) {
139
+ const insertAt = bodyStartAfterDirectives(enclosingFn, currentCode);
140
+ let declared = inlinedInitData.get(insertAt);
141
+ if (!declared) {
142
+ declared = /* @__PURE__ */ new Set();
143
+ inlinedInitData.set(insertAt, declared);
144
+ }
145
+ if (!declared.has(initDataVar)) {
146
+ declared.add(initDataVar);
147
+ ms.appendLeft(insertAt, `
145
148
  ${initDataDecl}
146
149
  `);
147
- }
148
- } else if (!initDataDefs.has(initDataVar)) {
149
- initDataDefs.set(initDataVar, initDataDecl);
150
- }
151
- const localFnCode = buildLocalFunction(candidate.fnNode, currentCode, fnName);
152
- const localName = fnName || "_worklet";
153
- const closureProps = closureVars.map(v => `${v}: ${v}`).join(", ");
154
- const iife = `(function () {
150
+ }
151
+ } else if (!initDataDefs.has(initDataVar)) {
152
+ initDataDefs.set(initDataVar, initDataDecl);
153
+ }
154
+ const localFnCode = buildLocalFunction(candidate.fnNode, currentCode, fnName);
155
+ const localName = fnName || "_worklet";
156
+ const closureProps = closureVars.map((v) => `${v}: ${v}`).join(", ");
157
+ const iife = `(function () {
155
158
  var _e = [new (typeof global !== 'undefined' ? global : globalThis).Error(), 1, -27];
156
159
  var ${localName} = ${localFnCode};
157
160
  ${localName}.__closure = { ${closureProps} };
@@ -161,69 +164,70 @@ ${initDataDecl}
161
164
  ${localName}.__stackDetails = _e;
162
165
  return ${localName};
163
166
  })()`;
164
- if (candidate.kind === "function_declaration") {
165
- if (candidate.parent?.type === "ExportNamedDeclaration") {
166
- ms.overwrite(candidate.parent.start, candidate.parent.end, `export var ${candidate.name} = ${iife};`);
167
- } else if (candidate.parent?.type === "ExportDefaultDeclaration") {
168
- ms.overwrite(candidate.parent.start, candidate.parent.end, `var ${candidate.name || "_defaultWorklet"} = ${iife};
167
+ if (candidate.kind === "function_declaration") {
168
+ if (candidate.parent?.type === "ExportNamedDeclaration") {
169
+ ms.overwrite(candidate.parent.start, candidate.parent.end, `export var ${candidate.name} = ${iife};`);
170
+ } else if (candidate.parent?.type === "ExportDefaultDeclaration") {
171
+ ms.overwrite(candidate.parent.start, candidate.parent.end, `var ${candidate.name || "_defaultWorklet"} = ${iife};
169
172
  export default ${candidate.name || "_defaultWorklet"};`);
170
- } else {
171
- ms.overwrite(candidate.node.start, candidate.node.end, `var ${candidate.name} = ${iife};`);
172
- }
173
- } else if (candidate.kind === "object_method") {
174
- ms.overwrite(candidate.node.start, candidate.node.end, `${candidate.name}: ${iife}`);
175
- } else {
176
- ms.overwrite(candidate.node.start, candidate.node.end, iife);
177
- }
178
- }
179
- if (sourceMaps) {
180
- passMaps.push(ms.generateMap({
181
- source: cleanId,
182
- file: cleanId,
183
- hires: true,
184
- includeContent: true
185
- }));
186
- }
187
- currentCode = ms.toString();
188
- }
189
- const finalCheck = parseSync(cleanId, currentCode, {
190
- sourceType: "module",
191
- lang
192
- });
193
- const remaining = findWorkletCandidates(finalCheck.program);
194
- if (remaining.length > 0) {
195
- throw new Error(`[worklets] Exceeded maximum pass budget while transforming worklets in ${cleanId}. ${remaining.length} worklet(s) remained untransformed.`);
196
- }
197
- if (initDataDefs.size > 0) {
198
- const initDataCode = Array.from(initDataDefs.values()).join("\n") + "\n";
199
- const msPrepend = new MagicString(currentCode);
200
- msPrepend.prepend(initDataCode);
201
- if (sourceMaps) {
202
- passMaps.push(msPrepend.generateMap({
203
- source: cleanId,
204
- file: cleanId,
205
- hires: true,
206
- includeContent: true
207
- }));
208
- }
209
- currentCode = msPrepend.toString();
210
- }
211
- let map = void 0;
212
- if (sourceMaps && passMaps.length > 0) {
213
- if (passMaps.length === 1) {
214
- map = passMaps[0];
215
- } else {
216
- map = remapping(passMaps.slice().reverse(), () => null);
217
- }
218
- if (map) {
219
- map.sources = [cleanId];
220
- map.file = cleanId;
221
- }
222
- }
223
- return {
224
- code: currentCode,
225
- map
226
- };
173
+ } else {
174
+ ms.overwrite(candidate.node.start, candidate.node.end, `var ${candidate.name} = ${iife};`);
175
+ }
176
+ } else if (candidate.kind === "object_method") {
177
+ ms.overwrite(candidate.node.start, candidate.node.end, `${candidate.name}: ${iife}`);
178
+ } else {
179
+ ms.overwrite(candidate.node.start, candidate.node.end, iife);
180
+ }
181
+ }
182
+ if (sourceMaps) {
183
+ passMaps.push(ms.generateMap({
184
+ source: cleanId,
185
+ file: cleanId,
186
+ hires: true,
187
+ includeContent: true
188
+ }));
189
+ }
190
+ currentCode = ms.toString();
191
+ }
192
+ const finalCheck = parseSync(cleanId, currentCode, {
193
+ sourceType: "module",
194
+ lang
195
+ });
196
+ const remaining = findWorkletCandidates(finalCheck.program);
197
+ if (remaining.length > 0) {
198
+ throw new Error(`[worklets] Exceeded maximum pass budget while transforming worklets in ${cleanId}. ${remaining.length} worklet(s) remained untransformed.`);
199
+ }
200
+ if (initDataDefs.size > 0) {
201
+ const initDataCode = Array.from(initDataDefs.values()).join("\n") + "\n";
202
+ const msPrepend = new MagicString(currentCode);
203
+ msPrepend.prepend(initDataCode);
204
+ if (sourceMaps) {
205
+ passMaps.push(msPrepend.generateMap({
206
+ source: cleanId,
207
+ file: cleanId,
208
+ hires: true,
209
+ includeContent: true
210
+ }));
211
+ }
212
+ currentCode = msPrepend.toString();
213
+ }
214
+ let map = void 0;
215
+ if (sourceMaps && passMaps.length > 0) {
216
+ if (passMaps.length === 1) {
217
+ map = passMaps[0];
218
+ } else {
219
+ map = remapping(passMaps.slice().reverse(), () => null);
220
+ }
221
+ if (map) {
222
+ map.sources = [cleanId];
223
+ map.file = cleanId;
224
+ }
225
+ }
226
+ return {
227
+ code: currentCode,
228
+ map
229
+ };
227
230
  }
231
+
228
232
  export { executeWorkletTransform, prepareWorkletsForReactCompiler };
229
233
  //# sourceMappingURL=transform.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["path","MagicString","remapping","parseSync","bodyStartAfterDirectives","findWorkletCandidates","hasDirective","createGlobalsSet","calculateWorkletHash","getClosureVariables","buildLocalFunction","serializeWorkletForUI","FUNCTION_TYPES","Set","prepareWorkletsForReactCompiler","id","code","sourceMaps","cleanId","split","parsed","sourceType","lang","test","endsWith","errors","length","error","Error","codeframe","message","candidates","program","filter","candidate","isAutoWorklet","fnNode","output","body","type","appendLeft","start","end","toString","map","generateMap","source","hires","includeContent","findEnclosingFunction","node","best","walk","n","Array","isArray","c","has","key","executeWorkletTransform","options","resolveVersionFn","initialParse","err","initialCandidates","ms","file","map2","pluginVersion","projectRoot","globals","strictGlobal","location","relativeSourceLocation","relative","replace","currentCode","initDataDefs","Map","passMaps","remainingPassBudget","parseResult","innermostCandidates","some","other","inlinedInitData","closureVars","fnName","name","serializedCode","workletHash","initDataVar","initDataDecl","JSON","stringify","enclosingFn","insertAt","declared","get","set","add","localFnCode","localName","closureProps","v","join","iife","kind","parent","overwrite","push","finalCheck","remaining","size","initDataCode","from","values","msPrepend","prepend","slice","reverse","sources"],"sources":["../../../src/workl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AAA,CAAM,EAAEC,OAAA,CAAQ,GAAG,MAAM,IAAI;IACxD;IACA,IAAI5E,GAAA,EAAK;MACPA,GAAA,CAAI6E,OAAA,GAAU,CAACvG,OAAO;MACtB0B,GAAA,CAAIsB,IAAA,GAAOhD,OAAA;IACb;EACF;EAEA,OAAO;IACLF,IAAA,EAAM4D,WAAA;IACNhC;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"transform.js","names":[],"sources":["esm/worklets/transform.js"],"sourcesContent":["import path from \"node:path\";\nimport MagicString from \"magic-string\";\nimport remapping from \"@jridgewell/remapping\";\nimport { parseSync } from \"oxc-parser\";\nimport {\n bodyStartAfterDirectives,\n findWorkletCandidates,\n hasDirective\n} from \"./autoworklet\";\nimport { createGlobalsSet } from \"./globals\";\nimport { calculateWorkletHash } from \"./hash\";\nimport { getClosureVariables } from \"./scope\";\nimport { buildLocalFunction, serializeWorkletForUI } from \"./serialize\";\nconst FUNCTION_TYPES = /* @__PURE__ */ new Set([\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n \"ArrowFunctionExpression\"\n]);\nfunction prepareWorkletsForReactCompiler(id, code, sourceMaps = false) {\n const cleanId = id.split(\"?\")[0];\n const parsed = parseSync(cleanId, code, {\n sourceType: \"module\",\n lang: /\\.[cm]?ts$/.test(cleanId) ? \"ts\" : cleanId.endsWith(\".tsx\") ? \"tsx\" : \"jsx\"\n });\n if (parsed.errors.length) {\n const error = parsed.errors[0];\n throw new Error(\n error.codeframe || error.message || \"Syntax Error while parsing worklet\"\n );\n }\n const candidates = findWorkletCandidates(parsed.program).filter(\n (candidate) => candidate.isAutoWorklet && !hasDirective(candidate.fnNode, \"worklet\")\n );\n if (!candidates.length) return null;\n const output = new MagicString(code);\n for (const { fnNode } of candidates) {\n const body = fnNode.body;\n if (body.type === \"BlockStatement\") {\n output.appendLeft(body.start + 1, \"'worklet';\");\n } else {\n output.appendLeft(body.start, \"{ 'worklet'; return (\");\n output.appendLeft(body.end, \"); }\");\n }\n }\n return {\n code: output.toString(),\n map: sourceMaps ? output.generateMap({ source: cleanId, hires: true, includeContent: true }) : void 0\n };\n}\nfunction findEnclosingFunction(program, node) {\n let best = void 0;\n const walk = (n) => {\n if (!n || typeof n !== \"object\") return;\n if (Array.isArray(n)) {\n for (const c of n) walk(c);\n return;\n }\n if (typeof n.type !== \"string\") return;\n if (typeof n.start === \"number\" && (n.start > node.start || n.end < node.end)) return;\n if (FUNCTION_TYPES.has(n.type) && n !== node && n.body?.type === \"BlockStatement\" && n.body.start < node.start && n.body.end > node.end && (!best || n.body.start > best.body.start)) {\n best = n;\n }\n for (const key in n) {\n if (key === \"parent\") continue;\n walk(n[key]);\n }\n };\n walk(program);\n return best;\n}\nfunction executeWorkletTransform(id, code, sourceMaps = false, options, resolveVersionFn) {\n const cleanId = id.split(\"?\")[0];\n const lang = /\\.[cm]?ts$/.test(cleanId) ? \"ts\" : cleanId.endsWith(\".tsx\") ? \"tsx\" : \"jsx\";\n const initialParse = parseSync(cleanId, code, {\n sourceType: \"module\",\n lang\n });\n if (initialParse.errors && initialParse.errors.length > 0) {\n const err = initialParse.errors[0];\n throw new Error(err.codeframe || err.message || \"Syntax Error while parsing worklet\");\n }\n const initialCandidates = findWorkletCandidates(initialParse.program);\n if (initialCandidates.length === 0) {\n let map2 = void 0;\n if (sourceMaps) {\n const ms = new MagicString(code);\n map2 = ms.generateMap({\n source: cleanId,\n file: cleanId,\n hires: true,\n includeContent: true\n });\n }\n return { code, map: map2 };\n }\n const pluginVersion = options?.pluginVersion || (resolveVersionFn ? resolveVersionFn(options?.projectRoot, cleanId) : \"0.0.0\");\n const globals = createGlobalsSet(options?.globals, options?.strictGlobal);\n let location = cleanId;\n if (options?.relativeSourceLocation && options?.projectRoot) {\n location = path.relative(options.projectRoot, cleanId).replace(/\\\\/g, \"/\");\n }\n let currentCode = code;\n const initDataDefs = /* @__PURE__ */ new Map();\n const passMaps = [];\n let remainingPassBudget = 100;\n while (remainingPassBudget-- > 0) {\n const parseResult = parseSync(cleanId, currentCode, {\n sourceType: \"module\",\n lang\n });\n if (parseResult.errors && parseResult.errors.length > 0) {\n const err = parseResult.errors[0];\n throw new Error(\n err.codeframe || err.message || \"Syntax Error while parsing worklet\"\n );\n }\n const candidates = findWorkletCandidates(parseResult.program);\n if (candidates.length === 0) {\n break;\n }\n const innermostCandidates = candidates.filter((c) => {\n return !candidates.some(\n (other) => other !== c && other.fnNode.start >= c.fnNode.start && other.fnNode.end <= c.fnNode.end\n );\n });\n if (innermostCandidates.length === 0) {\n throw new Error(\n `[worklets] Cyclic or unresolvable worklet nesting detected in ${cleanId}`\n );\n }\n const ms = new MagicString(currentCode);\n const inlinedInitData = /* @__PURE__ */ new Map();\n for (const candidate of innermostCandidates) {\n const closureVars = hasDirective(candidate.fnNode, \"no-worklet-closure\") ? [] : getClosureVariables(candidate.fnNode, globals);\n const fnName = candidate.name;\n const serializedCode = serializeWorkletForUI(\n candidate.fnNode,\n currentCode,\n fnName,\n closureVars\n );\n const workletHash = calculateWorkletHash(serializedCode);\n const initDataVar = `_worklet_${workletHash}_init_data`;\n const initDataDecl = `var ${initDataVar} = {\n code: ${JSON.stringify(serializedCode)},\n location: ${JSON.stringify(location)}\n};`;\n const enclosingFn = hasDirective(candidate.fnNode, \"limit-init-data-hoisting\") ? findEnclosingFunction(parseResult.program, candidate.fnNode) : void 0;\n if (enclosingFn) {\n const insertAt = bodyStartAfterDirectives(enclosingFn, currentCode);\n let declared = inlinedInitData.get(insertAt);\n if (!declared) {\n declared = /* @__PURE__ */ new Set();\n inlinedInitData.set(insertAt, declared);\n }\n if (!declared.has(initDataVar)) {\n declared.add(initDataVar);\n ms.appendLeft(insertAt, `\n${initDataDecl}\n`);\n }\n } else if (!initDataDefs.has(initDataVar)) {\n initDataDefs.set(initDataVar, initDataDecl);\n }\n const localFnCode = buildLocalFunction(candidate.fnNode, currentCode, fnName);\n const localName = fnName || \"_worklet\";\n const closureProps = closureVars.map((v) => `${v}: ${v}`).join(\", \");\n const iife = `(function () {\n var _e = [new (typeof global !== 'undefined' ? global : globalThis).Error(), 1, -27];\n var ${localName} = ${localFnCode};\n ${localName}.__closure = { ${closureProps} };\n ${localName}.__workletHash = ${workletHash};\n ${localName}.__pluginVersion = ${JSON.stringify(pluginVersion)};\n ${localName}.__initData = ${initDataVar};\n ${localName}.__stackDetails = _e;\n return ${localName};\n})()`;\n if (candidate.kind === \"function_declaration\") {\n if (candidate.parent?.type === \"ExportNamedDeclaration\") {\n ms.overwrite(\n candidate.parent.start,\n candidate.parent.end,\n `export var ${candidate.name} = ${iife};`\n );\n } else if (candidate.parent?.type === \"ExportDefaultDeclaration\") {\n ms.overwrite(\n candidate.parent.start,\n candidate.parent.end,\n `var ${candidate.name || \"_defaultWorklet\"} = ${iife};\nexport default ${candidate.name || \"_defaultWorklet\"};`\n );\n } else {\n ms.overwrite(\n candidate.node.start,\n candidate.node.end,\n `var ${candidate.name} = ${iife};`\n );\n }\n } else if (candidate.kind === \"object_method\") {\n ms.overwrite(\n candidate.node.start,\n candidate.node.end,\n `${candidate.name}: ${iife}`\n );\n } else {\n ms.overwrite(candidate.node.start, candidate.node.end, iife);\n }\n }\n if (sourceMaps) {\n passMaps.push(\n ms.generateMap({\n source: cleanId,\n file: cleanId,\n hires: true,\n includeContent: true\n })\n );\n }\n currentCode = ms.toString();\n }\n const finalCheck = parseSync(cleanId, currentCode, { sourceType: \"module\", lang });\n const remaining = findWorkletCandidates(finalCheck.program);\n if (remaining.length > 0) {\n throw new Error(\n `[worklets] Exceeded maximum pass budget while transforming worklets in ${cleanId}. ${remaining.length} worklet(s) remained untransformed.`\n );\n }\n if (initDataDefs.size > 0) {\n const initDataCode = Array.from(initDataDefs.values()).join(\"\\n\") + \"\\n\";\n const msPrepend = new MagicString(currentCode);\n msPrepend.prepend(initDataCode);\n if (sourceMaps) {\n passMaps.push(\n msPrepend.generateMap({\n source: cleanId,\n file: cleanId,\n hires: true,\n includeContent: true\n })\n );\n }\n currentCode = msPrepend.toString();\n }\n let map = void 0;\n if (sourceMaps && passMaps.length > 0) {\n if (passMaps.length === 1) {\n map = passMaps[0];\n } else {\n map = remapping(passMaps.slice().reverse(), () => null);\n }\n if (map) {\n map.sources = [cleanId];\n map.file = cleanId;\n }\n }\n return {\n code: currentCode,\n map\n };\n}\nexport {\n executeWorkletTransform,\n prepareWorkletsForReactCompiler\n};\n//# sourceMappingURL=transform.js.map\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,iCAAiC,IAAI,IAAI;CAC7C;CACA;CACA;AACF,CAAC;AACD,SAAS,gCAAgC,IAAI,MAAM,aAAa,OAAO;CACrE,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,CAAC;CAC9B,MAAM,SAAS,UAAU,SAAS,MAAM;EACtC,YAAY;EACZ,MAAM,aAAa,KAAK,OAAO,IAAI,OAAO,QAAQ,SAAS,MAAM,IAAI,QAAQ;CAC/E,CAAC;CACD,IAAI,OAAO,OAAO,QAAQ;EACxB,MAAM,QAAQ,OAAO,OAAO;EAC5B,MAAM,IAAI,MACR,MAAM,aAAa,MAAM,WAAW,oCACtC;CACF;CACA,MAAM,aAAa,sBAAsB,OAAO,OAAO,CAAC,CAAC,QACtD,cAAc,UAAU,iBAAiB,CAAC,aAAa,UAAU,QAAQ,SAAS,CACrF;CACA,IAAI,CAAC,WAAW,QAAQ,OAAO;CAC/B,MAAM,SAAS,IAAI,YAAY,IAAI;CACnC,KAAK,MAAM,EAAE,YAAY,YAAY;EACnC,MAAM,OAAO,OAAO;EACpB,IAAI,KAAK,SAAS,kBAAkB;GAClC,OAAO,WAAW,KAAK,QAAQ,GAAG,YAAY;EAChD,OAAO;GACL,OAAO,WAAW,KAAK,OAAO,uBAAuB;GACrD,OAAO,WAAW,KAAK,KAAK,MAAM;EACpC;CACF;CACA,OAAO;EACL,MAAM,OAAO,SAAS;EACtB,KAAK,aAAa,OAAO,YAAY;GAAE,QAAQ;GAAS,OAAO;GAAM,gBAAgB;EAAK,CAAC,IAAI,KAAK;CACtG;AAC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EACjB,OAAO;GACL,MAAM,UAAU,SAAS,MAAM,CAAC,CAAC,QAAQ,SAAS,IAAI;EACxD;EACA,IAAI,KAAK;GACP,IAAI,UAAU,CAAC,OAAO;GACtB,IAAI,OAAO;EACb;CACF;CACA,OAAO;EACL,MAAM;EACN;CACF;AACF"}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vxrn/compiler",
3
- "version": "2.0.0-beta.33.1",
3
+ "version": "2.0.0-beta.45.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -36,12 +36,13 @@
36
36
  "@babel/plugin-transform-react-jsx": "^7.27.1",
37
37
  "@babel/plugin-transform-regenerator": "^7.28.4",
38
38
  "@jridgewell/remapping": "^2.3.0",
39
- "@vxrn/utils": "2.0.0-beta.33.1",
40
- "@vxrn/vite-native-client": "2.0.0-beta.33.1",
39
+ "@vxrn/utils": "2.0.0-beta.45.1",
40
+ "@vxrn/vite-native-client": "2.0.0-beta.45.1",
41
41
  "babel-plugin-react-compiler": "^1.0.0",
42
- "babel-plugin-syntax-hermes-parser": "^0.32.0",
42
+ "babel-plugin-syntax-hermes-parser": "^0.36.1",
43
+ "babel-plugin-transform-flow-enums": "^0.0.2",
43
44
  "esbuild": "^0.25.12",
44
- "hermes-parser": "^0.32.0",
45
+ "hermes-parser": "^0.36.1",
45
46
  "magic-string": "^0.30.21",
46
47
  "oxc-parser": "^0.112.0",
47
48
  "oxc-transform": "^0.148.0",
@@ -50,7 +51,7 @@
50
51
  },
51
52
  "devDependencies": {
52
53
  "@jridgewell/trace-mapping": "^0.3.25",
53
- "@tamagui/build": "2.6.2",
54
+ "@tamagui/build": "3.0.0-beta.1309.1",
54
55
  "depcheck": "^1.4.7",
55
56
  "rolldown": "^1.2.8",
56
57
  "vite": "^8.2.2",
package/src/cache.ts CHANGED
@@ -50,7 +50,7 @@ function getCacheDir(): string {
50
50
  }
51
51
 
52
52
  // hash config state so cache invalidates when compiler/reanimated/nativewind toggles change
53
- function getConfigFingerprint(): string {
53
+ function getConfigFingerprint(userBabelConfigPath?: string | null): string {
54
54
  return createHash('sha1')
55
55
  .update(
56
56
  JSON.stringify({
@@ -59,6 +59,10 @@ function getConfigFingerprint(): string {
59
59
  nativeWorklets: isNativeWorkletsEnabled(),
60
60
  nativewind: configuration.enableNativewind,
61
61
  nativeCSS: configuration.enableNativeCSS,
62
+ // transform output depends on the user babel config when one applies,
63
+ // so its identity joins the fingerprint. adding, removing, or editing
64
+ // babel.config.* must miss entries written without that change.
65
+ babelConfig: getBabelConfigIdentity(userBabelConfigPath),
62
66
  // bump when the transform engine changes, so entries written by a
63
67
  // previous engine aren't served for the same source
64
68
  engine: 'oxc-worklets-hermes-async',
@@ -68,9 +72,33 @@ function getConfigFingerprint(): string {
68
72
  .slice(0, 8)
69
73
  }
70
74
 
71
- function getCacheKey(filePath: string, environment: string): string {
75
+ // identity of the user babel config influencing a transform: path plus mtime
76
+ // and content hash, or null when none applies. mtime alone misses edits that
77
+ // preserve it, content alone misses same-byte swaps across paths. cheap: the
78
+ // file is tiny and its path is already resolved by the caller.
79
+ function getBabelConfigIdentity(configPath?: string | null): string | null {
80
+ if (!configPath) return null
81
+ try {
82
+ const mtime = statSync(configPath).mtimeMs
83
+ const hash = createHash('sha1')
84
+ .update(readFileSync(configPath))
85
+ .digest('hex')
86
+ .slice(0, 16)
87
+ return `${configPath}:${mtime}:${hash}`
88
+ } catch {
89
+ // deleted or unreadable between resolve and hash: the path alone still
90
+ // distinguishes this entry from the no-config one.
91
+ return configPath
92
+ }
93
+ }
94
+
95
+ function getCacheKey(
96
+ filePath: string,
97
+ environment: string,
98
+ userBabelConfigPath?: string | null
99
+ ): string {
72
100
  const hash = createHash('sha1')
73
- .update(`${environment}:${filePath}:${getConfigFingerprint()}`)
101
+ .update(`${environment}:${filePath}:${getConfigFingerprint(userBabelConfigPath)}`)
74
102
  .digest('hex')
75
103
  return hash
76
104
  }
@@ -83,13 +111,14 @@ function getContentHash(code: string): string {
83
111
  export function getCachedTransform(
84
112
  filePath: string,
85
113
  code: string,
86
- environment: string
114
+ environment: string,
115
+ userBabelConfigPath?: string | null
87
116
  ): { code: string; map?: any } | null {
88
117
  try {
89
118
  // Strip leading null byte (Vite virtual module prefix) if present
90
119
  const cleanPath = filePath.startsWith('\0') ? filePath.slice(1) : filePath
91
120
  const cacheDir = getCacheDir()
92
- const cacheKey = getCacheKey(cleanPath, environment)
121
+ const cacheKey = getCacheKey(cleanPath, environment, userBabelConfigPath)
93
122
  const cachePath = join(cacheDir, `${cacheKey}.json`)
94
123
 
95
124
  if (!existsSync(cachePath)) {
@@ -126,13 +155,14 @@ export function setCachedTransform(
126
155
  filePath: string,
127
156
  code: string,
128
157
  result: { code: string; map?: any },
129
- environment: string
158
+ environment: string,
159
+ userBabelConfigPath?: string | null
130
160
  ): void {
131
161
  try {
132
162
  // Strip leading null byte (Vite virtual module prefix) if present
133
163
  const cleanPath = filePath.startsWith('\0') ? filePath.slice(1) : filePath
134
164
  const cacheDir = getCacheDir()
135
- const cacheKey = getCacheKey(cleanPath, environment)
165
+ const cacheKey = getCacheKey(cleanPath, environment, userBabelConfigPath)
136
166
  const cachePath = join(cacheDir, `${cacheKey}.json`)
137
167
 
138
168
  const mtime = statSync(cleanPath).mtimeMs