@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.
- package/dist/cjs/cache.cjs +112 -109
- package/dist/cjs/configure.cjs +26 -28
- package/dist/cjs/constants.cjs +56 -60
- package/dist/cjs/index.cjs +420 -438
- 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 +278 -218
- 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 +96 -89
- 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 -420
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +417 -420
- 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 +261 -194
- 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/cache.ts +37 -7
- package/src/index.ts +33 -18
- package/src/transformBabel.test.ts +311 -1
- package/src/transformBabel.ts +110 -13
- package/src/transformWorklets.test.ts +7 -1
- package/types/cache.d.ts +2 -2
- package/types/cache.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/transformBabel.d.ts +16 -1
- 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 -360
- 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 -337
- 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
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 =
|
|
44
|
-
const IMPORT_UIMANAGER =
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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([
|
|
128
|
+
const NULLISH_TYPES = /* @__PURE__ */ new Set([
|
|
129
|
+
"TSUndefinedKeyword",
|
|
130
|
+
"TSNullKeyword",
|
|
131
|
+
"TSVoidKeyword",
|
|
132
|
+
"NullLiteralTypeAnnotation",
|
|
133
|
+
"VoidTypeAnnotation"
|
|
134
|
+
]);
|
|
150
135
|
function readUnion(node) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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([
|
|
166
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
347
|
-
|
|
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
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
358
|
+
}
|
|
359
|
+
lines.push(attrLines.length ? ` validAttributes: {
|
|
377
360
|
${attrLines.join(",\n")}
|
|
378
361
|
}` : " validAttributes: {}");
|
|
379
|
-
|
|
362
|
+
return `{
|
|
380
363
|
${lines.join(",\n")}
|
|
381
364
|
}`;
|
|
382
365
|
}
|
|
383
366
|
function printCommands(commands) {
|
|
384
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
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
|
-
|
|
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
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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
|
+
}
|