@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,1847 @@
1
+ /**
2
+ * This is an implementation of
3
+ * https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts
4
+ *
5
+ * The JS API is deprecated, but there doesn't seem to be a valid alternative at this point.
6
+ */
7
+
8
+ /* eslint-disable @typescript-eslint/no-unused-vars */
9
+ /* eslint-disable @typescript-eslint/no-explicit-any */
10
+ /* eslint-disable no-param-reassign */
11
+ /* eslint-disable class-methods-use-this */
12
+ /* eslint-disable consistent-return */
13
+ // eslint-disable-next-line import/no-extraneous-dependencies
14
+ import {
15
+ Accessibility,
16
+ Argument,
17
+ ArrayExpression,
18
+ ArrayPattern,
19
+ ArrowFunctionExpression,
20
+ AssignmentExpression,
21
+ AssignmentPattern,
22
+ AssignmentPatternProperty,
23
+ AssignmentProperty,
24
+ AwaitExpression,
25
+ BigIntLiteral,
26
+ BinaryExpression,
27
+ BindingIdentifier,
28
+ BlockStatement,
29
+ BooleanLiteral,
30
+ BreakStatement,
31
+ CallExpression,
32
+ CatchClause,
33
+ Class,
34
+ ClassDeclaration,
35
+ ClassExpression,
36
+ ClassMember,
37
+ ClassMethod,
38
+ ClassProperty,
39
+ ComputedPropName,
40
+ ConditionalExpression,
41
+ Constructor,
42
+ ContinueStatement,
43
+ DebuggerStatement,
44
+ Declaration,
45
+ Decorator,
46
+ DefaultDecl,
47
+ DoWhileStatement,
48
+ EmptyStatement,
49
+ ExportAllDeclaration,
50
+ ExportDeclaration,
51
+ ExportDefaultDeclaration,
52
+ ExportDefaultExpression,
53
+ ExportDefaultSpecifier,
54
+ ExportNamedDeclaration,
55
+ ExportNamespaceSpecifier,
56
+ ExportSpecifier,
57
+ ExprOrSpread,
58
+ Expression,
59
+ ExpressionStatement,
60
+ Fn,
61
+ ForInStatement,
62
+ ForOfStatement,
63
+ ForStatement,
64
+ FunctionDeclaration,
65
+ FunctionExpression,
66
+ GetterProperty,
67
+ Identifier,
68
+ IfStatement,
69
+ Import,
70
+ ImportDeclaration,
71
+ ImportDefaultSpecifier,
72
+ ImportNamespaceSpecifier,
73
+ ImportSpecifier,
74
+ JSXAttrValue,
75
+ JSXAttribute,
76
+ JSXAttributeName,
77
+ JSXAttributeOrSpread,
78
+ JSXClosingElement,
79
+ JSXClosingFragment,
80
+ JSXElement,
81
+ JSXElementChild,
82
+ JSXElementName,
83
+ JSXEmptyExpression,
84
+ JSXExpressionContainer,
85
+ JSXFragment,
86
+ JSXMemberExpression,
87
+ JSXNamespacedName,
88
+ JSXObject,
89
+ JSXOpeningElement,
90
+ JSXOpeningFragment,
91
+ JSXSpreadChild,
92
+ JSXText,
93
+ KeyValuePatternProperty,
94
+ KeyValueProperty,
95
+ LabeledStatement,
96
+ MemberExpression,
97
+ MetaProperty,
98
+ MethodProperty,
99
+ Module,
100
+ ModuleDeclaration,
101
+ ModuleExportName,
102
+ ModuleItem,
103
+ NamedExportSpecifier,
104
+ NamedImportSpecifier,
105
+ NewExpression,
106
+ NullLiteral,
107
+ NumericLiteral,
108
+ ObjectExpression,
109
+ ObjectPattern,
110
+ ObjectPatternProperty,
111
+ OptionalChainingCall,
112
+ OptionalChainingExpression,
113
+ Param,
114
+ ParenthesisExpression,
115
+ Pattern,
116
+ PrivateMethod,
117
+ PrivateName,
118
+ PrivateProperty,
119
+ Program,
120
+ Property,
121
+ PropertyName,
122
+ RegExpLiteral,
123
+ RestElement,
124
+ ReturnStatement,
125
+ Script,
126
+ SequenceExpression,
127
+ SetterProperty,
128
+ SpreadElement,
129
+ Statement,
130
+ StaticBlock,
131
+ StringLiteral,
132
+ Super,
133
+ SuperPropExpression,
134
+ SwitchCase,
135
+ SwitchStatement,
136
+ TaggedTemplateExpression,
137
+ TemplateLiteral,
138
+ ThisExpression,
139
+ ThrowStatement,
140
+ TryStatement,
141
+ TsAsExpression,
142
+ TsCallSignatureDeclaration,
143
+ TsConstAssertion,
144
+ TsConstructSignatureDeclaration,
145
+ TsEntityName,
146
+ TsEnumDeclaration,
147
+ TsEnumMember,
148
+ TsEnumMemberId,
149
+ TsExportAssignment,
150
+ TsExpressionWithTypeArguments,
151
+ TsExternalModuleReference,
152
+ TsFnParameter,
153
+ TsGetterSignature,
154
+ TsImportEqualsDeclaration,
155
+ TsIndexSignature,
156
+ TsInstantiation,
157
+ TsInterfaceBody,
158
+ TsInterfaceDeclaration,
159
+ TsMethodSignature,
160
+ TsModuleBlock,
161
+ TsModuleDeclaration,
162
+ TsModuleName,
163
+ TsModuleReference,
164
+ TsNamespaceBody,
165
+ TsNamespaceDeclaration,
166
+ TsNamespaceExportDeclaration,
167
+ TsNonNullExpression,
168
+ TsParameterProperty,
169
+ TsParameterPropertyParameter,
170
+ TsPropertySignature,
171
+ TsQualifiedName,
172
+ TsSatisfiesExpression,
173
+ TsSetterSignature,
174
+ TsType,
175
+ TsTypeAliasDeclaration,
176
+ TsTypeAnnotation,
177
+ TsTypeAssertion,
178
+ TsTypeElement,
179
+ TsTypeParameter,
180
+ TsTypeParameterDeclaration,
181
+ TsTypeParameterInstantiation,
182
+ UnaryExpression,
183
+ UpdateExpression,
184
+ VariableDeclaration,
185
+ VariableDeclarator,
186
+ WhileStatement,
187
+ WithStatement,
188
+ YieldExpression,
189
+ } from '@swc/types'
190
+
191
+ /**
192
+ * @deprecated JavaScript API is deprecated. Please use Wasm plugin instead.
193
+ */
194
+ export class Visitor {
195
+ visitProgram(n: Program): Program {
196
+ switch (n.type) {
197
+ case 'Module':
198
+ return this.visitModule(n)
199
+ case 'Script':
200
+ return this.visitScript(n)
201
+ }
202
+ }
203
+
204
+ visitModule(m: Module): Module {
205
+ m.body = this.visitModuleItems(m.body)
206
+ return m
207
+ }
208
+
209
+ visitScript(m: Script): Script {
210
+ m.body = this.visitStatements(m.body)
211
+ return m
212
+ }
213
+
214
+ visitModuleItems(items: ModuleItem[]): ModuleItem[] {
215
+ return items.map(this.visitModuleItem.bind(this))
216
+ }
217
+
218
+ visitModuleItem(n: ModuleItem): ModuleItem {
219
+ switch (n.type) {
220
+ case 'ExportDeclaration':
221
+ case 'ExportDefaultDeclaration':
222
+ case 'ExportNamedDeclaration':
223
+ case 'ExportDefaultExpression':
224
+ case 'ImportDeclaration':
225
+ case 'ExportAllDeclaration':
226
+ case 'TsImportEqualsDeclaration':
227
+ case 'TsExportAssignment':
228
+ case 'TsNamespaceExportDeclaration':
229
+ return this.visitModuleDeclaration(n)
230
+ default:
231
+ return this.visitStatement(n)
232
+ }
233
+ }
234
+
235
+ visitModuleDeclaration(n: ModuleDeclaration): ModuleDeclaration {
236
+ switch (n.type) {
237
+ case 'ExportDeclaration':
238
+ return this.visitExportDeclaration(n)
239
+ case 'ExportDefaultDeclaration':
240
+ return this.visitExportDefaultDeclaration(n)
241
+ case 'ExportNamedDeclaration':
242
+ return this.visitExportNamedDeclaration(n)
243
+ case 'ExportDefaultExpression':
244
+ return this.visitExportDefaultExpression(n)
245
+ case 'ImportDeclaration':
246
+ return this.visitImportDeclaration(n)
247
+ case 'ExportAllDeclaration':
248
+ return this.visitExportAllDeclaration(n)
249
+ case 'TsImportEqualsDeclaration':
250
+ return this.visitTsImportEqualsDeclaration(n)
251
+ case 'TsExportAssignment':
252
+ return this.visitTsExportAssignment(n)
253
+ case 'TsNamespaceExportDeclaration':
254
+ return this.visitTsNamespaceExportDeclaration(n)
255
+ }
256
+ }
257
+
258
+ visitTsNamespaceExportDeclaration(n: TsNamespaceExportDeclaration): ModuleDeclaration {
259
+ n.id = this.visitBindingIdentifier(n.id)
260
+ return n
261
+ }
262
+
263
+ visitTsExportAssignment(n: TsExportAssignment): TsExportAssignment {
264
+ n.expression = this.visitExpression(n.expression)
265
+
266
+ return n
267
+ }
268
+
269
+ visitTsImportEqualsDeclaration(n: TsImportEqualsDeclaration): ModuleDeclaration {
270
+ n.id = this.visitBindingIdentifier(n.id)
271
+ n.moduleRef = this.visitTsModuleReference(n.moduleRef)
272
+ return n
273
+ }
274
+
275
+ visitTsModuleReference(n: TsModuleReference): TsModuleReference {
276
+ switch (n.type) {
277
+ case 'Identifier':
278
+ return this.visitIdentifierReference(n)
279
+ case 'TsExternalModuleReference':
280
+ return this.visitTsExternalModuleReference(n)
281
+ case 'TsQualifiedName':
282
+ return this.visitTsQualifiedName(n)
283
+ }
284
+ }
285
+
286
+ visitTsExternalModuleReference(n: TsExternalModuleReference): TsExternalModuleReference {
287
+ n.expression = this.visitStringLiteral(n.expression)
288
+ return n
289
+ }
290
+
291
+ visitExportAllDeclaration(n: ExportAllDeclaration): ModuleDeclaration {
292
+ n.source = this.visitStringLiteral(n.source)
293
+ return n
294
+ }
295
+
296
+ visitExportDefaultExpression(n: ExportDefaultExpression): ModuleDeclaration {
297
+ n.expression = this.visitExpression(n.expression)
298
+ return n
299
+ }
300
+
301
+ visitExportNamedDeclaration(n: ExportNamedDeclaration): ModuleDeclaration {
302
+ n.specifiers = this.visitExportSpecifiers(n.specifiers)
303
+ n.source = this.visitOptionalStringLiteral(n.source)
304
+ return n
305
+ }
306
+
307
+ visitExportSpecifiers(nodes: ExportSpecifier[]): ExportSpecifier[] {
308
+ return nodes.map(this.visitExportSpecifier.bind(this))
309
+ }
310
+
311
+ visitExportSpecifier(n: ExportSpecifier): ExportSpecifier {
312
+ switch (n.type) {
313
+ case 'ExportDefaultSpecifier':
314
+ return this.visitExportDefaultSpecifier(n)
315
+ case 'ExportNamespaceSpecifier':
316
+ return this.visitExportNamespaceSpecifier(n)
317
+ case 'ExportSpecifier':
318
+ return this.visitNamedExportSpecifier(n)
319
+ }
320
+ }
321
+
322
+ visitNamedExportSpecifier(n: NamedExportSpecifier): ExportSpecifier {
323
+ if (n.exported) {
324
+ n.exported = this.visitModuleExportName(n.exported)
325
+ }
326
+ n.orig = this.visitModuleExportName(n.orig)
327
+ return n
328
+ }
329
+
330
+ visitModuleExportName(n: ModuleExportName): ModuleExportName {
331
+ switch (n.type) {
332
+ case 'Identifier':
333
+ return this.visitIdentifier(n)
334
+ case 'StringLiteral':
335
+ return this.visitStringLiteral(n)
336
+ }
337
+ }
338
+
339
+ visitExportNamespaceSpecifier(n: ExportNamespaceSpecifier): ExportSpecifier {
340
+ n.name = this.visitModuleExportName(n.name)
341
+ return n
342
+ }
343
+
344
+ visitExportDefaultSpecifier(n: ExportDefaultSpecifier): ExportSpecifier {
345
+ n.exported = this.visitBindingIdentifier(n.exported)
346
+ return n
347
+ }
348
+
349
+ visitOptionalStringLiteral(n: StringLiteral | undefined): StringLiteral | undefined {
350
+ if (n) {
351
+ return this.visitStringLiteral(n)
352
+ }
353
+ }
354
+
355
+ visitExportDefaultDeclaration(n: ExportDefaultDeclaration): ModuleDeclaration {
356
+ n.decl = this.visitDefaultDeclaration(n.decl)
357
+ return n
358
+ }
359
+
360
+ visitDefaultDeclaration(n: DefaultDecl): DefaultDecl {
361
+ switch (n.type) {
362
+ case 'ClassExpression':
363
+ return this.visitClassExpression(n)
364
+ case 'FunctionExpression':
365
+ return this.visitFunctionExpression(n)
366
+ case 'TsInterfaceDeclaration':
367
+ return this.visitTsInterfaceDeclaration(n)
368
+ }
369
+ }
370
+
371
+ visitFunctionExpression(n: FunctionExpression): FunctionExpression {
372
+ n = this.visitFunction(n)
373
+ if (n.identifier) {
374
+ n.identifier = this.visitBindingIdentifier(n.identifier)
375
+ }
376
+ return n
377
+ }
378
+
379
+ visitClassExpression(n: ClassExpression): ClassExpression {
380
+ n = this.visitClass(n)
381
+ if (n.identifier) {
382
+ n.identifier = this.visitBindingIdentifier(n.identifier)
383
+ }
384
+ return n
385
+ }
386
+
387
+ visitExportDeclaration(n: ExportDeclaration): ModuleDeclaration {
388
+ n.declaration = this.visitDeclaration(n.declaration)
389
+ return n
390
+ }
391
+
392
+ visitArrayExpression(e: ArrayExpression): Expression {
393
+ if (e.elements) {
394
+ e.elements = e.elements.map(this.visitArrayElement.bind(this))
395
+ }
396
+ return e
397
+ }
398
+
399
+ visitArrayElement(e: ExprOrSpread | undefined): ExprOrSpread | undefined {
400
+ if (e) {
401
+ return this.visitExprOrSpread(e)
402
+ }
403
+ }
404
+
405
+ visitExprOrSpread(e: ExprOrSpread): ExprOrSpread {
406
+ return {
407
+ ...e,
408
+ expression: this.visitExpression(e.expression),
409
+ }
410
+ }
411
+
412
+ visitExprOrSpreads(nodes: ExprOrSpread[]): ExprOrSpread[] {
413
+ return nodes.map(this.visitExprOrSpread.bind(this))
414
+ }
415
+
416
+ visitSpreadElement(e: SpreadElement): SpreadElement {
417
+ e.arguments = this.visitExpression(e.arguments)
418
+ return e
419
+ }
420
+
421
+ visitOptionalExpression(e: Expression | undefined): Expression | undefined {
422
+ if (e) {
423
+ return this.visitExpression(e)
424
+ }
425
+ }
426
+
427
+ visitArrowFunctionExpression(e: ArrowFunctionExpression): Expression {
428
+ e.body = this.visitArrowBody(e.body)
429
+ e.params = this.visitPatterns(e.params)
430
+ e.returnType = this.visitTsTypeAnnotation(e.returnType)
431
+ e.typeParameters = this.visitTsTypeParameterDeclaration(e.typeParameters)
432
+
433
+ return e
434
+ }
435
+
436
+ visitArrowBody(body: BlockStatement | Expression): BlockStatement | Expression {
437
+ switch (body.type) {
438
+ case 'BlockStatement':
439
+ return this.visitBlockStatement(body)
440
+ default:
441
+ return this.visitExpression(body)
442
+ }
443
+ }
444
+
445
+ visitBlockStatement(block: BlockStatement): BlockStatement {
446
+ block.stmts = this.visitStatements(block.stmts)
447
+
448
+ return block
449
+ }
450
+
451
+ visitStatements(stmts: Statement[]): Statement[] {
452
+ return stmts.map(this.visitStatement.bind(this))
453
+ }
454
+
455
+ visitStatement(stmt: Statement): Statement {
456
+ switch (stmt.type) {
457
+ case 'ClassDeclaration':
458
+ case 'FunctionDeclaration':
459
+ case 'TsEnumDeclaration':
460
+ case 'TsInterfaceDeclaration':
461
+ case 'TsModuleDeclaration':
462
+ case 'TsTypeAliasDeclaration':
463
+ case 'VariableDeclaration':
464
+ return this.visitDeclaration(stmt)
465
+
466
+ case 'BreakStatement':
467
+ return this.visitBreakStatement(stmt)
468
+ case 'BlockStatement':
469
+ return this.visitBlockStatement(stmt)
470
+ case 'ContinueStatement':
471
+ return this.visitContinueStatement(stmt)
472
+ case 'DebuggerStatement':
473
+ return this.visitDebuggerStatement(stmt)
474
+ case 'DoWhileStatement':
475
+ return this.visitDoWhileStatement(stmt)
476
+ case 'EmptyStatement':
477
+ return this.visitEmptyStatement(stmt)
478
+ case 'ForInStatement':
479
+ return this.visitForInStatement(stmt)
480
+ case 'ForOfStatement':
481
+ return this.visitForOfStatement(stmt)
482
+ case 'ForStatement':
483
+ return this.visitForStatement(stmt)
484
+ case 'IfStatement':
485
+ return this.visitIfStatement(stmt)
486
+ case 'LabeledStatement':
487
+ return this.visitLabeledStatement(stmt)
488
+ case 'ReturnStatement':
489
+ return this.visitReturnStatement(stmt)
490
+ case 'SwitchStatement':
491
+ return this.visitSwitchStatement(stmt)
492
+ case 'ThrowStatement':
493
+ return this.visitThrowStatement(stmt)
494
+ case 'TryStatement':
495
+ return this.visitTryStatement(stmt)
496
+ case 'WhileStatement':
497
+ return this.visitWhileStatement(stmt)
498
+ case 'WithStatement':
499
+ return this.visitWithStatement(stmt)
500
+ case 'ExpressionStatement':
501
+ return this.visitExpressionStatement(stmt)
502
+
503
+ default:
504
+ throw new Error(`Unknown statement type: ${(stmt as any).type}`)
505
+ }
506
+ }
507
+
508
+ visitSwitchStatement(stmt: SwitchStatement): Statement {
509
+ stmt.discriminant = this.visitExpression(stmt.discriminant)
510
+ stmt.cases = this.visitSwitchCases(stmt.cases)
511
+ return stmt
512
+ }
513
+
514
+ visitSwitchCases(cases: SwitchCase[]): SwitchCase[] {
515
+ return cases.map(this.visitSwitchCase.bind(this))
516
+ }
517
+
518
+ visitSwitchCase(c: SwitchCase): SwitchCase {
519
+ c.test = this.visitOptionalExpression(c.test)
520
+ c.consequent = this.visitStatements(c.consequent)
521
+
522
+ return c
523
+ }
524
+
525
+ visitIfStatement(stmt: IfStatement): Statement {
526
+ stmt.test = this.visitExpression(stmt.test)
527
+ stmt.consequent = this.visitStatement(stmt.consequent)
528
+ stmt.alternate = this.visitOptionalStatement(stmt.alternate)
529
+
530
+ return stmt
531
+ }
532
+
533
+ visitOptionalStatement(stmt: Statement | undefined): Statement | undefined {
534
+ if (stmt) {
535
+ return this.visitStatement(stmt)
536
+ }
537
+ }
538
+
539
+ visitBreakStatement(stmt: BreakStatement): Statement {
540
+ if (stmt.label) {
541
+ stmt.label = this.visitLabelIdentifier(stmt.label)
542
+ }
543
+
544
+ return stmt
545
+ }
546
+
547
+ visitWhileStatement(stmt: WhileStatement): Statement {
548
+ stmt.test = this.visitExpression(stmt.test)
549
+ stmt.body = this.visitStatement(stmt.body)
550
+ return stmt
551
+ }
552
+
553
+ visitTryStatement(stmt: TryStatement): Statement {
554
+ stmt.block = this.visitBlockStatement(stmt.block)
555
+ stmt.handler = this.visitCatchClause(stmt.handler)
556
+ if (stmt.finalizer) {
557
+ stmt.finalizer = this.visitBlockStatement(stmt.finalizer)
558
+ }
559
+ return stmt
560
+ }
561
+
562
+ visitCatchClause(handler: CatchClause | undefined): CatchClause | undefined {
563
+ if (handler) {
564
+ if (handler.param) {
565
+ handler.param = this.visitPattern(handler.param)
566
+ }
567
+
568
+ handler.body = this.visitBlockStatement(handler.body)
569
+ }
570
+
571
+ return handler
572
+ }
573
+
574
+ visitThrowStatement(stmt: ThrowStatement): Statement {
575
+ stmt.argument = this.visitExpression(stmt.argument)
576
+ return stmt
577
+ }
578
+
579
+ visitReturnStatement(stmt: ReturnStatement): Statement {
580
+ if (stmt.argument) {
581
+ stmt.argument = this.visitExpression(stmt.argument)
582
+ }
583
+ return stmt
584
+ }
585
+
586
+ visitLabeledStatement(stmt: LabeledStatement): Statement {
587
+ stmt.label = this.visitLabelIdentifier(stmt.label)
588
+ stmt.body = this.visitStatement(stmt.body)
589
+
590
+ return stmt
591
+ }
592
+
593
+ visitForStatement(stmt: ForStatement): Statement {
594
+ if (stmt.init) {
595
+ if (stmt.init.type === 'VariableDeclaration') {
596
+ stmt.init = this.visitVariableDeclaration(stmt.init)
597
+ } else {
598
+ stmt.init = this.visitOptionalExpression(stmt.init)
599
+ }
600
+ }
601
+
602
+ stmt.test = this.visitOptionalExpression(stmt.test)
603
+ stmt.update = this.visitOptionalExpression(stmt.update)
604
+ stmt.body = this.visitStatement(stmt.body)
605
+
606
+ return stmt
607
+ }
608
+
609
+ visitForOfStatement(stmt: ForOfStatement): Statement {
610
+ if (stmt.left.type === 'VariableDeclaration') {
611
+ stmt.left = this.visitVariableDeclaration(stmt.left)
612
+ } else {
613
+ stmt.left = this.visitPattern(stmt.left)
614
+ }
615
+ stmt.right = this.visitExpression(stmt.right)
616
+ stmt.body = this.visitStatement(stmt.body)
617
+ return stmt
618
+ }
619
+
620
+ visitForInStatement(stmt: ForInStatement): Statement {
621
+ if (stmt.left.type === 'VariableDeclaration') {
622
+ stmt.left = this.visitVariableDeclaration(stmt.left)
623
+ } else {
624
+ stmt.left = this.visitPattern(stmt.left)
625
+ }
626
+ stmt.right = this.visitExpression(stmt.right)
627
+ stmt.body = this.visitStatement(stmt.body)
628
+ return stmt
629
+ }
630
+
631
+ visitEmptyStatement(stmt: EmptyStatement): EmptyStatement {
632
+ return stmt
633
+ }
634
+
635
+ visitDoWhileStatement(stmt: DoWhileStatement): Statement {
636
+ stmt.body = this.visitStatement(stmt.body)
637
+ stmt.test = this.visitExpression(stmt.test)
638
+ return stmt
639
+ }
640
+
641
+ visitDebuggerStatement(stmt: DebuggerStatement): Statement {
642
+ return stmt
643
+ }
644
+
645
+ visitWithStatement(stmt: WithStatement): Statement {
646
+ stmt.object = this.visitExpression(stmt.object)
647
+ stmt.body = this.visitStatement(stmt.body)
648
+ return stmt
649
+ }
650
+
651
+ visitDeclaration(decl: Declaration): Declaration {
652
+ switch (decl.type) {
653
+ case 'ClassDeclaration':
654
+ return this.visitClassDeclaration(decl)
655
+ case 'FunctionDeclaration':
656
+ return this.visitFunctionDeclaration(decl)
657
+ case 'TsEnumDeclaration':
658
+ return this.visitTsEnumDeclaration(decl)
659
+ case 'TsInterfaceDeclaration':
660
+ return this.visitTsInterfaceDeclaration(decl)
661
+ case 'TsModuleDeclaration':
662
+ return this.visitTsModuleDeclaration(decl)
663
+ case 'TsTypeAliasDeclaration':
664
+ return this.visitTsTypeAliasDeclaration(decl)
665
+ case 'VariableDeclaration':
666
+ return this.visitVariableDeclaration(decl)
667
+ }
668
+ }
669
+
670
+ visitVariableDeclaration(n: VariableDeclaration): VariableDeclaration {
671
+ n.declarations = this.visitVariableDeclarators(n.declarations)
672
+ return n
673
+ }
674
+
675
+ visitVariableDeclarators(nodes: VariableDeclarator[]): VariableDeclarator[] {
676
+ return nodes.map(this.visitVariableDeclarator.bind(this))
677
+ }
678
+
679
+ visitVariableDeclarator(n: VariableDeclarator): VariableDeclarator {
680
+ n.id = this.visitPattern(n.id)
681
+ n.init = this.visitOptionalExpression(n.init)
682
+ return n
683
+ }
684
+
685
+ visitTsTypeAliasDeclaration(n: TsTypeAliasDeclaration): Declaration {
686
+ n.id = this.visitBindingIdentifier(n.id)
687
+ n.typeAnnotation = this.visitTsType(n.typeAnnotation)
688
+ n.typeParams = this.visitTsTypeParameterDeclaration(n.typeParams)
689
+ return n
690
+ }
691
+
692
+ visitTsModuleDeclaration(n: TsModuleDeclaration): Declaration {
693
+ n.id = this.visitTsModuleName(n.id)
694
+ if (n.body) {
695
+ n.body = this.visitTsNamespaceBody(n.body)
696
+ }
697
+ return n
698
+ }
699
+
700
+ visitTsModuleName(n: TsModuleName): TsModuleName {
701
+ switch (n.type) {
702
+ case 'Identifier':
703
+ return this.visitBindingIdentifier(n)
704
+ case 'StringLiteral':
705
+ return this.visitStringLiteral(n)
706
+ }
707
+ }
708
+
709
+ visitTsNamespaceBody(n: TsNamespaceBody): TsNamespaceBody | undefined {
710
+ if (n) {
711
+ switch (n.type) {
712
+ case 'TsModuleBlock':
713
+ return this.visitTsModuleBlock(n)
714
+ case 'TsNamespaceDeclaration':
715
+ return this.visitTsNamespaceDeclaration(n)
716
+ }
717
+ }
718
+ }
719
+
720
+ visitTsNamespaceDeclaration(n: TsNamespaceDeclaration): TsModuleBlock | TsNamespaceDeclaration {
721
+ const body = this.visitTsNamespaceBody(n.body)
722
+ if (body) {
723
+ n.body = body
724
+ }
725
+ n.id = this.visitBindingIdentifier(n.id)
726
+ return n
727
+ }
728
+
729
+ visitTsModuleBlock(n: TsModuleBlock): TsModuleBlock | TsNamespaceDeclaration {
730
+ n.body = this.visitModuleItems(n.body)
731
+ return n
732
+ }
733
+
734
+ visitTsInterfaceDeclaration(n: TsInterfaceDeclaration): TsInterfaceDeclaration {
735
+ n.id = this.visitBindingIdentifier(n.id)
736
+ n.typeParams = this.visitTsTypeParameterDeclaration(n.typeParams)
737
+ n.extends = this.visitTsExpressionsWithTypeArguments(n.extends)
738
+ n.body = this.visitTsInterfaceBody(n.body)
739
+ return n
740
+ }
741
+
742
+ visitTsInterfaceBody(n: TsInterfaceBody): TsInterfaceBody {
743
+ n.body = this.visitTsTypeElements(n.body)
744
+ return n
745
+ }
746
+
747
+ visitTsTypeElements(nodes: TsTypeElement[]): TsTypeElement[] {
748
+ return nodes.map(this.visitTsTypeElement.bind(this))
749
+ }
750
+
751
+ visitTsTypeElement(n: TsTypeElement): TsTypeElement {
752
+ switch (n.type) {
753
+ case 'TsCallSignatureDeclaration':
754
+ return this.visitTsCallSignatureDeclaration(n)
755
+ case 'TsConstructSignatureDeclaration':
756
+ return this.visitTsConstructSignatureDeclaration(n)
757
+ case 'TsPropertySignature':
758
+ return this.visitTsPropertySignature(n)
759
+ case 'TsGetterSignature':
760
+ return this.visitTsGetterSignature(n)
761
+ case 'TsSetterSignature':
762
+ return this.visitTsSetterSignature(n)
763
+ case 'TsMethodSignature':
764
+ return this.visitTsMethodSignature(n)
765
+ case 'TsIndexSignature':
766
+ return this.visitTsIndexSignature(n)
767
+ }
768
+ }
769
+
770
+ visitTsCallSignatureDeclaration(n: TsCallSignatureDeclaration): TsCallSignatureDeclaration {
771
+ n.params = this.visitTsFnParameters(n.params)
772
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
773
+ return n
774
+ }
775
+
776
+ visitTsConstructSignatureDeclaration(
777
+ n: TsConstructSignatureDeclaration,
778
+ ): TsConstructSignatureDeclaration {
779
+ n.params = this.visitTsFnParameters(n.params)
780
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
781
+ return n
782
+ }
783
+
784
+ visitTsPropertySignature(n: TsPropertySignature): TsPropertySignature {
785
+ n.params = this.visitTsFnParameters(n.params)
786
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
787
+ return n
788
+ }
789
+
790
+ visitTsGetterSignature(n: TsGetterSignature): TsGetterSignature {
791
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
792
+ return n
793
+ }
794
+
795
+ visitTsSetterSignature(n: TsSetterSignature): TsSetterSignature {
796
+ n.param = this.visitTsFnParameter(n.param)
797
+ return n
798
+ }
799
+
800
+ visitTsMethodSignature(n: TsMethodSignature): TsMethodSignature {
801
+ n.params = this.visitTsFnParameters(n.params)
802
+ n.typeAnn = this.visitTsTypeAnnotation(n.typeAnn)
803
+ return n
804
+ }
805
+
806
+ visitTsEnumDeclaration(n: TsEnumDeclaration): Declaration {
807
+ n.id = this.visitIdentifier(n.id)
808
+ n.members = this.visitTsEnumMembers(n.members)
809
+ return n
810
+ }
811
+
812
+ visitTsEnumMembers(nodes: TsEnumMember[]): TsEnumMember[] {
813
+ return nodes.map(this.visitTsEnumMember.bind(this))
814
+ }
815
+
816
+ visitTsEnumMember(n: TsEnumMember): TsEnumMember {
817
+ n.id = this.visitTsEnumMemberId(n.id)
818
+ n.init = this.visitOptionalExpression(n.init)
819
+ return n
820
+ }
821
+
822
+ visitTsEnumMemberId(n: TsEnumMemberId): TsEnumMemberId {
823
+ switch (n.type) {
824
+ case 'Identifier':
825
+ return this.visitBindingIdentifier(n)
826
+ case 'StringLiteral':
827
+ return this.visitStringLiteral(n)
828
+ }
829
+ }
830
+
831
+ visitFunctionDeclaration(decl: FunctionDeclaration): Declaration {
832
+ decl.identifier = this.visitIdentifier(decl.identifier)
833
+ decl = this.visitFunction(decl)
834
+
835
+ return decl
836
+ }
837
+
838
+ visitClassDeclaration(decl: ClassDeclaration): Declaration {
839
+ decl = this.visitClass(decl)
840
+ decl.identifier = this.visitIdentifier(decl.identifier)
841
+ return decl
842
+ }
843
+
844
+ visitClassBody(members: ClassMember[]): ClassMember[] {
845
+ return members.map(this.visitClassMember.bind(this))
846
+ }
847
+
848
+ visitClassMember(member: ClassMember): ClassMember {
849
+ switch (member.type) {
850
+ case 'ClassMethod':
851
+ return this.visitClassMethod(member)
852
+ case 'ClassProperty':
853
+ return this.visitClassProperty(member)
854
+ case 'Constructor':
855
+ return this.visitConstructor(member)
856
+ case 'PrivateMethod':
857
+ return this.visitPrivateMethod(member)
858
+ case 'PrivateProperty':
859
+ return this.visitPrivateProperty(member)
860
+ case 'TsIndexSignature':
861
+ return this.visitTsIndexSignature(member)
862
+ case 'EmptyStatement':
863
+ return this.visitEmptyStatement(member)
864
+ case 'StaticBlock':
865
+ return this.visitStaticBlock(member)
866
+ }
867
+ }
868
+
869
+ visitTsIndexSignature(n: TsIndexSignature): TsIndexSignature {
870
+ n.params = this.visitTsFnParameters(n.params)
871
+ if (n.typeAnnotation) n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
872
+ return n
873
+ }
874
+
875
+ visitTsFnParameters(params: TsFnParameter[]): TsFnParameter[] {
876
+ return params.map(this.visitTsFnParameter.bind(this))
877
+ }
878
+
879
+ visitTsFnParameter(n: TsFnParameter): TsFnParameter {
880
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
881
+ return n
882
+ }
883
+
884
+ visitPrivateProperty(n: PrivateProperty): ClassMember {
885
+ n.decorators = this.visitDecorators(n.decorators)
886
+ n.key = this.visitPrivateName(n.key)
887
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
888
+ n.value = this.visitOptionalExpression(n.value)
889
+ return n
890
+ }
891
+
892
+ visitPrivateMethod(n: PrivateMethod): ClassMember {
893
+ n.accessibility = this.visitAccessibility(n.accessibility)
894
+ n.function = this.visitFunction(n.function)
895
+ n.key = this.visitPrivateName(n.key)
896
+ return n
897
+ }
898
+
899
+ visitPrivateName(n: PrivateName): PrivateName {
900
+ return n
901
+ }
902
+
903
+ visitConstructor(n: Constructor): ClassMember {
904
+ n.accessibility = this.visitAccessibility(n.accessibility)
905
+ n.key = this.visitPropertyName(n.key)
906
+ n.params = this.visitConstructorParameters(n.params)
907
+ if (n.body) {
908
+ n.body = this.visitBlockStatement(n.body)
909
+ }
910
+ return n
911
+ }
912
+
913
+ visitConstructorParameters(
914
+ nodes: (Param | TsParameterProperty)[],
915
+ ): (Param | TsParameterProperty)[] {
916
+ return nodes.map(this.visitConstructorParameter.bind(this))
917
+ }
918
+
919
+ visitConstructorParameter(n: Param | TsParameterProperty): Param | TsParameterProperty {
920
+ switch (n.type) {
921
+ case 'TsParameterProperty':
922
+ return this.visitTsParameterProperty(n)
923
+ default:
924
+ return this.visitParameter(n)
925
+ }
926
+ }
927
+
928
+ visitStaticBlock(n: StaticBlock): StaticBlock {
929
+ n.body = this.visitBlockStatement(n.body)
930
+ return n
931
+ }
932
+
933
+ visitTsParameterProperty(n: TsParameterProperty): TsParameterProperty | Param {
934
+ n.accessibility = this.visitAccessibility(n.accessibility)
935
+ n.decorators = this.visitDecorators(n.decorators)
936
+ n.param = this.visitTsParameterPropertyParameter(n.param)
937
+ return n
938
+ }
939
+
940
+ visitTsParameterPropertyParameter(n: TsParameterPropertyParameter): TsParameterPropertyParameter {
941
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
942
+ return n
943
+ }
944
+
945
+ visitPropertyName(key: PropertyName): PropertyName {
946
+ switch (key.type) {
947
+ case 'Identifier':
948
+ return this.visitBindingIdentifier(key)
949
+ case 'StringLiteral':
950
+ return this.visitStringLiteral(key)
951
+ case 'NumericLiteral':
952
+ return this.visitNumericLiteral(key)
953
+ case 'BigIntLiteral':
954
+ return this.visitBigIntLiteral(key)
955
+ default:
956
+ return this.visitComputedPropertyKey(key)
957
+ }
958
+ }
959
+
960
+ visitAccessibility(n: Accessibility | undefined): Accessibility | undefined {
961
+ return n
962
+ }
963
+
964
+ visitClassProperty(n: ClassProperty): ClassMember {
965
+ n.accessibility = this.visitAccessibility(n.accessibility)
966
+ n.decorators = this.visitDecorators(n.decorators)
967
+ n.key = this.visitPropertyName(n.key)
968
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
969
+ n.value = this.visitOptionalExpression(n.value)
970
+ return n
971
+ }
972
+
973
+ visitClassMethod(n: ClassMethod): ClassMember {
974
+ n.accessibility = this.visitAccessibility(n.accessibility)
975
+ n.function = this.visitFunction(n.function)
976
+ n.key = this.visitPropertyName(n.key)
977
+ return n
978
+ }
979
+
980
+ visitComputedPropertyKey(n: ComputedPropName): ComputedPropName {
981
+ n.expression = this.visitExpression(n.expression)
982
+ return n
983
+ }
984
+
985
+ visitClass<T extends Class>(n: T): T {
986
+ n.decorators = this.visitDecorators(n.decorators)
987
+
988
+ n.superClass = this.visitOptionalExpression(n.superClass)
989
+
990
+ n.superTypeParams = this.visitTsTypeParameterInstantiation(n.superTypeParams)
991
+ if (n.implements) {
992
+ n.implements = this.visitTsExpressionsWithTypeArguments(n.implements)
993
+ }
994
+
995
+ n.body = this.visitClassBody(n.body)
996
+ return n
997
+ }
998
+
999
+ visitFunction<T extends Fn>(n: T): T {
1000
+ n.decorators = this.visitDecorators(n.decorators)
1001
+ n.params = this.visitParameters(n.params)
1002
+ if (n.body) {
1003
+ n.body = this.visitBlockStatement(n.body)
1004
+ }
1005
+ n.returnType = this.visitTsTypeAnnotation(n.returnType)
1006
+ n.typeParameters = this.visitTsTypeParameterDeclaration(n.typeParameters)
1007
+ return n
1008
+ }
1009
+
1010
+ visitTsExpressionsWithTypeArguments(
1011
+ nodes: TsExpressionWithTypeArguments[],
1012
+ ): TsExpressionWithTypeArguments[] {
1013
+ return nodes.map(this.visitTsExpressionWithTypeArguments.bind(this))
1014
+ }
1015
+
1016
+ visitTsExpressionWithTypeArguments(
1017
+ n: TsExpressionWithTypeArguments,
1018
+ ): TsExpressionWithTypeArguments {
1019
+ n.expression = this.visitExpression(n.expression)
1020
+ n.typeArguments = this.visitTsTypeParameterInstantiation(n.typeArguments)
1021
+ return n
1022
+ }
1023
+
1024
+ visitTsTypeParameterInstantiation(
1025
+ n: TsTypeParameterInstantiation | undefined,
1026
+ ): TsTypeParameterInstantiation | undefined {
1027
+ if (n) {
1028
+ n.params = this.visitTsTypes(n.params)
1029
+ }
1030
+ return n
1031
+ }
1032
+
1033
+ visitTsTypes(nodes: TsType[]): TsType[] {
1034
+ return nodes.map(this.visitTsType.bind(this))
1035
+ }
1036
+
1037
+ visitTsEntityName(n: TsEntityName): TsEntityName {
1038
+ switch (n.type) {
1039
+ case 'Identifier':
1040
+ return this.visitBindingIdentifier(n)
1041
+ case 'TsQualifiedName':
1042
+ return this.visitTsQualifiedName(n)
1043
+ }
1044
+ }
1045
+
1046
+ visitTsQualifiedName(n: TsQualifiedName): TsQualifiedName {
1047
+ n.left = this.visitTsEntityName(n.left)
1048
+ n.right = this.visitIdentifier(n.right)
1049
+ return n
1050
+ }
1051
+
1052
+ visitDecorators(nodes: Decorator[] | undefined): Decorator[] | undefined {
1053
+ if (nodes) {
1054
+ return nodes.map(this.visitDecorator.bind(this))
1055
+ }
1056
+ }
1057
+
1058
+ visitDecorator(n: Decorator): Decorator {
1059
+ n.expression = this.visitExpression(n.expression)
1060
+
1061
+ return n
1062
+ }
1063
+
1064
+ visitExpressionStatement(stmt: ExpressionStatement): Statement {
1065
+ stmt.expression = this.visitExpression(stmt.expression)
1066
+ return stmt
1067
+ }
1068
+
1069
+ visitContinueStatement(stmt: ContinueStatement): Statement {
1070
+ if (stmt.label) {
1071
+ stmt.label = this.visitLabelIdentifier(stmt.label)
1072
+ }
1073
+ return stmt
1074
+ }
1075
+
1076
+ visitExpression(n: Expression): Expression {
1077
+ switch (n.type) {
1078
+ case 'ArrayExpression':
1079
+ return this.visitArrayExpression(n)
1080
+ case 'ArrowFunctionExpression':
1081
+ return this.visitArrowFunctionExpression(n)
1082
+ case 'AssignmentExpression':
1083
+ return this.visitAssignmentExpression(n)
1084
+ case 'AwaitExpression':
1085
+ return this.visitAwaitExpression(n)
1086
+ case 'BigIntLiteral':
1087
+ return this.visitBigIntLiteral(n)
1088
+ case 'BinaryExpression':
1089
+ return this.visitBinaryExpression(n)
1090
+ case 'BooleanLiteral':
1091
+ return this.visitBooleanLiteral(n)
1092
+ case 'CallExpression':
1093
+ return this.visitCallExpression(n)
1094
+ case 'ClassExpression':
1095
+ return this.visitClassExpression(n)
1096
+ case 'ConditionalExpression':
1097
+ return this.visitConditionalExpression(n)
1098
+ case 'FunctionExpression':
1099
+ return this.visitFunctionExpression(n)
1100
+ case 'Identifier':
1101
+ return this.visitIdentifierReference(n)
1102
+ case 'JSXElement':
1103
+ return this.visitJSXElement(n)
1104
+ case 'JSXEmptyExpression':
1105
+ return this.visitJSXEmptyExpression(n)
1106
+ case 'JSXFragment':
1107
+ return this.visitJSXFragment(n)
1108
+ case 'JSXMemberExpression':
1109
+ return this.visitJSXMemberExpression(n)
1110
+ case 'JSXNamespacedName':
1111
+ return this.visitJSXNamespacedName(n)
1112
+ case 'JSXText':
1113
+ return this.visitJSXText(n)
1114
+ case 'MemberExpression':
1115
+ return this.visitMemberExpression(n)
1116
+ case 'SuperPropExpression':
1117
+ return this.visitSuperPropExpression(n)
1118
+ case 'MetaProperty':
1119
+ return this.visitMetaProperty(n)
1120
+ case 'NewExpression':
1121
+ return this.visitNewExpression(n)
1122
+ case 'NullLiteral':
1123
+ return this.visitNullLiteral(n)
1124
+ case 'NumericLiteral':
1125
+ return this.visitNumericLiteral(n)
1126
+ case 'ObjectExpression':
1127
+ return this.visitObjectExpression(n)
1128
+ case 'ParenthesisExpression':
1129
+ return this.visitParenthesisExpression(n)
1130
+ case 'PrivateName':
1131
+ return this.visitPrivateName(n)
1132
+ case 'RegExpLiteral':
1133
+ return this.visitRegExpLiteral(n)
1134
+ case 'SequenceExpression':
1135
+ return this.visitSequenceExpression(n)
1136
+ case 'StringLiteral':
1137
+ return this.visitStringLiteral(n)
1138
+ case 'TaggedTemplateExpression':
1139
+ return this.visitTaggedTemplateExpression(n)
1140
+ case 'TemplateLiteral':
1141
+ return this.visitTemplateLiteral(n)
1142
+ case 'ThisExpression':
1143
+ return this.visitThisExpression(n)
1144
+ case 'TsAsExpression':
1145
+ return this.visitTsAsExpression(n)
1146
+ case 'TsSatisfiesExpression':
1147
+ return this.visitTsSatisfiesExpression(n)
1148
+ case 'TsNonNullExpression':
1149
+ return this.visitTsNonNullExpression(n)
1150
+ case 'TsTypeAssertion':
1151
+ return this.visitTsTypeAssertion(n)
1152
+ case 'TsConstAssertion':
1153
+ return this.visitTsConstAssertion(n)
1154
+ case 'TsInstantiation':
1155
+ return this.visitTsInstantiation(n)
1156
+ case 'UnaryExpression':
1157
+ return this.visitUnaryExpression(n)
1158
+ case 'UpdateExpression':
1159
+ return this.visitUpdateExpression(n)
1160
+ case 'YieldExpression':
1161
+ return this.visitYieldExpression(n)
1162
+ case 'OptionalChainingExpression':
1163
+ return this.visitOptionalChainingExpression(n)
1164
+ case 'Invalid':
1165
+ return n
1166
+ }
1167
+ }
1168
+
1169
+ visitOptionalChainingExpression(n: OptionalChainingExpression): Expression {
1170
+ n.base = this.visitMemberExpressionOrOptionalChainingCall(n.base)
1171
+ return n
1172
+ }
1173
+
1174
+ visitMemberExpressionOrOptionalChainingCall(
1175
+ n: MemberExpression | OptionalChainingCall,
1176
+ ): MemberExpression | OptionalChainingCall {
1177
+ switch (n.type) {
1178
+ case 'MemberExpression':
1179
+ return this.visitMemberExpression(n)
1180
+ case 'CallExpression':
1181
+ return this.visitOptionalChainingCall(n)
1182
+ }
1183
+ }
1184
+
1185
+ visitOptionalChainingCall(n: OptionalChainingCall): OptionalChainingCall {
1186
+ n.callee = this.visitExpression(n.callee)
1187
+ n.arguments = this.visitExprOrSpreads(n.arguments)
1188
+ if (n.typeArguments) n.typeArguments = this.visitTsTypeParameterInstantiation(n.typeArguments)
1189
+ return n
1190
+ }
1191
+
1192
+ visitAssignmentExpression(n: AssignmentExpression): Expression {
1193
+ n.left = this.visitPatternOrExpression(n.left)
1194
+ n.right = this.visitExpression(n.right)
1195
+ return n
1196
+ }
1197
+
1198
+ visitPatternOrExpression(n: Pattern | Expression): Pattern | Expression {
1199
+ switch (n.type) {
1200
+ case 'ObjectPattern':
1201
+ case 'ArrayPattern':
1202
+ case 'Identifier':
1203
+ case 'AssignmentPattern':
1204
+ case 'RestElement':
1205
+ return this.visitPattern(n)
1206
+ default:
1207
+ return this.visitExpression(n)
1208
+ }
1209
+ }
1210
+
1211
+ visitYieldExpression(n: YieldExpression): Expression {
1212
+ n.argument = this.visitOptionalExpression(n.argument)
1213
+ return n
1214
+ }
1215
+
1216
+ visitUpdateExpression(n: UpdateExpression): Expression {
1217
+ n.argument = this.visitExpression(n.argument)
1218
+ return n
1219
+ }
1220
+
1221
+ visitUnaryExpression(n: UnaryExpression): Expression {
1222
+ n.argument = this.visitExpression(n.argument)
1223
+ return n
1224
+ }
1225
+
1226
+ visitTsTypeAssertion(n: TsTypeAssertion): Expression {
1227
+ n.expression = this.visitExpression(n.expression)
1228
+ n.typeAnnotation = this.visitTsType(n.typeAnnotation)
1229
+ return n
1230
+ }
1231
+
1232
+ visitTsConstAssertion(n: TsConstAssertion): Expression {
1233
+ n.expression = this.visitExpression(n.expression)
1234
+ return n
1235
+ }
1236
+
1237
+ visitTsInstantiation(n: TsInstantiation): TsInstantiation {
1238
+ n.expression = this.visitExpression(n.expression)
1239
+ return n
1240
+ }
1241
+
1242
+ visitTsNonNullExpression(n: TsNonNullExpression): Expression {
1243
+ n.expression = this.visitExpression(n.expression)
1244
+ return n
1245
+ }
1246
+
1247
+ visitTsAsExpression(n: TsAsExpression): Expression {
1248
+ n.expression = this.visitExpression(n.expression)
1249
+ n.typeAnnotation = this.visitTsType(n.typeAnnotation)
1250
+ return n
1251
+ }
1252
+
1253
+ visitTsSatisfiesExpression(n: TsSatisfiesExpression): Expression {
1254
+ n.expression = this.visitExpression(n.expression)
1255
+ n.typeAnnotation = this.visitTsType(n.typeAnnotation)
1256
+ return n
1257
+ }
1258
+
1259
+ visitThisExpression(n: ThisExpression): Expression {
1260
+ return n
1261
+ }
1262
+
1263
+ visitTemplateLiteral(n: TemplateLiteral): Expression {
1264
+ n.expressions = n.expressions.map(this.visitExpression.bind(this))
1265
+ return n
1266
+ }
1267
+
1268
+ visitParameters(n: Param[]): Param[] {
1269
+ return n.map(this.visitParameter.bind(this))
1270
+ }
1271
+
1272
+ visitParameter(n: Param): Param {
1273
+ n.pat = this.visitPattern(n.pat)
1274
+ return n
1275
+ }
1276
+
1277
+ visitTaggedTemplateExpression(n: TaggedTemplateExpression): Expression {
1278
+ n.tag = this.visitExpression(n.tag)
1279
+ const template = this.visitTemplateLiteral(n.template)
1280
+ if (template.type === 'TemplateLiteral') {
1281
+ n.template = template
1282
+ }
1283
+ return n
1284
+ }
1285
+
1286
+ visitSequenceExpression(n: SequenceExpression): Expression {
1287
+ n.expressions = n.expressions.map(this.visitExpression.bind(this))
1288
+ return n
1289
+ }
1290
+
1291
+ visitRegExpLiteral(n: RegExpLiteral): Expression {
1292
+ return n
1293
+ }
1294
+
1295
+ visitParenthesisExpression(n: ParenthesisExpression): Expression {
1296
+ n.expression = this.visitExpression(n.expression)
1297
+ return n
1298
+ }
1299
+
1300
+ visitObjectExpression(n: ObjectExpression): Expression {
1301
+ if (n.properties) {
1302
+ n.properties = this.visitObjectProperties(n.properties)
1303
+ }
1304
+ return n
1305
+ }
1306
+
1307
+ visitObjectProperties(nodes: (Property | SpreadElement)[]): (Property | SpreadElement)[] {
1308
+ return nodes.map(this.visitObjectProperty.bind(this))
1309
+ }
1310
+
1311
+ visitObjectProperty(n: Property | SpreadElement): Property | SpreadElement {
1312
+ switch (n.type) {
1313
+ case 'SpreadElement':
1314
+ return this.visitSpreadElement(n)
1315
+ default:
1316
+ return this.visitProperty(n)
1317
+ }
1318
+ }
1319
+
1320
+ visitProperty(n: Property): Property | SpreadElement {
1321
+ switch (n.type) {
1322
+ case 'Identifier':
1323
+ return this.visitIdentifier(n)
1324
+ case 'AssignmentProperty':
1325
+ return this.visitAssignmentProperty(n)
1326
+ case 'GetterProperty':
1327
+ return this.visitGetterProperty(n)
1328
+ case 'KeyValueProperty':
1329
+ return this.visitKeyValueProperty(n)
1330
+ case 'MethodProperty':
1331
+ return this.visitMethodProperty(n)
1332
+ case 'SetterProperty':
1333
+ return this.visitSetterProperty(n)
1334
+ }
1335
+ }
1336
+
1337
+ visitSetterProperty(n: SetterProperty): Property | SpreadElement {
1338
+ n.key = this.visitPropertyName(n.key)
1339
+ n.param = this.visitPattern(n.param)
1340
+ if (n.body) {
1341
+ n.body = this.visitBlockStatement(n.body)
1342
+ }
1343
+ return n
1344
+ }
1345
+
1346
+ visitMethodProperty(n: MethodProperty): Property | SpreadElement {
1347
+ n.key = this.visitPropertyName(n.key)
1348
+ if (n.body) {
1349
+ n.body = this.visitBlockStatement(n.body)
1350
+ }
1351
+ n.decorators = this.visitDecorators(n.decorators)
1352
+ n.params = this.visitParameters(n.params)
1353
+ n.returnType = this.visitTsTypeAnnotation(n.returnType)
1354
+ n.typeParameters = this.visitTsTypeParameterDeclaration(n.typeParameters)
1355
+ return n
1356
+ }
1357
+
1358
+ visitKeyValueProperty(n: KeyValueProperty): Property | SpreadElement {
1359
+ n.key = this.visitPropertyName(n.key)
1360
+ n.value = this.visitExpression(n.value)
1361
+ return n
1362
+ }
1363
+
1364
+ visitGetterProperty(n: GetterProperty): Property | SpreadElement {
1365
+ n.key = this.visitPropertyName(n.key)
1366
+ if (n.body) {
1367
+ n.body = this.visitBlockStatement(n.body)
1368
+ }
1369
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
1370
+ return n
1371
+ }
1372
+
1373
+ visitAssignmentProperty(n: AssignmentProperty): Property | SpreadElement {
1374
+ n.key = this.visitIdentifier(n.key)
1375
+ n.value = this.visitExpression(n.value)
1376
+ return n
1377
+ }
1378
+
1379
+ visitNullLiteral(n: NullLiteral): NullLiteral {
1380
+ return n
1381
+ }
1382
+
1383
+ visitNewExpression(n: NewExpression): Expression {
1384
+ n.callee = this.visitExpression(n.callee)
1385
+ if (n.arguments) {
1386
+ n.arguments = this.visitArguments(n.arguments)
1387
+ }
1388
+ n.typeArguments = this.visitTsTypeArguments(n.typeArguments)
1389
+ return n
1390
+ }
1391
+
1392
+ visitTsTypeArguments(
1393
+ n: TsTypeParameterInstantiation | undefined,
1394
+ ): TsTypeParameterInstantiation | undefined {
1395
+ if (n) {
1396
+ n.params = this.visitTsTypes(n.params)
1397
+ }
1398
+ return n
1399
+ }
1400
+
1401
+ visitArguments(nodes: Argument[]): Argument[] {
1402
+ return nodes.map(this.visitArgument.bind(this))
1403
+ }
1404
+
1405
+ visitArgument(n: Argument): Argument {
1406
+ n.expression = this.visitExpression(n.expression)
1407
+ return n
1408
+ }
1409
+
1410
+ visitMetaProperty(n: MetaProperty): Expression {
1411
+ return n
1412
+ }
1413
+
1414
+ visitMemberExpression(n: MemberExpression): MemberExpression {
1415
+ n.object = this.visitExpression(n.object)
1416
+ switch (n.property.type) {
1417
+ case 'Computed': {
1418
+ n.property = this.visitComputedPropertyKey(n.property)
1419
+ return n
1420
+ }
1421
+ case 'Identifier': {
1422
+ n.property = this.visitIdentifier(n.property)
1423
+ return n
1424
+ }
1425
+ case 'PrivateName': {
1426
+ n.property = this.visitPrivateName(n.property)
1427
+ return n
1428
+ }
1429
+ }
1430
+ }
1431
+
1432
+ visitSuperPropExpression(n: SuperPropExpression): Expression {
1433
+ switch (n.property.type) {
1434
+ case 'Computed': {
1435
+ n.property = this.visitComputedPropertyKey(n.property)
1436
+ return n
1437
+ }
1438
+ case 'Identifier': {
1439
+ n.property = this.visitIdentifier(n.property)
1440
+ return n
1441
+ }
1442
+ }
1443
+ }
1444
+
1445
+ visitCallee(n: Expression | Super | Import): Expression | Super | Import {
1446
+ if (n.type === 'Super' || n.type === 'Import') {
1447
+ return n
1448
+ }
1449
+ return this.visitExpression(n)
1450
+ }
1451
+
1452
+ visitJSXText(n: JSXText): JSXText {
1453
+ return n
1454
+ }
1455
+
1456
+ visitJSXNamespacedName(n: JSXNamespacedName): JSXNamespacedName {
1457
+ n.namespace = this.visitIdentifierReference(n.namespace)
1458
+ n.name = this.visitIdentifierReference(n.name)
1459
+ return n
1460
+ }
1461
+
1462
+ visitJSXMemberExpression(n: JSXMemberExpression): JSXMemberExpression {
1463
+ n.object = this.visitJSXObject(n.object)
1464
+ n.property = this.visitIdentifierReference(n.property)
1465
+ return n
1466
+ }
1467
+
1468
+ visitJSXObject(n: JSXObject): JSXObject {
1469
+ switch (n.type) {
1470
+ case 'Identifier':
1471
+ return this.visitIdentifierReference(n)
1472
+ case 'JSXMemberExpression':
1473
+ return this.visitJSXMemberExpression(n)
1474
+ }
1475
+ }
1476
+
1477
+ visitJSXFragment(n: JSXFragment): JSXFragment {
1478
+ n.opening = this.visitJSXOpeningFragment(n.opening)
1479
+ if (n.children) {
1480
+ n.children = this.visitJSXElementChildren(n.children)
1481
+ }
1482
+ n.closing = this.visitJSXClosingFragment(n.closing)
1483
+ return n
1484
+ }
1485
+
1486
+ visitJSXClosingFragment(n: JSXClosingFragment): JSXClosingFragment {
1487
+ return n
1488
+ }
1489
+
1490
+ visitJSXElementChildren(nodes: JSXElementChild[]): JSXElementChild[] {
1491
+ return nodes.map(this.visitJSXElementChild.bind(this))
1492
+ }
1493
+
1494
+ visitJSXElementChild(n: JSXElementChild): JSXElementChild {
1495
+ switch (n.type) {
1496
+ case 'JSXElement':
1497
+ return this.visitJSXElement(n)
1498
+ case 'JSXExpressionContainer':
1499
+ return this.visitJSXExpressionContainer(n)
1500
+ case 'JSXFragment':
1501
+ return this.visitJSXFragment(n)
1502
+ case 'JSXSpreadChild':
1503
+ return this.visitJSXSpreadChild(n)
1504
+ case 'JSXText':
1505
+ return this.visitJSXText(n)
1506
+ }
1507
+ }
1508
+
1509
+ visitJSXExpressionContainer(n: JSXExpressionContainer): JSXExpressionContainer {
1510
+ n.expression = this.visitExpression(n.expression)
1511
+ return n
1512
+ }
1513
+
1514
+ visitJSXSpreadChild(n: JSXSpreadChild): JSXElementChild {
1515
+ n.expression = this.visitExpression(n.expression)
1516
+ return n
1517
+ }
1518
+
1519
+ visitJSXOpeningFragment(n: JSXOpeningFragment): JSXOpeningFragment {
1520
+ return n
1521
+ }
1522
+
1523
+ visitJSXEmptyExpression(n: JSXEmptyExpression): Expression {
1524
+ return n
1525
+ }
1526
+
1527
+ visitJSXElement(n: JSXElement): JSXElement {
1528
+ n.opening = this.visitJSXOpeningElement(n.opening)
1529
+ n.children = this.visitJSXElementChildren(n.children)
1530
+ n.closing = this.visitJSXClosingElement(n.closing)
1531
+ return n
1532
+ }
1533
+
1534
+ visitJSXClosingElement(n: JSXClosingElement | undefined): JSXClosingElement | undefined {
1535
+ if (n) {
1536
+ n.name = this.visitJSXElementName(n.name)
1537
+ }
1538
+ return n
1539
+ }
1540
+
1541
+ visitJSXElementName(n: JSXElementName): JSXElementName {
1542
+ switch (n.type) {
1543
+ case 'Identifier':
1544
+ return this.visitIdentifierReference(n)
1545
+ case 'JSXMemberExpression':
1546
+ return this.visitJSXMemberExpression(n)
1547
+ case 'JSXNamespacedName':
1548
+ return this.visitJSXNamespacedName(n)
1549
+ }
1550
+ }
1551
+
1552
+ visitJSXOpeningElement(n: JSXOpeningElement): JSXOpeningElement {
1553
+ n.name = this.visitJSXElementName(n.name)
1554
+ n.typeArguments = this.visitTsTypeParameterInstantiation(n.typeArguments)
1555
+ n.attributes = this.visitJSXAttributeOrSpreads(n.attributes)
1556
+ return n
1557
+ }
1558
+
1559
+ visitJSXAttributes(
1560
+ attrs: JSXAttributeOrSpread[] | undefined,
1561
+ ): JSXAttributeOrSpread[] | undefined {
1562
+ if (attrs) return attrs.map(this.visitJSXAttributeOrSpread.bind(this))
1563
+ }
1564
+
1565
+ visitJSXAttributeOrSpread(n: JSXAttributeOrSpread): JSXAttributeOrSpread {
1566
+ switch (n.type) {
1567
+ case 'JSXAttribute':
1568
+ return this.visitJSXAttribute(n)
1569
+ case 'SpreadElement':
1570
+ return this.visitSpreadElement(n)
1571
+ }
1572
+ }
1573
+
1574
+ visitJSXAttributeOrSpreads(nodes: JSXAttributeOrSpread[]): JSXAttributeOrSpread[] {
1575
+ return nodes.map(this.visitJSXAttributeOrSpread.bind(this))
1576
+ }
1577
+
1578
+ visitJSXAttribute(n: JSXAttribute): JSXAttributeOrSpread {
1579
+ n.name = this.visitJSXAttributeName(n.name)
1580
+ n.value = this.visitJSXAttributeValue(n.value)
1581
+ return n
1582
+ }
1583
+
1584
+ visitJSXAttributeValue(n: JSXAttrValue | undefined): JSXAttrValue | undefined {
1585
+ if (!n) return n
1586
+
1587
+ switch (n.type) {
1588
+ case 'BooleanLiteral':
1589
+ return this.visitBooleanLiteral(n)
1590
+ case 'NullLiteral':
1591
+ return this.visitNullLiteral(n)
1592
+ case 'NumericLiteral':
1593
+ return this.visitNumericLiteral(n)
1594
+ case 'JSXText':
1595
+ return this.visitJSXText(n)
1596
+ case 'StringLiteral':
1597
+ return this.visitStringLiteral(n)
1598
+
1599
+ case 'JSXElement':
1600
+ return this.visitJSXElement(n)
1601
+ case 'JSXExpressionContainer':
1602
+ return this.visitJSXExpressionContainer(n)
1603
+ case 'JSXFragment':
1604
+ return this.visitJSXFragment(n)
1605
+ }
1606
+ return n
1607
+ }
1608
+
1609
+ visitJSXAttributeName(n: JSXAttributeName): JSXAttributeName {
1610
+ switch (n.type) {
1611
+ case 'Identifier':
1612
+ return this.visitIdentifierReference(n)
1613
+ case 'JSXNamespacedName':
1614
+ return this.visitJSXNamespacedName(n)
1615
+ }
1616
+ }
1617
+
1618
+ visitConditionalExpression(n: ConditionalExpression): Expression {
1619
+ n.test = this.visitExpression(n.test)
1620
+ n.consequent = this.visitExpression(n.consequent)
1621
+ n.alternate = this.visitExpression(n.alternate)
1622
+ return n
1623
+ }
1624
+
1625
+ visitCallExpression(n: CallExpression): Expression {
1626
+ n.callee = this.visitCallee(n.callee)
1627
+ n.typeArguments = this.visitTsTypeParameterInstantiation(n.typeArguments)
1628
+ if (n.arguments) {
1629
+ n.arguments = this.visitArguments(n.arguments)
1630
+ }
1631
+
1632
+ return n
1633
+ }
1634
+
1635
+ visitBooleanLiteral(n: BooleanLiteral): BooleanLiteral {
1636
+ return n
1637
+ }
1638
+
1639
+ visitBinaryExpression(n: BinaryExpression): Expression {
1640
+ n.left = this.visitExpression(n.left)
1641
+ n.right = this.visitExpression(n.right)
1642
+ return n
1643
+ }
1644
+
1645
+ visitAwaitExpression(n: AwaitExpression): Expression {
1646
+ n.argument = this.visitExpression(n.argument)
1647
+ return n
1648
+ }
1649
+
1650
+ visitTsTypeParameterDeclaration(
1651
+ n: TsTypeParameterDeclaration | undefined,
1652
+ ): TsTypeParameterDeclaration | undefined {
1653
+ if (n) {
1654
+ n.parameters = this.visitTsTypeParameters(n.parameters)
1655
+ }
1656
+ return n
1657
+ }
1658
+
1659
+ visitTsTypeParameters(nodes: TsTypeParameter[]): TsTypeParameter[] {
1660
+ return nodes.map(this.visitTsTypeParameter.bind(this))
1661
+ }
1662
+
1663
+ visitTsTypeParameter(n: TsTypeParameter): TsTypeParameter {
1664
+ if (n.constraint) {
1665
+ n.constraint = this.visitTsType(n.constraint)
1666
+ }
1667
+ if (n.default) {
1668
+ n.default = this.visitTsType(n.default)
1669
+ }
1670
+ n.name = this.visitIdentifierReference(n.name)
1671
+ return n
1672
+ }
1673
+
1674
+ visitTsTypeAnnotation(a: TsTypeAnnotation | undefined): TsTypeAnnotation | undefined {
1675
+ if (a) {
1676
+ a.typeAnnotation = this.visitTsType(a.typeAnnotation)
1677
+ }
1678
+ return a
1679
+ }
1680
+
1681
+ visitTsType(n: TsType): TsType {
1682
+ return n
1683
+ throw new Error('Method visitTsType not implemented.')
1684
+ }
1685
+
1686
+ visitPatterns(nodes: Pattern[]): Pattern[] {
1687
+ return nodes.map(this.visitPattern.bind(this))
1688
+ }
1689
+
1690
+ visitImportDeclaration(n: ImportDeclaration): ImportDeclaration {
1691
+ n.source = this.visitStringLiteral(n.source)
1692
+ n.specifiers = this.visitImportSpecifiers(n.specifiers || [])
1693
+ return n
1694
+ }
1695
+
1696
+ visitImportSpecifiers(nodes: ImportSpecifier[]): ImportSpecifier[] {
1697
+ return nodes.map(this.visitImportSpecifier.bind(this))
1698
+ }
1699
+
1700
+ visitImportSpecifier(node: ImportSpecifier): ImportSpecifier {
1701
+ switch (node.type) {
1702
+ case 'ImportDefaultSpecifier':
1703
+ return this.visitImportDefaultSpecifier(node)
1704
+
1705
+ case 'ImportNamespaceSpecifier':
1706
+ return this.visitImportNamespaceSpecifier(node)
1707
+
1708
+ case 'ImportSpecifier':
1709
+ return this.visitNamedImportSpecifier(node)
1710
+ }
1711
+ }
1712
+
1713
+ visitNamedImportSpecifier(node: NamedImportSpecifier): NamedImportSpecifier {
1714
+ node.local = this.visitBindingIdentifier(node.local)
1715
+
1716
+ if (node.imported) {
1717
+ node.imported = this.visitModuleExportName(node.imported)
1718
+ }
1719
+
1720
+ return node
1721
+ }
1722
+
1723
+ visitImportNamespaceSpecifier(node: ImportNamespaceSpecifier): ImportNamespaceSpecifier {
1724
+ node.local = this.visitBindingIdentifier(node.local)
1725
+
1726
+ return node
1727
+ }
1728
+
1729
+ visitImportDefaultSpecifier(node: ImportDefaultSpecifier): ImportSpecifier {
1730
+ node.local = this.visitBindingIdentifier(node.local)
1731
+
1732
+ return node
1733
+ }
1734
+
1735
+ visitBindingIdentifier(i: BindingIdentifier): BindingIdentifier {
1736
+ if (i.typeAnnotation) {
1737
+ i.typeAnnotation = this.visitTsTypeAnnotation(i.typeAnnotation)
1738
+ }
1739
+ return this.visitIdentifier(i)
1740
+ }
1741
+
1742
+ visitIdentifierReference(i: Identifier): Identifier {
1743
+ return this.visitIdentifier(i)
1744
+ }
1745
+
1746
+ visitLabelIdentifier(label: Identifier): Identifier {
1747
+ return this.visitIdentifier(label)
1748
+ }
1749
+
1750
+ visitIdentifier(n: Identifier): Identifier {
1751
+ return n
1752
+ }
1753
+
1754
+ visitStringLiteral(n: StringLiteral): StringLiteral {
1755
+ return n
1756
+ }
1757
+
1758
+ visitNumericLiteral(n: NumericLiteral): NumericLiteral {
1759
+ return n
1760
+ }
1761
+
1762
+ visitBigIntLiteral(n: BigIntLiteral): BigIntLiteral {
1763
+ return n
1764
+ }
1765
+
1766
+ visitPattern(n: Pattern): Pattern {
1767
+ switch (n.type) {
1768
+ case 'Identifier':
1769
+ return this.visitBindingIdentifier(n)
1770
+ case 'ArrayPattern':
1771
+ return this.visitArrayPattern(n)
1772
+ case 'ObjectPattern':
1773
+ return this.visitObjectPattern(n)
1774
+ case 'AssignmentPattern':
1775
+ return this.visitAssignmentPattern(n)
1776
+ case 'RestElement':
1777
+ return this.visitRestElement(n)
1778
+ default:
1779
+ return this.visitExpression(n)
1780
+ }
1781
+ }
1782
+
1783
+ visitRestElement(n: RestElement): RestElement {
1784
+ n.argument = this.visitPattern(n.argument)
1785
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
1786
+ return n
1787
+ }
1788
+
1789
+ visitAssignmentPattern(n: AssignmentPattern): Pattern {
1790
+ n.left = this.visitPattern(n.left)
1791
+ n.right = this.visitExpression(n.right)
1792
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
1793
+ return n
1794
+ }
1795
+
1796
+ visitObjectPattern(n: ObjectPattern): Pattern {
1797
+ n.properties = this.visitObjectPatternProperties(n.properties || [])
1798
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
1799
+ return n
1800
+ }
1801
+
1802
+ visitObjectPatternProperties(nodes: ObjectPatternProperty[]): ObjectPatternProperty[] {
1803
+ return nodes.map(this.visitObjectPatternProperty.bind(this))
1804
+ }
1805
+
1806
+ visitObjectPatternProperty(n: ObjectPatternProperty): ObjectPatternProperty {
1807
+ switch (n.type) {
1808
+ case 'AssignmentPatternProperty':
1809
+ return this.visitAssignmentPatternProperty(n)
1810
+ case 'KeyValuePatternProperty':
1811
+ return this.visitKeyValuePatternProperty(n)
1812
+ case 'RestElement':
1813
+ return this.visitRestElement(n)
1814
+ }
1815
+ }
1816
+
1817
+ visitKeyValuePatternProperty(n: KeyValuePatternProperty): ObjectPatternProperty {
1818
+ n.key = this.visitPropertyName(n.key)
1819
+ n.value = this.visitPattern(n.value)
1820
+ return n
1821
+ }
1822
+
1823
+ visitAssignmentPatternProperty(n: AssignmentPatternProperty): ObjectPatternProperty {
1824
+ n.key = this.visitBindingIdentifier(n.key)
1825
+ n.value = this.visitOptionalExpression(n.value)
1826
+ return n
1827
+ }
1828
+
1829
+ visitArrayPattern(n: ArrayPattern): Pattern {
1830
+ n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
1831
+ n.elements = this.visitArrayPatternElements(n.elements)
1832
+ return n
1833
+ }
1834
+
1835
+ visitArrayPatternElements(nodes: (Pattern | undefined)[]): (Pattern | undefined)[] {
1836
+ return nodes.map(this.visitArrayPatternElement.bind(this))
1837
+ }
1838
+
1839
+ visitArrayPatternElement(n: Pattern | undefined): Pattern | undefined {
1840
+ if (n) {
1841
+ n = this.visitPattern(n)
1842
+ }
1843
+ return n
1844
+ }
1845
+ }
1846
+
1847
+ export default Visitor