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