@vxrn/compiler 1.25.13 → 1.25.16-1788753284749

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 (124) hide show
  1. package/dist/cjs/cache.cjs +3 -1
  2. package/dist/cjs/configure.cjs +9 -1
  3. package/dist/cjs/index.cjs +82 -4
  4. package/dist/cjs/reactNativeCodegen.cjs +140 -0
  5. package/dist/cjs/reactNativeViewConfig.cjs +489 -0
  6. package/dist/cjs/transformBabel.cjs +15 -20
  7. package/dist/cjs/transformBabel.test.cjs +260 -0
  8. package/dist/cjs/transformHermesLoops.cjs +317 -0
  9. package/dist/cjs/transformHermesLoops.test.cjs +220 -0
  10. package/dist/cjs/transformSWC.cjs +102 -137
  11. package/dist/cjs/transformSWC.test.cjs +74 -0
  12. package/dist/cjs/transformWorklets.cjs +121 -0
  13. package/dist/cjs/transformWorklets.test.cjs +604 -0
  14. package/dist/cjs/worklets/autoworklet.cjs +265 -0
  15. package/dist/cjs/worklets/globals.cjs +71 -0
  16. package/dist/cjs/worklets/hash.cjs +38 -0
  17. package/dist/cjs/worklets/scope.cjs +370 -0
  18. package/dist/cjs/worklets/serialize.cjs +101 -0
  19. package/dist/cjs/worklets/transform.cjs +232 -0
  20. package/dist/cjs/worklets/types.cjs +18 -0
  21. package/dist/esm/cache.mjs +4 -2
  22. package/dist/esm/cache.mjs.map +1 -1
  23. package/dist/esm/configure.mjs +8 -1
  24. package/dist/esm/configure.mjs.map +1 -1
  25. package/dist/esm/index.js +72 -5
  26. package/dist/esm/index.js.map +1 -1
  27. package/dist/esm/index.mjs +72 -5
  28. package/dist/esm/index.mjs.map +1 -1
  29. package/dist/esm/reactNativeCodegen.mjs +104 -0
  30. package/dist/esm/reactNativeCodegen.mjs.map +1 -0
  31. package/dist/esm/reactNativeViewConfig.mjs +460 -0
  32. package/dist/esm/reactNativeViewConfig.mjs.map +1 -0
  33. package/dist/esm/transformBabel.mjs +14 -19
  34. package/dist/esm/transformBabel.mjs.map +1 -1
  35. package/dist/esm/transformBabel.test.mjs +261 -1
  36. package/dist/esm/transformBabel.test.mjs.map +1 -1
  37. package/dist/esm/transformHermesLoops.mjs +281 -0
  38. package/dist/esm/transformHermesLoops.mjs.map +1 -0
  39. package/dist/esm/transformHermesLoops.test.mjs +197 -0
  40. package/dist/esm/transformHermesLoops.test.mjs.map +1 -0
  41. package/dist/esm/transformSWC.mjs +89 -138
  42. package/dist/esm/transformSWC.mjs.map +1 -1
  43. package/dist/esm/transformSWC.test.mjs +75 -0
  44. package/dist/esm/transformSWC.test.mjs.map +1 -0
  45. package/dist/esm/transformWorklets.mjs +81 -0
  46. package/dist/esm/transformWorklets.mjs.map +1 -0
  47. package/dist/esm/transformWorklets.test.mjs +581 -0
  48. package/dist/esm/transformWorklets.test.mjs.map +1 -0
  49. package/dist/esm/worklets/autoworklet.mjs +234 -0
  50. package/dist/esm/worklets/autoworklet.mjs.map +1 -0
  51. package/dist/esm/worklets/globals.mjs +45 -0
  52. package/dist/esm/worklets/globals.mjs.map +1 -0
  53. package/dist/esm/worklets/hash.mjs +13 -0
  54. package/dist/esm/worklets/hash.mjs.map +1 -0
  55. package/dist/esm/worklets/scope.mjs +345 -0
  56. package/dist/esm/worklets/scope.mjs.map +1 -0
  57. package/dist/esm/worklets/serialize.mjs +75 -0
  58. package/dist/esm/worklets/serialize.mjs.map +1 -0
  59. package/dist/esm/worklets/transform.mjs +196 -0
  60. package/dist/esm/worklets/transform.mjs.map +1 -0
  61. package/dist/esm/worklets/types.mjs +2 -0
  62. package/dist/esm/worklets/types.mjs.map +1 -0
  63. package/package.json +10 -6
  64. package/src/cache.ts +9 -2
  65. package/src/configure.ts +12 -0
  66. package/src/index.ts +93 -13
  67. package/src/reactNativeCodegen.ts +181 -0
  68. package/src/reactNativeViewConfig.ts +593 -0
  69. package/src/transformBabel.test.ts +268 -1
  70. package/src/transformBabel.ts +21 -31
  71. package/src/transformHermesLoops.test.ts +282 -0
  72. package/src/transformHermesLoops.ts +433 -0
  73. package/src/transformSWC.test.ts +88 -0
  74. package/src/transformSWC.ts +109 -160
  75. package/src/transformWorklets.test.ts +708 -0
  76. package/src/transformWorklets.ts +160 -0
  77. package/src/types.ts +4 -4
  78. package/src/worklets/autoworklet.ts +391 -0
  79. package/src/worklets/globals.ts +125 -0
  80. package/src/worklets/hash.ts +14 -0
  81. package/src/worklets/scope.ts +401 -0
  82. package/src/worklets/serialize.ts +114 -0
  83. package/src/worklets/transform.ts +282 -0
  84. package/src/worklets/types.ts +26 -0
  85. package/types/cache.d.ts +1 -0
  86. package/types/cache.d.ts.map +1 -1
  87. package/types/configure.d.ts +2 -0
  88. package/types/configure.d.ts.map +1 -1
  89. package/types/index.d.ts +3 -0
  90. package/types/index.d.ts.map +1 -1
  91. package/types/reactNativeCodegen.d.ts +5 -0
  92. package/types/reactNativeCodegen.d.ts.map +1 -0
  93. package/types/reactNativeViewConfig.d.ts +35 -0
  94. package/types/reactNativeViewConfig.d.ts.map +1 -0
  95. package/types/transformBabel.d.ts +3 -3
  96. package/types/transformBabel.d.ts.map +1 -1
  97. package/types/transformHermesLoops.d.ts +5 -0
  98. package/types/transformHermesLoops.d.ts.map +1 -0
  99. package/types/transformHermesLoops.test.d.ts +2 -0
  100. package/types/transformHermesLoops.test.d.ts.map +1 -0
  101. package/types/transformSWC.d.ts +12 -3
  102. package/types/transformSWC.d.ts.map +1 -1
  103. package/types/transformSWC.test.d.ts +2 -0
  104. package/types/transformSWC.test.d.ts.map +1 -0
  105. package/types/transformWorklets.d.ts +22 -0
  106. package/types/transformWorklets.d.ts.map +1 -0
  107. package/types/transformWorklets.test.d.ts +2 -0
  108. package/types/transformWorklets.test.d.ts.map +1 -0
  109. package/types/types.d.ts +4 -4
  110. package/types/types.d.ts.map +1 -1
  111. package/types/worklets/autoworklet.d.ts +14 -0
  112. package/types/worklets/autoworklet.d.ts.map +1 -0
  113. package/types/worklets/globals.d.ts +3 -0
  114. package/types/worklets/globals.d.ts.map +1 -0
  115. package/types/worklets/hash.d.ts +5 -0
  116. package/types/worklets/hash.d.ts.map +1 -0
  117. package/types/worklets/scope.d.ts +7 -0
  118. package/types/worklets/scope.d.ts.map +1 -0
  119. package/types/worklets/serialize.d.ts +12 -0
  120. package/types/worklets/serialize.d.ts.map +1 -0
  121. package/types/worklets/transform.d.ts +6 -0
  122. package/types/worklets/transform.d.ts.map +1 -0
  123. package/types/worklets/types.d.ts +21 -0
  124. package/types/worklets/types.d.ts.map +1 -0
@@ -0,0 +1,489 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var reactNativeViewConfig_exports = {};
24
+ __export(reactNativeViewConfig_exports, {
25
+ generateViewConfig: () => generateViewConfig,
26
+ getLibraryName: () => getLibraryName,
27
+ parseSpec: () => parseSpec,
28
+ renderViewConfigModule: () => renderViewConfigModule
29
+ });
30
+ module.exports = __toCommonJS(reactNativeViewConfig_exports);
31
+ var import_node_module = require("node:module");
32
+ var import_node_path = require("node:path");
33
+ var import_oxc_parser = require("oxc-parser");
34
+ const import_meta = {};
35
+ const SELF_URL = typeof __filename !== "undefined" ? __filename : import_meta.url;
36
+ const COLOR_ATTRIBUTE = "require('react-native/Libraries/Components/View/ReactNativeStyleAttributes').colorAttribute";
37
+ const COLOR_ARRAY_ATTRIBUTE = "{\n process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray'))\n }";
38
+ const IMAGE_ATTRIBUTE = "{\n process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Image/resolveAssetSource'))\n }";
39
+ const POINT_ATTRIBUTE = "{\n diff: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/pointsDiffer'))\n }";
40
+ const EDGE_INSETS_ATTRIBUTE = "{\n diff: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/Utilities/differ/insetsDiffer'))\n }";
41
+ const IMPORT_REGISTRY = "const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');";
42
+ const IMPORT_IGNORE = "const {ConditionallyIgnoredEventHandlers} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore');";
43
+ const IMPORT_DISPATCH = 'const {dispatchCommand} = require("react-native/Libraries/ReactNative/RendererProxy");';
44
+ const IMPORT_UIMANAGER = 'const {UIManager} = require("react-native-web")';
45
+ let hermesParser = void 0;
46
+ function getHermesParser(projectRoot) {
47
+ if (hermesParser === void 0) {
48
+ try {
49
+ const req = projectRoot ? (0, import_node_module.createRequire)((0, import_node_path.join)(projectRoot, "package.json")) : (0, import_node_module.createRequire)(SELF_URL);
50
+ hermesParser = req("hermes-parser");
51
+ } catch {
52
+ try {
53
+ hermesParser = (0, import_node_module.createRequire)(SELF_URL)("hermes-parser");
54
+ } catch {
55
+ hermesParser = null;
56
+ }
57
+ }
58
+ }
59
+ return hermesParser;
60
+ }
61
+ function readType(node) {
62
+ if (!node) return {
63
+ name: "",
64
+ args: []
65
+ };
66
+ switch (node.type) {
67
+ // flow
68
+ case "NullableTypeAnnotation":
69
+ case "TypeAnnotation":
70
+ return readType(node.typeAnnotation);
71
+ case "GenericTypeAnnotation":
72
+ return {
73
+ name: readTypeName(node.id),
74
+ args: (node.typeParameters?.params ?? []).map(readType)
75
+ };
76
+ case "ObjectTypeAnnotation":
77
+ return {
78
+ name: "__object",
79
+ args: []
80
+ };
81
+ case "StringTypeAnnotation":
82
+ return {
83
+ name: "string",
84
+ args: []
85
+ };
86
+ case "BooleanTypeAnnotation":
87
+ return {
88
+ name: "boolean",
89
+ args: []
90
+ };
91
+ case "NumberTypeAnnotation":
92
+ return {
93
+ name: "number",
94
+ args: []
95
+ };
96
+ case "UnionTypeAnnotation":
97
+ return readUnion(node);
98
+ case "FunctionTypeAnnotation":
99
+ return {
100
+ name: "__function",
101
+ args: []
102
+ };
103
+ // typescript
104
+ case "TSTypeAnnotation":
105
+ return readType(node.typeAnnotation);
106
+ case "TSTypeReference":
107
+ return {
108
+ name: readTypeName(node.typeName),
109
+ args: (node.typeArguments ?? node.typeParameters)?.params?.map(readType) ?? []
110
+ };
111
+ case "TSTypeLiteral":
112
+ return {
113
+ name: "__object",
114
+ args: []
115
+ };
116
+ case "TSStringKeyword":
117
+ return {
118
+ name: "string",
119
+ args: []
120
+ };
121
+ case "TSBooleanKeyword":
122
+ return {
123
+ name: "boolean",
124
+ args: []
125
+ };
126
+ case "TSNumberKeyword":
127
+ return {
128
+ name: "number",
129
+ args: []
130
+ };
131
+ case "TSUnionType":
132
+ return readUnion(node);
133
+ case "TSFunctionType":
134
+ return {
135
+ name: "__function",
136
+ args: []
137
+ };
138
+ case "TSArrayType":
139
+ return {
140
+ name: "Array",
141
+ args: [readType(node.elementType)]
142
+ };
143
+ }
144
+ return {
145
+ name: "__unknown",
146
+ args: []
147
+ };
148
+ }
149
+ const NULLISH_TYPES = /* @__PURE__ */new Set(["TSUndefinedKeyword", "TSNullKeyword", "TSVoidKeyword", "NullLiteralTypeAnnotation", "VoidTypeAnnotation"]);
150
+ function readUnion(node) {
151
+ const real = (node.types ?? []).filter(t => !NULLISH_TYPES.has(t.type));
152
+ if (real.length === 1) return readType(real[0]);
153
+ return {
154
+ name: "__union",
155
+ args: []
156
+ };
157
+ }
158
+ function readTypeName(id) {
159
+ if (!id) return "";
160
+ if (id.type === "Identifier") return id.name;
161
+ if (id.type === "QualifiedTypeIdentifier") return readTypeName(id.id);
162
+ if (id.type === "TSQualifiedName") return readTypeName(id.right);
163
+ return "";
164
+ }
165
+ const READONLY_ARRAYS = /* @__PURE__ */new Set(["ReadonlyArray", "$ReadOnlyArray", "Array"]);
166
+ const TRANSPARENT = /* @__PURE__ */new Set(["WithDefault", "UnsafeMixed", "Readonly", "$ReadOnly"]);
167
+ function unwrap(type) {
168
+ let cur = type;
169
+ while (TRANSPARENT.has(cur.name) && cur.args.length > 0) {
170
+ cur = cur.args[0];
171
+ }
172
+ return cur;
173
+ }
174
+ function attributeValue(type) {
175
+ const t = unwrap(type);
176
+ switch (t.name) {
177
+ case "ColorValue":
178
+ case "ProcessedColorValue":
179
+ return COLOR_ATTRIBUTE;
180
+ case "ImageSource":
181
+ return IMAGE_ATTRIBUTE;
182
+ case "PointValue":
183
+ return POINT_ATTRIBUTE;
184
+ case "EdgeInsetsValue":
185
+ return EDGE_INSETS_ATTRIBUTE;
186
+ }
187
+ if (READONLY_ARRAYS.has(t.name) && t.args.length === 1) {
188
+ const el = unwrap(t.args[0]);
189
+ if (el.name === "ColorValue" || el.name === "ProcessedColorValue") {
190
+ return COLOR_ARRAY_ATTRIBUTE;
191
+ }
192
+ }
193
+ return "true";
194
+ }
195
+ function eventOf(name, type) {
196
+ const t = unwrap(type);
197
+ if (t.name !== "DirectEventHandler" && t.name !== "BubblingEventHandler") return null;
198
+ const override = t.args[1]?.name;
199
+ return {
200
+ name,
201
+ bubbling: t.name === "BubblingEventHandler",
202
+ topName: normalizeInputEventName(override && override !== "__unknown" ? override : name)
203
+ };
204
+ }
205
+ function normalizeInputEventName(name) {
206
+ if (name.startsWith("on")) return name.replace(/^on/, "top");
207
+ if (!name.startsWith("top")) return `top${name[0].toUpperCase()}${name.slice(1)}`;
208
+ return name;
209
+ }
210
+ function collectDeclarations(body) {
211
+ const out = /* @__PURE__ */new Map();
212
+ for (const raw of body) {
213
+ const node = raw?.type === "ExportNamedDeclaration" ? raw.declaration : raw;
214
+ if (!node) continue;
215
+ switch (node.type) {
216
+ case "TSTypeAliasDeclaration":
217
+ case "TypeAlias":
218
+ case "TSInterfaceDeclaration":
219
+ case "InterfaceDeclaration":
220
+ if (node.id?.name) out.set(node.id.name, node);
221
+ break;
222
+ }
223
+ }
224
+ return out;
225
+ }
226
+ function flattenMembers(typeName, decls, seen = /* @__PURE__ */new Set()) {
227
+ if (typeName === "ViewProps" || seen.has(typeName)) return [];
228
+ seen.add(typeName);
229
+ const decl = decls.get(typeName);
230
+ if (!decl) return [];
231
+ const out = [];
232
+ const heritage = decl.extends ?? decl.heritage ?? [];
233
+ for (const h of heritage) {
234
+ const name = readTypeName(h.id ?? h.expression ?? h.typeName);
235
+ if (name) out.push(...flattenMembers(name, decls, seen));
236
+ }
237
+ const bodyNode = decl.body ??
238
+ // interface
239
+ decl.right ??
240
+ // type alias
241
+ decl.typeAnnotation;
242
+ out.push(...readObjectMembers(bodyNode, decls, seen));
243
+ return out;
244
+ }
245
+ function readObjectMembers(node, decls, seen) {
246
+ if (!node) return [];
247
+ if (node.type === "TSTypeReference" || node.type === "GenericTypeAnnotation") {
248
+ const name = readTypeName(node.typeName ?? node.id);
249
+ const args = (node.typeArguments ?? node.typeParameters)?.params ?? [];
250
+ if (TRANSPARENT.has(name) && args.length) {
251
+ return readObjectMembers(args[0], decls, seen);
252
+ }
253
+ return flattenMembers(name, decls, seen);
254
+ }
255
+ if (node.type === "TSIntersectionType" || node.type === "IntersectionTypeAnnotation") {
256
+ const out2 = [];
257
+ for (const t of node.types ?? []) out2.push(...readObjectMembers(t, decls, seen));
258
+ return out2;
259
+ }
260
+ const members = node.members ?? node.body ?? node.properties ?? [];
261
+ const out = [];
262
+ for (const m of members) {
263
+ switch (m.type) {
264
+ case "TSPropertySignature":
265
+ case "ObjectTypeProperty":
266
+ {
267
+ const name = m.key?.name ?? m.key?.value;
268
+ if (!name) break;
269
+ out.push({
270
+ name,
271
+ type: readType(m.typeAnnotation ?? m.value)
272
+ });
273
+ break;
274
+ }
275
+ // flow's `...OtherProps` inside an object type
276
+ case "ObjectTypeSpreadProperty":
277
+ {
278
+ const name = readTypeName(m.argument?.id ?? m.argument);
279
+ if (name) out.push(...flattenMembers(name, decls, seen));
280
+ break;
281
+ }
282
+ }
283
+ }
284
+ return out;
285
+ }
286
+ function findComponentCall(body) {
287
+ for (const node of body) {
288
+ if (node.type !== "ExportDefaultDeclaration") continue;
289
+ let expr = node.declaration;
290
+ while (expr) {
291
+ if (expr.type === "CallExpression") break;
292
+ expr = expr.expression ?? (expr.type === "SequenceExpression" ? expr.expressions[expr.expressions.length - 1] : null);
293
+ }
294
+ if (expr?.type === "CallExpression" && expr.callee?.name === "codegenNativeComponent") {
295
+ return expr;
296
+ }
297
+ }
298
+ return null;
299
+ }
300
+ function findCommandsCall(body) {
301
+ for (const raw of body) {
302
+ const node = raw?.type === "ExportNamedDeclaration" ? raw.declaration : raw;
303
+ const decl = node?.declarations?.[0];
304
+ let init = decl?.init;
305
+ while (init && init.type !== "CallExpression") init = init.expression;
306
+ if (init?.type === "CallExpression" && init.callee?.name === "codegenNativeCommands") {
307
+ return init;
308
+ }
309
+ }
310
+ return null;
311
+ }
312
+ function readStringOption(objectExpression, key) {
313
+ for (const p of objectExpression?.properties ?? []) {
314
+ if ((p.key?.name ?? p.key?.value) === key && typeof p.value?.value === "string") {
315
+ return p.value.value;
316
+ }
317
+ }
318
+ return null;
319
+ }
320
+ function readCommands(call, decls) {
321
+ const typeName = readTypeName((call.typeArguments ?? call.typeParameters)?.params?.[0]?.typeName ?? (call.typeArguments ?? call.typeParameters)?.params?.[0]?.id);
322
+ const supported = [];
323
+ for (const p of call.arguments?.[0]?.properties ?? []) {
324
+ if ((p.key?.name ?? p.key?.value) !== "supportedCommands") continue;
325
+ for (const el of p.value?.elements ?? []) {
326
+ if (typeof el?.value === "string") supported.push(el.value);
327
+ }
328
+ }
329
+ if (!supported.length) return [];
330
+ const decl = decls.get(typeName);
331
+ const byName = /* @__PURE__ */new Map();
332
+ const commandMembers = decl?.body?.body ?? decl?.body?.members ?? decl?.body?.properties ?? [];
333
+ for (const m of commandMembers) {
334
+ const name = m.key?.name ?? m.key?.value;
335
+ if (!name) continue;
336
+ const fn = m.typeAnnotation?.typeAnnotation ?? m.value ?? m.typeAnnotation;
337
+ const params = (fn?.params ?? fn?.parameters ?? []).slice(1);
338
+ byName.set(name, params.map((p, i) => p.name?.name ?? p.name ?? `arg${i}`));
339
+ }
340
+ return supported.map(name => ({
341
+ name,
342
+ params: byName.get(name) ?? []
343
+ }));
344
+ }
345
+ function indent(text, spaces) {
346
+ const pad = " ".repeat(spaces);
347
+ return text.split("\n").map((line, i) => i === 0 || line === "" ? line : pad + line).join("\n");
348
+ }
349
+ function printViewConfig(componentName, attributes, events) {
350
+ const lines = [` uiViewClassName: ${JSON.stringify(componentName)}`];
351
+ const bubbling = events.filter(e => e.bubbling);
352
+ if (bubbling.length) {
353
+ lines.push(` bubblingEventTypes: {
354
+ ${bubbling.map(e => ` ${e.topName}: {
355
+ phasedRegistrationNames: {
356
+ captured: ${JSON.stringify(`${e.name}Capture`)},
357
+ bubbled: ${JSON.stringify(e.name)}
358
+ }
359
+ }`).join(",\n")}
360
+ }`);
361
+ }
362
+ const direct = events.filter(e => !e.bubbling);
363
+ if (direct.length) {
364
+ lines.push(` directEventTypes: {
365
+ ${direct.map(e => ` ${e.topName}: {
366
+ registrationName: ${JSON.stringify(e.name)}
367
+ }`).join(",\n")}
368
+ }`);
369
+ }
370
+ const attrLines = attributes.map(a => ` ${a.name}: ${indent(a.value, 4)}`);
371
+ if (events.length) {
372
+ attrLines.push(` ...ConditionallyIgnoredEventHandlers({
373
+ ${events.map(e => ` ${e.name}: true`).join(",\n")}
374
+ })`);
375
+ }
376
+ lines.push(attrLines.length ? ` validAttributes: {
377
+ ${attrLines.join(",\n")}
378
+ }` : " validAttributes: {}");
379
+ return `{
380
+ ${lines.join(",\n")}
381
+ }`;
382
+ }
383
+ function printCommands(commands) {
384
+ return `export const Commands = {
385
+ ${commands.map(c => ` ${c.name}(ref${c.params.map(p => `, ${p}`).join("")}) {
386
+ dispatchCommand(ref, ${JSON.stringify(c.name)}, [${c.params.join(", ")}]);
387
+ }`).join(",\n")}
388
+ };`;
389
+ }
390
+ const FILE_HEADER = `/**
391
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
392
+ *
393
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
394
+ * once the code is regenerated.
395
+ *
396
+ * @flow
397
+ *
398
+ * @generated by codegen project: GenerateViewConfigJs.js
399
+ */
400
+
401
+ 'use strict';
402
+ `;
403
+ function parseSpec(code, filename, projectRoot) {
404
+ const isTS = /\.[cm]?tsx?$/.test(filename);
405
+ if (isTS) {
406
+ const result = (0, import_oxc_parser.parseSync)(filename, code, {
407
+ lang: filename.endsWith("x") ? "tsx" : "ts"
408
+ });
409
+ if (result.errors?.length) return null;
410
+ return result.program;
411
+ }
412
+ const hermes = getHermesParser(projectRoot);
413
+ if (!hermes) return null;
414
+ try {
415
+ return hermes.parse(code, {
416
+ babel: false,
417
+ flow: "all",
418
+ sourceFilename: filename
419
+ });
420
+ } catch {
421
+ return null;
422
+ }
423
+ }
424
+ function generateViewConfig(program) {
425
+ const body = program?.body;
426
+ if (!body) return null;
427
+ const call = findComponentCall(body);
428
+ if (!call) return null;
429
+ const componentNameArg = call.arguments?.[0];
430
+ if (typeof componentNameArg?.value !== "string") return null;
431
+ const componentName = componentNameArg.value;
432
+ const options = call.arguments?.[1];
433
+ const paperComponentName = readStringOption(options, "paperComponentName");
434
+ const paperComponentNameDeprecated = readStringOption(options, "paperComponentNameDeprecated");
435
+ const propsTypeName = readTypeName((call.typeArguments ?? call.typeParameters)?.params?.[0]?.typeName ?? (call.typeArguments ?? call.typeParameters)?.params?.[0]?.id);
436
+ if (!propsTypeName) return null;
437
+ const decls = collectDeclarations(body);
438
+ const members = flattenMembers(propsTypeName, decls);
439
+ const attributes = [];
440
+ const events = [];
441
+ for (const m of members) {
442
+ const event = eventOf(m.name, m.type);
443
+ if (event) {
444
+ events.push(event);
445
+ continue;
446
+ }
447
+ attributes.push({
448
+ name: m.name,
449
+ value: attributeValue(m.type)
450
+ });
451
+ }
452
+ const commandsCall = findCommandsCall(body);
453
+ const commands = commandsCall ? readCommands(commandsCall, decls) : [];
454
+ const imports = /* @__PURE__ */new Set([IMPORT_REGISTRY]);
455
+ if (events.length) imports.add(IMPORT_IGNORE);
456
+ if (commands.length) imports.add(IMPORT_DISPATCH);
457
+ if (paperComponentNameDeprecated) imports.add(IMPORT_UIMANAGER);
458
+ const nativeName = paperComponentName ?? componentName;
459
+ const parts = [`let nativeComponentName = '${nativeName}';`];
460
+ if (paperComponentNameDeprecated) {
461
+ parts.push(`if (UIManager.hasViewManagerConfig('${componentName}')) {
462
+ nativeComponentName = '${componentName}';
463
+ } else if (UIManager.hasViewManagerConfig('${paperComponentNameDeprecated}')) {
464
+ nativeComponentName = '${paperComponentNameDeprecated}';
465
+ } else {
466
+ throw new Error('Failed to find native component for either "${componentName}" or "${paperComponentNameDeprecated}"');
467
+ }`);
468
+ }
469
+ parts.push(`export const __INTERNAL_VIEW_CONFIG = ${printViewConfig(nativeName, attributes, events)};`);
470
+ parts.push("export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG);");
471
+ if (commands.length) parts.push(printCommands(commands));
472
+ return {
473
+ imports: [...imports].sort(),
474
+ body: parts.join("\n")
475
+ };
476
+ }
477
+ function renderViewConfigModule(result) {
478
+ return `
479
+ ${FILE_HEADER}
480
+ ${result.imports.join("\n")}
481
+
482
+ ${result.body}
483
+ `;
484
+ }
485
+ function getLibraryName(filename) {
486
+ const base = (0, import_node_path.basename)(filename);
487
+ const replaced = base.replace(/NativeComponent\.[cm]?[jt]sx?$/, "");
488
+ return replaced === base ? base.replace(/\.[cm]?[jt]sx?$/, "") : replaced;
489
+ }
@@ -39,9 +39,7 @@ __export(transformBabel_exports, {
39
39
  });
40
40
  module.exports = __toCommonJS(transformBabel_exports);
41
41
  var import_node_path = require("node:path");
42
- var import_core = __toESM(require("@babel/core"), 1);
43
42
  var import_utils = require("@vxrn/utils");
44
- var import_babel_plugin_syntax_hermes_parser = __toESM(require("babel-plugin-syntax-hermes-parser"), 1);
45
43
  var import_vite = require("vite");
46
44
  var import_configure = require("./configure.cjs");
47
45
  var import_constants = require("./constants.cjs");
@@ -77,17 +75,16 @@ const getOptions = (props, force = false) => {
77
75
  }
78
76
  }
79
77
  if (enableNativewind || shouldBabelReanimated(props)) {
80
- (0, import_constants.debug)?.(`Using babel worklets on file ${props.id}`);
81
- plugins.push((0, import_utils.resolvePath)("react-native-worklets/plugin", props.projectRoot));
78
+ try {
79
+ const workletsPlugin = (0, import_utils.resolvePath)("react-native-worklets/plugin", props.projectRoot);
80
+ (0, import_constants.debug)?.(`Using babel worklets on file ${props.id}`);
81
+ plugins.push(workletsPlugin);
82
+ } catch {}
82
83
  }
83
84
  if (shouldBabelReactCompiler(props)) {
84
85
  (0, import_constants.debug)?.(`Using babel react compiler on file`);
85
86
  plugins.push(getBabelReactCompilerPlugin(props));
86
87
  }
87
- if (shouldBabelReactNativeCodegen(props)) {
88
- (0, import_constants.debug)?.(`Using babel @react-native/babel-plugin-codegen on file`);
89
- plugins.push("@react-native/babel-plugin-codegen");
90
- }
91
88
  if (plugins.length) {
92
89
  return {
93
90
  plugins
@@ -95,12 +92,13 @@ const getOptions = (props, force = false) => {
95
92
  }
96
93
  return null;
97
94
  };
98
- async function transformOxcReactCompiler(id, code, target) {
95
+ async function transformOxcReactCompiler(id, code, target, sourceMap = false) {
99
96
  const {
100
97
  transform
101
98
  } = await import("oxc-transform-react");
102
99
  const result = await transform(id, code, {
103
100
  jsx: "preserve",
101
+ sourcemap: sourceMap,
104
102
  reactCompiler: {
105
103
  target
106
104
  }
@@ -113,10 +111,15 @@ async function transformOxcReactCompiler(id, code, target) {
113
111
  }
114
112
  return {
115
113
  code: result.code,
116
- map: void 0
114
+ map: sourceMap ? result.map : void 0
117
115
  };
118
116
  }
119
117
  async function transformBabel(id, code, options) {
118
+ const [{
119
+ default: babelCore
120
+ }, {
121
+ default: hermesParserPlugin
122
+ }] = await Promise.all([import("@babel/core"), import("babel-plugin-syntax-hermes-parser")]);
120
123
  const extension = (0, import_node_path.extname)(id);
121
124
  const isTSX = extension === ".tsx";
122
125
  const isTS = isTSX || extension === ".ts";
@@ -140,13 +143,13 @@ async function transformBabel(id, code, options) {
140
143
  // plugins like
141
144
  // @react-native/babel-plugin-codegen silently fail on RN specs and the runtime
142
145
  // "Codegen didn't run" warning fires. TS path is byte-identical (empty slice).
143
- plugins: [...(isTS ? [] : [[import_babel_plugin_syntax_hermes_parser.default, {
146
+ plugins: [...(isTS ? [] : [[hermesParserPlugin, {
144
147
  parseLangTypes: "flow",
145
148
  reactRuntimeTarget: "19"
146
149
  }]]), ...(options.plugins || []), ...(isTS ? [] : ["@babel/plugin-transform-flow-strip-types"])]
147
150
  };
148
151
  return await new Promise((res, rej) => {
149
- import_core.default.transform(code, babelOptions, (err, result) => {
152
+ babelCore.transform(code, babelOptions, (err, result) => {
150
153
  if (!result || err) {
151
154
  return rej(err || new Error(`[vxrn:compiler] babel returned no result for ${id}`));
152
155
  }
@@ -163,14 +166,6 @@ const getBasePlugins = ({
163
166
  // NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
164
167
  regenerator: false
165
168
  }]];
166
- const NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/;
167
- const SPEC_FILE_RE = /[/\\]specs?[/\\]/;
168
- const shouldBabelReactNativeCodegen = ({
169
- id,
170
- environment
171
- }) => {
172
- return (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id));
173
- };
174
169
  const shouldBabelReactCompiler = props => {
175
170
  if (props.environment === "ssr") {
176
171
  return false;