@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
|
@@ -3,70 +3,93 @@ 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 autoworklet_exports = {};
|
|
24
22
|
__export(autoworklet_exports, {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
AUTOWORKLET_FUNCTION_ARGS: () => AUTOWORKLET_FUNCTION_ARGS,
|
|
24
|
+
GESTURE_BUILDER_METHODS: () => GESTURE_BUILDER_METHODS,
|
|
25
|
+
WORKLET_DIRECTIVES: () => WORKLET_DIRECTIVES,
|
|
26
|
+
bodyStartAfterDirectives: () => bodyStartAfterDirectives,
|
|
27
|
+
findWorkletCandidates: () => findWorkletCandidates,
|
|
28
|
+
hasDirective: () => hasDirective,
|
|
29
|
+
hasWorkletDirective: () => hasWorkletDirective
|
|
32
30
|
});
|
|
33
31
|
module.exports = __toCommonJS(autoworklet_exports);
|
|
34
|
-
const AUTOWORKLET_FUNCTION_ARGS = Object.assign(/* @__PURE__ */Object.create(null), {
|
|
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
|
-
|
|
32
|
+
const AUTOWORKLET_FUNCTION_ARGS = Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
33
|
+
useFrameCallback: [0],
|
|
34
|
+
useAnimatedStyle: [0],
|
|
35
|
+
useAnimatedProps: [0],
|
|
36
|
+
createAnimatedPropAdapter: [0],
|
|
37
|
+
useDerivedValue: [0],
|
|
38
|
+
useAnimatedScrollHandler: [0],
|
|
39
|
+
useAnimatedGestureHandler: [0],
|
|
40
|
+
useAnimatedReaction: [0, 1],
|
|
41
|
+
withTiming: [2],
|
|
42
|
+
withSpring: [2],
|
|
43
|
+
withDecay: [1],
|
|
44
|
+
withRepeat: [3],
|
|
45
|
+
runOnUI: [0],
|
|
46
|
+
executeOnUIRuntimeSync: [0],
|
|
47
|
+
scheduleOnUI: [0],
|
|
48
|
+
runOnUISync: [0],
|
|
49
|
+
runOnUIAsync: [0],
|
|
50
|
+
runOnRuntime: [1],
|
|
51
|
+
runOnRuntimeSync: [1],
|
|
52
|
+
runOnRuntimeAsync: [1],
|
|
53
|
+
scheduleOnRuntime: [1],
|
|
54
|
+
runOnRuntimeSyncWithId: [1],
|
|
55
|
+
scheduleOnRuntimeWithId: [1],
|
|
56
|
+
useTapGesture: [0],
|
|
57
|
+
usePanGesture: [0],
|
|
58
|
+
usePinchGesture: [0],
|
|
59
|
+
useRotationGesture: [0],
|
|
60
|
+
useFlingGesture: [0],
|
|
61
|
+
useLongPressGesture: [0],
|
|
62
|
+
useNativeGesture: [0],
|
|
63
|
+
useManualGesture: [0],
|
|
64
|
+
useHoverGesture: [0]
|
|
67
65
|
});
|
|
68
|
-
const GESTURE_BUILDER_METHODS = /* @__PURE__ */new Set([
|
|
69
|
-
|
|
66
|
+
const GESTURE_BUILDER_METHODS = /* @__PURE__ */ new Set([
|
|
67
|
+
"onBegin",
|
|
68
|
+
"onStart",
|
|
69
|
+
"onEnd",
|
|
70
|
+
"onFinalize",
|
|
71
|
+
"onUpdate",
|
|
72
|
+
"onChange",
|
|
73
|
+
"onTouchesDown",
|
|
74
|
+
"onTouchesMove",
|
|
75
|
+
"onTouchesUp",
|
|
76
|
+
"onTouchesCancelled"
|
|
77
|
+
]);
|
|
78
|
+
const GESTURE_KINDS = /* @__PURE__ */ new Set([
|
|
79
|
+
"Tap",
|
|
80
|
+
"Pan",
|
|
81
|
+
"Pinch",
|
|
82
|
+
"Rotation",
|
|
83
|
+
"Fling",
|
|
84
|
+
"LongPress",
|
|
85
|
+
"ForceTouch",
|
|
86
|
+
"Native",
|
|
87
|
+
"Manual",
|
|
88
|
+
"Race",
|
|
89
|
+
"Simultaneous",
|
|
90
|
+
"Exclusive",
|
|
91
|
+
"Hover"
|
|
92
|
+
]);
|
|
70
93
|
const LAYOUT_ANIMATIONS = new Set(`BounceIn BounceInDown BounceInLeft BounceInRight BounceInUp BounceOut BounceOutDown
|
|
71
94
|
BounceOutLeft BounceOutRight BounceOutUp FadeIn FadeInDown FadeInLeft FadeInRight FadeInUp
|
|
72
95
|
FadeOut FadeOutDown FadeOutLeft FadeOutRight FadeOutUp FlipInEasyX FlipInEasyY FlipInXDown
|
|
@@ -80,186 +103,218 @@ const LAYOUT_ANIMATIONS = new Set(`BounceIn BounceInDown BounceInLeft BounceInRi
|
|
|
80
103
|
ZoomInRotate ZoomInUp ZoomOut ZoomOutDown ZoomOutEasyDown ZoomOutEasyUp ZoomOutLeft
|
|
81
104
|
ZoomOutRight ZoomOutRotate ZoomOutUp Layout LinearTransition SequencedTransition
|
|
82
105
|
FadingTransition JumpingTransition CurvedTransition EntryExitTransition`.split(/\s+/));
|
|
83
|
-
const LAYOUT_ANIMATION_CHAIN_METHODS = /* @__PURE__ */new Set([
|
|
106
|
+
const LAYOUT_ANIMATION_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
107
|
+
"build",
|
|
108
|
+
"duration",
|
|
109
|
+
"delay",
|
|
110
|
+
"getDuration",
|
|
111
|
+
"randomDelay",
|
|
112
|
+
"getDelay",
|
|
113
|
+
"getDelayFunction",
|
|
114
|
+
"easing",
|
|
115
|
+
"rotate",
|
|
116
|
+
"springify",
|
|
117
|
+
"damping",
|
|
118
|
+
"mass",
|
|
119
|
+
"stiffness",
|
|
120
|
+
"overshootClamping",
|
|
121
|
+
"energyThreshold",
|
|
122
|
+
"restDisplacementThreshold",
|
|
123
|
+
"restSpeedThreshold",
|
|
124
|
+
"withInitialValues",
|
|
125
|
+
"getAnimationAndConfig",
|
|
126
|
+
"easingX",
|
|
127
|
+
"easingY",
|
|
128
|
+
"easingWidth",
|
|
129
|
+
"easingHeight",
|
|
130
|
+
"entering",
|
|
131
|
+
"exiting",
|
|
132
|
+
"reverse"
|
|
133
|
+
]);
|
|
84
134
|
function isGestureObject(exp) {
|
|
85
|
-
|
|
135
|
+
return exp?.type === "CallExpression" && exp.callee?.type === "MemberExpression" && exp.callee.object?.type === "Identifier" && exp.callee.object.name === "Gesture" && exp.callee.property?.type === "Identifier" && GESTURE_KINDS.has(exp.callee.property.name);
|
|
86
136
|
}
|
|
87
137
|
function containsGestureObject(exp) {
|
|
88
|
-
|
|
89
|
-
|
|
138
|
+
if (isGestureObject(exp)) return true;
|
|
139
|
+
return exp?.type === "CallExpression" && exp.callee?.type === "MemberExpression" && containsGestureObject(exp.callee.object);
|
|
90
140
|
}
|
|
91
141
|
function isLayoutAnimationChain(exp) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
142
|
+
if (exp?.type === "Identifier" && LAYOUT_ANIMATIONS.has(exp.name)) return true;
|
|
143
|
+
if (exp?.type === "NewExpression" && exp.callee?.type === "Identifier" && LAYOUT_ANIMATIONS.has(exp.callee.name)) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return exp?.type === "CallExpression" && exp.callee?.type === "MemberExpression" && exp.callee.property?.type === "Identifier" && LAYOUT_ANIMATION_CHAIN_METHODS.has(exp.callee.property.name) && isLayoutAnimationChain(exp.callee.object);
|
|
97
147
|
}
|
|
98
148
|
function isChainedCallback(callee) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
149
|
+
if (callee?.type !== "MemberExpression" || callee.property?.type !== "Identifier") {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const name = callee.property.name;
|
|
153
|
+
if (GESTURE_BUILDER_METHODS.has(name)) return containsGestureObject(callee.object);
|
|
154
|
+
if (name === "withCallback") return isLayoutAnimationChain(callee.object);
|
|
155
|
+
return false;
|
|
106
156
|
}
|
|
107
|
-
const WORKLET_DIRECTIVES = [
|
|
157
|
+
const WORKLET_DIRECTIVES = [
|
|
158
|
+
"worklet",
|
|
159
|
+
"no-worklet-closure",
|
|
160
|
+
"limit-init-data-hoisting"
|
|
161
|
+
];
|
|
108
162
|
function statementDirective(stmt) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
163
|
+
if (!stmt || stmt.type !== "ExpressionStatement") return void 0;
|
|
164
|
+
if (typeof stmt.directive === "string") return stmt.directive;
|
|
165
|
+
if (stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string") {
|
|
166
|
+
return stmt.expression.value;
|
|
167
|
+
}
|
|
168
|
+
return void 0;
|
|
115
169
|
}
|
|
116
170
|
function hasDirective(fnNode, directive) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
171
|
+
if (!fnNode || !fnNode.body) return false;
|
|
172
|
+
if (Array.isArray(fnNode.body.directives)) {
|
|
173
|
+
for (const d of fnNode.body.directives) {
|
|
174
|
+
if (d.directive === directive || d.value === directive) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (fnNode.body.type === "BlockStatement" && Array.isArray(fnNode.body.body)) {
|
|
180
|
+
for (const stmt of fnNode.body.body) {
|
|
181
|
+
const found = statementDirective(stmt);
|
|
182
|
+
if (found === void 0) break;
|
|
183
|
+
if (found === directive) return true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
133
187
|
}
|
|
134
188
|
function hasWorkletDirective(fnNode) {
|
|
135
|
-
|
|
189
|
+
return hasDirective(fnNode, "worklet");
|
|
136
190
|
}
|
|
137
191
|
function bodyStartAfterDirectives(fnNode, code) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
192
|
+
let start = fnNode.body.start + 1;
|
|
193
|
+
if (fnNode.body.type !== "BlockStatement" || !Array.isArray(fnNode.body.body)) return start;
|
|
194
|
+
for (const stmt of fnNode.body.body) {
|
|
195
|
+
const found = statementDirective(stmt);
|
|
196
|
+
if (found === void 0 || !WORKLET_DIRECTIVES.includes(found)) break;
|
|
197
|
+
start = stmt.end;
|
|
198
|
+
while (start < fnNode.body.end && (code[start] === ";" || /\s/.test(code[start]))) {
|
|
199
|
+
start++;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return start;
|
|
149
203
|
}
|
|
150
204
|
function findWorkletCandidates(program) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
205
|
+
const candidates = [];
|
|
206
|
+
const seenStarts = /* @__PURE__ */ new Set();
|
|
207
|
+
function addCandidate(candidate) {
|
|
208
|
+
const fnStart = candidate.fnNode.start;
|
|
209
|
+
if (seenStarts.has(fnStart)) return;
|
|
210
|
+
seenStarts.add(fnStart);
|
|
211
|
+
candidates.push(candidate);
|
|
212
|
+
}
|
|
213
|
+
function getCalleeName(callee) {
|
|
214
|
+
if (!callee) return null;
|
|
215
|
+
if (callee.type === "Identifier") {
|
|
216
|
+
return callee.name;
|
|
217
|
+
}
|
|
218
|
+
if (callee.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier") {
|
|
219
|
+
return callee.property.name;
|
|
220
|
+
}
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
function walk(node, parent) {
|
|
224
|
+
if (!node || typeof node !== "object") return;
|
|
225
|
+
if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
|
|
226
|
+
if (hasWorkletDirective(node)) {
|
|
227
|
+
let kind = "function_expression";
|
|
228
|
+
if (node.type === "FunctionDeclaration") kind = "function_declaration";
|
|
229
|
+
else if (node.type === "ArrowFunctionExpression") kind = "arrow_function";
|
|
230
|
+
let name = node.id?.name;
|
|
231
|
+
if (!name && parent?.type === "VariableDeclarator" && parent.id?.name) {
|
|
232
|
+
name = parent.id.name;
|
|
233
|
+
}
|
|
234
|
+
addCandidate({
|
|
235
|
+
node,
|
|
236
|
+
fnNode: node,
|
|
237
|
+
kind,
|
|
238
|
+
name,
|
|
239
|
+
parent,
|
|
240
|
+
isAutoWorklet: false
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
} else if (node.type === "Property" && (node.method || node.value?.type === "FunctionExpression" || node.value?.type === "ArrowFunctionExpression")) {
|
|
244
|
+
const fn = node.value;
|
|
245
|
+
if (hasWorkletDirective(fn)) {
|
|
246
|
+
addCandidate({
|
|
247
|
+
node: node.method ? node : fn,
|
|
248
|
+
fnNode: fn,
|
|
249
|
+
kind: node.method ? "object_method" : fn.type === "ArrowFunctionExpression" ? "arrow_function" : "function_expression",
|
|
250
|
+
name: node.key?.name,
|
|
251
|
+
parent,
|
|
252
|
+
isAutoWorklet: false
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (node.type === "CallExpression") {
|
|
257
|
+
const calleeName = getCalleeName(node.callee);
|
|
258
|
+
const argIndices = calleeName ? AUTOWORKLET_FUNCTION_ARGS[calleeName] : void 0;
|
|
259
|
+
const chained = !argIndices && isChainedCallback(node.callee);
|
|
260
|
+
const indices = argIndices ?? (chained ? node.arguments.map((_, i) => i) : void 0);
|
|
261
|
+
if (indices) {
|
|
262
|
+
for (const idx of indices) {
|
|
263
|
+
const arg = node.arguments[idx];
|
|
264
|
+
if (!arg) continue;
|
|
265
|
+
if (arg.type === "ArrowFunctionExpression" || arg.type === "FunctionExpression") {
|
|
266
|
+
let name = arg.id?.name;
|
|
267
|
+
if (!name && parent?.type === "VariableDeclarator" && parent.id?.name) {
|
|
268
|
+
name = parent.id.name;
|
|
269
|
+
}
|
|
270
|
+
addCandidate({
|
|
271
|
+
node: arg,
|
|
272
|
+
fnNode: arg,
|
|
273
|
+
kind: arg.type === "ArrowFunctionExpression" ? "arrow_function" : "function_expression",
|
|
274
|
+
name,
|
|
275
|
+
parent: node,
|
|
276
|
+
isAutoWorklet: true
|
|
277
|
+
});
|
|
278
|
+
} else if (arg.type === "ObjectExpression" && Array.isArray(arg.properties)) {
|
|
279
|
+
for (const prop of arg.properties) {
|
|
280
|
+
if (prop.type === "Property") {
|
|
281
|
+
if (prop.method) {
|
|
282
|
+
addCandidate({
|
|
283
|
+
node: prop,
|
|
284
|
+
fnNode: prop.value,
|
|
285
|
+
kind: "object_method",
|
|
286
|
+
name: prop.key?.name,
|
|
287
|
+
parent: arg,
|
|
288
|
+
isAutoWorklet: true
|
|
289
|
+
});
|
|
290
|
+
} else if (prop.value?.type === "ArrowFunctionExpression" || prop.value?.type === "FunctionExpression") {
|
|
291
|
+
addCandidate({
|
|
292
|
+
node: prop.value,
|
|
293
|
+
fnNode: prop.value,
|
|
294
|
+
kind: prop.value.type === "ArrowFunctionExpression" ? "arrow_function" : "function_expression",
|
|
295
|
+
name: prop.key?.name,
|
|
296
|
+
parent: prop,
|
|
297
|
+
isAutoWorklet: true
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
for (const key of Object.keys(node)) {
|
|
307
|
+
if (key === "start" || key === "end" || key === "loc" || key === "range") continue;
|
|
308
|
+
const child = node[key];
|
|
309
|
+
if (Array.isArray(child)) {
|
|
310
|
+
for (const item of child) {
|
|
311
|
+
walk(item, node);
|
|
312
|
+
}
|
|
313
|
+
} else if (child && typeof child === "object") {
|
|
314
|
+
walk(child, node);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
walk(program, null);
|
|
319
|
+
return candidates;
|
|
320
|
+
}
|