@graphcommerce/next-config 8.1.0-canary.2 → 8.1.0-canary.5

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 (44) hide show
  1. package/CHANGELOG.md +133 -1
  2. package/Config.graphqls +4 -2
  3. package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +19 -2
  4. package/__tests__/config/utils/replaceConfigInString.ts +4 -0
  5. package/__tests__/interceptors/findPlugins.ts +473 -113
  6. package/__tests__/interceptors/generateInterceptors.ts +610 -322
  7. package/__tests__/interceptors/parseStructure.ts +158 -0
  8. package/__tests__/interceptors/writeInterceptors.ts +23 -14
  9. package/__tests__/utils/resolveDependenciesSync.ts +28 -25
  10. package/dist/config/commands/generateConfig.js +5 -2
  11. package/dist/config/demoConfig.js +19 -4
  12. package/dist/generated/config.js +8 -1
  13. package/dist/interceptors/InterceptorPlugin.js +70 -25
  14. package/dist/interceptors/RenameVisitor.js +19 -0
  15. package/dist/interceptors/Visitor.js +1418 -0
  16. package/dist/interceptors/extractExports.js +201 -0
  17. package/dist/interceptors/findOriginalSource.js +87 -0
  18. package/dist/interceptors/findPlugins.js +21 -53
  19. package/dist/interceptors/generateInterceptor.js +200 -0
  20. package/dist/interceptors/generateInterceptors.js +38 -179
  21. package/dist/interceptors/parseStructure.js +71 -0
  22. package/dist/interceptors/swc.js +16 -0
  23. package/dist/interceptors/writeInterceptors.js +19 -10
  24. package/dist/utils/resolveDependency.js +27 -5
  25. package/dist/withGraphCommerce.js +2 -1
  26. package/package.json +4 -1
  27. package/src/config/commands/generateConfig.ts +5 -2
  28. package/src/config/demoConfig.ts +19 -4
  29. package/src/config/index.ts +4 -2
  30. package/src/generated/config.ts +25 -3
  31. package/src/index.ts +16 -6
  32. package/src/interceptors/InterceptorPlugin.ts +90 -32
  33. package/src/interceptors/RenameVisitor.ts +17 -0
  34. package/src/interceptors/Visitor.ts +1847 -0
  35. package/src/interceptors/extractExports.ts +230 -0
  36. package/src/interceptors/findOriginalSource.ts +105 -0
  37. package/src/interceptors/findPlugins.ts +36 -87
  38. package/src/interceptors/generateInterceptor.ts +271 -0
  39. package/src/interceptors/generateInterceptors.ts +67 -237
  40. package/src/interceptors/parseStructure.ts +82 -0
  41. package/src/interceptors/swc.ts +13 -0
  42. package/src/interceptors/writeInterceptors.ts +26 -10
  43. package/src/utils/resolveDependency.ts +51 -12
  44. package/src/withGraphCommerce.ts +2 -1
@@ -0,0 +1,1418 @@
1
+ "use strict";
2
+ /**
3
+ * This is an implementation of
4
+ * https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts
5
+ *
6
+ * The JS API is deprecated, but there doesn't seem to be a valid alternative at this point.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Visitor = void 0;
10
+ /**
11
+ * @deprecated JavaScript API is deprecated. Please use Wasm plugin instead.
12
+ */
13
+ class Visitor {
14
+ visitProgram(n) {
15
+ switch (n.type) {
16
+ case 'Module':
17
+ return this.visitModule(n);
18
+ case 'Script':
19
+ return this.visitScript(n);
20
+ }
21
+ }
22
+ visitModule(m) {
23
+ m.body = this.visitModuleItems(m.body);
24
+ return m;
25
+ }
26
+ visitScript(m) {
27
+ m.body = this.visitStatements(m.body);
28
+ return m;
29
+ }
30
+ visitModuleItems(items) {
31
+ return items.map(this.visitModuleItem.bind(this));
32
+ }
33
+ visitModuleItem(n) {
34
+ switch (n.type) {
35
+ case 'ExportDeclaration':
36
+ case 'ExportDefaultDeclaration':
37
+ case 'ExportNamedDeclaration':
38
+ case 'ExportDefaultExpression':
39
+ case 'ImportDeclaration':
40
+ case 'ExportAllDeclaration':
41
+ case 'TsImportEqualsDeclaration':
42
+ case 'TsExportAssignment':
43
+ case 'TsNamespaceExportDeclaration':
44
+ return this.visitModuleDeclaration(n);
45
+ default:
46
+ return this.visitStatement(n);
47
+ }
48
+ }
49
+ visitModuleDeclaration(n) {
50
+ switch (n.type) {
51
+ case 'ExportDeclaration':
52
+ return this.visitExportDeclaration(n);
53
+ case 'ExportDefaultDeclaration':
54
+ return this.visitExportDefaultDeclaration(n);
55
+ case 'ExportNamedDeclaration':
56
+ return this.visitExportNamedDeclaration(n);
57
+ case 'ExportDefaultExpression':
58
+ return this.visitExportDefaultExpression(n);
59
+ case 'ImportDeclaration':
60
+ return this.visitImportDeclaration(n);
61
+ case 'ExportAllDeclaration':
62
+ return this.visitExportAllDeclaration(n);
63
+ case 'TsImportEqualsDeclaration':
64
+ return this.visitTsImportEqualsDeclaration(n);
65
+ case 'TsExportAssignment':
66
+ return this.visitTsExportAssignment(n);
67
+ case 'TsNamespaceExportDeclaration':
68
+ return this.visitTsNamespaceExportDeclaration(n);
69
+ }
70
+ }
71
+ visitTsNamespaceExportDeclaration(n) {
72
+ n.id = this.visitBindingIdentifier(n.id);
73
+ return n;
74
+ }
75
+ visitTsExportAssignment(n) {
76
+ n.expression = this.visitExpression(n.expression);
77
+ return n;
78
+ }
79
+ visitTsImportEqualsDeclaration(n) {
80
+ n.id = this.visitBindingIdentifier(n.id);
81
+ n.moduleRef = this.visitTsModuleReference(n.moduleRef);
82
+ return n;
83
+ }
84
+ visitTsModuleReference(n) {
85
+ switch (n.type) {
86
+ case 'Identifier':
87
+ return this.visitIdentifierReference(n);
88
+ case 'TsExternalModuleReference':
89
+ return this.visitTsExternalModuleReference(n);
90
+ case 'TsQualifiedName':
91
+ return this.visitTsQualifiedName(n);
92
+ }
93
+ }
94
+ visitTsExternalModuleReference(n) {
95
+ n.expression = this.visitStringLiteral(n.expression);
96
+ return n;
97
+ }
98
+ visitExportAllDeclaration(n) {
99
+ n.source = this.visitStringLiteral(n.source);
100
+ return n;
101
+ }
102
+ visitExportDefaultExpression(n) {
103
+ n.expression = this.visitExpression(n.expression);
104
+ return n;
105
+ }
106
+ visitExportNamedDeclaration(n) {
107
+ n.specifiers = this.visitExportSpecifiers(n.specifiers);
108
+ n.source = this.visitOptionalStringLiteral(n.source);
109
+ return n;
110
+ }
111
+ visitExportSpecifiers(nodes) {
112
+ return nodes.map(this.visitExportSpecifier.bind(this));
113
+ }
114
+ visitExportSpecifier(n) {
115
+ switch (n.type) {
116
+ case 'ExportDefaultSpecifier':
117
+ return this.visitExportDefaultSpecifier(n);
118
+ case 'ExportNamespaceSpecifier':
119
+ return this.visitExportNamespaceSpecifier(n);
120
+ case 'ExportSpecifier':
121
+ return this.visitNamedExportSpecifier(n);
122
+ }
123
+ }
124
+ visitNamedExportSpecifier(n) {
125
+ if (n.exported) {
126
+ n.exported = this.visitModuleExportName(n.exported);
127
+ }
128
+ n.orig = this.visitModuleExportName(n.orig);
129
+ return n;
130
+ }
131
+ visitModuleExportName(n) {
132
+ switch (n.type) {
133
+ case 'Identifier':
134
+ return this.visitIdentifier(n);
135
+ case 'StringLiteral':
136
+ return this.visitStringLiteral(n);
137
+ }
138
+ }
139
+ visitExportNamespaceSpecifier(n) {
140
+ n.name = this.visitModuleExportName(n.name);
141
+ return n;
142
+ }
143
+ visitExportDefaultSpecifier(n) {
144
+ n.exported = this.visitBindingIdentifier(n.exported);
145
+ return n;
146
+ }
147
+ visitOptionalStringLiteral(n) {
148
+ if (n) {
149
+ return this.visitStringLiteral(n);
150
+ }
151
+ }
152
+ visitExportDefaultDeclaration(n) {
153
+ n.decl = this.visitDefaultDeclaration(n.decl);
154
+ return n;
155
+ }
156
+ visitDefaultDeclaration(n) {
157
+ switch (n.type) {
158
+ case 'ClassExpression':
159
+ return this.visitClassExpression(n);
160
+ case 'FunctionExpression':
161
+ return this.visitFunctionExpression(n);
162
+ case 'TsInterfaceDeclaration':
163
+ return this.visitTsInterfaceDeclaration(n);
164
+ }
165
+ }
166
+ visitFunctionExpression(n) {
167
+ n = this.visitFunction(n);
168
+ if (n.identifier) {
169
+ n.identifier = this.visitBindingIdentifier(n.identifier);
170
+ }
171
+ return n;
172
+ }
173
+ visitClassExpression(n) {
174
+ n = this.visitClass(n);
175
+ if (n.identifier) {
176
+ n.identifier = this.visitBindingIdentifier(n.identifier);
177
+ }
178
+ return n;
179
+ }
180
+ visitExportDeclaration(n) {
181
+ n.declaration = this.visitDeclaration(n.declaration);
182
+ return n;
183
+ }
184
+ visitArrayExpression(e) {
185
+ if (e.elements) {
186
+ e.elements = e.elements.map(this.visitArrayElement.bind(this));
187
+ }
188
+ return e;
189
+ }
190
+ visitArrayElement(e) {
191
+ if (e) {
192
+ return this.visitExprOrSpread(e);
193
+ }
194
+ }
195
+ visitExprOrSpread(e) {
196
+ return {
197
+ ...e,
198
+ expression: this.visitExpression(e.expression),
199
+ };
200
+ }
201
+ visitExprOrSpreads(nodes) {
202
+ return nodes.map(this.visitExprOrSpread.bind(this));
203
+ }
204
+ visitSpreadElement(e) {
205
+ e.arguments = this.visitExpression(e.arguments);
206
+ return e;
207
+ }
208
+ visitOptionalExpression(e) {
209
+ if (e) {
210
+ return this.visitExpression(e);
211
+ }
212
+ }
213
+ visitArrowFunctionExpression(e) {
214
+ e.body = this.visitArrowBody(e.body);
215
+ e.params = this.visitPatterns(e.params);
216
+ e.returnType = this.visitTsTypeAnnotation(e.returnType);
217
+ e.typeParameters = this.visitTsTypeParameterDeclaration(e.typeParameters);
218
+ return e;
219
+ }
220
+ visitArrowBody(body) {
221
+ switch (body.type) {
222
+ case 'BlockStatement':
223
+ return this.visitBlockStatement(body);
224
+ default:
225
+ return this.visitExpression(body);
226
+ }
227
+ }
228
+ visitBlockStatement(block) {
229
+ block.stmts = this.visitStatements(block.stmts);
230
+ return block;
231
+ }
232
+ visitStatements(stmts) {
233
+ return stmts.map(this.visitStatement.bind(this));
234
+ }
235
+ visitStatement(stmt) {
236
+ switch (stmt.type) {
237
+ case 'ClassDeclaration':
238
+ case 'FunctionDeclaration':
239
+ case 'TsEnumDeclaration':
240
+ case 'TsInterfaceDeclaration':
241
+ case 'TsModuleDeclaration':
242
+ case 'TsTypeAliasDeclaration':
243
+ case 'VariableDeclaration':
244
+ return this.visitDeclaration(stmt);
245
+ case 'BreakStatement':
246
+ return this.visitBreakStatement(stmt);
247
+ case 'BlockStatement':
248
+ return this.visitBlockStatement(stmt);
249
+ case 'ContinueStatement':
250
+ return this.visitContinueStatement(stmt);
251
+ case 'DebuggerStatement':
252
+ return this.visitDebuggerStatement(stmt);
253
+ case 'DoWhileStatement':
254
+ return this.visitDoWhileStatement(stmt);
255
+ case 'EmptyStatement':
256
+ return this.visitEmptyStatement(stmt);
257
+ case 'ForInStatement':
258
+ return this.visitForInStatement(stmt);
259
+ case 'ForOfStatement':
260
+ return this.visitForOfStatement(stmt);
261
+ case 'ForStatement':
262
+ return this.visitForStatement(stmt);
263
+ case 'IfStatement':
264
+ return this.visitIfStatement(stmt);
265
+ case 'LabeledStatement':
266
+ return this.visitLabeledStatement(stmt);
267
+ case 'ReturnStatement':
268
+ return this.visitReturnStatement(stmt);
269
+ case 'SwitchStatement':
270
+ return this.visitSwitchStatement(stmt);
271
+ case 'ThrowStatement':
272
+ return this.visitThrowStatement(stmt);
273
+ case 'TryStatement':
274
+ return this.visitTryStatement(stmt);
275
+ case 'WhileStatement':
276
+ return this.visitWhileStatement(stmt);
277
+ case 'WithStatement':
278
+ return this.visitWithStatement(stmt);
279
+ case 'ExpressionStatement':
280
+ return this.visitExpressionStatement(stmt);
281
+ default:
282
+ throw new Error(`Unknown statement type: ${stmt.type}`);
283
+ }
284
+ }
285
+ visitSwitchStatement(stmt) {
286
+ stmt.discriminant = this.visitExpression(stmt.discriminant);
287
+ stmt.cases = this.visitSwitchCases(stmt.cases);
288
+ return stmt;
289
+ }
290
+ visitSwitchCases(cases) {
291
+ return cases.map(this.visitSwitchCase.bind(this));
292
+ }
293
+ visitSwitchCase(c) {
294
+ c.test = this.visitOptionalExpression(c.test);
295
+ c.consequent = this.visitStatements(c.consequent);
296
+ return c;
297
+ }
298
+ visitIfStatement(stmt) {
299
+ stmt.test = this.visitExpression(stmt.test);
300
+ stmt.consequent = this.visitStatement(stmt.consequent);
301
+ stmt.alternate = this.visitOptionalStatement(stmt.alternate);
302
+ return stmt;
303
+ }
304
+ visitOptionalStatement(stmt) {
305
+ if (stmt) {
306
+ return this.visitStatement(stmt);
307
+ }
308
+ }
309
+ visitBreakStatement(stmt) {
310
+ if (stmt.label) {
311
+ stmt.label = this.visitLabelIdentifier(stmt.label);
312
+ }
313
+ return stmt;
314
+ }
315
+ visitWhileStatement(stmt) {
316
+ stmt.test = this.visitExpression(stmt.test);
317
+ stmt.body = this.visitStatement(stmt.body);
318
+ return stmt;
319
+ }
320
+ visitTryStatement(stmt) {
321
+ stmt.block = this.visitBlockStatement(stmt.block);
322
+ stmt.handler = this.visitCatchClause(stmt.handler);
323
+ if (stmt.finalizer) {
324
+ stmt.finalizer = this.visitBlockStatement(stmt.finalizer);
325
+ }
326
+ return stmt;
327
+ }
328
+ visitCatchClause(handler) {
329
+ if (handler) {
330
+ if (handler.param) {
331
+ handler.param = this.visitPattern(handler.param);
332
+ }
333
+ handler.body = this.visitBlockStatement(handler.body);
334
+ }
335
+ return handler;
336
+ }
337
+ visitThrowStatement(stmt) {
338
+ stmt.argument = this.visitExpression(stmt.argument);
339
+ return stmt;
340
+ }
341
+ visitReturnStatement(stmt) {
342
+ if (stmt.argument) {
343
+ stmt.argument = this.visitExpression(stmt.argument);
344
+ }
345
+ return stmt;
346
+ }
347
+ visitLabeledStatement(stmt) {
348
+ stmt.label = this.visitLabelIdentifier(stmt.label);
349
+ stmt.body = this.visitStatement(stmt.body);
350
+ return stmt;
351
+ }
352
+ visitForStatement(stmt) {
353
+ if (stmt.init) {
354
+ if (stmt.init.type === 'VariableDeclaration') {
355
+ stmt.init = this.visitVariableDeclaration(stmt.init);
356
+ }
357
+ else {
358
+ stmt.init = this.visitOptionalExpression(stmt.init);
359
+ }
360
+ }
361
+ stmt.test = this.visitOptionalExpression(stmt.test);
362
+ stmt.update = this.visitOptionalExpression(stmt.update);
363
+ stmt.body = this.visitStatement(stmt.body);
364
+ return stmt;
365
+ }
366
+ visitForOfStatement(stmt) {
367
+ if (stmt.left.type === 'VariableDeclaration') {
368
+ stmt.left = this.visitVariableDeclaration(stmt.left);
369
+ }
370
+ else {
371
+ stmt.left = this.visitPattern(stmt.left);
372
+ }
373
+ stmt.right = this.visitExpression(stmt.right);
374
+ stmt.body = this.visitStatement(stmt.body);
375
+ return stmt;
376
+ }
377
+ visitForInStatement(stmt) {
378
+ if (stmt.left.type === 'VariableDeclaration') {
379
+ stmt.left = this.visitVariableDeclaration(stmt.left);
380
+ }
381
+ else {
382
+ stmt.left = this.visitPattern(stmt.left);
383
+ }
384
+ stmt.right = this.visitExpression(stmt.right);
385
+ stmt.body = this.visitStatement(stmt.body);
386
+ return stmt;
387
+ }
388
+ visitEmptyStatement(stmt) {
389
+ return stmt;
390
+ }
391
+ visitDoWhileStatement(stmt) {
392
+ stmt.body = this.visitStatement(stmt.body);
393
+ stmt.test = this.visitExpression(stmt.test);
394
+ return stmt;
395
+ }
396
+ visitDebuggerStatement(stmt) {
397
+ return stmt;
398
+ }
399
+ visitWithStatement(stmt) {
400
+ stmt.object = this.visitExpression(stmt.object);
401
+ stmt.body = this.visitStatement(stmt.body);
402
+ return stmt;
403
+ }
404
+ visitDeclaration(decl) {
405
+ switch (decl.type) {
406
+ case 'ClassDeclaration':
407
+ return this.visitClassDeclaration(decl);
408
+ case 'FunctionDeclaration':
409
+ return this.visitFunctionDeclaration(decl);
410
+ case 'TsEnumDeclaration':
411
+ return this.visitTsEnumDeclaration(decl);
412
+ case 'TsInterfaceDeclaration':
413
+ return this.visitTsInterfaceDeclaration(decl);
414
+ case 'TsModuleDeclaration':
415
+ return this.visitTsModuleDeclaration(decl);
416
+ case 'TsTypeAliasDeclaration':
417
+ return this.visitTsTypeAliasDeclaration(decl);
418
+ case 'VariableDeclaration':
419
+ return this.visitVariableDeclaration(decl);
420
+ }
421
+ }
422
+ visitVariableDeclaration(n) {
423
+ n.declarations = this.visitVariableDeclarators(n.declarations);
424
+ return n;
425
+ }
426
+ visitVariableDeclarators(nodes) {
427
+ return nodes.map(this.visitVariableDeclarator.bind(this));
428
+ }
429
+ visitVariableDeclarator(n) {
430
+ n.id = this.visitPattern(n.id);
431
+ n.init = this.visitOptionalExpression(n.init);
432
+ return n;
433
+ }
434
+ visitTsTypeAliasDeclaration(n) {
435
+ n.id = this.visitBindingIdentifier(n.id);
436
+ n.typeAnnotation = this.visitTsType(n.typeAnnotation);
437
+ n.typeParams = this.visitTsTypeParameterDeclaration(n.typeParams);
438
+ return n;
439
+ }
440
+ visitTsModuleDeclaration(n) {
441
+ n.id = this.visitTsModuleName(n.id);
442
+ if (n.body) {
443
+ n.body = this.visitTsNamespaceBody(n.body);
444
+ }
445
+ return n;
446
+ }
447
+ visitTsModuleName(n) {
448
+ switch (n.type) {
449
+ case 'Identifier':
450
+ return this.visitBindingIdentifier(n);
451
+ case 'StringLiteral':
452
+ return this.visitStringLiteral(n);
453
+ }
454
+ }
455
+ visitTsNamespaceBody(n) {
456
+ if (n) {
457
+ switch (n.type) {
458
+ case 'TsModuleBlock':
459
+ return this.visitTsModuleBlock(n);
460
+ case 'TsNamespaceDeclaration':
461
+ return this.visitTsNamespaceDeclaration(n);
462
+ }
463
+ }
464
+ }
465
+ visitTsNamespaceDeclaration(n) {
466
+ const body = this.visitTsNamespaceBody(n.body);
467
+ if (body) {
468
+ n.body = body;
469
+ }
470
+ n.id = this.visitBindingIdentifier(n.id);
471
+ return n;
472
+ }
473
+ visitTsModuleBlock(n) {
474
+ n.body = this.visitModuleItems(n.body);
475
+ return n;
476
+ }
477
+ visitTsInterfaceDeclaration(n) {
478
+ n.id = this.visitBindingIdentifier(n.id);
479
+ n.typeParams = this.visitTsTypeParameterDeclaration(n.typeParams);
480
+ n.extends = this.visitTsExpressionsWithTypeArguments(n.extends);
481
+ n.body = this.visitTsInterfaceBody(n.body);
482
+ return n;
483
+ }
484
+ visitTsInterfaceBody(n) {
485
+ n.body = this.visitTsTypeElements(n.body);
486
+ return n;
487
+ }
488
+ visitTsTypeElements(nodes) {
489
+ return nodes.map(this.visitTsTypeElement.bind(this));
490
+ }
491
+ visitTsTypeElement(n) {
492
+ switch (n.type) {
493
+ case 'TsCallSignatureDeclaration':
494
+ return this.visitTsCallSignatureDeclaration(n);
495
+ case 'TsConstructSignatureDeclaration':
496
+ return this.visitTsConstructSignatureDeclaration(n);
497
+ case 'TsPropertySignature':
498
+ return this.visitTsPropertySignature(n);
499
+ case 'TsGetterSignature':
500
+ return this.visitTsGetterSignature(n);
501
+ case 'TsSetterSignature':
502
+ return this.visitTsSetterSignature(n);
503
+ case 'TsMethodSignature':
504
+ return this.visitTsMethodSignature(n);
505
+ case 'TsIndexSignature':
506
+ return this.visitTsIndexSignature(n);
507
+ }
508
+ }
509
+ visitTsCallSignatureDeclaration(n) {
510
+ n.params = this.visitTsFnParameters(n.params);
511
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
512
+ return n;
513
+ }
514
+ visitTsConstructSignatureDeclaration(n) {
515
+ n.params = this.visitTsFnParameters(n.params);
516
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
517
+ return n;
518
+ }
519
+ visitTsPropertySignature(n) {
520
+ n.params = this.visitTsFnParameters(n.params);
521
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
522
+ return n;
523
+ }
524
+ visitTsGetterSignature(n) {
525
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
526
+ return n;
527
+ }
528
+ visitTsSetterSignature(n) {
529
+ n.param = this.visitTsFnParameter(n.param);
530
+ return n;
531
+ }
532
+ visitTsMethodSignature(n) {
533
+ n.params = this.visitTsFnParameters(n.params);
534
+ n.typeAnn = this.visitTsTypeAnnotation(n.typeAnn);
535
+ return n;
536
+ }
537
+ visitTsEnumDeclaration(n) {
538
+ n.id = this.visitIdentifier(n.id);
539
+ n.members = this.visitTsEnumMembers(n.members);
540
+ return n;
541
+ }
542
+ visitTsEnumMembers(nodes) {
543
+ return nodes.map(this.visitTsEnumMember.bind(this));
544
+ }
545
+ visitTsEnumMember(n) {
546
+ n.id = this.visitTsEnumMemberId(n.id);
547
+ n.init = this.visitOptionalExpression(n.init);
548
+ return n;
549
+ }
550
+ visitTsEnumMemberId(n) {
551
+ switch (n.type) {
552
+ case 'Identifier':
553
+ return this.visitBindingIdentifier(n);
554
+ case 'StringLiteral':
555
+ return this.visitStringLiteral(n);
556
+ }
557
+ }
558
+ visitFunctionDeclaration(decl) {
559
+ decl.identifier = this.visitIdentifier(decl.identifier);
560
+ decl = this.visitFunction(decl);
561
+ return decl;
562
+ }
563
+ visitClassDeclaration(decl) {
564
+ decl = this.visitClass(decl);
565
+ decl.identifier = this.visitIdentifier(decl.identifier);
566
+ return decl;
567
+ }
568
+ visitClassBody(members) {
569
+ return members.map(this.visitClassMember.bind(this));
570
+ }
571
+ visitClassMember(member) {
572
+ switch (member.type) {
573
+ case 'ClassMethod':
574
+ return this.visitClassMethod(member);
575
+ case 'ClassProperty':
576
+ return this.visitClassProperty(member);
577
+ case 'Constructor':
578
+ return this.visitConstructor(member);
579
+ case 'PrivateMethod':
580
+ return this.visitPrivateMethod(member);
581
+ case 'PrivateProperty':
582
+ return this.visitPrivateProperty(member);
583
+ case 'TsIndexSignature':
584
+ return this.visitTsIndexSignature(member);
585
+ case 'EmptyStatement':
586
+ return this.visitEmptyStatement(member);
587
+ case 'StaticBlock':
588
+ return this.visitStaticBlock(member);
589
+ }
590
+ }
591
+ visitTsIndexSignature(n) {
592
+ n.params = this.visitTsFnParameters(n.params);
593
+ if (n.typeAnnotation)
594
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
595
+ return n;
596
+ }
597
+ visitTsFnParameters(params) {
598
+ return params.map(this.visitTsFnParameter.bind(this));
599
+ }
600
+ visitTsFnParameter(n) {
601
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
602
+ return n;
603
+ }
604
+ visitPrivateProperty(n) {
605
+ n.decorators = this.visitDecorators(n.decorators);
606
+ n.key = this.visitPrivateName(n.key);
607
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
608
+ n.value = this.visitOptionalExpression(n.value);
609
+ return n;
610
+ }
611
+ visitPrivateMethod(n) {
612
+ n.accessibility = this.visitAccessibility(n.accessibility);
613
+ n.function = this.visitFunction(n.function);
614
+ n.key = this.visitPrivateName(n.key);
615
+ return n;
616
+ }
617
+ visitPrivateName(n) {
618
+ return n;
619
+ }
620
+ visitConstructor(n) {
621
+ n.accessibility = this.visitAccessibility(n.accessibility);
622
+ n.key = this.visitPropertyName(n.key);
623
+ n.params = this.visitConstructorParameters(n.params);
624
+ if (n.body) {
625
+ n.body = this.visitBlockStatement(n.body);
626
+ }
627
+ return n;
628
+ }
629
+ visitConstructorParameters(nodes) {
630
+ return nodes.map(this.visitConstructorParameter.bind(this));
631
+ }
632
+ visitConstructorParameter(n) {
633
+ switch (n.type) {
634
+ case 'TsParameterProperty':
635
+ return this.visitTsParameterProperty(n);
636
+ default:
637
+ return this.visitParameter(n);
638
+ }
639
+ }
640
+ visitStaticBlock(n) {
641
+ n.body = this.visitBlockStatement(n.body);
642
+ return n;
643
+ }
644
+ visitTsParameterProperty(n) {
645
+ n.accessibility = this.visitAccessibility(n.accessibility);
646
+ n.decorators = this.visitDecorators(n.decorators);
647
+ n.param = this.visitTsParameterPropertyParameter(n.param);
648
+ return n;
649
+ }
650
+ visitTsParameterPropertyParameter(n) {
651
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
652
+ return n;
653
+ }
654
+ visitPropertyName(key) {
655
+ switch (key.type) {
656
+ case 'Identifier':
657
+ return this.visitBindingIdentifier(key);
658
+ case 'StringLiteral':
659
+ return this.visitStringLiteral(key);
660
+ case 'NumericLiteral':
661
+ return this.visitNumericLiteral(key);
662
+ case 'BigIntLiteral':
663
+ return this.visitBigIntLiteral(key);
664
+ default:
665
+ return this.visitComputedPropertyKey(key);
666
+ }
667
+ }
668
+ visitAccessibility(n) {
669
+ return n;
670
+ }
671
+ visitClassProperty(n) {
672
+ n.accessibility = this.visitAccessibility(n.accessibility);
673
+ n.decorators = this.visitDecorators(n.decorators);
674
+ n.key = this.visitPropertyName(n.key);
675
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
676
+ n.value = this.visitOptionalExpression(n.value);
677
+ return n;
678
+ }
679
+ visitClassMethod(n) {
680
+ n.accessibility = this.visitAccessibility(n.accessibility);
681
+ n.function = this.visitFunction(n.function);
682
+ n.key = this.visitPropertyName(n.key);
683
+ return n;
684
+ }
685
+ visitComputedPropertyKey(n) {
686
+ n.expression = this.visitExpression(n.expression);
687
+ return n;
688
+ }
689
+ visitClass(n) {
690
+ n.decorators = this.visitDecorators(n.decorators);
691
+ n.superClass = this.visitOptionalExpression(n.superClass);
692
+ n.superTypeParams = this.visitTsTypeParameterInstantiation(n.superTypeParams);
693
+ if (n.implements) {
694
+ n.implements = this.visitTsExpressionsWithTypeArguments(n.implements);
695
+ }
696
+ n.body = this.visitClassBody(n.body);
697
+ return n;
698
+ }
699
+ visitFunction(n) {
700
+ n.decorators = this.visitDecorators(n.decorators);
701
+ n.params = this.visitParameters(n.params);
702
+ if (n.body) {
703
+ n.body = this.visitBlockStatement(n.body);
704
+ }
705
+ n.returnType = this.visitTsTypeAnnotation(n.returnType);
706
+ n.typeParameters = this.visitTsTypeParameterDeclaration(n.typeParameters);
707
+ return n;
708
+ }
709
+ visitTsExpressionsWithTypeArguments(nodes) {
710
+ return nodes.map(this.visitTsExpressionWithTypeArguments.bind(this));
711
+ }
712
+ visitTsExpressionWithTypeArguments(n) {
713
+ n.expression = this.visitExpression(n.expression);
714
+ n.typeArguments = this.visitTsTypeParameterInstantiation(n.typeArguments);
715
+ return n;
716
+ }
717
+ visitTsTypeParameterInstantiation(n) {
718
+ if (n) {
719
+ n.params = this.visitTsTypes(n.params);
720
+ }
721
+ return n;
722
+ }
723
+ visitTsTypes(nodes) {
724
+ return nodes.map(this.visitTsType.bind(this));
725
+ }
726
+ visitTsEntityName(n) {
727
+ switch (n.type) {
728
+ case 'Identifier':
729
+ return this.visitBindingIdentifier(n);
730
+ case 'TsQualifiedName':
731
+ return this.visitTsQualifiedName(n);
732
+ }
733
+ }
734
+ visitTsQualifiedName(n) {
735
+ n.left = this.visitTsEntityName(n.left);
736
+ n.right = this.visitIdentifier(n.right);
737
+ return n;
738
+ }
739
+ visitDecorators(nodes) {
740
+ if (nodes) {
741
+ return nodes.map(this.visitDecorator.bind(this));
742
+ }
743
+ }
744
+ visitDecorator(n) {
745
+ n.expression = this.visitExpression(n.expression);
746
+ return n;
747
+ }
748
+ visitExpressionStatement(stmt) {
749
+ stmt.expression = this.visitExpression(stmt.expression);
750
+ return stmt;
751
+ }
752
+ visitContinueStatement(stmt) {
753
+ if (stmt.label) {
754
+ stmt.label = this.visitLabelIdentifier(stmt.label);
755
+ }
756
+ return stmt;
757
+ }
758
+ visitExpression(n) {
759
+ switch (n.type) {
760
+ case 'ArrayExpression':
761
+ return this.visitArrayExpression(n);
762
+ case 'ArrowFunctionExpression':
763
+ return this.visitArrowFunctionExpression(n);
764
+ case 'AssignmentExpression':
765
+ return this.visitAssignmentExpression(n);
766
+ case 'AwaitExpression':
767
+ return this.visitAwaitExpression(n);
768
+ case 'BigIntLiteral':
769
+ return this.visitBigIntLiteral(n);
770
+ case 'BinaryExpression':
771
+ return this.visitBinaryExpression(n);
772
+ case 'BooleanLiteral':
773
+ return this.visitBooleanLiteral(n);
774
+ case 'CallExpression':
775
+ return this.visitCallExpression(n);
776
+ case 'ClassExpression':
777
+ return this.visitClassExpression(n);
778
+ case 'ConditionalExpression':
779
+ return this.visitConditionalExpression(n);
780
+ case 'FunctionExpression':
781
+ return this.visitFunctionExpression(n);
782
+ case 'Identifier':
783
+ return this.visitIdentifierReference(n);
784
+ case 'JSXElement':
785
+ return this.visitJSXElement(n);
786
+ case 'JSXEmptyExpression':
787
+ return this.visitJSXEmptyExpression(n);
788
+ case 'JSXFragment':
789
+ return this.visitJSXFragment(n);
790
+ case 'JSXMemberExpression':
791
+ return this.visitJSXMemberExpression(n);
792
+ case 'JSXNamespacedName':
793
+ return this.visitJSXNamespacedName(n);
794
+ case 'JSXText':
795
+ return this.visitJSXText(n);
796
+ case 'MemberExpression':
797
+ return this.visitMemberExpression(n);
798
+ case 'SuperPropExpression':
799
+ return this.visitSuperPropExpression(n);
800
+ case 'MetaProperty':
801
+ return this.visitMetaProperty(n);
802
+ case 'NewExpression':
803
+ return this.visitNewExpression(n);
804
+ case 'NullLiteral':
805
+ return this.visitNullLiteral(n);
806
+ case 'NumericLiteral':
807
+ return this.visitNumericLiteral(n);
808
+ case 'ObjectExpression':
809
+ return this.visitObjectExpression(n);
810
+ case 'ParenthesisExpression':
811
+ return this.visitParenthesisExpression(n);
812
+ case 'PrivateName':
813
+ return this.visitPrivateName(n);
814
+ case 'RegExpLiteral':
815
+ return this.visitRegExpLiteral(n);
816
+ case 'SequenceExpression':
817
+ return this.visitSequenceExpression(n);
818
+ case 'StringLiteral':
819
+ return this.visitStringLiteral(n);
820
+ case 'TaggedTemplateExpression':
821
+ return this.visitTaggedTemplateExpression(n);
822
+ case 'TemplateLiteral':
823
+ return this.visitTemplateLiteral(n);
824
+ case 'ThisExpression':
825
+ return this.visitThisExpression(n);
826
+ case 'TsAsExpression':
827
+ return this.visitTsAsExpression(n);
828
+ case 'TsSatisfiesExpression':
829
+ return this.visitTsSatisfiesExpression(n);
830
+ case 'TsNonNullExpression':
831
+ return this.visitTsNonNullExpression(n);
832
+ case 'TsTypeAssertion':
833
+ return this.visitTsTypeAssertion(n);
834
+ case 'TsConstAssertion':
835
+ return this.visitTsConstAssertion(n);
836
+ case 'TsInstantiation':
837
+ return this.visitTsInstantiation(n);
838
+ case 'UnaryExpression':
839
+ return this.visitUnaryExpression(n);
840
+ case 'UpdateExpression':
841
+ return this.visitUpdateExpression(n);
842
+ case 'YieldExpression':
843
+ return this.visitYieldExpression(n);
844
+ case 'OptionalChainingExpression':
845
+ return this.visitOptionalChainingExpression(n);
846
+ case 'Invalid':
847
+ return n;
848
+ }
849
+ }
850
+ visitOptionalChainingExpression(n) {
851
+ n.base = this.visitMemberExpressionOrOptionalChainingCall(n.base);
852
+ return n;
853
+ }
854
+ visitMemberExpressionOrOptionalChainingCall(n) {
855
+ switch (n.type) {
856
+ case 'MemberExpression':
857
+ return this.visitMemberExpression(n);
858
+ case 'CallExpression':
859
+ return this.visitOptionalChainingCall(n);
860
+ }
861
+ }
862
+ visitOptionalChainingCall(n) {
863
+ n.callee = this.visitExpression(n.callee);
864
+ n.arguments = this.visitExprOrSpreads(n.arguments);
865
+ if (n.typeArguments)
866
+ n.typeArguments = this.visitTsTypeParameterInstantiation(n.typeArguments);
867
+ return n;
868
+ }
869
+ visitAssignmentExpression(n) {
870
+ n.left = this.visitPatternOrExpression(n.left);
871
+ n.right = this.visitExpression(n.right);
872
+ return n;
873
+ }
874
+ visitPatternOrExpression(n) {
875
+ switch (n.type) {
876
+ case 'ObjectPattern':
877
+ case 'ArrayPattern':
878
+ case 'Identifier':
879
+ case 'AssignmentPattern':
880
+ case 'RestElement':
881
+ return this.visitPattern(n);
882
+ default:
883
+ return this.visitExpression(n);
884
+ }
885
+ }
886
+ visitYieldExpression(n) {
887
+ n.argument = this.visitOptionalExpression(n.argument);
888
+ return n;
889
+ }
890
+ visitUpdateExpression(n) {
891
+ n.argument = this.visitExpression(n.argument);
892
+ return n;
893
+ }
894
+ visitUnaryExpression(n) {
895
+ n.argument = this.visitExpression(n.argument);
896
+ return n;
897
+ }
898
+ visitTsTypeAssertion(n) {
899
+ n.expression = this.visitExpression(n.expression);
900
+ n.typeAnnotation = this.visitTsType(n.typeAnnotation);
901
+ return n;
902
+ }
903
+ visitTsConstAssertion(n) {
904
+ n.expression = this.visitExpression(n.expression);
905
+ return n;
906
+ }
907
+ visitTsInstantiation(n) {
908
+ n.expression = this.visitExpression(n.expression);
909
+ return n;
910
+ }
911
+ visitTsNonNullExpression(n) {
912
+ n.expression = this.visitExpression(n.expression);
913
+ return n;
914
+ }
915
+ visitTsAsExpression(n) {
916
+ n.expression = this.visitExpression(n.expression);
917
+ n.typeAnnotation = this.visitTsType(n.typeAnnotation);
918
+ return n;
919
+ }
920
+ visitTsSatisfiesExpression(n) {
921
+ n.expression = this.visitExpression(n.expression);
922
+ n.typeAnnotation = this.visitTsType(n.typeAnnotation);
923
+ return n;
924
+ }
925
+ visitThisExpression(n) {
926
+ return n;
927
+ }
928
+ visitTemplateLiteral(n) {
929
+ n.expressions = n.expressions.map(this.visitExpression.bind(this));
930
+ return n;
931
+ }
932
+ visitParameters(n) {
933
+ return n.map(this.visitParameter.bind(this));
934
+ }
935
+ visitParameter(n) {
936
+ n.pat = this.visitPattern(n.pat);
937
+ return n;
938
+ }
939
+ visitTaggedTemplateExpression(n) {
940
+ n.tag = this.visitExpression(n.tag);
941
+ const template = this.visitTemplateLiteral(n.template);
942
+ if (template.type === 'TemplateLiteral') {
943
+ n.template = template;
944
+ }
945
+ return n;
946
+ }
947
+ visitSequenceExpression(n) {
948
+ n.expressions = n.expressions.map(this.visitExpression.bind(this));
949
+ return n;
950
+ }
951
+ visitRegExpLiteral(n) {
952
+ return n;
953
+ }
954
+ visitParenthesisExpression(n) {
955
+ n.expression = this.visitExpression(n.expression);
956
+ return n;
957
+ }
958
+ visitObjectExpression(n) {
959
+ if (n.properties) {
960
+ n.properties = this.visitObjectProperties(n.properties);
961
+ }
962
+ return n;
963
+ }
964
+ visitObjectProperties(nodes) {
965
+ return nodes.map(this.visitObjectProperty.bind(this));
966
+ }
967
+ visitObjectProperty(n) {
968
+ switch (n.type) {
969
+ case 'SpreadElement':
970
+ return this.visitSpreadElement(n);
971
+ default:
972
+ return this.visitProperty(n);
973
+ }
974
+ }
975
+ visitProperty(n) {
976
+ switch (n.type) {
977
+ case 'Identifier':
978
+ return this.visitIdentifier(n);
979
+ case 'AssignmentProperty':
980
+ return this.visitAssignmentProperty(n);
981
+ case 'GetterProperty':
982
+ return this.visitGetterProperty(n);
983
+ case 'KeyValueProperty':
984
+ return this.visitKeyValueProperty(n);
985
+ case 'MethodProperty':
986
+ return this.visitMethodProperty(n);
987
+ case 'SetterProperty':
988
+ return this.visitSetterProperty(n);
989
+ }
990
+ }
991
+ visitSetterProperty(n) {
992
+ n.key = this.visitPropertyName(n.key);
993
+ n.param = this.visitPattern(n.param);
994
+ if (n.body) {
995
+ n.body = this.visitBlockStatement(n.body);
996
+ }
997
+ return n;
998
+ }
999
+ visitMethodProperty(n) {
1000
+ n.key = this.visitPropertyName(n.key);
1001
+ if (n.body) {
1002
+ n.body = this.visitBlockStatement(n.body);
1003
+ }
1004
+ n.decorators = this.visitDecorators(n.decorators);
1005
+ n.params = this.visitParameters(n.params);
1006
+ n.returnType = this.visitTsTypeAnnotation(n.returnType);
1007
+ n.typeParameters = this.visitTsTypeParameterDeclaration(n.typeParameters);
1008
+ return n;
1009
+ }
1010
+ visitKeyValueProperty(n) {
1011
+ n.key = this.visitPropertyName(n.key);
1012
+ n.value = this.visitExpression(n.value);
1013
+ return n;
1014
+ }
1015
+ visitGetterProperty(n) {
1016
+ n.key = this.visitPropertyName(n.key);
1017
+ if (n.body) {
1018
+ n.body = this.visitBlockStatement(n.body);
1019
+ }
1020
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
1021
+ return n;
1022
+ }
1023
+ visitAssignmentProperty(n) {
1024
+ n.key = this.visitIdentifier(n.key);
1025
+ n.value = this.visitExpression(n.value);
1026
+ return n;
1027
+ }
1028
+ visitNullLiteral(n) {
1029
+ return n;
1030
+ }
1031
+ visitNewExpression(n) {
1032
+ n.callee = this.visitExpression(n.callee);
1033
+ if (n.arguments) {
1034
+ n.arguments = this.visitArguments(n.arguments);
1035
+ }
1036
+ n.typeArguments = this.visitTsTypeArguments(n.typeArguments);
1037
+ return n;
1038
+ }
1039
+ visitTsTypeArguments(n) {
1040
+ if (n) {
1041
+ n.params = this.visitTsTypes(n.params);
1042
+ }
1043
+ return n;
1044
+ }
1045
+ visitArguments(nodes) {
1046
+ return nodes.map(this.visitArgument.bind(this));
1047
+ }
1048
+ visitArgument(n) {
1049
+ n.expression = this.visitExpression(n.expression);
1050
+ return n;
1051
+ }
1052
+ visitMetaProperty(n) {
1053
+ return n;
1054
+ }
1055
+ visitMemberExpression(n) {
1056
+ n.object = this.visitExpression(n.object);
1057
+ switch (n.property.type) {
1058
+ case 'Computed': {
1059
+ n.property = this.visitComputedPropertyKey(n.property);
1060
+ return n;
1061
+ }
1062
+ case 'Identifier': {
1063
+ n.property = this.visitIdentifier(n.property);
1064
+ return n;
1065
+ }
1066
+ case 'PrivateName': {
1067
+ n.property = this.visitPrivateName(n.property);
1068
+ return n;
1069
+ }
1070
+ }
1071
+ }
1072
+ visitSuperPropExpression(n) {
1073
+ switch (n.property.type) {
1074
+ case 'Computed': {
1075
+ n.property = this.visitComputedPropertyKey(n.property);
1076
+ return n;
1077
+ }
1078
+ case 'Identifier': {
1079
+ n.property = this.visitIdentifier(n.property);
1080
+ return n;
1081
+ }
1082
+ }
1083
+ }
1084
+ visitCallee(n) {
1085
+ if (n.type === 'Super' || n.type === 'Import') {
1086
+ return n;
1087
+ }
1088
+ return this.visitExpression(n);
1089
+ }
1090
+ visitJSXText(n) {
1091
+ return n;
1092
+ }
1093
+ visitJSXNamespacedName(n) {
1094
+ n.namespace = this.visitIdentifierReference(n.namespace);
1095
+ n.name = this.visitIdentifierReference(n.name);
1096
+ return n;
1097
+ }
1098
+ visitJSXMemberExpression(n) {
1099
+ n.object = this.visitJSXObject(n.object);
1100
+ n.property = this.visitIdentifierReference(n.property);
1101
+ return n;
1102
+ }
1103
+ visitJSXObject(n) {
1104
+ switch (n.type) {
1105
+ case 'Identifier':
1106
+ return this.visitIdentifierReference(n);
1107
+ case 'JSXMemberExpression':
1108
+ return this.visitJSXMemberExpression(n);
1109
+ }
1110
+ }
1111
+ visitJSXFragment(n) {
1112
+ n.opening = this.visitJSXOpeningFragment(n.opening);
1113
+ if (n.children) {
1114
+ n.children = this.visitJSXElementChildren(n.children);
1115
+ }
1116
+ n.closing = this.visitJSXClosingFragment(n.closing);
1117
+ return n;
1118
+ }
1119
+ visitJSXClosingFragment(n) {
1120
+ return n;
1121
+ }
1122
+ visitJSXElementChildren(nodes) {
1123
+ return nodes.map(this.visitJSXElementChild.bind(this));
1124
+ }
1125
+ visitJSXElementChild(n) {
1126
+ switch (n.type) {
1127
+ case 'JSXElement':
1128
+ return this.visitJSXElement(n);
1129
+ case 'JSXExpressionContainer':
1130
+ return this.visitJSXExpressionContainer(n);
1131
+ case 'JSXFragment':
1132
+ return this.visitJSXFragment(n);
1133
+ case 'JSXSpreadChild':
1134
+ return this.visitJSXSpreadChild(n);
1135
+ case 'JSXText':
1136
+ return this.visitJSXText(n);
1137
+ }
1138
+ }
1139
+ visitJSXExpressionContainer(n) {
1140
+ n.expression = this.visitExpression(n.expression);
1141
+ return n;
1142
+ }
1143
+ visitJSXSpreadChild(n) {
1144
+ n.expression = this.visitExpression(n.expression);
1145
+ return n;
1146
+ }
1147
+ visitJSXOpeningFragment(n) {
1148
+ return n;
1149
+ }
1150
+ visitJSXEmptyExpression(n) {
1151
+ return n;
1152
+ }
1153
+ visitJSXElement(n) {
1154
+ n.opening = this.visitJSXOpeningElement(n.opening);
1155
+ n.children = this.visitJSXElementChildren(n.children);
1156
+ n.closing = this.visitJSXClosingElement(n.closing);
1157
+ return n;
1158
+ }
1159
+ visitJSXClosingElement(n) {
1160
+ if (n) {
1161
+ n.name = this.visitJSXElementName(n.name);
1162
+ }
1163
+ return n;
1164
+ }
1165
+ visitJSXElementName(n) {
1166
+ switch (n.type) {
1167
+ case 'Identifier':
1168
+ return this.visitIdentifierReference(n);
1169
+ case 'JSXMemberExpression':
1170
+ return this.visitJSXMemberExpression(n);
1171
+ case 'JSXNamespacedName':
1172
+ return this.visitJSXNamespacedName(n);
1173
+ }
1174
+ }
1175
+ visitJSXOpeningElement(n) {
1176
+ n.name = this.visitJSXElementName(n.name);
1177
+ n.typeArguments = this.visitTsTypeParameterInstantiation(n.typeArguments);
1178
+ n.attributes = this.visitJSXAttributeOrSpreads(n.attributes);
1179
+ return n;
1180
+ }
1181
+ visitJSXAttributes(attrs) {
1182
+ if (attrs)
1183
+ return attrs.map(this.visitJSXAttributeOrSpread.bind(this));
1184
+ }
1185
+ visitJSXAttributeOrSpread(n) {
1186
+ switch (n.type) {
1187
+ case 'JSXAttribute':
1188
+ return this.visitJSXAttribute(n);
1189
+ case 'SpreadElement':
1190
+ return this.visitSpreadElement(n);
1191
+ }
1192
+ }
1193
+ visitJSXAttributeOrSpreads(nodes) {
1194
+ return nodes.map(this.visitJSXAttributeOrSpread.bind(this));
1195
+ }
1196
+ visitJSXAttribute(n) {
1197
+ n.name = this.visitJSXAttributeName(n.name);
1198
+ n.value = this.visitJSXAttributeValue(n.value);
1199
+ return n;
1200
+ }
1201
+ visitJSXAttributeValue(n) {
1202
+ if (!n)
1203
+ return n;
1204
+ switch (n.type) {
1205
+ case 'BooleanLiteral':
1206
+ return this.visitBooleanLiteral(n);
1207
+ case 'NullLiteral':
1208
+ return this.visitNullLiteral(n);
1209
+ case 'NumericLiteral':
1210
+ return this.visitNumericLiteral(n);
1211
+ case 'JSXText':
1212
+ return this.visitJSXText(n);
1213
+ case 'StringLiteral':
1214
+ return this.visitStringLiteral(n);
1215
+ case 'JSXElement':
1216
+ return this.visitJSXElement(n);
1217
+ case 'JSXExpressionContainer':
1218
+ return this.visitJSXExpressionContainer(n);
1219
+ case 'JSXFragment':
1220
+ return this.visitJSXFragment(n);
1221
+ }
1222
+ return n;
1223
+ }
1224
+ visitJSXAttributeName(n) {
1225
+ switch (n.type) {
1226
+ case 'Identifier':
1227
+ return this.visitIdentifierReference(n);
1228
+ case 'JSXNamespacedName':
1229
+ return this.visitJSXNamespacedName(n);
1230
+ }
1231
+ }
1232
+ visitConditionalExpression(n) {
1233
+ n.test = this.visitExpression(n.test);
1234
+ n.consequent = this.visitExpression(n.consequent);
1235
+ n.alternate = this.visitExpression(n.alternate);
1236
+ return n;
1237
+ }
1238
+ visitCallExpression(n) {
1239
+ n.callee = this.visitCallee(n.callee);
1240
+ n.typeArguments = this.visitTsTypeParameterInstantiation(n.typeArguments);
1241
+ if (n.arguments) {
1242
+ n.arguments = this.visitArguments(n.arguments);
1243
+ }
1244
+ return n;
1245
+ }
1246
+ visitBooleanLiteral(n) {
1247
+ return n;
1248
+ }
1249
+ visitBinaryExpression(n) {
1250
+ n.left = this.visitExpression(n.left);
1251
+ n.right = this.visitExpression(n.right);
1252
+ return n;
1253
+ }
1254
+ visitAwaitExpression(n) {
1255
+ n.argument = this.visitExpression(n.argument);
1256
+ return n;
1257
+ }
1258
+ visitTsTypeParameterDeclaration(n) {
1259
+ if (n) {
1260
+ n.parameters = this.visitTsTypeParameters(n.parameters);
1261
+ }
1262
+ return n;
1263
+ }
1264
+ visitTsTypeParameters(nodes) {
1265
+ return nodes.map(this.visitTsTypeParameter.bind(this));
1266
+ }
1267
+ visitTsTypeParameter(n) {
1268
+ if (n.constraint) {
1269
+ n.constraint = this.visitTsType(n.constraint);
1270
+ }
1271
+ if (n.default) {
1272
+ n.default = this.visitTsType(n.default);
1273
+ }
1274
+ n.name = this.visitIdentifierReference(n.name);
1275
+ return n;
1276
+ }
1277
+ visitTsTypeAnnotation(a) {
1278
+ if (a) {
1279
+ a.typeAnnotation = this.visitTsType(a.typeAnnotation);
1280
+ }
1281
+ return a;
1282
+ }
1283
+ visitTsType(n) {
1284
+ return n;
1285
+ throw new Error('Method visitTsType not implemented.');
1286
+ }
1287
+ visitPatterns(nodes) {
1288
+ return nodes.map(this.visitPattern.bind(this));
1289
+ }
1290
+ visitImportDeclaration(n) {
1291
+ n.source = this.visitStringLiteral(n.source);
1292
+ n.specifiers = this.visitImportSpecifiers(n.specifiers || []);
1293
+ return n;
1294
+ }
1295
+ visitImportSpecifiers(nodes) {
1296
+ return nodes.map(this.visitImportSpecifier.bind(this));
1297
+ }
1298
+ visitImportSpecifier(node) {
1299
+ switch (node.type) {
1300
+ case 'ImportDefaultSpecifier':
1301
+ return this.visitImportDefaultSpecifier(node);
1302
+ case 'ImportNamespaceSpecifier':
1303
+ return this.visitImportNamespaceSpecifier(node);
1304
+ case 'ImportSpecifier':
1305
+ return this.visitNamedImportSpecifier(node);
1306
+ }
1307
+ }
1308
+ visitNamedImportSpecifier(node) {
1309
+ node.local = this.visitBindingIdentifier(node.local);
1310
+ if (node.imported) {
1311
+ node.imported = this.visitModuleExportName(node.imported);
1312
+ }
1313
+ return node;
1314
+ }
1315
+ visitImportNamespaceSpecifier(node) {
1316
+ node.local = this.visitBindingIdentifier(node.local);
1317
+ return node;
1318
+ }
1319
+ visitImportDefaultSpecifier(node) {
1320
+ node.local = this.visitBindingIdentifier(node.local);
1321
+ return node;
1322
+ }
1323
+ visitBindingIdentifier(i) {
1324
+ if (i.typeAnnotation) {
1325
+ i.typeAnnotation = this.visitTsTypeAnnotation(i.typeAnnotation);
1326
+ }
1327
+ return this.visitIdentifier(i);
1328
+ }
1329
+ visitIdentifierReference(i) {
1330
+ return this.visitIdentifier(i);
1331
+ }
1332
+ visitLabelIdentifier(label) {
1333
+ return this.visitIdentifier(label);
1334
+ }
1335
+ visitIdentifier(n) {
1336
+ return n;
1337
+ }
1338
+ visitStringLiteral(n) {
1339
+ return n;
1340
+ }
1341
+ visitNumericLiteral(n) {
1342
+ return n;
1343
+ }
1344
+ visitBigIntLiteral(n) {
1345
+ return n;
1346
+ }
1347
+ visitPattern(n) {
1348
+ switch (n.type) {
1349
+ case 'Identifier':
1350
+ return this.visitBindingIdentifier(n);
1351
+ case 'ArrayPattern':
1352
+ return this.visitArrayPattern(n);
1353
+ case 'ObjectPattern':
1354
+ return this.visitObjectPattern(n);
1355
+ case 'AssignmentPattern':
1356
+ return this.visitAssignmentPattern(n);
1357
+ case 'RestElement':
1358
+ return this.visitRestElement(n);
1359
+ default:
1360
+ return this.visitExpression(n);
1361
+ }
1362
+ }
1363
+ visitRestElement(n) {
1364
+ n.argument = this.visitPattern(n.argument);
1365
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
1366
+ return n;
1367
+ }
1368
+ visitAssignmentPattern(n) {
1369
+ n.left = this.visitPattern(n.left);
1370
+ n.right = this.visitExpression(n.right);
1371
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
1372
+ return n;
1373
+ }
1374
+ visitObjectPattern(n) {
1375
+ n.properties = this.visitObjectPatternProperties(n.properties || []);
1376
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
1377
+ return n;
1378
+ }
1379
+ visitObjectPatternProperties(nodes) {
1380
+ return nodes.map(this.visitObjectPatternProperty.bind(this));
1381
+ }
1382
+ visitObjectPatternProperty(n) {
1383
+ switch (n.type) {
1384
+ case 'AssignmentPatternProperty':
1385
+ return this.visitAssignmentPatternProperty(n);
1386
+ case 'KeyValuePatternProperty':
1387
+ return this.visitKeyValuePatternProperty(n);
1388
+ case 'RestElement':
1389
+ return this.visitRestElement(n);
1390
+ }
1391
+ }
1392
+ visitKeyValuePatternProperty(n) {
1393
+ n.key = this.visitPropertyName(n.key);
1394
+ n.value = this.visitPattern(n.value);
1395
+ return n;
1396
+ }
1397
+ visitAssignmentPatternProperty(n) {
1398
+ n.key = this.visitBindingIdentifier(n.key);
1399
+ n.value = this.visitOptionalExpression(n.value);
1400
+ return n;
1401
+ }
1402
+ visitArrayPattern(n) {
1403
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
1404
+ n.elements = this.visitArrayPatternElements(n.elements);
1405
+ return n;
1406
+ }
1407
+ visitArrayPatternElements(nodes) {
1408
+ return nodes.map(this.visitArrayPatternElement.bind(this));
1409
+ }
1410
+ visitArrayPatternElement(n) {
1411
+ if (n) {
1412
+ n = this.visitPattern(n);
1413
+ }
1414
+ return n;
1415
+ }
1416
+ }
1417
+ exports.Visitor = Visitor;
1418
+ exports.default = Visitor;