@vxrn/compiler 2.0.0-beta.33.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.
Files changed (94) 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/types/cache.d.ts +2 -2
  67. package/types/cache.d.ts.map +1 -1
  68. package/types/index.d.ts.map +1 -1
  69. package/types/transformBabel.d.ts +16 -1
  70. package/types/transformBabel.d.ts.map +1 -1
  71. package/types/transformSWC.d.ts +1 -4
  72. package/types/transformSWC.d.ts.map +1 -1
  73. package/dist/cjs/transformBabel.test.cjs +0 -360
  74. package/dist/cjs/transformHermesLoops.test.cjs +0 -257
  75. package/dist/cjs/transformSWC.test.cjs +0 -117
  76. package/dist/cjs/transformWorklets.test.cjs +0 -604
  77. package/dist/esm/transformBabel.test.mjs +0 -337
  78. package/dist/esm/transformBabel.test.mjs.map +0 -1
  79. package/dist/esm/transformHermesLoops.test.mjs +0 -234
  80. package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
  81. package/dist/esm/transformSWC.test.mjs +0 -118
  82. package/dist/esm/transformSWC.test.mjs.map +0 -1
  83. package/dist/esm/transformWorklets.test.mjs +0 -581
  84. package/dist/esm/transformWorklets.test.mjs.map +0 -1
  85. package/dist/esm/types.mjs.map +0 -1
  86. package/dist/esm/worklets/types.mjs.map +0 -1
  87. package/types/transformBabel.test.d.ts +0 -2
  88. package/types/transformBabel.test.d.ts.map +0 -1
  89. package/types/transformHermesLoops.test.d.ts +0 -2
  90. package/types/transformHermesLoops.test.d.ts.map +0 -1
  91. package/types/transformSWC.test.d.ts +0 -2
  92. package/types/transformSWC.test.d.ts.map +0 -1
  93. package/types/transformWorklets.test.d.ts +0 -2
  94. 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
- 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 autoworklet_exports = {};
24
22
  __export(autoworklet_exports, {
25
- AUTOWORKLET_FUNCTION_ARGS: () => AUTOWORKLET_FUNCTION_ARGS,
26
- GESTURE_BUILDER_METHODS: () => GESTURE_BUILDER_METHODS,
27
- WORKLET_DIRECTIVES: () => WORKLET_DIRECTIVES,
28
- bodyStartAfterDirectives: () => bodyStartAfterDirectives,
29
- findWorkletCandidates: () => findWorkletCandidates,
30
- hasDirective: () => hasDirective,
31
- hasWorkletDirective: () => hasWorkletDirective
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
- useFrameCallback: [0],
36
- useAnimatedStyle: [0],
37
- useAnimatedProps: [0],
38
- createAnimatedPropAdapter: [0],
39
- useDerivedValue: [0],
40
- useAnimatedScrollHandler: [0],
41
- useAnimatedGestureHandler: [0],
42
- useAnimatedReaction: [0, 1],
43
- withTiming: [2],
44
- withSpring: [2],
45
- withDecay: [1],
46
- withRepeat: [3],
47
- runOnUI: [0],
48
- executeOnUIRuntimeSync: [0],
49
- scheduleOnUI: [0],
50
- runOnUISync: [0],
51
- runOnUIAsync: [0],
52
- runOnRuntime: [1],
53
- runOnRuntimeSync: [1],
54
- runOnRuntimeAsync: [1],
55
- scheduleOnRuntime: [1],
56
- runOnRuntimeSyncWithId: [1],
57
- scheduleOnRuntimeWithId: [1],
58
- useTapGesture: [0],
59
- usePanGesture: [0],
60
- usePinchGesture: [0],
61
- useRotationGesture: [0],
62
- useFlingGesture: [0],
63
- useLongPressGesture: [0],
64
- useNativeGesture: [0],
65
- useManualGesture: [0],
66
- useHoverGesture: [0]
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(["onBegin", "onStart", "onEnd", "onFinalize", "onUpdate", "onChange", "onTouchesDown", "onTouchesMove", "onTouchesUp", "onTouchesCancelled"]);
69
- const GESTURE_KINDS = /* @__PURE__ */new Set(["Tap", "Pan", "Pinch", "Rotation", "Fling", "LongPress", "ForceTouch", "Native", "Manual", "Race", "Simultaneous", "Exclusive", "Hover"]);
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(["build", "duration", "delay", "getDuration", "randomDelay", "getDelay", "getDelayFunction", "easing", "rotate", "springify", "damping", "mass", "stiffness", "overshootClamping", "energyThreshold", "restDisplacementThreshold", "restSpeedThreshold", "withInitialValues", "getAnimationAndConfig", "easingX", "easingY", "easingWidth", "easingHeight", "entering", "exiting", "reverse"]);
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
- 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);
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
- if (isGestureObject(exp)) return true;
89
- return exp?.type === "CallExpression" && exp.callee?.type === "MemberExpression" && containsGestureObject(exp.callee.object);
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
- if (exp?.type === "Identifier" && LAYOUT_ANIMATIONS.has(exp.name)) return true;
93
- if (exp?.type === "NewExpression" && exp.callee?.type === "Identifier" && LAYOUT_ANIMATIONS.has(exp.callee.name)) {
94
- return true;
95
- }
96
- 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);
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
- if (callee?.type !== "MemberExpression" || callee.property?.type !== "Identifier") {
100
- return false;
101
- }
102
- const name = callee.property.name;
103
- if (GESTURE_BUILDER_METHODS.has(name)) return containsGestureObject(callee.object);
104
- if (name === "withCallback") return isLayoutAnimationChain(callee.object);
105
- return false;
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 = ["worklet", "no-worklet-closure", "limit-init-data-hoisting"];
157
+ const WORKLET_DIRECTIVES = [
158
+ "worklet",
159
+ "no-worklet-closure",
160
+ "limit-init-data-hoisting"
161
+ ];
108
162
  function statementDirective(stmt) {
109
- if (!stmt || stmt.type !== "ExpressionStatement") return void 0;
110
- if (typeof stmt.directive === "string") return stmt.directive;
111
- if (stmt.expression?.type === "Literal" && typeof stmt.expression.value === "string") {
112
- return stmt.expression.value;
113
- }
114
- return void 0;
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
- if (!fnNode || !fnNode.body) return false;
118
- if (Array.isArray(fnNode.body.directives)) {
119
- for (const d of fnNode.body.directives) {
120
- if (d.directive === directive || d.value === directive) {
121
- return true;
122
- }
123
- }
124
- }
125
- if (fnNode.body.type === "BlockStatement" && Array.isArray(fnNode.body.body)) {
126
- for (const stmt of fnNode.body.body) {
127
- const found = statementDirective(stmt);
128
- if (found === void 0) break;
129
- if (found === directive) return true;
130
- }
131
- }
132
- return false;
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
- return hasDirective(fnNode, "worklet");
189
+ return hasDirective(fnNode, "worklet");
136
190
  }
137
191
  function bodyStartAfterDirectives(fnNode, code) {
138
- let start = fnNode.body.start + 1;
139
- if (fnNode.body.type !== "BlockStatement" || !Array.isArray(fnNode.body.body)) return start;
140
- for (const stmt of fnNode.body.body) {
141
- const found = statementDirective(stmt);
142
- if (found === void 0 || !WORKLET_DIRECTIVES.includes(found)) break;
143
- start = stmt.end;
144
- while (start < fnNode.body.end && (code[start] === ";" || /\s/.test(code[start]))) {
145
- start++;
146
- }
147
- }
148
- return start;
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
- const candidates = [];
152
- const seenStarts = /* @__PURE__ */new Set();
153
- function addCandidate(candidate) {
154
- const fnStart = candidate.fnNode.start;
155
- if (seenStarts.has(fnStart)) return;
156
- seenStarts.add(fnStart);
157
- candidates.push(candidate);
158
- }
159
- function getCalleeName(callee) {
160
- if (!callee) return null;
161
- if (callee.type === "Identifier") {
162
- return callee.name;
163
- }
164
- if (callee.type === "MemberExpression" && !callee.computed && callee.property?.type === "Identifier") {
165
- return callee.property.name;
166
- }
167
- return null;
168
- }
169
- function walk(node, parent) {
170
- if (!node || typeof node !== "object") return;
171
- if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
172
- if (hasWorkletDirective(node)) {
173
- let kind = "function_expression";
174
- if (node.type === "FunctionDeclaration") kind = "function_declaration";else if (node.type === "ArrowFunctionExpression") kind = "arrow_function";
175
- let name = node.id?.name;
176
- if (!name && parent?.type === "VariableDeclarator" && parent.id?.name) {
177
- name = parent.id.name;
178
- }
179
- addCandidate({
180
- node,
181
- fnNode: node,
182
- kind,
183
- name,
184
- parent,
185
- isAutoWorklet: false
186
- });
187
- }
188
- } else if (node.type === "Property" && (node.method || node.value?.type === "FunctionExpression" || node.value?.type === "ArrowFunctionExpression")) {
189
- const fn = node.value;
190
- if (hasWorkletDirective(fn)) {
191
- addCandidate({
192
- node: node.method ? node : fn,
193
- fnNode: fn,
194
- kind: node.method ? "object_method" : fn.type === "ArrowFunctionExpression" ? "arrow_function" : "function_expression",
195
- name: node.key?.name,
196
- parent,
197
- isAutoWorklet: false
198
- });
199
- }
200
- }
201
- if (node.type === "CallExpression") {
202
- const calleeName = getCalleeName(node.callee);
203
- const argIndices = calleeName ? AUTOWORKLET_FUNCTION_ARGS[calleeName] : void 0;
204
- const chained = !argIndices && isChainedCallback(node.callee);
205
- const indices = argIndices ?? (chained ? node.arguments.map((_, i) => i) : void 0);
206
- if (indices) {
207
- for (const idx of indices) {
208
- const arg = node.arguments[idx];
209
- if (!arg) continue;
210
- if (arg.type === "ArrowFunctionExpression" || arg.type === "FunctionExpression") {
211
- let name = arg.id?.name;
212
- if (!name && parent?.type === "VariableDeclarator" && parent.id?.name) {
213
- name = parent.id.name;
214
- }
215
- addCandidate({
216
- node: arg,
217
- fnNode: arg,
218
- kind: arg.type === "ArrowFunctionExpression" ? "arrow_function" : "function_expression",
219
- name,
220
- parent: node,
221
- isAutoWorklet: true
222
- });
223
- } else if (arg.type === "ObjectExpression" && Array.isArray(arg.properties)) {
224
- for (const prop of arg.properties) {
225
- if (prop.type === "Property") {
226
- if (prop.method) {
227
- addCandidate({
228
- node: prop,
229
- fnNode: prop.value,
230
- kind: "object_method",
231
- name: prop.key?.name,
232
- parent: arg,
233
- isAutoWorklet: true
234
- });
235
- } else if (prop.value?.type === "ArrowFunctionExpression" || prop.value?.type === "FunctionExpression") {
236
- addCandidate({
237
- node: prop.value,
238
- fnNode: prop.value,
239
- kind: prop.value.type === "ArrowFunctionExpression" ? "arrow_function" : "function_expression",
240
- name: prop.key?.name,
241
- parent: prop,
242
- isAutoWorklet: true
243
- });
244
- }
245
- }
246
- }
247
- }
248
- }
249
- }
250
- }
251
- for (const key of Object.keys(node)) {
252
- if (key === "start" || key === "end" || key === "loc" || key === "range") continue;
253
- const child = node[key];
254
- if (Array.isArray(child)) {
255
- for (const item of child) {
256
- walk(item, node);
257
- }
258
- } else if (child && typeof child === "object") {
259
- walk(child, node);
260
- }
261
- }
262
- }
263
- walk(program, null);
264
- return candidates;
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
+ }