dprint_swc_ext/view/
generated.rs

1// This code is code generated.
2// Run `./scripts/generate.sh` from the root directory to regenerate it.
3use std::cell::RefCell;
4use std::mem;
5use bumpalo::Bump;
6use crate::swc::common::Spanned;
7use crate::swc::ast as swc_ast;
8use crate::swc::atoms as swc_atoms;
9pub use crate::swc::ast::{Accessibility, AssignOp, BinaryOp, EsVersion, ImportPhase, MetaPropKind, MethodKind, TruePlusMinus, TsKeywordTypeKind, TsTypeOperatorOp, UnaryOp, UpdateOp, VarDeclKind};
10use crate::swc::common as swc_common;
11use crate::common::*;
12use crate::view::types::*;
13
14thread_local! {
15  static LOCAL_BUMP_ALLOCATOR: RefCell<Bump> = RefCell::new(Bump::new());
16}
17
18pub fn with_ast_view<'a, T>(info: ProgramInfo, with_view: impl FnOnce(Program<'a>) -> T) -> T {
19  match info.program {
20    ProgramRef::Module(module) => {
21      with_ast_view_for_module(ModuleInfo {
22        module,
23        text_info: info.text_info,
24        tokens: info.tokens,
25        comments: info.comments,
26      }, |module| with_view(Program::Module(module)))
27    }
28    ProgramRef::Script(script) => {
29      with_ast_view_for_script(ScriptInfo {
30        script,
31        text_info: info.text_info,
32        tokens: info.tokens,
33        comments: info.comments,
34      }, |script| with_view(Program::Script(script)))
35    }
36  }
37}
38
39pub fn with_ast_view_for_module<'a, T>(info: ModuleInfo, with_view: impl FnOnce(&'a Module<'a>) -> T) -> T {
40  LOCAL_BUMP_ALLOCATOR.with(|bump_cell| {
41    let mut bump_borrow = bump_cell.borrow_mut();
42    let bump_ref = unsafe { mem::transmute::<&Bump, &'a Bump>(&bump_borrow) };
43    let info_ref = unsafe { mem::transmute::<&ModuleInfo, &'a ModuleInfo<'a>>(&info) };
44    let tokens = info_ref.tokens.map(|t| TokenContainer::new(t));
45    let tokens_ref = tokens.as_ref().map(|t| unsafe { mem::transmute::<&TokenContainer, &'a TokenContainer<'a>>(t) });
46    let comments = info_ref.comments.map(|c| CommentContainer::new(
47      c.leading,
48      c.trailing,
49      tokens_ref.expect("Tokens must be provided when using comments."),
50      info_ref.text_info.expect("Text info must be provided when using comments"),
51    ));
52    let comments_ref = comments.as_ref().map(|t| unsafe { mem::transmute::<&CommentContainer, &'a CommentContainer<'a>>(t) });
53    let ast_view = get_view_for_module(info_ref, tokens_ref, comments_ref, bump_ref);
54    let result = with_view(ast_view);
55    bump_borrow.reset();
56    result
57  })
58}
59
60pub fn with_ast_view_for_script<'a, T>(info: ScriptInfo, with_view: impl FnOnce(&'a Script<'a>) -> T) -> T {
61  LOCAL_BUMP_ALLOCATOR.with(|bump_cell| {
62    let mut bump_borrow = bump_cell.borrow_mut();
63    let bump_ref = unsafe { mem::transmute::<&Bump, &'a Bump>(&bump_borrow) };
64    let info_ref = unsafe { mem::transmute::<&ScriptInfo, &'a ScriptInfo<'a>>(&info) };
65    let tokens = info_ref.tokens.map(|t| TokenContainer::new(t));
66    let tokens_ref = tokens.as_ref().map(|t| unsafe { mem::transmute::<&TokenContainer, &'a TokenContainer<'a>>(t) });
67    let comments = info_ref.comments.map(|c| CommentContainer::new(
68      c.leading,
69      c.trailing,
70      tokens_ref.expect("Tokens must be provided when using comments."),
71      info_ref.text_info.expect("Text info must be provided when using comments"),
72    ));
73    let comments_ref = comments.as_ref().map(|t| unsafe { mem::transmute::<&CommentContainer, &'a CommentContainer<'a>>(t) });
74    let ast_view = get_view_for_script(info_ref, tokens_ref, comments_ref, bump_ref);
75    let result = with_view(ast_view);
76    bump_borrow.reset();
77    result
78  })
79}
80
81#[derive(Clone, Copy)]
82pub enum Node<'a> {
83  ArrayLit(&'a ArrayLit<'a>),
84  ArrayPat(&'a ArrayPat<'a>),
85  ArrowExpr(&'a ArrowExpr<'a>),
86  AssignExpr(&'a AssignExpr<'a>),
87  AssignPat(&'a AssignPat<'a>),
88  AssignPatProp(&'a AssignPatProp<'a>),
89  AssignProp(&'a AssignProp<'a>),
90  AutoAccessor(&'a AutoAccessor<'a>),
91  AwaitExpr(&'a AwaitExpr<'a>),
92  BigInt(&'a BigInt<'a>),
93  BinExpr(&'a BinExpr<'a>),
94  BindingIdent(&'a BindingIdent<'a>),
95  BlockStmt(&'a BlockStmt<'a>),
96  Bool(&'a Bool<'a>),
97  BreakStmt(&'a BreakStmt<'a>),
98  CallExpr(&'a CallExpr<'a>),
99  CatchClause(&'a CatchClause<'a>),
100  Class(&'a Class<'a>),
101  ClassDecl(&'a ClassDecl<'a>),
102  ClassExpr(&'a ClassExpr<'a>),
103  ClassMethod(&'a ClassMethod<'a>),
104  ClassProp(&'a ClassProp<'a>),
105  ComputedPropName(&'a ComputedPropName<'a>),
106  CondExpr(&'a CondExpr<'a>),
107  Constructor(&'a Constructor<'a>),
108  ContinueStmt(&'a ContinueStmt<'a>),
109  DebuggerStmt(&'a DebuggerStmt<'a>),
110  Decorator(&'a Decorator<'a>),
111  DoWhileStmt(&'a DoWhileStmt<'a>),
112  EmptyStmt(&'a EmptyStmt<'a>),
113  ExportAll(&'a ExportAll<'a>),
114  ExportDecl(&'a ExportDecl<'a>),
115  ExportDefaultDecl(&'a ExportDefaultDecl<'a>),
116  ExportDefaultExpr(&'a ExportDefaultExpr<'a>),
117  ExportDefaultSpecifier(&'a ExportDefaultSpecifier<'a>),
118  ExportNamedSpecifier(&'a ExportNamedSpecifier<'a>),
119  ExportNamespaceSpecifier(&'a ExportNamespaceSpecifier<'a>),
120  ExprOrSpread(&'a ExprOrSpread<'a>),
121  ExprStmt(&'a ExprStmt<'a>),
122  FnDecl(&'a FnDecl<'a>),
123  FnExpr(&'a FnExpr<'a>),
124  ForInStmt(&'a ForInStmt<'a>),
125  ForOfStmt(&'a ForOfStmt<'a>),
126  ForStmt(&'a ForStmt<'a>),
127  Function(&'a Function<'a>),
128  GetterProp(&'a GetterProp<'a>),
129  Ident(&'a Ident<'a>),
130  IdentName(&'a IdentName<'a>),
131  IfStmt(&'a IfStmt<'a>),
132  Import(&'a Import<'a>),
133  ImportDecl(&'a ImportDecl<'a>),
134  ImportDefaultSpecifier(&'a ImportDefaultSpecifier<'a>),
135  ImportNamedSpecifier(&'a ImportNamedSpecifier<'a>),
136  ImportStarAsSpecifier(&'a ImportStarAsSpecifier<'a>),
137  Invalid(&'a Invalid<'a>),
138  JSXAttr(&'a JSXAttr<'a>),
139  JSXClosingElement(&'a JSXClosingElement<'a>),
140  JSXClosingFragment(&'a JSXClosingFragment<'a>),
141  JSXElement(&'a JSXElement<'a>),
142  JSXEmptyExpr(&'a JSXEmptyExpr<'a>),
143  JSXExprContainer(&'a JSXExprContainer<'a>),
144  JSXFragment(&'a JSXFragment<'a>),
145  JSXMemberExpr(&'a JSXMemberExpr<'a>),
146  JSXNamespacedName(&'a JSXNamespacedName<'a>),
147  JSXOpeningElement(&'a JSXOpeningElement<'a>),
148  JSXOpeningFragment(&'a JSXOpeningFragment<'a>),
149  JSXSpreadChild(&'a JSXSpreadChild<'a>),
150  JSXText(&'a JSXText<'a>),
151  KeyValuePatProp(&'a KeyValuePatProp<'a>),
152  KeyValueProp(&'a KeyValueProp<'a>),
153  LabeledStmt(&'a LabeledStmt<'a>),
154  MemberExpr(&'a MemberExpr<'a>),
155  MetaPropExpr(&'a MetaPropExpr<'a>),
156  MethodProp(&'a MethodProp<'a>),
157  Module(&'a Module<'a>),
158  NamedExport(&'a NamedExport<'a>),
159  NewExpr(&'a NewExpr<'a>),
160  Null(&'a Null<'a>),
161  Number(&'a Number<'a>),
162  ObjectLit(&'a ObjectLit<'a>),
163  ObjectPat(&'a ObjectPat<'a>),
164  OptCall(&'a OptCall<'a>),
165  OptChainExpr(&'a OptChainExpr<'a>),
166  Param(&'a Param<'a>),
167  ParenExpr(&'a ParenExpr<'a>),
168  PrivateMethod(&'a PrivateMethod<'a>),
169  PrivateName(&'a PrivateName<'a>),
170  PrivateProp(&'a PrivateProp<'a>),
171  Regex(&'a Regex<'a>),
172  RestPat(&'a RestPat<'a>),
173  ReturnStmt(&'a ReturnStmt<'a>),
174  Script(&'a Script<'a>),
175  SeqExpr(&'a SeqExpr<'a>),
176  SetterProp(&'a SetterProp<'a>),
177  SpreadElement(&'a SpreadElement<'a>),
178  StaticBlock(&'a StaticBlock<'a>),
179  Str(&'a Str<'a>),
180  Super(&'a Super<'a>),
181  SuperPropExpr(&'a SuperPropExpr<'a>),
182  SwitchCase(&'a SwitchCase<'a>),
183  SwitchStmt(&'a SwitchStmt<'a>),
184  TaggedTpl(&'a TaggedTpl<'a>),
185  ThisExpr(&'a ThisExpr<'a>),
186  ThrowStmt(&'a ThrowStmt<'a>),
187  Tpl(&'a Tpl<'a>),
188  TplElement(&'a TplElement<'a>),
189  TryStmt(&'a TryStmt<'a>),
190  TsArrayType(&'a TsArrayType<'a>),
191  TsAsExpr(&'a TsAsExpr<'a>),
192  TsCallSignatureDecl(&'a TsCallSignatureDecl<'a>),
193  TsConditionalType(&'a TsConditionalType<'a>),
194  TsConstAssertion(&'a TsConstAssertion<'a>),
195  TsConstructSignatureDecl(&'a TsConstructSignatureDecl<'a>),
196  TsConstructorType(&'a TsConstructorType<'a>),
197  TsEnumDecl(&'a TsEnumDecl<'a>),
198  TsEnumMember(&'a TsEnumMember<'a>),
199  TsExportAssignment(&'a TsExportAssignment<'a>),
200  TsExprWithTypeArgs(&'a TsExprWithTypeArgs<'a>),
201  TsExternalModuleRef(&'a TsExternalModuleRef<'a>),
202  TsFnType(&'a TsFnType<'a>),
203  TsGetterSignature(&'a TsGetterSignature<'a>),
204  TsImportCallOptions(&'a TsImportCallOptions<'a>),
205  TsImportEqualsDecl(&'a TsImportEqualsDecl<'a>),
206  TsImportType(&'a TsImportType<'a>),
207  TsIndexSignature(&'a TsIndexSignature<'a>),
208  TsIndexedAccessType(&'a TsIndexedAccessType<'a>),
209  TsInferType(&'a TsInferType<'a>),
210  TsInstantiation(&'a TsInstantiation<'a>),
211  TsInterfaceBody(&'a TsInterfaceBody<'a>),
212  TsInterfaceDecl(&'a TsInterfaceDecl<'a>),
213  TsIntersectionType(&'a TsIntersectionType<'a>),
214  TsKeywordType(&'a TsKeywordType<'a>),
215  TsLitType(&'a TsLitType<'a>),
216  TsMappedType(&'a TsMappedType<'a>),
217  TsMethodSignature(&'a TsMethodSignature<'a>),
218  TsModuleBlock(&'a TsModuleBlock<'a>),
219  TsModuleDecl(&'a TsModuleDecl<'a>),
220  TsNamespaceDecl(&'a TsNamespaceDecl<'a>),
221  TsNamespaceExportDecl(&'a TsNamespaceExportDecl<'a>),
222  TsNonNullExpr(&'a TsNonNullExpr<'a>),
223  TsOptionalType(&'a TsOptionalType<'a>),
224  TsParamProp(&'a TsParamProp<'a>),
225  TsParenthesizedType(&'a TsParenthesizedType<'a>),
226  TsPropertySignature(&'a TsPropertySignature<'a>),
227  TsQualifiedName(&'a TsQualifiedName<'a>),
228  TsRestType(&'a TsRestType<'a>),
229  TsSatisfiesExpr(&'a TsSatisfiesExpr<'a>),
230  TsSetterSignature(&'a TsSetterSignature<'a>),
231  TsThisType(&'a TsThisType<'a>),
232  TsTplLitType(&'a TsTplLitType<'a>),
233  TsTupleElement(&'a TsTupleElement<'a>),
234  TsTupleType(&'a TsTupleType<'a>),
235  TsTypeAliasDecl(&'a TsTypeAliasDecl<'a>),
236  TsTypeAnn(&'a TsTypeAnn<'a>),
237  TsTypeAssertion(&'a TsTypeAssertion<'a>),
238  TsTypeLit(&'a TsTypeLit<'a>),
239  TsTypeOperator(&'a TsTypeOperator<'a>),
240  TsTypeParam(&'a TsTypeParam<'a>),
241  TsTypeParamDecl(&'a TsTypeParamDecl<'a>),
242  TsTypeParamInstantiation(&'a TsTypeParamInstantiation<'a>),
243  TsTypePredicate(&'a TsTypePredicate<'a>),
244  TsTypeQuery(&'a TsTypeQuery<'a>),
245  TsTypeRef(&'a TsTypeRef<'a>),
246  TsUnionType(&'a TsUnionType<'a>),
247  UnaryExpr(&'a UnaryExpr<'a>),
248  UpdateExpr(&'a UpdateExpr<'a>),
249  UsingDecl(&'a UsingDecl<'a>),
250  VarDecl(&'a VarDecl<'a>),
251  VarDeclarator(&'a VarDeclarator<'a>),
252  WhileStmt(&'a WhileStmt<'a>),
253  WithStmt(&'a WithStmt<'a>),
254  YieldExpr(&'a YieldExpr<'a>),
255}
256
257impl<'a> Node<'a> {
258  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
259    T::to(self)
260  }
261
262  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
263    if let Some(result) = T::to(self) {
264      result
265    } else {
266      panic!("Tried to cast node of type {} to {}.", self.kind(), T::kind())
267    }
268  }
269
270  pub fn is<T: CastableNode<'a>>(&self) -> bool {
271    self.kind() == T::kind()
272  }
273}
274
275impl<'a> SourceRanged for Node<'a> {
276  fn start(&self) -> SourcePos {
277    match self {
278      Node::ArrayLit(node) => node.start(),
279      Node::ArrayPat(node) => node.start(),
280      Node::ArrowExpr(node) => node.start(),
281      Node::AssignExpr(node) => node.start(),
282      Node::AssignPat(node) => node.start(),
283      Node::AssignPatProp(node) => node.start(),
284      Node::AssignProp(node) => node.start(),
285      Node::AutoAccessor(node) => node.start(),
286      Node::AwaitExpr(node) => node.start(),
287      Node::BigInt(node) => node.start(),
288      Node::BinExpr(node) => node.start(),
289      Node::BindingIdent(node) => node.start(),
290      Node::BlockStmt(node) => node.start(),
291      Node::Bool(node) => node.start(),
292      Node::BreakStmt(node) => node.start(),
293      Node::CallExpr(node) => node.start(),
294      Node::CatchClause(node) => node.start(),
295      Node::Class(node) => node.start(),
296      Node::ClassDecl(node) => node.start(),
297      Node::ClassExpr(node) => node.start(),
298      Node::ClassMethod(node) => node.start(),
299      Node::ClassProp(node) => node.start(),
300      Node::ComputedPropName(node) => node.start(),
301      Node::CondExpr(node) => node.start(),
302      Node::Constructor(node) => node.start(),
303      Node::ContinueStmt(node) => node.start(),
304      Node::DebuggerStmt(node) => node.start(),
305      Node::Decorator(node) => node.start(),
306      Node::DoWhileStmt(node) => node.start(),
307      Node::EmptyStmt(node) => node.start(),
308      Node::ExportAll(node) => node.start(),
309      Node::ExportDecl(node) => node.start(),
310      Node::ExportDefaultDecl(node) => node.start(),
311      Node::ExportDefaultExpr(node) => node.start(),
312      Node::ExportDefaultSpecifier(node) => node.start(),
313      Node::ExportNamedSpecifier(node) => node.start(),
314      Node::ExportNamespaceSpecifier(node) => node.start(),
315      Node::ExprOrSpread(node) => node.start(),
316      Node::ExprStmt(node) => node.start(),
317      Node::FnDecl(node) => node.start(),
318      Node::FnExpr(node) => node.start(),
319      Node::ForInStmt(node) => node.start(),
320      Node::ForOfStmt(node) => node.start(),
321      Node::ForStmt(node) => node.start(),
322      Node::Function(node) => node.start(),
323      Node::GetterProp(node) => node.start(),
324      Node::Ident(node) => node.start(),
325      Node::IdentName(node) => node.start(),
326      Node::IfStmt(node) => node.start(),
327      Node::Import(node) => node.start(),
328      Node::ImportDecl(node) => node.start(),
329      Node::ImportDefaultSpecifier(node) => node.start(),
330      Node::ImportNamedSpecifier(node) => node.start(),
331      Node::ImportStarAsSpecifier(node) => node.start(),
332      Node::Invalid(node) => node.start(),
333      Node::JSXAttr(node) => node.start(),
334      Node::JSXClosingElement(node) => node.start(),
335      Node::JSXClosingFragment(node) => node.start(),
336      Node::JSXElement(node) => node.start(),
337      Node::JSXEmptyExpr(node) => node.start(),
338      Node::JSXExprContainer(node) => node.start(),
339      Node::JSXFragment(node) => node.start(),
340      Node::JSXMemberExpr(node) => node.start(),
341      Node::JSXNamespacedName(node) => node.start(),
342      Node::JSXOpeningElement(node) => node.start(),
343      Node::JSXOpeningFragment(node) => node.start(),
344      Node::JSXSpreadChild(node) => node.start(),
345      Node::JSXText(node) => node.start(),
346      Node::KeyValuePatProp(node) => node.start(),
347      Node::KeyValueProp(node) => node.start(),
348      Node::LabeledStmt(node) => node.start(),
349      Node::MemberExpr(node) => node.start(),
350      Node::MetaPropExpr(node) => node.start(),
351      Node::MethodProp(node) => node.start(),
352      Node::Module(node) => node.start(),
353      Node::NamedExport(node) => node.start(),
354      Node::NewExpr(node) => node.start(),
355      Node::Null(node) => node.start(),
356      Node::Number(node) => node.start(),
357      Node::ObjectLit(node) => node.start(),
358      Node::ObjectPat(node) => node.start(),
359      Node::OptCall(node) => node.start(),
360      Node::OptChainExpr(node) => node.start(),
361      Node::Param(node) => node.start(),
362      Node::ParenExpr(node) => node.start(),
363      Node::PrivateMethod(node) => node.start(),
364      Node::PrivateName(node) => node.start(),
365      Node::PrivateProp(node) => node.start(),
366      Node::Regex(node) => node.start(),
367      Node::RestPat(node) => node.start(),
368      Node::ReturnStmt(node) => node.start(),
369      Node::Script(node) => node.start(),
370      Node::SeqExpr(node) => node.start(),
371      Node::SetterProp(node) => node.start(),
372      Node::SpreadElement(node) => node.start(),
373      Node::StaticBlock(node) => node.start(),
374      Node::Str(node) => node.start(),
375      Node::Super(node) => node.start(),
376      Node::SuperPropExpr(node) => node.start(),
377      Node::SwitchCase(node) => node.start(),
378      Node::SwitchStmt(node) => node.start(),
379      Node::TaggedTpl(node) => node.start(),
380      Node::ThisExpr(node) => node.start(),
381      Node::ThrowStmt(node) => node.start(),
382      Node::Tpl(node) => node.start(),
383      Node::TplElement(node) => node.start(),
384      Node::TryStmt(node) => node.start(),
385      Node::TsArrayType(node) => node.start(),
386      Node::TsAsExpr(node) => node.start(),
387      Node::TsCallSignatureDecl(node) => node.start(),
388      Node::TsConditionalType(node) => node.start(),
389      Node::TsConstAssertion(node) => node.start(),
390      Node::TsConstructSignatureDecl(node) => node.start(),
391      Node::TsConstructorType(node) => node.start(),
392      Node::TsEnumDecl(node) => node.start(),
393      Node::TsEnumMember(node) => node.start(),
394      Node::TsExportAssignment(node) => node.start(),
395      Node::TsExprWithTypeArgs(node) => node.start(),
396      Node::TsExternalModuleRef(node) => node.start(),
397      Node::TsFnType(node) => node.start(),
398      Node::TsGetterSignature(node) => node.start(),
399      Node::TsImportCallOptions(node) => node.start(),
400      Node::TsImportEqualsDecl(node) => node.start(),
401      Node::TsImportType(node) => node.start(),
402      Node::TsIndexSignature(node) => node.start(),
403      Node::TsIndexedAccessType(node) => node.start(),
404      Node::TsInferType(node) => node.start(),
405      Node::TsInstantiation(node) => node.start(),
406      Node::TsInterfaceBody(node) => node.start(),
407      Node::TsInterfaceDecl(node) => node.start(),
408      Node::TsIntersectionType(node) => node.start(),
409      Node::TsKeywordType(node) => node.start(),
410      Node::TsLitType(node) => node.start(),
411      Node::TsMappedType(node) => node.start(),
412      Node::TsMethodSignature(node) => node.start(),
413      Node::TsModuleBlock(node) => node.start(),
414      Node::TsModuleDecl(node) => node.start(),
415      Node::TsNamespaceDecl(node) => node.start(),
416      Node::TsNamespaceExportDecl(node) => node.start(),
417      Node::TsNonNullExpr(node) => node.start(),
418      Node::TsOptionalType(node) => node.start(),
419      Node::TsParamProp(node) => node.start(),
420      Node::TsParenthesizedType(node) => node.start(),
421      Node::TsPropertySignature(node) => node.start(),
422      Node::TsQualifiedName(node) => node.start(),
423      Node::TsRestType(node) => node.start(),
424      Node::TsSatisfiesExpr(node) => node.start(),
425      Node::TsSetterSignature(node) => node.start(),
426      Node::TsThisType(node) => node.start(),
427      Node::TsTplLitType(node) => node.start(),
428      Node::TsTupleElement(node) => node.start(),
429      Node::TsTupleType(node) => node.start(),
430      Node::TsTypeAliasDecl(node) => node.start(),
431      Node::TsTypeAnn(node) => node.start(),
432      Node::TsTypeAssertion(node) => node.start(),
433      Node::TsTypeLit(node) => node.start(),
434      Node::TsTypeOperator(node) => node.start(),
435      Node::TsTypeParam(node) => node.start(),
436      Node::TsTypeParamDecl(node) => node.start(),
437      Node::TsTypeParamInstantiation(node) => node.start(),
438      Node::TsTypePredicate(node) => node.start(),
439      Node::TsTypeQuery(node) => node.start(),
440      Node::TsTypeRef(node) => node.start(),
441      Node::TsUnionType(node) => node.start(),
442      Node::UnaryExpr(node) => node.start(),
443      Node::UpdateExpr(node) => node.start(),
444      Node::UsingDecl(node) => node.start(),
445      Node::VarDecl(node) => node.start(),
446      Node::VarDeclarator(node) => node.start(),
447      Node::WhileStmt(node) => node.start(),
448      Node::WithStmt(node) => node.start(),
449      Node::YieldExpr(node) => node.start(),
450    }
451  }
452  fn end(&self) -> SourcePos {
453    match self {
454      Node::ArrayLit(node) => node.end(),
455      Node::ArrayPat(node) => node.end(),
456      Node::ArrowExpr(node) => node.end(),
457      Node::AssignExpr(node) => node.end(),
458      Node::AssignPat(node) => node.end(),
459      Node::AssignPatProp(node) => node.end(),
460      Node::AssignProp(node) => node.end(),
461      Node::AutoAccessor(node) => node.end(),
462      Node::AwaitExpr(node) => node.end(),
463      Node::BigInt(node) => node.end(),
464      Node::BinExpr(node) => node.end(),
465      Node::BindingIdent(node) => node.end(),
466      Node::BlockStmt(node) => node.end(),
467      Node::Bool(node) => node.end(),
468      Node::BreakStmt(node) => node.end(),
469      Node::CallExpr(node) => node.end(),
470      Node::CatchClause(node) => node.end(),
471      Node::Class(node) => node.end(),
472      Node::ClassDecl(node) => node.end(),
473      Node::ClassExpr(node) => node.end(),
474      Node::ClassMethod(node) => node.end(),
475      Node::ClassProp(node) => node.end(),
476      Node::ComputedPropName(node) => node.end(),
477      Node::CondExpr(node) => node.end(),
478      Node::Constructor(node) => node.end(),
479      Node::ContinueStmt(node) => node.end(),
480      Node::DebuggerStmt(node) => node.end(),
481      Node::Decorator(node) => node.end(),
482      Node::DoWhileStmt(node) => node.end(),
483      Node::EmptyStmt(node) => node.end(),
484      Node::ExportAll(node) => node.end(),
485      Node::ExportDecl(node) => node.end(),
486      Node::ExportDefaultDecl(node) => node.end(),
487      Node::ExportDefaultExpr(node) => node.end(),
488      Node::ExportDefaultSpecifier(node) => node.end(),
489      Node::ExportNamedSpecifier(node) => node.end(),
490      Node::ExportNamespaceSpecifier(node) => node.end(),
491      Node::ExprOrSpread(node) => node.end(),
492      Node::ExprStmt(node) => node.end(),
493      Node::FnDecl(node) => node.end(),
494      Node::FnExpr(node) => node.end(),
495      Node::ForInStmt(node) => node.end(),
496      Node::ForOfStmt(node) => node.end(),
497      Node::ForStmt(node) => node.end(),
498      Node::Function(node) => node.end(),
499      Node::GetterProp(node) => node.end(),
500      Node::Ident(node) => node.end(),
501      Node::IdentName(node) => node.end(),
502      Node::IfStmt(node) => node.end(),
503      Node::Import(node) => node.end(),
504      Node::ImportDecl(node) => node.end(),
505      Node::ImportDefaultSpecifier(node) => node.end(),
506      Node::ImportNamedSpecifier(node) => node.end(),
507      Node::ImportStarAsSpecifier(node) => node.end(),
508      Node::Invalid(node) => node.end(),
509      Node::JSXAttr(node) => node.end(),
510      Node::JSXClosingElement(node) => node.end(),
511      Node::JSXClosingFragment(node) => node.end(),
512      Node::JSXElement(node) => node.end(),
513      Node::JSXEmptyExpr(node) => node.end(),
514      Node::JSXExprContainer(node) => node.end(),
515      Node::JSXFragment(node) => node.end(),
516      Node::JSXMemberExpr(node) => node.end(),
517      Node::JSXNamespacedName(node) => node.end(),
518      Node::JSXOpeningElement(node) => node.end(),
519      Node::JSXOpeningFragment(node) => node.end(),
520      Node::JSXSpreadChild(node) => node.end(),
521      Node::JSXText(node) => node.end(),
522      Node::KeyValuePatProp(node) => node.end(),
523      Node::KeyValueProp(node) => node.end(),
524      Node::LabeledStmt(node) => node.end(),
525      Node::MemberExpr(node) => node.end(),
526      Node::MetaPropExpr(node) => node.end(),
527      Node::MethodProp(node) => node.end(),
528      Node::Module(node) => node.end(),
529      Node::NamedExport(node) => node.end(),
530      Node::NewExpr(node) => node.end(),
531      Node::Null(node) => node.end(),
532      Node::Number(node) => node.end(),
533      Node::ObjectLit(node) => node.end(),
534      Node::ObjectPat(node) => node.end(),
535      Node::OptCall(node) => node.end(),
536      Node::OptChainExpr(node) => node.end(),
537      Node::Param(node) => node.end(),
538      Node::ParenExpr(node) => node.end(),
539      Node::PrivateMethod(node) => node.end(),
540      Node::PrivateName(node) => node.end(),
541      Node::PrivateProp(node) => node.end(),
542      Node::Regex(node) => node.end(),
543      Node::RestPat(node) => node.end(),
544      Node::ReturnStmt(node) => node.end(),
545      Node::Script(node) => node.end(),
546      Node::SeqExpr(node) => node.end(),
547      Node::SetterProp(node) => node.end(),
548      Node::SpreadElement(node) => node.end(),
549      Node::StaticBlock(node) => node.end(),
550      Node::Str(node) => node.end(),
551      Node::Super(node) => node.end(),
552      Node::SuperPropExpr(node) => node.end(),
553      Node::SwitchCase(node) => node.end(),
554      Node::SwitchStmt(node) => node.end(),
555      Node::TaggedTpl(node) => node.end(),
556      Node::ThisExpr(node) => node.end(),
557      Node::ThrowStmt(node) => node.end(),
558      Node::Tpl(node) => node.end(),
559      Node::TplElement(node) => node.end(),
560      Node::TryStmt(node) => node.end(),
561      Node::TsArrayType(node) => node.end(),
562      Node::TsAsExpr(node) => node.end(),
563      Node::TsCallSignatureDecl(node) => node.end(),
564      Node::TsConditionalType(node) => node.end(),
565      Node::TsConstAssertion(node) => node.end(),
566      Node::TsConstructSignatureDecl(node) => node.end(),
567      Node::TsConstructorType(node) => node.end(),
568      Node::TsEnumDecl(node) => node.end(),
569      Node::TsEnumMember(node) => node.end(),
570      Node::TsExportAssignment(node) => node.end(),
571      Node::TsExprWithTypeArgs(node) => node.end(),
572      Node::TsExternalModuleRef(node) => node.end(),
573      Node::TsFnType(node) => node.end(),
574      Node::TsGetterSignature(node) => node.end(),
575      Node::TsImportCallOptions(node) => node.end(),
576      Node::TsImportEqualsDecl(node) => node.end(),
577      Node::TsImportType(node) => node.end(),
578      Node::TsIndexSignature(node) => node.end(),
579      Node::TsIndexedAccessType(node) => node.end(),
580      Node::TsInferType(node) => node.end(),
581      Node::TsInstantiation(node) => node.end(),
582      Node::TsInterfaceBody(node) => node.end(),
583      Node::TsInterfaceDecl(node) => node.end(),
584      Node::TsIntersectionType(node) => node.end(),
585      Node::TsKeywordType(node) => node.end(),
586      Node::TsLitType(node) => node.end(),
587      Node::TsMappedType(node) => node.end(),
588      Node::TsMethodSignature(node) => node.end(),
589      Node::TsModuleBlock(node) => node.end(),
590      Node::TsModuleDecl(node) => node.end(),
591      Node::TsNamespaceDecl(node) => node.end(),
592      Node::TsNamespaceExportDecl(node) => node.end(),
593      Node::TsNonNullExpr(node) => node.end(),
594      Node::TsOptionalType(node) => node.end(),
595      Node::TsParamProp(node) => node.end(),
596      Node::TsParenthesizedType(node) => node.end(),
597      Node::TsPropertySignature(node) => node.end(),
598      Node::TsQualifiedName(node) => node.end(),
599      Node::TsRestType(node) => node.end(),
600      Node::TsSatisfiesExpr(node) => node.end(),
601      Node::TsSetterSignature(node) => node.end(),
602      Node::TsThisType(node) => node.end(),
603      Node::TsTplLitType(node) => node.end(),
604      Node::TsTupleElement(node) => node.end(),
605      Node::TsTupleType(node) => node.end(),
606      Node::TsTypeAliasDecl(node) => node.end(),
607      Node::TsTypeAnn(node) => node.end(),
608      Node::TsTypeAssertion(node) => node.end(),
609      Node::TsTypeLit(node) => node.end(),
610      Node::TsTypeOperator(node) => node.end(),
611      Node::TsTypeParam(node) => node.end(),
612      Node::TsTypeParamDecl(node) => node.end(),
613      Node::TsTypeParamInstantiation(node) => node.end(),
614      Node::TsTypePredicate(node) => node.end(),
615      Node::TsTypeQuery(node) => node.end(),
616      Node::TsTypeRef(node) => node.end(),
617      Node::TsUnionType(node) => node.end(),
618      Node::UnaryExpr(node) => node.end(),
619      Node::UpdateExpr(node) => node.end(),
620      Node::UsingDecl(node) => node.end(),
621      Node::VarDecl(node) => node.end(),
622      Node::VarDeclarator(node) => node.end(),
623      Node::WhileStmt(node) => node.end(),
624      Node::WithStmt(node) => node.end(),
625      Node::YieldExpr(node) => node.end(),
626    }
627  }
628}
629
630impl<'a> NodeTrait<'a> for Node<'a> {
631  fn parent(&self) -> Option<Node<'a>> {
632    match self {
633      Node::ArrayLit(node) => NodeTrait::parent(*node),
634      Node::ArrayPat(node) => NodeTrait::parent(*node),
635      Node::ArrowExpr(node) => NodeTrait::parent(*node),
636      Node::AssignExpr(node) => NodeTrait::parent(*node),
637      Node::AssignPat(node) => NodeTrait::parent(*node),
638      Node::AssignPatProp(node) => NodeTrait::parent(*node),
639      Node::AssignProp(node) => NodeTrait::parent(*node),
640      Node::AutoAccessor(node) => NodeTrait::parent(*node),
641      Node::AwaitExpr(node) => NodeTrait::parent(*node),
642      Node::BigInt(node) => NodeTrait::parent(*node),
643      Node::BinExpr(node) => NodeTrait::parent(*node),
644      Node::BindingIdent(node) => NodeTrait::parent(*node),
645      Node::BlockStmt(node) => NodeTrait::parent(*node),
646      Node::Bool(node) => NodeTrait::parent(*node),
647      Node::BreakStmt(node) => NodeTrait::parent(*node),
648      Node::CallExpr(node) => NodeTrait::parent(*node),
649      Node::CatchClause(node) => NodeTrait::parent(*node),
650      Node::Class(node) => NodeTrait::parent(*node),
651      Node::ClassDecl(node) => NodeTrait::parent(*node),
652      Node::ClassExpr(node) => NodeTrait::parent(*node),
653      Node::ClassMethod(node) => NodeTrait::parent(*node),
654      Node::ClassProp(node) => NodeTrait::parent(*node),
655      Node::ComputedPropName(node) => NodeTrait::parent(*node),
656      Node::CondExpr(node) => NodeTrait::parent(*node),
657      Node::Constructor(node) => NodeTrait::parent(*node),
658      Node::ContinueStmt(node) => NodeTrait::parent(*node),
659      Node::DebuggerStmt(node) => NodeTrait::parent(*node),
660      Node::Decorator(node) => NodeTrait::parent(*node),
661      Node::DoWhileStmt(node) => NodeTrait::parent(*node),
662      Node::EmptyStmt(node) => NodeTrait::parent(*node),
663      Node::ExportAll(node) => NodeTrait::parent(*node),
664      Node::ExportDecl(node) => NodeTrait::parent(*node),
665      Node::ExportDefaultDecl(node) => NodeTrait::parent(*node),
666      Node::ExportDefaultExpr(node) => NodeTrait::parent(*node),
667      Node::ExportDefaultSpecifier(node) => NodeTrait::parent(*node),
668      Node::ExportNamedSpecifier(node) => NodeTrait::parent(*node),
669      Node::ExportNamespaceSpecifier(node) => NodeTrait::parent(*node),
670      Node::ExprOrSpread(node) => NodeTrait::parent(*node),
671      Node::ExprStmt(node) => NodeTrait::parent(*node),
672      Node::FnDecl(node) => NodeTrait::parent(*node),
673      Node::FnExpr(node) => NodeTrait::parent(*node),
674      Node::ForInStmt(node) => NodeTrait::parent(*node),
675      Node::ForOfStmt(node) => NodeTrait::parent(*node),
676      Node::ForStmt(node) => NodeTrait::parent(*node),
677      Node::Function(node) => NodeTrait::parent(*node),
678      Node::GetterProp(node) => NodeTrait::parent(*node),
679      Node::Ident(node) => NodeTrait::parent(*node),
680      Node::IdentName(node) => NodeTrait::parent(*node),
681      Node::IfStmt(node) => NodeTrait::parent(*node),
682      Node::Import(node) => NodeTrait::parent(*node),
683      Node::ImportDecl(node) => NodeTrait::parent(*node),
684      Node::ImportDefaultSpecifier(node) => NodeTrait::parent(*node),
685      Node::ImportNamedSpecifier(node) => NodeTrait::parent(*node),
686      Node::ImportStarAsSpecifier(node) => NodeTrait::parent(*node),
687      Node::Invalid(node) => NodeTrait::parent(*node),
688      Node::JSXAttr(node) => NodeTrait::parent(*node),
689      Node::JSXClosingElement(node) => NodeTrait::parent(*node),
690      Node::JSXClosingFragment(node) => NodeTrait::parent(*node),
691      Node::JSXElement(node) => NodeTrait::parent(*node),
692      Node::JSXEmptyExpr(node) => NodeTrait::parent(*node),
693      Node::JSXExprContainer(node) => NodeTrait::parent(*node),
694      Node::JSXFragment(node) => NodeTrait::parent(*node),
695      Node::JSXMemberExpr(node) => NodeTrait::parent(*node),
696      Node::JSXNamespacedName(node) => NodeTrait::parent(*node),
697      Node::JSXOpeningElement(node) => NodeTrait::parent(*node),
698      Node::JSXOpeningFragment(node) => NodeTrait::parent(*node),
699      Node::JSXSpreadChild(node) => NodeTrait::parent(*node),
700      Node::JSXText(node) => NodeTrait::parent(*node),
701      Node::KeyValuePatProp(node) => NodeTrait::parent(*node),
702      Node::KeyValueProp(node) => NodeTrait::parent(*node),
703      Node::LabeledStmt(node) => NodeTrait::parent(*node),
704      Node::MemberExpr(node) => NodeTrait::parent(*node),
705      Node::MetaPropExpr(node) => NodeTrait::parent(*node),
706      Node::MethodProp(node) => NodeTrait::parent(*node),
707      Node::Module(node) => NodeTrait::parent(*node),
708      Node::NamedExport(node) => NodeTrait::parent(*node),
709      Node::NewExpr(node) => NodeTrait::parent(*node),
710      Node::Null(node) => NodeTrait::parent(*node),
711      Node::Number(node) => NodeTrait::parent(*node),
712      Node::ObjectLit(node) => NodeTrait::parent(*node),
713      Node::ObjectPat(node) => NodeTrait::parent(*node),
714      Node::OptCall(node) => NodeTrait::parent(*node),
715      Node::OptChainExpr(node) => NodeTrait::parent(*node),
716      Node::Param(node) => NodeTrait::parent(*node),
717      Node::ParenExpr(node) => NodeTrait::parent(*node),
718      Node::PrivateMethod(node) => NodeTrait::parent(*node),
719      Node::PrivateName(node) => NodeTrait::parent(*node),
720      Node::PrivateProp(node) => NodeTrait::parent(*node),
721      Node::Regex(node) => NodeTrait::parent(*node),
722      Node::RestPat(node) => NodeTrait::parent(*node),
723      Node::ReturnStmt(node) => NodeTrait::parent(*node),
724      Node::Script(node) => NodeTrait::parent(*node),
725      Node::SeqExpr(node) => NodeTrait::parent(*node),
726      Node::SetterProp(node) => NodeTrait::parent(*node),
727      Node::SpreadElement(node) => NodeTrait::parent(*node),
728      Node::StaticBlock(node) => NodeTrait::parent(*node),
729      Node::Str(node) => NodeTrait::parent(*node),
730      Node::Super(node) => NodeTrait::parent(*node),
731      Node::SuperPropExpr(node) => NodeTrait::parent(*node),
732      Node::SwitchCase(node) => NodeTrait::parent(*node),
733      Node::SwitchStmt(node) => NodeTrait::parent(*node),
734      Node::TaggedTpl(node) => NodeTrait::parent(*node),
735      Node::ThisExpr(node) => NodeTrait::parent(*node),
736      Node::ThrowStmt(node) => NodeTrait::parent(*node),
737      Node::Tpl(node) => NodeTrait::parent(*node),
738      Node::TplElement(node) => NodeTrait::parent(*node),
739      Node::TryStmt(node) => NodeTrait::parent(*node),
740      Node::TsArrayType(node) => NodeTrait::parent(*node),
741      Node::TsAsExpr(node) => NodeTrait::parent(*node),
742      Node::TsCallSignatureDecl(node) => NodeTrait::parent(*node),
743      Node::TsConditionalType(node) => NodeTrait::parent(*node),
744      Node::TsConstAssertion(node) => NodeTrait::parent(*node),
745      Node::TsConstructSignatureDecl(node) => NodeTrait::parent(*node),
746      Node::TsConstructorType(node) => NodeTrait::parent(*node),
747      Node::TsEnumDecl(node) => NodeTrait::parent(*node),
748      Node::TsEnumMember(node) => NodeTrait::parent(*node),
749      Node::TsExportAssignment(node) => NodeTrait::parent(*node),
750      Node::TsExprWithTypeArgs(node) => NodeTrait::parent(*node),
751      Node::TsExternalModuleRef(node) => NodeTrait::parent(*node),
752      Node::TsFnType(node) => NodeTrait::parent(*node),
753      Node::TsGetterSignature(node) => NodeTrait::parent(*node),
754      Node::TsImportCallOptions(node) => NodeTrait::parent(*node),
755      Node::TsImportEqualsDecl(node) => NodeTrait::parent(*node),
756      Node::TsImportType(node) => NodeTrait::parent(*node),
757      Node::TsIndexSignature(node) => NodeTrait::parent(*node),
758      Node::TsIndexedAccessType(node) => NodeTrait::parent(*node),
759      Node::TsInferType(node) => NodeTrait::parent(*node),
760      Node::TsInstantiation(node) => NodeTrait::parent(*node),
761      Node::TsInterfaceBody(node) => NodeTrait::parent(*node),
762      Node::TsInterfaceDecl(node) => NodeTrait::parent(*node),
763      Node::TsIntersectionType(node) => NodeTrait::parent(*node),
764      Node::TsKeywordType(node) => NodeTrait::parent(*node),
765      Node::TsLitType(node) => NodeTrait::parent(*node),
766      Node::TsMappedType(node) => NodeTrait::parent(*node),
767      Node::TsMethodSignature(node) => NodeTrait::parent(*node),
768      Node::TsModuleBlock(node) => NodeTrait::parent(*node),
769      Node::TsModuleDecl(node) => NodeTrait::parent(*node),
770      Node::TsNamespaceDecl(node) => NodeTrait::parent(*node),
771      Node::TsNamespaceExportDecl(node) => NodeTrait::parent(*node),
772      Node::TsNonNullExpr(node) => NodeTrait::parent(*node),
773      Node::TsOptionalType(node) => NodeTrait::parent(*node),
774      Node::TsParamProp(node) => NodeTrait::parent(*node),
775      Node::TsParenthesizedType(node) => NodeTrait::parent(*node),
776      Node::TsPropertySignature(node) => NodeTrait::parent(*node),
777      Node::TsQualifiedName(node) => NodeTrait::parent(*node),
778      Node::TsRestType(node) => NodeTrait::parent(*node),
779      Node::TsSatisfiesExpr(node) => NodeTrait::parent(*node),
780      Node::TsSetterSignature(node) => NodeTrait::parent(*node),
781      Node::TsThisType(node) => NodeTrait::parent(*node),
782      Node::TsTplLitType(node) => NodeTrait::parent(*node),
783      Node::TsTupleElement(node) => NodeTrait::parent(*node),
784      Node::TsTupleType(node) => NodeTrait::parent(*node),
785      Node::TsTypeAliasDecl(node) => NodeTrait::parent(*node),
786      Node::TsTypeAnn(node) => NodeTrait::parent(*node),
787      Node::TsTypeAssertion(node) => NodeTrait::parent(*node),
788      Node::TsTypeLit(node) => NodeTrait::parent(*node),
789      Node::TsTypeOperator(node) => NodeTrait::parent(*node),
790      Node::TsTypeParam(node) => NodeTrait::parent(*node),
791      Node::TsTypeParamDecl(node) => NodeTrait::parent(*node),
792      Node::TsTypeParamInstantiation(node) => NodeTrait::parent(*node),
793      Node::TsTypePredicate(node) => NodeTrait::parent(*node),
794      Node::TsTypeQuery(node) => NodeTrait::parent(*node),
795      Node::TsTypeRef(node) => NodeTrait::parent(*node),
796      Node::TsUnionType(node) => NodeTrait::parent(*node),
797      Node::UnaryExpr(node) => NodeTrait::parent(*node),
798      Node::UpdateExpr(node) => NodeTrait::parent(*node),
799      Node::UsingDecl(node) => NodeTrait::parent(*node),
800      Node::VarDecl(node) => NodeTrait::parent(*node),
801      Node::VarDeclarator(node) => NodeTrait::parent(*node),
802      Node::WhileStmt(node) => NodeTrait::parent(*node),
803      Node::WithStmt(node) => NodeTrait::parent(*node),
804      Node::YieldExpr(node) => NodeTrait::parent(*node),
805    }
806  }
807
808  fn children(&self) -> Vec<Node<'a>> {
809    match self {
810      Node::ArrayLit(node) => node.children(),
811      Node::ArrayPat(node) => node.children(),
812      Node::ArrowExpr(node) => node.children(),
813      Node::AssignExpr(node) => node.children(),
814      Node::AssignPat(node) => node.children(),
815      Node::AssignPatProp(node) => node.children(),
816      Node::AssignProp(node) => node.children(),
817      Node::AutoAccessor(node) => node.children(),
818      Node::AwaitExpr(node) => node.children(),
819      Node::BigInt(node) => node.children(),
820      Node::BinExpr(node) => node.children(),
821      Node::BindingIdent(node) => node.children(),
822      Node::BlockStmt(node) => node.children(),
823      Node::Bool(node) => node.children(),
824      Node::BreakStmt(node) => node.children(),
825      Node::CallExpr(node) => node.children(),
826      Node::CatchClause(node) => node.children(),
827      Node::Class(node) => node.children(),
828      Node::ClassDecl(node) => node.children(),
829      Node::ClassExpr(node) => node.children(),
830      Node::ClassMethod(node) => node.children(),
831      Node::ClassProp(node) => node.children(),
832      Node::ComputedPropName(node) => node.children(),
833      Node::CondExpr(node) => node.children(),
834      Node::Constructor(node) => node.children(),
835      Node::ContinueStmt(node) => node.children(),
836      Node::DebuggerStmt(node) => node.children(),
837      Node::Decorator(node) => node.children(),
838      Node::DoWhileStmt(node) => node.children(),
839      Node::EmptyStmt(node) => node.children(),
840      Node::ExportAll(node) => node.children(),
841      Node::ExportDecl(node) => node.children(),
842      Node::ExportDefaultDecl(node) => node.children(),
843      Node::ExportDefaultExpr(node) => node.children(),
844      Node::ExportDefaultSpecifier(node) => node.children(),
845      Node::ExportNamedSpecifier(node) => node.children(),
846      Node::ExportNamespaceSpecifier(node) => node.children(),
847      Node::ExprOrSpread(node) => node.children(),
848      Node::ExprStmt(node) => node.children(),
849      Node::FnDecl(node) => node.children(),
850      Node::FnExpr(node) => node.children(),
851      Node::ForInStmt(node) => node.children(),
852      Node::ForOfStmt(node) => node.children(),
853      Node::ForStmt(node) => node.children(),
854      Node::Function(node) => node.children(),
855      Node::GetterProp(node) => node.children(),
856      Node::Ident(node) => node.children(),
857      Node::IdentName(node) => node.children(),
858      Node::IfStmt(node) => node.children(),
859      Node::Import(node) => node.children(),
860      Node::ImportDecl(node) => node.children(),
861      Node::ImportDefaultSpecifier(node) => node.children(),
862      Node::ImportNamedSpecifier(node) => node.children(),
863      Node::ImportStarAsSpecifier(node) => node.children(),
864      Node::Invalid(node) => node.children(),
865      Node::JSXAttr(node) => node.children(),
866      Node::JSXClosingElement(node) => node.children(),
867      Node::JSXClosingFragment(node) => node.children(),
868      Node::JSXElement(node) => node.children(),
869      Node::JSXEmptyExpr(node) => node.children(),
870      Node::JSXExprContainer(node) => node.children(),
871      Node::JSXFragment(node) => node.children(),
872      Node::JSXMemberExpr(node) => node.children(),
873      Node::JSXNamespacedName(node) => node.children(),
874      Node::JSXOpeningElement(node) => node.children(),
875      Node::JSXOpeningFragment(node) => node.children(),
876      Node::JSXSpreadChild(node) => node.children(),
877      Node::JSXText(node) => node.children(),
878      Node::KeyValuePatProp(node) => node.children(),
879      Node::KeyValueProp(node) => node.children(),
880      Node::LabeledStmt(node) => node.children(),
881      Node::MemberExpr(node) => node.children(),
882      Node::MetaPropExpr(node) => node.children(),
883      Node::MethodProp(node) => node.children(),
884      Node::Module(node) => node.children(),
885      Node::NamedExport(node) => node.children(),
886      Node::NewExpr(node) => node.children(),
887      Node::Null(node) => node.children(),
888      Node::Number(node) => node.children(),
889      Node::ObjectLit(node) => node.children(),
890      Node::ObjectPat(node) => node.children(),
891      Node::OptCall(node) => node.children(),
892      Node::OptChainExpr(node) => node.children(),
893      Node::Param(node) => node.children(),
894      Node::ParenExpr(node) => node.children(),
895      Node::PrivateMethod(node) => node.children(),
896      Node::PrivateName(node) => node.children(),
897      Node::PrivateProp(node) => node.children(),
898      Node::Regex(node) => node.children(),
899      Node::RestPat(node) => node.children(),
900      Node::ReturnStmt(node) => node.children(),
901      Node::Script(node) => node.children(),
902      Node::SeqExpr(node) => node.children(),
903      Node::SetterProp(node) => node.children(),
904      Node::SpreadElement(node) => node.children(),
905      Node::StaticBlock(node) => node.children(),
906      Node::Str(node) => node.children(),
907      Node::Super(node) => node.children(),
908      Node::SuperPropExpr(node) => node.children(),
909      Node::SwitchCase(node) => node.children(),
910      Node::SwitchStmt(node) => node.children(),
911      Node::TaggedTpl(node) => node.children(),
912      Node::ThisExpr(node) => node.children(),
913      Node::ThrowStmt(node) => node.children(),
914      Node::Tpl(node) => node.children(),
915      Node::TplElement(node) => node.children(),
916      Node::TryStmt(node) => node.children(),
917      Node::TsArrayType(node) => node.children(),
918      Node::TsAsExpr(node) => node.children(),
919      Node::TsCallSignatureDecl(node) => node.children(),
920      Node::TsConditionalType(node) => node.children(),
921      Node::TsConstAssertion(node) => node.children(),
922      Node::TsConstructSignatureDecl(node) => node.children(),
923      Node::TsConstructorType(node) => node.children(),
924      Node::TsEnumDecl(node) => node.children(),
925      Node::TsEnumMember(node) => node.children(),
926      Node::TsExportAssignment(node) => node.children(),
927      Node::TsExprWithTypeArgs(node) => node.children(),
928      Node::TsExternalModuleRef(node) => node.children(),
929      Node::TsFnType(node) => node.children(),
930      Node::TsGetterSignature(node) => node.children(),
931      Node::TsImportCallOptions(node) => node.children(),
932      Node::TsImportEqualsDecl(node) => node.children(),
933      Node::TsImportType(node) => node.children(),
934      Node::TsIndexSignature(node) => node.children(),
935      Node::TsIndexedAccessType(node) => node.children(),
936      Node::TsInferType(node) => node.children(),
937      Node::TsInstantiation(node) => node.children(),
938      Node::TsInterfaceBody(node) => node.children(),
939      Node::TsInterfaceDecl(node) => node.children(),
940      Node::TsIntersectionType(node) => node.children(),
941      Node::TsKeywordType(node) => node.children(),
942      Node::TsLitType(node) => node.children(),
943      Node::TsMappedType(node) => node.children(),
944      Node::TsMethodSignature(node) => node.children(),
945      Node::TsModuleBlock(node) => node.children(),
946      Node::TsModuleDecl(node) => node.children(),
947      Node::TsNamespaceDecl(node) => node.children(),
948      Node::TsNamespaceExportDecl(node) => node.children(),
949      Node::TsNonNullExpr(node) => node.children(),
950      Node::TsOptionalType(node) => node.children(),
951      Node::TsParamProp(node) => node.children(),
952      Node::TsParenthesizedType(node) => node.children(),
953      Node::TsPropertySignature(node) => node.children(),
954      Node::TsQualifiedName(node) => node.children(),
955      Node::TsRestType(node) => node.children(),
956      Node::TsSatisfiesExpr(node) => node.children(),
957      Node::TsSetterSignature(node) => node.children(),
958      Node::TsThisType(node) => node.children(),
959      Node::TsTplLitType(node) => node.children(),
960      Node::TsTupleElement(node) => node.children(),
961      Node::TsTupleType(node) => node.children(),
962      Node::TsTypeAliasDecl(node) => node.children(),
963      Node::TsTypeAnn(node) => node.children(),
964      Node::TsTypeAssertion(node) => node.children(),
965      Node::TsTypeLit(node) => node.children(),
966      Node::TsTypeOperator(node) => node.children(),
967      Node::TsTypeParam(node) => node.children(),
968      Node::TsTypeParamDecl(node) => node.children(),
969      Node::TsTypeParamInstantiation(node) => node.children(),
970      Node::TsTypePredicate(node) => node.children(),
971      Node::TsTypeQuery(node) => node.children(),
972      Node::TsTypeRef(node) => node.children(),
973      Node::TsUnionType(node) => node.children(),
974      Node::UnaryExpr(node) => node.children(),
975      Node::UpdateExpr(node) => node.children(),
976      Node::UsingDecl(node) => node.children(),
977      Node::VarDecl(node) => node.children(),
978      Node::VarDeclarator(node) => node.children(),
979      Node::WhileStmt(node) => node.children(),
980      Node::WithStmt(node) => node.children(),
981      Node::YieldExpr(node) => node.children(),
982    }
983  }
984
985  fn as_node(&self) -> Node<'a> {
986    match self {
987      Node::ArrayLit(node) => node.as_node(),
988      Node::ArrayPat(node) => node.as_node(),
989      Node::ArrowExpr(node) => node.as_node(),
990      Node::AssignExpr(node) => node.as_node(),
991      Node::AssignPat(node) => node.as_node(),
992      Node::AssignPatProp(node) => node.as_node(),
993      Node::AssignProp(node) => node.as_node(),
994      Node::AutoAccessor(node) => node.as_node(),
995      Node::AwaitExpr(node) => node.as_node(),
996      Node::BigInt(node) => node.as_node(),
997      Node::BinExpr(node) => node.as_node(),
998      Node::BindingIdent(node) => node.as_node(),
999      Node::BlockStmt(node) => node.as_node(),
1000      Node::Bool(node) => node.as_node(),
1001      Node::BreakStmt(node) => node.as_node(),
1002      Node::CallExpr(node) => node.as_node(),
1003      Node::CatchClause(node) => node.as_node(),
1004      Node::Class(node) => node.as_node(),
1005      Node::ClassDecl(node) => node.as_node(),
1006      Node::ClassExpr(node) => node.as_node(),
1007      Node::ClassMethod(node) => node.as_node(),
1008      Node::ClassProp(node) => node.as_node(),
1009      Node::ComputedPropName(node) => node.as_node(),
1010      Node::CondExpr(node) => node.as_node(),
1011      Node::Constructor(node) => node.as_node(),
1012      Node::ContinueStmt(node) => node.as_node(),
1013      Node::DebuggerStmt(node) => node.as_node(),
1014      Node::Decorator(node) => node.as_node(),
1015      Node::DoWhileStmt(node) => node.as_node(),
1016      Node::EmptyStmt(node) => node.as_node(),
1017      Node::ExportAll(node) => node.as_node(),
1018      Node::ExportDecl(node) => node.as_node(),
1019      Node::ExportDefaultDecl(node) => node.as_node(),
1020      Node::ExportDefaultExpr(node) => node.as_node(),
1021      Node::ExportDefaultSpecifier(node) => node.as_node(),
1022      Node::ExportNamedSpecifier(node) => node.as_node(),
1023      Node::ExportNamespaceSpecifier(node) => node.as_node(),
1024      Node::ExprOrSpread(node) => node.as_node(),
1025      Node::ExprStmt(node) => node.as_node(),
1026      Node::FnDecl(node) => node.as_node(),
1027      Node::FnExpr(node) => node.as_node(),
1028      Node::ForInStmt(node) => node.as_node(),
1029      Node::ForOfStmt(node) => node.as_node(),
1030      Node::ForStmt(node) => node.as_node(),
1031      Node::Function(node) => node.as_node(),
1032      Node::GetterProp(node) => node.as_node(),
1033      Node::Ident(node) => node.as_node(),
1034      Node::IdentName(node) => node.as_node(),
1035      Node::IfStmt(node) => node.as_node(),
1036      Node::Import(node) => node.as_node(),
1037      Node::ImportDecl(node) => node.as_node(),
1038      Node::ImportDefaultSpecifier(node) => node.as_node(),
1039      Node::ImportNamedSpecifier(node) => node.as_node(),
1040      Node::ImportStarAsSpecifier(node) => node.as_node(),
1041      Node::Invalid(node) => node.as_node(),
1042      Node::JSXAttr(node) => node.as_node(),
1043      Node::JSXClosingElement(node) => node.as_node(),
1044      Node::JSXClosingFragment(node) => node.as_node(),
1045      Node::JSXElement(node) => node.as_node(),
1046      Node::JSXEmptyExpr(node) => node.as_node(),
1047      Node::JSXExprContainer(node) => node.as_node(),
1048      Node::JSXFragment(node) => node.as_node(),
1049      Node::JSXMemberExpr(node) => node.as_node(),
1050      Node::JSXNamespacedName(node) => node.as_node(),
1051      Node::JSXOpeningElement(node) => node.as_node(),
1052      Node::JSXOpeningFragment(node) => node.as_node(),
1053      Node::JSXSpreadChild(node) => node.as_node(),
1054      Node::JSXText(node) => node.as_node(),
1055      Node::KeyValuePatProp(node) => node.as_node(),
1056      Node::KeyValueProp(node) => node.as_node(),
1057      Node::LabeledStmt(node) => node.as_node(),
1058      Node::MemberExpr(node) => node.as_node(),
1059      Node::MetaPropExpr(node) => node.as_node(),
1060      Node::MethodProp(node) => node.as_node(),
1061      Node::Module(node) => node.as_node(),
1062      Node::NamedExport(node) => node.as_node(),
1063      Node::NewExpr(node) => node.as_node(),
1064      Node::Null(node) => node.as_node(),
1065      Node::Number(node) => node.as_node(),
1066      Node::ObjectLit(node) => node.as_node(),
1067      Node::ObjectPat(node) => node.as_node(),
1068      Node::OptCall(node) => node.as_node(),
1069      Node::OptChainExpr(node) => node.as_node(),
1070      Node::Param(node) => node.as_node(),
1071      Node::ParenExpr(node) => node.as_node(),
1072      Node::PrivateMethod(node) => node.as_node(),
1073      Node::PrivateName(node) => node.as_node(),
1074      Node::PrivateProp(node) => node.as_node(),
1075      Node::Regex(node) => node.as_node(),
1076      Node::RestPat(node) => node.as_node(),
1077      Node::ReturnStmt(node) => node.as_node(),
1078      Node::Script(node) => node.as_node(),
1079      Node::SeqExpr(node) => node.as_node(),
1080      Node::SetterProp(node) => node.as_node(),
1081      Node::SpreadElement(node) => node.as_node(),
1082      Node::StaticBlock(node) => node.as_node(),
1083      Node::Str(node) => node.as_node(),
1084      Node::Super(node) => node.as_node(),
1085      Node::SuperPropExpr(node) => node.as_node(),
1086      Node::SwitchCase(node) => node.as_node(),
1087      Node::SwitchStmt(node) => node.as_node(),
1088      Node::TaggedTpl(node) => node.as_node(),
1089      Node::ThisExpr(node) => node.as_node(),
1090      Node::ThrowStmt(node) => node.as_node(),
1091      Node::Tpl(node) => node.as_node(),
1092      Node::TplElement(node) => node.as_node(),
1093      Node::TryStmt(node) => node.as_node(),
1094      Node::TsArrayType(node) => node.as_node(),
1095      Node::TsAsExpr(node) => node.as_node(),
1096      Node::TsCallSignatureDecl(node) => node.as_node(),
1097      Node::TsConditionalType(node) => node.as_node(),
1098      Node::TsConstAssertion(node) => node.as_node(),
1099      Node::TsConstructSignatureDecl(node) => node.as_node(),
1100      Node::TsConstructorType(node) => node.as_node(),
1101      Node::TsEnumDecl(node) => node.as_node(),
1102      Node::TsEnumMember(node) => node.as_node(),
1103      Node::TsExportAssignment(node) => node.as_node(),
1104      Node::TsExprWithTypeArgs(node) => node.as_node(),
1105      Node::TsExternalModuleRef(node) => node.as_node(),
1106      Node::TsFnType(node) => node.as_node(),
1107      Node::TsGetterSignature(node) => node.as_node(),
1108      Node::TsImportCallOptions(node) => node.as_node(),
1109      Node::TsImportEqualsDecl(node) => node.as_node(),
1110      Node::TsImportType(node) => node.as_node(),
1111      Node::TsIndexSignature(node) => node.as_node(),
1112      Node::TsIndexedAccessType(node) => node.as_node(),
1113      Node::TsInferType(node) => node.as_node(),
1114      Node::TsInstantiation(node) => node.as_node(),
1115      Node::TsInterfaceBody(node) => node.as_node(),
1116      Node::TsInterfaceDecl(node) => node.as_node(),
1117      Node::TsIntersectionType(node) => node.as_node(),
1118      Node::TsKeywordType(node) => node.as_node(),
1119      Node::TsLitType(node) => node.as_node(),
1120      Node::TsMappedType(node) => node.as_node(),
1121      Node::TsMethodSignature(node) => node.as_node(),
1122      Node::TsModuleBlock(node) => node.as_node(),
1123      Node::TsModuleDecl(node) => node.as_node(),
1124      Node::TsNamespaceDecl(node) => node.as_node(),
1125      Node::TsNamespaceExportDecl(node) => node.as_node(),
1126      Node::TsNonNullExpr(node) => node.as_node(),
1127      Node::TsOptionalType(node) => node.as_node(),
1128      Node::TsParamProp(node) => node.as_node(),
1129      Node::TsParenthesizedType(node) => node.as_node(),
1130      Node::TsPropertySignature(node) => node.as_node(),
1131      Node::TsQualifiedName(node) => node.as_node(),
1132      Node::TsRestType(node) => node.as_node(),
1133      Node::TsSatisfiesExpr(node) => node.as_node(),
1134      Node::TsSetterSignature(node) => node.as_node(),
1135      Node::TsThisType(node) => node.as_node(),
1136      Node::TsTplLitType(node) => node.as_node(),
1137      Node::TsTupleElement(node) => node.as_node(),
1138      Node::TsTupleType(node) => node.as_node(),
1139      Node::TsTypeAliasDecl(node) => node.as_node(),
1140      Node::TsTypeAnn(node) => node.as_node(),
1141      Node::TsTypeAssertion(node) => node.as_node(),
1142      Node::TsTypeLit(node) => node.as_node(),
1143      Node::TsTypeOperator(node) => node.as_node(),
1144      Node::TsTypeParam(node) => node.as_node(),
1145      Node::TsTypeParamDecl(node) => node.as_node(),
1146      Node::TsTypeParamInstantiation(node) => node.as_node(),
1147      Node::TsTypePredicate(node) => node.as_node(),
1148      Node::TsTypeQuery(node) => node.as_node(),
1149      Node::TsTypeRef(node) => node.as_node(),
1150      Node::TsUnionType(node) => node.as_node(),
1151      Node::UnaryExpr(node) => node.as_node(),
1152      Node::UpdateExpr(node) => node.as_node(),
1153      Node::UsingDecl(node) => node.as_node(),
1154      Node::VarDecl(node) => node.as_node(),
1155      Node::VarDeclarator(node) => node.as_node(),
1156      Node::WhileStmt(node) => node.as_node(),
1157      Node::WithStmt(node) => node.as_node(),
1158      Node::YieldExpr(node) => node.as_node(),
1159    }
1160  }
1161
1162  fn kind(&self) -> NodeKind {
1163    match self {
1164      Node::ArrayLit(_) => NodeKind::ArrayLit,
1165      Node::ArrayPat(_) => NodeKind::ArrayPat,
1166      Node::ArrowExpr(_) => NodeKind::ArrowExpr,
1167      Node::AssignExpr(_) => NodeKind::AssignExpr,
1168      Node::AssignPat(_) => NodeKind::AssignPat,
1169      Node::AssignPatProp(_) => NodeKind::AssignPatProp,
1170      Node::AssignProp(_) => NodeKind::AssignProp,
1171      Node::AutoAccessor(_) => NodeKind::AutoAccessor,
1172      Node::AwaitExpr(_) => NodeKind::AwaitExpr,
1173      Node::BigInt(_) => NodeKind::BigInt,
1174      Node::BinExpr(_) => NodeKind::BinExpr,
1175      Node::BindingIdent(_) => NodeKind::BindingIdent,
1176      Node::BlockStmt(_) => NodeKind::BlockStmt,
1177      Node::Bool(_) => NodeKind::Bool,
1178      Node::BreakStmt(_) => NodeKind::BreakStmt,
1179      Node::CallExpr(_) => NodeKind::CallExpr,
1180      Node::CatchClause(_) => NodeKind::CatchClause,
1181      Node::Class(_) => NodeKind::Class,
1182      Node::ClassDecl(_) => NodeKind::ClassDecl,
1183      Node::ClassExpr(_) => NodeKind::ClassExpr,
1184      Node::ClassMethod(_) => NodeKind::ClassMethod,
1185      Node::ClassProp(_) => NodeKind::ClassProp,
1186      Node::ComputedPropName(_) => NodeKind::ComputedPropName,
1187      Node::CondExpr(_) => NodeKind::CondExpr,
1188      Node::Constructor(_) => NodeKind::Constructor,
1189      Node::ContinueStmt(_) => NodeKind::ContinueStmt,
1190      Node::DebuggerStmt(_) => NodeKind::DebuggerStmt,
1191      Node::Decorator(_) => NodeKind::Decorator,
1192      Node::DoWhileStmt(_) => NodeKind::DoWhileStmt,
1193      Node::EmptyStmt(_) => NodeKind::EmptyStmt,
1194      Node::ExportAll(_) => NodeKind::ExportAll,
1195      Node::ExportDecl(_) => NodeKind::ExportDecl,
1196      Node::ExportDefaultDecl(_) => NodeKind::ExportDefaultDecl,
1197      Node::ExportDefaultExpr(_) => NodeKind::ExportDefaultExpr,
1198      Node::ExportDefaultSpecifier(_) => NodeKind::ExportDefaultSpecifier,
1199      Node::ExportNamedSpecifier(_) => NodeKind::ExportNamedSpecifier,
1200      Node::ExportNamespaceSpecifier(_) => NodeKind::ExportNamespaceSpecifier,
1201      Node::ExprOrSpread(_) => NodeKind::ExprOrSpread,
1202      Node::ExprStmt(_) => NodeKind::ExprStmt,
1203      Node::FnDecl(_) => NodeKind::FnDecl,
1204      Node::FnExpr(_) => NodeKind::FnExpr,
1205      Node::ForInStmt(_) => NodeKind::ForInStmt,
1206      Node::ForOfStmt(_) => NodeKind::ForOfStmt,
1207      Node::ForStmt(_) => NodeKind::ForStmt,
1208      Node::Function(_) => NodeKind::Function,
1209      Node::GetterProp(_) => NodeKind::GetterProp,
1210      Node::Ident(_) => NodeKind::Ident,
1211      Node::IdentName(_) => NodeKind::IdentName,
1212      Node::IfStmt(_) => NodeKind::IfStmt,
1213      Node::Import(_) => NodeKind::Import,
1214      Node::ImportDecl(_) => NodeKind::ImportDecl,
1215      Node::ImportDefaultSpecifier(_) => NodeKind::ImportDefaultSpecifier,
1216      Node::ImportNamedSpecifier(_) => NodeKind::ImportNamedSpecifier,
1217      Node::ImportStarAsSpecifier(_) => NodeKind::ImportStarAsSpecifier,
1218      Node::Invalid(_) => NodeKind::Invalid,
1219      Node::JSXAttr(_) => NodeKind::JSXAttr,
1220      Node::JSXClosingElement(_) => NodeKind::JSXClosingElement,
1221      Node::JSXClosingFragment(_) => NodeKind::JSXClosingFragment,
1222      Node::JSXElement(_) => NodeKind::JSXElement,
1223      Node::JSXEmptyExpr(_) => NodeKind::JSXEmptyExpr,
1224      Node::JSXExprContainer(_) => NodeKind::JSXExprContainer,
1225      Node::JSXFragment(_) => NodeKind::JSXFragment,
1226      Node::JSXMemberExpr(_) => NodeKind::JSXMemberExpr,
1227      Node::JSXNamespacedName(_) => NodeKind::JSXNamespacedName,
1228      Node::JSXOpeningElement(_) => NodeKind::JSXOpeningElement,
1229      Node::JSXOpeningFragment(_) => NodeKind::JSXOpeningFragment,
1230      Node::JSXSpreadChild(_) => NodeKind::JSXSpreadChild,
1231      Node::JSXText(_) => NodeKind::JSXText,
1232      Node::KeyValuePatProp(_) => NodeKind::KeyValuePatProp,
1233      Node::KeyValueProp(_) => NodeKind::KeyValueProp,
1234      Node::LabeledStmt(_) => NodeKind::LabeledStmt,
1235      Node::MemberExpr(_) => NodeKind::MemberExpr,
1236      Node::MetaPropExpr(_) => NodeKind::MetaPropExpr,
1237      Node::MethodProp(_) => NodeKind::MethodProp,
1238      Node::Module(_) => NodeKind::Module,
1239      Node::NamedExport(_) => NodeKind::NamedExport,
1240      Node::NewExpr(_) => NodeKind::NewExpr,
1241      Node::Null(_) => NodeKind::Null,
1242      Node::Number(_) => NodeKind::Number,
1243      Node::ObjectLit(_) => NodeKind::ObjectLit,
1244      Node::ObjectPat(_) => NodeKind::ObjectPat,
1245      Node::OptCall(_) => NodeKind::OptCall,
1246      Node::OptChainExpr(_) => NodeKind::OptChainExpr,
1247      Node::Param(_) => NodeKind::Param,
1248      Node::ParenExpr(_) => NodeKind::ParenExpr,
1249      Node::PrivateMethod(_) => NodeKind::PrivateMethod,
1250      Node::PrivateName(_) => NodeKind::PrivateName,
1251      Node::PrivateProp(_) => NodeKind::PrivateProp,
1252      Node::Regex(_) => NodeKind::Regex,
1253      Node::RestPat(_) => NodeKind::RestPat,
1254      Node::ReturnStmt(_) => NodeKind::ReturnStmt,
1255      Node::Script(_) => NodeKind::Script,
1256      Node::SeqExpr(_) => NodeKind::SeqExpr,
1257      Node::SetterProp(_) => NodeKind::SetterProp,
1258      Node::SpreadElement(_) => NodeKind::SpreadElement,
1259      Node::StaticBlock(_) => NodeKind::StaticBlock,
1260      Node::Str(_) => NodeKind::Str,
1261      Node::Super(_) => NodeKind::Super,
1262      Node::SuperPropExpr(_) => NodeKind::SuperPropExpr,
1263      Node::SwitchCase(_) => NodeKind::SwitchCase,
1264      Node::SwitchStmt(_) => NodeKind::SwitchStmt,
1265      Node::TaggedTpl(_) => NodeKind::TaggedTpl,
1266      Node::ThisExpr(_) => NodeKind::ThisExpr,
1267      Node::ThrowStmt(_) => NodeKind::ThrowStmt,
1268      Node::Tpl(_) => NodeKind::Tpl,
1269      Node::TplElement(_) => NodeKind::TplElement,
1270      Node::TryStmt(_) => NodeKind::TryStmt,
1271      Node::TsArrayType(_) => NodeKind::TsArrayType,
1272      Node::TsAsExpr(_) => NodeKind::TsAsExpr,
1273      Node::TsCallSignatureDecl(_) => NodeKind::TsCallSignatureDecl,
1274      Node::TsConditionalType(_) => NodeKind::TsConditionalType,
1275      Node::TsConstAssertion(_) => NodeKind::TsConstAssertion,
1276      Node::TsConstructSignatureDecl(_) => NodeKind::TsConstructSignatureDecl,
1277      Node::TsConstructorType(_) => NodeKind::TsConstructorType,
1278      Node::TsEnumDecl(_) => NodeKind::TsEnumDecl,
1279      Node::TsEnumMember(_) => NodeKind::TsEnumMember,
1280      Node::TsExportAssignment(_) => NodeKind::TsExportAssignment,
1281      Node::TsExprWithTypeArgs(_) => NodeKind::TsExprWithTypeArgs,
1282      Node::TsExternalModuleRef(_) => NodeKind::TsExternalModuleRef,
1283      Node::TsFnType(_) => NodeKind::TsFnType,
1284      Node::TsGetterSignature(_) => NodeKind::TsGetterSignature,
1285      Node::TsImportCallOptions(_) => NodeKind::TsImportCallOptions,
1286      Node::TsImportEqualsDecl(_) => NodeKind::TsImportEqualsDecl,
1287      Node::TsImportType(_) => NodeKind::TsImportType,
1288      Node::TsIndexSignature(_) => NodeKind::TsIndexSignature,
1289      Node::TsIndexedAccessType(_) => NodeKind::TsIndexedAccessType,
1290      Node::TsInferType(_) => NodeKind::TsInferType,
1291      Node::TsInstantiation(_) => NodeKind::TsInstantiation,
1292      Node::TsInterfaceBody(_) => NodeKind::TsInterfaceBody,
1293      Node::TsInterfaceDecl(_) => NodeKind::TsInterfaceDecl,
1294      Node::TsIntersectionType(_) => NodeKind::TsIntersectionType,
1295      Node::TsKeywordType(_) => NodeKind::TsKeywordType,
1296      Node::TsLitType(_) => NodeKind::TsLitType,
1297      Node::TsMappedType(_) => NodeKind::TsMappedType,
1298      Node::TsMethodSignature(_) => NodeKind::TsMethodSignature,
1299      Node::TsModuleBlock(_) => NodeKind::TsModuleBlock,
1300      Node::TsModuleDecl(_) => NodeKind::TsModuleDecl,
1301      Node::TsNamespaceDecl(_) => NodeKind::TsNamespaceDecl,
1302      Node::TsNamespaceExportDecl(_) => NodeKind::TsNamespaceExportDecl,
1303      Node::TsNonNullExpr(_) => NodeKind::TsNonNullExpr,
1304      Node::TsOptionalType(_) => NodeKind::TsOptionalType,
1305      Node::TsParamProp(_) => NodeKind::TsParamProp,
1306      Node::TsParenthesizedType(_) => NodeKind::TsParenthesizedType,
1307      Node::TsPropertySignature(_) => NodeKind::TsPropertySignature,
1308      Node::TsQualifiedName(_) => NodeKind::TsQualifiedName,
1309      Node::TsRestType(_) => NodeKind::TsRestType,
1310      Node::TsSatisfiesExpr(_) => NodeKind::TsSatisfiesExpr,
1311      Node::TsSetterSignature(_) => NodeKind::TsSetterSignature,
1312      Node::TsThisType(_) => NodeKind::TsThisType,
1313      Node::TsTplLitType(_) => NodeKind::TsTplLitType,
1314      Node::TsTupleElement(_) => NodeKind::TsTupleElement,
1315      Node::TsTupleType(_) => NodeKind::TsTupleType,
1316      Node::TsTypeAliasDecl(_) => NodeKind::TsTypeAliasDecl,
1317      Node::TsTypeAnn(_) => NodeKind::TsTypeAnn,
1318      Node::TsTypeAssertion(_) => NodeKind::TsTypeAssertion,
1319      Node::TsTypeLit(_) => NodeKind::TsTypeLit,
1320      Node::TsTypeOperator(_) => NodeKind::TsTypeOperator,
1321      Node::TsTypeParam(_) => NodeKind::TsTypeParam,
1322      Node::TsTypeParamDecl(_) => NodeKind::TsTypeParamDecl,
1323      Node::TsTypeParamInstantiation(_) => NodeKind::TsTypeParamInstantiation,
1324      Node::TsTypePredicate(_) => NodeKind::TsTypePredicate,
1325      Node::TsTypeQuery(_) => NodeKind::TsTypeQuery,
1326      Node::TsTypeRef(_) => NodeKind::TsTypeRef,
1327      Node::TsUnionType(_) => NodeKind::TsUnionType,
1328      Node::UnaryExpr(_) => NodeKind::UnaryExpr,
1329      Node::UpdateExpr(_) => NodeKind::UpdateExpr,
1330      Node::UsingDecl(_) => NodeKind::UsingDecl,
1331      Node::VarDecl(_) => NodeKind::VarDecl,
1332      Node::VarDeclarator(_) => NodeKind::VarDeclarator,
1333      Node::WhileStmt(_) => NodeKind::WhileStmt,
1334      Node::WithStmt(_) => NodeKind::WithStmt,
1335      Node::YieldExpr(_) => NodeKind::YieldExpr,
1336    }
1337  }
1338}
1339
1340#[derive(Clone, PartialEq, Debug, Copy)]
1341pub enum NodeKind {
1342  ArrayLit,
1343  ArrayPat,
1344  ArrowExpr,
1345  AssignExpr,
1346  AssignPat,
1347  AssignPatProp,
1348  AssignProp,
1349  AutoAccessor,
1350  AwaitExpr,
1351  BigInt,
1352  BinExpr,
1353  BindingIdent,
1354  BlockStmt,
1355  Bool,
1356  BreakStmt,
1357  CallExpr,
1358  CatchClause,
1359  Class,
1360  ClassDecl,
1361  ClassExpr,
1362  ClassMethod,
1363  ClassProp,
1364  ComputedPropName,
1365  CondExpr,
1366  Constructor,
1367  ContinueStmt,
1368  DebuggerStmt,
1369  Decorator,
1370  DoWhileStmt,
1371  EmptyStmt,
1372  ExportAll,
1373  ExportDecl,
1374  ExportDefaultDecl,
1375  ExportDefaultExpr,
1376  ExportDefaultSpecifier,
1377  ExportNamedSpecifier,
1378  ExportNamespaceSpecifier,
1379  ExprOrSpread,
1380  ExprStmt,
1381  FnDecl,
1382  FnExpr,
1383  ForInStmt,
1384  ForOfStmt,
1385  ForStmt,
1386  Function,
1387  GetterProp,
1388  Ident,
1389  IdentName,
1390  IfStmt,
1391  Import,
1392  ImportDecl,
1393  ImportDefaultSpecifier,
1394  ImportNamedSpecifier,
1395  ImportStarAsSpecifier,
1396  Invalid,
1397  JSXAttr,
1398  JSXClosingElement,
1399  JSXClosingFragment,
1400  JSXElement,
1401  JSXEmptyExpr,
1402  JSXExprContainer,
1403  JSXFragment,
1404  JSXMemberExpr,
1405  JSXNamespacedName,
1406  JSXOpeningElement,
1407  JSXOpeningFragment,
1408  JSXSpreadChild,
1409  JSXText,
1410  KeyValuePatProp,
1411  KeyValueProp,
1412  LabeledStmt,
1413  MemberExpr,
1414  MetaPropExpr,
1415  MethodProp,
1416  Module,
1417  NamedExport,
1418  NewExpr,
1419  Null,
1420  Number,
1421  ObjectLit,
1422  ObjectPat,
1423  OptCall,
1424  OptChainExpr,
1425  Param,
1426  ParenExpr,
1427  PrivateMethod,
1428  PrivateName,
1429  PrivateProp,
1430  Regex,
1431  RestPat,
1432  ReturnStmt,
1433  Script,
1434  SeqExpr,
1435  SetterProp,
1436  SpreadElement,
1437  StaticBlock,
1438  Str,
1439  Super,
1440  SuperPropExpr,
1441  SwitchCase,
1442  SwitchStmt,
1443  TaggedTpl,
1444  ThisExpr,
1445  ThrowStmt,
1446  Tpl,
1447  TplElement,
1448  TryStmt,
1449  TsArrayType,
1450  TsAsExpr,
1451  TsCallSignatureDecl,
1452  TsConditionalType,
1453  TsConstAssertion,
1454  TsConstructSignatureDecl,
1455  TsConstructorType,
1456  TsEnumDecl,
1457  TsEnumMember,
1458  TsExportAssignment,
1459  TsExprWithTypeArgs,
1460  TsExternalModuleRef,
1461  TsFnType,
1462  TsGetterSignature,
1463  TsImportCallOptions,
1464  TsImportEqualsDecl,
1465  TsImportType,
1466  TsIndexSignature,
1467  TsIndexedAccessType,
1468  TsInferType,
1469  TsInstantiation,
1470  TsInterfaceBody,
1471  TsInterfaceDecl,
1472  TsIntersectionType,
1473  TsKeywordType,
1474  TsLitType,
1475  TsMappedType,
1476  TsMethodSignature,
1477  TsModuleBlock,
1478  TsModuleDecl,
1479  TsNamespaceDecl,
1480  TsNamespaceExportDecl,
1481  TsNonNullExpr,
1482  TsOptionalType,
1483  TsParamProp,
1484  TsParenthesizedType,
1485  TsPropertySignature,
1486  TsQualifiedName,
1487  TsRestType,
1488  TsSatisfiesExpr,
1489  TsSetterSignature,
1490  TsThisType,
1491  TsTplLitType,
1492  TsTupleElement,
1493  TsTupleType,
1494  TsTypeAliasDecl,
1495  TsTypeAnn,
1496  TsTypeAssertion,
1497  TsTypeLit,
1498  TsTypeOperator,
1499  TsTypeParam,
1500  TsTypeParamDecl,
1501  TsTypeParamInstantiation,
1502  TsTypePredicate,
1503  TsTypeQuery,
1504  TsTypeRef,
1505  TsUnionType,
1506  UnaryExpr,
1507  UpdateExpr,
1508  UsingDecl,
1509  VarDecl,
1510  VarDeclarator,
1511  WhileStmt,
1512  WithStmt,
1513  YieldExpr,
1514}
1515
1516impl std::fmt::Display for NodeKind {
1517  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1518    write!(f, "{}", match self {
1519      NodeKind::ArrayLit => "ArrayLit",
1520      NodeKind::ArrayPat => "ArrayPat",
1521      NodeKind::ArrowExpr => "ArrowExpr",
1522      NodeKind::AssignExpr => "AssignExpr",
1523      NodeKind::AssignPat => "AssignPat",
1524      NodeKind::AssignPatProp => "AssignPatProp",
1525      NodeKind::AssignProp => "AssignProp",
1526      NodeKind::AutoAccessor => "AutoAccessor",
1527      NodeKind::AwaitExpr => "AwaitExpr",
1528      NodeKind::BigInt => "BigInt",
1529      NodeKind::BinExpr => "BinExpr",
1530      NodeKind::BindingIdent => "BindingIdent",
1531      NodeKind::BlockStmt => "BlockStmt",
1532      NodeKind::Bool => "Bool",
1533      NodeKind::BreakStmt => "BreakStmt",
1534      NodeKind::CallExpr => "CallExpr",
1535      NodeKind::CatchClause => "CatchClause",
1536      NodeKind::Class => "Class",
1537      NodeKind::ClassDecl => "ClassDecl",
1538      NodeKind::ClassExpr => "ClassExpr",
1539      NodeKind::ClassMethod => "ClassMethod",
1540      NodeKind::ClassProp => "ClassProp",
1541      NodeKind::ComputedPropName => "ComputedPropName",
1542      NodeKind::CondExpr => "CondExpr",
1543      NodeKind::Constructor => "Constructor",
1544      NodeKind::ContinueStmt => "ContinueStmt",
1545      NodeKind::DebuggerStmt => "DebuggerStmt",
1546      NodeKind::Decorator => "Decorator",
1547      NodeKind::DoWhileStmt => "DoWhileStmt",
1548      NodeKind::EmptyStmt => "EmptyStmt",
1549      NodeKind::ExportAll => "ExportAll",
1550      NodeKind::ExportDecl => "ExportDecl",
1551      NodeKind::ExportDefaultDecl => "ExportDefaultDecl",
1552      NodeKind::ExportDefaultExpr => "ExportDefaultExpr",
1553      NodeKind::ExportDefaultSpecifier => "ExportDefaultSpecifier",
1554      NodeKind::ExportNamedSpecifier => "ExportNamedSpecifier",
1555      NodeKind::ExportNamespaceSpecifier => "ExportNamespaceSpecifier",
1556      NodeKind::ExprOrSpread => "ExprOrSpread",
1557      NodeKind::ExprStmt => "ExprStmt",
1558      NodeKind::FnDecl => "FnDecl",
1559      NodeKind::FnExpr => "FnExpr",
1560      NodeKind::ForInStmt => "ForInStmt",
1561      NodeKind::ForOfStmt => "ForOfStmt",
1562      NodeKind::ForStmt => "ForStmt",
1563      NodeKind::Function => "Function",
1564      NodeKind::GetterProp => "GetterProp",
1565      NodeKind::Ident => "Ident",
1566      NodeKind::IdentName => "IdentName",
1567      NodeKind::IfStmt => "IfStmt",
1568      NodeKind::Import => "Import",
1569      NodeKind::ImportDecl => "ImportDecl",
1570      NodeKind::ImportDefaultSpecifier => "ImportDefaultSpecifier",
1571      NodeKind::ImportNamedSpecifier => "ImportNamedSpecifier",
1572      NodeKind::ImportStarAsSpecifier => "ImportStarAsSpecifier",
1573      NodeKind::Invalid => "Invalid",
1574      NodeKind::JSXAttr => "JSXAttr",
1575      NodeKind::JSXClosingElement => "JSXClosingElement",
1576      NodeKind::JSXClosingFragment => "JSXClosingFragment",
1577      NodeKind::JSXElement => "JSXElement",
1578      NodeKind::JSXEmptyExpr => "JSXEmptyExpr",
1579      NodeKind::JSXExprContainer => "JSXExprContainer",
1580      NodeKind::JSXFragment => "JSXFragment",
1581      NodeKind::JSXMemberExpr => "JSXMemberExpr",
1582      NodeKind::JSXNamespacedName => "JSXNamespacedName",
1583      NodeKind::JSXOpeningElement => "JSXOpeningElement",
1584      NodeKind::JSXOpeningFragment => "JSXOpeningFragment",
1585      NodeKind::JSXSpreadChild => "JSXSpreadChild",
1586      NodeKind::JSXText => "JSXText",
1587      NodeKind::KeyValuePatProp => "KeyValuePatProp",
1588      NodeKind::KeyValueProp => "KeyValueProp",
1589      NodeKind::LabeledStmt => "LabeledStmt",
1590      NodeKind::MemberExpr => "MemberExpr",
1591      NodeKind::MetaPropExpr => "MetaPropExpr",
1592      NodeKind::MethodProp => "MethodProp",
1593      NodeKind::Module => "Module",
1594      NodeKind::NamedExport => "NamedExport",
1595      NodeKind::NewExpr => "NewExpr",
1596      NodeKind::Null => "Null",
1597      NodeKind::Number => "Number",
1598      NodeKind::ObjectLit => "ObjectLit",
1599      NodeKind::ObjectPat => "ObjectPat",
1600      NodeKind::OptCall => "OptCall",
1601      NodeKind::OptChainExpr => "OptChainExpr",
1602      NodeKind::Param => "Param",
1603      NodeKind::ParenExpr => "ParenExpr",
1604      NodeKind::PrivateMethod => "PrivateMethod",
1605      NodeKind::PrivateName => "PrivateName",
1606      NodeKind::PrivateProp => "PrivateProp",
1607      NodeKind::Regex => "Regex",
1608      NodeKind::RestPat => "RestPat",
1609      NodeKind::ReturnStmt => "ReturnStmt",
1610      NodeKind::Script => "Script",
1611      NodeKind::SeqExpr => "SeqExpr",
1612      NodeKind::SetterProp => "SetterProp",
1613      NodeKind::SpreadElement => "SpreadElement",
1614      NodeKind::StaticBlock => "StaticBlock",
1615      NodeKind::Str => "Str",
1616      NodeKind::Super => "Super",
1617      NodeKind::SuperPropExpr => "SuperPropExpr",
1618      NodeKind::SwitchCase => "SwitchCase",
1619      NodeKind::SwitchStmt => "SwitchStmt",
1620      NodeKind::TaggedTpl => "TaggedTpl",
1621      NodeKind::ThisExpr => "ThisExpr",
1622      NodeKind::ThrowStmt => "ThrowStmt",
1623      NodeKind::Tpl => "Tpl",
1624      NodeKind::TplElement => "TplElement",
1625      NodeKind::TryStmt => "TryStmt",
1626      NodeKind::TsArrayType => "TsArrayType",
1627      NodeKind::TsAsExpr => "TsAsExpr",
1628      NodeKind::TsCallSignatureDecl => "TsCallSignatureDecl",
1629      NodeKind::TsConditionalType => "TsConditionalType",
1630      NodeKind::TsConstAssertion => "TsConstAssertion",
1631      NodeKind::TsConstructSignatureDecl => "TsConstructSignatureDecl",
1632      NodeKind::TsConstructorType => "TsConstructorType",
1633      NodeKind::TsEnumDecl => "TsEnumDecl",
1634      NodeKind::TsEnumMember => "TsEnumMember",
1635      NodeKind::TsExportAssignment => "TsExportAssignment",
1636      NodeKind::TsExprWithTypeArgs => "TsExprWithTypeArgs",
1637      NodeKind::TsExternalModuleRef => "TsExternalModuleRef",
1638      NodeKind::TsFnType => "TsFnType",
1639      NodeKind::TsGetterSignature => "TsGetterSignature",
1640      NodeKind::TsImportCallOptions => "TsImportCallOptions",
1641      NodeKind::TsImportEqualsDecl => "TsImportEqualsDecl",
1642      NodeKind::TsImportType => "TsImportType",
1643      NodeKind::TsIndexSignature => "TsIndexSignature",
1644      NodeKind::TsIndexedAccessType => "TsIndexedAccessType",
1645      NodeKind::TsInferType => "TsInferType",
1646      NodeKind::TsInstantiation => "TsInstantiation",
1647      NodeKind::TsInterfaceBody => "TsInterfaceBody",
1648      NodeKind::TsInterfaceDecl => "TsInterfaceDecl",
1649      NodeKind::TsIntersectionType => "TsIntersectionType",
1650      NodeKind::TsKeywordType => "TsKeywordType",
1651      NodeKind::TsLitType => "TsLitType",
1652      NodeKind::TsMappedType => "TsMappedType",
1653      NodeKind::TsMethodSignature => "TsMethodSignature",
1654      NodeKind::TsModuleBlock => "TsModuleBlock",
1655      NodeKind::TsModuleDecl => "TsModuleDecl",
1656      NodeKind::TsNamespaceDecl => "TsNamespaceDecl",
1657      NodeKind::TsNamespaceExportDecl => "TsNamespaceExportDecl",
1658      NodeKind::TsNonNullExpr => "TsNonNullExpr",
1659      NodeKind::TsOptionalType => "TsOptionalType",
1660      NodeKind::TsParamProp => "TsParamProp",
1661      NodeKind::TsParenthesizedType => "TsParenthesizedType",
1662      NodeKind::TsPropertySignature => "TsPropertySignature",
1663      NodeKind::TsQualifiedName => "TsQualifiedName",
1664      NodeKind::TsRestType => "TsRestType",
1665      NodeKind::TsSatisfiesExpr => "TsSatisfiesExpr",
1666      NodeKind::TsSetterSignature => "TsSetterSignature",
1667      NodeKind::TsThisType => "TsThisType",
1668      NodeKind::TsTplLitType => "TsTplLitType",
1669      NodeKind::TsTupleElement => "TsTupleElement",
1670      NodeKind::TsTupleType => "TsTupleType",
1671      NodeKind::TsTypeAliasDecl => "TsTypeAliasDecl",
1672      NodeKind::TsTypeAnn => "TsTypeAnn",
1673      NodeKind::TsTypeAssertion => "TsTypeAssertion",
1674      NodeKind::TsTypeLit => "TsTypeLit",
1675      NodeKind::TsTypeOperator => "TsTypeOperator",
1676      NodeKind::TsTypeParam => "TsTypeParam",
1677      NodeKind::TsTypeParamDecl => "TsTypeParamDecl",
1678      NodeKind::TsTypeParamInstantiation => "TsTypeParamInstantiation",
1679      NodeKind::TsTypePredicate => "TsTypePredicate",
1680      NodeKind::TsTypeQuery => "TsTypeQuery",
1681      NodeKind::TsTypeRef => "TsTypeRef",
1682      NodeKind::TsUnionType => "TsUnionType",
1683      NodeKind::UnaryExpr => "UnaryExpr",
1684      NodeKind::UpdateExpr => "UpdateExpr",
1685      NodeKind::UsingDecl => "UsingDecl",
1686      NodeKind::VarDecl => "VarDecl",
1687      NodeKind::VarDeclarator => "VarDeclarator",
1688      NodeKind::WhileStmt => "WhileStmt",
1689      NodeKind::WithStmt => "WithStmt",
1690      NodeKind::YieldExpr => "YieldExpr",
1691    })
1692  }
1693}
1694
1695#[derive(Copy, Clone)]
1696pub enum AssignTarget<'a> {
1697  Simple(SimpleAssignTarget<'a>),
1698  Pat(AssignTargetPat<'a>),
1699}
1700
1701impl<'a> AssignTarget<'a> {
1702  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
1703    T::to(&self.into())
1704  }
1705
1706  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
1707    let node: Node<'a> = self.into();
1708    if let Some(result) = T::to(&node) {
1709      result
1710    } else {
1711      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
1712    }
1713  }
1714
1715  pub fn is<T: CastableNode<'a>>(&self) -> bool {
1716    self.kind() == T::kind()
1717  }
1718}
1719
1720impl<'a> SourceRanged for AssignTarget<'a> {
1721  fn start(&self) -> SourcePos {
1722    match self {
1723      AssignTarget::Simple(node) => node.start(),
1724      AssignTarget::Pat(node) => node.start(),
1725    }
1726  }
1727  fn end(&self) -> SourcePos {
1728    match self {
1729      AssignTarget::Simple(node) => node.end(),
1730      AssignTarget::Pat(node) => node.end(),
1731    }
1732  }
1733}
1734
1735impl<'a> NodeTrait<'a> for AssignTarget<'a> {
1736  fn parent(&self) -> Option<Node<'a>> {
1737    match self {
1738      AssignTarget::Simple(node) => NodeTrait::parent(node),
1739      AssignTarget::Pat(node) => NodeTrait::parent(node),
1740    }
1741  }
1742
1743  fn children(&self) -> Vec<Node<'a>> {
1744    match self {
1745      AssignTarget::Simple(node) => node.children(),
1746      AssignTarget::Pat(node) => node.children(),
1747    }
1748  }
1749
1750  fn as_node(&self) -> Node<'a> {
1751    match self {
1752      AssignTarget::Simple(node) => node.as_node(),
1753      AssignTarget::Pat(node) => node.as_node(),
1754    }
1755  }
1756
1757  fn kind(&self) -> NodeKind {
1758    match self {
1759      AssignTarget::Simple(node) => node.kind(),
1760      AssignTarget::Pat(node) => node.kind(),
1761    }
1762  }
1763}
1764
1765impl<'a> From<&AssignTarget<'a>> for Node<'a> {
1766  fn from(node: &AssignTarget<'a>) -> Node<'a> {
1767    match node {
1768      AssignTarget::Simple(node) => node.into(),
1769      AssignTarget::Pat(node) => node.into(),
1770    }
1771  }
1772}
1773
1774impl<'a> From<AssignTarget<'a>> for Node<'a> {
1775  fn from(node: AssignTarget<'a>) -> Node<'a> {
1776    match node {
1777      AssignTarget::Simple(node) => node.into(),
1778      AssignTarget::Pat(node) => node.into(),
1779    }
1780  }
1781}
1782
1783fn get_view_for_assign_target<'a>(inner: &'a swc_ast::AssignTarget, bump: &'a Bump) -> AssignTarget<'a> {
1784  match inner {
1785    swc_ast::AssignTarget::Simple(value) => AssignTarget::Simple(get_view_for_simple_assign_target(value, bump)),
1786    swc_ast::AssignTarget::Pat(value) => AssignTarget::Pat(get_view_for_assign_target_pat(value, bump)),
1787  }
1788}
1789
1790fn set_parent_for_assign_target<'a>(node: &AssignTarget<'a>, parent: Node<'a>) {
1791  match node {
1792    AssignTarget::Simple(value) => set_parent_for_simple_assign_target(value, parent),
1793    AssignTarget::Pat(value) => set_parent_for_assign_target_pat(value, parent),
1794  }
1795}
1796
1797#[derive(Copy, Clone)]
1798pub enum AssignTargetPat<'a> {
1799  Array(&'a ArrayPat<'a>),
1800  Object(&'a ObjectPat<'a>),
1801  Invalid(&'a Invalid<'a>),
1802}
1803
1804impl<'a> AssignTargetPat<'a> {
1805  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
1806    T::to(&self.into())
1807  }
1808
1809  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
1810    let node: Node<'a> = self.into();
1811    if let Some(result) = T::to(&node) {
1812      result
1813    } else {
1814      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
1815    }
1816  }
1817
1818  pub fn is<T: CastableNode<'a>>(&self) -> bool {
1819    self.kind() == T::kind()
1820  }
1821  pub fn parent(&self) -> Node<'a> {
1822    NodeTrait::parent(self).unwrap()
1823  }
1824}
1825
1826impl<'a> SourceRanged for AssignTargetPat<'a> {
1827  fn start(&self) -> SourcePos {
1828    match self {
1829      AssignTargetPat::Array(node) => node.start(),
1830      AssignTargetPat::Object(node) => node.start(),
1831      AssignTargetPat::Invalid(node) => node.start(),
1832    }
1833  }
1834  fn end(&self) -> SourcePos {
1835    match self {
1836      AssignTargetPat::Array(node) => node.end(),
1837      AssignTargetPat::Object(node) => node.end(),
1838      AssignTargetPat::Invalid(node) => node.end(),
1839    }
1840  }
1841}
1842
1843impl<'a> NodeTrait<'a> for AssignTargetPat<'a> {
1844  fn parent(&self) -> Option<Node<'a>> {
1845    match self {
1846      AssignTargetPat::Array(node) => NodeTrait::parent(*node),
1847      AssignTargetPat::Object(node) => NodeTrait::parent(*node),
1848      AssignTargetPat::Invalid(node) => NodeTrait::parent(*node),
1849    }
1850  }
1851
1852  fn children(&self) -> Vec<Node<'a>> {
1853    match self {
1854      AssignTargetPat::Array(node) => node.children(),
1855      AssignTargetPat::Object(node) => node.children(),
1856      AssignTargetPat::Invalid(node) => node.children(),
1857    }
1858  }
1859
1860  fn as_node(&self) -> Node<'a> {
1861    match self {
1862      AssignTargetPat::Array(node) => node.as_node(),
1863      AssignTargetPat::Object(node) => node.as_node(),
1864      AssignTargetPat::Invalid(node) => node.as_node(),
1865    }
1866  }
1867
1868  fn kind(&self) -> NodeKind {
1869    match self {
1870      AssignTargetPat::Array(_) => NodeKind::ArrayPat,
1871      AssignTargetPat::Object(_) => NodeKind::ObjectPat,
1872      AssignTargetPat::Invalid(_) => NodeKind::Invalid,
1873    }
1874  }
1875}
1876
1877impl<'a> From<&AssignTargetPat<'a>> for Node<'a> {
1878  fn from(node: &AssignTargetPat<'a>) -> Node<'a> {
1879    match node {
1880      AssignTargetPat::Array(node) => (*node).into(),
1881      AssignTargetPat::Object(node) => (*node).into(),
1882      AssignTargetPat::Invalid(node) => (*node).into(),
1883    }
1884  }
1885}
1886
1887impl<'a> From<AssignTargetPat<'a>> for Node<'a> {
1888  fn from(node: AssignTargetPat<'a>) -> Node<'a> {
1889    match node {
1890      AssignTargetPat::Array(node) => node.into(),
1891      AssignTargetPat::Object(node) => node.into(),
1892      AssignTargetPat::Invalid(node) => node.into(),
1893    }
1894  }
1895}
1896
1897fn get_view_for_assign_target_pat<'a>(inner: &'a swc_ast::AssignTargetPat, bump: &'a Bump) -> AssignTargetPat<'a> {
1898  match inner {
1899    swc_ast::AssignTargetPat::Array(value) => AssignTargetPat::Array(get_view_for_array_pat(value, bump)),
1900    swc_ast::AssignTargetPat::Object(value) => AssignTargetPat::Object(get_view_for_object_pat(value, bump)),
1901    swc_ast::AssignTargetPat::Invalid(value) => AssignTargetPat::Invalid(get_view_for_invalid(value, bump)),
1902  }
1903}
1904
1905fn set_parent_for_assign_target_pat<'a>(node: &AssignTargetPat<'a>, parent: Node<'a>) {
1906  match node {
1907    AssignTargetPat::Array(value) => set_parent_for_array_pat(value, parent),
1908    AssignTargetPat::Object(value) => set_parent_for_object_pat(value, parent),
1909    AssignTargetPat::Invalid(value) => set_parent_for_invalid(value, parent),
1910  }
1911}
1912
1913#[derive(Copy, Clone)]
1914pub enum BlockStmtOrExpr<'a> {
1915  BlockStmt(&'a BlockStmt<'a>),
1916  Expr(Expr<'a>),
1917}
1918
1919impl<'a> BlockStmtOrExpr<'a> {
1920  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
1921    T::to(&self.into())
1922  }
1923
1924  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
1925    let node: Node<'a> = self.into();
1926    if let Some(result) = T::to(&node) {
1927      result
1928    } else {
1929      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
1930    }
1931  }
1932
1933  pub fn is<T: CastableNode<'a>>(&self) -> bool {
1934    self.kind() == T::kind()
1935  }
1936}
1937
1938impl<'a> SourceRanged for BlockStmtOrExpr<'a> {
1939  fn start(&self) -> SourcePos {
1940    match self {
1941      BlockStmtOrExpr::BlockStmt(node) => node.start(),
1942      BlockStmtOrExpr::Expr(node) => node.start(),
1943    }
1944  }
1945  fn end(&self) -> SourcePos {
1946    match self {
1947      BlockStmtOrExpr::BlockStmt(node) => node.end(),
1948      BlockStmtOrExpr::Expr(node) => node.end(),
1949    }
1950  }
1951}
1952
1953impl<'a> NodeTrait<'a> for BlockStmtOrExpr<'a> {
1954  fn parent(&self) -> Option<Node<'a>> {
1955    match self {
1956      BlockStmtOrExpr::BlockStmt(node) => NodeTrait::parent(*node),
1957      BlockStmtOrExpr::Expr(node) => NodeTrait::parent(node),
1958    }
1959  }
1960
1961  fn children(&self) -> Vec<Node<'a>> {
1962    match self {
1963      BlockStmtOrExpr::BlockStmt(node) => node.children(),
1964      BlockStmtOrExpr::Expr(node) => node.children(),
1965    }
1966  }
1967
1968  fn as_node(&self) -> Node<'a> {
1969    match self {
1970      BlockStmtOrExpr::BlockStmt(node) => node.as_node(),
1971      BlockStmtOrExpr::Expr(node) => node.as_node(),
1972    }
1973  }
1974
1975  fn kind(&self) -> NodeKind {
1976    match self {
1977      BlockStmtOrExpr::BlockStmt(_) => NodeKind::BlockStmt,
1978      BlockStmtOrExpr::Expr(node) => node.kind(),
1979    }
1980  }
1981}
1982
1983impl<'a> From<&BlockStmtOrExpr<'a>> for Node<'a> {
1984  fn from(node: &BlockStmtOrExpr<'a>) -> Node<'a> {
1985    match node {
1986      BlockStmtOrExpr::BlockStmt(node) => (*node).into(),
1987      BlockStmtOrExpr::Expr(node) => node.into(),
1988    }
1989  }
1990}
1991
1992impl<'a> From<BlockStmtOrExpr<'a>> for Node<'a> {
1993  fn from(node: BlockStmtOrExpr<'a>) -> Node<'a> {
1994    match node {
1995      BlockStmtOrExpr::BlockStmt(node) => node.into(),
1996      BlockStmtOrExpr::Expr(node) => node.into(),
1997    }
1998  }
1999}
2000
2001fn get_view_for_block_stmt_or_expr<'a>(inner: &'a swc_ast::BlockStmtOrExpr, bump: &'a Bump) -> BlockStmtOrExpr<'a> {
2002  match inner {
2003    swc_ast::BlockStmtOrExpr::BlockStmt(value) => BlockStmtOrExpr::BlockStmt(get_view_for_block_stmt(value, bump)),
2004    swc_ast::BlockStmtOrExpr::Expr(value) => BlockStmtOrExpr::Expr(get_view_for_expr(value, bump)),
2005  }
2006}
2007
2008fn set_parent_for_block_stmt_or_expr<'a>(node: &BlockStmtOrExpr<'a>, parent: Node<'a>) {
2009  match node {
2010    BlockStmtOrExpr::BlockStmt(value) => set_parent_for_block_stmt(value, parent),
2011    BlockStmtOrExpr::Expr(value) => set_parent_for_expr(value, parent),
2012  }
2013}
2014
2015#[derive(Copy, Clone)]
2016pub enum Callee<'a> {
2017  Super(&'a Super<'a>),
2018  Import(&'a Import<'a>),
2019  Expr(Expr<'a>),
2020}
2021
2022impl<'a> Callee<'a> {
2023  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
2024    T::to(&self.into())
2025  }
2026
2027  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
2028    let node: Node<'a> = self.into();
2029    if let Some(result) = T::to(&node) {
2030      result
2031    } else {
2032      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
2033    }
2034  }
2035
2036  pub fn is<T: CastableNode<'a>>(&self) -> bool {
2037    self.kind() == T::kind()
2038  }
2039}
2040
2041impl<'a> SourceRanged for Callee<'a> {
2042  fn start(&self) -> SourcePos {
2043    match self {
2044      Callee::Super(node) => node.start(),
2045      Callee::Import(node) => node.start(),
2046      Callee::Expr(node) => node.start(),
2047    }
2048  }
2049  fn end(&self) -> SourcePos {
2050    match self {
2051      Callee::Super(node) => node.end(),
2052      Callee::Import(node) => node.end(),
2053      Callee::Expr(node) => node.end(),
2054    }
2055  }
2056}
2057
2058impl<'a> NodeTrait<'a> for Callee<'a> {
2059  fn parent(&self) -> Option<Node<'a>> {
2060    match self {
2061      Callee::Super(node) => NodeTrait::parent(*node),
2062      Callee::Import(node) => NodeTrait::parent(*node),
2063      Callee::Expr(node) => NodeTrait::parent(node),
2064    }
2065  }
2066
2067  fn children(&self) -> Vec<Node<'a>> {
2068    match self {
2069      Callee::Super(node) => node.children(),
2070      Callee::Import(node) => node.children(),
2071      Callee::Expr(node) => node.children(),
2072    }
2073  }
2074
2075  fn as_node(&self) -> Node<'a> {
2076    match self {
2077      Callee::Super(node) => node.as_node(),
2078      Callee::Import(node) => node.as_node(),
2079      Callee::Expr(node) => node.as_node(),
2080    }
2081  }
2082
2083  fn kind(&self) -> NodeKind {
2084    match self {
2085      Callee::Super(_) => NodeKind::Super,
2086      Callee::Import(_) => NodeKind::Import,
2087      Callee::Expr(node) => node.kind(),
2088    }
2089  }
2090}
2091
2092impl<'a> From<&Callee<'a>> for Node<'a> {
2093  fn from(node: &Callee<'a>) -> Node<'a> {
2094    match node {
2095      Callee::Super(node) => (*node).into(),
2096      Callee::Import(node) => (*node).into(),
2097      Callee::Expr(node) => node.into(),
2098    }
2099  }
2100}
2101
2102impl<'a> From<Callee<'a>> for Node<'a> {
2103  fn from(node: Callee<'a>) -> Node<'a> {
2104    match node {
2105      Callee::Super(node) => node.into(),
2106      Callee::Import(node) => node.into(),
2107      Callee::Expr(node) => node.into(),
2108    }
2109  }
2110}
2111
2112fn get_view_for_callee<'a>(inner: &'a swc_ast::Callee, bump: &'a Bump) -> Callee<'a> {
2113  match inner {
2114    swc_ast::Callee::Super(value) => Callee::Super(get_view_for_super(value, bump)),
2115    swc_ast::Callee::Import(value) => Callee::Import(get_view_for_import(value, bump)),
2116    swc_ast::Callee::Expr(value) => Callee::Expr(get_view_for_expr(value, bump)),
2117  }
2118}
2119
2120fn set_parent_for_callee<'a>(node: &Callee<'a>, parent: Node<'a>) {
2121  match node {
2122    Callee::Super(value) => set_parent_for_super(value, parent),
2123    Callee::Import(value) => set_parent_for_import(value, parent),
2124    Callee::Expr(value) => set_parent_for_expr(value, parent),
2125  }
2126}
2127
2128#[derive(Copy, Clone)]
2129pub enum ClassMember<'a> {
2130  Constructor(&'a Constructor<'a>),
2131  /// `es2015`
2132  Method(&'a ClassMethod<'a>),
2133  PrivateMethod(&'a PrivateMethod<'a>),
2134  /// stage 0 / Typescript
2135  ClassProp(&'a ClassProp<'a>),
2136  PrivateProp(&'a PrivateProp<'a>),
2137  TsIndexSignature(&'a TsIndexSignature<'a>),
2138  Empty(&'a EmptyStmt<'a>),
2139  /// Stage 3
2140  StaticBlock(&'a StaticBlock<'a>),
2141  /// Stage 3
2142  AutoAccessor(&'a AutoAccessor<'a>),
2143}
2144
2145impl<'a> ClassMember<'a> {
2146  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
2147    T::to(&self.into())
2148  }
2149
2150  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
2151    let node: Node<'a> = self.into();
2152    if let Some(result) = T::to(&node) {
2153      result
2154    } else {
2155      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
2156    }
2157  }
2158
2159  pub fn is<T: CastableNode<'a>>(&self) -> bool {
2160    self.kind() == T::kind()
2161  }
2162  pub fn parent(&self) -> Node<'a> {
2163    NodeTrait::parent(self).unwrap()
2164  }
2165}
2166
2167impl<'a> SourceRanged for ClassMember<'a> {
2168  fn start(&self) -> SourcePos {
2169    match self {
2170      ClassMember::Constructor(node) => node.start(),
2171      ClassMember::Method(node) => node.start(),
2172      ClassMember::PrivateMethod(node) => node.start(),
2173      ClassMember::ClassProp(node) => node.start(),
2174      ClassMember::PrivateProp(node) => node.start(),
2175      ClassMember::TsIndexSignature(node) => node.start(),
2176      ClassMember::Empty(node) => node.start(),
2177      ClassMember::StaticBlock(node) => node.start(),
2178      ClassMember::AutoAccessor(node) => node.start(),
2179    }
2180  }
2181  fn end(&self) -> SourcePos {
2182    match self {
2183      ClassMember::Constructor(node) => node.end(),
2184      ClassMember::Method(node) => node.end(),
2185      ClassMember::PrivateMethod(node) => node.end(),
2186      ClassMember::ClassProp(node) => node.end(),
2187      ClassMember::PrivateProp(node) => node.end(),
2188      ClassMember::TsIndexSignature(node) => node.end(),
2189      ClassMember::Empty(node) => node.end(),
2190      ClassMember::StaticBlock(node) => node.end(),
2191      ClassMember::AutoAccessor(node) => node.end(),
2192    }
2193  }
2194}
2195
2196impl<'a> NodeTrait<'a> for ClassMember<'a> {
2197  fn parent(&self) -> Option<Node<'a>> {
2198    match self {
2199      ClassMember::Constructor(node) => NodeTrait::parent(*node),
2200      ClassMember::Method(node) => NodeTrait::parent(*node),
2201      ClassMember::PrivateMethod(node) => NodeTrait::parent(*node),
2202      ClassMember::ClassProp(node) => NodeTrait::parent(*node),
2203      ClassMember::PrivateProp(node) => NodeTrait::parent(*node),
2204      ClassMember::TsIndexSignature(node) => NodeTrait::parent(*node),
2205      ClassMember::Empty(node) => NodeTrait::parent(*node),
2206      ClassMember::StaticBlock(node) => NodeTrait::parent(*node),
2207      ClassMember::AutoAccessor(node) => NodeTrait::parent(*node),
2208    }
2209  }
2210
2211  fn children(&self) -> Vec<Node<'a>> {
2212    match self {
2213      ClassMember::Constructor(node) => node.children(),
2214      ClassMember::Method(node) => node.children(),
2215      ClassMember::PrivateMethod(node) => node.children(),
2216      ClassMember::ClassProp(node) => node.children(),
2217      ClassMember::PrivateProp(node) => node.children(),
2218      ClassMember::TsIndexSignature(node) => node.children(),
2219      ClassMember::Empty(node) => node.children(),
2220      ClassMember::StaticBlock(node) => node.children(),
2221      ClassMember::AutoAccessor(node) => node.children(),
2222    }
2223  }
2224
2225  fn as_node(&self) -> Node<'a> {
2226    match self {
2227      ClassMember::Constructor(node) => node.as_node(),
2228      ClassMember::Method(node) => node.as_node(),
2229      ClassMember::PrivateMethod(node) => node.as_node(),
2230      ClassMember::ClassProp(node) => node.as_node(),
2231      ClassMember::PrivateProp(node) => node.as_node(),
2232      ClassMember::TsIndexSignature(node) => node.as_node(),
2233      ClassMember::Empty(node) => node.as_node(),
2234      ClassMember::StaticBlock(node) => node.as_node(),
2235      ClassMember::AutoAccessor(node) => node.as_node(),
2236    }
2237  }
2238
2239  fn kind(&self) -> NodeKind {
2240    match self {
2241      ClassMember::Constructor(_) => NodeKind::Constructor,
2242      ClassMember::Method(_) => NodeKind::ClassMethod,
2243      ClassMember::PrivateMethod(_) => NodeKind::PrivateMethod,
2244      ClassMember::ClassProp(_) => NodeKind::ClassProp,
2245      ClassMember::PrivateProp(_) => NodeKind::PrivateProp,
2246      ClassMember::TsIndexSignature(_) => NodeKind::TsIndexSignature,
2247      ClassMember::Empty(_) => NodeKind::EmptyStmt,
2248      ClassMember::StaticBlock(_) => NodeKind::StaticBlock,
2249      ClassMember::AutoAccessor(_) => NodeKind::AutoAccessor,
2250    }
2251  }
2252}
2253
2254impl<'a> From<&ClassMember<'a>> for Node<'a> {
2255  fn from(node: &ClassMember<'a>) -> Node<'a> {
2256    match node {
2257      ClassMember::Constructor(node) => (*node).into(),
2258      ClassMember::Method(node) => (*node).into(),
2259      ClassMember::PrivateMethod(node) => (*node).into(),
2260      ClassMember::ClassProp(node) => (*node).into(),
2261      ClassMember::PrivateProp(node) => (*node).into(),
2262      ClassMember::TsIndexSignature(node) => (*node).into(),
2263      ClassMember::Empty(node) => (*node).into(),
2264      ClassMember::StaticBlock(node) => (*node).into(),
2265      ClassMember::AutoAccessor(node) => (*node).into(),
2266    }
2267  }
2268}
2269
2270impl<'a> From<ClassMember<'a>> for Node<'a> {
2271  fn from(node: ClassMember<'a>) -> Node<'a> {
2272    match node {
2273      ClassMember::Constructor(node) => node.into(),
2274      ClassMember::Method(node) => node.into(),
2275      ClassMember::PrivateMethod(node) => node.into(),
2276      ClassMember::ClassProp(node) => node.into(),
2277      ClassMember::PrivateProp(node) => node.into(),
2278      ClassMember::TsIndexSignature(node) => node.into(),
2279      ClassMember::Empty(node) => node.into(),
2280      ClassMember::StaticBlock(node) => node.into(),
2281      ClassMember::AutoAccessor(node) => node.into(),
2282    }
2283  }
2284}
2285
2286fn get_view_for_class_member<'a>(inner: &'a swc_ast::ClassMember, bump: &'a Bump) -> ClassMember<'a> {
2287  match inner {
2288    swc_ast::ClassMember::Constructor(value) => ClassMember::Constructor(get_view_for_constructor(value, bump)),
2289    swc_ast::ClassMember::Method(value) => ClassMember::Method(get_view_for_class_method(value, bump)),
2290    swc_ast::ClassMember::PrivateMethod(value) => ClassMember::PrivateMethod(get_view_for_private_method(value, bump)),
2291    swc_ast::ClassMember::ClassProp(value) => ClassMember::ClassProp(get_view_for_class_prop(value, bump)),
2292    swc_ast::ClassMember::PrivateProp(value) => ClassMember::PrivateProp(get_view_for_private_prop(value, bump)),
2293    swc_ast::ClassMember::TsIndexSignature(value) => ClassMember::TsIndexSignature(get_view_for_ts_index_signature(value, bump)),
2294    swc_ast::ClassMember::Empty(value) => ClassMember::Empty(get_view_for_empty_stmt(value, bump)),
2295    swc_ast::ClassMember::StaticBlock(value) => ClassMember::StaticBlock(get_view_for_static_block(value, bump)),
2296    swc_ast::ClassMember::AutoAccessor(value) => ClassMember::AutoAccessor(get_view_for_auto_accessor(value, bump)),
2297  }
2298}
2299
2300fn set_parent_for_class_member<'a>(node: &ClassMember<'a>, parent: Node<'a>) {
2301  match node {
2302    ClassMember::Constructor(value) => set_parent_for_constructor(value, parent),
2303    ClassMember::Method(value) => set_parent_for_class_method(value, parent),
2304    ClassMember::PrivateMethod(value) => set_parent_for_private_method(value, parent),
2305    ClassMember::ClassProp(value) => set_parent_for_class_prop(value, parent),
2306    ClassMember::PrivateProp(value) => set_parent_for_private_prop(value, parent),
2307    ClassMember::TsIndexSignature(value) => set_parent_for_ts_index_signature(value, parent),
2308    ClassMember::Empty(value) => set_parent_for_empty_stmt(value, parent),
2309    ClassMember::StaticBlock(value) => set_parent_for_static_block(value, parent),
2310    ClassMember::AutoAccessor(value) => set_parent_for_auto_accessor(value, parent),
2311  }
2312}
2313
2314#[derive(Copy, Clone)]
2315pub enum Decl<'a> {
2316  Class(&'a ClassDecl<'a>),
2317  Fn(&'a FnDecl<'a>),
2318  Var(&'a VarDecl<'a>),
2319  Using(&'a UsingDecl<'a>),
2320  TsInterface(&'a TsInterfaceDecl<'a>),
2321  TsTypeAlias(&'a TsTypeAliasDecl<'a>),
2322  TsEnum(&'a TsEnumDecl<'a>),
2323  TsModule(&'a TsModuleDecl<'a>),
2324}
2325
2326impl<'a> Decl<'a> {
2327  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
2328    T::to(&self.into())
2329  }
2330
2331  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
2332    let node: Node<'a> = self.into();
2333    if let Some(result) = T::to(&node) {
2334      result
2335    } else {
2336      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
2337    }
2338  }
2339
2340  pub fn is<T: CastableNode<'a>>(&self) -> bool {
2341    self.kind() == T::kind()
2342  }
2343  pub fn parent(&self) -> Node<'a> {
2344    NodeTrait::parent(self).unwrap()
2345  }
2346}
2347
2348impl<'a> SourceRanged for Decl<'a> {
2349  fn start(&self) -> SourcePos {
2350    match self {
2351      Decl::Class(node) => node.start(),
2352      Decl::Fn(node) => node.start(),
2353      Decl::Var(node) => node.start(),
2354      Decl::Using(node) => node.start(),
2355      Decl::TsInterface(node) => node.start(),
2356      Decl::TsTypeAlias(node) => node.start(),
2357      Decl::TsEnum(node) => node.start(),
2358      Decl::TsModule(node) => node.start(),
2359    }
2360  }
2361  fn end(&self) -> SourcePos {
2362    match self {
2363      Decl::Class(node) => node.end(),
2364      Decl::Fn(node) => node.end(),
2365      Decl::Var(node) => node.end(),
2366      Decl::Using(node) => node.end(),
2367      Decl::TsInterface(node) => node.end(),
2368      Decl::TsTypeAlias(node) => node.end(),
2369      Decl::TsEnum(node) => node.end(),
2370      Decl::TsModule(node) => node.end(),
2371    }
2372  }
2373}
2374
2375impl<'a> NodeTrait<'a> for Decl<'a> {
2376  fn parent(&self) -> Option<Node<'a>> {
2377    match self {
2378      Decl::Class(node) => NodeTrait::parent(*node),
2379      Decl::Fn(node) => NodeTrait::parent(*node),
2380      Decl::Var(node) => NodeTrait::parent(*node),
2381      Decl::Using(node) => NodeTrait::parent(*node),
2382      Decl::TsInterface(node) => NodeTrait::parent(*node),
2383      Decl::TsTypeAlias(node) => NodeTrait::parent(*node),
2384      Decl::TsEnum(node) => NodeTrait::parent(*node),
2385      Decl::TsModule(node) => NodeTrait::parent(*node),
2386    }
2387  }
2388
2389  fn children(&self) -> Vec<Node<'a>> {
2390    match self {
2391      Decl::Class(node) => node.children(),
2392      Decl::Fn(node) => node.children(),
2393      Decl::Var(node) => node.children(),
2394      Decl::Using(node) => node.children(),
2395      Decl::TsInterface(node) => node.children(),
2396      Decl::TsTypeAlias(node) => node.children(),
2397      Decl::TsEnum(node) => node.children(),
2398      Decl::TsModule(node) => node.children(),
2399    }
2400  }
2401
2402  fn as_node(&self) -> Node<'a> {
2403    match self {
2404      Decl::Class(node) => node.as_node(),
2405      Decl::Fn(node) => node.as_node(),
2406      Decl::Var(node) => node.as_node(),
2407      Decl::Using(node) => node.as_node(),
2408      Decl::TsInterface(node) => node.as_node(),
2409      Decl::TsTypeAlias(node) => node.as_node(),
2410      Decl::TsEnum(node) => node.as_node(),
2411      Decl::TsModule(node) => node.as_node(),
2412    }
2413  }
2414
2415  fn kind(&self) -> NodeKind {
2416    match self {
2417      Decl::Class(_) => NodeKind::ClassDecl,
2418      Decl::Fn(_) => NodeKind::FnDecl,
2419      Decl::Var(_) => NodeKind::VarDecl,
2420      Decl::Using(_) => NodeKind::UsingDecl,
2421      Decl::TsInterface(_) => NodeKind::TsInterfaceDecl,
2422      Decl::TsTypeAlias(_) => NodeKind::TsTypeAliasDecl,
2423      Decl::TsEnum(_) => NodeKind::TsEnumDecl,
2424      Decl::TsModule(_) => NodeKind::TsModuleDecl,
2425    }
2426  }
2427}
2428
2429impl<'a> From<&Decl<'a>> for Node<'a> {
2430  fn from(node: &Decl<'a>) -> Node<'a> {
2431    match node {
2432      Decl::Class(node) => (*node).into(),
2433      Decl::Fn(node) => (*node).into(),
2434      Decl::Var(node) => (*node).into(),
2435      Decl::Using(node) => (*node).into(),
2436      Decl::TsInterface(node) => (*node).into(),
2437      Decl::TsTypeAlias(node) => (*node).into(),
2438      Decl::TsEnum(node) => (*node).into(),
2439      Decl::TsModule(node) => (*node).into(),
2440    }
2441  }
2442}
2443
2444impl<'a> From<Decl<'a>> for Node<'a> {
2445  fn from(node: Decl<'a>) -> Node<'a> {
2446    match node {
2447      Decl::Class(node) => node.into(),
2448      Decl::Fn(node) => node.into(),
2449      Decl::Var(node) => node.into(),
2450      Decl::Using(node) => node.into(),
2451      Decl::TsInterface(node) => node.into(),
2452      Decl::TsTypeAlias(node) => node.into(),
2453      Decl::TsEnum(node) => node.into(),
2454      Decl::TsModule(node) => node.into(),
2455    }
2456  }
2457}
2458
2459fn get_view_for_decl<'a>(inner: &'a swc_ast::Decl, bump: &'a Bump) -> Decl<'a> {
2460  match inner {
2461    swc_ast::Decl::Class(value) => Decl::Class(get_view_for_class_decl(value, bump)),
2462    swc_ast::Decl::Fn(value) => Decl::Fn(get_view_for_fn_decl(value, bump)),
2463    swc_ast::Decl::Var(value) => Decl::Var(get_view_for_var_decl(value, bump)),
2464    swc_ast::Decl::Using(value) => Decl::Using(get_view_for_using_decl(value, bump)),
2465    swc_ast::Decl::TsInterface(value) => Decl::TsInterface(get_view_for_ts_interface_decl(value, bump)),
2466    swc_ast::Decl::TsTypeAlias(value) => Decl::TsTypeAlias(get_view_for_ts_type_alias_decl(value, bump)),
2467    swc_ast::Decl::TsEnum(value) => Decl::TsEnum(get_view_for_ts_enum_decl(value, bump)),
2468    swc_ast::Decl::TsModule(value) => Decl::TsModule(get_view_for_ts_module_decl(value, bump)),
2469  }
2470}
2471
2472fn set_parent_for_decl<'a>(node: &Decl<'a>, parent: Node<'a>) {
2473  match node {
2474    Decl::Class(value) => set_parent_for_class_decl(value, parent),
2475    Decl::Fn(value) => set_parent_for_fn_decl(value, parent),
2476    Decl::Var(value) => set_parent_for_var_decl(value, parent),
2477    Decl::Using(value) => set_parent_for_using_decl(value, parent),
2478    Decl::TsInterface(value) => set_parent_for_ts_interface_decl(value, parent),
2479    Decl::TsTypeAlias(value) => set_parent_for_ts_type_alias_decl(value, parent),
2480    Decl::TsEnum(value) => set_parent_for_ts_enum_decl(value, parent),
2481    Decl::TsModule(value) => set_parent_for_ts_module_decl(value, parent),
2482  }
2483}
2484
2485#[derive(Copy, Clone)]
2486pub enum DefaultDecl<'a> {
2487  Class(&'a ClassExpr<'a>),
2488  Fn(&'a FnExpr<'a>),
2489  TsInterfaceDecl(&'a TsInterfaceDecl<'a>),
2490}
2491
2492impl<'a> DefaultDecl<'a> {
2493  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
2494    T::to(&self.into())
2495  }
2496
2497  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
2498    let node: Node<'a> = self.into();
2499    if let Some(result) = T::to(&node) {
2500      result
2501    } else {
2502      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
2503    }
2504  }
2505
2506  pub fn is<T: CastableNode<'a>>(&self) -> bool {
2507    self.kind() == T::kind()
2508  }
2509  pub fn parent(&self) -> Node<'a> {
2510    NodeTrait::parent(self).unwrap()
2511  }
2512}
2513
2514impl<'a> SourceRanged for DefaultDecl<'a> {
2515  fn start(&self) -> SourcePos {
2516    match self {
2517      DefaultDecl::Class(node) => node.start(),
2518      DefaultDecl::Fn(node) => node.start(),
2519      DefaultDecl::TsInterfaceDecl(node) => node.start(),
2520    }
2521  }
2522  fn end(&self) -> SourcePos {
2523    match self {
2524      DefaultDecl::Class(node) => node.end(),
2525      DefaultDecl::Fn(node) => node.end(),
2526      DefaultDecl::TsInterfaceDecl(node) => node.end(),
2527    }
2528  }
2529}
2530
2531impl<'a> NodeTrait<'a> for DefaultDecl<'a> {
2532  fn parent(&self) -> Option<Node<'a>> {
2533    match self {
2534      DefaultDecl::Class(node) => NodeTrait::parent(*node),
2535      DefaultDecl::Fn(node) => NodeTrait::parent(*node),
2536      DefaultDecl::TsInterfaceDecl(node) => NodeTrait::parent(*node),
2537    }
2538  }
2539
2540  fn children(&self) -> Vec<Node<'a>> {
2541    match self {
2542      DefaultDecl::Class(node) => node.children(),
2543      DefaultDecl::Fn(node) => node.children(),
2544      DefaultDecl::TsInterfaceDecl(node) => node.children(),
2545    }
2546  }
2547
2548  fn as_node(&self) -> Node<'a> {
2549    match self {
2550      DefaultDecl::Class(node) => node.as_node(),
2551      DefaultDecl::Fn(node) => node.as_node(),
2552      DefaultDecl::TsInterfaceDecl(node) => node.as_node(),
2553    }
2554  }
2555
2556  fn kind(&self) -> NodeKind {
2557    match self {
2558      DefaultDecl::Class(_) => NodeKind::ClassExpr,
2559      DefaultDecl::Fn(_) => NodeKind::FnExpr,
2560      DefaultDecl::TsInterfaceDecl(_) => NodeKind::TsInterfaceDecl,
2561    }
2562  }
2563}
2564
2565impl<'a> From<&DefaultDecl<'a>> for Node<'a> {
2566  fn from(node: &DefaultDecl<'a>) -> Node<'a> {
2567    match node {
2568      DefaultDecl::Class(node) => (*node).into(),
2569      DefaultDecl::Fn(node) => (*node).into(),
2570      DefaultDecl::TsInterfaceDecl(node) => (*node).into(),
2571    }
2572  }
2573}
2574
2575impl<'a> From<DefaultDecl<'a>> for Node<'a> {
2576  fn from(node: DefaultDecl<'a>) -> Node<'a> {
2577    match node {
2578      DefaultDecl::Class(node) => node.into(),
2579      DefaultDecl::Fn(node) => node.into(),
2580      DefaultDecl::TsInterfaceDecl(node) => node.into(),
2581    }
2582  }
2583}
2584
2585fn get_view_for_default_decl<'a>(inner: &'a swc_ast::DefaultDecl, bump: &'a Bump) -> DefaultDecl<'a> {
2586  match inner {
2587    swc_ast::DefaultDecl::Class(value) => DefaultDecl::Class(get_view_for_class_expr(value, bump)),
2588    swc_ast::DefaultDecl::Fn(value) => DefaultDecl::Fn(get_view_for_fn_expr(value, bump)),
2589    swc_ast::DefaultDecl::TsInterfaceDecl(value) => DefaultDecl::TsInterfaceDecl(get_view_for_ts_interface_decl(value, bump)),
2590  }
2591}
2592
2593fn set_parent_for_default_decl<'a>(node: &DefaultDecl<'a>, parent: Node<'a>) {
2594  match node {
2595    DefaultDecl::Class(value) => set_parent_for_class_expr(value, parent),
2596    DefaultDecl::Fn(value) => set_parent_for_fn_expr(value, parent),
2597    DefaultDecl::TsInterfaceDecl(value) => set_parent_for_ts_interface_decl(value, parent),
2598  }
2599}
2600
2601#[derive(Copy, Clone)]
2602pub enum ExportSpecifier<'a> {
2603  Namespace(&'a ExportNamespaceSpecifier<'a>),
2604  Default(&'a ExportDefaultSpecifier<'a>),
2605  Named(&'a ExportNamedSpecifier<'a>),
2606}
2607
2608impl<'a> ExportSpecifier<'a> {
2609  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
2610    T::to(&self.into())
2611  }
2612
2613  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
2614    let node: Node<'a> = self.into();
2615    if let Some(result) = T::to(&node) {
2616      result
2617    } else {
2618      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
2619    }
2620  }
2621
2622  pub fn is<T: CastableNode<'a>>(&self) -> bool {
2623    self.kind() == T::kind()
2624  }
2625  pub fn parent(&self) -> &'a NamedExport<'a> {
2626    NodeTrait::parent(self).unwrap().expect::<NamedExport>()
2627  }
2628}
2629
2630impl<'a> SourceRanged for ExportSpecifier<'a> {
2631  fn start(&self) -> SourcePos {
2632    match self {
2633      ExportSpecifier::Namespace(node) => node.start(),
2634      ExportSpecifier::Default(node) => node.start(),
2635      ExportSpecifier::Named(node) => node.start(),
2636    }
2637  }
2638  fn end(&self) -> SourcePos {
2639    match self {
2640      ExportSpecifier::Namespace(node) => node.end(),
2641      ExportSpecifier::Default(node) => node.end(),
2642      ExportSpecifier::Named(node) => node.end(),
2643    }
2644  }
2645}
2646
2647impl<'a> NodeTrait<'a> for ExportSpecifier<'a> {
2648  fn parent(&self) -> Option<Node<'a>> {
2649    match self {
2650      ExportSpecifier::Namespace(node) => NodeTrait::parent(*node),
2651      ExportSpecifier::Default(node) => NodeTrait::parent(*node),
2652      ExportSpecifier::Named(node) => NodeTrait::parent(*node),
2653    }
2654  }
2655
2656  fn children(&self) -> Vec<Node<'a>> {
2657    match self {
2658      ExportSpecifier::Namespace(node) => node.children(),
2659      ExportSpecifier::Default(node) => node.children(),
2660      ExportSpecifier::Named(node) => node.children(),
2661    }
2662  }
2663
2664  fn as_node(&self) -> Node<'a> {
2665    match self {
2666      ExportSpecifier::Namespace(node) => node.as_node(),
2667      ExportSpecifier::Default(node) => node.as_node(),
2668      ExportSpecifier::Named(node) => node.as_node(),
2669    }
2670  }
2671
2672  fn kind(&self) -> NodeKind {
2673    match self {
2674      ExportSpecifier::Namespace(_) => NodeKind::ExportNamespaceSpecifier,
2675      ExportSpecifier::Default(_) => NodeKind::ExportDefaultSpecifier,
2676      ExportSpecifier::Named(_) => NodeKind::ExportNamedSpecifier,
2677    }
2678  }
2679}
2680
2681impl<'a> From<&ExportSpecifier<'a>> for Node<'a> {
2682  fn from(node: &ExportSpecifier<'a>) -> Node<'a> {
2683    match node {
2684      ExportSpecifier::Namespace(node) => (*node).into(),
2685      ExportSpecifier::Default(node) => (*node).into(),
2686      ExportSpecifier::Named(node) => (*node).into(),
2687    }
2688  }
2689}
2690
2691impl<'a> From<ExportSpecifier<'a>> for Node<'a> {
2692  fn from(node: ExportSpecifier<'a>) -> Node<'a> {
2693    match node {
2694      ExportSpecifier::Namespace(node) => node.into(),
2695      ExportSpecifier::Default(node) => node.into(),
2696      ExportSpecifier::Named(node) => node.into(),
2697    }
2698  }
2699}
2700
2701fn get_view_for_export_specifier<'a>(inner: &'a swc_ast::ExportSpecifier, bump: &'a Bump) -> ExportSpecifier<'a> {
2702  match inner {
2703    swc_ast::ExportSpecifier::Namespace(value) => ExportSpecifier::Namespace(get_view_for_export_namespace_specifier(value, bump)),
2704    swc_ast::ExportSpecifier::Default(value) => ExportSpecifier::Default(get_view_for_export_default_specifier(value, bump)),
2705    swc_ast::ExportSpecifier::Named(value) => ExportSpecifier::Named(get_view_for_export_named_specifier(value, bump)),
2706  }
2707}
2708
2709fn set_parent_for_export_specifier<'a>(node: &ExportSpecifier<'a>, parent: Node<'a>) {
2710  match node {
2711    ExportSpecifier::Namespace(value) => set_parent_for_export_namespace_specifier(value, parent),
2712    ExportSpecifier::Default(value) => set_parent_for_export_default_specifier(value, parent),
2713    ExportSpecifier::Named(value) => set_parent_for_export_named_specifier(value, parent),
2714  }
2715}
2716
2717#[derive(Copy, Clone)]
2718pub enum Expr<'a> {
2719  This(&'a ThisExpr<'a>),
2720  Array(&'a ArrayLit<'a>),
2721  Object(&'a ObjectLit<'a>),
2722  Fn(&'a FnExpr<'a>),
2723  Unary(&'a UnaryExpr<'a>),
2724  /// `++v`, `--v`, `v++`, `v--`
2725  Update(&'a UpdateExpr<'a>),
2726  Bin(&'a BinExpr<'a>),
2727  Assign(&'a AssignExpr<'a>),
2728  /// A member expression. If computed is true, the node corresponds to a
2729  /// computed (a[b]) member expression and property is an Expression. If
2730  /// computed is false, the node corresponds to a static (a.b) member
2731  /// expression and property is an Identifier.
2732  Member(&'a MemberExpr<'a>),
2733  SuperProp(&'a SuperPropExpr<'a>),
2734  /// true ? 'a' : 'b'
2735  Cond(&'a CondExpr<'a>),
2736  Call(&'a CallExpr<'a>),
2737  /// `new Cat()`
2738  New(&'a NewExpr<'a>),
2739  Seq(&'a SeqExpr<'a>),
2740  Ident(&'a Ident<'a>),
2741  Lit(Lit<'a>),
2742  Tpl(&'a Tpl<'a>),
2743  TaggedTpl(&'a TaggedTpl<'a>),
2744  Arrow(&'a ArrowExpr<'a>),
2745  Class(&'a ClassExpr<'a>),
2746  Yield(&'a YieldExpr<'a>),
2747  MetaProp(&'a MetaPropExpr<'a>),
2748  Await(&'a AwaitExpr<'a>),
2749  Paren(&'a ParenExpr<'a>),
2750  JSXMember(&'a JSXMemberExpr<'a>),
2751  JSXNamespacedName(&'a JSXNamespacedName<'a>),
2752  JSXEmpty(&'a JSXEmptyExpr<'a>),
2753  JSXElement(&'a JSXElement<'a>),
2754  JSXFragment(&'a JSXFragment<'a>),
2755  TsTypeAssertion(&'a TsTypeAssertion<'a>),
2756  TsConstAssertion(&'a TsConstAssertion<'a>),
2757  TsNonNull(&'a TsNonNullExpr<'a>),
2758  TsAs(&'a TsAsExpr<'a>),
2759  TsInstantiation(&'a TsInstantiation<'a>),
2760  TsSatisfies(&'a TsSatisfiesExpr<'a>),
2761  PrivateName(&'a PrivateName<'a>),
2762  OptChain(&'a OptChainExpr<'a>),
2763  Invalid(&'a Invalid<'a>),
2764}
2765
2766impl<'a> Expr<'a> {
2767  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
2768    T::to(&self.into())
2769  }
2770
2771  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
2772    let node: Node<'a> = self.into();
2773    if let Some(result) = T::to(&node) {
2774      result
2775    } else {
2776      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
2777    }
2778  }
2779
2780  pub fn is<T: CastableNode<'a>>(&self) -> bool {
2781    self.kind() == T::kind()
2782  }
2783}
2784
2785impl<'a> SourceRanged for Expr<'a> {
2786  fn start(&self) -> SourcePos {
2787    match self {
2788      Expr::This(node) => node.start(),
2789      Expr::Array(node) => node.start(),
2790      Expr::Object(node) => node.start(),
2791      Expr::Fn(node) => node.start(),
2792      Expr::Unary(node) => node.start(),
2793      Expr::Update(node) => node.start(),
2794      Expr::Bin(node) => node.start(),
2795      Expr::Assign(node) => node.start(),
2796      Expr::Member(node) => node.start(),
2797      Expr::SuperProp(node) => node.start(),
2798      Expr::Cond(node) => node.start(),
2799      Expr::Call(node) => node.start(),
2800      Expr::New(node) => node.start(),
2801      Expr::Seq(node) => node.start(),
2802      Expr::Ident(node) => node.start(),
2803      Expr::Lit(node) => node.start(),
2804      Expr::Tpl(node) => node.start(),
2805      Expr::TaggedTpl(node) => node.start(),
2806      Expr::Arrow(node) => node.start(),
2807      Expr::Class(node) => node.start(),
2808      Expr::Yield(node) => node.start(),
2809      Expr::MetaProp(node) => node.start(),
2810      Expr::Await(node) => node.start(),
2811      Expr::Paren(node) => node.start(),
2812      Expr::JSXMember(node) => node.start(),
2813      Expr::JSXNamespacedName(node) => node.start(),
2814      Expr::JSXEmpty(node) => node.start(),
2815      Expr::JSXElement(node) => node.start(),
2816      Expr::JSXFragment(node) => node.start(),
2817      Expr::TsTypeAssertion(node) => node.start(),
2818      Expr::TsConstAssertion(node) => node.start(),
2819      Expr::TsNonNull(node) => node.start(),
2820      Expr::TsAs(node) => node.start(),
2821      Expr::TsInstantiation(node) => node.start(),
2822      Expr::TsSatisfies(node) => node.start(),
2823      Expr::PrivateName(node) => node.start(),
2824      Expr::OptChain(node) => node.start(),
2825      Expr::Invalid(node) => node.start(),
2826    }
2827  }
2828  fn end(&self) -> SourcePos {
2829    match self {
2830      Expr::This(node) => node.end(),
2831      Expr::Array(node) => node.end(),
2832      Expr::Object(node) => node.end(),
2833      Expr::Fn(node) => node.end(),
2834      Expr::Unary(node) => node.end(),
2835      Expr::Update(node) => node.end(),
2836      Expr::Bin(node) => node.end(),
2837      Expr::Assign(node) => node.end(),
2838      Expr::Member(node) => node.end(),
2839      Expr::SuperProp(node) => node.end(),
2840      Expr::Cond(node) => node.end(),
2841      Expr::Call(node) => node.end(),
2842      Expr::New(node) => node.end(),
2843      Expr::Seq(node) => node.end(),
2844      Expr::Ident(node) => node.end(),
2845      Expr::Lit(node) => node.end(),
2846      Expr::Tpl(node) => node.end(),
2847      Expr::TaggedTpl(node) => node.end(),
2848      Expr::Arrow(node) => node.end(),
2849      Expr::Class(node) => node.end(),
2850      Expr::Yield(node) => node.end(),
2851      Expr::MetaProp(node) => node.end(),
2852      Expr::Await(node) => node.end(),
2853      Expr::Paren(node) => node.end(),
2854      Expr::JSXMember(node) => node.end(),
2855      Expr::JSXNamespacedName(node) => node.end(),
2856      Expr::JSXEmpty(node) => node.end(),
2857      Expr::JSXElement(node) => node.end(),
2858      Expr::JSXFragment(node) => node.end(),
2859      Expr::TsTypeAssertion(node) => node.end(),
2860      Expr::TsConstAssertion(node) => node.end(),
2861      Expr::TsNonNull(node) => node.end(),
2862      Expr::TsAs(node) => node.end(),
2863      Expr::TsInstantiation(node) => node.end(),
2864      Expr::TsSatisfies(node) => node.end(),
2865      Expr::PrivateName(node) => node.end(),
2866      Expr::OptChain(node) => node.end(),
2867      Expr::Invalid(node) => node.end(),
2868    }
2869  }
2870}
2871
2872impl<'a> NodeTrait<'a> for Expr<'a> {
2873  fn parent(&self) -> Option<Node<'a>> {
2874    match self {
2875      Expr::This(node) => NodeTrait::parent(*node),
2876      Expr::Array(node) => NodeTrait::parent(*node),
2877      Expr::Object(node) => NodeTrait::parent(*node),
2878      Expr::Fn(node) => NodeTrait::parent(*node),
2879      Expr::Unary(node) => NodeTrait::parent(*node),
2880      Expr::Update(node) => NodeTrait::parent(*node),
2881      Expr::Bin(node) => NodeTrait::parent(*node),
2882      Expr::Assign(node) => NodeTrait::parent(*node),
2883      Expr::Member(node) => NodeTrait::parent(*node),
2884      Expr::SuperProp(node) => NodeTrait::parent(*node),
2885      Expr::Cond(node) => NodeTrait::parent(*node),
2886      Expr::Call(node) => NodeTrait::parent(*node),
2887      Expr::New(node) => NodeTrait::parent(*node),
2888      Expr::Seq(node) => NodeTrait::parent(*node),
2889      Expr::Ident(node) => NodeTrait::parent(*node),
2890      Expr::Lit(node) => NodeTrait::parent(node),
2891      Expr::Tpl(node) => NodeTrait::parent(*node),
2892      Expr::TaggedTpl(node) => NodeTrait::parent(*node),
2893      Expr::Arrow(node) => NodeTrait::parent(*node),
2894      Expr::Class(node) => NodeTrait::parent(*node),
2895      Expr::Yield(node) => NodeTrait::parent(*node),
2896      Expr::MetaProp(node) => NodeTrait::parent(*node),
2897      Expr::Await(node) => NodeTrait::parent(*node),
2898      Expr::Paren(node) => NodeTrait::parent(*node),
2899      Expr::JSXMember(node) => NodeTrait::parent(*node),
2900      Expr::JSXNamespacedName(node) => NodeTrait::parent(*node),
2901      Expr::JSXEmpty(node) => NodeTrait::parent(*node),
2902      Expr::JSXElement(node) => NodeTrait::parent(*node),
2903      Expr::JSXFragment(node) => NodeTrait::parent(*node),
2904      Expr::TsTypeAssertion(node) => NodeTrait::parent(*node),
2905      Expr::TsConstAssertion(node) => NodeTrait::parent(*node),
2906      Expr::TsNonNull(node) => NodeTrait::parent(*node),
2907      Expr::TsAs(node) => NodeTrait::parent(*node),
2908      Expr::TsInstantiation(node) => NodeTrait::parent(*node),
2909      Expr::TsSatisfies(node) => NodeTrait::parent(*node),
2910      Expr::PrivateName(node) => NodeTrait::parent(*node),
2911      Expr::OptChain(node) => NodeTrait::parent(*node),
2912      Expr::Invalid(node) => NodeTrait::parent(*node),
2913    }
2914  }
2915
2916  fn children(&self) -> Vec<Node<'a>> {
2917    match self {
2918      Expr::This(node) => node.children(),
2919      Expr::Array(node) => node.children(),
2920      Expr::Object(node) => node.children(),
2921      Expr::Fn(node) => node.children(),
2922      Expr::Unary(node) => node.children(),
2923      Expr::Update(node) => node.children(),
2924      Expr::Bin(node) => node.children(),
2925      Expr::Assign(node) => node.children(),
2926      Expr::Member(node) => node.children(),
2927      Expr::SuperProp(node) => node.children(),
2928      Expr::Cond(node) => node.children(),
2929      Expr::Call(node) => node.children(),
2930      Expr::New(node) => node.children(),
2931      Expr::Seq(node) => node.children(),
2932      Expr::Ident(node) => node.children(),
2933      Expr::Lit(node) => node.children(),
2934      Expr::Tpl(node) => node.children(),
2935      Expr::TaggedTpl(node) => node.children(),
2936      Expr::Arrow(node) => node.children(),
2937      Expr::Class(node) => node.children(),
2938      Expr::Yield(node) => node.children(),
2939      Expr::MetaProp(node) => node.children(),
2940      Expr::Await(node) => node.children(),
2941      Expr::Paren(node) => node.children(),
2942      Expr::JSXMember(node) => node.children(),
2943      Expr::JSXNamespacedName(node) => node.children(),
2944      Expr::JSXEmpty(node) => node.children(),
2945      Expr::JSXElement(node) => node.children(),
2946      Expr::JSXFragment(node) => node.children(),
2947      Expr::TsTypeAssertion(node) => node.children(),
2948      Expr::TsConstAssertion(node) => node.children(),
2949      Expr::TsNonNull(node) => node.children(),
2950      Expr::TsAs(node) => node.children(),
2951      Expr::TsInstantiation(node) => node.children(),
2952      Expr::TsSatisfies(node) => node.children(),
2953      Expr::PrivateName(node) => node.children(),
2954      Expr::OptChain(node) => node.children(),
2955      Expr::Invalid(node) => node.children(),
2956    }
2957  }
2958
2959  fn as_node(&self) -> Node<'a> {
2960    match self {
2961      Expr::This(node) => node.as_node(),
2962      Expr::Array(node) => node.as_node(),
2963      Expr::Object(node) => node.as_node(),
2964      Expr::Fn(node) => node.as_node(),
2965      Expr::Unary(node) => node.as_node(),
2966      Expr::Update(node) => node.as_node(),
2967      Expr::Bin(node) => node.as_node(),
2968      Expr::Assign(node) => node.as_node(),
2969      Expr::Member(node) => node.as_node(),
2970      Expr::SuperProp(node) => node.as_node(),
2971      Expr::Cond(node) => node.as_node(),
2972      Expr::Call(node) => node.as_node(),
2973      Expr::New(node) => node.as_node(),
2974      Expr::Seq(node) => node.as_node(),
2975      Expr::Ident(node) => node.as_node(),
2976      Expr::Lit(node) => node.as_node(),
2977      Expr::Tpl(node) => node.as_node(),
2978      Expr::TaggedTpl(node) => node.as_node(),
2979      Expr::Arrow(node) => node.as_node(),
2980      Expr::Class(node) => node.as_node(),
2981      Expr::Yield(node) => node.as_node(),
2982      Expr::MetaProp(node) => node.as_node(),
2983      Expr::Await(node) => node.as_node(),
2984      Expr::Paren(node) => node.as_node(),
2985      Expr::JSXMember(node) => node.as_node(),
2986      Expr::JSXNamespacedName(node) => node.as_node(),
2987      Expr::JSXEmpty(node) => node.as_node(),
2988      Expr::JSXElement(node) => node.as_node(),
2989      Expr::JSXFragment(node) => node.as_node(),
2990      Expr::TsTypeAssertion(node) => node.as_node(),
2991      Expr::TsConstAssertion(node) => node.as_node(),
2992      Expr::TsNonNull(node) => node.as_node(),
2993      Expr::TsAs(node) => node.as_node(),
2994      Expr::TsInstantiation(node) => node.as_node(),
2995      Expr::TsSatisfies(node) => node.as_node(),
2996      Expr::PrivateName(node) => node.as_node(),
2997      Expr::OptChain(node) => node.as_node(),
2998      Expr::Invalid(node) => node.as_node(),
2999    }
3000  }
3001
3002  fn kind(&self) -> NodeKind {
3003    match self {
3004      Expr::This(_) => NodeKind::ThisExpr,
3005      Expr::Array(_) => NodeKind::ArrayLit,
3006      Expr::Object(_) => NodeKind::ObjectLit,
3007      Expr::Fn(_) => NodeKind::FnExpr,
3008      Expr::Unary(_) => NodeKind::UnaryExpr,
3009      Expr::Update(_) => NodeKind::UpdateExpr,
3010      Expr::Bin(_) => NodeKind::BinExpr,
3011      Expr::Assign(_) => NodeKind::AssignExpr,
3012      Expr::Member(_) => NodeKind::MemberExpr,
3013      Expr::SuperProp(_) => NodeKind::SuperPropExpr,
3014      Expr::Cond(_) => NodeKind::CondExpr,
3015      Expr::Call(_) => NodeKind::CallExpr,
3016      Expr::New(_) => NodeKind::NewExpr,
3017      Expr::Seq(_) => NodeKind::SeqExpr,
3018      Expr::Ident(_) => NodeKind::Ident,
3019      Expr::Lit(node) => node.kind(),
3020      Expr::Tpl(_) => NodeKind::Tpl,
3021      Expr::TaggedTpl(_) => NodeKind::TaggedTpl,
3022      Expr::Arrow(_) => NodeKind::ArrowExpr,
3023      Expr::Class(_) => NodeKind::ClassExpr,
3024      Expr::Yield(_) => NodeKind::YieldExpr,
3025      Expr::MetaProp(_) => NodeKind::MetaPropExpr,
3026      Expr::Await(_) => NodeKind::AwaitExpr,
3027      Expr::Paren(_) => NodeKind::ParenExpr,
3028      Expr::JSXMember(_) => NodeKind::JSXMemberExpr,
3029      Expr::JSXNamespacedName(_) => NodeKind::JSXNamespacedName,
3030      Expr::JSXEmpty(_) => NodeKind::JSXEmptyExpr,
3031      Expr::JSXElement(_) => NodeKind::JSXElement,
3032      Expr::JSXFragment(_) => NodeKind::JSXFragment,
3033      Expr::TsTypeAssertion(_) => NodeKind::TsTypeAssertion,
3034      Expr::TsConstAssertion(_) => NodeKind::TsConstAssertion,
3035      Expr::TsNonNull(_) => NodeKind::TsNonNullExpr,
3036      Expr::TsAs(_) => NodeKind::TsAsExpr,
3037      Expr::TsInstantiation(_) => NodeKind::TsInstantiation,
3038      Expr::TsSatisfies(_) => NodeKind::TsSatisfiesExpr,
3039      Expr::PrivateName(_) => NodeKind::PrivateName,
3040      Expr::OptChain(_) => NodeKind::OptChainExpr,
3041      Expr::Invalid(_) => NodeKind::Invalid,
3042    }
3043  }
3044}
3045
3046impl<'a> From<&Expr<'a>> for Node<'a> {
3047  fn from(node: &Expr<'a>) -> Node<'a> {
3048    match node {
3049      Expr::This(node) => (*node).into(),
3050      Expr::Array(node) => (*node).into(),
3051      Expr::Object(node) => (*node).into(),
3052      Expr::Fn(node) => (*node).into(),
3053      Expr::Unary(node) => (*node).into(),
3054      Expr::Update(node) => (*node).into(),
3055      Expr::Bin(node) => (*node).into(),
3056      Expr::Assign(node) => (*node).into(),
3057      Expr::Member(node) => (*node).into(),
3058      Expr::SuperProp(node) => (*node).into(),
3059      Expr::Cond(node) => (*node).into(),
3060      Expr::Call(node) => (*node).into(),
3061      Expr::New(node) => (*node).into(),
3062      Expr::Seq(node) => (*node).into(),
3063      Expr::Ident(node) => (*node).into(),
3064      Expr::Lit(node) => node.into(),
3065      Expr::Tpl(node) => (*node).into(),
3066      Expr::TaggedTpl(node) => (*node).into(),
3067      Expr::Arrow(node) => (*node).into(),
3068      Expr::Class(node) => (*node).into(),
3069      Expr::Yield(node) => (*node).into(),
3070      Expr::MetaProp(node) => (*node).into(),
3071      Expr::Await(node) => (*node).into(),
3072      Expr::Paren(node) => (*node).into(),
3073      Expr::JSXMember(node) => (*node).into(),
3074      Expr::JSXNamespacedName(node) => (*node).into(),
3075      Expr::JSXEmpty(node) => (*node).into(),
3076      Expr::JSXElement(node) => (*node).into(),
3077      Expr::JSXFragment(node) => (*node).into(),
3078      Expr::TsTypeAssertion(node) => (*node).into(),
3079      Expr::TsConstAssertion(node) => (*node).into(),
3080      Expr::TsNonNull(node) => (*node).into(),
3081      Expr::TsAs(node) => (*node).into(),
3082      Expr::TsInstantiation(node) => (*node).into(),
3083      Expr::TsSatisfies(node) => (*node).into(),
3084      Expr::PrivateName(node) => (*node).into(),
3085      Expr::OptChain(node) => (*node).into(),
3086      Expr::Invalid(node) => (*node).into(),
3087    }
3088  }
3089}
3090
3091impl<'a> From<Expr<'a>> for Node<'a> {
3092  fn from(node: Expr<'a>) -> Node<'a> {
3093    match node {
3094      Expr::This(node) => node.into(),
3095      Expr::Array(node) => node.into(),
3096      Expr::Object(node) => node.into(),
3097      Expr::Fn(node) => node.into(),
3098      Expr::Unary(node) => node.into(),
3099      Expr::Update(node) => node.into(),
3100      Expr::Bin(node) => node.into(),
3101      Expr::Assign(node) => node.into(),
3102      Expr::Member(node) => node.into(),
3103      Expr::SuperProp(node) => node.into(),
3104      Expr::Cond(node) => node.into(),
3105      Expr::Call(node) => node.into(),
3106      Expr::New(node) => node.into(),
3107      Expr::Seq(node) => node.into(),
3108      Expr::Ident(node) => node.into(),
3109      Expr::Lit(node) => node.into(),
3110      Expr::Tpl(node) => node.into(),
3111      Expr::TaggedTpl(node) => node.into(),
3112      Expr::Arrow(node) => node.into(),
3113      Expr::Class(node) => node.into(),
3114      Expr::Yield(node) => node.into(),
3115      Expr::MetaProp(node) => node.into(),
3116      Expr::Await(node) => node.into(),
3117      Expr::Paren(node) => node.into(),
3118      Expr::JSXMember(node) => node.into(),
3119      Expr::JSXNamespacedName(node) => node.into(),
3120      Expr::JSXEmpty(node) => node.into(),
3121      Expr::JSXElement(node) => node.into(),
3122      Expr::JSXFragment(node) => node.into(),
3123      Expr::TsTypeAssertion(node) => node.into(),
3124      Expr::TsConstAssertion(node) => node.into(),
3125      Expr::TsNonNull(node) => node.into(),
3126      Expr::TsAs(node) => node.into(),
3127      Expr::TsInstantiation(node) => node.into(),
3128      Expr::TsSatisfies(node) => node.into(),
3129      Expr::PrivateName(node) => node.into(),
3130      Expr::OptChain(node) => node.into(),
3131      Expr::Invalid(node) => node.into(),
3132    }
3133  }
3134}
3135
3136fn get_view_for_expr<'a>(inner: &'a swc_ast::Expr, bump: &'a Bump) -> Expr<'a> {
3137  match inner {
3138    swc_ast::Expr::This(value) => Expr::This(get_view_for_this_expr(value, bump)),
3139    swc_ast::Expr::Array(value) => Expr::Array(get_view_for_array_lit(value, bump)),
3140    swc_ast::Expr::Object(value) => Expr::Object(get_view_for_object_lit(value, bump)),
3141    swc_ast::Expr::Fn(value) => Expr::Fn(get_view_for_fn_expr(value, bump)),
3142    swc_ast::Expr::Unary(value) => Expr::Unary(get_view_for_unary_expr(value, bump)),
3143    swc_ast::Expr::Update(value) => Expr::Update(get_view_for_update_expr(value, bump)),
3144    swc_ast::Expr::Bin(value) => Expr::Bin(get_view_for_bin_expr(value, bump)),
3145    swc_ast::Expr::Assign(value) => Expr::Assign(get_view_for_assign_expr(value, bump)),
3146    swc_ast::Expr::Member(value) => Expr::Member(get_view_for_member_expr(value, bump)),
3147    swc_ast::Expr::SuperProp(value) => Expr::SuperProp(get_view_for_super_prop_expr(value, bump)),
3148    swc_ast::Expr::Cond(value) => Expr::Cond(get_view_for_cond_expr(value, bump)),
3149    swc_ast::Expr::Call(value) => Expr::Call(get_view_for_call_expr(value, bump)),
3150    swc_ast::Expr::New(value) => Expr::New(get_view_for_new_expr(value, bump)),
3151    swc_ast::Expr::Seq(value) => Expr::Seq(get_view_for_seq_expr(value, bump)),
3152    swc_ast::Expr::Ident(value) => Expr::Ident(get_view_for_ident(value, bump)),
3153    swc_ast::Expr::Lit(value) => Expr::Lit(get_view_for_lit(value, bump)),
3154    swc_ast::Expr::Tpl(value) => Expr::Tpl(get_view_for_tpl(value, bump)),
3155    swc_ast::Expr::TaggedTpl(value) => Expr::TaggedTpl(get_view_for_tagged_tpl(value, bump)),
3156    swc_ast::Expr::Arrow(value) => Expr::Arrow(get_view_for_arrow_expr(value, bump)),
3157    swc_ast::Expr::Class(value) => Expr::Class(get_view_for_class_expr(value, bump)),
3158    swc_ast::Expr::Yield(value) => Expr::Yield(get_view_for_yield_expr(value, bump)),
3159    swc_ast::Expr::MetaProp(value) => Expr::MetaProp(get_view_for_meta_prop_expr(value, bump)),
3160    swc_ast::Expr::Await(value) => Expr::Await(get_view_for_await_expr(value, bump)),
3161    swc_ast::Expr::Paren(value) => Expr::Paren(get_view_for_paren_expr(value, bump)),
3162    swc_ast::Expr::JSXMember(value) => Expr::JSXMember(get_view_for_jsxmember_expr(value, bump)),
3163    swc_ast::Expr::JSXNamespacedName(value) => Expr::JSXNamespacedName(get_view_for_jsxnamespaced_name(value, bump)),
3164    swc_ast::Expr::JSXEmpty(value) => Expr::JSXEmpty(get_view_for_jsxempty_expr(value, bump)),
3165    swc_ast::Expr::JSXElement(value) => Expr::JSXElement(get_view_for_jsxelement(value, bump)),
3166    swc_ast::Expr::JSXFragment(value) => Expr::JSXFragment(get_view_for_jsxfragment(value, bump)),
3167    swc_ast::Expr::TsTypeAssertion(value) => Expr::TsTypeAssertion(get_view_for_ts_type_assertion(value, bump)),
3168    swc_ast::Expr::TsConstAssertion(value) => Expr::TsConstAssertion(get_view_for_ts_const_assertion(value, bump)),
3169    swc_ast::Expr::TsNonNull(value) => Expr::TsNonNull(get_view_for_ts_non_null_expr(value, bump)),
3170    swc_ast::Expr::TsAs(value) => Expr::TsAs(get_view_for_ts_as_expr(value, bump)),
3171    swc_ast::Expr::TsInstantiation(value) => Expr::TsInstantiation(get_view_for_ts_instantiation(value, bump)),
3172    swc_ast::Expr::TsSatisfies(value) => Expr::TsSatisfies(get_view_for_ts_satisfies_expr(value, bump)),
3173    swc_ast::Expr::PrivateName(value) => Expr::PrivateName(get_view_for_private_name(value, bump)),
3174    swc_ast::Expr::OptChain(value) => Expr::OptChain(get_view_for_opt_chain_expr(value, bump)),
3175    swc_ast::Expr::Invalid(value) => Expr::Invalid(get_view_for_invalid(value, bump)),
3176  }
3177}
3178
3179fn set_parent_for_expr<'a>(node: &Expr<'a>, parent: Node<'a>) {
3180  match node {
3181    Expr::This(value) => set_parent_for_this_expr(value, parent),
3182    Expr::Array(value) => set_parent_for_array_lit(value, parent),
3183    Expr::Object(value) => set_parent_for_object_lit(value, parent),
3184    Expr::Fn(value) => set_parent_for_fn_expr(value, parent),
3185    Expr::Unary(value) => set_parent_for_unary_expr(value, parent),
3186    Expr::Update(value) => set_parent_for_update_expr(value, parent),
3187    Expr::Bin(value) => set_parent_for_bin_expr(value, parent),
3188    Expr::Assign(value) => set_parent_for_assign_expr(value, parent),
3189    Expr::Member(value) => set_parent_for_member_expr(value, parent),
3190    Expr::SuperProp(value) => set_parent_for_super_prop_expr(value, parent),
3191    Expr::Cond(value) => set_parent_for_cond_expr(value, parent),
3192    Expr::Call(value) => set_parent_for_call_expr(value, parent),
3193    Expr::New(value) => set_parent_for_new_expr(value, parent),
3194    Expr::Seq(value) => set_parent_for_seq_expr(value, parent),
3195    Expr::Ident(value) => set_parent_for_ident(value, parent),
3196    Expr::Lit(value) => set_parent_for_lit(value, parent),
3197    Expr::Tpl(value) => set_parent_for_tpl(value, parent),
3198    Expr::TaggedTpl(value) => set_parent_for_tagged_tpl(value, parent),
3199    Expr::Arrow(value) => set_parent_for_arrow_expr(value, parent),
3200    Expr::Class(value) => set_parent_for_class_expr(value, parent),
3201    Expr::Yield(value) => set_parent_for_yield_expr(value, parent),
3202    Expr::MetaProp(value) => set_parent_for_meta_prop_expr(value, parent),
3203    Expr::Await(value) => set_parent_for_await_expr(value, parent),
3204    Expr::Paren(value) => set_parent_for_paren_expr(value, parent),
3205    Expr::JSXMember(value) => set_parent_for_jsxmember_expr(value, parent),
3206    Expr::JSXNamespacedName(value) => set_parent_for_jsxnamespaced_name(value, parent),
3207    Expr::JSXEmpty(value) => set_parent_for_jsxempty_expr(value, parent),
3208    Expr::JSXElement(value) => set_parent_for_jsxelement(value, parent),
3209    Expr::JSXFragment(value) => set_parent_for_jsxfragment(value, parent),
3210    Expr::TsTypeAssertion(value) => set_parent_for_ts_type_assertion(value, parent),
3211    Expr::TsConstAssertion(value) => set_parent_for_ts_const_assertion(value, parent),
3212    Expr::TsNonNull(value) => set_parent_for_ts_non_null_expr(value, parent),
3213    Expr::TsAs(value) => set_parent_for_ts_as_expr(value, parent),
3214    Expr::TsInstantiation(value) => set_parent_for_ts_instantiation(value, parent),
3215    Expr::TsSatisfies(value) => set_parent_for_ts_satisfies_expr(value, parent),
3216    Expr::PrivateName(value) => set_parent_for_private_name(value, parent),
3217    Expr::OptChain(value) => set_parent_for_opt_chain_expr(value, parent),
3218    Expr::Invalid(value) => set_parent_for_invalid(value, parent),
3219  }
3220}
3221
3222/// A head for for-in and for-of loop.
3223#[derive(Copy, Clone)]
3224pub enum ForHead<'a> {
3225  VarDecl(&'a VarDecl<'a>),
3226  UsingDecl(&'a UsingDecl<'a>),
3227  Pat(Pat<'a>),
3228}
3229
3230impl<'a> ForHead<'a> {
3231  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
3232    T::to(&self.into())
3233  }
3234
3235  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
3236    let node: Node<'a> = self.into();
3237    if let Some(result) = T::to(&node) {
3238      result
3239    } else {
3240      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
3241    }
3242  }
3243
3244  pub fn is<T: CastableNode<'a>>(&self) -> bool {
3245    self.kind() == T::kind()
3246  }
3247}
3248
3249impl<'a> SourceRanged for ForHead<'a> {
3250  fn start(&self) -> SourcePos {
3251    match self {
3252      ForHead::VarDecl(node) => node.start(),
3253      ForHead::UsingDecl(node) => node.start(),
3254      ForHead::Pat(node) => node.start(),
3255    }
3256  }
3257  fn end(&self) -> SourcePos {
3258    match self {
3259      ForHead::VarDecl(node) => node.end(),
3260      ForHead::UsingDecl(node) => node.end(),
3261      ForHead::Pat(node) => node.end(),
3262    }
3263  }
3264}
3265
3266impl<'a> NodeTrait<'a> for ForHead<'a> {
3267  fn parent(&self) -> Option<Node<'a>> {
3268    match self {
3269      ForHead::VarDecl(node) => NodeTrait::parent(*node),
3270      ForHead::UsingDecl(node) => NodeTrait::parent(*node),
3271      ForHead::Pat(node) => NodeTrait::parent(node),
3272    }
3273  }
3274
3275  fn children(&self) -> Vec<Node<'a>> {
3276    match self {
3277      ForHead::VarDecl(node) => node.children(),
3278      ForHead::UsingDecl(node) => node.children(),
3279      ForHead::Pat(node) => node.children(),
3280    }
3281  }
3282
3283  fn as_node(&self) -> Node<'a> {
3284    match self {
3285      ForHead::VarDecl(node) => node.as_node(),
3286      ForHead::UsingDecl(node) => node.as_node(),
3287      ForHead::Pat(node) => node.as_node(),
3288    }
3289  }
3290
3291  fn kind(&self) -> NodeKind {
3292    match self {
3293      ForHead::VarDecl(_) => NodeKind::VarDecl,
3294      ForHead::UsingDecl(_) => NodeKind::UsingDecl,
3295      ForHead::Pat(node) => node.kind(),
3296    }
3297  }
3298}
3299
3300impl<'a> From<&ForHead<'a>> for Node<'a> {
3301  fn from(node: &ForHead<'a>) -> Node<'a> {
3302    match node {
3303      ForHead::VarDecl(node) => (*node).into(),
3304      ForHead::UsingDecl(node) => (*node).into(),
3305      ForHead::Pat(node) => node.into(),
3306    }
3307  }
3308}
3309
3310impl<'a> From<ForHead<'a>> for Node<'a> {
3311  fn from(node: ForHead<'a>) -> Node<'a> {
3312    match node {
3313      ForHead::VarDecl(node) => node.into(),
3314      ForHead::UsingDecl(node) => node.into(),
3315      ForHead::Pat(node) => node.into(),
3316    }
3317  }
3318}
3319
3320fn get_view_for_for_head<'a>(inner: &'a swc_ast::ForHead, bump: &'a Bump) -> ForHead<'a> {
3321  match inner {
3322    swc_ast::ForHead::VarDecl(value) => ForHead::VarDecl(get_view_for_var_decl(value, bump)),
3323    swc_ast::ForHead::UsingDecl(value) => ForHead::UsingDecl(get_view_for_using_decl(value, bump)),
3324    swc_ast::ForHead::Pat(value) => ForHead::Pat(get_view_for_pat(value, bump)),
3325  }
3326}
3327
3328fn set_parent_for_for_head<'a>(node: &ForHead<'a>, parent: Node<'a>) {
3329  match node {
3330    ForHead::VarDecl(value) => set_parent_for_var_decl(value, parent),
3331    ForHead::UsingDecl(value) => set_parent_for_using_decl(value, parent),
3332    ForHead::Pat(value) => set_parent_for_pat(value, parent),
3333  }
3334}
3335
3336#[derive(Copy, Clone)]
3337pub enum ImportSpecifier<'a> {
3338  Named(&'a ImportNamedSpecifier<'a>),
3339  Default(&'a ImportDefaultSpecifier<'a>),
3340  Namespace(&'a ImportStarAsSpecifier<'a>),
3341}
3342
3343impl<'a> ImportSpecifier<'a> {
3344  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
3345    T::to(&self.into())
3346  }
3347
3348  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
3349    let node: Node<'a> = self.into();
3350    if let Some(result) = T::to(&node) {
3351      result
3352    } else {
3353      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
3354    }
3355  }
3356
3357  pub fn is<T: CastableNode<'a>>(&self) -> bool {
3358    self.kind() == T::kind()
3359  }
3360  pub fn parent(&self) -> &'a ImportDecl<'a> {
3361    NodeTrait::parent(self).unwrap().expect::<ImportDecl>()
3362  }
3363}
3364
3365impl<'a> SourceRanged for ImportSpecifier<'a> {
3366  fn start(&self) -> SourcePos {
3367    match self {
3368      ImportSpecifier::Named(node) => node.start(),
3369      ImportSpecifier::Default(node) => node.start(),
3370      ImportSpecifier::Namespace(node) => node.start(),
3371    }
3372  }
3373  fn end(&self) -> SourcePos {
3374    match self {
3375      ImportSpecifier::Named(node) => node.end(),
3376      ImportSpecifier::Default(node) => node.end(),
3377      ImportSpecifier::Namespace(node) => node.end(),
3378    }
3379  }
3380}
3381
3382impl<'a> NodeTrait<'a> for ImportSpecifier<'a> {
3383  fn parent(&self) -> Option<Node<'a>> {
3384    match self {
3385      ImportSpecifier::Named(node) => NodeTrait::parent(*node),
3386      ImportSpecifier::Default(node) => NodeTrait::parent(*node),
3387      ImportSpecifier::Namespace(node) => NodeTrait::parent(*node),
3388    }
3389  }
3390
3391  fn children(&self) -> Vec<Node<'a>> {
3392    match self {
3393      ImportSpecifier::Named(node) => node.children(),
3394      ImportSpecifier::Default(node) => node.children(),
3395      ImportSpecifier::Namespace(node) => node.children(),
3396    }
3397  }
3398
3399  fn as_node(&self) -> Node<'a> {
3400    match self {
3401      ImportSpecifier::Named(node) => node.as_node(),
3402      ImportSpecifier::Default(node) => node.as_node(),
3403      ImportSpecifier::Namespace(node) => node.as_node(),
3404    }
3405  }
3406
3407  fn kind(&self) -> NodeKind {
3408    match self {
3409      ImportSpecifier::Named(_) => NodeKind::ImportNamedSpecifier,
3410      ImportSpecifier::Default(_) => NodeKind::ImportDefaultSpecifier,
3411      ImportSpecifier::Namespace(_) => NodeKind::ImportStarAsSpecifier,
3412    }
3413  }
3414}
3415
3416impl<'a> From<&ImportSpecifier<'a>> for Node<'a> {
3417  fn from(node: &ImportSpecifier<'a>) -> Node<'a> {
3418    match node {
3419      ImportSpecifier::Named(node) => (*node).into(),
3420      ImportSpecifier::Default(node) => (*node).into(),
3421      ImportSpecifier::Namespace(node) => (*node).into(),
3422    }
3423  }
3424}
3425
3426impl<'a> From<ImportSpecifier<'a>> for Node<'a> {
3427  fn from(node: ImportSpecifier<'a>) -> Node<'a> {
3428    match node {
3429      ImportSpecifier::Named(node) => node.into(),
3430      ImportSpecifier::Default(node) => node.into(),
3431      ImportSpecifier::Namespace(node) => node.into(),
3432    }
3433  }
3434}
3435
3436fn get_view_for_import_specifier<'a>(inner: &'a swc_ast::ImportSpecifier, bump: &'a Bump) -> ImportSpecifier<'a> {
3437  match inner {
3438    swc_ast::ImportSpecifier::Named(value) => ImportSpecifier::Named(get_view_for_import_named_specifier(value, bump)),
3439    swc_ast::ImportSpecifier::Default(value) => ImportSpecifier::Default(get_view_for_import_default_specifier(value, bump)),
3440    swc_ast::ImportSpecifier::Namespace(value) => ImportSpecifier::Namespace(get_view_for_import_star_as_specifier(value, bump)),
3441  }
3442}
3443
3444fn set_parent_for_import_specifier<'a>(node: &ImportSpecifier<'a>, parent: Node<'a>) {
3445  match node {
3446    ImportSpecifier::Named(value) => set_parent_for_import_named_specifier(value, parent),
3447    ImportSpecifier::Default(value) => set_parent_for_import_default_specifier(value, parent),
3448    ImportSpecifier::Namespace(value) => set_parent_for_import_star_as_specifier(value, parent),
3449  }
3450}
3451
3452#[derive(Copy, Clone)]
3453pub enum JSXAttrName<'a> {
3454  Ident(&'a IdentName<'a>),
3455  JSXNamespacedName(&'a JSXNamespacedName<'a>),
3456}
3457
3458impl<'a> JSXAttrName<'a> {
3459  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
3460    T::to(&self.into())
3461  }
3462
3463  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
3464    let node: Node<'a> = self.into();
3465    if let Some(result) = T::to(&node) {
3466      result
3467    } else {
3468      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
3469    }
3470  }
3471
3472  pub fn is<T: CastableNode<'a>>(&self) -> bool {
3473    self.kind() == T::kind()
3474  }
3475  pub fn parent(&self) -> Node<'a> {
3476    NodeTrait::parent(self).unwrap()
3477  }
3478}
3479
3480impl<'a> SourceRanged for JSXAttrName<'a> {
3481  fn start(&self) -> SourcePos {
3482    match self {
3483      JSXAttrName::Ident(node) => node.start(),
3484      JSXAttrName::JSXNamespacedName(node) => node.start(),
3485    }
3486  }
3487  fn end(&self) -> SourcePos {
3488    match self {
3489      JSXAttrName::Ident(node) => node.end(),
3490      JSXAttrName::JSXNamespacedName(node) => node.end(),
3491    }
3492  }
3493}
3494
3495impl<'a> NodeTrait<'a> for JSXAttrName<'a> {
3496  fn parent(&self) -> Option<Node<'a>> {
3497    match self {
3498      JSXAttrName::Ident(node) => NodeTrait::parent(*node),
3499      JSXAttrName::JSXNamespacedName(node) => NodeTrait::parent(*node),
3500    }
3501  }
3502
3503  fn children(&self) -> Vec<Node<'a>> {
3504    match self {
3505      JSXAttrName::Ident(node) => node.children(),
3506      JSXAttrName::JSXNamespacedName(node) => node.children(),
3507    }
3508  }
3509
3510  fn as_node(&self) -> Node<'a> {
3511    match self {
3512      JSXAttrName::Ident(node) => node.as_node(),
3513      JSXAttrName::JSXNamespacedName(node) => node.as_node(),
3514    }
3515  }
3516
3517  fn kind(&self) -> NodeKind {
3518    match self {
3519      JSXAttrName::Ident(_) => NodeKind::IdentName,
3520      JSXAttrName::JSXNamespacedName(_) => NodeKind::JSXNamespacedName,
3521    }
3522  }
3523}
3524
3525impl<'a> From<&JSXAttrName<'a>> for Node<'a> {
3526  fn from(node: &JSXAttrName<'a>) -> Node<'a> {
3527    match node {
3528      JSXAttrName::Ident(node) => (*node).into(),
3529      JSXAttrName::JSXNamespacedName(node) => (*node).into(),
3530    }
3531  }
3532}
3533
3534impl<'a> From<JSXAttrName<'a>> for Node<'a> {
3535  fn from(node: JSXAttrName<'a>) -> Node<'a> {
3536    match node {
3537      JSXAttrName::Ident(node) => node.into(),
3538      JSXAttrName::JSXNamespacedName(node) => node.into(),
3539    }
3540  }
3541}
3542
3543fn get_view_for_jsxattr_name<'a>(inner: &'a swc_ast::JSXAttrName, bump: &'a Bump) -> JSXAttrName<'a> {
3544  match inner {
3545    swc_ast::JSXAttrName::Ident(value) => JSXAttrName::Ident(get_view_for_ident_name(value, bump)),
3546    swc_ast::JSXAttrName::JSXNamespacedName(value) => JSXAttrName::JSXNamespacedName(get_view_for_jsxnamespaced_name(value, bump)),
3547  }
3548}
3549
3550fn set_parent_for_jsxattr_name<'a>(node: &JSXAttrName<'a>, parent: Node<'a>) {
3551  match node {
3552    JSXAttrName::Ident(value) => set_parent_for_ident_name(value, parent),
3553    JSXAttrName::JSXNamespacedName(value) => set_parent_for_jsxnamespaced_name(value, parent),
3554  }
3555}
3556
3557#[derive(Copy, Clone)]
3558pub enum JSXAttrOrSpread<'a> {
3559  JSXAttr(&'a JSXAttr<'a>),
3560  SpreadElement(&'a SpreadElement<'a>),
3561}
3562
3563impl<'a> JSXAttrOrSpread<'a> {
3564  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
3565    T::to(&self.into())
3566  }
3567
3568  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
3569    let node: Node<'a> = self.into();
3570    if let Some(result) = T::to(&node) {
3571      result
3572    } else {
3573      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
3574    }
3575  }
3576
3577  pub fn is<T: CastableNode<'a>>(&self) -> bool {
3578    self.kind() == T::kind()
3579  }
3580  pub fn parent(&self) -> Node<'a> {
3581    NodeTrait::parent(self).unwrap()
3582  }
3583}
3584
3585impl<'a> SourceRanged for JSXAttrOrSpread<'a> {
3586  fn start(&self) -> SourcePos {
3587    match self {
3588      JSXAttrOrSpread::JSXAttr(node) => node.start(),
3589      JSXAttrOrSpread::SpreadElement(node) => node.start(),
3590    }
3591  }
3592  fn end(&self) -> SourcePos {
3593    match self {
3594      JSXAttrOrSpread::JSXAttr(node) => node.end(),
3595      JSXAttrOrSpread::SpreadElement(node) => node.end(),
3596    }
3597  }
3598}
3599
3600impl<'a> NodeTrait<'a> for JSXAttrOrSpread<'a> {
3601  fn parent(&self) -> Option<Node<'a>> {
3602    match self {
3603      JSXAttrOrSpread::JSXAttr(node) => NodeTrait::parent(*node),
3604      JSXAttrOrSpread::SpreadElement(node) => NodeTrait::parent(*node),
3605    }
3606  }
3607
3608  fn children(&self) -> Vec<Node<'a>> {
3609    match self {
3610      JSXAttrOrSpread::JSXAttr(node) => node.children(),
3611      JSXAttrOrSpread::SpreadElement(node) => node.children(),
3612    }
3613  }
3614
3615  fn as_node(&self) -> Node<'a> {
3616    match self {
3617      JSXAttrOrSpread::JSXAttr(node) => node.as_node(),
3618      JSXAttrOrSpread::SpreadElement(node) => node.as_node(),
3619    }
3620  }
3621
3622  fn kind(&self) -> NodeKind {
3623    match self {
3624      JSXAttrOrSpread::JSXAttr(_) => NodeKind::JSXAttr,
3625      JSXAttrOrSpread::SpreadElement(_) => NodeKind::SpreadElement,
3626    }
3627  }
3628}
3629
3630impl<'a> From<&JSXAttrOrSpread<'a>> for Node<'a> {
3631  fn from(node: &JSXAttrOrSpread<'a>) -> Node<'a> {
3632    match node {
3633      JSXAttrOrSpread::JSXAttr(node) => (*node).into(),
3634      JSXAttrOrSpread::SpreadElement(node) => (*node).into(),
3635    }
3636  }
3637}
3638
3639impl<'a> From<JSXAttrOrSpread<'a>> for Node<'a> {
3640  fn from(node: JSXAttrOrSpread<'a>) -> Node<'a> {
3641    match node {
3642      JSXAttrOrSpread::JSXAttr(node) => node.into(),
3643      JSXAttrOrSpread::SpreadElement(node) => node.into(),
3644    }
3645  }
3646}
3647
3648fn get_view_for_jsxattr_or_spread<'a>(inner: &'a swc_ast::JSXAttrOrSpread, bump: &'a Bump) -> JSXAttrOrSpread<'a> {
3649  match inner {
3650    swc_ast::JSXAttrOrSpread::JSXAttr(value) => JSXAttrOrSpread::JSXAttr(get_view_for_jsxattr(value, bump)),
3651    swc_ast::JSXAttrOrSpread::SpreadElement(value) => JSXAttrOrSpread::SpreadElement(get_view_for_spread_element(value, bump)),
3652  }
3653}
3654
3655fn set_parent_for_jsxattr_or_spread<'a>(node: &JSXAttrOrSpread<'a>, parent: Node<'a>) {
3656  match node {
3657    JSXAttrOrSpread::JSXAttr(value) => set_parent_for_jsxattr(value, parent),
3658    JSXAttrOrSpread::SpreadElement(value) => set_parent_for_spread_element(value, parent),
3659  }
3660}
3661
3662#[derive(Copy, Clone)]
3663pub enum JSXAttrValue<'a> {
3664  Str(&'a Str<'a>),
3665  JSXExprContainer(&'a JSXExprContainer<'a>),
3666  JSXElement(&'a JSXElement<'a>),
3667  JSXFragment(&'a JSXFragment<'a>),
3668}
3669
3670impl<'a> JSXAttrValue<'a> {
3671  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
3672    T::to(&self.into())
3673  }
3674
3675  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
3676    let node: Node<'a> = self.into();
3677    if let Some(result) = T::to(&node) {
3678      result
3679    } else {
3680      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
3681    }
3682  }
3683
3684  pub fn is<T: CastableNode<'a>>(&self) -> bool {
3685    self.kind() == T::kind()
3686  }
3687  pub fn parent(&self) -> Node<'a> {
3688    NodeTrait::parent(self).unwrap()
3689  }
3690}
3691
3692impl<'a> SourceRanged for JSXAttrValue<'a> {
3693  fn start(&self) -> SourcePos {
3694    match self {
3695      JSXAttrValue::Str(node) => node.start(),
3696      JSXAttrValue::JSXExprContainer(node) => node.start(),
3697      JSXAttrValue::JSXElement(node) => node.start(),
3698      JSXAttrValue::JSXFragment(node) => node.start(),
3699    }
3700  }
3701  fn end(&self) -> SourcePos {
3702    match self {
3703      JSXAttrValue::Str(node) => node.end(),
3704      JSXAttrValue::JSXExprContainer(node) => node.end(),
3705      JSXAttrValue::JSXElement(node) => node.end(),
3706      JSXAttrValue::JSXFragment(node) => node.end(),
3707    }
3708  }
3709}
3710
3711impl<'a> NodeTrait<'a> for JSXAttrValue<'a> {
3712  fn parent(&self) -> Option<Node<'a>> {
3713    match self {
3714      JSXAttrValue::Str(node) => NodeTrait::parent(*node),
3715      JSXAttrValue::JSXExprContainer(node) => NodeTrait::parent(*node),
3716      JSXAttrValue::JSXElement(node) => NodeTrait::parent(*node),
3717      JSXAttrValue::JSXFragment(node) => NodeTrait::parent(*node),
3718    }
3719  }
3720
3721  fn children(&self) -> Vec<Node<'a>> {
3722    match self {
3723      JSXAttrValue::Str(node) => node.children(),
3724      JSXAttrValue::JSXExprContainer(node) => node.children(),
3725      JSXAttrValue::JSXElement(node) => node.children(),
3726      JSXAttrValue::JSXFragment(node) => node.children(),
3727    }
3728  }
3729
3730  fn as_node(&self) -> Node<'a> {
3731    match self {
3732      JSXAttrValue::Str(node) => node.as_node(),
3733      JSXAttrValue::JSXExprContainer(node) => node.as_node(),
3734      JSXAttrValue::JSXElement(node) => node.as_node(),
3735      JSXAttrValue::JSXFragment(node) => node.as_node(),
3736    }
3737  }
3738
3739  fn kind(&self) -> NodeKind {
3740    match self {
3741      JSXAttrValue::Str(_) => NodeKind::Str,
3742      JSXAttrValue::JSXExprContainer(_) => NodeKind::JSXExprContainer,
3743      JSXAttrValue::JSXElement(_) => NodeKind::JSXElement,
3744      JSXAttrValue::JSXFragment(_) => NodeKind::JSXFragment,
3745    }
3746  }
3747}
3748
3749impl<'a> From<&JSXAttrValue<'a>> for Node<'a> {
3750  fn from(node: &JSXAttrValue<'a>) -> Node<'a> {
3751    match node {
3752      JSXAttrValue::Str(node) => (*node).into(),
3753      JSXAttrValue::JSXExprContainer(node) => (*node).into(),
3754      JSXAttrValue::JSXElement(node) => (*node).into(),
3755      JSXAttrValue::JSXFragment(node) => (*node).into(),
3756    }
3757  }
3758}
3759
3760impl<'a> From<JSXAttrValue<'a>> for Node<'a> {
3761  fn from(node: JSXAttrValue<'a>) -> Node<'a> {
3762    match node {
3763      JSXAttrValue::Str(node) => node.into(),
3764      JSXAttrValue::JSXExprContainer(node) => node.into(),
3765      JSXAttrValue::JSXElement(node) => node.into(),
3766      JSXAttrValue::JSXFragment(node) => node.into(),
3767    }
3768  }
3769}
3770
3771fn get_view_for_jsxattr_value<'a>(inner: &'a swc_ast::JSXAttrValue, bump: &'a Bump) -> JSXAttrValue<'a> {
3772  match inner {
3773    swc_ast::JSXAttrValue::Str(value) => JSXAttrValue::Str(get_view_for_str(value, bump)),
3774    swc_ast::JSXAttrValue::JSXExprContainer(value) => JSXAttrValue::JSXExprContainer(get_view_for_jsxexpr_container(value, bump)),
3775    swc_ast::JSXAttrValue::JSXElement(value) => JSXAttrValue::JSXElement(get_view_for_jsxelement(value, bump)),
3776    swc_ast::JSXAttrValue::JSXFragment(value) => JSXAttrValue::JSXFragment(get_view_for_jsxfragment(value, bump)),
3777  }
3778}
3779
3780fn set_parent_for_jsxattr_value<'a>(node: &JSXAttrValue<'a>, parent: Node<'a>) {
3781  match node {
3782    JSXAttrValue::Str(value) => set_parent_for_str(value, parent),
3783    JSXAttrValue::JSXExprContainer(value) => set_parent_for_jsxexpr_container(value, parent),
3784    JSXAttrValue::JSXElement(value) => set_parent_for_jsxelement(value, parent),
3785    JSXAttrValue::JSXFragment(value) => set_parent_for_jsxfragment(value, parent),
3786  }
3787}
3788
3789#[derive(Copy, Clone)]
3790pub enum JSXElementChild<'a> {
3791  JSXText(&'a JSXText<'a>),
3792  JSXExprContainer(&'a JSXExprContainer<'a>),
3793  JSXSpreadChild(&'a JSXSpreadChild<'a>),
3794  JSXElement(&'a JSXElement<'a>),
3795  JSXFragment(&'a JSXFragment<'a>),
3796}
3797
3798impl<'a> JSXElementChild<'a> {
3799  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
3800    T::to(&self.into())
3801  }
3802
3803  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
3804    let node: Node<'a> = self.into();
3805    if let Some(result) = T::to(&node) {
3806      result
3807    } else {
3808      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
3809    }
3810  }
3811
3812  pub fn is<T: CastableNode<'a>>(&self) -> bool {
3813    self.kind() == T::kind()
3814  }
3815  pub fn parent(&self) -> Node<'a> {
3816    NodeTrait::parent(self).unwrap()
3817  }
3818}
3819
3820impl<'a> SourceRanged for JSXElementChild<'a> {
3821  fn start(&self) -> SourcePos {
3822    match self {
3823      JSXElementChild::JSXText(node) => node.start(),
3824      JSXElementChild::JSXExprContainer(node) => node.start(),
3825      JSXElementChild::JSXSpreadChild(node) => node.start(),
3826      JSXElementChild::JSXElement(node) => node.start(),
3827      JSXElementChild::JSXFragment(node) => node.start(),
3828    }
3829  }
3830  fn end(&self) -> SourcePos {
3831    match self {
3832      JSXElementChild::JSXText(node) => node.end(),
3833      JSXElementChild::JSXExprContainer(node) => node.end(),
3834      JSXElementChild::JSXSpreadChild(node) => node.end(),
3835      JSXElementChild::JSXElement(node) => node.end(),
3836      JSXElementChild::JSXFragment(node) => node.end(),
3837    }
3838  }
3839}
3840
3841impl<'a> NodeTrait<'a> for JSXElementChild<'a> {
3842  fn parent(&self) -> Option<Node<'a>> {
3843    match self {
3844      JSXElementChild::JSXText(node) => NodeTrait::parent(*node),
3845      JSXElementChild::JSXExprContainer(node) => NodeTrait::parent(*node),
3846      JSXElementChild::JSXSpreadChild(node) => NodeTrait::parent(*node),
3847      JSXElementChild::JSXElement(node) => NodeTrait::parent(*node),
3848      JSXElementChild::JSXFragment(node) => NodeTrait::parent(*node),
3849    }
3850  }
3851
3852  fn children(&self) -> Vec<Node<'a>> {
3853    match self {
3854      JSXElementChild::JSXText(node) => node.children(),
3855      JSXElementChild::JSXExprContainer(node) => node.children(),
3856      JSXElementChild::JSXSpreadChild(node) => node.children(),
3857      JSXElementChild::JSXElement(node) => node.children(),
3858      JSXElementChild::JSXFragment(node) => node.children(),
3859    }
3860  }
3861
3862  fn as_node(&self) -> Node<'a> {
3863    match self {
3864      JSXElementChild::JSXText(node) => node.as_node(),
3865      JSXElementChild::JSXExprContainer(node) => node.as_node(),
3866      JSXElementChild::JSXSpreadChild(node) => node.as_node(),
3867      JSXElementChild::JSXElement(node) => node.as_node(),
3868      JSXElementChild::JSXFragment(node) => node.as_node(),
3869    }
3870  }
3871
3872  fn kind(&self) -> NodeKind {
3873    match self {
3874      JSXElementChild::JSXText(_) => NodeKind::JSXText,
3875      JSXElementChild::JSXExprContainer(_) => NodeKind::JSXExprContainer,
3876      JSXElementChild::JSXSpreadChild(_) => NodeKind::JSXSpreadChild,
3877      JSXElementChild::JSXElement(_) => NodeKind::JSXElement,
3878      JSXElementChild::JSXFragment(_) => NodeKind::JSXFragment,
3879    }
3880  }
3881}
3882
3883impl<'a> From<&JSXElementChild<'a>> for Node<'a> {
3884  fn from(node: &JSXElementChild<'a>) -> Node<'a> {
3885    match node {
3886      JSXElementChild::JSXText(node) => (*node).into(),
3887      JSXElementChild::JSXExprContainer(node) => (*node).into(),
3888      JSXElementChild::JSXSpreadChild(node) => (*node).into(),
3889      JSXElementChild::JSXElement(node) => (*node).into(),
3890      JSXElementChild::JSXFragment(node) => (*node).into(),
3891    }
3892  }
3893}
3894
3895impl<'a> From<JSXElementChild<'a>> for Node<'a> {
3896  fn from(node: JSXElementChild<'a>) -> Node<'a> {
3897    match node {
3898      JSXElementChild::JSXText(node) => node.into(),
3899      JSXElementChild::JSXExprContainer(node) => node.into(),
3900      JSXElementChild::JSXSpreadChild(node) => node.into(),
3901      JSXElementChild::JSXElement(node) => node.into(),
3902      JSXElementChild::JSXFragment(node) => node.into(),
3903    }
3904  }
3905}
3906
3907fn get_view_for_jsxelement_child<'a>(inner: &'a swc_ast::JSXElementChild, bump: &'a Bump) -> JSXElementChild<'a> {
3908  match inner {
3909    swc_ast::JSXElementChild::JSXText(value) => JSXElementChild::JSXText(get_view_for_jsxtext(value, bump)),
3910    swc_ast::JSXElementChild::JSXExprContainer(value) => JSXElementChild::JSXExprContainer(get_view_for_jsxexpr_container(value, bump)),
3911    swc_ast::JSXElementChild::JSXSpreadChild(value) => JSXElementChild::JSXSpreadChild(get_view_for_jsxspread_child(value, bump)),
3912    swc_ast::JSXElementChild::JSXElement(value) => JSXElementChild::JSXElement(get_view_for_jsxelement(value, bump)),
3913    swc_ast::JSXElementChild::JSXFragment(value) => JSXElementChild::JSXFragment(get_view_for_jsxfragment(value, bump)),
3914  }
3915}
3916
3917fn set_parent_for_jsxelement_child<'a>(node: &JSXElementChild<'a>, parent: Node<'a>) {
3918  match node {
3919    JSXElementChild::JSXText(value) => set_parent_for_jsxtext(value, parent),
3920    JSXElementChild::JSXExprContainer(value) => set_parent_for_jsxexpr_container(value, parent),
3921    JSXElementChild::JSXSpreadChild(value) => set_parent_for_jsxspread_child(value, parent),
3922    JSXElementChild::JSXElement(value) => set_parent_for_jsxelement(value, parent),
3923    JSXElementChild::JSXFragment(value) => set_parent_for_jsxfragment(value, parent),
3924  }
3925}
3926
3927#[derive(Copy, Clone)]
3928pub enum JSXElementName<'a> {
3929  Ident(&'a Ident<'a>),
3930  JSXMemberExpr(&'a JSXMemberExpr<'a>),
3931  JSXNamespacedName(&'a JSXNamespacedName<'a>),
3932}
3933
3934impl<'a> JSXElementName<'a> {
3935  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
3936    T::to(&self.into())
3937  }
3938
3939  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
3940    let node: Node<'a> = self.into();
3941    if let Some(result) = T::to(&node) {
3942      result
3943    } else {
3944      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
3945    }
3946  }
3947
3948  pub fn is<T: CastableNode<'a>>(&self) -> bool {
3949    self.kind() == T::kind()
3950  }
3951  pub fn parent(&self) -> Node<'a> {
3952    NodeTrait::parent(self).unwrap()
3953  }
3954}
3955
3956impl<'a> SourceRanged for JSXElementName<'a> {
3957  fn start(&self) -> SourcePos {
3958    match self {
3959      JSXElementName::Ident(node) => node.start(),
3960      JSXElementName::JSXMemberExpr(node) => node.start(),
3961      JSXElementName::JSXNamespacedName(node) => node.start(),
3962    }
3963  }
3964  fn end(&self) -> SourcePos {
3965    match self {
3966      JSXElementName::Ident(node) => node.end(),
3967      JSXElementName::JSXMemberExpr(node) => node.end(),
3968      JSXElementName::JSXNamespacedName(node) => node.end(),
3969    }
3970  }
3971}
3972
3973impl<'a> NodeTrait<'a> for JSXElementName<'a> {
3974  fn parent(&self) -> Option<Node<'a>> {
3975    match self {
3976      JSXElementName::Ident(node) => NodeTrait::parent(*node),
3977      JSXElementName::JSXMemberExpr(node) => NodeTrait::parent(*node),
3978      JSXElementName::JSXNamespacedName(node) => NodeTrait::parent(*node),
3979    }
3980  }
3981
3982  fn children(&self) -> Vec<Node<'a>> {
3983    match self {
3984      JSXElementName::Ident(node) => node.children(),
3985      JSXElementName::JSXMemberExpr(node) => node.children(),
3986      JSXElementName::JSXNamespacedName(node) => node.children(),
3987    }
3988  }
3989
3990  fn as_node(&self) -> Node<'a> {
3991    match self {
3992      JSXElementName::Ident(node) => node.as_node(),
3993      JSXElementName::JSXMemberExpr(node) => node.as_node(),
3994      JSXElementName::JSXNamespacedName(node) => node.as_node(),
3995    }
3996  }
3997
3998  fn kind(&self) -> NodeKind {
3999    match self {
4000      JSXElementName::Ident(_) => NodeKind::Ident,
4001      JSXElementName::JSXMemberExpr(_) => NodeKind::JSXMemberExpr,
4002      JSXElementName::JSXNamespacedName(_) => NodeKind::JSXNamespacedName,
4003    }
4004  }
4005}
4006
4007impl<'a> From<&JSXElementName<'a>> for Node<'a> {
4008  fn from(node: &JSXElementName<'a>) -> Node<'a> {
4009    match node {
4010      JSXElementName::Ident(node) => (*node).into(),
4011      JSXElementName::JSXMemberExpr(node) => (*node).into(),
4012      JSXElementName::JSXNamespacedName(node) => (*node).into(),
4013    }
4014  }
4015}
4016
4017impl<'a> From<JSXElementName<'a>> for Node<'a> {
4018  fn from(node: JSXElementName<'a>) -> Node<'a> {
4019    match node {
4020      JSXElementName::Ident(node) => node.into(),
4021      JSXElementName::JSXMemberExpr(node) => node.into(),
4022      JSXElementName::JSXNamespacedName(node) => node.into(),
4023    }
4024  }
4025}
4026
4027fn get_view_for_jsxelement_name<'a>(inner: &'a swc_ast::JSXElementName, bump: &'a Bump) -> JSXElementName<'a> {
4028  match inner {
4029    swc_ast::JSXElementName::Ident(value) => JSXElementName::Ident(get_view_for_ident(value, bump)),
4030    swc_ast::JSXElementName::JSXMemberExpr(value) => JSXElementName::JSXMemberExpr(get_view_for_jsxmember_expr(value, bump)),
4031    swc_ast::JSXElementName::JSXNamespacedName(value) => JSXElementName::JSXNamespacedName(get_view_for_jsxnamespaced_name(value, bump)),
4032  }
4033}
4034
4035fn set_parent_for_jsxelement_name<'a>(node: &JSXElementName<'a>, parent: Node<'a>) {
4036  match node {
4037    JSXElementName::Ident(value) => set_parent_for_ident(value, parent),
4038    JSXElementName::JSXMemberExpr(value) => set_parent_for_jsxmember_expr(value, parent),
4039    JSXElementName::JSXNamespacedName(value) => set_parent_for_jsxnamespaced_name(value, parent),
4040  }
4041}
4042
4043#[derive(Copy, Clone)]
4044pub enum JSXExpr<'a> {
4045  JSXEmptyExpr(&'a JSXEmptyExpr<'a>),
4046  Expr(Expr<'a>),
4047}
4048
4049impl<'a> JSXExpr<'a> {
4050  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4051    T::to(&self.into())
4052  }
4053
4054  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4055    let node: Node<'a> = self.into();
4056    if let Some(result) = T::to(&node) {
4057      result
4058    } else {
4059      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4060    }
4061  }
4062
4063  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4064    self.kind() == T::kind()
4065  }
4066}
4067
4068impl<'a> SourceRanged for JSXExpr<'a> {
4069  fn start(&self) -> SourcePos {
4070    match self {
4071      JSXExpr::JSXEmptyExpr(node) => node.start(),
4072      JSXExpr::Expr(node) => node.start(),
4073    }
4074  }
4075  fn end(&self) -> SourcePos {
4076    match self {
4077      JSXExpr::JSXEmptyExpr(node) => node.end(),
4078      JSXExpr::Expr(node) => node.end(),
4079    }
4080  }
4081}
4082
4083impl<'a> NodeTrait<'a> for JSXExpr<'a> {
4084  fn parent(&self) -> Option<Node<'a>> {
4085    match self {
4086      JSXExpr::JSXEmptyExpr(node) => NodeTrait::parent(*node),
4087      JSXExpr::Expr(node) => NodeTrait::parent(node),
4088    }
4089  }
4090
4091  fn children(&self) -> Vec<Node<'a>> {
4092    match self {
4093      JSXExpr::JSXEmptyExpr(node) => node.children(),
4094      JSXExpr::Expr(node) => node.children(),
4095    }
4096  }
4097
4098  fn as_node(&self) -> Node<'a> {
4099    match self {
4100      JSXExpr::JSXEmptyExpr(node) => node.as_node(),
4101      JSXExpr::Expr(node) => node.as_node(),
4102    }
4103  }
4104
4105  fn kind(&self) -> NodeKind {
4106    match self {
4107      JSXExpr::JSXEmptyExpr(_) => NodeKind::JSXEmptyExpr,
4108      JSXExpr::Expr(node) => node.kind(),
4109    }
4110  }
4111}
4112
4113impl<'a> From<&JSXExpr<'a>> for Node<'a> {
4114  fn from(node: &JSXExpr<'a>) -> Node<'a> {
4115    match node {
4116      JSXExpr::JSXEmptyExpr(node) => (*node).into(),
4117      JSXExpr::Expr(node) => node.into(),
4118    }
4119  }
4120}
4121
4122impl<'a> From<JSXExpr<'a>> for Node<'a> {
4123  fn from(node: JSXExpr<'a>) -> Node<'a> {
4124    match node {
4125      JSXExpr::JSXEmptyExpr(node) => node.into(),
4126      JSXExpr::Expr(node) => node.into(),
4127    }
4128  }
4129}
4130
4131fn get_view_for_jsxexpr<'a>(inner: &'a swc_ast::JSXExpr, bump: &'a Bump) -> JSXExpr<'a> {
4132  match inner {
4133    swc_ast::JSXExpr::JSXEmptyExpr(value) => JSXExpr::JSXEmptyExpr(get_view_for_jsxempty_expr(value, bump)),
4134    swc_ast::JSXExpr::Expr(value) => JSXExpr::Expr(get_view_for_expr(value, bump)),
4135  }
4136}
4137
4138fn set_parent_for_jsxexpr<'a>(node: &JSXExpr<'a>, parent: Node<'a>) {
4139  match node {
4140    JSXExpr::JSXEmptyExpr(value) => set_parent_for_jsxempty_expr(value, parent),
4141    JSXExpr::Expr(value) => set_parent_for_expr(value, parent),
4142  }
4143}
4144
4145/// Used for `obj` property of `JSXMemberExpr`.
4146#[derive(Copy, Clone)]
4147pub enum JSXObject<'a> {
4148  JSXMemberExpr(&'a JSXMemberExpr<'a>),
4149  Ident(&'a Ident<'a>),
4150}
4151
4152impl<'a> JSXObject<'a> {
4153  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4154    T::to(&self.into())
4155  }
4156
4157  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4158    let node: Node<'a> = self.into();
4159    if let Some(result) = T::to(&node) {
4160      result
4161    } else {
4162      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4163    }
4164  }
4165
4166  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4167    self.kind() == T::kind()
4168  }
4169  pub fn parent(&self) -> Node<'a> {
4170    NodeTrait::parent(self).unwrap()
4171  }
4172}
4173
4174impl<'a> SourceRanged for JSXObject<'a> {
4175  fn start(&self) -> SourcePos {
4176    match self {
4177      JSXObject::JSXMemberExpr(node) => node.start(),
4178      JSXObject::Ident(node) => node.start(),
4179    }
4180  }
4181  fn end(&self) -> SourcePos {
4182    match self {
4183      JSXObject::JSXMemberExpr(node) => node.end(),
4184      JSXObject::Ident(node) => node.end(),
4185    }
4186  }
4187}
4188
4189impl<'a> NodeTrait<'a> for JSXObject<'a> {
4190  fn parent(&self) -> Option<Node<'a>> {
4191    match self {
4192      JSXObject::JSXMemberExpr(node) => NodeTrait::parent(*node),
4193      JSXObject::Ident(node) => NodeTrait::parent(*node),
4194    }
4195  }
4196
4197  fn children(&self) -> Vec<Node<'a>> {
4198    match self {
4199      JSXObject::JSXMemberExpr(node) => node.children(),
4200      JSXObject::Ident(node) => node.children(),
4201    }
4202  }
4203
4204  fn as_node(&self) -> Node<'a> {
4205    match self {
4206      JSXObject::JSXMemberExpr(node) => node.as_node(),
4207      JSXObject::Ident(node) => node.as_node(),
4208    }
4209  }
4210
4211  fn kind(&self) -> NodeKind {
4212    match self {
4213      JSXObject::JSXMemberExpr(_) => NodeKind::JSXMemberExpr,
4214      JSXObject::Ident(_) => NodeKind::Ident,
4215    }
4216  }
4217}
4218
4219impl<'a> From<&JSXObject<'a>> for Node<'a> {
4220  fn from(node: &JSXObject<'a>) -> Node<'a> {
4221    match node {
4222      JSXObject::JSXMemberExpr(node) => (*node).into(),
4223      JSXObject::Ident(node) => (*node).into(),
4224    }
4225  }
4226}
4227
4228impl<'a> From<JSXObject<'a>> for Node<'a> {
4229  fn from(node: JSXObject<'a>) -> Node<'a> {
4230    match node {
4231      JSXObject::JSXMemberExpr(node) => node.into(),
4232      JSXObject::Ident(node) => node.into(),
4233    }
4234  }
4235}
4236
4237fn get_view_for_jsxobject<'a>(inner: &'a swc_ast::JSXObject, bump: &'a Bump) -> JSXObject<'a> {
4238  match inner {
4239    swc_ast::JSXObject::JSXMemberExpr(value) => JSXObject::JSXMemberExpr(get_view_for_jsxmember_expr(value, bump)),
4240    swc_ast::JSXObject::Ident(value) => JSXObject::Ident(get_view_for_ident(value, bump)),
4241  }
4242}
4243
4244fn set_parent_for_jsxobject<'a>(node: &JSXObject<'a>, parent: Node<'a>) {
4245  match node {
4246    JSXObject::JSXMemberExpr(value) => set_parent_for_jsxmember_expr(value, parent),
4247    JSXObject::Ident(value) => set_parent_for_ident(value, parent),
4248  }
4249}
4250
4251/// Either a private name or a public name.
4252#[derive(Copy, Clone)]
4253pub enum Key<'a> {
4254  Private(&'a PrivateName<'a>),
4255  Public(PropName<'a>),
4256}
4257
4258impl<'a> Key<'a> {
4259  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4260    T::to(&self.into())
4261  }
4262
4263  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4264    let node: Node<'a> = self.into();
4265    if let Some(result) = T::to(&node) {
4266      result
4267    } else {
4268      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4269    }
4270  }
4271
4272  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4273    self.kind() == T::kind()
4274  }
4275}
4276
4277impl<'a> SourceRanged for Key<'a> {
4278  fn start(&self) -> SourcePos {
4279    match self {
4280      Key::Private(node) => node.start(),
4281      Key::Public(node) => node.start(),
4282    }
4283  }
4284  fn end(&self) -> SourcePos {
4285    match self {
4286      Key::Private(node) => node.end(),
4287      Key::Public(node) => node.end(),
4288    }
4289  }
4290}
4291
4292impl<'a> NodeTrait<'a> for Key<'a> {
4293  fn parent(&self) -> Option<Node<'a>> {
4294    match self {
4295      Key::Private(node) => NodeTrait::parent(*node),
4296      Key::Public(node) => NodeTrait::parent(node),
4297    }
4298  }
4299
4300  fn children(&self) -> Vec<Node<'a>> {
4301    match self {
4302      Key::Private(node) => node.children(),
4303      Key::Public(node) => node.children(),
4304    }
4305  }
4306
4307  fn as_node(&self) -> Node<'a> {
4308    match self {
4309      Key::Private(node) => node.as_node(),
4310      Key::Public(node) => node.as_node(),
4311    }
4312  }
4313
4314  fn kind(&self) -> NodeKind {
4315    match self {
4316      Key::Private(_) => NodeKind::PrivateName,
4317      Key::Public(node) => node.kind(),
4318    }
4319  }
4320}
4321
4322impl<'a> From<&Key<'a>> for Node<'a> {
4323  fn from(node: &Key<'a>) -> Node<'a> {
4324    match node {
4325      Key::Private(node) => (*node).into(),
4326      Key::Public(node) => node.into(),
4327    }
4328  }
4329}
4330
4331impl<'a> From<Key<'a>> for Node<'a> {
4332  fn from(node: Key<'a>) -> Node<'a> {
4333    match node {
4334      Key::Private(node) => node.into(),
4335      Key::Public(node) => node.into(),
4336    }
4337  }
4338}
4339
4340fn get_view_for_key<'a>(inner: &'a swc_ast::Key, bump: &'a Bump) -> Key<'a> {
4341  match inner {
4342    swc_ast::Key::Private(value) => Key::Private(get_view_for_private_name(value, bump)),
4343    swc_ast::Key::Public(value) => Key::Public(get_view_for_prop_name(value, bump)),
4344  }
4345}
4346
4347fn set_parent_for_key<'a>(node: &Key<'a>, parent: Node<'a>) {
4348  match node {
4349    Key::Private(value) => set_parent_for_private_name(value, parent),
4350    Key::Public(value) => set_parent_for_prop_name(value, parent),
4351  }
4352}
4353
4354#[derive(Copy, Clone)]
4355pub enum Lit<'a> {
4356  Str(&'a Str<'a>),
4357  Bool(&'a Bool<'a>),
4358  Null(&'a Null<'a>),
4359  Num(&'a Number<'a>),
4360  BigInt(&'a BigInt<'a>),
4361  Regex(&'a Regex<'a>),
4362  JSXText(&'a JSXText<'a>),
4363}
4364
4365impl<'a> Lit<'a> {
4366  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4367    T::to(&self.into())
4368  }
4369
4370  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4371    let node: Node<'a> = self.into();
4372    if let Some(result) = T::to(&node) {
4373      result
4374    } else {
4375      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4376    }
4377  }
4378
4379  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4380    self.kind() == T::kind()
4381  }
4382  pub fn parent(&self) -> Node<'a> {
4383    NodeTrait::parent(self).unwrap()
4384  }
4385}
4386
4387impl<'a> SourceRanged for Lit<'a> {
4388  fn start(&self) -> SourcePos {
4389    match self {
4390      Lit::Str(node) => node.start(),
4391      Lit::Bool(node) => node.start(),
4392      Lit::Null(node) => node.start(),
4393      Lit::Num(node) => node.start(),
4394      Lit::BigInt(node) => node.start(),
4395      Lit::Regex(node) => node.start(),
4396      Lit::JSXText(node) => node.start(),
4397    }
4398  }
4399  fn end(&self) -> SourcePos {
4400    match self {
4401      Lit::Str(node) => node.end(),
4402      Lit::Bool(node) => node.end(),
4403      Lit::Null(node) => node.end(),
4404      Lit::Num(node) => node.end(),
4405      Lit::BigInt(node) => node.end(),
4406      Lit::Regex(node) => node.end(),
4407      Lit::JSXText(node) => node.end(),
4408    }
4409  }
4410}
4411
4412impl<'a> NodeTrait<'a> for Lit<'a> {
4413  fn parent(&self) -> Option<Node<'a>> {
4414    match self {
4415      Lit::Str(node) => NodeTrait::parent(*node),
4416      Lit::Bool(node) => NodeTrait::parent(*node),
4417      Lit::Null(node) => NodeTrait::parent(*node),
4418      Lit::Num(node) => NodeTrait::parent(*node),
4419      Lit::BigInt(node) => NodeTrait::parent(*node),
4420      Lit::Regex(node) => NodeTrait::parent(*node),
4421      Lit::JSXText(node) => NodeTrait::parent(*node),
4422    }
4423  }
4424
4425  fn children(&self) -> Vec<Node<'a>> {
4426    match self {
4427      Lit::Str(node) => node.children(),
4428      Lit::Bool(node) => node.children(),
4429      Lit::Null(node) => node.children(),
4430      Lit::Num(node) => node.children(),
4431      Lit::BigInt(node) => node.children(),
4432      Lit::Regex(node) => node.children(),
4433      Lit::JSXText(node) => node.children(),
4434    }
4435  }
4436
4437  fn as_node(&self) -> Node<'a> {
4438    match self {
4439      Lit::Str(node) => node.as_node(),
4440      Lit::Bool(node) => node.as_node(),
4441      Lit::Null(node) => node.as_node(),
4442      Lit::Num(node) => node.as_node(),
4443      Lit::BigInt(node) => node.as_node(),
4444      Lit::Regex(node) => node.as_node(),
4445      Lit::JSXText(node) => node.as_node(),
4446    }
4447  }
4448
4449  fn kind(&self) -> NodeKind {
4450    match self {
4451      Lit::Str(_) => NodeKind::Str,
4452      Lit::Bool(_) => NodeKind::Bool,
4453      Lit::Null(_) => NodeKind::Null,
4454      Lit::Num(_) => NodeKind::Number,
4455      Lit::BigInt(_) => NodeKind::BigInt,
4456      Lit::Regex(_) => NodeKind::Regex,
4457      Lit::JSXText(_) => NodeKind::JSXText,
4458    }
4459  }
4460}
4461
4462impl<'a> From<&Lit<'a>> for Node<'a> {
4463  fn from(node: &Lit<'a>) -> Node<'a> {
4464    match node {
4465      Lit::Str(node) => (*node).into(),
4466      Lit::Bool(node) => (*node).into(),
4467      Lit::Null(node) => (*node).into(),
4468      Lit::Num(node) => (*node).into(),
4469      Lit::BigInt(node) => (*node).into(),
4470      Lit::Regex(node) => (*node).into(),
4471      Lit::JSXText(node) => (*node).into(),
4472    }
4473  }
4474}
4475
4476impl<'a> From<Lit<'a>> for Node<'a> {
4477  fn from(node: Lit<'a>) -> Node<'a> {
4478    match node {
4479      Lit::Str(node) => node.into(),
4480      Lit::Bool(node) => node.into(),
4481      Lit::Null(node) => node.into(),
4482      Lit::Num(node) => node.into(),
4483      Lit::BigInt(node) => node.into(),
4484      Lit::Regex(node) => node.into(),
4485      Lit::JSXText(node) => node.into(),
4486    }
4487  }
4488}
4489
4490fn get_view_for_lit<'a>(inner: &'a swc_ast::Lit, bump: &'a Bump) -> Lit<'a> {
4491  match inner {
4492    swc_ast::Lit::Str(value) => Lit::Str(get_view_for_str(value, bump)),
4493    swc_ast::Lit::Bool(value) => Lit::Bool(get_view_for_bool(value, bump)),
4494    swc_ast::Lit::Null(value) => Lit::Null(get_view_for_null(value, bump)),
4495    swc_ast::Lit::Num(value) => Lit::Num(get_view_for_number(value, bump)),
4496    swc_ast::Lit::BigInt(value) => Lit::BigInt(get_view_for_big_int(value, bump)),
4497    swc_ast::Lit::Regex(value) => Lit::Regex(get_view_for_regex(value, bump)),
4498    swc_ast::Lit::JSXText(value) => Lit::JSXText(get_view_for_jsxtext(value, bump)),
4499  }
4500}
4501
4502fn set_parent_for_lit<'a>(node: &Lit<'a>, parent: Node<'a>) {
4503  match node {
4504    Lit::Str(value) => set_parent_for_str(value, parent),
4505    Lit::Bool(value) => set_parent_for_bool(value, parent),
4506    Lit::Null(value) => set_parent_for_null(value, parent),
4507    Lit::Num(value) => set_parent_for_number(value, parent),
4508    Lit::BigInt(value) => set_parent_for_big_int(value, parent),
4509    Lit::Regex(value) => set_parent_for_regex(value, parent),
4510    Lit::JSXText(value) => set_parent_for_jsxtext(value, parent),
4511  }
4512}
4513
4514#[derive(Copy, Clone)]
4515pub enum MemberProp<'a> {
4516  Ident(&'a IdentName<'a>),
4517  PrivateName(&'a PrivateName<'a>),
4518  Computed(&'a ComputedPropName<'a>),
4519}
4520
4521impl<'a> MemberProp<'a> {
4522  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4523    T::to(&self.into())
4524  }
4525
4526  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4527    let node: Node<'a> = self.into();
4528    if let Some(result) = T::to(&node) {
4529      result
4530    } else {
4531      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4532    }
4533  }
4534
4535  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4536    self.kind() == T::kind()
4537  }
4538  pub fn parent(&self) -> Node<'a> {
4539    NodeTrait::parent(self).unwrap()
4540  }
4541}
4542
4543impl<'a> SourceRanged for MemberProp<'a> {
4544  fn start(&self) -> SourcePos {
4545    match self {
4546      MemberProp::Ident(node) => node.start(),
4547      MemberProp::PrivateName(node) => node.start(),
4548      MemberProp::Computed(node) => node.start(),
4549    }
4550  }
4551  fn end(&self) -> SourcePos {
4552    match self {
4553      MemberProp::Ident(node) => node.end(),
4554      MemberProp::PrivateName(node) => node.end(),
4555      MemberProp::Computed(node) => node.end(),
4556    }
4557  }
4558}
4559
4560impl<'a> NodeTrait<'a> for MemberProp<'a> {
4561  fn parent(&self) -> Option<Node<'a>> {
4562    match self {
4563      MemberProp::Ident(node) => NodeTrait::parent(*node),
4564      MemberProp::PrivateName(node) => NodeTrait::parent(*node),
4565      MemberProp::Computed(node) => NodeTrait::parent(*node),
4566    }
4567  }
4568
4569  fn children(&self) -> Vec<Node<'a>> {
4570    match self {
4571      MemberProp::Ident(node) => node.children(),
4572      MemberProp::PrivateName(node) => node.children(),
4573      MemberProp::Computed(node) => node.children(),
4574    }
4575  }
4576
4577  fn as_node(&self) -> Node<'a> {
4578    match self {
4579      MemberProp::Ident(node) => node.as_node(),
4580      MemberProp::PrivateName(node) => node.as_node(),
4581      MemberProp::Computed(node) => node.as_node(),
4582    }
4583  }
4584
4585  fn kind(&self) -> NodeKind {
4586    match self {
4587      MemberProp::Ident(_) => NodeKind::IdentName,
4588      MemberProp::PrivateName(_) => NodeKind::PrivateName,
4589      MemberProp::Computed(_) => NodeKind::ComputedPropName,
4590    }
4591  }
4592}
4593
4594impl<'a> From<&MemberProp<'a>> for Node<'a> {
4595  fn from(node: &MemberProp<'a>) -> Node<'a> {
4596    match node {
4597      MemberProp::Ident(node) => (*node).into(),
4598      MemberProp::PrivateName(node) => (*node).into(),
4599      MemberProp::Computed(node) => (*node).into(),
4600    }
4601  }
4602}
4603
4604impl<'a> From<MemberProp<'a>> for Node<'a> {
4605  fn from(node: MemberProp<'a>) -> Node<'a> {
4606    match node {
4607      MemberProp::Ident(node) => node.into(),
4608      MemberProp::PrivateName(node) => node.into(),
4609      MemberProp::Computed(node) => node.into(),
4610    }
4611  }
4612}
4613
4614fn get_view_for_member_prop<'a>(inner: &'a swc_ast::MemberProp, bump: &'a Bump) -> MemberProp<'a> {
4615  match inner {
4616    swc_ast::MemberProp::Ident(value) => MemberProp::Ident(get_view_for_ident_name(value, bump)),
4617    swc_ast::MemberProp::PrivateName(value) => MemberProp::PrivateName(get_view_for_private_name(value, bump)),
4618    swc_ast::MemberProp::Computed(value) => MemberProp::Computed(get_view_for_computed_prop_name(value, bump)),
4619  }
4620}
4621
4622fn set_parent_for_member_prop<'a>(node: &MemberProp<'a>, parent: Node<'a>) {
4623  match node {
4624    MemberProp::Ident(value) => set_parent_for_ident_name(value, parent),
4625    MemberProp::PrivateName(value) => set_parent_for_private_name(value, parent),
4626    MemberProp::Computed(value) => set_parent_for_computed_prop_name(value, parent),
4627  }
4628}
4629
4630#[derive(Copy, Clone)]
4631pub enum ModuleDecl<'a> {
4632  Import(&'a ImportDecl<'a>),
4633  ExportDecl(&'a ExportDecl<'a>),
4634  ExportNamed(&'a NamedExport<'a>),
4635  ExportDefaultDecl(&'a ExportDefaultDecl<'a>),
4636  ExportDefaultExpr(&'a ExportDefaultExpr<'a>),
4637  ExportAll(&'a ExportAll<'a>),
4638  TsImportEquals(&'a TsImportEqualsDecl<'a>),
4639  TsExportAssignment(&'a TsExportAssignment<'a>),
4640  TsNamespaceExport(&'a TsNamespaceExportDecl<'a>),
4641}
4642
4643impl<'a> ModuleDecl<'a> {
4644  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4645    T::to(&self.into())
4646  }
4647
4648  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4649    let node: Node<'a> = self.into();
4650    if let Some(result) = T::to(&node) {
4651      result
4652    } else {
4653      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4654    }
4655  }
4656
4657  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4658    self.kind() == T::kind()
4659  }
4660  pub fn parent(&self) -> Node<'a> {
4661    NodeTrait::parent(self).unwrap()
4662  }
4663}
4664
4665impl<'a> SourceRanged for ModuleDecl<'a> {
4666  fn start(&self) -> SourcePos {
4667    match self {
4668      ModuleDecl::Import(node) => node.start(),
4669      ModuleDecl::ExportDecl(node) => node.start(),
4670      ModuleDecl::ExportNamed(node) => node.start(),
4671      ModuleDecl::ExportDefaultDecl(node) => node.start(),
4672      ModuleDecl::ExportDefaultExpr(node) => node.start(),
4673      ModuleDecl::ExportAll(node) => node.start(),
4674      ModuleDecl::TsImportEquals(node) => node.start(),
4675      ModuleDecl::TsExportAssignment(node) => node.start(),
4676      ModuleDecl::TsNamespaceExport(node) => node.start(),
4677    }
4678  }
4679  fn end(&self) -> SourcePos {
4680    match self {
4681      ModuleDecl::Import(node) => node.end(),
4682      ModuleDecl::ExportDecl(node) => node.end(),
4683      ModuleDecl::ExportNamed(node) => node.end(),
4684      ModuleDecl::ExportDefaultDecl(node) => node.end(),
4685      ModuleDecl::ExportDefaultExpr(node) => node.end(),
4686      ModuleDecl::ExportAll(node) => node.end(),
4687      ModuleDecl::TsImportEquals(node) => node.end(),
4688      ModuleDecl::TsExportAssignment(node) => node.end(),
4689      ModuleDecl::TsNamespaceExport(node) => node.end(),
4690    }
4691  }
4692}
4693
4694impl<'a> NodeTrait<'a> for ModuleDecl<'a> {
4695  fn parent(&self) -> Option<Node<'a>> {
4696    match self {
4697      ModuleDecl::Import(node) => NodeTrait::parent(*node),
4698      ModuleDecl::ExportDecl(node) => NodeTrait::parent(*node),
4699      ModuleDecl::ExportNamed(node) => NodeTrait::parent(*node),
4700      ModuleDecl::ExportDefaultDecl(node) => NodeTrait::parent(*node),
4701      ModuleDecl::ExportDefaultExpr(node) => NodeTrait::parent(*node),
4702      ModuleDecl::ExportAll(node) => NodeTrait::parent(*node),
4703      ModuleDecl::TsImportEquals(node) => NodeTrait::parent(*node),
4704      ModuleDecl::TsExportAssignment(node) => NodeTrait::parent(*node),
4705      ModuleDecl::TsNamespaceExport(node) => NodeTrait::parent(*node),
4706    }
4707  }
4708
4709  fn children(&self) -> Vec<Node<'a>> {
4710    match self {
4711      ModuleDecl::Import(node) => node.children(),
4712      ModuleDecl::ExportDecl(node) => node.children(),
4713      ModuleDecl::ExportNamed(node) => node.children(),
4714      ModuleDecl::ExportDefaultDecl(node) => node.children(),
4715      ModuleDecl::ExportDefaultExpr(node) => node.children(),
4716      ModuleDecl::ExportAll(node) => node.children(),
4717      ModuleDecl::TsImportEquals(node) => node.children(),
4718      ModuleDecl::TsExportAssignment(node) => node.children(),
4719      ModuleDecl::TsNamespaceExport(node) => node.children(),
4720    }
4721  }
4722
4723  fn as_node(&self) -> Node<'a> {
4724    match self {
4725      ModuleDecl::Import(node) => node.as_node(),
4726      ModuleDecl::ExportDecl(node) => node.as_node(),
4727      ModuleDecl::ExportNamed(node) => node.as_node(),
4728      ModuleDecl::ExportDefaultDecl(node) => node.as_node(),
4729      ModuleDecl::ExportDefaultExpr(node) => node.as_node(),
4730      ModuleDecl::ExportAll(node) => node.as_node(),
4731      ModuleDecl::TsImportEquals(node) => node.as_node(),
4732      ModuleDecl::TsExportAssignment(node) => node.as_node(),
4733      ModuleDecl::TsNamespaceExport(node) => node.as_node(),
4734    }
4735  }
4736
4737  fn kind(&self) -> NodeKind {
4738    match self {
4739      ModuleDecl::Import(_) => NodeKind::ImportDecl,
4740      ModuleDecl::ExportDecl(_) => NodeKind::ExportDecl,
4741      ModuleDecl::ExportNamed(_) => NodeKind::NamedExport,
4742      ModuleDecl::ExportDefaultDecl(_) => NodeKind::ExportDefaultDecl,
4743      ModuleDecl::ExportDefaultExpr(_) => NodeKind::ExportDefaultExpr,
4744      ModuleDecl::ExportAll(_) => NodeKind::ExportAll,
4745      ModuleDecl::TsImportEquals(_) => NodeKind::TsImportEqualsDecl,
4746      ModuleDecl::TsExportAssignment(_) => NodeKind::TsExportAssignment,
4747      ModuleDecl::TsNamespaceExport(_) => NodeKind::TsNamespaceExportDecl,
4748    }
4749  }
4750}
4751
4752impl<'a> From<&ModuleDecl<'a>> for Node<'a> {
4753  fn from(node: &ModuleDecl<'a>) -> Node<'a> {
4754    match node {
4755      ModuleDecl::Import(node) => (*node).into(),
4756      ModuleDecl::ExportDecl(node) => (*node).into(),
4757      ModuleDecl::ExportNamed(node) => (*node).into(),
4758      ModuleDecl::ExportDefaultDecl(node) => (*node).into(),
4759      ModuleDecl::ExportDefaultExpr(node) => (*node).into(),
4760      ModuleDecl::ExportAll(node) => (*node).into(),
4761      ModuleDecl::TsImportEquals(node) => (*node).into(),
4762      ModuleDecl::TsExportAssignment(node) => (*node).into(),
4763      ModuleDecl::TsNamespaceExport(node) => (*node).into(),
4764    }
4765  }
4766}
4767
4768impl<'a> From<ModuleDecl<'a>> for Node<'a> {
4769  fn from(node: ModuleDecl<'a>) -> Node<'a> {
4770    match node {
4771      ModuleDecl::Import(node) => node.into(),
4772      ModuleDecl::ExportDecl(node) => node.into(),
4773      ModuleDecl::ExportNamed(node) => node.into(),
4774      ModuleDecl::ExportDefaultDecl(node) => node.into(),
4775      ModuleDecl::ExportDefaultExpr(node) => node.into(),
4776      ModuleDecl::ExportAll(node) => node.into(),
4777      ModuleDecl::TsImportEquals(node) => node.into(),
4778      ModuleDecl::TsExportAssignment(node) => node.into(),
4779      ModuleDecl::TsNamespaceExport(node) => node.into(),
4780    }
4781  }
4782}
4783
4784fn get_view_for_module_decl<'a>(inner: &'a swc_ast::ModuleDecl, bump: &'a Bump) -> ModuleDecl<'a> {
4785  match inner {
4786    swc_ast::ModuleDecl::Import(value) => ModuleDecl::Import(get_view_for_import_decl(value, bump)),
4787    swc_ast::ModuleDecl::ExportDecl(value) => ModuleDecl::ExportDecl(get_view_for_export_decl(value, bump)),
4788    swc_ast::ModuleDecl::ExportNamed(value) => ModuleDecl::ExportNamed(get_view_for_named_export(value, bump)),
4789    swc_ast::ModuleDecl::ExportDefaultDecl(value) => ModuleDecl::ExportDefaultDecl(get_view_for_export_default_decl(value, bump)),
4790    swc_ast::ModuleDecl::ExportDefaultExpr(value) => ModuleDecl::ExportDefaultExpr(get_view_for_export_default_expr(value, bump)),
4791    swc_ast::ModuleDecl::ExportAll(value) => ModuleDecl::ExportAll(get_view_for_export_all(value, bump)),
4792    swc_ast::ModuleDecl::TsImportEquals(value) => ModuleDecl::TsImportEquals(get_view_for_ts_import_equals_decl(value, bump)),
4793    swc_ast::ModuleDecl::TsExportAssignment(value) => ModuleDecl::TsExportAssignment(get_view_for_ts_export_assignment(value, bump)),
4794    swc_ast::ModuleDecl::TsNamespaceExport(value) => ModuleDecl::TsNamespaceExport(get_view_for_ts_namespace_export_decl(value, bump)),
4795  }
4796}
4797
4798fn set_parent_for_module_decl<'a>(node: &ModuleDecl<'a>, parent: Node<'a>) {
4799  match node {
4800    ModuleDecl::Import(value) => set_parent_for_import_decl(value, parent),
4801    ModuleDecl::ExportDecl(value) => set_parent_for_export_decl(value, parent),
4802    ModuleDecl::ExportNamed(value) => set_parent_for_named_export(value, parent),
4803    ModuleDecl::ExportDefaultDecl(value) => set_parent_for_export_default_decl(value, parent),
4804    ModuleDecl::ExportDefaultExpr(value) => set_parent_for_export_default_expr(value, parent),
4805    ModuleDecl::ExportAll(value) => set_parent_for_export_all(value, parent),
4806    ModuleDecl::TsImportEquals(value) => set_parent_for_ts_import_equals_decl(value, parent),
4807    ModuleDecl::TsExportAssignment(value) => set_parent_for_ts_export_assignment(value, parent),
4808    ModuleDecl::TsNamespaceExport(value) => set_parent_for_ts_namespace_export_decl(value, parent),
4809  }
4810}
4811
4812#[derive(Copy, Clone)]
4813pub enum ModuleExportName<'a> {
4814  Ident(&'a Ident<'a>),
4815  Str(&'a Str<'a>),
4816}
4817
4818impl<'a> ModuleExportName<'a> {
4819  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4820    T::to(&self.into())
4821  }
4822
4823  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4824    let node: Node<'a> = self.into();
4825    if let Some(result) = T::to(&node) {
4826      result
4827    } else {
4828      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4829    }
4830  }
4831
4832  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4833    self.kind() == T::kind()
4834  }
4835  pub fn parent(&self) -> Node<'a> {
4836    NodeTrait::parent(self).unwrap()
4837  }
4838}
4839
4840impl<'a> SourceRanged for ModuleExportName<'a> {
4841  fn start(&self) -> SourcePos {
4842    match self {
4843      ModuleExportName::Ident(node) => node.start(),
4844      ModuleExportName::Str(node) => node.start(),
4845    }
4846  }
4847  fn end(&self) -> SourcePos {
4848    match self {
4849      ModuleExportName::Ident(node) => node.end(),
4850      ModuleExportName::Str(node) => node.end(),
4851    }
4852  }
4853}
4854
4855impl<'a> NodeTrait<'a> for ModuleExportName<'a> {
4856  fn parent(&self) -> Option<Node<'a>> {
4857    match self {
4858      ModuleExportName::Ident(node) => NodeTrait::parent(*node),
4859      ModuleExportName::Str(node) => NodeTrait::parent(*node),
4860    }
4861  }
4862
4863  fn children(&self) -> Vec<Node<'a>> {
4864    match self {
4865      ModuleExportName::Ident(node) => node.children(),
4866      ModuleExportName::Str(node) => node.children(),
4867    }
4868  }
4869
4870  fn as_node(&self) -> Node<'a> {
4871    match self {
4872      ModuleExportName::Ident(node) => node.as_node(),
4873      ModuleExportName::Str(node) => node.as_node(),
4874    }
4875  }
4876
4877  fn kind(&self) -> NodeKind {
4878    match self {
4879      ModuleExportName::Ident(_) => NodeKind::Ident,
4880      ModuleExportName::Str(_) => NodeKind::Str,
4881    }
4882  }
4883}
4884
4885impl<'a> From<&ModuleExportName<'a>> for Node<'a> {
4886  fn from(node: &ModuleExportName<'a>) -> Node<'a> {
4887    match node {
4888      ModuleExportName::Ident(node) => (*node).into(),
4889      ModuleExportName::Str(node) => (*node).into(),
4890    }
4891  }
4892}
4893
4894impl<'a> From<ModuleExportName<'a>> for Node<'a> {
4895  fn from(node: ModuleExportName<'a>) -> Node<'a> {
4896    match node {
4897      ModuleExportName::Ident(node) => node.into(),
4898      ModuleExportName::Str(node) => node.into(),
4899    }
4900  }
4901}
4902
4903fn get_view_for_module_export_name<'a>(inner: &'a swc_ast::ModuleExportName, bump: &'a Bump) -> ModuleExportName<'a> {
4904  match inner {
4905    swc_ast::ModuleExportName::Ident(value) => ModuleExportName::Ident(get_view_for_ident(value, bump)),
4906    swc_ast::ModuleExportName::Str(value) => ModuleExportName::Str(get_view_for_str(value, bump)),
4907  }
4908}
4909
4910fn set_parent_for_module_export_name<'a>(node: &ModuleExportName<'a>, parent: Node<'a>) {
4911  match node {
4912    ModuleExportName::Ident(value) => set_parent_for_ident(value, parent),
4913    ModuleExportName::Str(value) => set_parent_for_str(value, parent),
4914  }
4915}
4916
4917#[derive(Copy, Clone)]
4918pub enum ModuleItem<'a> {
4919  ModuleDecl(ModuleDecl<'a>),
4920  Stmt(Stmt<'a>),
4921}
4922
4923impl<'a> ModuleItem<'a> {
4924  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4925    T::to(&self.into())
4926  }
4927
4928  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4929    let node: Node<'a> = self.into();
4930    if let Some(result) = T::to(&node) {
4931      result
4932    } else {
4933      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4934    }
4935  }
4936
4937  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4938    self.kind() == T::kind()
4939  }
4940}
4941
4942impl<'a> SourceRanged for ModuleItem<'a> {
4943  fn start(&self) -> SourcePos {
4944    match self {
4945      ModuleItem::ModuleDecl(node) => node.start(),
4946      ModuleItem::Stmt(node) => node.start(),
4947    }
4948  }
4949  fn end(&self) -> SourcePos {
4950    match self {
4951      ModuleItem::ModuleDecl(node) => node.end(),
4952      ModuleItem::Stmt(node) => node.end(),
4953    }
4954  }
4955}
4956
4957impl<'a> NodeTrait<'a> for ModuleItem<'a> {
4958  fn parent(&self) -> Option<Node<'a>> {
4959    match self {
4960      ModuleItem::ModuleDecl(node) => NodeTrait::parent(node),
4961      ModuleItem::Stmt(node) => NodeTrait::parent(node),
4962    }
4963  }
4964
4965  fn children(&self) -> Vec<Node<'a>> {
4966    match self {
4967      ModuleItem::ModuleDecl(node) => node.children(),
4968      ModuleItem::Stmt(node) => node.children(),
4969    }
4970  }
4971
4972  fn as_node(&self) -> Node<'a> {
4973    match self {
4974      ModuleItem::ModuleDecl(node) => node.as_node(),
4975      ModuleItem::Stmt(node) => node.as_node(),
4976    }
4977  }
4978
4979  fn kind(&self) -> NodeKind {
4980    match self {
4981      ModuleItem::ModuleDecl(node) => node.kind(),
4982      ModuleItem::Stmt(node) => node.kind(),
4983    }
4984  }
4985}
4986
4987impl<'a> From<&ModuleItem<'a>> for Node<'a> {
4988  fn from(node: &ModuleItem<'a>) -> Node<'a> {
4989    match node {
4990      ModuleItem::ModuleDecl(node) => node.into(),
4991      ModuleItem::Stmt(node) => node.into(),
4992    }
4993  }
4994}
4995
4996impl<'a> From<ModuleItem<'a>> for Node<'a> {
4997  fn from(node: ModuleItem<'a>) -> Node<'a> {
4998    match node {
4999      ModuleItem::ModuleDecl(node) => node.into(),
5000      ModuleItem::Stmt(node) => node.into(),
5001    }
5002  }
5003}
5004
5005fn get_view_for_module_item<'a>(inner: &'a swc_ast::ModuleItem, bump: &'a Bump) -> ModuleItem<'a> {
5006  match inner {
5007    swc_ast::ModuleItem::ModuleDecl(value) => ModuleItem::ModuleDecl(get_view_for_module_decl(value, bump)),
5008    swc_ast::ModuleItem::Stmt(value) => ModuleItem::Stmt(get_view_for_stmt(value, bump)),
5009  }
5010}
5011
5012fn set_parent_for_module_item<'a>(node: &ModuleItem<'a>, parent: Node<'a>) {
5013  match node {
5014    ModuleItem::ModuleDecl(value) => set_parent_for_module_decl(value, parent),
5015    ModuleItem::Stmt(value) => set_parent_for_stmt(value, parent),
5016  }
5017}
5018
5019#[derive(Copy, Clone)]
5020pub enum ObjectPatProp<'a> {
5021  KeyValue(&'a KeyValuePatProp<'a>),
5022  Assign(&'a AssignPatProp<'a>),
5023  Rest(&'a RestPat<'a>),
5024}
5025
5026impl<'a> ObjectPatProp<'a> {
5027  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5028    T::to(&self.into())
5029  }
5030
5031  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5032    let node: Node<'a> = self.into();
5033    if let Some(result) = T::to(&node) {
5034      result
5035    } else {
5036      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5037    }
5038  }
5039
5040  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5041    self.kind() == T::kind()
5042  }
5043  pub fn parent(&self) -> Node<'a> {
5044    NodeTrait::parent(self).unwrap()
5045  }
5046}
5047
5048impl<'a> SourceRanged for ObjectPatProp<'a> {
5049  fn start(&self) -> SourcePos {
5050    match self {
5051      ObjectPatProp::KeyValue(node) => node.start(),
5052      ObjectPatProp::Assign(node) => node.start(),
5053      ObjectPatProp::Rest(node) => node.start(),
5054    }
5055  }
5056  fn end(&self) -> SourcePos {
5057    match self {
5058      ObjectPatProp::KeyValue(node) => node.end(),
5059      ObjectPatProp::Assign(node) => node.end(),
5060      ObjectPatProp::Rest(node) => node.end(),
5061    }
5062  }
5063}
5064
5065impl<'a> NodeTrait<'a> for ObjectPatProp<'a> {
5066  fn parent(&self) -> Option<Node<'a>> {
5067    match self {
5068      ObjectPatProp::KeyValue(node) => NodeTrait::parent(*node),
5069      ObjectPatProp::Assign(node) => NodeTrait::parent(*node),
5070      ObjectPatProp::Rest(node) => NodeTrait::parent(*node),
5071    }
5072  }
5073
5074  fn children(&self) -> Vec<Node<'a>> {
5075    match self {
5076      ObjectPatProp::KeyValue(node) => node.children(),
5077      ObjectPatProp::Assign(node) => node.children(),
5078      ObjectPatProp::Rest(node) => node.children(),
5079    }
5080  }
5081
5082  fn as_node(&self) -> Node<'a> {
5083    match self {
5084      ObjectPatProp::KeyValue(node) => node.as_node(),
5085      ObjectPatProp::Assign(node) => node.as_node(),
5086      ObjectPatProp::Rest(node) => node.as_node(),
5087    }
5088  }
5089
5090  fn kind(&self) -> NodeKind {
5091    match self {
5092      ObjectPatProp::KeyValue(_) => NodeKind::KeyValuePatProp,
5093      ObjectPatProp::Assign(_) => NodeKind::AssignPatProp,
5094      ObjectPatProp::Rest(_) => NodeKind::RestPat,
5095    }
5096  }
5097}
5098
5099impl<'a> From<&ObjectPatProp<'a>> for Node<'a> {
5100  fn from(node: &ObjectPatProp<'a>) -> Node<'a> {
5101    match node {
5102      ObjectPatProp::KeyValue(node) => (*node).into(),
5103      ObjectPatProp::Assign(node) => (*node).into(),
5104      ObjectPatProp::Rest(node) => (*node).into(),
5105    }
5106  }
5107}
5108
5109impl<'a> From<ObjectPatProp<'a>> for Node<'a> {
5110  fn from(node: ObjectPatProp<'a>) -> Node<'a> {
5111    match node {
5112      ObjectPatProp::KeyValue(node) => node.into(),
5113      ObjectPatProp::Assign(node) => node.into(),
5114      ObjectPatProp::Rest(node) => node.into(),
5115    }
5116  }
5117}
5118
5119fn get_view_for_object_pat_prop<'a>(inner: &'a swc_ast::ObjectPatProp, bump: &'a Bump) -> ObjectPatProp<'a> {
5120  match inner {
5121    swc_ast::ObjectPatProp::KeyValue(value) => ObjectPatProp::KeyValue(get_view_for_key_value_pat_prop(value, bump)),
5122    swc_ast::ObjectPatProp::Assign(value) => ObjectPatProp::Assign(get_view_for_assign_pat_prop(value, bump)),
5123    swc_ast::ObjectPatProp::Rest(value) => ObjectPatProp::Rest(get_view_for_rest_pat(value, bump)),
5124  }
5125}
5126
5127fn set_parent_for_object_pat_prop<'a>(node: &ObjectPatProp<'a>, parent: Node<'a>) {
5128  match node {
5129    ObjectPatProp::KeyValue(value) => set_parent_for_key_value_pat_prop(value, parent),
5130    ObjectPatProp::Assign(value) => set_parent_for_assign_pat_prop(value, parent),
5131    ObjectPatProp::Rest(value) => set_parent_for_rest_pat(value, parent),
5132  }
5133}
5134
5135#[derive(Copy, Clone)]
5136pub enum OptChainBase<'a> {
5137  Member(&'a MemberExpr<'a>),
5138  Call(&'a OptCall<'a>),
5139}
5140
5141impl<'a> OptChainBase<'a> {
5142  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5143    T::to(&self.into())
5144  }
5145
5146  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5147    let node: Node<'a> = self.into();
5148    if let Some(result) = T::to(&node) {
5149      result
5150    } else {
5151      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5152    }
5153  }
5154
5155  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5156    self.kind() == T::kind()
5157  }
5158  pub fn parent(&self) -> Node<'a> {
5159    NodeTrait::parent(self).unwrap()
5160  }
5161}
5162
5163impl<'a> SourceRanged for OptChainBase<'a> {
5164  fn start(&self) -> SourcePos {
5165    match self {
5166      OptChainBase::Member(node) => node.start(),
5167      OptChainBase::Call(node) => node.start(),
5168    }
5169  }
5170  fn end(&self) -> SourcePos {
5171    match self {
5172      OptChainBase::Member(node) => node.end(),
5173      OptChainBase::Call(node) => node.end(),
5174    }
5175  }
5176}
5177
5178impl<'a> NodeTrait<'a> for OptChainBase<'a> {
5179  fn parent(&self) -> Option<Node<'a>> {
5180    match self {
5181      OptChainBase::Member(node) => NodeTrait::parent(*node),
5182      OptChainBase::Call(node) => NodeTrait::parent(*node),
5183    }
5184  }
5185
5186  fn children(&self) -> Vec<Node<'a>> {
5187    match self {
5188      OptChainBase::Member(node) => node.children(),
5189      OptChainBase::Call(node) => node.children(),
5190    }
5191  }
5192
5193  fn as_node(&self) -> Node<'a> {
5194    match self {
5195      OptChainBase::Member(node) => node.as_node(),
5196      OptChainBase::Call(node) => node.as_node(),
5197    }
5198  }
5199
5200  fn kind(&self) -> NodeKind {
5201    match self {
5202      OptChainBase::Member(_) => NodeKind::MemberExpr,
5203      OptChainBase::Call(_) => NodeKind::OptCall,
5204    }
5205  }
5206}
5207
5208impl<'a> From<&OptChainBase<'a>> for Node<'a> {
5209  fn from(node: &OptChainBase<'a>) -> Node<'a> {
5210    match node {
5211      OptChainBase::Member(node) => (*node).into(),
5212      OptChainBase::Call(node) => (*node).into(),
5213    }
5214  }
5215}
5216
5217impl<'a> From<OptChainBase<'a>> for Node<'a> {
5218  fn from(node: OptChainBase<'a>) -> Node<'a> {
5219    match node {
5220      OptChainBase::Member(node) => node.into(),
5221      OptChainBase::Call(node) => node.into(),
5222    }
5223  }
5224}
5225
5226fn get_view_for_opt_chain_base<'a>(inner: &'a swc_ast::OptChainBase, bump: &'a Bump) -> OptChainBase<'a> {
5227  match inner {
5228    swc_ast::OptChainBase::Member(value) => OptChainBase::Member(get_view_for_member_expr(value, bump)),
5229    swc_ast::OptChainBase::Call(value) => OptChainBase::Call(get_view_for_opt_call(value, bump)),
5230  }
5231}
5232
5233fn set_parent_for_opt_chain_base<'a>(node: &OptChainBase<'a>, parent: Node<'a>) {
5234  match node {
5235    OptChainBase::Member(value) => set_parent_for_member_expr(value, parent),
5236    OptChainBase::Call(value) => set_parent_for_opt_call(value, parent),
5237  }
5238}
5239
5240#[derive(Copy, Clone)]
5241pub enum ParamOrTsParamProp<'a> {
5242  TsParamProp(&'a TsParamProp<'a>),
5243  Param(&'a Param<'a>),
5244}
5245
5246impl<'a> ParamOrTsParamProp<'a> {
5247  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5248    T::to(&self.into())
5249  }
5250
5251  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5252    let node: Node<'a> = self.into();
5253    if let Some(result) = T::to(&node) {
5254      result
5255    } else {
5256      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5257    }
5258  }
5259
5260  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5261    self.kind() == T::kind()
5262  }
5263  pub fn parent(&self) -> Node<'a> {
5264    NodeTrait::parent(self).unwrap()
5265  }
5266}
5267
5268impl<'a> SourceRanged for ParamOrTsParamProp<'a> {
5269  fn start(&self) -> SourcePos {
5270    match self {
5271      ParamOrTsParamProp::TsParamProp(node) => node.start(),
5272      ParamOrTsParamProp::Param(node) => node.start(),
5273    }
5274  }
5275  fn end(&self) -> SourcePos {
5276    match self {
5277      ParamOrTsParamProp::TsParamProp(node) => node.end(),
5278      ParamOrTsParamProp::Param(node) => node.end(),
5279    }
5280  }
5281}
5282
5283impl<'a> NodeTrait<'a> for ParamOrTsParamProp<'a> {
5284  fn parent(&self) -> Option<Node<'a>> {
5285    match self {
5286      ParamOrTsParamProp::TsParamProp(node) => NodeTrait::parent(*node),
5287      ParamOrTsParamProp::Param(node) => NodeTrait::parent(*node),
5288    }
5289  }
5290
5291  fn children(&self) -> Vec<Node<'a>> {
5292    match self {
5293      ParamOrTsParamProp::TsParamProp(node) => node.children(),
5294      ParamOrTsParamProp::Param(node) => node.children(),
5295    }
5296  }
5297
5298  fn as_node(&self) -> Node<'a> {
5299    match self {
5300      ParamOrTsParamProp::TsParamProp(node) => node.as_node(),
5301      ParamOrTsParamProp::Param(node) => node.as_node(),
5302    }
5303  }
5304
5305  fn kind(&self) -> NodeKind {
5306    match self {
5307      ParamOrTsParamProp::TsParamProp(_) => NodeKind::TsParamProp,
5308      ParamOrTsParamProp::Param(_) => NodeKind::Param,
5309    }
5310  }
5311}
5312
5313impl<'a> From<&ParamOrTsParamProp<'a>> for Node<'a> {
5314  fn from(node: &ParamOrTsParamProp<'a>) -> Node<'a> {
5315    match node {
5316      ParamOrTsParamProp::TsParamProp(node) => (*node).into(),
5317      ParamOrTsParamProp::Param(node) => (*node).into(),
5318    }
5319  }
5320}
5321
5322impl<'a> From<ParamOrTsParamProp<'a>> for Node<'a> {
5323  fn from(node: ParamOrTsParamProp<'a>) -> Node<'a> {
5324    match node {
5325      ParamOrTsParamProp::TsParamProp(node) => node.into(),
5326      ParamOrTsParamProp::Param(node) => node.into(),
5327    }
5328  }
5329}
5330
5331fn get_view_for_param_or_ts_param_prop<'a>(inner: &'a swc_ast::ParamOrTsParamProp, bump: &'a Bump) -> ParamOrTsParamProp<'a> {
5332  match inner {
5333    swc_ast::ParamOrTsParamProp::TsParamProp(value) => ParamOrTsParamProp::TsParamProp(get_view_for_ts_param_prop(value, bump)),
5334    swc_ast::ParamOrTsParamProp::Param(value) => ParamOrTsParamProp::Param(get_view_for_param(value, bump)),
5335  }
5336}
5337
5338fn set_parent_for_param_or_ts_param_prop<'a>(node: &ParamOrTsParamProp<'a>, parent: Node<'a>) {
5339  match node {
5340    ParamOrTsParamProp::TsParamProp(value) => set_parent_for_ts_param_prop(value, parent),
5341    ParamOrTsParamProp::Param(value) => set_parent_for_param(value, parent),
5342  }
5343}
5344
5345#[derive(Copy, Clone)]
5346pub enum Pat<'a> {
5347  Ident(&'a BindingIdent<'a>),
5348  Array(&'a ArrayPat<'a>),
5349  Rest(&'a RestPat<'a>),
5350  Object(&'a ObjectPat<'a>),
5351  Assign(&'a AssignPat<'a>),
5352  Invalid(&'a Invalid<'a>),
5353  /// Only for for-in / for-of loops. This is *syntactically* valid.
5354  Expr(Expr<'a>),
5355}
5356
5357impl<'a> Pat<'a> {
5358  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5359    T::to(&self.into())
5360  }
5361
5362  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5363    let node: Node<'a> = self.into();
5364    if let Some(result) = T::to(&node) {
5365      result
5366    } else {
5367      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5368    }
5369  }
5370
5371  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5372    self.kind() == T::kind()
5373  }
5374}
5375
5376impl<'a> SourceRanged for Pat<'a> {
5377  fn start(&self) -> SourcePos {
5378    match self {
5379      Pat::Ident(node) => node.start(),
5380      Pat::Array(node) => node.start(),
5381      Pat::Rest(node) => node.start(),
5382      Pat::Object(node) => node.start(),
5383      Pat::Assign(node) => node.start(),
5384      Pat::Invalid(node) => node.start(),
5385      Pat::Expr(node) => node.start(),
5386    }
5387  }
5388  fn end(&self) -> SourcePos {
5389    match self {
5390      Pat::Ident(node) => node.end(),
5391      Pat::Array(node) => node.end(),
5392      Pat::Rest(node) => node.end(),
5393      Pat::Object(node) => node.end(),
5394      Pat::Assign(node) => node.end(),
5395      Pat::Invalid(node) => node.end(),
5396      Pat::Expr(node) => node.end(),
5397    }
5398  }
5399}
5400
5401impl<'a> NodeTrait<'a> for Pat<'a> {
5402  fn parent(&self) -> Option<Node<'a>> {
5403    match self {
5404      Pat::Ident(node) => NodeTrait::parent(*node),
5405      Pat::Array(node) => NodeTrait::parent(*node),
5406      Pat::Rest(node) => NodeTrait::parent(*node),
5407      Pat::Object(node) => NodeTrait::parent(*node),
5408      Pat::Assign(node) => NodeTrait::parent(*node),
5409      Pat::Invalid(node) => NodeTrait::parent(*node),
5410      Pat::Expr(node) => NodeTrait::parent(node),
5411    }
5412  }
5413
5414  fn children(&self) -> Vec<Node<'a>> {
5415    match self {
5416      Pat::Ident(node) => node.children(),
5417      Pat::Array(node) => node.children(),
5418      Pat::Rest(node) => node.children(),
5419      Pat::Object(node) => node.children(),
5420      Pat::Assign(node) => node.children(),
5421      Pat::Invalid(node) => node.children(),
5422      Pat::Expr(node) => node.children(),
5423    }
5424  }
5425
5426  fn as_node(&self) -> Node<'a> {
5427    match self {
5428      Pat::Ident(node) => node.as_node(),
5429      Pat::Array(node) => node.as_node(),
5430      Pat::Rest(node) => node.as_node(),
5431      Pat::Object(node) => node.as_node(),
5432      Pat::Assign(node) => node.as_node(),
5433      Pat::Invalid(node) => node.as_node(),
5434      Pat::Expr(node) => node.as_node(),
5435    }
5436  }
5437
5438  fn kind(&self) -> NodeKind {
5439    match self {
5440      Pat::Ident(_) => NodeKind::BindingIdent,
5441      Pat::Array(_) => NodeKind::ArrayPat,
5442      Pat::Rest(_) => NodeKind::RestPat,
5443      Pat::Object(_) => NodeKind::ObjectPat,
5444      Pat::Assign(_) => NodeKind::AssignPat,
5445      Pat::Invalid(_) => NodeKind::Invalid,
5446      Pat::Expr(node) => node.kind(),
5447    }
5448  }
5449}
5450
5451impl<'a> From<&Pat<'a>> for Node<'a> {
5452  fn from(node: &Pat<'a>) -> Node<'a> {
5453    match node {
5454      Pat::Ident(node) => (*node).into(),
5455      Pat::Array(node) => (*node).into(),
5456      Pat::Rest(node) => (*node).into(),
5457      Pat::Object(node) => (*node).into(),
5458      Pat::Assign(node) => (*node).into(),
5459      Pat::Invalid(node) => (*node).into(),
5460      Pat::Expr(node) => node.into(),
5461    }
5462  }
5463}
5464
5465impl<'a> From<Pat<'a>> for Node<'a> {
5466  fn from(node: Pat<'a>) -> Node<'a> {
5467    match node {
5468      Pat::Ident(node) => node.into(),
5469      Pat::Array(node) => node.into(),
5470      Pat::Rest(node) => node.into(),
5471      Pat::Object(node) => node.into(),
5472      Pat::Assign(node) => node.into(),
5473      Pat::Invalid(node) => node.into(),
5474      Pat::Expr(node) => node.into(),
5475    }
5476  }
5477}
5478
5479fn get_view_for_pat<'a>(inner: &'a swc_ast::Pat, bump: &'a Bump) -> Pat<'a> {
5480  match inner {
5481    swc_ast::Pat::Ident(value) => Pat::Ident(get_view_for_binding_ident(value, bump)),
5482    swc_ast::Pat::Array(value) => Pat::Array(get_view_for_array_pat(value, bump)),
5483    swc_ast::Pat::Rest(value) => Pat::Rest(get_view_for_rest_pat(value, bump)),
5484    swc_ast::Pat::Object(value) => Pat::Object(get_view_for_object_pat(value, bump)),
5485    swc_ast::Pat::Assign(value) => Pat::Assign(get_view_for_assign_pat(value, bump)),
5486    swc_ast::Pat::Invalid(value) => Pat::Invalid(get_view_for_invalid(value, bump)),
5487    swc_ast::Pat::Expr(value) => Pat::Expr(get_view_for_expr(value, bump)),
5488  }
5489}
5490
5491fn set_parent_for_pat<'a>(node: &Pat<'a>, parent: Node<'a>) {
5492  match node {
5493    Pat::Ident(value) => set_parent_for_binding_ident(value, parent),
5494    Pat::Array(value) => set_parent_for_array_pat(value, parent),
5495    Pat::Rest(value) => set_parent_for_rest_pat(value, parent),
5496    Pat::Object(value) => set_parent_for_object_pat(value, parent),
5497    Pat::Assign(value) => set_parent_for_assign_pat(value, parent),
5498    Pat::Invalid(value) => set_parent_for_invalid(value, parent),
5499    Pat::Expr(value) => set_parent_for_expr(value, parent),
5500  }
5501}
5502
5503#[derive(Copy, Clone)]
5504pub enum Prop<'a> {
5505  /// `a` in `{ a, }`
5506  Shorthand(&'a Ident<'a>),
5507  /// `key: value` in `{ key: value, }`
5508  KeyValue(&'a KeyValueProp<'a>),
5509  /// This is **invalid** for object literal.
5510  Assign(&'a AssignProp<'a>),
5511  Getter(&'a GetterProp<'a>),
5512  Setter(&'a SetterProp<'a>),
5513  Method(&'a MethodProp<'a>),
5514}
5515
5516impl<'a> Prop<'a> {
5517  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5518    T::to(&self.into())
5519  }
5520
5521  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5522    let node: Node<'a> = self.into();
5523    if let Some(result) = T::to(&node) {
5524      result
5525    } else {
5526      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5527    }
5528  }
5529
5530  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5531    self.kind() == T::kind()
5532  }
5533  pub fn parent(&self) -> Node<'a> {
5534    NodeTrait::parent(self).unwrap()
5535  }
5536}
5537
5538impl<'a> SourceRanged for Prop<'a> {
5539  fn start(&self) -> SourcePos {
5540    match self {
5541      Prop::Shorthand(node) => node.start(),
5542      Prop::KeyValue(node) => node.start(),
5543      Prop::Assign(node) => node.start(),
5544      Prop::Getter(node) => node.start(),
5545      Prop::Setter(node) => node.start(),
5546      Prop::Method(node) => node.start(),
5547    }
5548  }
5549  fn end(&self) -> SourcePos {
5550    match self {
5551      Prop::Shorthand(node) => node.end(),
5552      Prop::KeyValue(node) => node.end(),
5553      Prop::Assign(node) => node.end(),
5554      Prop::Getter(node) => node.end(),
5555      Prop::Setter(node) => node.end(),
5556      Prop::Method(node) => node.end(),
5557    }
5558  }
5559}
5560
5561impl<'a> NodeTrait<'a> for Prop<'a> {
5562  fn parent(&self) -> Option<Node<'a>> {
5563    match self {
5564      Prop::Shorthand(node) => NodeTrait::parent(*node),
5565      Prop::KeyValue(node) => NodeTrait::parent(*node),
5566      Prop::Assign(node) => NodeTrait::parent(*node),
5567      Prop::Getter(node) => NodeTrait::parent(*node),
5568      Prop::Setter(node) => NodeTrait::parent(*node),
5569      Prop::Method(node) => NodeTrait::parent(*node),
5570    }
5571  }
5572
5573  fn children(&self) -> Vec<Node<'a>> {
5574    match self {
5575      Prop::Shorthand(node) => node.children(),
5576      Prop::KeyValue(node) => node.children(),
5577      Prop::Assign(node) => node.children(),
5578      Prop::Getter(node) => node.children(),
5579      Prop::Setter(node) => node.children(),
5580      Prop::Method(node) => node.children(),
5581    }
5582  }
5583
5584  fn as_node(&self) -> Node<'a> {
5585    match self {
5586      Prop::Shorthand(node) => node.as_node(),
5587      Prop::KeyValue(node) => node.as_node(),
5588      Prop::Assign(node) => node.as_node(),
5589      Prop::Getter(node) => node.as_node(),
5590      Prop::Setter(node) => node.as_node(),
5591      Prop::Method(node) => node.as_node(),
5592    }
5593  }
5594
5595  fn kind(&self) -> NodeKind {
5596    match self {
5597      Prop::Shorthand(_) => NodeKind::Ident,
5598      Prop::KeyValue(_) => NodeKind::KeyValueProp,
5599      Prop::Assign(_) => NodeKind::AssignProp,
5600      Prop::Getter(_) => NodeKind::GetterProp,
5601      Prop::Setter(_) => NodeKind::SetterProp,
5602      Prop::Method(_) => NodeKind::MethodProp,
5603    }
5604  }
5605}
5606
5607impl<'a> From<&Prop<'a>> for Node<'a> {
5608  fn from(node: &Prop<'a>) -> Node<'a> {
5609    match node {
5610      Prop::Shorthand(node) => (*node).into(),
5611      Prop::KeyValue(node) => (*node).into(),
5612      Prop::Assign(node) => (*node).into(),
5613      Prop::Getter(node) => (*node).into(),
5614      Prop::Setter(node) => (*node).into(),
5615      Prop::Method(node) => (*node).into(),
5616    }
5617  }
5618}
5619
5620impl<'a> From<Prop<'a>> for Node<'a> {
5621  fn from(node: Prop<'a>) -> Node<'a> {
5622    match node {
5623      Prop::Shorthand(node) => node.into(),
5624      Prop::KeyValue(node) => node.into(),
5625      Prop::Assign(node) => node.into(),
5626      Prop::Getter(node) => node.into(),
5627      Prop::Setter(node) => node.into(),
5628      Prop::Method(node) => node.into(),
5629    }
5630  }
5631}
5632
5633fn get_view_for_prop<'a>(inner: &'a swc_ast::Prop, bump: &'a Bump) -> Prop<'a> {
5634  match inner {
5635    swc_ast::Prop::Shorthand(value) => Prop::Shorthand(get_view_for_ident(value, bump)),
5636    swc_ast::Prop::KeyValue(value) => Prop::KeyValue(get_view_for_key_value_prop(value, bump)),
5637    swc_ast::Prop::Assign(value) => Prop::Assign(get_view_for_assign_prop(value, bump)),
5638    swc_ast::Prop::Getter(value) => Prop::Getter(get_view_for_getter_prop(value, bump)),
5639    swc_ast::Prop::Setter(value) => Prop::Setter(get_view_for_setter_prop(value, bump)),
5640    swc_ast::Prop::Method(value) => Prop::Method(get_view_for_method_prop(value, bump)),
5641  }
5642}
5643
5644fn set_parent_for_prop<'a>(node: &Prop<'a>, parent: Node<'a>) {
5645  match node {
5646    Prop::Shorthand(value) => set_parent_for_ident(value, parent),
5647    Prop::KeyValue(value) => set_parent_for_key_value_prop(value, parent),
5648    Prop::Assign(value) => set_parent_for_assign_prop(value, parent),
5649    Prop::Getter(value) => set_parent_for_getter_prop(value, parent),
5650    Prop::Setter(value) => set_parent_for_setter_prop(value, parent),
5651    Prop::Method(value) => set_parent_for_method_prop(value, parent),
5652  }
5653}
5654
5655#[derive(Copy, Clone)]
5656pub enum PropName<'a> {
5657  Ident(&'a IdentName<'a>),
5658  /// String literal.
5659  Str(&'a Str<'a>),
5660  /// Numeric literal.
5661  Num(&'a Number<'a>),
5662  Computed(&'a ComputedPropName<'a>),
5663  BigInt(&'a BigInt<'a>),
5664}
5665
5666impl<'a> PropName<'a> {
5667  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5668    T::to(&self.into())
5669  }
5670
5671  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5672    let node: Node<'a> = self.into();
5673    if let Some(result) = T::to(&node) {
5674      result
5675    } else {
5676      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5677    }
5678  }
5679
5680  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5681    self.kind() == T::kind()
5682  }
5683  pub fn parent(&self) -> Node<'a> {
5684    NodeTrait::parent(self).unwrap()
5685  }
5686}
5687
5688impl<'a> SourceRanged for PropName<'a> {
5689  fn start(&self) -> SourcePos {
5690    match self {
5691      PropName::Ident(node) => node.start(),
5692      PropName::Str(node) => node.start(),
5693      PropName::Num(node) => node.start(),
5694      PropName::Computed(node) => node.start(),
5695      PropName::BigInt(node) => node.start(),
5696    }
5697  }
5698  fn end(&self) -> SourcePos {
5699    match self {
5700      PropName::Ident(node) => node.end(),
5701      PropName::Str(node) => node.end(),
5702      PropName::Num(node) => node.end(),
5703      PropName::Computed(node) => node.end(),
5704      PropName::BigInt(node) => node.end(),
5705    }
5706  }
5707}
5708
5709impl<'a> NodeTrait<'a> for PropName<'a> {
5710  fn parent(&self) -> Option<Node<'a>> {
5711    match self {
5712      PropName::Ident(node) => NodeTrait::parent(*node),
5713      PropName::Str(node) => NodeTrait::parent(*node),
5714      PropName::Num(node) => NodeTrait::parent(*node),
5715      PropName::Computed(node) => NodeTrait::parent(*node),
5716      PropName::BigInt(node) => NodeTrait::parent(*node),
5717    }
5718  }
5719
5720  fn children(&self) -> Vec<Node<'a>> {
5721    match self {
5722      PropName::Ident(node) => node.children(),
5723      PropName::Str(node) => node.children(),
5724      PropName::Num(node) => node.children(),
5725      PropName::Computed(node) => node.children(),
5726      PropName::BigInt(node) => node.children(),
5727    }
5728  }
5729
5730  fn as_node(&self) -> Node<'a> {
5731    match self {
5732      PropName::Ident(node) => node.as_node(),
5733      PropName::Str(node) => node.as_node(),
5734      PropName::Num(node) => node.as_node(),
5735      PropName::Computed(node) => node.as_node(),
5736      PropName::BigInt(node) => node.as_node(),
5737    }
5738  }
5739
5740  fn kind(&self) -> NodeKind {
5741    match self {
5742      PropName::Ident(_) => NodeKind::IdentName,
5743      PropName::Str(_) => NodeKind::Str,
5744      PropName::Num(_) => NodeKind::Number,
5745      PropName::Computed(_) => NodeKind::ComputedPropName,
5746      PropName::BigInt(_) => NodeKind::BigInt,
5747    }
5748  }
5749}
5750
5751impl<'a> From<&PropName<'a>> for Node<'a> {
5752  fn from(node: &PropName<'a>) -> Node<'a> {
5753    match node {
5754      PropName::Ident(node) => (*node).into(),
5755      PropName::Str(node) => (*node).into(),
5756      PropName::Num(node) => (*node).into(),
5757      PropName::Computed(node) => (*node).into(),
5758      PropName::BigInt(node) => (*node).into(),
5759    }
5760  }
5761}
5762
5763impl<'a> From<PropName<'a>> for Node<'a> {
5764  fn from(node: PropName<'a>) -> Node<'a> {
5765    match node {
5766      PropName::Ident(node) => node.into(),
5767      PropName::Str(node) => node.into(),
5768      PropName::Num(node) => node.into(),
5769      PropName::Computed(node) => node.into(),
5770      PropName::BigInt(node) => node.into(),
5771    }
5772  }
5773}
5774
5775fn get_view_for_prop_name<'a>(inner: &'a swc_ast::PropName, bump: &'a Bump) -> PropName<'a> {
5776  match inner {
5777    swc_ast::PropName::Ident(value) => PropName::Ident(get_view_for_ident_name(value, bump)),
5778    swc_ast::PropName::Str(value) => PropName::Str(get_view_for_str(value, bump)),
5779    swc_ast::PropName::Num(value) => PropName::Num(get_view_for_number(value, bump)),
5780    swc_ast::PropName::Computed(value) => PropName::Computed(get_view_for_computed_prop_name(value, bump)),
5781    swc_ast::PropName::BigInt(value) => PropName::BigInt(get_view_for_big_int(value, bump)),
5782  }
5783}
5784
5785fn set_parent_for_prop_name<'a>(node: &PropName<'a>, parent: Node<'a>) {
5786  match node {
5787    PropName::Ident(value) => set_parent_for_ident_name(value, parent),
5788    PropName::Str(value) => set_parent_for_str(value, parent),
5789    PropName::Num(value) => set_parent_for_number(value, parent),
5790    PropName::Computed(value) => set_parent_for_computed_prop_name(value, parent),
5791    PropName::BigInt(value) => set_parent_for_big_int(value, parent),
5792  }
5793}
5794
5795#[derive(Copy, Clone)]
5796pub enum PropOrSpread<'a> {
5797  /// Spread properties, e.g., `{a: 1, ...obj, b: 2}`.
5798  Spread(&'a SpreadElement<'a>),
5799  Prop(Prop<'a>),
5800}
5801
5802impl<'a> PropOrSpread<'a> {
5803  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5804    T::to(&self.into())
5805  }
5806
5807  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5808    let node: Node<'a> = self.into();
5809    if let Some(result) = T::to(&node) {
5810      result
5811    } else {
5812      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5813    }
5814  }
5815
5816  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5817    self.kind() == T::kind()
5818  }
5819}
5820
5821impl<'a> SourceRanged for PropOrSpread<'a> {
5822  fn start(&self) -> SourcePos {
5823    match self {
5824      PropOrSpread::Spread(node) => node.start(),
5825      PropOrSpread::Prop(node) => node.start(),
5826    }
5827  }
5828  fn end(&self) -> SourcePos {
5829    match self {
5830      PropOrSpread::Spread(node) => node.end(),
5831      PropOrSpread::Prop(node) => node.end(),
5832    }
5833  }
5834}
5835
5836impl<'a> NodeTrait<'a> for PropOrSpread<'a> {
5837  fn parent(&self) -> Option<Node<'a>> {
5838    match self {
5839      PropOrSpread::Spread(node) => NodeTrait::parent(*node),
5840      PropOrSpread::Prop(node) => NodeTrait::parent(node),
5841    }
5842  }
5843
5844  fn children(&self) -> Vec<Node<'a>> {
5845    match self {
5846      PropOrSpread::Spread(node) => node.children(),
5847      PropOrSpread::Prop(node) => node.children(),
5848    }
5849  }
5850
5851  fn as_node(&self) -> Node<'a> {
5852    match self {
5853      PropOrSpread::Spread(node) => node.as_node(),
5854      PropOrSpread::Prop(node) => node.as_node(),
5855    }
5856  }
5857
5858  fn kind(&self) -> NodeKind {
5859    match self {
5860      PropOrSpread::Spread(_) => NodeKind::SpreadElement,
5861      PropOrSpread::Prop(node) => node.kind(),
5862    }
5863  }
5864}
5865
5866impl<'a> From<&PropOrSpread<'a>> for Node<'a> {
5867  fn from(node: &PropOrSpread<'a>) -> Node<'a> {
5868    match node {
5869      PropOrSpread::Spread(node) => (*node).into(),
5870      PropOrSpread::Prop(node) => node.into(),
5871    }
5872  }
5873}
5874
5875impl<'a> From<PropOrSpread<'a>> for Node<'a> {
5876  fn from(node: PropOrSpread<'a>) -> Node<'a> {
5877    match node {
5878      PropOrSpread::Spread(node) => node.into(),
5879      PropOrSpread::Prop(node) => node.into(),
5880    }
5881  }
5882}
5883
5884fn get_view_for_prop_or_spread<'a>(inner: &'a swc_ast::PropOrSpread, bump: &'a Bump) -> PropOrSpread<'a> {
5885  match inner {
5886    swc_ast::PropOrSpread::Spread(value) => PropOrSpread::Spread(get_view_for_spread_element(value, bump)),
5887    swc_ast::PropOrSpread::Prop(value) => PropOrSpread::Prop(get_view_for_prop(value, bump)),
5888  }
5889}
5890
5891fn set_parent_for_prop_or_spread<'a>(node: &PropOrSpread<'a>, parent: Node<'a>) {
5892  match node {
5893    PropOrSpread::Spread(value) => set_parent_for_spread_element(value, parent),
5894    PropOrSpread::Prop(value) => set_parent_for_prop(value, parent),
5895  }
5896}
5897
5898#[derive(Copy, Clone)]
5899pub enum SimpleAssignTarget<'a> {
5900  /// Note: This type is to help implementing visitor and the field `type_ann`
5901  /// is always [None].
5902  Ident(&'a BindingIdent<'a>),
5903  Member(&'a MemberExpr<'a>),
5904  SuperProp(&'a SuperPropExpr<'a>),
5905  Paren(&'a ParenExpr<'a>),
5906  OptChain(&'a OptChainExpr<'a>),
5907  TsAs(&'a TsAsExpr<'a>),
5908  TsSatisfies(&'a TsSatisfiesExpr<'a>),
5909  TsNonNull(&'a TsNonNullExpr<'a>),
5910  TsTypeAssertion(&'a TsTypeAssertion<'a>),
5911  TsInstantiation(&'a TsInstantiation<'a>),
5912  Invalid(&'a Invalid<'a>),
5913}
5914
5915impl<'a> SimpleAssignTarget<'a> {
5916  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5917    T::to(&self.into())
5918  }
5919
5920  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5921    let node: Node<'a> = self.into();
5922    if let Some(result) = T::to(&node) {
5923      result
5924    } else {
5925      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5926    }
5927  }
5928
5929  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5930    self.kind() == T::kind()
5931  }
5932  pub fn parent(&self) -> Node<'a> {
5933    NodeTrait::parent(self).unwrap()
5934  }
5935}
5936
5937impl<'a> SourceRanged for SimpleAssignTarget<'a> {
5938  fn start(&self) -> SourcePos {
5939    match self {
5940      SimpleAssignTarget::Ident(node) => node.start(),
5941      SimpleAssignTarget::Member(node) => node.start(),
5942      SimpleAssignTarget::SuperProp(node) => node.start(),
5943      SimpleAssignTarget::Paren(node) => node.start(),
5944      SimpleAssignTarget::OptChain(node) => node.start(),
5945      SimpleAssignTarget::TsAs(node) => node.start(),
5946      SimpleAssignTarget::TsSatisfies(node) => node.start(),
5947      SimpleAssignTarget::TsNonNull(node) => node.start(),
5948      SimpleAssignTarget::TsTypeAssertion(node) => node.start(),
5949      SimpleAssignTarget::TsInstantiation(node) => node.start(),
5950      SimpleAssignTarget::Invalid(node) => node.start(),
5951    }
5952  }
5953  fn end(&self) -> SourcePos {
5954    match self {
5955      SimpleAssignTarget::Ident(node) => node.end(),
5956      SimpleAssignTarget::Member(node) => node.end(),
5957      SimpleAssignTarget::SuperProp(node) => node.end(),
5958      SimpleAssignTarget::Paren(node) => node.end(),
5959      SimpleAssignTarget::OptChain(node) => node.end(),
5960      SimpleAssignTarget::TsAs(node) => node.end(),
5961      SimpleAssignTarget::TsSatisfies(node) => node.end(),
5962      SimpleAssignTarget::TsNonNull(node) => node.end(),
5963      SimpleAssignTarget::TsTypeAssertion(node) => node.end(),
5964      SimpleAssignTarget::TsInstantiation(node) => node.end(),
5965      SimpleAssignTarget::Invalid(node) => node.end(),
5966    }
5967  }
5968}
5969
5970impl<'a> NodeTrait<'a> for SimpleAssignTarget<'a> {
5971  fn parent(&self) -> Option<Node<'a>> {
5972    match self {
5973      SimpleAssignTarget::Ident(node) => NodeTrait::parent(*node),
5974      SimpleAssignTarget::Member(node) => NodeTrait::parent(*node),
5975      SimpleAssignTarget::SuperProp(node) => NodeTrait::parent(*node),
5976      SimpleAssignTarget::Paren(node) => NodeTrait::parent(*node),
5977      SimpleAssignTarget::OptChain(node) => NodeTrait::parent(*node),
5978      SimpleAssignTarget::TsAs(node) => NodeTrait::parent(*node),
5979      SimpleAssignTarget::TsSatisfies(node) => NodeTrait::parent(*node),
5980      SimpleAssignTarget::TsNonNull(node) => NodeTrait::parent(*node),
5981      SimpleAssignTarget::TsTypeAssertion(node) => NodeTrait::parent(*node),
5982      SimpleAssignTarget::TsInstantiation(node) => NodeTrait::parent(*node),
5983      SimpleAssignTarget::Invalid(node) => NodeTrait::parent(*node),
5984    }
5985  }
5986
5987  fn children(&self) -> Vec<Node<'a>> {
5988    match self {
5989      SimpleAssignTarget::Ident(node) => node.children(),
5990      SimpleAssignTarget::Member(node) => node.children(),
5991      SimpleAssignTarget::SuperProp(node) => node.children(),
5992      SimpleAssignTarget::Paren(node) => node.children(),
5993      SimpleAssignTarget::OptChain(node) => node.children(),
5994      SimpleAssignTarget::TsAs(node) => node.children(),
5995      SimpleAssignTarget::TsSatisfies(node) => node.children(),
5996      SimpleAssignTarget::TsNonNull(node) => node.children(),
5997      SimpleAssignTarget::TsTypeAssertion(node) => node.children(),
5998      SimpleAssignTarget::TsInstantiation(node) => node.children(),
5999      SimpleAssignTarget::Invalid(node) => node.children(),
6000    }
6001  }
6002
6003  fn as_node(&self) -> Node<'a> {
6004    match self {
6005      SimpleAssignTarget::Ident(node) => node.as_node(),
6006      SimpleAssignTarget::Member(node) => node.as_node(),
6007      SimpleAssignTarget::SuperProp(node) => node.as_node(),
6008      SimpleAssignTarget::Paren(node) => node.as_node(),
6009      SimpleAssignTarget::OptChain(node) => node.as_node(),
6010      SimpleAssignTarget::TsAs(node) => node.as_node(),
6011      SimpleAssignTarget::TsSatisfies(node) => node.as_node(),
6012      SimpleAssignTarget::TsNonNull(node) => node.as_node(),
6013      SimpleAssignTarget::TsTypeAssertion(node) => node.as_node(),
6014      SimpleAssignTarget::TsInstantiation(node) => node.as_node(),
6015      SimpleAssignTarget::Invalid(node) => node.as_node(),
6016    }
6017  }
6018
6019  fn kind(&self) -> NodeKind {
6020    match self {
6021      SimpleAssignTarget::Ident(_) => NodeKind::BindingIdent,
6022      SimpleAssignTarget::Member(_) => NodeKind::MemberExpr,
6023      SimpleAssignTarget::SuperProp(_) => NodeKind::SuperPropExpr,
6024      SimpleAssignTarget::Paren(_) => NodeKind::ParenExpr,
6025      SimpleAssignTarget::OptChain(_) => NodeKind::OptChainExpr,
6026      SimpleAssignTarget::TsAs(_) => NodeKind::TsAsExpr,
6027      SimpleAssignTarget::TsSatisfies(_) => NodeKind::TsSatisfiesExpr,
6028      SimpleAssignTarget::TsNonNull(_) => NodeKind::TsNonNullExpr,
6029      SimpleAssignTarget::TsTypeAssertion(_) => NodeKind::TsTypeAssertion,
6030      SimpleAssignTarget::TsInstantiation(_) => NodeKind::TsInstantiation,
6031      SimpleAssignTarget::Invalid(_) => NodeKind::Invalid,
6032    }
6033  }
6034}
6035
6036impl<'a> From<&SimpleAssignTarget<'a>> for Node<'a> {
6037  fn from(node: &SimpleAssignTarget<'a>) -> Node<'a> {
6038    match node {
6039      SimpleAssignTarget::Ident(node) => (*node).into(),
6040      SimpleAssignTarget::Member(node) => (*node).into(),
6041      SimpleAssignTarget::SuperProp(node) => (*node).into(),
6042      SimpleAssignTarget::Paren(node) => (*node).into(),
6043      SimpleAssignTarget::OptChain(node) => (*node).into(),
6044      SimpleAssignTarget::TsAs(node) => (*node).into(),
6045      SimpleAssignTarget::TsSatisfies(node) => (*node).into(),
6046      SimpleAssignTarget::TsNonNull(node) => (*node).into(),
6047      SimpleAssignTarget::TsTypeAssertion(node) => (*node).into(),
6048      SimpleAssignTarget::TsInstantiation(node) => (*node).into(),
6049      SimpleAssignTarget::Invalid(node) => (*node).into(),
6050    }
6051  }
6052}
6053
6054impl<'a> From<SimpleAssignTarget<'a>> for Node<'a> {
6055  fn from(node: SimpleAssignTarget<'a>) -> Node<'a> {
6056    match node {
6057      SimpleAssignTarget::Ident(node) => node.into(),
6058      SimpleAssignTarget::Member(node) => node.into(),
6059      SimpleAssignTarget::SuperProp(node) => node.into(),
6060      SimpleAssignTarget::Paren(node) => node.into(),
6061      SimpleAssignTarget::OptChain(node) => node.into(),
6062      SimpleAssignTarget::TsAs(node) => node.into(),
6063      SimpleAssignTarget::TsSatisfies(node) => node.into(),
6064      SimpleAssignTarget::TsNonNull(node) => node.into(),
6065      SimpleAssignTarget::TsTypeAssertion(node) => node.into(),
6066      SimpleAssignTarget::TsInstantiation(node) => node.into(),
6067      SimpleAssignTarget::Invalid(node) => node.into(),
6068    }
6069  }
6070}
6071
6072fn get_view_for_simple_assign_target<'a>(inner: &'a swc_ast::SimpleAssignTarget, bump: &'a Bump) -> SimpleAssignTarget<'a> {
6073  match inner {
6074    swc_ast::SimpleAssignTarget::Ident(value) => SimpleAssignTarget::Ident(get_view_for_binding_ident(value, bump)),
6075    swc_ast::SimpleAssignTarget::Member(value) => SimpleAssignTarget::Member(get_view_for_member_expr(value, bump)),
6076    swc_ast::SimpleAssignTarget::SuperProp(value) => SimpleAssignTarget::SuperProp(get_view_for_super_prop_expr(value, bump)),
6077    swc_ast::SimpleAssignTarget::Paren(value) => SimpleAssignTarget::Paren(get_view_for_paren_expr(value, bump)),
6078    swc_ast::SimpleAssignTarget::OptChain(value) => SimpleAssignTarget::OptChain(get_view_for_opt_chain_expr(value, bump)),
6079    swc_ast::SimpleAssignTarget::TsAs(value) => SimpleAssignTarget::TsAs(get_view_for_ts_as_expr(value, bump)),
6080    swc_ast::SimpleAssignTarget::TsSatisfies(value) => SimpleAssignTarget::TsSatisfies(get_view_for_ts_satisfies_expr(value, bump)),
6081    swc_ast::SimpleAssignTarget::TsNonNull(value) => SimpleAssignTarget::TsNonNull(get_view_for_ts_non_null_expr(value, bump)),
6082    swc_ast::SimpleAssignTarget::TsTypeAssertion(value) => SimpleAssignTarget::TsTypeAssertion(get_view_for_ts_type_assertion(value, bump)),
6083    swc_ast::SimpleAssignTarget::TsInstantiation(value) => SimpleAssignTarget::TsInstantiation(get_view_for_ts_instantiation(value, bump)),
6084    swc_ast::SimpleAssignTarget::Invalid(value) => SimpleAssignTarget::Invalid(get_view_for_invalid(value, bump)),
6085  }
6086}
6087
6088fn set_parent_for_simple_assign_target<'a>(node: &SimpleAssignTarget<'a>, parent: Node<'a>) {
6089  match node {
6090    SimpleAssignTarget::Ident(value) => set_parent_for_binding_ident(value, parent),
6091    SimpleAssignTarget::Member(value) => set_parent_for_member_expr(value, parent),
6092    SimpleAssignTarget::SuperProp(value) => set_parent_for_super_prop_expr(value, parent),
6093    SimpleAssignTarget::Paren(value) => set_parent_for_paren_expr(value, parent),
6094    SimpleAssignTarget::OptChain(value) => set_parent_for_opt_chain_expr(value, parent),
6095    SimpleAssignTarget::TsAs(value) => set_parent_for_ts_as_expr(value, parent),
6096    SimpleAssignTarget::TsSatisfies(value) => set_parent_for_ts_satisfies_expr(value, parent),
6097    SimpleAssignTarget::TsNonNull(value) => set_parent_for_ts_non_null_expr(value, parent),
6098    SimpleAssignTarget::TsTypeAssertion(value) => set_parent_for_ts_type_assertion(value, parent),
6099    SimpleAssignTarget::TsInstantiation(value) => set_parent_for_ts_instantiation(value, parent),
6100    SimpleAssignTarget::Invalid(value) => set_parent_for_invalid(value, parent),
6101  }
6102}
6103
6104#[derive(Copy, Clone)]
6105pub enum Stmt<'a> {
6106  Block(&'a BlockStmt<'a>),
6107  Empty(&'a EmptyStmt<'a>),
6108  Debugger(&'a DebuggerStmt<'a>),
6109  With(&'a WithStmt<'a>),
6110  Return(&'a ReturnStmt<'a>),
6111  Labeled(&'a LabeledStmt<'a>),
6112  Break(&'a BreakStmt<'a>),
6113  Continue(&'a ContinueStmt<'a>),
6114  If(&'a IfStmt<'a>),
6115  Switch(&'a SwitchStmt<'a>),
6116  Throw(&'a ThrowStmt<'a>),
6117  /// A try statement. If handler is null then finalizer must be a BlockStmt.
6118  Try(&'a TryStmt<'a>),
6119  While(&'a WhileStmt<'a>),
6120  DoWhile(&'a DoWhileStmt<'a>),
6121  For(&'a ForStmt<'a>),
6122  ForIn(&'a ForInStmt<'a>),
6123  ForOf(&'a ForOfStmt<'a>),
6124  Decl(Decl<'a>),
6125  Expr(&'a ExprStmt<'a>),
6126}
6127
6128impl<'a> Stmt<'a> {
6129  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6130    T::to(&self.into())
6131  }
6132
6133  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6134    let node: Node<'a> = self.into();
6135    if let Some(result) = T::to(&node) {
6136      result
6137    } else {
6138      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6139    }
6140  }
6141
6142  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6143    self.kind() == T::kind()
6144  }
6145}
6146
6147impl<'a> SourceRanged for Stmt<'a> {
6148  fn start(&self) -> SourcePos {
6149    match self {
6150      Stmt::Block(node) => node.start(),
6151      Stmt::Empty(node) => node.start(),
6152      Stmt::Debugger(node) => node.start(),
6153      Stmt::With(node) => node.start(),
6154      Stmt::Return(node) => node.start(),
6155      Stmt::Labeled(node) => node.start(),
6156      Stmt::Break(node) => node.start(),
6157      Stmt::Continue(node) => node.start(),
6158      Stmt::If(node) => node.start(),
6159      Stmt::Switch(node) => node.start(),
6160      Stmt::Throw(node) => node.start(),
6161      Stmt::Try(node) => node.start(),
6162      Stmt::While(node) => node.start(),
6163      Stmt::DoWhile(node) => node.start(),
6164      Stmt::For(node) => node.start(),
6165      Stmt::ForIn(node) => node.start(),
6166      Stmt::ForOf(node) => node.start(),
6167      Stmt::Decl(node) => node.start(),
6168      Stmt::Expr(node) => node.start(),
6169    }
6170  }
6171  fn end(&self) -> SourcePos {
6172    match self {
6173      Stmt::Block(node) => node.end(),
6174      Stmt::Empty(node) => node.end(),
6175      Stmt::Debugger(node) => node.end(),
6176      Stmt::With(node) => node.end(),
6177      Stmt::Return(node) => node.end(),
6178      Stmt::Labeled(node) => node.end(),
6179      Stmt::Break(node) => node.end(),
6180      Stmt::Continue(node) => node.end(),
6181      Stmt::If(node) => node.end(),
6182      Stmt::Switch(node) => node.end(),
6183      Stmt::Throw(node) => node.end(),
6184      Stmt::Try(node) => node.end(),
6185      Stmt::While(node) => node.end(),
6186      Stmt::DoWhile(node) => node.end(),
6187      Stmt::For(node) => node.end(),
6188      Stmt::ForIn(node) => node.end(),
6189      Stmt::ForOf(node) => node.end(),
6190      Stmt::Decl(node) => node.end(),
6191      Stmt::Expr(node) => node.end(),
6192    }
6193  }
6194}
6195
6196impl<'a> NodeTrait<'a> for Stmt<'a> {
6197  fn parent(&self) -> Option<Node<'a>> {
6198    match self {
6199      Stmt::Block(node) => NodeTrait::parent(*node),
6200      Stmt::Empty(node) => NodeTrait::parent(*node),
6201      Stmt::Debugger(node) => NodeTrait::parent(*node),
6202      Stmt::With(node) => NodeTrait::parent(*node),
6203      Stmt::Return(node) => NodeTrait::parent(*node),
6204      Stmt::Labeled(node) => NodeTrait::parent(*node),
6205      Stmt::Break(node) => NodeTrait::parent(*node),
6206      Stmt::Continue(node) => NodeTrait::parent(*node),
6207      Stmt::If(node) => NodeTrait::parent(*node),
6208      Stmt::Switch(node) => NodeTrait::parent(*node),
6209      Stmt::Throw(node) => NodeTrait::parent(*node),
6210      Stmt::Try(node) => NodeTrait::parent(*node),
6211      Stmt::While(node) => NodeTrait::parent(*node),
6212      Stmt::DoWhile(node) => NodeTrait::parent(*node),
6213      Stmt::For(node) => NodeTrait::parent(*node),
6214      Stmt::ForIn(node) => NodeTrait::parent(*node),
6215      Stmt::ForOf(node) => NodeTrait::parent(*node),
6216      Stmt::Decl(node) => NodeTrait::parent(node),
6217      Stmt::Expr(node) => NodeTrait::parent(*node),
6218    }
6219  }
6220
6221  fn children(&self) -> Vec<Node<'a>> {
6222    match self {
6223      Stmt::Block(node) => node.children(),
6224      Stmt::Empty(node) => node.children(),
6225      Stmt::Debugger(node) => node.children(),
6226      Stmt::With(node) => node.children(),
6227      Stmt::Return(node) => node.children(),
6228      Stmt::Labeled(node) => node.children(),
6229      Stmt::Break(node) => node.children(),
6230      Stmt::Continue(node) => node.children(),
6231      Stmt::If(node) => node.children(),
6232      Stmt::Switch(node) => node.children(),
6233      Stmt::Throw(node) => node.children(),
6234      Stmt::Try(node) => node.children(),
6235      Stmt::While(node) => node.children(),
6236      Stmt::DoWhile(node) => node.children(),
6237      Stmt::For(node) => node.children(),
6238      Stmt::ForIn(node) => node.children(),
6239      Stmt::ForOf(node) => node.children(),
6240      Stmt::Decl(node) => node.children(),
6241      Stmt::Expr(node) => node.children(),
6242    }
6243  }
6244
6245  fn as_node(&self) -> Node<'a> {
6246    match self {
6247      Stmt::Block(node) => node.as_node(),
6248      Stmt::Empty(node) => node.as_node(),
6249      Stmt::Debugger(node) => node.as_node(),
6250      Stmt::With(node) => node.as_node(),
6251      Stmt::Return(node) => node.as_node(),
6252      Stmt::Labeled(node) => node.as_node(),
6253      Stmt::Break(node) => node.as_node(),
6254      Stmt::Continue(node) => node.as_node(),
6255      Stmt::If(node) => node.as_node(),
6256      Stmt::Switch(node) => node.as_node(),
6257      Stmt::Throw(node) => node.as_node(),
6258      Stmt::Try(node) => node.as_node(),
6259      Stmt::While(node) => node.as_node(),
6260      Stmt::DoWhile(node) => node.as_node(),
6261      Stmt::For(node) => node.as_node(),
6262      Stmt::ForIn(node) => node.as_node(),
6263      Stmt::ForOf(node) => node.as_node(),
6264      Stmt::Decl(node) => node.as_node(),
6265      Stmt::Expr(node) => node.as_node(),
6266    }
6267  }
6268
6269  fn kind(&self) -> NodeKind {
6270    match self {
6271      Stmt::Block(_) => NodeKind::BlockStmt,
6272      Stmt::Empty(_) => NodeKind::EmptyStmt,
6273      Stmt::Debugger(_) => NodeKind::DebuggerStmt,
6274      Stmt::With(_) => NodeKind::WithStmt,
6275      Stmt::Return(_) => NodeKind::ReturnStmt,
6276      Stmt::Labeled(_) => NodeKind::LabeledStmt,
6277      Stmt::Break(_) => NodeKind::BreakStmt,
6278      Stmt::Continue(_) => NodeKind::ContinueStmt,
6279      Stmt::If(_) => NodeKind::IfStmt,
6280      Stmt::Switch(_) => NodeKind::SwitchStmt,
6281      Stmt::Throw(_) => NodeKind::ThrowStmt,
6282      Stmt::Try(_) => NodeKind::TryStmt,
6283      Stmt::While(_) => NodeKind::WhileStmt,
6284      Stmt::DoWhile(_) => NodeKind::DoWhileStmt,
6285      Stmt::For(_) => NodeKind::ForStmt,
6286      Stmt::ForIn(_) => NodeKind::ForInStmt,
6287      Stmt::ForOf(_) => NodeKind::ForOfStmt,
6288      Stmt::Decl(node) => node.kind(),
6289      Stmt::Expr(_) => NodeKind::ExprStmt,
6290    }
6291  }
6292}
6293
6294impl<'a> From<&Stmt<'a>> for Node<'a> {
6295  fn from(node: &Stmt<'a>) -> Node<'a> {
6296    match node {
6297      Stmt::Block(node) => (*node).into(),
6298      Stmt::Empty(node) => (*node).into(),
6299      Stmt::Debugger(node) => (*node).into(),
6300      Stmt::With(node) => (*node).into(),
6301      Stmt::Return(node) => (*node).into(),
6302      Stmt::Labeled(node) => (*node).into(),
6303      Stmt::Break(node) => (*node).into(),
6304      Stmt::Continue(node) => (*node).into(),
6305      Stmt::If(node) => (*node).into(),
6306      Stmt::Switch(node) => (*node).into(),
6307      Stmt::Throw(node) => (*node).into(),
6308      Stmt::Try(node) => (*node).into(),
6309      Stmt::While(node) => (*node).into(),
6310      Stmt::DoWhile(node) => (*node).into(),
6311      Stmt::For(node) => (*node).into(),
6312      Stmt::ForIn(node) => (*node).into(),
6313      Stmt::ForOf(node) => (*node).into(),
6314      Stmt::Decl(node) => node.into(),
6315      Stmt::Expr(node) => (*node).into(),
6316    }
6317  }
6318}
6319
6320impl<'a> From<Stmt<'a>> for Node<'a> {
6321  fn from(node: Stmt<'a>) -> Node<'a> {
6322    match node {
6323      Stmt::Block(node) => node.into(),
6324      Stmt::Empty(node) => node.into(),
6325      Stmt::Debugger(node) => node.into(),
6326      Stmt::With(node) => node.into(),
6327      Stmt::Return(node) => node.into(),
6328      Stmt::Labeled(node) => node.into(),
6329      Stmt::Break(node) => node.into(),
6330      Stmt::Continue(node) => node.into(),
6331      Stmt::If(node) => node.into(),
6332      Stmt::Switch(node) => node.into(),
6333      Stmt::Throw(node) => node.into(),
6334      Stmt::Try(node) => node.into(),
6335      Stmt::While(node) => node.into(),
6336      Stmt::DoWhile(node) => node.into(),
6337      Stmt::For(node) => node.into(),
6338      Stmt::ForIn(node) => node.into(),
6339      Stmt::ForOf(node) => node.into(),
6340      Stmt::Decl(node) => node.into(),
6341      Stmt::Expr(node) => node.into(),
6342    }
6343  }
6344}
6345
6346fn get_view_for_stmt<'a>(inner: &'a swc_ast::Stmt, bump: &'a Bump) -> Stmt<'a> {
6347  match inner {
6348    swc_ast::Stmt::Block(value) => Stmt::Block(get_view_for_block_stmt(value, bump)),
6349    swc_ast::Stmt::Empty(value) => Stmt::Empty(get_view_for_empty_stmt(value, bump)),
6350    swc_ast::Stmt::Debugger(value) => Stmt::Debugger(get_view_for_debugger_stmt(value, bump)),
6351    swc_ast::Stmt::With(value) => Stmt::With(get_view_for_with_stmt(value, bump)),
6352    swc_ast::Stmt::Return(value) => Stmt::Return(get_view_for_return_stmt(value, bump)),
6353    swc_ast::Stmt::Labeled(value) => Stmt::Labeled(get_view_for_labeled_stmt(value, bump)),
6354    swc_ast::Stmt::Break(value) => Stmt::Break(get_view_for_break_stmt(value, bump)),
6355    swc_ast::Stmt::Continue(value) => Stmt::Continue(get_view_for_continue_stmt(value, bump)),
6356    swc_ast::Stmt::If(value) => Stmt::If(get_view_for_if_stmt(value, bump)),
6357    swc_ast::Stmt::Switch(value) => Stmt::Switch(get_view_for_switch_stmt(value, bump)),
6358    swc_ast::Stmt::Throw(value) => Stmt::Throw(get_view_for_throw_stmt(value, bump)),
6359    swc_ast::Stmt::Try(value) => Stmt::Try(get_view_for_try_stmt(value, bump)),
6360    swc_ast::Stmt::While(value) => Stmt::While(get_view_for_while_stmt(value, bump)),
6361    swc_ast::Stmt::DoWhile(value) => Stmt::DoWhile(get_view_for_do_while_stmt(value, bump)),
6362    swc_ast::Stmt::For(value) => Stmt::For(get_view_for_for_stmt(value, bump)),
6363    swc_ast::Stmt::ForIn(value) => Stmt::ForIn(get_view_for_for_in_stmt(value, bump)),
6364    swc_ast::Stmt::ForOf(value) => Stmt::ForOf(get_view_for_for_of_stmt(value, bump)),
6365    swc_ast::Stmt::Decl(value) => Stmt::Decl(get_view_for_decl(value, bump)),
6366    swc_ast::Stmt::Expr(value) => Stmt::Expr(get_view_for_expr_stmt(value, bump)),
6367  }
6368}
6369
6370fn set_parent_for_stmt<'a>(node: &Stmt<'a>, parent: Node<'a>) {
6371  match node {
6372    Stmt::Block(value) => set_parent_for_block_stmt(value, parent),
6373    Stmt::Empty(value) => set_parent_for_empty_stmt(value, parent),
6374    Stmt::Debugger(value) => set_parent_for_debugger_stmt(value, parent),
6375    Stmt::With(value) => set_parent_for_with_stmt(value, parent),
6376    Stmt::Return(value) => set_parent_for_return_stmt(value, parent),
6377    Stmt::Labeled(value) => set_parent_for_labeled_stmt(value, parent),
6378    Stmt::Break(value) => set_parent_for_break_stmt(value, parent),
6379    Stmt::Continue(value) => set_parent_for_continue_stmt(value, parent),
6380    Stmt::If(value) => set_parent_for_if_stmt(value, parent),
6381    Stmt::Switch(value) => set_parent_for_switch_stmt(value, parent),
6382    Stmt::Throw(value) => set_parent_for_throw_stmt(value, parent),
6383    Stmt::Try(value) => set_parent_for_try_stmt(value, parent),
6384    Stmt::While(value) => set_parent_for_while_stmt(value, parent),
6385    Stmt::DoWhile(value) => set_parent_for_do_while_stmt(value, parent),
6386    Stmt::For(value) => set_parent_for_for_stmt(value, parent),
6387    Stmt::ForIn(value) => set_parent_for_for_in_stmt(value, parent),
6388    Stmt::ForOf(value) => set_parent_for_for_of_stmt(value, parent),
6389    Stmt::Decl(value) => set_parent_for_decl(value, parent),
6390    Stmt::Expr(value) => set_parent_for_expr_stmt(value, parent),
6391  }
6392}
6393
6394#[derive(Copy, Clone)]
6395pub enum SuperProp<'a> {
6396  Ident(&'a IdentName<'a>),
6397  Computed(&'a ComputedPropName<'a>),
6398}
6399
6400impl<'a> SuperProp<'a> {
6401  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6402    T::to(&self.into())
6403  }
6404
6405  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6406    let node: Node<'a> = self.into();
6407    if let Some(result) = T::to(&node) {
6408      result
6409    } else {
6410      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6411    }
6412  }
6413
6414  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6415    self.kind() == T::kind()
6416  }
6417  pub fn parent(&self) -> Node<'a> {
6418    NodeTrait::parent(self).unwrap()
6419  }
6420}
6421
6422impl<'a> SourceRanged for SuperProp<'a> {
6423  fn start(&self) -> SourcePos {
6424    match self {
6425      SuperProp::Ident(node) => node.start(),
6426      SuperProp::Computed(node) => node.start(),
6427    }
6428  }
6429  fn end(&self) -> SourcePos {
6430    match self {
6431      SuperProp::Ident(node) => node.end(),
6432      SuperProp::Computed(node) => node.end(),
6433    }
6434  }
6435}
6436
6437impl<'a> NodeTrait<'a> for SuperProp<'a> {
6438  fn parent(&self) -> Option<Node<'a>> {
6439    match self {
6440      SuperProp::Ident(node) => NodeTrait::parent(*node),
6441      SuperProp::Computed(node) => NodeTrait::parent(*node),
6442    }
6443  }
6444
6445  fn children(&self) -> Vec<Node<'a>> {
6446    match self {
6447      SuperProp::Ident(node) => node.children(),
6448      SuperProp::Computed(node) => node.children(),
6449    }
6450  }
6451
6452  fn as_node(&self) -> Node<'a> {
6453    match self {
6454      SuperProp::Ident(node) => node.as_node(),
6455      SuperProp::Computed(node) => node.as_node(),
6456    }
6457  }
6458
6459  fn kind(&self) -> NodeKind {
6460    match self {
6461      SuperProp::Ident(_) => NodeKind::IdentName,
6462      SuperProp::Computed(_) => NodeKind::ComputedPropName,
6463    }
6464  }
6465}
6466
6467impl<'a> From<&SuperProp<'a>> for Node<'a> {
6468  fn from(node: &SuperProp<'a>) -> Node<'a> {
6469    match node {
6470      SuperProp::Ident(node) => (*node).into(),
6471      SuperProp::Computed(node) => (*node).into(),
6472    }
6473  }
6474}
6475
6476impl<'a> From<SuperProp<'a>> for Node<'a> {
6477  fn from(node: SuperProp<'a>) -> Node<'a> {
6478    match node {
6479      SuperProp::Ident(node) => node.into(),
6480      SuperProp::Computed(node) => node.into(),
6481    }
6482  }
6483}
6484
6485fn get_view_for_super_prop<'a>(inner: &'a swc_ast::SuperProp, bump: &'a Bump) -> SuperProp<'a> {
6486  match inner {
6487    swc_ast::SuperProp::Ident(value) => SuperProp::Ident(get_view_for_ident_name(value, bump)),
6488    swc_ast::SuperProp::Computed(value) => SuperProp::Computed(get_view_for_computed_prop_name(value, bump)),
6489  }
6490}
6491
6492fn set_parent_for_super_prop<'a>(node: &SuperProp<'a>, parent: Node<'a>) {
6493  match node {
6494    SuperProp::Ident(value) => set_parent_for_ident_name(value, parent),
6495    SuperProp::Computed(value) => set_parent_for_computed_prop_name(value, parent),
6496  }
6497}
6498
6499#[derive(Copy, Clone)]
6500pub enum TsEntityName<'a> {
6501  TsQualifiedName(&'a TsQualifiedName<'a>),
6502  Ident(&'a Ident<'a>),
6503}
6504
6505impl<'a> TsEntityName<'a> {
6506  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6507    T::to(&self.into())
6508  }
6509
6510  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6511    let node: Node<'a> = self.into();
6512    if let Some(result) = T::to(&node) {
6513      result
6514    } else {
6515      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6516    }
6517  }
6518
6519  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6520    self.kind() == T::kind()
6521  }
6522  pub fn parent(&self) -> Node<'a> {
6523    NodeTrait::parent(self).unwrap()
6524  }
6525}
6526
6527impl<'a> SourceRanged for TsEntityName<'a> {
6528  fn start(&self) -> SourcePos {
6529    match self {
6530      TsEntityName::TsQualifiedName(node) => node.start(),
6531      TsEntityName::Ident(node) => node.start(),
6532    }
6533  }
6534  fn end(&self) -> SourcePos {
6535    match self {
6536      TsEntityName::TsQualifiedName(node) => node.end(),
6537      TsEntityName::Ident(node) => node.end(),
6538    }
6539  }
6540}
6541
6542impl<'a> NodeTrait<'a> for TsEntityName<'a> {
6543  fn parent(&self) -> Option<Node<'a>> {
6544    match self {
6545      TsEntityName::TsQualifiedName(node) => NodeTrait::parent(*node),
6546      TsEntityName::Ident(node) => NodeTrait::parent(*node),
6547    }
6548  }
6549
6550  fn children(&self) -> Vec<Node<'a>> {
6551    match self {
6552      TsEntityName::TsQualifiedName(node) => node.children(),
6553      TsEntityName::Ident(node) => node.children(),
6554    }
6555  }
6556
6557  fn as_node(&self) -> Node<'a> {
6558    match self {
6559      TsEntityName::TsQualifiedName(node) => node.as_node(),
6560      TsEntityName::Ident(node) => node.as_node(),
6561    }
6562  }
6563
6564  fn kind(&self) -> NodeKind {
6565    match self {
6566      TsEntityName::TsQualifiedName(_) => NodeKind::TsQualifiedName,
6567      TsEntityName::Ident(_) => NodeKind::Ident,
6568    }
6569  }
6570}
6571
6572impl<'a> From<&TsEntityName<'a>> for Node<'a> {
6573  fn from(node: &TsEntityName<'a>) -> Node<'a> {
6574    match node {
6575      TsEntityName::TsQualifiedName(node) => (*node).into(),
6576      TsEntityName::Ident(node) => (*node).into(),
6577    }
6578  }
6579}
6580
6581impl<'a> From<TsEntityName<'a>> for Node<'a> {
6582  fn from(node: TsEntityName<'a>) -> Node<'a> {
6583    match node {
6584      TsEntityName::TsQualifiedName(node) => node.into(),
6585      TsEntityName::Ident(node) => node.into(),
6586    }
6587  }
6588}
6589
6590fn get_view_for_ts_entity_name<'a>(inner: &'a swc_ast::TsEntityName, bump: &'a Bump) -> TsEntityName<'a> {
6591  match inner {
6592    swc_ast::TsEntityName::TsQualifiedName(value) => TsEntityName::TsQualifiedName(get_view_for_ts_qualified_name(value, bump)),
6593    swc_ast::TsEntityName::Ident(value) => TsEntityName::Ident(get_view_for_ident(value, bump)),
6594  }
6595}
6596
6597fn set_parent_for_ts_entity_name<'a>(node: &TsEntityName<'a>, parent: Node<'a>) {
6598  match node {
6599    TsEntityName::TsQualifiedName(value) => set_parent_for_ts_qualified_name(value, parent),
6600    TsEntityName::Ident(value) => set_parent_for_ident(value, parent),
6601  }
6602}
6603
6604///
6605/// - Invalid: [Ident] with empty symbol.
6606#[derive(Copy, Clone)]
6607pub enum TsEnumMemberId<'a> {
6608  Ident(&'a Ident<'a>),
6609  Str(&'a Str<'a>),
6610}
6611
6612impl<'a> TsEnumMemberId<'a> {
6613  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6614    T::to(&self.into())
6615  }
6616
6617  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6618    let node: Node<'a> = self.into();
6619    if let Some(result) = T::to(&node) {
6620      result
6621    } else {
6622      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6623    }
6624  }
6625
6626  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6627    self.kind() == T::kind()
6628  }
6629  pub fn parent(&self) -> Node<'a> {
6630    NodeTrait::parent(self).unwrap()
6631  }
6632}
6633
6634impl<'a> SourceRanged for TsEnumMemberId<'a> {
6635  fn start(&self) -> SourcePos {
6636    match self {
6637      TsEnumMemberId::Ident(node) => node.start(),
6638      TsEnumMemberId::Str(node) => node.start(),
6639    }
6640  }
6641  fn end(&self) -> SourcePos {
6642    match self {
6643      TsEnumMemberId::Ident(node) => node.end(),
6644      TsEnumMemberId::Str(node) => node.end(),
6645    }
6646  }
6647}
6648
6649impl<'a> NodeTrait<'a> for TsEnumMemberId<'a> {
6650  fn parent(&self) -> Option<Node<'a>> {
6651    match self {
6652      TsEnumMemberId::Ident(node) => NodeTrait::parent(*node),
6653      TsEnumMemberId::Str(node) => NodeTrait::parent(*node),
6654    }
6655  }
6656
6657  fn children(&self) -> Vec<Node<'a>> {
6658    match self {
6659      TsEnumMemberId::Ident(node) => node.children(),
6660      TsEnumMemberId::Str(node) => node.children(),
6661    }
6662  }
6663
6664  fn as_node(&self) -> Node<'a> {
6665    match self {
6666      TsEnumMemberId::Ident(node) => node.as_node(),
6667      TsEnumMemberId::Str(node) => node.as_node(),
6668    }
6669  }
6670
6671  fn kind(&self) -> NodeKind {
6672    match self {
6673      TsEnumMemberId::Ident(_) => NodeKind::Ident,
6674      TsEnumMemberId::Str(_) => NodeKind::Str,
6675    }
6676  }
6677}
6678
6679impl<'a> From<&TsEnumMemberId<'a>> for Node<'a> {
6680  fn from(node: &TsEnumMemberId<'a>) -> Node<'a> {
6681    match node {
6682      TsEnumMemberId::Ident(node) => (*node).into(),
6683      TsEnumMemberId::Str(node) => (*node).into(),
6684    }
6685  }
6686}
6687
6688impl<'a> From<TsEnumMemberId<'a>> for Node<'a> {
6689  fn from(node: TsEnumMemberId<'a>) -> Node<'a> {
6690    match node {
6691      TsEnumMemberId::Ident(node) => node.into(),
6692      TsEnumMemberId::Str(node) => node.into(),
6693    }
6694  }
6695}
6696
6697fn get_view_for_ts_enum_member_id<'a>(inner: &'a swc_ast::TsEnumMemberId, bump: &'a Bump) -> TsEnumMemberId<'a> {
6698  match inner {
6699    swc_ast::TsEnumMemberId::Ident(value) => TsEnumMemberId::Ident(get_view_for_ident(value, bump)),
6700    swc_ast::TsEnumMemberId::Str(value) => TsEnumMemberId::Str(get_view_for_str(value, bump)),
6701  }
6702}
6703
6704fn set_parent_for_ts_enum_member_id<'a>(node: &TsEnumMemberId<'a>, parent: Node<'a>) {
6705  match node {
6706    TsEnumMemberId::Ident(value) => set_parent_for_ident(value, parent),
6707    TsEnumMemberId::Str(value) => set_parent_for_str(value, parent),
6708  }
6709}
6710
6711#[derive(Copy, Clone)]
6712pub enum TsFnOrConstructorType<'a> {
6713  TsFnType(&'a TsFnType<'a>),
6714  TsConstructorType(&'a TsConstructorType<'a>),
6715}
6716
6717impl<'a> TsFnOrConstructorType<'a> {
6718  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6719    T::to(&self.into())
6720  }
6721
6722  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6723    let node: Node<'a> = self.into();
6724    if let Some(result) = T::to(&node) {
6725      result
6726    } else {
6727      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6728    }
6729  }
6730
6731  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6732    self.kind() == T::kind()
6733  }
6734  pub fn parent(&self) -> Node<'a> {
6735    NodeTrait::parent(self).unwrap()
6736  }
6737}
6738
6739impl<'a> SourceRanged for TsFnOrConstructorType<'a> {
6740  fn start(&self) -> SourcePos {
6741    match self {
6742      TsFnOrConstructorType::TsFnType(node) => node.start(),
6743      TsFnOrConstructorType::TsConstructorType(node) => node.start(),
6744    }
6745  }
6746  fn end(&self) -> SourcePos {
6747    match self {
6748      TsFnOrConstructorType::TsFnType(node) => node.end(),
6749      TsFnOrConstructorType::TsConstructorType(node) => node.end(),
6750    }
6751  }
6752}
6753
6754impl<'a> NodeTrait<'a> for TsFnOrConstructorType<'a> {
6755  fn parent(&self) -> Option<Node<'a>> {
6756    match self {
6757      TsFnOrConstructorType::TsFnType(node) => NodeTrait::parent(*node),
6758      TsFnOrConstructorType::TsConstructorType(node) => NodeTrait::parent(*node),
6759    }
6760  }
6761
6762  fn children(&self) -> Vec<Node<'a>> {
6763    match self {
6764      TsFnOrConstructorType::TsFnType(node) => node.children(),
6765      TsFnOrConstructorType::TsConstructorType(node) => node.children(),
6766    }
6767  }
6768
6769  fn as_node(&self) -> Node<'a> {
6770    match self {
6771      TsFnOrConstructorType::TsFnType(node) => node.as_node(),
6772      TsFnOrConstructorType::TsConstructorType(node) => node.as_node(),
6773    }
6774  }
6775
6776  fn kind(&self) -> NodeKind {
6777    match self {
6778      TsFnOrConstructorType::TsFnType(_) => NodeKind::TsFnType,
6779      TsFnOrConstructorType::TsConstructorType(_) => NodeKind::TsConstructorType,
6780    }
6781  }
6782}
6783
6784impl<'a> From<&TsFnOrConstructorType<'a>> for Node<'a> {
6785  fn from(node: &TsFnOrConstructorType<'a>) -> Node<'a> {
6786    match node {
6787      TsFnOrConstructorType::TsFnType(node) => (*node).into(),
6788      TsFnOrConstructorType::TsConstructorType(node) => (*node).into(),
6789    }
6790  }
6791}
6792
6793impl<'a> From<TsFnOrConstructorType<'a>> for Node<'a> {
6794  fn from(node: TsFnOrConstructorType<'a>) -> Node<'a> {
6795    match node {
6796      TsFnOrConstructorType::TsFnType(node) => node.into(),
6797      TsFnOrConstructorType::TsConstructorType(node) => node.into(),
6798    }
6799  }
6800}
6801
6802fn get_view_for_ts_fn_or_constructor_type<'a>(inner: &'a swc_ast::TsFnOrConstructorType, bump: &'a Bump) -> TsFnOrConstructorType<'a> {
6803  match inner {
6804    swc_ast::TsFnOrConstructorType::TsFnType(value) => TsFnOrConstructorType::TsFnType(get_view_for_ts_fn_type(value, bump)),
6805    swc_ast::TsFnOrConstructorType::TsConstructorType(value) => TsFnOrConstructorType::TsConstructorType(get_view_for_ts_constructor_type(value, bump)),
6806  }
6807}
6808
6809fn set_parent_for_ts_fn_or_constructor_type<'a>(node: &TsFnOrConstructorType<'a>, parent: Node<'a>) {
6810  match node {
6811    TsFnOrConstructorType::TsFnType(value) => set_parent_for_ts_fn_type(value, parent),
6812    TsFnOrConstructorType::TsConstructorType(value) => set_parent_for_ts_constructor_type(value, parent),
6813  }
6814}
6815
6816#[derive(Copy, Clone)]
6817pub enum TsFnParam<'a> {
6818  Ident(&'a BindingIdent<'a>),
6819  Array(&'a ArrayPat<'a>),
6820  Rest(&'a RestPat<'a>),
6821  Object(&'a ObjectPat<'a>),
6822}
6823
6824impl<'a> TsFnParam<'a> {
6825  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6826    T::to(&self.into())
6827  }
6828
6829  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6830    let node: Node<'a> = self.into();
6831    if let Some(result) = T::to(&node) {
6832      result
6833    } else {
6834      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6835    }
6836  }
6837
6838  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6839    self.kind() == T::kind()
6840  }
6841  pub fn parent(&self) -> Node<'a> {
6842    NodeTrait::parent(self).unwrap()
6843  }
6844}
6845
6846impl<'a> SourceRanged for TsFnParam<'a> {
6847  fn start(&self) -> SourcePos {
6848    match self {
6849      TsFnParam::Ident(node) => node.start(),
6850      TsFnParam::Array(node) => node.start(),
6851      TsFnParam::Rest(node) => node.start(),
6852      TsFnParam::Object(node) => node.start(),
6853    }
6854  }
6855  fn end(&self) -> SourcePos {
6856    match self {
6857      TsFnParam::Ident(node) => node.end(),
6858      TsFnParam::Array(node) => node.end(),
6859      TsFnParam::Rest(node) => node.end(),
6860      TsFnParam::Object(node) => node.end(),
6861    }
6862  }
6863}
6864
6865impl<'a> NodeTrait<'a> for TsFnParam<'a> {
6866  fn parent(&self) -> Option<Node<'a>> {
6867    match self {
6868      TsFnParam::Ident(node) => NodeTrait::parent(*node),
6869      TsFnParam::Array(node) => NodeTrait::parent(*node),
6870      TsFnParam::Rest(node) => NodeTrait::parent(*node),
6871      TsFnParam::Object(node) => NodeTrait::parent(*node),
6872    }
6873  }
6874
6875  fn children(&self) -> Vec<Node<'a>> {
6876    match self {
6877      TsFnParam::Ident(node) => node.children(),
6878      TsFnParam::Array(node) => node.children(),
6879      TsFnParam::Rest(node) => node.children(),
6880      TsFnParam::Object(node) => node.children(),
6881    }
6882  }
6883
6884  fn as_node(&self) -> Node<'a> {
6885    match self {
6886      TsFnParam::Ident(node) => node.as_node(),
6887      TsFnParam::Array(node) => node.as_node(),
6888      TsFnParam::Rest(node) => node.as_node(),
6889      TsFnParam::Object(node) => node.as_node(),
6890    }
6891  }
6892
6893  fn kind(&self) -> NodeKind {
6894    match self {
6895      TsFnParam::Ident(_) => NodeKind::BindingIdent,
6896      TsFnParam::Array(_) => NodeKind::ArrayPat,
6897      TsFnParam::Rest(_) => NodeKind::RestPat,
6898      TsFnParam::Object(_) => NodeKind::ObjectPat,
6899    }
6900  }
6901}
6902
6903impl<'a> From<&TsFnParam<'a>> for Node<'a> {
6904  fn from(node: &TsFnParam<'a>) -> Node<'a> {
6905    match node {
6906      TsFnParam::Ident(node) => (*node).into(),
6907      TsFnParam::Array(node) => (*node).into(),
6908      TsFnParam::Rest(node) => (*node).into(),
6909      TsFnParam::Object(node) => (*node).into(),
6910    }
6911  }
6912}
6913
6914impl<'a> From<TsFnParam<'a>> for Node<'a> {
6915  fn from(node: TsFnParam<'a>) -> Node<'a> {
6916    match node {
6917      TsFnParam::Ident(node) => node.into(),
6918      TsFnParam::Array(node) => node.into(),
6919      TsFnParam::Rest(node) => node.into(),
6920      TsFnParam::Object(node) => node.into(),
6921    }
6922  }
6923}
6924
6925fn get_view_for_ts_fn_param<'a>(inner: &'a swc_ast::TsFnParam, bump: &'a Bump) -> TsFnParam<'a> {
6926  match inner {
6927    swc_ast::TsFnParam::Ident(value) => TsFnParam::Ident(get_view_for_binding_ident(value, bump)),
6928    swc_ast::TsFnParam::Array(value) => TsFnParam::Array(get_view_for_array_pat(value, bump)),
6929    swc_ast::TsFnParam::Rest(value) => TsFnParam::Rest(get_view_for_rest_pat(value, bump)),
6930    swc_ast::TsFnParam::Object(value) => TsFnParam::Object(get_view_for_object_pat(value, bump)),
6931  }
6932}
6933
6934fn set_parent_for_ts_fn_param<'a>(node: &TsFnParam<'a>, parent: Node<'a>) {
6935  match node {
6936    TsFnParam::Ident(value) => set_parent_for_binding_ident(value, parent),
6937    TsFnParam::Array(value) => set_parent_for_array_pat(value, parent),
6938    TsFnParam::Rest(value) => set_parent_for_rest_pat(value, parent),
6939    TsFnParam::Object(value) => set_parent_for_object_pat(value, parent),
6940  }
6941}
6942
6943#[derive(Copy, Clone)]
6944pub enum TsLit<'a> {
6945  Number(&'a Number<'a>),
6946  Str(&'a Str<'a>),
6947  Bool(&'a Bool<'a>),
6948  BigInt(&'a BigInt<'a>),
6949  Tpl(&'a TsTplLitType<'a>),
6950}
6951
6952impl<'a> TsLit<'a> {
6953  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6954    T::to(&self.into())
6955  }
6956
6957  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6958    let node: Node<'a> = self.into();
6959    if let Some(result) = T::to(&node) {
6960      result
6961    } else {
6962      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6963    }
6964  }
6965
6966  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6967    self.kind() == T::kind()
6968  }
6969  pub fn parent(&self) -> Node<'a> {
6970    NodeTrait::parent(self).unwrap()
6971  }
6972}
6973
6974impl<'a> SourceRanged for TsLit<'a> {
6975  fn start(&self) -> SourcePos {
6976    match self {
6977      TsLit::Number(node) => node.start(),
6978      TsLit::Str(node) => node.start(),
6979      TsLit::Bool(node) => node.start(),
6980      TsLit::BigInt(node) => node.start(),
6981      TsLit::Tpl(node) => node.start(),
6982    }
6983  }
6984  fn end(&self) -> SourcePos {
6985    match self {
6986      TsLit::Number(node) => node.end(),
6987      TsLit::Str(node) => node.end(),
6988      TsLit::Bool(node) => node.end(),
6989      TsLit::BigInt(node) => node.end(),
6990      TsLit::Tpl(node) => node.end(),
6991    }
6992  }
6993}
6994
6995impl<'a> NodeTrait<'a> for TsLit<'a> {
6996  fn parent(&self) -> Option<Node<'a>> {
6997    match self {
6998      TsLit::Number(node) => NodeTrait::parent(*node),
6999      TsLit::Str(node) => NodeTrait::parent(*node),
7000      TsLit::Bool(node) => NodeTrait::parent(*node),
7001      TsLit::BigInt(node) => NodeTrait::parent(*node),
7002      TsLit::Tpl(node) => NodeTrait::parent(*node),
7003    }
7004  }
7005
7006  fn children(&self) -> Vec<Node<'a>> {
7007    match self {
7008      TsLit::Number(node) => node.children(),
7009      TsLit::Str(node) => node.children(),
7010      TsLit::Bool(node) => node.children(),
7011      TsLit::BigInt(node) => node.children(),
7012      TsLit::Tpl(node) => node.children(),
7013    }
7014  }
7015
7016  fn as_node(&self) -> Node<'a> {
7017    match self {
7018      TsLit::Number(node) => node.as_node(),
7019      TsLit::Str(node) => node.as_node(),
7020      TsLit::Bool(node) => node.as_node(),
7021      TsLit::BigInt(node) => node.as_node(),
7022      TsLit::Tpl(node) => node.as_node(),
7023    }
7024  }
7025
7026  fn kind(&self) -> NodeKind {
7027    match self {
7028      TsLit::Number(_) => NodeKind::Number,
7029      TsLit::Str(_) => NodeKind::Str,
7030      TsLit::Bool(_) => NodeKind::Bool,
7031      TsLit::BigInt(_) => NodeKind::BigInt,
7032      TsLit::Tpl(_) => NodeKind::TsTplLitType,
7033    }
7034  }
7035}
7036
7037impl<'a> From<&TsLit<'a>> for Node<'a> {
7038  fn from(node: &TsLit<'a>) -> Node<'a> {
7039    match node {
7040      TsLit::Number(node) => (*node).into(),
7041      TsLit::Str(node) => (*node).into(),
7042      TsLit::Bool(node) => (*node).into(),
7043      TsLit::BigInt(node) => (*node).into(),
7044      TsLit::Tpl(node) => (*node).into(),
7045    }
7046  }
7047}
7048
7049impl<'a> From<TsLit<'a>> for Node<'a> {
7050  fn from(node: TsLit<'a>) -> Node<'a> {
7051    match node {
7052      TsLit::Number(node) => node.into(),
7053      TsLit::Str(node) => node.into(),
7054      TsLit::Bool(node) => node.into(),
7055      TsLit::BigInt(node) => node.into(),
7056      TsLit::Tpl(node) => node.into(),
7057    }
7058  }
7059}
7060
7061fn get_view_for_ts_lit<'a>(inner: &'a swc_ast::TsLit, bump: &'a Bump) -> TsLit<'a> {
7062  match inner {
7063    swc_ast::TsLit::Number(value) => TsLit::Number(get_view_for_number(value, bump)),
7064    swc_ast::TsLit::Str(value) => TsLit::Str(get_view_for_str(value, bump)),
7065    swc_ast::TsLit::Bool(value) => TsLit::Bool(get_view_for_bool(value, bump)),
7066    swc_ast::TsLit::BigInt(value) => TsLit::BigInt(get_view_for_big_int(value, bump)),
7067    swc_ast::TsLit::Tpl(value) => TsLit::Tpl(get_view_for_ts_tpl_lit_type(value, bump)),
7068  }
7069}
7070
7071fn set_parent_for_ts_lit<'a>(node: &TsLit<'a>, parent: Node<'a>) {
7072  match node {
7073    TsLit::Number(value) => set_parent_for_number(value, parent),
7074    TsLit::Str(value) => set_parent_for_str(value, parent),
7075    TsLit::Bool(value) => set_parent_for_bool(value, parent),
7076    TsLit::BigInt(value) => set_parent_for_big_int(value, parent),
7077    TsLit::Tpl(value) => set_parent_for_ts_tpl_lit_type(value, parent),
7078  }
7079}
7080
7081#[derive(Copy, Clone)]
7082pub enum TsModuleName<'a> {
7083  Ident(&'a Ident<'a>),
7084  Str(&'a Str<'a>),
7085}
7086
7087impl<'a> TsModuleName<'a> {
7088  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7089    T::to(&self.into())
7090  }
7091
7092  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7093    let node: Node<'a> = self.into();
7094    if let Some(result) = T::to(&node) {
7095      result
7096    } else {
7097      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7098    }
7099  }
7100
7101  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7102    self.kind() == T::kind()
7103  }
7104  pub fn parent(&self) -> Node<'a> {
7105    NodeTrait::parent(self).unwrap()
7106  }
7107}
7108
7109impl<'a> SourceRanged for TsModuleName<'a> {
7110  fn start(&self) -> SourcePos {
7111    match self {
7112      TsModuleName::Ident(node) => node.start(),
7113      TsModuleName::Str(node) => node.start(),
7114    }
7115  }
7116  fn end(&self) -> SourcePos {
7117    match self {
7118      TsModuleName::Ident(node) => node.end(),
7119      TsModuleName::Str(node) => node.end(),
7120    }
7121  }
7122}
7123
7124impl<'a> NodeTrait<'a> for TsModuleName<'a> {
7125  fn parent(&self) -> Option<Node<'a>> {
7126    match self {
7127      TsModuleName::Ident(node) => NodeTrait::parent(*node),
7128      TsModuleName::Str(node) => NodeTrait::parent(*node),
7129    }
7130  }
7131
7132  fn children(&self) -> Vec<Node<'a>> {
7133    match self {
7134      TsModuleName::Ident(node) => node.children(),
7135      TsModuleName::Str(node) => node.children(),
7136    }
7137  }
7138
7139  fn as_node(&self) -> Node<'a> {
7140    match self {
7141      TsModuleName::Ident(node) => node.as_node(),
7142      TsModuleName::Str(node) => node.as_node(),
7143    }
7144  }
7145
7146  fn kind(&self) -> NodeKind {
7147    match self {
7148      TsModuleName::Ident(_) => NodeKind::Ident,
7149      TsModuleName::Str(_) => NodeKind::Str,
7150    }
7151  }
7152}
7153
7154impl<'a> From<&TsModuleName<'a>> for Node<'a> {
7155  fn from(node: &TsModuleName<'a>) -> Node<'a> {
7156    match node {
7157      TsModuleName::Ident(node) => (*node).into(),
7158      TsModuleName::Str(node) => (*node).into(),
7159    }
7160  }
7161}
7162
7163impl<'a> From<TsModuleName<'a>> for Node<'a> {
7164  fn from(node: TsModuleName<'a>) -> Node<'a> {
7165    match node {
7166      TsModuleName::Ident(node) => node.into(),
7167      TsModuleName::Str(node) => node.into(),
7168    }
7169  }
7170}
7171
7172fn get_view_for_ts_module_name<'a>(inner: &'a swc_ast::TsModuleName, bump: &'a Bump) -> TsModuleName<'a> {
7173  match inner {
7174    swc_ast::TsModuleName::Ident(value) => TsModuleName::Ident(get_view_for_ident(value, bump)),
7175    swc_ast::TsModuleName::Str(value) => TsModuleName::Str(get_view_for_str(value, bump)),
7176  }
7177}
7178
7179fn set_parent_for_ts_module_name<'a>(node: &TsModuleName<'a>, parent: Node<'a>) {
7180  match node {
7181    TsModuleName::Ident(value) => set_parent_for_ident(value, parent),
7182    TsModuleName::Str(value) => set_parent_for_str(value, parent),
7183  }
7184}
7185
7186#[derive(Copy, Clone)]
7187pub enum TsModuleRef<'a> {
7188  TsEntityName(TsEntityName<'a>),
7189  TsExternalModuleRef(&'a TsExternalModuleRef<'a>),
7190}
7191
7192impl<'a> TsModuleRef<'a> {
7193  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7194    T::to(&self.into())
7195  }
7196
7197  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7198    let node: Node<'a> = self.into();
7199    if let Some(result) = T::to(&node) {
7200      result
7201    } else {
7202      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7203    }
7204  }
7205
7206  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7207    self.kind() == T::kind()
7208  }
7209}
7210
7211impl<'a> SourceRanged for TsModuleRef<'a> {
7212  fn start(&self) -> SourcePos {
7213    match self {
7214      TsModuleRef::TsEntityName(node) => node.start(),
7215      TsModuleRef::TsExternalModuleRef(node) => node.start(),
7216    }
7217  }
7218  fn end(&self) -> SourcePos {
7219    match self {
7220      TsModuleRef::TsEntityName(node) => node.end(),
7221      TsModuleRef::TsExternalModuleRef(node) => node.end(),
7222    }
7223  }
7224}
7225
7226impl<'a> NodeTrait<'a> for TsModuleRef<'a> {
7227  fn parent(&self) -> Option<Node<'a>> {
7228    match self {
7229      TsModuleRef::TsEntityName(node) => NodeTrait::parent(node),
7230      TsModuleRef::TsExternalModuleRef(node) => NodeTrait::parent(*node),
7231    }
7232  }
7233
7234  fn children(&self) -> Vec<Node<'a>> {
7235    match self {
7236      TsModuleRef::TsEntityName(node) => node.children(),
7237      TsModuleRef::TsExternalModuleRef(node) => node.children(),
7238    }
7239  }
7240
7241  fn as_node(&self) -> Node<'a> {
7242    match self {
7243      TsModuleRef::TsEntityName(node) => node.as_node(),
7244      TsModuleRef::TsExternalModuleRef(node) => node.as_node(),
7245    }
7246  }
7247
7248  fn kind(&self) -> NodeKind {
7249    match self {
7250      TsModuleRef::TsEntityName(node) => node.kind(),
7251      TsModuleRef::TsExternalModuleRef(_) => NodeKind::TsExternalModuleRef,
7252    }
7253  }
7254}
7255
7256impl<'a> From<&TsModuleRef<'a>> for Node<'a> {
7257  fn from(node: &TsModuleRef<'a>) -> Node<'a> {
7258    match node {
7259      TsModuleRef::TsEntityName(node) => node.into(),
7260      TsModuleRef::TsExternalModuleRef(node) => (*node).into(),
7261    }
7262  }
7263}
7264
7265impl<'a> From<TsModuleRef<'a>> for Node<'a> {
7266  fn from(node: TsModuleRef<'a>) -> Node<'a> {
7267    match node {
7268      TsModuleRef::TsEntityName(node) => node.into(),
7269      TsModuleRef::TsExternalModuleRef(node) => node.into(),
7270    }
7271  }
7272}
7273
7274fn get_view_for_ts_module_ref<'a>(inner: &'a swc_ast::TsModuleRef, bump: &'a Bump) -> TsModuleRef<'a> {
7275  match inner {
7276    swc_ast::TsModuleRef::TsEntityName(value) => TsModuleRef::TsEntityName(get_view_for_ts_entity_name(value, bump)),
7277    swc_ast::TsModuleRef::TsExternalModuleRef(value) => TsModuleRef::TsExternalModuleRef(get_view_for_ts_external_module_ref(value, bump)),
7278  }
7279}
7280
7281fn set_parent_for_ts_module_ref<'a>(node: &TsModuleRef<'a>, parent: Node<'a>) {
7282  match node {
7283    TsModuleRef::TsEntityName(value) => set_parent_for_ts_entity_name(value, parent),
7284    TsModuleRef::TsExternalModuleRef(value) => set_parent_for_ts_external_module_ref(value, parent),
7285  }
7286}
7287
7288/// `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as
7289/// its body.
7290#[derive(Copy, Clone)]
7291pub enum TsNamespaceBody<'a> {
7292  TsModuleBlock(&'a TsModuleBlock<'a>),
7293  TsNamespaceDecl(&'a TsNamespaceDecl<'a>),
7294}
7295
7296impl<'a> TsNamespaceBody<'a> {
7297  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7298    T::to(&self.into())
7299  }
7300
7301  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7302    let node: Node<'a> = self.into();
7303    if let Some(result) = T::to(&node) {
7304      result
7305    } else {
7306      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7307    }
7308  }
7309
7310  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7311    self.kind() == T::kind()
7312  }
7313  pub fn parent(&self) -> Node<'a> {
7314    NodeTrait::parent(self).unwrap()
7315  }
7316}
7317
7318impl<'a> SourceRanged for TsNamespaceBody<'a> {
7319  fn start(&self) -> SourcePos {
7320    match self {
7321      TsNamespaceBody::TsModuleBlock(node) => node.start(),
7322      TsNamespaceBody::TsNamespaceDecl(node) => node.start(),
7323    }
7324  }
7325  fn end(&self) -> SourcePos {
7326    match self {
7327      TsNamespaceBody::TsModuleBlock(node) => node.end(),
7328      TsNamespaceBody::TsNamespaceDecl(node) => node.end(),
7329    }
7330  }
7331}
7332
7333impl<'a> NodeTrait<'a> for TsNamespaceBody<'a> {
7334  fn parent(&self) -> Option<Node<'a>> {
7335    match self {
7336      TsNamespaceBody::TsModuleBlock(node) => NodeTrait::parent(*node),
7337      TsNamespaceBody::TsNamespaceDecl(node) => NodeTrait::parent(*node),
7338    }
7339  }
7340
7341  fn children(&self) -> Vec<Node<'a>> {
7342    match self {
7343      TsNamespaceBody::TsModuleBlock(node) => node.children(),
7344      TsNamespaceBody::TsNamespaceDecl(node) => node.children(),
7345    }
7346  }
7347
7348  fn as_node(&self) -> Node<'a> {
7349    match self {
7350      TsNamespaceBody::TsModuleBlock(node) => node.as_node(),
7351      TsNamespaceBody::TsNamespaceDecl(node) => node.as_node(),
7352    }
7353  }
7354
7355  fn kind(&self) -> NodeKind {
7356    match self {
7357      TsNamespaceBody::TsModuleBlock(_) => NodeKind::TsModuleBlock,
7358      TsNamespaceBody::TsNamespaceDecl(_) => NodeKind::TsNamespaceDecl,
7359    }
7360  }
7361}
7362
7363impl<'a> From<&TsNamespaceBody<'a>> for Node<'a> {
7364  fn from(node: &TsNamespaceBody<'a>) -> Node<'a> {
7365    match node {
7366      TsNamespaceBody::TsModuleBlock(node) => (*node).into(),
7367      TsNamespaceBody::TsNamespaceDecl(node) => (*node).into(),
7368    }
7369  }
7370}
7371
7372impl<'a> From<TsNamespaceBody<'a>> for Node<'a> {
7373  fn from(node: TsNamespaceBody<'a>) -> Node<'a> {
7374    match node {
7375      TsNamespaceBody::TsModuleBlock(node) => node.into(),
7376      TsNamespaceBody::TsNamespaceDecl(node) => node.into(),
7377    }
7378  }
7379}
7380
7381fn get_view_for_ts_namespace_body<'a>(inner: &'a swc_ast::TsNamespaceBody, bump: &'a Bump) -> TsNamespaceBody<'a> {
7382  match inner {
7383    swc_ast::TsNamespaceBody::TsModuleBlock(value) => TsNamespaceBody::TsModuleBlock(get_view_for_ts_module_block(value, bump)),
7384    swc_ast::TsNamespaceBody::TsNamespaceDecl(value) => TsNamespaceBody::TsNamespaceDecl(get_view_for_ts_namespace_decl(value, bump)),
7385  }
7386}
7387
7388fn set_parent_for_ts_namespace_body<'a>(node: &TsNamespaceBody<'a>, parent: Node<'a>) {
7389  match node {
7390    TsNamespaceBody::TsModuleBlock(value) => set_parent_for_ts_module_block(value, parent),
7391    TsNamespaceBody::TsNamespaceDecl(value) => set_parent_for_ts_namespace_decl(value, parent),
7392  }
7393}
7394
7395#[derive(Copy, Clone)]
7396pub enum TsParamPropParam<'a> {
7397  Ident(&'a BindingIdent<'a>),
7398  Assign(&'a AssignPat<'a>),
7399}
7400
7401impl<'a> TsParamPropParam<'a> {
7402  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7403    T::to(&self.into())
7404  }
7405
7406  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7407    let node: Node<'a> = self.into();
7408    if let Some(result) = T::to(&node) {
7409      result
7410    } else {
7411      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7412    }
7413  }
7414
7415  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7416    self.kind() == T::kind()
7417  }
7418  pub fn parent(&self) -> Node<'a> {
7419    NodeTrait::parent(self).unwrap()
7420  }
7421}
7422
7423impl<'a> SourceRanged for TsParamPropParam<'a> {
7424  fn start(&self) -> SourcePos {
7425    match self {
7426      TsParamPropParam::Ident(node) => node.start(),
7427      TsParamPropParam::Assign(node) => node.start(),
7428    }
7429  }
7430  fn end(&self) -> SourcePos {
7431    match self {
7432      TsParamPropParam::Ident(node) => node.end(),
7433      TsParamPropParam::Assign(node) => node.end(),
7434    }
7435  }
7436}
7437
7438impl<'a> NodeTrait<'a> for TsParamPropParam<'a> {
7439  fn parent(&self) -> Option<Node<'a>> {
7440    match self {
7441      TsParamPropParam::Ident(node) => NodeTrait::parent(*node),
7442      TsParamPropParam::Assign(node) => NodeTrait::parent(*node),
7443    }
7444  }
7445
7446  fn children(&self) -> Vec<Node<'a>> {
7447    match self {
7448      TsParamPropParam::Ident(node) => node.children(),
7449      TsParamPropParam::Assign(node) => node.children(),
7450    }
7451  }
7452
7453  fn as_node(&self) -> Node<'a> {
7454    match self {
7455      TsParamPropParam::Ident(node) => node.as_node(),
7456      TsParamPropParam::Assign(node) => node.as_node(),
7457    }
7458  }
7459
7460  fn kind(&self) -> NodeKind {
7461    match self {
7462      TsParamPropParam::Ident(_) => NodeKind::BindingIdent,
7463      TsParamPropParam::Assign(_) => NodeKind::AssignPat,
7464    }
7465  }
7466}
7467
7468impl<'a> From<&TsParamPropParam<'a>> for Node<'a> {
7469  fn from(node: &TsParamPropParam<'a>) -> Node<'a> {
7470    match node {
7471      TsParamPropParam::Ident(node) => (*node).into(),
7472      TsParamPropParam::Assign(node) => (*node).into(),
7473    }
7474  }
7475}
7476
7477impl<'a> From<TsParamPropParam<'a>> for Node<'a> {
7478  fn from(node: TsParamPropParam<'a>) -> Node<'a> {
7479    match node {
7480      TsParamPropParam::Ident(node) => node.into(),
7481      TsParamPropParam::Assign(node) => node.into(),
7482    }
7483  }
7484}
7485
7486fn get_view_for_ts_param_prop_param<'a>(inner: &'a swc_ast::TsParamPropParam, bump: &'a Bump) -> TsParamPropParam<'a> {
7487  match inner {
7488    swc_ast::TsParamPropParam::Ident(value) => TsParamPropParam::Ident(get_view_for_binding_ident(value, bump)),
7489    swc_ast::TsParamPropParam::Assign(value) => TsParamPropParam::Assign(get_view_for_assign_pat(value, bump)),
7490  }
7491}
7492
7493fn set_parent_for_ts_param_prop_param<'a>(node: &TsParamPropParam<'a>, parent: Node<'a>) {
7494  match node {
7495    TsParamPropParam::Ident(value) => set_parent_for_binding_ident(value, parent),
7496    TsParamPropParam::Assign(value) => set_parent_for_assign_pat(value, parent),
7497  }
7498}
7499
7500#[derive(Copy, Clone)]
7501pub enum TsThisTypeOrIdent<'a> {
7502  TsThisType(&'a TsThisType<'a>),
7503  Ident(&'a Ident<'a>),
7504}
7505
7506impl<'a> TsThisTypeOrIdent<'a> {
7507  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7508    T::to(&self.into())
7509  }
7510
7511  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7512    let node: Node<'a> = self.into();
7513    if let Some(result) = T::to(&node) {
7514      result
7515    } else {
7516      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7517    }
7518  }
7519
7520  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7521    self.kind() == T::kind()
7522  }
7523  pub fn parent(&self) -> Node<'a> {
7524    NodeTrait::parent(self).unwrap()
7525  }
7526}
7527
7528impl<'a> SourceRanged for TsThisTypeOrIdent<'a> {
7529  fn start(&self) -> SourcePos {
7530    match self {
7531      TsThisTypeOrIdent::TsThisType(node) => node.start(),
7532      TsThisTypeOrIdent::Ident(node) => node.start(),
7533    }
7534  }
7535  fn end(&self) -> SourcePos {
7536    match self {
7537      TsThisTypeOrIdent::TsThisType(node) => node.end(),
7538      TsThisTypeOrIdent::Ident(node) => node.end(),
7539    }
7540  }
7541}
7542
7543impl<'a> NodeTrait<'a> for TsThisTypeOrIdent<'a> {
7544  fn parent(&self) -> Option<Node<'a>> {
7545    match self {
7546      TsThisTypeOrIdent::TsThisType(node) => NodeTrait::parent(*node),
7547      TsThisTypeOrIdent::Ident(node) => NodeTrait::parent(*node),
7548    }
7549  }
7550
7551  fn children(&self) -> Vec<Node<'a>> {
7552    match self {
7553      TsThisTypeOrIdent::TsThisType(node) => node.children(),
7554      TsThisTypeOrIdent::Ident(node) => node.children(),
7555    }
7556  }
7557
7558  fn as_node(&self) -> Node<'a> {
7559    match self {
7560      TsThisTypeOrIdent::TsThisType(node) => node.as_node(),
7561      TsThisTypeOrIdent::Ident(node) => node.as_node(),
7562    }
7563  }
7564
7565  fn kind(&self) -> NodeKind {
7566    match self {
7567      TsThisTypeOrIdent::TsThisType(_) => NodeKind::TsThisType,
7568      TsThisTypeOrIdent::Ident(_) => NodeKind::Ident,
7569    }
7570  }
7571}
7572
7573impl<'a> From<&TsThisTypeOrIdent<'a>> for Node<'a> {
7574  fn from(node: &TsThisTypeOrIdent<'a>) -> Node<'a> {
7575    match node {
7576      TsThisTypeOrIdent::TsThisType(node) => (*node).into(),
7577      TsThisTypeOrIdent::Ident(node) => (*node).into(),
7578    }
7579  }
7580}
7581
7582impl<'a> From<TsThisTypeOrIdent<'a>> for Node<'a> {
7583  fn from(node: TsThisTypeOrIdent<'a>) -> Node<'a> {
7584    match node {
7585      TsThisTypeOrIdent::TsThisType(node) => node.into(),
7586      TsThisTypeOrIdent::Ident(node) => node.into(),
7587    }
7588  }
7589}
7590
7591fn get_view_for_ts_this_type_or_ident<'a>(inner: &'a swc_ast::TsThisTypeOrIdent, bump: &'a Bump) -> TsThisTypeOrIdent<'a> {
7592  match inner {
7593    swc_ast::TsThisTypeOrIdent::TsThisType(value) => TsThisTypeOrIdent::TsThisType(get_view_for_ts_this_type(value, bump)),
7594    swc_ast::TsThisTypeOrIdent::Ident(value) => TsThisTypeOrIdent::Ident(get_view_for_ident(value, bump)),
7595  }
7596}
7597
7598fn set_parent_for_ts_this_type_or_ident<'a>(node: &TsThisTypeOrIdent<'a>, parent: Node<'a>) {
7599  match node {
7600    TsThisTypeOrIdent::TsThisType(value) => set_parent_for_ts_this_type(value, parent),
7601    TsThisTypeOrIdent::Ident(value) => set_parent_for_ident(value, parent),
7602  }
7603}
7604
7605#[derive(Copy, Clone)]
7606pub enum TsType<'a> {
7607  TsKeywordType(&'a TsKeywordType<'a>),
7608  TsThisType(&'a TsThisType<'a>),
7609  TsFnOrConstructorType(TsFnOrConstructorType<'a>),
7610  TsTypeRef(&'a TsTypeRef<'a>),
7611  TsTypeQuery(&'a TsTypeQuery<'a>),
7612  TsTypeLit(&'a TsTypeLit<'a>),
7613  TsArrayType(&'a TsArrayType<'a>),
7614  TsTupleType(&'a TsTupleType<'a>),
7615  TsOptionalType(&'a TsOptionalType<'a>),
7616  TsRestType(&'a TsRestType<'a>),
7617  TsUnionOrIntersectionType(TsUnionOrIntersectionType<'a>),
7618  TsConditionalType(&'a TsConditionalType<'a>),
7619  TsInferType(&'a TsInferType<'a>),
7620  TsParenthesizedType(&'a TsParenthesizedType<'a>),
7621  TsTypeOperator(&'a TsTypeOperator<'a>),
7622  TsIndexedAccessType(&'a TsIndexedAccessType<'a>),
7623  TsMappedType(&'a TsMappedType<'a>),
7624  TsLitType(&'a TsLitType<'a>),
7625  TsTypePredicate(&'a TsTypePredicate<'a>),
7626  TsImportType(&'a TsImportType<'a>),
7627}
7628
7629impl<'a> TsType<'a> {
7630  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7631    T::to(&self.into())
7632  }
7633
7634  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7635    let node: Node<'a> = self.into();
7636    if let Some(result) = T::to(&node) {
7637      result
7638    } else {
7639      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7640    }
7641  }
7642
7643  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7644    self.kind() == T::kind()
7645  }
7646}
7647
7648impl<'a> SourceRanged for TsType<'a> {
7649  fn start(&self) -> SourcePos {
7650    match self {
7651      TsType::TsKeywordType(node) => node.start(),
7652      TsType::TsThisType(node) => node.start(),
7653      TsType::TsFnOrConstructorType(node) => node.start(),
7654      TsType::TsTypeRef(node) => node.start(),
7655      TsType::TsTypeQuery(node) => node.start(),
7656      TsType::TsTypeLit(node) => node.start(),
7657      TsType::TsArrayType(node) => node.start(),
7658      TsType::TsTupleType(node) => node.start(),
7659      TsType::TsOptionalType(node) => node.start(),
7660      TsType::TsRestType(node) => node.start(),
7661      TsType::TsUnionOrIntersectionType(node) => node.start(),
7662      TsType::TsConditionalType(node) => node.start(),
7663      TsType::TsInferType(node) => node.start(),
7664      TsType::TsParenthesizedType(node) => node.start(),
7665      TsType::TsTypeOperator(node) => node.start(),
7666      TsType::TsIndexedAccessType(node) => node.start(),
7667      TsType::TsMappedType(node) => node.start(),
7668      TsType::TsLitType(node) => node.start(),
7669      TsType::TsTypePredicate(node) => node.start(),
7670      TsType::TsImportType(node) => node.start(),
7671    }
7672  }
7673  fn end(&self) -> SourcePos {
7674    match self {
7675      TsType::TsKeywordType(node) => node.end(),
7676      TsType::TsThisType(node) => node.end(),
7677      TsType::TsFnOrConstructorType(node) => node.end(),
7678      TsType::TsTypeRef(node) => node.end(),
7679      TsType::TsTypeQuery(node) => node.end(),
7680      TsType::TsTypeLit(node) => node.end(),
7681      TsType::TsArrayType(node) => node.end(),
7682      TsType::TsTupleType(node) => node.end(),
7683      TsType::TsOptionalType(node) => node.end(),
7684      TsType::TsRestType(node) => node.end(),
7685      TsType::TsUnionOrIntersectionType(node) => node.end(),
7686      TsType::TsConditionalType(node) => node.end(),
7687      TsType::TsInferType(node) => node.end(),
7688      TsType::TsParenthesizedType(node) => node.end(),
7689      TsType::TsTypeOperator(node) => node.end(),
7690      TsType::TsIndexedAccessType(node) => node.end(),
7691      TsType::TsMappedType(node) => node.end(),
7692      TsType::TsLitType(node) => node.end(),
7693      TsType::TsTypePredicate(node) => node.end(),
7694      TsType::TsImportType(node) => node.end(),
7695    }
7696  }
7697}
7698
7699impl<'a> NodeTrait<'a> for TsType<'a> {
7700  fn parent(&self) -> Option<Node<'a>> {
7701    match self {
7702      TsType::TsKeywordType(node) => NodeTrait::parent(*node),
7703      TsType::TsThisType(node) => NodeTrait::parent(*node),
7704      TsType::TsFnOrConstructorType(node) => NodeTrait::parent(node),
7705      TsType::TsTypeRef(node) => NodeTrait::parent(*node),
7706      TsType::TsTypeQuery(node) => NodeTrait::parent(*node),
7707      TsType::TsTypeLit(node) => NodeTrait::parent(*node),
7708      TsType::TsArrayType(node) => NodeTrait::parent(*node),
7709      TsType::TsTupleType(node) => NodeTrait::parent(*node),
7710      TsType::TsOptionalType(node) => NodeTrait::parent(*node),
7711      TsType::TsRestType(node) => NodeTrait::parent(*node),
7712      TsType::TsUnionOrIntersectionType(node) => NodeTrait::parent(node),
7713      TsType::TsConditionalType(node) => NodeTrait::parent(*node),
7714      TsType::TsInferType(node) => NodeTrait::parent(*node),
7715      TsType::TsParenthesizedType(node) => NodeTrait::parent(*node),
7716      TsType::TsTypeOperator(node) => NodeTrait::parent(*node),
7717      TsType::TsIndexedAccessType(node) => NodeTrait::parent(*node),
7718      TsType::TsMappedType(node) => NodeTrait::parent(*node),
7719      TsType::TsLitType(node) => NodeTrait::parent(*node),
7720      TsType::TsTypePredicate(node) => NodeTrait::parent(*node),
7721      TsType::TsImportType(node) => NodeTrait::parent(*node),
7722    }
7723  }
7724
7725  fn children(&self) -> Vec<Node<'a>> {
7726    match self {
7727      TsType::TsKeywordType(node) => node.children(),
7728      TsType::TsThisType(node) => node.children(),
7729      TsType::TsFnOrConstructorType(node) => node.children(),
7730      TsType::TsTypeRef(node) => node.children(),
7731      TsType::TsTypeQuery(node) => node.children(),
7732      TsType::TsTypeLit(node) => node.children(),
7733      TsType::TsArrayType(node) => node.children(),
7734      TsType::TsTupleType(node) => node.children(),
7735      TsType::TsOptionalType(node) => node.children(),
7736      TsType::TsRestType(node) => node.children(),
7737      TsType::TsUnionOrIntersectionType(node) => node.children(),
7738      TsType::TsConditionalType(node) => node.children(),
7739      TsType::TsInferType(node) => node.children(),
7740      TsType::TsParenthesizedType(node) => node.children(),
7741      TsType::TsTypeOperator(node) => node.children(),
7742      TsType::TsIndexedAccessType(node) => node.children(),
7743      TsType::TsMappedType(node) => node.children(),
7744      TsType::TsLitType(node) => node.children(),
7745      TsType::TsTypePredicate(node) => node.children(),
7746      TsType::TsImportType(node) => node.children(),
7747    }
7748  }
7749
7750  fn as_node(&self) -> Node<'a> {
7751    match self {
7752      TsType::TsKeywordType(node) => node.as_node(),
7753      TsType::TsThisType(node) => node.as_node(),
7754      TsType::TsFnOrConstructorType(node) => node.as_node(),
7755      TsType::TsTypeRef(node) => node.as_node(),
7756      TsType::TsTypeQuery(node) => node.as_node(),
7757      TsType::TsTypeLit(node) => node.as_node(),
7758      TsType::TsArrayType(node) => node.as_node(),
7759      TsType::TsTupleType(node) => node.as_node(),
7760      TsType::TsOptionalType(node) => node.as_node(),
7761      TsType::TsRestType(node) => node.as_node(),
7762      TsType::TsUnionOrIntersectionType(node) => node.as_node(),
7763      TsType::TsConditionalType(node) => node.as_node(),
7764      TsType::TsInferType(node) => node.as_node(),
7765      TsType::TsParenthesizedType(node) => node.as_node(),
7766      TsType::TsTypeOperator(node) => node.as_node(),
7767      TsType::TsIndexedAccessType(node) => node.as_node(),
7768      TsType::TsMappedType(node) => node.as_node(),
7769      TsType::TsLitType(node) => node.as_node(),
7770      TsType::TsTypePredicate(node) => node.as_node(),
7771      TsType::TsImportType(node) => node.as_node(),
7772    }
7773  }
7774
7775  fn kind(&self) -> NodeKind {
7776    match self {
7777      TsType::TsKeywordType(_) => NodeKind::TsKeywordType,
7778      TsType::TsThisType(_) => NodeKind::TsThisType,
7779      TsType::TsFnOrConstructorType(node) => node.kind(),
7780      TsType::TsTypeRef(_) => NodeKind::TsTypeRef,
7781      TsType::TsTypeQuery(_) => NodeKind::TsTypeQuery,
7782      TsType::TsTypeLit(_) => NodeKind::TsTypeLit,
7783      TsType::TsArrayType(_) => NodeKind::TsArrayType,
7784      TsType::TsTupleType(_) => NodeKind::TsTupleType,
7785      TsType::TsOptionalType(_) => NodeKind::TsOptionalType,
7786      TsType::TsRestType(_) => NodeKind::TsRestType,
7787      TsType::TsUnionOrIntersectionType(node) => node.kind(),
7788      TsType::TsConditionalType(_) => NodeKind::TsConditionalType,
7789      TsType::TsInferType(_) => NodeKind::TsInferType,
7790      TsType::TsParenthesizedType(_) => NodeKind::TsParenthesizedType,
7791      TsType::TsTypeOperator(_) => NodeKind::TsTypeOperator,
7792      TsType::TsIndexedAccessType(_) => NodeKind::TsIndexedAccessType,
7793      TsType::TsMappedType(_) => NodeKind::TsMappedType,
7794      TsType::TsLitType(_) => NodeKind::TsLitType,
7795      TsType::TsTypePredicate(_) => NodeKind::TsTypePredicate,
7796      TsType::TsImportType(_) => NodeKind::TsImportType,
7797    }
7798  }
7799}
7800
7801impl<'a> From<&TsType<'a>> for Node<'a> {
7802  fn from(node: &TsType<'a>) -> Node<'a> {
7803    match node {
7804      TsType::TsKeywordType(node) => (*node).into(),
7805      TsType::TsThisType(node) => (*node).into(),
7806      TsType::TsFnOrConstructorType(node) => node.into(),
7807      TsType::TsTypeRef(node) => (*node).into(),
7808      TsType::TsTypeQuery(node) => (*node).into(),
7809      TsType::TsTypeLit(node) => (*node).into(),
7810      TsType::TsArrayType(node) => (*node).into(),
7811      TsType::TsTupleType(node) => (*node).into(),
7812      TsType::TsOptionalType(node) => (*node).into(),
7813      TsType::TsRestType(node) => (*node).into(),
7814      TsType::TsUnionOrIntersectionType(node) => node.into(),
7815      TsType::TsConditionalType(node) => (*node).into(),
7816      TsType::TsInferType(node) => (*node).into(),
7817      TsType::TsParenthesizedType(node) => (*node).into(),
7818      TsType::TsTypeOperator(node) => (*node).into(),
7819      TsType::TsIndexedAccessType(node) => (*node).into(),
7820      TsType::TsMappedType(node) => (*node).into(),
7821      TsType::TsLitType(node) => (*node).into(),
7822      TsType::TsTypePredicate(node) => (*node).into(),
7823      TsType::TsImportType(node) => (*node).into(),
7824    }
7825  }
7826}
7827
7828impl<'a> From<TsType<'a>> for Node<'a> {
7829  fn from(node: TsType<'a>) -> Node<'a> {
7830    match node {
7831      TsType::TsKeywordType(node) => node.into(),
7832      TsType::TsThisType(node) => node.into(),
7833      TsType::TsFnOrConstructorType(node) => node.into(),
7834      TsType::TsTypeRef(node) => node.into(),
7835      TsType::TsTypeQuery(node) => node.into(),
7836      TsType::TsTypeLit(node) => node.into(),
7837      TsType::TsArrayType(node) => node.into(),
7838      TsType::TsTupleType(node) => node.into(),
7839      TsType::TsOptionalType(node) => node.into(),
7840      TsType::TsRestType(node) => node.into(),
7841      TsType::TsUnionOrIntersectionType(node) => node.into(),
7842      TsType::TsConditionalType(node) => node.into(),
7843      TsType::TsInferType(node) => node.into(),
7844      TsType::TsParenthesizedType(node) => node.into(),
7845      TsType::TsTypeOperator(node) => node.into(),
7846      TsType::TsIndexedAccessType(node) => node.into(),
7847      TsType::TsMappedType(node) => node.into(),
7848      TsType::TsLitType(node) => node.into(),
7849      TsType::TsTypePredicate(node) => node.into(),
7850      TsType::TsImportType(node) => node.into(),
7851    }
7852  }
7853}
7854
7855fn get_view_for_ts_type<'a>(inner: &'a swc_ast::TsType, bump: &'a Bump) -> TsType<'a> {
7856  match inner {
7857    swc_ast::TsType::TsKeywordType(value) => TsType::TsKeywordType(get_view_for_ts_keyword_type(value, bump)),
7858    swc_ast::TsType::TsThisType(value) => TsType::TsThisType(get_view_for_ts_this_type(value, bump)),
7859    swc_ast::TsType::TsFnOrConstructorType(value) => TsType::TsFnOrConstructorType(get_view_for_ts_fn_or_constructor_type(value, bump)),
7860    swc_ast::TsType::TsTypeRef(value) => TsType::TsTypeRef(get_view_for_ts_type_ref(value, bump)),
7861    swc_ast::TsType::TsTypeQuery(value) => TsType::TsTypeQuery(get_view_for_ts_type_query(value, bump)),
7862    swc_ast::TsType::TsTypeLit(value) => TsType::TsTypeLit(get_view_for_ts_type_lit(value, bump)),
7863    swc_ast::TsType::TsArrayType(value) => TsType::TsArrayType(get_view_for_ts_array_type(value, bump)),
7864    swc_ast::TsType::TsTupleType(value) => TsType::TsTupleType(get_view_for_ts_tuple_type(value, bump)),
7865    swc_ast::TsType::TsOptionalType(value) => TsType::TsOptionalType(get_view_for_ts_optional_type(value, bump)),
7866    swc_ast::TsType::TsRestType(value) => TsType::TsRestType(get_view_for_ts_rest_type(value, bump)),
7867    swc_ast::TsType::TsUnionOrIntersectionType(value) => TsType::TsUnionOrIntersectionType(get_view_for_ts_union_or_intersection_type(value, bump)),
7868    swc_ast::TsType::TsConditionalType(value) => TsType::TsConditionalType(get_view_for_ts_conditional_type(value, bump)),
7869    swc_ast::TsType::TsInferType(value) => TsType::TsInferType(get_view_for_ts_infer_type(value, bump)),
7870    swc_ast::TsType::TsParenthesizedType(value) => TsType::TsParenthesizedType(get_view_for_ts_parenthesized_type(value, bump)),
7871    swc_ast::TsType::TsTypeOperator(value) => TsType::TsTypeOperator(get_view_for_ts_type_operator(value, bump)),
7872    swc_ast::TsType::TsIndexedAccessType(value) => TsType::TsIndexedAccessType(get_view_for_ts_indexed_access_type(value, bump)),
7873    swc_ast::TsType::TsMappedType(value) => TsType::TsMappedType(get_view_for_ts_mapped_type(value, bump)),
7874    swc_ast::TsType::TsLitType(value) => TsType::TsLitType(get_view_for_ts_lit_type(value, bump)),
7875    swc_ast::TsType::TsTypePredicate(value) => TsType::TsTypePredicate(get_view_for_ts_type_predicate(value, bump)),
7876    swc_ast::TsType::TsImportType(value) => TsType::TsImportType(get_view_for_ts_import_type(value, bump)),
7877  }
7878}
7879
7880fn set_parent_for_ts_type<'a>(node: &TsType<'a>, parent: Node<'a>) {
7881  match node {
7882    TsType::TsKeywordType(value) => set_parent_for_ts_keyword_type(value, parent),
7883    TsType::TsThisType(value) => set_parent_for_ts_this_type(value, parent),
7884    TsType::TsFnOrConstructorType(value) => set_parent_for_ts_fn_or_constructor_type(value, parent),
7885    TsType::TsTypeRef(value) => set_parent_for_ts_type_ref(value, parent),
7886    TsType::TsTypeQuery(value) => set_parent_for_ts_type_query(value, parent),
7887    TsType::TsTypeLit(value) => set_parent_for_ts_type_lit(value, parent),
7888    TsType::TsArrayType(value) => set_parent_for_ts_array_type(value, parent),
7889    TsType::TsTupleType(value) => set_parent_for_ts_tuple_type(value, parent),
7890    TsType::TsOptionalType(value) => set_parent_for_ts_optional_type(value, parent),
7891    TsType::TsRestType(value) => set_parent_for_ts_rest_type(value, parent),
7892    TsType::TsUnionOrIntersectionType(value) => set_parent_for_ts_union_or_intersection_type(value, parent),
7893    TsType::TsConditionalType(value) => set_parent_for_ts_conditional_type(value, parent),
7894    TsType::TsInferType(value) => set_parent_for_ts_infer_type(value, parent),
7895    TsType::TsParenthesizedType(value) => set_parent_for_ts_parenthesized_type(value, parent),
7896    TsType::TsTypeOperator(value) => set_parent_for_ts_type_operator(value, parent),
7897    TsType::TsIndexedAccessType(value) => set_parent_for_ts_indexed_access_type(value, parent),
7898    TsType::TsMappedType(value) => set_parent_for_ts_mapped_type(value, parent),
7899    TsType::TsLitType(value) => set_parent_for_ts_lit_type(value, parent),
7900    TsType::TsTypePredicate(value) => set_parent_for_ts_type_predicate(value, parent),
7901    TsType::TsImportType(value) => set_parent_for_ts_import_type(value, parent),
7902  }
7903}
7904
7905#[derive(Copy, Clone)]
7906pub enum TsTypeElement<'a> {
7907  TsCallSignatureDecl(&'a TsCallSignatureDecl<'a>),
7908  TsConstructSignatureDecl(&'a TsConstructSignatureDecl<'a>),
7909  TsPropertySignature(&'a TsPropertySignature<'a>),
7910  TsGetterSignature(&'a TsGetterSignature<'a>),
7911  TsSetterSignature(&'a TsSetterSignature<'a>),
7912  TsMethodSignature(&'a TsMethodSignature<'a>),
7913  TsIndexSignature(&'a TsIndexSignature<'a>),
7914}
7915
7916impl<'a> TsTypeElement<'a> {
7917  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7918    T::to(&self.into())
7919  }
7920
7921  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7922    let node: Node<'a> = self.into();
7923    if let Some(result) = T::to(&node) {
7924      result
7925    } else {
7926      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7927    }
7928  }
7929
7930  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7931    self.kind() == T::kind()
7932  }
7933  pub fn parent(&self) -> Node<'a> {
7934    NodeTrait::parent(self).unwrap()
7935  }
7936}
7937
7938impl<'a> SourceRanged for TsTypeElement<'a> {
7939  fn start(&self) -> SourcePos {
7940    match self {
7941      TsTypeElement::TsCallSignatureDecl(node) => node.start(),
7942      TsTypeElement::TsConstructSignatureDecl(node) => node.start(),
7943      TsTypeElement::TsPropertySignature(node) => node.start(),
7944      TsTypeElement::TsGetterSignature(node) => node.start(),
7945      TsTypeElement::TsSetterSignature(node) => node.start(),
7946      TsTypeElement::TsMethodSignature(node) => node.start(),
7947      TsTypeElement::TsIndexSignature(node) => node.start(),
7948    }
7949  }
7950  fn end(&self) -> SourcePos {
7951    match self {
7952      TsTypeElement::TsCallSignatureDecl(node) => node.end(),
7953      TsTypeElement::TsConstructSignatureDecl(node) => node.end(),
7954      TsTypeElement::TsPropertySignature(node) => node.end(),
7955      TsTypeElement::TsGetterSignature(node) => node.end(),
7956      TsTypeElement::TsSetterSignature(node) => node.end(),
7957      TsTypeElement::TsMethodSignature(node) => node.end(),
7958      TsTypeElement::TsIndexSignature(node) => node.end(),
7959    }
7960  }
7961}
7962
7963impl<'a> NodeTrait<'a> for TsTypeElement<'a> {
7964  fn parent(&self) -> Option<Node<'a>> {
7965    match self {
7966      TsTypeElement::TsCallSignatureDecl(node) => NodeTrait::parent(*node),
7967      TsTypeElement::TsConstructSignatureDecl(node) => NodeTrait::parent(*node),
7968      TsTypeElement::TsPropertySignature(node) => NodeTrait::parent(*node),
7969      TsTypeElement::TsGetterSignature(node) => NodeTrait::parent(*node),
7970      TsTypeElement::TsSetterSignature(node) => NodeTrait::parent(*node),
7971      TsTypeElement::TsMethodSignature(node) => NodeTrait::parent(*node),
7972      TsTypeElement::TsIndexSignature(node) => NodeTrait::parent(*node),
7973    }
7974  }
7975
7976  fn children(&self) -> Vec<Node<'a>> {
7977    match self {
7978      TsTypeElement::TsCallSignatureDecl(node) => node.children(),
7979      TsTypeElement::TsConstructSignatureDecl(node) => node.children(),
7980      TsTypeElement::TsPropertySignature(node) => node.children(),
7981      TsTypeElement::TsGetterSignature(node) => node.children(),
7982      TsTypeElement::TsSetterSignature(node) => node.children(),
7983      TsTypeElement::TsMethodSignature(node) => node.children(),
7984      TsTypeElement::TsIndexSignature(node) => node.children(),
7985    }
7986  }
7987
7988  fn as_node(&self) -> Node<'a> {
7989    match self {
7990      TsTypeElement::TsCallSignatureDecl(node) => node.as_node(),
7991      TsTypeElement::TsConstructSignatureDecl(node) => node.as_node(),
7992      TsTypeElement::TsPropertySignature(node) => node.as_node(),
7993      TsTypeElement::TsGetterSignature(node) => node.as_node(),
7994      TsTypeElement::TsSetterSignature(node) => node.as_node(),
7995      TsTypeElement::TsMethodSignature(node) => node.as_node(),
7996      TsTypeElement::TsIndexSignature(node) => node.as_node(),
7997    }
7998  }
7999
8000  fn kind(&self) -> NodeKind {
8001    match self {
8002      TsTypeElement::TsCallSignatureDecl(_) => NodeKind::TsCallSignatureDecl,
8003      TsTypeElement::TsConstructSignatureDecl(_) => NodeKind::TsConstructSignatureDecl,
8004      TsTypeElement::TsPropertySignature(_) => NodeKind::TsPropertySignature,
8005      TsTypeElement::TsGetterSignature(_) => NodeKind::TsGetterSignature,
8006      TsTypeElement::TsSetterSignature(_) => NodeKind::TsSetterSignature,
8007      TsTypeElement::TsMethodSignature(_) => NodeKind::TsMethodSignature,
8008      TsTypeElement::TsIndexSignature(_) => NodeKind::TsIndexSignature,
8009    }
8010  }
8011}
8012
8013impl<'a> From<&TsTypeElement<'a>> for Node<'a> {
8014  fn from(node: &TsTypeElement<'a>) -> Node<'a> {
8015    match node {
8016      TsTypeElement::TsCallSignatureDecl(node) => (*node).into(),
8017      TsTypeElement::TsConstructSignatureDecl(node) => (*node).into(),
8018      TsTypeElement::TsPropertySignature(node) => (*node).into(),
8019      TsTypeElement::TsGetterSignature(node) => (*node).into(),
8020      TsTypeElement::TsSetterSignature(node) => (*node).into(),
8021      TsTypeElement::TsMethodSignature(node) => (*node).into(),
8022      TsTypeElement::TsIndexSignature(node) => (*node).into(),
8023    }
8024  }
8025}
8026
8027impl<'a> From<TsTypeElement<'a>> for Node<'a> {
8028  fn from(node: TsTypeElement<'a>) -> Node<'a> {
8029    match node {
8030      TsTypeElement::TsCallSignatureDecl(node) => node.into(),
8031      TsTypeElement::TsConstructSignatureDecl(node) => node.into(),
8032      TsTypeElement::TsPropertySignature(node) => node.into(),
8033      TsTypeElement::TsGetterSignature(node) => node.into(),
8034      TsTypeElement::TsSetterSignature(node) => node.into(),
8035      TsTypeElement::TsMethodSignature(node) => node.into(),
8036      TsTypeElement::TsIndexSignature(node) => node.into(),
8037    }
8038  }
8039}
8040
8041fn get_view_for_ts_type_element<'a>(inner: &'a swc_ast::TsTypeElement, bump: &'a Bump) -> TsTypeElement<'a> {
8042  match inner {
8043    swc_ast::TsTypeElement::TsCallSignatureDecl(value) => TsTypeElement::TsCallSignatureDecl(get_view_for_ts_call_signature_decl(value, bump)),
8044    swc_ast::TsTypeElement::TsConstructSignatureDecl(value) => TsTypeElement::TsConstructSignatureDecl(get_view_for_ts_construct_signature_decl(value, bump)),
8045    swc_ast::TsTypeElement::TsPropertySignature(value) => TsTypeElement::TsPropertySignature(get_view_for_ts_property_signature(value, bump)),
8046    swc_ast::TsTypeElement::TsGetterSignature(value) => TsTypeElement::TsGetterSignature(get_view_for_ts_getter_signature(value, bump)),
8047    swc_ast::TsTypeElement::TsSetterSignature(value) => TsTypeElement::TsSetterSignature(get_view_for_ts_setter_signature(value, bump)),
8048    swc_ast::TsTypeElement::TsMethodSignature(value) => TsTypeElement::TsMethodSignature(get_view_for_ts_method_signature(value, bump)),
8049    swc_ast::TsTypeElement::TsIndexSignature(value) => TsTypeElement::TsIndexSignature(get_view_for_ts_index_signature(value, bump)),
8050  }
8051}
8052
8053fn set_parent_for_ts_type_element<'a>(node: &TsTypeElement<'a>, parent: Node<'a>) {
8054  match node {
8055    TsTypeElement::TsCallSignatureDecl(value) => set_parent_for_ts_call_signature_decl(value, parent),
8056    TsTypeElement::TsConstructSignatureDecl(value) => set_parent_for_ts_construct_signature_decl(value, parent),
8057    TsTypeElement::TsPropertySignature(value) => set_parent_for_ts_property_signature(value, parent),
8058    TsTypeElement::TsGetterSignature(value) => set_parent_for_ts_getter_signature(value, parent),
8059    TsTypeElement::TsSetterSignature(value) => set_parent_for_ts_setter_signature(value, parent),
8060    TsTypeElement::TsMethodSignature(value) => set_parent_for_ts_method_signature(value, parent),
8061    TsTypeElement::TsIndexSignature(value) => set_parent_for_ts_index_signature(value, parent),
8062  }
8063}
8064
8065#[derive(Copy, Clone)]
8066pub enum TsTypeQueryExpr<'a> {
8067  TsEntityName(TsEntityName<'a>),
8068  Import(&'a TsImportType<'a>),
8069}
8070
8071impl<'a> TsTypeQueryExpr<'a> {
8072  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
8073    T::to(&self.into())
8074  }
8075
8076  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
8077    let node: Node<'a> = self.into();
8078    if let Some(result) = T::to(&node) {
8079      result
8080    } else {
8081      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
8082    }
8083  }
8084
8085  pub fn is<T: CastableNode<'a>>(&self) -> bool {
8086    self.kind() == T::kind()
8087  }
8088}
8089
8090impl<'a> SourceRanged for TsTypeQueryExpr<'a> {
8091  fn start(&self) -> SourcePos {
8092    match self {
8093      TsTypeQueryExpr::TsEntityName(node) => node.start(),
8094      TsTypeQueryExpr::Import(node) => node.start(),
8095    }
8096  }
8097  fn end(&self) -> SourcePos {
8098    match self {
8099      TsTypeQueryExpr::TsEntityName(node) => node.end(),
8100      TsTypeQueryExpr::Import(node) => node.end(),
8101    }
8102  }
8103}
8104
8105impl<'a> NodeTrait<'a> for TsTypeQueryExpr<'a> {
8106  fn parent(&self) -> Option<Node<'a>> {
8107    match self {
8108      TsTypeQueryExpr::TsEntityName(node) => NodeTrait::parent(node),
8109      TsTypeQueryExpr::Import(node) => NodeTrait::parent(*node),
8110    }
8111  }
8112
8113  fn children(&self) -> Vec<Node<'a>> {
8114    match self {
8115      TsTypeQueryExpr::TsEntityName(node) => node.children(),
8116      TsTypeQueryExpr::Import(node) => node.children(),
8117    }
8118  }
8119
8120  fn as_node(&self) -> Node<'a> {
8121    match self {
8122      TsTypeQueryExpr::TsEntityName(node) => node.as_node(),
8123      TsTypeQueryExpr::Import(node) => node.as_node(),
8124    }
8125  }
8126
8127  fn kind(&self) -> NodeKind {
8128    match self {
8129      TsTypeQueryExpr::TsEntityName(node) => node.kind(),
8130      TsTypeQueryExpr::Import(_) => NodeKind::TsImportType,
8131    }
8132  }
8133}
8134
8135impl<'a> From<&TsTypeQueryExpr<'a>> for Node<'a> {
8136  fn from(node: &TsTypeQueryExpr<'a>) -> Node<'a> {
8137    match node {
8138      TsTypeQueryExpr::TsEntityName(node) => node.into(),
8139      TsTypeQueryExpr::Import(node) => (*node).into(),
8140    }
8141  }
8142}
8143
8144impl<'a> From<TsTypeQueryExpr<'a>> for Node<'a> {
8145  fn from(node: TsTypeQueryExpr<'a>) -> Node<'a> {
8146    match node {
8147      TsTypeQueryExpr::TsEntityName(node) => node.into(),
8148      TsTypeQueryExpr::Import(node) => node.into(),
8149    }
8150  }
8151}
8152
8153fn get_view_for_ts_type_query_expr<'a>(inner: &'a swc_ast::TsTypeQueryExpr, bump: &'a Bump) -> TsTypeQueryExpr<'a> {
8154  match inner {
8155    swc_ast::TsTypeQueryExpr::TsEntityName(value) => TsTypeQueryExpr::TsEntityName(get_view_for_ts_entity_name(value, bump)),
8156    swc_ast::TsTypeQueryExpr::Import(value) => TsTypeQueryExpr::Import(get_view_for_ts_import_type(value, bump)),
8157  }
8158}
8159
8160fn set_parent_for_ts_type_query_expr<'a>(node: &TsTypeQueryExpr<'a>, parent: Node<'a>) {
8161  match node {
8162    TsTypeQueryExpr::TsEntityName(value) => set_parent_for_ts_entity_name(value, parent),
8163    TsTypeQueryExpr::Import(value) => set_parent_for_ts_import_type(value, parent),
8164  }
8165}
8166
8167#[derive(Copy, Clone)]
8168pub enum TsUnionOrIntersectionType<'a> {
8169  TsUnionType(&'a TsUnionType<'a>),
8170  TsIntersectionType(&'a TsIntersectionType<'a>),
8171}
8172
8173impl<'a> TsUnionOrIntersectionType<'a> {
8174  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
8175    T::to(&self.into())
8176  }
8177
8178  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
8179    let node: Node<'a> = self.into();
8180    if let Some(result) = T::to(&node) {
8181      result
8182    } else {
8183      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
8184    }
8185  }
8186
8187  pub fn is<T: CastableNode<'a>>(&self) -> bool {
8188    self.kind() == T::kind()
8189  }
8190  pub fn parent(&self) -> Node<'a> {
8191    NodeTrait::parent(self).unwrap()
8192  }
8193}
8194
8195impl<'a> SourceRanged for TsUnionOrIntersectionType<'a> {
8196  fn start(&self) -> SourcePos {
8197    match self {
8198      TsUnionOrIntersectionType::TsUnionType(node) => node.start(),
8199      TsUnionOrIntersectionType::TsIntersectionType(node) => node.start(),
8200    }
8201  }
8202  fn end(&self) -> SourcePos {
8203    match self {
8204      TsUnionOrIntersectionType::TsUnionType(node) => node.end(),
8205      TsUnionOrIntersectionType::TsIntersectionType(node) => node.end(),
8206    }
8207  }
8208}
8209
8210impl<'a> NodeTrait<'a> for TsUnionOrIntersectionType<'a> {
8211  fn parent(&self) -> Option<Node<'a>> {
8212    match self {
8213      TsUnionOrIntersectionType::TsUnionType(node) => NodeTrait::parent(*node),
8214      TsUnionOrIntersectionType::TsIntersectionType(node) => NodeTrait::parent(*node),
8215    }
8216  }
8217
8218  fn children(&self) -> Vec<Node<'a>> {
8219    match self {
8220      TsUnionOrIntersectionType::TsUnionType(node) => node.children(),
8221      TsUnionOrIntersectionType::TsIntersectionType(node) => node.children(),
8222    }
8223  }
8224
8225  fn as_node(&self) -> Node<'a> {
8226    match self {
8227      TsUnionOrIntersectionType::TsUnionType(node) => node.as_node(),
8228      TsUnionOrIntersectionType::TsIntersectionType(node) => node.as_node(),
8229    }
8230  }
8231
8232  fn kind(&self) -> NodeKind {
8233    match self {
8234      TsUnionOrIntersectionType::TsUnionType(_) => NodeKind::TsUnionType,
8235      TsUnionOrIntersectionType::TsIntersectionType(_) => NodeKind::TsIntersectionType,
8236    }
8237  }
8238}
8239
8240impl<'a> From<&TsUnionOrIntersectionType<'a>> for Node<'a> {
8241  fn from(node: &TsUnionOrIntersectionType<'a>) -> Node<'a> {
8242    match node {
8243      TsUnionOrIntersectionType::TsUnionType(node) => (*node).into(),
8244      TsUnionOrIntersectionType::TsIntersectionType(node) => (*node).into(),
8245    }
8246  }
8247}
8248
8249impl<'a> From<TsUnionOrIntersectionType<'a>> for Node<'a> {
8250  fn from(node: TsUnionOrIntersectionType<'a>) -> Node<'a> {
8251    match node {
8252      TsUnionOrIntersectionType::TsUnionType(node) => node.into(),
8253      TsUnionOrIntersectionType::TsIntersectionType(node) => node.into(),
8254    }
8255  }
8256}
8257
8258fn get_view_for_ts_union_or_intersection_type<'a>(inner: &'a swc_ast::TsUnionOrIntersectionType, bump: &'a Bump) -> TsUnionOrIntersectionType<'a> {
8259  match inner {
8260    swc_ast::TsUnionOrIntersectionType::TsUnionType(value) => TsUnionOrIntersectionType::TsUnionType(get_view_for_ts_union_type(value, bump)),
8261    swc_ast::TsUnionOrIntersectionType::TsIntersectionType(value) => TsUnionOrIntersectionType::TsIntersectionType(get_view_for_ts_intersection_type(value, bump)),
8262  }
8263}
8264
8265fn set_parent_for_ts_union_or_intersection_type<'a>(node: &TsUnionOrIntersectionType<'a>, parent: Node<'a>) {
8266  match node {
8267    TsUnionOrIntersectionType::TsUnionType(value) => set_parent_for_ts_union_type(value, parent),
8268    TsUnionOrIntersectionType::TsIntersectionType(value) => set_parent_for_ts_intersection_type(value, parent),
8269  }
8270}
8271
8272#[derive(Copy, Clone)]
8273pub enum VarDeclOrExpr<'a> {
8274  VarDecl(&'a VarDecl<'a>),
8275  Expr(Expr<'a>),
8276}
8277
8278impl<'a> VarDeclOrExpr<'a> {
8279  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
8280    T::to(&self.into())
8281  }
8282
8283  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
8284    let node: Node<'a> = self.into();
8285    if let Some(result) = T::to(&node) {
8286      result
8287    } else {
8288      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
8289    }
8290  }
8291
8292  pub fn is<T: CastableNode<'a>>(&self) -> bool {
8293    self.kind() == T::kind()
8294  }
8295}
8296
8297impl<'a> SourceRanged for VarDeclOrExpr<'a> {
8298  fn start(&self) -> SourcePos {
8299    match self {
8300      VarDeclOrExpr::VarDecl(node) => node.start(),
8301      VarDeclOrExpr::Expr(node) => node.start(),
8302    }
8303  }
8304  fn end(&self) -> SourcePos {
8305    match self {
8306      VarDeclOrExpr::VarDecl(node) => node.end(),
8307      VarDeclOrExpr::Expr(node) => node.end(),
8308    }
8309  }
8310}
8311
8312impl<'a> NodeTrait<'a> for VarDeclOrExpr<'a> {
8313  fn parent(&self) -> Option<Node<'a>> {
8314    match self {
8315      VarDeclOrExpr::VarDecl(node) => NodeTrait::parent(*node),
8316      VarDeclOrExpr::Expr(node) => NodeTrait::parent(node),
8317    }
8318  }
8319
8320  fn children(&self) -> Vec<Node<'a>> {
8321    match self {
8322      VarDeclOrExpr::VarDecl(node) => node.children(),
8323      VarDeclOrExpr::Expr(node) => node.children(),
8324    }
8325  }
8326
8327  fn as_node(&self) -> Node<'a> {
8328    match self {
8329      VarDeclOrExpr::VarDecl(node) => node.as_node(),
8330      VarDeclOrExpr::Expr(node) => node.as_node(),
8331    }
8332  }
8333
8334  fn kind(&self) -> NodeKind {
8335    match self {
8336      VarDeclOrExpr::VarDecl(_) => NodeKind::VarDecl,
8337      VarDeclOrExpr::Expr(node) => node.kind(),
8338    }
8339  }
8340}
8341
8342impl<'a> From<&VarDeclOrExpr<'a>> for Node<'a> {
8343  fn from(node: &VarDeclOrExpr<'a>) -> Node<'a> {
8344    match node {
8345      VarDeclOrExpr::VarDecl(node) => (*node).into(),
8346      VarDeclOrExpr::Expr(node) => node.into(),
8347    }
8348  }
8349}
8350
8351impl<'a> From<VarDeclOrExpr<'a>> for Node<'a> {
8352  fn from(node: VarDeclOrExpr<'a>) -> Node<'a> {
8353    match node {
8354      VarDeclOrExpr::VarDecl(node) => node.into(),
8355      VarDeclOrExpr::Expr(node) => node.into(),
8356    }
8357  }
8358}
8359
8360fn get_view_for_var_decl_or_expr<'a>(inner: &'a swc_ast::VarDeclOrExpr, bump: &'a Bump) -> VarDeclOrExpr<'a> {
8361  match inner {
8362    swc_ast::VarDeclOrExpr::VarDecl(value) => VarDeclOrExpr::VarDecl(get_view_for_var_decl(value, bump)),
8363    swc_ast::VarDeclOrExpr::Expr(value) => VarDeclOrExpr::Expr(get_view_for_expr(value, bump)),
8364  }
8365}
8366
8367fn set_parent_for_var_decl_or_expr<'a>(node: &VarDeclOrExpr<'a>, parent: Node<'a>) {
8368  match node {
8369    VarDeclOrExpr::VarDecl(value) => set_parent_for_var_decl(value, parent),
8370    VarDeclOrExpr::Expr(value) => set_parent_for_expr(value, parent),
8371  }
8372}
8373
8374/// Array literal.
8375#[derive(Clone)]
8376pub struct ArrayLit<'a> {
8377  parent: ParentOnceCell<Node<'a>>,
8378  pub inner: &'a swc_ast::ArrayLit,
8379  pub elems: &'a [Option<&'a ExprOrSpread<'a>>],
8380}
8381
8382impl<'a> ArrayLit<'a> {
8383  pub fn parent(&self) -> Node<'a> {
8384    self.parent.get().unwrap()
8385  }
8386}
8387
8388impl<'a> SourceRanged for ArrayLit<'a> {
8389  fn start(&self) -> SourcePos {
8390    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8391  }
8392  fn end(&self) -> SourcePos {
8393    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8394  }
8395}
8396
8397impl<'a> From<&ArrayLit<'a>> for Node<'a> {
8398  fn from(node: &ArrayLit<'a>) -> Node<'a> {
8399    let node = unsafe { mem::transmute::<&ArrayLit<'a>, &'a ArrayLit<'a>>(node) };
8400    Node::ArrayLit(node)
8401  }
8402}
8403
8404impl<'a> NodeTrait<'a> for ArrayLit<'a> {
8405  fn parent(&self) -> Option<Node<'a>> {
8406    Some(self.parent.get().unwrap().clone())
8407  }
8408
8409  fn children(&self) -> Vec<Node<'a>> {
8410    let mut children = Vec::with_capacity(self.elems.len());
8411    for child in self.elems.iter() {
8412      if let Some(child) = child {
8413        children.push((*child).into());
8414      }
8415    }
8416    children
8417  }
8418
8419  fn as_node(&self) -> Node<'a> {
8420    self.into()
8421  }
8422
8423  fn kind(&self) -> NodeKind {
8424    NodeKind::ArrayLit
8425  }
8426}
8427
8428impl<'a> CastableNode<'a> for ArrayLit<'a> {
8429  fn to(node: &Node<'a>) -> Option<&'a Self> {
8430    if let Node::ArrayLit(node) = node {
8431      Some(node)
8432    } else {
8433      None
8434    }
8435  }
8436
8437  fn kind() -> NodeKind {
8438    NodeKind::ArrayLit
8439  }
8440}
8441
8442fn get_view_for_array_lit<'a>(inner: &'a swc_ast::ArrayLit, bump: &'a Bump) -> &'a ArrayLit<'a> {
8443  let node = bump.alloc(ArrayLit {
8444    inner,
8445    parent: Default::default(),
8446    elems: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.elems.len(), bump);vec.extend(inner.elems.iter().map(|value| match value {
8447      Some(value) => Some(get_view_for_expr_or_spread(value, bump)),
8448      None => None,
8449    })); vec }),
8450  });
8451  let parent: Node<'a> = (&*node).into();
8452  for value in node.elems.iter() {
8453    if let Some(value) = value {
8454      set_parent_for_expr_or_spread(value, parent)
8455    }
8456  }
8457  node
8458}
8459
8460fn set_parent_for_array_lit<'a>(node: &ArrayLit<'a>, parent: Node<'a>) {
8461  node.parent.set(parent);
8462}
8463
8464#[derive(Clone)]
8465pub struct ArrayPat<'a> {
8466  parent: ParentOnceCell<Node<'a>>,
8467  pub inner: &'a swc_ast::ArrayPat,
8468  pub elems: &'a [Option<Pat<'a>>],
8469  pub type_ann: Option<&'a TsTypeAnn<'a>>,
8470}
8471
8472impl<'a> ArrayPat<'a> {
8473  pub fn parent(&self) -> Node<'a> {
8474    self.parent.get().unwrap()
8475  }
8476
8477  /// Only in an ambient context
8478  pub fn optional(&self) -> bool {
8479    self.inner.optional
8480  }
8481}
8482
8483impl<'a> SourceRanged for ArrayPat<'a> {
8484  fn start(&self) -> SourcePos {
8485    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8486  }
8487  fn end(&self) -> SourcePos {
8488    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8489  }
8490}
8491
8492impl<'a> From<&ArrayPat<'a>> for Node<'a> {
8493  fn from(node: &ArrayPat<'a>) -> Node<'a> {
8494    let node = unsafe { mem::transmute::<&ArrayPat<'a>, &'a ArrayPat<'a>>(node) };
8495    Node::ArrayPat(node)
8496  }
8497}
8498
8499impl<'a> NodeTrait<'a> for ArrayPat<'a> {
8500  fn parent(&self) -> Option<Node<'a>> {
8501    Some(self.parent.get().unwrap().clone())
8502  }
8503
8504  fn children(&self) -> Vec<Node<'a>> {
8505    let mut children = Vec::with_capacity(self.elems.len() + match &self.type_ann { Some(_value) => 1, None => 0, });
8506    for child in self.elems.iter() {
8507      if let Some(child) = child.as_ref() {
8508        children.push(child.into());
8509      }
8510    }
8511    if let Some(child) = self.type_ann {
8512      children.push(child.into());
8513    }
8514    children
8515  }
8516
8517  fn as_node(&self) -> Node<'a> {
8518    self.into()
8519  }
8520
8521  fn kind(&self) -> NodeKind {
8522    NodeKind::ArrayPat
8523  }
8524}
8525
8526impl<'a> CastableNode<'a> for ArrayPat<'a> {
8527  fn to(node: &Node<'a>) -> Option<&'a Self> {
8528    if let Node::ArrayPat(node) = node {
8529      Some(node)
8530    } else {
8531      None
8532    }
8533  }
8534
8535  fn kind() -> NodeKind {
8536    NodeKind::ArrayPat
8537  }
8538}
8539
8540fn get_view_for_array_pat<'a>(inner: &'a swc_ast::ArrayPat, bump: &'a Bump) -> &'a ArrayPat<'a> {
8541  let node = bump.alloc(ArrayPat {
8542    inner,
8543    parent: Default::default(),
8544    elems: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.elems.len(), bump);vec.extend(inner.elems.iter().map(|value| match value {
8545      Some(value) => Some(get_view_for_pat(value, bump)),
8546      None => None,
8547    })); vec }),
8548    type_ann: match &inner.type_ann {
8549      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
8550      None => None,
8551    },
8552  });
8553  let parent: Node<'a> = (&*node).into();
8554  for value in node.elems.iter() {
8555    if let Some(value) = value {
8556      set_parent_for_pat(value, parent)
8557    }
8558  }
8559  if let Some(value) = &node.type_ann {
8560    set_parent_for_ts_type_ann(value, parent)
8561  };
8562  node
8563}
8564
8565fn set_parent_for_array_pat<'a>(node: &ArrayPat<'a>, parent: Node<'a>) {
8566  node.parent.set(parent);
8567}
8568
8569#[derive(Clone)]
8570pub struct ArrowExpr<'a> {
8571  parent: ParentOnceCell<Node<'a>>,
8572  pub inner: &'a swc_ast::ArrowExpr,
8573  pub params: &'a [Pat<'a>],
8574  /// This is boxed to reduce the type size of [Expr].
8575  pub body: BlockStmtOrExpr<'a>,
8576  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
8577  pub return_type: Option<&'a TsTypeAnn<'a>>,
8578}
8579
8580impl<'a> ArrowExpr<'a> {
8581  pub fn parent(&self) -> Node<'a> {
8582    self.parent.get().unwrap()
8583  }
8584
8585  pub fn ctxt(&self) -> swc_common::SyntaxContext {
8586    self.inner.ctxt
8587  }
8588
8589  pub fn is_async(&self) -> bool {
8590    self.inner.is_async
8591  }
8592
8593  pub fn is_generator(&self) -> bool {
8594    self.inner.is_generator
8595  }
8596}
8597
8598impl<'a> SourceRanged for ArrowExpr<'a> {
8599  fn start(&self) -> SourcePos {
8600    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8601  }
8602  fn end(&self) -> SourcePos {
8603    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8604  }
8605}
8606
8607impl<'a> From<&ArrowExpr<'a>> for Node<'a> {
8608  fn from(node: &ArrowExpr<'a>) -> Node<'a> {
8609    let node = unsafe { mem::transmute::<&ArrowExpr<'a>, &'a ArrowExpr<'a>>(node) };
8610    Node::ArrowExpr(node)
8611  }
8612}
8613
8614impl<'a> NodeTrait<'a> for ArrowExpr<'a> {
8615  fn parent(&self) -> Option<Node<'a>> {
8616    Some(self.parent.get().unwrap().clone())
8617  }
8618
8619  fn children(&self) -> Vec<Node<'a>> {
8620    let mut children = Vec::with_capacity(1 + self.params.len() + match &self.type_params { Some(_value) => 1, None => 0, } + match &self.return_type { Some(_value) => 1, None => 0, });
8621    for child in self.params.iter() {
8622      children.push(child.into());
8623    }
8624    children.push((&self.body).into());
8625    if let Some(child) = self.type_params {
8626      children.push(child.into());
8627    }
8628    if let Some(child) = self.return_type {
8629      children.push(child.into());
8630    }
8631    children
8632  }
8633
8634  fn as_node(&self) -> Node<'a> {
8635    self.into()
8636  }
8637
8638  fn kind(&self) -> NodeKind {
8639    NodeKind::ArrowExpr
8640  }
8641}
8642
8643impl<'a> CastableNode<'a> for ArrowExpr<'a> {
8644  fn to(node: &Node<'a>) -> Option<&'a Self> {
8645    if let Node::ArrowExpr(node) = node {
8646      Some(node)
8647    } else {
8648      None
8649    }
8650  }
8651
8652  fn kind() -> NodeKind {
8653    NodeKind::ArrowExpr
8654  }
8655}
8656
8657fn get_view_for_arrow_expr<'a>(inner: &'a swc_ast::ArrowExpr, bump: &'a Bump) -> &'a ArrowExpr<'a> {
8658  let node = bump.alloc(ArrowExpr {
8659    inner,
8660    parent: Default::default(),
8661    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_pat(value, bump))); vec }),
8662    body: get_view_for_block_stmt_or_expr(&inner.body, bump),
8663    type_params: match &inner.type_params {
8664      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
8665      None => None,
8666    },
8667    return_type: match &inner.return_type {
8668      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
8669      None => None,
8670    },
8671  });
8672  let parent: Node<'a> = (&*node).into();
8673  for value in node.params.iter() {
8674    set_parent_for_pat(value, parent)
8675  }
8676  set_parent_for_block_stmt_or_expr(&node.body, parent);
8677  if let Some(value) = &node.type_params {
8678    set_parent_for_ts_type_param_decl(value, parent)
8679  };
8680  if let Some(value) = &node.return_type {
8681    set_parent_for_ts_type_ann(value, parent)
8682  };
8683  node
8684}
8685
8686fn set_parent_for_arrow_expr<'a>(node: &ArrowExpr<'a>, parent: Node<'a>) {
8687  node.parent.set(parent);
8688}
8689
8690#[derive(Clone)]
8691pub struct AssignExpr<'a> {
8692  parent: ParentOnceCell<Node<'a>>,
8693  pub inner: &'a swc_ast::AssignExpr,
8694  pub left: AssignTarget<'a>,
8695  pub right: Expr<'a>,
8696}
8697
8698impl<'a> AssignExpr<'a> {
8699  pub fn parent(&self) -> Node<'a> {
8700    self.parent.get().unwrap()
8701  }
8702
8703  pub fn op(&self) -> AssignOp {
8704    self.inner.op
8705  }
8706}
8707
8708impl<'a> SourceRanged for AssignExpr<'a> {
8709  fn start(&self) -> SourcePos {
8710    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8711  }
8712  fn end(&self) -> SourcePos {
8713    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8714  }
8715}
8716
8717impl<'a> From<&AssignExpr<'a>> for Node<'a> {
8718  fn from(node: &AssignExpr<'a>) -> Node<'a> {
8719    let node = unsafe { mem::transmute::<&AssignExpr<'a>, &'a AssignExpr<'a>>(node) };
8720    Node::AssignExpr(node)
8721  }
8722}
8723
8724impl<'a> NodeTrait<'a> for AssignExpr<'a> {
8725  fn parent(&self) -> Option<Node<'a>> {
8726    Some(self.parent.get().unwrap().clone())
8727  }
8728
8729  fn children(&self) -> Vec<Node<'a>> {
8730    let mut children = Vec::with_capacity(2);
8731    children.push((&self.left).into());
8732    children.push((&self.right).into());
8733    children
8734  }
8735
8736  fn as_node(&self) -> Node<'a> {
8737    self.into()
8738  }
8739
8740  fn kind(&self) -> NodeKind {
8741    NodeKind::AssignExpr
8742  }
8743}
8744
8745impl<'a> CastableNode<'a> for AssignExpr<'a> {
8746  fn to(node: &Node<'a>) -> Option<&'a Self> {
8747    if let Node::AssignExpr(node) = node {
8748      Some(node)
8749    } else {
8750      None
8751    }
8752  }
8753
8754  fn kind() -> NodeKind {
8755    NodeKind::AssignExpr
8756  }
8757}
8758
8759fn get_view_for_assign_expr<'a>(inner: &'a swc_ast::AssignExpr, bump: &'a Bump) -> &'a AssignExpr<'a> {
8760  let node = bump.alloc(AssignExpr {
8761    inner,
8762    parent: Default::default(),
8763    left: get_view_for_assign_target(&inner.left, bump),
8764    right: get_view_for_expr(&inner.right, bump),
8765  });
8766  let parent: Node<'a> = (&*node).into();
8767  set_parent_for_assign_target(&node.left, parent);
8768  set_parent_for_expr(&node.right, parent);
8769  node
8770}
8771
8772fn set_parent_for_assign_expr<'a>(node: &AssignExpr<'a>, parent: Node<'a>) {
8773  node.parent.set(parent);
8774}
8775
8776#[derive(Clone)]
8777pub struct AssignPat<'a> {
8778  parent: ParentOnceCell<Node<'a>>,
8779  pub inner: &'a swc_ast::AssignPat,
8780  pub left: Pat<'a>,
8781  pub right: Expr<'a>,
8782}
8783
8784impl<'a> AssignPat<'a> {
8785  pub fn parent(&self) -> Node<'a> {
8786    self.parent.get().unwrap()
8787  }
8788}
8789
8790impl<'a> SourceRanged for AssignPat<'a> {
8791  fn start(&self) -> SourcePos {
8792    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8793  }
8794  fn end(&self) -> SourcePos {
8795    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8796  }
8797}
8798
8799impl<'a> From<&AssignPat<'a>> for Node<'a> {
8800  fn from(node: &AssignPat<'a>) -> Node<'a> {
8801    let node = unsafe { mem::transmute::<&AssignPat<'a>, &'a AssignPat<'a>>(node) };
8802    Node::AssignPat(node)
8803  }
8804}
8805
8806impl<'a> NodeTrait<'a> for AssignPat<'a> {
8807  fn parent(&self) -> Option<Node<'a>> {
8808    Some(self.parent.get().unwrap().clone())
8809  }
8810
8811  fn children(&self) -> Vec<Node<'a>> {
8812    let mut children = Vec::with_capacity(2);
8813    children.push((&self.left).into());
8814    children.push((&self.right).into());
8815    children
8816  }
8817
8818  fn as_node(&self) -> Node<'a> {
8819    self.into()
8820  }
8821
8822  fn kind(&self) -> NodeKind {
8823    NodeKind::AssignPat
8824  }
8825}
8826
8827impl<'a> CastableNode<'a> for AssignPat<'a> {
8828  fn to(node: &Node<'a>) -> Option<&'a Self> {
8829    if let Node::AssignPat(node) = node {
8830      Some(node)
8831    } else {
8832      None
8833    }
8834  }
8835
8836  fn kind() -> NodeKind {
8837    NodeKind::AssignPat
8838  }
8839}
8840
8841fn get_view_for_assign_pat<'a>(inner: &'a swc_ast::AssignPat, bump: &'a Bump) -> &'a AssignPat<'a> {
8842  let node = bump.alloc(AssignPat {
8843    inner,
8844    parent: Default::default(),
8845    left: get_view_for_pat(&inner.left, bump),
8846    right: get_view_for_expr(&inner.right, bump),
8847  });
8848  let parent: Node<'a> = (&*node).into();
8849  set_parent_for_pat(&node.left, parent);
8850  set_parent_for_expr(&node.right, parent);
8851  node
8852}
8853
8854fn set_parent_for_assign_pat<'a>(node: &AssignPat<'a>, parent: Node<'a>) {
8855  node.parent.set(parent);
8856}
8857
8858/// `{key}` or `{key = value}`
8859#[derive(Clone)]
8860pub struct AssignPatProp<'a> {
8861  parent: ParentOnceCell<&'a ObjectPat<'a>>,
8862  pub inner: &'a swc_ast::AssignPatProp,
8863  /// Note: This type is to help implementing visitor and the field `type_ann`
8864  /// is always [None].
8865  pub key: &'a BindingIdent<'a>,
8866  pub value: Option<Expr<'a>>,
8867}
8868
8869impl<'a> AssignPatProp<'a> {
8870  pub fn parent(&self) -> &'a ObjectPat<'a> {
8871    self.parent.get().unwrap()
8872  }
8873}
8874
8875impl<'a> SourceRanged for AssignPatProp<'a> {
8876  fn start(&self) -> SourcePos {
8877    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8878  }
8879  fn end(&self) -> SourcePos {
8880    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8881  }
8882}
8883
8884impl<'a> From<&AssignPatProp<'a>> for Node<'a> {
8885  fn from(node: &AssignPatProp<'a>) -> Node<'a> {
8886    let node = unsafe { mem::transmute::<&AssignPatProp<'a>, &'a AssignPatProp<'a>>(node) };
8887    Node::AssignPatProp(node)
8888  }
8889}
8890
8891impl<'a> NodeTrait<'a> for AssignPatProp<'a> {
8892  fn parent(&self) -> Option<Node<'a>> {
8893    Some(self.parent.get().unwrap().into())
8894  }
8895
8896  fn children(&self) -> Vec<Node<'a>> {
8897    let mut children = Vec::with_capacity(1 + match &self.value { Some(_value) => 1, None => 0, });
8898    children.push(self.key.into());
8899    if let Some(child) = self.value.as_ref() {
8900      children.push(child.into());
8901    }
8902    children
8903  }
8904
8905  fn as_node(&self) -> Node<'a> {
8906    self.into()
8907  }
8908
8909  fn kind(&self) -> NodeKind {
8910    NodeKind::AssignPatProp
8911  }
8912}
8913
8914impl<'a> CastableNode<'a> for AssignPatProp<'a> {
8915  fn to(node: &Node<'a>) -> Option<&'a Self> {
8916    if let Node::AssignPatProp(node) = node {
8917      Some(node)
8918    } else {
8919      None
8920    }
8921  }
8922
8923  fn kind() -> NodeKind {
8924    NodeKind::AssignPatProp
8925  }
8926}
8927
8928fn get_view_for_assign_pat_prop<'a>(inner: &'a swc_ast::AssignPatProp, bump: &'a Bump) -> &'a AssignPatProp<'a> {
8929  let node = bump.alloc(AssignPatProp {
8930    inner,
8931    parent: Default::default(),
8932    key: get_view_for_binding_ident(&inner.key, bump),
8933    value: match &inner.value {
8934      Some(value) => Some(get_view_for_expr(value, bump)),
8935      None => None,
8936    },
8937  });
8938  let parent: Node<'a> = (&*node).into();
8939  set_parent_for_binding_ident(&node.key, parent);
8940  if let Some(value) = &node.value {
8941    set_parent_for_expr(value, parent)
8942  };
8943  node
8944}
8945
8946fn set_parent_for_assign_pat_prop<'a>(node: &AssignPatProp<'a>, parent: Node<'a>) {
8947  node.parent.set(parent.expect::<ObjectPat>());
8948}
8949
8950#[derive(Clone)]
8951pub struct AssignProp<'a> {
8952  parent: ParentOnceCell<&'a ObjectLit<'a>>,
8953  pub inner: &'a swc_ast::AssignProp,
8954  pub key: &'a Ident<'a>,
8955  pub value: Expr<'a>,
8956}
8957
8958impl<'a> AssignProp<'a> {
8959  pub fn parent(&self) -> &'a ObjectLit<'a> {
8960    self.parent.get().unwrap()
8961  }
8962}
8963
8964impl<'a> SourceRanged for AssignProp<'a> {
8965  fn start(&self) -> SourcePos {
8966    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8967  }
8968  fn end(&self) -> SourcePos {
8969    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8970  }
8971}
8972
8973impl<'a> From<&AssignProp<'a>> for Node<'a> {
8974  fn from(node: &AssignProp<'a>) -> Node<'a> {
8975    let node = unsafe { mem::transmute::<&AssignProp<'a>, &'a AssignProp<'a>>(node) };
8976    Node::AssignProp(node)
8977  }
8978}
8979
8980impl<'a> NodeTrait<'a> for AssignProp<'a> {
8981  fn parent(&self) -> Option<Node<'a>> {
8982    Some(self.parent.get().unwrap().into())
8983  }
8984
8985  fn children(&self) -> Vec<Node<'a>> {
8986    let mut children = Vec::with_capacity(2);
8987    children.push(self.key.into());
8988    children.push((&self.value).into());
8989    children
8990  }
8991
8992  fn as_node(&self) -> Node<'a> {
8993    self.into()
8994  }
8995
8996  fn kind(&self) -> NodeKind {
8997    NodeKind::AssignProp
8998  }
8999}
9000
9001impl<'a> CastableNode<'a> for AssignProp<'a> {
9002  fn to(node: &Node<'a>) -> Option<&'a Self> {
9003    if let Node::AssignProp(node) = node {
9004      Some(node)
9005    } else {
9006      None
9007    }
9008  }
9009
9010  fn kind() -> NodeKind {
9011    NodeKind::AssignProp
9012  }
9013}
9014
9015fn get_view_for_assign_prop<'a>(inner: &'a swc_ast::AssignProp, bump: &'a Bump) -> &'a AssignProp<'a> {
9016  let node = bump.alloc(AssignProp {
9017    inner,
9018    parent: Default::default(),
9019    key: get_view_for_ident(&inner.key, bump),
9020    value: get_view_for_expr(&inner.value, bump),
9021  });
9022  let parent: Node<'a> = (&*node).into();
9023  set_parent_for_ident(&node.key, parent);
9024  set_parent_for_expr(&node.value, parent);
9025  node
9026}
9027
9028fn set_parent_for_assign_prop<'a>(node: &AssignProp<'a>, parent: Node<'a>) {
9029  node.parent.set(parent.expect::<ObjectLit>());
9030}
9031
9032#[derive(Clone)]
9033pub struct AutoAccessor<'a> {
9034  parent: ParentOnceCell<&'a Class<'a>>,
9035  pub inner: &'a swc_ast::AutoAccessor,
9036  pub key: Key<'a>,
9037  pub value: Option<Expr<'a>>,
9038  pub type_ann: Option<&'a TsTypeAnn<'a>>,
9039  pub decorators: &'a [&'a Decorator<'a>],
9040}
9041
9042impl<'a> AutoAccessor<'a> {
9043  pub fn parent(&self) -> &'a Class<'a> {
9044    self.parent.get().unwrap()
9045  }
9046
9047  pub fn is_static(&self) -> bool {
9048    self.inner.is_static
9049  }
9050
9051  /// Typescript extension.
9052  pub fn accessibility(&self) -> Option<Accessibility> {
9053    self.inner.accessibility
9054  }
9055
9056  pub fn is_abstract(&self) -> bool {
9057    self.inner.is_abstract
9058  }
9059
9060  pub fn is_override(&self) -> bool {
9061    self.inner.is_override
9062  }
9063
9064  pub fn definite(&self) -> bool {
9065    self.inner.definite
9066  }
9067}
9068
9069impl<'a> SourceRanged for AutoAccessor<'a> {
9070  fn start(&self) -> SourcePos {
9071    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9072  }
9073  fn end(&self) -> SourcePos {
9074    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9075  }
9076}
9077
9078impl<'a> From<&AutoAccessor<'a>> for Node<'a> {
9079  fn from(node: &AutoAccessor<'a>) -> Node<'a> {
9080    let node = unsafe { mem::transmute::<&AutoAccessor<'a>, &'a AutoAccessor<'a>>(node) };
9081    Node::AutoAccessor(node)
9082  }
9083}
9084
9085impl<'a> NodeTrait<'a> for AutoAccessor<'a> {
9086  fn parent(&self) -> Option<Node<'a>> {
9087    Some(self.parent.get().unwrap().into())
9088  }
9089
9090  fn children(&self) -> Vec<Node<'a>> {
9091    let mut children = Vec::with_capacity(1 + match &self.value { Some(_value) => 1, None => 0, } + match &self.type_ann { Some(_value) => 1, None => 0, } + self.decorators.len());
9092    children.push((&self.key).into());
9093    if let Some(child) = self.value.as_ref() {
9094      children.push(child.into());
9095    }
9096    if let Some(child) = self.type_ann {
9097      children.push(child.into());
9098    }
9099    for child in self.decorators.iter() {
9100      children.push((*child).into());
9101    }
9102    children
9103  }
9104
9105  fn as_node(&self) -> Node<'a> {
9106    self.into()
9107  }
9108
9109  fn kind(&self) -> NodeKind {
9110    NodeKind::AutoAccessor
9111  }
9112}
9113
9114impl<'a> CastableNode<'a> for AutoAccessor<'a> {
9115  fn to(node: &Node<'a>) -> Option<&'a Self> {
9116    if let Node::AutoAccessor(node) = node {
9117      Some(node)
9118    } else {
9119      None
9120    }
9121  }
9122
9123  fn kind() -> NodeKind {
9124    NodeKind::AutoAccessor
9125  }
9126}
9127
9128fn get_view_for_auto_accessor<'a>(inner: &'a swc_ast::AutoAccessor, bump: &'a Bump) -> &'a AutoAccessor<'a> {
9129  let node = bump.alloc(AutoAccessor {
9130    inner,
9131    parent: Default::default(),
9132    key: get_view_for_key(&inner.key, bump),
9133    value: match &inner.value {
9134      Some(value) => Some(get_view_for_expr(value, bump)),
9135      None => None,
9136    },
9137    type_ann: match &inner.type_ann {
9138      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
9139      None => None,
9140    },
9141    decorators: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.decorators.len(), bump);vec.extend(inner.decorators.iter().map(|value| get_view_for_decorator(value, bump))); vec }),
9142  });
9143  let parent: Node<'a> = (&*node).into();
9144  set_parent_for_key(&node.key, parent);
9145  if let Some(value) = &node.value {
9146    set_parent_for_expr(value, parent)
9147  };
9148  if let Some(value) = &node.type_ann {
9149    set_parent_for_ts_type_ann(value, parent)
9150  };
9151  for value in node.decorators.iter() {
9152    set_parent_for_decorator(value, parent)
9153  }
9154  node
9155}
9156
9157fn set_parent_for_auto_accessor<'a>(node: &AutoAccessor<'a>, parent: Node<'a>) {
9158  node.parent.set(parent.expect::<Class>());
9159}
9160
9161#[derive(Clone)]
9162pub struct AwaitExpr<'a> {
9163  parent: ParentOnceCell<Node<'a>>,
9164  pub inner: &'a swc_ast::AwaitExpr,
9165  pub arg: Expr<'a>,
9166}
9167
9168impl<'a> AwaitExpr<'a> {
9169  pub fn parent(&self) -> Node<'a> {
9170    self.parent.get().unwrap()
9171  }
9172}
9173
9174impl<'a> SourceRanged for AwaitExpr<'a> {
9175  fn start(&self) -> SourcePos {
9176    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9177  }
9178  fn end(&self) -> SourcePos {
9179    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9180  }
9181}
9182
9183impl<'a> From<&AwaitExpr<'a>> for Node<'a> {
9184  fn from(node: &AwaitExpr<'a>) -> Node<'a> {
9185    let node = unsafe { mem::transmute::<&AwaitExpr<'a>, &'a AwaitExpr<'a>>(node) };
9186    Node::AwaitExpr(node)
9187  }
9188}
9189
9190impl<'a> NodeTrait<'a> for AwaitExpr<'a> {
9191  fn parent(&self) -> Option<Node<'a>> {
9192    Some(self.parent.get().unwrap().clone())
9193  }
9194
9195  fn children(&self) -> Vec<Node<'a>> {
9196    let mut children = Vec::with_capacity(1);
9197    children.push((&self.arg).into());
9198    children
9199  }
9200
9201  fn as_node(&self) -> Node<'a> {
9202    self.into()
9203  }
9204
9205  fn kind(&self) -> NodeKind {
9206    NodeKind::AwaitExpr
9207  }
9208}
9209
9210impl<'a> CastableNode<'a> for AwaitExpr<'a> {
9211  fn to(node: &Node<'a>) -> Option<&'a Self> {
9212    if let Node::AwaitExpr(node) = node {
9213      Some(node)
9214    } else {
9215      None
9216    }
9217  }
9218
9219  fn kind() -> NodeKind {
9220    NodeKind::AwaitExpr
9221  }
9222}
9223
9224fn get_view_for_await_expr<'a>(inner: &'a swc_ast::AwaitExpr, bump: &'a Bump) -> &'a AwaitExpr<'a> {
9225  let node = bump.alloc(AwaitExpr {
9226    inner,
9227    parent: Default::default(),
9228    arg: get_view_for_expr(&inner.arg, bump),
9229  });
9230  let parent: Node<'a> = (&*node).into();
9231  set_parent_for_expr(&node.arg, parent);
9232  node
9233}
9234
9235fn set_parent_for_await_expr<'a>(node: &AwaitExpr<'a>, parent: Node<'a>) {
9236  node.parent.set(parent);
9237}
9238
9239#[derive(Clone)]
9240pub struct BigInt<'a> {
9241  parent: ParentOnceCell<Node<'a>>,
9242  pub inner: &'a swc_ast::BigInt,
9243}
9244
9245impl<'a> BigInt<'a> {
9246  pub fn parent(&self) -> Node<'a> {
9247    self.parent.get().unwrap()
9248  }
9249
9250  pub fn value(&self) -> &num_bigint::BigInt {
9251    &self.inner.value
9252  }
9253
9254  /// Use `None` value only for transformations to avoid recalculate
9255  /// characters in big integer
9256  pub fn raw(&self) -> &Option<swc_atoms::Atom> {
9257    &self.inner.raw
9258  }
9259}
9260
9261impl<'a> SourceRanged for BigInt<'a> {
9262  fn start(&self) -> SourcePos {
9263    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9264  }
9265  fn end(&self) -> SourcePos {
9266    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9267  }
9268}
9269
9270impl<'a> From<&BigInt<'a>> for Node<'a> {
9271  fn from(node: &BigInt<'a>) -> Node<'a> {
9272    let node = unsafe { mem::transmute::<&BigInt<'a>, &'a BigInt<'a>>(node) };
9273    Node::BigInt(node)
9274  }
9275}
9276
9277impl<'a> NodeTrait<'a> for BigInt<'a> {
9278  fn parent(&self) -> Option<Node<'a>> {
9279    Some(self.parent.get().unwrap().clone())
9280  }
9281
9282  fn children(&self) -> Vec<Node<'a>> {
9283    Vec::with_capacity(0)
9284  }
9285
9286  fn as_node(&self) -> Node<'a> {
9287    self.into()
9288  }
9289
9290  fn kind(&self) -> NodeKind {
9291    NodeKind::BigInt
9292  }
9293}
9294
9295impl<'a> CastableNode<'a> for BigInt<'a> {
9296  fn to(node: &Node<'a>) -> Option<&'a Self> {
9297    if let Node::BigInt(node) = node {
9298      Some(node)
9299    } else {
9300      None
9301    }
9302  }
9303
9304  fn kind() -> NodeKind {
9305    NodeKind::BigInt
9306  }
9307}
9308
9309fn get_view_for_big_int<'a>(inner: &'a swc_ast::BigInt, bump: &'a Bump) -> &'a BigInt<'a> {
9310  let node = bump.alloc(BigInt {
9311    inner,
9312    parent: Default::default(),
9313  });
9314  node
9315}
9316
9317fn set_parent_for_big_int<'a>(node: &BigInt<'a>, parent: Node<'a>) {
9318  node.parent.set(parent);
9319}
9320
9321#[derive(Clone)]
9322pub struct BinExpr<'a> {
9323  parent: ParentOnceCell<Node<'a>>,
9324  pub inner: &'a swc_ast::BinExpr,
9325  pub left: Expr<'a>,
9326  pub right: Expr<'a>,
9327}
9328
9329impl<'a> BinExpr<'a> {
9330  pub fn parent(&self) -> Node<'a> {
9331    self.parent.get().unwrap()
9332  }
9333
9334  pub fn op(&self) -> BinaryOp {
9335    self.inner.op
9336  }
9337}
9338
9339impl<'a> SourceRanged for BinExpr<'a> {
9340  fn start(&self) -> SourcePos {
9341    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9342  }
9343  fn end(&self) -> SourcePos {
9344    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9345  }
9346}
9347
9348impl<'a> From<&BinExpr<'a>> for Node<'a> {
9349  fn from(node: &BinExpr<'a>) -> Node<'a> {
9350    let node = unsafe { mem::transmute::<&BinExpr<'a>, &'a BinExpr<'a>>(node) };
9351    Node::BinExpr(node)
9352  }
9353}
9354
9355impl<'a> NodeTrait<'a> for BinExpr<'a> {
9356  fn parent(&self) -> Option<Node<'a>> {
9357    Some(self.parent.get().unwrap().clone())
9358  }
9359
9360  fn children(&self) -> Vec<Node<'a>> {
9361    let mut children = Vec::with_capacity(2);
9362    children.push((&self.left).into());
9363    children.push((&self.right).into());
9364    children
9365  }
9366
9367  fn as_node(&self) -> Node<'a> {
9368    self.into()
9369  }
9370
9371  fn kind(&self) -> NodeKind {
9372    NodeKind::BinExpr
9373  }
9374}
9375
9376impl<'a> CastableNode<'a> for BinExpr<'a> {
9377  fn to(node: &Node<'a>) -> Option<&'a Self> {
9378    if let Node::BinExpr(node) = node {
9379      Some(node)
9380    } else {
9381      None
9382    }
9383  }
9384
9385  fn kind() -> NodeKind {
9386    NodeKind::BinExpr
9387  }
9388}
9389
9390fn get_view_for_bin_expr<'a>(inner: &'a swc_ast::BinExpr, bump: &'a Bump) -> &'a BinExpr<'a> {
9391  let node = bump.alloc(BinExpr {
9392    inner,
9393    parent: Default::default(),
9394    left: get_view_for_expr(&inner.left, bump),
9395    right: get_view_for_expr(&inner.right, bump),
9396  });
9397  let parent: Node<'a> = (&*node).into();
9398  set_parent_for_expr(&node.left, parent);
9399  set_parent_for_expr(&node.right, parent);
9400  node
9401}
9402
9403fn set_parent_for_bin_expr<'a>(node: &BinExpr<'a>, parent: Node<'a>) {
9404  node.parent.set(parent);
9405}
9406
9407/// Identifier used as a pattern.
9408#[derive(Clone)]
9409pub struct BindingIdent<'a> {
9410  parent: ParentOnceCell<Node<'a>>,
9411  pub inner: &'a swc_ast::BindingIdent,
9412  pub id: &'a Ident<'a>,
9413  pub type_ann: Option<&'a TsTypeAnn<'a>>,
9414}
9415
9416impl<'a> BindingIdent<'a> {
9417  pub fn parent(&self) -> Node<'a> {
9418    self.parent.get().unwrap()
9419  }
9420}
9421
9422impl<'a> SourceRanged for BindingIdent<'a> {
9423  fn start(&self) -> SourcePos {
9424    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9425  }
9426  fn end(&self) -> SourcePos {
9427    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9428  }
9429}
9430
9431impl<'a> From<&BindingIdent<'a>> for Node<'a> {
9432  fn from(node: &BindingIdent<'a>) -> Node<'a> {
9433    let node = unsafe { mem::transmute::<&BindingIdent<'a>, &'a BindingIdent<'a>>(node) };
9434    Node::BindingIdent(node)
9435  }
9436}
9437
9438impl<'a> NodeTrait<'a> for BindingIdent<'a> {
9439  fn parent(&self) -> Option<Node<'a>> {
9440    Some(self.parent.get().unwrap().clone())
9441  }
9442
9443  fn children(&self) -> Vec<Node<'a>> {
9444    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
9445    children.push(self.id.into());
9446    if let Some(child) = self.type_ann {
9447      children.push(child.into());
9448    }
9449    children
9450  }
9451
9452  fn as_node(&self) -> Node<'a> {
9453    self.into()
9454  }
9455
9456  fn kind(&self) -> NodeKind {
9457    NodeKind::BindingIdent
9458  }
9459}
9460
9461impl<'a> CastableNode<'a> for BindingIdent<'a> {
9462  fn to(node: &Node<'a>) -> Option<&'a Self> {
9463    if let Node::BindingIdent(node) = node {
9464      Some(node)
9465    } else {
9466      None
9467    }
9468  }
9469
9470  fn kind() -> NodeKind {
9471    NodeKind::BindingIdent
9472  }
9473}
9474
9475fn get_view_for_binding_ident<'a>(inner: &'a swc_ast::BindingIdent, bump: &'a Bump) -> &'a BindingIdent<'a> {
9476  let node = bump.alloc(BindingIdent {
9477    inner,
9478    parent: Default::default(),
9479    id: get_view_for_ident(&inner.id, bump),
9480    type_ann: match &inner.type_ann {
9481      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
9482      None => None,
9483    },
9484  });
9485  let parent: Node<'a> = (&*node).into();
9486  set_parent_for_ident(&node.id, parent);
9487  if let Some(value) = &node.type_ann {
9488    set_parent_for_ts_type_ann(value, parent)
9489  };
9490  node
9491}
9492
9493fn set_parent_for_binding_ident<'a>(node: &BindingIdent<'a>, parent: Node<'a>) {
9494  node.parent.set(parent);
9495}
9496
9497/// Use when only block statements are allowed.
9498#[derive(Clone)]
9499pub struct BlockStmt<'a> {
9500  parent: ParentOnceCell<Node<'a>>,
9501  pub inner: &'a swc_ast::BlockStmt,
9502  pub stmts: &'a [Stmt<'a>],
9503}
9504
9505impl<'a> BlockStmt<'a> {
9506  pub fn parent(&self) -> Node<'a> {
9507    self.parent.get().unwrap()
9508  }
9509
9510  pub fn ctxt(&self) -> swc_common::SyntaxContext {
9511    self.inner.ctxt
9512  }
9513}
9514
9515impl<'a> SourceRanged for BlockStmt<'a> {
9516  fn start(&self) -> SourcePos {
9517    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9518  }
9519  fn end(&self) -> SourcePos {
9520    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9521  }
9522}
9523
9524impl<'a> From<&BlockStmt<'a>> for Node<'a> {
9525  fn from(node: &BlockStmt<'a>) -> Node<'a> {
9526    let node = unsafe { mem::transmute::<&BlockStmt<'a>, &'a BlockStmt<'a>>(node) };
9527    Node::BlockStmt(node)
9528  }
9529}
9530
9531impl<'a> NodeTrait<'a> for BlockStmt<'a> {
9532  fn parent(&self) -> Option<Node<'a>> {
9533    Some(self.parent.get().unwrap().clone())
9534  }
9535
9536  fn children(&self) -> Vec<Node<'a>> {
9537    let mut children = Vec::with_capacity(self.stmts.len());
9538    for child in self.stmts.iter() {
9539      children.push(child.into());
9540    }
9541    children
9542  }
9543
9544  fn as_node(&self) -> Node<'a> {
9545    self.into()
9546  }
9547
9548  fn kind(&self) -> NodeKind {
9549    NodeKind::BlockStmt
9550  }
9551}
9552
9553impl<'a> CastableNode<'a> for BlockStmt<'a> {
9554  fn to(node: &Node<'a>) -> Option<&'a Self> {
9555    if let Node::BlockStmt(node) = node {
9556      Some(node)
9557    } else {
9558      None
9559    }
9560  }
9561
9562  fn kind() -> NodeKind {
9563    NodeKind::BlockStmt
9564  }
9565}
9566
9567fn get_view_for_block_stmt<'a>(inner: &'a swc_ast::BlockStmt, bump: &'a Bump) -> &'a BlockStmt<'a> {
9568  let node = bump.alloc(BlockStmt {
9569    inner,
9570    parent: Default::default(),
9571    stmts: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.stmts.len(), bump);vec.extend(inner.stmts.iter().map(|value| get_view_for_stmt(value, bump))); vec }),
9572  });
9573  let parent: Node<'a> = (&*node).into();
9574  for value in node.stmts.iter() {
9575    set_parent_for_stmt(value, parent)
9576  }
9577  node
9578}
9579
9580fn set_parent_for_block_stmt<'a>(node: &BlockStmt<'a>, parent: Node<'a>) {
9581  node.parent.set(parent);
9582}
9583
9584/// A boolean literal.
9585///
9586///
9587/// # Creation
9588///
9589/// If you are creating a boolean literal with a dummy span, please use
9590/// `true.into()` or `false.into()`, instead of creating this struct directly.
9591///
9592/// All of `Box<Expr>`, `Expr`, `Lit`, `Bool` implements `From<bool>`.
9593#[derive(Clone)]
9594pub struct Bool<'a> {
9595  parent: ParentOnceCell<Node<'a>>,
9596  pub inner: &'a swc_ast::Bool,
9597}
9598
9599impl<'a> Bool<'a> {
9600  pub fn parent(&self) -> Node<'a> {
9601    self.parent.get().unwrap()
9602  }
9603
9604  pub fn value(&self) -> bool {
9605    self.inner.value
9606  }
9607}
9608
9609impl<'a> SourceRanged for Bool<'a> {
9610  fn start(&self) -> SourcePos {
9611    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9612  }
9613  fn end(&self) -> SourcePos {
9614    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9615  }
9616}
9617
9618impl<'a> From<&Bool<'a>> for Node<'a> {
9619  fn from(node: &Bool<'a>) -> Node<'a> {
9620    let node = unsafe { mem::transmute::<&Bool<'a>, &'a Bool<'a>>(node) };
9621    Node::Bool(node)
9622  }
9623}
9624
9625impl<'a> NodeTrait<'a> for Bool<'a> {
9626  fn parent(&self) -> Option<Node<'a>> {
9627    Some(self.parent.get().unwrap().clone())
9628  }
9629
9630  fn children(&self) -> Vec<Node<'a>> {
9631    Vec::with_capacity(0)
9632  }
9633
9634  fn as_node(&self) -> Node<'a> {
9635    self.into()
9636  }
9637
9638  fn kind(&self) -> NodeKind {
9639    NodeKind::Bool
9640  }
9641}
9642
9643impl<'a> CastableNode<'a> for Bool<'a> {
9644  fn to(node: &Node<'a>) -> Option<&'a Self> {
9645    if let Node::Bool(node) = node {
9646      Some(node)
9647    } else {
9648      None
9649    }
9650  }
9651
9652  fn kind() -> NodeKind {
9653    NodeKind::Bool
9654  }
9655}
9656
9657fn get_view_for_bool<'a>(inner: &'a swc_ast::Bool, bump: &'a Bump) -> &'a Bool<'a> {
9658  let node = bump.alloc(Bool {
9659    inner,
9660    parent: Default::default(),
9661  });
9662  node
9663}
9664
9665fn set_parent_for_bool<'a>(node: &Bool<'a>, parent: Node<'a>) {
9666  node.parent.set(parent);
9667}
9668
9669#[derive(Clone)]
9670pub struct BreakStmt<'a> {
9671  parent: ParentOnceCell<Node<'a>>,
9672  pub inner: &'a swc_ast::BreakStmt,
9673  pub label: Option<&'a Ident<'a>>,
9674}
9675
9676impl<'a> BreakStmt<'a> {
9677  pub fn parent(&self) -> Node<'a> {
9678    self.parent.get().unwrap()
9679  }
9680}
9681
9682impl<'a> SourceRanged for BreakStmt<'a> {
9683  fn start(&self) -> SourcePos {
9684    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9685  }
9686  fn end(&self) -> SourcePos {
9687    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9688  }
9689}
9690
9691impl<'a> From<&BreakStmt<'a>> for Node<'a> {
9692  fn from(node: &BreakStmt<'a>) -> Node<'a> {
9693    let node = unsafe { mem::transmute::<&BreakStmt<'a>, &'a BreakStmt<'a>>(node) };
9694    Node::BreakStmt(node)
9695  }
9696}
9697
9698impl<'a> NodeTrait<'a> for BreakStmt<'a> {
9699  fn parent(&self) -> Option<Node<'a>> {
9700    Some(self.parent.get().unwrap().clone())
9701  }
9702
9703  fn children(&self) -> Vec<Node<'a>> {
9704    let mut children = Vec::with_capacity(match &self.label { Some(_value) => 1, None => 0, });
9705    if let Some(child) = self.label {
9706      children.push(child.into());
9707    }
9708    children
9709  }
9710
9711  fn as_node(&self) -> Node<'a> {
9712    self.into()
9713  }
9714
9715  fn kind(&self) -> NodeKind {
9716    NodeKind::BreakStmt
9717  }
9718}
9719
9720impl<'a> CastableNode<'a> for BreakStmt<'a> {
9721  fn to(node: &Node<'a>) -> Option<&'a Self> {
9722    if let Node::BreakStmt(node) = node {
9723      Some(node)
9724    } else {
9725      None
9726    }
9727  }
9728
9729  fn kind() -> NodeKind {
9730    NodeKind::BreakStmt
9731  }
9732}
9733
9734fn get_view_for_break_stmt<'a>(inner: &'a swc_ast::BreakStmt, bump: &'a Bump) -> &'a BreakStmt<'a> {
9735  let node = bump.alloc(BreakStmt {
9736    inner,
9737    parent: Default::default(),
9738    label: match &inner.label {
9739      Some(value) => Some(get_view_for_ident(value, bump)),
9740      None => None,
9741    },
9742  });
9743  let parent: Node<'a> = (&*node).into();
9744  if let Some(value) = &node.label {
9745    set_parent_for_ident(value, parent)
9746  };
9747  node
9748}
9749
9750fn set_parent_for_break_stmt<'a>(node: &BreakStmt<'a>, parent: Node<'a>) {
9751  node.parent.set(parent);
9752}
9753
9754#[derive(Clone)]
9755pub struct CallExpr<'a> {
9756  parent: ParentOnceCell<Node<'a>>,
9757  pub inner: &'a swc_ast::CallExpr,
9758  pub callee: Callee<'a>,
9759  pub args: &'a [&'a ExprOrSpread<'a>],
9760  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
9761}
9762
9763impl<'a> CallExpr<'a> {
9764  pub fn parent(&self) -> Node<'a> {
9765    self.parent.get().unwrap()
9766  }
9767
9768  pub fn ctxt(&self) -> swc_common::SyntaxContext {
9769    self.inner.ctxt
9770  }
9771}
9772
9773impl<'a> SourceRanged for CallExpr<'a> {
9774  fn start(&self) -> SourcePos {
9775    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9776  }
9777  fn end(&self) -> SourcePos {
9778    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9779  }
9780}
9781
9782impl<'a> From<&CallExpr<'a>> for Node<'a> {
9783  fn from(node: &CallExpr<'a>) -> Node<'a> {
9784    let node = unsafe { mem::transmute::<&CallExpr<'a>, &'a CallExpr<'a>>(node) };
9785    Node::CallExpr(node)
9786  }
9787}
9788
9789impl<'a> NodeTrait<'a> for CallExpr<'a> {
9790  fn parent(&self) -> Option<Node<'a>> {
9791    Some(self.parent.get().unwrap().clone())
9792  }
9793
9794  fn children(&self) -> Vec<Node<'a>> {
9795    let mut children = Vec::with_capacity(1 + self.args.len() + match &self.type_args { Some(_value) => 1, None => 0, });
9796    children.push((&self.callee).into());
9797    for child in self.args.iter() {
9798      children.push((*child).into());
9799    }
9800    if let Some(child) = self.type_args {
9801      children.push(child.into());
9802    }
9803    children
9804  }
9805
9806  fn as_node(&self) -> Node<'a> {
9807    self.into()
9808  }
9809
9810  fn kind(&self) -> NodeKind {
9811    NodeKind::CallExpr
9812  }
9813}
9814
9815impl<'a> CastableNode<'a> for CallExpr<'a> {
9816  fn to(node: &Node<'a>) -> Option<&'a Self> {
9817    if let Node::CallExpr(node) = node {
9818      Some(node)
9819    } else {
9820      None
9821    }
9822  }
9823
9824  fn kind() -> NodeKind {
9825    NodeKind::CallExpr
9826  }
9827}
9828
9829fn get_view_for_call_expr<'a>(inner: &'a swc_ast::CallExpr, bump: &'a Bump) -> &'a CallExpr<'a> {
9830  let node = bump.alloc(CallExpr {
9831    inner,
9832    parent: Default::default(),
9833    callee: get_view_for_callee(&inner.callee, bump),
9834    args: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.args.len(), bump);vec.extend(inner.args.iter().map(|value| get_view_for_expr_or_spread(value, bump))); vec }),
9835    type_args: match &inner.type_args {
9836      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
9837      None => None,
9838    },
9839  });
9840  let parent: Node<'a> = (&*node).into();
9841  set_parent_for_callee(&node.callee, parent);
9842  for value in node.args.iter() {
9843    set_parent_for_expr_or_spread(value, parent)
9844  }
9845  if let Some(value) = &node.type_args {
9846    set_parent_for_ts_type_param_instantiation(value, parent)
9847  };
9848  node
9849}
9850
9851fn set_parent_for_call_expr<'a>(node: &CallExpr<'a>, parent: Node<'a>) {
9852  node.parent.set(parent);
9853}
9854
9855#[derive(Clone)]
9856pub struct CatchClause<'a> {
9857  parent: ParentOnceCell<&'a TryStmt<'a>>,
9858  pub inner: &'a swc_ast::CatchClause,
9859  /// es2019
9860  ///
9861  /// The param is null if the catch binding is omitted. E.g., try { foo() }
9862  /// catch { bar() }
9863  pub param: Option<Pat<'a>>,
9864  pub body: &'a BlockStmt<'a>,
9865}
9866
9867impl<'a> CatchClause<'a> {
9868  pub fn parent(&self) -> &'a TryStmt<'a> {
9869    self.parent.get().unwrap()
9870  }
9871}
9872
9873impl<'a> SourceRanged for CatchClause<'a> {
9874  fn start(&self) -> SourcePos {
9875    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9876  }
9877  fn end(&self) -> SourcePos {
9878    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9879  }
9880}
9881
9882impl<'a> From<&CatchClause<'a>> for Node<'a> {
9883  fn from(node: &CatchClause<'a>) -> Node<'a> {
9884    let node = unsafe { mem::transmute::<&CatchClause<'a>, &'a CatchClause<'a>>(node) };
9885    Node::CatchClause(node)
9886  }
9887}
9888
9889impl<'a> NodeTrait<'a> for CatchClause<'a> {
9890  fn parent(&self) -> Option<Node<'a>> {
9891    Some(self.parent.get().unwrap().into())
9892  }
9893
9894  fn children(&self) -> Vec<Node<'a>> {
9895    let mut children = Vec::with_capacity(1 + match &self.param { Some(_value) => 1, None => 0, });
9896    if let Some(child) = self.param.as_ref() {
9897      children.push(child.into());
9898    }
9899    children.push(self.body.into());
9900    children
9901  }
9902
9903  fn as_node(&self) -> Node<'a> {
9904    self.into()
9905  }
9906
9907  fn kind(&self) -> NodeKind {
9908    NodeKind::CatchClause
9909  }
9910}
9911
9912impl<'a> CastableNode<'a> for CatchClause<'a> {
9913  fn to(node: &Node<'a>) -> Option<&'a Self> {
9914    if let Node::CatchClause(node) = node {
9915      Some(node)
9916    } else {
9917      None
9918    }
9919  }
9920
9921  fn kind() -> NodeKind {
9922    NodeKind::CatchClause
9923  }
9924}
9925
9926fn get_view_for_catch_clause<'a>(inner: &'a swc_ast::CatchClause, bump: &'a Bump) -> &'a CatchClause<'a> {
9927  let node = bump.alloc(CatchClause {
9928    inner,
9929    parent: Default::default(),
9930    param: match &inner.param {
9931      Some(value) => Some(get_view_for_pat(value, bump)),
9932      None => None,
9933    },
9934    body: get_view_for_block_stmt(&inner.body, bump),
9935  });
9936  let parent: Node<'a> = (&*node).into();
9937  if let Some(value) = &node.param {
9938    set_parent_for_pat(value, parent)
9939  };
9940  set_parent_for_block_stmt(&node.body, parent);
9941  node
9942}
9943
9944fn set_parent_for_catch_clause<'a>(node: &CatchClause<'a>, parent: Node<'a>) {
9945  node.parent.set(parent.expect::<TryStmt>());
9946}
9947
9948#[derive(Clone)]
9949pub struct Class<'a> {
9950  parent: ParentOnceCell<Node<'a>>,
9951  pub inner: &'a swc_ast::Class,
9952  pub decorators: &'a [&'a Decorator<'a>],
9953  pub body: &'a [ClassMember<'a>],
9954  pub super_class: Option<Expr<'a>>,
9955  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
9956  pub super_type_params: Option<&'a TsTypeParamInstantiation<'a>>,
9957  /// Typescript extension.
9958  pub implements: &'a [&'a TsExprWithTypeArgs<'a>],
9959}
9960
9961impl<'a> Class<'a> {
9962  pub fn parent(&self) -> Node<'a> {
9963    self.parent.get().unwrap()
9964  }
9965
9966  pub fn ctxt(&self) -> swc_common::SyntaxContext {
9967    self.inner.ctxt
9968  }
9969
9970  pub fn is_abstract(&self) -> bool {
9971    self.inner.is_abstract
9972  }
9973}
9974
9975impl<'a> SourceRanged for Class<'a> {
9976  fn start(&self) -> SourcePos {
9977    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9978  }
9979  fn end(&self) -> SourcePos {
9980    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9981  }
9982}
9983
9984impl<'a> From<&Class<'a>> for Node<'a> {
9985  fn from(node: &Class<'a>) -> Node<'a> {
9986    let node = unsafe { mem::transmute::<&Class<'a>, &'a Class<'a>>(node) };
9987    Node::Class(node)
9988  }
9989}
9990
9991impl<'a> NodeTrait<'a> for Class<'a> {
9992  fn parent(&self) -> Option<Node<'a>> {
9993    Some(self.parent.get().unwrap().clone())
9994  }
9995
9996  fn children(&self) -> Vec<Node<'a>> {
9997    let mut children = Vec::with_capacity(self.decorators.len() + self.body.len() + match &self.super_class { Some(_value) => 1, None => 0, } + match &self.type_params { Some(_value) => 1, None => 0, } + match &self.super_type_params { Some(_value) => 1, None => 0, } + self.implements.len());
9998    for child in self.decorators.iter() {
9999      children.push((*child).into());
10000    }
10001    for child in self.body.iter() {
10002      children.push(child.into());
10003    }
10004    if let Some(child) = self.super_class.as_ref() {
10005      children.push(child.into());
10006    }
10007    if let Some(child) = self.type_params {
10008      children.push(child.into());
10009    }
10010    if let Some(child) = self.super_type_params {
10011      children.push(child.into());
10012    }
10013    for child in self.implements.iter() {
10014      children.push((*child).into());
10015    }
10016    children
10017  }
10018
10019  fn as_node(&self) -> Node<'a> {
10020    self.into()
10021  }
10022
10023  fn kind(&self) -> NodeKind {
10024    NodeKind::Class
10025  }
10026}
10027
10028impl<'a> CastableNode<'a> for Class<'a> {
10029  fn to(node: &Node<'a>) -> Option<&'a Self> {
10030    if let Node::Class(node) = node {
10031      Some(node)
10032    } else {
10033      None
10034    }
10035  }
10036
10037  fn kind() -> NodeKind {
10038    NodeKind::Class
10039  }
10040}
10041
10042fn get_view_for_class<'a>(inner: &'a swc_ast::Class, bump: &'a Bump) -> &'a Class<'a> {
10043  let node = bump.alloc(Class {
10044    inner,
10045    parent: Default::default(),
10046    decorators: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.decorators.len(), bump);vec.extend(inner.decorators.iter().map(|value| get_view_for_decorator(value, bump))); vec }),
10047    body: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.body.len(), bump);vec.extend(inner.body.iter().map(|value| get_view_for_class_member(value, bump))); vec }),
10048    super_class: match &inner.super_class {
10049      Some(value) => Some(get_view_for_expr(value, bump)),
10050      None => None,
10051    },
10052    type_params: match &inner.type_params {
10053      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
10054      None => None,
10055    },
10056    super_type_params: match &inner.super_type_params {
10057      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
10058      None => None,
10059    },
10060    implements: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.implements.len(), bump);vec.extend(inner.implements.iter().map(|value| get_view_for_ts_expr_with_type_args(value, bump))); vec }),
10061  });
10062  let parent: Node<'a> = (&*node).into();
10063  for value in node.decorators.iter() {
10064    set_parent_for_decorator(value, parent)
10065  }
10066  for value in node.body.iter() {
10067    set_parent_for_class_member(value, parent)
10068  }
10069  if let Some(value) = &node.super_class {
10070    set_parent_for_expr(value, parent)
10071  };
10072  if let Some(value) = &node.type_params {
10073    set_parent_for_ts_type_param_decl(value, parent)
10074  };
10075  if let Some(value) = &node.super_type_params {
10076    set_parent_for_ts_type_param_instantiation(value, parent)
10077  };
10078  for value in node.implements.iter() {
10079    set_parent_for_ts_expr_with_type_args(value, parent)
10080  }
10081  node
10082}
10083
10084fn set_parent_for_class<'a>(node: &Class<'a>, parent: Node<'a>) {
10085  node.parent.set(parent);
10086}
10087
10088#[derive(Clone)]
10089pub struct ClassDecl<'a> {
10090  parent: ParentOnceCell<Node<'a>>,
10091  pub inner: &'a swc_ast::ClassDecl,
10092  pub ident: &'a Ident<'a>,
10093  pub class: &'a Class<'a>,
10094}
10095
10096impl<'a> ClassDecl<'a> {
10097  pub fn parent(&self) -> Node<'a> {
10098    self.parent.get().unwrap()
10099  }
10100
10101  pub fn declare(&self) -> bool {
10102    self.inner.declare
10103  }
10104}
10105
10106impl<'a> SourceRanged for ClassDecl<'a> {
10107  fn start(&self) -> SourcePos {
10108    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10109  }
10110  fn end(&self) -> SourcePos {
10111    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10112  }
10113}
10114
10115impl<'a> From<&ClassDecl<'a>> for Node<'a> {
10116  fn from(node: &ClassDecl<'a>) -> Node<'a> {
10117    let node = unsafe { mem::transmute::<&ClassDecl<'a>, &'a ClassDecl<'a>>(node) };
10118    Node::ClassDecl(node)
10119  }
10120}
10121
10122impl<'a> NodeTrait<'a> for ClassDecl<'a> {
10123  fn parent(&self) -> Option<Node<'a>> {
10124    Some(self.parent.get().unwrap().clone())
10125  }
10126
10127  fn children(&self) -> Vec<Node<'a>> {
10128    let mut children = Vec::with_capacity(2);
10129    children.push(self.ident.into());
10130    children.push(self.class.into());
10131    children
10132  }
10133
10134  fn as_node(&self) -> Node<'a> {
10135    self.into()
10136  }
10137
10138  fn kind(&self) -> NodeKind {
10139    NodeKind::ClassDecl
10140  }
10141}
10142
10143impl<'a> CastableNode<'a> for ClassDecl<'a> {
10144  fn to(node: &Node<'a>) -> Option<&'a Self> {
10145    if let Node::ClassDecl(node) = node {
10146      Some(node)
10147    } else {
10148      None
10149    }
10150  }
10151
10152  fn kind() -> NodeKind {
10153    NodeKind::ClassDecl
10154  }
10155}
10156
10157fn get_view_for_class_decl<'a>(inner: &'a swc_ast::ClassDecl, bump: &'a Bump) -> &'a ClassDecl<'a> {
10158  let node = bump.alloc(ClassDecl {
10159    inner,
10160    parent: Default::default(),
10161    ident: get_view_for_ident(&inner.ident, bump),
10162    class: get_view_for_class(&inner.class, bump),
10163  });
10164  let parent: Node<'a> = (&*node).into();
10165  set_parent_for_ident(&node.ident, parent);
10166  set_parent_for_class(&node.class, parent);
10167  node
10168}
10169
10170fn set_parent_for_class_decl<'a>(node: &ClassDecl<'a>, parent: Node<'a>) {
10171  node.parent.set(parent);
10172}
10173
10174/// Class expression.
10175#[derive(Clone)]
10176pub struct ClassExpr<'a> {
10177  parent: ParentOnceCell<Node<'a>>,
10178  pub inner: &'a swc_ast::ClassExpr,
10179  pub ident: Option<&'a Ident<'a>>,
10180  pub class: &'a Class<'a>,
10181}
10182
10183impl<'a> ClassExpr<'a> {
10184  pub fn parent(&self) -> Node<'a> {
10185    self.parent.get().unwrap()
10186  }
10187}
10188
10189impl<'a> SourceRanged for ClassExpr<'a> {
10190  fn start(&self) -> SourcePos {
10191    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10192  }
10193  fn end(&self) -> SourcePos {
10194    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10195  }
10196}
10197
10198impl<'a> From<&ClassExpr<'a>> for Node<'a> {
10199  fn from(node: &ClassExpr<'a>) -> Node<'a> {
10200    let node = unsafe { mem::transmute::<&ClassExpr<'a>, &'a ClassExpr<'a>>(node) };
10201    Node::ClassExpr(node)
10202  }
10203}
10204
10205impl<'a> NodeTrait<'a> for ClassExpr<'a> {
10206  fn parent(&self) -> Option<Node<'a>> {
10207    Some(self.parent.get().unwrap().clone())
10208  }
10209
10210  fn children(&self) -> Vec<Node<'a>> {
10211    let mut children = Vec::with_capacity(1 + match &self.ident { Some(_value) => 1, None => 0, });
10212    if let Some(child) = self.ident {
10213      children.push(child.into());
10214    }
10215    children.push(self.class.into());
10216    children
10217  }
10218
10219  fn as_node(&self) -> Node<'a> {
10220    self.into()
10221  }
10222
10223  fn kind(&self) -> NodeKind {
10224    NodeKind::ClassExpr
10225  }
10226}
10227
10228impl<'a> CastableNode<'a> for ClassExpr<'a> {
10229  fn to(node: &Node<'a>) -> Option<&'a Self> {
10230    if let Node::ClassExpr(node) = node {
10231      Some(node)
10232    } else {
10233      None
10234    }
10235  }
10236
10237  fn kind() -> NodeKind {
10238    NodeKind::ClassExpr
10239  }
10240}
10241
10242fn get_view_for_class_expr<'a>(inner: &'a swc_ast::ClassExpr, bump: &'a Bump) -> &'a ClassExpr<'a> {
10243  let node = bump.alloc(ClassExpr {
10244    inner,
10245    parent: Default::default(),
10246    ident: match &inner.ident {
10247      Some(value) => Some(get_view_for_ident(value, bump)),
10248      None => None,
10249    },
10250    class: get_view_for_class(&inner.class, bump),
10251  });
10252  let parent: Node<'a> = (&*node).into();
10253  if let Some(value) = &node.ident {
10254    set_parent_for_ident(value, parent)
10255  };
10256  set_parent_for_class(&node.class, parent);
10257  node
10258}
10259
10260fn set_parent_for_class_expr<'a>(node: &ClassExpr<'a>, parent: Node<'a>) {
10261  node.parent.set(parent);
10262}
10263
10264#[derive(Clone)]
10265pub struct ClassMethod<'a> {
10266  parent: ParentOnceCell<&'a Class<'a>>,
10267  pub inner: &'a swc_ast::ClassMethod,
10268  pub key: PropName<'a>,
10269  pub function: &'a Function<'a>,
10270}
10271
10272impl<'a> ClassMethod<'a> {
10273  pub fn parent(&self) -> &'a Class<'a> {
10274    self.parent.get().unwrap()
10275  }
10276
10277  pub fn method_kind(&self) -> MethodKind {
10278    self.inner.kind
10279  }
10280
10281  pub fn is_static(&self) -> bool {
10282    self.inner.is_static
10283  }
10284
10285  /// Typescript extension.
10286  pub fn accessibility(&self) -> Option<Accessibility> {
10287    self.inner.accessibility
10288  }
10289
10290  /// Typescript extension.
10291  pub fn is_abstract(&self) -> bool {
10292    self.inner.is_abstract
10293  }
10294
10295  pub fn is_optional(&self) -> bool {
10296    self.inner.is_optional
10297  }
10298
10299  pub fn is_override(&self) -> bool {
10300    self.inner.is_override
10301  }
10302}
10303
10304impl<'a> SourceRanged for ClassMethod<'a> {
10305  fn start(&self) -> SourcePos {
10306    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10307  }
10308  fn end(&self) -> SourcePos {
10309    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10310  }
10311}
10312
10313impl<'a> From<&ClassMethod<'a>> for Node<'a> {
10314  fn from(node: &ClassMethod<'a>) -> Node<'a> {
10315    let node = unsafe { mem::transmute::<&ClassMethod<'a>, &'a ClassMethod<'a>>(node) };
10316    Node::ClassMethod(node)
10317  }
10318}
10319
10320impl<'a> NodeTrait<'a> for ClassMethod<'a> {
10321  fn parent(&self) -> Option<Node<'a>> {
10322    Some(self.parent.get().unwrap().into())
10323  }
10324
10325  fn children(&self) -> Vec<Node<'a>> {
10326    let mut children = Vec::with_capacity(2);
10327    children.push((&self.key).into());
10328    children.push(self.function.into());
10329    children
10330  }
10331
10332  fn as_node(&self) -> Node<'a> {
10333    self.into()
10334  }
10335
10336  fn kind(&self) -> NodeKind {
10337    NodeKind::ClassMethod
10338  }
10339}
10340
10341impl<'a> CastableNode<'a> for ClassMethod<'a> {
10342  fn to(node: &Node<'a>) -> Option<&'a Self> {
10343    if let Node::ClassMethod(node) = node {
10344      Some(node)
10345    } else {
10346      None
10347    }
10348  }
10349
10350  fn kind() -> NodeKind {
10351    NodeKind::ClassMethod
10352  }
10353}
10354
10355fn get_view_for_class_method<'a>(inner: &'a swc_ast::ClassMethod, bump: &'a Bump) -> &'a ClassMethod<'a> {
10356  let node = bump.alloc(ClassMethod {
10357    inner,
10358    parent: Default::default(),
10359    key: get_view_for_prop_name(&inner.key, bump),
10360    function: get_view_for_function(&inner.function, bump),
10361  });
10362  let parent: Node<'a> = (&*node).into();
10363  set_parent_for_prop_name(&node.key, parent);
10364  set_parent_for_function(&node.function, parent);
10365  node
10366}
10367
10368fn set_parent_for_class_method<'a>(node: &ClassMethod<'a>, parent: Node<'a>) {
10369  node.parent.set(parent.expect::<Class>());
10370}
10371
10372#[derive(Clone)]
10373pub struct ClassProp<'a> {
10374  parent: ParentOnceCell<&'a Class<'a>>,
10375  pub inner: &'a swc_ast::ClassProp,
10376  pub key: PropName<'a>,
10377  pub value: Option<Expr<'a>>,
10378  pub type_ann: Option<&'a TsTypeAnn<'a>>,
10379  pub decorators: &'a [&'a Decorator<'a>],
10380}
10381
10382impl<'a> ClassProp<'a> {
10383  pub fn parent(&self) -> &'a Class<'a> {
10384    self.parent.get().unwrap()
10385  }
10386
10387  pub fn is_static(&self) -> bool {
10388    self.inner.is_static
10389  }
10390
10391  /// Typescript extension.
10392  pub fn accessibility(&self) -> Option<Accessibility> {
10393    self.inner.accessibility
10394  }
10395
10396  /// Typescript extension.
10397  pub fn is_abstract(&self) -> bool {
10398    self.inner.is_abstract
10399  }
10400
10401  pub fn is_optional(&self) -> bool {
10402    self.inner.is_optional
10403  }
10404
10405  pub fn is_override(&self) -> bool {
10406    self.inner.is_override
10407  }
10408
10409  pub fn readonly(&self) -> bool {
10410    self.inner.readonly
10411  }
10412
10413  pub fn declare(&self) -> bool {
10414    self.inner.declare
10415  }
10416
10417  pub fn definite(&self) -> bool {
10418    self.inner.definite
10419  }
10420}
10421
10422impl<'a> SourceRanged for ClassProp<'a> {
10423  fn start(&self) -> SourcePos {
10424    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10425  }
10426  fn end(&self) -> SourcePos {
10427    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10428  }
10429}
10430
10431impl<'a> From<&ClassProp<'a>> for Node<'a> {
10432  fn from(node: &ClassProp<'a>) -> Node<'a> {
10433    let node = unsafe { mem::transmute::<&ClassProp<'a>, &'a ClassProp<'a>>(node) };
10434    Node::ClassProp(node)
10435  }
10436}
10437
10438impl<'a> NodeTrait<'a> for ClassProp<'a> {
10439  fn parent(&self) -> Option<Node<'a>> {
10440    Some(self.parent.get().unwrap().into())
10441  }
10442
10443  fn children(&self) -> Vec<Node<'a>> {
10444    let mut children = Vec::with_capacity(1 + match &self.value { Some(_value) => 1, None => 0, } + match &self.type_ann { Some(_value) => 1, None => 0, } + self.decorators.len());
10445    children.push((&self.key).into());
10446    if let Some(child) = self.value.as_ref() {
10447      children.push(child.into());
10448    }
10449    if let Some(child) = self.type_ann {
10450      children.push(child.into());
10451    }
10452    for child in self.decorators.iter() {
10453      children.push((*child).into());
10454    }
10455    children
10456  }
10457
10458  fn as_node(&self) -> Node<'a> {
10459    self.into()
10460  }
10461
10462  fn kind(&self) -> NodeKind {
10463    NodeKind::ClassProp
10464  }
10465}
10466
10467impl<'a> CastableNode<'a> for ClassProp<'a> {
10468  fn to(node: &Node<'a>) -> Option<&'a Self> {
10469    if let Node::ClassProp(node) = node {
10470      Some(node)
10471    } else {
10472      None
10473    }
10474  }
10475
10476  fn kind() -> NodeKind {
10477    NodeKind::ClassProp
10478  }
10479}
10480
10481fn get_view_for_class_prop<'a>(inner: &'a swc_ast::ClassProp, bump: &'a Bump) -> &'a ClassProp<'a> {
10482  let node = bump.alloc(ClassProp {
10483    inner,
10484    parent: Default::default(),
10485    key: get_view_for_prop_name(&inner.key, bump),
10486    value: match &inner.value {
10487      Some(value) => Some(get_view_for_expr(value, bump)),
10488      None => None,
10489    },
10490    type_ann: match &inner.type_ann {
10491      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
10492      None => None,
10493    },
10494    decorators: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.decorators.len(), bump);vec.extend(inner.decorators.iter().map(|value| get_view_for_decorator(value, bump))); vec }),
10495  });
10496  let parent: Node<'a> = (&*node).into();
10497  set_parent_for_prop_name(&node.key, parent);
10498  if let Some(value) = &node.value {
10499    set_parent_for_expr(value, parent)
10500  };
10501  if let Some(value) = &node.type_ann {
10502    set_parent_for_ts_type_ann(value, parent)
10503  };
10504  for value in node.decorators.iter() {
10505    set_parent_for_decorator(value, parent)
10506  }
10507  node
10508}
10509
10510fn set_parent_for_class_prop<'a>(node: &ClassProp<'a>, parent: Node<'a>) {
10511  node.parent.set(parent.expect::<Class>());
10512}
10513
10514#[derive(Clone)]
10515pub struct ComputedPropName<'a> {
10516  parent: ParentOnceCell<Node<'a>>,
10517  pub inner: &'a swc_ast::ComputedPropName,
10518  pub expr: Expr<'a>,
10519}
10520
10521impl<'a> ComputedPropName<'a> {
10522  pub fn parent(&self) -> Node<'a> {
10523    self.parent.get().unwrap()
10524  }
10525}
10526
10527impl<'a> SourceRanged for ComputedPropName<'a> {
10528  fn start(&self) -> SourcePos {
10529    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10530  }
10531  fn end(&self) -> SourcePos {
10532    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10533  }
10534}
10535
10536impl<'a> From<&ComputedPropName<'a>> for Node<'a> {
10537  fn from(node: &ComputedPropName<'a>) -> Node<'a> {
10538    let node = unsafe { mem::transmute::<&ComputedPropName<'a>, &'a ComputedPropName<'a>>(node) };
10539    Node::ComputedPropName(node)
10540  }
10541}
10542
10543impl<'a> NodeTrait<'a> for ComputedPropName<'a> {
10544  fn parent(&self) -> Option<Node<'a>> {
10545    Some(self.parent.get().unwrap().clone())
10546  }
10547
10548  fn children(&self) -> Vec<Node<'a>> {
10549    let mut children = Vec::with_capacity(1);
10550    children.push((&self.expr).into());
10551    children
10552  }
10553
10554  fn as_node(&self) -> Node<'a> {
10555    self.into()
10556  }
10557
10558  fn kind(&self) -> NodeKind {
10559    NodeKind::ComputedPropName
10560  }
10561}
10562
10563impl<'a> CastableNode<'a> for ComputedPropName<'a> {
10564  fn to(node: &Node<'a>) -> Option<&'a Self> {
10565    if let Node::ComputedPropName(node) = node {
10566      Some(node)
10567    } else {
10568      None
10569    }
10570  }
10571
10572  fn kind() -> NodeKind {
10573    NodeKind::ComputedPropName
10574  }
10575}
10576
10577fn get_view_for_computed_prop_name<'a>(inner: &'a swc_ast::ComputedPropName, bump: &'a Bump) -> &'a ComputedPropName<'a> {
10578  let node = bump.alloc(ComputedPropName {
10579    inner,
10580    parent: Default::default(),
10581    expr: get_view_for_expr(&inner.expr, bump),
10582  });
10583  let parent: Node<'a> = (&*node).into();
10584  set_parent_for_expr(&node.expr, parent);
10585  node
10586}
10587
10588fn set_parent_for_computed_prop_name<'a>(node: &ComputedPropName<'a>, parent: Node<'a>) {
10589  node.parent.set(parent);
10590}
10591
10592#[derive(Clone)]
10593pub struct CondExpr<'a> {
10594  parent: ParentOnceCell<Node<'a>>,
10595  pub inner: &'a swc_ast::CondExpr,
10596  pub test: Expr<'a>,
10597  pub cons: Expr<'a>,
10598  pub alt: Expr<'a>,
10599}
10600
10601impl<'a> CondExpr<'a> {
10602  pub fn parent(&self) -> Node<'a> {
10603    self.parent.get().unwrap()
10604  }
10605}
10606
10607impl<'a> SourceRanged for CondExpr<'a> {
10608  fn start(&self) -> SourcePos {
10609    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10610  }
10611  fn end(&self) -> SourcePos {
10612    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10613  }
10614}
10615
10616impl<'a> From<&CondExpr<'a>> for Node<'a> {
10617  fn from(node: &CondExpr<'a>) -> Node<'a> {
10618    let node = unsafe { mem::transmute::<&CondExpr<'a>, &'a CondExpr<'a>>(node) };
10619    Node::CondExpr(node)
10620  }
10621}
10622
10623impl<'a> NodeTrait<'a> for CondExpr<'a> {
10624  fn parent(&self) -> Option<Node<'a>> {
10625    Some(self.parent.get().unwrap().clone())
10626  }
10627
10628  fn children(&self) -> Vec<Node<'a>> {
10629    let mut children = Vec::with_capacity(3);
10630    children.push((&self.test).into());
10631    children.push((&self.cons).into());
10632    children.push((&self.alt).into());
10633    children
10634  }
10635
10636  fn as_node(&self) -> Node<'a> {
10637    self.into()
10638  }
10639
10640  fn kind(&self) -> NodeKind {
10641    NodeKind::CondExpr
10642  }
10643}
10644
10645impl<'a> CastableNode<'a> for CondExpr<'a> {
10646  fn to(node: &Node<'a>) -> Option<&'a Self> {
10647    if let Node::CondExpr(node) = node {
10648      Some(node)
10649    } else {
10650      None
10651    }
10652  }
10653
10654  fn kind() -> NodeKind {
10655    NodeKind::CondExpr
10656  }
10657}
10658
10659fn get_view_for_cond_expr<'a>(inner: &'a swc_ast::CondExpr, bump: &'a Bump) -> &'a CondExpr<'a> {
10660  let node = bump.alloc(CondExpr {
10661    inner,
10662    parent: Default::default(),
10663    test: get_view_for_expr(&inner.test, bump),
10664    cons: get_view_for_expr(&inner.cons, bump),
10665    alt: get_view_for_expr(&inner.alt, bump),
10666  });
10667  let parent: Node<'a> = (&*node).into();
10668  set_parent_for_expr(&node.test, parent);
10669  set_parent_for_expr(&node.cons, parent);
10670  set_parent_for_expr(&node.alt, parent);
10671  node
10672}
10673
10674fn set_parent_for_cond_expr<'a>(node: &CondExpr<'a>, parent: Node<'a>) {
10675  node.parent.set(parent);
10676}
10677
10678#[derive(Clone)]
10679pub struct Constructor<'a> {
10680  parent: ParentOnceCell<&'a Class<'a>>,
10681  pub inner: &'a swc_ast::Constructor,
10682  pub key: PropName<'a>,
10683  pub params: &'a [ParamOrTsParamProp<'a>],
10684  pub body: Option<&'a BlockStmt<'a>>,
10685}
10686
10687impl<'a> Constructor<'a> {
10688  pub fn parent(&self) -> &'a Class<'a> {
10689    self.parent.get().unwrap()
10690  }
10691
10692  pub fn ctxt(&self) -> swc_common::SyntaxContext {
10693    self.inner.ctxt
10694  }
10695
10696  pub fn accessibility(&self) -> Option<Accessibility> {
10697    self.inner.accessibility
10698  }
10699
10700  pub fn is_optional(&self) -> bool {
10701    self.inner.is_optional
10702  }
10703}
10704
10705impl<'a> SourceRanged for Constructor<'a> {
10706  fn start(&self) -> SourcePos {
10707    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10708  }
10709  fn end(&self) -> SourcePos {
10710    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10711  }
10712}
10713
10714impl<'a> From<&Constructor<'a>> for Node<'a> {
10715  fn from(node: &Constructor<'a>) -> Node<'a> {
10716    let node = unsafe { mem::transmute::<&Constructor<'a>, &'a Constructor<'a>>(node) };
10717    Node::Constructor(node)
10718  }
10719}
10720
10721impl<'a> NodeTrait<'a> for Constructor<'a> {
10722  fn parent(&self) -> Option<Node<'a>> {
10723    Some(self.parent.get().unwrap().into())
10724  }
10725
10726  fn children(&self) -> Vec<Node<'a>> {
10727    let mut children = Vec::with_capacity(1 + self.params.len() + match &self.body { Some(_value) => 1, None => 0, });
10728    children.push((&self.key).into());
10729    for child in self.params.iter() {
10730      children.push(child.into());
10731    }
10732    if let Some(child) = self.body {
10733      children.push(child.into());
10734    }
10735    children
10736  }
10737
10738  fn as_node(&self) -> Node<'a> {
10739    self.into()
10740  }
10741
10742  fn kind(&self) -> NodeKind {
10743    NodeKind::Constructor
10744  }
10745}
10746
10747impl<'a> CastableNode<'a> for Constructor<'a> {
10748  fn to(node: &Node<'a>) -> Option<&'a Self> {
10749    if let Node::Constructor(node) = node {
10750      Some(node)
10751    } else {
10752      None
10753    }
10754  }
10755
10756  fn kind() -> NodeKind {
10757    NodeKind::Constructor
10758  }
10759}
10760
10761fn get_view_for_constructor<'a>(inner: &'a swc_ast::Constructor, bump: &'a Bump) -> &'a Constructor<'a> {
10762  let node = bump.alloc(Constructor {
10763    inner,
10764    parent: Default::default(),
10765    key: get_view_for_prop_name(&inner.key, bump),
10766    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_param_or_ts_param_prop(value, bump))); vec }),
10767    body: match &inner.body {
10768      Some(value) => Some(get_view_for_block_stmt(value, bump)),
10769      None => None,
10770    },
10771  });
10772  let parent: Node<'a> = (&*node).into();
10773  set_parent_for_prop_name(&node.key, parent);
10774  for value in node.params.iter() {
10775    set_parent_for_param_or_ts_param_prop(value, parent)
10776  }
10777  if let Some(value) = &node.body {
10778    set_parent_for_block_stmt(value, parent)
10779  };
10780  node
10781}
10782
10783fn set_parent_for_constructor<'a>(node: &Constructor<'a>, parent: Node<'a>) {
10784  node.parent.set(parent.expect::<Class>());
10785}
10786
10787#[derive(Clone)]
10788pub struct ContinueStmt<'a> {
10789  parent: ParentOnceCell<Node<'a>>,
10790  pub inner: &'a swc_ast::ContinueStmt,
10791  pub label: Option<&'a Ident<'a>>,
10792}
10793
10794impl<'a> ContinueStmt<'a> {
10795  pub fn parent(&self) -> Node<'a> {
10796    self.parent.get().unwrap()
10797  }
10798}
10799
10800impl<'a> SourceRanged for ContinueStmt<'a> {
10801  fn start(&self) -> SourcePos {
10802    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10803  }
10804  fn end(&self) -> SourcePos {
10805    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10806  }
10807}
10808
10809impl<'a> From<&ContinueStmt<'a>> for Node<'a> {
10810  fn from(node: &ContinueStmt<'a>) -> Node<'a> {
10811    let node = unsafe { mem::transmute::<&ContinueStmt<'a>, &'a ContinueStmt<'a>>(node) };
10812    Node::ContinueStmt(node)
10813  }
10814}
10815
10816impl<'a> NodeTrait<'a> for ContinueStmt<'a> {
10817  fn parent(&self) -> Option<Node<'a>> {
10818    Some(self.parent.get().unwrap().clone())
10819  }
10820
10821  fn children(&self) -> Vec<Node<'a>> {
10822    let mut children = Vec::with_capacity(match &self.label { Some(_value) => 1, None => 0, });
10823    if let Some(child) = self.label {
10824      children.push(child.into());
10825    }
10826    children
10827  }
10828
10829  fn as_node(&self) -> Node<'a> {
10830    self.into()
10831  }
10832
10833  fn kind(&self) -> NodeKind {
10834    NodeKind::ContinueStmt
10835  }
10836}
10837
10838impl<'a> CastableNode<'a> for ContinueStmt<'a> {
10839  fn to(node: &Node<'a>) -> Option<&'a Self> {
10840    if let Node::ContinueStmt(node) = node {
10841      Some(node)
10842    } else {
10843      None
10844    }
10845  }
10846
10847  fn kind() -> NodeKind {
10848    NodeKind::ContinueStmt
10849  }
10850}
10851
10852fn get_view_for_continue_stmt<'a>(inner: &'a swc_ast::ContinueStmt, bump: &'a Bump) -> &'a ContinueStmt<'a> {
10853  let node = bump.alloc(ContinueStmt {
10854    inner,
10855    parent: Default::default(),
10856    label: match &inner.label {
10857      Some(value) => Some(get_view_for_ident(value, bump)),
10858      None => None,
10859    },
10860  });
10861  let parent: Node<'a> = (&*node).into();
10862  if let Some(value) = &node.label {
10863    set_parent_for_ident(value, parent)
10864  };
10865  node
10866}
10867
10868fn set_parent_for_continue_stmt<'a>(node: &ContinueStmt<'a>, parent: Node<'a>) {
10869  node.parent.set(parent);
10870}
10871
10872#[derive(Clone)]
10873pub struct DebuggerStmt<'a> {
10874  parent: ParentOnceCell<Node<'a>>,
10875  pub inner: &'a swc_ast::DebuggerStmt,
10876}
10877
10878impl<'a> DebuggerStmt<'a> {
10879  pub fn parent(&self) -> Node<'a> {
10880    self.parent.get().unwrap()
10881  }
10882}
10883
10884impl<'a> SourceRanged for DebuggerStmt<'a> {
10885  fn start(&self) -> SourcePos {
10886    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10887  }
10888  fn end(&self) -> SourcePos {
10889    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10890  }
10891}
10892
10893impl<'a> From<&DebuggerStmt<'a>> for Node<'a> {
10894  fn from(node: &DebuggerStmt<'a>) -> Node<'a> {
10895    let node = unsafe { mem::transmute::<&DebuggerStmt<'a>, &'a DebuggerStmt<'a>>(node) };
10896    Node::DebuggerStmt(node)
10897  }
10898}
10899
10900impl<'a> NodeTrait<'a> for DebuggerStmt<'a> {
10901  fn parent(&self) -> Option<Node<'a>> {
10902    Some(self.parent.get().unwrap().clone())
10903  }
10904
10905  fn children(&self) -> Vec<Node<'a>> {
10906    Vec::with_capacity(0)
10907  }
10908
10909  fn as_node(&self) -> Node<'a> {
10910    self.into()
10911  }
10912
10913  fn kind(&self) -> NodeKind {
10914    NodeKind::DebuggerStmt
10915  }
10916}
10917
10918impl<'a> CastableNode<'a> for DebuggerStmt<'a> {
10919  fn to(node: &Node<'a>) -> Option<&'a Self> {
10920    if let Node::DebuggerStmt(node) = node {
10921      Some(node)
10922    } else {
10923      None
10924    }
10925  }
10926
10927  fn kind() -> NodeKind {
10928    NodeKind::DebuggerStmt
10929  }
10930}
10931
10932fn get_view_for_debugger_stmt<'a>(inner: &'a swc_ast::DebuggerStmt, bump: &'a Bump) -> &'a DebuggerStmt<'a> {
10933  let node = bump.alloc(DebuggerStmt {
10934    inner,
10935    parent: Default::default(),
10936  });
10937  node
10938}
10939
10940fn set_parent_for_debugger_stmt<'a>(node: &DebuggerStmt<'a>, parent: Node<'a>) {
10941  node.parent.set(parent);
10942}
10943
10944#[derive(Clone)]
10945pub struct Decorator<'a> {
10946  parent: ParentOnceCell<Node<'a>>,
10947  pub inner: &'a swc_ast::Decorator,
10948  pub expr: Expr<'a>,
10949}
10950
10951impl<'a> Decorator<'a> {
10952  pub fn parent(&self) -> Node<'a> {
10953    self.parent.get().unwrap()
10954  }
10955}
10956
10957impl<'a> SourceRanged for Decorator<'a> {
10958  fn start(&self) -> SourcePos {
10959    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10960  }
10961  fn end(&self) -> SourcePos {
10962    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10963  }
10964}
10965
10966impl<'a> From<&Decorator<'a>> for Node<'a> {
10967  fn from(node: &Decorator<'a>) -> Node<'a> {
10968    let node = unsafe { mem::transmute::<&Decorator<'a>, &'a Decorator<'a>>(node) };
10969    Node::Decorator(node)
10970  }
10971}
10972
10973impl<'a> NodeTrait<'a> for Decorator<'a> {
10974  fn parent(&self) -> Option<Node<'a>> {
10975    Some(self.parent.get().unwrap().clone())
10976  }
10977
10978  fn children(&self) -> Vec<Node<'a>> {
10979    let mut children = Vec::with_capacity(1);
10980    children.push((&self.expr).into());
10981    children
10982  }
10983
10984  fn as_node(&self) -> Node<'a> {
10985    self.into()
10986  }
10987
10988  fn kind(&self) -> NodeKind {
10989    NodeKind::Decorator
10990  }
10991}
10992
10993impl<'a> CastableNode<'a> for Decorator<'a> {
10994  fn to(node: &Node<'a>) -> Option<&'a Self> {
10995    if let Node::Decorator(node) = node {
10996      Some(node)
10997    } else {
10998      None
10999    }
11000  }
11001
11002  fn kind() -> NodeKind {
11003    NodeKind::Decorator
11004  }
11005}
11006
11007fn get_view_for_decorator<'a>(inner: &'a swc_ast::Decorator, bump: &'a Bump) -> &'a Decorator<'a> {
11008  let node = bump.alloc(Decorator {
11009    inner,
11010    parent: Default::default(),
11011    expr: get_view_for_expr(&inner.expr, bump),
11012  });
11013  let parent: Node<'a> = (&*node).into();
11014  set_parent_for_expr(&node.expr, parent);
11015  node
11016}
11017
11018fn set_parent_for_decorator<'a>(node: &Decorator<'a>, parent: Node<'a>) {
11019  node.parent.set(parent);
11020}
11021
11022#[derive(Clone)]
11023pub struct DoWhileStmt<'a> {
11024  parent: ParentOnceCell<Node<'a>>,
11025  pub inner: &'a swc_ast::DoWhileStmt,
11026  pub test: Expr<'a>,
11027  pub body: Stmt<'a>,
11028}
11029
11030impl<'a> DoWhileStmt<'a> {
11031  pub fn parent(&self) -> Node<'a> {
11032    self.parent.get().unwrap()
11033  }
11034}
11035
11036impl<'a> SourceRanged for DoWhileStmt<'a> {
11037  fn start(&self) -> SourcePos {
11038    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11039  }
11040  fn end(&self) -> SourcePos {
11041    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11042  }
11043}
11044
11045impl<'a> From<&DoWhileStmt<'a>> for Node<'a> {
11046  fn from(node: &DoWhileStmt<'a>) -> Node<'a> {
11047    let node = unsafe { mem::transmute::<&DoWhileStmt<'a>, &'a DoWhileStmt<'a>>(node) };
11048    Node::DoWhileStmt(node)
11049  }
11050}
11051
11052impl<'a> NodeTrait<'a> for DoWhileStmt<'a> {
11053  fn parent(&self) -> Option<Node<'a>> {
11054    Some(self.parent.get().unwrap().clone())
11055  }
11056
11057  fn children(&self) -> Vec<Node<'a>> {
11058    let mut children = Vec::with_capacity(2);
11059    children.push((&self.test).into());
11060    children.push((&self.body).into());
11061    children
11062  }
11063
11064  fn as_node(&self) -> Node<'a> {
11065    self.into()
11066  }
11067
11068  fn kind(&self) -> NodeKind {
11069    NodeKind::DoWhileStmt
11070  }
11071}
11072
11073impl<'a> CastableNode<'a> for DoWhileStmt<'a> {
11074  fn to(node: &Node<'a>) -> Option<&'a Self> {
11075    if let Node::DoWhileStmt(node) = node {
11076      Some(node)
11077    } else {
11078      None
11079    }
11080  }
11081
11082  fn kind() -> NodeKind {
11083    NodeKind::DoWhileStmt
11084  }
11085}
11086
11087fn get_view_for_do_while_stmt<'a>(inner: &'a swc_ast::DoWhileStmt, bump: &'a Bump) -> &'a DoWhileStmt<'a> {
11088  let node = bump.alloc(DoWhileStmt {
11089    inner,
11090    parent: Default::default(),
11091    test: get_view_for_expr(&inner.test, bump),
11092    body: get_view_for_stmt(&inner.body, bump),
11093  });
11094  let parent: Node<'a> = (&*node).into();
11095  set_parent_for_expr(&node.test, parent);
11096  set_parent_for_stmt(&node.body, parent);
11097  node
11098}
11099
11100fn set_parent_for_do_while_stmt<'a>(node: &DoWhileStmt<'a>, parent: Node<'a>) {
11101  node.parent.set(parent);
11102}
11103
11104#[derive(Clone)]
11105pub struct EmptyStmt<'a> {
11106  parent: ParentOnceCell<Node<'a>>,
11107  pub inner: &'a swc_ast::EmptyStmt,
11108}
11109
11110impl<'a> EmptyStmt<'a> {
11111  pub fn parent(&self) -> Node<'a> {
11112    self.parent.get().unwrap()
11113  }
11114}
11115
11116impl<'a> SourceRanged for EmptyStmt<'a> {
11117  fn start(&self) -> SourcePos {
11118    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11119  }
11120  fn end(&self) -> SourcePos {
11121    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11122  }
11123}
11124
11125impl<'a> From<&EmptyStmt<'a>> for Node<'a> {
11126  fn from(node: &EmptyStmt<'a>) -> Node<'a> {
11127    let node = unsafe { mem::transmute::<&EmptyStmt<'a>, &'a EmptyStmt<'a>>(node) };
11128    Node::EmptyStmt(node)
11129  }
11130}
11131
11132impl<'a> NodeTrait<'a> for EmptyStmt<'a> {
11133  fn parent(&self) -> Option<Node<'a>> {
11134    Some(self.parent.get().unwrap().clone())
11135  }
11136
11137  fn children(&self) -> Vec<Node<'a>> {
11138    Vec::with_capacity(0)
11139  }
11140
11141  fn as_node(&self) -> Node<'a> {
11142    self.into()
11143  }
11144
11145  fn kind(&self) -> NodeKind {
11146    NodeKind::EmptyStmt
11147  }
11148}
11149
11150impl<'a> CastableNode<'a> for EmptyStmt<'a> {
11151  fn to(node: &Node<'a>) -> Option<&'a Self> {
11152    if let Node::EmptyStmt(node) = node {
11153      Some(node)
11154    } else {
11155      None
11156    }
11157  }
11158
11159  fn kind() -> NodeKind {
11160    NodeKind::EmptyStmt
11161  }
11162}
11163
11164fn get_view_for_empty_stmt<'a>(inner: &'a swc_ast::EmptyStmt, bump: &'a Bump) -> &'a EmptyStmt<'a> {
11165  let node = bump.alloc(EmptyStmt {
11166    inner,
11167    parent: Default::default(),
11168  });
11169  node
11170}
11171
11172fn set_parent_for_empty_stmt<'a>(node: &EmptyStmt<'a>, parent: Node<'a>) {
11173  node.parent.set(parent);
11174}
11175
11176/// `export * from 'mod'`
11177#[derive(Clone)]
11178pub struct ExportAll<'a> {
11179  parent: ParentOnceCell<Node<'a>>,
11180  pub inner: &'a swc_ast::ExportAll,
11181  pub src: &'a Str<'a>,
11182  pub with: Option<&'a ObjectLit<'a>>,
11183}
11184
11185impl<'a> ExportAll<'a> {
11186  pub fn parent(&self) -> Node<'a> {
11187    self.parent.get().unwrap()
11188  }
11189
11190  pub fn type_only(&self) -> bool {
11191    self.inner.type_only
11192  }
11193}
11194
11195impl<'a> SourceRanged for ExportAll<'a> {
11196  fn start(&self) -> SourcePos {
11197    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11198  }
11199  fn end(&self) -> SourcePos {
11200    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11201  }
11202}
11203
11204impl<'a> From<&ExportAll<'a>> for Node<'a> {
11205  fn from(node: &ExportAll<'a>) -> Node<'a> {
11206    let node = unsafe { mem::transmute::<&ExportAll<'a>, &'a ExportAll<'a>>(node) };
11207    Node::ExportAll(node)
11208  }
11209}
11210
11211impl<'a> NodeTrait<'a> for ExportAll<'a> {
11212  fn parent(&self) -> Option<Node<'a>> {
11213    Some(self.parent.get().unwrap().clone())
11214  }
11215
11216  fn children(&self) -> Vec<Node<'a>> {
11217    let mut children = Vec::with_capacity(1 + match &self.with { Some(_value) => 1, None => 0, });
11218    children.push(self.src.into());
11219    if let Some(child) = self.with {
11220      children.push(child.into());
11221    }
11222    children
11223  }
11224
11225  fn as_node(&self) -> Node<'a> {
11226    self.into()
11227  }
11228
11229  fn kind(&self) -> NodeKind {
11230    NodeKind::ExportAll
11231  }
11232}
11233
11234impl<'a> CastableNode<'a> for ExportAll<'a> {
11235  fn to(node: &Node<'a>) -> Option<&'a Self> {
11236    if let Node::ExportAll(node) = node {
11237      Some(node)
11238    } else {
11239      None
11240    }
11241  }
11242
11243  fn kind() -> NodeKind {
11244    NodeKind::ExportAll
11245  }
11246}
11247
11248fn get_view_for_export_all<'a>(inner: &'a swc_ast::ExportAll, bump: &'a Bump) -> &'a ExportAll<'a> {
11249  let node = bump.alloc(ExportAll {
11250    inner,
11251    parent: Default::default(),
11252    src: get_view_for_str(&inner.src, bump),
11253    with: match &inner.with {
11254      Some(value) => Some(get_view_for_object_lit(value, bump)),
11255      None => None,
11256    },
11257  });
11258  let parent: Node<'a> = (&*node).into();
11259  set_parent_for_str(&node.src, parent);
11260  if let Some(value) = &node.with {
11261    set_parent_for_object_lit(value, parent)
11262  };
11263  node
11264}
11265
11266fn set_parent_for_export_all<'a>(node: &ExportAll<'a>, parent: Node<'a>) {
11267  node.parent.set(parent);
11268}
11269
11270#[derive(Clone)]
11271pub struct ExportDecl<'a> {
11272  parent: ParentOnceCell<Node<'a>>,
11273  pub inner: &'a swc_ast::ExportDecl,
11274  pub decl: Decl<'a>,
11275}
11276
11277impl<'a> ExportDecl<'a> {
11278  pub fn parent(&self) -> Node<'a> {
11279    self.parent.get().unwrap()
11280  }
11281}
11282
11283impl<'a> SourceRanged for ExportDecl<'a> {
11284  fn start(&self) -> SourcePos {
11285    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11286  }
11287  fn end(&self) -> SourcePos {
11288    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11289  }
11290}
11291
11292impl<'a> From<&ExportDecl<'a>> for Node<'a> {
11293  fn from(node: &ExportDecl<'a>) -> Node<'a> {
11294    let node = unsafe { mem::transmute::<&ExportDecl<'a>, &'a ExportDecl<'a>>(node) };
11295    Node::ExportDecl(node)
11296  }
11297}
11298
11299impl<'a> NodeTrait<'a> for ExportDecl<'a> {
11300  fn parent(&self) -> Option<Node<'a>> {
11301    Some(self.parent.get().unwrap().clone())
11302  }
11303
11304  fn children(&self) -> Vec<Node<'a>> {
11305    let mut children = Vec::with_capacity(1);
11306    children.push((&self.decl).into());
11307    children
11308  }
11309
11310  fn as_node(&self) -> Node<'a> {
11311    self.into()
11312  }
11313
11314  fn kind(&self) -> NodeKind {
11315    NodeKind::ExportDecl
11316  }
11317}
11318
11319impl<'a> CastableNode<'a> for ExportDecl<'a> {
11320  fn to(node: &Node<'a>) -> Option<&'a Self> {
11321    if let Node::ExportDecl(node) = node {
11322      Some(node)
11323    } else {
11324      None
11325    }
11326  }
11327
11328  fn kind() -> NodeKind {
11329    NodeKind::ExportDecl
11330  }
11331}
11332
11333fn get_view_for_export_decl<'a>(inner: &'a swc_ast::ExportDecl, bump: &'a Bump) -> &'a ExportDecl<'a> {
11334  let node = bump.alloc(ExportDecl {
11335    inner,
11336    parent: Default::default(),
11337    decl: get_view_for_decl(&inner.decl, bump),
11338  });
11339  let parent: Node<'a> = (&*node).into();
11340  set_parent_for_decl(&node.decl, parent);
11341  node
11342}
11343
11344fn set_parent_for_export_decl<'a>(node: &ExportDecl<'a>, parent: Node<'a>) {
11345  node.parent.set(parent);
11346}
11347
11348#[derive(Clone)]
11349pub struct ExportDefaultDecl<'a> {
11350  parent: ParentOnceCell<Node<'a>>,
11351  pub inner: &'a swc_ast::ExportDefaultDecl,
11352  pub decl: DefaultDecl<'a>,
11353}
11354
11355impl<'a> ExportDefaultDecl<'a> {
11356  pub fn parent(&self) -> Node<'a> {
11357    self.parent.get().unwrap()
11358  }
11359}
11360
11361impl<'a> SourceRanged for ExportDefaultDecl<'a> {
11362  fn start(&self) -> SourcePos {
11363    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11364  }
11365  fn end(&self) -> SourcePos {
11366    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11367  }
11368}
11369
11370impl<'a> From<&ExportDefaultDecl<'a>> for Node<'a> {
11371  fn from(node: &ExportDefaultDecl<'a>) -> Node<'a> {
11372    let node = unsafe { mem::transmute::<&ExportDefaultDecl<'a>, &'a ExportDefaultDecl<'a>>(node) };
11373    Node::ExportDefaultDecl(node)
11374  }
11375}
11376
11377impl<'a> NodeTrait<'a> for ExportDefaultDecl<'a> {
11378  fn parent(&self) -> Option<Node<'a>> {
11379    Some(self.parent.get().unwrap().clone())
11380  }
11381
11382  fn children(&self) -> Vec<Node<'a>> {
11383    let mut children = Vec::with_capacity(1);
11384    children.push((&self.decl).into());
11385    children
11386  }
11387
11388  fn as_node(&self) -> Node<'a> {
11389    self.into()
11390  }
11391
11392  fn kind(&self) -> NodeKind {
11393    NodeKind::ExportDefaultDecl
11394  }
11395}
11396
11397impl<'a> CastableNode<'a> for ExportDefaultDecl<'a> {
11398  fn to(node: &Node<'a>) -> Option<&'a Self> {
11399    if let Node::ExportDefaultDecl(node) = node {
11400      Some(node)
11401    } else {
11402      None
11403    }
11404  }
11405
11406  fn kind() -> NodeKind {
11407    NodeKind::ExportDefaultDecl
11408  }
11409}
11410
11411fn get_view_for_export_default_decl<'a>(inner: &'a swc_ast::ExportDefaultDecl, bump: &'a Bump) -> &'a ExportDefaultDecl<'a> {
11412  let node = bump.alloc(ExportDefaultDecl {
11413    inner,
11414    parent: Default::default(),
11415    decl: get_view_for_default_decl(&inner.decl, bump),
11416  });
11417  let parent: Node<'a> = (&*node).into();
11418  set_parent_for_default_decl(&node.decl, parent);
11419  node
11420}
11421
11422fn set_parent_for_export_default_decl<'a>(node: &ExportDefaultDecl<'a>, parent: Node<'a>) {
11423  node.parent.set(parent);
11424}
11425
11426/// Default exports other than **direct** function expression or class
11427/// expression.
11428///
11429///
11430/// # Note
11431///
11432/// ```ts
11433/// export default function Foo() {
11434/// }
11435/// ```
11436///
11437/// is [`ExportDefaultDecl`] and it's hoisted.
11438///
11439/// ```ts
11440/// export default (function Foo() {
11441/// })
11442/// ```
11443///
11444/// is [`ExportDefaultExpr`] and it's not hoisted.
11445#[derive(Clone)]
11446pub struct ExportDefaultExpr<'a> {
11447  parent: ParentOnceCell<Node<'a>>,
11448  pub inner: &'a swc_ast::ExportDefaultExpr,
11449  pub expr: Expr<'a>,
11450}
11451
11452impl<'a> ExportDefaultExpr<'a> {
11453  pub fn parent(&self) -> Node<'a> {
11454    self.parent.get().unwrap()
11455  }
11456}
11457
11458impl<'a> SourceRanged for ExportDefaultExpr<'a> {
11459  fn start(&self) -> SourcePos {
11460    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11461  }
11462  fn end(&self) -> SourcePos {
11463    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11464  }
11465}
11466
11467impl<'a> From<&ExportDefaultExpr<'a>> for Node<'a> {
11468  fn from(node: &ExportDefaultExpr<'a>) -> Node<'a> {
11469    let node = unsafe { mem::transmute::<&ExportDefaultExpr<'a>, &'a ExportDefaultExpr<'a>>(node) };
11470    Node::ExportDefaultExpr(node)
11471  }
11472}
11473
11474impl<'a> NodeTrait<'a> for ExportDefaultExpr<'a> {
11475  fn parent(&self) -> Option<Node<'a>> {
11476    Some(self.parent.get().unwrap().clone())
11477  }
11478
11479  fn children(&self) -> Vec<Node<'a>> {
11480    let mut children = Vec::with_capacity(1);
11481    children.push((&self.expr).into());
11482    children
11483  }
11484
11485  fn as_node(&self) -> Node<'a> {
11486    self.into()
11487  }
11488
11489  fn kind(&self) -> NodeKind {
11490    NodeKind::ExportDefaultExpr
11491  }
11492}
11493
11494impl<'a> CastableNode<'a> for ExportDefaultExpr<'a> {
11495  fn to(node: &Node<'a>) -> Option<&'a Self> {
11496    if let Node::ExportDefaultExpr(node) = node {
11497      Some(node)
11498    } else {
11499      None
11500    }
11501  }
11502
11503  fn kind() -> NodeKind {
11504    NodeKind::ExportDefaultExpr
11505  }
11506}
11507
11508fn get_view_for_export_default_expr<'a>(inner: &'a swc_ast::ExportDefaultExpr, bump: &'a Bump) -> &'a ExportDefaultExpr<'a> {
11509  let node = bump.alloc(ExportDefaultExpr {
11510    inner,
11511    parent: Default::default(),
11512    expr: get_view_for_expr(&inner.expr, bump),
11513  });
11514  let parent: Node<'a> = (&*node).into();
11515  set_parent_for_expr(&node.expr, parent);
11516  node
11517}
11518
11519fn set_parent_for_export_default_expr<'a>(node: &ExportDefaultExpr<'a>, parent: Node<'a>) {
11520  node.parent.set(parent);
11521}
11522
11523#[derive(Clone)]
11524pub struct ExportDefaultSpecifier<'a> {
11525  parent: ParentOnceCell<&'a NamedExport<'a>>,
11526  pub inner: &'a swc_ast::ExportDefaultSpecifier,
11527  pub exported: &'a Ident<'a>,
11528}
11529
11530impl<'a> ExportDefaultSpecifier<'a> {
11531  pub fn parent(&self) -> &'a NamedExport<'a> {
11532    self.parent.get().unwrap()
11533  }
11534}
11535
11536impl<'a> SourceRanged for ExportDefaultSpecifier<'a> {
11537  fn start(&self) -> SourcePos {
11538    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11539  }
11540  fn end(&self) -> SourcePos {
11541    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11542  }
11543}
11544
11545impl<'a> From<&ExportDefaultSpecifier<'a>> for Node<'a> {
11546  fn from(node: &ExportDefaultSpecifier<'a>) -> Node<'a> {
11547    let node = unsafe { mem::transmute::<&ExportDefaultSpecifier<'a>, &'a ExportDefaultSpecifier<'a>>(node) };
11548    Node::ExportDefaultSpecifier(node)
11549  }
11550}
11551
11552impl<'a> NodeTrait<'a> for ExportDefaultSpecifier<'a> {
11553  fn parent(&self) -> Option<Node<'a>> {
11554    Some(self.parent.get().unwrap().into())
11555  }
11556
11557  fn children(&self) -> Vec<Node<'a>> {
11558    let mut children = Vec::with_capacity(1);
11559    children.push(self.exported.into());
11560    children
11561  }
11562
11563  fn as_node(&self) -> Node<'a> {
11564    self.into()
11565  }
11566
11567  fn kind(&self) -> NodeKind {
11568    NodeKind::ExportDefaultSpecifier
11569  }
11570}
11571
11572impl<'a> CastableNode<'a> for ExportDefaultSpecifier<'a> {
11573  fn to(node: &Node<'a>) -> Option<&'a Self> {
11574    if let Node::ExportDefaultSpecifier(node) = node {
11575      Some(node)
11576    } else {
11577      None
11578    }
11579  }
11580
11581  fn kind() -> NodeKind {
11582    NodeKind::ExportDefaultSpecifier
11583  }
11584}
11585
11586fn get_view_for_export_default_specifier<'a>(inner: &'a swc_ast::ExportDefaultSpecifier, bump: &'a Bump) -> &'a ExportDefaultSpecifier<'a> {
11587  let node = bump.alloc(ExportDefaultSpecifier {
11588    inner,
11589    parent: Default::default(),
11590    exported: get_view_for_ident(&inner.exported, bump),
11591  });
11592  let parent: Node<'a> = (&*node).into();
11593  set_parent_for_ident(&node.exported, parent);
11594  node
11595}
11596
11597fn set_parent_for_export_default_specifier<'a>(node: &ExportDefaultSpecifier<'a>, parent: Node<'a>) {
11598  node.parent.set(parent.expect::<NamedExport>());
11599}
11600
11601#[derive(Clone)]
11602pub struct ExportNamedSpecifier<'a> {
11603  parent: ParentOnceCell<&'a NamedExport<'a>>,
11604  pub inner: &'a swc_ast::ExportNamedSpecifier,
11605  /// `foo` in `export { foo as bar }`
11606  pub orig: ModuleExportName<'a>,
11607  /// `Some(bar)` in `export { foo as bar }`
11608  pub exported: Option<ModuleExportName<'a>>,
11609}
11610
11611impl<'a> ExportNamedSpecifier<'a> {
11612  pub fn parent(&self) -> &'a NamedExport<'a> {
11613    self.parent.get().unwrap()
11614  }
11615
11616  /// `type` in `export { type foo as bar }`
11617  pub fn is_type_only(&self) -> bool {
11618    self.inner.is_type_only
11619  }
11620}
11621
11622impl<'a> SourceRanged for ExportNamedSpecifier<'a> {
11623  fn start(&self) -> SourcePos {
11624    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11625  }
11626  fn end(&self) -> SourcePos {
11627    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11628  }
11629}
11630
11631impl<'a> From<&ExportNamedSpecifier<'a>> for Node<'a> {
11632  fn from(node: &ExportNamedSpecifier<'a>) -> Node<'a> {
11633    let node = unsafe { mem::transmute::<&ExportNamedSpecifier<'a>, &'a ExportNamedSpecifier<'a>>(node) };
11634    Node::ExportNamedSpecifier(node)
11635  }
11636}
11637
11638impl<'a> NodeTrait<'a> for ExportNamedSpecifier<'a> {
11639  fn parent(&self) -> Option<Node<'a>> {
11640    Some(self.parent.get().unwrap().into())
11641  }
11642
11643  fn children(&self) -> Vec<Node<'a>> {
11644    let mut children = Vec::with_capacity(1 + match &self.exported { Some(_value) => 1, None => 0, });
11645    children.push((&self.orig).into());
11646    if let Some(child) = self.exported.as_ref() {
11647      children.push(child.into());
11648    }
11649    children
11650  }
11651
11652  fn as_node(&self) -> Node<'a> {
11653    self.into()
11654  }
11655
11656  fn kind(&self) -> NodeKind {
11657    NodeKind::ExportNamedSpecifier
11658  }
11659}
11660
11661impl<'a> CastableNode<'a> for ExportNamedSpecifier<'a> {
11662  fn to(node: &Node<'a>) -> Option<&'a Self> {
11663    if let Node::ExportNamedSpecifier(node) = node {
11664      Some(node)
11665    } else {
11666      None
11667    }
11668  }
11669
11670  fn kind() -> NodeKind {
11671    NodeKind::ExportNamedSpecifier
11672  }
11673}
11674
11675fn get_view_for_export_named_specifier<'a>(inner: &'a swc_ast::ExportNamedSpecifier, bump: &'a Bump) -> &'a ExportNamedSpecifier<'a> {
11676  let node = bump.alloc(ExportNamedSpecifier {
11677    inner,
11678    parent: Default::default(),
11679    orig: get_view_for_module_export_name(&inner.orig, bump),
11680    exported: match &inner.exported {
11681      Some(value) => Some(get_view_for_module_export_name(value, bump)),
11682      None => None,
11683    },
11684  });
11685  let parent: Node<'a> = (&*node).into();
11686  set_parent_for_module_export_name(&node.orig, parent);
11687  if let Some(value) = &node.exported {
11688    set_parent_for_module_export_name(value, parent)
11689  };
11690  node
11691}
11692
11693fn set_parent_for_export_named_specifier<'a>(node: &ExportNamedSpecifier<'a>, parent: Node<'a>) {
11694  node.parent.set(parent.expect::<NamedExport>());
11695}
11696
11697/// `export * as foo from 'src';`
11698#[derive(Clone)]
11699pub struct ExportNamespaceSpecifier<'a> {
11700  parent: ParentOnceCell<&'a NamedExport<'a>>,
11701  pub inner: &'a swc_ast::ExportNamespaceSpecifier,
11702  pub name: ModuleExportName<'a>,
11703}
11704
11705impl<'a> ExportNamespaceSpecifier<'a> {
11706  pub fn parent(&self) -> &'a NamedExport<'a> {
11707    self.parent.get().unwrap()
11708  }
11709}
11710
11711impl<'a> SourceRanged for ExportNamespaceSpecifier<'a> {
11712  fn start(&self) -> SourcePos {
11713    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11714  }
11715  fn end(&self) -> SourcePos {
11716    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11717  }
11718}
11719
11720impl<'a> From<&ExportNamespaceSpecifier<'a>> for Node<'a> {
11721  fn from(node: &ExportNamespaceSpecifier<'a>) -> Node<'a> {
11722    let node = unsafe { mem::transmute::<&ExportNamespaceSpecifier<'a>, &'a ExportNamespaceSpecifier<'a>>(node) };
11723    Node::ExportNamespaceSpecifier(node)
11724  }
11725}
11726
11727impl<'a> NodeTrait<'a> for ExportNamespaceSpecifier<'a> {
11728  fn parent(&self) -> Option<Node<'a>> {
11729    Some(self.parent.get().unwrap().into())
11730  }
11731
11732  fn children(&self) -> Vec<Node<'a>> {
11733    let mut children = Vec::with_capacity(1);
11734    children.push((&self.name).into());
11735    children
11736  }
11737
11738  fn as_node(&self) -> Node<'a> {
11739    self.into()
11740  }
11741
11742  fn kind(&self) -> NodeKind {
11743    NodeKind::ExportNamespaceSpecifier
11744  }
11745}
11746
11747impl<'a> CastableNode<'a> for ExportNamespaceSpecifier<'a> {
11748  fn to(node: &Node<'a>) -> Option<&'a Self> {
11749    if let Node::ExportNamespaceSpecifier(node) = node {
11750      Some(node)
11751    } else {
11752      None
11753    }
11754  }
11755
11756  fn kind() -> NodeKind {
11757    NodeKind::ExportNamespaceSpecifier
11758  }
11759}
11760
11761fn get_view_for_export_namespace_specifier<'a>(inner: &'a swc_ast::ExportNamespaceSpecifier, bump: &'a Bump) -> &'a ExportNamespaceSpecifier<'a> {
11762  let node = bump.alloc(ExportNamespaceSpecifier {
11763    inner,
11764    parent: Default::default(),
11765    name: get_view_for_module_export_name(&inner.name, bump),
11766  });
11767  let parent: Node<'a> = (&*node).into();
11768  set_parent_for_module_export_name(&node.name, parent);
11769  node
11770}
11771
11772fn set_parent_for_export_namespace_specifier<'a>(node: &ExportNamespaceSpecifier<'a>, parent: Node<'a>) {
11773  node.parent.set(parent.expect::<NamedExport>());
11774}
11775
11776#[derive(Clone)]
11777pub struct ExprOrSpread<'a> {
11778  parent: ParentOnceCell<Node<'a>>,
11779  pub inner: &'a swc_ast::ExprOrSpread,
11780  pub expr: Expr<'a>,
11781}
11782
11783impl<'a> ExprOrSpread<'a> {
11784  pub fn parent(&self) -> Node<'a> {
11785    self.parent.get().unwrap()
11786  }
11787
11788  pub fn spread(&self) -> &Option<swc_common::Span> {
11789    &self.inner.spread
11790  }
11791}
11792
11793impl<'a> SourceRanged for ExprOrSpread<'a> {
11794  fn start(&self) -> SourcePos {
11795    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11796  }
11797  fn end(&self) -> SourcePos {
11798    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11799  }
11800}
11801
11802impl<'a> From<&ExprOrSpread<'a>> for Node<'a> {
11803  fn from(node: &ExprOrSpread<'a>) -> Node<'a> {
11804    let node = unsafe { mem::transmute::<&ExprOrSpread<'a>, &'a ExprOrSpread<'a>>(node) };
11805    Node::ExprOrSpread(node)
11806  }
11807}
11808
11809impl<'a> NodeTrait<'a> for ExprOrSpread<'a> {
11810  fn parent(&self) -> Option<Node<'a>> {
11811    Some(self.parent.get().unwrap().clone())
11812  }
11813
11814  fn children(&self) -> Vec<Node<'a>> {
11815    let mut children = Vec::with_capacity(1);
11816    children.push((&self.expr).into());
11817    children
11818  }
11819
11820  fn as_node(&self) -> Node<'a> {
11821    self.into()
11822  }
11823
11824  fn kind(&self) -> NodeKind {
11825    NodeKind::ExprOrSpread
11826  }
11827}
11828
11829impl<'a> CastableNode<'a> for ExprOrSpread<'a> {
11830  fn to(node: &Node<'a>) -> Option<&'a Self> {
11831    if let Node::ExprOrSpread(node) = node {
11832      Some(node)
11833    } else {
11834      None
11835    }
11836  }
11837
11838  fn kind() -> NodeKind {
11839    NodeKind::ExprOrSpread
11840  }
11841}
11842
11843fn get_view_for_expr_or_spread<'a>(inner: &'a swc_ast::ExprOrSpread, bump: &'a Bump) -> &'a ExprOrSpread<'a> {
11844  let node = bump.alloc(ExprOrSpread {
11845    inner,
11846    parent: Default::default(),
11847    expr: get_view_for_expr(&inner.expr, bump),
11848  });
11849  let parent: Node<'a> = (&*node).into();
11850  set_parent_for_expr(&node.expr, parent);
11851  node
11852}
11853
11854fn set_parent_for_expr_or_spread<'a>(node: &ExprOrSpread<'a>, parent: Node<'a>) {
11855  node.parent.set(parent);
11856}
11857
11858#[derive(Clone)]
11859pub struct ExprStmt<'a> {
11860  parent: ParentOnceCell<Node<'a>>,
11861  pub inner: &'a swc_ast::ExprStmt,
11862  pub expr: Expr<'a>,
11863}
11864
11865impl<'a> ExprStmt<'a> {
11866  pub fn parent(&self) -> Node<'a> {
11867    self.parent.get().unwrap()
11868  }
11869}
11870
11871impl<'a> SourceRanged for ExprStmt<'a> {
11872  fn start(&self) -> SourcePos {
11873    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11874  }
11875  fn end(&self) -> SourcePos {
11876    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11877  }
11878}
11879
11880impl<'a> From<&ExprStmt<'a>> for Node<'a> {
11881  fn from(node: &ExprStmt<'a>) -> Node<'a> {
11882    let node = unsafe { mem::transmute::<&ExprStmt<'a>, &'a ExprStmt<'a>>(node) };
11883    Node::ExprStmt(node)
11884  }
11885}
11886
11887impl<'a> NodeTrait<'a> for ExprStmt<'a> {
11888  fn parent(&self) -> Option<Node<'a>> {
11889    Some(self.parent.get().unwrap().clone())
11890  }
11891
11892  fn children(&self) -> Vec<Node<'a>> {
11893    let mut children = Vec::with_capacity(1);
11894    children.push((&self.expr).into());
11895    children
11896  }
11897
11898  fn as_node(&self) -> Node<'a> {
11899    self.into()
11900  }
11901
11902  fn kind(&self) -> NodeKind {
11903    NodeKind::ExprStmt
11904  }
11905}
11906
11907impl<'a> CastableNode<'a> for ExprStmt<'a> {
11908  fn to(node: &Node<'a>) -> Option<&'a Self> {
11909    if let Node::ExprStmt(node) = node {
11910      Some(node)
11911    } else {
11912      None
11913    }
11914  }
11915
11916  fn kind() -> NodeKind {
11917    NodeKind::ExprStmt
11918  }
11919}
11920
11921fn get_view_for_expr_stmt<'a>(inner: &'a swc_ast::ExprStmt, bump: &'a Bump) -> &'a ExprStmt<'a> {
11922  let node = bump.alloc(ExprStmt {
11923    inner,
11924    parent: Default::default(),
11925    expr: get_view_for_expr(&inner.expr, bump),
11926  });
11927  let parent: Node<'a> = (&*node).into();
11928  set_parent_for_expr(&node.expr, parent);
11929  node
11930}
11931
11932fn set_parent_for_expr_stmt<'a>(node: &ExprStmt<'a>, parent: Node<'a>) {
11933  node.parent.set(parent);
11934}
11935
11936#[derive(Clone)]
11937pub struct FnDecl<'a> {
11938  parent: ParentOnceCell<Node<'a>>,
11939  pub inner: &'a swc_ast::FnDecl,
11940  pub ident: &'a Ident<'a>,
11941  pub function: &'a Function<'a>,
11942}
11943
11944impl<'a> FnDecl<'a> {
11945  pub fn parent(&self) -> Node<'a> {
11946    self.parent.get().unwrap()
11947  }
11948
11949  pub fn declare(&self) -> bool {
11950    self.inner.declare
11951  }
11952}
11953
11954impl<'a> SourceRanged for FnDecl<'a> {
11955  fn start(&self) -> SourcePos {
11956    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11957  }
11958  fn end(&self) -> SourcePos {
11959    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11960  }
11961}
11962
11963impl<'a> From<&FnDecl<'a>> for Node<'a> {
11964  fn from(node: &FnDecl<'a>) -> Node<'a> {
11965    let node = unsafe { mem::transmute::<&FnDecl<'a>, &'a FnDecl<'a>>(node) };
11966    Node::FnDecl(node)
11967  }
11968}
11969
11970impl<'a> NodeTrait<'a> for FnDecl<'a> {
11971  fn parent(&self) -> Option<Node<'a>> {
11972    Some(self.parent.get().unwrap().clone())
11973  }
11974
11975  fn children(&self) -> Vec<Node<'a>> {
11976    let mut children = Vec::with_capacity(2);
11977    children.push(self.ident.into());
11978    children.push(self.function.into());
11979    children
11980  }
11981
11982  fn as_node(&self) -> Node<'a> {
11983    self.into()
11984  }
11985
11986  fn kind(&self) -> NodeKind {
11987    NodeKind::FnDecl
11988  }
11989}
11990
11991impl<'a> CastableNode<'a> for FnDecl<'a> {
11992  fn to(node: &Node<'a>) -> Option<&'a Self> {
11993    if let Node::FnDecl(node) = node {
11994      Some(node)
11995    } else {
11996      None
11997    }
11998  }
11999
12000  fn kind() -> NodeKind {
12001    NodeKind::FnDecl
12002  }
12003}
12004
12005fn get_view_for_fn_decl<'a>(inner: &'a swc_ast::FnDecl, bump: &'a Bump) -> &'a FnDecl<'a> {
12006  let node = bump.alloc(FnDecl {
12007    inner,
12008    parent: Default::default(),
12009    ident: get_view_for_ident(&inner.ident, bump),
12010    function: get_view_for_function(&inner.function, bump),
12011  });
12012  let parent: Node<'a> = (&*node).into();
12013  set_parent_for_ident(&node.ident, parent);
12014  set_parent_for_function(&node.function, parent);
12015  node
12016}
12017
12018fn set_parent_for_fn_decl<'a>(node: &FnDecl<'a>, parent: Node<'a>) {
12019  node.parent.set(parent);
12020}
12021
12022/// Function expression.
12023#[derive(Clone)]
12024pub struct FnExpr<'a> {
12025  parent: ParentOnceCell<Node<'a>>,
12026  pub inner: &'a swc_ast::FnExpr,
12027  pub ident: Option<&'a Ident<'a>>,
12028  pub function: &'a Function<'a>,
12029}
12030
12031impl<'a> FnExpr<'a> {
12032  pub fn parent(&self) -> Node<'a> {
12033    self.parent.get().unwrap()
12034  }
12035}
12036
12037impl<'a> SourceRanged for FnExpr<'a> {
12038  fn start(&self) -> SourcePos {
12039    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12040  }
12041  fn end(&self) -> SourcePos {
12042    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12043  }
12044}
12045
12046impl<'a> From<&FnExpr<'a>> for Node<'a> {
12047  fn from(node: &FnExpr<'a>) -> Node<'a> {
12048    let node = unsafe { mem::transmute::<&FnExpr<'a>, &'a FnExpr<'a>>(node) };
12049    Node::FnExpr(node)
12050  }
12051}
12052
12053impl<'a> NodeTrait<'a> for FnExpr<'a> {
12054  fn parent(&self) -> Option<Node<'a>> {
12055    Some(self.parent.get().unwrap().clone())
12056  }
12057
12058  fn children(&self) -> Vec<Node<'a>> {
12059    let mut children = Vec::with_capacity(1 + match &self.ident { Some(_value) => 1, None => 0, });
12060    if let Some(child) = self.ident {
12061      children.push(child.into());
12062    }
12063    children.push(self.function.into());
12064    children
12065  }
12066
12067  fn as_node(&self) -> Node<'a> {
12068    self.into()
12069  }
12070
12071  fn kind(&self) -> NodeKind {
12072    NodeKind::FnExpr
12073  }
12074}
12075
12076impl<'a> CastableNode<'a> for FnExpr<'a> {
12077  fn to(node: &Node<'a>) -> Option<&'a Self> {
12078    if let Node::FnExpr(node) = node {
12079      Some(node)
12080    } else {
12081      None
12082    }
12083  }
12084
12085  fn kind() -> NodeKind {
12086    NodeKind::FnExpr
12087  }
12088}
12089
12090fn get_view_for_fn_expr<'a>(inner: &'a swc_ast::FnExpr, bump: &'a Bump) -> &'a FnExpr<'a> {
12091  let node = bump.alloc(FnExpr {
12092    inner,
12093    parent: Default::default(),
12094    ident: match &inner.ident {
12095      Some(value) => Some(get_view_for_ident(value, bump)),
12096      None => None,
12097    },
12098    function: get_view_for_function(&inner.function, bump),
12099  });
12100  let parent: Node<'a> = (&*node).into();
12101  if let Some(value) = &node.ident {
12102    set_parent_for_ident(value, parent)
12103  };
12104  set_parent_for_function(&node.function, parent);
12105  node
12106}
12107
12108fn set_parent_for_fn_expr<'a>(node: &FnExpr<'a>, parent: Node<'a>) {
12109  node.parent.set(parent);
12110}
12111
12112#[derive(Clone)]
12113pub struct ForInStmt<'a> {
12114  parent: ParentOnceCell<Node<'a>>,
12115  pub inner: &'a swc_ast::ForInStmt,
12116  pub left: ForHead<'a>,
12117  pub right: Expr<'a>,
12118  pub body: Stmt<'a>,
12119}
12120
12121impl<'a> ForInStmt<'a> {
12122  pub fn parent(&self) -> Node<'a> {
12123    self.parent.get().unwrap()
12124  }
12125}
12126
12127impl<'a> SourceRanged for ForInStmt<'a> {
12128  fn start(&self) -> SourcePos {
12129    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12130  }
12131  fn end(&self) -> SourcePos {
12132    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12133  }
12134}
12135
12136impl<'a> From<&ForInStmt<'a>> for Node<'a> {
12137  fn from(node: &ForInStmt<'a>) -> Node<'a> {
12138    let node = unsafe { mem::transmute::<&ForInStmt<'a>, &'a ForInStmt<'a>>(node) };
12139    Node::ForInStmt(node)
12140  }
12141}
12142
12143impl<'a> NodeTrait<'a> for ForInStmt<'a> {
12144  fn parent(&self) -> Option<Node<'a>> {
12145    Some(self.parent.get().unwrap().clone())
12146  }
12147
12148  fn children(&self) -> Vec<Node<'a>> {
12149    let mut children = Vec::with_capacity(3);
12150    children.push((&self.left).into());
12151    children.push((&self.right).into());
12152    children.push((&self.body).into());
12153    children
12154  }
12155
12156  fn as_node(&self) -> Node<'a> {
12157    self.into()
12158  }
12159
12160  fn kind(&self) -> NodeKind {
12161    NodeKind::ForInStmt
12162  }
12163}
12164
12165impl<'a> CastableNode<'a> for ForInStmt<'a> {
12166  fn to(node: &Node<'a>) -> Option<&'a Self> {
12167    if let Node::ForInStmt(node) = node {
12168      Some(node)
12169    } else {
12170      None
12171    }
12172  }
12173
12174  fn kind() -> NodeKind {
12175    NodeKind::ForInStmt
12176  }
12177}
12178
12179fn get_view_for_for_in_stmt<'a>(inner: &'a swc_ast::ForInStmt, bump: &'a Bump) -> &'a ForInStmt<'a> {
12180  let node = bump.alloc(ForInStmt {
12181    inner,
12182    parent: Default::default(),
12183    left: get_view_for_for_head(&inner.left, bump),
12184    right: get_view_for_expr(&inner.right, bump),
12185    body: get_view_for_stmt(&inner.body, bump),
12186  });
12187  let parent: Node<'a> = (&*node).into();
12188  set_parent_for_for_head(&node.left, parent);
12189  set_parent_for_expr(&node.right, parent);
12190  set_parent_for_stmt(&node.body, parent);
12191  node
12192}
12193
12194fn set_parent_for_for_in_stmt<'a>(node: &ForInStmt<'a>, parent: Node<'a>) {
12195  node.parent.set(parent);
12196}
12197
12198#[derive(Clone)]
12199pub struct ForOfStmt<'a> {
12200  parent: ParentOnceCell<Node<'a>>,
12201  pub inner: &'a swc_ast::ForOfStmt,
12202  pub left: ForHead<'a>,
12203  pub right: Expr<'a>,
12204  pub body: Stmt<'a>,
12205}
12206
12207impl<'a> ForOfStmt<'a> {
12208  pub fn parent(&self) -> Node<'a> {
12209    self.parent.get().unwrap()
12210  }
12211
12212  /// Span of the await token.
12213  ///
12214  /// es2018
12215  ///
12216  /// for-await-of statements, e.g., `for await (const x of xs) {`
12217  pub fn is_await(&self) -> bool {
12218    self.inner.is_await
12219  }
12220}
12221
12222impl<'a> SourceRanged for ForOfStmt<'a> {
12223  fn start(&self) -> SourcePos {
12224    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12225  }
12226  fn end(&self) -> SourcePos {
12227    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12228  }
12229}
12230
12231impl<'a> From<&ForOfStmt<'a>> for Node<'a> {
12232  fn from(node: &ForOfStmt<'a>) -> Node<'a> {
12233    let node = unsafe { mem::transmute::<&ForOfStmt<'a>, &'a ForOfStmt<'a>>(node) };
12234    Node::ForOfStmt(node)
12235  }
12236}
12237
12238impl<'a> NodeTrait<'a> for ForOfStmt<'a> {
12239  fn parent(&self) -> Option<Node<'a>> {
12240    Some(self.parent.get().unwrap().clone())
12241  }
12242
12243  fn children(&self) -> Vec<Node<'a>> {
12244    let mut children = Vec::with_capacity(3);
12245    children.push((&self.left).into());
12246    children.push((&self.right).into());
12247    children.push((&self.body).into());
12248    children
12249  }
12250
12251  fn as_node(&self) -> Node<'a> {
12252    self.into()
12253  }
12254
12255  fn kind(&self) -> NodeKind {
12256    NodeKind::ForOfStmt
12257  }
12258}
12259
12260impl<'a> CastableNode<'a> for ForOfStmt<'a> {
12261  fn to(node: &Node<'a>) -> Option<&'a Self> {
12262    if let Node::ForOfStmt(node) = node {
12263      Some(node)
12264    } else {
12265      None
12266    }
12267  }
12268
12269  fn kind() -> NodeKind {
12270    NodeKind::ForOfStmt
12271  }
12272}
12273
12274fn get_view_for_for_of_stmt<'a>(inner: &'a swc_ast::ForOfStmt, bump: &'a Bump) -> &'a ForOfStmt<'a> {
12275  let node = bump.alloc(ForOfStmt {
12276    inner,
12277    parent: Default::default(),
12278    left: get_view_for_for_head(&inner.left, bump),
12279    right: get_view_for_expr(&inner.right, bump),
12280    body: get_view_for_stmt(&inner.body, bump),
12281  });
12282  let parent: Node<'a> = (&*node).into();
12283  set_parent_for_for_head(&node.left, parent);
12284  set_parent_for_expr(&node.right, parent);
12285  set_parent_for_stmt(&node.body, parent);
12286  node
12287}
12288
12289fn set_parent_for_for_of_stmt<'a>(node: &ForOfStmt<'a>, parent: Node<'a>) {
12290  node.parent.set(parent);
12291}
12292
12293#[derive(Clone)]
12294pub struct ForStmt<'a> {
12295  parent: ParentOnceCell<Node<'a>>,
12296  pub inner: &'a swc_ast::ForStmt,
12297  pub init: Option<VarDeclOrExpr<'a>>,
12298  pub test: Option<Expr<'a>>,
12299  pub update: Option<Expr<'a>>,
12300  pub body: Stmt<'a>,
12301}
12302
12303impl<'a> ForStmt<'a> {
12304  pub fn parent(&self) -> Node<'a> {
12305    self.parent.get().unwrap()
12306  }
12307}
12308
12309impl<'a> SourceRanged for ForStmt<'a> {
12310  fn start(&self) -> SourcePos {
12311    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12312  }
12313  fn end(&self) -> SourcePos {
12314    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12315  }
12316}
12317
12318impl<'a> From<&ForStmt<'a>> for Node<'a> {
12319  fn from(node: &ForStmt<'a>) -> Node<'a> {
12320    let node = unsafe { mem::transmute::<&ForStmt<'a>, &'a ForStmt<'a>>(node) };
12321    Node::ForStmt(node)
12322  }
12323}
12324
12325impl<'a> NodeTrait<'a> for ForStmt<'a> {
12326  fn parent(&self) -> Option<Node<'a>> {
12327    Some(self.parent.get().unwrap().clone())
12328  }
12329
12330  fn children(&self) -> Vec<Node<'a>> {
12331    let mut children = Vec::with_capacity(1 + match &self.init { Some(_value) => 1, None => 0, } + match &self.test { Some(_value) => 1, None => 0, } + match &self.update { Some(_value) => 1, None => 0, });
12332    if let Some(child) = self.init.as_ref() {
12333      children.push(child.into());
12334    }
12335    if let Some(child) = self.test.as_ref() {
12336      children.push(child.into());
12337    }
12338    if let Some(child) = self.update.as_ref() {
12339      children.push(child.into());
12340    }
12341    children.push((&self.body).into());
12342    children
12343  }
12344
12345  fn as_node(&self) -> Node<'a> {
12346    self.into()
12347  }
12348
12349  fn kind(&self) -> NodeKind {
12350    NodeKind::ForStmt
12351  }
12352}
12353
12354impl<'a> CastableNode<'a> for ForStmt<'a> {
12355  fn to(node: &Node<'a>) -> Option<&'a Self> {
12356    if let Node::ForStmt(node) = node {
12357      Some(node)
12358    } else {
12359      None
12360    }
12361  }
12362
12363  fn kind() -> NodeKind {
12364    NodeKind::ForStmt
12365  }
12366}
12367
12368fn get_view_for_for_stmt<'a>(inner: &'a swc_ast::ForStmt, bump: &'a Bump) -> &'a ForStmt<'a> {
12369  let node = bump.alloc(ForStmt {
12370    inner,
12371    parent: Default::default(),
12372    init: match &inner.init {
12373      Some(value) => Some(get_view_for_var_decl_or_expr(value, bump)),
12374      None => None,
12375    },
12376    test: match &inner.test {
12377      Some(value) => Some(get_view_for_expr(value, bump)),
12378      None => None,
12379    },
12380    update: match &inner.update {
12381      Some(value) => Some(get_view_for_expr(value, bump)),
12382      None => None,
12383    },
12384    body: get_view_for_stmt(&inner.body, bump),
12385  });
12386  let parent: Node<'a> = (&*node).into();
12387  if let Some(value) = &node.init {
12388    set_parent_for_var_decl_or_expr(value, parent)
12389  };
12390  if let Some(value) = &node.test {
12391    set_parent_for_expr(value, parent)
12392  };
12393  if let Some(value) = &node.update {
12394    set_parent_for_expr(value, parent)
12395  };
12396  set_parent_for_stmt(&node.body, parent);
12397  node
12398}
12399
12400fn set_parent_for_for_stmt<'a>(node: &ForStmt<'a>, parent: Node<'a>) {
12401  node.parent.set(parent);
12402}
12403
12404/// Common parts of function and method.
12405#[derive(Clone)]
12406pub struct Function<'a> {
12407  parent: ParentOnceCell<Node<'a>>,
12408  pub inner: &'a swc_ast::Function,
12409  pub params: &'a [&'a Param<'a>],
12410  pub decorators: &'a [&'a Decorator<'a>],
12411  pub body: Option<&'a BlockStmt<'a>>,
12412  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
12413  pub return_type: Option<&'a TsTypeAnn<'a>>,
12414}
12415
12416impl<'a> Function<'a> {
12417  pub fn parent(&self) -> Node<'a> {
12418    self.parent.get().unwrap()
12419  }
12420
12421  pub fn ctxt(&self) -> swc_common::SyntaxContext {
12422    self.inner.ctxt
12423  }
12424
12425  /// if it's a generator.
12426  pub fn is_generator(&self) -> bool {
12427    self.inner.is_generator
12428  }
12429
12430  /// if it's an async function.
12431  pub fn is_async(&self) -> bool {
12432    self.inner.is_async
12433  }
12434}
12435
12436impl<'a> SourceRanged for Function<'a> {
12437  fn start(&self) -> SourcePos {
12438    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12439  }
12440  fn end(&self) -> SourcePos {
12441    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12442  }
12443}
12444
12445impl<'a> From<&Function<'a>> for Node<'a> {
12446  fn from(node: &Function<'a>) -> Node<'a> {
12447    let node = unsafe { mem::transmute::<&Function<'a>, &'a Function<'a>>(node) };
12448    Node::Function(node)
12449  }
12450}
12451
12452impl<'a> NodeTrait<'a> for Function<'a> {
12453  fn parent(&self) -> Option<Node<'a>> {
12454    Some(self.parent.get().unwrap().clone())
12455  }
12456
12457  fn children(&self) -> Vec<Node<'a>> {
12458    let mut children = Vec::with_capacity(self.params.len() + self.decorators.len() + match &self.body { Some(_value) => 1, None => 0, } + match &self.type_params { Some(_value) => 1, None => 0, } + match &self.return_type { Some(_value) => 1, None => 0, });
12459    for child in self.params.iter() {
12460      children.push((*child).into());
12461    }
12462    for child in self.decorators.iter() {
12463      children.push((*child).into());
12464    }
12465    if let Some(child) = self.body {
12466      children.push(child.into());
12467    }
12468    if let Some(child) = self.type_params {
12469      children.push(child.into());
12470    }
12471    if let Some(child) = self.return_type {
12472      children.push(child.into());
12473    }
12474    children
12475  }
12476
12477  fn as_node(&self) -> Node<'a> {
12478    self.into()
12479  }
12480
12481  fn kind(&self) -> NodeKind {
12482    NodeKind::Function
12483  }
12484}
12485
12486impl<'a> CastableNode<'a> for Function<'a> {
12487  fn to(node: &Node<'a>) -> Option<&'a Self> {
12488    if let Node::Function(node) = node {
12489      Some(node)
12490    } else {
12491      None
12492    }
12493  }
12494
12495  fn kind() -> NodeKind {
12496    NodeKind::Function
12497  }
12498}
12499
12500fn get_view_for_function<'a>(inner: &'a swc_ast::Function, bump: &'a Bump) -> &'a Function<'a> {
12501  let node = bump.alloc(Function {
12502    inner,
12503    parent: Default::default(),
12504    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_param(value, bump))); vec }),
12505    decorators: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.decorators.len(), bump);vec.extend(inner.decorators.iter().map(|value| get_view_for_decorator(value, bump))); vec }),
12506    body: match &inner.body {
12507      Some(value) => Some(get_view_for_block_stmt(value, bump)),
12508      None => None,
12509    },
12510    type_params: match &inner.type_params {
12511      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
12512      None => None,
12513    },
12514    return_type: match &inner.return_type {
12515      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
12516      None => None,
12517    },
12518  });
12519  let parent: Node<'a> = (&*node).into();
12520  for value in node.params.iter() {
12521    set_parent_for_param(value, parent)
12522  }
12523  for value in node.decorators.iter() {
12524    set_parent_for_decorator(value, parent)
12525  }
12526  if let Some(value) = &node.body {
12527    set_parent_for_block_stmt(value, parent)
12528  };
12529  if let Some(value) = &node.type_params {
12530    set_parent_for_ts_type_param_decl(value, parent)
12531  };
12532  if let Some(value) = &node.return_type {
12533    set_parent_for_ts_type_ann(value, parent)
12534  };
12535  node
12536}
12537
12538fn set_parent_for_function<'a>(node: &Function<'a>, parent: Node<'a>) {
12539  node.parent.set(parent);
12540}
12541
12542#[derive(Clone)]
12543pub struct GetterProp<'a> {
12544  parent: ParentOnceCell<&'a ObjectLit<'a>>,
12545  pub inner: &'a swc_ast::GetterProp,
12546  pub key: PropName<'a>,
12547  pub type_ann: Option<&'a TsTypeAnn<'a>>,
12548  pub body: Option<&'a BlockStmt<'a>>,
12549}
12550
12551impl<'a> GetterProp<'a> {
12552  pub fn parent(&self) -> &'a ObjectLit<'a> {
12553    self.parent.get().unwrap()
12554  }
12555}
12556
12557impl<'a> SourceRanged for GetterProp<'a> {
12558  fn start(&self) -> SourcePos {
12559    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12560  }
12561  fn end(&self) -> SourcePos {
12562    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12563  }
12564}
12565
12566impl<'a> From<&GetterProp<'a>> for Node<'a> {
12567  fn from(node: &GetterProp<'a>) -> Node<'a> {
12568    let node = unsafe { mem::transmute::<&GetterProp<'a>, &'a GetterProp<'a>>(node) };
12569    Node::GetterProp(node)
12570  }
12571}
12572
12573impl<'a> NodeTrait<'a> for GetterProp<'a> {
12574  fn parent(&self) -> Option<Node<'a>> {
12575    Some(self.parent.get().unwrap().into())
12576  }
12577
12578  fn children(&self) -> Vec<Node<'a>> {
12579    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, } + match &self.body { Some(_value) => 1, None => 0, });
12580    children.push((&self.key).into());
12581    if let Some(child) = self.type_ann {
12582      children.push(child.into());
12583    }
12584    if let Some(child) = self.body {
12585      children.push(child.into());
12586    }
12587    children
12588  }
12589
12590  fn as_node(&self) -> Node<'a> {
12591    self.into()
12592  }
12593
12594  fn kind(&self) -> NodeKind {
12595    NodeKind::GetterProp
12596  }
12597}
12598
12599impl<'a> CastableNode<'a> for GetterProp<'a> {
12600  fn to(node: &Node<'a>) -> Option<&'a Self> {
12601    if let Node::GetterProp(node) = node {
12602      Some(node)
12603    } else {
12604      None
12605    }
12606  }
12607
12608  fn kind() -> NodeKind {
12609    NodeKind::GetterProp
12610  }
12611}
12612
12613fn get_view_for_getter_prop<'a>(inner: &'a swc_ast::GetterProp, bump: &'a Bump) -> &'a GetterProp<'a> {
12614  let node = bump.alloc(GetterProp {
12615    inner,
12616    parent: Default::default(),
12617    key: get_view_for_prop_name(&inner.key, bump),
12618    type_ann: match &inner.type_ann {
12619      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
12620      None => None,
12621    },
12622    body: match &inner.body {
12623      Some(value) => Some(get_view_for_block_stmt(value, bump)),
12624      None => None,
12625    },
12626  });
12627  let parent: Node<'a> = (&*node).into();
12628  set_parent_for_prop_name(&node.key, parent);
12629  if let Some(value) = &node.type_ann {
12630    set_parent_for_ts_type_ann(value, parent)
12631  };
12632  if let Some(value) = &node.body {
12633    set_parent_for_block_stmt(value, parent)
12634  };
12635  node
12636}
12637
12638fn set_parent_for_getter_prop<'a>(node: &GetterProp<'a>, parent: Node<'a>) {
12639  node.parent.set(parent.expect::<ObjectLit>());
12640}
12641
12642/// A complete identifier with span.
12643///
12644/// Identifier of swc consists of two parts. The first one is symbol, which is
12645/// stored using an interned string, [Atom] . The second
12646/// one is [SyntaxContext][swc_common::SyntaxContext], which can be
12647/// used to distinguish identifier with same symbol.
12648///
12649/// Let me explain this with an example.
12650///
12651/// ```ts
12652/// let a = 5
12653/// {
12654///     let a = 3;
12655/// }
12656/// ```
12657/// In the code above, there are two variables with the symbol a.
12658///
12659///
12660/// Other compilers typically uses type like `Scope`, and store them nested, but
12661/// in rust, type like `Scope`  requires [Arc<Mutex<Scope>>] so swc uses
12662/// different approach. Instead of passing scopes, swc annotates two variables
12663/// with different tag, which is named
12664/// [SyntaxContext]. The notation for the syntax
12665/// context is #n where n is a number. e.g. `foo#1`
12666///
12667/// For the example above, after applying resolver pass, it becomes.
12668///
12669/// ```ts
12670/// let a#1 = 5
12671/// {
12672///     let a#2 = 3;
12673/// }
12674/// ```
12675///
12676/// Thanks to the `tag` we attached, we can now distinguish them.
12677///
12678/// ([Atom], [SyntaxContext])
12679///
12680/// See [Id], which is a type alias for this.
12681///
12682/// This can be used to store all variables in a module to single hash map.
12683///
12684/// # Comparison
12685///
12686/// While comparing two identifiers, you can use `.to_id()`.
12687///
12688/// # HashMap
12689///
12690/// There's a type named [Id] which only contains minimal information to
12691/// distinguish identifiers.
12692#[derive(Clone)]
12693pub struct Ident<'a> {
12694  parent: ParentOnceCell<Node<'a>>,
12695  pub inner: &'a swc_ast::Ident,
12696}
12697
12698impl<'a> Ident<'a> {
12699  pub fn parent(&self) -> Node<'a> {
12700    self.parent.get().unwrap()
12701  }
12702
12703  pub fn ctxt(&self) -> swc_common::SyntaxContext {
12704    self.inner.ctxt
12705  }
12706
12707  pub fn sym(&self) -> &swc_atoms::Atom {
12708    &self.inner.sym
12709  }
12710
12711  /// TypeScript only. Used in case of an optional parameter.
12712  pub fn optional(&self) -> bool {
12713    self.inner.optional
12714  }
12715}
12716
12717impl<'a> SourceRanged for Ident<'a> {
12718  fn start(&self) -> SourcePos {
12719    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12720  }
12721  fn end(&self) -> SourcePos {
12722    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12723  }
12724}
12725
12726impl<'a> From<&Ident<'a>> for Node<'a> {
12727  fn from(node: &Ident<'a>) -> Node<'a> {
12728    let node = unsafe { mem::transmute::<&Ident<'a>, &'a Ident<'a>>(node) };
12729    Node::Ident(node)
12730  }
12731}
12732
12733impl<'a> NodeTrait<'a> for Ident<'a> {
12734  fn parent(&self) -> Option<Node<'a>> {
12735    Some(self.parent.get().unwrap().clone())
12736  }
12737
12738  fn children(&self) -> Vec<Node<'a>> {
12739    Vec::with_capacity(0)
12740  }
12741
12742  fn as_node(&self) -> Node<'a> {
12743    self.into()
12744  }
12745
12746  fn kind(&self) -> NodeKind {
12747    NodeKind::Ident
12748  }
12749}
12750
12751impl<'a> CastableNode<'a> for Ident<'a> {
12752  fn to(node: &Node<'a>) -> Option<&'a Self> {
12753    if let Node::Ident(node) = node {
12754      Some(node)
12755    } else {
12756      None
12757    }
12758  }
12759
12760  fn kind() -> NodeKind {
12761    NodeKind::Ident
12762  }
12763}
12764
12765fn get_view_for_ident<'a>(inner: &'a swc_ast::Ident, bump: &'a Bump) -> &'a Ident<'a> {
12766  let node = bump.alloc(Ident {
12767    inner,
12768    parent: Default::default(),
12769  });
12770  node
12771}
12772
12773fn set_parent_for_ident<'a>(node: &Ident<'a>, parent: Node<'a>) {
12774  node.parent.set(parent);
12775}
12776
12777#[derive(Clone)]
12778pub struct IdentName<'a> {
12779  parent: ParentOnceCell<Node<'a>>,
12780  pub inner: &'a swc_ast::IdentName,
12781}
12782
12783impl<'a> IdentName<'a> {
12784  pub fn parent(&self) -> Node<'a> {
12785    self.parent.get().unwrap()
12786  }
12787
12788  pub fn sym(&self) -> &swc_atoms::Atom {
12789    &self.inner.sym
12790  }
12791}
12792
12793impl<'a> SourceRanged for IdentName<'a> {
12794  fn start(&self) -> SourcePos {
12795    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12796  }
12797  fn end(&self) -> SourcePos {
12798    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12799  }
12800}
12801
12802impl<'a> From<&IdentName<'a>> for Node<'a> {
12803  fn from(node: &IdentName<'a>) -> Node<'a> {
12804    let node = unsafe { mem::transmute::<&IdentName<'a>, &'a IdentName<'a>>(node) };
12805    Node::IdentName(node)
12806  }
12807}
12808
12809impl<'a> NodeTrait<'a> for IdentName<'a> {
12810  fn parent(&self) -> Option<Node<'a>> {
12811    Some(self.parent.get().unwrap().clone())
12812  }
12813
12814  fn children(&self) -> Vec<Node<'a>> {
12815    Vec::with_capacity(0)
12816  }
12817
12818  fn as_node(&self) -> Node<'a> {
12819    self.into()
12820  }
12821
12822  fn kind(&self) -> NodeKind {
12823    NodeKind::IdentName
12824  }
12825}
12826
12827impl<'a> CastableNode<'a> for IdentName<'a> {
12828  fn to(node: &Node<'a>) -> Option<&'a Self> {
12829    if let Node::IdentName(node) = node {
12830      Some(node)
12831    } else {
12832      None
12833    }
12834  }
12835
12836  fn kind() -> NodeKind {
12837    NodeKind::IdentName
12838  }
12839}
12840
12841fn get_view_for_ident_name<'a>(inner: &'a swc_ast::IdentName, bump: &'a Bump) -> &'a IdentName<'a> {
12842  let node = bump.alloc(IdentName {
12843    inner,
12844    parent: Default::default(),
12845  });
12846  node
12847}
12848
12849fn set_parent_for_ident_name<'a>(node: &IdentName<'a>, parent: Node<'a>) {
12850  node.parent.set(parent);
12851}
12852
12853#[derive(Clone)]
12854pub struct IfStmt<'a> {
12855  parent: ParentOnceCell<Node<'a>>,
12856  pub inner: &'a swc_ast::IfStmt,
12857  pub test: Expr<'a>,
12858  pub cons: Stmt<'a>,
12859  pub alt: Option<Stmt<'a>>,
12860}
12861
12862impl<'a> IfStmt<'a> {
12863  pub fn parent(&self) -> Node<'a> {
12864    self.parent.get().unwrap()
12865  }
12866}
12867
12868impl<'a> SourceRanged for IfStmt<'a> {
12869  fn start(&self) -> SourcePos {
12870    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12871  }
12872  fn end(&self) -> SourcePos {
12873    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12874  }
12875}
12876
12877impl<'a> From<&IfStmt<'a>> for Node<'a> {
12878  fn from(node: &IfStmt<'a>) -> Node<'a> {
12879    let node = unsafe { mem::transmute::<&IfStmt<'a>, &'a IfStmt<'a>>(node) };
12880    Node::IfStmt(node)
12881  }
12882}
12883
12884impl<'a> NodeTrait<'a> for IfStmt<'a> {
12885  fn parent(&self) -> Option<Node<'a>> {
12886    Some(self.parent.get().unwrap().clone())
12887  }
12888
12889  fn children(&self) -> Vec<Node<'a>> {
12890    let mut children = Vec::with_capacity(2 + match &self.alt { Some(_value) => 1, None => 0, });
12891    children.push((&self.test).into());
12892    children.push((&self.cons).into());
12893    if let Some(child) = self.alt.as_ref() {
12894      children.push(child.into());
12895    }
12896    children
12897  }
12898
12899  fn as_node(&self) -> Node<'a> {
12900    self.into()
12901  }
12902
12903  fn kind(&self) -> NodeKind {
12904    NodeKind::IfStmt
12905  }
12906}
12907
12908impl<'a> CastableNode<'a> for IfStmt<'a> {
12909  fn to(node: &Node<'a>) -> Option<&'a Self> {
12910    if let Node::IfStmt(node) = node {
12911      Some(node)
12912    } else {
12913      None
12914    }
12915  }
12916
12917  fn kind() -> NodeKind {
12918    NodeKind::IfStmt
12919  }
12920}
12921
12922fn get_view_for_if_stmt<'a>(inner: &'a swc_ast::IfStmt, bump: &'a Bump) -> &'a IfStmt<'a> {
12923  let node = bump.alloc(IfStmt {
12924    inner,
12925    parent: Default::default(),
12926    test: get_view_for_expr(&inner.test, bump),
12927    cons: get_view_for_stmt(&inner.cons, bump),
12928    alt: match &inner.alt {
12929      Some(value) => Some(get_view_for_stmt(value, bump)),
12930      None => None,
12931    },
12932  });
12933  let parent: Node<'a> = (&*node).into();
12934  set_parent_for_expr(&node.test, parent);
12935  set_parent_for_stmt(&node.cons, parent);
12936  if let Some(value) = &node.alt {
12937    set_parent_for_stmt(value, parent)
12938  };
12939  node
12940}
12941
12942fn set_parent_for_if_stmt<'a>(node: &IfStmt<'a>, parent: Node<'a>) {
12943  node.parent.set(parent);
12944}
12945
12946#[derive(Clone)]
12947pub struct Import<'a> {
12948  parent: ParentOnceCell<&'a CallExpr<'a>>,
12949  pub inner: &'a swc_ast::Import,
12950}
12951
12952impl<'a> Import<'a> {
12953  pub fn parent(&self) -> &'a CallExpr<'a> {
12954    self.parent.get().unwrap()
12955  }
12956
12957  pub fn phase(&self) -> ImportPhase {
12958    self.inner.phase
12959  }
12960}
12961
12962impl<'a> SourceRanged for Import<'a> {
12963  fn start(&self) -> SourcePos {
12964    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12965  }
12966  fn end(&self) -> SourcePos {
12967    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12968  }
12969}
12970
12971impl<'a> From<&Import<'a>> for Node<'a> {
12972  fn from(node: &Import<'a>) -> Node<'a> {
12973    let node = unsafe { mem::transmute::<&Import<'a>, &'a Import<'a>>(node) };
12974    Node::Import(node)
12975  }
12976}
12977
12978impl<'a> NodeTrait<'a> for Import<'a> {
12979  fn parent(&self) -> Option<Node<'a>> {
12980    Some(self.parent.get().unwrap().into())
12981  }
12982
12983  fn children(&self) -> Vec<Node<'a>> {
12984    Vec::with_capacity(0)
12985  }
12986
12987  fn as_node(&self) -> Node<'a> {
12988    self.into()
12989  }
12990
12991  fn kind(&self) -> NodeKind {
12992    NodeKind::Import
12993  }
12994}
12995
12996impl<'a> CastableNode<'a> for Import<'a> {
12997  fn to(node: &Node<'a>) -> Option<&'a Self> {
12998    if let Node::Import(node) = node {
12999      Some(node)
13000    } else {
13001      None
13002    }
13003  }
13004
13005  fn kind() -> NodeKind {
13006    NodeKind::Import
13007  }
13008}
13009
13010fn get_view_for_import<'a>(inner: &'a swc_ast::Import, bump: &'a Bump) -> &'a Import<'a> {
13011  let node = bump.alloc(Import {
13012    inner,
13013    parent: Default::default(),
13014  });
13015  node
13016}
13017
13018fn set_parent_for_import<'a>(node: &Import<'a>, parent: Node<'a>) {
13019  node.parent.set(parent.expect::<CallExpr>());
13020}
13021
13022#[derive(Clone)]
13023pub struct ImportDecl<'a> {
13024  parent: ParentOnceCell<Node<'a>>,
13025  pub inner: &'a swc_ast::ImportDecl,
13026  pub specifiers: &'a [ImportSpecifier<'a>],
13027  pub src: &'a Str<'a>,
13028  pub with: Option<&'a ObjectLit<'a>>,
13029}
13030
13031impl<'a> ImportDecl<'a> {
13032  pub fn parent(&self) -> Node<'a> {
13033    self.parent.get().unwrap()
13034  }
13035
13036  pub fn type_only(&self) -> bool {
13037    self.inner.type_only
13038  }
13039
13040  pub fn phase(&self) -> ImportPhase {
13041    self.inner.phase
13042  }
13043}
13044
13045impl<'a> SourceRanged for ImportDecl<'a> {
13046  fn start(&self) -> SourcePos {
13047    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13048  }
13049  fn end(&self) -> SourcePos {
13050    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13051  }
13052}
13053
13054impl<'a> From<&ImportDecl<'a>> for Node<'a> {
13055  fn from(node: &ImportDecl<'a>) -> Node<'a> {
13056    let node = unsafe { mem::transmute::<&ImportDecl<'a>, &'a ImportDecl<'a>>(node) };
13057    Node::ImportDecl(node)
13058  }
13059}
13060
13061impl<'a> NodeTrait<'a> for ImportDecl<'a> {
13062  fn parent(&self) -> Option<Node<'a>> {
13063    Some(self.parent.get().unwrap().clone())
13064  }
13065
13066  fn children(&self) -> Vec<Node<'a>> {
13067    let mut children = Vec::with_capacity(1 + self.specifiers.len() + match &self.with { Some(_value) => 1, None => 0, });
13068    for child in self.specifiers.iter() {
13069      children.push(child.into());
13070    }
13071    children.push(self.src.into());
13072    if let Some(child) = self.with {
13073      children.push(child.into());
13074    }
13075    children
13076  }
13077
13078  fn as_node(&self) -> Node<'a> {
13079    self.into()
13080  }
13081
13082  fn kind(&self) -> NodeKind {
13083    NodeKind::ImportDecl
13084  }
13085}
13086
13087impl<'a> CastableNode<'a> for ImportDecl<'a> {
13088  fn to(node: &Node<'a>) -> Option<&'a Self> {
13089    if let Node::ImportDecl(node) = node {
13090      Some(node)
13091    } else {
13092      None
13093    }
13094  }
13095
13096  fn kind() -> NodeKind {
13097    NodeKind::ImportDecl
13098  }
13099}
13100
13101fn get_view_for_import_decl<'a>(inner: &'a swc_ast::ImportDecl, bump: &'a Bump) -> &'a ImportDecl<'a> {
13102  let node = bump.alloc(ImportDecl {
13103    inner,
13104    parent: Default::default(),
13105    specifiers: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.specifiers.len(), bump);vec.extend(inner.specifiers.iter().map(|value| get_view_for_import_specifier(value, bump))); vec }),
13106    src: get_view_for_str(&inner.src, bump),
13107    with: match &inner.with {
13108      Some(value) => Some(get_view_for_object_lit(value, bump)),
13109      None => None,
13110    },
13111  });
13112  let parent: Node<'a> = (&*node).into();
13113  for value in node.specifiers.iter() {
13114    set_parent_for_import_specifier(value, parent)
13115  }
13116  set_parent_for_str(&node.src, parent);
13117  if let Some(value) = &node.with {
13118    set_parent_for_object_lit(value, parent)
13119  };
13120  node
13121}
13122
13123fn set_parent_for_import_decl<'a>(node: &ImportDecl<'a>, parent: Node<'a>) {
13124  node.parent.set(parent);
13125}
13126
13127/// e.g. `import foo from 'mod.js'`
13128#[derive(Clone)]
13129pub struct ImportDefaultSpecifier<'a> {
13130  parent: ParentOnceCell<&'a ImportDecl<'a>>,
13131  pub inner: &'a swc_ast::ImportDefaultSpecifier,
13132  pub local: &'a Ident<'a>,
13133}
13134
13135impl<'a> ImportDefaultSpecifier<'a> {
13136  pub fn parent(&self) -> &'a ImportDecl<'a> {
13137    self.parent.get().unwrap()
13138  }
13139}
13140
13141impl<'a> SourceRanged for ImportDefaultSpecifier<'a> {
13142  fn start(&self) -> SourcePos {
13143    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13144  }
13145  fn end(&self) -> SourcePos {
13146    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13147  }
13148}
13149
13150impl<'a> From<&ImportDefaultSpecifier<'a>> for Node<'a> {
13151  fn from(node: &ImportDefaultSpecifier<'a>) -> Node<'a> {
13152    let node = unsafe { mem::transmute::<&ImportDefaultSpecifier<'a>, &'a ImportDefaultSpecifier<'a>>(node) };
13153    Node::ImportDefaultSpecifier(node)
13154  }
13155}
13156
13157impl<'a> NodeTrait<'a> for ImportDefaultSpecifier<'a> {
13158  fn parent(&self) -> Option<Node<'a>> {
13159    Some(self.parent.get().unwrap().into())
13160  }
13161
13162  fn children(&self) -> Vec<Node<'a>> {
13163    let mut children = Vec::with_capacity(1);
13164    children.push(self.local.into());
13165    children
13166  }
13167
13168  fn as_node(&self) -> Node<'a> {
13169    self.into()
13170  }
13171
13172  fn kind(&self) -> NodeKind {
13173    NodeKind::ImportDefaultSpecifier
13174  }
13175}
13176
13177impl<'a> CastableNode<'a> for ImportDefaultSpecifier<'a> {
13178  fn to(node: &Node<'a>) -> Option<&'a Self> {
13179    if let Node::ImportDefaultSpecifier(node) = node {
13180      Some(node)
13181    } else {
13182      None
13183    }
13184  }
13185
13186  fn kind() -> NodeKind {
13187    NodeKind::ImportDefaultSpecifier
13188  }
13189}
13190
13191fn get_view_for_import_default_specifier<'a>(inner: &'a swc_ast::ImportDefaultSpecifier, bump: &'a Bump) -> &'a ImportDefaultSpecifier<'a> {
13192  let node = bump.alloc(ImportDefaultSpecifier {
13193    inner,
13194    parent: Default::default(),
13195    local: get_view_for_ident(&inner.local, bump),
13196  });
13197  let parent: Node<'a> = (&*node).into();
13198  set_parent_for_ident(&node.local, parent);
13199  node
13200}
13201
13202fn set_parent_for_import_default_specifier<'a>(node: &ImportDefaultSpecifier<'a>, parent: Node<'a>) {
13203  node.parent.set(parent.expect::<ImportDecl>());
13204}
13205
13206/// e.g. local = foo, imported = None `import { foo } from 'mod.js'`
13207/// e.g. local = bar, imported = Some(foo) for `import { foo as bar } from
13208/// 'mod.js'`
13209#[derive(Clone)]
13210pub struct ImportNamedSpecifier<'a> {
13211  parent: ParentOnceCell<&'a ImportDecl<'a>>,
13212  pub inner: &'a swc_ast::ImportNamedSpecifier,
13213  pub local: &'a Ident<'a>,
13214  pub imported: Option<ModuleExportName<'a>>,
13215}
13216
13217impl<'a> ImportNamedSpecifier<'a> {
13218  pub fn parent(&self) -> &'a ImportDecl<'a> {
13219    self.parent.get().unwrap()
13220  }
13221
13222  pub fn is_type_only(&self) -> bool {
13223    self.inner.is_type_only
13224  }
13225}
13226
13227impl<'a> SourceRanged for ImportNamedSpecifier<'a> {
13228  fn start(&self) -> SourcePos {
13229    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13230  }
13231  fn end(&self) -> SourcePos {
13232    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13233  }
13234}
13235
13236impl<'a> From<&ImportNamedSpecifier<'a>> for Node<'a> {
13237  fn from(node: &ImportNamedSpecifier<'a>) -> Node<'a> {
13238    let node = unsafe { mem::transmute::<&ImportNamedSpecifier<'a>, &'a ImportNamedSpecifier<'a>>(node) };
13239    Node::ImportNamedSpecifier(node)
13240  }
13241}
13242
13243impl<'a> NodeTrait<'a> for ImportNamedSpecifier<'a> {
13244  fn parent(&self) -> Option<Node<'a>> {
13245    Some(self.parent.get().unwrap().into())
13246  }
13247
13248  fn children(&self) -> Vec<Node<'a>> {
13249    let mut children = Vec::with_capacity(1 + match &self.imported { Some(_value) => 1, None => 0, });
13250    children.push(self.local.into());
13251    if let Some(child) = self.imported.as_ref() {
13252      children.push(child.into());
13253    }
13254    children
13255  }
13256
13257  fn as_node(&self) -> Node<'a> {
13258    self.into()
13259  }
13260
13261  fn kind(&self) -> NodeKind {
13262    NodeKind::ImportNamedSpecifier
13263  }
13264}
13265
13266impl<'a> CastableNode<'a> for ImportNamedSpecifier<'a> {
13267  fn to(node: &Node<'a>) -> Option<&'a Self> {
13268    if let Node::ImportNamedSpecifier(node) = node {
13269      Some(node)
13270    } else {
13271      None
13272    }
13273  }
13274
13275  fn kind() -> NodeKind {
13276    NodeKind::ImportNamedSpecifier
13277  }
13278}
13279
13280fn get_view_for_import_named_specifier<'a>(inner: &'a swc_ast::ImportNamedSpecifier, bump: &'a Bump) -> &'a ImportNamedSpecifier<'a> {
13281  let node = bump.alloc(ImportNamedSpecifier {
13282    inner,
13283    parent: Default::default(),
13284    local: get_view_for_ident(&inner.local, bump),
13285    imported: match &inner.imported {
13286      Some(value) => Some(get_view_for_module_export_name(value, bump)),
13287      None => None,
13288    },
13289  });
13290  let parent: Node<'a> = (&*node).into();
13291  set_parent_for_ident(&node.local, parent);
13292  if let Some(value) = &node.imported {
13293    set_parent_for_module_export_name(value, parent)
13294  };
13295  node
13296}
13297
13298fn set_parent_for_import_named_specifier<'a>(node: &ImportNamedSpecifier<'a>, parent: Node<'a>) {
13299  node.parent.set(parent.expect::<ImportDecl>());
13300}
13301
13302/// e.g. `import * as foo from 'mod.js'`.
13303#[derive(Clone)]
13304pub struct ImportStarAsSpecifier<'a> {
13305  parent: ParentOnceCell<&'a ImportDecl<'a>>,
13306  pub inner: &'a swc_ast::ImportStarAsSpecifier,
13307  pub local: &'a Ident<'a>,
13308}
13309
13310impl<'a> ImportStarAsSpecifier<'a> {
13311  pub fn parent(&self) -> &'a ImportDecl<'a> {
13312    self.parent.get().unwrap()
13313  }
13314}
13315
13316impl<'a> SourceRanged for ImportStarAsSpecifier<'a> {
13317  fn start(&self) -> SourcePos {
13318    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13319  }
13320  fn end(&self) -> SourcePos {
13321    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13322  }
13323}
13324
13325impl<'a> From<&ImportStarAsSpecifier<'a>> for Node<'a> {
13326  fn from(node: &ImportStarAsSpecifier<'a>) -> Node<'a> {
13327    let node = unsafe { mem::transmute::<&ImportStarAsSpecifier<'a>, &'a ImportStarAsSpecifier<'a>>(node) };
13328    Node::ImportStarAsSpecifier(node)
13329  }
13330}
13331
13332impl<'a> NodeTrait<'a> for ImportStarAsSpecifier<'a> {
13333  fn parent(&self) -> Option<Node<'a>> {
13334    Some(self.parent.get().unwrap().into())
13335  }
13336
13337  fn children(&self) -> Vec<Node<'a>> {
13338    let mut children = Vec::with_capacity(1);
13339    children.push(self.local.into());
13340    children
13341  }
13342
13343  fn as_node(&self) -> Node<'a> {
13344    self.into()
13345  }
13346
13347  fn kind(&self) -> NodeKind {
13348    NodeKind::ImportStarAsSpecifier
13349  }
13350}
13351
13352impl<'a> CastableNode<'a> for ImportStarAsSpecifier<'a> {
13353  fn to(node: &Node<'a>) -> Option<&'a Self> {
13354    if let Node::ImportStarAsSpecifier(node) = node {
13355      Some(node)
13356    } else {
13357      None
13358    }
13359  }
13360
13361  fn kind() -> NodeKind {
13362    NodeKind::ImportStarAsSpecifier
13363  }
13364}
13365
13366fn get_view_for_import_star_as_specifier<'a>(inner: &'a swc_ast::ImportStarAsSpecifier, bump: &'a Bump) -> &'a ImportStarAsSpecifier<'a> {
13367  let node = bump.alloc(ImportStarAsSpecifier {
13368    inner,
13369    parent: Default::default(),
13370    local: get_view_for_ident(&inner.local, bump),
13371  });
13372  let parent: Node<'a> = (&*node).into();
13373  set_parent_for_ident(&node.local, parent);
13374  node
13375}
13376
13377fn set_parent_for_import_star_as_specifier<'a>(node: &ImportStarAsSpecifier<'a>, parent: Node<'a>) {
13378  node.parent.set(parent.expect::<ImportDecl>());
13379}
13380
13381/// Represents a invalid node.
13382#[derive(Clone)]
13383pub struct Invalid<'a> {
13384  parent: ParentOnceCell<Node<'a>>,
13385  pub inner: &'a swc_ast::Invalid,
13386}
13387
13388impl<'a> Invalid<'a> {
13389  pub fn parent(&self) -> Node<'a> {
13390    self.parent.get().unwrap()
13391  }
13392}
13393
13394impl<'a> SourceRanged for Invalid<'a> {
13395  fn start(&self) -> SourcePos {
13396    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13397  }
13398  fn end(&self) -> SourcePos {
13399    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13400  }
13401}
13402
13403impl<'a> From<&Invalid<'a>> for Node<'a> {
13404  fn from(node: &Invalid<'a>) -> Node<'a> {
13405    let node = unsafe { mem::transmute::<&Invalid<'a>, &'a Invalid<'a>>(node) };
13406    Node::Invalid(node)
13407  }
13408}
13409
13410impl<'a> NodeTrait<'a> for Invalid<'a> {
13411  fn parent(&self) -> Option<Node<'a>> {
13412    Some(self.parent.get().unwrap().clone())
13413  }
13414
13415  fn children(&self) -> Vec<Node<'a>> {
13416    Vec::with_capacity(0)
13417  }
13418
13419  fn as_node(&self) -> Node<'a> {
13420    self.into()
13421  }
13422
13423  fn kind(&self) -> NodeKind {
13424    NodeKind::Invalid
13425  }
13426}
13427
13428impl<'a> CastableNode<'a> for Invalid<'a> {
13429  fn to(node: &Node<'a>) -> Option<&'a Self> {
13430    if let Node::Invalid(node) = node {
13431      Some(node)
13432    } else {
13433      None
13434    }
13435  }
13436
13437  fn kind() -> NodeKind {
13438    NodeKind::Invalid
13439  }
13440}
13441
13442fn get_view_for_invalid<'a>(inner: &'a swc_ast::Invalid, bump: &'a Bump) -> &'a Invalid<'a> {
13443  let node = bump.alloc(Invalid {
13444    inner,
13445    parent: Default::default(),
13446  });
13447  node
13448}
13449
13450fn set_parent_for_invalid<'a>(node: &Invalid<'a>, parent: Node<'a>) {
13451  node.parent.set(parent);
13452}
13453
13454#[derive(Clone)]
13455pub struct JSXAttr<'a> {
13456  parent: ParentOnceCell<&'a JSXOpeningElement<'a>>,
13457  pub inner: &'a swc_ast::JSXAttr,
13458  pub name: JSXAttrName<'a>,
13459  /// Babel uses Expr instead of JSXAttrValue
13460  pub value: Option<JSXAttrValue<'a>>,
13461}
13462
13463impl<'a> JSXAttr<'a> {
13464  pub fn parent(&self) -> &'a JSXOpeningElement<'a> {
13465    self.parent.get().unwrap()
13466  }
13467}
13468
13469impl<'a> SourceRanged for JSXAttr<'a> {
13470  fn start(&self) -> SourcePos {
13471    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13472  }
13473  fn end(&self) -> SourcePos {
13474    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13475  }
13476}
13477
13478impl<'a> From<&JSXAttr<'a>> for Node<'a> {
13479  fn from(node: &JSXAttr<'a>) -> Node<'a> {
13480    let node = unsafe { mem::transmute::<&JSXAttr<'a>, &'a JSXAttr<'a>>(node) };
13481    Node::JSXAttr(node)
13482  }
13483}
13484
13485impl<'a> NodeTrait<'a> for JSXAttr<'a> {
13486  fn parent(&self) -> Option<Node<'a>> {
13487    Some(self.parent.get().unwrap().into())
13488  }
13489
13490  fn children(&self) -> Vec<Node<'a>> {
13491    let mut children = Vec::with_capacity(1 + match &self.value { Some(_value) => 1, None => 0, });
13492    children.push((&self.name).into());
13493    if let Some(child) = self.value.as_ref() {
13494      children.push(child.into());
13495    }
13496    children
13497  }
13498
13499  fn as_node(&self) -> Node<'a> {
13500    self.into()
13501  }
13502
13503  fn kind(&self) -> NodeKind {
13504    NodeKind::JSXAttr
13505  }
13506}
13507
13508impl<'a> CastableNode<'a> for JSXAttr<'a> {
13509  fn to(node: &Node<'a>) -> Option<&'a Self> {
13510    if let Node::JSXAttr(node) = node {
13511      Some(node)
13512    } else {
13513      None
13514    }
13515  }
13516
13517  fn kind() -> NodeKind {
13518    NodeKind::JSXAttr
13519  }
13520}
13521
13522fn get_view_for_jsxattr<'a>(inner: &'a swc_ast::JSXAttr, bump: &'a Bump) -> &'a JSXAttr<'a> {
13523  let node = bump.alloc(JSXAttr {
13524    inner,
13525    parent: Default::default(),
13526    name: get_view_for_jsxattr_name(&inner.name, bump),
13527    value: match &inner.value {
13528      Some(value) => Some(get_view_for_jsxattr_value(value, bump)),
13529      None => None,
13530    },
13531  });
13532  let parent: Node<'a> = (&*node).into();
13533  set_parent_for_jsxattr_name(&node.name, parent);
13534  if let Some(value) = &node.value {
13535    set_parent_for_jsxattr_value(value, parent)
13536  };
13537  node
13538}
13539
13540fn set_parent_for_jsxattr<'a>(node: &JSXAttr<'a>, parent: Node<'a>) {
13541  node.parent.set(parent.expect::<JSXOpeningElement>());
13542}
13543
13544#[derive(Clone)]
13545pub struct JSXClosingElement<'a> {
13546  parent: ParentOnceCell<&'a JSXElement<'a>>,
13547  pub inner: &'a swc_ast::JSXClosingElement,
13548  pub name: JSXElementName<'a>,
13549}
13550
13551impl<'a> JSXClosingElement<'a> {
13552  pub fn parent(&self) -> &'a JSXElement<'a> {
13553    self.parent.get().unwrap()
13554  }
13555}
13556
13557impl<'a> SourceRanged for JSXClosingElement<'a> {
13558  fn start(&self) -> SourcePos {
13559    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13560  }
13561  fn end(&self) -> SourcePos {
13562    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13563  }
13564}
13565
13566impl<'a> From<&JSXClosingElement<'a>> for Node<'a> {
13567  fn from(node: &JSXClosingElement<'a>) -> Node<'a> {
13568    let node = unsafe { mem::transmute::<&JSXClosingElement<'a>, &'a JSXClosingElement<'a>>(node) };
13569    Node::JSXClosingElement(node)
13570  }
13571}
13572
13573impl<'a> NodeTrait<'a> for JSXClosingElement<'a> {
13574  fn parent(&self) -> Option<Node<'a>> {
13575    Some(self.parent.get().unwrap().into())
13576  }
13577
13578  fn children(&self) -> Vec<Node<'a>> {
13579    let mut children = Vec::with_capacity(1);
13580    children.push((&self.name).into());
13581    children
13582  }
13583
13584  fn as_node(&self) -> Node<'a> {
13585    self.into()
13586  }
13587
13588  fn kind(&self) -> NodeKind {
13589    NodeKind::JSXClosingElement
13590  }
13591}
13592
13593impl<'a> CastableNode<'a> for JSXClosingElement<'a> {
13594  fn to(node: &Node<'a>) -> Option<&'a Self> {
13595    if let Node::JSXClosingElement(node) = node {
13596      Some(node)
13597    } else {
13598      None
13599    }
13600  }
13601
13602  fn kind() -> NodeKind {
13603    NodeKind::JSXClosingElement
13604  }
13605}
13606
13607fn get_view_for_jsxclosing_element<'a>(inner: &'a swc_ast::JSXClosingElement, bump: &'a Bump) -> &'a JSXClosingElement<'a> {
13608  let node = bump.alloc(JSXClosingElement {
13609    inner,
13610    parent: Default::default(),
13611    name: get_view_for_jsxelement_name(&inner.name, bump),
13612  });
13613  let parent: Node<'a> = (&*node).into();
13614  set_parent_for_jsxelement_name(&node.name, parent);
13615  node
13616}
13617
13618fn set_parent_for_jsxclosing_element<'a>(node: &JSXClosingElement<'a>, parent: Node<'a>) {
13619  node.parent.set(parent.expect::<JSXElement>());
13620}
13621
13622#[derive(Clone)]
13623pub struct JSXClosingFragment<'a> {
13624  parent: ParentOnceCell<&'a JSXFragment<'a>>,
13625  pub inner: &'a swc_ast::JSXClosingFragment,
13626}
13627
13628impl<'a> JSXClosingFragment<'a> {
13629  pub fn parent(&self) -> &'a JSXFragment<'a> {
13630    self.parent.get().unwrap()
13631  }
13632}
13633
13634impl<'a> SourceRanged for JSXClosingFragment<'a> {
13635  fn start(&self) -> SourcePos {
13636    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13637  }
13638  fn end(&self) -> SourcePos {
13639    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13640  }
13641}
13642
13643impl<'a> From<&JSXClosingFragment<'a>> for Node<'a> {
13644  fn from(node: &JSXClosingFragment<'a>) -> Node<'a> {
13645    let node = unsafe { mem::transmute::<&JSXClosingFragment<'a>, &'a JSXClosingFragment<'a>>(node) };
13646    Node::JSXClosingFragment(node)
13647  }
13648}
13649
13650impl<'a> NodeTrait<'a> for JSXClosingFragment<'a> {
13651  fn parent(&self) -> Option<Node<'a>> {
13652    Some(self.parent.get().unwrap().into())
13653  }
13654
13655  fn children(&self) -> Vec<Node<'a>> {
13656    Vec::with_capacity(0)
13657  }
13658
13659  fn as_node(&self) -> Node<'a> {
13660    self.into()
13661  }
13662
13663  fn kind(&self) -> NodeKind {
13664    NodeKind::JSXClosingFragment
13665  }
13666}
13667
13668impl<'a> CastableNode<'a> for JSXClosingFragment<'a> {
13669  fn to(node: &Node<'a>) -> Option<&'a Self> {
13670    if let Node::JSXClosingFragment(node) = node {
13671      Some(node)
13672    } else {
13673      None
13674    }
13675  }
13676
13677  fn kind() -> NodeKind {
13678    NodeKind::JSXClosingFragment
13679  }
13680}
13681
13682fn get_view_for_jsxclosing_fragment<'a>(inner: &'a swc_ast::JSXClosingFragment, bump: &'a Bump) -> &'a JSXClosingFragment<'a> {
13683  let node = bump.alloc(JSXClosingFragment {
13684    inner,
13685    parent: Default::default(),
13686  });
13687  node
13688}
13689
13690fn set_parent_for_jsxclosing_fragment<'a>(node: &JSXClosingFragment<'a>, parent: Node<'a>) {
13691  node.parent.set(parent.expect::<JSXFragment>());
13692}
13693
13694#[derive(Clone)]
13695pub struct JSXElement<'a> {
13696  parent: ParentOnceCell<Node<'a>>,
13697  pub inner: &'a swc_ast::JSXElement,
13698  pub opening: &'a JSXOpeningElement<'a>,
13699  pub children: &'a [JSXElementChild<'a>],
13700  pub closing: Option<&'a JSXClosingElement<'a>>,
13701}
13702
13703impl<'a> JSXElement<'a> {
13704  pub fn parent(&self) -> Node<'a> {
13705    self.parent.get().unwrap()
13706  }
13707}
13708
13709impl<'a> SourceRanged for JSXElement<'a> {
13710  fn start(&self) -> SourcePos {
13711    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13712  }
13713  fn end(&self) -> SourcePos {
13714    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13715  }
13716}
13717
13718impl<'a> From<&JSXElement<'a>> for Node<'a> {
13719  fn from(node: &JSXElement<'a>) -> Node<'a> {
13720    let node = unsafe { mem::transmute::<&JSXElement<'a>, &'a JSXElement<'a>>(node) };
13721    Node::JSXElement(node)
13722  }
13723}
13724
13725impl<'a> NodeTrait<'a> for JSXElement<'a> {
13726  fn parent(&self) -> Option<Node<'a>> {
13727    Some(self.parent.get().unwrap().clone())
13728  }
13729
13730  fn children(&self) -> Vec<Node<'a>> {
13731    let mut children = Vec::with_capacity(1 + self.children.len() + match &self.closing { Some(_value) => 1, None => 0, });
13732    children.push(self.opening.into());
13733    for child in self.children.iter() {
13734      children.push(child.into());
13735    }
13736    if let Some(child) = self.closing {
13737      children.push(child.into());
13738    }
13739    children
13740  }
13741
13742  fn as_node(&self) -> Node<'a> {
13743    self.into()
13744  }
13745
13746  fn kind(&self) -> NodeKind {
13747    NodeKind::JSXElement
13748  }
13749}
13750
13751impl<'a> CastableNode<'a> for JSXElement<'a> {
13752  fn to(node: &Node<'a>) -> Option<&'a Self> {
13753    if let Node::JSXElement(node) = node {
13754      Some(node)
13755    } else {
13756      None
13757    }
13758  }
13759
13760  fn kind() -> NodeKind {
13761    NodeKind::JSXElement
13762  }
13763}
13764
13765fn get_view_for_jsxelement<'a>(inner: &'a swc_ast::JSXElement, bump: &'a Bump) -> &'a JSXElement<'a> {
13766  let node = bump.alloc(JSXElement {
13767    inner,
13768    parent: Default::default(),
13769    opening: get_view_for_jsxopening_element(&inner.opening, bump),
13770    children: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.children.len(), bump);vec.extend(inner.children.iter().map(|value| get_view_for_jsxelement_child(value, bump))); vec }),
13771    closing: match &inner.closing {
13772      Some(value) => Some(get_view_for_jsxclosing_element(value, bump)),
13773      None => None,
13774    },
13775  });
13776  let parent: Node<'a> = (&*node).into();
13777  set_parent_for_jsxopening_element(&node.opening, parent);
13778  for value in node.children.iter() {
13779    set_parent_for_jsxelement_child(value, parent)
13780  }
13781  if let Some(value) = &node.closing {
13782    set_parent_for_jsxclosing_element(value, parent)
13783  };
13784  node
13785}
13786
13787fn set_parent_for_jsxelement<'a>(node: &JSXElement<'a>, parent: Node<'a>) {
13788  node.parent.set(parent);
13789}
13790
13791#[derive(Clone)]
13792pub struct JSXEmptyExpr<'a> {
13793  parent: ParentOnceCell<Node<'a>>,
13794  pub inner: &'a swc_ast::JSXEmptyExpr,
13795}
13796
13797impl<'a> JSXEmptyExpr<'a> {
13798  pub fn parent(&self) -> Node<'a> {
13799    self.parent.get().unwrap()
13800  }
13801}
13802
13803impl<'a> SourceRanged for JSXEmptyExpr<'a> {
13804  fn start(&self) -> SourcePos {
13805    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13806  }
13807  fn end(&self) -> SourcePos {
13808    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13809  }
13810}
13811
13812impl<'a> From<&JSXEmptyExpr<'a>> for Node<'a> {
13813  fn from(node: &JSXEmptyExpr<'a>) -> Node<'a> {
13814    let node = unsafe { mem::transmute::<&JSXEmptyExpr<'a>, &'a JSXEmptyExpr<'a>>(node) };
13815    Node::JSXEmptyExpr(node)
13816  }
13817}
13818
13819impl<'a> NodeTrait<'a> for JSXEmptyExpr<'a> {
13820  fn parent(&self) -> Option<Node<'a>> {
13821    Some(self.parent.get().unwrap().clone())
13822  }
13823
13824  fn children(&self) -> Vec<Node<'a>> {
13825    Vec::with_capacity(0)
13826  }
13827
13828  fn as_node(&self) -> Node<'a> {
13829    self.into()
13830  }
13831
13832  fn kind(&self) -> NodeKind {
13833    NodeKind::JSXEmptyExpr
13834  }
13835}
13836
13837impl<'a> CastableNode<'a> for JSXEmptyExpr<'a> {
13838  fn to(node: &Node<'a>) -> Option<&'a Self> {
13839    if let Node::JSXEmptyExpr(node) = node {
13840      Some(node)
13841    } else {
13842      None
13843    }
13844  }
13845
13846  fn kind() -> NodeKind {
13847    NodeKind::JSXEmptyExpr
13848  }
13849}
13850
13851fn get_view_for_jsxempty_expr<'a>(inner: &'a swc_ast::JSXEmptyExpr, bump: &'a Bump) -> &'a JSXEmptyExpr<'a> {
13852  let node = bump.alloc(JSXEmptyExpr {
13853    inner,
13854    parent: Default::default(),
13855  });
13856  node
13857}
13858
13859fn set_parent_for_jsxempty_expr<'a>(node: &JSXEmptyExpr<'a>, parent: Node<'a>) {
13860  node.parent.set(parent);
13861}
13862
13863#[derive(Clone)]
13864pub struct JSXExprContainer<'a> {
13865  parent: ParentOnceCell<Node<'a>>,
13866  pub inner: &'a swc_ast::JSXExprContainer,
13867  pub expr: JSXExpr<'a>,
13868}
13869
13870impl<'a> JSXExprContainer<'a> {
13871  pub fn parent(&self) -> Node<'a> {
13872    self.parent.get().unwrap()
13873  }
13874}
13875
13876impl<'a> SourceRanged for JSXExprContainer<'a> {
13877  fn start(&self) -> SourcePos {
13878    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13879  }
13880  fn end(&self) -> SourcePos {
13881    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13882  }
13883}
13884
13885impl<'a> From<&JSXExprContainer<'a>> for Node<'a> {
13886  fn from(node: &JSXExprContainer<'a>) -> Node<'a> {
13887    let node = unsafe { mem::transmute::<&JSXExprContainer<'a>, &'a JSXExprContainer<'a>>(node) };
13888    Node::JSXExprContainer(node)
13889  }
13890}
13891
13892impl<'a> NodeTrait<'a> for JSXExprContainer<'a> {
13893  fn parent(&self) -> Option<Node<'a>> {
13894    Some(self.parent.get().unwrap().clone())
13895  }
13896
13897  fn children(&self) -> Vec<Node<'a>> {
13898    let mut children = Vec::with_capacity(1);
13899    children.push((&self.expr).into());
13900    children
13901  }
13902
13903  fn as_node(&self) -> Node<'a> {
13904    self.into()
13905  }
13906
13907  fn kind(&self) -> NodeKind {
13908    NodeKind::JSXExprContainer
13909  }
13910}
13911
13912impl<'a> CastableNode<'a> for JSXExprContainer<'a> {
13913  fn to(node: &Node<'a>) -> Option<&'a Self> {
13914    if let Node::JSXExprContainer(node) = node {
13915      Some(node)
13916    } else {
13917      None
13918    }
13919  }
13920
13921  fn kind() -> NodeKind {
13922    NodeKind::JSXExprContainer
13923  }
13924}
13925
13926fn get_view_for_jsxexpr_container<'a>(inner: &'a swc_ast::JSXExprContainer, bump: &'a Bump) -> &'a JSXExprContainer<'a> {
13927  let node = bump.alloc(JSXExprContainer {
13928    inner,
13929    parent: Default::default(),
13930    expr: get_view_for_jsxexpr(&inner.expr, bump),
13931  });
13932  let parent: Node<'a> = (&*node).into();
13933  set_parent_for_jsxexpr(&node.expr, parent);
13934  node
13935}
13936
13937fn set_parent_for_jsxexpr_container<'a>(node: &JSXExprContainer<'a>, parent: Node<'a>) {
13938  node.parent.set(parent);
13939}
13940
13941#[derive(Clone)]
13942pub struct JSXFragment<'a> {
13943  parent: ParentOnceCell<Node<'a>>,
13944  pub inner: &'a swc_ast::JSXFragment,
13945  pub opening: &'a JSXOpeningFragment<'a>,
13946  pub children: &'a [JSXElementChild<'a>],
13947  pub closing: &'a JSXClosingFragment<'a>,
13948}
13949
13950impl<'a> JSXFragment<'a> {
13951  pub fn parent(&self) -> Node<'a> {
13952    self.parent.get().unwrap()
13953  }
13954}
13955
13956impl<'a> SourceRanged for JSXFragment<'a> {
13957  fn start(&self) -> SourcePos {
13958    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13959  }
13960  fn end(&self) -> SourcePos {
13961    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13962  }
13963}
13964
13965impl<'a> From<&JSXFragment<'a>> for Node<'a> {
13966  fn from(node: &JSXFragment<'a>) -> Node<'a> {
13967    let node = unsafe { mem::transmute::<&JSXFragment<'a>, &'a JSXFragment<'a>>(node) };
13968    Node::JSXFragment(node)
13969  }
13970}
13971
13972impl<'a> NodeTrait<'a> for JSXFragment<'a> {
13973  fn parent(&self) -> Option<Node<'a>> {
13974    Some(self.parent.get().unwrap().clone())
13975  }
13976
13977  fn children(&self) -> Vec<Node<'a>> {
13978    let mut children = Vec::with_capacity(2 + self.children.len());
13979    children.push(self.opening.into());
13980    for child in self.children.iter() {
13981      children.push(child.into());
13982    }
13983    children.push(self.closing.into());
13984    children
13985  }
13986
13987  fn as_node(&self) -> Node<'a> {
13988    self.into()
13989  }
13990
13991  fn kind(&self) -> NodeKind {
13992    NodeKind::JSXFragment
13993  }
13994}
13995
13996impl<'a> CastableNode<'a> for JSXFragment<'a> {
13997  fn to(node: &Node<'a>) -> Option<&'a Self> {
13998    if let Node::JSXFragment(node) = node {
13999      Some(node)
14000    } else {
14001      None
14002    }
14003  }
14004
14005  fn kind() -> NodeKind {
14006    NodeKind::JSXFragment
14007  }
14008}
14009
14010fn get_view_for_jsxfragment<'a>(inner: &'a swc_ast::JSXFragment, bump: &'a Bump) -> &'a JSXFragment<'a> {
14011  let node = bump.alloc(JSXFragment {
14012    inner,
14013    parent: Default::default(),
14014    opening: get_view_for_jsxopening_fragment(&inner.opening, bump),
14015    children: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.children.len(), bump);vec.extend(inner.children.iter().map(|value| get_view_for_jsxelement_child(value, bump))); vec }),
14016    closing: get_view_for_jsxclosing_fragment(&inner.closing, bump),
14017  });
14018  let parent: Node<'a> = (&*node).into();
14019  set_parent_for_jsxopening_fragment(&node.opening, parent);
14020  for value in node.children.iter() {
14021    set_parent_for_jsxelement_child(value, parent)
14022  }
14023  set_parent_for_jsxclosing_fragment(&node.closing, parent);
14024  node
14025}
14026
14027fn set_parent_for_jsxfragment<'a>(node: &JSXFragment<'a>, parent: Node<'a>) {
14028  node.parent.set(parent);
14029}
14030
14031#[derive(Clone)]
14032pub struct JSXMemberExpr<'a> {
14033  parent: ParentOnceCell<Node<'a>>,
14034  pub inner: &'a swc_ast::JSXMemberExpr,
14035  pub obj: JSXObject<'a>,
14036  pub prop: &'a IdentName<'a>,
14037}
14038
14039impl<'a> JSXMemberExpr<'a> {
14040  pub fn parent(&self) -> Node<'a> {
14041    self.parent.get().unwrap()
14042  }
14043}
14044
14045impl<'a> SourceRanged for JSXMemberExpr<'a> {
14046  fn start(&self) -> SourcePos {
14047    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14048  }
14049  fn end(&self) -> SourcePos {
14050    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14051  }
14052}
14053
14054impl<'a> From<&JSXMemberExpr<'a>> for Node<'a> {
14055  fn from(node: &JSXMemberExpr<'a>) -> Node<'a> {
14056    let node = unsafe { mem::transmute::<&JSXMemberExpr<'a>, &'a JSXMemberExpr<'a>>(node) };
14057    Node::JSXMemberExpr(node)
14058  }
14059}
14060
14061impl<'a> NodeTrait<'a> for JSXMemberExpr<'a> {
14062  fn parent(&self) -> Option<Node<'a>> {
14063    Some(self.parent.get().unwrap().clone())
14064  }
14065
14066  fn children(&self) -> Vec<Node<'a>> {
14067    let mut children = Vec::with_capacity(2);
14068    children.push((&self.obj).into());
14069    children.push(self.prop.into());
14070    children
14071  }
14072
14073  fn as_node(&self) -> Node<'a> {
14074    self.into()
14075  }
14076
14077  fn kind(&self) -> NodeKind {
14078    NodeKind::JSXMemberExpr
14079  }
14080}
14081
14082impl<'a> CastableNode<'a> for JSXMemberExpr<'a> {
14083  fn to(node: &Node<'a>) -> Option<&'a Self> {
14084    if let Node::JSXMemberExpr(node) = node {
14085      Some(node)
14086    } else {
14087      None
14088    }
14089  }
14090
14091  fn kind() -> NodeKind {
14092    NodeKind::JSXMemberExpr
14093  }
14094}
14095
14096fn get_view_for_jsxmember_expr<'a>(inner: &'a swc_ast::JSXMemberExpr, bump: &'a Bump) -> &'a JSXMemberExpr<'a> {
14097  let node = bump.alloc(JSXMemberExpr {
14098    inner,
14099    parent: Default::default(),
14100    obj: get_view_for_jsxobject(&inner.obj, bump),
14101    prop: get_view_for_ident_name(&inner.prop, bump),
14102  });
14103  let parent: Node<'a> = (&*node).into();
14104  set_parent_for_jsxobject(&node.obj, parent);
14105  set_parent_for_ident_name(&node.prop, parent);
14106  node
14107}
14108
14109fn set_parent_for_jsxmember_expr<'a>(node: &JSXMemberExpr<'a>, parent: Node<'a>) {
14110  node.parent.set(parent);
14111}
14112
14113/// XML-based namespace syntax:
14114#[derive(Clone)]
14115pub struct JSXNamespacedName<'a> {
14116  parent: ParentOnceCell<Node<'a>>,
14117  pub inner: &'a swc_ast::JSXNamespacedName,
14118  pub ns: &'a IdentName<'a>,
14119  pub name: &'a IdentName<'a>,
14120}
14121
14122impl<'a> JSXNamespacedName<'a> {
14123  pub fn parent(&self) -> Node<'a> {
14124    self.parent.get().unwrap()
14125  }
14126}
14127
14128impl<'a> SourceRanged for JSXNamespacedName<'a> {
14129  fn start(&self) -> SourcePos {
14130    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14131  }
14132  fn end(&self) -> SourcePos {
14133    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14134  }
14135}
14136
14137impl<'a> From<&JSXNamespacedName<'a>> for Node<'a> {
14138  fn from(node: &JSXNamespacedName<'a>) -> Node<'a> {
14139    let node = unsafe { mem::transmute::<&JSXNamespacedName<'a>, &'a JSXNamespacedName<'a>>(node) };
14140    Node::JSXNamespacedName(node)
14141  }
14142}
14143
14144impl<'a> NodeTrait<'a> for JSXNamespacedName<'a> {
14145  fn parent(&self) -> Option<Node<'a>> {
14146    Some(self.parent.get().unwrap().clone())
14147  }
14148
14149  fn children(&self) -> Vec<Node<'a>> {
14150    let mut children = Vec::with_capacity(2);
14151    children.push(self.ns.into());
14152    children.push(self.name.into());
14153    children
14154  }
14155
14156  fn as_node(&self) -> Node<'a> {
14157    self.into()
14158  }
14159
14160  fn kind(&self) -> NodeKind {
14161    NodeKind::JSXNamespacedName
14162  }
14163}
14164
14165impl<'a> CastableNode<'a> for JSXNamespacedName<'a> {
14166  fn to(node: &Node<'a>) -> Option<&'a Self> {
14167    if let Node::JSXNamespacedName(node) = node {
14168      Some(node)
14169    } else {
14170      None
14171    }
14172  }
14173
14174  fn kind() -> NodeKind {
14175    NodeKind::JSXNamespacedName
14176  }
14177}
14178
14179fn get_view_for_jsxnamespaced_name<'a>(inner: &'a swc_ast::JSXNamespacedName, bump: &'a Bump) -> &'a JSXNamespacedName<'a> {
14180  let node = bump.alloc(JSXNamespacedName {
14181    inner,
14182    parent: Default::default(),
14183    ns: get_view_for_ident_name(&inner.ns, bump),
14184    name: get_view_for_ident_name(&inner.name, bump),
14185  });
14186  let parent: Node<'a> = (&*node).into();
14187  set_parent_for_ident_name(&node.ns, parent);
14188  set_parent_for_ident_name(&node.name, parent);
14189  node
14190}
14191
14192fn set_parent_for_jsxnamespaced_name<'a>(node: &JSXNamespacedName<'a>, parent: Node<'a>) {
14193  node.parent.set(parent);
14194}
14195
14196#[derive(Clone)]
14197pub struct JSXOpeningElement<'a> {
14198  parent: ParentOnceCell<&'a JSXElement<'a>>,
14199  pub inner: &'a swc_ast::JSXOpeningElement,
14200  pub name: JSXElementName<'a>,
14201  pub attrs: &'a [JSXAttrOrSpread<'a>],
14202  /// Note: This field's name is different from one from babel because it is
14203  /// misleading
14204  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
14205}
14206
14207impl<'a> JSXOpeningElement<'a> {
14208  pub fn parent(&self) -> &'a JSXElement<'a> {
14209    self.parent.get().unwrap()
14210  }
14211
14212  pub fn self_closing(&self) -> bool {
14213    self.inner.self_closing
14214  }
14215}
14216
14217impl<'a> SourceRanged for JSXOpeningElement<'a> {
14218  fn start(&self) -> SourcePos {
14219    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14220  }
14221  fn end(&self) -> SourcePos {
14222    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14223  }
14224}
14225
14226impl<'a> From<&JSXOpeningElement<'a>> for Node<'a> {
14227  fn from(node: &JSXOpeningElement<'a>) -> Node<'a> {
14228    let node = unsafe { mem::transmute::<&JSXOpeningElement<'a>, &'a JSXOpeningElement<'a>>(node) };
14229    Node::JSXOpeningElement(node)
14230  }
14231}
14232
14233impl<'a> NodeTrait<'a> for JSXOpeningElement<'a> {
14234  fn parent(&self) -> Option<Node<'a>> {
14235    Some(self.parent.get().unwrap().into())
14236  }
14237
14238  fn children(&self) -> Vec<Node<'a>> {
14239    let mut children = Vec::with_capacity(1 + self.attrs.len() + match &self.type_args { Some(_value) => 1, None => 0, });
14240    children.push((&self.name).into());
14241    for child in self.attrs.iter() {
14242      children.push(child.into());
14243    }
14244    if let Some(child) = self.type_args {
14245      children.push(child.into());
14246    }
14247    children
14248  }
14249
14250  fn as_node(&self) -> Node<'a> {
14251    self.into()
14252  }
14253
14254  fn kind(&self) -> NodeKind {
14255    NodeKind::JSXOpeningElement
14256  }
14257}
14258
14259impl<'a> CastableNode<'a> for JSXOpeningElement<'a> {
14260  fn to(node: &Node<'a>) -> Option<&'a Self> {
14261    if let Node::JSXOpeningElement(node) = node {
14262      Some(node)
14263    } else {
14264      None
14265    }
14266  }
14267
14268  fn kind() -> NodeKind {
14269    NodeKind::JSXOpeningElement
14270  }
14271}
14272
14273fn get_view_for_jsxopening_element<'a>(inner: &'a swc_ast::JSXOpeningElement, bump: &'a Bump) -> &'a JSXOpeningElement<'a> {
14274  let node = bump.alloc(JSXOpeningElement {
14275    inner,
14276    parent: Default::default(),
14277    name: get_view_for_jsxelement_name(&inner.name, bump),
14278    attrs: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.attrs.len(), bump);vec.extend(inner.attrs.iter().map(|value| get_view_for_jsxattr_or_spread(value, bump))); vec }),
14279    type_args: match &inner.type_args {
14280      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
14281      None => None,
14282    },
14283  });
14284  let parent: Node<'a> = (&*node).into();
14285  set_parent_for_jsxelement_name(&node.name, parent);
14286  for value in node.attrs.iter() {
14287    set_parent_for_jsxattr_or_spread(value, parent)
14288  }
14289  if let Some(value) = &node.type_args {
14290    set_parent_for_ts_type_param_instantiation(value, parent)
14291  };
14292  node
14293}
14294
14295fn set_parent_for_jsxopening_element<'a>(node: &JSXOpeningElement<'a>, parent: Node<'a>) {
14296  node.parent.set(parent.expect::<JSXElement>());
14297}
14298
14299#[derive(Clone)]
14300pub struct JSXOpeningFragment<'a> {
14301  parent: ParentOnceCell<&'a JSXFragment<'a>>,
14302  pub inner: &'a swc_ast::JSXOpeningFragment,
14303}
14304
14305impl<'a> JSXOpeningFragment<'a> {
14306  pub fn parent(&self) -> &'a JSXFragment<'a> {
14307    self.parent.get().unwrap()
14308  }
14309}
14310
14311impl<'a> SourceRanged for JSXOpeningFragment<'a> {
14312  fn start(&self) -> SourcePos {
14313    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14314  }
14315  fn end(&self) -> SourcePos {
14316    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14317  }
14318}
14319
14320impl<'a> From<&JSXOpeningFragment<'a>> for Node<'a> {
14321  fn from(node: &JSXOpeningFragment<'a>) -> Node<'a> {
14322    let node = unsafe { mem::transmute::<&JSXOpeningFragment<'a>, &'a JSXOpeningFragment<'a>>(node) };
14323    Node::JSXOpeningFragment(node)
14324  }
14325}
14326
14327impl<'a> NodeTrait<'a> for JSXOpeningFragment<'a> {
14328  fn parent(&self) -> Option<Node<'a>> {
14329    Some(self.parent.get().unwrap().into())
14330  }
14331
14332  fn children(&self) -> Vec<Node<'a>> {
14333    Vec::with_capacity(0)
14334  }
14335
14336  fn as_node(&self) -> Node<'a> {
14337    self.into()
14338  }
14339
14340  fn kind(&self) -> NodeKind {
14341    NodeKind::JSXOpeningFragment
14342  }
14343}
14344
14345impl<'a> CastableNode<'a> for JSXOpeningFragment<'a> {
14346  fn to(node: &Node<'a>) -> Option<&'a Self> {
14347    if let Node::JSXOpeningFragment(node) = node {
14348      Some(node)
14349    } else {
14350      None
14351    }
14352  }
14353
14354  fn kind() -> NodeKind {
14355    NodeKind::JSXOpeningFragment
14356  }
14357}
14358
14359fn get_view_for_jsxopening_fragment<'a>(inner: &'a swc_ast::JSXOpeningFragment, bump: &'a Bump) -> &'a JSXOpeningFragment<'a> {
14360  let node = bump.alloc(JSXOpeningFragment {
14361    inner,
14362    parent: Default::default(),
14363  });
14364  node
14365}
14366
14367fn set_parent_for_jsxopening_fragment<'a>(node: &JSXOpeningFragment<'a>, parent: Node<'a>) {
14368  node.parent.set(parent.expect::<JSXFragment>());
14369}
14370
14371#[derive(Clone)]
14372pub struct JSXSpreadChild<'a> {
14373  parent: ParentOnceCell<Node<'a>>,
14374  pub inner: &'a swc_ast::JSXSpreadChild,
14375  pub expr: Expr<'a>,
14376}
14377
14378impl<'a> JSXSpreadChild<'a> {
14379  pub fn parent(&self) -> Node<'a> {
14380    self.parent.get().unwrap()
14381  }
14382}
14383
14384impl<'a> SourceRanged for JSXSpreadChild<'a> {
14385  fn start(&self) -> SourcePos {
14386    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14387  }
14388  fn end(&self) -> SourcePos {
14389    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14390  }
14391}
14392
14393impl<'a> From<&JSXSpreadChild<'a>> for Node<'a> {
14394  fn from(node: &JSXSpreadChild<'a>) -> Node<'a> {
14395    let node = unsafe { mem::transmute::<&JSXSpreadChild<'a>, &'a JSXSpreadChild<'a>>(node) };
14396    Node::JSXSpreadChild(node)
14397  }
14398}
14399
14400impl<'a> NodeTrait<'a> for JSXSpreadChild<'a> {
14401  fn parent(&self) -> Option<Node<'a>> {
14402    Some(self.parent.get().unwrap().clone())
14403  }
14404
14405  fn children(&self) -> Vec<Node<'a>> {
14406    let mut children = Vec::with_capacity(1);
14407    children.push((&self.expr).into());
14408    children
14409  }
14410
14411  fn as_node(&self) -> Node<'a> {
14412    self.into()
14413  }
14414
14415  fn kind(&self) -> NodeKind {
14416    NodeKind::JSXSpreadChild
14417  }
14418}
14419
14420impl<'a> CastableNode<'a> for JSXSpreadChild<'a> {
14421  fn to(node: &Node<'a>) -> Option<&'a Self> {
14422    if let Node::JSXSpreadChild(node) = node {
14423      Some(node)
14424    } else {
14425      None
14426    }
14427  }
14428
14429  fn kind() -> NodeKind {
14430    NodeKind::JSXSpreadChild
14431  }
14432}
14433
14434fn get_view_for_jsxspread_child<'a>(inner: &'a swc_ast::JSXSpreadChild, bump: &'a Bump) -> &'a JSXSpreadChild<'a> {
14435  let node = bump.alloc(JSXSpreadChild {
14436    inner,
14437    parent: Default::default(),
14438    expr: get_view_for_expr(&inner.expr, bump),
14439  });
14440  let parent: Node<'a> = (&*node).into();
14441  set_parent_for_expr(&node.expr, parent);
14442  node
14443}
14444
14445fn set_parent_for_jsxspread_child<'a>(node: &JSXSpreadChild<'a>, parent: Node<'a>) {
14446  node.parent.set(parent);
14447}
14448
14449#[derive(Clone)]
14450pub struct JSXText<'a> {
14451  parent: ParentOnceCell<Node<'a>>,
14452  pub inner: &'a swc_ast::JSXText,
14453}
14454
14455impl<'a> JSXText<'a> {
14456  pub fn parent(&self) -> Node<'a> {
14457    self.parent.get().unwrap()
14458  }
14459
14460  pub fn value(&self) -> &swc_atoms::Atom {
14461    &self.inner.value
14462  }
14463
14464  pub fn raw(&self) -> &swc_atoms::Atom {
14465    &self.inner.raw
14466  }
14467}
14468
14469impl<'a> SourceRanged for JSXText<'a> {
14470  fn start(&self) -> SourcePos {
14471    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14472  }
14473  fn end(&self) -> SourcePos {
14474    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14475  }
14476}
14477
14478impl<'a> From<&JSXText<'a>> for Node<'a> {
14479  fn from(node: &JSXText<'a>) -> Node<'a> {
14480    let node = unsafe { mem::transmute::<&JSXText<'a>, &'a JSXText<'a>>(node) };
14481    Node::JSXText(node)
14482  }
14483}
14484
14485impl<'a> NodeTrait<'a> for JSXText<'a> {
14486  fn parent(&self) -> Option<Node<'a>> {
14487    Some(self.parent.get().unwrap().clone())
14488  }
14489
14490  fn children(&self) -> Vec<Node<'a>> {
14491    Vec::with_capacity(0)
14492  }
14493
14494  fn as_node(&self) -> Node<'a> {
14495    self.into()
14496  }
14497
14498  fn kind(&self) -> NodeKind {
14499    NodeKind::JSXText
14500  }
14501}
14502
14503impl<'a> CastableNode<'a> for JSXText<'a> {
14504  fn to(node: &Node<'a>) -> Option<&'a Self> {
14505    if let Node::JSXText(node) = node {
14506      Some(node)
14507    } else {
14508      None
14509    }
14510  }
14511
14512  fn kind() -> NodeKind {
14513    NodeKind::JSXText
14514  }
14515}
14516
14517fn get_view_for_jsxtext<'a>(inner: &'a swc_ast::JSXText, bump: &'a Bump) -> &'a JSXText<'a> {
14518  let node = bump.alloc(JSXText {
14519    inner,
14520    parent: Default::default(),
14521  });
14522  node
14523}
14524
14525fn set_parent_for_jsxtext<'a>(node: &JSXText<'a>, parent: Node<'a>) {
14526  node.parent.set(parent);
14527}
14528
14529/// `{key: value}`
14530#[derive(Clone)]
14531pub struct KeyValuePatProp<'a> {
14532  parent: ParentOnceCell<&'a ObjectPat<'a>>,
14533  pub inner: &'a swc_ast::KeyValuePatProp,
14534  pub key: PropName<'a>,
14535  pub value: Pat<'a>,
14536}
14537
14538impl<'a> KeyValuePatProp<'a> {
14539  pub fn parent(&self) -> &'a ObjectPat<'a> {
14540    self.parent.get().unwrap()
14541  }
14542}
14543
14544impl<'a> SourceRanged for KeyValuePatProp<'a> {
14545  fn start(&self) -> SourcePos {
14546    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14547  }
14548  fn end(&self) -> SourcePos {
14549    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14550  }
14551}
14552
14553impl<'a> From<&KeyValuePatProp<'a>> for Node<'a> {
14554  fn from(node: &KeyValuePatProp<'a>) -> Node<'a> {
14555    let node = unsafe { mem::transmute::<&KeyValuePatProp<'a>, &'a KeyValuePatProp<'a>>(node) };
14556    Node::KeyValuePatProp(node)
14557  }
14558}
14559
14560impl<'a> NodeTrait<'a> for KeyValuePatProp<'a> {
14561  fn parent(&self) -> Option<Node<'a>> {
14562    Some(self.parent.get().unwrap().into())
14563  }
14564
14565  fn children(&self) -> Vec<Node<'a>> {
14566    let mut children = Vec::with_capacity(2);
14567    children.push((&self.key).into());
14568    children.push((&self.value).into());
14569    children
14570  }
14571
14572  fn as_node(&self) -> Node<'a> {
14573    self.into()
14574  }
14575
14576  fn kind(&self) -> NodeKind {
14577    NodeKind::KeyValuePatProp
14578  }
14579}
14580
14581impl<'a> CastableNode<'a> for KeyValuePatProp<'a> {
14582  fn to(node: &Node<'a>) -> Option<&'a Self> {
14583    if let Node::KeyValuePatProp(node) = node {
14584      Some(node)
14585    } else {
14586      None
14587    }
14588  }
14589
14590  fn kind() -> NodeKind {
14591    NodeKind::KeyValuePatProp
14592  }
14593}
14594
14595fn get_view_for_key_value_pat_prop<'a>(inner: &'a swc_ast::KeyValuePatProp, bump: &'a Bump) -> &'a KeyValuePatProp<'a> {
14596  let node = bump.alloc(KeyValuePatProp {
14597    inner,
14598    parent: Default::default(),
14599    key: get_view_for_prop_name(&inner.key, bump),
14600    value: get_view_for_pat(&inner.value, bump),
14601  });
14602  let parent: Node<'a> = (&*node).into();
14603  set_parent_for_prop_name(&node.key, parent);
14604  set_parent_for_pat(&node.value, parent);
14605  node
14606}
14607
14608fn set_parent_for_key_value_pat_prop<'a>(node: &KeyValuePatProp<'a>, parent: Node<'a>) {
14609  node.parent.set(parent.expect::<ObjectPat>());
14610}
14611
14612#[derive(Clone)]
14613pub struct KeyValueProp<'a> {
14614  parent: ParentOnceCell<&'a ObjectLit<'a>>,
14615  pub inner: &'a swc_ast::KeyValueProp,
14616  pub key: PropName<'a>,
14617  pub value: Expr<'a>,
14618}
14619
14620impl<'a> KeyValueProp<'a> {
14621  pub fn parent(&self) -> &'a ObjectLit<'a> {
14622    self.parent.get().unwrap()
14623  }
14624}
14625
14626impl<'a> SourceRanged for KeyValueProp<'a> {
14627  fn start(&self) -> SourcePos {
14628    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14629  }
14630  fn end(&self) -> SourcePos {
14631    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14632  }
14633}
14634
14635impl<'a> From<&KeyValueProp<'a>> for Node<'a> {
14636  fn from(node: &KeyValueProp<'a>) -> Node<'a> {
14637    let node = unsafe { mem::transmute::<&KeyValueProp<'a>, &'a KeyValueProp<'a>>(node) };
14638    Node::KeyValueProp(node)
14639  }
14640}
14641
14642impl<'a> NodeTrait<'a> for KeyValueProp<'a> {
14643  fn parent(&self) -> Option<Node<'a>> {
14644    Some(self.parent.get().unwrap().into())
14645  }
14646
14647  fn children(&self) -> Vec<Node<'a>> {
14648    let mut children = Vec::with_capacity(2);
14649    children.push((&self.key).into());
14650    children.push((&self.value).into());
14651    children
14652  }
14653
14654  fn as_node(&self) -> Node<'a> {
14655    self.into()
14656  }
14657
14658  fn kind(&self) -> NodeKind {
14659    NodeKind::KeyValueProp
14660  }
14661}
14662
14663impl<'a> CastableNode<'a> for KeyValueProp<'a> {
14664  fn to(node: &Node<'a>) -> Option<&'a Self> {
14665    if let Node::KeyValueProp(node) = node {
14666      Some(node)
14667    } else {
14668      None
14669    }
14670  }
14671
14672  fn kind() -> NodeKind {
14673    NodeKind::KeyValueProp
14674  }
14675}
14676
14677fn get_view_for_key_value_prop<'a>(inner: &'a swc_ast::KeyValueProp, bump: &'a Bump) -> &'a KeyValueProp<'a> {
14678  let node = bump.alloc(KeyValueProp {
14679    inner,
14680    parent: Default::default(),
14681    key: get_view_for_prop_name(&inner.key, bump),
14682    value: get_view_for_expr(&inner.value, bump),
14683  });
14684  let parent: Node<'a> = (&*node).into();
14685  set_parent_for_prop_name(&node.key, parent);
14686  set_parent_for_expr(&node.value, parent);
14687  node
14688}
14689
14690fn set_parent_for_key_value_prop<'a>(node: &KeyValueProp<'a>, parent: Node<'a>) {
14691  node.parent.set(parent.expect::<ObjectLit>());
14692}
14693
14694#[derive(Clone)]
14695pub struct LabeledStmt<'a> {
14696  parent: ParentOnceCell<Node<'a>>,
14697  pub inner: &'a swc_ast::LabeledStmt,
14698  pub label: &'a Ident<'a>,
14699  pub body: Stmt<'a>,
14700}
14701
14702impl<'a> LabeledStmt<'a> {
14703  pub fn parent(&self) -> Node<'a> {
14704    self.parent.get().unwrap()
14705  }
14706}
14707
14708impl<'a> SourceRanged for LabeledStmt<'a> {
14709  fn start(&self) -> SourcePos {
14710    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14711  }
14712  fn end(&self) -> SourcePos {
14713    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14714  }
14715}
14716
14717impl<'a> From<&LabeledStmt<'a>> for Node<'a> {
14718  fn from(node: &LabeledStmt<'a>) -> Node<'a> {
14719    let node = unsafe { mem::transmute::<&LabeledStmt<'a>, &'a LabeledStmt<'a>>(node) };
14720    Node::LabeledStmt(node)
14721  }
14722}
14723
14724impl<'a> NodeTrait<'a> for LabeledStmt<'a> {
14725  fn parent(&self) -> Option<Node<'a>> {
14726    Some(self.parent.get().unwrap().clone())
14727  }
14728
14729  fn children(&self) -> Vec<Node<'a>> {
14730    let mut children = Vec::with_capacity(2);
14731    children.push(self.label.into());
14732    children.push((&self.body).into());
14733    children
14734  }
14735
14736  fn as_node(&self) -> Node<'a> {
14737    self.into()
14738  }
14739
14740  fn kind(&self) -> NodeKind {
14741    NodeKind::LabeledStmt
14742  }
14743}
14744
14745impl<'a> CastableNode<'a> for LabeledStmt<'a> {
14746  fn to(node: &Node<'a>) -> Option<&'a Self> {
14747    if let Node::LabeledStmt(node) = node {
14748      Some(node)
14749    } else {
14750      None
14751    }
14752  }
14753
14754  fn kind() -> NodeKind {
14755    NodeKind::LabeledStmt
14756  }
14757}
14758
14759fn get_view_for_labeled_stmt<'a>(inner: &'a swc_ast::LabeledStmt, bump: &'a Bump) -> &'a LabeledStmt<'a> {
14760  let node = bump.alloc(LabeledStmt {
14761    inner,
14762    parent: Default::default(),
14763    label: get_view_for_ident(&inner.label, bump),
14764    body: get_view_for_stmt(&inner.body, bump),
14765  });
14766  let parent: Node<'a> = (&*node).into();
14767  set_parent_for_ident(&node.label, parent);
14768  set_parent_for_stmt(&node.body, parent);
14769  node
14770}
14771
14772fn set_parent_for_labeled_stmt<'a>(node: &LabeledStmt<'a>, parent: Node<'a>) {
14773  node.parent.set(parent);
14774}
14775
14776#[derive(Clone)]
14777pub struct MemberExpr<'a> {
14778  parent: ParentOnceCell<Node<'a>>,
14779  pub inner: &'a swc_ast::MemberExpr,
14780  pub obj: Expr<'a>,
14781  pub prop: MemberProp<'a>,
14782}
14783
14784impl<'a> MemberExpr<'a> {
14785  pub fn parent(&self) -> Node<'a> {
14786    self.parent.get().unwrap()
14787  }
14788}
14789
14790impl<'a> SourceRanged for MemberExpr<'a> {
14791  fn start(&self) -> SourcePos {
14792    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14793  }
14794  fn end(&self) -> SourcePos {
14795    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14796  }
14797}
14798
14799impl<'a> From<&MemberExpr<'a>> for Node<'a> {
14800  fn from(node: &MemberExpr<'a>) -> Node<'a> {
14801    let node = unsafe { mem::transmute::<&MemberExpr<'a>, &'a MemberExpr<'a>>(node) };
14802    Node::MemberExpr(node)
14803  }
14804}
14805
14806impl<'a> NodeTrait<'a> for MemberExpr<'a> {
14807  fn parent(&self) -> Option<Node<'a>> {
14808    Some(self.parent.get().unwrap().clone())
14809  }
14810
14811  fn children(&self) -> Vec<Node<'a>> {
14812    let mut children = Vec::with_capacity(2);
14813    children.push((&self.obj).into());
14814    children.push((&self.prop).into());
14815    children
14816  }
14817
14818  fn as_node(&self) -> Node<'a> {
14819    self.into()
14820  }
14821
14822  fn kind(&self) -> NodeKind {
14823    NodeKind::MemberExpr
14824  }
14825}
14826
14827impl<'a> CastableNode<'a> for MemberExpr<'a> {
14828  fn to(node: &Node<'a>) -> Option<&'a Self> {
14829    if let Node::MemberExpr(node) = node {
14830      Some(node)
14831    } else {
14832      None
14833    }
14834  }
14835
14836  fn kind() -> NodeKind {
14837    NodeKind::MemberExpr
14838  }
14839}
14840
14841fn get_view_for_member_expr<'a>(inner: &'a swc_ast::MemberExpr, bump: &'a Bump) -> &'a MemberExpr<'a> {
14842  let node = bump.alloc(MemberExpr {
14843    inner,
14844    parent: Default::default(),
14845    obj: get_view_for_expr(&inner.obj, bump),
14846    prop: get_view_for_member_prop(&inner.prop, bump),
14847  });
14848  let parent: Node<'a> = (&*node).into();
14849  set_parent_for_expr(&node.obj, parent);
14850  set_parent_for_member_prop(&node.prop, parent);
14851  node
14852}
14853
14854fn set_parent_for_member_expr<'a>(node: &MemberExpr<'a>, parent: Node<'a>) {
14855  node.parent.set(parent);
14856}
14857
14858#[derive(Clone)]
14859pub struct MetaPropExpr<'a> {
14860  parent: ParentOnceCell<Node<'a>>,
14861  pub inner: &'a swc_ast::MetaPropExpr,
14862}
14863
14864impl<'a> MetaPropExpr<'a> {
14865  pub fn parent(&self) -> Node<'a> {
14866    self.parent.get().unwrap()
14867  }
14868
14869  pub fn prop_kind(&self) -> MetaPropKind {
14870    self.inner.kind
14871  }
14872}
14873
14874impl<'a> SourceRanged for MetaPropExpr<'a> {
14875  fn start(&self) -> SourcePos {
14876    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14877  }
14878  fn end(&self) -> SourcePos {
14879    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14880  }
14881}
14882
14883impl<'a> From<&MetaPropExpr<'a>> for Node<'a> {
14884  fn from(node: &MetaPropExpr<'a>) -> Node<'a> {
14885    let node = unsafe { mem::transmute::<&MetaPropExpr<'a>, &'a MetaPropExpr<'a>>(node) };
14886    Node::MetaPropExpr(node)
14887  }
14888}
14889
14890impl<'a> NodeTrait<'a> for MetaPropExpr<'a> {
14891  fn parent(&self) -> Option<Node<'a>> {
14892    Some(self.parent.get().unwrap().clone())
14893  }
14894
14895  fn children(&self) -> Vec<Node<'a>> {
14896    Vec::with_capacity(0)
14897  }
14898
14899  fn as_node(&self) -> Node<'a> {
14900    self.into()
14901  }
14902
14903  fn kind(&self) -> NodeKind {
14904    NodeKind::MetaPropExpr
14905  }
14906}
14907
14908impl<'a> CastableNode<'a> for MetaPropExpr<'a> {
14909  fn to(node: &Node<'a>) -> Option<&'a Self> {
14910    if let Node::MetaPropExpr(node) = node {
14911      Some(node)
14912    } else {
14913      None
14914    }
14915  }
14916
14917  fn kind() -> NodeKind {
14918    NodeKind::MetaPropExpr
14919  }
14920}
14921
14922fn get_view_for_meta_prop_expr<'a>(inner: &'a swc_ast::MetaPropExpr, bump: &'a Bump) -> &'a MetaPropExpr<'a> {
14923  let node = bump.alloc(MetaPropExpr {
14924    inner,
14925    parent: Default::default(),
14926  });
14927  node
14928}
14929
14930fn set_parent_for_meta_prop_expr<'a>(node: &MetaPropExpr<'a>, parent: Node<'a>) {
14931  node.parent.set(parent);
14932}
14933
14934#[derive(Clone)]
14935pub struct MethodProp<'a> {
14936  parent: ParentOnceCell<&'a ObjectLit<'a>>,
14937  pub inner: &'a swc_ast::MethodProp,
14938  pub key: PropName<'a>,
14939  pub function: &'a Function<'a>,
14940}
14941
14942impl<'a> MethodProp<'a> {
14943  pub fn parent(&self) -> &'a ObjectLit<'a> {
14944    self.parent.get().unwrap()
14945  }
14946}
14947
14948impl<'a> SourceRanged for MethodProp<'a> {
14949  fn start(&self) -> SourcePos {
14950    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14951  }
14952  fn end(&self) -> SourcePos {
14953    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14954  }
14955}
14956
14957impl<'a> From<&MethodProp<'a>> for Node<'a> {
14958  fn from(node: &MethodProp<'a>) -> Node<'a> {
14959    let node = unsafe { mem::transmute::<&MethodProp<'a>, &'a MethodProp<'a>>(node) };
14960    Node::MethodProp(node)
14961  }
14962}
14963
14964impl<'a> NodeTrait<'a> for MethodProp<'a> {
14965  fn parent(&self) -> Option<Node<'a>> {
14966    Some(self.parent.get().unwrap().into())
14967  }
14968
14969  fn children(&self) -> Vec<Node<'a>> {
14970    let mut children = Vec::with_capacity(2);
14971    children.push((&self.key).into());
14972    children.push(self.function.into());
14973    children
14974  }
14975
14976  fn as_node(&self) -> Node<'a> {
14977    self.into()
14978  }
14979
14980  fn kind(&self) -> NodeKind {
14981    NodeKind::MethodProp
14982  }
14983}
14984
14985impl<'a> CastableNode<'a> for MethodProp<'a> {
14986  fn to(node: &Node<'a>) -> Option<&'a Self> {
14987    if let Node::MethodProp(node) = node {
14988      Some(node)
14989    } else {
14990      None
14991    }
14992  }
14993
14994  fn kind() -> NodeKind {
14995    NodeKind::MethodProp
14996  }
14997}
14998
14999fn get_view_for_method_prop<'a>(inner: &'a swc_ast::MethodProp, bump: &'a Bump) -> &'a MethodProp<'a> {
15000  let node = bump.alloc(MethodProp {
15001    inner,
15002    parent: Default::default(),
15003    key: get_view_for_prop_name(&inner.key, bump),
15004    function: get_view_for_function(&inner.function, bump),
15005  });
15006  let parent: Node<'a> = (&*node).into();
15007  set_parent_for_prop_name(&node.key, parent);
15008  set_parent_for_function(&node.function, parent);
15009  node
15010}
15011
15012fn set_parent_for_method_prop<'a>(node: &MethodProp<'a>, parent: Node<'a>) {
15013  node.parent.set(parent.expect::<ObjectLit>());
15014}
15015
15016#[derive(Clone)]
15017pub struct Module<'a> {
15018  pub text_info: Option<&'a SourceTextInfo>,
15019  pub tokens: Option<&'a TokenContainer<'a>>,
15020  pub comments: Option<&'a CommentContainer<'a>>,
15021  pub inner: &'a swc_ast::Module,
15022  pub body: &'a [ModuleItem<'a>],
15023}
15024
15025impl<'a> Module<'a> {
15026  pub fn shebang(&self) -> &Option<swc_atoms::Atom> {
15027    &self.inner.shebang
15028  }
15029}
15030
15031impl<'a> SourceRanged for Module<'a> {
15032  fn start(&self) -> SourcePos {
15033    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15034  }
15035  fn end(&self) -> SourcePos {
15036    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15037  }
15038}
15039
15040impl<'a> From<&Module<'a>> for Node<'a> {
15041  fn from(node: &Module<'a>) -> Node<'a> {
15042    let node = unsafe { mem::transmute::<&Module<'a>, &'a Module<'a>>(node) };
15043    Node::Module(node)
15044  }
15045}
15046
15047impl<'a> NodeTrait<'a> for Module<'a> {
15048  fn parent(&self) -> Option<Node<'a>> {
15049    None
15050  }
15051
15052  fn children(&self) -> Vec<Node<'a>> {
15053    let mut children = Vec::with_capacity(self.body.len());
15054    for child in self.body.iter() {
15055      children.push(child.into());
15056    }
15057    children
15058  }
15059
15060  fn as_node(&self) -> Node<'a> {
15061    self.into()
15062  }
15063
15064  fn kind(&self) -> NodeKind {
15065    NodeKind::Module
15066  }
15067}
15068
15069impl<'a> CastableNode<'a> for Module<'a> {
15070  fn to(node: &Node<'a>) -> Option<&'a Self> {
15071    if let Node::Module(node) = node {
15072      Some(node)
15073    } else {
15074      None
15075    }
15076  }
15077
15078  fn kind() -> NodeKind {
15079    NodeKind::Module
15080  }
15081}
15082
15083fn get_view_for_module<'a>(source_file_info: &'a ModuleInfo<'a>, tokens: Option<&'a TokenContainer<'a>>, comments: Option<&'a CommentContainer<'a>>, bump: &'a Bump) -> &'a Module<'a> {
15084  let inner = source_file_info.module;
15085  let node = bump.alloc(Module {
15086    inner,
15087    text_info: source_file_info.text_info,
15088    tokens,
15089    comments,
15090    body: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.body.len(), bump);vec.extend(inner.body.iter().map(|value| get_view_for_module_item(value, bump))); vec }),
15091  });
15092  let parent: Node<'a> = (&*node).into();
15093  for value in node.body.iter() {
15094    set_parent_for_module_item(value, parent)
15095  }
15096  node
15097}
15098
15099/// `export { foo } from 'mod'`
15100/// `export { foo as bar } from 'mod'`
15101#[derive(Clone)]
15102pub struct NamedExport<'a> {
15103  parent: ParentOnceCell<Node<'a>>,
15104  pub inner: &'a swc_ast::NamedExport,
15105  pub specifiers: &'a [ExportSpecifier<'a>],
15106  pub src: Option<&'a Str<'a>>,
15107  pub with: Option<&'a ObjectLit<'a>>,
15108}
15109
15110impl<'a> NamedExport<'a> {
15111  pub fn parent(&self) -> Node<'a> {
15112    self.parent.get().unwrap()
15113  }
15114
15115  pub fn type_only(&self) -> bool {
15116    self.inner.type_only
15117  }
15118}
15119
15120impl<'a> SourceRanged for NamedExport<'a> {
15121  fn start(&self) -> SourcePos {
15122    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15123  }
15124  fn end(&self) -> SourcePos {
15125    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15126  }
15127}
15128
15129impl<'a> From<&NamedExport<'a>> for Node<'a> {
15130  fn from(node: &NamedExport<'a>) -> Node<'a> {
15131    let node = unsafe { mem::transmute::<&NamedExport<'a>, &'a NamedExport<'a>>(node) };
15132    Node::NamedExport(node)
15133  }
15134}
15135
15136impl<'a> NodeTrait<'a> for NamedExport<'a> {
15137  fn parent(&self) -> Option<Node<'a>> {
15138    Some(self.parent.get().unwrap().clone())
15139  }
15140
15141  fn children(&self) -> Vec<Node<'a>> {
15142    let mut children = Vec::with_capacity(self.specifiers.len() + match &self.src { Some(_value) => 1, None => 0, } + match &self.with { Some(_value) => 1, None => 0, });
15143    for child in self.specifiers.iter() {
15144      children.push(child.into());
15145    }
15146    if let Some(child) = self.src {
15147      children.push(child.into());
15148    }
15149    if let Some(child) = self.with {
15150      children.push(child.into());
15151    }
15152    children
15153  }
15154
15155  fn as_node(&self) -> Node<'a> {
15156    self.into()
15157  }
15158
15159  fn kind(&self) -> NodeKind {
15160    NodeKind::NamedExport
15161  }
15162}
15163
15164impl<'a> CastableNode<'a> for NamedExport<'a> {
15165  fn to(node: &Node<'a>) -> Option<&'a Self> {
15166    if let Node::NamedExport(node) = node {
15167      Some(node)
15168    } else {
15169      None
15170    }
15171  }
15172
15173  fn kind() -> NodeKind {
15174    NodeKind::NamedExport
15175  }
15176}
15177
15178fn get_view_for_named_export<'a>(inner: &'a swc_ast::NamedExport, bump: &'a Bump) -> &'a NamedExport<'a> {
15179  let node = bump.alloc(NamedExport {
15180    inner,
15181    parent: Default::default(),
15182    specifiers: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.specifiers.len(), bump);vec.extend(inner.specifiers.iter().map(|value| get_view_for_export_specifier(value, bump))); vec }),
15183    src: match &inner.src {
15184      Some(value) => Some(get_view_for_str(value, bump)),
15185      None => None,
15186    },
15187    with: match &inner.with {
15188      Some(value) => Some(get_view_for_object_lit(value, bump)),
15189      None => None,
15190    },
15191  });
15192  let parent: Node<'a> = (&*node).into();
15193  for value in node.specifiers.iter() {
15194    set_parent_for_export_specifier(value, parent)
15195  }
15196  if let Some(value) = &node.src {
15197    set_parent_for_str(value, parent)
15198  };
15199  if let Some(value) = &node.with {
15200    set_parent_for_object_lit(value, parent)
15201  };
15202  node
15203}
15204
15205fn set_parent_for_named_export<'a>(node: &NamedExport<'a>, parent: Node<'a>) {
15206  node.parent.set(parent);
15207}
15208
15209#[derive(Clone)]
15210pub struct NewExpr<'a> {
15211  parent: ParentOnceCell<Node<'a>>,
15212  pub inner: &'a swc_ast::NewExpr,
15213  pub callee: Expr<'a>,
15214  pub args: Option<&'a [&'a ExprOrSpread<'a>]>,
15215  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
15216}
15217
15218impl<'a> NewExpr<'a> {
15219  pub fn parent(&self) -> Node<'a> {
15220    self.parent.get().unwrap()
15221  }
15222
15223  pub fn ctxt(&self) -> swc_common::SyntaxContext {
15224    self.inner.ctxt
15225  }
15226}
15227
15228impl<'a> SourceRanged for NewExpr<'a> {
15229  fn start(&self) -> SourcePos {
15230    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15231  }
15232  fn end(&self) -> SourcePos {
15233    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15234  }
15235}
15236
15237impl<'a> From<&NewExpr<'a>> for Node<'a> {
15238  fn from(node: &NewExpr<'a>) -> Node<'a> {
15239    let node = unsafe { mem::transmute::<&NewExpr<'a>, &'a NewExpr<'a>>(node) };
15240    Node::NewExpr(node)
15241  }
15242}
15243
15244impl<'a> NodeTrait<'a> for NewExpr<'a> {
15245  fn parent(&self) -> Option<Node<'a>> {
15246    Some(self.parent.get().unwrap().clone())
15247  }
15248
15249  fn children(&self) -> Vec<Node<'a>> {
15250    let mut children = Vec::with_capacity(1 + match &self.args { Some(_value) => _value.len(), None => 0, } + match &self.type_args { Some(_value) => 1, None => 0, });
15251    children.push((&self.callee).into());
15252    if let Some(child) = self.args.as_ref() {
15253      for child in child.iter() {
15254        children.push((*child).into());
15255      }
15256    }
15257    if let Some(child) = self.type_args {
15258      children.push(child.into());
15259    }
15260    children
15261  }
15262
15263  fn as_node(&self) -> Node<'a> {
15264    self.into()
15265  }
15266
15267  fn kind(&self) -> NodeKind {
15268    NodeKind::NewExpr
15269  }
15270}
15271
15272impl<'a> CastableNode<'a> for NewExpr<'a> {
15273  fn to(node: &Node<'a>) -> Option<&'a Self> {
15274    if let Node::NewExpr(node) = node {
15275      Some(node)
15276    } else {
15277      None
15278    }
15279  }
15280
15281  fn kind() -> NodeKind {
15282    NodeKind::NewExpr
15283  }
15284}
15285
15286fn get_view_for_new_expr<'a>(inner: &'a swc_ast::NewExpr, bump: &'a Bump) -> &'a NewExpr<'a> {
15287  let node = bump.alloc(NewExpr {
15288    inner,
15289    parent: Default::default(),
15290    callee: get_view_for_expr(&inner.callee, bump),
15291    args: match &inner.args {
15292      Some(value) => Some(bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(value.len(), bump);vec.extend(value.iter().map(|value| get_view_for_expr_or_spread(value, bump))); vec })),
15293      None => None,
15294    },
15295    type_args: match &inner.type_args {
15296      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
15297      None => None,
15298    },
15299  });
15300  let parent: Node<'a> = (&*node).into();
15301  set_parent_for_expr(&node.callee, parent);
15302  if let Some(value) = &node.args {
15303    for value in value.iter() {
15304      set_parent_for_expr_or_spread(value, parent)
15305    }
15306  };
15307  if let Some(value) = &node.type_args {
15308    set_parent_for_ts_type_param_instantiation(value, parent)
15309  };
15310  node
15311}
15312
15313fn set_parent_for_new_expr<'a>(node: &NewExpr<'a>, parent: Node<'a>) {
15314  node.parent.set(parent);
15315}
15316
15317#[derive(Clone)]
15318pub struct Null<'a> {
15319  parent: ParentOnceCell<Node<'a>>,
15320  pub inner: &'a swc_ast::Null,
15321}
15322
15323impl<'a> Null<'a> {
15324  pub fn parent(&self) -> Node<'a> {
15325    self.parent.get().unwrap()
15326  }
15327}
15328
15329impl<'a> SourceRanged for Null<'a> {
15330  fn start(&self) -> SourcePos {
15331    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15332  }
15333  fn end(&self) -> SourcePos {
15334    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15335  }
15336}
15337
15338impl<'a> From<&Null<'a>> for Node<'a> {
15339  fn from(node: &Null<'a>) -> Node<'a> {
15340    let node = unsafe { mem::transmute::<&Null<'a>, &'a Null<'a>>(node) };
15341    Node::Null(node)
15342  }
15343}
15344
15345impl<'a> NodeTrait<'a> for Null<'a> {
15346  fn parent(&self) -> Option<Node<'a>> {
15347    Some(self.parent.get().unwrap().clone())
15348  }
15349
15350  fn children(&self) -> Vec<Node<'a>> {
15351    Vec::with_capacity(0)
15352  }
15353
15354  fn as_node(&self) -> Node<'a> {
15355    self.into()
15356  }
15357
15358  fn kind(&self) -> NodeKind {
15359    NodeKind::Null
15360  }
15361}
15362
15363impl<'a> CastableNode<'a> for Null<'a> {
15364  fn to(node: &Node<'a>) -> Option<&'a Self> {
15365    if let Node::Null(node) = node {
15366      Some(node)
15367    } else {
15368      None
15369    }
15370  }
15371
15372  fn kind() -> NodeKind {
15373    NodeKind::Null
15374  }
15375}
15376
15377fn get_view_for_null<'a>(inner: &'a swc_ast::Null, bump: &'a Bump) -> &'a Null<'a> {
15378  let node = bump.alloc(Null {
15379    inner,
15380    parent: Default::default(),
15381  });
15382  node
15383}
15384
15385fn set_parent_for_null<'a>(node: &Null<'a>, parent: Node<'a>) {
15386  node.parent.set(parent);
15387}
15388
15389/// A numeric literal.
15390///
15391///
15392/// # Creation
15393///
15394/// If you are creating a numeric literal with a dummy span, please use
15395/// `literal.into()`, instead of creating this struct directly.
15396///
15397/// All of `Box<Expr>`, `Expr`, `Lit`, `Number` implements `From<64>` and
15398/// `From<usize>`.
15399#[derive(Clone)]
15400pub struct Number<'a> {
15401  parent: ParentOnceCell<Node<'a>>,
15402  pub inner: &'a swc_ast::Number,
15403}
15404
15405impl<'a> Number<'a> {
15406  pub fn parent(&self) -> Node<'a> {
15407    self.parent.get().unwrap()
15408  }
15409
15410  /// **Note**: This should not be `NaN`. Use [crate::Ident] to represent NaN.
15411  ///
15412  /// If you store `NaN` in this field, a hash map will behave strangely.
15413  pub fn value(&self) -> f64 {
15414    self.inner.value
15415  }
15416
15417  /// Use `None` value only for transformations to avoid recalculate
15418  /// characters in number literal
15419  pub fn raw(&self) -> &Option<swc_atoms::Atom> {
15420    &self.inner.raw
15421  }
15422}
15423
15424impl<'a> SourceRanged for Number<'a> {
15425  fn start(&self) -> SourcePos {
15426    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15427  }
15428  fn end(&self) -> SourcePos {
15429    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15430  }
15431}
15432
15433impl<'a> From<&Number<'a>> for Node<'a> {
15434  fn from(node: &Number<'a>) -> Node<'a> {
15435    let node = unsafe { mem::transmute::<&Number<'a>, &'a Number<'a>>(node) };
15436    Node::Number(node)
15437  }
15438}
15439
15440impl<'a> NodeTrait<'a> for Number<'a> {
15441  fn parent(&self) -> Option<Node<'a>> {
15442    Some(self.parent.get().unwrap().clone())
15443  }
15444
15445  fn children(&self) -> Vec<Node<'a>> {
15446    Vec::with_capacity(0)
15447  }
15448
15449  fn as_node(&self) -> Node<'a> {
15450    self.into()
15451  }
15452
15453  fn kind(&self) -> NodeKind {
15454    NodeKind::Number
15455  }
15456}
15457
15458impl<'a> CastableNode<'a> for Number<'a> {
15459  fn to(node: &Node<'a>) -> Option<&'a Self> {
15460    if let Node::Number(node) = node {
15461      Some(node)
15462    } else {
15463      None
15464    }
15465  }
15466
15467  fn kind() -> NodeKind {
15468    NodeKind::Number
15469  }
15470}
15471
15472fn get_view_for_number<'a>(inner: &'a swc_ast::Number, bump: &'a Bump) -> &'a Number<'a> {
15473  let node = bump.alloc(Number {
15474    inner,
15475    parent: Default::default(),
15476  });
15477  node
15478}
15479
15480fn set_parent_for_number<'a>(node: &Number<'a>, parent: Node<'a>) {
15481  node.parent.set(parent);
15482}
15483
15484/// Object literal.
15485#[derive(Clone)]
15486pub struct ObjectLit<'a> {
15487  parent: ParentOnceCell<Node<'a>>,
15488  pub inner: &'a swc_ast::ObjectLit,
15489  pub props: &'a [PropOrSpread<'a>],
15490}
15491
15492impl<'a> ObjectLit<'a> {
15493  pub fn parent(&self) -> Node<'a> {
15494    self.parent.get().unwrap()
15495  }
15496}
15497
15498impl<'a> SourceRanged for ObjectLit<'a> {
15499  fn start(&self) -> SourcePos {
15500    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15501  }
15502  fn end(&self) -> SourcePos {
15503    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15504  }
15505}
15506
15507impl<'a> From<&ObjectLit<'a>> for Node<'a> {
15508  fn from(node: &ObjectLit<'a>) -> Node<'a> {
15509    let node = unsafe { mem::transmute::<&ObjectLit<'a>, &'a ObjectLit<'a>>(node) };
15510    Node::ObjectLit(node)
15511  }
15512}
15513
15514impl<'a> NodeTrait<'a> for ObjectLit<'a> {
15515  fn parent(&self) -> Option<Node<'a>> {
15516    Some(self.parent.get().unwrap().clone())
15517  }
15518
15519  fn children(&self) -> Vec<Node<'a>> {
15520    let mut children = Vec::with_capacity(self.props.len());
15521    for child in self.props.iter() {
15522      children.push(child.into());
15523    }
15524    children
15525  }
15526
15527  fn as_node(&self) -> Node<'a> {
15528    self.into()
15529  }
15530
15531  fn kind(&self) -> NodeKind {
15532    NodeKind::ObjectLit
15533  }
15534}
15535
15536impl<'a> CastableNode<'a> for ObjectLit<'a> {
15537  fn to(node: &Node<'a>) -> Option<&'a Self> {
15538    if let Node::ObjectLit(node) = node {
15539      Some(node)
15540    } else {
15541      None
15542    }
15543  }
15544
15545  fn kind() -> NodeKind {
15546    NodeKind::ObjectLit
15547  }
15548}
15549
15550fn get_view_for_object_lit<'a>(inner: &'a swc_ast::ObjectLit, bump: &'a Bump) -> &'a ObjectLit<'a> {
15551  let node = bump.alloc(ObjectLit {
15552    inner,
15553    parent: Default::default(),
15554    props: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.props.len(), bump);vec.extend(inner.props.iter().map(|value| get_view_for_prop_or_spread(value, bump))); vec }),
15555  });
15556  let parent: Node<'a> = (&*node).into();
15557  for value in node.props.iter() {
15558    set_parent_for_prop_or_spread(value, parent)
15559  }
15560  node
15561}
15562
15563fn set_parent_for_object_lit<'a>(node: &ObjectLit<'a>, parent: Node<'a>) {
15564  node.parent.set(parent);
15565}
15566
15567#[derive(Clone)]
15568pub struct ObjectPat<'a> {
15569  parent: ParentOnceCell<Node<'a>>,
15570  pub inner: &'a swc_ast::ObjectPat,
15571  pub props: &'a [ObjectPatProp<'a>],
15572  pub type_ann: Option<&'a TsTypeAnn<'a>>,
15573}
15574
15575impl<'a> ObjectPat<'a> {
15576  pub fn parent(&self) -> Node<'a> {
15577    self.parent.get().unwrap()
15578  }
15579
15580  /// Only in an ambient context
15581  pub fn optional(&self) -> bool {
15582    self.inner.optional
15583  }
15584}
15585
15586impl<'a> SourceRanged for ObjectPat<'a> {
15587  fn start(&self) -> SourcePos {
15588    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15589  }
15590  fn end(&self) -> SourcePos {
15591    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15592  }
15593}
15594
15595impl<'a> From<&ObjectPat<'a>> for Node<'a> {
15596  fn from(node: &ObjectPat<'a>) -> Node<'a> {
15597    let node = unsafe { mem::transmute::<&ObjectPat<'a>, &'a ObjectPat<'a>>(node) };
15598    Node::ObjectPat(node)
15599  }
15600}
15601
15602impl<'a> NodeTrait<'a> for ObjectPat<'a> {
15603  fn parent(&self) -> Option<Node<'a>> {
15604    Some(self.parent.get().unwrap().clone())
15605  }
15606
15607  fn children(&self) -> Vec<Node<'a>> {
15608    let mut children = Vec::with_capacity(self.props.len() + match &self.type_ann { Some(_value) => 1, None => 0, });
15609    for child in self.props.iter() {
15610      children.push(child.into());
15611    }
15612    if let Some(child) = self.type_ann {
15613      children.push(child.into());
15614    }
15615    children
15616  }
15617
15618  fn as_node(&self) -> Node<'a> {
15619    self.into()
15620  }
15621
15622  fn kind(&self) -> NodeKind {
15623    NodeKind::ObjectPat
15624  }
15625}
15626
15627impl<'a> CastableNode<'a> for ObjectPat<'a> {
15628  fn to(node: &Node<'a>) -> Option<&'a Self> {
15629    if let Node::ObjectPat(node) = node {
15630      Some(node)
15631    } else {
15632      None
15633    }
15634  }
15635
15636  fn kind() -> NodeKind {
15637    NodeKind::ObjectPat
15638  }
15639}
15640
15641fn get_view_for_object_pat<'a>(inner: &'a swc_ast::ObjectPat, bump: &'a Bump) -> &'a ObjectPat<'a> {
15642  let node = bump.alloc(ObjectPat {
15643    inner,
15644    parent: Default::default(),
15645    props: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.props.len(), bump);vec.extend(inner.props.iter().map(|value| get_view_for_object_pat_prop(value, bump))); vec }),
15646    type_ann: match &inner.type_ann {
15647      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
15648      None => None,
15649    },
15650  });
15651  let parent: Node<'a> = (&*node).into();
15652  for value in node.props.iter() {
15653    set_parent_for_object_pat_prop(value, parent)
15654  }
15655  if let Some(value) = &node.type_ann {
15656    set_parent_for_ts_type_ann(value, parent)
15657  };
15658  node
15659}
15660
15661fn set_parent_for_object_pat<'a>(node: &ObjectPat<'a>, parent: Node<'a>) {
15662  node.parent.set(parent);
15663}
15664
15665#[derive(Clone)]
15666pub struct OptCall<'a> {
15667  parent: ParentOnceCell<&'a OptChainExpr<'a>>,
15668  pub inner: &'a swc_ast::OptCall,
15669  pub callee: Expr<'a>,
15670  pub args: &'a [&'a ExprOrSpread<'a>],
15671  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
15672}
15673
15674impl<'a> OptCall<'a> {
15675  pub fn parent(&self) -> &'a OptChainExpr<'a> {
15676    self.parent.get().unwrap()
15677  }
15678
15679  pub fn ctxt(&self) -> swc_common::SyntaxContext {
15680    self.inner.ctxt
15681  }
15682}
15683
15684impl<'a> SourceRanged for OptCall<'a> {
15685  fn start(&self) -> SourcePos {
15686    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15687  }
15688  fn end(&self) -> SourcePos {
15689    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15690  }
15691}
15692
15693impl<'a> From<&OptCall<'a>> for Node<'a> {
15694  fn from(node: &OptCall<'a>) -> Node<'a> {
15695    let node = unsafe { mem::transmute::<&OptCall<'a>, &'a OptCall<'a>>(node) };
15696    Node::OptCall(node)
15697  }
15698}
15699
15700impl<'a> NodeTrait<'a> for OptCall<'a> {
15701  fn parent(&self) -> Option<Node<'a>> {
15702    Some(self.parent.get().unwrap().into())
15703  }
15704
15705  fn children(&self) -> Vec<Node<'a>> {
15706    let mut children = Vec::with_capacity(1 + self.args.len() + match &self.type_args { Some(_value) => 1, None => 0, });
15707    children.push((&self.callee).into());
15708    for child in self.args.iter() {
15709      children.push((*child).into());
15710    }
15711    if let Some(child) = self.type_args {
15712      children.push(child.into());
15713    }
15714    children
15715  }
15716
15717  fn as_node(&self) -> Node<'a> {
15718    self.into()
15719  }
15720
15721  fn kind(&self) -> NodeKind {
15722    NodeKind::OptCall
15723  }
15724}
15725
15726impl<'a> CastableNode<'a> for OptCall<'a> {
15727  fn to(node: &Node<'a>) -> Option<&'a Self> {
15728    if let Node::OptCall(node) = node {
15729      Some(node)
15730    } else {
15731      None
15732    }
15733  }
15734
15735  fn kind() -> NodeKind {
15736    NodeKind::OptCall
15737  }
15738}
15739
15740fn get_view_for_opt_call<'a>(inner: &'a swc_ast::OptCall, bump: &'a Bump) -> &'a OptCall<'a> {
15741  let node = bump.alloc(OptCall {
15742    inner,
15743    parent: Default::default(),
15744    callee: get_view_for_expr(&inner.callee, bump),
15745    args: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.args.len(), bump);vec.extend(inner.args.iter().map(|value| get_view_for_expr_or_spread(value, bump))); vec }),
15746    type_args: match &inner.type_args {
15747      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
15748      None => None,
15749    },
15750  });
15751  let parent: Node<'a> = (&*node).into();
15752  set_parent_for_expr(&node.callee, parent);
15753  for value in node.args.iter() {
15754    set_parent_for_expr_or_spread(value, parent)
15755  }
15756  if let Some(value) = &node.type_args {
15757    set_parent_for_ts_type_param_instantiation(value, parent)
15758  };
15759  node
15760}
15761
15762fn set_parent_for_opt_call<'a>(node: &OptCall<'a>, parent: Node<'a>) {
15763  node.parent.set(parent.expect::<OptChainExpr>());
15764}
15765
15766#[derive(Clone)]
15767pub struct OptChainExpr<'a> {
15768  parent: ParentOnceCell<Node<'a>>,
15769  pub inner: &'a swc_ast::OptChainExpr,
15770  /// This is boxed to reduce the type size of [Expr].
15771  pub base: OptChainBase<'a>,
15772}
15773
15774impl<'a> OptChainExpr<'a> {
15775  pub fn parent(&self) -> Node<'a> {
15776    self.parent.get().unwrap()
15777  }
15778
15779  pub fn optional(&self) -> bool {
15780    self.inner.optional
15781  }
15782}
15783
15784impl<'a> SourceRanged for OptChainExpr<'a> {
15785  fn start(&self) -> SourcePos {
15786    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15787  }
15788  fn end(&self) -> SourcePos {
15789    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15790  }
15791}
15792
15793impl<'a> From<&OptChainExpr<'a>> for Node<'a> {
15794  fn from(node: &OptChainExpr<'a>) -> Node<'a> {
15795    let node = unsafe { mem::transmute::<&OptChainExpr<'a>, &'a OptChainExpr<'a>>(node) };
15796    Node::OptChainExpr(node)
15797  }
15798}
15799
15800impl<'a> NodeTrait<'a> for OptChainExpr<'a> {
15801  fn parent(&self) -> Option<Node<'a>> {
15802    Some(self.parent.get().unwrap().clone())
15803  }
15804
15805  fn children(&self) -> Vec<Node<'a>> {
15806    let mut children = Vec::with_capacity(1);
15807    children.push((&self.base).into());
15808    children
15809  }
15810
15811  fn as_node(&self) -> Node<'a> {
15812    self.into()
15813  }
15814
15815  fn kind(&self) -> NodeKind {
15816    NodeKind::OptChainExpr
15817  }
15818}
15819
15820impl<'a> CastableNode<'a> for OptChainExpr<'a> {
15821  fn to(node: &Node<'a>) -> Option<&'a Self> {
15822    if let Node::OptChainExpr(node) = node {
15823      Some(node)
15824    } else {
15825      None
15826    }
15827  }
15828
15829  fn kind() -> NodeKind {
15830    NodeKind::OptChainExpr
15831  }
15832}
15833
15834fn get_view_for_opt_chain_expr<'a>(inner: &'a swc_ast::OptChainExpr, bump: &'a Bump) -> &'a OptChainExpr<'a> {
15835  let node = bump.alloc(OptChainExpr {
15836    inner,
15837    parent: Default::default(),
15838    base: get_view_for_opt_chain_base(&inner.base, bump),
15839  });
15840  let parent: Node<'a> = (&*node).into();
15841  set_parent_for_opt_chain_base(&node.base, parent);
15842  node
15843}
15844
15845fn set_parent_for_opt_chain_expr<'a>(node: &OptChainExpr<'a>, parent: Node<'a>) {
15846  node.parent.set(parent);
15847}
15848
15849#[derive(Clone)]
15850pub struct Param<'a> {
15851  parent: ParentOnceCell<Node<'a>>,
15852  pub inner: &'a swc_ast::Param,
15853  pub decorators: &'a [&'a Decorator<'a>],
15854  pub pat: Pat<'a>,
15855}
15856
15857impl<'a> Param<'a> {
15858  pub fn parent(&self) -> Node<'a> {
15859    self.parent.get().unwrap()
15860  }
15861}
15862
15863impl<'a> SourceRanged for Param<'a> {
15864  fn start(&self) -> SourcePos {
15865    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15866  }
15867  fn end(&self) -> SourcePos {
15868    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15869  }
15870}
15871
15872impl<'a> From<&Param<'a>> for Node<'a> {
15873  fn from(node: &Param<'a>) -> Node<'a> {
15874    let node = unsafe { mem::transmute::<&Param<'a>, &'a Param<'a>>(node) };
15875    Node::Param(node)
15876  }
15877}
15878
15879impl<'a> NodeTrait<'a> for Param<'a> {
15880  fn parent(&self) -> Option<Node<'a>> {
15881    Some(self.parent.get().unwrap().clone())
15882  }
15883
15884  fn children(&self) -> Vec<Node<'a>> {
15885    let mut children = Vec::with_capacity(1 + self.decorators.len());
15886    for child in self.decorators.iter() {
15887      children.push((*child).into());
15888    }
15889    children.push((&self.pat).into());
15890    children
15891  }
15892
15893  fn as_node(&self) -> Node<'a> {
15894    self.into()
15895  }
15896
15897  fn kind(&self) -> NodeKind {
15898    NodeKind::Param
15899  }
15900}
15901
15902impl<'a> CastableNode<'a> for Param<'a> {
15903  fn to(node: &Node<'a>) -> Option<&'a Self> {
15904    if let Node::Param(node) = node {
15905      Some(node)
15906    } else {
15907      None
15908    }
15909  }
15910
15911  fn kind() -> NodeKind {
15912    NodeKind::Param
15913  }
15914}
15915
15916fn get_view_for_param<'a>(inner: &'a swc_ast::Param, bump: &'a Bump) -> &'a Param<'a> {
15917  let node = bump.alloc(Param {
15918    inner,
15919    parent: Default::default(),
15920    decorators: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.decorators.len(), bump);vec.extend(inner.decorators.iter().map(|value| get_view_for_decorator(value, bump))); vec }),
15921    pat: get_view_for_pat(&inner.pat, bump),
15922  });
15923  let parent: Node<'a> = (&*node).into();
15924  for value in node.decorators.iter() {
15925    set_parent_for_decorator(value, parent)
15926  }
15927  set_parent_for_pat(&node.pat, parent);
15928  node
15929}
15930
15931fn set_parent_for_param<'a>(node: &Param<'a>, parent: Node<'a>) {
15932  node.parent.set(parent);
15933}
15934
15935#[derive(Clone)]
15936pub struct ParenExpr<'a> {
15937  parent: ParentOnceCell<Node<'a>>,
15938  pub inner: &'a swc_ast::ParenExpr,
15939  pub expr: Expr<'a>,
15940}
15941
15942impl<'a> ParenExpr<'a> {
15943  pub fn parent(&self) -> Node<'a> {
15944    self.parent.get().unwrap()
15945  }
15946}
15947
15948impl<'a> SourceRanged for ParenExpr<'a> {
15949  fn start(&self) -> SourcePos {
15950    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15951  }
15952  fn end(&self) -> SourcePos {
15953    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15954  }
15955}
15956
15957impl<'a> From<&ParenExpr<'a>> for Node<'a> {
15958  fn from(node: &ParenExpr<'a>) -> Node<'a> {
15959    let node = unsafe { mem::transmute::<&ParenExpr<'a>, &'a ParenExpr<'a>>(node) };
15960    Node::ParenExpr(node)
15961  }
15962}
15963
15964impl<'a> NodeTrait<'a> for ParenExpr<'a> {
15965  fn parent(&self) -> Option<Node<'a>> {
15966    Some(self.parent.get().unwrap().clone())
15967  }
15968
15969  fn children(&self) -> Vec<Node<'a>> {
15970    let mut children = Vec::with_capacity(1);
15971    children.push((&self.expr).into());
15972    children
15973  }
15974
15975  fn as_node(&self) -> Node<'a> {
15976    self.into()
15977  }
15978
15979  fn kind(&self) -> NodeKind {
15980    NodeKind::ParenExpr
15981  }
15982}
15983
15984impl<'a> CastableNode<'a> for ParenExpr<'a> {
15985  fn to(node: &Node<'a>) -> Option<&'a Self> {
15986    if let Node::ParenExpr(node) = node {
15987      Some(node)
15988    } else {
15989      None
15990    }
15991  }
15992
15993  fn kind() -> NodeKind {
15994    NodeKind::ParenExpr
15995  }
15996}
15997
15998fn get_view_for_paren_expr<'a>(inner: &'a swc_ast::ParenExpr, bump: &'a Bump) -> &'a ParenExpr<'a> {
15999  let node = bump.alloc(ParenExpr {
16000    inner,
16001    parent: Default::default(),
16002    expr: get_view_for_expr(&inner.expr, bump),
16003  });
16004  let parent: Node<'a> = (&*node).into();
16005  set_parent_for_expr(&node.expr, parent);
16006  node
16007}
16008
16009fn set_parent_for_paren_expr<'a>(node: &ParenExpr<'a>, parent: Node<'a>) {
16010  node.parent.set(parent);
16011}
16012
16013#[derive(Clone)]
16014pub struct PrivateMethod<'a> {
16015  parent: ParentOnceCell<&'a Class<'a>>,
16016  pub inner: &'a swc_ast::PrivateMethod,
16017  pub key: &'a PrivateName<'a>,
16018  pub function: &'a Function<'a>,
16019}
16020
16021impl<'a> PrivateMethod<'a> {
16022  pub fn parent(&self) -> &'a Class<'a> {
16023    self.parent.get().unwrap()
16024  }
16025
16026  pub fn method_kind(&self) -> MethodKind {
16027    self.inner.kind
16028  }
16029
16030  pub fn is_static(&self) -> bool {
16031    self.inner.is_static
16032  }
16033
16034  /// Typescript extension.
16035  pub fn accessibility(&self) -> Option<Accessibility> {
16036    self.inner.accessibility
16037  }
16038
16039  /// Typescript extension.
16040  pub fn is_abstract(&self) -> bool {
16041    self.inner.is_abstract
16042  }
16043
16044  pub fn is_optional(&self) -> bool {
16045    self.inner.is_optional
16046  }
16047
16048  pub fn is_override(&self) -> bool {
16049    self.inner.is_override
16050  }
16051}
16052
16053impl<'a> SourceRanged for PrivateMethod<'a> {
16054  fn start(&self) -> SourcePos {
16055    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16056  }
16057  fn end(&self) -> SourcePos {
16058    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16059  }
16060}
16061
16062impl<'a> From<&PrivateMethod<'a>> for Node<'a> {
16063  fn from(node: &PrivateMethod<'a>) -> Node<'a> {
16064    let node = unsafe { mem::transmute::<&PrivateMethod<'a>, &'a PrivateMethod<'a>>(node) };
16065    Node::PrivateMethod(node)
16066  }
16067}
16068
16069impl<'a> NodeTrait<'a> for PrivateMethod<'a> {
16070  fn parent(&self) -> Option<Node<'a>> {
16071    Some(self.parent.get().unwrap().into())
16072  }
16073
16074  fn children(&self) -> Vec<Node<'a>> {
16075    let mut children = Vec::with_capacity(2);
16076    children.push(self.key.into());
16077    children.push(self.function.into());
16078    children
16079  }
16080
16081  fn as_node(&self) -> Node<'a> {
16082    self.into()
16083  }
16084
16085  fn kind(&self) -> NodeKind {
16086    NodeKind::PrivateMethod
16087  }
16088}
16089
16090impl<'a> CastableNode<'a> for PrivateMethod<'a> {
16091  fn to(node: &Node<'a>) -> Option<&'a Self> {
16092    if let Node::PrivateMethod(node) = node {
16093      Some(node)
16094    } else {
16095      None
16096    }
16097  }
16098
16099  fn kind() -> NodeKind {
16100    NodeKind::PrivateMethod
16101  }
16102}
16103
16104fn get_view_for_private_method<'a>(inner: &'a swc_ast::PrivateMethod, bump: &'a Bump) -> &'a PrivateMethod<'a> {
16105  let node = bump.alloc(PrivateMethod {
16106    inner,
16107    parent: Default::default(),
16108    key: get_view_for_private_name(&inner.key, bump),
16109    function: get_view_for_function(&inner.function, bump),
16110  });
16111  let parent: Node<'a> = (&*node).into();
16112  set_parent_for_private_name(&node.key, parent);
16113  set_parent_for_function(&node.function, parent);
16114  node
16115}
16116
16117fn set_parent_for_private_method<'a>(node: &PrivateMethod<'a>, parent: Node<'a>) {
16118  node.parent.set(parent.expect::<Class>());
16119}
16120
16121#[derive(Clone)]
16122pub struct PrivateName<'a> {
16123  parent: ParentOnceCell<Node<'a>>,
16124  pub inner: &'a swc_ast::PrivateName,
16125}
16126
16127impl<'a> PrivateName<'a> {
16128  pub fn parent(&self) -> Node<'a> {
16129    self.parent.get().unwrap()
16130  }
16131
16132  pub fn name(&self) -> &swc_atoms::Atom {
16133    &self.inner.name
16134  }
16135}
16136
16137impl<'a> SourceRanged for PrivateName<'a> {
16138  fn start(&self) -> SourcePos {
16139    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16140  }
16141  fn end(&self) -> SourcePos {
16142    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16143  }
16144}
16145
16146impl<'a> From<&PrivateName<'a>> for Node<'a> {
16147  fn from(node: &PrivateName<'a>) -> Node<'a> {
16148    let node = unsafe { mem::transmute::<&PrivateName<'a>, &'a PrivateName<'a>>(node) };
16149    Node::PrivateName(node)
16150  }
16151}
16152
16153impl<'a> NodeTrait<'a> for PrivateName<'a> {
16154  fn parent(&self) -> Option<Node<'a>> {
16155    Some(self.parent.get().unwrap().clone())
16156  }
16157
16158  fn children(&self) -> Vec<Node<'a>> {
16159    Vec::with_capacity(0)
16160  }
16161
16162  fn as_node(&self) -> Node<'a> {
16163    self.into()
16164  }
16165
16166  fn kind(&self) -> NodeKind {
16167    NodeKind::PrivateName
16168  }
16169}
16170
16171impl<'a> CastableNode<'a> for PrivateName<'a> {
16172  fn to(node: &Node<'a>) -> Option<&'a Self> {
16173    if let Node::PrivateName(node) = node {
16174      Some(node)
16175    } else {
16176      None
16177    }
16178  }
16179
16180  fn kind() -> NodeKind {
16181    NodeKind::PrivateName
16182  }
16183}
16184
16185fn get_view_for_private_name<'a>(inner: &'a swc_ast::PrivateName, bump: &'a Bump) -> &'a PrivateName<'a> {
16186  let node = bump.alloc(PrivateName {
16187    inner,
16188    parent: Default::default(),
16189  });
16190  node
16191}
16192
16193fn set_parent_for_private_name<'a>(node: &PrivateName<'a>, parent: Node<'a>) {
16194  node.parent.set(parent);
16195}
16196
16197#[derive(Clone)]
16198pub struct PrivateProp<'a> {
16199  parent: ParentOnceCell<&'a Class<'a>>,
16200  pub inner: &'a swc_ast::PrivateProp,
16201  pub key: &'a PrivateName<'a>,
16202  pub value: Option<Expr<'a>>,
16203  pub type_ann: Option<&'a TsTypeAnn<'a>>,
16204  pub decorators: &'a [&'a Decorator<'a>],
16205}
16206
16207impl<'a> PrivateProp<'a> {
16208  pub fn parent(&self) -> &'a Class<'a> {
16209    self.parent.get().unwrap()
16210  }
16211
16212  pub fn ctxt(&self) -> swc_common::SyntaxContext {
16213    self.inner.ctxt
16214  }
16215
16216  pub fn is_static(&self) -> bool {
16217    self.inner.is_static
16218  }
16219
16220  /// Typescript extension.
16221  pub fn accessibility(&self) -> Option<Accessibility> {
16222    self.inner.accessibility
16223  }
16224
16225  pub fn is_optional(&self) -> bool {
16226    self.inner.is_optional
16227  }
16228
16229  pub fn is_override(&self) -> bool {
16230    self.inner.is_override
16231  }
16232
16233  pub fn readonly(&self) -> bool {
16234    self.inner.readonly
16235  }
16236
16237  pub fn definite(&self) -> bool {
16238    self.inner.definite
16239  }
16240}
16241
16242impl<'a> SourceRanged for PrivateProp<'a> {
16243  fn start(&self) -> SourcePos {
16244    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16245  }
16246  fn end(&self) -> SourcePos {
16247    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16248  }
16249}
16250
16251impl<'a> From<&PrivateProp<'a>> for Node<'a> {
16252  fn from(node: &PrivateProp<'a>) -> Node<'a> {
16253    let node = unsafe { mem::transmute::<&PrivateProp<'a>, &'a PrivateProp<'a>>(node) };
16254    Node::PrivateProp(node)
16255  }
16256}
16257
16258impl<'a> NodeTrait<'a> for PrivateProp<'a> {
16259  fn parent(&self) -> Option<Node<'a>> {
16260    Some(self.parent.get().unwrap().into())
16261  }
16262
16263  fn children(&self) -> Vec<Node<'a>> {
16264    let mut children = Vec::with_capacity(1 + match &self.value { Some(_value) => 1, None => 0, } + match &self.type_ann { Some(_value) => 1, None => 0, } + self.decorators.len());
16265    children.push(self.key.into());
16266    if let Some(child) = self.value.as_ref() {
16267      children.push(child.into());
16268    }
16269    if let Some(child) = self.type_ann {
16270      children.push(child.into());
16271    }
16272    for child in self.decorators.iter() {
16273      children.push((*child).into());
16274    }
16275    children
16276  }
16277
16278  fn as_node(&self) -> Node<'a> {
16279    self.into()
16280  }
16281
16282  fn kind(&self) -> NodeKind {
16283    NodeKind::PrivateProp
16284  }
16285}
16286
16287impl<'a> CastableNode<'a> for PrivateProp<'a> {
16288  fn to(node: &Node<'a>) -> Option<&'a Self> {
16289    if let Node::PrivateProp(node) = node {
16290      Some(node)
16291    } else {
16292      None
16293    }
16294  }
16295
16296  fn kind() -> NodeKind {
16297    NodeKind::PrivateProp
16298  }
16299}
16300
16301fn get_view_for_private_prop<'a>(inner: &'a swc_ast::PrivateProp, bump: &'a Bump) -> &'a PrivateProp<'a> {
16302  let node = bump.alloc(PrivateProp {
16303    inner,
16304    parent: Default::default(),
16305    key: get_view_for_private_name(&inner.key, bump),
16306    value: match &inner.value {
16307      Some(value) => Some(get_view_for_expr(value, bump)),
16308      None => None,
16309    },
16310    type_ann: match &inner.type_ann {
16311      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
16312      None => None,
16313    },
16314    decorators: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.decorators.len(), bump);vec.extend(inner.decorators.iter().map(|value| get_view_for_decorator(value, bump))); vec }),
16315  });
16316  let parent: Node<'a> = (&*node).into();
16317  set_parent_for_private_name(&node.key, parent);
16318  if let Some(value) = &node.value {
16319    set_parent_for_expr(value, parent)
16320  };
16321  if let Some(value) = &node.type_ann {
16322    set_parent_for_ts_type_ann(value, parent)
16323  };
16324  for value in node.decorators.iter() {
16325    set_parent_for_decorator(value, parent)
16326  }
16327  node
16328}
16329
16330fn set_parent_for_private_prop<'a>(node: &PrivateProp<'a>, parent: Node<'a>) {
16331  node.parent.set(parent.expect::<Class>());
16332}
16333
16334#[derive(Clone)]
16335pub struct Regex<'a> {
16336  parent: ParentOnceCell<Node<'a>>,
16337  pub inner: &'a swc_ast::Regex,
16338}
16339
16340impl<'a> Regex<'a> {
16341  pub fn parent(&self) -> Node<'a> {
16342    self.parent.get().unwrap()
16343  }
16344
16345  pub fn exp(&self) -> &swc_atoms::Atom {
16346    &self.inner.exp
16347  }
16348
16349  pub fn flags(&self) -> &swc_atoms::Atom {
16350    &self.inner.flags
16351  }
16352}
16353
16354impl<'a> SourceRanged for Regex<'a> {
16355  fn start(&self) -> SourcePos {
16356    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16357  }
16358  fn end(&self) -> SourcePos {
16359    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16360  }
16361}
16362
16363impl<'a> From<&Regex<'a>> for Node<'a> {
16364  fn from(node: &Regex<'a>) -> Node<'a> {
16365    let node = unsafe { mem::transmute::<&Regex<'a>, &'a Regex<'a>>(node) };
16366    Node::Regex(node)
16367  }
16368}
16369
16370impl<'a> NodeTrait<'a> for Regex<'a> {
16371  fn parent(&self) -> Option<Node<'a>> {
16372    Some(self.parent.get().unwrap().clone())
16373  }
16374
16375  fn children(&self) -> Vec<Node<'a>> {
16376    Vec::with_capacity(0)
16377  }
16378
16379  fn as_node(&self) -> Node<'a> {
16380    self.into()
16381  }
16382
16383  fn kind(&self) -> NodeKind {
16384    NodeKind::Regex
16385  }
16386}
16387
16388impl<'a> CastableNode<'a> for Regex<'a> {
16389  fn to(node: &Node<'a>) -> Option<&'a Self> {
16390    if let Node::Regex(node) = node {
16391      Some(node)
16392    } else {
16393      None
16394    }
16395  }
16396
16397  fn kind() -> NodeKind {
16398    NodeKind::Regex
16399  }
16400}
16401
16402fn get_view_for_regex<'a>(inner: &'a swc_ast::Regex, bump: &'a Bump) -> &'a Regex<'a> {
16403  let node = bump.alloc(Regex {
16404    inner,
16405    parent: Default::default(),
16406  });
16407  node
16408}
16409
16410fn set_parent_for_regex<'a>(node: &Regex<'a>, parent: Node<'a>) {
16411  node.parent.set(parent);
16412}
16413
16414/// EsTree `RestElement`
16415#[derive(Clone)]
16416pub struct RestPat<'a> {
16417  parent: ParentOnceCell<Node<'a>>,
16418  pub inner: &'a swc_ast::RestPat,
16419  pub arg: Pat<'a>,
16420  pub type_ann: Option<&'a TsTypeAnn<'a>>,
16421}
16422
16423impl<'a> RestPat<'a> {
16424  pub fn parent(&self) -> Node<'a> {
16425    self.parent.get().unwrap()
16426  }
16427
16428  pub fn dot3_token(&self) -> &swc_common::Span {
16429    &self.inner.dot3_token
16430  }
16431}
16432
16433impl<'a> SourceRanged for RestPat<'a> {
16434  fn start(&self) -> SourcePos {
16435    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16436  }
16437  fn end(&self) -> SourcePos {
16438    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16439  }
16440}
16441
16442impl<'a> From<&RestPat<'a>> for Node<'a> {
16443  fn from(node: &RestPat<'a>) -> Node<'a> {
16444    let node = unsafe { mem::transmute::<&RestPat<'a>, &'a RestPat<'a>>(node) };
16445    Node::RestPat(node)
16446  }
16447}
16448
16449impl<'a> NodeTrait<'a> for RestPat<'a> {
16450  fn parent(&self) -> Option<Node<'a>> {
16451    Some(self.parent.get().unwrap().clone())
16452  }
16453
16454  fn children(&self) -> Vec<Node<'a>> {
16455    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
16456    children.push((&self.arg).into());
16457    if let Some(child) = self.type_ann {
16458      children.push(child.into());
16459    }
16460    children
16461  }
16462
16463  fn as_node(&self) -> Node<'a> {
16464    self.into()
16465  }
16466
16467  fn kind(&self) -> NodeKind {
16468    NodeKind::RestPat
16469  }
16470}
16471
16472impl<'a> CastableNode<'a> for RestPat<'a> {
16473  fn to(node: &Node<'a>) -> Option<&'a Self> {
16474    if let Node::RestPat(node) = node {
16475      Some(node)
16476    } else {
16477      None
16478    }
16479  }
16480
16481  fn kind() -> NodeKind {
16482    NodeKind::RestPat
16483  }
16484}
16485
16486fn get_view_for_rest_pat<'a>(inner: &'a swc_ast::RestPat, bump: &'a Bump) -> &'a RestPat<'a> {
16487  let node = bump.alloc(RestPat {
16488    inner,
16489    parent: Default::default(),
16490    arg: get_view_for_pat(&inner.arg, bump),
16491    type_ann: match &inner.type_ann {
16492      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
16493      None => None,
16494    },
16495  });
16496  let parent: Node<'a> = (&*node).into();
16497  set_parent_for_pat(&node.arg, parent);
16498  if let Some(value) = &node.type_ann {
16499    set_parent_for_ts_type_ann(value, parent)
16500  };
16501  node
16502}
16503
16504fn set_parent_for_rest_pat<'a>(node: &RestPat<'a>, parent: Node<'a>) {
16505  node.parent.set(parent);
16506}
16507
16508#[derive(Clone)]
16509pub struct ReturnStmt<'a> {
16510  parent: ParentOnceCell<Node<'a>>,
16511  pub inner: &'a swc_ast::ReturnStmt,
16512  pub arg: Option<Expr<'a>>,
16513}
16514
16515impl<'a> ReturnStmt<'a> {
16516  pub fn parent(&self) -> Node<'a> {
16517    self.parent.get().unwrap()
16518  }
16519}
16520
16521impl<'a> SourceRanged for ReturnStmt<'a> {
16522  fn start(&self) -> SourcePos {
16523    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16524  }
16525  fn end(&self) -> SourcePos {
16526    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16527  }
16528}
16529
16530impl<'a> From<&ReturnStmt<'a>> for Node<'a> {
16531  fn from(node: &ReturnStmt<'a>) -> Node<'a> {
16532    let node = unsafe { mem::transmute::<&ReturnStmt<'a>, &'a ReturnStmt<'a>>(node) };
16533    Node::ReturnStmt(node)
16534  }
16535}
16536
16537impl<'a> NodeTrait<'a> for ReturnStmt<'a> {
16538  fn parent(&self) -> Option<Node<'a>> {
16539    Some(self.parent.get().unwrap().clone())
16540  }
16541
16542  fn children(&self) -> Vec<Node<'a>> {
16543    let mut children = Vec::with_capacity(match &self.arg { Some(_value) => 1, None => 0, });
16544    if let Some(child) = self.arg.as_ref() {
16545      children.push(child.into());
16546    }
16547    children
16548  }
16549
16550  fn as_node(&self) -> Node<'a> {
16551    self.into()
16552  }
16553
16554  fn kind(&self) -> NodeKind {
16555    NodeKind::ReturnStmt
16556  }
16557}
16558
16559impl<'a> CastableNode<'a> for ReturnStmt<'a> {
16560  fn to(node: &Node<'a>) -> Option<&'a Self> {
16561    if let Node::ReturnStmt(node) = node {
16562      Some(node)
16563    } else {
16564      None
16565    }
16566  }
16567
16568  fn kind() -> NodeKind {
16569    NodeKind::ReturnStmt
16570  }
16571}
16572
16573fn get_view_for_return_stmt<'a>(inner: &'a swc_ast::ReturnStmt, bump: &'a Bump) -> &'a ReturnStmt<'a> {
16574  let node = bump.alloc(ReturnStmt {
16575    inner,
16576    parent: Default::default(),
16577    arg: match &inner.arg {
16578      Some(value) => Some(get_view_for_expr(value, bump)),
16579      None => None,
16580    },
16581  });
16582  let parent: Node<'a> = (&*node).into();
16583  if let Some(value) = &node.arg {
16584    set_parent_for_expr(value, parent)
16585  };
16586  node
16587}
16588
16589fn set_parent_for_return_stmt<'a>(node: &ReturnStmt<'a>, parent: Node<'a>) {
16590  node.parent.set(parent);
16591}
16592
16593#[derive(Clone)]
16594pub struct Script<'a> {
16595  pub text_info: Option<&'a SourceTextInfo>,
16596  pub tokens: Option<&'a TokenContainer<'a>>,
16597  pub comments: Option<&'a CommentContainer<'a>>,
16598  pub inner: &'a swc_ast::Script,
16599  pub body: &'a [Stmt<'a>],
16600}
16601
16602impl<'a> Script<'a> {
16603  pub fn shebang(&self) -> &Option<swc_atoms::Atom> {
16604    &self.inner.shebang
16605  }
16606}
16607
16608impl<'a> SourceRanged for Script<'a> {
16609  fn start(&self) -> SourcePos {
16610    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16611  }
16612  fn end(&self) -> SourcePos {
16613    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16614  }
16615}
16616
16617impl<'a> From<&Script<'a>> for Node<'a> {
16618  fn from(node: &Script<'a>) -> Node<'a> {
16619    let node = unsafe { mem::transmute::<&Script<'a>, &'a Script<'a>>(node) };
16620    Node::Script(node)
16621  }
16622}
16623
16624impl<'a> NodeTrait<'a> for Script<'a> {
16625  fn parent(&self) -> Option<Node<'a>> {
16626    None
16627  }
16628
16629  fn children(&self) -> Vec<Node<'a>> {
16630    let mut children = Vec::with_capacity(self.body.len());
16631    for child in self.body.iter() {
16632      children.push(child.into());
16633    }
16634    children
16635  }
16636
16637  fn as_node(&self) -> Node<'a> {
16638    self.into()
16639  }
16640
16641  fn kind(&self) -> NodeKind {
16642    NodeKind::Script
16643  }
16644}
16645
16646impl<'a> CastableNode<'a> for Script<'a> {
16647  fn to(node: &Node<'a>) -> Option<&'a Self> {
16648    if let Node::Script(node) = node {
16649      Some(node)
16650    } else {
16651      None
16652    }
16653  }
16654
16655  fn kind() -> NodeKind {
16656    NodeKind::Script
16657  }
16658}
16659
16660fn get_view_for_script<'a>(source_file_info: &'a ScriptInfo<'a>, tokens: Option<&'a TokenContainer<'a>>, comments: Option<&'a CommentContainer<'a>>, bump: &'a Bump) -> &'a Script<'a> {
16661  let inner = source_file_info.script;
16662  let node = bump.alloc(Script {
16663    inner,
16664    text_info: source_file_info.text_info,
16665    tokens,
16666    comments,
16667    body: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.body.len(), bump);vec.extend(inner.body.iter().map(|value| get_view_for_stmt(value, bump))); vec }),
16668  });
16669  let parent: Node<'a> = (&*node).into();
16670  for value in node.body.iter() {
16671    set_parent_for_stmt(value, parent)
16672  }
16673  node
16674}
16675
16676#[derive(Clone)]
16677pub struct SeqExpr<'a> {
16678  parent: ParentOnceCell<Node<'a>>,
16679  pub inner: &'a swc_ast::SeqExpr,
16680  pub exprs: &'a [Expr<'a>],
16681}
16682
16683impl<'a> SeqExpr<'a> {
16684  pub fn parent(&self) -> Node<'a> {
16685    self.parent.get().unwrap()
16686  }
16687}
16688
16689impl<'a> SourceRanged for SeqExpr<'a> {
16690  fn start(&self) -> SourcePos {
16691    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16692  }
16693  fn end(&self) -> SourcePos {
16694    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16695  }
16696}
16697
16698impl<'a> From<&SeqExpr<'a>> for Node<'a> {
16699  fn from(node: &SeqExpr<'a>) -> Node<'a> {
16700    let node = unsafe { mem::transmute::<&SeqExpr<'a>, &'a SeqExpr<'a>>(node) };
16701    Node::SeqExpr(node)
16702  }
16703}
16704
16705impl<'a> NodeTrait<'a> for SeqExpr<'a> {
16706  fn parent(&self) -> Option<Node<'a>> {
16707    Some(self.parent.get().unwrap().clone())
16708  }
16709
16710  fn children(&self) -> Vec<Node<'a>> {
16711    let mut children = Vec::with_capacity(self.exprs.len());
16712    for child in self.exprs.iter() {
16713      children.push(child.into());
16714    }
16715    children
16716  }
16717
16718  fn as_node(&self) -> Node<'a> {
16719    self.into()
16720  }
16721
16722  fn kind(&self) -> NodeKind {
16723    NodeKind::SeqExpr
16724  }
16725}
16726
16727impl<'a> CastableNode<'a> for SeqExpr<'a> {
16728  fn to(node: &Node<'a>) -> Option<&'a Self> {
16729    if let Node::SeqExpr(node) = node {
16730      Some(node)
16731    } else {
16732      None
16733    }
16734  }
16735
16736  fn kind() -> NodeKind {
16737    NodeKind::SeqExpr
16738  }
16739}
16740
16741fn get_view_for_seq_expr<'a>(inner: &'a swc_ast::SeqExpr, bump: &'a Bump) -> &'a SeqExpr<'a> {
16742  let node = bump.alloc(SeqExpr {
16743    inner,
16744    parent: Default::default(),
16745    exprs: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.exprs.len(), bump);vec.extend(inner.exprs.iter().map(|value| get_view_for_expr(value, bump))); vec }),
16746  });
16747  let parent: Node<'a> = (&*node).into();
16748  for value in node.exprs.iter() {
16749    set_parent_for_expr(value, parent)
16750  }
16751  node
16752}
16753
16754fn set_parent_for_seq_expr<'a>(node: &SeqExpr<'a>, parent: Node<'a>) {
16755  node.parent.set(parent);
16756}
16757
16758#[derive(Clone)]
16759pub struct SetterProp<'a> {
16760  parent: ParentOnceCell<&'a ObjectLit<'a>>,
16761  pub inner: &'a swc_ast::SetterProp,
16762  pub key: PropName<'a>,
16763  pub this_param: Option<Pat<'a>>,
16764  pub param: Pat<'a>,
16765  pub body: Option<&'a BlockStmt<'a>>,
16766}
16767
16768impl<'a> SetterProp<'a> {
16769  pub fn parent(&self) -> &'a ObjectLit<'a> {
16770    self.parent.get().unwrap()
16771  }
16772}
16773
16774impl<'a> SourceRanged for SetterProp<'a> {
16775  fn start(&self) -> SourcePos {
16776    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16777  }
16778  fn end(&self) -> SourcePos {
16779    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16780  }
16781}
16782
16783impl<'a> From<&SetterProp<'a>> for Node<'a> {
16784  fn from(node: &SetterProp<'a>) -> Node<'a> {
16785    let node = unsafe { mem::transmute::<&SetterProp<'a>, &'a SetterProp<'a>>(node) };
16786    Node::SetterProp(node)
16787  }
16788}
16789
16790impl<'a> NodeTrait<'a> for SetterProp<'a> {
16791  fn parent(&self) -> Option<Node<'a>> {
16792    Some(self.parent.get().unwrap().into())
16793  }
16794
16795  fn children(&self) -> Vec<Node<'a>> {
16796    let mut children = Vec::with_capacity(2 + match &self.this_param { Some(_value) => 1, None => 0, } + match &self.body { Some(_value) => 1, None => 0, });
16797    children.push((&self.key).into());
16798    if let Some(child) = self.this_param.as_ref() {
16799      children.push(child.into());
16800    }
16801    children.push((&self.param).into());
16802    if let Some(child) = self.body {
16803      children.push(child.into());
16804    }
16805    children
16806  }
16807
16808  fn as_node(&self) -> Node<'a> {
16809    self.into()
16810  }
16811
16812  fn kind(&self) -> NodeKind {
16813    NodeKind::SetterProp
16814  }
16815}
16816
16817impl<'a> CastableNode<'a> for SetterProp<'a> {
16818  fn to(node: &Node<'a>) -> Option<&'a Self> {
16819    if let Node::SetterProp(node) = node {
16820      Some(node)
16821    } else {
16822      None
16823    }
16824  }
16825
16826  fn kind() -> NodeKind {
16827    NodeKind::SetterProp
16828  }
16829}
16830
16831fn get_view_for_setter_prop<'a>(inner: &'a swc_ast::SetterProp, bump: &'a Bump) -> &'a SetterProp<'a> {
16832  let node = bump.alloc(SetterProp {
16833    inner,
16834    parent: Default::default(),
16835    key: get_view_for_prop_name(&inner.key, bump),
16836    this_param: match &inner.this_param {
16837      Some(value) => Some(get_view_for_pat(value, bump)),
16838      None => None,
16839    },
16840    param: get_view_for_pat(&inner.param, bump),
16841    body: match &inner.body {
16842      Some(value) => Some(get_view_for_block_stmt(value, bump)),
16843      None => None,
16844    },
16845  });
16846  let parent: Node<'a> = (&*node).into();
16847  set_parent_for_prop_name(&node.key, parent);
16848  if let Some(value) = &node.this_param {
16849    set_parent_for_pat(value, parent)
16850  };
16851  set_parent_for_pat(&node.param, parent);
16852  if let Some(value) = &node.body {
16853    set_parent_for_block_stmt(value, parent)
16854  };
16855  node
16856}
16857
16858fn set_parent_for_setter_prop<'a>(node: &SetterProp<'a>, parent: Node<'a>) {
16859  node.parent.set(parent.expect::<ObjectLit>());
16860}
16861
16862#[derive(Clone)]
16863pub struct SpreadElement<'a> {
16864  parent: ParentOnceCell<Node<'a>>,
16865  pub inner: &'a swc_ast::SpreadElement,
16866  pub expr: Expr<'a>,
16867}
16868
16869impl<'a> SpreadElement<'a> {
16870  pub fn parent(&self) -> Node<'a> {
16871    self.parent.get().unwrap()
16872  }
16873
16874  pub fn dot3_token(&self) -> &swc_common::Span {
16875    &self.inner.dot3_token
16876  }
16877}
16878
16879impl<'a> SourceRanged for SpreadElement<'a> {
16880  fn start(&self) -> SourcePos {
16881    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16882  }
16883  fn end(&self) -> SourcePos {
16884    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16885  }
16886}
16887
16888impl<'a> From<&SpreadElement<'a>> for Node<'a> {
16889  fn from(node: &SpreadElement<'a>) -> Node<'a> {
16890    let node = unsafe { mem::transmute::<&SpreadElement<'a>, &'a SpreadElement<'a>>(node) };
16891    Node::SpreadElement(node)
16892  }
16893}
16894
16895impl<'a> NodeTrait<'a> for SpreadElement<'a> {
16896  fn parent(&self) -> Option<Node<'a>> {
16897    Some(self.parent.get().unwrap().clone())
16898  }
16899
16900  fn children(&self) -> Vec<Node<'a>> {
16901    let mut children = Vec::with_capacity(1);
16902    children.push((&self.expr).into());
16903    children
16904  }
16905
16906  fn as_node(&self) -> Node<'a> {
16907    self.into()
16908  }
16909
16910  fn kind(&self) -> NodeKind {
16911    NodeKind::SpreadElement
16912  }
16913}
16914
16915impl<'a> CastableNode<'a> for SpreadElement<'a> {
16916  fn to(node: &Node<'a>) -> Option<&'a Self> {
16917    if let Node::SpreadElement(node) = node {
16918      Some(node)
16919    } else {
16920      None
16921    }
16922  }
16923
16924  fn kind() -> NodeKind {
16925    NodeKind::SpreadElement
16926  }
16927}
16928
16929fn get_view_for_spread_element<'a>(inner: &'a swc_ast::SpreadElement, bump: &'a Bump) -> &'a SpreadElement<'a> {
16930  let node = bump.alloc(SpreadElement {
16931    inner,
16932    parent: Default::default(),
16933    expr: get_view_for_expr(&inner.expr, bump),
16934  });
16935  let parent: Node<'a> = (&*node).into();
16936  set_parent_for_expr(&node.expr, parent);
16937  node
16938}
16939
16940fn set_parent_for_spread_element<'a>(node: &SpreadElement<'a>, parent: Node<'a>) {
16941  node.parent.set(parent);
16942}
16943
16944#[derive(Clone)]
16945pub struct StaticBlock<'a> {
16946  parent: ParentOnceCell<&'a Class<'a>>,
16947  pub inner: &'a swc_ast::StaticBlock,
16948  pub body: &'a BlockStmt<'a>,
16949}
16950
16951impl<'a> StaticBlock<'a> {
16952  pub fn parent(&self) -> &'a Class<'a> {
16953    self.parent.get().unwrap()
16954  }
16955}
16956
16957impl<'a> SourceRanged for StaticBlock<'a> {
16958  fn start(&self) -> SourcePos {
16959    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16960  }
16961  fn end(&self) -> SourcePos {
16962    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16963  }
16964}
16965
16966impl<'a> From<&StaticBlock<'a>> for Node<'a> {
16967  fn from(node: &StaticBlock<'a>) -> Node<'a> {
16968    let node = unsafe { mem::transmute::<&StaticBlock<'a>, &'a StaticBlock<'a>>(node) };
16969    Node::StaticBlock(node)
16970  }
16971}
16972
16973impl<'a> NodeTrait<'a> for StaticBlock<'a> {
16974  fn parent(&self) -> Option<Node<'a>> {
16975    Some(self.parent.get().unwrap().into())
16976  }
16977
16978  fn children(&self) -> Vec<Node<'a>> {
16979    let mut children = Vec::with_capacity(1);
16980    children.push(self.body.into());
16981    children
16982  }
16983
16984  fn as_node(&self) -> Node<'a> {
16985    self.into()
16986  }
16987
16988  fn kind(&self) -> NodeKind {
16989    NodeKind::StaticBlock
16990  }
16991}
16992
16993impl<'a> CastableNode<'a> for StaticBlock<'a> {
16994  fn to(node: &Node<'a>) -> Option<&'a Self> {
16995    if let Node::StaticBlock(node) = node {
16996      Some(node)
16997    } else {
16998      None
16999    }
17000  }
17001
17002  fn kind() -> NodeKind {
17003    NodeKind::StaticBlock
17004  }
17005}
17006
17007fn get_view_for_static_block<'a>(inner: &'a swc_ast::StaticBlock, bump: &'a Bump) -> &'a StaticBlock<'a> {
17008  let node = bump.alloc(StaticBlock {
17009    inner,
17010    parent: Default::default(),
17011    body: get_view_for_block_stmt(&inner.body, bump),
17012  });
17013  let parent: Node<'a> = (&*node).into();
17014  set_parent_for_block_stmt(&node.body, parent);
17015  node
17016}
17017
17018fn set_parent_for_static_block<'a>(node: &StaticBlock<'a>, parent: Node<'a>) {
17019  node.parent.set(parent.expect::<Class>());
17020}
17021
17022/// A string literal.
17023#[derive(Clone)]
17024pub struct Str<'a> {
17025  parent: ParentOnceCell<Node<'a>>,
17026  pub inner: &'a swc_ast::Str,
17027}
17028
17029impl<'a> Str<'a> {
17030  pub fn parent(&self) -> Node<'a> {
17031    self.parent.get().unwrap()
17032  }
17033
17034  pub fn value(&self) -> &swc_atoms::Wtf8Atom {
17035    &self.inner.value
17036  }
17037
17038  /// Use `None` value only for transformations to avoid recalculate escaped
17039  /// characters in strings
17040  pub fn raw(&self) -> &Option<swc_atoms::Atom> {
17041    &self.inner.raw
17042  }
17043}
17044
17045impl<'a> SourceRanged for Str<'a> {
17046  fn start(&self) -> SourcePos {
17047    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17048  }
17049  fn end(&self) -> SourcePos {
17050    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17051  }
17052}
17053
17054impl<'a> From<&Str<'a>> for Node<'a> {
17055  fn from(node: &Str<'a>) -> Node<'a> {
17056    let node = unsafe { mem::transmute::<&Str<'a>, &'a Str<'a>>(node) };
17057    Node::Str(node)
17058  }
17059}
17060
17061impl<'a> NodeTrait<'a> for Str<'a> {
17062  fn parent(&self) -> Option<Node<'a>> {
17063    Some(self.parent.get().unwrap().clone())
17064  }
17065
17066  fn children(&self) -> Vec<Node<'a>> {
17067    Vec::with_capacity(0)
17068  }
17069
17070  fn as_node(&self) -> Node<'a> {
17071    self.into()
17072  }
17073
17074  fn kind(&self) -> NodeKind {
17075    NodeKind::Str
17076  }
17077}
17078
17079impl<'a> CastableNode<'a> for Str<'a> {
17080  fn to(node: &Node<'a>) -> Option<&'a Self> {
17081    if let Node::Str(node) = node {
17082      Some(node)
17083    } else {
17084      None
17085    }
17086  }
17087
17088  fn kind() -> NodeKind {
17089    NodeKind::Str
17090  }
17091}
17092
17093fn get_view_for_str<'a>(inner: &'a swc_ast::Str, bump: &'a Bump) -> &'a Str<'a> {
17094  let node = bump.alloc(Str {
17095    inner,
17096    parent: Default::default(),
17097  });
17098  node
17099}
17100
17101fn set_parent_for_str<'a>(node: &Str<'a>, parent: Node<'a>) {
17102  node.parent.set(parent);
17103}
17104
17105#[derive(Clone)]
17106pub struct Super<'a> {
17107  parent: ParentOnceCell<Node<'a>>,
17108  pub inner: &'a swc_ast::Super,
17109}
17110
17111impl<'a> Super<'a> {
17112  pub fn parent(&self) -> Node<'a> {
17113    self.parent.get().unwrap()
17114  }
17115}
17116
17117impl<'a> SourceRanged for Super<'a> {
17118  fn start(&self) -> SourcePos {
17119    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17120  }
17121  fn end(&self) -> SourcePos {
17122    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17123  }
17124}
17125
17126impl<'a> From<&Super<'a>> for Node<'a> {
17127  fn from(node: &Super<'a>) -> Node<'a> {
17128    let node = unsafe { mem::transmute::<&Super<'a>, &'a Super<'a>>(node) };
17129    Node::Super(node)
17130  }
17131}
17132
17133impl<'a> NodeTrait<'a> for Super<'a> {
17134  fn parent(&self) -> Option<Node<'a>> {
17135    Some(self.parent.get().unwrap().clone())
17136  }
17137
17138  fn children(&self) -> Vec<Node<'a>> {
17139    Vec::with_capacity(0)
17140  }
17141
17142  fn as_node(&self) -> Node<'a> {
17143    self.into()
17144  }
17145
17146  fn kind(&self) -> NodeKind {
17147    NodeKind::Super
17148  }
17149}
17150
17151impl<'a> CastableNode<'a> for Super<'a> {
17152  fn to(node: &Node<'a>) -> Option<&'a Self> {
17153    if let Node::Super(node) = node {
17154      Some(node)
17155    } else {
17156      None
17157    }
17158  }
17159
17160  fn kind() -> NodeKind {
17161    NodeKind::Super
17162  }
17163}
17164
17165fn get_view_for_super<'a>(inner: &'a swc_ast::Super, bump: &'a Bump) -> &'a Super<'a> {
17166  let node = bump.alloc(Super {
17167    inner,
17168    parent: Default::default(),
17169  });
17170  node
17171}
17172
17173fn set_parent_for_super<'a>(node: &Super<'a>, parent: Node<'a>) {
17174  node.parent.set(parent);
17175}
17176
17177#[derive(Clone)]
17178pub struct SuperPropExpr<'a> {
17179  parent: ParentOnceCell<Node<'a>>,
17180  pub inner: &'a swc_ast::SuperPropExpr,
17181  pub obj: &'a Super<'a>,
17182  pub prop: SuperProp<'a>,
17183}
17184
17185impl<'a> SuperPropExpr<'a> {
17186  pub fn parent(&self) -> Node<'a> {
17187    self.parent.get().unwrap()
17188  }
17189}
17190
17191impl<'a> SourceRanged for SuperPropExpr<'a> {
17192  fn start(&self) -> SourcePos {
17193    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17194  }
17195  fn end(&self) -> SourcePos {
17196    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17197  }
17198}
17199
17200impl<'a> From<&SuperPropExpr<'a>> for Node<'a> {
17201  fn from(node: &SuperPropExpr<'a>) -> Node<'a> {
17202    let node = unsafe { mem::transmute::<&SuperPropExpr<'a>, &'a SuperPropExpr<'a>>(node) };
17203    Node::SuperPropExpr(node)
17204  }
17205}
17206
17207impl<'a> NodeTrait<'a> for SuperPropExpr<'a> {
17208  fn parent(&self) -> Option<Node<'a>> {
17209    Some(self.parent.get().unwrap().clone())
17210  }
17211
17212  fn children(&self) -> Vec<Node<'a>> {
17213    let mut children = Vec::with_capacity(2);
17214    children.push(self.obj.into());
17215    children.push((&self.prop).into());
17216    children
17217  }
17218
17219  fn as_node(&self) -> Node<'a> {
17220    self.into()
17221  }
17222
17223  fn kind(&self) -> NodeKind {
17224    NodeKind::SuperPropExpr
17225  }
17226}
17227
17228impl<'a> CastableNode<'a> for SuperPropExpr<'a> {
17229  fn to(node: &Node<'a>) -> Option<&'a Self> {
17230    if let Node::SuperPropExpr(node) = node {
17231      Some(node)
17232    } else {
17233      None
17234    }
17235  }
17236
17237  fn kind() -> NodeKind {
17238    NodeKind::SuperPropExpr
17239  }
17240}
17241
17242fn get_view_for_super_prop_expr<'a>(inner: &'a swc_ast::SuperPropExpr, bump: &'a Bump) -> &'a SuperPropExpr<'a> {
17243  let node = bump.alloc(SuperPropExpr {
17244    inner,
17245    parent: Default::default(),
17246    obj: get_view_for_super(&inner.obj, bump),
17247    prop: get_view_for_super_prop(&inner.prop, bump),
17248  });
17249  let parent: Node<'a> = (&*node).into();
17250  set_parent_for_super(&node.obj, parent);
17251  set_parent_for_super_prop(&node.prop, parent);
17252  node
17253}
17254
17255fn set_parent_for_super_prop_expr<'a>(node: &SuperPropExpr<'a>, parent: Node<'a>) {
17256  node.parent.set(parent);
17257}
17258
17259#[derive(Clone)]
17260pub struct SwitchCase<'a> {
17261  parent: ParentOnceCell<&'a SwitchStmt<'a>>,
17262  pub inner: &'a swc_ast::SwitchCase,
17263  /// None for `default:`
17264  pub test: Option<Expr<'a>>,
17265  pub cons: &'a [Stmt<'a>],
17266}
17267
17268impl<'a> SwitchCase<'a> {
17269  pub fn parent(&self) -> &'a SwitchStmt<'a> {
17270    self.parent.get().unwrap()
17271  }
17272}
17273
17274impl<'a> SourceRanged for SwitchCase<'a> {
17275  fn start(&self) -> SourcePos {
17276    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17277  }
17278  fn end(&self) -> SourcePos {
17279    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17280  }
17281}
17282
17283impl<'a> From<&SwitchCase<'a>> for Node<'a> {
17284  fn from(node: &SwitchCase<'a>) -> Node<'a> {
17285    let node = unsafe { mem::transmute::<&SwitchCase<'a>, &'a SwitchCase<'a>>(node) };
17286    Node::SwitchCase(node)
17287  }
17288}
17289
17290impl<'a> NodeTrait<'a> for SwitchCase<'a> {
17291  fn parent(&self) -> Option<Node<'a>> {
17292    Some(self.parent.get().unwrap().into())
17293  }
17294
17295  fn children(&self) -> Vec<Node<'a>> {
17296    let mut children = Vec::with_capacity(match &self.test { Some(_value) => 1, None => 0, } + self.cons.len());
17297    if let Some(child) = self.test.as_ref() {
17298      children.push(child.into());
17299    }
17300    for child in self.cons.iter() {
17301      children.push(child.into());
17302    }
17303    children
17304  }
17305
17306  fn as_node(&self) -> Node<'a> {
17307    self.into()
17308  }
17309
17310  fn kind(&self) -> NodeKind {
17311    NodeKind::SwitchCase
17312  }
17313}
17314
17315impl<'a> CastableNode<'a> for SwitchCase<'a> {
17316  fn to(node: &Node<'a>) -> Option<&'a Self> {
17317    if let Node::SwitchCase(node) = node {
17318      Some(node)
17319    } else {
17320      None
17321    }
17322  }
17323
17324  fn kind() -> NodeKind {
17325    NodeKind::SwitchCase
17326  }
17327}
17328
17329fn get_view_for_switch_case<'a>(inner: &'a swc_ast::SwitchCase, bump: &'a Bump) -> &'a SwitchCase<'a> {
17330  let node = bump.alloc(SwitchCase {
17331    inner,
17332    parent: Default::default(),
17333    test: match &inner.test {
17334      Some(value) => Some(get_view_for_expr(value, bump)),
17335      None => None,
17336    },
17337    cons: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.cons.len(), bump);vec.extend(inner.cons.iter().map(|value| get_view_for_stmt(value, bump))); vec }),
17338  });
17339  let parent: Node<'a> = (&*node).into();
17340  if let Some(value) = &node.test {
17341    set_parent_for_expr(value, parent)
17342  };
17343  for value in node.cons.iter() {
17344    set_parent_for_stmt(value, parent)
17345  }
17346  node
17347}
17348
17349fn set_parent_for_switch_case<'a>(node: &SwitchCase<'a>, parent: Node<'a>) {
17350  node.parent.set(parent.expect::<SwitchStmt>());
17351}
17352
17353#[derive(Clone)]
17354pub struct SwitchStmt<'a> {
17355  parent: ParentOnceCell<Node<'a>>,
17356  pub inner: &'a swc_ast::SwitchStmt,
17357  pub discriminant: Expr<'a>,
17358  pub cases: &'a [&'a SwitchCase<'a>],
17359}
17360
17361impl<'a> SwitchStmt<'a> {
17362  pub fn parent(&self) -> Node<'a> {
17363    self.parent.get().unwrap()
17364  }
17365}
17366
17367impl<'a> SourceRanged for SwitchStmt<'a> {
17368  fn start(&self) -> SourcePos {
17369    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17370  }
17371  fn end(&self) -> SourcePos {
17372    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17373  }
17374}
17375
17376impl<'a> From<&SwitchStmt<'a>> for Node<'a> {
17377  fn from(node: &SwitchStmt<'a>) -> Node<'a> {
17378    let node = unsafe { mem::transmute::<&SwitchStmt<'a>, &'a SwitchStmt<'a>>(node) };
17379    Node::SwitchStmt(node)
17380  }
17381}
17382
17383impl<'a> NodeTrait<'a> for SwitchStmt<'a> {
17384  fn parent(&self) -> Option<Node<'a>> {
17385    Some(self.parent.get().unwrap().clone())
17386  }
17387
17388  fn children(&self) -> Vec<Node<'a>> {
17389    let mut children = Vec::with_capacity(1 + self.cases.len());
17390    children.push((&self.discriminant).into());
17391    for child in self.cases.iter() {
17392      children.push((*child).into());
17393    }
17394    children
17395  }
17396
17397  fn as_node(&self) -> Node<'a> {
17398    self.into()
17399  }
17400
17401  fn kind(&self) -> NodeKind {
17402    NodeKind::SwitchStmt
17403  }
17404}
17405
17406impl<'a> CastableNode<'a> for SwitchStmt<'a> {
17407  fn to(node: &Node<'a>) -> Option<&'a Self> {
17408    if let Node::SwitchStmt(node) = node {
17409      Some(node)
17410    } else {
17411      None
17412    }
17413  }
17414
17415  fn kind() -> NodeKind {
17416    NodeKind::SwitchStmt
17417  }
17418}
17419
17420fn get_view_for_switch_stmt<'a>(inner: &'a swc_ast::SwitchStmt, bump: &'a Bump) -> &'a SwitchStmt<'a> {
17421  let node = bump.alloc(SwitchStmt {
17422    inner,
17423    parent: Default::default(),
17424    discriminant: get_view_for_expr(&inner.discriminant, bump),
17425    cases: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.cases.len(), bump);vec.extend(inner.cases.iter().map(|value| get_view_for_switch_case(value, bump))); vec }),
17426  });
17427  let parent: Node<'a> = (&*node).into();
17428  set_parent_for_expr(&node.discriminant, parent);
17429  for value in node.cases.iter() {
17430    set_parent_for_switch_case(value, parent)
17431  }
17432  node
17433}
17434
17435fn set_parent_for_switch_stmt<'a>(node: &SwitchStmt<'a>, parent: Node<'a>) {
17436  node.parent.set(parent);
17437}
17438
17439#[derive(Clone)]
17440pub struct TaggedTpl<'a> {
17441  parent: ParentOnceCell<Node<'a>>,
17442  pub inner: &'a swc_ast::TaggedTpl,
17443  pub tag: Expr<'a>,
17444  pub type_params: Option<&'a TsTypeParamInstantiation<'a>>,
17445  /// This is boxed to reduce the type size of [Expr].
17446  pub tpl: &'a Tpl<'a>,
17447}
17448
17449impl<'a> TaggedTpl<'a> {
17450  pub fn parent(&self) -> Node<'a> {
17451    self.parent.get().unwrap()
17452  }
17453
17454  pub fn ctxt(&self) -> swc_common::SyntaxContext {
17455    self.inner.ctxt
17456  }
17457}
17458
17459impl<'a> SourceRanged for TaggedTpl<'a> {
17460  fn start(&self) -> SourcePos {
17461    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17462  }
17463  fn end(&self) -> SourcePos {
17464    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17465  }
17466}
17467
17468impl<'a> From<&TaggedTpl<'a>> for Node<'a> {
17469  fn from(node: &TaggedTpl<'a>) -> Node<'a> {
17470    let node = unsafe { mem::transmute::<&TaggedTpl<'a>, &'a TaggedTpl<'a>>(node) };
17471    Node::TaggedTpl(node)
17472  }
17473}
17474
17475impl<'a> NodeTrait<'a> for TaggedTpl<'a> {
17476  fn parent(&self) -> Option<Node<'a>> {
17477    Some(self.parent.get().unwrap().clone())
17478  }
17479
17480  fn children(&self) -> Vec<Node<'a>> {
17481    let mut children = Vec::with_capacity(2 + match &self.type_params { Some(_value) => 1, None => 0, });
17482    children.push((&self.tag).into());
17483    if let Some(child) = self.type_params {
17484      children.push(child.into());
17485    }
17486    children.push(self.tpl.into());
17487    children
17488  }
17489
17490  fn as_node(&self) -> Node<'a> {
17491    self.into()
17492  }
17493
17494  fn kind(&self) -> NodeKind {
17495    NodeKind::TaggedTpl
17496  }
17497}
17498
17499impl<'a> CastableNode<'a> for TaggedTpl<'a> {
17500  fn to(node: &Node<'a>) -> Option<&'a Self> {
17501    if let Node::TaggedTpl(node) = node {
17502      Some(node)
17503    } else {
17504      None
17505    }
17506  }
17507
17508  fn kind() -> NodeKind {
17509    NodeKind::TaggedTpl
17510  }
17511}
17512
17513fn get_view_for_tagged_tpl<'a>(inner: &'a swc_ast::TaggedTpl, bump: &'a Bump) -> &'a TaggedTpl<'a> {
17514  let node = bump.alloc(TaggedTpl {
17515    inner,
17516    parent: Default::default(),
17517    tag: get_view_for_expr(&inner.tag, bump),
17518    type_params: match &inner.type_params {
17519      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
17520      None => None,
17521    },
17522    tpl: get_view_for_tpl(&inner.tpl, bump),
17523  });
17524  let parent: Node<'a> = (&*node).into();
17525  set_parent_for_expr(&node.tag, parent);
17526  if let Some(value) = &node.type_params {
17527    set_parent_for_ts_type_param_instantiation(value, parent)
17528  };
17529  set_parent_for_tpl(&node.tpl, parent);
17530  node
17531}
17532
17533fn set_parent_for_tagged_tpl<'a>(node: &TaggedTpl<'a>, parent: Node<'a>) {
17534  node.parent.set(parent);
17535}
17536
17537#[derive(Clone)]
17538pub struct ThisExpr<'a> {
17539  parent: ParentOnceCell<Node<'a>>,
17540  pub inner: &'a swc_ast::ThisExpr,
17541}
17542
17543impl<'a> ThisExpr<'a> {
17544  pub fn parent(&self) -> Node<'a> {
17545    self.parent.get().unwrap()
17546  }
17547}
17548
17549impl<'a> SourceRanged for ThisExpr<'a> {
17550  fn start(&self) -> SourcePos {
17551    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17552  }
17553  fn end(&self) -> SourcePos {
17554    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17555  }
17556}
17557
17558impl<'a> From<&ThisExpr<'a>> for Node<'a> {
17559  fn from(node: &ThisExpr<'a>) -> Node<'a> {
17560    let node = unsafe { mem::transmute::<&ThisExpr<'a>, &'a ThisExpr<'a>>(node) };
17561    Node::ThisExpr(node)
17562  }
17563}
17564
17565impl<'a> NodeTrait<'a> for ThisExpr<'a> {
17566  fn parent(&self) -> Option<Node<'a>> {
17567    Some(self.parent.get().unwrap().clone())
17568  }
17569
17570  fn children(&self) -> Vec<Node<'a>> {
17571    Vec::with_capacity(0)
17572  }
17573
17574  fn as_node(&self) -> Node<'a> {
17575    self.into()
17576  }
17577
17578  fn kind(&self) -> NodeKind {
17579    NodeKind::ThisExpr
17580  }
17581}
17582
17583impl<'a> CastableNode<'a> for ThisExpr<'a> {
17584  fn to(node: &Node<'a>) -> Option<&'a Self> {
17585    if let Node::ThisExpr(node) = node {
17586      Some(node)
17587    } else {
17588      None
17589    }
17590  }
17591
17592  fn kind() -> NodeKind {
17593    NodeKind::ThisExpr
17594  }
17595}
17596
17597fn get_view_for_this_expr<'a>(inner: &'a swc_ast::ThisExpr, bump: &'a Bump) -> &'a ThisExpr<'a> {
17598  let node = bump.alloc(ThisExpr {
17599    inner,
17600    parent: Default::default(),
17601  });
17602  node
17603}
17604
17605fn set_parent_for_this_expr<'a>(node: &ThisExpr<'a>, parent: Node<'a>) {
17606  node.parent.set(parent);
17607}
17608
17609#[derive(Clone)]
17610pub struct ThrowStmt<'a> {
17611  parent: ParentOnceCell<Node<'a>>,
17612  pub inner: &'a swc_ast::ThrowStmt,
17613  pub arg: Expr<'a>,
17614}
17615
17616impl<'a> ThrowStmt<'a> {
17617  pub fn parent(&self) -> Node<'a> {
17618    self.parent.get().unwrap()
17619  }
17620}
17621
17622impl<'a> SourceRanged for ThrowStmt<'a> {
17623  fn start(&self) -> SourcePos {
17624    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17625  }
17626  fn end(&self) -> SourcePos {
17627    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17628  }
17629}
17630
17631impl<'a> From<&ThrowStmt<'a>> for Node<'a> {
17632  fn from(node: &ThrowStmt<'a>) -> Node<'a> {
17633    let node = unsafe { mem::transmute::<&ThrowStmt<'a>, &'a ThrowStmt<'a>>(node) };
17634    Node::ThrowStmt(node)
17635  }
17636}
17637
17638impl<'a> NodeTrait<'a> for ThrowStmt<'a> {
17639  fn parent(&self) -> Option<Node<'a>> {
17640    Some(self.parent.get().unwrap().clone())
17641  }
17642
17643  fn children(&self) -> Vec<Node<'a>> {
17644    let mut children = Vec::with_capacity(1);
17645    children.push((&self.arg).into());
17646    children
17647  }
17648
17649  fn as_node(&self) -> Node<'a> {
17650    self.into()
17651  }
17652
17653  fn kind(&self) -> NodeKind {
17654    NodeKind::ThrowStmt
17655  }
17656}
17657
17658impl<'a> CastableNode<'a> for ThrowStmt<'a> {
17659  fn to(node: &Node<'a>) -> Option<&'a Self> {
17660    if let Node::ThrowStmt(node) = node {
17661      Some(node)
17662    } else {
17663      None
17664    }
17665  }
17666
17667  fn kind() -> NodeKind {
17668    NodeKind::ThrowStmt
17669  }
17670}
17671
17672fn get_view_for_throw_stmt<'a>(inner: &'a swc_ast::ThrowStmt, bump: &'a Bump) -> &'a ThrowStmt<'a> {
17673  let node = bump.alloc(ThrowStmt {
17674    inner,
17675    parent: Default::default(),
17676    arg: get_view_for_expr(&inner.arg, bump),
17677  });
17678  let parent: Node<'a> = (&*node).into();
17679  set_parent_for_expr(&node.arg, parent);
17680  node
17681}
17682
17683fn set_parent_for_throw_stmt<'a>(node: &ThrowStmt<'a>, parent: Node<'a>) {
17684  node.parent.set(parent);
17685}
17686
17687#[derive(Clone)]
17688pub struct Tpl<'a> {
17689  parent: ParentOnceCell<Node<'a>>,
17690  pub inner: &'a swc_ast::Tpl,
17691  pub exprs: &'a [Expr<'a>],
17692  pub quasis: &'a [&'a TplElement<'a>],
17693}
17694
17695impl<'a> Tpl<'a> {
17696  pub fn parent(&self) -> Node<'a> {
17697    self.parent.get().unwrap()
17698  }
17699}
17700
17701impl<'a> SourceRanged for Tpl<'a> {
17702  fn start(&self) -> SourcePos {
17703    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17704  }
17705  fn end(&self) -> SourcePos {
17706    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17707  }
17708}
17709
17710impl<'a> From<&Tpl<'a>> for Node<'a> {
17711  fn from(node: &Tpl<'a>) -> Node<'a> {
17712    let node = unsafe { mem::transmute::<&Tpl<'a>, &'a Tpl<'a>>(node) };
17713    Node::Tpl(node)
17714  }
17715}
17716
17717impl<'a> NodeTrait<'a> for Tpl<'a> {
17718  fn parent(&self) -> Option<Node<'a>> {
17719    Some(self.parent.get().unwrap().clone())
17720  }
17721
17722  fn children(&self) -> Vec<Node<'a>> {
17723    let mut children = Vec::with_capacity(self.exprs.len() + self.quasis.len());
17724    for child in self.exprs.iter() {
17725      children.push(child.into());
17726    }
17727    for child in self.quasis.iter() {
17728      children.push((*child).into());
17729    }
17730    children
17731  }
17732
17733  fn as_node(&self) -> Node<'a> {
17734    self.into()
17735  }
17736
17737  fn kind(&self) -> NodeKind {
17738    NodeKind::Tpl
17739  }
17740}
17741
17742impl<'a> CastableNode<'a> for Tpl<'a> {
17743  fn to(node: &Node<'a>) -> Option<&'a Self> {
17744    if let Node::Tpl(node) = node {
17745      Some(node)
17746    } else {
17747      None
17748    }
17749  }
17750
17751  fn kind() -> NodeKind {
17752    NodeKind::Tpl
17753  }
17754}
17755
17756fn get_view_for_tpl<'a>(inner: &'a swc_ast::Tpl, bump: &'a Bump) -> &'a Tpl<'a> {
17757  let node = bump.alloc(Tpl {
17758    inner,
17759    parent: Default::default(),
17760    exprs: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.exprs.len(), bump);vec.extend(inner.exprs.iter().map(|value| get_view_for_expr(value, bump))); vec }),
17761    quasis: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.quasis.len(), bump);vec.extend(inner.quasis.iter().map(|value| get_view_for_tpl_element(value, bump))); vec }),
17762  });
17763  let parent: Node<'a> = (&*node).into();
17764  for value in node.exprs.iter() {
17765    set_parent_for_expr(value, parent)
17766  }
17767  for value in node.quasis.iter() {
17768    set_parent_for_tpl_element(value, parent)
17769  }
17770  node
17771}
17772
17773fn set_parent_for_tpl<'a>(node: &Tpl<'a>, parent: Node<'a>) {
17774  node.parent.set(parent);
17775}
17776
17777#[derive(Clone)]
17778pub struct TplElement<'a> {
17779  parent: ParentOnceCell<Node<'a>>,
17780  pub inner: &'a swc_ast::TplElement,
17781}
17782
17783impl<'a> TplElement<'a> {
17784  pub fn parent(&self) -> Node<'a> {
17785    self.parent.get().unwrap()
17786  }
17787
17788  pub fn tail(&self) -> bool {
17789    self.inner.tail
17790  }
17791
17792  /// This value is never used by `swc_ecma_codegen`, and this fact is
17793  /// considered as a public API.
17794  ///
17795  /// If you are going to use codegen right after creating a [TplElement], you
17796  /// don't have to worry about this value.
17797  pub fn cooked(&self) -> &Option<swc_atoms::Wtf8Atom> {
17798    &self.inner.cooked
17799  }
17800
17801  /// You may need to perform. `.replace("\r\n", "\n").replace('\r', "\n")` on
17802  /// this value.
17803  pub fn raw(&self) -> &swc_atoms::Atom {
17804    &self.inner.raw
17805  }
17806}
17807
17808impl<'a> SourceRanged for TplElement<'a> {
17809  fn start(&self) -> SourcePos {
17810    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17811  }
17812  fn end(&self) -> SourcePos {
17813    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17814  }
17815}
17816
17817impl<'a> From<&TplElement<'a>> for Node<'a> {
17818  fn from(node: &TplElement<'a>) -> Node<'a> {
17819    let node = unsafe { mem::transmute::<&TplElement<'a>, &'a TplElement<'a>>(node) };
17820    Node::TplElement(node)
17821  }
17822}
17823
17824impl<'a> NodeTrait<'a> for TplElement<'a> {
17825  fn parent(&self) -> Option<Node<'a>> {
17826    Some(self.parent.get().unwrap().clone())
17827  }
17828
17829  fn children(&self) -> Vec<Node<'a>> {
17830    Vec::with_capacity(0)
17831  }
17832
17833  fn as_node(&self) -> Node<'a> {
17834    self.into()
17835  }
17836
17837  fn kind(&self) -> NodeKind {
17838    NodeKind::TplElement
17839  }
17840}
17841
17842impl<'a> CastableNode<'a> for TplElement<'a> {
17843  fn to(node: &Node<'a>) -> Option<&'a Self> {
17844    if let Node::TplElement(node) = node {
17845      Some(node)
17846    } else {
17847      None
17848    }
17849  }
17850
17851  fn kind() -> NodeKind {
17852    NodeKind::TplElement
17853  }
17854}
17855
17856fn get_view_for_tpl_element<'a>(inner: &'a swc_ast::TplElement, bump: &'a Bump) -> &'a TplElement<'a> {
17857  let node = bump.alloc(TplElement {
17858    inner,
17859    parent: Default::default(),
17860  });
17861  node
17862}
17863
17864fn set_parent_for_tpl_element<'a>(node: &TplElement<'a>, parent: Node<'a>) {
17865  node.parent.set(parent);
17866}
17867
17868#[derive(Clone)]
17869pub struct TryStmt<'a> {
17870  parent: ParentOnceCell<Node<'a>>,
17871  pub inner: &'a swc_ast::TryStmt,
17872  pub block: &'a BlockStmt<'a>,
17873  pub handler: Option<&'a CatchClause<'a>>,
17874  pub finalizer: Option<&'a BlockStmt<'a>>,
17875}
17876
17877impl<'a> TryStmt<'a> {
17878  pub fn parent(&self) -> Node<'a> {
17879    self.parent.get().unwrap()
17880  }
17881}
17882
17883impl<'a> SourceRanged for TryStmt<'a> {
17884  fn start(&self) -> SourcePos {
17885    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17886  }
17887  fn end(&self) -> SourcePos {
17888    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17889  }
17890}
17891
17892impl<'a> From<&TryStmt<'a>> for Node<'a> {
17893  fn from(node: &TryStmt<'a>) -> Node<'a> {
17894    let node = unsafe { mem::transmute::<&TryStmt<'a>, &'a TryStmt<'a>>(node) };
17895    Node::TryStmt(node)
17896  }
17897}
17898
17899impl<'a> NodeTrait<'a> for TryStmt<'a> {
17900  fn parent(&self) -> Option<Node<'a>> {
17901    Some(self.parent.get().unwrap().clone())
17902  }
17903
17904  fn children(&self) -> Vec<Node<'a>> {
17905    let mut children = Vec::with_capacity(1 + match &self.handler { Some(_value) => 1, None => 0, } + match &self.finalizer { Some(_value) => 1, None => 0, });
17906    children.push(self.block.into());
17907    if let Some(child) = self.handler {
17908      children.push(child.into());
17909    }
17910    if let Some(child) = self.finalizer {
17911      children.push(child.into());
17912    }
17913    children
17914  }
17915
17916  fn as_node(&self) -> Node<'a> {
17917    self.into()
17918  }
17919
17920  fn kind(&self) -> NodeKind {
17921    NodeKind::TryStmt
17922  }
17923}
17924
17925impl<'a> CastableNode<'a> for TryStmt<'a> {
17926  fn to(node: &Node<'a>) -> Option<&'a Self> {
17927    if let Node::TryStmt(node) = node {
17928      Some(node)
17929    } else {
17930      None
17931    }
17932  }
17933
17934  fn kind() -> NodeKind {
17935    NodeKind::TryStmt
17936  }
17937}
17938
17939fn get_view_for_try_stmt<'a>(inner: &'a swc_ast::TryStmt, bump: &'a Bump) -> &'a TryStmt<'a> {
17940  let node = bump.alloc(TryStmt {
17941    inner,
17942    parent: Default::default(),
17943    block: get_view_for_block_stmt(&inner.block, bump),
17944    handler: match &inner.handler {
17945      Some(value) => Some(get_view_for_catch_clause(value, bump)),
17946      None => None,
17947    },
17948    finalizer: match &inner.finalizer {
17949      Some(value) => Some(get_view_for_block_stmt(value, bump)),
17950      None => None,
17951    },
17952  });
17953  let parent: Node<'a> = (&*node).into();
17954  set_parent_for_block_stmt(&node.block, parent);
17955  if let Some(value) = &node.handler {
17956    set_parent_for_catch_clause(value, parent)
17957  };
17958  if let Some(value) = &node.finalizer {
17959    set_parent_for_block_stmt(value, parent)
17960  };
17961  node
17962}
17963
17964fn set_parent_for_try_stmt<'a>(node: &TryStmt<'a>, parent: Node<'a>) {
17965  node.parent.set(parent);
17966}
17967
17968#[derive(Clone)]
17969pub struct TsArrayType<'a> {
17970  parent: ParentOnceCell<Node<'a>>,
17971  pub inner: &'a swc_ast::TsArrayType,
17972  pub elem_type: TsType<'a>,
17973}
17974
17975impl<'a> TsArrayType<'a> {
17976  pub fn parent(&self) -> Node<'a> {
17977    self.parent.get().unwrap()
17978  }
17979}
17980
17981impl<'a> SourceRanged for TsArrayType<'a> {
17982  fn start(&self) -> SourcePos {
17983    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17984  }
17985  fn end(&self) -> SourcePos {
17986    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17987  }
17988}
17989
17990impl<'a> From<&TsArrayType<'a>> for Node<'a> {
17991  fn from(node: &TsArrayType<'a>) -> Node<'a> {
17992    let node = unsafe { mem::transmute::<&TsArrayType<'a>, &'a TsArrayType<'a>>(node) };
17993    Node::TsArrayType(node)
17994  }
17995}
17996
17997impl<'a> NodeTrait<'a> for TsArrayType<'a> {
17998  fn parent(&self) -> Option<Node<'a>> {
17999    Some(self.parent.get().unwrap().clone())
18000  }
18001
18002  fn children(&self) -> Vec<Node<'a>> {
18003    let mut children = Vec::with_capacity(1);
18004    children.push((&self.elem_type).into());
18005    children
18006  }
18007
18008  fn as_node(&self) -> Node<'a> {
18009    self.into()
18010  }
18011
18012  fn kind(&self) -> NodeKind {
18013    NodeKind::TsArrayType
18014  }
18015}
18016
18017impl<'a> CastableNode<'a> for TsArrayType<'a> {
18018  fn to(node: &Node<'a>) -> Option<&'a Self> {
18019    if let Node::TsArrayType(node) = node {
18020      Some(node)
18021    } else {
18022      None
18023    }
18024  }
18025
18026  fn kind() -> NodeKind {
18027    NodeKind::TsArrayType
18028  }
18029}
18030
18031fn get_view_for_ts_array_type<'a>(inner: &'a swc_ast::TsArrayType, bump: &'a Bump) -> &'a TsArrayType<'a> {
18032  let node = bump.alloc(TsArrayType {
18033    inner,
18034    parent: Default::default(),
18035    elem_type: get_view_for_ts_type(&inner.elem_type, bump),
18036  });
18037  let parent: Node<'a> = (&*node).into();
18038  set_parent_for_ts_type(&node.elem_type, parent);
18039  node
18040}
18041
18042fn set_parent_for_ts_array_type<'a>(node: &TsArrayType<'a>, parent: Node<'a>) {
18043  node.parent.set(parent);
18044}
18045
18046#[derive(Clone)]
18047pub struct TsAsExpr<'a> {
18048  parent: ParentOnceCell<Node<'a>>,
18049  pub inner: &'a swc_ast::TsAsExpr,
18050  pub expr: Expr<'a>,
18051  pub type_ann: TsType<'a>,
18052}
18053
18054impl<'a> TsAsExpr<'a> {
18055  pub fn parent(&self) -> Node<'a> {
18056    self.parent.get().unwrap()
18057  }
18058}
18059
18060impl<'a> SourceRanged for TsAsExpr<'a> {
18061  fn start(&self) -> SourcePos {
18062    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18063  }
18064  fn end(&self) -> SourcePos {
18065    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18066  }
18067}
18068
18069impl<'a> From<&TsAsExpr<'a>> for Node<'a> {
18070  fn from(node: &TsAsExpr<'a>) -> Node<'a> {
18071    let node = unsafe { mem::transmute::<&TsAsExpr<'a>, &'a TsAsExpr<'a>>(node) };
18072    Node::TsAsExpr(node)
18073  }
18074}
18075
18076impl<'a> NodeTrait<'a> for TsAsExpr<'a> {
18077  fn parent(&self) -> Option<Node<'a>> {
18078    Some(self.parent.get().unwrap().clone())
18079  }
18080
18081  fn children(&self) -> Vec<Node<'a>> {
18082    let mut children = Vec::with_capacity(2);
18083    children.push((&self.expr).into());
18084    children.push((&self.type_ann).into());
18085    children
18086  }
18087
18088  fn as_node(&self) -> Node<'a> {
18089    self.into()
18090  }
18091
18092  fn kind(&self) -> NodeKind {
18093    NodeKind::TsAsExpr
18094  }
18095}
18096
18097impl<'a> CastableNode<'a> for TsAsExpr<'a> {
18098  fn to(node: &Node<'a>) -> Option<&'a Self> {
18099    if let Node::TsAsExpr(node) = node {
18100      Some(node)
18101    } else {
18102      None
18103    }
18104  }
18105
18106  fn kind() -> NodeKind {
18107    NodeKind::TsAsExpr
18108  }
18109}
18110
18111fn get_view_for_ts_as_expr<'a>(inner: &'a swc_ast::TsAsExpr, bump: &'a Bump) -> &'a TsAsExpr<'a> {
18112  let node = bump.alloc(TsAsExpr {
18113    inner,
18114    parent: Default::default(),
18115    expr: get_view_for_expr(&inner.expr, bump),
18116    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
18117  });
18118  let parent: Node<'a> = (&*node).into();
18119  set_parent_for_expr(&node.expr, parent);
18120  set_parent_for_ts_type(&node.type_ann, parent);
18121  node
18122}
18123
18124fn set_parent_for_ts_as_expr<'a>(node: &TsAsExpr<'a>, parent: Node<'a>) {
18125  node.parent.set(parent);
18126}
18127
18128#[derive(Clone)]
18129pub struct TsCallSignatureDecl<'a> {
18130  parent: ParentOnceCell<Node<'a>>,
18131  pub inner: &'a swc_ast::TsCallSignatureDecl,
18132  pub params: &'a [TsFnParam<'a>],
18133  pub type_ann: Option<&'a TsTypeAnn<'a>>,
18134  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
18135}
18136
18137impl<'a> TsCallSignatureDecl<'a> {
18138  pub fn parent(&self) -> Node<'a> {
18139    self.parent.get().unwrap()
18140  }
18141}
18142
18143impl<'a> SourceRanged for TsCallSignatureDecl<'a> {
18144  fn start(&self) -> SourcePos {
18145    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18146  }
18147  fn end(&self) -> SourcePos {
18148    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18149  }
18150}
18151
18152impl<'a> From<&TsCallSignatureDecl<'a>> for Node<'a> {
18153  fn from(node: &TsCallSignatureDecl<'a>) -> Node<'a> {
18154    let node = unsafe { mem::transmute::<&TsCallSignatureDecl<'a>, &'a TsCallSignatureDecl<'a>>(node) };
18155    Node::TsCallSignatureDecl(node)
18156  }
18157}
18158
18159impl<'a> NodeTrait<'a> for TsCallSignatureDecl<'a> {
18160  fn parent(&self) -> Option<Node<'a>> {
18161    Some(self.parent.get().unwrap().clone())
18162  }
18163
18164  fn children(&self) -> Vec<Node<'a>> {
18165    let mut children = Vec::with_capacity(self.params.len() + match &self.type_ann { Some(_value) => 1, None => 0, } + match &self.type_params { Some(_value) => 1, None => 0, });
18166    for child in self.params.iter() {
18167      children.push(child.into());
18168    }
18169    if let Some(child) = self.type_ann {
18170      children.push(child.into());
18171    }
18172    if let Some(child) = self.type_params {
18173      children.push(child.into());
18174    }
18175    children
18176  }
18177
18178  fn as_node(&self) -> Node<'a> {
18179    self.into()
18180  }
18181
18182  fn kind(&self) -> NodeKind {
18183    NodeKind::TsCallSignatureDecl
18184  }
18185}
18186
18187impl<'a> CastableNode<'a> for TsCallSignatureDecl<'a> {
18188  fn to(node: &Node<'a>) -> Option<&'a Self> {
18189    if let Node::TsCallSignatureDecl(node) = node {
18190      Some(node)
18191    } else {
18192      None
18193    }
18194  }
18195
18196  fn kind() -> NodeKind {
18197    NodeKind::TsCallSignatureDecl
18198  }
18199}
18200
18201fn get_view_for_ts_call_signature_decl<'a>(inner: &'a swc_ast::TsCallSignatureDecl, bump: &'a Bump) -> &'a TsCallSignatureDecl<'a> {
18202  let node = bump.alloc(TsCallSignatureDecl {
18203    inner,
18204    parent: Default::default(),
18205    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_ts_fn_param(value, bump))); vec }),
18206    type_ann: match &inner.type_ann {
18207      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
18208      None => None,
18209    },
18210    type_params: match &inner.type_params {
18211      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
18212      None => None,
18213    },
18214  });
18215  let parent: Node<'a> = (&*node).into();
18216  for value in node.params.iter() {
18217    set_parent_for_ts_fn_param(value, parent)
18218  }
18219  if let Some(value) = &node.type_ann {
18220    set_parent_for_ts_type_ann(value, parent)
18221  };
18222  if let Some(value) = &node.type_params {
18223    set_parent_for_ts_type_param_decl(value, parent)
18224  };
18225  node
18226}
18227
18228fn set_parent_for_ts_call_signature_decl<'a>(node: &TsCallSignatureDecl<'a>, parent: Node<'a>) {
18229  node.parent.set(parent);
18230}
18231
18232#[derive(Clone)]
18233pub struct TsConditionalType<'a> {
18234  parent: ParentOnceCell<Node<'a>>,
18235  pub inner: &'a swc_ast::TsConditionalType,
18236  pub check_type: TsType<'a>,
18237  pub extends_type: TsType<'a>,
18238  pub true_type: TsType<'a>,
18239  pub false_type: TsType<'a>,
18240}
18241
18242impl<'a> TsConditionalType<'a> {
18243  pub fn parent(&self) -> Node<'a> {
18244    self.parent.get().unwrap()
18245  }
18246}
18247
18248impl<'a> SourceRanged for TsConditionalType<'a> {
18249  fn start(&self) -> SourcePos {
18250    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18251  }
18252  fn end(&self) -> SourcePos {
18253    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18254  }
18255}
18256
18257impl<'a> From<&TsConditionalType<'a>> for Node<'a> {
18258  fn from(node: &TsConditionalType<'a>) -> Node<'a> {
18259    let node = unsafe { mem::transmute::<&TsConditionalType<'a>, &'a TsConditionalType<'a>>(node) };
18260    Node::TsConditionalType(node)
18261  }
18262}
18263
18264impl<'a> NodeTrait<'a> for TsConditionalType<'a> {
18265  fn parent(&self) -> Option<Node<'a>> {
18266    Some(self.parent.get().unwrap().clone())
18267  }
18268
18269  fn children(&self) -> Vec<Node<'a>> {
18270    let mut children = Vec::with_capacity(4);
18271    children.push((&self.check_type).into());
18272    children.push((&self.extends_type).into());
18273    children.push((&self.true_type).into());
18274    children.push((&self.false_type).into());
18275    children
18276  }
18277
18278  fn as_node(&self) -> Node<'a> {
18279    self.into()
18280  }
18281
18282  fn kind(&self) -> NodeKind {
18283    NodeKind::TsConditionalType
18284  }
18285}
18286
18287impl<'a> CastableNode<'a> for TsConditionalType<'a> {
18288  fn to(node: &Node<'a>) -> Option<&'a Self> {
18289    if let Node::TsConditionalType(node) = node {
18290      Some(node)
18291    } else {
18292      None
18293    }
18294  }
18295
18296  fn kind() -> NodeKind {
18297    NodeKind::TsConditionalType
18298  }
18299}
18300
18301fn get_view_for_ts_conditional_type<'a>(inner: &'a swc_ast::TsConditionalType, bump: &'a Bump) -> &'a TsConditionalType<'a> {
18302  let node = bump.alloc(TsConditionalType {
18303    inner,
18304    parent: Default::default(),
18305    check_type: get_view_for_ts_type(&inner.check_type, bump),
18306    extends_type: get_view_for_ts_type(&inner.extends_type, bump),
18307    true_type: get_view_for_ts_type(&inner.true_type, bump),
18308    false_type: get_view_for_ts_type(&inner.false_type, bump),
18309  });
18310  let parent: Node<'a> = (&*node).into();
18311  set_parent_for_ts_type(&node.check_type, parent);
18312  set_parent_for_ts_type(&node.extends_type, parent);
18313  set_parent_for_ts_type(&node.true_type, parent);
18314  set_parent_for_ts_type(&node.false_type, parent);
18315  node
18316}
18317
18318fn set_parent_for_ts_conditional_type<'a>(node: &TsConditionalType<'a>, parent: Node<'a>) {
18319  node.parent.set(parent);
18320}
18321
18322#[derive(Clone)]
18323pub struct TsConstAssertion<'a> {
18324  parent: ParentOnceCell<Node<'a>>,
18325  pub inner: &'a swc_ast::TsConstAssertion,
18326  pub expr: Expr<'a>,
18327}
18328
18329impl<'a> TsConstAssertion<'a> {
18330  pub fn parent(&self) -> Node<'a> {
18331    self.parent.get().unwrap()
18332  }
18333}
18334
18335impl<'a> SourceRanged for TsConstAssertion<'a> {
18336  fn start(&self) -> SourcePos {
18337    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18338  }
18339  fn end(&self) -> SourcePos {
18340    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18341  }
18342}
18343
18344impl<'a> From<&TsConstAssertion<'a>> for Node<'a> {
18345  fn from(node: &TsConstAssertion<'a>) -> Node<'a> {
18346    let node = unsafe { mem::transmute::<&TsConstAssertion<'a>, &'a TsConstAssertion<'a>>(node) };
18347    Node::TsConstAssertion(node)
18348  }
18349}
18350
18351impl<'a> NodeTrait<'a> for TsConstAssertion<'a> {
18352  fn parent(&self) -> Option<Node<'a>> {
18353    Some(self.parent.get().unwrap().clone())
18354  }
18355
18356  fn children(&self) -> Vec<Node<'a>> {
18357    let mut children = Vec::with_capacity(1);
18358    children.push((&self.expr).into());
18359    children
18360  }
18361
18362  fn as_node(&self) -> Node<'a> {
18363    self.into()
18364  }
18365
18366  fn kind(&self) -> NodeKind {
18367    NodeKind::TsConstAssertion
18368  }
18369}
18370
18371impl<'a> CastableNode<'a> for TsConstAssertion<'a> {
18372  fn to(node: &Node<'a>) -> Option<&'a Self> {
18373    if let Node::TsConstAssertion(node) = node {
18374      Some(node)
18375    } else {
18376      None
18377    }
18378  }
18379
18380  fn kind() -> NodeKind {
18381    NodeKind::TsConstAssertion
18382  }
18383}
18384
18385fn get_view_for_ts_const_assertion<'a>(inner: &'a swc_ast::TsConstAssertion, bump: &'a Bump) -> &'a TsConstAssertion<'a> {
18386  let node = bump.alloc(TsConstAssertion {
18387    inner,
18388    parent: Default::default(),
18389    expr: get_view_for_expr(&inner.expr, bump),
18390  });
18391  let parent: Node<'a> = (&*node).into();
18392  set_parent_for_expr(&node.expr, parent);
18393  node
18394}
18395
18396fn set_parent_for_ts_const_assertion<'a>(node: &TsConstAssertion<'a>, parent: Node<'a>) {
18397  node.parent.set(parent);
18398}
18399
18400#[derive(Clone)]
18401pub struct TsConstructSignatureDecl<'a> {
18402  parent: ParentOnceCell<Node<'a>>,
18403  pub inner: &'a swc_ast::TsConstructSignatureDecl,
18404  pub params: &'a [TsFnParam<'a>],
18405  pub type_ann: Option<&'a TsTypeAnn<'a>>,
18406  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
18407}
18408
18409impl<'a> TsConstructSignatureDecl<'a> {
18410  pub fn parent(&self) -> Node<'a> {
18411    self.parent.get().unwrap()
18412  }
18413}
18414
18415impl<'a> SourceRanged for TsConstructSignatureDecl<'a> {
18416  fn start(&self) -> SourcePos {
18417    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18418  }
18419  fn end(&self) -> SourcePos {
18420    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18421  }
18422}
18423
18424impl<'a> From<&TsConstructSignatureDecl<'a>> for Node<'a> {
18425  fn from(node: &TsConstructSignatureDecl<'a>) -> Node<'a> {
18426    let node = unsafe { mem::transmute::<&TsConstructSignatureDecl<'a>, &'a TsConstructSignatureDecl<'a>>(node) };
18427    Node::TsConstructSignatureDecl(node)
18428  }
18429}
18430
18431impl<'a> NodeTrait<'a> for TsConstructSignatureDecl<'a> {
18432  fn parent(&self) -> Option<Node<'a>> {
18433    Some(self.parent.get().unwrap().clone())
18434  }
18435
18436  fn children(&self) -> Vec<Node<'a>> {
18437    let mut children = Vec::with_capacity(self.params.len() + match &self.type_ann { Some(_value) => 1, None => 0, } + match &self.type_params { Some(_value) => 1, None => 0, });
18438    for child in self.params.iter() {
18439      children.push(child.into());
18440    }
18441    if let Some(child) = self.type_ann {
18442      children.push(child.into());
18443    }
18444    if let Some(child) = self.type_params {
18445      children.push(child.into());
18446    }
18447    children
18448  }
18449
18450  fn as_node(&self) -> Node<'a> {
18451    self.into()
18452  }
18453
18454  fn kind(&self) -> NodeKind {
18455    NodeKind::TsConstructSignatureDecl
18456  }
18457}
18458
18459impl<'a> CastableNode<'a> for TsConstructSignatureDecl<'a> {
18460  fn to(node: &Node<'a>) -> Option<&'a Self> {
18461    if let Node::TsConstructSignatureDecl(node) = node {
18462      Some(node)
18463    } else {
18464      None
18465    }
18466  }
18467
18468  fn kind() -> NodeKind {
18469    NodeKind::TsConstructSignatureDecl
18470  }
18471}
18472
18473fn get_view_for_ts_construct_signature_decl<'a>(inner: &'a swc_ast::TsConstructSignatureDecl, bump: &'a Bump) -> &'a TsConstructSignatureDecl<'a> {
18474  let node = bump.alloc(TsConstructSignatureDecl {
18475    inner,
18476    parent: Default::default(),
18477    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_ts_fn_param(value, bump))); vec }),
18478    type_ann: match &inner.type_ann {
18479      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
18480      None => None,
18481    },
18482    type_params: match &inner.type_params {
18483      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
18484      None => None,
18485    },
18486  });
18487  let parent: Node<'a> = (&*node).into();
18488  for value in node.params.iter() {
18489    set_parent_for_ts_fn_param(value, parent)
18490  }
18491  if let Some(value) = &node.type_ann {
18492    set_parent_for_ts_type_ann(value, parent)
18493  };
18494  if let Some(value) = &node.type_params {
18495    set_parent_for_ts_type_param_decl(value, parent)
18496  };
18497  node
18498}
18499
18500fn set_parent_for_ts_construct_signature_decl<'a>(node: &TsConstructSignatureDecl<'a>, parent: Node<'a>) {
18501  node.parent.set(parent);
18502}
18503
18504#[derive(Clone)]
18505pub struct TsConstructorType<'a> {
18506  parent: ParentOnceCell<Node<'a>>,
18507  pub inner: &'a swc_ast::TsConstructorType,
18508  pub params: &'a [TsFnParam<'a>],
18509  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
18510  pub type_ann: &'a TsTypeAnn<'a>,
18511}
18512
18513impl<'a> TsConstructorType<'a> {
18514  pub fn parent(&self) -> Node<'a> {
18515    self.parent.get().unwrap()
18516  }
18517
18518  pub fn is_abstract(&self) -> bool {
18519    self.inner.is_abstract
18520  }
18521}
18522
18523impl<'a> SourceRanged for TsConstructorType<'a> {
18524  fn start(&self) -> SourcePos {
18525    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18526  }
18527  fn end(&self) -> SourcePos {
18528    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18529  }
18530}
18531
18532impl<'a> From<&TsConstructorType<'a>> for Node<'a> {
18533  fn from(node: &TsConstructorType<'a>) -> Node<'a> {
18534    let node = unsafe { mem::transmute::<&TsConstructorType<'a>, &'a TsConstructorType<'a>>(node) };
18535    Node::TsConstructorType(node)
18536  }
18537}
18538
18539impl<'a> NodeTrait<'a> for TsConstructorType<'a> {
18540  fn parent(&self) -> Option<Node<'a>> {
18541    Some(self.parent.get().unwrap().clone())
18542  }
18543
18544  fn children(&self) -> Vec<Node<'a>> {
18545    let mut children = Vec::with_capacity(1 + self.params.len() + match &self.type_params { Some(_value) => 1, None => 0, });
18546    for child in self.params.iter() {
18547      children.push(child.into());
18548    }
18549    if let Some(child) = self.type_params {
18550      children.push(child.into());
18551    }
18552    children.push(self.type_ann.into());
18553    children
18554  }
18555
18556  fn as_node(&self) -> Node<'a> {
18557    self.into()
18558  }
18559
18560  fn kind(&self) -> NodeKind {
18561    NodeKind::TsConstructorType
18562  }
18563}
18564
18565impl<'a> CastableNode<'a> for TsConstructorType<'a> {
18566  fn to(node: &Node<'a>) -> Option<&'a Self> {
18567    if let Node::TsConstructorType(node) = node {
18568      Some(node)
18569    } else {
18570      None
18571    }
18572  }
18573
18574  fn kind() -> NodeKind {
18575    NodeKind::TsConstructorType
18576  }
18577}
18578
18579fn get_view_for_ts_constructor_type<'a>(inner: &'a swc_ast::TsConstructorType, bump: &'a Bump) -> &'a TsConstructorType<'a> {
18580  let node = bump.alloc(TsConstructorType {
18581    inner,
18582    parent: Default::default(),
18583    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_ts_fn_param(value, bump))); vec }),
18584    type_params: match &inner.type_params {
18585      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
18586      None => None,
18587    },
18588    type_ann: get_view_for_ts_type_ann(&inner.type_ann, bump),
18589  });
18590  let parent: Node<'a> = (&*node).into();
18591  for value in node.params.iter() {
18592    set_parent_for_ts_fn_param(value, parent)
18593  }
18594  if let Some(value) = &node.type_params {
18595    set_parent_for_ts_type_param_decl(value, parent)
18596  };
18597  set_parent_for_ts_type_ann(&node.type_ann, parent);
18598  node
18599}
18600
18601fn set_parent_for_ts_constructor_type<'a>(node: &TsConstructorType<'a>, parent: Node<'a>) {
18602  node.parent.set(parent);
18603}
18604
18605#[derive(Clone)]
18606pub struct TsEnumDecl<'a> {
18607  parent: ParentOnceCell<Node<'a>>,
18608  pub inner: &'a swc_ast::TsEnumDecl,
18609  pub id: &'a Ident<'a>,
18610  pub members: &'a [&'a TsEnumMember<'a>],
18611}
18612
18613impl<'a> TsEnumDecl<'a> {
18614  pub fn parent(&self) -> Node<'a> {
18615    self.parent.get().unwrap()
18616  }
18617
18618  pub fn declare(&self) -> bool {
18619    self.inner.declare
18620  }
18621
18622  pub fn is_const(&self) -> bool {
18623    self.inner.is_const
18624  }
18625}
18626
18627impl<'a> SourceRanged for TsEnumDecl<'a> {
18628  fn start(&self) -> SourcePos {
18629    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18630  }
18631  fn end(&self) -> SourcePos {
18632    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18633  }
18634}
18635
18636impl<'a> From<&TsEnumDecl<'a>> for Node<'a> {
18637  fn from(node: &TsEnumDecl<'a>) -> Node<'a> {
18638    let node = unsafe { mem::transmute::<&TsEnumDecl<'a>, &'a TsEnumDecl<'a>>(node) };
18639    Node::TsEnumDecl(node)
18640  }
18641}
18642
18643impl<'a> NodeTrait<'a> for TsEnumDecl<'a> {
18644  fn parent(&self) -> Option<Node<'a>> {
18645    Some(self.parent.get().unwrap().clone())
18646  }
18647
18648  fn children(&self) -> Vec<Node<'a>> {
18649    let mut children = Vec::with_capacity(1 + self.members.len());
18650    children.push(self.id.into());
18651    for child in self.members.iter() {
18652      children.push((*child).into());
18653    }
18654    children
18655  }
18656
18657  fn as_node(&self) -> Node<'a> {
18658    self.into()
18659  }
18660
18661  fn kind(&self) -> NodeKind {
18662    NodeKind::TsEnumDecl
18663  }
18664}
18665
18666impl<'a> CastableNode<'a> for TsEnumDecl<'a> {
18667  fn to(node: &Node<'a>) -> Option<&'a Self> {
18668    if let Node::TsEnumDecl(node) = node {
18669      Some(node)
18670    } else {
18671      None
18672    }
18673  }
18674
18675  fn kind() -> NodeKind {
18676    NodeKind::TsEnumDecl
18677  }
18678}
18679
18680fn get_view_for_ts_enum_decl<'a>(inner: &'a swc_ast::TsEnumDecl, bump: &'a Bump) -> &'a TsEnumDecl<'a> {
18681  let node = bump.alloc(TsEnumDecl {
18682    inner,
18683    parent: Default::default(),
18684    id: get_view_for_ident(&inner.id, bump),
18685    members: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.members.len(), bump);vec.extend(inner.members.iter().map(|value| get_view_for_ts_enum_member(value, bump))); vec }),
18686  });
18687  let parent: Node<'a> = (&*node).into();
18688  set_parent_for_ident(&node.id, parent);
18689  for value in node.members.iter() {
18690    set_parent_for_ts_enum_member(value, parent)
18691  }
18692  node
18693}
18694
18695fn set_parent_for_ts_enum_decl<'a>(node: &TsEnumDecl<'a>, parent: Node<'a>) {
18696  node.parent.set(parent);
18697}
18698
18699#[derive(Clone)]
18700pub struct TsEnumMember<'a> {
18701  parent: ParentOnceCell<&'a TsEnumDecl<'a>>,
18702  pub inner: &'a swc_ast::TsEnumMember,
18703  pub id: TsEnumMemberId<'a>,
18704  pub init: Option<Expr<'a>>,
18705}
18706
18707impl<'a> TsEnumMember<'a> {
18708  pub fn parent(&self) -> &'a TsEnumDecl<'a> {
18709    self.parent.get().unwrap()
18710  }
18711}
18712
18713impl<'a> SourceRanged for TsEnumMember<'a> {
18714  fn start(&self) -> SourcePos {
18715    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18716  }
18717  fn end(&self) -> SourcePos {
18718    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18719  }
18720}
18721
18722impl<'a> From<&TsEnumMember<'a>> for Node<'a> {
18723  fn from(node: &TsEnumMember<'a>) -> Node<'a> {
18724    let node = unsafe { mem::transmute::<&TsEnumMember<'a>, &'a TsEnumMember<'a>>(node) };
18725    Node::TsEnumMember(node)
18726  }
18727}
18728
18729impl<'a> NodeTrait<'a> for TsEnumMember<'a> {
18730  fn parent(&self) -> Option<Node<'a>> {
18731    Some(self.parent.get().unwrap().into())
18732  }
18733
18734  fn children(&self) -> Vec<Node<'a>> {
18735    let mut children = Vec::with_capacity(1 + match &self.init { Some(_value) => 1, None => 0, });
18736    children.push((&self.id).into());
18737    if let Some(child) = self.init.as_ref() {
18738      children.push(child.into());
18739    }
18740    children
18741  }
18742
18743  fn as_node(&self) -> Node<'a> {
18744    self.into()
18745  }
18746
18747  fn kind(&self) -> NodeKind {
18748    NodeKind::TsEnumMember
18749  }
18750}
18751
18752impl<'a> CastableNode<'a> for TsEnumMember<'a> {
18753  fn to(node: &Node<'a>) -> Option<&'a Self> {
18754    if let Node::TsEnumMember(node) = node {
18755      Some(node)
18756    } else {
18757      None
18758    }
18759  }
18760
18761  fn kind() -> NodeKind {
18762    NodeKind::TsEnumMember
18763  }
18764}
18765
18766fn get_view_for_ts_enum_member<'a>(inner: &'a swc_ast::TsEnumMember, bump: &'a Bump) -> &'a TsEnumMember<'a> {
18767  let node = bump.alloc(TsEnumMember {
18768    inner,
18769    parent: Default::default(),
18770    id: get_view_for_ts_enum_member_id(&inner.id, bump),
18771    init: match &inner.init {
18772      Some(value) => Some(get_view_for_expr(value, bump)),
18773      None => None,
18774    },
18775  });
18776  let parent: Node<'a> = (&*node).into();
18777  set_parent_for_ts_enum_member_id(&node.id, parent);
18778  if let Some(value) = &node.init {
18779    set_parent_for_expr(value, parent)
18780  };
18781  node
18782}
18783
18784fn set_parent_for_ts_enum_member<'a>(node: &TsEnumMember<'a>, parent: Node<'a>) {
18785  node.parent.set(parent.expect::<TsEnumDecl>());
18786}
18787
18788/// TypeScript's own parser uses ExportAssignment for both `export default` and
18789/// `export =`. But for @babel/parser, `export default` is an ExportDefaultDecl,
18790/// so a TsExportAssignment is always `export =`.
18791#[derive(Clone)]
18792pub struct TsExportAssignment<'a> {
18793  parent: ParentOnceCell<Node<'a>>,
18794  pub inner: &'a swc_ast::TsExportAssignment,
18795  pub expr: Expr<'a>,
18796}
18797
18798impl<'a> TsExportAssignment<'a> {
18799  pub fn parent(&self) -> Node<'a> {
18800    self.parent.get().unwrap()
18801  }
18802}
18803
18804impl<'a> SourceRanged for TsExportAssignment<'a> {
18805  fn start(&self) -> SourcePos {
18806    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18807  }
18808  fn end(&self) -> SourcePos {
18809    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18810  }
18811}
18812
18813impl<'a> From<&TsExportAssignment<'a>> for Node<'a> {
18814  fn from(node: &TsExportAssignment<'a>) -> Node<'a> {
18815    let node = unsafe { mem::transmute::<&TsExportAssignment<'a>, &'a TsExportAssignment<'a>>(node) };
18816    Node::TsExportAssignment(node)
18817  }
18818}
18819
18820impl<'a> NodeTrait<'a> for TsExportAssignment<'a> {
18821  fn parent(&self) -> Option<Node<'a>> {
18822    Some(self.parent.get().unwrap().clone())
18823  }
18824
18825  fn children(&self) -> Vec<Node<'a>> {
18826    let mut children = Vec::with_capacity(1);
18827    children.push((&self.expr).into());
18828    children
18829  }
18830
18831  fn as_node(&self) -> Node<'a> {
18832    self.into()
18833  }
18834
18835  fn kind(&self) -> NodeKind {
18836    NodeKind::TsExportAssignment
18837  }
18838}
18839
18840impl<'a> CastableNode<'a> for TsExportAssignment<'a> {
18841  fn to(node: &Node<'a>) -> Option<&'a Self> {
18842    if let Node::TsExportAssignment(node) = node {
18843      Some(node)
18844    } else {
18845      None
18846    }
18847  }
18848
18849  fn kind() -> NodeKind {
18850    NodeKind::TsExportAssignment
18851  }
18852}
18853
18854fn get_view_for_ts_export_assignment<'a>(inner: &'a swc_ast::TsExportAssignment, bump: &'a Bump) -> &'a TsExportAssignment<'a> {
18855  let node = bump.alloc(TsExportAssignment {
18856    inner,
18857    parent: Default::default(),
18858    expr: get_view_for_expr(&inner.expr, bump),
18859  });
18860  let parent: Node<'a> = (&*node).into();
18861  set_parent_for_expr(&node.expr, parent);
18862  node
18863}
18864
18865fn set_parent_for_ts_export_assignment<'a>(node: &TsExportAssignment<'a>, parent: Node<'a>) {
18866  node.parent.set(parent);
18867}
18868
18869#[derive(Clone)]
18870pub struct TsExprWithTypeArgs<'a> {
18871  parent: ParentOnceCell<Node<'a>>,
18872  pub inner: &'a swc_ast::TsExprWithTypeArgs,
18873  pub expr: Expr<'a>,
18874  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
18875}
18876
18877impl<'a> TsExprWithTypeArgs<'a> {
18878  pub fn parent(&self) -> Node<'a> {
18879    self.parent.get().unwrap()
18880  }
18881}
18882
18883impl<'a> SourceRanged for TsExprWithTypeArgs<'a> {
18884  fn start(&self) -> SourcePos {
18885    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18886  }
18887  fn end(&self) -> SourcePos {
18888    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18889  }
18890}
18891
18892impl<'a> From<&TsExprWithTypeArgs<'a>> for Node<'a> {
18893  fn from(node: &TsExprWithTypeArgs<'a>) -> Node<'a> {
18894    let node = unsafe { mem::transmute::<&TsExprWithTypeArgs<'a>, &'a TsExprWithTypeArgs<'a>>(node) };
18895    Node::TsExprWithTypeArgs(node)
18896  }
18897}
18898
18899impl<'a> NodeTrait<'a> for TsExprWithTypeArgs<'a> {
18900  fn parent(&self) -> Option<Node<'a>> {
18901    Some(self.parent.get().unwrap().clone())
18902  }
18903
18904  fn children(&self) -> Vec<Node<'a>> {
18905    let mut children = Vec::with_capacity(1 + match &self.type_args { Some(_value) => 1, None => 0, });
18906    children.push((&self.expr).into());
18907    if let Some(child) = self.type_args {
18908      children.push(child.into());
18909    }
18910    children
18911  }
18912
18913  fn as_node(&self) -> Node<'a> {
18914    self.into()
18915  }
18916
18917  fn kind(&self) -> NodeKind {
18918    NodeKind::TsExprWithTypeArgs
18919  }
18920}
18921
18922impl<'a> CastableNode<'a> for TsExprWithTypeArgs<'a> {
18923  fn to(node: &Node<'a>) -> Option<&'a Self> {
18924    if let Node::TsExprWithTypeArgs(node) = node {
18925      Some(node)
18926    } else {
18927      None
18928    }
18929  }
18930
18931  fn kind() -> NodeKind {
18932    NodeKind::TsExprWithTypeArgs
18933  }
18934}
18935
18936fn get_view_for_ts_expr_with_type_args<'a>(inner: &'a swc_ast::TsExprWithTypeArgs, bump: &'a Bump) -> &'a TsExprWithTypeArgs<'a> {
18937  let node = bump.alloc(TsExprWithTypeArgs {
18938    inner,
18939    parent: Default::default(),
18940    expr: get_view_for_expr(&inner.expr, bump),
18941    type_args: match &inner.type_args {
18942      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
18943      None => None,
18944    },
18945  });
18946  let parent: Node<'a> = (&*node).into();
18947  set_parent_for_expr(&node.expr, parent);
18948  if let Some(value) = &node.type_args {
18949    set_parent_for_ts_type_param_instantiation(value, parent)
18950  };
18951  node
18952}
18953
18954fn set_parent_for_ts_expr_with_type_args<'a>(node: &TsExprWithTypeArgs<'a>, parent: Node<'a>) {
18955  node.parent.set(parent);
18956}
18957
18958#[derive(Clone)]
18959pub struct TsExternalModuleRef<'a> {
18960  parent: ParentOnceCell<&'a TsImportEqualsDecl<'a>>,
18961  pub inner: &'a swc_ast::TsExternalModuleRef,
18962  pub expr: &'a Str<'a>,
18963}
18964
18965impl<'a> TsExternalModuleRef<'a> {
18966  pub fn parent(&self) -> &'a TsImportEqualsDecl<'a> {
18967    self.parent.get().unwrap()
18968  }
18969}
18970
18971impl<'a> SourceRanged for TsExternalModuleRef<'a> {
18972  fn start(&self) -> SourcePos {
18973    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18974  }
18975  fn end(&self) -> SourcePos {
18976    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18977  }
18978}
18979
18980impl<'a> From<&TsExternalModuleRef<'a>> for Node<'a> {
18981  fn from(node: &TsExternalModuleRef<'a>) -> Node<'a> {
18982    let node = unsafe { mem::transmute::<&TsExternalModuleRef<'a>, &'a TsExternalModuleRef<'a>>(node) };
18983    Node::TsExternalModuleRef(node)
18984  }
18985}
18986
18987impl<'a> NodeTrait<'a> for TsExternalModuleRef<'a> {
18988  fn parent(&self) -> Option<Node<'a>> {
18989    Some(self.parent.get().unwrap().into())
18990  }
18991
18992  fn children(&self) -> Vec<Node<'a>> {
18993    let mut children = Vec::with_capacity(1);
18994    children.push(self.expr.into());
18995    children
18996  }
18997
18998  fn as_node(&self) -> Node<'a> {
18999    self.into()
19000  }
19001
19002  fn kind(&self) -> NodeKind {
19003    NodeKind::TsExternalModuleRef
19004  }
19005}
19006
19007impl<'a> CastableNode<'a> for TsExternalModuleRef<'a> {
19008  fn to(node: &Node<'a>) -> Option<&'a Self> {
19009    if let Node::TsExternalModuleRef(node) = node {
19010      Some(node)
19011    } else {
19012      None
19013    }
19014  }
19015
19016  fn kind() -> NodeKind {
19017    NodeKind::TsExternalModuleRef
19018  }
19019}
19020
19021fn get_view_for_ts_external_module_ref<'a>(inner: &'a swc_ast::TsExternalModuleRef, bump: &'a Bump) -> &'a TsExternalModuleRef<'a> {
19022  let node = bump.alloc(TsExternalModuleRef {
19023    inner,
19024    parent: Default::default(),
19025    expr: get_view_for_str(&inner.expr, bump),
19026  });
19027  let parent: Node<'a> = (&*node).into();
19028  set_parent_for_str(&node.expr, parent);
19029  node
19030}
19031
19032fn set_parent_for_ts_external_module_ref<'a>(node: &TsExternalModuleRef<'a>, parent: Node<'a>) {
19033  node.parent.set(parent.expect::<TsImportEqualsDecl>());
19034}
19035
19036#[derive(Clone)]
19037pub struct TsFnType<'a> {
19038  parent: ParentOnceCell<Node<'a>>,
19039  pub inner: &'a swc_ast::TsFnType,
19040  pub params: &'a [TsFnParam<'a>],
19041  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
19042  pub type_ann: &'a TsTypeAnn<'a>,
19043}
19044
19045impl<'a> TsFnType<'a> {
19046  pub fn parent(&self) -> Node<'a> {
19047    self.parent.get().unwrap()
19048  }
19049}
19050
19051impl<'a> SourceRanged for TsFnType<'a> {
19052  fn start(&self) -> SourcePos {
19053    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19054  }
19055  fn end(&self) -> SourcePos {
19056    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19057  }
19058}
19059
19060impl<'a> From<&TsFnType<'a>> for Node<'a> {
19061  fn from(node: &TsFnType<'a>) -> Node<'a> {
19062    let node = unsafe { mem::transmute::<&TsFnType<'a>, &'a TsFnType<'a>>(node) };
19063    Node::TsFnType(node)
19064  }
19065}
19066
19067impl<'a> NodeTrait<'a> for TsFnType<'a> {
19068  fn parent(&self) -> Option<Node<'a>> {
19069    Some(self.parent.get().unwrap().clone())
19070  }
19071
19072  fn children(&self) -> Vec<Node<'a>> {
19073    let mut children = Vec::with_capacity(1 + self.params.len() + match &self.type_params { Some(_value) => 1, None => 0, });
19074    for child in self.params.iter() {
19075      children.push(child.into());
19076    }
19077    if let Some(child) = self.type_params {
19078      children.push(child.into());
19079    }
19080    children.push(self.type_ann.into());
19081    children
19082  }
19083
19084  fn as_node(&self) -> Node<'a> {
19085    self.into()
19086  }
19087
19088  fn kind(&self) -> NodeKind {
19089    NodeKind::TsFnType
19090  }
19091}
19092
19093impl<'a> CastableNode<'a> for TsFnType<'a> {
19094  fn to(node: &Node<'a>) -> Option<&'a Self> {
19095    if let Node::TsFnType(node) = node {
19096      Some(node)
19097    } else {
19098      None
19099    }
19100  }
19101
19102  fn kind() -> NodeKind {
19103    NodeKind::TsFnType
19104  }
19105}
19106
19107fn get_view_for_ts_fn_type<'a>(inner: &'a swc_ast::TsFnType, bump: &'a Bump) -> &'a TsFnType<'a> {
19108  let node = bump.alloc(TsFnType {
19109    inner,
19110    parent: Default::default(),
19111    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_ts_fn_param(value, bump))); vec }),
19112    type_params: match &inner.type_params {
19113      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
19114      None => None,
19115    },
19116    type_ann: get_view_for_ts_type_ann(&inner.type_ann, bump),
19117  });
19118  let parent: Node<'a> = (&*node).into();
19119  for value in node.params.iter() {
19120    set_parent_for_ts_fn_param(value, parent)
19121  }
19122  if let Some(value) = &node.type_params {
19123    set_parent_for_ts_type_param_decl(value, parent)
19124  };
19125  set_parent_for_ts_type_ann(&node.type_ann, parent);
19126  node
19127}
19128
19129fn set_parent_for_ts_fn_type<'a>(node: &TsFnType<'a>, parent: Node<'a>) {
19130  node.parent.set(parent);
19131}
19132
19133#[derive(Clone)]
19134pub struct TsGetterSignature<'a> {
19135  parent: ParentOnceCell<Node<'a>>,
19136  pub inner: &'a swc_ast::TsGetterSignature,
19137  pub key: Expr<'a>,
19138  pub type_ann: Option<&'a TsTypeAnn<'a>>,
19139}
19140
19141impl<'a> TsGetterSignature<'a> {
19142  pub fn parent(&self) -> Node<'a> {
19143    self.parent.get().unwrap()
19144  }
19145
19146  pub fn computed(&self) -> bool {
19147    self.inner.computed
19148  }
19149}
19150
19151impl<'a> SourceRanged for TsGetterSignature<'a> {
19152  fn start(&self) -> SourcePos {
19153    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19154  }
19155  fn end(&self) -> SourcePos {
19156    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19157  }
19158}
19159
19160impl<'a> From<&TsGetterSignature<'a>> for Node<'a> {
19161  fn from(node: &TsGetterSignature<'a>) -> Node<'a> {
19162    let node = unsafe { mem::transmute::<&TsGetterSignature<'a>, &'a TsGetterSignature<'a>>(node) };
19163    Node::TsGetterSignature(node)
19164  }
19165}
19166
19167impl<'a> NodeTrait<'a> for TsGetterSignature<'a> {
19168  fn parent(&self) -> Option<Node<'a>> {
19169    Some(self.parent.get().unwrap().clone())
19170  }
19171
19172  fn children(&self) -> Vec<Node<'a>> {
19173    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
19174    children.push((&self.key).into());
19175    if let Some(child) = self.type_ann {
19176      children.push(child.into());
19177    }
19178    children
19179  }
19180
19181  fn as_node(&self) -> Node<'a> {
19182    self.into()
19183  }
19184
19185  fn kind(&self) -> NodeKind {
19186    NodeKind::TsGetterSignature
19187  }
19188}
19189
19190impl<'a> CastableNode<'a> for TsGetterSignature<'a> {
19191  fn to(node: &Node<'a>) -> Option<&'a Self> {
19192    if let Node::TsGetterSignature(node) = node {
19193      Some(node)
19194    } else {
19195      None
19196    }
19197  }
19198
19199  fn kind() -> NodeKind {
19200    NodeKind::TsGetterSignature
19201  }
19202}
19203
19204fn get_view_for_ts_getter_signature<'a>(inner: &'a swc_ast::TsGetterSignature, bump: &'a Bump) -> &'a TsGetterSignature<'a> {
19205  let node = bump.alloc(TsGetterSignature {
19206    inner,
19207    parent: Default::default(),
19208    key: get_view_for_expr(&inner.key, bump),
19209    type_ann: match &inner.type_ann {
19210      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
19211      None => None,
19212    },
19213  });
19214  let parent: Node<'a> = (&*node).into();
19215  set_parent_for_expr(&node.key, parent);
19216  if let Some(value) = &node.type_ann {
19217    set_parent_for_ts_type_ann(value, parent)
19218  };
19219  node
19220}
19221
19222fn set_parent_for_ts_getter_signature<'a>(node: &TsGetterSignature<'a>, parent: Node<'a>) {
19223  node.parent.set(parent);
19224}
19225
19226#[derive(Clone)]
19227pub struct TsImportCallOptions<'a> {
19228  parent: ParentOnceCell<&'a TsImportType<'a>>,
19229  pub inner: &'a swc_ast::TsImportCallOptions,
19230  pub with: &'a ObjectLit<'a>,
19231}
19232
19233impl<'a> TsImportCallOptions<'a> {
19234  pub fn parent(&self) -> &'a TsImportType<'a> {
19235    self.parent.get().unwrap()
19236  }
19237}
19238
19239impl<'a> SourceRanged for TsImportCallOptions<'a> {
19240  fn start(&self) -> SourcePos {
19241    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19242  }
19243  fn end(&self) -> SourcePos {
19244    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19245  }
19246}
19247
19248impl<'a> From<&TsImportCallOptions<'a>> for Node<'a> {
19249  fn from(node: &TsImportCallOptions<'a>) -> Node<'a> {
19250    let node = unsafe { mem::transmute::<&TsImportCallOptions<'a>, &'a TsImportCallOptions<'a>>(node) };
19251    Node::TsImportCallOptions(node)
19252  }
19253}
19254
19255impl<'a> NodeTrait<'a> for TsImportCallOptions<'a> {
19256  fn parent(&self) -> Option<Node<'a>> {
19257    Some(self.parent.get().unwrap().into())
19258  }
19259
19260  fn children(&self) -> Vec<Node<'a>> {
19261    let mut children = Vec::with_capacity(1);
19262    children.push(self.with.into());
19263    children
19264  }
19265
19266  fn as_node(&self) -> Node<'a> {
19267    self.into()
19268  }
19269
19270  fn kind(&self) -> NodeKind {
19271    NodeKind::TsImportCallOptions
19272  }
19273}
19274
19275impl<'a> CastableNode<'a> for TsImportCallOptions<'a> {
19276  fn to(node: &Node<'a>) -> Option<&'a Self> {
19277    if let Node::TsImportCallOptions(node) = node {
19278      Some(node)
19279    } else {
19280      None
19281    }
19282  }
19283
19284  fn kind() -> NodeKind {
19285    NodeKind::TsImportCallOptions
19286  }
19287}
19288
19289fn get_view_for_ts_import_call_options<'a>(inner: &'a swc_ast::TsImportCallOptions, bump: &'a Bump) -> &'a TsImportCallOptions<'a> {
19290  let node = bump.alloc(TsImportCallOptions {
19291    inner,
19292    parent: Default::default(),
19293    with: get_view_for_object_lit(&inner.with, bump),
19294  });
19295  let parent: Node<'a> = (&*node).into();
19296  set_parent_for_object_lit(&node.with, parent);
19297  node
19298}
19299
19300fn set_parent_for_ts_import_call_options<'a>(node: &TsImportCallOptions<'a>, parent: Node<'a>) {
19301  node.parent.set(parent.expect::<TsImportType>());
19302}
19303
19304#[derive(Clone)]
19305pub struct TsImportEqualsDecl<'a> {
19306  parent: ParentOnceCell<Node<'a>>,
19307  pub inner: &'a swc_ast::TsImportEqualsDecl,
19308  pub id: &'a Ident<'a>,
19309  pub module_ref: TsModuleRef<'a>,
19310}
19311
19312impl<'a> TsImportEqualsDecl<'a> {
19313  pub fn parent(&self) -> Node<'a> {
19314    self.parent.get().unwrap()
19315  }
19316
19317  pub fn is_export(&self) -> bool {
19318    self.inner.is_export
19319  }
19320
19321  pub fn is_type_only(&self) -> bool {
19322    self.inner.is_type_only
19323  }
19324}
19325
19326impl<'a> SourceRanged for TsImportEqualsDecl<'a> {
19327  fn start(&self) -> SourcePos {
19328    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19329  }
19330  fn end(&self) -> SourcePos {
19331    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19332  }
19333}
19334
19335impl<'a> From<&TsImportEqualsDecl<'a>> for Node<'a> {
19336  fn from(node: &TsImportEqualsDecl<'a>) -> Node<'a> {
19337    let node = unsafe { mem::transmute::<&TsImportEqualsDecl<'a>, &'a TsImportEqualsDecl<'a>>(node) };
19338    Node::TsImportEqualsDecl(node)
19339  }
19340}
19341
19342impl<'a> NodeTrait<'a> for TsImportEqualsDecl<'a> {
19343  fn parent(&self) -> Option<Node<'a>> {
19344    Some(self.parent.get().unwrap().clone())
19345  }
19346
19347  fn children(&self) -> Vec<Node<'a>> {
19348    let mut children = Vec::with_capacity(2);
19349    children.push(self.id.into());
19350    children.push((&self.module_ref).into());
19351    children
19352  }
19353
19354  fn as_node(&self) -> Node<'a> {
19355    self.into()
19356  }
19357
19358  fn kind(&self) -> NodeKind {
19359    NodeKind::TsImportEqualsDecl
19360  }
19361}
19362
19363impl<'a> CastableNode<'a> for TsImportEqualsDecl<'a> {
19364  fn to(node: &Node<'a>) -> Option<&'a Self> {
19365    if let Node::TsImportEqualsDecl(node) = node {
19366      Some(node)
19367    } else {
19368      None
19369    }
19370  }
19371
19372  fn kind() -> NodeKind {
19373    NodeKind::TsImportEqualsDecl
19374  }
19375}
19376
19377fn get_view_for_ts_import_equals_decl<'a>(inner: &'a swc_ast::TsImportEqualsDecl, bump: &'a Bump) -> &'a TsImportEqualsDecl<'a> {
19378  let node = bump.alloc(TsImportEqualsDecl {
19379    inner,
19380    parent: Default::default(),
19381    id: get_view_for_ident(&inner.id, bump),
19382    module_ref: get_view_for_ts_module_ref(&inner.module_ref, bump),
19383  });
19384  let parent: Node<'a> = (&*node).into();
19385  set_parent_for_ident(&node.id, parent);
19386  set_parent_for_ts_module_ref(&node.module_ref, parent);
19387  node
19388}
19389
19390fn set_parent_for_ts_import_equals_decl<'a>(node: &TsImportEqualsDecl<'a>, parent: Node<'a>) {
19391  node.parent.set(parent);
19392}
19393
19394#[derive(Clone)]
19395pub struct TsImportType<'a> {
19396  parent: ParentOnceCell<Node<'a>>,
19397  pub inner: &'a swc_ast::TsImportType,
19398  pub arg: &'a Str<'a>,
19399  pub qualifier: Option<TsEntityName<'a>>,
19400  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
19401  pub attributes: Option<&'a TsImportCallOptions<'a>>,
19402}
19403
19404impl<'a> TsImportType<'a> {
19405  pub fn parent(&self) -> Node<'a> {
19406    self.parent.get().unwrap()
19407  }
19408}
19409
19410impl<'a> SourceRanged for TsImportType<'a> {
19411  fn start(&self) -> SourcePos {
19412    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19413  }
19414  fn end(&self) -> SourcePos {
19415    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19416  }
19417}
19418
19419impl<'a> From<&TsImportType<'a>> for Node<'a> {
19420  fn from(node: &TsImportType<'a>) -> Node<'a> {
19421    let node = unsafe { mem::transmute::<&TsImportType<'a>, &'a TsImportType<'a>>(node) };
19422    Node::TsImportType(node)
19423  }
19424}
19425
19426impl<'a> NodeTrait<'a> for TsImportType<'a> {
19427  fn parent(&self) -> Option<Node<'a>> {
19428    Some(self.parent.get().unwrap().clone())
19429  }
19430
19431  fn children(&self) -> Vec<Node<'a>> {
19432    let mut children = Vec::with_capacity(1 + match &self.qualifier { Some(_value) => 1, None => 0, } + match &self.type_args { Some(_value) => 1, None => 0, } + match &self.attributes { Some(_value) => 1, None => 0, });
19433    children.push(self.arg.into());
19434    if let Some(child) = self.qualifier.as_ref() {
19435      children.push(child.into());
19436    }
19437    if let Some(child) = self.type_args {
19438      children.push(child.into());
19439    }
19440    if let Some(child) = self.attributes {
19441      children.push(child.into());
19442    }
19443    children
19444  }
19445
19446  fn as_node(&self) -> Node<'a> {
19447    self.into()
19448  }
19449
19450  fn kind(&self) -> NodeKind {
19451    NodeKind::TsImportType
19452  }
19453}
19454
19455impl<'a> CastableNode<'a> for TsImportType<'a> {
19456  fn to(node: &Node<'a>) -> Option<&'a Self> {
19457    if let Node::TsImportType(node) = node {
19458      Some(node)
19459    } else {
19460      None
19461    }
19462  }
19463
19464  fn kind() -> NodeKind {
19465    NodeKind::TsImportType
19466  }
19467}
19468
19469fn get_view_for_ts_import_type<'a>(inner: &'a swc_ast::TsImportType, bump: &'a Bump) -> &'a TsImportType<'a> {
19470  let node = bump.alloc(TsImportType {
19471    inner,
19472    parent: Default::default(),
19473    arg: get_view_for_str(&inner.arg, bump),
19474    qualifier: match &inner.qualifier {
19475      Some(value) => Some(get_view_for_ts_entity_name(value, bump)),
19476      None => None,
19477    },
19478    type_args: match &inner.type_args {
19479      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
19480      None => None,
19481    },
19482    attributes: match &inner.attributes {
19483      Some(value) => Some(get_view_for_ts_import_call_options(value, bump)),
19484      None => None,
19485    },
19486  });
19487  let parent: Node<'a> = (&*node).into();
19488  set_parent_for_str(&node.arg, parent);
19489  if let Some(value) = &node.qualifier {
19490    set_parent_for_ts_entity_name(value, parent)
19491  };
19492  if let Some(value) = &node.type_args {
19493    set_parent_for_ts_type_param_instantiation(value, parent)
19494  };
19495  if let Some(value) = &node.attributes {
19496    set_parent_for_ts_import_call_options(value, parent)
19497  };
19498  node
19499}
19500
19501fn set_parent_for_ts_import_type<'a>(node: &TsImportType<'a>, parent: Node<'a>) {
19502  node.parent.set(parent);
19503}
19504
19505#[derive(Clone)]
19506pub struct TsIndexSignature<'a> {
19507  parent: ParentOnceCell<Node<'a>>,
19508  pub inner: &'a swc_ast::TsIndexSignature,
19509  pub params: &'a [TsFnParam<'a>],
19510  pub type_ann: Option<&'a TsTypeAnn<'a>>,
19511}
19512
19513impl<'a> TsIndexSignature<'a> {
19514  pub fn parent(&self) -> Node<'a> {
19515    self.parent.get().unwrap()
19516  }
19517
19518  pub fn readonly(&self) -> bool {
19519    self.inner.readonly
19520  }
19521
19522  pub fn is_static(&self) -> bool {
19523    self.inner.is_static
19524  }
19525}
19526
19527impl<'a> SourceRanged for TsIndexSignature<'a> {
19528  fn start(&self) -> SourcePos {
19529    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19530  }
19531  fn end(&self) -> SourcePos {
19532    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19533  }
19534}
19535
19536impl<'a> From<&TsIndexSignature<'a>> for Node<'a> {
19537  fn from(node: &TsIndexSignature<'a>) -> Node<'a> {
19538    let node = unsafe { mem::transmute::<&TsIndexSignature<'a>, &'a TsIndexSignature<'a>>(node) };
19539    Node::TsIndexSignature(node)
19540  }
19541}
19542
19543impl<'a> NodeTrait<'a> for TsIndexSignature<'a> {
19544  fn parent(&self) -> Option<Node<'a>> {
19545    Some(self.parent.get().unwrap().clone())
19546  }
19547
19548  fn children(&self) -> Vec<Node<'a>> {
19549    let mut children = Vec::with_capacity(self.params.len() + match &self.type_ann { Some(_value) => 1, None => 0, });
19550    for child in self.params.iter() {
19551      children.push(child.into());
19552    }
19553    if let Some(child) = self.type_ann {
19554      children.push(child.into());
19555    }
19556    children
19557  }
19558
19559  fn as_node(&self) -> Node<'a> {
19560    self.into()
19561  }
19562
19563  fn kind(&self) -> NodeKind {
19564    NodeKind::TsIndexSignature
19565  }
19566}
19567
19568impl<'a> CastableNode<'a> for TsIndexSignature<'a> {
19569  fn to(node: &Node<'a>) -> Option<&'a Self> {
19570    if let Node::TsIndexSignature(node) = node {
19571      Some(node)
19572    } else {
19573      None
19574    }
19575  }
19576
19577  fn kind() -> NodeKind {
19578    NodeKind::TsIndexSignature
19579  }
19580}
19581
19582fn get_view_for_ts_index_signature<'a>(inner: &'a swc_ast::TsIndexSignature, bump: &'a Bump) -> &'a TsIndexSignature<'a> {
19583  let node = bump.alloc(TsIndexSignature {
19584    inner,
19585    parent: Default::default(),
19586    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_ts_fn_param(value, bump))); vec }),
19587    type_ann: match &inner.type_ann {
19588      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
19589      None => None,
19590    },
19591  });
19592  let parent: Node<'a> = (&*node).into();
19593  for value in node.params.iter() {
19594    set_parent_for_ts_fn_param(value, parent)
19595  }
19596  if let Some(value) = &node.type_ann {
19597    set_parent_for_ts_type_ann(value, parent)
19598  };
19599  node
19600}
19601
19602fn set_parent_for_ts_index_signature<'a>(node: &TsIndexSignature<'a>, parent: Node<'a>) {
19603  node.parent.set(parent);
19604}
19605
19606#[derive(Clone)]
19607pub struct TsIndexedAccessType<'a> {
19608  parent: ParentOnceCell<Node<'a>>,
19609  pub inner: &'a swc_ast::TsIndexedAccessType,
19610  pub obj_type: TsType<'a>,
19611  pub index_type: TsType<'a>,
19612}
19613
19614impl<'a> TsIndexedAccessType<'a> {
19615  pub fn parent(&self) -> Node<'a> {
19616    self.parent.get().unwrap()
19617  }
19618
19619  pub fn readonly(&self) -> bool {
19620    self.inner.readonly
19621  }
19622}
19623
19624impl<'a> SourceRanged for TsIndexedAccessType<'a> {
19625  fn start(&self) -> SourcePos {
19626    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19627  }
19628  fn end(&self) -> SourcePos {
19629    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19630  }
19631}
19632
19633impl<'a> From<&TsIndexedAccessType<'a>> for Node<'a> {
19634  fn from(node: &TsIndexedAccessType<'a>) -> Node<'a> {
19635    let node = unsafe { mem::transmute::<&TsIndexedAccessType<'a>, &'a TsIndexedAccessType<'a>>(node) };
19636    Node::TsIndexedAccessType(node)
19637  }
19638}
19639
19640impl<'a> NodeTrait<'a> for TsIndexedAccessType<'a> {
19641  fn parent(&self) -> Option<Node<'a>> {
19642    Some(self.parent.get().unwrap().clone())
19643  }
19644
19645  fn children(&self) -> Vec<Node<'a>> {
19646    let mut children = Vec::with_capacity(2);
19647    children.push((&self.obj_type).into());
19648    children.push((&self.index_type).into());
19649    children
19650  }
19651
19652  fn as_node(&self) -> Node<'a> {
19653    self.into()
19654  }
19655
19656  fn kind(&self) -> NodeKind {
19657    NodeKind::TsIndexedAccessType
19658  }
19659}
19660
19661impl<'a> CastableNode<'a> for TsIndexedAccessType<'a> {
19662  fn to(node: &Node<'a>) -> Option<&'a Self> {
19663    if let Node::TsIndexedAccessType(node) = node {
19664      Some(node)
19665    } else {
19666      None
19667    }
19668  }
19669
19670  fn kind() -> NodeKind {
19671    NodeKind::TsIndexedAccessType
19672  }
19673}
19674
19675fn get_view_for_ts_indexed_access_type<'a>(inner: &'a swc_ast::TsIndexedAccessType, bump: &'a Bump) -> &'a TsIndexedAccessType<'a> {
19676  let node = bump.alloc(TsIndexedAccessType {
19677    inner,
19678    parent: Default::default(),
19679    obj_type: get_view_for_ts_type(&inner.obj_type, bump),
19680    index_type: get_view_for_ts_type(&inner.index_type, bump),
19681  });
19682  let parent: Node<'a> = (&*node).into();
19683  set_parent_for_ts_type(&node.obj_type, parent);
19684  set_parent_for_ts_type(&node.index_type, parent);
19685  node
19686}
19687
19688fn set_parent_for_ts_indexed_access_type<'a>(node: &TsIndexedAccessType<'a>, parent: Node<'a>) {
19689  node.parent.set(parent);
19690}
19691
19692#[derive(Clone)]
19693pub struct TsInferType<'a> {
19694  parent: ParentOnceCell<Node<'a>>,
19695  pub inner: &'a swc_ast::TsInferType,
19696  pub type_param: &'a TsTypeParam<'a>,
19697}
19698
19699impl<'a> TsInferType<'a> {
19700  pub fn parent(&self) -> Node<'a> {
19701    self.parent.get().unwrap()
19702  }
19703}
19704
19705impl<'a> SourceRanged for TsInferType<'a> {
19706  fn start(&self) -> SourcePos {
19707    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19708  }
19709  fn end(&self) -> SourcePos {
19710    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19711  }
19712}
19713
19714impl<'a> From<&TsInferType<'a>> for Node<'a> {
19715  fn from(node: &TsInferType<'a>) -> Node<'a> {
19716    let node = unsafe { mem::transmute::<&TsInferType<'a>, &'a TsInferType<'a>>(node) };
19717    Node::TsInferType(node)
19718  }
19719}
19720
19721impl<'a> NodeTrait<'a> for TsInferType<'a> {
19722  fn parent(&self) -> Option<Node<'a>> {
19723    Some(self.parent.get().unwrap().clone())
19724  }
19725
19726  fn children(&self) -> Vec<Node<'a>> {
19727    let mut children = Vec::with_capacity(1);
19728    children.push(self.type_param.into());
19729    children
19730  }
19731
19732  fn as_node(&self) -> Node<'a> {
19733    self.into()
19734  }
19735
19736  fn kind(&self) -> NodeKind {
19737    NodeKind::TsInferType
19738  }
19739}
19740
19741impl<'a> CastableNode<'a> for TsInferType<'a> {
19742  fn to(node: &Node<'a>) -> Option<&'a Self> {
19743    if let Node::TsInferType(node) = node {
19744      Some(node)
19745    } else {
19746      None
19747    }
19748  }
19749
19750  fn kind() -> NodeKind {
19751    NodeKind::TsInferType
19752  }
19753}
19754
19755fn get_view_for_ts_infer_type<'a>(inner: &'a swc_ast::TsInferType, bump: &'a Bump) -> &'a TsInferType<'a> {
19756  let node = bump.alloc(TsInferType {
19757    inner,
19758    parent: Default::default(),
19759    type_param: get_view_for_ts_type_param(&inner.type_param, bump),
19760  });
19761  let parent: Node<'a> = (&*node).into();
19762  set_parent_for_ts_type_param(&node.type_param, parent);
19763  node
19764}
19765
19766fn set_parent_for_ts_infer_type<'a>(node: &TsInferType<'a>, parent: Node<'a>) {
19767  node.parent.set(parent);
19768}
19769
19770#[derive(Clone)]
19771pub struct TsInstantiation<'a> {
19772  parent: ParentOnceCell<Node<'a>>,
19773  pub inner: &'a swc_ast::TsInstantiation,
19774  pub expr: Expr<'a>,
19775  pub type_args: &'a TsTypeParamInstantiation<'a>,
19776}
19777
19778impl<'a> TsInstantiation<'a> {
19779  pub fn parent(&self) -> Node<'a> {
19780    self.parent.get().unwrap()
19781  }
19782}
19783
19784impl<'a> SourceRanged for TsInstantiation<'a> {
19785  fn start(&self) -> SourcePos {
19786    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19787  }
19788  fn end(&self) -> SourcePos {
19789    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19790  }
19791}
19792
19793impl<'a> From<&TsInstantiation<'a>> for Node<'a> {
19794  fn from(node: &TsInstantiation<'a>) -> Node<'a> {
19795    let node = unsafe { mem::transmute::<&TsInstantiation<'a>, &'a TsInstantiation<'a>>(node) };
19796    Node::TsInstantiation(node)
19797  }
19798}
19799
19800impl<'a> NodeTrait<'a> for TsInstantiation<'a> {
19801  fn parent(&self) -> Option<Node<'a>> {
19802    Some(self.parent.get().unwrap().clone())
19803  }
19804
19805  fn children(&self) -> Vec<Node<'a>> {
19806    let mut children = Vec::with_capacity(2);
19807    children.push((&self.expr).into());
19808    children.push(self.type_args.into());
19809    children
19810  }
19811
19812  fn as_node(&self) -> Node<'a> {
19813    self.into()
19814  }
19815
19816  fn kind(&self) -> NodeKind {
19817    NodeKind::TsInstantiation
19818  }
19819}
19820
19821impl<'a> CastableNode<'a> for TsInstantiation<'a> {
19822  fn to(node: &Node<'a>) -> Option<&'a Self> {
19823    if let Node::TsInstantiation(node) = node {
19824      Some(node)
19825    } else {
19826      None
19827    }
19828  }
19829
19830  fn kind() -> NodeKind {
19831    NodeKind::TsInstantiation
19832  }
19833}
19834
19835fn get_view_for_ts_instantiation<'a>(inner: &'a swc_ast::TsInstantiation, bump: &'a Bump) -> &'a TsInstantiation<'a> {
19836  let node = bump.alloc(TsInstantiation {
19837    inner,
19838    parent: Default::default(),
19839    expr: get_view_for_expr(&inner.expr, bump),
19840    type_args: get_view_for_ts_type_param_instantiation(&inner.type_args, bump),
19841  });
19842  let parent: Node<'a> = (&*node).into();
19843  set_parent_for_expr(&node.expr, parent);
19844  set_parent_for_ts_type_param_instantiation(&node.type_args, parent);
19845  node
19846}
19847
19848fn set_parent_for_ts_instantiation<'a>(node: &TsInstantiation<'a>, parent: Node<'a>) {
19849  node.parent.set(parent);
19850}
19851
19852#[derive(Clone)]
19853pub struct TsInterfaceBody<'a> {
19854  parent: ParentOnceCell<&'a TsInterfaceDecl<'a>>,
19855  pub inner: &'a swc_ast::TsInterfaceBody,
19856  pub body: &'a [TsTypeElement<'a>],
19857}
19858
19859impl<'a> TsInterfaceBody<'a> {
19860  pub fn parent(&self) -> &'a TsInterfaceDecl<'a> {
19861    self.parent.get().unwrap()
19862  }
19863}
19864
19865impl<'a> SourceRanged for TsInterfaceBody<'a> {
19866  fn start(&self) -> SourcePos {
19867    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19868  }
19869  fn end(&self) -> SourcePos {
19870    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19871  }
19872}
19873
19874impl<'a> From<&TsInterfaceBody<'a>> for Node<'a> {
19875  fn from(node: &TsInterfaceBody<'a>) -> Node<'a> {
19876    let node = unsafe { mem::transmute::<&TsInterfaceBody<'a>, &'a TsInterfaceBody<'a>>(node) };
19877    Node::TsInterfaceBody(node)
19878  }
19879}
19880
19881impl<'a> NodeTrait<'a> for TsInterfaceBody<'a> {
19882  fn parent(&self) -> Option<Node<'a>> {
19883    Some(self.parent.get().unwrap().into())
19884  }
19885
19886  fn children(&self) -> Vec<Node<'a>> {
19887    let mut children = Vec::with_capacity(self.body.len());
19888    for child in self.body.iter() {
19889      children.push(child.into());
19890    }
19891    children
19892  }
19893
19894  fn as_node(&self) -> Node<'a> {
19895    self.into()
19896  }
19897
19898  fn kind(&self) -> NodeKind {
19899    NodeKind::TsInterfaceBody
19900  }
19901}
19902
19903impl<'a> CastableNode<'a> for TsInterfaceBody<'a> {
19904  fn to(node: &Node<'a>) -> Option<&'a Self> {
19905    if let Node::TsInterfaceBody(node) = node {
19906      Some(node)
19907    } else {
19908      None
19909    }
19910  }
19911
19912  fn kind() -> NodeKind {
19913    NodeKind::TsInterfaceBody
19914  }
19915}
19916
19917fn get_view_for_ts_interface_body<'a>(inner: &'a swc_ast::TsInterfaceBody, bump: &'a Bump) -> &'a TsInterfaceBody<'a> {
19918  let node = bump.alloc(TsInterfaceBody {
19919    inner,
19920    parent: Default::default(),
19921    body: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.body.len(), bump);vec.extend(inner.body.iter().map(|value| get_view_for_ts_type_element(value, bump))); vec }),
19922  });
19923  let parent: Node<'a> = (&*node).into();
19924  for value in node.body.iter() {
19925    set_parent_for_ts_type_element(value, parent)
19926  }
19927  node
19928}
19929
19930fn set_parent_for_ts_interface_body<'a>(node: &TsInterfaceBody<'a>, parent: Node<'a>) {
19931  node.parent.set(parent.expect::<TsInterfaceDecl>());
19932}
19933
19934#[derive(Clone)]
19935pub struct TsInterfaceDecl<'a> {
19936  parent: ParentOnceCell<Node<'a>>,
19937  pub inner: &'a swc_ast::TsInterfaceDecl,
19938  pub id: &'a Ident<'a>,
19939  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
19940  pub extends: &'a [&'a TsExprWithTypeArgs<'a>],
19941  pub body: &'a TsInterfaceBody<'a>,
19942}
19943
19944impl<'a> TsInterfaceDecl<'a> {
19945  pub fn parent(&self) -> Node<'a> {
19946    self.parent.get().unwrap()
19947  }
19948
19949  pub fn declare(&self) -> bool {
19950    self.inner.declare
19951  }
19952}
19953
19954impl<'a> SourceRanged for TsInterfaceDecl<'a> {
19955  fn start(&self) -> SourcePos {
19956    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19957  }
19958  fn end(&self) -> SourcePos {
19959    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19960  }
19961}
19962
19963impl<'a> From<&TsInterfaceDecl<'a>> for Node<'a> {
19964  fn from(node: &TsInterfaceDecl<'a>) -> Node<'a> {
19965    let node = unsafe { mem::transmute::<&TsInterfaceDecl<'a>, &'a TsInterfaceDecl<'a>>(node) };
19966    Node::TsInterfaceDecl(node)
19967  }
19968}
19969
19970impl<'a> NodeTrait<'a> for TsInterfaceDecl<'a> {
19971  fn parent(&self) -> Option<Node<'a>> {
19972    Some(self.parent.get().unwrap().clone())
19973  }
19974
19975  fn children(&self) -> Vec<Node<'a>> {
19976    let mut children = Vec::with_capacity(2 + match &self.type_params { Some(_value) => 1, None => 0, } + self.extends.len());
19977    children.push(self.id.into());
19978    if let Some(child) = self.type_params {
19979      children.push(child.into());
19980    }
19981    for child in self.extends.iter() {
19982      children.push((*child).into());
19983    }
19984    children.push(self.body.into());
19985    children
19986  }
19987
19988  fn as_node(&self) -> Node<'a> {
19989    self.into()
19990  }
19991
19992  fn kind(&self) -> NodeKind {
19993    NodeKind::TsInterfaceDecl
19994  }
19995}
19996
19997impl<'a> CastableNode<'a> for TsInterfaceDecl<'a> {
19998  fn to(node: &Node<'a>) -> Option<&'a Self> {
19999    if let Node::TsInterfaceDecl(node) = node {
20000      Some(node)
20001    } else {
20002      None
20003    }
20004  }
20005
20006  fn kind() -> NodeKind {
20007    NodeKind::TsInterfaceDecl
20008  }
20009}
20010
20011fn get_view_for_ts_interface_decl<'a>(inner: &'a swc_ast::TsInterfaceDecl, bump: &'a Bump) -> &'a TsInterfaceDecl<'a> {
20012  let node = bump.alloc(TsInterfaceDecl {
20013    inner,
20014    parent: Default::default(),
20015    id: get_view_for_ident(&inner.id, bump),
20016    type_params: match &inner.type_params {
20017      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
20018      None => None,
20019    },
20020    extends: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.extends.len(), bump);vec.extend(inner.extends.iter().map(|value| get_view_for_ts_expr_with_type_args(value, bump))); vec }),
20021    body: get_view_for_ts_interface_body(&inner.body, bump),
20022  });
20023  let parent: Node<'a> = (&*node).into();
20024  set_parent_for_ident(&node.id, parent);
20025  if let Some(value) = &node.type_params {
20026    set_parent_for_ts_type_param_decl(value, parent)
20027  };
20028  for value in node.extends.iter() {
20029    set_parent_for_ts_expr_with_type_args(value, parent)
20030  }
20031  set_parent_for_ts_interface_body(&node.body, parent);
20032  node
20033}
20034
20035fn set_parent_for_ts_interface_decl<'a>(node: &TsInterfaceDecl<'a>, parent: Node<'a>) {
20036  node.parent.set(parent);
20037}
20038
20039#[derive(Clone)]
20040pub struct TsIntersectionType<'a> {
20041  parent: ParentOnceCell<Node<'a>>,
20042  pub inner: &'a swc_ast::TsIntersectionType,
20043  pub types: &'a [TsType<'a>],
20044}
20045
20046impl<'a> TsIntersectionType<'a> {
20047  pub fn parent(&self) -> Node<'a> {
20048    self.parent.get().unwrap()
20049  }
20050}
20051
20052impl<'a> SourceRanged for TsIntersectionType<'a> {
20053  fn start(&self) -> SourcePos {
20054    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20055  }
20056  fn end(&self) -> SourcePos {
20057    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20058  }
20059}
20060
20061impl<'a> From<&TsIntersectionType<'a>> for Node<'a> {
20062  fn from(node: &TsIntersectionType<'a>) -> Node<'a> {
20063    let node = unsafe { mem::transmute::<&TsIntersectionType<'a>, &'a TsIntersectionType<'a>>(node) };
20064    Node::TsIntersectionType(node)
20065  }
20066}
20067
20068impl<'a> NodeTrait<'a> for TsIntersectionType<'a> {
20069  fn parent(&self) -> Option<Node<'a>> {
20070    Some(self.parent.get().unwrap().clone())
20071  }
20072
20073  fn children(&self) -> Vec<Node<'a>> {
20074    let mut children = Vec::with_capacity(self.types.len());
20075    for child in self.types.iter() {
20076      children.push(child.into());
20077    }
20078    children
20079  }
20080
20081  fn as_node(&self) -> Node<'a> {
20082    self.into()
20083  }
20084
20085  fn kind(&self) -> NodeKind {
20086    NodeKind::TsIntersectionType
20087  }
20088}
20089
20090impl<'a> CastableNode<'a> for TsIntersectionType<'a> {
20091  fn to(node: &Node<'a>) -> Option<&'a Self> {
20092    if let Node::TsIntersectionType(node) = node {
20093      Some(node)
20094    } else {
20095      None
20096    }
20097  }
20098
20099  fn kind() -> NodeKind {
20100    NodeKind::TsIntersectionType
20101  }
20102}
20103
20104fn get_view_for_ts_intersection_type<'a>(inner: &'a swc_ast::TsIntersectionType, bump: &'a Bump) -> &'a TsIntersectionType<'a> {
20105  let node = bump.alloc(TsIntersectionType {
20106    inner,
20107    parent: Default::default(),
20108    types: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.types.len(), bump);vec.extend(inner.types.iter().map(|value| get_view_for_ts_type(value, bump))); vec }),
20109  });
20110  let parent: Node<'a> = (&*node).into();
20111  for value in node.types.iter() {
20112    set_parent_for_ts_type(value, parent)
20113  }
20114  node
20115}
20116
20117fn set_parent_for_ts_intersection_type<'a>(node: &TsIntersectionType<'a>, parent: Node<'a>) {
20118  node.parent.set(parent);
20119}
20120
20121#[derive(Clone)]
20122pub struct TsKeywordType<'a> {
20123  parent: ParentOnceCell<Node<'a>>,
20124  pub inner: &'a swc_ast::TsKeywordType,
20125}
20126
20127impl<'a> TsKeywordType<'a> {
20128  pub fn parent(&self) -> Node<'a> {
20129    self.parent.get().unwrap()
20130  }
20131
20132  pub fn keyword_kind(&self) -> TsKeywordTypeKind {
20133    self.inner.kind
20134  }
20135}
20136
20137impl<'a> SourceRanged for TsKeywordType<'a> {
20138  fn start(&self) -> SourcePos {
20139    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20140  }
20141  fn end(&self) -> SourcePos {
20142    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20143  }
20144}
20145
20146impl<'a> From<&TsKeywordType<'a>> for Node<'a> {
20147  fn from(node: &TsKeywordType<'a>) -> Node<'a> {
20148    let node = unsafe { mem::transmute::<&TsKeywordType<'a>, &'a TsKeywordType<'a>>(node) };
20149    Node::TsKeywordType(node)
20150  }
20151}
20152
20153impl<'a> NodeTrait<'a> for TsKeywordType<'a> {
20154  fn parent(&self) -> Option<Node<'a>> {
20155    Some(self.parent.get().unwrap().clone())
20156  }
20157
20158  fn children(&self) -> Vec<Node<'a>> {
20159    Vec::with_capacity(0)
20160  }
20161
20162  fn as_node(&self) -> Node<'a> {
20163    self.into()
20164  }
20165
20166  fn kind(&self) -> NodeKind {
20167    NodeKind::TsKeywordType
20168  }
20169}
20170
20171impl<'a> CastableNode<'a> for TsKeywordType<'a> {
20172  fn to(node: &Node<'a>) -> Option<&'a Self> {
20173    if let Node::TsKeywordType(node) = node {
20174      Some(node)
20175    } else {
20176      None
20177    }
20178  }
20179
20180  fn kind() -> NodeKind {
20181    NodeKind::TsKeywordType
20182  }
20183}
20184
20185fn get_view_for_ts_keyword_type<'a>(inner: &'a swc_ast::TsKeywordType, bump: &'a Bump) -> &'a TsKeywordType<'a> {
20186  let node = bump.alloc(TsKeywordType {
20187    inner,
20188    parent: Default::default(),
20189  });
20190  node
20191}
20192
20193fn set_parent_for_ts_keyword_type<'a>(node: &TsKeywordType<'a>, parent: Node<'a>) {
20194  node.parent.set(parent);
20195}
20196
20197#[derive(Clone)]
20198pub struct TsLitType<'a> {
20199  parent: ParentOnceCell<Node<'a>>,
20200  pub inner: &'a swc_ast::TsLitType,
20201  pub lit: TsLit<'a>,
20202}
20203
20204impl<'a> TsLitType<'a> {
20205  pub fn parent(&self) -> Node<'a> {
20206    self.parent.get().unwrap()
20207  }
20208}
20209
20210impl<'a> SourceRanged for TsLitType<'a> {
20211  fn start(&self) -> SourcePos {
20212    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20213  }
20214  fn end(&self) -> SourcePos {
20215    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20216  }
20217}
20218
20219impl<'a> From<&TsLitType<'a>> for Node<'a> {
20220  fn from(node: &TsLitType<'a>) -> Node<'a> {
20221    let node = unsafe { mem::transmute::<&TsLitType<'a>, &'a TsLitType<'a>>(node) };
20222    Node::TsLitType(node)
20223  }
20224}
20225
20226impl<'a> NodeTrait<'a> for TsLitType<'a> {
20227  fn parent(&self) -> Option<Node<'a>> {
20228    Some(self.parent.get().unwrap().clone())
20229  }
20230
20231  fn children(&self) -> Vec<Node<'a>> {
20232    let mut children = Vec::with_capacity(1);
20233    children.push((&self.lit).into());
20234    children
20235  }
20236
20237  fn as_node(&self) -> Node<'a> {
20238    self.into()
20239  }
20240
20241  fn kind(&self) -> NodeKind {
20242    NodeKind::TsLitType
20243  }
20244}
20245
20246impl<'a> CastableNode<'a> for TsLitType<'a> {
20247  fn to(node: &Node<'a>) -> Option<&'a Self> {
20248    if let Node::TsLitType(node) = node {
20249      Some(node)
20250    } else {
20251      None
20252    }
20253  }
20254
20255  fn kind() -> NodeKind {
20256    NodeKind::TsLitType
20257  }
20258}
20259
20260fn get_view_for_ts_lit_type<'a>(inner: &'a swc_ast::TsLitType, bump: &'a Bump) -> &'a TsLitType<'a> {
20261  let node = bump.alloc(TsLitType {
20262    inner,
20263    parent: Default::default(),
20264    lit: get_view_for_ts_lit(&inner.lit, bump),
20265  });
20266  let parent: Node<'a> = (&*node).into();
20267  set_parent_for_ts_lit(&node.lit, parent);
20268  node
20269}
20270
20271fn set_parent_for_ts_lit_type<'a>(node: &TsLitType<'a>, parent: Node<'a>) {
20272  node.parent.set(parent);
20273}
20274
20275#[derive(Clone)]
20276pub struct TsMappedType<'a> {
20277  parent: ParentOnceCell<Node<'a>>,
20278  pub inner: &'a swc_ast::TsMappedType,
20279  pub type_param: &'a TsTypeParam<'a>,
20280  pub name_type: Option<TsType<'a>>,
20281  pub type_ann: Option<TsType<'a>>,
20282}
20283
20284impl<'a> TsMappedType<'a> {
20285  pub fn parent(&self) -> Node<'a> {
20286    self.parent.get().unwrap()
20287  }
20288
20289  pub fn readonly(&self) -> Option<TruePlusMinus> {
20290    self.inner.readonly
20291  }
20292
20293  pub fn optional(&self) -> Option<TruePlusMinus> {
20294    self.inner.optional
20295  }
20296}
20297
20298impl<'a> SourceRanged for TsMappedType<'a> {
20299  fn start(&self) -> SourcePos {
20300    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20301  }
20302  fn end(&self) -> SourcePos {
20303    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20304  }
20305}
20306
20307impl<'a> From<&TsMappedType<'a>> for Node<'a> {
20308  fn from(node: &TsMappedType<'a>) -> Node<'a> {
20309    let node = unsafe { mem::transmute::<&TsMappedType<'a>, &'a TsMappedType<'a>>(node) };
20310    Node::TsMappedType(node)
20311  }
20312}
20313
20314impl<'a> NodeTrait<'a> for TsMappedType<'a> {
20315  fn parent(&self) -> Option<Node<'a>> {
20316    Some(self.parent.get().unwrap().clone())
20317  }
20318
20319  fn children(&self) -> Vec<Node<'a>> {
20320    let mut children = Vec::with_capacity(1 + match &self.name_type { Some(_value) => 1, None => 0, } + match &self.type_ann { Some(_value) => 1, None => 0, });
20321    children.push(self.type_param.into());
20322    if let Some(child) = self.name_type.as_ref() {
20323      children.push(child.into());
20324    }
20325    if let Some(child) = self.type_ann.as_ref() {
20326      children.push(child.into());
20327    }
20328    children
20329  }
20330
20331  fn as_node(&self) -> Node<'a> {
20332    self.into()
20333  }
20334
20335  fn kind(&self) -> NodeKind {
20336    NodeKind::TsMappedType
20337  }
20338}
20339
20340impl<'a> CastableNode<'a> for TsMappedType<'a> {
20341  fn to(node: &Node<'a>) -> Option<&'a Self> {
20342    if let Node::TsMappedType(node) = node {
20343      Some(node)
20344    } else {
20345      None
20346    }
20347  }
20348
20349  fn kind() -> NodeKind {
20350    NodeKind::TsMappedType
20351  }
20352}
20353
20354fn get_view_for_ts_mapped_type<'a>(inner: &'a swc_ast::TsMappedType, bump: &'a Bump) -> &'a TsMappedType<'a> {
20355  let node = bump.alloc(TsMappedType {
20356    inner,
20357    parent: Default::default(),
20358    type_param: get_view_for_ts_type_param(&inner.type_param, bump),
20359    name_type: match &inner.name_type {
20360      Some(value) => Some(get_view_for_ts_type(value, bump)),
20361      None => None,
20362    },
20363    type_ann: match &inner.type_ann {
20364      Some(value) => Some(get_view_for_ts_type(value, bump)),
20365      None => None,
20366    },
20367  });
20368  let parent: Node<'a> = (&*node).into();
20369  set_parent_for_ts_type_param(&node.type_param, parent);
20370  if let Some(value) = &node.name_type {
20371    set_parent_for_ts_type(value, parent)
20372  };
20373  if let Some(value) = &node.type_ann {
20374    set_parent_for_ts_type(value, parent)
20375  };
20376  node
20377}
20378
20379fn set_parent_for_ts_mapped_type<'a>(node: &TsMappedType<'a>, parent: Node<'a>) {
20380  node.parent.set(parent);
20381}
20382
20383#[derive(Clone)]
20384pub struct TsMethodSignature<'a> {
20385  parent: ParentOnceCell<Node<'a>>,
20386  pub inner: &'a swc_ast::TsMethodSignature,
20387  pub key: Expr<'a>,
20388  pub params: &'a [TsFnParam<'a>],
20389  pub type_ann: Option<&'a TsTypeAnn<'a>>,
20390  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
20391}
20392
20393impl<'a> TsMethodSignature<'a> {
20394  pub fn parent(&self) -> Node<'a> {
20395    self.parent.get().unwrap()
20396  }
20397
20398  pub fn computed(&self) -> bool {
20399    self.inner.computed
20400  }
20401
20402  pub fn optional(&self) -> bool {
20403    self.inner.optional
20404  }
20405}
20406
20407impl<'a> SourceRanged for TsMethodSignature<'a> {
20408  fn start(&self) -> SourcePos {
20409    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20410  }
20411  fn end(&self) -> SourcePos {
20412    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20413  }
20414}
20415
20416impl<'a> From<&TsMethodSignature<'a>> for Node<'a> {
20417  fn from(node: &TsMethodSignature<'a>) -> Node<'a> {
20418    let node = unsafe { mem::transmute::<&TsMethodSignature<'a>, &'a TsMethodSignature<'a>>(node) };
20419    Node::TsMethodSignature(node)
20420  }
20421}
20422
20423impl<'a> NodeTrait<'a> for TsMethodSignature<'a> {
20424  fn parent(&self) -> Option<Node<'a>> {
20425    Some(self.parent.get().unwrap().clone())
20426  }
20427
20428  fn children(&self) -> Vec<Node<'a>> {
20429    let mut children = Vec::with_capacity(1 + self.params.len() + match &self.type_ann { Some(_value) => 1, None => 0, } + match &self.type_params { Some(_value) => 1, None => 0, });
20430    children.push((&self.key).into());
20431    for child in self.params.iter() {
20432      children.push(child.into());
20433    }
20434    if let Some(child) = self.type_ann {
20435      children.push(child.into());
20436    }
20437    if let Some(child) = self.type_params {
20438      children.push(child.into());
20439    }
20440    children
20441  }
20442
20443  fn as_node(&self) -> Node<'a> {
20444    self.into()
20445  }
20446
20447  fn kind(&self) -> NodeKind {
20448    NodeKind::TsMethodSignature
20449  }
20450}
20451
20452impl<'a> CastableNode<'a> for TsMethodSignature<'a> {
20453  fn to(node: &Node<'a>) -> Option<&'a Self> {
20454    if let Node::TsMethodSignature(node) = node {
20455      Some(node)
20456    } else {
20457      None
20458    }
20459  }
20460
20461  fn kind() -> NodeKind {
20462    NodeKind::TsMethodSignature
20463  }
20464}
20465
20466fn get_view_for_ts_method_signature<'a>(inner: &'a swc_ast::TsMethodSignature, bump: &'a Bump) -> &'a TsMethodSignature<'a> {
20467  let node = bump.alloc(TsMethodSignature {
20468    inner,
20469    parent: Default::default(),
20470    key: get_view_for_expr(&inner.key, bump),
20471    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_ts_fn_param(value, bump))); vec }),
20472    type_ann: match &inner.type_ann {
20473      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
20474      None => None,
20475    },
20476    type_params: match &inner.type_params {
20477      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
20478      None => None,
20479    },
20480  });
20481  let parent: Node<'a> = (&*node).into();
20482  set_parent_for_expr(&node.key, parent);
20483  for value in node.params.iter() {
20484    set_parent_for_ts_fn_param(value, parent)
20485  }
20486  if let Some(value) = &node.type_ann {
20487    set_parent_for_ts_type_ann(value, parent)
20488  };
20489  if let Some(value) = &node.type_params {
20490    set_parent_for_ts_type_param_decl(value, parent)
20491  };
20492  node
20493}
20494
20495fn set_parent_for_ts_method_signature<'a>(node: &TsMethodSignature<'a>, parent: Node<'a>) {
20496  node.parent.set(parent);
20497}
20498
20499#[derive(Clone)]
20500pub struct TsModuleBlock<'a> {
20501  parent: ParentOnceCell<Node<'a>>,
20502  pub inner: &'a swc_ast::TsModuleBlock,
20503  pub body: &'a [ModuleItem<'a>],
20504}
20505
20506impl<'a> TsModuleBlock<'a> {
20507  pub fn parent(&self) -> Node<'a> {
20508    self.parent.get().unwrap()
20509  }
20510}
20511
20512impl<'a> SourceRanged for TsModuleBlock<'a> {
20513  fn start(&self) -> SourcePos {
20514    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20515  }
20516  fn end(&self) -> SourcePos {
20517    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20518  }
20519}
20520
20521impl<'a> From<&TsModuleBlock<'a>> for Node<'a> {
20522  fn from(node: &TsModuleBlock<'a>) -> Node<'a> {
20523    let node = unsafe { mem::transmute::<&TsModuleBlock<'a>, &'a TsModuleBlock<'a>>(node) };
20524    Node::TsModuleBlock(node)
20525  }
20526}
20527
20528impl<'a> NodeTrait<'a> for TsModuleBlock<'a> {
20529  fn parent(&self) -> Option<Node<'a>> {
20530    Some(self.parent.get().unwrap().clone())
20531  }
20532
20533  fn children(&self) -> Vec<Node<'a>> {
20534    let mut children = Vec::with_capacity(self.body.len());
20535    for child in self.body.iter() {
20536      children.push(child.into());
20537    }
20538    children
20539  }
20540
20541  fn as_node(&self) -> Node<'a> {
20542    self.into()
20543  }
20544
20545  fn kind(&self) -> NodeKind {
20546    NodeKind::TsModuleBlock
20547  }
20548}
20549
20550impl<'a> CastableNode<'a> for TsModuleBlock<'a> {
20551  fn to(node: &Node<'a>) -> Option<&'a Self> {
20552    if let Node::TsModuleBlock(node) = node {
20553      Some(node)
20554    } else {
20555      None
20556    }
20557  }
20558
20559  fn kind() -> NodeKind {
20560    NodeKind::TsModuleBlock
20561  }
20562}
20563
20564fn get_view_for_ts_module_block<'a>(inner: &'a swc_ast::TsModuleBlock, bump: &'a Bump) -> &'a TsModuleBlock<'a> {
20565  let node = bump.alloc(TsModuleBlock {
20566    inner,
20567    parent: Default::default(),
20568    body: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.body.len(), bump);vec.extend(inner.body.iter().map(|value| get_view_for_module_item(value, bump))); vec }),
20569  });
20570  let parent: Node<'a> = (&*node).into();
20571  for value in node.body.iter() {
20572    set_parent_for_module_item(value, parent)
20573  }
20574  node
20575}
20576
20577fn set_parent_for_ts_module_block<'a>(node: &TsModuleBlock<'a>, parent: Node<'a>) {
20578  node.parent.set(parent);
20579}
20580
20581#[derive(Clone)]
20582pub struct TsModuleDecl<'a> {
20583  parent: ParentOnceCell<Node<'a>>,
20584  pub inner: &'a swc_ast::TsModuleDecl,
20585  pub id: TsModuleName<'a>,
20586  pub body: Option<TsNamespaceBody<'a>>,
20587}
20588
20589impl<'a> TsModuleDecl<'a> {
20590  pub fn parent(&self) -> Node<'a> {
20591    self.parent.get().unwrap()
20592  }
20593
20594  pub fn declare(&self) -> bool {
20595    self.inner.declare
20596  }
20597
20598  /// In TypeScript, this is only available through`node.flags`.
20599  pub fn global(&self) -> bool {
20600    self.inner.global
20601  }
20602
20603  pub fn namespace(&self) -> bool {
20604    self.inner.namespace
20605  }
20606}
20607
20608impl<'a> SourceRanged for TsModuleDecl<'a> {
20609  fn start(&self) -> SourcePos {
20610    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20611  }
20612  fn end(&self) -> SourcePos {
20613    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20614  }
20615}
20616
20617impl<'a> From<&TsModuleDecl<'a>> for Node<'a> {
20618  fn from(node: &TsModuleDecl<'a>) -> Node<'a> {
20619    let node = unsafe { mem::transmute::<&TsModuleDecl<'a>, &'a TsModuleDecl<'a>>(node) };
20620    Node::TsModuleDecl(node)
20621  }
20622}
20623
20624impl<'a> NodeTrait<'a> for TsModuleDecl<'a> {
20625  fn parent(&self) -> Option<Node<'a>> {
20626    Some(self.parent.get().unwrap().clone())
20627  }
20628
20629  fn children(&self) -> Vec<Node<'a>> {
20630    let mut children = Vec::with_capacity(1 + match &self.body { Some(_value) => 1, None => 0, });
20631    children.push((&self.id).into());
20632    if let Some(child) = self.body.as_ref() {
20633      children.push(child.into());
20634    }
20635    children
20636  }
20637
20638  fn as_node(&self) -> Node<'a> {
20639    self.into()
20640  }
20641
20642  fn kind(&self) -> NodeKind {
20643    NodeKind::TsModuleDecl
20644  }
20645}
20646
20647impl<'a> CastableNode<'a> for TsModuleDecl<'a> {
20648  fn to(node: &Node<'a>) -> Option<&'a Self> {
20649    if let Node::TsModuleDecl(node) = node {
20650      Some(node)
20651    } else {
20652      None
20653    }
20654  }
20655
20656  fn kind() -> NodeKind {
20657    NodeKind::TsModuleDecl
20658  }
20659}
20660
20661fn get_view_for_ts_module_decl<'a>(inner: &'a swc_ast::TsModuleDecl, bump: &'a Bump) -> &'a TsModuleDecl<'a> {
20662  let node = bump.alloc(TsModuleDecl {
20663    inner,
20664    parent: Default::default(),
20665    id: get_view_for_ts_module_name(&inner.id, bump),
20666    body: match &inner.body {
20667      Some(value) => Some(get_view_for_ts_namespace_body(value, bump)),
20668      None => None,
20669    },
20670  });
20671  let parent: Node<'a> = (&*node).into();
20672  set_parent_for_ts_module_name(&node.id, parent);
20673  if let Some(value) = &node.body {
20674    set_parent_for_ts_namespace_body(value, parent)
20675  };
20676  node
20677}
20678
20679fn set_parent_for_ts_module_decl<'a>(node: &TsModuleDecl<'a>, parent: Node<'a>) {
20680  node.parent.set(parent);
20681}
20682
20683#[derive(Clone)]
20684pub struct TsNamespaceDecl<'a> {
20685  parent: ParentOnceCell<Node<'a>>,
20686  pub inner: &'a swc_ast::TsNamespaceDecl,
20687  pub id: &'a Ident<'a>,
20688  pub body: TsNamespaceBody<'a>,
20689}
20690
20691impl<'a> TsNamespaceDecl<'a> {
20692  pub fn parent(&self) -> Node<'a> {
20693    self.parent.get().unwrap()
20694  }
20695
20696  pub fn declare(&self) -> bool {
20697    self.inner.declare
20698  }
20699
20700  /// In TypeScript, this is only available through`node.flags`.
20701  pub fn global(&self) -> bool {
20702    self.inner.global
20703  }
20704}
20705
20706impl<'a> SourceRanged for TsNamespaceDecl<'a> {
20707  fn start(&self) -> SourcePos {
20708    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20709  }
20710  fn end(&self) -> SourcePos {
20711    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20712  }
20713}
20714
20715impl<'a> From<&TsNamespaceDecl<'a>> for Node<'a> {
20716  fn from(node: &TsNamespaceDecl<'a>) -> Node<'a> {
20717    let node = unsafe { mem::transmute::<&TsNamespaceDecl<'a>, &'a TsNamespaceDecl<'a>>(node) };
20718    Node::TsNamespaceDecl(node)
20719  }
20720}
20721
20722impl<'a> NodeTrait<'a> for TsNamespaceDecl<'a> {
20723  fn parent(&self) -> Option<Node<'a>> {
20724    Some(self.parent.get().unwrap().clone())
20725  }
20726
20727  fn children(&self) -> Vec<Node<'a>> {
20728    let mut children = Vec::with_capacity(2);
20729    children.push(self.id.into());
20730    children.push((&self.body).into());
20731    children
20732  }
20733
20734  fn as_node(&self) -> Node<'a> {
20735    self.into()
20736  }
20737
20738  fn kind(&self) -> NodeKind {
20739    NodeKind::TsNamespaceDecl
20740  }
20741}
20742
20743impl<'a> CastableNode<'a> for TsNamespaceDecl<'a> {
20744  fn to(node: &Node<'a>) -> Option<&'a Self> {
20745    if let Node::TsNamespaceDecl(node) = node {
20746      Some(node)
20747    } else {
20748      None
20749    }
20750  }
20751
20752  fn kind() -> NodeKind {
20753    NodeKind::TsNamespaceDecl
20754  }
20755}
20756
20757fn get_view_for_ts_namespace_decl<'a>(inner: &'a swc_ast::TsNamespaceDecl, bump: &'a Bump) -> &'a TsNamespaceDecl<'a> {
20758  let node = bump.alloc(TsNamespaceDecl {
20759    inner,
20760    parent: Default::default(),
20761    id: get_view_for_ident(&inner.id, bump),
20762    body: get_view_for_ts_namespace_body(&inner.body, bump),
20763  });
20764  let parent: Node<'a> = (&*node).into();
20765  set_parent_for_ident(&node.id, parent);
20766  set_parent_for_ts_namespace_body(&node.body, parent);
20767  node
20768}
20769
20770fn set_parent_for_ts_namespace_decl<'a>(node: &TsNamespaceDecl<'a>, parent: Node<'a>) {
20771  node.parent.set(parent);
20772}
20773
20774#[derive(Clone)]
20775pub struct TsNamespaceExportDecl<'a> {
20776  parent: ParentOnceCell<Node<'a>>,
20777  pub inner: &'a swc_ast::TsNamespaceExportDecl,
20778  pub id: &'a Ident<'a>,
20779}
20780
20781impl<'a> TsNamespaceExportDecl<'a> {
20782  pub fn parent(&self) -> Node<'a> {
20783    self.parent.get().unwrap()
20784  }
20785}
20786
20787impl<'a> SourceRanged for TsNamespaceExportDecl<'a> {
20788  fn start(&self) -> SourcePos {
20789    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20790  }
20791  fn end(&self) -> SourcePos {
20792    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20793  }
20794}
20795
20796impl<'a> From<&TsNamespaceExportDecl<'a>> for Node<'a> {
20797  fn from(node: &TsNamespaceExportDecl<'a>) -> Node<'a> {
20798    let node = unsafe { mem::transmute::<&TsNamespaceExportDecl<'a>, &'a TsNamespaceExportDecl<'a>>(node) };
20799    Node::TsNamespaceExportDecl(node)
20800  }
20801}
20802
20803impl<'a> NodeTrait<'a> for TsNamespaceExportDecl<'a> {
20804  fn parent(&self) -> Option<Node<'a>> {
20805    Some(self.parent.get().unwrap().clone())
20806  }
20807
20808  fn children(&self) -> Vec<Node<'a>> {
20809    let mut children = Vec::with_capacity(1);
20810    children.push(self.id.into());
20811    children
20812  }
20813
20814  fn as_node(&self) -> Node<'a> {
20815    self.into()
20816  }
20817
20818  fn kind(&self) -> NodeKind {
20819    NodeKind::TsNamespaceExportDecl
20820  }
20821}
20822
20823impl<'a> CastableNode<'a> for TsNamespaceExportDecl<'a> {
20824  fn to(node: &Node<'a>) -> Option<&'a Self> {
20825    if let Node::TsNamespaceExportDecl(node) = node {
20826      Some(node)
20827    } else {
20828      None
20829    }
20830  }
20831
20832  fn kind() -> NodeKind {
20833    NodeKind::TsNamespaceExportDecl
20834  }
20835}
20836
20837fn get_view_for_ts_namespace_export_decl<'a>(inner: &'a swc_ast::TsNamespaceExportDecl, bump: &'a Bump) -> &'a TsNamespaceExportDecl<'a> {
20838  let node = bump.alloc(TsNamespaceExportDecl {
20839    inner,
20840    parent: Default::default(),
20841    id: get_view_for_ident(&inner.id, bump),
20842  });
20843  let parent: Node<'a> = (&*node).into();
20844  set_parent_for_ident(&node.id, parent);
20845  node
20846}
20847
20848fn set_parent_for_ts_namespace_export_decl<'a>(node: &TsNamespaceExportDecl<'a>, parent: Node<'a>) {
20849  node.parent.set(parent);
20850}
20851
20852#[derive(Clone)]
20853pub struct TsNonNullExpr<'a> {
20854  parent: ParentOnceCell<Node<'a>>,
20855  pub inner: &'a swc_ast::TsNonNullExpr,
20856  pub expr: Expr<'a>,
20857}
20858
20859impl<'a> TsNonNullExpr<'a> {
20860  pub fn parent(&self) -> Node<'a> {
20861    self.parent.get().unwrap()
20862  }
20863}
20864
20865impl<'a> SourceRanged for TsNonNullExpr<'a> {
20866  fn start(&self) -> SourcePos {
20867    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20868  }
20869  fn end(&self) -> SourcePos {
20870    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20871  }
20872}
20873
20874impl<'a> From<&TsNonNullExpr<'a>> for Node<'a> {
20875  fn from(node: &TsNonNullExpr<'a>) -> Node<'a> {
20876    let node = unsafe { mem::transmute::<&TsNonNullExpr<'a>, &'a TsNonNullExpr<'a>>(node) };
20877    Node::TsNonNullExpr(node)
20878  }
20879}
20880
20881impl<'a> NodeTrait<'a> for TsNonNullExpr<'a> {
20882  fn parent(&self) -> Option<Node<'a>> {
20883    Some(self.parent.get().unwrap().clone())
20884  }
20885
20886  fn children(&self) -> Vec<Node<'a>> {
20887    let mut children = Vec::with_capacity(1);
20888    children.push((&self.expr).into());
20889    children
20890  }
20891
20892  fn as_node(&self) -> Node<'a> {
20893    self.into()
20894  }
20895
20896  fn kind(&self) -> NodeKind {
20897    NodeKind::TsNonNullExpr
20898  }
20899}
20900
20901impl<'a> CastableNode<'a> for TsNonNullExpr<'a> {
20902  fn to(node: &Node<'a>) -> Option<&'a Self> {
20903    if let Node::TsNonNullExpr(node) = node {
20904      Some(node)
20905    } else {
20906      None
20907    }
20908  }
20909
20910  fn kind() -> NodeKind {
20911    NodeKind::TsNonNullExpr
20912  }
20913}
20914
20915fn get_view_for_ts_non_null_expr<'a>(inner: &'a swc_ast::TsNonNullExpr, bump: &'a Bump) -> &'a TsNonNullExpr<'a> {
20916  let node = bump.alloc(TsNonNullExpr {
20917    inner,
20918    parent: Default::default(),
20919    expr: get_view_for_expr(&inner.expr, bump),
20920  });
20921  let parent: Node<'a> = (&*node).into();
20922  set_parent_for_expr(&node.expr, parent);
20923  node
20924}
20925
20926fn set_parent_for_ts_non_null_expr<'a>(node: &TsNonNullExpr<'a>, parent: Node<'a>) {
20927  node.parent.set(parent);
20928}
20929
20930#[derive(Clone)]
20931pub struct TsOptionalType<'a> {
20932  parent: ParentOnceCell<Node<'a>>,
20933  pub inner: &'a swc_ast::TsOptionalType,
20934  pub type_ann: TsType<'a>,
20935}
20936
20937impl<'a> TsOptionalType<'a> {
20938  pub fn parent(&self) -> Node<'a> {
20939    self.parent.get().unwrap()
20940  }
20941}
20942
20943impl<'a> SourceRanged for TsOptionalType<'a> {
20944  fn start(&self) -> SourcePos {
20945    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20946  }
20947  fn end(&self) -> SourcePos {
20948    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20949  }
20950}
20951
20952impl<'a> From<&TsOptionalType<'a>> for Node<'a> {
20953  fn from(node: &TsOptionalType<'a>) -> Node<'a> {
20954    let node = unsafe { mem::transmute::<&TsOptionalType<'a>, &'a TsOptionalType<'a>>(node) };
20955    Node::TsOptionalType(node)
20956  }
20957}
20958
20959impl<'a> NodeTrait<'a> for TsOptionalType<'a> {
20960  fn parent(&self) -> Option<Node<'a>> {
20961    Some(self.parent.get().unwrap().clone())
20962  }
20963
20964  fn children(&self) -> Vec<Node<'a>> {
20965    let mut children = Vec::with_capacity(1);
20966    children.push((&self.type_ann).into());
20967    children
20968  }
20969
20970  fn as_node(&self) -> Node<'a> {
20971    self.into()
20972  }
20973
20974  fn kind(&self) -> NodeKind {
20975    NodeKind::TsOptionalType
20976  }
20977}
20978
20979impl<'a> CastableNode<'a> for TsOptionalType<'a> {
20980  fn to(node: &Node<'a>) -> Option<&'a Self> {
20981    if let Node::TsOptionalType(node) = node {
20982      Some(node)
20983    } else {
20984      None
20985    }
20986  }
20987
20988  fn kind() -> NodeKind {
20989    NodeKind::TsOptionalType
20990  }
20991}
20992
20993fn get_view_for_ts_optional_type<'a>(inner: &'a swc_ast::TsOptionalType, bump: &'a Bump) -> &'a TsOptionalType<'a> {
20994  let node = bump.alloc(TsOptionalType {
20995    inner,
20996    parent: Default::default(),
20997    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
20998  });
20999  let parent: Node<'a> = (&*node).into();
21000  set_parent_for_ts_type(&node.type_ann, parent);
21001  node
21002}
21003
21004fn set_parent_for_ts_optional_type<'a>(node: &TsOptionalType<'a>, parent: Node<'a>) {
21005  node.parent.set(parent);
21006}
21007
21008#[derive(Clone)]
21009pub struct TsParamProp<'a> {
21010  parent: ParentOnceCell<&'a Constructor<'a>>,
21011  pub inner: &'a swc_ast::TsParamProp,
21012  pub decorators: &'a [&'a Decorator<'a>],
21013  pub param: TsParamPropParam<'a>,
21014}
21015
21016impl<'a> TsParamProp<'a> {
21017  pub fn parent(&self) -> &'a Constructor<'a> {
21018    self.parent.get().unwrap()
21019  }
21020
21021  /// At least one of `accessibility` or `readonly` must be set.
21022  pub fn accessibility(&self) -> Option<Accessibility> {
21023    self.inner.accessibility
21024  }
21025
21026  pub fn is_override(&self) -> bool {
21027    self.inner.is_override
21028  }
21029
21030  pub fn readonly(&self) -> bool {
21031    self.inner.readonly
21032  }
21033}
21034
21035impl<'a> SourceRanged for TsParamProp<'a> {
21036  fn start(&self) -> SourcePos {
21037    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21038  }
21039  fn end(&self) -> SourcePos {
21040    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21041  }
21042}
21043
21044impl<'a> From<&TsParamProp<'a>> for Node<'a> {
21045  fn from(node: &TsParamProp<'a>) -> Node<'a> {
21046    let node = unsafe { mem::transmute::<&TsParamProp<'a>, &'a TsParamProp<'a>>(node) };
21047    Node::TsParamProp(node)
21048  }
21049}
21050
21051impl<'a> NodeTrait<'a> for TsParamProp<'a> {
21052  fn parent(&self) -> Option<Node<'a>> {
21053    Some(self.parent.get().unwrap().into())
21054  }
21055
21056  fn children(&self) -> Vec<Node<'a>> {
21057    let mut children = Vec::with_capacity(1 + self.decorators.len());
21058    for child in self.decorators.iter() {
21059      children.push((*child).into());
21060    }
21061    children.push((&self.param).into());
21062    children
21063  }
21064
21065  fn as_node(&self) -> Node<'a> {
21066    self.into()
21067  }
21068
21069  fn kind(&self) -> NodeKind {
21070    NodeKind::TsParamProp
21071  }
21072}
21073
21074impl<'a> CastableNode<'a> for TsParamProp<'a> {
21075  fn to(node: &Node<'a>) -> Option<&'a Self> {
21076    if let Node::TsParamProp(node) = node {
21077      Some(node)
21078    } else {
21079      None
21080    }
21081  }
21082
21083  fn kind() -> NodeKind {
21084    NodeKind::TsParamProp
21085  }
21086}
21087
21088fn get_view_for_ts_param_prop<'a>(inner: &'a swc_ast::TsParamProp, bump: &'a Bump) -> &'a TsParamProp<'a> {
21089  let node = bump.alloc(TsParamProp {
21090    inner,
21091    parent: Default::default(),
21092    decorators: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.decorators.len(), bump);vec.extend(inner.decorators.iter().map(|value| get_view_for_decorator(value, bump))); vec }),
21093    param: get_view_for_ts_param_prop_param(&inner.param, bump),
21094  });
21095  let parent: Node<'a> = (&*node).into();
21096  for value in node.decorators.iter() {
21097    set_parent_for_decorator(value, parent)
21098  }
21099  set_parent_for_ts_param_prop_param(&node.param, parent);
21100  node
21101}
21102
21103fn set_parent_for_ts_param_prop<'a>(node: &TsParamProp<'a>, parent: Node<'a>) {
21104  node.parent.set(parent.expect::<Constructor>());
21105}
21106
21107#[derive(Clone)]
21108pub struct TsParenthesizedType<'a> {
21109  parent: ParentOnceCell<Node<'a>>,
21110  pub inner: &'a swc_ast::TsParenthesizedType,
21111  pub type_ann: TsType<'a>,
21112}
21113
21114impl<'a> TsParenthesizedType<'a> {
21115  pub fn parent(&self) -> Node<'a> {
21116    self.parent.get().unwrap()
21117  }
21118}
21119
21120impl<'a> SourceRanged for TsParenthesizedType<'a> {
21121  fn start(&self) -> SourcePos {
21122    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21123  }
21124  fn end(&self) -> SourcePos {
21125    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21126  }
21127}
21128
21129impl<'a> From<&TsParenthesizedType<'a>> for Node<'a> {
21130  fn from(node: &TsParenthesizedType<'a>) -> Node<'a> {
21131    let node = unsafe { mem::transmute::<&TsParenthesizedType<'a>, &'a TsParenthesizedType<'a>>(node) };
21132    Node::TsParenthesizedType(node)
21133  }
21134}
21135
21136impl<'a> NodeTrait<'a> for TsParenthesizedType<'a> {
21137  fn parent(&self) -> Option<Node<'a>> {
21138    Some(self.parent.get().unwrap().clone())
21139  }
21140
21141  fn children(&self) -> Vec<Node<'a>> {
21142    let mut children = Vec::with_capacity(1);
21143    children.push((&self.type_ann).into());
21144    children
21145  }
21146
21147  fn as_node(&self) -> Node<'a> {
21148    self.into()
21149  }
21150
21151  fn kind(&self) -> NodeKind {
21152    NodeKind::TsParenthesizedType
21153  }
21154}
21155
21156impl<'a> CastableNode<'a> for TsParenthesizedType<'a> {
21157  fn to(node: &Node<'a>) -> Option<&'a Self> {
21158    if let Node::TsParenthesizedType(node) = node {
21159      Some(node)
21160    } else {
21161      None
21162    }
21163  }
21164
21165  fn kind() -> NodeKind {
21166    NodeKind::TsParenthesizedType
21167  }
21168}
21169
21170fn get_view_for_ts_parenthesized_type<'a>(inner: &'a swc_ast::TsParenthesizedType, bump: &'a Bump) -> &'a TsParenthesizedType<'a> {
21171  let node = bump.alloc(TsParenthesizedType {
21172    inner,
21173    parent: Default::default(),
21174    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
21175  });
21176  let parent: Node<'a> = (&*node).into();
21177  set_parent_for_ts_type(&node.type_ann, parent);
21178  node
21179}
21180
21181fn set_parent_for_ts_parenthesized_type<'a>(node: &TsParenthesizedType<'a>, parent: Node<'a>) {
21182  node.parent.set(parent);
21183}
21184
21185#[derive(Clone)]
21186pub struct TsPropertySignature<'a> {
21187  parent: ParentOnceCell<Node<'a>>,
21188  pub inner: &'a swc_ast::TsPropertySignature,
21189  pub key: Expr<'a>,
21190  pub type_ann: Option<&'a TsTypeAnn<'a>>,
21191}
21192
21193impl<'a> TsPropertySignature<'a> {
21194  pub fn parent(&self) -> Node<'a> {
21195    self.parent.get().unwrap()
21196  }
21197
21198  pub fn readonly(&self) -> bool {
21199    self.inner.readonly
21200  }
21201
21202  pub fn computed(&self) -> bool {
21203    self.inner.computed
21204  }
21205
21206  pub fn optional(&self) -> bool {
21207    self.inner.optional
21208  }
21209}
21210
21211impl<'a> SourceRanged for TsPropertySignature<'a> {
21212  fn start(&self) -> SourcePos {
21213    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21214  }
21215  fn end(&self) -> SourcePos {
21216    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21217  }
21218}
21219
21220impl<'a> From<&TsPropertySignature<'a>> for Node<'a> {
21221  fn from(node: &TsPropertySignature<'a>) -> Node<'a> {
21222    let node = unsafe { mem::transmute::<&TsPropertySignature<'a>, &'a TsPropertySignature<'a>>(node) };
21223    Node::TsPropertySignature(node)
21224  }
21225}
21226
21227impl<'a> NodeTrait<'a> for TsPropertySignature<'a> {
21228  fn parent(&self) -> Option<Node<'a>> {
21229    Some(self.parent.get().unwrap().clone())
21230  }
21231
21232  fn children(&self) -> Vec<Node<'a>> {
21233    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
21234    children.push((&self.key).into());
21235    if let Some(child) = self.type_ann {
21236      children.push(child.into());
21237    }
21238    children
21239  }
21240
21241  fn as_node(&self) -> Node<'a> {
21242    self.into()
21243  }
21244
21245  fn kind(&self) -> NodeKind {
21246    NodeKind::TsPropertySignature
21247  }
21248}
21249
21250impl<'a> CastableNode<'a> for TsPropertySignature<'a> {
21251  fn to(node: &Node<'a>) -> Option<&'a Self> {
21252    if let Node::TsPropertySignature(node) = node {
21253      Some(node)
21254    } else {
21255      None
21256    }
21257  }
21258
21259  fn kind() -> NodeKind {
21260    NodeKind::TsPropertySignature
21261  }
21262}
21263
21264fn get_view_for_ts_property_signature<'a>(inner: &'a swc_ast::TsPropertySignature, bump: &'a Bump) -> &'a TsPropertySignature<'a> {
21265  let node = bump.alloc(TsPropertySignature {
21266    inner,
21267    parent: Default::default(),
21268    key: get_view_for_expr(&inner.key, bump),
21269    type_ann: match &inner.type_ann {
21270      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
21271      None => None,
21272    },
21273  });
21274  let parent: Node<'a> = (&*node).into();
21275  set_parent_for_expr(&node.key, parent);
21276  if let Some(value) = &node.type_ann {
21277    set_parent_for_ts_type_ann(value, parent)
21278  };
21279  node
21280}
21281
21282fn set_parent_for_ts_property_signature<'a>(node: &TsPropertySignature<'a>, parent: Node<'a>) {
21283  node.parent.set(parent);
21284}
21285
21286#[derive(Clone)]
21287pub struct TsQualifiedName<'a> {
21288  parent: ParentOnceCell<Node<'a>>,
21289  pub inner: &'a swc_ast::TsQualifiedName,
21290  pub left: TsEntityName<'a>,
21291  pub right: &'a IdentName<'a>,
21292}
21293
21294impl<'a> TsQualifiedName<'a> {
21295  pub fn parent(&self) -> Node<'a> {
21296    self.parent.get().unwrap()
21297  }
21298}
21299
21300impl<'a> SourceRanged for TsQualifiedName<'a> {
21301  fn start(&self) -> SourcePos {
21302    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21303  }
21304  fn end(&self) -> SourcePos {
21305    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21306  }
21307}
21308
21309impl<'a> From<&TsQualifiedName<'a>> for Node<'a> {
21310  fn from(node: &TsQualifiedName<'a>) -> Node<'a> {
21311    let node = unsafe { mem::transmute::<&TsQualifiedName<'a>, &'a TsQualifiedName<'a>>(node) };
21312    Node::TsQualifiedName(node)
21313  }
21314}
21315
21316impl<'a> NodeTrait<'a> for TsQualifiedName<'a> {
21317  fn parent(&self) -> Option<Node<'a>> {
21318    Some(self.parent.get().unwrap().clone())
21319  }
21320
21321  fn children(&self) -> Vec<Node<'a>> {
21322    let mut children = Vec::with_capacity(2);
21323    children.push((&self.left).into());
21324    children.push(self.right.into());
21325    children
21326  }
21327
21328  fn as_node(&self) -> Node<'a> {
21329    self.into()
21330  }
21331
21332  fn kind(&self) -> NodeKind {
21333    NodeKind::TsQualifiedName
21334  }
21335}
21336
21337impl<'a> CastableNode<'a> for TsQualifiedName<'a> {
21338  fn to(node: &Node<'a>) -> Option<&'a Self> {
21339    if let Node::TsQualifiedName(node) = node {
21340      Some(node)
21341    } else {
21342      None
21343    }
21344  }
21345
21346  fn kind() -> NodeKind {
21347    NodeKind::TsQualifiedName
21348  }
21349}
21350
21351fn get_view_for_ts_qualified_name<'a>(inner: &'a swc_ast::TsQualifiedName, bump: &'a Bump) -> &'a TsQualifiedName<'a> {
21352  let node = bump.alloc(TsQualifiedName {
21353    inner,
21354    parent: Default::default(),
21355    left: get_view_for_ts_entity_name(&inner.left, bump),
21356    right: get_view_for_ident_name(&inner.right, bump),
21357  });
21358  let parent: Node<'a> = (&*node).into();
21359  set_parent_for_ts_entity_name(&node.left, parent);
21360  set_parent_for_ident_name(&node.right, parent);
21361  node
21362}
21363
21364fn set_parent_for_ts_qualified_name<'a>(node: &TsQualifiedName<'a>, parent: Node<'a>) {
21365  node.parent.set(parent);
21366}
21367
21368#[derive(Clone)]
21369pub struct TsRestType<'a> {
21370  parent: ParentOnceCell<Node<'a>>,
21371  pub inner: &'a swc_ast::TsRestType,
21372  pub type_ann: TsType<'a>,
21373}
21374
21375impl<'a> TsRestType<'a> {
21376  pub fn parent(&self) -> Node<'a> {
21377    self.parent.get().unwrap()
21378  }
21379}
21380
21381impl<'a> SourceRanged for TsRestType<'a> {
21382  fn start(&self) -> SourcePos {
21383    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21384  }
21385  fn end(&self) -> SourcePos {
21386    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21387  }
21388}
21389
21390impl<'a> From<&TsRestType<'a>> for Node<'a> {
21391  fn from(node: &TsRestType<'a>) -> Node<'a> {
21392    let node = unsafe { mem::transmute::<&TsRestType<'a>, &'a TsRestType<'a>>(node) };
21393    Node::TsRestType(node)
21394  }
21395}
21396
21397impl<'a> NodeTrait<'a> for TsRestType<'a> {
21398  fn parent(&self) -> Option<Node<'a>> {
21399    Some(self.parent.get().unwrap().clone())
21400  }
21401
21402  fn children(&self) -> Vec<Node<'a>> {
21403    let mut children = Vec::with_capacity(1);
21404    children.push((&self.type_ann).into());
21405    children
21406  }
21407
21408  fn as_node(&self) -> Node<'a> {
21409    self.into()
21410  }
21411
21412  fn kind(&self) -> NodeKind {
21413    NodeKind::TsRestType
21414  }
21415}
21416
21417impl<'a> CastableNode<'a> for TsRestType<'a> {
21418  fn to(node: &Node<'a>) -> Option<&'a Self> {
21419    if let Node::TsRestType(node) = node {
21420      Some(node)
21421    } else {
21422      None
21423    }
21424  }
21425
21426  fn kind() -> NodeKind {
21427    NodeKind::TsRestType
21428  }
21429}
21430
21431fn get_view_for_ts_rest_type<'a>(inner: &'a swc_ast::TsRestType, bump: &'a Bump) -> &'a TsRestType<'a> {
21432  let node = bump.alloc(TsRestType {
21433    inner,
21434    parent: Default::default(),
21435    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
21436  });
21437  let parent: Node<'a> = (&*node).into();
21438  set_parent_for_ts_type(&node.type_ann, parent);
21439  node
21440}
21441
21442fn set_parent_for_ts_rest_type<'a>(node: &TsRestType<'a>, parent: Node<'a>) {
21443  node.parent.set(parent);
21444}
21445
21446#[derive(Clone)]
21447pub struct TsSatisfiesExpr<'a> {
21448  parent: ParentOnceCell<Node<'a>>,
21449  pub inner: &'a swc_ast::TsSatisfiesExpr,
21450  pub expr: Expr<'a>,
21451  pub type_ann: TsType<'a>,
21452}
21453
21454impl<'a> TsSatisfiesExpr<'a> {
21455  pub fn parent(&self) -> Node<'a> {
21456    self.parent.get().unwrap()
21457  }
21458}
21459
21460impl<'a> SourceRanged for TsSatisfiesExpr<'a> {
21461  fn start(&self) -> SourcePos {
21462    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21463  }
21464  fn end(&self) -> SourcePos {
21465    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21466  }
21467}
21468
21469impl<'a> From<&TsSatisfiesExpr<'a>> for Node<'a> {
21470  fn from(node: &TsSatisfiesExpr<'a>) -> Node<'a> {
21471    let node = unsafe { mem::transmute::<&TsSatisfiesExpr<'a>, &'a TsSatisfiesExpr<'a>>(node) };
21472    Node::TsSatisfiesExpr(node)
21473  }
21474}
21475
21476impl<'a> NodeTrait<'a> for TsSatisfiesExpr<'a> {
21477  fn parent(&self) -> Option<Node<'a>> {
21478    Some(self.parent.get().unwrap().clone())
21479  }
21480
21481  fn children(&self) -> Vec<Node<'a>> {
21482    let mut children = Vec::with_capacity(2);
21483    children.push((&self.expr).into());
21484    children.push((&self.type_ann).into());
21485    children
21486  }
21487
21488  fn as_node(&self) -> Node<'a> {
21489    self.into()
21490  }
21491
21492  fn kind(&self) -> NodeKind {
21493    NodeKind::TsSatisfiesExpr
21494  }
21495}
21496
21497impl<'a> CastableNode<'a> for TsSatisfiesExpr<'a> {
21498  fn to(node: &Node<'a>) -> Option<&'a Self> {
21499    if let Node::TsSatisfiesExpr(node) = node {
21500      Some(node)
21501    } else {
21502      None
21503    }
21504  }
21505
21506  fn kind() -> NodeKind {
21507    NodeKind::TsSatisfiesExpr
21508  }
21509}
21510
21511fn get_view_for_ts_satisfies_expr<'a>(inner: &'a swc_ast::TsSatisfiesExpr, bump: &'a Bump) -> &'a TsSatisfiesExpr<'a> {
21512  let node = bump.alloc(TsSatisfiesExpr {
21513    inner,
21514    parent: Default::default(),
21515    expr: get_view_for_expr(&inner.expr, bump),
21516    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
21517  });
21518  let parent: Node<'a> = (&*node).into();
21519  set_parent_for_expr(&node.expr, parent);
21520  set_parent_for_ts_type(&node.type_ann, parent);
21521  node
21522}
21523
21524fn set_parent_for_ts_satisfies_expr<'a>(node: &TsSatisfiesExpr<'a>, parent: Node<'a>) {
21525  node.parent.set(parent);
21526}
21527
21528#[derive(Clone)]
21529pub struct TsSetterSignature<'a> {
21530  parent: ParentOnceCell<Node<'a>>,
21531  pub inner: &'a swc_ast::TsSetterSignature,
21532  pub key: Expr<'a>,
21533  pub param: TsFnParam<'a>,
21534}
21535
21536impl<'a> TsSetterSignature<'a> {
21537  pub fn parent(&self) -> Node<'a> {
21538    self.parent.get().unwrap()
21539  }
21540
21541  pub fn computed(&self) -> bool {
21542    self.inner.computed
21543  }
21544}
21545
21546impl<'a> SourceRanged for TsSetterSignature<'a> {
21547  fn start(&self) -> SourcePos {
21548    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21549  }
21550  fn end(&self) -> SourcePos {
21551    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21552  }
21553}
21554
21555impl<'a> From<&TsSetterSignature<'a>> for Node<'a> {
21556  fn from(node: &TsSetterSignature<'a>) -> Node<'a> {
21557    let node = unsafe { mem::transmute::<&TsSetterSignature<'a>, &'a TsSetterSignature<'a>>(node) };
21558    Node::TsSetterSignature(node)
21559  }
21560}
21561
21562impl<'a> NodeTrait<'a> for TsSetterSignature<'a> {
21563  fn parent(&self) -> Option<Node<'a>> {
21564    Some(self.parent.get().unwrap().clone())
21565  }
21566
21567  fn children(&self) -> Vec<Node<'a>> {
21568    let mut children = Vec::with_capacity(2);
21569    children.push((&self.key).into());
21570    children.push((&self.param).into());
21571    children
21572  }
21573
21574  fn as_node(&self) -> Node<'a> {
21575    self.into()
21576  }
21577
21578  fn kind(&self) -> NodeKind {
21579    NodeKind::TsSetterSignature
21580  }
21581}
21582
21583impl<'a> CastableNode<'a> for TsSetterSignature<'a> {
21584  fn to(node: &Node<'a>) -> Option<&'a Self> {
21585    if let Node::TsSetterSignature(node) = node {
21586      Some(node)
21587    } else {
21588      None
21589    }
21590  }
21591
21592  fn kind() -> NodeKind {
21593    NodeKind::TsSetterSignature
21594  }
21595}
21596
21597fn get_view_for_ts_setter_signature<'a>(inner: &'a swc_ast::TsSetterSignature, bump: &'a Bump) -> &'a TsSetterSignature<'a> {
21598  let node = bump.alloc(TsSetterSignature {
21599    inner,
21600    parent: Default::default(),
21601    key: get_view_for_expr(&inner.key, bump),
21602    param: get_view_for_ts_fn_param(&inner.param, bump),
21603  });
21604  let parent: Node<'a> = (&*node).into();
21605  set_parent_for_expr(&node.key, parent);
21606  set_parent_for_ts_fn_param(&node.param, parent);
21607  node
21608}
21609
21610fn set_parent_for_ts_setter_signature<'a>(node: &TsSetterSignature<'a>, parent: Node<'a>) {
21611  node.parent.set(parent);
21612}
21613
21614#[derive(Clone)]
21615pub struct TsThisType<'a> {
21616  parent: ParentOnceCell<Node<'a>>,
21617  pub inner: &'a swc_ast::TsThisType,
21618}
21619
21620impl<'a> TsThisType<'a> {
21621  pub fn parent(&self) -> Node<'a> {
21622    self.parent.get().unwrap()
21623  }
21624}
21625
21626impl<'a> SourceRanged for TsThisType<'a> {
21627  fn start(&self) -> SourcePos {
21628    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21629  }
21630  fn end(&self) -> SourcePos {
21631    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21632  }
21633}
21634
21635impl<'a> From<&TsThisType<'a>> for Node<'a> {
21636  fn from(node: &TsThisType<'a>) -> Node<'a> {
21637    let node = unsafe { mem::transmute::<&TsThisType<'a>, &'a TsThisType<'a>>(node) };
21638    Node::TsThisType(node)
21639  }
21640}
21641
21642impl<'a> NodeTrait<'a> for TsThisType<'a> {
21643  fn parent(&self) -> Option<Node<'a>> {
21644    Some(self.parent.get().unwrap().clone())
21645  }
21646
21647  fn children(&self) -> Vec<Node<'a>> {
21648    Vec::with_capacity(0)
21649  }
21650
21651  fn as_node(&self) -> Node<'a> {
21652    self.into()
21653  }
21654
21655  fn kind(&self) -> NodeKind {
21656    NodeKind::TsThisType
21657  }
21658}
21659
21660impl<'a> CastableNode<'a> for TsThisType<'a> {
21661  fn to(node: &Node<'a>) -> Option<&'a Self> {
21662    if let Node::TsThisType(node) = node {
21663      Some(node)
21664    } else {
21665      None
21666    }
21667  }
21668
21669  fn kind() -> NodeKind {
21670    NodeKind::TsThisType
21671  }
21672}
21673
21674fn get_view_for_ts_this_type<'a>(inner: &'a swc_ast::TsThisType, bump: &'a Bump) -> &'a TsThisType<'a> {
21675  let node = bump.alloc(TsThisType {
21676    inner,
21677    parent: Default::default(),
21678  });
21679  node
21680}
21681
21682fn set_parent_for_ts_this_type<'a>(node: &TsThisType<'a>, parent: Node<'a>) {
21683  node.parent.set(parent);
21684}
21685
21686#[derive(Clone)]
21687pub struct TsTplLitType<'a> {
21688  parent: ParentOnceCell<&'a TsLitType<'a>>,
21689  pub inner: &'a swc_ast::TsTplLitType,
21690  pub types: &'a [TsType<'a>],
21691  pub quasis: &'a [&'a TplElement<'a>],
21692}
21693
21694impl<'a> TsTplLitType<'a> {
21695  pub fn parent(&self) -> &'a TsLitType<'a> {
21696    self.parent.get().unwrap()
21697  }
21698}
21699
21700impl<'a> SourceRanged for TsTplLitType<'a> {
21701  fn start(&self) -> SourcePos {
21702    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21703  }
21704  fn end(&self) -> SourcePos {
21705    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21706  }
21707}
21708
21709impl<'a> From<&TsTplLitType<'a>> for Node<'a> {
21710  fn from(node: &TsTplLitType<'a>) -> Node<'a> {
21711    let node = unsafe { mem::transmute::<&TsTplLitType<'a>, &'a TsTplLitType<'a>>(node) };
21712    Node::TsTplLitType(node)
21713  }
21714}
21715
21716impl<'a> NodeTrait<'a> for TsTplLitType<'a> {
21717  fn parent(&self) -> Option<Node<'a>> {
21718    Some(self.parent.get().unwrap().into())
21719  }
21720
21721  fn children(&self) -> Vec<Node<'a>> {
21722    let mut children = Vec::with_capacity(self.types.len() + self.quasis.len());
21723    for child in self.types.iter() {
21724      children.push(child.into());
21725    }
21726    for child in self.quasis.iter() {
21727      children.push((*child).into());
21728    }
21729    children
21730  }
21731
21732  fn as_node(&self) -> Node<'a> {
21733    self.into()
21734  }
21735
21736  fn kind(&self) -> NodeKind {
21737    NodeKind::TsTplLitType
21738  }
21739}
21740
21741impl<'a> CastableNode<'a> for TsTplLitType<'a> {
21742  fn to(node: &Node<'a>) -> Option<&'a Self> {
21743    if let Node::TsTplLitType(node) = node {
21744      Some(node)
21745    } else {
21746      None
21747    }
21748  }
21749
21750  fn kind() -> NodeKind {
21751    NodeKind::TsTplLitType
21752  }
21753}
21754
21755fn get_view_for_ts_tpl_lit_type<'a>(inner: &'a swc_ast::TsTplLitType, bump: &'a Bump) -> &'a TsTplLitType<'a> {
21756  let node = bump.alloc(TsTplLitType {
21757    inner,
21758    parent: Default::default(),
21759    types: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.types.len(), bump);vec.extend(inner.types.iter().map(|value| get_view_for_ts_type(value, bump))); vec }),
21760    quasis: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.quasis.len(), bump);vec.extend(inner.quasis.iter().map(|value| get_view_for_tpl_element(value, bump))); vec }),
21761  });
21762  let parent: Node<'a> = (&*node).into();
21763  for value in node.types.iter() {
21764    set_parent_for_ts_type(value, parent)
21765  }
21766  for value in node.quasis.iter() {
21767    set_parent_for_tpl_element(value, parent)
21768  }
21769  node
21770}
21771
21772fn set_parent_for_ts_tpl_lit_type<'a>(node: &TsTplLitType<'a>, parent: Node<'a>) {
21773  node.parent.set(parent.expect::<TsLitType>());
21774}
21775
21776#[derive(Clone)]
21777pub struct TsTupleElement<'a> {
21778  parent: ParentOnceCell<&'a TsTupleType<'a>>,
21779  pub inner: &'a swc_ast::TsTupleElement,
21780  /// `Ident` or `RestPat { arg: Ident }`
21781  pub label: Option<Pat<'a>>,
21782  pub ty: TsType<'a>,
21783}
21784
21785impl<'a> TsTupleElement<'a> {
21786  pub fn parent(&self) -> &'a TsTupleType<'a> {
21787    self.parent.get().unwrap()
21788  }
21789}
21790
21791impl<'a> SourceRanged for TsTupleElement<'a> {
21792  fn start(&self) -> SourcePos {
21793    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21794  }
21795  fn end(&self) -> SourcePos {
21796    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21797  }
21798}
21799
21800impl<'a> From<&TsTupleElement<'a>> for Node<'a> {
21801  fn from(node: &TsTupleElement<'a>) -> Node<'a> {
21802    let node = unsafe { mem::transmute::<&TsTupleElement<'a>, &'a TsTupleElement<'a>>(node) };
21803    Node::TsTupleElement(node)
21804  }
21805}
21806
21807impl<'a> NodeTrait<'a> for TsTupleElement<'a> {
21808  fn parent(&self) -> Option<Node<'a>> {
21809    Some(self.parent.get().unwrap().into())
21810  }
21811
21812  fn children(&self) -> Vec<Node<'a>> {
21813    let mut children = Vec::with_capacity(1 + match &self.label { Some(_value) => 1, None => 0, });
21814    if let Some(child) = self.label.as_ref() {
21815      children.push(child.into());
21816    }
21817    children.push((&self.ty).into());
21818    children
21819  }
21820
21821  fn as_node(&self) -> Node<'a> {
21822    self.into()
21823  }
21824
21825  fn kind(&self) -> NodeKind {
21826    NodeKind::TsTupleElement
21827  }
21828}
21829
21830impl<'a> CastableNode<'a> for TsTupleElement<'a> {
21831  fn to(node: &Node<'a>) -> Option<&'a Self> {
21832    if let Node::TsTupleElement(node) = node {
21833      Some(node)
21834    } else {
21835      None
21836    }
21837  }
21838
21839  fn kind() -> NodeKind {
21840    NodeKind::TsTupleElement
21841  }
21842}
21843
21844fn get_view_for_ts_tuple_element<'a>(inner: &'a swc_ast::TsTupleElement, bump: &'a Bump) -> &'a TsTupleElement<'a> {
21845  let node = bump.alloc(TsTupleElement {
21846    inner,
21847    parent: Default::default(),
21848    label: match &inner.label {
21849      Some(value) => Some(get_view_for_pat(value, bump)),
21850      None => None,
21851    },
21852    ty: get_view_for_ts_type(&inner.ty, bump),
21853  });
21854  let parent: Node<'a> = (&*node).into();
21855  if let Some(value) = &node.label {
21856    set_parent_for_pat(value, parent)
21857  };
21858  set_parent_for_ts_type(&node.ty, parent);
21859  node
21860}
21861
21862fn set_parent_for_ts_tuple_element<'a>(node: &TsTupleElement<'a>, parent: Node<'a>) {
21863  node.parent.set(parent.expect::<TsTupleType>());
21864}
21865
21866#[derive(Clone)]
21867pub struct TsTupleType<'a> {
21868  parent: ParentOnceCell<Node<'a>>,
21869  pub inner: &'a swc_ast::TsTupleType,
21870  pub elem_types: &'a [&'a TsTupleElement<'a>],
21871}
21872
21873impl<'a> TsTupleType<'a> {
21874  pub fn parent(&self) -> Node<'a> {
21875    self.parent.get().unwrap()
21876  }
21877}
21878
21879impl<'a> SourceRanged for TsTupleType<'a> {
21880  fn start(&self) -> SourcePos {
21881    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21882  }
21883  fn end(&self) -> SourcePos {
21884    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21885  }
21886}
21887
21888impl<'a> From<&TsTupleType<'a>> for Node<'a> {
21889  fn from(node: &TsTupleType<'a>) -> Node<'a> {
21890    let node = unsafe { mem::transmute::<&TsTupleType<'a>, &'a TsTupleType<'a>>(node) };
21891    Node::TsTupleType(node)
21892  }
21893}
21894
21895impl<'a> NodeTrait<'a> for TsTupleType<'a> {
21896  fn parent(&self) -> Option<Node<'a>> {
21897    Some(self.parent.get().unwrap().clone())
21898  }
21899
21900  fn children(&self) -> Vec<Node<'a>> {
21901    let mut children = Vec::with_capacity(self.elem_types.len());
21902    for child in self.elem_types.iter() {
21903      children.push((*child).into());
21904    }
21905    children
21906  }
21907
21908  fn as_node(&self) -> Node<'a> {
21909    self.into()
21910  }
21911
21912  fn kind(&self) -> NodeKind {
21913    NodeKind::TsTupleType
21914  }
21915}
21916
21917impl<'a> CastableNode<'a> for TsTupleType<'a> {
21918  fn to(node: &Node<'a>) -> Option<&'a Self> {
21919    if let Node::TsTupleType(node) = node {
21920      Some(node)
21921    } else {
21922      None
21923    }
21924  }
21925
21926  fn kind() -> NodeKind {
21927    NodeKind::TsTupleType
21928  }
21929}
21930
21931fn get_view_for_ts_tuple_type<'a>(inner: &'a swc_ast::TsTupleType, bump: &'a Bump) -> &'a TsTupleType<'a> {
21932  let node = bump.alloc(TsTupleType {
21933    inner,
21934    parent: Default::default(),
21935    elem_types: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.elem_types.len(), bump);vec.extend(inner.elem_types.iter().map(|value| get_view_for_ts_tuple_element(value, bump))); vec }),
21936  });
21937  let parent: Node<'a> = (&*node).into();
21938  for value in node.elem_types.iter() {
21939    set_parent_for_ts_tuple_element(value, parent)
21940  }
21941  node
21942}
21943
21944fn set_parent_for_ts_tuple_type<'a>(node: &TsTupleType<'a>, parent: Node<'a>) {
21945  node.parent.set(parent);
21946}
21947
21948#[derive(Clone)]
21949pub struct TsTypeAliasDecl<'a> {
21950  parent: ParentOnceCell<Node<'a>>,
21951  pub inner: &'a swc_ast::TsTypeAliasDecl,
21952  pub id: &'a Ident<'a>,
21953  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
21954  pub type_ann: TsType<'a>,
21955}
21956
21957impl<'a> TsTypeAliasDecl<'a> {
21958  pub fn parent(&self) -> Node<'a> {
21959    self.parent.get().unwrap()
21960  }
21961
21962  pub fn declare(&self) -> bool {
21963    self.inner.declare
21964  }
21965}
21966
21967impl<'a> SourceRanged for TsTypeAliasDecl<'a> {
21968  fn start(&self) -> SourcePos {
21969    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21970  }
21971  fn end(&self) -> SourcePos {
21972    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21973  }
21974}
21975
21976impl<'a> From<&TsTypeAliasDecl<'a>> for Node<'a> {
21977  fn from(node: &TsTypeAliasDecl<'a>) -> Node<'a> {
21978    let node = unsafe { mem::transmute::<&TsTypeAliasDecl<'a>, &'a TsTypeAliasDecl<'a>>(node) };
21979    Node::TsTypeAliasDecl(node)
21980  }
21981}
21982
21983impl<'a> NodeTrait<'a> for TsTypeAliasDecl<'a> {
21984  fn parent(&self) -> Option<Node<'a>> {
21985    Some(self.parent.get().unwrap().clone())
21986  }
21987
21988  fn children(&self) -> Vec<Node<'a>> {
21989    let mut children = Vec::with_capacity(2 + match &self.type_params { Some(_value) => 1, None => 0, });
21990    children.push(self.id.into());
21991    if let Some(child) = self.type_params {
21992      children.push(child.into());
21993    }
21994    children.push((&self.type_ann).into());
21995    children
21996  }
21997
21998  fn as_node(&self) -> Node<'a> {
21999    self.into()
22000  }
22001
22002  fn kind(&self) -> NodeKind {
22003    NodeKind::TsTypeAliasDecl
22004  }
22005}
22006
22007impl<'a> CastableNode<'a> for TsTypeAliasDecl<'a> {
22008  fn to(node: &Node<'a>) -> Option<&'a Self> {
22009    if let Node::TsTypeAliasDecl(node) = node {
22010      Some(node)
22011    } else {
22012      None
22013    }
22014  }
22015
22016  fn kind() -> NodeKind {
22017    NodeKind::TsTypeAliasDecl
22018  }
22019}
22020
22021fn get_view_for_ts_type_alias_decl<'a>(inner: &'a swc_ast::TsTypeAliasDecl, bump: &'a Bump) -> &'a TsTypeAliasDecl<'a> {
22022  let node = bump.alloc(TsTypeAliasDecl {
22023    inner,
22024    parent: Default::default(),
22025    id: get_view_for_ident(&inner.id, bump),
22026    type_params: match &inner.type_params {
22027      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
22028      None => None,
22029    },
22030    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
22031  });
22032  let parent: Node<'a> = (&*node).into();
22033  set_parent_for_ident(&node.id, parent);
22034  if let Some(value) = &node.type_params {
22035    set_parent_for_ts_type_param_decl(value, parent)
22036  };
22037  set_parent_for_ts_type(&node.type_ann, parent);
22038  node
22039}
22040
22041fn set_parent_for_ts_type_alias_decl<'a>(node: &TsTypeAliasDecl<'a>, parent: Node<'a>) {
22042  node.parent.set(parent);
22043}
22044
22045#[derive(Clone)]
22046pub struct TsTypeAnn<'a> {
22047  parent: ParentOnceCell<Node<'a>>,
22048  pub inner: &'a swc_ast::TsTypeAnn,
22049  pub type_ann: TsType<'a>,
22050}
22051
22052impl<'a> TsTypeAnn<'a> {
22053  pub fn parent(&self) -> Node<'a> {
22054    self.parent.get().unwrap()
22055  }
22056}
22057
22058impl<'a> SourceRanged for TsTypeAnn<'a> {
22059  fn start(&self) -> SourcePos {
22060    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22061  }
22062  fn end(&self) -> SourcePos {
22063    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22064  }
22065}
22066
22067impl<'a> From<&TsTypeAnn<'a>> for Node<'a> {
22068  fn from(node: &TsTypeAnn<'a>) -> Node<'a> {
22069    let node = unsafe { mem::transmute::<&TsTypeAnn<'a>, &'a TsTypeAnn<'a>>(node) };
22070    Node::TsTypeAnn(node)
22071  }
22072}
22073
22074impl<'a> NodeTrait<'a> for TsTypeAnn<'a> {
22075  fn parent(&self) -> Option<Node<'a>> {
22076    Some(self.parent.get().unwrap().clone())
22077  }
22078
22079  fn children(&self) -> Vec<Node<'a>> {
22080    let mut children = Vec::with_capacity(1);
22081    children.push((&self.type_ann).into());
22082    children
22083  }
22084
22085  fn as_node(&self) -> Node<'a> {
22086    self.into()
22087  }
22088
22089  fn kind(&self) -> NodeKind {
22090    NodeKind::TsTypeAnn
22091  }
22092}
22093
22094impl<'a> CastableNode<'a> for TsTypeAnn<'a> {
22095  fn to(node: &Node<'a>) -> Option<&'a Self> {
22096    if let Node::TsTypeAnn(node) = node {
22097      Some(node)
22098    } else {
22099      None
22100    }
22101  }
22102
22103  fn kind() -> NodeKind {
22104    NodeKind::TsTypeAnn
22105  }
22106}
22107
22108fn get_view_for_ts_type_ann<'a>(inner: &'a swc_ast::TsTypeAnn, bump: &'a Bump) -> &'a TsTypeAnn<'a> {
22109  let node = bump.alloc(TsTypeAnn {
22110    inner,
22111    parent: Default::default(),
22112    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
22113  });
22114  let parent: Node<'a> = (&*node).into();
22115  set_parent_for_ts_type(&node.type_ann, parent);
22116  node
22117}
22118
22119fn set_parent_for_ts_type_ann<'a>(node: &TsTypeAnn<'a>, parent: Node<'a>) {
22120  node.parent.set(parent);
22121}
22122
22123#[derive(Clone)]
22124pub struct TsTypeAssertion<'a> {
22125  parent: ParentOnceCell<Node<'a>>,
22126  pub inner: &'a swc_ast::TsTypeAssertion,
22127  pub expr: Expr<'a>,
22128  pub type_ann: TsType<'a>,
22129}
22130
22131impl<'a> TsTypeAssertion<'a> {
22132  pub fn parent(&self) -> Node<'a> {
22133    self.parent.get().unwrap()
22134  }
22135}
22136
22137impl<'a> SourceRanged for TsTypeAssertion<'a> {
22138  fn start(&self) -> SourcePos {
22139    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22140  }
22141  fn end(&self) -> SourcePos {
22142    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22143  }
22144}
22145
22146impl<'a> From<&TsTypeAssertion<'a>> for Node<'a> {
22147  fn from(node: &TsTypeAssertion<'a>) -> Node<'a> {
22148    let node = unsafe { mem::transmute::<&TsTypeAssertion<'a>, &'a TsTypeAssertion<'a>>(node) };
22149    Node::TsTypeAssertion(node)
22150  }
22151}
22152
22153impl<'a> NodeTrait<'a> for TsTypeAssertion<'a> {
22154  fn parent(&self) -> Option<Node<'a>> {
22155    Some(self.parent.get().unwrap().clone())
22156  }
22157
22158  fn children(&self) -> Vec<Node<'a>> {
22159    let mut children = Vec::with_capacity(2);
22160    children.push((&self.expr).into());
22161    children.push((&self.type_ann).into());
22162    children
22163  }
22164
22165  fn as_node(&self) -> Node<'a> {
22166    self.into()
22167  }
22168
22169  fn kind(&self) -> NodeKind {
22170    NodeKind::TsTypeAssertion
22171  }
22172}
22173
22174impl<'a> CastableNode<'a> for TsTypeAssertion<'a> {
22175  fn to(node: &Node<'a>) -> Option<&'a Self> {
22176    if let Node::TsTypeAssertion(node) = node {
22177      Some(node)
22178    } else {
22179      None
22180    }
22181  }
22182
22183  fn kind() -> NodeKind {
22184    NodeKind::TsTypeAssertion
22185  }
22186}
22187
22188fn get_view_for_ts_type_assertion<'a>(inner: &'a swc_ast::TsTypeAssertion, bump: &'a Bump) -> &'a TsTypeAssertion<'a> {
22189  let node = bump.alloc(TsTypeAssertion {
22190    inner,
22191    parent: Default::default(),
22192    expr: get_view_for_expr(&inner.expr, bump),
22193    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
22194  });
22195  let parent: Node<'a> = (&*node).into();
22196  set_parent_for_expr(&node.expr, parent);
22197  set_parent_for_ts_type(&node.type_ann, parent);
22198  node
22199}
22200
22201fn set_parent_for_ts_type_assertion<'a>(node: &TsTypeAssertion<'a>, parent: Node<'a>) {
22202  node.parent.set(parent);
22203}
22204
22205#[derive(Clone)]
22206pub struct TsTypeLit<'a> {
22207  parent: ParentOnceCell<Node<'a>>,
22208  pub inner: &'a swc_ast::TsTypeLit,
22209  pub members: &'a [TsTypeElement<'a>],
22210}
22211
22212impl<'a> TsTypeLit<'a> {
22213  pub fn parent(&self) -> Node<'a> {
22214    self.parent.get().unwrap()
22215  }
22216}
22217
22218impl<'a> SourceRanged for TsTypeLit<'a> {
22219  fn start(&self) -> SourcePos {
22220    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22221  }
22222  fn end(&self) -> SourcePos {
22223    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22224  }
22225}
22226
22227impl<'a> From<&TsTypeLit<'a>> for Node<'a> {
22228  fn from(node: &TsTypeLit<'a>) -> Node<'a> {
22229    let node = unsafe { mem::transmute::<&TsTypeLit<'a>, &'a TsTypeLit<'a>>(node) };
22230    Node::TsTypeLit(node)
22231  }
22232}
22233
22234impl<'a> NodeTrait<'a> for TsTypeLit<'a> {
22235  fn parent(&self) -> Option<Node<'a>> {
22236    Some(self.parent.get().unwrap().clone())
22237  }
22238
22239  fn children(&self) -> Vec<Node<'a>> {
22240    let mut children = Vec::with_capacity(self.members.len());
22241    for child in self.members.iter() {
22242      children.push(child.into());
22243    }
22244    children
22245  }
22246
22247  fn as_node(&self) -> Node<'a> {
22248    self.into()
22249  }
22250
22251  fn kind(&self) -> NodeKind {
22252    NodeKind::TsTypeLit
22253  }
22254}
22255
22256impl<'a> CastableNode<'a> for TsTypeLit<'a> {
22257  fn to(node: &Node<'a>) -> Option<&'a Self> {
22258    if let Node::TsTypeLit(node) = node {
22259      Some(node)
22260    } else {
22261      None
22262    }
22263  }
22264
22265  fn kind() -> NodeKind {
22266    NodeKind::TsTypeLit
22267  }
22268}
22269
22270fn get_view_for_ts_type_lit<'a>(inner: &'a swc_ast::TsTypeLit, bump: &'a Bump) -> &'a TsTypeLit<'a> {
22271  let node = bump.alloc(TsTypeLit {
22272    inner,
22273    parent: Default::default(),
22274    members: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.members.len(), bump);vec.extend(inner.members.iter().map(|value| get_view_for_ts_type_element(value, bump))); vec }),
22275  });
22276  let parent: Node<'a> = (&*node).into();
22277  for value in node.members.iter() {
22278    set_parent_for_ts_type_element(value, parent)
22279  }
22280  node
22281}
22282
22283fn set_parent_for_ts_type_lit<'a>(node: &TsTypeLit<'a>, parent: Node<'a>) {
22284  node.parent.set(parent);
22285}
22286
22287#[derive(Clone)]
22288pub struct TsTypeOperator<'a> {
22289  parent: ParentOnceCell<Node<'a>>,
22290  pub inner: &'a swc_ast::TsTypeOperator,
22291  pub type_ann: TsType<'a>,
22292}
22293
22294impl<'a> TsTypeOperator<'a> {
22295  pub fn parent(&self) -> Node<'a> {
22296    self.parent.get().unwrap()
22297  }
22298
22299  pub fn op(&self) -> TsTypeOperatorOp {
22300    self.inner.op
22301  }
22302}
22303
22304impl<'a> SourceRanged for TsTypeOperator<'a> {
22305  fn start(&self) -> SourcePos {
22306    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22307  }
22308  fn end(&self) -> SourcePos {
22309    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22310  }
22311}
22312
22313impl<'a> From<&TsTypeOperator<'a>> for Node<'a> {
22314  fn from(node: &TsTypeOperator<'a>) -> Node<'a> {
22315    let node = unsafe { mem::transmute::<&TsTypeOperator<'a>, &'a TsTypeOperator<'a>>(node) };
22316    Node::TsTypeOperator(node)
22317  }
22318}
22319
22320impl<'a> NodeTrait<'a> for TsTypeOperator<'a> {
22321  fn parent(&self) -> Option<Node<'a>> {
22322    Some(self.parent.get().unwrap().clone())
22323  }
22324
22325  fn children(&self) -> Vec<Node<'a>> {
22326    let mut children = Vec::with_capacity(1);
22327    children.push((&self.type_ann).into());
22328    children
22329  }
22330
22331  fn as_node(&self) -> Node<'a> {
22332    self.into()
22333  }
22334
22335  fn kind(&self) -> NodeKind {
22336    NodeKind::TsTypeOperator
22337  }
22338}
22339
22340impl<'a> CastableNode<'a> for TsTypeOperator<'a> {
22341  fn to(node: &Node<'a>) -> Option<&'a Self> {
22342    if let Node::TsTypeOperator(node) = node {
22343      Some(node)
22344    } else {
22345      None
22346    }
22347  }
22348
22349  fn kind() -> NodeKind {
22350    NodeKind::TsTypeOperator
22351  }
22352}
22353
22354fn get_view_for_ts_type_operator<'a>(inner: &'a swc_ast::TsTypeOperator, bump: &'a Bump) -> &'a TsTypeOperator<'a> {
22355  let node = bump.alloc(TsTypeOperator {
22356    inner,
22357    parent: Default::default(),
22358    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
22359  });
22360  let parent: Node<'a> = (&*node).into();
22361  set_parent_for_ts_type(&node.type_ann, parent);
22362  node
22363}
22364
22365fn set_parent_for_ts_type_operator<'a>(node: &TsTypeOperator<'a>, parent: Node<'a>) {
22366  node.parent.set(parent);
22367}
22368
22369#[derive(Clone)]
22370pub struct TsTypeParam<'a> {
22371  parent: ParentOnceCell<Node<'a>>,
22372  pub inner: &'a swc_ast::TsTypeParam,
22373  pub name: &'a Ident<'a>,
22374  pub constraint: Option<TsType<'a>>,
22375  pub default: Option<TsType<'a>>,
22376}
22377
22378impl<'a> TsTypeParam<'a> {
22379  pub fn parent(&self) -> Node<'a> {
22380    self.parent.get().unwrap()
22381  }
22382
22383  pub fn is_in(&self) -> bool {
22384    self.inner.is_in
22385  }
22386
22387  pub fn is_out(&self) -> bool {
22388    self.inner.is_out
22389  }
22390
22391  pub fn is_const(&self) -> bool {
22392    self.inner.is_const
22393  }
22394}
22395
22396impl<'a> SourceRanged for TsTypeParam<'a> {
22397  fn start(&self) -> SourcePos {
22398    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22399  }
22400  fn end(&self) -> SourcePos {
22401    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22402  }
22403}
22404
22405impl<'a> From<&TsTypeParam<'a>> for Node<'a> {
22406  fn from(node: &TsTypeParam<'a>) -> Node<'a> {
22407    let node = unsafe { mem::transmute::<&TsTypeParam<'a>, &'a TsTypeParam<'a>>(node) };
22408    Node::TsTypeParam(node)
22409  }
22410}
22411
22412impl<'a> NodeTrait<'a> for TsTypeParam<'a> {
22413  fn parent(&self) -> Option<Node<'a>> {
22414    Some(self.parent.get().unwrap().clone())
22415  }
22416
22417  fn children(&self) -> Vec<Node<'a>> {
22418    let mut children = Vec::with_capacity(1 + match &self.constraint { Some(_value) => 1, None => 0, } + match &self.default { Some(_value) => 1, None => 0, });
22419    children.push(self.name.into());
22420    if let Some(child) = self.constraint.as_ref() {
22421      children.push(child.into());
22422    }
22423    if let Some(child) = self.default.as_ref() {
22424      children.push(child.into());
22425    }
22426    children
22427  }
22428
22429  fn as_node(&self) -> Node<'a> {
22430    self.into()
22431  }
22432
22433  fn kind(&self) -> NodeKind {
22434    NodeKind::TsTypeParam
22435  }
22436}
22437
22438impl<'a> CastableNode<'a> for TsTypeParam<'a> {
22439  fn to(node: &Node<'a>) -> Option<&'a Self> {
22440    if let Node::TsTypeParam(node) = node {
22441      Some(node)
22442    } else {
22443      None
22444    }
22445  }
22446
22447  fn kind() -> NodeKind {
22448    NodeKind::TsTypeParam
22449  }
22450}
22451
22452fn get_view_for_ts_type_param<'a>(inner: &'a swc_ast::TsTypeParam, bump: &'a Bump) -> &'a TsTypeParam<'a> {
22453  let node = bump.alloc(TsTypeParam {
22454    inner,
22455    parent: Default::default(),
22456    name: get_view_for_ident(&inner.name, bump),
22457    constraint: match &inner.constraint {
22458      Some(value) => Some(get_view_for_ts_type(value, bump)),
22459      None => None,
22460    },
22461    default: match &inner.default {
22462      Some(value) => Some(get_view_for_ts_type(value, bump)),
22463      None => None,
22464    },
22465  });
22466  let parent: Node<'a> = (&*node).into();
22467  set_parent_for_ident(&node.name, parent);
22468  if let Some(value) = &node.constraint {
22469    set_parent_for_ts_type(value, parent)
22470  };
22471  if let Some(value) = &node.default {
22472    set_parent_for_ts_type(value, parent)
22473  };
22474  node
22475}
22476
22477fn set_parent_for_ts_type_param<'a>(node: &TsTypeParam<'a>, parent: Node<'a>) {
22478  node.parent.set(parent);
22479}
22480
22481#[derive(Clone)]
22482pub struct TsTypeParamDecl<'a> {
22483  parent: ParentOnceCell<Node<'a>>,
22484  pub inner: &'a swc_ast::TsTypeParamDecl,
22485  pub params: &'a [&'a TsTypeParam<'a>],
22486}
22487
22488impl<'a> TsTypeParamDecl<'a> {
22489  pub fn parent(&self) -> Node<'a> {
22490    self.parent.get().unwrap()
22491  }
22492}
22493
22494impl<'a> SourceRanged for TsTypeParamDecl<'a> {
22495  fn start(&self) -> SourcePos {
22496    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22497  }
22498  fn end(&self) -> SourcePos {
22499    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22500  }
22501}
22502
22503impl<'a> From<&TsTypeParamDecl<'a>> for Node<'a> {
22504  fn from(node: &TsTypeParamDecl<'a>) -> Node<'a> {
22505    let node = unsafe { mem::transmute::<&TsTypeParamDecl<'a>, &'a TsTypeParamDecl<'a>>(node) };
22506    Node::TsTypeParamDecl(node)
22507  }
22508}
22509
22510impl<'a> NodeTrait<'a> for TsTypeParamDecl<'a> {
22511  fn parent(&self) -> Option<Node<'a>> {
22512    Some(self.parent.get().unwrap().clone())
22513  }
22514
22515  fn children(&self) -> Vec<Node<'a>> {
22516    let mut children = Vec::with_capacity(self.params.len());
22517    for child in self.params.iter() {
22518      children.push((*child).into());
22519    }
22520    children
22521  }
22522
22523  fn as_node(&self) -> Node<'a> {
22524    self.into()
22525  }
22526
22527  fn kind(&self) -> NodeKind {
22528    NodeKind::TsTypeParamDecl
22529  }
22530}
22531
22532impl<'a> CastableNode<'a> for TsTypeParamDecl<'a> {
22533  fn to(node: &Node<'a>) -> Option<&'a Self> {
22534    if let Node::TsTypeParamDecl(node) = node {
22535      Some(node)
22536    } else {
22537      None
22538    }
22539  }
22540
22541  fn kind() -> NodeKind {
22542    NodeKind::TsTypeParamDecl
22543  }
22544}
22545
22546fn get_view_for_ts_type_param_decl<'a>(inner: &'a swc_ast::TsTypeParamDecl, bump: &'a Bump) -> &'a TsTypeParamDecl<'a> {
22547  let node = bump.alloc(TsTypeParamDecl {
22548    inner,
22549    parent: Default::default(),
22550    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_ts_type_param(value, bump))); vec }),
22551  });
22552  let parent: Node<'a> = (&*node).into();
22553  for value in node.params.iter() {
22554    set_parent_for_ts_type_param(value, parent)
22555  }
22556  node
22557}
22558
22559fn set_parent_for_ts_type_param_decl<'a>(node: &TsTypeParamDecl<'a>, parent: Node<'a>) {
22560  node.parent.set(parent);
22561}
22562
22563#[derive(Clone)]
22564pub struct TsTypeParamInstantiation<'a> {
22565  parent: ParentOnceCell<Node<'a>>,
22566  pub inner: &'a swc_ast::TsTypeParamInstantiation,
22567  pub params: &'a [TsType<'a>],
22568}
22569
22570impl<'a> TsTypeParamInstantiation<'a> {
22571  pub fn parent(&self) -> Node<'a> {
22572    self.parent.get().unwrap()
22573  }
22574}
22575
22576impl<'a> SourceRanged for TsTypeParamInstantiation<'a> {
22577  fn start(&self) -> SourcePos {
22578    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22579  }
22580  fn end(&self) -> SourcePos {
22581    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22582  }
22583}
22584
22585impl<'a> From<&TsTypeParamInstantiation<'a>> for Node<'a> {
22586  fn from(node: &TsTypeParamInstantiation<'a>) -> Node<'a> {
22587    let node = unsafe { mem::transmute::<&TsTypeParamInstantiation<'a>, &'a TsTypeParamInstantiation<'a>>(node) };
22588    Node::TsTypeParamInstantiation(node)
22589  }
22590}
22591
22592impl<'a> NodeTrait<'a> for TsTypeParamInstantiation<'a> {
22593  fn parent(&self) -> Option<Node<'a>> {
22594    Some(self.parent.get().unwrap().clone())
22595  }
22596
22597  fn children(&self) -> Vec<Node<'a>> {
22598    let mut children = Vec::with_capacity(self.params.len());
22599    for child in self.params.iter() {
22600      children.push(child.into());
22601    }
22602    children
22603  }
22604
22605  fn as_node(&self) -> Node<'a> {
22606    self.into()
22607  }
22608
22609  fn kind(&self) -> NodeKind {
22610    NodeKind::TsTypeParamInstantiation
22611  }
22612}
22613
22614impl<'a> CastableNode<'a> for TsTypeParamInstantiation<'a> {
22615  fn to(node: &Node<'a>) -> Option<&'a Self> {
22616    if let Node::TsTypeParamInstantiation(node) = node {
22617      Some(node)
22618    } else {
22619      None
22620    }
22621  }
22622
22623  fn kind() -> NodeKind {
22624    NodeKind::TsTypeParamInstantiation
22625  }
22626}
22627
22628fn get_view_for_ts_type_param_instantiation<'a>(inner: &'a swc_ast::TsTypeParamInstantiation, bump: &'a Bump) -> &'a TsTypeParamInstantiation<'a> {
22629  let node = bump.alloc(TsTypeParamInstantiation {
22630    inner,
22631    parent: Default::default(),
22632    params: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.params.len(), bump);vec.extend(inner.params.iter().map(|value| get_view_for_ts_type(value, bump))); vec }),
22633  });
22634  let parent: Node<'a> = (&*node).into();
22635  for value in node.params.iter() {
22636    set_parent_for_ts_type(value, parent)
22637  }
22638  node
22639}
22640
22641fn set_parent_for_ts_type_param_instantiation<'a>(node: &TsTypeParamInstantiation<'a>, parent: Node<'a>) {
22642  node.parent.set(parent);
22643}
22644
22645#[derive(Clone)]
22646pub struct TsTypePredicate<'a> {
22647  parent: ParentOnceCell<Node<'a>>,
22648  pub inner: &'a swc_ast::TsTypePredicate,
22649  pub param_name: TsThisTypeOrIdent<'a>,
22650  pub type_ann: Option<&'a TsTypeAnn<'a>>,
22651}
22652
22653impl<'a> TsTypePredicate<'a> {
22654  pub fn parent(&self) -> Node<'a> {
22655    self.parent.get().unwrap()
22656  }
22657
22658  pub fn asserts(&self) -> bool {
22659    self.inner.asserts
22660  }
22661}
22662
22663impl<'a> SourceRanged for TsTypePredicate<'a> {
22664  fn start(&self) -> SourcePos {
22665    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22666  }
22667  fn end(&self) -> SourcePos {
22668    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22669  }
22670}
22671
22672impl<'a> From<&TsTypePredicate<'a>> for Node<'a> {
22673  fn from(node: &TsTypePredicate<'a>) -> Node<'a> {
22674    let node = unsafe { mem::transmute::<&TsTypePredicate<'a>, &'a TsTypePredicate<'a>>(node) };
22675    Node::TsTypePredicate(node)
22676  }
22677}
22678
22679impl<'a> NodeTrait<'a> for TsTypePredicate<'a> {
22680  fn parent(&self) -> Option<Node<'a>> {
22681    Some(self.parent.get().unwrap().clone())
22682  }
22683
22684  fn children(&self) -> Vec<Node<'a>> {
22685    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
22686    children.push((&self.param_name).into());
22687    if let Some(child) = self.type_ann {
22688      children.push(child.into());
22689    }
22690    children
22691  }
22692
22693  fn as_node(&self) -> Node<'a> {
22694    self.into()
22695  }
22696
22697  fn kind(&self) -> NodeKind {
22698    NodeKind::TsTypePredicate
22699  }
22700}
22701
22702impl<'a> CastableNode<'a> for TsTypePredicate<'a> {
22703  fn to(node: &Node<'a>) -> Option<&'a Self> {
22704    if let Node::TsTypePredicate(node) = node {
22705      Some(node)
22706    } else {
22707      None
22708    }
22709  }
22710
22711  fn kind() -> NodeKind {
22712    NodeKind::TsTypePredicate
22713  }
22714}
22715
22716fn get_view_for_ts_type_predicate<'a>(inner: &'a swc_ast::TsTypePredicate, bump: &'a Bump) -> &'a TsTypePredicate<'a> {
22717  let node = bump.alloc(TsTypePredicate {
22718    inner,
22719    parent: Default::default(),
22720    param_name: get_view_for_ts_this_type_or_ident(&inner.param_name, bump),
22721    type_ann: match &inner.type_ann {
22722      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
22723      None => None,
22724    },
22725  });
22726  let parent: Node<'a> = (&*node).into();
22727  set_parent_for_ts_this_type_or_ident(&node.param_name, parent);
22728  if let Some(value) = &node.type_ann {
22729    set_parent_for_ts_type_ann(value, parent)
22730  };
22731  node
22732}
22733
22734fn set_parent_for_ts_type_predicate<'a>(node: &TsTypePredicate<'a>, parent: Node<'a>) {
22735  node.parent.set(parent);
22736}
22737
22738/// `typeof` operator
22739#[derive(Clone)]
22740pub struct TsTypeQuery<'a> {
22741  parent: ParentOnceCell<Node<'a>>,
22742  pub inner: &'a swc_ast::TsTypeQuery,
22743  pub expr_name: TsTypeQueryExpr<'a>,
22744  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
22745}
22746
22747impl<'a> TsTypeQuery<'a> {
22748  pub fn parent(&self) -> Node<'a> {
22749    self.parent.get().unwrap()
22750  }
22751}
22752
22753impl<'a> SourceRanged for TsTypeQuery<'a> {
22754  fn start(&self) -> SourcePos {
22755    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22756  }
22757  fn end(&self) -> SourcePos {
22758    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22759  }
22760}
22761
22762impl<'a> From<&TsTypeQuery<'a>> for Node<'a> {
22763  fn from(node: &TsTypeQuery<'a>) -> Node<'a> {
22764    let node = unsafe { mem::transmute::<&TsTypeQuery<'a>, &'a TsTypeQuery<'a>>(node) };
22765    Node::TsTypeQuery(node)
22766  }
22767}
22768
22769impl<'a> NodeTrait<'a> for TsTypeQuery<'a> {
22770  fn parent(&self) -> Option<Node<'a>> {
22771    Some(self.parent.get().unwrap().clone())
22772  }
22773
22774  fn children(&self) -> Vec<Node<'a>> {
22775    let mut children = Vec::with_capacity(1 + match &self.type_args { Some(_value) => 1, None => 0, });
22776    children.push((&self.expr_name).into());
22777    if let Some(child) = self.type_args {
22778      children.push(child.into());
22779    }
22780    children
22781  }
22782
22783  fn as_node(&self) -> Node<'a> {
22784    self.into()
22785  }
22786
22787  fn kind(&self) -> NodeKind {
22788    NodeKind::TsTypeQuery
22789  }
22790}
22791
22792impl<'a> CastableNode<'a> for TsTypeQuery<'a> {
22793  fn to(node: &Node<'a>) -> Option<&'a Self> {
22794    if let Node::TsTypeQuery(node) = node {
22795      Some(node)
22796    } else {
22797      None
22798    }
22799  }
22800
22801  fn kind() -> NodeKind {
22802    NodeKind::TsTypeQuery
22803  }
22804}
22805
22806fn get_view_for_ts_type_query<'a>(inner: &'a swc_ast::TsTypeQuery, bump: &'a Bump) -> &'a TsTypeQuery<'a> {
22807  let node = bump.alloc(TsTypeQuery {
22808    inner,
22809    parent: Default::default(),
22810    expr_name: get_view_for_ts_type_query_expr(&inner.expr_name, bump),
22811    type_args: match &inner.type_args {
22812      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
22813      None => None,
22814    },
22815  });
22816  let parent: Node<'a> = (&*node).into();
22817  set_parent_for_ts_type_query_expr(&node.expr_name, parent);
22818  if let Some(value) = &node.type_args {
22819    set_parent_for_ts_type_param_instantiation(value, parent)
22820  };
22821  node
22822}
22823
22824fn set_parent_for_ts_type_query<'a>(node: &TsTypeQuery<'a>, parent: Node<'a>) {
22825  node.parent.set(parent);
22826}
22827
22828#[derive(Clone)]
22829pub struct TsTypeRef<'a> {
22830  parent: ParentOnceCell<Node<'a>>,
22831  pub inner: &'a swc_ast::TsTypeRef,
22832  pub type_name: TsEntityName<'a>,
22833  pub type_params: Option<&'a TsTypeParamInstantiation<'a>>,
22834}
22835
22836impl<'a> TsTypeRef<'a> {
22837  pub fn parent(&self) -> Node<'a> {
22838    self.parent.get().unwrap()
22839  }
22840}
22841
22842impl<'a> SourceRanged for TsTypeRef<'a> {
22843  fn start(&self) -> SourcePos {
22844    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22845  }
22846  fn end(&self) -> SourcePos {
22847    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22848  }
22849}
22850
22851impl<'a> From<&TsTypeRef<'a>> for Node<'a> {
22852  fn from(node: &TsTypeRef<'a>) -> Node<'a> {
22853    let node = unsafe { mem::transmute::<&TsTypeRef<'a>, &'a TsTypeRef<'a>>(node) };
22854    Node::TsTypeRef(node)
22855  }
22856}
22857
22858impl<'a> NodeTrait<'a> for TsTypeRef<'a> {
22859  fn parent(&self) -> Option<Node<'a>> {
22860    Some(self.parent.get().unwrap().clone())
22861  }
22862
22863  fn children(&self) -> Vec<Node<'a>> {
22864    let mut children = Vec::with_capacity(1 + match &self.type_params { Some(_value) => 1, None => 0, });
22865    children.push((&self.type_name).into());
22866    if let Some(child) = self.type_params {
22867      children.push(child.into());
22868    }
22869    children
22870  }
22871
22872  fn as_node(&self) -> Node<'a> {
22873    self.into()
22874  }
22875
22876  fn kind(&self) -> NodeKind {
22877    NodeKind::TsTypeRef
22878  }
22879}
22880
22881impl<'a> CastableNode<'a> for TsTypeRef<'a> {
22882  fn to(node: &Node<'a>) -> Option<&'a Self> {
22883    if let Node::TsTypeRef(node) = node {
22884      Some(node)
22885    } else {
22886      None
22887    }
22888  }
22889
22890  fn kind() -> NodeKind {
22891    NodeKind::TsTypeRef
22892  }
22893}
22894
22895fn get_view_for_ts_type_ref<'a>(inner: &'a swc_ast::TsTypeRef, bump: &'a Bump) -> &'a TsTypeRef<'a> {
22896  let node = bump.alloc(TsTypeRef {
22897    inner,
22898    parent: Default::default(),
22899    type_name: get_view_for_ts_entity_name(&inner.type_name, bump),
22900    type_params: match &inner.type_params {
22901      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
22902      None => None,
22903    },
22904  });
22905  let parent: Node<'a> = (&*node).into();
22906  set_parent_for_ts_entity_name(&node.type_name, parent);
22907  if let Some(value) = &node.type_params {
22908    set_parent_for_ts_type_param_instantiation(value, parent)
22909  };
22910  node
22911}
22912
22913fn set_parent_for_ts_type_ref<'a>(node: &TsTypeRef<'a>, parent: Node<'a>) {
22914  node.parent.set(parent);
22915}
22916
22917#[derive(Clone)]
22918pub struct TsUnionType<'a> {
22919  parent: ParentOnceCell<Node<'a>>,
22920  pub inner: &'a swc_ast::TsUnionType,
22921  pub types: &'a [TsType<'a>],
22922}
22923
22924impl<'a> TsUnionType<'a> {
22925  pub fn parent(&self) -> Node<'a> {
22926    self.parent.get().unwrap()
22927  }
22928}
22929
22930impl<'a> SourceRanged for TsUnionType<'a> {
22931  fn start(&self) -> SourcePos {
22932    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22933  }
22934  fn end(&self) -> SourcePos {
22935    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22936  }
22937}
22938
22939impl<'a> From<&TsUnionType<'a>> for Node<'a> {
22940  fn from(node: &TsUnionType<'a>) -> Node<'a> {
22941    let node = unsafe { mem::transmute::<&TsUnionType<'a>, &'a TsUnionType<'a>>(node) };
22942    Node::TsUnionType(node)
22943  }
22944}
22945
22946impl<'a> NodeTrait<'a> for TsUnionType<'a> {
22947  fn parent(&self) -> Option<Node<'a>> {
22948    Some(self.parent.get().unwrap().clone())
22949  }
22950
22951  fn children(&self) -> Vec<Node<'a>> {
22952    let mut children = Vec::with_capacity(self.types.len());
22953    for child in self.types.iter() {
22954      children.push(child.into());
22955    }
22956    children
22957  }
22958
22959  fn as_node(&self) -> Node<'a> {
22960    self.into()
22961  }
22962
22963  fn kind(&self) -> NodeKind {
22964    NodeKind::TsUnionType
22965  }
22966}
22967
22968impl<'a> CastableNode<'a> for TsUnionType<'a> {
22969  fn to(node: &Node<'a>) -> Option<&'a Self> {
22970    if let Node::TsUnionType(node) = node {
22971      Some(node)
22972    } else {
22973      None
22974    }
22975  }
22976
22977  fn kind() -> NodeKind {
22978    NodeKind::TsUnionType
22979  }
22980}
22981
22982fn get_view_for_ts_union_type<'a>(inner: &'a swc_ast::TsUnionType, bump: &'a Bump) -> &'a TsUnionType<'a> {
22983  let node = bump.alloc(TsUnionType {
22984    inner,
22985    parent: Default::default(),
22986    types: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.types.len(), bump);vec.extend(inner.types.iter().map(|value| get_view_for_ts_type(value, bump))); vec }),
22987  });
22988  let parent: Node<'a> = (&*node).into();
22989  for value in node.types.iter() {
22990    set_parent_for_ts_type(value, parent)
22991  }
22992  node
22993}
22994
22995fn set_parent_for_ts_union_type<'a>(node: &TsUnionType<'a>, parent: Node<'a>) {
22996  node.parent.set(parent);
22997}
22998
22999#[derive(Clone)]
23000pub struct UnaryExpr<'a> {
23001  parent: ParentOnceCell<Node<'a>>,
23002  pub inner: &'a swc_ast::UnaryExpr,
23003  pub arg: Expr<'a>,
23004}
23005
23006impl<'a> UnaryExpr<'a> {
23007  pub fn parent(&self) -> Node<'a> {
23008    self.parent.get().unwrap()
23009  }
23010
23011  pub fn op(&self) -> UnaryOp {
23012    self.inner.op
23013  }
23014}
23015
23016impl<'a> SourceRanged for UnaryExpr<'a> {
23017  fn start(&self) -> SourcePos {
23018    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23019  }
23020  fn end(&self) -> SourcePos {
23021    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23022  }
23023}
23024
23025impl<'a> From<&UnaryExpr<'a>> for Node<'a> {
23026  fn from(node: &UnaryExpr<'a>) -> Node<'a> {
23027    let node = unsafe { mem::transmute::<&UnaryExpr<'a>, &'a UnaryExpr<'a>>(node) };
23028    Node::UnaryExpr(node)
23029  }
23030}
23031
23032impl<'a> NodeTrait<'a> for UnaryExpr<'a> {
23033  fn parent(&self) -> Option<Node<'a>> {
23034    Some(self.parent.get().unwrap().clone())
23035  }
23036
23037  fn children(&self) -> Vec<Node<'a>> {
23038    let mut children = Vec::with_capacity(1);
23039    children.push((&self.arg).into());
23040    children
23041  }
23042
23043  fn as_node(&self) -> Node<'a> {
23044    self.into()
23045  }
23046
23047  fn kind(&self) -> NodeKind {
23048    NodeKind::UnaryExpr
23049  }
23050}
23051
23052impl<'a> CastableNode<'a> for UnaryExpr<'a> {
23053  fn to(node: &Node<'a>) -> Option<&'a Self> {
23054    if let Node::UnaryExpr(node) = node {
23055      Some(node)
23056    } else {
23057      None
23058    }
23059  }
23060
23061  fn kind() -> NodeKind {
23062    NodeKind::UnaryExpr
23063  }
23064}
23065
23066fn get_view_for_unary_expr<'a>(inner: &'a swc_ast::UnaryExpr, bump: &'a Bump) -> &'a UnaryExpr<'a> {
23067  let node = bump.alloc(UnaryExpr {
23068    inner,
23069    parent: Default::default(),
23070    arg: get_view_for_expr(&inner.arg, bump),
23071  });
23072  let parent: Node<'a> = (&*node).into();
23073  set_parent_for_expr(&node.arg, parent);
23074  node
23075}
23076
23077fn set_parent_for_unary_expr<'a>(node: &UnaryExpr<'a>, parent: Node<'a>) {
23078  node.parent.set(parent);
23079}
23080
23081#[derive(Clone)]
23082pub struct UpdateExpr<'a> {
23083  parent: ParentOnceCell<Node<'a>>,
23084  pub inner: &'a swc_ast::UpdateExpr,
23085  pub arg: Expr<'a>,
23086}
23087
23088impl<'a> UpdateExpr<'a> {
23089  pub fn parent(&self) -> Node<'a> {
23090    self.parent.get().unwrap()
23091  }
23092
23093  pub fn op(&self) -> UpdateOp {
23094    self.inner.op
23095  }
23096
23097  pub fn prefix(&self) -> bool {
23098    self.inner.prefix
23099  }
23100}
23101
23102impl<'a> SourceRanged for UpdateExpr<'a> {
23103  fn start(&self) -> SourcePos {
23104    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23105  }
23106  fn end(&self) -> SourcePos {
23107    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23108  }
23109}
23110
23111impl<'a> From<&UpdateExpr<'a>> for Node<'a> {
23112  fn from(node: &UpdateExpr<'a>) -> Node<'a> {
23113    let node = unsafe { mem::transmute::<&UpdateExpr<'a>, &'a UpdateExpr<'a>>(node) };
23114    Node::UpdateExpr(node)
23115  }
23116}
23117
23118impl<'a> NodeTrait<'a> for UpdateExpr<'a> {
23119  fn parent(&self) -> Option<Node<'a>> {
23120    Some(self.parent.get().unwrap().clone())
23121  }
23122
23123  fn children(&self) -> Vec<Node<'a>> {
23124    let mut children = Vec::with_capacity(1);
23125    children.push((&self.arg).into());
23126    children
23127  }
23128
23129  fn as_node(&self) -> Node<'a> {
23130    self.into()
23131  }
23132
23133  fn kind(&self) -> NodeKind {
23134    NodeKind::UpdateExpr
23135  }
23136}
23137
23138impl<'a> CastableNode<'a> for UpdateExpr<'a> {
23139  fn to(node: &Node<'a>) -> Option<&'a Self> {
23140    if let Node::UpdateExpr(node) = node {
23141      Some(node)
23142    } else {
23143      None
23144    }
23145  }
23146
23147  fn kind() -> NodeKind {
23148    NodeKind::UpdateExpr
23149  }
23150}
23151
23152fn get_view_for_update_expr<'a>(inner: &'a swc_ast::UpdateExpr, bump: &'a Bump) -> &'a UpdateExpr<'a> {
23153  let node = bump.alloc(UpdateExpr {
23154    inner,
23155    parent: Default::default(),
23156    arg: get_view_for_expr(&inner.arg, bump),
23157  });
23158  let parent: Node<'a> = (&*node).into();
23159  set_parent_for_expr(&node.arg, parent);
23160  node
23161}
23162
23163fn set_parent_for_update_expr<'a>(node: &UpdateExpr<'a>, parent: Node<'a>) {
23164  node.parent.set(parent);
23165}
23166
23167#[derive(Clone)]
23168pub struct UsingDecl<'a> {
23169  parent: ParentOnceCell<Node<'a>>,
23170  pub inner: &'a swc_ast::UsingDecl,
23171  pub decls: &'a [&'a VarDeclarator<'a>],
23172}
23173
23174impl<'a> UsingDecl<'a> {
23175  pub fn parent(&self) -> Node<'a> {
23176    self.parent.get().unwrap()
23177  }
23178
23179  pub fn is_await(&self) -> bool {
23180    self.inner.is_await
23181  }
23182}
23183
23184impl<'a> SourceRanged for UsingDecl<'a> {
23185  fn start(&self) -> SourcePos {
23186    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23187  }
23188  fn end(&self) -> SourcePos {
23189    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23190  }
23191}
23192
23193impl<'a> From<&UsingDecl<'a>> for Node<'a> {
23194  fn from(node: &UsingDecl<'a>) -> Node<'a> {
23195    let node = unsafe { mem::transmute::<&UsingDecl<'a>, &'a UsingDecl<'a>>(node) };
23196    Node::UsingDecl(node)
23197  }
23198}
23199
23200impl<'a> NodeTrait<'a> for UsingDecl<'a> {
23201  fn parent(&self) -> Option<Node<'a>> {
23202    Some(self.parent.get().unwrap().clone())
23203  }
23204
23205  fn children(&self) -> Vec<Node<'a>> {
23206    let mut children = Vec::with_capacity(self.decls.len());
23207    for child in self.decls.iter() {
23208      children.push((*child).into());
23209    }
23210    children
23211  }
23212
23213  fn as_node(&self) -> Node<'a> {
23214    self.into()
23215  }
23216
23217  fn kind(&self) -> NodeKind {
23218    NodeKind::UsingDecl
23219  }
23220}
23221
23222impl<'a> CastableNode<'a> for UsingDecl<'a> {
23223  fn to(node: &Node<'a>) -> Option<&'a Self> {
23224    if let Node::UsingDecl(node) = node {
23225      Some(node)
23226    } else {
23227      None
23228    }
23229  }
23230
23231  fn kind() -> NodeKind {
23232    NodeKind::UsingDecl
23233  }
23234}
23235
23236fn get_view_for_using_decl<'a>(inner: &'a swc_ast::UsingDecl, bump: &'a Bump) -> &'a UsingDecl<'a> {
23237  let node = bump.alloc(UsingDecl {
23238    inner,
23239    parent: Default::default(),
23240    decls: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.decls.len(), bump);vec.extend(inner.decls.iter().map(|value| get_view_for_var_declarator(value, bump))); vec }),
23241  });
23242  let parent: Node<'a> = (&*node).into();
23243  for value in node.decls.iter() {
23244    set_parent_for_var_declarator(value, parent)
23245  }
23246  node
23247}
23248
23249fn set_parent_for_using_decl<'a>(node: &UsingDecl<'a>, parent: Node<'a>) {
23250  node.parent.set(parent);
23251}
23252
23253#[derive(Clone)]
23254pub struct VarDecl<'a> {
23255  parent: ParentOnceCell<Node<'a>>,
23256  pub inner: &'a swc_ast::VarDecl,
23257  pub decls: &'a [&'a VarDeclarator<'a>],
23258}
23259
23260impl<'a> VarDecl<'a> {
23261  pub fn parent(&self) -> Node<'a> {
23262    self.parent.get().unwrap()
23263  }
23264
23265  pub fn ctxt(&self) -> swc_common::SyntaxContext {
23266    self.inner.ctxt
23267  }
23268
23269  pub fn decl_kind(&self) -> VarDeclKind {
23270    self.inner.kind
23271  }
23272
23273  pub fn declare(&self) -> bool {
23274    self.inner.declare
23275  }
23276}
23277
23278impl<'a> SourceRanged for VarDecl<'a> {
23279  fn start(&self) -> SourcePos {
23280    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23281  }
23282  fn end(&self) -> SourcePos {
23283    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23284  }
23285}
23286
23287impl<'a> From<&VarDecl<'a>> for Node<'a> {
23288  fn from(node: &VarDecl<'a>) -> Node<'a> {
23289    let node = unsafe { mem::transmute::<&VarDecl<'a>, &'a VarDecl<'a>>(node) };
23290    Node::VarDecl(node)
23291  }
23292}
23293
23294impl<'a> NodeTrait<'a> for VarDecl<'a> {
23295  fn parent(&self) -> Option<Node<'a>> {
23296    Some(self.parent.get().unwrap().clone())
23297  }
23298
23299  fn children(&self) -> Vec<Node<'a>> {
23300    let mut children = Vec::with_capacity(self.decls.len());
23301    for child in self.decls.iter() {
23302      children.push((*child).into());
23303    }
23304    children
23305  }
23306
23307  fn as_node(&self) -> Node<'a> {
23308    self.into()
23309  }
23310
23311  fn kind(&self) -> NodeKind {
23312    NodeKind::VarDecl
23313  }
23314}
23315
23316impl<'a> CastableNode<'a> for VarDecl<'a> {
23317  fn to(node: &Node<'a>) -> Option<&'a Self> {
23318    if let Node::VarDecl(node) = node {
23319      Some(node)
23320    } else {
23321      None
23322    }
23323  }
23324
23325  fn kind() -> NodeKind {
23326    NodeKind::VarDecl
23327  }
23328}
23329
23330fn get_view_for_var_decl<'a>(inner: &'a swc_ast::VarDecl, bump: &'a Bump) -> &'a VarDecl<'a> {
23331  let node = bump.alloc(VarDecl {
23332    inner,
23333    parent: Default::default(),
23334    decls: bump.alloc({let mut vec = allocator_api2::vec::Vec::with_capacity_in(inner.decls.len(), bump);vec.extend(inner.decls.iter().map(|value| get_view_for_var_declarator(value, bump))); vec }),
23335  });
23336  let parent: Node<'a> = (&*node).into();
23337  for value in node.decls.iter() {
23338    set_parent_for_var_declarator(value, parent)
23339  }
23340  node
23341}
23342
23343fn set_parent_for_var_decl<'a>(node: &VarDecl<'a>, parent: Node<'a>) {
23344  node.parent.set(parent);
23345}
23346
23347#[derive(Clone)]
23348pub struct VarDeclarator<'a> {
23349  parent: ParentOnceCell<Node<'a>>,
23350  pub inner: &'a swc_ast::VarDeclarator,
23351  pub name: Pat<'a>,
23352  /// Initialization expression.
23353  pub init: Option<Expr<'a>>,
23354}
23355
23356impl<'a> VarDeclarator<'a> {
23357  pub fn parent(&self) -> Node<'a> {
23358    self.parent.get().unwrap()
23359  }
23360
23361  /// Typescript only
23362  pub fn definite(&self) -> bool {
23363    self.inner.definite
23364  }
23365}
23366
23367impl<'a> SourceRanged for VarDeclarator<'a> {
23368  fn start(&self) -> SourcePos {
23369    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23370  }
23371  fn end(&self) -> SourcePos {
23372    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23373  }
23374}
23375
23376impl<'a> From<&VarDeclarator<'a>> for Node<'a> {
23377  fn from(node: &VarDeclarator<'a>) -> Node<'a> {
23378    let node = unsafe { mem::transmute::<&VarDeclarator<'a>, &'a VarDeclarator<'a>>(node) };
23379    Node::VarDeclarator(node)
23380  }
23381}
23382
23383impl<'a> NodeTrait<'a> for VarDeclarator<'a> {
23384  fn parent(&self) -> Option<Node<'a>> {
23385    Some(self.parent.get().unwrap().clone())
23386  }
23387
23388  fn children(&self) -> Vec<Node<'a>> {
23389    let mut children = Vec::with_capacity(1 + match &self.init { Some(_value) => 1, None => 0, });
23390    children.push((&self.name).into());
23391    if let Some(child) = self.init.as_ref() {
23392      children.push(child.into());
23393    }
23394    children
23395  }
23396
23397  fn as_node(&self) -> Node<'a> {
23398    self.into()
23399  }
23400
23401  fn kind(&self) -> NodeKind {
23402    NodeKind::VarDeclarator
23403  }
23404}
23405
23406impl<'a> CastableNode<'a> for VarDeclarator<'a> {
23407  fn to(node: &Node<'a>) -> Option<&'a Self> {
23408    if let Node::VarDeclarator(node) = node {
23409      Some(node)
23410    } else {
23411      None
23412    }
23413  }
23414
23415  fn kind() -> NodeKind {
23416    NodeKind::VarDeclarator
23417  }
23418}
23419
23420fn get_view_for_var_declarator<'a>(inner: &'a swc_ast::VarDeclarator, bump: &'a Bump) -> &'a VarDeclarator<'a> {
23421  let node = bump.alloc(VarDeclarator {
23422    inner,
23423    parent: Default::default(),
23424    name: get_view_for_pat(&inner.name, bump),
23425    init: match &inner.init {
23426      Some(value) => Some(get_view_for_expr(value, bump)),
23427      None => None,
23428    },
23429  });
23430  let parent: Node<'a> = (&*node).into();
23431  set_parent_for_pat(&node.name, parent);
23432  if let Some(value) = &node.init {
23433    set_parent_for_expr(value, parent)
23434  };
23435  node
23436}
23437
23438fn set_parent_for_var_declarator<'a>(node: &VarDeclarator<'a>, parent: Node<'a>) {
23439  node.parent.set(parent);
23440}
23441
23442#[derive(Clone)]
23443pub struct WhileStmt<'a> {
23444  parent: ParentOnceCell<Node<'a>>,
23445  pub inner: &'a swc_ast::WhileStmt,
23446  pub test: Expr<'a>,
23447  pub body: Stmt<'a>,
23448}
23449
23450impl<'a> WhileStmt<'a> {
23451  pub fn parent(&self) -> Node<'a> {
23452    self.parent.get().unwrap()
23453  }
23454}
23455
23456impl<'a> SourceRanged for WhileStmt<'a> {
23457  fn start(&self) -> SourcePos {
23458    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23459  }
23460  fn end(&self) -> SourcePos {
23461    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23462  }
23463}
23464
23465impl<'a> From<&WhileStmt<'a>> for Node<'a> {
23466  fn from(node: &WhileStmt<'a>) -> Node<'a> {
23467    let node = unsafe { mem::transmute::<&WhileStmt<'a>, &'a WhileStmt<'a>>(node) };
23468    Node::WhileStmt(node)
23469  }
23470}
23471
23472impl<'a> NodeTrait<'a> for WhileStmt<'a> {
23473  fn parent(&self) -> Option<Node<'a>> {
23474    Some(self.parent.get().unwrap().clone())
23475  }
23476
23477  fn children(&self) -> Vec<Node<'a>> {
23478    let mut children = Vec::with_capacity(2);
23479    children.push((&self.test).into());
23480    children.push((&self.body).into());
23481    children
23482  }
23483
23484  fn as_node(&self) -> Node<'a> {
23485    self.into()
23486  }
23487
23488  fn kind(&self) -> NodeKind {
23489    NodeKind::WhileStmt
23490  }
23491}
23492
23493impl<'a> CastableNode<'a> for WhileStmt<'a> {
23494  fn to(node: &Node<'a>) -> Option<&'a Self> {
23495    if let Node::WhileStmt(node) = node {
23496      Some(node)
23497    } else {
23498      None
23499    }
23500  }
23501
23502  fn kind() -> NodeKind {
23503    NodeKind::WhileStmt
23504  }
23505}
23506
23507fn get_view_for_while_stmt<'a>(inner: &'a swc_ast::WhileStmt, bump: &'a Bump) -> &'a WhileStmt<'a> {
23508  let node = bump.alloc(WhileStmt {
23509    inner,
23510    parent: Default::default(),
23511    test: get_view_for_expr(&inner.test, bump),
23512    body: get_view_for_stmt(&inner.body, bump),
23513  });
23514  let parent: Node<'a> = (&*node).into();
23515  set_parent_for_expr(&node.test, parent);
23516  set_parent_for_stmt(&node.body, parent);
23517  node
23518}
23519
23520fn set_parent_for_while_stmt<'a>(node: &WhileStmt<'a>, parent: Node<'a>) {
23521  node.parent.set(parent);
23522}
23523
23524#[derive(Clone)]
23525pub struct WithStmt<'a> {
23526  parent: ParentOnceCell<Node<'a>>,
23527  pub inner: &'a swc_ast::WithStmt,
23528  pub obj: Expr<'a>,
23529  pub body: Stmt<'a>,
23530}
23531
23532impl<'a> WithStmt<'a> {
23533  pub fn parent(&self) -> Node<'a> {
23534    self.parent.get().unwrap()
23535  }
23536}
23537
23538impl<'a> SourceRanged for WithStmt<'a> {
23539  fn start(&self) -> SourcePos {
23540    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23541  }
23542  fn end(&self) -> SourcePos {
23543    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23544  }
23545}
23546
23547impl<'a> From<&WithStmt<'a>> for Node<'a> {
23548  fn from(node: &WithStmt<'a>) -> Node<'a> {
23549    let node = unsafe { mem::transmute::<&WithStmt<'a>, &'a WithStmt<'a>>(node) };
23550    Node::WithStmt(node)
23551  }
23552}
23553
23554impl<'a> NodeTrait<'a> for WithStmt<'a> {
23555  fn parent(&self) -> Option<Node<'a>> {
23556    Some(self.parent.get().unwrap().clone())
23557  }
23558
23559  fn children(&self) -> Vec<Node<'a>> {
23560    let mut children = Vec::with_capacity(2);
23561    children.push((&self.obj).into());
23562    children.push((&self.body).into());
23563    children
23564  }
23565
23566  fn as_node(&self) -> Node<'a> {
23567    self.into()
23568  }
23569
23570  fn kind(&self) -> NodeKind {
23571    NodeKind::WithStmt
23572  }
23573}
23574
23575impl<'a> CastableNode<'a> for WithStmt<'a> {
23576  fn to(node: &Node<'a>) -> Option<&'a Self> {
23577    if let Node::WithStmt(node) = node {
23578      Some(node)
23579    } else {
23580      None
23581    }
23582  }
23583
23584  fn kind() -> NodeKind {
23585    NodeKind::WithStmt
23586  }
23587}
23588
23589fn get_view_for_with_stmt<'a>(inner: &'a swc_ast::WithStmt, bump: &'a Bump) -> &'a WithStmt<'a> {
23590  let node = bump.alloc(WithStmt {
23591    inner,
23592    parent: Default::default(),
23593    obj: get_view_for_expr(&inner.obj, bump),
23594    body: get_view_for_stmt(&inner.body, bump),
23595  });
23596  let parent: Node<'a> = (&*node).into();
23597  set_parent_for_expr(&node.obj, parent);
23598  set_parent_for_stmt(&node.body, parent);
23599  node
23600}
23601
23602fn set_parent_for_with_stmt<'a>(node: &WithStmt<'a>, parent: Node<'a>) {
23603  node.parent.set(parent);
23604}
23605
23606#[derive(Clone)]
23607pub struct YieldExpr<'a> {
23608  parent: ParentOnceCell<Node<'a>>,
23609  pub inner: &'a swc_ast::YieldExpr,
23610  pub arg: Option<Expr<'a>>,
23611}
23612
23613impl<'a> YieldExpr<'a> {
23614  pub fn parent(&self) -> Node<'a> {
23615    self.parent.get().unwrap()
23616  }
23617
23618  pub fn delegate(&self) -> bool {
23619    self.inner.delegate
23620  }
23621}
23622
23623impl<'a> SourceRanged for YieldExpr<'a> {
23624  fn start(&self) -> SourcePos {
23625    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23626  }
23627  fn end(&self) -> SourcePos {
23628    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23629  }
23630}
23631
23632impl<'a> From<&YieldExpr<'a>> for Node<'a> {
23633  fn from(node: &YieldExpr<'a>) -> Node<'a> {
23634    let node = unsafe { mem::transmute::<&YieldExpr<'a>, &'a YieldExpr<'a>>(node) };
23635    Node::YieldExpr(node)
23636  }
23637}
23638
23639impl<'a> NodeTrait<'a> for YieldExpr<'a> {
23640  fn parent(&self) -> Option<Node<'a>> {
23641    Some(self.parent.get().unwrap().clone())
23642  }
23643
23644  fn children(&self) -> Vec<Node<'a>> {
23645    let mut children = Vec::with_capacity(match &self.arg { Some(_value) => 1, None => 0, });
23646    if let Some(child) = self.arg.as_ref() {
23647      children.push(child.into());
23648    }
23649    children
23650  }
23651
23652  fn as_node(&self) -> Node<'a> {
23653    self.into()
23654  }
23655
23656  fn kind(&self) -> NodeKind {
23657    NodeKind::YieldExpr
23658  }
23659}
23660
23661impl<'a> CastableNode<'a> for YieldExpr<'a> {
23662  fn to(node: &Node<'a>) -> Option<&'a Self> {
23663    if let Node::YieldExpr(node) = node {
23664      Some(node)
23665    } else {
23666      None
23667    }
23668  }
23669
23670  fn kind() -> NodeKind {
23671    NodeKind::YieldExpr
23672  }
23673}
23674
23675fn get_view_for_yield_expr<'a>(inner: &'a swc_ast::YieldExpr, bump: &'a Bump) -> &'a YieldExpr<'a> {
23676  let node = bump.alloc(YieldExpr {
23677    inner,
23678    parent: Default::default(),
23679    arg: match &inner.arg {
23680      Some(value) => Some(get_view_for_expr(value, bump)),
23681      None => None,
23682    },
23683  });
23684  let parent: Node<'a> = (&*node).into();
23685  if let Some(value) = &node.arg {
23686    set_parent_for_expr(value, parent)
23687  };
23688  node
23689}
23690
23691fn set_parent_for_yield_expr<'a>(node: &YieldExpr<'a>, parent: Node<'a>) {
23692  node.parent.set(parent);
23693}
23694
23695struct ParentOnceCell<T> {
23696  cell: std::cell::UnsafeCell<Option<T>>,
23697}
23698
23699impl<T> ParentOnceCell<T> {
23700  pub fn get(&self) -> &Option<T> {
23701    unsafe { &*self.cell.get() }
23702  }
23703
23704  #[cold]
23705  pub fn set(&self, value: T) {
23706    unsafe {
23707      let inner = self.cell.get();
23708      inner.replace(Some(value));
23709    }
23710  }
23711}
23712
23713impl<T> Default for ParentOnceCell<T> {
23714  fn default() -> Self {
23715    Self {
23716      cell: std::cell::UnsafeCell::new(None),
23717    }
23718  }
23719}
23720
23721impl<T: Clone> Clone for ParentOnceCell<T> {
23722  fn clone(&self) -> Self {
23723    Self {
23724      cell: std::cell::UnsafeCell::new(self.get().clone()),
23725    }
23726  }
23727}
23728