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