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