@swc/core 1.5.22 → 1.5.23

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