1#![cfg_attr(docsrs, feature(doc_cfg))]
3#![deny(clippy::all)]
4#![allow(clippy::ptr_arg)]
5
6#[doc(hidden)]
7pub extern crate swc_ecma_ast;
8
9use std::{borrow::Cow, fmt::Debug};
10
11use swc_common::{pass::CompilerPass, util::take::Take, Span, DUMMY_SP};
12use swc_ecma_ast::*;
13use swc_visit::{Repeat, Repeated};
14
15pub use crate::generated::*;
16mod generated;
17
18pub fn fold_pass<V>(pass: V) -> FoldPass<V>
19where
20 V: Fold,
21{
22 FoldPass { pass }
23}
24
25pub struct FoldPass<V> {
26 pass: V,
27}
28
29impl<V> Pass for FoldPass<V>
30where
31 V: Fold,
32{
33 #[inline(always)]
34 fn process(&mut self, program: &mut Program) {
35 program.map_with_mut(|p| p.fold_with(&mut self.pass));
36 }
37}
38
39impl<V> Fold for FoldPass<V>
40where
41 V: Fold,
42{
43 #[inline(always)]
44 fn fold_program(&mut self, node: Program) -> Program {
45 self.pass.fold_program(node)
46 }
47
48 #[inline(always)]
49 fn fold_module(&mut self, node: Module) -> Module {
50 self.pass.fold_module(node)
51 }
52
53 #[inline(always)]
54 fn fold_script(&mut self, node: Script) -> Script {
55 self.pass.fold_script(node)
56 }
57
58 #[inline(always)]
59 fn fold_stmt(&mut self, node: Stmt) -> Stmt {
60 self.pass.fold_stmt(node)
61 }
62
63 #[inline(always)]
64 fn fold_module_item(&mut self, item: ModuleItem) -> ModuleItem {
65 self.pass.fold_module_item(item)
66 }
67
68 #[inline(always)]
69 fn fold_expr(&mut self, expr: Expr) -> Expr {
70 self.pass.fold_expr(expr)
71 }
72
73 #[inline(always)]
74 fn fold_pat(&mut self, pat: Pat) -> Pat {
75 self.pass.fold_pat(pat)
76 }
77
78 #[inline(always)]
79 fn fold_assign_target(&mut self, target: AssignTarget) -> AssignTarget {
80 self.pass.fold_assign_target(target)
81 }
82
83 #[inline(always)]
84 fn fold_ident(&mut self, ident: Ident) -> Ident {
85 self.pass.fold_ident(ident)
86 }
87}
88
89impl<V> Repeated for FoldPass<V>
90where
91 V: Fold + Repeated,
92{
93 fn changed(&self) -> bool {
94 self.pass.changed()
95 }
96
97 fn reset(&mut self) {
98 self.pass.reset();
99 }
100}
101
102impl<V> CompilerPass for FoldPass<V>
103where
104 V: Fold + CompilerPass,
105{
106 fn name(&self) -> Cow<'static, str> {
107 self.pass.name()
108 }
109}
110
111pub fn visit_mut_pass<V>(pass: V) -> VisitMutPass<V>
112where
113 V: VisitMut,
114{
115 VisitMutPass { pass }
116}
117
118pub struct VisitMutPass<V> {
119 pass: V,
120}
121
122impl<V> Pass for VisitMutPass<V>
123where
124 V: VisitMut,
125{
126 #[inline(always)]
127 fn process(&mut self, program: &mut Program) {
128 program.visit_mut_with(&mut self.pass);
129 }
130}
131
132impl<V> VisitMut for VisitMutPass<V>
133where
134 V: VisitMut,
135{
136 #[inline(always)]
137 fn visit_mut_program(&mut self, program: &mut Program) {
138 self.pass.visit_mut_program(program);
139 }
140
141 #[inline(always)]
142 fn visit_mut_module(&mut self, module: &mut Module) {
143 self.pass.visit_mut_module(module);
144 }
145
146 #[inline(always)]
147 fn visit_mut_script(&mut self, script: &mut Script) {
148 self.pass.visit_mut_script(script);
149 }
150
151 #[inline(always)]
152 fn visit_mut_module_item(&mut self, item: &mut ModuleItem) {
153 self.pass.visit_mut_module_item(item);
154 }
155
156 #[inline(always)]
157 fn visit_mut_stmt(&mut self, stmt: &mut Stmt) {
158 self.pass.visit_mut_stmt(stmt);
159 }
160
161 #[inline(always)]
162 fn visit_mut_expr(&mut self, expr: &mut Expr) {
163 self.pass.visit_mut_expr(expr);
164 }
165
166 #[inline(always)]
167 fn visit_mut_pat(&mut self, pat: &mut Pat) {
168 self.pass.visit_mut_pat(pat);
169 }
170
171 #[inline(always)]
172 fn visit_mut_assign_target(&mut self, target: &mut AssignTarget) {
173 self.pass.visit_mut_assign_target(target);
174 }
175
176 #[inline(always)]
177 fn visit_mut_ident(&mut self, ident: &mut Ident) {
178 self.pass.visit_mut_ident(ident);
179 }
180}
181
182impl<V> Repeated for VisitMutPass<V>
183where
184 V: VisitMut + Repeated,
185{
186 fn changed(&self) -> bool {
187 self.pass.changed()
188 }
189
190 fn reset(&mut self) {
191 self.pass.reset();
192 }
193}
194
195impl<V> CompilerPass for VisitMutPass<V>
196where
197 V: VisitMut + CompilerPass,
198{
199 fn name(&self) -> Cow<'static, str> {
200 self.pass.name()
201 }
202}
203
204pub fn visit_pass<V>(pass: V) -> VisitPass<V>
205where
206 V: Visit,
207{
208 VisitPass { pass }
209}
210
211pub struct VisitPass<V> {
212 pass: V,
213}
214
215impl<V> Pass for VisitPass<V>
216where
217 V: Visit,
218{
219 #[inline(always)]
220 fn process(&mut self, program: &mut Program) {
221 program.visit_with(&mut self.pass);
222 }
223}
224
225impl<V> Repeated for VisitPass<V>
226where
227 V: Visit + Repeated,
228{
229 fn changed(&self) -> bool {
230 self.pass.changed()
231 }
232
233 fn reset(&mut self) {
234 self.pass.reset();
235 }
236}
237
238impl<V> CompilerPass for VisitPass<V>
239where
240 V: Visit + CompilerPass,
241{
242 fn name(&self) -> Cow<'static, str> {
243 self.pass.name()
244 }
245}
246
247impl<V> Fold for Repeat<V>
248where
249 V: Fold + Repeated,
250{
251 fn fold_program(&mut self, mut node: Program) -> Program {
252 loop {
253 self.pass.reset();
254 node = node.fold_with(&mut self.pass);
255
256 if !self.pass.changed() {
257 break;
258 }
259 }
260
261 node
262 }
263
264 fn fold_module(&mut self, mut node: Module) -> Module {
265 loop {
266 self.pass.reset();
267 node = node.fold_with(&mut self.pass);
268
269 if !self.pass.changed() {
270 break;
271 }
272 }
273
274 node
275 }
276
277 fn fold_script(&mut self, mut node: Script) -> Script {
278 loop {
279 self.pass.reset();
280 node = node.fold_with(&mut self.pass);
281
282 if !self.pass.changed() {
283 break;
284 }
285 }
286
287 node
288 }
289}
290
291impl<V> VisitMut for Repeat<V>
292where
293 V: VisitMut + Repeated,
294{
295 fn visit_mut_program(&mut self, node: &mut Program) {
296 loop {
297 self.pass.reset();
298 node.visit_mut_with(&mut self.pass);
299
300 if !self.pass.changed() {
301 break;
302 }
303 }
304 }
305
306 fn visit_mut_module(&mut self, node: &mut Module) {
307 loop {
308 self.pass.reset();
309 node.visit_mut_with(&mut self.pass);
310
311 if !self.pass.changed() {
312 break;
313 }
314 }
315 }
316
317 fn visit_mut_script(&mut self, node: &mut Script) {
318 loop {
319 self.pass.reset();
320 node.visit_mut_with(&mut self.pass);
321
322 if !self.pass.changed() {
323 break;
324 }
325 }
326 }
327}
328
329#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
331struct SpanRemover;
332
333pub fn span_remover() -> impl Debug + Fold + Copy + Eq + Default + 'static {
335 SpanRemover
336}
337
338impl Fold for SpanRemover {
339 fn fold_span(&mut self, _: Span) -> Span {
340 DUMMY_SP
341 }
342}
343
344#[macro_export]
345macro_rules! assert_eq_ignore_span {
346 ($l:expr, $r:expr) => {{
347 use $crate::FoldWith;
348 let l = $l.fold_with(&mut $crate::span_remover());
349 let r = $r.fold_with(&mut $crate::span_remover());
350
351 assert_eq!(l, r);
352 }};
353
354 ($l:expr, $r:expr, $($tts:tt)*) => {{
355 use $crate::FoldWith;
356 let l = $l.fold_with(&mut $crate::span_remover());
357 let r = $r.fold_with(&mut $crate::span_remover());
358
359 assert_eq!(l, r, $($tts)*);
360 }};
361}
362
363pub trait InjectVars {
368 fn take_vars(&mut self) -> Vec<VarDeclarator>;
369}
370
371impl<V> InjectVars for FoldPass<V>
372where
373 V: Fold + InjectVars,
374{
375 fn take_vars(&mut self) -> Vec<VarDeclarator> {
376 self.pass.take_vars()
377 }
378}
379
380impl<V> InjectVars for VisitMutPass<V>
381where
382 V: VisitMut + InjectVars,
383{
384 fn take_vars(&mut self) -> Vec<VarDeclarator> {
385 self.pass.take_vars()
386 }
387}
388
389impl<V> InjectVars for VisitPass<V>
390where
391 V: Visit + InjectVars,
392{
393 fn take_vars(&mut self) -> Vec<VarDeclarator> {
394 self.pass.take_vars()
395 }
396}
397
398#[macro_export]
400macro_rules! noop_fold_type {
401 ($name:ident, $N:tt) => {
402 fn $name(&mut self, node: $crate::swc_ecma_ast::$N) -> $crate::swc_ecma_ast::$N {
403 node
404 }
405 };
406 () => {
407 noop_fold_type!(fold_accessibility, Accessibility);
408 noop_fold_type!(fold_true_plus_minus, TruePlusMinus);
409 noop_fold_type!(fold_ts_array_type, TsArrayType);
410 noop_fold_type!(fold_ts_call_signature_decl, TsCallSignatureDecl);
411 noop_fold_type!(fold_ts_conditional_type, TsConditionalType);
412 noop_fold_type!(fold_ts_construct_signature_decl, TsConstructSignatureDecl);
413 noop_fold_type!(fold_ts_constructor_type, TsConstructorType);
414 noop_fold_type!(fold_ts_entity_name, TsEntityName);
415 noop_fold_type!(fold_ts_enum_decl, TsEnumDecl);
416 noop_fold_type!(fold_ts_enum_member, TsEnumMember);
417 noop_fold_type!(fold_ts_enum_member_id, TsEnumMemberId);
418 noop_fold_type!(fold_ts_expr_with_type_args, TsExprWithTypeArgs);
419 noop_fold_type!(fold_ts_fn_or_constructor_type, TsFnOrConstructorType);
420 noop_fold_type!(fold_ts_fn_param, TsFnParam);
421 noop_fold_type!(fold_ts_fn_type, TsFnType);
422 noop_fold_type!(fold_ts_import_equals_decl, TsImportEqualsDecl);
423 noop_fold_type!(fold_ts_import_type, TsImportType);
424 noop_fold_type!(fold_ts_index_signature, TsIndexSignature);
425 noop_fold_type!(fold_ts_indexed_access_type, TsIndexedAccessType);
426 noop_fold_type!(fold_ts_infer_type, TsInferType);
427 noop_fold_type!(fold_ts_interface_body, TsInterfaceBody);
428 noop_fold_type!(fold_ts_interface_decl, TsInterfaceDecl);
429 noop_fold_type!(fold_ts_intersection_type, TsIntersectionType);
430 noop_fold_type!(fold_ts_keyword_type, TsKeywordType);
431 noop_fold_type!(fold_ts_keyword_type_kind, TsKeywordTypeKind);
432 noop_fold_type!(fold_ts_mapped_type, TsMappedType);
433 noop_fold_type!(fold_ts_method_signature, TsMethodSignature);
434 noop_fold_type!(fold_ts_module_block, TsModuleBlock);
435 noop_fold_type!(fold_ts_module_decl, TsModuleDecl);
436 noop_fold_type!(fold_ts_module_name, TsModuleName);
437 noop_fold_type!(fold_ts_namespace_body, TsNamespaceBody);
438 noop_fold_type!(fold_ts_namespace_decl, TsNamespaceDecl);
439 noop_fold_type!(fold_ts_namespace_export_decl, TsNamespaceExportDecl);
440 noop_fold_type!(fold_ts_optional_type, TsOptionalType);
441 noop_fold_type!(fold_ts_param_prop, TsParamProp);
442 noop_fold_type!(fold_ts_param_prop_param, TsParamPropParam);
443 noop_fold_type!(fold_ts_parenthesized_type, TsParenthesizedType);
444 noop_fold_type!(fold_ts_property_signature, TsPropertySignature);
445 noop_fold_type!(fold_ts_qualified_name, TsQualifiedName);
446 noop_fold_type!(fold_ts_rest_type, TsRestType);
447 noop_fold_type!(fold_ts_this_type, TsThisType);
448 noop_fold_type!(fold_ts_this_type_or_ident, TsThisTypeOrIdent);
449 noop_fold_type!(fold_ts_tuple_type, TsTupleType);
450 noop_fold_type!(fold_ts_type, TsType);
451 noop_fold_type!(fold_ts_type_alias_decl, TsTypeAliasDecl);
452 noop_fold_type!(fold_ts_type_ann, TsTypeAnn);
453 noop_fold_type!(fold_ts_type_assertion, TsTypeAssertion);
454 noop_fold_type!(fold_ts_type_element, TsTypeElement);
455 noop_fold_type!(fold_ts_type_lit, TsTypeLit);
456 noop_fold_type!(fold_ts_type_operator, TsTypeOperator);
457 noop_fold_type!(fold_ts_type_operator_op, TsTypeOperatorOp);
458 noop_fold_type!(fold_ts_type_param, TsTypeParam);
459 noop_fold_type!(fold_ts_type_param_decl, TsTypeParamDecl);
460 noop_fold_type!(fold_ts_type_param_instantiation, TsTypeParamInstantiation);
461 noop_fold_type!(fold_ts_type_predicate, TsTypePredicate);
462 noop_fold_type!(fold_ts_type_query, TsTypeQuery);
463 noop_fold_type!(fold_ts_type_query_expr, TsTypeQueryExpr);
464 noop_fold_type!(fold_ts_type_ref, TsTypeRef);
465 noop_fold_type!(
466 fold_ts_union_or_intersection_type,
467 TsUnionOrIntersectionType
468 );
469 noop_fold_type!(fold_ts_union_type, TsUnionType);
470 };
471}
472
473#[macro_export]
475macro_rules! noop_visit_type {
476 (fail) => {
477 noop_visit_type!(visit_accessibility, Accessibility, fail);
478 noop_visit_type!(visit_true_plus_minus, TruePlusMinus, fail);
479 noop_visit_type!(visit_ts_array_type, TsArrayType, fail);
480 noop_visit_type!(visit_ts_call_signature_decl, TsCallSignatureDecl, fail);
481 noop_visit_type!(visit_ts_conditional_type, TsConditionalType, fail);
482 noop_visit_type!(
483 visit_ts_construct_signature_decl,
484 TsConstructSignatureDecl,
485 fail
486 );
487 noop_visit_type!(visit_ts_constructor_type, TsConstructorType, fail);
488 noop_visit_type!(visit_ts_entity_name, TsEntityName, fail);
489 noop_visit_type!(visit_ts_expr_with_type_args, TsExprWithTypeArgs, fail);
490 noop_visit_type!(visit_ts_fn_or_constructor_type, TsFnOrConstructorType, fail);
491 noop_visit_type!(visit_ts_fn_param, TsFnParam, fail);
492 noop_visit_type!(visit_ts_fn_type, TsFnType, fail);
493 noop_visit_type!(visit_ts_import_type, TsImportType, fail);
494 noop_visit_type!(visit_ts_index_signature, TsIndexSignature, fail);
495 noop_visit_type!(visit_ts_indexed_access_type, TsIndexedAccessType, fail);
496 noop_visit_type!(visit_ts_infer_type, TsInferType, fail);
497 noop_visit_type!(visit_ts_interface_body, TsInterfaceBody, fail);
498 noop_visit_type!(visit_ts_interface_decl, TsInterfaceDecl, fail);
499 noop_visit_type!(visit_ts_intersection_type, TsIntersectionType, fail);
500 noop_visit_type!(visit_ts_keyword_type, TsKeywordType, fail);
501 noop_visit_type!(visit_ts_keyword_type_kind, TsKeywordTypeKind, fail);
502 noop_visit_type!(visit_ts_mapped_type, TsMappedType, fail);
503 noop_visit_type!(visit_ts_method_signature, TsMethodSignature, fail);
504 noop_visit_type!(visit_ts_optional_type, TsOptionalType, fail);
505 noop_visit_type!(visit_ts_parenthesized_type, TsParenthesizedType, fail);
506 noop_visit_type!(visit_ts_property_signature, TsPropertySignature, fail);
507 noop_visit_type!(visit_ts_qualified_name, TsQualifiedName, fail);
508 noop_visit_type!(visit_ts_rest_type, TsRestType, fail);
509 noop_visit_type!(visit_ts_this_type, TsThisType, fail);
510 noop_visit_type!(visit_ts_this_type_or_ident, TsThisTypeOrIdent, fail);
511 noop_visit_type!(visit_ts_tuple_type, TsTupleType, fail);
512 noop_visit_type!(visit_ts_type, TsType, fail);
513 noop_visit_type!(visit_ts_type_alias_decl, TsTypeAliasDecl, fail);
514 noop_visit_type!(visit_ts_type_ann, TsTypeAnn, fail);
515 noop_visit_type!(visit_ts_type_element, TsTypeElement, fail);
516 noop_visit_type!(visit_ts_type_lit, TsTypeLit, fail);
517 noop_visit_type!(visit_ts_type_operator, TsTypeOperator, fail);
518 noop_visit_type!(visit_ts_type_operator_op, TsTypeOperatorOp, fail);
519 noop_visit_type!(visit_ts_type_param, TsTypeParam, fail);
520 noop_visit_type!(visit_ts_type_param_decl, TsTypeParamDecl, fail);
521 noop_visit_type!(
522 visit_ts_type_param_instantiation,
523 TsTypeParamInstantiation,
524 fail
525 );
526 noop_visit_type!(visit_ts_type_predicate, TsTypePredicate, fail);
527 noop_visit_type!(visit_ts_type_query, TsTypeQuery, fail);
528 noop_visit_type!(visit_ts_type_query_expr, TsTypeQueryExpr, fail);
529 noop_visit_type!(visit_ts_type_ref, TsTypeRef, fail);
530 noop_visit_type!(
531 visit_ts_union_or_intersection_type,
532 TsUnionOrIntersectionType,
533 fail
534 );
535 noop_visit_type!(visit_ts_union_type, TsUnionType, fail);
536 };
537 () => {
538 noop_visit_type!(visit_accessibility, Accessibility);
539 noop_visit_type!(visit_true_plus_minus, TruePlusMinus);
540 noop_visit_type!(visit_ts_array_type, TsArrayType);
541 noop_visit_type!(visit_ts_call_signature_decl, TsCallSignatureDecl);
542 noop_visit_type!(visit_ts_conditional_type, TsConditionalType);
543 noop_visit_type!(visit_ts_construct_signature_decl, TsConstructSignatureDecl);
544 noop_visit_type!(visit_ts_constructor_type, TsConstructorType);
545 noop_visit_type!(visit_ts_entity_name, TsEntityName);
546 noop_visit_type!(visit_ts_expr_with_type_args, TsExprWithTypeArgs);
547 noop_visit_type!(visit_ts_fn_or_constructor_type, TsFnOrConstructorType);
548 noop_visit_type!(visit_ts_fn_param, TsFnParam);
549 noop_visit_type!(visit_ts_fn_type, TsFnType);
550 noop_visit_type!(visit_ts_import_type, TsImportType);
551 noop_visit_type!(visit_ts_index_signature, TsIndexSignature);
552 noop_visit_type!(visit_ts_indexed_access_type, TsIndexedAccessType);
553 noop_visit_type!(visit_ts_infer_type, TsInferType);
554 noop_visit_type!(visit_ts_interface_body, TsInterfaceBody);
555 noop_visit_type!(visit_ts_interface_decl, TsInterfaceDecl);
556 noop_visit_type!(visit_ts_intersection_type, TsIntersectionType);
557 noop_visit_type!(visit_ts_keyword_type, TsKeywordType);
558 noop_visit_type!(visit_ts_keyword_type_kind, TsKeywordTypeKind);
559 noop_visit_type!(visit_ts_mapped_type, TsMappedType);
560 noop_visit_type!(visit_ts_method_signature, TsMethodSignature);
561 noop_visit_type!(visit_ts_optional_type, TsOptionalType);
562 noop_visit_type!(visit_ts_parenthesized_type, TsParenthesizedType);
563 noop_visit_type!(visit_ts_property_signature, TsPropertySignature);
564 noop_visit_type!(visit_ts_qualified_name, TsQualifiedName);
565 noop_visit_type!(visit_ts_rest_type, TsRestType);
566 noop_visit_type!(visit_ts_this_type, TsThisType);
567 noop_visit_type!(visit_ts_this_type_or_ident, TsThisTypeOrIdent);
568 noop_visit_type!(visit_ts_tuple_type, TsTupleType);
569 noop_visit_type!(visit_ts_type, TsType);
570 noop_visit_type!(visit_ts_type_alias_decl, TsTypeAliasDecl);
571 noop_visit_type!(visit_ts_type_ann, TsTypeAnn);
572 noop_visit_type!(visit_ts_type_element, TsTypeElement);
573 noop_visit_type!(visit_ts_type_lit, TsTypeLit);
574 noop_visit_type!(visit_ts_type_operator, TsTypeOperator);
575 noop_visit_type!(visit_ts_type_operator_op, TsTypeOperatorOp);
576 noop_visit_type!(visit_ts_type_param, TsTypeParam);
577 noop_visit_type!(visit_ts_type_param_decl, TsTypeParamDecl);
578 noop_visit_type!(visit_ts_type_param_instantiation, TsTypeParamInstantiation);
579 noop_visit_type!(visit_ts_type_predicate, TsTypePredicate);
580 noop_visit_type!(visit_ts_type_query, TsTypeQuery);
581 noop_visit_type!(visit_ts_type_query_expr, TsTypeQueryExpr);
582 noop_visit_type!(visit_ts_type_ref, TsTypeRef);
583 noop_visit_type!(
584 visit_ts_union_or_intersection_type,
585 TsUnionOrIntersectionType
586 );
587 noop_visit_type!(visit_ts_union_type, TsUnionType);
588 };
589
590 ($name:ident, $N:tt, fail) => {
591 #[cfg_attr(not(debug_assertions), inline(always))]
592 fn $name(&mut self, _: &$crate::swc_ecma_ast::$N) {
593 $crate::fail_no_typescript(stringify!($name));
594 }
595 };
596 ($name:ident, $N:tt) => {
597 fn $name(&mut self, _: &$crate::swc_ecma_ast::$N) {}
598 };
599}
600
601#[doc(hidden)]
603#[cfg_attr(not(debug_assertions), inline(always))]
604pub fn fail_not_standard() {
605 unsafe {
606 debug_unreachable::debug_unreachable!(
607 "This visitor supports only standard ECMAScript types. This method fails for \
608 optimization purpose."
609 )
610 }
611}
612
613#[doc(hidden)]
615#[cfg_attr(not(debug_assertions), inline(always))]
616pub fn fail_no_typescript(visitor_name: &str) {
617 unsafe {
618 debug_unreachable::debug_unreachable!(
619 "This visitor does not support TypeScript. This method fails for optimization \
620 purposes. Encountered in unreachable visitor: {visitor_name}"
621 )
622 }
623}
624
625#[macro_export]
630macro_rules! standard_only_fold {
631 ($name:ident, $N:ident) => {
632 fn $name(&mut self, n: $crate::swc_ecma_ast::$N) -> $crate::swc_ecma_ast::$N {
633 $crate::fail_not_standard();
634 n
635 }
636 };
637 () => {
638 standard_only_fold!(fold_accessibility, Accessibility);
639 standard_only_fold!(fold_true_plus_minus, TruePlusMinus);
640 standard_only_fold!(fold_ts_array_type, TsArrayType);
641 standard_only_fold!(fold_ts_call_signature_decl, TsCallSignatureDecl);
642 standard_only_fold!(fold_ts_conditional_type, TsConditionalType);
643 standard_only_fold!(fold_ts_construct_signature_decl, TsConstructSignatureDecl);
644 standard_only_fold!(fold_ts_constructor_type, TsConstructorType);
645 standard_only_fold!(fold_ts_entity_name, TsEntityName);
646 standard_only_fold!(fold_ts_expr_with_type_args, TsExprWithTypeArgs);
647 standard_only_fold!(fold_ts_fn_or_constructor_type, TsFnOrConstructorType);
648 standard_only_fold!(fold_ts_fn_param, TsFnParam);
649 standard_only_fold!(fold_ts_fn_type, TsFnType);
650 standard_only_fold!(fold_ts_import_type, TsImportType);
651 standard_only_fold!(fold_ts_index_signature, TsIndexSignature);
652 standard_only_fold!(fold_ts_indexed_access_type, TsIndexedAccessType);
653 standard_only_fold!(fold_ts_infer_type, TsInferType);
654 standard_only_fold!(fold_ts_interface_body, TsInterfaceBody);
655 standard_only_fold!(fold_ts_interface_decl, TsInterfaceDecl);
656 standard_only_fold!(fold_ts_intersection_type, TsIntersectionType);
657 standard_only_fold!(fold_ts_keyword_type, TsKeywordType);
658 standard_only_fold!(fold_ts_keyword_type_kind, TsKeywordTypeKind);
659 standard_only_fold!(fold_ts_mapped_type, TsMappedType);
660 standard_only_fold!(fold_ts_method_signature, TsMethodSignature);
661 standard_only_fold!(fold_ts_optional_type, TsOptionalType);
662 standard_only_fold!(fold_ts_parenthesized_type, TsParenthesizedType);
663 standard_only_fold!(fold_ts_property_signature, TsPropertySignature);
664 standard_only_fold!(fold_ts_qualified_name, TsQualifiedName);
665 standard_only_fold!(fold_ts_rest_type, TsRestType);
666 standard_only_fold!(fold_ts_this_type, TsThisType);
667 standard_only_fold!(fold_ts_this_type_or_ident, TsThisTypeOrIdent);
668 standard_only_fold!(fold_ts_tuple_type, TsTupleType);
669 standard_only_fold!(fold_ts_type, TsType);
670 standard_only_fold!(fold_ts_type_alias_decl, TsTypeAliasDecl);
671 standard_only_fold!(fold_ts_type_ann, TsTypeAnn);
672 standard_only_fold!(fold_ts_type_element, TsTypeElement);
673 standard_only_fold!(fold_ts_type_lit, TsTypeLit);
674 standard_only_fold!(fold_ts_type_operator, TsTypeOperator);
675 standard_only_fold!(fold_ts_type_operator_op, TsTypeOperatorOp);
676 standard_only_fold!(fold_ts_type_param, TsTypeParam);
677 standard_only_fold!(fold_ts_type_param_decl, TsTypeParamDecl);
678 standard_only_fold!(fold_ts_type_param_instantiation, TsTypeParamInstantiation);
679 standard_only_fold!(fold_ts_type_predicate, TsTypePredicate);
680 standard_only_fold!(fold_ts_type_query, TsTypeQuery);
681 standard_only_fold!(fold_ts_type_query_expr, TsTypeQueryExpr);
682 standard_only_fold!(fold_ts_type_ref, TsTypeRef);
683 standard_only_fold!(
684 fold_ts_union_or_intersection_type,
685 TsUnionOrIntersectionType
686 );
687 standard_only_fold!(fold_ts_union_type, TsUnionType);
688
689 standard_only_fold!(fold_jsx_element, JSXElement);
690 standard_only_fold!(fold_jsx_fragment, JSXFragment);
691 standard_only_fold!(fold_jsx_empty_expr, JSXEmptyExpr);
692 standard_only_fold!(fold_jsx_member_expr, JSXMemberExpr);
693 standard_only_fold!(fold_jsx_namespaced_name, JSXNamespacedName);
694 };
695}
696
697#[macro_export]
702macro_rules! standard_only_visit {
703 ($name:ident, $N:ident) => {
704 fn $name(&mut self, _: &$crate::swc_ecma_ast::$N) {
705 $crate::fail_not_standard()
706 }
707 };
708 () => {
709 standard_only_visit!(visit_accessibility, Accessibility);
710 standard_only_visit!(visit_true_plus_minus, TruePlusMinus);
711 standard_only_visit!(visit_ts_array_type, TsArrayType);
712 standard_only_visit!(visit_ts_call_signature_decl, TsCallSignatureDecl);
713 standard_only_visit!(visit_ts_conditional_type, TsConditionalType);
714 standard_only_visit!(visit_ts_construct_signature_decl, TsConstructSignatureDecl);
715 standard_only_visit!(visit_ts_constructor_type, TsConstructorType);
716 standard_only_visit!(visit_ts_entity_name, TsEntityName);
717 standard_only_visit!(visit_ts_expr_with_type_args, TsExprWithTypeArgs);
718 standard_only_visit!(visit_ts_fn_or_constructor_type, TsFnOrConstructorType);
719 standard_only_visit!(visit_ts_fn_param, TsFnParam);
720 standard_only_visit!(visit_ts_fn_type, TsFnType);
721 standard_only_visit!(visit_ts_import_type, TsImportType);
722 standard_only_visit!(visit_ts_index_signature, TsIndexSignature);
723 standard_only_visit!(visit_ts_indexed_access_type, TsIndexedAccessType);
724 standard_only_visit!(visit_ts_infer_type, TsInferType);
725 standard_only_visit!(visit_ts_interface_body, TsInterfaceBody);
726 standard_only_visit!(visit_ts_interface_decl, TsInterfaceDecl);
727 standard_only_visit!(visit_ts_intersection_type, TsIntersectionType);
728 standard_only_visit!(visit_ts_keyword_type, TsKeywordType);
729 standard_only_visit!(visit_ts_keyword_type_kind, TsKeywordTypeKind);
730 standard_only_visit!(visit_ts_mapped_type, TsMappedType);
731 standard_only_visit!(visit_ts_method_signature, TsMethodSignature);
732 standard_only_visit!(visit_ts_optional_type, TsOptionalType);
733 standard_only_visit!(visit_ts_parenthesized_type, TsParenthesizedType);
734 standard_only_visit!(visit_ts_property_signature, TsPropertySignature);
735 standard_only_visit!(visit_ts_qualified_name, TsQualifiedName);
736 standard_only_visit!(visit_ts_rest_type, TsRestType);
737 standard_only_visit!(visit_ts_this_type, TsThisType);
738 standard_only_visit!(visit_ts_this_type_or_ident, TsThisTypeOrIdent);
739 standard_only_visit!(visit_ts_tuple_type, TsTupleType);
740 standard_only_visit!(visit_ts_type, TsType);
741 standard_only_visit!(visit_ts_type_alias_decl, TsTypeAliasDecl);
742 standard_only_visit!(visit_ts_type_ann, TsTypeAnn);
743 standard_only_visit!(visit_ts_type_element, TsTypeElement);
744 standard_only_visit!(visit_ts_type_lit, TsTypeLit);
745 standard_only_visit!(visit_ts_type_operator, TsTypeOperator);
746 standard_only_visit!(visit_ts_type_operator_op, TsTypeOperatorOp);
747 standard_only_visit!(visit_ts_type_param, TsTypeParam);
748 standard_only_visit!(visit_ts_type_param_decl, TsTypeParamDecl);
749 standard_only_visit!(visit_ts_type_param_instantiation, TsTypeParamInstantiation);
750 standard_only_visit!(visit_ts_type_predicate, TsTypePredicate);
751 standard_only_visit!(visit_ts_type_query, TsTypeQuery);
752 standard_only_visit!(visit_ts_type_query_expr, TsTypeQueryExpr);
753 standard_only_visit!(visit_ts_type_ref, TsTypeRef);
754 standard_only_visit!(
755 visit_ts_union_or_intersection_type,
756 TsUnionOrIntersectionType
757 );
758 standard_only_visit!(visit_ts_union_type, TsUnionType);
759
760 standard_only_visit!(visit_jsx_element, JSXElement);
761 standard_only_visit!(visit_jsx_fragment, JSXFragment);
762 standard_only_visit!(visit_jsx_empty_expr, JSXEmptyExpr);
763 standard_only_visit!(visit_jsx_member_expr, JSXMemberExpr);
764 standard_only_visit!(visit_jsx_namespaced_name, JSXNamespacedName);
765 };
766}
767
768#[macro_export]
773macro_rules! standard_only_visit_mut {
774 ($name:ident, $N:ident) => {
775 fn $name(&mut self, _: &mut $crate::swc_ecma_ast::$N) {
776 $crate::fail_not_standard()
777 }
778 };
779 () => {
780 standard_only_visit_mut!(visit_mut_accessibility, Accessibility);
781 standard_only_visit_mut!(visit_mut_true_plus_minus, TruePlusMinus);
782 standard_only_visit_mut!(visit_mut_ts_array_type, TsArrayType);
783 standard_only_visit_mut!(visit_mut_ts_call_signature_decl, TsCallSignatureDecl);
784 standard_only_visit_mut!(visit_mut_ts_conditional_type, TsConditionalType);
785 standard_only_visit_mut!(
786 visit_mut_ts_construct_signature_decl,
787 TsConstructSignatureDecl
788 );
789 standard_only_visit_mut!(visit_mut_ts_constructor_type, TsConstructorType);
790 standard_only_visit_mut!(visit_mut_ts_entity_name, TsEntityName);
791 standard_only_visit_mut!(visit_mut_ts_expr_with_type_args, TsExprWithTypeArgs);
792 standard_only_visit_mut!(visit_mut_ts_fn_or_constructor_type, TsFnOrConstructorType);
793 standard_only_visit_mut!(visit_mut_ts_fn_param, TsFnParam);
794 standard_only_visit_mut!(visit_mut_ts_fn_type, TsFnType);
795 standard_only_visit_mut!(visit_mut_ts_import_type, TsImportType);
796 standard_only_visit_mut!(visit_mut_ts_index_signature, TsIndexSignature);
797 standard_only_visit_mut!(visit_mut_ts_indexed_access_type, TsIndexedAccessType);
798 standard_only_visit_mut!(visit_mut_ts_infer_type, TsInferType);
799 standard_only_visit_mut!(visit_mut_ts_interface_body, TsInterfaceBody);
800 standard_only_visit_mut!(visit_mut_ts_interface_decl, TsInterfaceDecl);
801 standard_only_visit_mut!(visit_mut_ts_intersection_type, TsIntersectionType);
802 standard_only_visit_mut!(visit_mut_ts_keyword_type, TsKeywordType);
803 standard_only_visit_mut!(visit_mut_ts_keyword_type_kind, TsKeywordTypeKind);
804 standard_only_visit_mut!(visit_mut_ts_mapped_type, TsMappedType);
805 standard_only_visit_mut!(visit_mut_ts_method_signature, TsMethodSignature);
806 standard_only_visit_mut!(visit_mut_ts_optional_type, TsOptionalType);
807 standard_only_visit_mut!(visit_mut_ts_parenthesized_type, TsParenthesizedType);
808 standard_only_visit_mut!(visit_mut_ts_property_signature, TsPropertySignature);
809 standard_only_visit_mut!(visit_mut_ts_qualified_name, TsQualifiedName);
810 standard_only_visit_mut!(visit_mut_ts_rest_type, TsRestType);
811 standard_only_visit_mut!(visit_mut_ts_this_type, TsThisType);
812 standard_only_visit_mut!(visit_mut_ts_this_type_or_ident, TsThisTypeOrIdent);
813 standard_only_visit_mut!(visit_mut_ts_tuple_type, TsTupleType);
814 standard_only_visit_mut!(visit_mut_ts_type, TsType);
815 standard_only_visit_mut!(visit_mut_ts_type_alias_decl, TsTypeAliasDecl);
816 standard_only_visit_mut!(visit_mut_ts_type_ann, TsTypeAnn);
817 standard_only_visit_mut!(visit_mut_ts_type_element, TsTypeElement);
818 standard_only_visit_mut!(visit_mut_ts_type_lit, TsTypeLit);
819 standard_only_visit_mut!(visit_mut_ts_type_operator, TsTypeOperator);
820 standard_only_visit_mut!(visit_mut_ts_type_operator_op, TsTypeOperatorOp);
821 standard_only_visit_mut!(visit_mut_ts_type_param, TsTypeParam);
822 standard_only_visit_mut!(visit_mut_ts_type_param_decl, TsTypeParamDecl);
823 standard_only_visit_mut!(
824 visit_mut_ts_type_param_instantiation,
825 TsTypeParamInstantiation
826 );
827 standard_only_visit_mut!(visit_mut_ts_type_predicate, TsTypePredicate);
828 standard_only_visit_mut!(visit_mut_ts_type_query, TsTypeQuery);
829 standard_only_visit_mut!(visit_mut_ts_type_query_expr, TsTypeQueryExpr);
830 standard_only_visit_mut!(visit_mut_ts_type_ref, TsTypeRef);
831 standard_only_visit_mut!(
832 visit_mut_ts_union_or_intersection_type,
833 TsUnionOrIntersectionType
834 );
835 standard_only_visit_mut!(visit_mut_ts_union_type, TsUnionType);
836
837 standard_only_visit_mut!(visit_mut_jsx_element, JSXElement);
838 standard_only_visit_mut!(visit_mut_jsx_fragment, JSXFragment);
839 standard_only_visit_mut!(visit_mut_jsx_empty_expr, JSXEmptyExpr);
840 standard_only_visit_mut!(visit_mut_jsx_member_expr, JSXMemberExpr);
841 standard_only_visit_mut!(visit_mut_jsx_namespaced_name, JSXNamespacedName);
842 };
843}
844
845#[macro_export]
847macro_rules! noop_visit_mut_type {
848 (fail) => {
849 noop_visit_mut_type!(visit_mut_accessibility, Accessibility, fail);
850 noop_visit_mut_type!(visit_mut_true_plus_minus, TruePlusMinus, fail);
851 noop_visit_mut_type!(visit_mut_ts_array_type, TsArrayType, fail);
852 noop_visit_mut_type!(visit_mut_ts_call_signature_decl, TsCallSignatureDecl, fail);
853 noop_visit_mut_type!(visit_mut_ts_conditional_type, TsConditionalType, fail);
854 noop_visit_mut_type!(
855 visit_mut_ts_construct_signature_decl,
856 TsConstructSignatureDecl,
857 fail
858 );
859 noop_visit_mut_type!(visit_mut_ts_constructor_type, TsConstructorType, fail);
860 noop_visit_mut_type!(visit_mut_ts_entity_name, TsEntityName, fail);
861 noop_visit_mut_type!(visit_mut_ts_expr_with_type_args, TsExprWithTypeArgs, fail);
862 noop_visit_mut_type!(
863 visit_mut_ts_fn_or_constructor_type,
864 TsFnOrConstructorType,
865 fail
866 );
867 noop_visit_mut_type!(visit_mut_ts_fn_param, TsFnParam, fail);
868 noop_visit_mut_type!(visit_mut_ts_fn_type, TsFnType, fail);
869 noop_visit_mut_type!(visit_mut_ts_import_type, TsImportType, fail);
870 noop_visit_mut_type!(visit_mut_ts_index_signature, TsIndexSignature, fail);
871 noop_visit_mut_type!(visit_mut_ts_indexed_access_type, TsIndexedAccessType, fail);
872 noop_visit_mut_type!(visit_mut_ts_infer_type, TsInferType, fail);
873 noop_visit_mut_type!(visit_mut_ts_interface_body, TsInterfaceBody, fail);
874 noop_visit_mut_type!(visit_mut_ts_interface_decl, TsInterfaceDecl, fail);
875 noop_visit_mut_type!(visit_mut_ts_intersection_type, TsIntersectionType, fail);
876 noop_visit_mut_type!(visit_mut_ts_keyword_type, TsKeywordType, fail);
877 noop_visit_mut_type!(visit_mut_ts_keyword_type_kind, TsKeywordTypeKind, fail);
878 noop_visit_mut_type!(visit_mut_ts_mapped_type, TsMappedType, fail);
879 noop_visit_mut_type!(visit_mut_ts_method_signature, TsMethodSignature, fail);
880 noop_visit_mut_type!(visit_mut_ts_optional_type, TsOptionalType, fail);
881 noop_visit_mut_type!(visit_mut_ts_parenthesized_type, TsParenthesizedType, fail);
882 noop_visit_mut_type!(visit_mut_ts_property_signature, TsPropertySignature, fail);
883 noop_visit_mut_type!(visit_mut_ts_qualified_name, TsQualifiedName, fail);
884 noop_visit_mut_type!(visit_mut_ts_rest_type, TsRestType, fail);
885 noop_visit_mut_type!(visit_mut_ts_this_type, TsThisType, fail);
886 noop_visit_mut_type!(visit_mut_ts_this_type_or_ident, TsThisTypeOrIdent, fail);
887 noop_visit_mut_type!(visit_mut_ts_tuple_type, TsTupleType, fail);
888 noop_visit_mut_type!(visit_mut_ts_type, TsType, fail);
889 noop_visit_mut_type!(visit_mut_ts_type_alias_decl, TsTypeAliasDecl, fail);
890 noop_visit_mut_type!(visit_mut_ts_type_ann, TsTypeAnn, fail);
891 noop_visit_mut_type!(visit_mut_ts_type_element, TsTypeElement, fail);
892 noop_visit_mut_type!(visit_mut_ts_type_lit, TsTypeLit, fail);
893 noop_visit_mut_type!(visit_mut_ts_type_operator, TsTypeOperator, fail);
894 noop_visit_mut_type!(visit_mut_ts_type_operator_op, TsTypeOperatorOp, fail);
895 noop_visit_mut_type!(visit_mut_ts_type_param, TsTypeParam, fail);
896 noop_visit_mut_type!(visit_mut_ts_type_param_decl, TsTypeParamDecl, fail);
897 noop_visit_mut_type!(
898 visit_mut_ts_type_param_instantiation,
899 TsTypeParamInstantiation,
900 fail
901 );
902 noop_visit_mut_type!(visit_mut_ts_type_predicate, TsTypePredicate, fail);
903 noop_visit_mut_type!(visit_mut_ts_type_query, TsTypeQuery, fail);
904 noop_visit_mut_type!(visit_mut_ts_type_query_expr, TsTypeQueryExpr, fail);
905 noop_visit_mut_type!(visit_mut_ts_type_ref, TsTypeRef, fail);
906 noop_visit_mut_type!(
907 visit_mut_ts_union_or_intersection_type,
908 TsUnionOrIntersectionType,
909 fail
910 );
911 noop_visit_mut_type!(visit_mut_ts_union_type, TsUnionType, fail);
912 };
913 () => {
914 noop_visit_mut_type!(visit_mut_accessibility, Accessibility);
915 noop_visit_mut_type!(visit_mut_true_plus_minus, TruePlusMinus);
916 noop_visit_mut_type!(visit_mut_ts_array_type, TsArrayType);
917 noop_visit_mut_type!(visit_mut_ts_call_signature_decl, TsCallSignatureDecl);
918 noop_visit_mut_type!(visit_mut_ts_conditional_type, TsConditionalType);
919 noop_visit_mut_type!(
920 visit_mut_ts_construct_signature_decl,
921 TsConstructSignatureDecl
922 );
923 noop_visit_mut_type!(visit_mut_ts_constructor_type, TsConstructorType);
924 noop_visit_mut_type!(visit_mut_ts_entity_name, TsEntityName);
925 noop_visit_mut_type!(visit_mut_ts_expr_with_type_args, TsExprWithTypeArgs);
926 noop_visit_mut_type!(visit_mut_ts_fn_or_constructor_type, TsFnOrConstructorType);
927 noop_visit_mut_type!(visit_mut_ts_fn_param, TsFnParam);
928 noop_visit_mut_type!(visit_mut_ts_fn_type, TsFnType);
929 noop_visit_mut_type!(visit_mut_ts_import_type, TsImportType);
930 noop_visit_mut_type!(visit_mut_ts_index_signature, TsIndexSignature);
931 noop_visit_mut_type!(visit_mut_ts_indexed_access_type, TsIndexedAccessType);
932 noop_visit_mut_type!(visit_mut_ts_infer_type, TsInferType);
933 noop_visit_mut_type!(visit_mut_ts_interface_body, TsInterfaceBody);
934 noop_visit_mut_type!(visit_mut_ts_interface_decl, TsInterfaceDecl);
935 noop_visit_mut_type!(visit_mut_ts_intersection_type, TsIntersectionType);
936 noop_visit_mut_type!(visit_mut_ts_keyword_type, TsKeywordType);
937 noop_visit_mut_type!(visit_mut_ts_keyword_type_kind, TsKeywordTypeKind);
938 noop_visit_mut_type!(visit_mut_ts_mapped_type, TsMappedType);
939 noop_visit_mut_type!(visit_mut_ts_method_signature, TsMethodSignature);
940 noop_visit_mut_type!(visit_mut_ts_optional_type, TsOptionalType);
941 noop_visit_mut_type!(visit_mut_ts_parenthesized_type, TsParenthesizedType);
942 noop_visit_mut_type!(visit_mut_ts_property_signature, TsPropertySignature);
943 noop_visit_mut_type!(visit_mut_ts_qualified_name, TsQualifiedName);
944 noop_visit_mut_type!(visit_mut_ts_rest_type, TsRestType);
945 noop_visit_mut_type!(visit_mut_ts_this_type, TsThisType);
946 noop_visit_mut_type!(visit_mut_ts_this_type_or_ident, TsThisTypeOrIdent);
947 noop_visit_mut_type!(visit_mut_ts_tuple_type, TsTupleType);
948 noop_visit_mut_type!(visit_mut_ts_type, TsType);
949 noop_visit_mut_type!(visit_mut_ts_type_alias_decl, TsTypeAliasDecl);
950 noop_visit_mut_type!(visit_mut_ts_type_ann, TsTypeAnn);
951 noop_visit_mut_type!(visit_mut_ts_type_element, TsTypeElement);
952 noop_visit_mut_type!(visit_mut_ts_type_lit, TsTypeLit);
953 noop_visit_mut_type!(visit_mut_ts_type_operator, TsTypeOperator);
954 noop_visit_mut_type!(visit_mut_ts_type_operator_op, TsTypeOperatorOp);
955 noop_visit_mut_type!(visit_mut_ts_type_param, TsTypeParam);
956 noop_visit_mut_type!(visit_mut_ts_type_param_decl, TsTypeParamDecl);
957 noop_visit_mut_type!(
958 visit_mut_ts_type_param_instantiation,
959 TsTypeParamInstantiation
960 );
961 noop_visit_mut_type!(visit_mut_ts_type_predicate, TsTypePredicate);
962 noop_visit_mut_type!(visit_mut_ts_type_query, TsTypeQuery);
963 noop_visit_mut_type!(visit_mut_ts_type_query_expr, TsTypeQueryExpr);
964 noop_visit_mut_type!(visit_mut_ts_type_ref, TsTypeRef);
965 noop_visit_mut_type!(
966 visit_mut_ts_union_or_intersection_type,
967 TsUnionOrIntersectionType
968 );
969 noop_visit_mut_type!(visit_mut_ts_union_type, TsUnionType);
970 };
971
972 ($name:ident, $N:ident, fail) => {
973 #[cfg_attr(not(debug_assertions), inline(always))]
974 fn $name(&mut self, _: &mut $crate::swc_ecma_ast::$N) {
975 $crate::fail_no_typescript(stringify!($name));
976 }
977 };
978 ($name:ident, $N:ident) => {
979 fn $name(&mut self, _: &mut $crate::swc_ecma_ast::$N) {}
980 };
981}
982
983#[macro_export]
984macro_rules! visit_obj_and_computed {
985 () => {
986 fn visit_member_prop(&mut self, n: &$crate::swc_ecma_ast::MemberProp) {
987 if let $crate::swc_ecma_ast::MemberProp::Computed(c) = n {
988 c.visit_with(self);
989 }
990 }
991
992 fn visit_jsx_member_expr(&mut self, n: &$crate::swc_ecma_ast::JSXMemberExpr) {
993 n.obj.visit_with(self);
994 }
995
996 fn visit_super_prop(&mut self, n: &$crate::swc_ecma_ast::SuperProp) {
997 if let $crate::swc_ecma_ast::SuperProp::Computed(c) = n {
998 c.visit_with(self);
999 }
1000 }
1001 };
1002}
1003
1004#[macro_export]
1005macro_rules! visit_mut_obj_and_computed {
1006 () => {
1007 fn visit_mut_member_prop(&mut self, n: &mut $crate::swc_ecma_ast::MemberProp) {
1008 if let $crate::swc_ecma_ast::MemberProp::Computed(c) = n {
1009 c.visit_mut_with(self);
1010 }
1011 }
1012
1013 fn visit_mut_jsx_member_expr(&mut self, n: &mut $crate::swc_ecma_ast::JSXMemberExpr) {
1014 n.obj.visit_mut_with(self);
1015 }
1016
1017 fn visit_mut_super_prop(&mut self, n: &mut $crate::swc_ecma_ast::SuperProp) {
1018 if let $crate::swc_ecma_ast::SuperProp::Computed(c) = n {
1019 c.visit_mut_with(self);
1020 }
1021 }
1022 };
1023}
1024
1025macro_rules! impl_traits_for_tuple {
1026 (
1027 [$idx:tt, $name:ident], $([$idx_rest:tt, $name_rest:ident]),*
1028 ) => {
1029 impl<$name, $($name_rest),*> VisitMut for ($name, $($name_rest),*)
1030 where
1031 $name: VisitMut,
1032 $($name_rest: VisitMut),*
1033 {
1034
1035 fn visit_mut_program(&mut self, program: &mut Program) {
1036 self.$idx.visit_mut_program(program);
1037
1038 $(
1039 self.$idx_rest.visit_mut_program(program);
1040 )*
1041 }
1042
1043 fn visit_mut_module(&mut self, module: &mut Module) {
1044 self.$idx.visit_mut_module(module);
1045
1046 $(
1047 self.$idx_rest.visit_mut_module(module);
1048 )*
1049 }
1050
1051 fn visit_mut_script(&mut self, script: &mut Script) {
1052 self.$idx.visit_mut_script(script);
1053
1054 $(
1055 self.$idx_rest.visit_mut_script(script);
1056 )*
1057 }
1058
1059 fn visit_mut_stmt(&mut self, stmt: &mut Stmt) {
1060 self.$idx.visit_mut_stmt(stmt);
1061
1062 $(
1063 self.$idx_rest.visit_mut_stmt(stmt);
1064 )*
1065 }
1066
1067 fn visit_mut_expr(&mut self, expr: &mut Expr) {
1068 self.$idx.visit_mut_expr(expr);
1069
1070 $(
1071 self.$idx_rest.visit_mut_expr(expr);
1072 )*
1073 }
1074
1075 fn visit_mut_pat(&mut self, pat: &mut Pat) {
1076 self.$idx.visit_mut_pat(pat);
1077
1078 $(
1079 self.$idx_rest.visit_mut_pat(pat);
1080 )*
1081 }
1082
1083 fn visit_mut_assign_target(&mut self, target: &mut AssignTarget) {
1084 self.$idx.visit_mut_assign_target(target);
1085
1086 $(
1087 self.$idx_rest.visit_mut_assign_target(target);
1088 )*
1089 }
1090
1091 fn visit_mut_ident(&mut self, ident: &mut Ident) {
1092 self.$idx.visit_mut_ident(ident);
1093
1094 $(
1095 self.$idx_rest.visit_mut_ident(ident);
1096 )*
1097 }
1098 }
1099 };
1100}
1101
1102impl_traits_for_tuple!([0, A], [1, B]);
1103impl_traits_for_tuple!([0, A], [1, B], [2, C]);
1104impl_traits_for_tuple!([0, A], [1, B], [2, C], [3, D]);
1105impl_traits_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E]);
1106impl_traits_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F]);
1107impl_traits_for_tuple!([0, A], [1, B], [2, C], [3, D], [4, E], [5, F], [6, G]);
1108impl_traits_for_tuple!(
1109 [0, A],
1110 [1, B],
1111 [2, C],
1112 [3, D],
1113 [4, E],
1114 [5, F],
1115 [6, G],
1116 [7, H]
1117);
1118impl_traits_for_tuple!(
1119 [0, A],
1120 [1, B],
1121 [2, C],
1122 [3, D],
1123 [4, E],
1124 [5, F],
1125 [6, G],
1126 [7, H],
1127 [8, I]
1128);
1129impl_traits_for_tuple!(
1130 [0, A],
1131 [1, B],
1132 [2, C],
1133 [3, D],
1134 [4, E],
1135 [5, F],
1136 [6, G],
1137 [7, H],
1138 [8, I],
1139 [9, J]
1140);
1141impl_traits_for_tuple!(
1142 [0, A],
1143 [1, B],
1144 [2, C],
1145 [3, D],
1146 [4, E],
1147 [5, F],
1148 [6, G],
1149 [7, H],
1150 [8, I],
1151 [9, J],
1152 [10, K]
1153);
1154impl_traits_for_tuple!(
1155 [0, A],
1156 [1, B],
1157 [2, C],
1158 [3, D],
1159 [4, E],
1160 [5, F],
1161 [6, G],
1162 [7, H],
1163 [8, I],
1164 [9, J],
1165 [10, K],
1166 [11, L]
1167);
1168impl_traits_for_tuple!(
1169 [0, A],
1170 [1, B],
1171 [2, C],
1172 [3, D],
1173 [4, E],
1174 [5, F],
1175 [6, G],
1176 [7, H],
1177 [8, I],
1178 [9, J],
1179 [10, K],
1180 [11, L],
1181 [12, M]
1182);