@vxrn/compiler 2.0.0-beta.33.1 → 2.0.0-beta.362.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 (115) 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 +428 -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 +247 -221
  9. package/dist/cjs/transformHermesAsync.cjs +36 -47
  10. package/dist/cjs/transformHermesClasses.cjs +51 -0
  11. package/dist/cjs/transformHermesLoops.cjs +279 -281
  12. package/dist/cjs/transformSWC.cjs +183 -200
  13. package/dist/cjs/transformWorklets.cjs +107 -95
  14. package/dist/cjs/types.cjs +9 -11
  15. package/dist/cjs/workletUtils.cjs +30 -0
  16. package/dist/cjs/worklets/autoworklet.cjs +277 -222
  17. package/dist/cjs/worklets/globals.cjs +145 -60
  18. package/dist/cjs/worklets/hash.cjs +23 -27
  19. package/dist/cjs/worklets/scope.cjs +338 -359
  20. package/dist/cjs/worklets/serialize.cjs +73 -75
  21. package/dist/cjs/worklets/transform.cjs +217 -222
  22. package/dist/cjs/worklets/types.cjs +9 -11
  23. package/dist/esm/cache.mjs +96 -89
  24. package/dist/esm/cache.mjs.map +1 -1
  25. package/dist/esm/configure.mjs +11 -10
  26. package/dist/esm/configure.mjs.map +1 -1
  27. package/dist/esm/constants.mjs +41 -41
  28. package/dist/esm/constants.mjs.map +1 -1
  29. package/dist/esm/index.js +426 -420
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/index.mjs +426 -420
  32. package/dist/esm/index.mjs.map +1 -1
  33. package/dist/esm/reactNativeCodegen.mjs +90 -88
  34. package/dist/esm/reactNativeCodegen.mjs.map +1 -1
  35. package/dist/esm/reactNativeViewConfig.mjs +347 -362
  36. package/dist/esm/reactNativeViewConfig.mjs.map +1 -1
  37. package/dist/esm/refresh-runtime.mjs +372 -376
  38. package/dist/esm/refresh-runtime.mjs.map +1 -1
  39. package/dist/esm/transformBabel.mjs +231 -198
  40. package/dist/esm/transformBabel.mjs.map +1 -1
  41. package/dist/esm/transformHermesAsync.mjs +20 -21
  42. package/dist/esm/transformHermesAsync.mjs.map +1 -1
  43. package/dist/esm/transformHermesClasses.mjs +25 -0
  44. package/dist/esm/transformHermesClasses.mjs.map +1 -0
  45. package/dist/esm/transformHermesLoops.mjs +264 -255
  46. package/dist/esm/transformHermesLoops.mjs.map +1 -1
  47. package/dist/esm/transformSWC.mjs +163 -171
  48. package/dist/esm/transformSWC.mjs.map +1 -1
  49. package/dist/esm/transformWorklets.mjs +89 -69
  50. package/dist/esm/transformWorklets.mjs.map +1 -1
  51. package/dist/esm/types.mjs +0 -2
  52. package/dist/esm/workletUtils.mjs +5 -0
  53. package/dist/esm/worklets/autoworklet.mjs +258 -200
  54. package/dist/esm/worklets/autoworklet.mjs.map +1 -1
  55. package/dist/esm/worklets/globals.mjs +130 -42
  56. package/dist/esm/worklets/globals.mjs.map +1 -1
  57. package/dist/esm/worklets/hash.mjs +10 -9
  58. package/dist/esm/worklets/hash.mjs.map +1 -1
  59. package/dist/esm/worklets/scope.mjs +325 -341
  60. package/dist/esm/worklets/scope.mjs.map +1 -1
  61. package/dist/esm/worklets/serialize.mjs +60 -58
  62. package/dist/esm/worklets/serialize.mjs.map +1 -1
  63. package/dist/esm/worklets/transform.mjs +201 -197
  64. package/dist/esm/worklets/transform.mjs.map +1 -1
  65. package/dist/esm/worklets/types.mjs +0 -2
  66. package/package.json +15 -6
  67. package/src/cache.ts +37 -7
  68. package/src/index.ts +44 -19
  69. package/src/reactNativeViewConfig.ts +6 -1
  70. package/src/transformBabel.test.ts +351 -17
  71. package/src/transformBabel.ts +137 -96
  72. package/src/transformHermesClasses.ts +34 -0
  73. package/src/transformSWC.ts +12 -1
  74. package/src/transformWorklets.test.ts +80 -5
  75. package/src/workletUtils.ts +4 -0
  76. package/src/worklets/autoworklet.ts +5 -2
  77. package/src/worklets/globals.ts +23 -0
  78. package/src/worklets/serialize.ts +1 -1
  79. package/types/cache.d.ts +2 -2
  80. package/types/cache.d.ts.map +1 -1
  81. package/types/index.d.ts +1 -0
  82. package/types/index.d.ts.map +1 -1
  83. package/types/reactNativeViewConfig.d.ts.map +1 -1
  84. package/types/transformBabel.d.ts +16 -1
  85. package/types/transformBabel.d.ts.map +1 -1
  86. package/types/transformHermesClasses.d.ts +5 -0
  87. package/types/transformHermesClasses.d.ts.map +1 -0
  88. package/types/transformSWC.d.ts +1 -4
  89. package/types/transformSWC.d.ts.map +1 -1
  90. package/types/workletUtils.d.ts +4 -0
  91. package/types/workletUtils.d.ts.map +1 -0
  92. package/types/worklets/autoworklet.d.ts.map +1 -1
  93. package/types/worklets/globals.d.ts.map +1 -1
  94. package/dist/cjs/transformBabel.test.cjs +0 -360
  95. package/dist/cjs/transformHermesLoops.test.cjs +0 -257
  96. package/dist/cjs/transformSWC.test.cjs +0 -117
  97. package/dist/cjs/transformWorklets.test.cjs +0 -604
  98. package/dist/esm/transformBabel.test.mjs +0 -337
  99. package/dist/esm/transformBabel.test.mjs.map +0 -1
  100. package/dist/esm/transformHermesLoops.test.mjs +0 -234
  101. package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
  102. package/dist/esm/transformSWC.test.mjs +0 -118
  103. package/dist/esm/transformSWC.test.mjs.map +0 -1
  104. package/dist/esm/transformWorklets.test.mjs +0 -581
  105. package/dist/esm/transformWorklets.test.mjs.map +0 -1
  106. package/dist/esm/types.mjs.map +0 -1
  107. package/dist/esm/worklets/types.mjs.map +0 -1
  108. package/types/transformBabel.test.d.ts +0 -2
  109. package/types/transformBabel.test.d.ts.map +0 -1
  110. package/types/transformHermesLoops.test.d.ts +0 -2
  111. package/types/transformHermesLoops.test.d.ts.map +0 -1
  112. package/types/transformSWC.test.d.ts +0 -2
  113. package/types/transformSWC.test.d.ts.map +0 -1
  114. package/types/transformWorklets.test.d.ts +0 -2
  115. package/types/transformWorklets.test.d.ts.map +0 -1
@@ -3,368 +3,347 @@ 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 scope_exports = {};
24
- __export(scope_exports, {
25
- getClosureVariables: () => getClosureVariables
26
- });
22
+ __export(scope_exports, { getClosureVariables: () => getClosureVariables });
27
23
  module.exports = __toCommonJS(scope_exports);
28
24
  function getClosureVariables(fnNode, globals) {
29
- const rootScope = {
30
- parent: null,
31
- isFunction: true,
32
- bindings: /* @__PURE__ */new Set(),
33
- varBindings: /* @__PURE__ */new Set()
34
- };
35
- let currentScope = rootScope;
36
- const freeVariables = /* @__PURE__ */new Set();
37
- if (fnNode.id && fnNode.id.name) {
38
- rootScope.bindings.add(fnNode.id.name);
39
- }
40
- function pushScope(isFunction) {
41
- const newScope = {
42
- parent: currentScope,
43
- isFunction,
44
- bindings: /* @__PURE__ */new Set(),
45
- varBindings: isFunction ? /* @__PURE__ */new Set() : currentScope.varBindings
46
- };
47
- currentScope = newScope;
48
- return newScope;
49
- }
50
- function popScope() {
51
- if (currentScope.parent) {
52
- currentScope = currentScope.parent;
53
- }
54
- }
55
- function addBindings(pattern, targetSet) {
56
- if (!pattern) return;
57
- switch (pattern.type) {
58
- case "Identifier":
59
- targetSet.add(pattern.name);
60
- break;
61
- case "AssignmentPattern":
62
- addBindings(pattern.left, targetSet);
63
- walk(pattern.right);
64
- break;
65
- case "RestElement":
66
- addBindings(pattern.argument, targetSet);
67
- break;
68
- case "ArrayPattern":
69
- for (const el of pattern.elements) {
70
- if (el) addBindings(el, targetSet);
71
- }
72
- break;
73
- case "ObjectPattern":
74
- for (const prop of pattern.properties) {
75
- if (prop.type === "Property") {
76
- if (prop.computed) walk(prop.key);
77
- addBindings(prop.value, targetSet);
78
- } else if (prop.type === "RestElement") {
79
- addBindings(prop.argument, targetSet);
80
- }
81
- }
82
- break;
83
- }
84
- }
85
- function addBindingsOnly(pattern, targetSet) {
86
- if (!pattern) return;
87
- switch (pattern.type) {
88
- case "Identifier":
89
- targetSet.add(pattern.name);
90
- break;
91
- case "AssignmentPattern":
92
- addBindingsOnly(pattern.left, targetSet);
93
- break;
94
- case "RestElement":
95
- addBindingsOnly(pattern.argument, targetSet);
96
- break;
97
- case "ArrayPattern":
98
- for (const el of pattern.elements) {
99
- if (el) addBindingsOnly(el, targetSet);
100
- }
101
- break;
102
- case "ObjectPattern":
103
- for (const prop of pattern.properties) {
104
- if (prop.type === "Property") {
105
- addBindingsOnly(prop.value, targetSet);
106
- } else if (prop.type === "RestElement") {
107
- addBindingsOnly(prop.argument, targetSet);
108
- }
109
- }
110
- break;
111
- }
112
- }
113
- function hoistDeclarations(node, direct) {
114
- if (!node || typeof node !== "object" || typeof node.type !== "string") return;
115
- switch (node.type) {
116
- case "FunctionDeclaration":
117
- if (node.id?.name) {
118
- currentScope.bindings.add(node.id.name);
119
- currentScope.varBindings.add(node.id.name);
120
- }
121
- return;
122
- case "FunctionExpression":
123
- case "ArrowFunctionExpression":
124
- return;
125
- case "ClassDeclaration":
126
- if (direct && node.id?.name) currentScope.bindings.add(node.id.name);
127
- return;
128
- case "VariableDeclaration":
129
- if (node.kind === "var") {
130
- for (const d of node.declarations) addBindingsOnly(d.id, currentScope.varBindings);
131
- } else if (direct) {
132
- for (const d of node.declarations) addBindingsOnly(d.id, currentScope.bindings);
133
- }
134
- return;
135
- case "ExportNamedDeclaration":
136
- case "ExportDefaultDeclaration":
137
- hoistDeclarations(node.declaration, direct);
138
- return;
139
- }
140
- for (const key of Object.keys(node)) {
141
- if (key === "start" || key === "end" || key === "loc" || key === "range") continue;
142
- const child = node[key];
143
- if (Array.isArray(child)) {
144
- for (const item of child) hoistDeclarations(item, false);
145
- } else if (child && typeof child === "object") {
146
- hoistDeclarations(child, false);
147
- }
148
- }
149
- }
150
- if (fnNode.params) {
151
- for (const param of fnNode.params) {
152
- addBindings(param, rootScope.bindings);
153
- }
154
- }
155
- function isDeclaredInScopes(name, fromScope) {
156
- let s = fromScope;
157
- while (s) {
158
- if (s.bindings.has(name) || s.varBindings.has(name)) {
159
- return true;
160
- }
161
- s = s.parent;
162
- }
163
- return false;
164
- }
165
- function resolveIdentifier(name) {
166
- if (!isDeclaredInScopes(name, currentScope) && !globals.has(name)) {
167
- freeVariables.add(name);
168
- }
169
- }
170
- function walk(node) {
171
- if (!node || typeof node !== "object") return;
172
- if (node.type === "TSTypeAnnotation" || node.type === "TSTypeReference" || node.type === "TSTypeAliasDeclaration" || node.type === "TSInterfaceDeclaration" || node.type === "TSTypeParameterDeclaration" || node.type === "TSTypeParameterInstantiation" || node.type === "TSTypeQuery" || node.type === "TSQualifiedName") {
173
- return;
174
- }
175
- if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSInstantiationExpression") {
176
- walk(node.expression);
177
- return;
178
- }
179
- switch (node.type) {
180
- case "BlockStatement":
181
- {
182
- const isRootBody = node === fnNode.body;
183
- if (!isRootBody) {
184
- pushScope(false);
185
- }
186
- for (const stmt of node.body) {
187
- hoistDeclarations(stmt, true);
188
- }
189
- for (const stmt of node.body) {
190
- walk(stmt);
191
- }
192
- if (!isRootBody) {
193
- popScope();
194
- }
195
- return;
196
- }
197
- case "VariableDeclaration":
198
- {
199
- const isVar = node.kind === "var";
200
- const targetSet = isVar ? currentScope.varBindings : currentScope.bindings;
201
- for (const decl of node.declarations) {
202
- addBindings(decl.id, targetSet);
203
- if (decl.init) walk(decl.init);
204
- }
205
- return;
206
- }
207
- case "FunctionDeclaration":
208
- case "FunctionExpression":
209
- {
210
- if (node.id && node.id.name) {
211
- currentScope.bindings.add(node.id.name);
212
- }
213
- pushScope(true);
214
- if (node.params) {
215
- for (const param of node.params) {
216
- addBindings(param, currentScope.bindings);
217
- }
218
- }
219
- walk(node.body);
220
- popScope();
221
- return;
222
- }
223
- case "ArrowFunctionExpression":
224
- {
225
- pushScope(true);
226
- if (node.params) {
227
- for (const param of node.params) {
228
- addBindings(param, currentScope.bindings);
229
- }
230
- }
231
- walk(node.body);
232
- popScope();
233
- return;
234
- }
235
- case "CatchClause":
236
- {
237
- pushScope(false);
238
- if (node.param) {
239
- addBindings(node.param, currentScope.bindings);
240
- }
241
- walk(node.body);
242
- popScope();
243
- return;
244
- }
245
- case "ForStatement":
246
- {
247
- pushScope(false);
248
- if (node.init) walk(node.init);
249
- if (node.test) walk(node.test);
250
- if (node.update) walk(node.update);
251
- walk(node.body);
252
- popScope();
253
- return;
254
- }
255
- case "ForInStatement":
256
- case "ForOfStatement":
257
- {
258
- pushScope(false);
259
- walk(node.left);
260
- walk(node.right);
261
- walk(node.body);
262
- popScope();
263
- return;
264
- }
265
- case "ClassDeclaration":
266
- case "ClassExpression":
267
- {
268
- if (node.id && node.id.name) {
269
- currentScope.bindings.add(node.id.name);
270
- }
271
- if (node.superClass) walk(node.superClass);
272
- pushScope(false);
273
- walk(node.body);
274
- popScope();
275
- return;
276
- }
277
- case "MemberExpression":
278
- {
279
- walk(node.object);
280
- if (node.computed) {
281
- walk(node.property);
282
- }
283
- return;
284
- }
285
- case "Property":
286
- {
287
- if (node.computed) {
288
- walk(node.key);
289
- }
290
- walk(node.value);
291
- return;
292
- }
293
- case "MethodDefinition":
294
- {
295
- if (node.computed) {
296
- walk(node.key);
297
- }
298
- walk(node.value);
299
- return;
300
- }
301
- case "Identifier":
302
- {
303
- resolveIdentifier(node.name);
304
- return;
305
- }
306
- case "JSXElement":
307
- {
308
- if (node.openingElement) {
309
- const nameNode = node.openingElement.name;
310
- if (nameNode.type === "JSXIdentifier") {
311
- if (/^[A-Z]/.test(nameNode.name)) {
312
- resolveIdentifier(nameNode.name);
313
- }
314
- } else if (nameNode.type === "JSXMemberExpression") {
315
- let root = nameNode.object;
316
- while (root.type === "JSXMemberExpression") {
317
- root = root.object;
318
- }
319
- if (root.type === "JSXIdentifier") {
320
- resolveIdentifier(root.name);
321
- }
322
- }
323
- if (node.openingElement.attributes) {
324
- for (const attr of node.openingElement.attributes) {
325
- walk(attr);
326
- }
327
- }
328
- }
329
- if (node.children) {
330
- for (const child of node.children) {
331
- walk(child);
332
- }
333
- }
334
- return;
335
- }
336
- case "JSXAttribute":
337
- {
338
- if (node.value) {
339
- walk(node.value);
340
- }
341
- return;
342
- }
343
- case "JSXExpressionContainer":
344
- {
345
- walk(node.expression);
346
- return;
347
- }
348
- case "BreakStatement":
349
- case "ContinueStatement":
350
- case "LabeledStatement":
351
- {
352
- if (node.body) walk(node.body);
353
- return;
354
- }
355
- }
356
- for (const key of Object.keys(node)) {
357
- if (key === "start" || key === "end" || key === "loc" || key === "range") continue;
358
- const child = node[key];
359
- if (Array.isArray(child)) {
360
- for (const item of child) {
361
- walk(item);
362
- }
363
- } else if (child && typeof child === "object") {
364
- walk(child);
365
- }
366
- }
367
- }
368
- walk(fnNode.body);
369
- return Array.from(freeVariables).sort();
370
- }
25
+ const rootScope = {
26
+ parent: null,
27
+ isFunction: true,
28
+ bindings: /* @__PURE__ */ new Set(),
29
+ varBindings: /* @__PURE__ */ new Set()
30
+ };
31
+ let currentScope = rootScope;
32
+ const freeVariables = /* @__PURE__ */ new Set();
33
+ if (fnNode.id && fnNode.id.name) {
34
+ rootScope.bindings.add(fnNode.id.name);
35
+ }
36
+ function pushScope(isFunction) {
37
+ const newScope = {
38
+ parent: currentScope,
39
+ isFunction,
40
+ bindings: /* @__PURE__ */ new Set(),
41
+ varBindings: isFunction ? /* @__PURE__ */ new Set() : currentScope.varBindings
42
+ };
43
+ currentScope = newScope;
44
+ return newScope;
45
+ }
46
+ function popScope() {
47
+ if (currentScope.parent) {
48
+ currentScope = currentScope.parent;
49
+ }
50
+ }
51
+ function addBindings(pattern, targetSet) {
52
+ if (!pattern) return;
53
+ switch (pattern.type) {
54
+ case "Identifier":
55
+ targetSet.add(pattern.name);
56
+ break;
57
+ case "AssignmentPattern":
58
+ addBindings(pattern.left, targetSet);
59
+ walk(pattern.right);
60
+ break;
61
+ case "RestElement":
62
+ addBindings(pattern.argument, targetSet);
63
+ break;
64
+ case "ArrayPattern":
65
+ for (const el of pattern.elements) {
66
+ if (el) addBindings(el, targetSet);
67
+ }
68
+ break;
69
+ case "ObjectPattern":
70
+ for (const prop of pattern.properties) {
71
+ if (prop.type === "Property") {
72
+ if (prop.computed) walk(prop.key);
73
+ addBindings(prop.value, targetSet);
74
+ } else if (prop.type === "RestElement") {
75
+ addBindings(prop.argument, targetSet);
76
+ }
77
+ }
78
+ break;
79
+ }
80
+ }
81
+ function addBindingsOnly(pattern, targetSet) {
82
+ if (!pattern) return;
83
+ switch (pattern.type) {
84
+ case "Identifier":
85
+ targetSet.add(pattern.name);
86
+ break;
87
+ case "AssignmentPattern":
88
+ addBindingsOnly(pattern.left, targetSet);
89
+ break;
90
+ case "RestElement":
91
+ addBindingsOnly(pattern.argument, targetSet);
92
+ break;
93
+ case "ArrayPattern":
94
+ for (const el of pattern.elements) {
95
+ if (el) addBindingsOnly(el, targetSet);
96
+ }
97
+ break;
98
+ case "ObjectPattern":
99
+ for (const prop of pattern.properties) {
100
+ if (prop.type === "Property") {
101
+ addBindingsOnly(prop.value, targetSet);
102
+ } else if (prop.type === "RestElement") {
103
+ addBindingsOnly(prop.argument, targetSet);
104
+ }
105
+ }
106
+ break;
107
+ }
108
+ }
109
+ function hoistDeclarations(node, direct) {
110
+ if (!node || typeof node !== "object" || typeof node.type !== "string") return;
111
+ switch (node.type) {
112
+ case "FunctionDeclaration":
113
+ if (node.id?.name) {
114
+ currentScope.bindings.add(node.id.name);
115
+ currentScope.varBindings.add(node.id.name);
116
+ }
117
+ return;
118
+ case "FunctionExpression":
119
+ case "ArrowFunctionExpression": return;
120
+ case "ClassDeclaration":
121
+ if (direct && node.id?.name) currentScope.bindings.add(node.id.name);
122
+ return;
123
+ case "VariableDeclaration":
124
+ if (node.kind === "var") {
125
+ for (const d of node.declarations) addBindingsOnly(d.id, currentScope.varBindings);
126
+ } else if (direct) {
127
+ for (const d of node.declarations) addBindingsOnly(d.id, currentScope.bindings);
128
+ }
129
+ return;
130
+ case "ExportNamedDeclaration":
131
+ case "ExportDefaultDeclaration":
132
+ hoistDeclarations(node.declaration, direct);
133
+ return;
134
+ }
135
+ for (const key of Object.keys(node)) {
136
+ if (key === "start" || key === "end" || key === "loc" || key === "range") continue;
137
+ const child = node[key];
138
+ if (Array.isArray(child)) {
139
+ for (const item of child) hoistDeclarations(item, false);
140
+ } else if (child && typeof child === "object") {
141
+ hoistDeclarations(child, false);
142
+ }
143
+ }
144
+ }
145
+ if (fnNode.params) {
146
+ for (const param of fnNode.params) {
147
+ addBindings(param, rootScope.bindings);
148
+ }
149
+ }
150
+ function isDeclaredInScopes(name, fromScope) {
151
+ let s = fromScope;
152
+ while (s) {
153
+ if (s.bindings.has(name) || s.varBindings.has(name)) {
154
+ return true;
155
+ }
156
+ s = s.parent;
157
+ }
158
+ return false;
159
+ }
160
+ function resolveIdentifier(name) {
161
+ if (!isDeclaredInScopes(name, currentScope) && !globals.has(name)) {
162
+ freeVariables.add(name);
163
+ }
164
+ }
165
+ function walk(node) {
166
+ if (!node || typeof node !== "object") return;
167
+ if (node.type === "TSTypeAnnotation" || node.type === "TSTypeReference" || node.type === "TSTypeAliasDeclaration" || node.type === "TSInterfaceDeclaration" || node.type === "TSTypeParameterDeclaration" || node.type === "TSTypeParameterInstantiation" || node.type === "TSTypeQuery" || node.type === "TSQualifiedName") {
168
+ return;
169
+ }
170
+ if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSInstantiationExpression") {
171
+ walk(node.expression);
172
+ return;
173
+ }
174
+ switch (node.type) {
175
+ case "BlockStatement": {
176
+ const isRootBody = node === fnNode.body;
177
+ if (!isRootBody) {
178
+ pushScope(false);
179
+ }
180
+ for (const stmt of node.body) {
181
+ hoistDeclarations(stmt, true);
182
+ }
183
+ for (const stmt of node.body) {
184
+ walk(stmt);
185
+ }
186
+ if (!isRootBody) {
187
+ popScope();
188
+ }
189
+ return;
190
+ }
191
+ case "VariableDeclaration": {
192
+ const isVar = node.kind === "var";
193
+ const targetSet = isVar ? currentScope.varBindings : currentScope.bindings;
194
+ for (const decl of node.declarations) {
195
+ addBindings(decl.id, targetSet);
196
+ if (decl.init) walk(decl.init);
197
+ }
198
+ return;
199
+ }
200
+ case "FunctionDeclaration":
201
+ case "FunctionExpression": {
202
+ if (node.id && node.id.name) {
203
+ currentScope.bindings.add(node.id.name);
204
+ }
205
+ pushScope(true);
206
+ if (node.params) {
207
+ for (const param of node.params) {
208
+ addBindings(param, currentScope.bindings);
209
+ }
210
+ }
211
+ walk(node.body);
212
+ popScope();
213
+ return;
214
+ }
215
+ case "ArrowFunctionExpression": {
216
+ pushScope(true);
217
+ if (node.params) {
218
+ for (const param of node.params) {
219
+ addBindings(param, currentScope.bindings);
220
+ }
221
+ }
222
+ walk(node.body);
223
+ popScope();
224
+ return;
225
+ }
226
+ case "CatchClause": {
227
+ pushScope(false);
228
+ if (node.param) {
229
+ addBindings(node.param, currentScope.bindings);
230
+ }
231
+ walk(node.body);
232
+ popScope();
233
+ return;
234
+ }
235
+ case "ForStatement": {
236
+ pushScope(false);
237
+ if (node.init) walk(node.init);
238
+ if (node.test) walk(node.test);
239
+ if (node.update) walk(node.update);
240
+ walk(node.body);
241
+ popScope();
242
+ return;
243
+ }
244
+ case "ForInStatement":
245
+ case "ForOfStatement": {
246
+ pushScope(false);
247
+ walk(node.left);
248
+ walk(node.right);
249
+ walk(node.body);
250
+ popScope();
251
+ return;
252
+ }
253
+ case "ClassDeclaration":
254
+ case "ClassExpression": {
255
+ if (node.id && node.id.name) {
256
+ currentScope.bindings.add(node.id.name);
257
+ }
258
+ if (node.superClass) walk(node.superClass);
259
+ pushScope(false);
260
+ walk(node.body);
261
+ popScope();
262
+ return;
263
+ }
264
+ case "MemberExpression": {
265
+ walk(node.object);
266
+ if (node.computed) {
267
+ walk(node.property);
268
+ }
269
+ return;
270
+ }
271
+ case "Property": {
272
+ if (node.computed) {
273
+ walk(node.key);
274
+ }
275
+ walk(node.value);
276
+ return;
277
+ }
278
+ case "MethodDefinition": {
279
+ if (node.computed) {
280
+ walk(node.key);
281
+ }
282
+ walk(node.value);
283
+ return;
284
+ }
285
+ case "Identifier": {
286
+ resolveIdentifier(node.name);
287
+ return;
288
+ }
289
+ case "JSXElement": {
290
+ if (node.openingElement) {
291
+ const nameNode = node.openingElement.name;
292
+ if (nameNode.type === "JSXIdentifier") {
293
+ if (/^[A-Z]/.test(nameNode.name)) {
294
+ resolveIdentifier(nameNode.name);
295
+ }
296
+ } else if (nameNode.type === "JSXMemberExpression") {
297
+ let root = nameNode.object;
298
+ while (root.type === "JSXMemberExpression") {
299
+ root = root.object;
300
+ }
301
+ if (root.type === "JSXIdentifier") {
302
+ resolveIdentifier(root.name);
303
+ }
304
+ }
305
+ if (node.openingElement.attributes) {
306
+ for (const attr of node.openingElement.attributes) {
307
+ walk(attr);
308
+ }
309
+ }
310
+ }
311
+ if (node.children) {
312
+ for (const child of node.children) {
313
+ walk(child);
314
+ }
315
+ }
316
+ return;
317
+ }
318
+ case "JSXAttribute": {
319
+ if (node.value) {
320
+ walk(node.value);
321
+ }
322
+ return;
323
+ }
324
+ case "JSXExpressionContainer": {
325
+ walk(node.expression);
326
+ return;
327
+ }
328
+ case "BreakStatement":
329
+ case "ContinueStatement":
330
+ case "LabeledStatement": {
331
+ if (node.body) walk(node.body);
332
+ return;
333
+ }
334
+ }
335
+ for (const key of Object.keys(node)) {
336
+ if (key === "start" || key === "end" || key === "loc" || key === "range") continue;
337
+ const child = node[key];
338
+ if (Array.isArray(child)) {
339
+ for (const item of child) {
340
+ walk(item);
341
+ }
342
+ } else if (child && typeof child === "object") {
343
+ walk(child);
344
+ }
345
+ }
346
+ }
347
+ walk(fnNode.body);
348
+ return Array.from(freeVariables).sort();
349
+ }