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  Lit(Lit<'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}
3688
3689impl<'a> SourceRanged for JSXAttrValue<'a> {
3690  fn start(&self) -> SourcePos {
3691    match self {
3692      JSXAttrValue::Lit(node) => node.start(),
3693      JSXAttrValue::JSXExprContainer(node) => node.start(),
3694      JSXAttrValue::JSXElement(node) => node.start(),
3695      JSXAttrValue::JSXFragment(node) => node.start(),
3696    }
3697  }
3698  fn end(&self) -> SourcePos {
3699    match self {
3700      JSXAttrValue::Lit(node) => node.end(),
3701      JSXAttrValue::JSXExprContainer(node) => node.end(),
3702      JSXAttrValue::JSXElement(node) => node.end(),
3703      JSXAttrValue::JSXFragment(node) => node.end(),
3704    }
3705  }
3706}
3707
3708impl<'a> NodeTrait<'a> for JSXAttrValue<'a> {
3709  fn parent(&self) -> Option<Node<'a>> {
3710    match self {
3711      JSXAttrValue::Lit(node) => NodeTrait::parent(node),
3712      JSXAttrValue::JSXExprContainer(node) => NodeTrait::parent(*node),
3713      JSXAttrValue::JSXElement(node) => NodeTrait::parent(*node),
3714      JSXAttrValue::JSXFragment(node) => NodeTrait::parent(*node),
3715    }
3716  }
3717
3718  fn children(&self) -> Vec<Node<'a>> {
3719    match self {
3720      JSXAttrValue::Lit(node) => node.children(),
3721      JSXAttrValue::JSXExprContainer(node) => node.children(),
3722      JSXAttrValue::JSXElement(node) => node.children(),
3723      JSXAttrValue::JSXFragment(node) => node.children(),
3724    }
3725  }
3726
3727  fn as_node(&self) -> Node<'a> {
3728    match self {
3729      JSXAttrValue::Lit(node) => node.as_node(),
3730      JSXAttrValue::JSXExprContainer(node) => node.as_node(),
3731      JSXAttrValue::JSXElement(node) => node.as_node(),
3732      JSXAttrValue::JSXFragment(node) => node.as_node(),
3733    }
3734  }
3735
3736  fn kind(&self) -> NodeKind {
3737    match self {
3738      JSXAttrValue::Lit(node) => node.kind(),
3739      JSXAttrValue::JSXExprContainer(_) => NodeKind::JSXExprContainer,
3740      JSXAttrValue::JSXElement(_) => NodeKind::JSXElement,
3741      JSXAttrValue::JSXFragment(_) => NodeKind::JSXFragment,
3742    }
3743  }
3744}
3745
3746impl<'a> From<&JSXAttrValue<'a>> for Node<'a> {
3747  fn from(node: &JSXAttrValue<'a>) -> Node<'a> {
3748    match node {
3749      JSXAttrValue::Lit(node) => node.into(),
3750      JSXAttrValue::JSXExprContainer(node) => (*node).into(),
3751      JSXAttrValue::JSXElement(node) => (*node).into(),
3752      JSXAttrValue::JSXFragment(node) => (*node).into(),
3753    }
3754  }
3755}
3756
3757impl<'a> From<JSXAttrValue<'a>> for Node<'a> {
3758  fn from(node: JSXAttrValue<'a>) -> Node<'a> {
3759    match node {
3760      JSXAttrValue::Lit(node) => node.into(),
3761      JSXAttrValue::JSXExprContainer(node) => node.into(),
3762      JSXAttrValue::JSXElement(node) => node.into(),
3763      JSXAttrValue::JSXFragment(node) => node.into(),
3764    }
3765  }
3766}
3767
3768fn get_view_for_jsxattr_value<'a>(inner: &'a swc_ast::JSXAttrValue, bump: &'a Bump) -> JSXAttrValue<'a> {
3769  match inner {
3770    swc_ast::JSXAttrValue::Lit(value) => JSXAttrValue::Lit(get_view_for_lit(value, bump)),
3771    swc_ast::JSXAttrValue::JSXExprContainer(value) => JSXAttrValue::JSXExprContainer(get_view_for_jsxexpr_container(value, bump)),
3772    swc_ast::JSXAttrValue::JSXElement(value) => JSXAttrValue::JSXElement(get_view_for_jsxelement(value, bump)),
3773    swc_ast::JSXAttrValue::JSXFragment(value) => JSXAttrValue::JSXFragment(get_view_for_jsxfragment(value, bump)),
3774  }
3775}
3776
3777fn set_parent_for_jsxattr_value<'a>(node: &JSXAttrValue<'a>, parent: Node<'a>) {
3778  match node {
3779    JSXAttrValue::Lit(value) => set_parent_for_lit(value, parent),
3780    JSXAttrValue::JSXExprContainer(value) => set_parent_for_jsxexpr_container(value, parent),
3781    JSXAttrValue::JSXElement(value) => set_parent_for_jsxelement(value, parent),
3782    JSXAttrValue::JSXFragment(value) => set_parent_for_jsxfragment(value, parent),
3783  }
3784}
3785
3786#[derive(Copy, Clone)]
3787pub enum JSXElementChild<'a> {
3788  JSXText(&'a JSXText<'a>),
3789  JSXExprContainer(&'a JSXExprContainer<'a>),
3790  JSXSpreadChild(&'a JSXSpreadChild<'a>),
3791  JSXElement(&'a JSXElement<'a>),
3792  JSXFragment(&'a JSXFragment<'a>),
3793}
3794
3795impl<'a> JSXElementChild<'a> {
3796  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
3797    T::to(&self.into())
3798  }
3799
3800  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
3801    let node: Node<'a> = self.into();
3802    if let Some(result) = T::to(&node) {
3803      result
3804    } else {
3805      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
3806    }
3807  }
3808
3809  pub fn is<T: CastableNode<'a>>(&self) -> bool {
3810    self.kind() == T::kind()
3811  }
3812  pub fn parent(&self) -> Node<'a> {
3813    NodeTrait::parent(self).unwrap()
3814  }
3815}
3816
3817impl<'a> SourceRanged for JSXElementChild<'a> {
3818  fn start(&self) -> SourcePos {
3819    match self {
3820      JSXElementChild::JSXText(node) => node.start(),
3821      JSXElementChild::JSXExprContainer(node) => node.start(),
3822      JSXElementChild::JSXSpreadChild(node) => node.start(),
3823      JSXElementChild::JSXElement(node) => node.start(),
3824      JSXElementChild::JSXFragment(node) => node.start(),
3825    }
3826  }
3827  fn end(&self) -> SourcePos {
3828    match self {
3829      JSXElementChild::JSXText(node) => node.end(),
3830      JSXElementChild::JSXExprContainer(node) => node.end(),
3831      JSXElementChild::JSXSpreadChild(node) => node.end(),
3832      JSXElementChild::JSXElement(node) => node.end(),
3833      JSXElementChild::JSXFragment(node) => node.end(),
3834    }
3835  }
3836}
3837
3838impl<'a> NodeTrait<'a> for JSXElementChild<'a> {
3839  fn parent(&self) -> Option<Node<'a>> {
3840    match self {
3841      JSXElementChild::JSXText(node) => NodeTrait::parent(*node),
3842      JSXElementChild::JSXExprContainer(node) => NodeTrait::parent(*node),
3843      JSXElementChild::JSXSpreadChild(node) => NodeTrait::parent(*node),
3844      JSXElementChild::JSXElement(node) => NodeTrait::parent(*node),
3845      JSXElementChild::JSXFragment(node) => NodeTrait::parent(*node),
3846    }
3847  }
3848
3849  fn children(&self) -> Vec<Node<'a>> {
3850    match self {
3851      JSXElementChild::JSXText(node) => node.children(),
3852      JSXElementChild::JSXExprContainer(node) => node.children(),
3853      JSXElementChild::JSXSpreadChild(node) => node.children(),
3854      JSXElementChild::JSXElement(node) => node.children(),
3855      JSXElementChild::JSXFragment(node) => node.children(),
3856    }
3857  }
3858
3859  fn as_node(&self) -> Node<'a> {
3860    match self {
3861      JSXElementChild::JSXText(node) => node.as_node(),
3862      JSXElementChild::JSXExprContainer(node) => node.as_node(),
3863      JSXElementChild::JSXSpreadChild(node) => node.as_node(),
3864      JSXElementChild::JSXElement(node) => node.as_node(),
3865      JSXElementChild::JSXFragment(node) => node.as_node(),
3866    }
3867  }
3868
3869  fn kind(&self) -> NodeKind {
3870    match self {
3871      JSXElementChild::JSXText(_) => NodeKind::JSXText,
3872      JSXElementChild::JSXExprContainer(_) => NodeKind::JSXExprContainer,
3873      JSXElementChild::JSXSpreadChild(_) => NodeKind::JSXSpreadChild,
3874      JSXElementChild::JSXElement(_) => NodeKind::JSXElement,
3875      JSXElementChild::JSXFragment(_) => NodeKind::JSXFragment,
3876    }
3877  }
3878}
3879
3880impl<'a> From<&JSXElementChild<'a>> for Node<'a> {
3881  fn from(node: &JSXElementChild<'a>) -> Node<'a> {
3882    match node {
3883      JSXElementChild::JSXText(node) => (*node).into(),
3884      JSXElementChild::JSXExprContainer(node) => (*node).into(),
3885      JSXElementChild::JSXSpreadChild(node) => (*node).into(),
3886      JSXElementChild::JSXElement(node) => (*node).into(),
3887      JSXElementChild::JSXFragment(node) => (*node).into(),
3888    }
3889  }
3890}
3891
3892impl<'a> From<JSXElementChild<'a>> for Node<'a> {
3893  fn from(node: JSXElementChild<'a>) -> Node<'a> {
3894    match node {
3895      JSXElementChild::JSXText(node) => node.into(),
3896      JSXElementChild::JSXExprContainer(node) => node.into(),
3897      JSXElementChild::JSXSpreadChild(node) => node.into(),
3898      JSXElementChild::JSXElement(node) => node.into(),
3899      JSXElementChild::JSXFragment(node) => node.into(),
3900    }
3901  }
3902}
3903
3904fn get_view_for_jsxelement_child<'a>(inner: &'a swc_ast::JSXElementChild, bump: &'a Bump) -> JSXElementChild<'a> {
3905  match inner {
3906    swc_ast::JSXElementChild::JSXText(value) => JSXElementChild::JSXText(get_view_for_jsxtext(value, bump)),
3907    swc_ast::JSXElementChild::JSXExprContainer(value) => JSXElementChild::JSXExprContainer(get_view_for_jsxexpr_container(value, bump)),
3908    swc_ast::JSXElementChild::JSXSpreadChild(value) => JSXElementChild::JSXSpreadChild(get_view_for_jsxspread_child(value, bump)),
3909    swc_ast::JSXElementChild::JSXElement(value) => JSXElementChild::JSXElement(get_view_for_jsxelement(value, bump)),
3910    swc_ast::JSXElementChild::JSXFragment(value) => JSXElementChild::JSXFragment(get_view_for_jsxfragment(value, bump)),
3911  }
3912}
3913
3914fn set_parent_for_jsxelement_child<'a>(node: &JSXElementChild<'a>, parent: Node<'a>) {
3915  match node {
3916    JSXElementChild::JSXText(value) => set_parent_for_jsxtext(value, parent),
3917    JSXElementChild::JSXExprContainer(value) => set_parent_for_jsxexpr_container(value, parent),
3918    JSXElementChild::JSXSpreadChild(value) => set_parent_for_jsxspread_child(value, parent),
3919    JSXElementChild::JSXElement(value) => set_parent_for_jsxelement(value, parent),
3920    JSXElementChild::JSXFragment(value) => set_parent_for_jsxfragment(value, parent),
3921  }
3922}
3923
3924#[derive(Copy, Clone)]
3925pub enum JSXElementName<'a> {
3926  Ident(&'a Ident<'a>),
3927  JSXMemberExpr(&'a JSXMemberExpr<'a>),
3928  JSXNamespacedName(&'a JSXNamespacedName<'a>),
3929}
3930
3931impl<'a> JSXElementName<'a> {
3932  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
3933    T::to(&self.into())
3934  }
3935
3936  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
3937    let node: Node<'a> = self.into();
3938    if let Some(result) = T::to(&node) {
3939      result
3940    } else {
3941      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
3942    }
3943  }
3944
3945  pub fn is<T: CastableNode<'a>>(&self) -> bool {
3946    self.kind() == T::kind()
3947  }
3948  pub fn parent(&self) -> Node<'a> {
3949    NodeTrait::parent(self).unwrap()
3950  }
3951}
3952
3953impl<'a> SourceRanged for JSXElementName<'a> {
3954  fn start(&self) -> SourcePos {
3955    match self {
3956      JSXElementName::Ident(node) => node.start(),
3957      JSXElementName::JSXMemberExpr(node) => node.start(),
3958      JSXElementName::JSXNamespacedName(node) => node.start(),
3959    }
3960  }
3961  fn end(&self) -> SourcePos {
3962    match self {
3963      JSXElementName::Ident(node) => node.end(),
3964      JSXElementName::JSXMemberExpr(node) => node.end(),
3965      JSXElementName::JSXNamespacedName(node) => node.end(),
3966    }
3967  }
3968}
3969
3970impl<'a> NodeTrait<'a> for JSXElementName<'a> {
3971  fn parent(&self) -> Option<Node<'a>> {
3972    match self {
3973      JSXElementName::Ident(node) => NodeTrait::parent(*node),
3974      JSXElementName::JSXMemberExpr(node) => NodeTrait::parent(*node),
3975      JSXElementName::JSXNamespacedName(node) => NodeTrait::parent(*node),
3976    }
3977  }
3978
3979  fn children(&self) -> Vec<Node<'a>> {
3980    match self {
3981      JSXElementName::Ident(node) => node.children(),
3982      JSXElementName::JSXMemberExpr(node) => node.children(),
3983      JSXElementName::JSXNamespacedName(node) => node.children(),
3984    }
3985  }
3986
3987  fn as_node(&self) -> Node<'a> {
3988    match self {
3989      JSXElementName::Ident(node) => node.as_node(),
3990      JSXElementName::JSXMemberExpr(node) => node.as_node(),
3991      JSXElementName::JSXNamespacedName(node) => node.as_node(),
3992    }
3993  }
3994
3995  fn kind(&self) -> NodeKind {
3996    match self {
3997      JSXElementName::Ident(_) => NodeKind::Ident,
3998      JSXElementName::JSXMemberExpr(_) => NodeKind::JSXMemberExpr,
3999      JSXElementName::JSXNamespacedName(_) => NodeKind::JSXNamespacedName,
4000    }
4001  }
4002}
4003
4004impl<'a> From<&JSXElementName<'a>> for Node<'a> {
4005  fn from(node: &JSXElementName<'a>) -> Node<'a> {
4006    match node {
4007      JSXElementName::Ident(node) => (*node).into(),
4008      JSXElementName::JSXMemberExpr(node) => (*node).into(),
4009      JSXElementName::JSXNamespacedName(node) => (*node).into(),
4010    }
4011  }
4012}
4013
4014impl<'a> From<JSXElementName<'a>> for Node<'a> {
4015  fn from(node: JSXElementName<'a>) -> Node<'a> {
4016    match node {
4017      JSXElementName::Ident(node) => node.into(),
4018      JSXElementName::JSXMemberExpr(node) => node.into(),
4019      JSXElementName::JSXNamespacedName(node) => node.into(),
4020    }
4021  }
4022}
4023
4024fn get_view_for_jsxelement_name<'a>(inner: &'a swc_ast::JSXElementName, bump: &'a Bump) -> JSXElementName<'a> {
4025  match inner {
4026    swc_ast::JSXElementName::Ident(value) => JSXElementName::Ident(get_view_for_ident(value, bump)),
4027    swc_ast::JSXElementName::JSXMemberExpr(value) => JSXElementName::JSXMemberExpr(get_view_for_jsxmember_expr(value, bump)),
4028    swc_ast::JSXElementName::JSXNamespacedName(value) => JSXElementName::JSXNamespacedName(get_view_for_jsxnamespaced_name(value, bump)),
4029  }
4030}
4031
4032fn set_parent_for_jsxelement_name<'a>(node: &JSXElementName<'a>, parent: Node<'a>) {
4033  match node {
4034    JSXElementName::Ident(value) => set_parent_for_ident(value, parent),
4035    JSXElementName::JSXMemberExpr(value) => set_parent_for_jsxmember_expr(value, parent),
4036    JSXElementName::JSXNamespacedName(value) => set_parent_for_jsxnamespaced_name(value, parent),
4037  }
4038}
4039
4040#[derive(Copy, Clone)]
4041pub enum JSXExpr<'a> {
4042  JSXEmptyExpr(&'a JSXEmptyExpr<'a>),
4043  Expr(Expr<'a>),
4044}
4045
4046impl<'a> JSXExpr<'a> {
4047  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4048    T::to(&self.into())
4049  }
4050
4051  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4052    let node: Node<'a> = self.into();
4053    if let Some(result) = T::to(&node) {
4054      result
4055    } else {
4056      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4057    }
4058  }
4059
4060  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4061    self.kind() == T::kind()
4062  }
4063}
4064
4065impl<'a> SourceRanged for JSXExpr<'a> {
4066  fn start(&self) -> SourcePos {
4067    match self {
4068      JSXExpr::JSXEmptyExpr(node) => node.start(),
4069      JSXExpr::Expr(node) => node.start(),
4070    }
4071  }
4072  fn end(&self) -> SourcePos {
4073    match self {
4074      JSXExpr::JSXEmptyExpr(node) => node.end(),
4075      JSXExpr::Expr(node) => node.end(),
4076    }
4077  }
4078}
4079
4080impl<'a> NodeTrait<'a> for JSXExpr<'a> {
4081  fn parent(&self) -> Option<Node<'a>> {
4082    match self {
4083      JSXExpr::JSXEmptyExpr(node) => NodeTrait::parent(*node),
4084      JSXExpr::Expr(node) => NodeTrait::parent(node),
4085    }
4086  }
4087
4088  fn children(&self) -> Vec<Node<'a>> {
4089    match self {
4090      JSXExpr::JSXEmptyExpr(node) => node.children(),
4091      JSXExpr::Expr(node) => node.children(),
4092    }
4093  }
4094
4095  fn as_node(&self) -> Node<'a> {
4096    match self {
4097      JSXExpr::JSXEmptyExpr(node) => node.as_node(),
4098      JSXExpr::Expr(node) => node.as_node(),
4099    }
4100  }
4101
4102  fn kind(&self) -> NodeKind {
4103    match self {
4104      JSXExpr::JSXEmptyExpr(_) => NodeKind::JSXEmptyExpr,
4105      JSXExpr::Expr(node) => node.kind(),
4106    }
4107  }
4108}
4109
4110impl<'a> From<&JSXExpr<'a>> for Node<'a> {
4111  fn from(node: &JSXExpr<'a>) -> Node<'a> {
4112    match node {
4113      JSXExpr::JSXEmptyExpr(node) => (*node).into(),
4114      JSXExpr::Expr(node) => node.into(),
4115    }
4116  }
4117}
4118
4119impl<'a> From<JSXExpr<'a>> for Node<'a> {
4120  fn from(node: JSXExpr<'a>) -> Node<'a> {
4121    match node {
4122      JSXExpr::JSXEmptyExpr(node) => node.into(),
4123      JSXExpr::Expr(node) => node.into(),
4124    }
4125  }
4126}
4127
4128fn get_view_for_jsxexpr<'a>(inner: &'a swc_ast::JSXExpr, bump: &'a Bump) -> JSXExpr<'a> {
4129  match inner {
4130    swc_ast::JSXExpr::JSXEmptyExpr(value) => JSXExpr::JSXEmptyExpr(get_view_for_jsxempty_expr(value, bump)),
4131    swc_ast::JSXExpr::Expr(value) => JSXExpr::Expr(get_view_for_expr(value, bump)),
4132  }
4133}
4134
4135fn set_parent_for_jsxexpr<'a>(node: &JSXExpr<'a>, parent: Node<'a>) {
4136  match node {
4137    JSXExpr::JSXEmptyExpr(value) => set_parent_for_jsxempty_expr(value, parent),
4138    JSXExpr::Expr(value) => set_parent_for_expr(value, parent),
4139  }
4140}
4141
4142/// Used for `obj` property of `JSXMemberExpr`.
4143#[derive(Copy, Clone)]
4144pub enum JSXObject<'a> {
4145  JSXMemberExpr(&'a JSXMemberExpr<'a>),
4146  Ident(&'a Ident<'a>),
4147}
4148
4149impl<'a> JSXObject<'a> {
4150  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4151    T::to(&self.into())
4152  }
4153
4154  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4155    let node: Node<'a> = self.into();
4156    if let Some(result) = T::to(&node) {
4157      result
4158    } else {
4159      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4160    }
4161  }
4162
4163  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4164    self.kind() == T::kind()
4165  }
4166  pub fn parent(&self) -> Node<'a> {
4167    NodeTrait::parent(self).unwrap()
4168  }
4169}
4170
4171impl<'a> SourceRanged for JSXObject<'a> {
4172  fn start(&self) -> SourcePos {
4173    match self {
4174      JSXObject::JSXMemberExpr(node) => node.start(),
4175      JSXObject::Ident(node) => node.start(),
4176    }
4177  }
4178  fn end(&self) -> SourcePos {
4179    match self {
4180      JSXObject::JSXMemberExpr(node) => node.end(),
4181      JSXObject::Ident(node) => node.end(),
4182    }
4183  }
4184}
4185
4186impl<'a> NodeTrait<'a> for JSXObject<'a> {
4187  fn parent(&self) -> Option<Node<'a>> {
4188    match self {
4189      JSXObject::JSXMemberExpr(node) => NodeTrait::parent(*node),
4190      JSXObject::Ident(node) => NodeTrait::parent(*node),
4191    }
4192  }
4193
4194  fn children(&self) -> Vec<Node<'a>> {
4195    match self {
4196      JSXObject::JSXMemberExpr(node) => node.children(),
4197      JSXObject::Ident(node) => node.children(),
4198    }
4199  }
4200
4201  fn as_node(&self) -> Node<'a> {
4202    match self {
4203      JSXObject::JSXMemberExpr(node) => node.as_node(),
4204      JSXObject::Ident(node) => node.as_node(),
4205    }
4206  }
4207
4208  fn kind(&self) -> NodeKind {
4209    match self {
4210      JSXObject::JSXMemberExpr(_) => NodeKind::JSXMemberExpr,
4211      JSXObject::Ident(_) => NodeKind::Ident,
4212    }
4213  }
4214}
4215
4216impl<'a> From<&JSXObject<'a>> for Node<'a> {
4217  fn from(node: &JSXObject<'a>) -> Node<'a> {
4218    match node {
4219      JSXObject::JSXMemberExpr(node) => (*node).into(),
4220      JSXObject::Ident(node) => (*node).into(),
4221    }
4222  }
4223}
4224
4225impl<'a> From<JSXObject<'a>> for Node<'a> {
4226  fn from(node: JSXObject<'a>) -> Node<'a> {
4227    match node {
4228      JSXObject::JSXMemberExpr(node) => node.into(),
4229      JSXObject::Ident(node) => node.into(),
4230    }
4231  }
4232}
4233
4234fn get_view_for_jsxobject<'a>(inner: &'a swc_ast::JSXObject, bump: &'a Bump) -> JSXObject<'a> {
4235  match inner {
4236    swc_ast::JSXObject::JSXMemberExpr(value) => JSXObject::JSXMemberExpr(get_view_for_jsxmember_expr(value, bump)),
4237    swc_ast::JSXObject::Ident(value) => JSXObject::Ident(get_view_for_ident(value, bump)),
4238  }
4239}
4240
4241fn set_parent_for_jsxobject<'a>(node: &JSXObject<'a>, parent: Node<'a>) {
4242  match node {
4243    JSXObject::JSXMemberExpr(value) => set_parent_for_jsxmember_expr(value, parent),
4244    JSXObject::Ident(value) => set_parent_for_ident(value, parent),
4245  }
4246}
4247
4248/// Either a private name or a public name.
4249#[derive(Copy, Clone)]
4250pub enum Key<'a> {
4251  Private(&'a PrivateName<'a>),
4252  Public(PropName<'a>),
4253}
4254
4255impl<'a> Key<'a> {
4256  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4257    T::to(&self.into())
4258  }
4259
4260  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4261    let node: Node<'a> = self.into();
4262    if let Some(result) = T::to(&node) {
4263      result
4264    } else {
4265      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4266    }
4267  }
4268
4269  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4270    self.kind() == T::kind()
4271  }
4272}
4273
4274impl<'a> SourceRanged for Key<'a> {
4275  fn start(&self) -> SourcePos {
4276    match self {
4277      Key::Private(node) => node.start(),
4278      Key::Public(node) => node.start(),
4279    }
4280  }
4281  fn end(&self) -> SourcePos {
4282    match self {
4283      Key::Private(node) => node.end(),
4284      Key::Public(node) => node.end(),
4285    }
4286  }
4287}
4288
4289impl<'a> NodeTrait<'a> for Key<'a> {
4290  fn parent(&self) -> Option<Node<'a>> {
4291    match self {
4292      Key::Private(node) => NodeTrait::parent(*node),
4293      Key::Public(node) => NodeTrait::parent(node),
4294    }
4295  }
4296
4297  fn children(&self) -> Vec<Node<'a>> {
4298    match self {
4299      Key::Private(node) => node.children(),
4300      Key::Public(node) => node.children(),
4301    }
4302  }
4303
4304  fn as_node(&self) -> Node<'a> {
4305    match self {
4306      Key::Private(node) => node.as_node(),
4307      Key::Public(node) => node.as_node(),
4308    }
4309  }
4310
4311  fn kind(&self) -> NodeKind {
4312    match self {
4313      Key::Private(_) => NodeKind::PrivateName,
4314      Key::Public(node) => node.kind(),
4315    }
4316  }
4317}
4318
4319impl<'a> From<&Key<'a>> for Node<'a> {
4320  fn from(node: &Key<'a>) -> Node<'a> {
4321    match node {
4322      Key::Private(node) => (*node).into(),
4323      Key::Public(node) => node.into(),
4324    }
4325  }
4326}
4327
4328impl<'a> From<Key<'a>> for Node<'a> {
4329  fn from(node: Key<'a>) -> Node<'a> {
4330    match node {
4331      Key::Private(node) => node.into(),
4332      Key::Public(node) => node.into(),
4333    }
4334  }
4335}
4336
4337fn get_view_for_key<'a>(inner: &'a swc_ast::Key, bump: &'a Bump) -> Key<'a> {
4338  match inner {
4339    swc_ast::Key::Private(value) => Key::Private(get_view_for_private_name(value, bump)),
4340    swc_ast::Key::Public(value) => Key::Public(get_view_for_prop_name(value, bump)),
4341  }
4342}
4343
4344fn set_parent_for_key<'a>(node: &Key<'a>, parent: Node<'a>) {
4345  match node {
4346    Key::Private(value) => set_parent_for_private_name(value, parent),
4347    Key::Public(value) => set_parent_for_prop_name(value, parent),
4348  }
4349}
4350
4351#[derive(Copy, Clone)]
4352pub enum Lit<'a> {
4353  Str(&'a Str<'a>),
4354  Bool(&'a Bool<'a>),
4355  Null(&'a Null<'a>),
4356  Num(&'a Number<'a>),
4357  BigInt(&'a BigInt<'a>),
4358  Regex(&'a Regex<'a>),
4359  JSXText(&'a JSXText<'a>),
4360}
4361
4362impl<'a> Lit<'a> {
4363  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4364    T::to(&self.into())
4365  }
4366
4367  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4368    let node: Node<'a> = self.into();
4369    if let Some(result) = T::to(&node) {
4370      result
4371    } else {
4372      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4373    }
4374  }
4375
4376  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4377    self.kind() == T::kind()
4378  }
4379  pub fn parent(&self) -> Node<'a> {
4380    NodeTrait::parent(self).unwrap()
4381  }
4382}
4383
4384impl<'a> SourceRanged for Lit<'a> {
4385  fn start(&self) -> SourcePos {
4386    match self {
4387      Lit::Str(node) => node.start(),
4388      Lit::Bool(node) => node.start(),
4389      Lit::Null(node) => node.start(),
4390      Lit::Num(node) => node.start(),
4391      Lit::BigInt(node) => node.start(),
4392      Lit::Regex(node) => node.start(),
4393      Lit::JSXText(node) => node.start(),
4394    }
4395  }
4396  fn end(&self) -> SourcePos {
4397    match self {
4398      Lit::Str(node) => node.end(),
4399      Lit::Bool(node) => node.end(),
4400      Lit::Null(node) => node.end(),
4401      Lit::Num(node) => node.end(),
4402      Lit::BigInt(node) => node.end(),
4403      Lit::Regex(node) => node.end(),
4404      Lit::JSXText(node) => node.end(),
4405    }
4406  }
4407}
4408
4409impl<'a> NodeTrait<'a> for Lit<'a> {
4410  fn parent(&self) -> Option<Node<'a>> {
4411    match self {
4412      Lit::Str(node) => NodeTrait::parent(*node),
4413      Lit::Bool(node) => NodeTrait::parent(*node),
4414      Lit::Null(node) => NodeTrait::parent(*node),
4415      Lit::Num(node) => NodeTrait::parent(*node),
4416      Lit::BigInt(node) => NodeTrait::parent(*node),
4417      Lit::Regex(node) => NodeTrait::parent(*node),
4418      Lit::JSXText(node) => NodeTrait::parent(*node),
4419    }
4420  }
4421
4422  fn children(&self) -> Vec<Node<'a>> {
4423    match self {
4424      Lit::Str(node) => node.children(),
4425      Lit::Bool(node) => node.children(),
4426      Lit::Null(node) => node.children(),
4427      Lit::Num(node) => node.children(),
4428      Lit::BigInt(node) => node.children(),
4429      Lit::Regex(node) => node.children(),
4430      Lit::JSXText(node) => node.children(),
4431    }
4432  }
4433
4434  fn as_node(&self) -> Node<'a> {
4435    match self {
4436      Lit::Str(node) => node.as_node(),
4437      Lit::Bool(node) => node.as_node(),
4438      Lit::Null(node) => node.as_node(),
4439      Lit::Num(node) => node.as_node(),
4440      Lit::BigInt(node) => node.as_node(),
4441      Lit::Regex(node) => node.as_node(),
4442      Lit::JSXText(node) => node.as_node(),
4443    }
4444  }
4445
4446  fn kind(&self) -> NodeKind {
4447    match self {
4448      Lit::Str(_) => NodeKind::Str,
4449      Lit::Bool(_) => NodeKind::Bool,
4450      Lit::Null(_) => NodeKind::Null,
4451      Lit::Num(_) => NodeKind::Number,
4452      Lit::BigInt(_) => NodeKind::BigInt,
4453      Lit::Regex(_) => NodeKind::Regex,
4454      Lit::JSXText(_) => NodeKind::JSXText,
4455    }
4456  }
4457}
4458
4459impl<'a> From<&Lit<'a>> for Node<'a> {
4460  fn from(node: &Lit<'a>) -> Node<'a> {
4461    match node {
4462      Lit::Str(node) => (*node).into(),
4463      Lit::Bool(node) => (*node).into(),
4464      Lit::Null(node) => (*node).into(),
4465      Lit::Num(node) => (*node).into(),
4466      Lit::BigInt(node) => (*node).into(),
4467      Lit::Regex(node) => (*node).into(),
4468      Lit::JSXText(node) => (*node).into(),
4469    }
4470  }
4471}
4472
4473impl<'a> From<Lit<'a>> for Node<'a> {
4474  fn from(node: Lit<'a>) -> Node<'a> {
4475    match node {
4476      Lit::Str(node) => node.into(),
4477      Lit::Bool(node) => node.into(),
4478      Lit::Null(node) => node.into(),
4479      Lit::Num(node) => node.into(),
4480      Lit::BigInt(node) => node.into(),
4481      Lit::Regex(node) => node.into(),
4482      Lit::JSXText(node) => node.into(),
4483    }
4484  }
4485}
4486
4487fn get_view_for_lit<'a>(inner: &'a swc_ast::Lit, bump: &'a Bump) -> Lit<'a> {
4488  match inner {
4489    swc_ast::Lit::Str(value) => Lit::Str(get_view_for_str(value, bump)),
4490    swc_ast::Lit::Bool(value) => Lit::Bool(get_view_for_bool(value, bump)),
4491    swc_ast::Lit::Null(value) => Lit::Null(get_view_for_null(value, bump)),
4492    swc_ast::Lit::Num(value) => Lit::Num(get_view_for_number(value, bump)),
4493    swc_ast::Lit::BigInt(value) => Lit::BigInt(get_view_for_big_int(value, bump)),
4494    swc_ast::Lit::Regex(value) => Lit::Regex(get_view_for_regex(value, bump)),
4495    swc_ast::Lit::JSXText(value) => Lit::JSXText(get_view_for_jsxtext(value, bump)),
4496  }
4497}
4498
4499fn set_parent_for_lit<'a>(node: &Lit<'a>, parent: Node<'a>) {
4500  match node {
4501    Lit::Str(value) => set_parent_for_str(value, parent),
4502    Lit::Bool(value) => set_parent_for_bool(value, parent),
4503    Lit::Null(value) => set_parent_for_null(value, parent),
4504    Lit::Num(value) => set_parent_for_number(value, parent),
4505    Lit::BigInt(value) => set_parent_for_big_int(value, parent),
4506    Lit::Regex(value) => set_parent_for_regex(value, parent),
4507    Lit::JSXText(value) => set_parent_for_jsxtext(value, parent),
4508  }
4509}
4510
4511#[derive(Copy, Clone)]
4512pub enum MemberProp<'a> {
4513  Ident(&'a IdentName<'a>),
4514  PrivateName(&'a PrivateName<'a>),
4515  Computed(&'a ComputedPropName<'a>),
4516}
4517
4518impl<'a> MemberProp<'a> {
4519  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4520    T::to(&self.into())
4521  }
4522
4523  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4524    let node: Node<'a> = self.into();
4525    if let Some(result) = T::to(&node) {
4526      result
4527    } else {
4528      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4529    }
4530  }
4531
4532  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4533    self.kind() == T::kind()
4534  }
4535  pub fn parent(&self) -> Node<'a> {
4536    NodeTrait::parent(self).unwrap()
4537  }
4538}
4539
4540impl<'a> SourceRanged for MemberProp<'a> {
4541  fn start(&self) -> SourcePos {
4542    match self {
4543      MemberProp::Ident(node) => node.start(),
4544      MemberProp::PrivateName(node) => node.start(),
4545      MemberProp::Computed(node) => node.start(),
4546    }
4547  }
4548  fn end(&self) -> SourcePos {
4549    match self {
4550      MemberProp::Ident(node) => node.end(),
4551      MemberProp::PrivateName(node) => node.end(),
4552      MemberProp::Computed(node) => node.end(),
4553    }
4554  }
4555}
4556
4557impl<'a> NodeTrait<'a> for MemberProp<'a> {
4558  fn parent(&self) -> Option<Node<'a>> {
4559    match self {
4560      MemberProp::Ident(node) => NodeTrait::parent(*node),
4561      MemberProp::PrivateName(node) => NodeTrait::parent(*node),
4562      MemberProp::Computed(node) => NodeTrait::parent(*node),
4563    }
4564  }
4565
4566  fn children(&self) -> Vec<Node<'a>> {
4567    match self {
4568      MemberProp::Ident(node) => node.children(),
4569      MemberProp::PrivateName(node) => node.children(),
4570      MemberProp::Computed(node) => node.children(),
4571    }
4572  }
4573
4574  fn as_node(&self) -> Node<'a> {
4575    match self {
4576      MemberProp::Ident(node) => node.as_node(),
4577      MemberProp::PrivateName(node) => node.as_node(),
4578      MemberProp::Computed(node) => node.as_node(),
4579    }
4580  }
4581
4582  fn kind(&self) -> NodeKind {
4583    match self {
4584      MemberProp::Ident(_) => NodeKind::IdentName,
4585      MemberProp::PrivateName(_) => NodeKind::PrivateName,
4586      MemberProp::Computed(_) => NodeKind::ComputedPropName,
4587    }
4588  }
4589}
4590
4591impl<'a> From<&MemberProp<'a>> for Node<'a> {
4592  fn from(node: &MemberProp<'a>) -> Node<'a> {
4593    match node {
4594      MemberProp::Ident(node) => (*node).into(),
4595      MemberProp::PrivateName(node) => (*node).into(),
4596      MemberProp::Computed(node) => (*node).into(),
4597    }
4598  }
4599}
4600
4601impl<'a> From<MemberProp<'a>> for Node<'a> {
4602  fn from(node: MemberProp<'a>) -> Node<'a> {
4603    match node {
4604      MemberProp::Ident(node) => node.into(),
4605      MemberProp::PrivateName(node) => node.into(),
4606      MemberProp::Computed(node) => node.into(),
4607    }
4608  }
4609}
4610
4611fn get_view_for_member_prop<'a>(inner: &'a swc_ast::MemberProp, bump: &'a Bump) -> MemberProp<'a> {
4612  match inner {
4613    swc_ast::MemberProp::Ident(value) => MemberProp::Ident(get_view_for_ident_name(value, bump)),
4614    swc_ast::MemberProp::PrivateName(value) => MemberProp::PrivateName(get_view_for_private_name(value, bump)),
4615    swc_ast::MemberProp::Computed(value) => MemberProp::Computed(get_view_for_computed_prop_name(value, bump)),
4616  }
4617}
4618
4619fn set_parent_for_member_prop<'a>(node: &MemberProp<'a>, parent: Node<'a>) {
4620  match node {
4621    MemberProp::Ident(value) => set_parent_for_ident_name(value, parent),
4622    MemberProp::PrivateName(value) => set_parent_for_private_name(value, parent),
4623    MemberProp::Computed(value) => set_parent_for_computed_prop_name(value, parent),
4624  }
4625}
4626
4627#[derive(Copy, Clone)]
4628pub enum ModuleDecl<'a> {
4629  Import(&'a ImportDecl<'a>),
4630  ExportDecl(&'a ExportDecl<'a>),
4631  ExportNamed(&'a NamedExport<'a>),
4632  ExportDefaultDecl(&'a ExportDefaultDecl<'a>),
4633  ExportDefaultExpr(&'a ExportDefaultExpr<'a>),
4634  ExportAll(&'a ExportAll<'a>),
4635  TsImportEquals(&'a TsImportEqualsDecl<'a>),
4636  TsExportAssignment(&'a TsExportAssignment<'a>),
4637  TsNamespaceExport(&'a TsNamespaceExportDecl<'a>),
4638}
4639
4640impl<'a> ModuleDecl<'a> {
4641  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4642    T::to(&self.into())
4643  }
4644
4645  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4646    let node: Node<'a> = self.into();
4647    if let Some(result) = T::to(&node) {
4648      result
4649    } else {
4650      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4651    }
4652  }
4653
4654  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4655    self.kind() == T::kind()
4656  }
4657  pub fn parent(&self) -> Node<'a> {
4658    NodeTrait::parent(self).unwrap()
4659  }
4660}
4661
4662impl<'a> SourceRanged for ModuleDecl<'a> {
4663  fn start(&self) -> SourcePos {
4664    match self {
4665      ModuleDecl::Import(node) => node.start(),
4666      ModuleDecl::ExportDecl(node) => node.start(),
4667      ModuleDecl::ExportNamed(node) => node.start(),
4668      ModuleDecl::ExportDefaultDecl(node) => node.start(),
4669      ModuleDecl::ExportDefaultExpr(node) => node.start(),
4670      ModuleDecl::ExportAll(node) => node.start(),
4671      ModuleDecl::TsImportEquals(node) => node.start(),
4672      ModuleDecl::TsExportAssignment(node) => node.start(),
4673      ModuleDecl::TsNamespaceExport(node) => node.start(),
4674    }
4675  }
4676  fn end(&self) -> SourcePos {
4677    match self {
4678      ModuleDecl::Import(node) => node.end(),
4679      ModuleDecl::ExportDecl(node) => node.end(),
4680      ModuleDecl::ExportNamed(node) => node.end(),
4681      ModuleDecl::ExportDefaultDecl(node) => node.end(),
4682      ModuleDecl::ExportDefaultExpr(node) => node.end(),
4683      ModuleDecl::ExportAll(node) => node.end(),
4684      ModuleDecl::TsImportEquals(node) => node.end(),
4685      ModuleDecl::TsExportAssignment(node) => node.end(),
4686      ModuleDecl::TsNamespaceExport(node) => node.end(),
4687    }
4688  }
4689}
4690
4691impl<'a> NodeTrait<'a> for ModuleDecl<'a> {
4692  fn parent(&self) -> Option<Node<'a>> {
4693    match self {
4694      ModuleDecl::Import(node) => NodeTrait::parent(*node),
4695      ModuleDecl::ExportDecl(node) => NodeTrait::parent(*node),
4696      ModuleDecl::ExportNamed(node) => NodeTrait::parent(*node),
4697      ModuleDecl::ExportDefaultDecl(node) => NodeTrait::parent(*node),
4698      ModuleDecl::ExportDefaultExpr(node) => NodeTrait::parent(*node),
4699      ModuleDecl::ExportAll(node) => NodeTrait::parent(*node),
4700      ModuleDecl::TsImportEquals(node) => NodeTrait::parent(*node),
4701      ModuleDecl::TsExportAssignment(node) => NodeTrait::parent(*node),
4702      ModuleDecl::TsNamespaceExport(node) => NodeTrait::parent(*node),
4703    }
4704  }
4705
4706  fn children(&self) -> Vec<Node<'a>> {
4707    match self {
4708      ModuleDecl::Import(node) => node.children(),
4709      ModuleDecl::ExportDecl(node) => node.children(),
4710      ModuleDecl::ExportNamed(node) => node.children(),
4711      ModuleDecl::ExportDefaultDecl(node) => node.children(),
4712      ModuleDecl::ExportDefaultExpr(node) => node.children(),
4713      ModuleDecl::ExportAll(node) => node.children(),
4714      ModuleDecl::TsImportEquals(node) => node.children(),
4715      ModuleDecl::TsExportAssignment(node) => node.children(),
4716      ModuleDecl::TsNamespaceExport(node) => node.children(),
4717    }
4718  }
4719
4720  fn as_node(&self) -> Node<'a> {
4721    match self {
4722      ModuleDecl::Import(node) => node.as_node(),
4723      ModuleDecl::ExportDecl(node) => node.as_node(),
4724      ModuleDecl::ExportNamed(node) => node.as_node(),
4725      ModuleDecl::ExportDefaultDecl(node) => node.as_node(),
4726      ModuleDecl::ExportDefaultExpr(node) => node.as_node(),
4727      ModuleDecl::ExportAll(node) => node.as_node(),
4728      ModuleDecl::TsImportEquals(node) => node.as_node(),
4729      ModuleDecl::TsExportAssignment(node) => node.as_node(),
4730      ModuleDecl::TsNamespaceExport(node) => node.as_node(),
4731    }
4732  }
4733
4734  fn kind(&self) -> NodeKind {
4735    match self {
4736      ModuleDecl::Import(_) => NodeKind::ImportDecl,
4737      ModuleDecl::ExportDecl(_) => NodeKind::ExportDecl,
4738      ModuleDecl::ExportNamed(_) => NodeKind::NamedExport,
4739      ModuleDecl::ExportDefaultDecl(_) => NodeKind::ExportDefaultDecl,
4740      ModuleDecl::ExportDefaultExpr(_) => NodeKind::ExportDefaultExpr,
4741      ModuleDecl::ExportAll(_) => NodeKind::ExportAll,
4742      ModuleDecl::TsImportEquals(_) => NodeKind::TsImportEqualsDecl,
4743      ModuleDecl::TsExportAssignment(_) => NodeKind::TsExportAssignment,
4744      ModuleDecl::TsNamespaceExport(_) => NodeKind::TsNamespaceExportDecl,
4745    }
4746  }
4747}
4748
4749impl<'a> From<&ModuleDecl<'a>> for Node<'a> {
4750  fn from(node: &ModuleDecl<'a>) -> Node<'a> {
4751    match node {
4752      ModuleDecl::Import(node) => (*node).into(),
4753      ModuleDecl::ExportDecl(node) => (*node).into(),
4754      ModuleDecl::ExportNamed(node) => (*node).into(),
4755      ModuleDecl::ExportDefaultDecl(node) => (*node).into(),
4756      ModuleDecl::ExportDefaultExpr(node) => (*node).into(),
4757      ModuleDecl::ExportAll(node) => (*node).into(),
4758      ModuleDecl::TsImportEquals(node) => (*node).into(),
4759      ModuleDecl::TsExportAssignment(node) => (*node).into(),
4760      ModuleDecl::TsNamespaceExport(node) => (*node).into(),
4761    }
4762  }
4763}
4764
4765impl<'a> From<ModuleDecl<'a>> for Node<'a> {
4766  fn from(node: ModuleDecl<'a>) -> Node<'a> {
4767    match node {
4768      ModuleDecl::Import(node) => node.into(),
4769      ModuleDecl::ExportDecl(node) => node.into(),
4770      ModuleDecl::ExportNamed(node) => node.into(),
4771      ModuleDecl::ExportDefaultDecl(node) => node.into(),
4772      ModuleDecl::ExportDefaultExpr(node) => node.into(),
4773      ModuleDecl::ExportAll(node) => node.into(),
4774      ModuleDecl::TsImportEquals(node) => node.into(),
4775      ModuleDecl::TsExportAssignment(node) => node.into(),
4776      ModuleDecl::TsNamespaceExport(node) => node.into(),
4777    }
4778  }
4779}
4780
4781fn get_view_for_module_decl<'a>(inner: &'a swc_ast::ModuleDecl, bump: &'a Bump) -> ModuleDecl<'a> {
4782  match inner {
4783    swc_ast::ModuleDecl::Import(value) => ModuleDecl::Import(get_view_for_import_decl(value, bump)),
4784    swc_ast::ModuleDecl::ExportDecl(value) => ModuleDecl::ExportDecl(get_view_for_export_decl(value, bump)),
4785    swc_ast::ModuleDecl::ExportNamed(value) => ModuleDecl::ExportNamed(get_view_for_named_export(value, bump)),
4786    swc_ast::ModuleDecl::ExportDefaultDecl(value) => ModuleDecl::ExportDefaultDecl(get_view_for_export_default_decl(value, bump)),
4787    swc_ast::ModuleDecl::ExportDefaultExpr(value) => ModuleDecl::ExportDefaultExpr(get_view_for_export_default_expr(value, bump)),
4788    swc_ast::ModuleDecl::ExportAll(value) => ModuleDecl::ExportAll(get_view_for_export_all(value, bump)),
4789    swc_ast::ModuleDecl::TsImportEquals(value) => ModuleDecl::TsImportEquals(get_view_for_ts_import_equals_decl(value, bump)),
4790    swc_ast::ModuleDecl::TsExportAssignment(value) => ModuleDecl::TsExportAssignment(get_view_for_ts_export_assignment(value, bump)),
4791    swc_ast::ModuleDecl::TsNamespaceExport(value) => ModuleDecl::TsNamespaceExport(get_view_for_ts_namespace_export_decl(value, bump)),
4792  }
4793}
4794
4795fn set_parent_for_module_decl<'a>(node: &ModuleDecl<'a>, parent: Node<'a>) {
4796  match node {
4797    ModuleDecl::Import(value) => set_parent_for_import_decl(value, parent),
4798    ModuleDecl::ExportDecl(value) => set_parent_for_export_decl(value, parent),
4799    ModuleDecl::ExportNamed(value) => set_parent_for_named_export(value, parent),
4800    ModuleDecl::ExportDefaultDecl(value) => set_parent_for_export_default_decl(value, parent),
4801    ModuleDecl::ExportDefaultExpr(value) => set_parent_for_export_default_expr(value, parent),
4802    ModuleDecl::ExportAll(value) => set_parent_for_export_all(value, parent),
4803    ModuleDecl::TsImportEquals(value) => set_parent_for_ts_import_equals_decl(value, parent),
4804    ModuleDecl::TsExportAssignment(value) => set_parent_for_ts_export_assignment(value, parent),
4805    ModuleDecl::TsNamespaceExport(value) => set_parent_for_ts_namespace_export_decl(value, parent),
4806  }
4807}
4808
4809#[derive(Copy, Clone)]
4810pub enum ModuleExportName<'a> {
4811  Ident(&'a Ident<'a>),
4812  Str(&'a Str<'a>),
4813}
4814
4815impl<'a> ModuleExportName<'a> {
4816  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4817    T::to(&self.into())
4818  }
4819
4820  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4821    let node: Node<'a> = self.into();
4822    if let Some(result) = T::to(&node) {
4823      result
4824    } else {
4825      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4826    }
4827  }
4828
4829  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4830    self.kind() == T::kind()
4831  }
4832  pub fn parent(&self) -> Node<'a> {
4833    NodeTrait::parent(self).unwrap()
4834  }
4835}
4836
4837impl<'a> SourceRanged for ModuleExportName<'a> {
4838  fn start(&self) -> SourcePos {
4839    match self {
4840      ModuleExportName::Ident(node) => node.start(),
4841      ModuleExportName::Str(node) => node.start(),
4842    }
4843  }
4844  fn end(&self) -> SourcePos {
4845    match self {
4846      ModuleExportName::Ident(node) => node.end(),
4847      ModuleExportName::Str(node) => node.end(),
4848    }
4849  }
4850}
4851
4852impl<'a> NodeTrait<'a> for ModuleExportName<'a> {
4853  fn parent(&self) -> Option<Node<'a>> {
4854    match self {
4855      ModuleExportName::Ident(node) => NodeTrait::parent(*node),
4856      ModuleExportName::Str(node) => NodeTrait::parent(*node),
4857    }
4858  }
4859
4860  fn children(&self) -> Vec<Node<'a>> {
4861    match self {
4862      ModuleExportName::Ident(node) => node.children(),
4863      ModuleExportName::Str(node) => node.children(),
4864    }
4865  }
4866
4867  fn as_node(&self) -> Node<'a> {
4868    match self {
4869      ModuleExportName::Ident(node) => node.as_node(),
4870      ModuleExportName::Str(node) => node.as_node(),
4871    }
4872  }
4873
4874  fn kind(&self) -> NodeKind {
4875    match self {
4876      ModuleExportName::Ident(_) => NodeKind::Ident,
4877      ModuleExportName::Str(_) => NodeKind::Str,
4878    }
4879  }
4880}
4881
4882impl<'a> From<&ModuleExportName<'a>> for Node<'a> {
4883  fn from(node: &ModuleExportName<'a>) -> Node<'a> {
4884    match node {
4885      ModuleExportName::Ident(node) => (*node).into(),
4886      ModuleExportName::Str(node) => (*node).into(),
4887    }
4888  }
4889}
4890
4891impl<'a> From<ModuleExportName<'a>> for Node<'a> {
4892  fn from(node: ModuleExportName<'a>) -> Node<'a> {
4893    match node {
4894      ModuleExportName::Ident(node) => node.into(),
4895      ModuleExportName::Str(node) => node.into(),
4896    }
4897  }
4898}
4899
4900fn get_view_for_module_export_name<'a>(inner: &'a swc_ast::ModuleExportName, bump: &'a Bump) -> ModuleExportName<'a> {
4901  match inner {
4902    swc_ast::ModuleExportName::Ident(value) => ModuleExportName::Ident(get_view_for_ident(value, bump)),
4903    swc_ast::ModuleExportName::Str(value) => ModuleExportName::Str(get_view_for_str(value, bump)),
4904  }
4905}
4906
4907fn set_parent_for_module_export_name<'a>(node: &ModuleExportName<'a>, parent: Node<'a>) {
4908  match node {
4909    ModuleExportName::Ident(value) => set_parent_for_ident(value, parent),
4910    ModuleExportName::Str(value) => set_parent_for_str(value, parent),
4911  }
4912}
4913
4914#[derive(Copy, Clone)]
4915pub enum ModuleItem<'a> {
4916  ModuleDecl(ModuleDecl<'a>),
4917  Stmt(Stmt<'a>),
4918}
4919
4920impl<'a> ModuleItem<'a> {
4921  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
4922    T::to(&self.into())
4923  }
4924
4925  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
4926    let node: Node<'a> = self.into();
4927    if let Some(result) = T::to(&node) {
4928      result
4929    } else {
4930      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
4931    }
4932  }
4933
4934  pub fn is<T: CastableNode<'a>>(&self) -> bool {
4935    self.kind() == T::kind()
4936  }
4937}
4938
4939impl<'a> SourceRanged for ModuleItem<'a> {
4940  fn start(&self) -> SourcePos {
4941    match self {
4942      ModuleItem::ModuleDecl(node) => node.start(),
4943      ModuleItem::Stmt(node) => node.start(),
4944    }
4945  }
4946  fn end(&self) -> SourcePos {
4947    match self {
4948      ModuleItem::ModuleDecl(node) => node.end(),
4949      ModuleItem::Stmt(node) => node.end(),
4950    }
4951  }
4952}
4953
4954impl<'a> NodeTrait<'a> for ModuleItem<'a> {
4955  fn parent(&self) -> Option<Node<'a>> {
4956    match self {
4957      ModuleItem::ModuleDecl(node) => NodeTrait::parent(node),
4958      ModuleItem::Stmt(node) => NodeTrait::parent(node),
4959    }
4960  }
4961
4962  fn children(&self) -> Vec<Node<'a>> {
4963    match self {
4964      ModuleItem::ModuleDecl(node) => node.children(),
4965      ModuleItem::Stmt(node) => node.children(),
4966    }
4967  }
4968
4969  fn as_node(&self) -> Node<'a> {
4970    match self {
4971      ModuleItem::ModuleDecl(node) => node.as_node(),
4972      ModuleItem::Stmt(node) => node.as_node(),
4973    }
4974  }
4975
4976  fn kind(&self) -> NodeKind {
4977    match self {
4978      ModuleItem::ModuleDecl(node) => node.kind(),
4979      ModuleItem::Stmt(node) => node.kind(),
4980    }
4981  }
4982}
4983
4984impl<'a> From<&ModuleItem<'a>> for Node<'a> {
4985  fn from(node: &ModuleItem<'a>) -> Node<'a> {
4986    match node {
4987      ModuleItem::ModuleDecl(node) => node.into(),
4988      ModuleItem::Stmt(node) => node.into(),
4989    }
4990  }
4991}
4992
4993impl<'a> From<ModuleItem<'a>> for Node<'a> {
4994  fn from(node: ModuleItem<'a>) -> Node<'a> {
4995    match node {
4996      ModuleItem::ModuleDecl(node) => node.into(),
4997      ModuleItem::Stmt(node) => node.into(),
4998    }
4999  }
5000}
5001
5002fn get_view_for_module_item<'a>(inner: &'a swc_ast::ModuleItem, bump: &'a Bump) -> ModuleItem<'a> {
5003  match inner {
5004    swc_ast::ModuleItem::ModuleDecl(value) => ModuleItem::ModuleDecl(get_view_for_module_decl(value, bump)),
5005    swc_ast::ModuleItem::Stmt(value) => ModuleItem::Stmt(get_view_for_stmt(value, bump)),
5006  }
5007}
5008
5009fn set_parent_for_module_item<'a>(node: &ModuleItem<'a>, parent: Node<'a>) {
5010  match node {
5011    ModuleItem::ModuleDecl(value) => set_parent_for_module_decl(value, parent),
5012    ModuleItem::Stmt(value) => set_parent_for_stmt(value, parent),
5013  }
5014}
5015
5016#[derive(Copy, Clone)]
5017pub enum ObjectPatProp<'a> {
5018  KeyValue(&'a KeyValuePatProp<'a>),
5019  Assign(&'a AssignPatProp<'a>),
5020  Rest(&'a RestPat<'a>),
5021}
5022
5023impl<'a> ObjectPatProp<'a> {
5024  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5025    T::to(&self.into())
5026  }
5027
5028  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5029    let node: Node<'a> = self.into();
5030    if let Some(result) = T::to(&node) {
5031      result
5032    } else {
5033      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5034    }
5035  }
5036
5037  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5038    self.kind() == T::kind()
5039  }
5040  pub fn parent(&self) -> Node<'a> {
5041    NodeTrait::parent(self).unwrap()
5042  }
5043}
5044
5045impl<'a> SourceRanged for ObjectPatProp<'a> {
5046  fn start(&self) -> SourcePos {
5047    match self {
5048      ObjectPatProp::KeyValue(node) => node.start(),
5049      ObjectPatProp::Assign(node) => node.start(),
5050      ObjectPatProp::Rest(node) => node.start(),
5051    }
5052  }
5053  fn end(&self) -> SourcePos {
5054    match self {
5055      ObjectPatProp::KeyValue(node) => node.end(),
5056      ObjectPatProp::Assign(node) => node.end(),
5057      ObjectPatProp::Rest(node) => node.end(),
5058    }
5059  }
5060}
5061
5062impl<'a> NodeTrait<'a> for ObjectPatProp<'a> {
5063  fn parent(&self) -> Option<Node<'a>> {
5064    match self {
5065      ObjectPatProp::KeyValue(node) => NodeTrait::parent(*node),
5066      ObjectPatProp::Assign(node) => NodeTrait::parent(*node),
5067      ObjectPatProp::Rest(node) => NodeTrait::parent(*node),
5068    }
5069  }
5070
5071  fn children(&self) -> Vec<Node<'a>> {
5072    match self {
5073      ObjectPatProp::KeyValue(node) => node.children(),
5074      ObjectPatProp::Assign(node) => node.children(),
5075      ObjectPatProp::Rest(node) => node.children(),
5076    }
5077  }
5078
5079  fn as_node(&self) -> Node<'a> {
5080    match self {
5081      ObjectPatProp::KeyValue(node) => node.as_node(),
5082      ObjectPatProp::Assign(node) => node.as_node(),
5083      ObjectPatProp::Rest(node) => node.as_node(),
5084    }
5085  }
5086
5087  fn kind(&self) -> NodeKind {
5088    match self {
5089      ObjectPatProp::KeyValue(_) => NodeKind::KeyValuePatProp,
5090      ObjectPatProp::Assign(_) => NodeKind::AssignPatProp,
5091      ObjectPatProp::Rest(_) => NodeKind::RestPat,
5092    }
5093  }
5094}
5095
5096impl<'a> From<&ObjectPatProp<'a>> for Node<'a> {
5097  fn from(node: &ObjectPatProp<'a>) -> Node<'a> {
5098    match node {
5099      ObjectPatProp::KeyValue(node) => (*node).into(),
5100      ObjectPatProp::Assign(node) => (*node).into(),
5101      ObjectPatProp::Rest(node) => (*node).into(),
5102    }
5103  }
5104}
5105
5106impl<'a> From<ObjectPatProp<'a>> for Node<'a> {
5107  fn from(node: ObjectPatProp<'a>) -> Node<'a> {
5108    match node {
5109      ObjectPatProp::KeyValue(node) => node.into(),
5110      ObjectPatProp::Assign(node) => node.into(),
5111      ObjectPatProp::Rest(node) => node.into(),
5112    }
5113  }
5114}
5115
5116fn get_view_for_object_pat_prop<'a>(inner: &'a swc_ast::ObjectPatProp, bump: &'a Bump) -> ObjectPatProp<'a> {
5117  match inner {
5118    swc_ast::ObjectPatProp::KeyValue(value) => ObjectPatProp::KeyValue(get_view_for_key_value_pat_prop(value, bump)),
5119    swc_ast::ObjectPatProp::Assign(value) => ObjectPatProp::Assign(get_view_for_assign_pat_prop(value, bump)),
5120    swc_ast::ObjectPatProp::Rest(value) => ObjectPatProp::Rest(get_view_for_rest_pat(value, bump)),
5121  }
5122}
5123
5124fn set_parent_for_object_pat_prop<'a>(node: &ObjectPatProp<'a>, parent: Node<'a>) {
5125  match node {
5126    ObjectPatProp::KeyValue(value) => set_parent_for_key_value_pat_prop(value, parent),
5127    ObjectPatProp::Assign(value) => set_parent_for_assign_pat_prop(value, parent),
5128    ObjectPatProp::Rest(value) => set_parent_for_rest_pat(value, parent),
5129  }
5130}
5131
5132#[derive(Copy, Clone)]
5133pub enum OptChainBase<'a> {
5134  Member(&'a MemberExpr<'a>),
5135  Call(&'a OptCall<'a>),
5136}
5137
5138impl<'a> OptChainBase<'a> {
5139  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5140    T::to(&self.into())
5141  }
5142
5143  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5144    let node: Node<'a> = self.into();
5145    if let Some(result) = T::to(&node) {
5146      result
5147    } else {
5148      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5149    }
5150  }
5151
5152  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5153    self.kind() == T::kind()
5154  }
5155  pub fn parent(&self) -> Node<'a> {
5156    NodeTrait::parent(self).unwrap()
5157  }
5158}
5159
5160impl<'a> SourceRanged for OptChainBase<'a> {
5161  fn start(&self) -> SourcePos {
5162    match self {
5163      OptChainBase::Member(node) => node.start(),
5164      OptChainBase::Call(node) => node.start(),
5165    }
5166  }
5167  fn end(&self) -> SourcePos {
5168    match self {
5169      OptChainBase::Member(node) => node.end(),
5170      OptChainBase::Call(node) => node.end(),
5171    }
5172  }
5173}
5174
5175impl<'a> NodeTrait<'a> for OptChainBase<'a> {
5176  fn parent(&self) -> Option<Node<'a>> {
5177    match self {
5178      OptChainBase::Member(node) => NodeTrait::parent(*node),
5179      OptChainBase::Call(node) => NodeTrait::parent(*node),
5180    }
5181  }
5182
5183  fn children(&self) -> Vec<Node<'a>> {
5184    match self {
5185      OptChainBase::Member(node) => node.children(),
5186      OptChainBase::Call(node) => node.children(),
5187    }
5188  }
5189
5190  fn as_node(&self) -> Node<'a> {
5191    match self {
5192      OptChainBase::Member(node) => node.as_node(),
5193      OptChainBase::Call(node) => node.as_node(),
5194    }
5195  }
5196
5197  fn kind(&self) -> NodeKind {
5198    match self {
5199      OptChainBase::Member(_) => NodeKind::MemberExpr,
5200      OptChainBase::Call(_) => NodeKind::OptCall,
5201    }
5202  }
5203}
5204
5205impl<'a> From<&OptChainBase<'a>> for Node<'a> {
5206  fn from(node: &OptChainBase<'a>) -> Node<'a> {
5207    match node {
5208      OptChainBase::Member(node) => (*node).into(),
5209      OptChainBase::Call(node) => (*node).into(),
5210    }
5211  }
5212}
5213
5214impl<'a> From<OptChainBase<'a>> for Node<'a> {
5215  fn from(node: OptChainBase<'a>) -> Node<'a> {
5216    match node {
5217      OptChainBase::Member(node) => node.into(),
5218      OptChainBase::Call(node) => node.into(),
5219    }
5220  }
5221}
5222
5223fn get_view_for_opt_chain_base<'a>(inner: &'a swc_ast::OptChainBase, bump: &'a Bump) -> OptChainBase<'a> {
5224  match inner {
5225    swc_ast::OptChainBase::Member(value) => OptChainBase::Member(get_view_for_member_expr(value, bump)),
5226    swc_ast::OptChainBase::Call(value) => OptChainBase::Call(get_view_for_opt_call(value, bump)),
5227  }
5228}
5229
5230fn set_parent_for_opt_chain_base<'a>(node: &OptChainBase<'a>, parent: Node<'a>) {
5231  match node {
5232    OptChainBase::Member(value) => set_parent_for_member_expr(value, parent),
5233    OptChainBase::Call(value) => set_parent_for_opt_call(value, parent),
5234  }
5235}
5236
5237#[derive(Copy, Clone)]
5238pub enum ParamOrTsParamProp<'a> {
5239  TsParamProp(&'a TsParamProp<'a>),
5240  Param(&'a Param<'a>),
5241}
5242
5243impl<'a> ParamOrTsParamProp<'a> {
5244  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5245    T::to(&self.into())
5246  }
5247
5248  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5249    let node: Node<'a> = self.into();
5250    if let Some(result) = T::to(&node) {
5251      result
5252    } else {
5253      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5254    }
5255  }
5256
5257  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5258    self.kind() == T::kind()
5259  }
5260  pub fn parent(&self) -> Node<'a> {
5261    NodeTrait::parent(self).unwrap()
5262  }
5263}
5264
5265impl<'a> SourceRanged for ParamOrTsParamProp<'a> {
5266  fn start(&self) -> SourcePos {
5267    match self {
5268      ParamOrTsParamProp::TsParamProp(node) => node.start(),
5269      ParamOrTsParamProp::Param(node) => node.start(),
5270    }
5271  }
5272  fn end(&self) -> SourcePos {
5273    match self {
5274      ParamOrTsParamProp::TsParamProp(node) => node.end(),
5275      ParamOrTsParamProp::Param(node) => node.end(),
5276    }
5277  }
5278}
5279
5280impl<'a> NodeTrait<'a> for ParamOrTsParamProp<'a> {
5281  fn parent(&self) -> Option<Node<'a>> {
5282    match self {
5283      ParamOrTsParamProp::TsParamProp(node) => NodeTrait::parent(*node),
5284      ParamOrTsParamProp::Param(node) => NodeTrait::parent(*node),
5285    }
5286  }
5287
5288  fn children(&self) -> Vec<Node<'a>> {
5289    match self {
5290      ParamOrTsParamProp::TsParamProp(node) => node.children(),
5291      ParamOrTsParamProp::Param(node) => node.children(),
5292    }
5293  }
5294
5295  fn as_node(&self) -> Node<'a> {
5296    match self {
5297      ParamOrTsParamProp::TsParamProp(node) => node.as_node(),
5298      ParamOrTsParamProp::Param(node) => node.as_node(),
5299    }
5300  }
5301
5302  fn kind(&self) -> NodeKind {
5303    match self {
5304      ParamOrTsParamProp::TsParamProp(_) => NodeKind::TsParamProp,
5305      ParamOrTsParamProp::Param(_) => NodeKind::Param,
5306    }
5307  }
5308}
5309
5310impl<'a> From<&ParamOrTsParamProp<'a>> for Node<'a> {
5311  fn from(node: &ParamOrTsParamProp<'a>) -> Node<'a> {
5312    match node {
5313      ParamOrTsParamProp::TsParamProp(node) => (*node).into(),
5314      ParamOrTsParamProp::Param(node) => (*node).into(),
5315    }
5316  }
5317}
5318
5319impl<'a> From<ParamOrTsParamProp<'a>> for Node<'a> {
5320  fn from(node: ParamOrTsParamProp<'a>) -> Node<'a> {
5321    match node {
5322      ParamOrTsParamProp::TsParamProp(node) => node.into(),
5323      ParamOrTsParamProp::Param(node) => node.into(),
5324    }
5325  }
5326}
5327
5328fn get_view_for_param_or_ts_param_prop<'a>(inner: &'a swc_ast::ParamOrTsParamProp, bump: &'a Bump) -> ParamOrTsParamProp<'a> {
5329  match inner {
5330    swc_ast::ParamOrTsParamProp::TsParamProp(value) => ParamOrTsParamProp::TsParamProp(get_view_for_ts_param_prop(value, bump)),
5331    swc_ast::ParamOrTsParamProp::Param(value) => ParamOrTsParamProp::Param(get_view_for_param(value, bump)),
5332  }
5333}
5334
5335fn set_parent_for_param_or_ts_param_prop<'a>(node: &ParamOrTsParamProp<'a>, parent: Node<'a>) {
5336  match node {
5337    ParamOrTsParamProp::TsParamProp(value) => set_parent_for_ts_param_prop(value, parent),
5338    ParamOrTsParamProp::Param(value) => set_parent_for_param(value, parent),
5339  }
5340}
5341
5342#[derive(Copy, Clone)]
5343pub enum Pat<'a> {
5344  Ident(&'a BindingIdent<'a>),
5345  Array(&'a ArrayPat<'a>),
5346  Rest(&'a RestPat<'a>),
5347  Object(&'a ObjectPat<'a>),
5348  Assign(&'a AssignPat<'a>),
5349  Invalid(&'a Invalid<'a>),
5350  /// Only for for-in / for-of loops. This is *syntactically* valid.
5351  Expr(Expr<'a>),
5352}
5353
5354impl<'a> Pat<'a> {
5355  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5356    T::to(&self.into())
5357  }
5358
5359  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5360    let node: Node<'a> = self.into();
5361    if let Some(result) = T::to(&node) {
5362      result
5363    } else {
5364      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5365    }
5366  }
5367
5368  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5369    self.kind() == T::kind()
5370  }
5371}
5372
5373impl<'a> SourceRanged for Pat<'a> {
5374  fn start(&self) -> SourcePos {
5375    match self {
5376      Pat::Ident(node) => node.start(),
5377      Pat::Array(node) => node.start(),
5378      Pat::Rest(node) => node.start(),
5379      Pat::Object(node) => node.start(),
5380      Pat::Assign(node) => node.start(),
5381      Pat::Invalid(node) => node.start(),
5382      Pat::Expr(node) => node.start(),
5383    }
5384  }
5385  fn end(&self) -> SourcePos {
5386    match self {
5387      Pat::Ident(node) => node.end(),
5388      Pat::Array(node) => node.end(),
5389      Pat::Rest(node) => node.end(),
5390      Pat::Object(node) => node.end(),
5391      Pat::Assign(node) => node.end(),
5392      Pat::Invalid(node) => node.end(),
5393      Pat::Expr(node) => node.end(),
5394    }
5395  }
5396}
5397
5398impl<'a> NodeTrait<'a> for Pat<'a> {
5399  fn parent(&self) -> Option<Node<'a>> {
5400    match self {
5401      Pat::Ident(node) => NodeTrait::parent(*node),
5402      Pat::Array(node) => NodeTrait::parent(*node),
5403      Pat::Rest(node) => NodeTrait::parent(*node),
5404      Pat::Object(node) => NodeTrait::parent(*node),
5405      Pat::Assign(node) => NodeTrait::parent(*node),
5406      Pat::Invalid(node) => NodeTrait::parent(*node),
5407      Pat::Expr(node) => NodeTrait::parent(node),
5408    }
5409  }
5410
5411  fn children(&self) -> Vec<Node<'a>> {
5412    match self {
5413      Pat::Ident(node) => node.children(),
5414      Pat::Array(node) => node.children(),
5415      Pat::Rest(node) => node.children(),
5416      Pat::Object(node) => node.children(),
5417      Pat::Assign(node) => node.children(),
5418      Pat::Invalid(node) => node.children(),
5419      Pat::Expr(node) => node.children(),
5420    }
5421  }
5422
5423  fn as_node(&self) -> Node<'a> {
5424    match self {
5425      Pat::Ident(node) => node.as_node(),
5426      Pat::Array(node) => node.as_node(),
5427      Pat::Rest(node) => node.as_node(),
5428      Pat::Object(node) => node.as_node(),
5429      Pat::Assign(node) => node.as_node(),
5430      Pat::Invalid(node) => node.as_node(),
5431      Pat::Expr(node) => node.as_node(),
5432    }
5433  }
5434
5435  fn kind(&self) -> NodeKind {
5436    match self {
5437      Pat::Ident(_) => NodeKind::BindingIdent,
5438      Pat::Array(_) => NodeKind::ArrayPat,
5439      Pat::Rest(_) => NodeKind::RestPat,
5440      Pat::Object(_) => NodeKind::ObjectPat,
5441      Pat::Assign(_) => NodeKind::AssignPat,
5442      Pat::Invalid(_) => NodeKind::Invalid,
5443      Pat::Expr(node) => node.kind(),
5444    }
5445  }
5446}
5447
5448impl<'a> From<&Pat<'a>> for Node<'a> {
5449  fn from(node: &Pat<'a>) -> Node<'a> {
5450    match node {
5451      Pat::Ident(node) => (*node).into(),
5452      Pat::Array(node) => (*node).into(),
5453      Pat::Rest(node) => (*node).into(),
5454      Pat::Object(node) => (*node).into(),
5455      Pat::Assign(node) => (*node).into(),
5456      Pat::Invalid(node) => (*node).into(),
5457      Pat::Expr(node) => node.into(),
5458    }
5459  }
5460}
5461
5462impl<'a> From<Pat<'a>> for Node<'a> {
5463  fn from(node: Pat<'a>) -> Node<'a> {
5464    match node {
5465      Pat::Ident(node) => node.into(),
5466      Pat::Array(node) => node.into(),
5467      Pat::Rest(node) => node.into(),
5468      Pat::Object(node) => node.into(),
5469      Pat::Assign(node) => node.into(),
5470      Pat::Invalid(node) => node.into(),
5471      Pat::Expr(node) => node.into(),
5472    }
5473  }
5474}
5475
5476fn get_view_for_pat<'a>(inner: &'a swc_ast::Pat, bump: &'a Bump) -> Pat<'a> {
5477  match inner {
5478    swc_ast::Pat::Ident(value) => Pat::Ident(get_view_for_binding_ident(value, bump)),
5479    swc_ast::Pat::Array(value) => Pat::Array(get_view_for_array_pat(value, bump)),
5480    swc_ast::Pat::Rest(value) => Pat::Rest(get_view_for_rest_pat(value, bump)),
5481    swc_ast::Pat::Object(value) => Pat::Object(get_view_for_object_pat(value, bump)),
5482    swc_ast::Pat::Assign(value) => Pat::Assign(get_view_for_assign_pat(value, bump)),
5483    swc_ast::Pat::Invalid(value) => Pat::Invalid(get_view_for_invalid(value, bump)),
5484    swc_ast::Pat::Expr(value) => Pat::Expr(get_view_for_expr(value, bump)),
5485  }
5486}
5487
5488fn set_parent_for_pat<'a>(node: &Pat<'a>, parent: Node<'a>) {
5489  match node {
5490    Pat::Ident(value) => set_parent_for_binding_ident(value, parent),
5491    Pat::Array(value) => set_parent_for_array_pat(value, parent),
5492    Pat::Rest(value) => set_parent_for_rest_pat(value, parent),
5493    Pat::Object(value) => set_parent_for_object_pat(value, parent),
5494    Pat::Assign(value) => set_parent_for_assign_pat(value, parent),
5495    Pat::Invalid(value) => set_parent_for_invalid(value, parent),
5496    Pat::Expr(value) => set_parent_for_expr(value, parent),
5497  }
5498}
5499
5500#[derive(Copy, Clone)]
5501pub enum Prop<'a> {
5502  /// `a` in `{ a, }`
5503  Shorthand(&'a Ident<'a>),
5504  /// `key: value` in `{ key: value, }`
5505  KeyValue(&'a KeyValueProp<'a>),
5506  /// This is **invalid** for object literal.
5507  Assign(&'a AssignProp<'a>),
5508  Getter(&'a GetterProp<'a>),
5509  Setter(&'a SetterProp<'a>),
5510  Method(&'a MethodProp<'a>),
5511}
5512
5513impl<'a> Prop<'a> {
5514  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5515    T::to(&self.into())
5516  }
5517
5518  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5519    let node: Node<'a> = self.into();
5520    if let Some(result) = T::to(&node) {
5521      result
5522    } else {
5523      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5524    }
5525  }
5526
5527  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5528    self.kind() == T::kind()
5529  }
5530  pub fn parent(&self) -> Node<'a> {
5531    NodeTrait::parent(self).unwrap()
5532  }
5533}
5534
5535impl<'a> SourceRanged for Prop<'a> {
5536  fn start(&self) -> SourcePos {
5537    match self {
5538      Prop::Shorthand(node) => node.start(),
5539      Prop::KeyValue(node) => node.start(),
5540      Prop::Assign(node) => node.start(),
5541      Prop::Getter(node) => node.start(),
5542      Prop::Setter(node) => node.start(),
5543      Prop::Method(node) => node.start(),
5544    }
5545  }
5546  fn end(&self) -> SourcePos {
5547    match self {
5548      Prop::Shorthand(node) => node.end(),
5549      Prop::KeyValue(node) => node.end(),
5550      Prop::Assign(node) => node.end(),
5551      Prop::Getter(node) => node.end(),
5552      Prop::Setter(node) => node.end(),
5553      Prop::Method(node) => node.end(),
5554    }
5555  }
5556}
5557
5558impl<'a> NodeTrait<'a> for Prop<'a> {
5559  fn parent(&self) -> Option<Node<'a>> {
5560    match self {
5561      Prop::Shorthand(node) => NodeTrait::parent(*node),
5562      Prop::KeyValue(node) => NodeTrait::parent(*node),
5563      Prop::Assign(node) => NodeTrait::parent(*node),
5564      Prop::Getter(node) => NodeTrait::parent(*node),
5565      Prop::Setter(node) => NodeTrait::parent(*node),
5566      Prop::Method(node) => NodeTrait::parent(*node),
5567    }
5568  }
5569
5570  fn children(&self) -> Vec<Node<'a>> {
5571    match self {
5572      Prop::Shorthand(node) => node.children(),
5573      Prop::KeyValue(node) => node.children(),
5574      Prop::Assign(node) => node.children(),
5575      Prop::Getter(node) => node.children(),
5576      Prop::Setter(node) => node.children(),
5577      Prop::Method(node) => node.children(),
5578    }
5579  }
5580
5581  fn as_node(&self) -> Node<'a> {
5582    match self {
5583      Prop::Shorthand(node) => node.as_node(),
5584      Prop::KeyValue(node) => node.as_node(),
5585      Prop::Assign(node) => node.as_node(),
5586      Prop::Getter(node) => node.as_node(),
5587      Prop::Setter(node) => node.as_node(),
5588      Prop::Method(node) => node.as_node(),
5589    }
5590  }
5591
5592  fn kind(&self) -> NodeKind {
5593    match self {
5594      Prop::Shorthand(_) => NodeKind::Ident,
5595      Prop::KeyValue(_) => NodeKind::KeyValueProp,
5596      Prop::Assign(_) => NodeKind::AssignProp,
5597      Prop::Getter(_) => NodeKind::GetterProp,
5598      Prop::Setter(_) => NodeKind::SetterProp,
5599      Prop::Method(_) => NodeKind::MethodProp,
5600    }
5601  }
5602}
5603
5604impl<'a> From<&Prop<'a>> for Node<'a> {
5605  fn from(node: &Prop<'a>) -> Node<'a> {
5606    match node {
5607      Prop::Shorthand(node) => (*node).into(),
5608      Prop::KeyValue(node) => (*node).into(),
5609      Prop::Assign(node) => (*node).into(),
5610      Prop::Getter(node) => (*node).into(),
5611      Prop::Setter(node) => (*node).into(),
5612      Prop::Method(node) => (*node).into(),
5613    }
5614  }
5615}
5616
5617impl<'a> From<Prop<'a>> for Node<'a> {
5618  fn from(node: Prop<'a>) -> Node<'a> {
5619    match node {
5620      Prop::Shorthand(node) => node.into(),
5621      Prop::KeyValue(node) => node.into(),
5622      Prop::Assign(node) => node.into(),
5623      Prop::Getter(node) => node.into(),
5624      Prop::Setter(node) => node.into(),
5625      Prop::Method(node) => node.into(),
5626    }
5627  }
5628}
5629
5630fn get_view_for_prop<'a>(inner: &'a swc_ast::Prop, bump: &'a Bump) -> Prop<'a> {
5631  match inner {
5632    swc_ast::Prop::Shorthand(value) => Prop::Shorthand(get_view_for_ident(value, bump)),
5633    swc_ast::Prop::KeyValue(value) => Prop::KeyValue(get_view_for_key_value_prop(value, bump)),
5634    swc_ast::Prop::Assign(value) => Prop::Assign(get_view_for_assign_prop(value, bump)),
5635    swc_ast::Prop::Getter(value) => Prop::Getter(get_view_for_getter_prop(value, bump)),
5636    swc_ast::Prop::Setter(value) => Prop::Setter(get_view_for_setter_prop(value, bump)),
5637    swc_ast::Prop::Method(value) => Prop::Method(get_view_for_method_prop(value, bump)),
5638  }
5639}
5640
5641fn set_parent_for_prop<'a>(node: &Prop<'a>, parent: Node<'a>) {
5642  match node {
5643    Prop::Shorthand(value) => set_parent_for_ident(value, parent),
5644    Prop::KeyValue(value) => set_parent_for_key_value_prop(value, parent),
5645    Prop::Assign(value) => set_parent_for_assign_prop(value, parent),
5646    Prop::Getter(value) => set_parent_for_getter_prop(value, parent),
5647    Prop::Setter(value) => set_parent_for_setter_prop(value, parent),
5648    Prop::Method(value) => set_parent_for_method_prop(value, parent),
5649  }
5650}
5651
5652#[derive(Copy, Clone)]
5653pub enum PropName<'a> {
5654  Ident(&'a IdentName<'a>),
5655  /// String literal.
5656  Str(&'a Str<'a>),
5657  /// Numeric literal.
5658  Num(&'a Number<'a>),
5659  Computed(&'a ComputedPropName<'a>),
5660  BigInt(&'a BigInt<'a>),
5661}
5662
5663impl<'a> PropName<'a> {
5664  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5665    T::to(&self.into())
5666  }
5667
5668  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5669    let node: Node<'a> = self.into();
5670    if let Some(result) = T::to(&node) {
5671      result
5672    } else {
5673      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5674    }
5675  }
5676
5677  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5678    self.kind() == T::kind()
5679  }
5680  pub fn parent(&self) -> Node<'a> {
5681    NodeTrait::parent(self).unwrap()
5682  }
5683}
5684
5685impl<'a> SourceRanged for PropName<'a> {
5686  fn start(&self) -> SourcePos {
5687    match self {
5688      PropName::Ident(node) => node.start(),
5689      PropName::Str(node) => node.start(),
5690      PropName::Num(node) => node.start(),
5691      PropName::Computed(node) => node.start(),
5692      PropName::BigInt(node) => node.start(),
5693    }
5694  }
5695  fn end(&self) -> SourcePos {
5696    match self {
5697      PropName::Ident(node) => node.end(),
5698      PropName::Str(node) => node.end(),
5699      PropName::Num(node) => node.end(),
5700      PropName::Computed(node) => node.end(),
5701      PropName::BigInt(node) => node.end(),
5702    }
5703  }
5704}
5705
5706impl<'a> NodeTrait<'a> for PropName<'a> {
5707  fn parent(&self) -> Option<Node<'a>> {
5708    match self {
5709      PropName::Ident(node) => NodeTrait::parent(*node),
5710      PropName::Str(node) => NodeTrait::parent(*node),
5711      PropName::Num(node) => NodeTrait::parent(*node),
5712      PropName::Computed(node) => NodeTrait::parent(*node),
5713      PropName::BigInt(node) => NodeTrait::parent(*node),
5714    }
5715  }
5716
5717  fn children(&self) -> Vec<Node<'a>> {
5718    match self {
5719      PropName::Ident(node) => node.children(),
5720      PropName::Str(node) => node.children(),
5721      PropName::Num(node) => node.children(),
5722      PropName::Computed(node) => node.children(),
5723      PropName::BigInt(node) => node.children(),
5724    }
5725  }
5726
5727  fn as_node(&self) -> Node<'a> {
5728    match self {
5729      PropName::Ident(node) => node.as_node(),
5730      PropName::Str(node) => node.as_node(),
5731      PropName::Num(node) => node.as_node(),
5732      PropName::Computed(node) => node.as_node(),
5733      PropName::BigInt(node) => node.as_node(),
5734    }
5735  }
5736
5737  fn kind(&self) -> NodeKind {
5738    match self {
5739      PropName::Ident(_) => NodeKind::IdentName,
5740      PropName::Str(_) => NodeKind::Str,
5741      PropName::Num(_) => NodeKind::Number,
5742      PropName::Computed(_) => NodeKind::ComputedPropName,
5743      PropName::BigInt(_) => NodeKind::BigInt,
5744    }
5745  }
5746}
5747
5748impl<'a> From<&PropName<'a>> for Node<'a> {
5749  fn from(node: &PropName<'a>) -> Node<'a> {
5750    match node {
5751      PropName::Ident(node) => (*node).into(),
5752      PropName::Str(node) => (*node).into(),
5753      PropName::Num(node) => (*node).into(),
5754      PropName::Computed(node) => (*node).into(),
5755      PropName::BigInt(node) => (*node).into(),
5756    }
5757  }
5758}
5759
5760impl<'a> From<PropName<'a>> for Node<'a> {
5761  fn from(node: PropName<'a>) -> Node<'a> {
5762    match node {
5763      PropName::Ident(node) => node.into(),
5764      PropName::Str(node) => node.into(),
5765      PropName::Num(node) => node.into(),
5766      PropName::Computed(node) => node.into(),
5767      PropName::BigInt(node) => node.into(),
5768    }
5769  }
5770}
5771
5772fn get_view_for_prop_name<'a>(inner: &'a swc_ast::PropName, bump: &'a Bump) -> PropName<'a> {
5773  match inner {
5774    swc_ast::PropName::Ident(value) => PropName::Ident(get_view_for_ident_name(value, bump)),
5775    swc_ast::PropName::Str(value) => PropName::Str(get_view_for_str(value, bump)),
5776    swc_ast::PropName::Num(value) => PropName::Num(get_view_for_number(value, bump)),
5777    swc_ast::PropName::Computed(value) => PropName::Computed(get_view_for_computed_prop_name(value, bump)),
5778    swc_ast::PropName::BigInt(value) => PropName::BigInt(get_view_for_big_int(value, bump)),
5779  }
5780}
5781
5782fn set_parent_for_prop_name<'a>(node: &PropName<'a>, parent: Node<'a>) {
5783  match node {
5784    PropName::Ident(value) => set_parent_for_ident_name(value, parent),
5785    PropName::Str(value) => set_parent_for_str(value, parent),
5786    PropName::Num(value) => set_parent_for_number(value, parent),
5787    PropName::Computed(value) => set_parent_for_computed_prop_name(value, parent),
5788    PropName::BigInt(value) => set_parent_for_big_int(value, parent),
5789  }
5790}
5791
5792#[derive(Copy, Clone)]
5793pub enum PropOrSpread<'a> {
5794  /// Spread properties, e.g., `{a: 1, ...obj, b: 2}`.
5795  Spread(&'a SpreadElement<'a>),
5796  Prop(Prop<'a>),
5797}
5798
5799impl<'a> PropOrSpread<'a> {
5800  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5801    T::to(&self.into())
5802  }
5803
5804  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5805    let node: Node<'a> = self.into();
5806    if let Some(result) = T::to(&node) {
5807      result
5808    } else {
5809      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5810    }
5811  }
5812
5813  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5814    self.kind() == T::kind()
5815  }
5816}
5817
5818impl<'a> SourceRanged for PropOrSpread<'a> {
5819  fn start(&self) -> SourcePos {
5820    match self {
5821      PropOrSpread::Spread(node) => node.start(),
5822      PropOrSpread::Prop(node) => node.start(),
5823    }
5824  }
5825  fn end(&self) -> SourcePos {
5826    match self {
5827      PropOrSpread::Spread(node) => node.end(),
5828      PropOrSpread::Prop(node) => node.end(),
5829    }
5830  }
5831}
5832
5833impl<'a> NodeTrait<'a> for PropOrSpread<'a> {
5834  fn parent(&self) -> Option<Node<'a>> {
5835    match self {
5836      PropOrSpread::Spread(node) => NodeTrait::parent(*node),
5837      PropOrSpread::Prop(node) => NodeTrait::parent(node),
5838    }
5839  }
5840
5841  fn children(&self) -> Vec<Node<'a>> {
5842    match self {
5843      PropOrSpread::Spread(node) => node.children(),
5844      PropOrSpread::Prop(node) => node.children(),
5845    }
5846  }
5847
5848  fn as_node(&self) -> Node<'a> {
5849    match self {
5850      PropOrSpread::Spread(node) => node.as_node(),
5851      PropOrSpread::Prop(node) => node.as_node(),
5852    }
5853  }
5854
5855  fn kind(&self) -> NodeKind {
5856    match self {
5857      PropOrSpread::Spread(_) => NodeKind::SpreadElement,
5858      PropOrSpread::Prop(node) => node.kind(),
5859    }
5860  }
5861}
5862
5863impl<'a> From<&PropOrSpread<'a>> for Node<'a> {
5864  fn from(node: &PropOrSpread<'a>) -> Node<'a> {
5865    match node {
5866      PropOrSpread::Spread(node) => (*node).into(),
5867      PropOrSpread::Prop(node) => node.into(),
5868    }
5869  }
5870}
5871
5872impl<'a> From<PropOrSpread<'a>> for Node<'a> {
5873  fn from(node: PropOrSpread<'a>) -> Node<'a> {
5874    match node {
5875      PropOrSpread::Spread(node) => node.into(),
5876      PropOrSpread::Prop(node) => node.into(),
5877    }
5878  }
5879}
5880
5881fn get_view_for_prop_or_spread<'a>(inner: &'a swc_ast::PropOrSpread, bump: &'a Bump) -> PropOrSpread<'a> {
5882  match inner {
5883    swc_ast::PropOrSpread::Spread(value) => PropOrSpread::Spread(get_view_for_spread_element(value, bump)),
5884    swc_ast::PropOrSpread::Prop(value) => PropOrSpread::Prop(get_view_for_prop(value, bump)),
5885  }
5886}
5887
5888fn set_parent_for_prop_or_spread<'a>(node: &PropOrSpread<'a>, parent: Node<'a>) {
5889  match node {
5890    PropOrSpread::Spread(value) => set_parent_for_spread_element(value, parent),
5891    PropOrSpread::Prop(value) => set_parent_for_prop(value, parent),
5892  }
5893}
5894
5895#[derive(Copy, Clone)]
5896pub enum SimpleAssignTarget<'a> {
5897  /// Note: This type is to help implementing visitor and the field `type_ann`
5898  /// is always [None].
5899  Ident(&'a BindingIdent<'a>),
5900  Member(&'a MemberExpr<'a>),
5901  SuperProp(&'a SuperPropExpr<'a>),
5902  Paren(&'a ParenExpr<'a>),
5903  OptChain(&'a OptChainExpr<'a>),
5904  TsAs(&'a TsAsExpr<'a>),
5905  TsSatisfies(&'a TsSatisfiesExpr<'a>),
5906  TsNonNull(&'a TsNonNullExpr<'a>),
5907  TsTypeAssertion(&'a TsTypeAssertion<'a>),
5908  TsInstantiation(&'a TsInstantiation<'a>),
5909  Invalid(&'a Invalid<'a>),
5910}
5911
5912impl<'a> SimpleAssignTarget<'a> {
5913  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
5914    T::to(&self.into())
5915  }
5916
5917  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
5918    let node: Node<'a> = self.into();
5919    if let Some(result) = T::to(&node) {
5920      result
5921    } else {
5922      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
5923    }
5924  }
5925
5926  pub fn is<T: CastableNode<'a>>(&self) -> bool {
5927    self.kind() == T::kind()
5928  }
5929  pub fn parent(&self) -> Node<'a> {
5930    NodeTrait::parent(self).unwrap()
5931  }
5932}
5933
5934impl<'a> SourceRanged for SimpleAssignTarget<'a> {
5935  fn start(&self) -> SourcePos {
5936    match self {
5937      SimpleAssignTarget::Ident(node) => node.start(),
5938      SimpleAssignTarget::Member(node) => node.start(),
5939      SimpleAssignTarget::SuperProp(node) => node.start(),
5940      SimpleAssignTarget::Paren(node) => node.start(),
5941      SimpleAssignTarget::OptChain(node) => node.start(),
5942      SimpleAssignTarget::TsAs(node) => node.start(),
5943      SimpleAssignTarget::TsSatisfies(node) => node.start(),
5944      SimpleAssignTarget::TsNonNull(node) => node.start(),
5945      SimpleAssignTarget::TsTypeAssertion(node) => node.start(),
5946      SimpleAssignTarget::TsInstantiation(node) => node.start(),
5947      SimpleAssignTarget::Invalid(node) => node.start(),
5948    }
5949  }
5950  fn end(&self) -> SourcePos {
5951    match self {
5952      SimpleAssignTarget::Ident(node) => node.end(),
5953      SimpleAssignTarget::Member(node) => node.end(),
5954      SimpleAssignTarget::SuperProp(node) => node.end(),
5955      SimpleAssignTarget::Paren(node) => node.end(),
5956      SimpleAssignTarget::OptChain(node) => node.end(),
5957      SimpleAssignTarget::TsAs(node) => node.end(),
5958      SimpleAssignTarget::TsSatisfies(node) => node.end(),
5959      SimpleAssignTarget::TsNonNull(node) => node.end(),
5960      SimpleAssignTarget::TsTypeAssertion(node) => node.end(),
5961      SimpleAssignTarget::TsInstantiation(node) => node.end(),
5962      SimpleAssignTarget::Invalid(node) => node.end(),
5963    }
5964  }
5965}
5966
5967impl<'a> NodeTrait<'a> for SimpleAssignTarget<'a> {
5968  fn parent(&self) -> Option<Node<'a>> {
5969    match self {
5970      SimpleAssignTarget::Ident(node) => NodeTrait::parent(*node),
5971      SimpleAssignTarget::Member(node) => NodeTrait::parent(*node),
5972      SimpleAssignTarget::SuperProp(node) => NodeTrait::parent(*node),
5973      SimpleAssignTarget::Paren(node) => NodeTrait::parent(*node),
5974      SimpleAssignTarget::OptChain(node) => NodeTrait::parent(*node),
5975      SimpleAssignTarget::TsAs(node) => NodeTrait::parent(*node),
5976      SimpleAssignTarget::TsSatisfies(node) => NodeTrait::parent(*node),
5977      SimpleAssignTarget::TsNonNull(node) => NodeTrait::parent(*node),
5978      SimpleAssignTarget::TsTypeAssertion(node) => NodeTrait::parent(*node),
5979      SimpleAssignTarget::TsInstantiation(node) => NodeTrait::parent(*node),
5980      SimpleAssignTarget::Invalid(node) => NodeTrait::parent(*node),
5981    }
5982  }
5983
5984  fn children(&self) -> Vec<Node<'a>> {
5985    match self {
5986      SimpleAssignTarget::Ident(node) => node.children(),
5987      SimpleAssignTarget::Member(node) => node.children(),
5988      SimpleAssignTarget::SuperProp(node) => node.children(),
5989      SimpleAssignTarget::Paren(node) => node.children(),
5990      SimpleAssignTarget::OptChain(node) => node.children(),
5991      SimpleAssignTarget::TsAs(node) => node.children(),
5992      SimpleAssignTarget::TsSatisfies(node) => node.children(),
5993      SimpleAssignTarget::TsNonNull(node) => node.children(),
5994      SimpleAssignTarget::TsTypeAssertion(node) => node.children(),
5995      SimpleAssignTarget::TsInstantiation(node) => node.children(),
5996      SimpleAssignTarget::Invalid(node) => node.children(),
5997    }
5998  }
5999
6000  fn as_node(&self) -> Node<'a> {
6001    match self {
6002      SimpleAssignTarget::Ident(node) => node.as_node(),
6003      SimpleAssignTarget::Member(node) => node.as_node(),
6004      SimpleAssignTarget::SuperProp(node) => node.as_node(),
6005      SimpleAssignTarget::Paren(node) => node.as_node(),
6006      SimpleAssignTarget::OptChain(node) => node.as_node(),
6007      SimpleAssignTarget::TsAs(node) => node.as_node(),
6008      SimpleAssignTarget::TsSatisfies(node) => node.as_node(),
6009      SimpleAssignTarget::TsNonNull(node) => node.as_node(),
6010      SimpleAssignTarget::TsTypeAssertion(node) => node.as_node(),
6011      SimpleAssignTarget::TsInstantiation(node) => node.as_node(),
6012      SimpleAssignTarget::Invalid(node) => node.as_node(),
6013    }
6014  }
6015
6016  fn kind(&self) -> NodeKind {
6017    match self {
6018      SimpleAssignTarget::Ident(_) => NodeKind::BindingIdent,
6019      SimpleAssignTarget::Member(_) => NodeKind::MemberExpr,
6020      SimpleAssignTarget::SuperProp(_) => NodeKind::SuperPropExpr,
6021      SimpleAssignTarget::Paren(_) => NodeKind::ParenExpr,
6022      SimpleAssignTarget::OptChain(_) => NodeKind::OptChainExpr,
6023      SimpleAssignTarget::TsAs(_) => NodeKind::TsAsExpr,
6024      SimpleAssignTarget::TsSatisfies(_) => NodeKind::TsSatisfiesExpr,
6025      SimpleAssignTarget::TsNonNull(_) => NodeKind::TsNonNullExpr,
6026      SimpleAssignTarget::TsTypeAssertion(_) => NodeKind::TsTypeAssertion,
6027      SimpleAssignTarget::TsInstantiation(_) => NodeKind::TsInstantiation,
6028      SimpleAssignTarget::Invalid(_) => NodeKind::Invalid,
6029    }
6030  }
6031}
6032
6033impl<'a> From<&SimpleAssignTarget<'a>> for Node<'a> {
6034  fn from(node: &SimpleAssignTarget<'a>) -> Node<'a> {
6035    match node {
6036      SimpleAssignTarget::Ident(node) => (*node).into(),
6037      SimpleAssignTarget::Member(node) => (*node).into(),
6038      SimpleAssignTarget::SuperProp(node) => (*node).into(),
6039      SimpleAssignTarget::Paren(node) => (*node).into(),
6040      SimpleAssignTarget::OptChain(node) => (*node).into(),
6041      SimpleAssignTarget::TsAs(node) => (*node).into(),
6042      SimpleAssignTarget::TsSatisfies(node) => (*node).into(),
6043      SimpleAssignTarget::TsNonNull(node) => (*node).into(),
6044      SimpleAssignTarget::TsTypeAssertion(node) => (*node).into(),
6045      SimpleAssignTarget::TsInstantiation(node) => (*node).into(),
6046      SimpleAssignTarget::Invalid(node) => (*node).into(),
6047    }
6048  }
6049}
6050
6051impl<'a> From<SimpleAssignTarget<'a>> for Node<'a> {
6052  fn from(node: SimpleAssignTarget<'a>) -> Node<'a> {
6053    match node {
6054      SimpleAssignTarget::Ident(node) => node.into(),
6055      SimpleAssignTarget::Member(node) => node.into(),
6056      SimpleAssignTarget::SuperProp(node) => node.into(),
6057      SimpleAssignTarget::Paren(node) => node.into(),
6058      SimpleAssignTarget::OptChain(node) => node.into(),
6059      SimpleAssignTarget::TsAs(node) => node.into(),
6060      SimpleAssignTarget::TsSatisfies(node) => node.into(),
6061      SimpleAssignTarget::TsNonNull(node) => node.into(),
6062      SimpleAssignTarget::TsTypeAssertion(node) => node.into(),
6063      SimpleAssignTarget::TsInstantiation(node) => node.into(),
6064      SimpleAssignTarget::Invalid(node) => node.into(),
6065    }
6066  }
6067}
6068
6069fn get_view_for_simple_assign_target<'a>(inner: &'a swc_ast::SimpleAssignTarget, bump: &'a Bump) -> SimpleAssignTarget<'a> {
6070  match inner {
6071    swc_ast::SimpleAssignTarget::Ident(value) => SimpleAssignTarget::Ident(get_view_for_binding_ident(value, bump)),
6072    swc_ast::SimpleAssignTarget::Member(value) => SimpleAssignTarget::Member(get_view_for_member_expr(value, bump)),
6073    swc_ast::SimpleAssignTarget::SuperProp(value) => SimpleAssignTarget::SuperProp(get_view_for_super_prop_expr(value, bump)),
6074    swc_ast::SimpleAssignTarget::Paren(value) => SimpleAssignTarget::Paren(get_view_for_paren_expr(value, bump)),
6075    swc_ast::SimpleAssignTarget::OptChain(value) => SimpleAssignTarget::OptChain(get_view_for_opt_chain_expr(value, bump)),
6076    swc_ast::SimpleAssignTarget::TsAs(value) => SimpleAssignTarget::TsAs(get_view_for_ts_as_expr(value, bump)),
6077    swc_ast::SimpleAssignTarget::TsSatisfies(value) => SimpleAssignTarget::TsSatisfies(get_view_for_ts_satisfies_expr(value, bump)),
6078    swc_ast::SimpleAssignTarget::TsNonNull(value) => SimpleAssignTarget::TsNonNull(get_view_for_ts_non_null_expr(value, bump)),
6079    swc_ast::SimpleAssignTarget::TsTypeAssertion(value) => SimpleAssignTarget::TsTypeAssertion(get_view_for_ts_type_assertion(value, bump)),
6080    swc_ast::SimpleAssignTarget::TsInstantiation(value) => SimpleAssignTarget::TsInstantiation(get_view_for_ts_instantiation(value, bump)),
6081    swc_ast::SimpleAssignTarget::Invalid(value) => SimpleAssignTarget::Invalid(get_view_for_invalid(value, bump)),
6082  }
6083}
6084
6085fn set_parent_for_simple_assign_target<'a>(node: &SimpleAssignTarget<'a>, parent: Node<'a>) {
6086  match node {
6087    SimpleAssignTarget::Ident(value) => set_parent_for_binding_ident(value, parent),
6088    SimpleAssignTarget::Member(value) => set_parent_for_member_expr(value, parent),
6089    SimpleAssignTarget::SuperProp(value) => set_parent_for_super_prop_expr(value, parent),
6090    SimpleAssignTarget::Paren(value) => set_parent_for_paren_expr(value, parent),
6091    SimpleAssignTarget::OptChain(value) => set_parent_for_opt_chain_expr(value, parent),
6092    SimpleAssignTarget::TsAs(value) => set_parent_for_ts_as_expr(value, parent),
6093    SimpleAssignTarget::TsSatisfies(value) => set_parent_for_ts_satisfies_expr(value, parent),
6094    SimpleAssignTarget::TsNonNull(value) => set_parent_for_ts_non_null_expr(value, parent),
6095    SimpleAssignTarget::TsTypeAssertion(value) => set_parent_for_ts_type_assertion(value, parent),
6096    SimpleAssignTarget::TsInstantiation(value) => set_parent_for_ts_instantiation(value, parent),
6097    SimpleAssignTarget::Invalid(value) => set_parent_for_invalid(value, parent),
6098  }
6099}
6100
6101#[derive(Copy, Clone)]
6102pub enum Stmt<'a> {
6103  Block(&'a BlockStmt<'a>),
6104  Empty(&'a EmptyStmt<'a>),
6105  Debugger(&'a DebuggerStmt<'a>),
6106  With(&'a WithStmt<'a>),
6107  Return(&'a ReturnStmt<'a>),
6108  Labeled(&'a LabeledStmt<'a>),
6109  Break(&'a BreakStmt<'a>),
6110  Continue(&'a ContinueStmt<'a>),
6111  If(&'a IfStmt<'a>),
6112  Switch(&'a SwitchStmt<'a>),
6113  Throw(&'a ThrowStmt<'a>),
6114  /// A try statement. If handler is null then finalizer must be a BlockStmt.
6115  Try(&'a TryStmt<'a>),
6116  While(&'a WhileStmt<'a>),
6117  DoWhile(&'a DoWhileStmt<'a>),
6118  For(&'a ForStmt<'a>),
6119  ForIn(&'a ForInStmt<'a>),
6120  ForOf(&'a ForOfStmt<'a>),
6121  Decl(Decl<'a>),
6122  Expr(&'a ExprStmt<'a>),
6123}
6124
6125impl<'a> Stmt<'a> {
6126  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6127    T::to(&self.into())
6128  }
6129
6130  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6131    let node: Node<'a> = self.into();
6132    if let Some(result) = T::to(&node) {
6133      result
6134    } else {
6135      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6136    }
6137  }
6138
6139  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6140    self.kind() == T::kind()
6141  }
6142}
6143
6144impl<'a> SourceRanged for Stmt<'a> {
6145  fn start(&self) -> SourcePos {
6146    match self {
6147      Stmt::Block(node) => node.start(),
6148      Stmt::Empty(node) => node.start(),
6149      Stmt::Debugger(node) => node.start(),
6150      Stmt::With(node) => node.start(),
6151      Stmt::Return(node) => node.start(),
6152      Stmt::Labeled(node) => node.start(),
6153      Stmt::Break(node) => node.start(),
6154      Stmt::Continue(node) => node.start(),
6155      Stmt::If(node) => node.start(),
6156      Stmt::Switch(node) => node.start(),
6157      Stmt::Throw(node) => node.start(),
6158      Stmt::Try(node) => node.start(),
6159      Stmt::While(node) => node.start(),
6160      Stmt::DoWhile(node) => node.start(),
6161      Stmt::For(node) => node.start(),
6162      Stmt::ForIn(node) => node.start(),
6163      Stmt::ForOf(node) => node.start(),
6164      Stmt::Decl(node) => node.start(),
6165      Stmt::Expr(node) => node.start(),
6166    }
6167  }
6168  fn end(&self) -> SourcePos {
6169    match self {
6170      Stmt::Block(node) => node.end(),
6171      Stmt::Empty(node) => node.end(),
6172      Stmt::Debugger(node) => node.end(),
6173      Stmt::With(node) => node.end(),
6174      Stmt::Return(node) => node.end(),
6175      Stmt::Labeled(node) => node.end(),
6176      Stmt::Break(node) => node.end(),
6177      Stmt::Continue(node) => node.end(),
6178      Stmt::If(node) => node.end(),
6179      Stmt::Switch(node) => node.end(),
6180      Stmt::Throw(node) => node.end(),
6181      Stmt::Try(node) => node.end(),
6182      Stmt::While(node) => node.end(),
6183      Stmt::DoWhile(node) => node.end(),
6184      Stmt::For(node) => node.end(),
6185      Stmt::ForIn(node) => node.end(),
6186      Stmt::ForOf(node) => node.end(),
6187      Stmt::Decl(node) => node.end(),
6188      Stmt::Expr(node) => node.end(),
6189    }
6190  }
6191}
6192
6193impl<'a> NodeTrait<'a> for Stmt<'a> {
6194  fn parent(&self) -> Option<Node<'a>> {
6195    match self {
6196      Stmt::Block(node) => NodeTrait::parent(*node),
6197      Stmt::Empty(node) => NodeTrait::parent(*node),
6198      Stmt::Debugger(node) => NodeTrait::parent(*node),
6199      Stmt::With(node) => NodeTrait::parent(*node),
6200      Stmt::Return(node) => NodeTrait::parent(*node),
6201      Stmt::Labeled(node) => NodeTrait::parent(*node),
6202      Stmt::Break(node) => NodeTrait::parent(*node),
6203      Stmt::Continue(node) => NodeTrait::parent(*node),
6204      Stmt::If(node) => NodeTrait::parent(*node),
6205      Stmt::Switch(node) => NodeTrait::parent(*node),
6206      Stmt::Throw(node) => NodeTrait::parent(*node),
6207      Stmt::Try(node) => NodeTrait::parent(*node),
6208      Stmt::While(node) => NodeTrait::parent(*node),
6209      Stmt::DoWhile(node) => NodeTrait::parent(*node),
6210      Stmt::For(node) => NodeTrait::parent(*node),
6211      Stmt::ForIn(node) => NodeTrait::parent(*node),
6212      Stmt::ForOf(node) => NodeTrait::parent(*node),
6213      Stmt::Decl(node) => NodeTrait::parent(node),
6214      Stmt::Expr(node) => NodeTrait::parent(*node),
6215    }
6216  }
6217
6218  fn children(&self) -> Vec<Node<'a>> {
6219    match self {
6220      Stmt::Block(node) => node.children(),
6221      Stmt::Empty(node) => node.children(),
6222      Stmt::Debugger(node) => node.children(),
6223      Stmt::With(node) => node.children(),
6224      Stmt::Return(node) => node.children(),
6225      Stmt::Labeled(node) => node.children(),
6226      Stmt::Break(node) => node.children(),
6227      Stmt::Continue(node) => node.children(),
6228      Stmt::If(node) => node.children(),
6229      Stmt::Switch(node) => node.children(),
6230      Stmt::Throw(node) => node.children(),
6231      Stmt::Try(node) => node.children(),
6232      Stmt::While(node) => node.children(),
6233      Stmt::DoWhile(node) => node.children(),
6234      Stmt::For(node) => node.children(),
6235      Stmt::ForIn(node) => node.children(),
6236      Stmt::ForOf(node) => node.children(),
6237      Stmt::Decl(node) => node.children(),
6238      Stmt::Expr(node) => node.children(),
6239    }
6240  }
6241
6242  fn as_node(&self) -> Node<'a> {
6243    match self {
6244      Stmt::Block(node) => node.as_node(),
6245      Stmt::Empty(node) => node.as_node(),
6246      Stmt::Debugger(node) => node.as_node(),
6247      Stmt::With(node) => node.as_node(),
6248      Stmt::Return(node) => node.as_node(),
6249      Stmt::Labeled(node) => node.as_node(),
6250      Stmt::Break(node) => node.as_node(),
6251      Stmt::Continue(node) => node.as_node(),
6252      Stmt::If(node) => node.as_node(),
6253      Stmt::Switch(node) => node.as_node(),
6254      Stmt::Throw(node) => node.as_node(),
6255      Stmt::Try(node) => node.as_node(),
6256      Stmt::While(node) => node.as_node(),
6257      Stmt::DoWhile(node) => node.as_node(),
6258      Stmt::For(node) => node.as_node(),
6259      Stmt::ForIn(node) => node.as_node(),
6260      Stmt::ForOf(node) => node.as_node(),
6261      Stmt::Decl(node) => node.as_node(),
6262      Stmt::Expr(node) => node.as_node(),
6263    }
6264  }
6265
6266  fn kind(&self) -> NodeKind {
6267    match self {
6268      Stmt::Block(_) => NodeKind::BlockStmt,
6269      Stmt::Empty(_) => NodeKind::EmptyStmt,
6270      Stmt::Debugger(_) => NodeKind::DebuggerStmt,
6271      Stmt::With(_) => NodeKind::WithStmt,
6272      Stmt::Return(_) => NodeKind::ReturnStmt,
6273      Stmt::Labeled(_) => NodeKind::LabeledStmt,
6274      Stmt::Break(_) => NodeKind::BreakStmt,
6275      Stmt::Continue(_) => NodeKind::ContinueStmt,
6276      Stmt::If(_) => NodeKind::IfStmt,
6277      Stmt::Switch(_) => NodeKind::SwitchStmt,
6278      Stmt::Throw(_) => NodeKind::ThrowStmt,
6279      Stmt::Try(_) => NodeKind::TryStmt,
6280      Stmt::While(_) => NodeKind::WhileStmt,
6281      Stmt::DoWhile(_) => NodeKind::DoWhileStmt,
6282      Stmt::For(_) => NodeKind::ForStmt,
6283      Stmt::ForIn(_) => NodeKind::ForInStmt,
6284      Stmt::ForOf(_) => NodeKind::ForOfStmt,
6285      Stmt::Decl(node) => node.kind(),
6286      Stmt::Expr(_) => NodeKind::ExprStmt,
6287    }
6288  }
6289}
6290
6291impl<'a> From<&Stmt<'a>> for Node<'a> {
6292  fn from(node: &Stmt<'a>) -> Node<'a> {
6293    match node {
6294      Stmt::Block(node) => (*node).into(),
6295      Stmt::Empty(node) => (*node).into(),
6296      Stmt::Debugger(node) => (*node).into(),
6297      Stmt::With(node) => (*node).into(),
6298      Stmt::Return(node) => (*node).into(),
6299      Stmt::Labeled(node) => (*node).into(),
6300      Stmt::Break(node) => (*node).into(),
6301      Stmt::Continue(node) => (*node).into(),
6302      Stmt::If(node) => (*node).into(),
6303      Stmt::Switch(node) => (*node).into(),
6304      Stmt::Throw(node) => (*node).into(),
6305      Stmt::Try(node) => (*node).into(),
6306      Stmt::While(node) => (*node).into(),
6307      Stmt::DoWhile(node) => (*node).into(),
6308      Stmt::For(node) => (*node).into(),
6309      Stmt::ForIn(node) => (*node).into(),
6310      Stmt::ForOf(node) => (*node).into(),
6311      Stmt::Decl(node) => node.into(),
6312      Stmt::Expr(node) => (*node).into(),
6313    }
6314  }
6315}
6316
6317impl<'a> From<Stmt<'a>> for Node<'a> {
6318  fn from(node: Stmt<'a>) -> Node<'a> {
6319    match node {
6320      Stmt::Block(node) => node.into(),
6321      Stmt::Empty(node) => node.into(),
6322      Stmt::Debugger(node) => node.into(),
6323      Stmt::With(node) => node.into(),
6324      Stmt::Return(node) => node.into(),
6325      Stmt::Labeled(node) => node.into(),
6326      Stmt::Break(node) => node.into(),
6327      Stmt::Continue(node) => node.into(),
6328      Stmt::If(node) => node.into(),
6329      Stmt::Switch(node) => node.into(),
6330      Stmt::Throw(node) => node.into(),
6331      Stmt::Try(node) => node.into(),
6332      Stmt::While(node) => node.into(),
6333      Stmt::DoWhile(node) => node.into(),
6334      Stmt::For(node) => node.into(),
6335      Stmt::ForIn(node) => node.into(),
6336      Stmt::ForOf(node) => node.into(),
6337      Stmt::Decl(node) => node.into(),
6338      Stmt::Expr(node) => node.into(),
6339    }
6340  }
6341}
6342
6343fn get_view_for_stmt<'a>(inner: &'a swc_ast::Stmt, bump: &'a Bump) -> Stmt<'a> {
6344  match inner {
6345    swc_ast::Stmt::Block(value) => Stmt::Block(get_view_for_block_stmt(value, bump)),
6346    swc_ast::Stmt::Empty(value) => Stmt::Empty(get_view_for_empty_stmt(value, bump)),
6347    swc_ast::Stmt::Debugger(value) => Stmt::Debugger(get_view_for_debugger_stmt(value, bump)),
6348    swc_ast::Stmt::With(value) => Stmt::With(get_view_for_with_stmt(value, bump)),
6349    swc_ast::Stmt::Return(value) => Stmt::Return(get_view_for_return_stmt(value, bump)),
6350    swc_ast::Stmt::Labeled(value) => Stmt::Labeled(get_view_for_labeled_stmt(value, bump)),
6351    swc_ast::Stmt::Break(value) => Stmt::Break(get_view_for_break_stmt(value, bump)),
6352    swc_ast::Stmt::Continue(value) => Stmt::Continue(get_view_for_continue_stmt(value, bump)),
6353    swc_ast::Stmt::If(value) => Stmt::If(get_view_for_if_stmt(value, bump)),
6354    swc_ast::Stmt::Switch(value) => Stmt::Switch(get_view_for_switch_stmt(value, bump)),
6355    swc_ast::Stmt::Throw(value) => Stmt::Throw(get_view_for_throw_stmt(value, bump)),
6356    swc_ast::Stmt::Try(value) => Stmt::Try(get_view_for_try_stmt(value, bump)),
6357    swc_ast::Stmt::While(value) => Stmt::While(get_view_for_while_stmt(value, bump)),
6358    swc_ast::Stmt::DoWhile(value) => Stmt::DoWhile(get_view_for_do_while_stmt(value, bump)),
6359    swc_ast::Stmt::For(value) => Stmt::For(get_view_for_for_stmt(value, bump)),
6360    swc_ast::Stmt::ForIn(value) => Stmt::ForIn(get_view_for_for_in_stmt(value, bump)),
6361    swc_ast::Stmt::ForOf(value) => Stmt::ForOf(get_view_for_for_of_stmt(value, bump)),
6362    swc_ast::Stmt::Decl(value) => Stmt::Decl(get_view_for_decl(value, bump)),
6363    swc_ast::Stmt::Expr(value) => Stmt::Expr(get_view_for_expr_stmt(value, bump)),
6364  }
6365}
6366
6367fn set_parent_for_stmt<'a>(node: &Stmt<'a>, parent: Node<'a>) {
6368  match node {
6369    Stmt::Block(value) => set_parent_for_block_stmt(value, parent),
6370    Stmt::Empty(value) => set_parent_for_empty_stmt(value, parent),
6371    Stmt::Debugger(value) => set_parent_for_debugger_stmt(value, parent),
6372    Stmt::With(value) => set_parent_for_with_stmt(value, parent),
6373    Stmt::Return(value) => set_parent_for_return_stmt(value, parent),
6374    Stmt::Labeled(value) => set_parent_for_labeled_stmt(value, parent),
6375    Stmt::Break(value) => set_parent_for_break_stmt(value, parent),
6376    Stmt::Continue(value) => set_parent_for_continue_stmt(value, parent),
6377    Stmt::If(value) => set_parent_for_if_stmt(value, parent),
6378    Stmt::Switch(value) => set_parent_for_switch_stmt(value, parent),
6379    Stmt::Throw(value) => set_parent_for_throw_stmt(value, parent),
6380    Stmt::Try(value) => set_parent_for_try_stmt(value, parent),
6381    Stmt::While(value) => set_parent_for_while_stmt(value, parent),
6382    Stmt::DoWhile(value) => set_parent_for_do_while_stmt(value, parent),
6383    Stmt::For(value) => set_parent_for_for_stmt(value, parent),
6384    Stmt::ForIn(value) => set_parent_for_for_in_stmt(value, parent),
6385    Stmt::ForOf(value) => set_parent_for_for_of_stmt(value, parent),
6386    Stmt::Decl(value) => set_parent_for_decl(value, parent),
6387    Stmt::Expr(value) => set_parent_for_expr_stmt(value, parent),
6388  }
6389}
6390
6391#[derive(Copy, Clone)]
6392pub enum SuperProp<'a> {
6393  Ident(&'a IdentName<'a>),
6394  Computed(&'a ComputedPropName<'a>),
6395}
6396
6397impl<'a> SuperProp<'a> {
6398  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6399    T::to(&self.into())
6400  }
6401
6402  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6403    let node: Node<'a> = self.into();
6404    if let Some(result) = T::to(&node) {
6405      result
6406    } else {
6407      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6408    }
6409  }
6410
6411  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6412    self.kind() == T::kind()
6413  }
6414  pub fn parent(&self) -> Node<'a> {
6415    NodeTrait::parent(self).unwrap()
6416  }
6417}
6418
6419impl<'a> SourceRanged for SuperProp<'a> {
6420  fn start(&self) -> SourcePos {
6421    match self {
6422      SuperProp::Ident(node) => node.start(),
6423      SuperProp::Computed(node) => node.start(),
6424    }
6425  }
6426  fn end(&self) -> SourcePos {
6427    match self {
6428      SuperProp::Ident(node) => node.end(),
6429      SuperProp::Computed(node) => node.end(),
6430    }
6431  }
6432}
6433
6434impl<'a> NodeTrait<'a> for SuperProp<'a> {
6435  fn parent(&self) -> Option<Node<'a>> {
6436    match self {
6437      SuperProp::Ident(node) => NodeTrait::parent(*node),
6438      SuperProp::Computed(node) => NodeTrait::parent(*node),
6439    }
6440  }
6441
6442  fn children(&self) -> Vec<Node<'a>> {
6443    match self {
6444      SuperProp::Ident(node) => node.children(),
6445      SuperProp::Computed(node) => node.children(),
6446    }
6447  }
6448
6449  fn as_node(&self) -> Node<'a> {
6450    match self {
6451      SuperProp::Ident(node) => node.as_node(),
6452      SuperProp::Computed(node) => node.as_node(),
6453    }
6454  }
6455
6456  fn kind(&self) -> NodeKind {
6457    match self {
6458      SuperProp::Ident(_) => NodeKind::IdentName,
6459      SuperProp::Computed(_) => NodeKind::ComputedPropName,
6460    }
6461  }
6462}
6463
6464impl<'a> From<&SuperProp<'a>> for Node<'a> {
6465  fn from(node: &SuperProp<'a>) -> Node<'a> {
6466    match node {
6467      SuperProp::Ident(node) => (*node).into(),
6468      SuperProp::Computed(node) => (*node).into(),
6469    }
6470  }
6471}
6472
6473impl<'a> From<SuperProp<'a>> for Node<'a> {
6474  fn from(node: SuperProp<'a>) -> Node<'a> {
6475    match node {
6476      SuperProp::Ident(node) => node.into(),
6477      SuperProp::Computed(node) => node.into(),
6478    }
6479  }
6480}
6481
6482fn get_view_for_super_prop<'a>(inner: &'a swc_ast::SuperProp, bump: &'a Bump) -> SuperProp<'a> {
6483  match inner {
6484    swc_ast::SuperProp::Ident(value) => SuperProp::Ident(get_view_for_ident_name(value, bump)),
6485    swc_ast::SuperProp::Computed(value) => SuperProp::Computed(get_view_for_computed_prop_name(value, bump)),
6486  }
6487}
6488
6489fn set_parent_for_super_prop<'a>(node: &SuperProp<'a>, parent: Node<'a>) {
6490  match node {
6491    SuperProp::Ident(value) => set_parent_for_ident_name(value, parent),
6492    SuperProp::Computed(value) => set_parent_for_computed_prop_name(value, parent),
6493  }
6494}
6495
6496#[derive(Copy, Clone)]
6497pub enum TsEntityName<'a> {
6498  TsQualifiedName(&'a TsQualifiedName<'a>),
6499  Ident(&'a Ident<'a>),
6500}
6501
6502impl<'a> TsEntityName<'a> {
6503  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6504    T::to(&self.into())
6505  }
6506
6507  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6508    let node: Node<'a> = self.into();
6509    if let Some(result) = T::to(&node) {
6510      result
6511    } else {
6512      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6513    }
6514  }
6515
6516  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6517    self.kind() == T::kind()
6518  }
6519  pub fn parent(&self) -> Node<'a> {
6520    NodeTrait::parent(self).unwrap()
6521  }
6522}
6523
6524impl<'a> SourceRanged for TsEntityName<'a> {
6525  fn start(&self) -> SourcePos {
6526    match self {
6527      TsEntityName::TsQualifiedName(node) => node.start(),
6528      TsEntityName::Ident(node) => node.start(),
6529    }
6530  }
6531  fn end(&self) -> SourcePos {
6532    match self {
6533      TsEntityName::TsQualifiedName(node) => node.end(),
6534      TsEntityName::Ident(node) => node.end(),
6535    }
6536  }
6537}
6538
6539impl<'a> NodeTrait<'a> for TsEntityName<'a> {
6540  fn parent(&self) -> Option<Node<'a>> {
6541    match self {
6542      TsEntityName::TsQualifiedName(node) => NodeTrait::parent(*node),
6543      TsEntityName::Ident(node) => NodeTrait::parent(*node),
6544    }
6545  }
6546
6547  fn children(&self) -> Vec<Node<'a>> {
6548    match self {
6549      TsEntityName::TsQualifiedName(node) => node.children(),
6550      TsEntityName::Ident(node) => node.children(),
6551    }
6552  }
6553
6554  fn as_node(&self) -> Node<'a> {
6555    match self {
6556      TsEntityName::TsQualifiedName(node) => node.as_node(),
6557      TsEntityName::Ident(node) => node.as_node(),
6558    }
6559  }
6560
6561  fn kind(&self) -> NodeKind {
6562    match self {
6563      TsEntityName::TsQualifiedName(_) => NodeKind::TsQualifiedName,
6564      TsEntityName::Ident(_) => NodeKind::Ident,
6565    }
6566  }
6567}
6568
6569impl<'a> From<&TsEntityName<'a>> for Node<'a> {
6570  fn from(node: &TsEntityName<'a>) -> Node<'a> {
6571    match node {
6572      TsEntityName::TsQualifiedName(node) => (*node).into(),
6573      TsEntityName::Ident(node) => (*node).into(),
6574    }
6575  }
6576}
6577
6578impl<'a> From<TsEntityName<'a>> for Node<'a> {
6579  fn from(node: TsEntityName<'a>) -> Node<'a> {
6580    match node {
6581      TsEntityName::TsQualifiedName(node) => node.into(),
6582      TsEntityName::Ident(node) => node.into(),
6583    }
6584  }
6585}
6586
6587fn get_view_for_ts_entity_name<'a>(inner: &'a swc_ast::TsEntityName, bump: &'a Bump) -> TsEntityName<'a> {
6588  match inner {
6589    swc_ast::TsEntityName::TsQualifiedName(value) => TsEntityName::TsQualifiedName(get_view_for_ts_qualified_name(value, bump)),
6590    swc_ast::TsEntityName::Ident(value) => TsEntityName::Ident(get_view_for_ident(value, bump)),
6591  }
6592}
6593
6594fn set_parent_for_ts_entity_name<'a>(node: &TsEntityName<'a>, parent: Node<'a>) {
6595  match node {
6596    TsEntityName::TsQualifiedName(value) => set_parent_for_ts_qualified_name(value, parent),
6597    TsEntityName::Ident(value) => set_parent_for_ident(value, parent),
6598  }
6599}
6600
6601///
6602/// - Invalid: [Ident] with empty symbol.
6603#[derive(Copy, Clone)]
6604pub enum TsEnumMemberId<'a> {
6605  Ident(&'a Ident<'a>),
6606  Str(&'a Str<'a>),
6607}
6608
6609impl<'a> TsEnumMemberId<'a> {
6610  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6611    T::to(&self.into())
6612  }
6613
6614  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6615    let node: Node<'a> = self.into();
6616    if let Some(result) = T::to(&node) {
6617      result
6618    } else {
6619      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6620    }
6621  }
6622
6623  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6624    self.kind() == T::kind()
6625  }
6626  pub fn parent(&self) -> Node<'a> {
6627    NodeTrait::parent(self).unwrap()
6628  }
6629}
6630
6631impl<'a> SourceRanged for TsEnumMemberId<'a> {
6632  fn start(&self) -> SourcePos {
6633    match self {
6634      TsEnumMemberId::Ident(node) => node.start(),
6635      TsEnumMemberId::Str(node) => node.start(),
6636    }
6637  }
6638  fn end(&self) -> SourcePos {
6639    match self {
6640      TsEnumMemberId::Ident(node) => node.end(),
6641      TsEnumMemberId::Str(node) => node.end(),
6642    }
6643  }
6644}
6645
6646impl<'a> NodeTrait<'a> for TsEnumMemberId<'a> {
6647  fn parent(&self) -> Option<Node<'a>> {
6648    match self {
6649      TsEnumMemberId::Ident(node) => NodeTrait::parent(*node),
6650      TsEnumMemberId::Str(node) => NodeTrait::parent(*node),
6651    }
6652  }
6653
6654  fn children(&self) -> Vec<Node<'a>> {
6655    match self {
6656      TsEnumMemberId::Ident(node) => node.children(),
6657      TsEnumMemberId::Str(node) => node.children(),
6658    }
6659  }
6660
6661  fn as_node(&self) -> Node<'a> {
6662    match self {
6663      TsEnumMemberId::Ident(node) => node.as_node(),
6664      TsEnumMemberId::Str(node) => node.as_node(),
6665    }
6666  }
6667
6668  fn kind(&self) -> NodeKind {
6669    match self {
6670      TsEnumMemberId::Ident(_) => NodeKind::Ident,
6671      TsEnumMemberId::Str(_) => NodeKind::Str,
6672    }
6673  }
6674}
6675
6676impl<'a> From<&TsEnumMemberId<'a>> for Node<'a> {
6677  fn from(node: &TsEnumMemberId<'a>) -> Node<'a> {
6678    match node {
6679      TsEnumMemberId::Ident(node) => (*node).into(),
6680      TsEnumMemberId::Str(node) => (*node).into(),
6681    }
6682  }
6683}
6684
6685impl<'a> From<TsEnumMemberId<'a>> for Node<'a> {
6686  fn from(node: TsEnumMemberId<'a>) -> Node<'a> {
6687    match node {
6688      TsEnumMemberId::Ident(node) => node.into(),
6689      TsEnumMemberId::Str(node) => node.into(),
6690    }
6691  }
6692}
6693
6694fn get_view_for_ts_enum_member_id<'a>(inner: &'a swc_ast::TsEnumMemberId, bump: &'a Bump) -> TsEnumMemberId<'a> {
6695  match inner {
6696    swc_ast::TsEnumMemberId::Ident(value) => TsEnumMemberId::Ident(get_view_for_ident(value, bump)),
6697    swc_ast::TsEnumMemberId::Str(value) => TsEnumMemberId::Str(get_view_for_str(value, bump)),
6698  }
6699}
6700
6701fn set_parent_for_ts_enum_member_id<'a>(node: &TsEnumMemberId<'a>, parent: Node<'a>) {
6702  match node {
6703    TsEnumMemberId::Ident(value) => set_parent_for_ident(value, parent),
6704    TsEnumMemberId::Str(value) => set_parent_for_str(value, parent),
6705  }
6706}
6707
6708#[derive(Copy, Clone)]
6709pub enum TsFnOrConstructorType<'a> {
6710  TsFnType(&'a TsFnType<'a>),
6711  TsConstructorType(&'a TsConstructorType<'a>),
6712}
6713
6714impl<'a> TsFnOrConstructorType<'a> {
6715  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6716    T::to(&self.into())
6717  }
6718
6719  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6720    let node: Node<'a> = self.into();
6721    if let Some(result) = T::to(&node) {
6722      result
6723    } else {
6724      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6725    }
6726  }
6727
6728  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6729    self.kind() == T::kind()
6730  }
6731  pub fn parent(&self) -> Node<'a> {
6732    NodeTrait::parent(self).unwrap()
6733  }
6734}
6735
6736impl<'a> SourceRanged for TsFnOrConstructorType<'a> {
6737  fn start(&self) -> SourcePos {
6738    match self {
6739      TsFnOrConstructorType::TsFnType(node) => node.start(),
6740      TsFnOrConstructorType::TsConstructorType(node) => node.start(),
6741    }
6742  }
6743  fn end(&self) -> SourcePos {
6744    match self {
6745      TsFnOrConstructorType::TsFnType(node) => node.end(),
6746      TsFnOrConstructorType::TsConstructorType(node) => node.end(),
6747    }
6748  }
6749}
6750
6751impl<'a> NodeTrait<'a> for TsFnOrConstructorType<'a> {
6752  fn parent(&self) -> Option<Node<'a>> {
6753    match self {
6754      TsFnOrConstructorType::TsFnType(node) => NodeTrait::parent(*node),
6755      TsFnOrConstructorType::TsConstructorType(node) => NodeTrait::parent(*node),
6756    }
6757  }
6758
6759  fn children(&self) -> Vec<Node<'a>> {
6760    match self {
6761      TsFnOrConstructorType::TsFnType(node) => node.children(),
6762      TsFnOrConstructorType::TsConstructorType(node) => node.children(),
6763    }
6764  }
6765
6766  fn as_node(&self) -> Node<'a> {
6767    match self {
6768      TsFnOrConstructorType::TsFnType(node) => node.as_node(),
6769      TsFnOrConstructorType::TsConstructorType(node) => node.as_node(),
6770    }
6771  }
6772
6773  fn kind(&self) -> NodeKind {
6774    match self {
6775      TsFnOrConstructorType::TsFnType(_) => NodeKind::TsFnType,
6776      TsFnOrConstructorType::TsConstructorType(_) => NodeKind::TsConstructorType,
6777    }
6778  }
6779}
6780
6781impl<'a> From<&TsFnOrConstructorType<'a>> for Node<'a> {
6782  fn from(node: &TsFnOrConstructorType<'a>) -> Node<'a> {
6783    match node {
6784      TsFnOrConstructorType::TsFnType(node) => (*node).into(),
6785      TsFnOrConstructorType::TsConstructorType(node) => (*node).into(),
6786    }
6787  }
6788}
6789
6790impl<'a> From<TsFnOrConstructorType<'a>> for Node<'a> {
6791  fn from(node: TsFnOrConstructorType<'a>) -> Node<'a> {
6792    match node {
6793      TsFnOrConstructorType::TsFnType(node) => node.into(),
6794      TsFnOrConstructorType::TsConstructorType(node) => node.into(),
6795    }
6796  }
6797}
6798
6799fn get_view_for_ts_fn_or_constructor_type<'a>(inner: &'a swc_ast::TsFnOrConstructorType, bump: &'a Bump) -> TsFnOrConstructorType<'a> {
6800  match inner {
6801    swc_ast::TsFnOrConstructorType::TsFnType(value) => TsFnOrConstructorType::TsFnType(get_view_for_ts_fn_type(value, bump)),
6802    swc_ast::TsFnOrConstructorType::TsConstructorType(value) => TsFnOrConstructorType::TsConstructorType(get_view_for_ts_constructor_type(value, bump)),
6803  }
6804}
6805
6806fn set_parent_for_ts_fn_or_constructor_type<'a>(node: &TsFnOrConstructorType<'a>, parent: Node<'a>) {
6807  match node {
6808    TsFnOrConstructorType::TsFnType(value) => set_parent_for_ts_fn_type(value, parent),
6809    TsFnOrConstructorType::TsConstructorType(value) => set_parent_for_ts_constructor_type(value, parent),
6810  }
6811}
6812
6813#[derive(Copy, Clone)]
6814pub enum TsFnParam<'a> {
6815  Ident(&'a BindingIdent<'a>),
6816  Array(&'a ArrayPat<'a>),
6817  Rest(&'a RestPat<'a>),
6818  Object(&'a ObjectPat<'a>),
6819}
6820
6821impl<'a> TsFnParam<'a> {
6822  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6823    T::to(&self.into())
6824  }
6825
6826  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6827    let node: Node<'a> = self.into();
6828    if let Some(result) = T::to(&node) {
6829      result
6830    } else {
6831      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6832    }
6833  }
6834
6835  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6836    self.kind() == T::kind()
6837  }
6838  pub fn parent(&self) -> Node<'a> {
6839    NodeTrait::parent(self).unwrap()
6840  }
6841}
6842
6843impl<'a> SourceRanged for TsFnParam<'a> {
6844  fn start(&self) -> SourcePos {
6845    match self {
6846      TsFnParam::Ident(node) => node.start(),
6847      TsFnParam::Array(node) => node.start(),
6848      TsFnParam::Rest(node) => node.start(),
6849      TsFnParam::Object(node) => node.start(),
6850    }
6851  }
6852  fn end(&self) -> SourcePos {
6853    match self {
6854      TsFnParam::Ident(node) => node.end(),
6855      TsFnParam::Array(node) => node.end(),
6856      TsFnParam::Rest(node) => node.end(),
6857      TsFnParam::Object(node) => node.end(),
6858    }
6859  }
6860}
6861
6862impl<'a> NodeTrait<'a> for TsFnParam<'a> {
6863  fn parent(&self) -> Option<Node<'a>> {
6864    match self {
6865      TsFnParam::Ident(node) => NodeTrait::parent(*node),
6866      TsFnParam::Array(node) => NodeTrait::parent(*node),
6867      TsFnParam::Rest(node) => NodeTrait::parent(*node),
6868      TsFnParam::Object(node) => NodeTrait::parent(*node),
6869    }
6870  }
6871
6872  fn children(&self) -> Vec<Node<'a>> {
6873    match self {
6874      TsFnParam::Ident(node) => node.children(),
6875      TsFnParam::Array(node) => node.children(),
6876      TsFnParam::Rest(node) => node.children(),
6877      TsFnParam::Object(node) => node.children(),
6878    }
6879  }
6880
6881  fn as_node(&self) -> Node<'a> {
6882    match self {
6883      TsFnParam::Ident(node) => node.as_node(),
6884      TsFnParam::Array(node) => node.as_node(),
6885      TsFnParam::Rest(node) => node.as_node(),
6886      TsFnParam::Object(node) => node.as_node(),
6887    }
6888  }
6889
6890  fn kind(&self) -> NodeKind {
6891    match self {
6892      TsFnParam::Ident(_) => NodeKind::BindingIdent,
6893      TsFnParam::Array(_) => NodeKind::ArrayPat,
6894      TsFnParam::Rest(_) => NodeKind::RestPat,
6895      TsFnParam::Object(_) => NodeKind::ObjectPat,
6896    }
6897  }
6898}
6899
6900impl<'a> From<&TsFnParam<'a>> for Node<'a> {
6901  fn from(node: &TsFnParam<'a>) -> Node<'a> {
6902    match node {
6903      TsFnParam::Ident(node) => (*node).into(),
6904      TsFnParam::Array(node) => (*node).into(),
6905      TsFnParam::Rest(node) => (*node).into(),
6906      TsFnParam::Object(node) => (*node).into(),
6907    }
6908  }
6909}
6910
6911impl<'a> From<TsFnParam<'a>> for Node<'a> {
6912  fn from(node: TsFnParam<'a>) -> Node<'a> {
6913    match node {
6914      TsFnParam::Ident(node) => node.into(),
6915      TsFnParam::Array(node) => node.into(),
6916      TsFnParam::Rest(node) => node.into(),
6917      TsFnParam::Object(node) => node.into(),
6918    }
6919  }
6920}
6921
6922fn get_view_for_ts_fn_param<'a>(inner: &'a swc_ast::TsFnParam, bump: &'a Bump) -> TsFnParam<'a> {
6923  match inner {
6924    swc_ast::TsFnParam::Ident(value) => TsFnParam::Ident(get_view_for_binding_ident(value, bump)),
6925    swc_ast::TsFnParam::Array(value) => TsFnParam::Array(get_view_for_array_pat(value, bump)),
6926    swc_ast::TsFnParam::Rest(value) => TsFnParam::Rest(get_view_for_rest_pat(value, bump)),
6927    swc_ast::TsFnParam::Object(value) => TsFnParam::Object(get_view_for_object_pat(value, bump)),
6928  }
6929}
6930
6931fn set_parent_for_ts_fn_param<'a>(node: &TsFnParam<'a>, parent: Node<'a>) {
6932  match node {
6933    TsFnParam::Ident(value) => set_parent_for_binding_ident(value, parent),
6934    TsFnParam::Array(value) => set_parent_for_array_pat(value, parent),
6935    TsFnParam::Rest(value) => set_parent_for_rest_pat(value, parent),
6936    TsFnParam::Object(value) => set_parent_for_object_pat(value, parent),
6937  }
6938}
6939
6940#[derive(Copy, Clone)]
6941pub enum TsLit<'a> {
6942  Number(&'a Number<'a>),
6943  Str(&'a Str<'a>),
6944  Bool(&'a Bool<'a>),
6945  BigInt(&'a BigInt<'a>),
6946  Tpl(&'a TsTplLitType<'a>),
6947}
6948
6949impl<'a> TsLit<'a> {
6950  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
6951    T::to(&self.into())
6952  }
6953
6954  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
6955    let node: Node<'a> = self.into();
6956    if let Some(result) = T::to(&node) {
6957      result
6958    } else {
6959      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
6960    }
6961  }
6962
6963  pub fn is<T: CastableNode<'a>>(&self) -> bool {
6964    self.kind() == T::kind()
6965  }
6966  pub fn parent(&self) -> Node<'a> {
6967    NodeTrait::parent(self).unwrap()
6968  }
6969}
6970
6971impl<'a> SourceRanged for TsLit<'a> {
6972  fn start(&self) -> SourcePos {
6973    match self {
6974      TsLit::Number(node) => node.start(),
6975      TsLit::Str(node) => node.start(),
6976      TsLit::Bool(node) => node.start(),
6977      TsLit::BigInt(node) => node.start(),
6978      TsLit::Tpl(node) => node.start(),
6979    }
6980  }
6981  fn end(&self) -> SourcePos {
6982    match self {
6983      TsLit::Number(node) => node.end(),
6984      TsLit::Str(node) => node.end(),
6985      TsLit::Bool(node) => node.end(),
6986      TsLit::BigInt(node) => node.end(),
6987      TsLit::Tpl(node) => node.end(),
6988    }
6989  }
6990}
6991
6992impl<'a> NodeTrait<'a> for TsLit<'a> {
6993  fn parent(&self) -> Option<Node<'a>> {
6994    match self {
6995      TsLit::Number(node) => NodeTrait::parent(*node),
6996      TsLit::Str(node) => NodeTrait::parent(*node),
6997      TsLit::Bool(node) => NodeTrait::parent(*node),
6998      TsLit::BigInt(node) => NodeTrait::parent(*node),
6999      TsLit::Tpl(node) => NodeTrait::parent(*node),
7000    }
7001  }
7002
7003  fn children(&self) -> Vec<Node<'a>> {
7004    match self {
7005      TsLit::Number(node) => node.children(),
7006      TsLit::Str(node) => node.children(),
7007      TsLit::Bool(node) => node.children(),
7008      TsLit::BigInt(node) => node.children(),
7009      TsLit::Tpl(node) => node.children(),
7010    }
7011  }
7012
7013  fn as_node(&self) -> Node<'a> {
7014    match self {
7015      TsLit::Number(node) => node.as_node(),
7016      TsLit::Str(node) => node.as_node(),
7017      TsLit::Bool(node) => node.as_node(),
7018      TsLit::BigInt(node) => node.as_node(),
7019      TsLit::Tpl(node) => node.as_node(),
7020    }
7021  }
7022
7023  fn kind(&self) -> NodeKind {
7024    match self {
7025      TsLit::Number(_) => NodeKind::Number,
7026      TsLit::Str(_) => NodeKind::Str,
7027      TsLit::Bool(_) => NodeKind::Bool,
7028      TsLit::BigInt(_) => NodeKind::BigInt,
7029      TsLit::Tpl(_) => NodeKind::TsTplLitType,
7030    }
7031  }
7032}
7033
7034impl<'a> From<&TsLit<'a>> for Node<'a> {
7035  fn from(node: &TsLit<'a>) -> Node<'a> {
7036    match node {
7037      TsLit::Number(node) => (*node).into(),
7038      TsLit::Str(node) => (*node).into(),
7039      TsLit::Bool(node) => (*node).into(),
7040      TsLit::BigInt(node) => (*node).into(),
7041      TsLit::Tpl(node) => (*node).into(),
7042    }
7043  }
7044}
7045
7046impl<'a> From<TsLit<'a>> for Node<'a> {
7047  fn from(node: TsLit<'a>) -> Node<'a> {
7048    match node {
7049      TsLit::Number(node) => node.into(),
7050      TsLit::Str(node) => node.into(),
7051      TsLit::Bool(node) => node.into(),
7052      TsLit::BigInt(node) => node.into(),
7053      TsLit::Tpl(node) => node.into(),
7054    }
7055  }
7056}
7057
7058fn get_view_for_ts_lit<'a>(inner: &'a swc_ast::TsLit, bump: &'a Bump) -> TsLit<'a> {
7059  match inner {
7060    swc_ast::TsLit::Number(value) => TsLit::Number(get_view_for_number(value, bump)),
7061    swc_ast::TsLit::Str(value) => TsLit::Str(get_view_for_str(value, bump)),
7062    swc_ast::TsLit::Bool(value) => TsLit::Bool(get_view_for_bool(value, bump)),
7063    swc_ast::TsLit::BigInt(value) => TsLit::BigInt(get_view_for_big_int(value, bump)),
7064    swc_ast::TsLit::Tpl(value) => TsLit::Tpl(get_view_for_ts_tpl_lit_type(value, bump)),
7065  }
7066}
7067
7068fn set_parent_for_ts_lit<'a>(node: &TsLit<'a>, parent: Node<'a>) {
7069  match node {
7070    TsLit::Number(value) => set_parent_for_number(value, parent),
7071    TsLit::Str(value) => set_parent_for_str(value, parent),
7072    TsLit::Bool(value) => set_parent_for_bool(value, parent),
7073    TsLit::BigInt(value) => set_parent_for_big_int(value, parent),
7074    TsLit::Tpl(value) => set_parent_for_ts_tpl_lit_type(value, parent),
7075  }
7076}
7077
7078#[derive(Copy, Clone)]
7079pub enum TsModuleName<'a> {
7080  Ident(&'a Ident<'a>),
7081  Str(&'a Str<'a>),
7082}
7083
7084impl<'a> TsModuleName<'a> {
7085  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7086    T::to(&self.into())
7087  }
7088
7089  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7090    let node: Node<'a> = self.into();
7091    if let Some(result) = T::to(&node) {
7092      result
7093    } else {
7094      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7095    }
7096  }
7097
7098  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7099    self.kind() == T::kind()
7100  }
7101  pub fn parent(&self) -> Node<'a> {
7102    NodeTrait::parent(self).unwrap()
7103  }
7104}
7105
7106impl<'a> SourceRanged for TsModuleName<'a> {
7107  fn start(&self) -> SourcePos {
7108    match self {
7109      TsModuleName::Ident(node) => node.start(),
7110      TsModuleName::Str(node) => node.start(),
7111    }
7112  }
7113  fn end(&self) -> SourcePos {
7114    match self {
7115      TsModuleName::Ident(node) => node.end(),
7116      TsModuleName::Str(node) => node.end(),
7117    }
7118  }
7119}
7120
7121impl<'a> NodeTrait<'a> for TsModuleName<'a> {
7122  fn parent(&self) -> Option<Node<'a>> {
7123    match self {
7124      TsModuleName::Ident(node) => NodeTrait::parent(*node),
7125      TsModuleName::Str(node) => NodeTrait::parent(*node),
7126    }
7127  }
7128
7129  fn children(&self) -> Vec<Node<'a>> {
7130    match self {
7131      TsModuleName::Ident(node) => node.children(),
7132      TsModuleName::Str(node) => node.children(),
7133    }
7134  }
7135
7136  fn as_node(&self) -> Node<'a> {
7137    match self {
7138      TsModuleName::Ident(node) => node.as_node(),
7139      TsModuleName::Str(node) => node.as_node(),
7140    }
7141  }
7142
7143  fn kind(&self) -> NodeKind {
7144    match self {
7145      TsModuleName::Ident(_) => NodeKind::Ident,
7146      TsModuleName::Str(_) => NodeKind::Str,
7147    }
7148  }
7149}
7150
7151impl<'a> From<&TsModuleName<'a>> for Node<'a> {
7152  fn from(node: &TsModuleName<'a>) -> Node<'a> {
7153    match node {
7154      TsModuleName::Ident(node) => (*node).into(),
7155      TsModuleName::Str(node) => (*node).into(),
7156    }
7157  }
7158}
7159
7160impl<'a> From<TsModuleName<'a>> for Node<'a> {
7161  fn from(node: TsModuleName<'a>) -> Node<'a> {
7162    match node {
7163      TsModuleName::Ident(node) => node.into(),
7164      TsModuleName::Str(node) => node.into(),
7165    }
7166  }
7167}
7168
7169fn get_view_for_ts_module_name<'a>(inner: &'a swc_ast::TsModuleName, bump: &'a Bump) -> TsModuleName<'a> {
7170  match inner {
7171    swc_ast::TsModuleName::Ident(value) => TsModuleName::Ident(get_view_for_ident(value, bump)),
7172    swc_ast::TsModuleName::Str(value) => TsModuleName::Str(get_view_for_str(value, bump)),
7173  }
7174}
7175
7176fn set_parent_for_ts_module_name<'a>(node: &TsModuleName<'a>, parent: Node<'a>) {
7177  match node {
7178    TsModuleName::Ident(value) => set_parent_for_ident(value, parent),
7179    TsModuleName::Str(value) => set_parent_for_str(value, parent),
7180  }
7181}
7182
7183#[derive(Copy, Clone)]
7184pub enum TsModuleRef<'a> {
7185  TsEntityName(TsEntityName<'a>),
7186  TsExternalModuleRef(&'a TsExternalModuleRef<'a>),
7187}
7188
7189impl<'a> TsModuleRef<'a> {
7190  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7191    T::to(&self.into())
7192  }
7193
7194  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7195    let node: Node<'a> = self.into();
7196    if let Some(result) = T::to(&node) {
7197      result
7198    } else {
7199      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7200    }
7201  }
7202
7203  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7204    self.kind() == T::kind()
7205  }
7206}
7207
7208impl<'a> SourceRanged for TsModuleRef<'a> {
7209  fn start(&self) -> SourcePos {
7210    match self {
7211      TsModuleRef::TsEntityName(node) => node.start(),
7212      TsModuleRef::TsExternalModuleRef(node) => node.start(),
7213    }
7214  }
7215  fn end(&self) -> SourcePos {
7216    match self {
7217      TsModuleRef::TsEntityName(node) => node.end(),
7218      TsModuleRef::TsExternalModuleRef(node) => node.end(),
7219    }
7220  }
7221}
7222
7223impl<'a> NodeTrait<'a> for TsModuleRef<'a> {
7224  fn parent(&self) -> Option<Node<'a>> {
7225    match self {
7226      TsModuleRef::TsEntityName(node) => NodeTrait::parent(node),
7227      TsModuleRef::TsExternalModuleRef(node) => NodeTrait::parent(*node),
7228    }
7229  }
7230
7231  fn children(&self) -> Vec<Node<'a>> {
7232    match self {
7233      TsModuleRef::TsEntityName(node) => node.children(),
7234      TsModuleRef::TsExternalModuleRef(node) => node.children(),
7235    }
7236  }
7237
7238  fn as_node(&self) -> Node<'a> {
7239    match self {
7240      TsModuleRef::TsEntityName(node) => node.as_node(),
7241      TsModuleRef::TsExternalModuleRef(node) => node.as_node(),
7242    }
7243  }
7244
7245  fn kind(&self) -> NodeKind {
7246    match self {
7247      TsModuleRef::TsEntityName(node) => node.kind(),
7248      TsModuleRef::TsExternalModuleRef(_) => NodeKind::TsExternalModuleRef,
7249    }
7250  }
7251}
7252
7253impl<'a> From<&TsModuleRef<'a>> for Node<'a> {
7254  fn from(node: &TsModuleRef<'a>) -> Node<'a> {
7255    match node {
7256      TsModuleRef::TsEntityName(node) => node.into(),
7257      TsModuleRef::TsExternalModuleRef(node) => (*node).into(),
7258    }
7259  }
7260}
7261
7262impl<'a> From<TsModuleRef<'a>> for Node<'a> {
7263  fn from(node: TsModuleRef<'a>) -> Node<'a> {
7264    match node {
7265      TsModuleRef::TsEntityName(node) => node.into(),
7266      TsModuleRef::TsExternalModuleRef(node) => node.into(),
7267    }
7268  }
7269}
7270
7271fn get_view_for_ts_module_ref<'a>(inner: &'a swc_ast::TsModuleRef, bump: &'a Bump) -> TsModuleRef<'a> {
7272  match inner {
7273    swc_ast::TsModuleRef::TsEntityName(value) => TsModuleRef::TsEntityName(get_view_for_ts_entity_name(value, bump)),
7274    swc_ast::TsModuleRef::TsExternalModuleRef(value) => TsModuleRef::TsExternalModuleRef(get_view_for_ts_external_module_ref(value, bump)),
7275  }
7276}
7277
7278fn set_parent_for_ts_module_ref<'a>(node: &TsModuleRef<'a>, parent: Node<'a>) {
7279  match node {
7280    TsModuleRef::TsEntityName(value) => set_parent_for_ts_entity_name(value, parent),
7281    TsModuleRef::TsExternalModuleRef(value) => set_parent_for_ts_external_module_ref(value, parent),
7282  }
7283}
7284
7285/// `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as
7286/// its body.
7287#[derive(Copy, Clone)]
7288pub enum TsNamespaceBody<'a> {
7289  TsModuleBlock(&'a TsModuleBlock<'a>),
7290  TsNamespaceDecl(&'a TsNamespaceDecl<'a>),
7291}
7292
7293impl<'a> TsNamespaceBody<'a> {
7294  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7295    T::to(&self.into())
7296  }
7297
7298  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7299    let node: Node<'a> = self.into();
7300    if let Some(result) = T::to(&node) {
7301      result
7302    } else {
7303      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7304    }
7305  }
7306
7307  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7308    self.kind() == T::kind()
7309  }
7310  pub fn parent(&self) -> Node<'a> {
7311    NodeTrait::parent(self).unwrap()
7312  }
7313}
7314
7315impl<'a> SourceRanged for TsNamespaceBody<'a> {
7316  fn start(&self) -> SourcePos {
7317    match self {
7318      TsNamespaceBody::TsModuleBlock(node) => node.start(),
7319      TsNamespaceBody::TsNamespaceDecl(node) => node.start(),
7320    }
7321  }
7322  fn end(&self) -> SourcePos {
7323    match self {
7324      TsNamespaceBody::TsModuleBlock(node) => node.end(),
7325      TsNamespaceBody::TsNamespaceDecl(node) => node.end(),
7326    }
7327  }
7328}
7329
7330impl<'a> NodeTrait<'a> for TsNamespaceBody<'a> {
7331  fn parent(&self) -> Option<Node<'a>> {
7332    match self {
7333      TsNamespaceBody::TsModuleBlock(node) => NodeTrait::parent(*node),
7334      TsNamespaceBody::TsNamespaceDecl(node) => NodeTrait::parent(*node),
7335    }
7336  }
7337
7338  fn children(&self) -> Vec<Node<'a>> {
7339    match self {
7340      TsNamespaceBody::TsModuleBlock(node) => node.children(),
7341      TsNamespaceBody::TsNamespaceDecl(node) => node.children(),
7342    }
7343  }
7344
7345  fn as_node(&self) -> Node<'a> {
7346    match self {
7347      TsNamespaceBody::TsModuleBlock(node) => node.as_node(),
7348      TsNamespaceBody::TsNamespaceDecl(node) => node.as_node(),
7349    }
7350  }
7351
7352  fn kind(&self) -> NodeKind {
7353    match self {
7354      TsNamespaceBody::TsModuleBlock(_) => NodeKind::TsModuleBlock,
7355      TsNamespaceBody::TsNamespaceDecl(_) => NodeKind::TsNamespaceDecl,
7356    }
7357  }
7358}
7359
7360impl<'a> From<&TsNamespaceBody<'a>> for Node<'a> {
7361  fn from(node: &TsNamespaceBody<'a>) -> Node<'a> {
7362    match node {
7363      TsNamespaceBody::TsModuleBlock(node) => (*node).into(),
7364      TsNamespaceBody::TsNamespaceDecl(node) => (*node).into(),
7365    }
7366  }
7367}
7368
7369impl<'a> From<TsNamespaceBody<'a>> for Node<'a> {
7370  fn from(node: TsNamespaceBody<'a>) -> Node<'a> {
7371    match node {
7372      TsNamespaceBody::TsModuleBlock(node) => node.into(),
7373      TsNamespaceBody::TsNamespaceDecl(node) => node.into(),
7374    }
7375  }
7376}
7377
7378fn get_view_for_ts_namespace_body<'a>(inner: &'a swc_ast::TsNamespaceBody, bump: &'a Bump) -> TsNamespaceBody<'a> {
7379  match inner {
7380    swc_ast::TsNamespaceBody::TsModuleBlock(value) => TsNamespaceBody::TsModuleBlock(get_view_for_ts_module_block(value, bump)),
7381    swc_ast::TsNamespaceBody::TsNamespaceDecl(value) => TsNamespaceBody::TsNamespaceDecl(get_view_for_ts_namespace_decl(value, bump)),
7382  }
7383}
7384
7385fn set_parent_for_ts_namespace_body<'a>(node: &TsNamespaceBody<'a>, parent: Node<'a>) {
7386  match node {
7387    TsNamespaceBody::TsModuleBlock(value) => set_parent_for_ts_module_block(value, parent),
7388    TsNamespaceBody::TsNamespaceDecl(value) => set_parent_for_ts_namespace_decl(value, parent),
7389  }
7390}
7391
7392#[derive(Copy, Clone)]
7393pub enum TsParamPropParam<'a> {
7394  Ident(&'a BindingIdent<'a>),
7395  Assign(&'a AssignPat<'a>),
7396}
7397
7398impl<'a> TsParamPropParam<'a> {
7399  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7400    T::to(&self.into())
7401  }
7402
7403  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7404    let node: Node<'a> = self.into();
7405    if let Some(result) = T::to(&node) {
7406      result
7407    } else {
7408      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7409    }
7410  }
7411
7412  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7413    self.kind() == T::kind()
7414  }
7415  pub fn parent(&self) -> Node<'a> {
7416    NodeTrait::parent(self).unwrap()
7417  }
7418}
7419
7420impl<'a> SourceRanged for TsParamPropParam<'a> {
7421  fn start(&self) -> SourcePos {
7422    match self {
7423      TsParamPropParam::Ident(node) => node.start(),
7424      TsParamPropParam::Assign(node) => node.start(),
7425    }
7426  }
7427  fn end(&self) -> SourcePos {
7428    match self {
7429      TsParamPropParam::Ident(node) => node.end(),
7430      TsParamPropParam::Assign(node) => node.end(),
7431    }
7432  }
7433}
7434
7435impl<'a> NodeTrait<'a> for TsParamPropParam<'a> {
7436  fn parent(&self) -> Option<Node<'a>> {
7437    match self {
7438      TsParamPropParam::Ident(node) => NodeTrait::parent(*node),
7439      TsParamPropParam::Assign(node) => NodeTrait::parent(*node),
7440    }
7441  }
7442
7443  fn children(&self) -> Vec<Node<'a>> {
7444    match self {
7445      TsParamPropParam::Ident(node) => node.children(),
7446      TsParamPropParam::Assign(node) => node.children(),
7447    }
7448  }
7449
7450  fn as_node(&self) -> Node<'a> {
7451    match self {
7452      TsParamPropParam::Ident(node) => node.as_node(),
7453      TsParamPropParam::Assign(node) => node.as_node(),
7454    }
7455  }
7456
7457  fn kind(&self) -> NodeKind {
7458    match self {
7459      TsParamPropParam::Ident(_) => NodeKind::BindingIdent,
7460      TsParamPropParam::Assign(_) => NodeKind::AssignPat,
7461    }
7462  }
7463}
7464
7465impl<'a> From<&TsParamPropParam<'a>> for Node<'a> {
7466  fn from(node: &TsParamPropParam<'a>) -> Node<'a> {
7467    match node {
7468      TsParamPropParam::Ident(node) => (*node).into(),
7469      TsParamPropParam::Assign(node) => (*node).into(),
7470    }
7471  }
7472}
7473
7474impl<'a> From<TsParamPropParam<'a>> for Node<'a> {
7475  fn from(node: TsParamPropParam<'a>) -> Node<'a> {
7476    match node {
7477      TsParamPropParam::Ident(node) => node.into(),
7478      TsParamPropParam::Assign(node) => node.into(),
7479    }
7480  }
7481}
7482
7483fn get_view_for_ts_param_prop_param<'a>(inner: &'a swc_ast::TsParamPropParam, bump: &'a Bump) -> TsParamPropParam<'a> {
7484  match inner {
7485    swc_ast::TsParamPropParam::Ident(value) => TsParamPropParam::Ident(get_view_for_binding_ident(value, bump)),
7486    swc_ast::TsParamPropParam::Assign(value) => TsParamPropParam::Assign(get_view_for_assign_pat(value, bump)),
7487  }
7488}
7489
7490fn set_parent_for_ts_param_prop_param<'a>(node: &TsParamPropParam<'a>, parent: Node<'a>) {
7491  match node {
7492    TsParamPropParam::Ident(value) => set_parent_for_binding_ident(value, parent),
7493    TsParamPropParam::Assign(value) => set_parent_for_assign_pat(value, parent),
7494  }
7495}
7496
7497#[derive(Copy, Clone)]
7498pub enum TsThisTypeOrIdent<'a> {
7499  TsThisType(&'a TsThisType<'a>),
7500  Ident(&'a Ident<'a>),
7501}
7502
7503impl<'a> TsThisTypeOrIdent<'a> {
7504  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7505    T::to(&self.into())
7506  }
7507
7508  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7509    let node: Node<'a> = self.into();
7510    if let Some(result) = T::to(&node) {
7511      result
7512    } else {
7513      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7514    }
7515  }
7516
7517  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7518    self.kind() == T::kind()
7519  }
7520  pub fn parent(&self) -> Node<'a> {
7521    NodeTrait::parent(self).unwrap()
7522  }
7523}
7524
7525impl<'a> SourceRanged for TsThisTypeOrIdent<'a> {
7526  fn start(&self) -> SourcePos {
7527    match self {
7528      TsThisTypeOrIdent::TsThisType(node) => node.start(),
7529      TsThisTypeOrIdent::Ident(node) => node.start(),
7530    }
7531  }
7532  fn end(&self) -> SourcePos {
7533    match self {
7534      TsThisTypeOrIdent::TsThisType(node) => node.end(),
7535      TsThisTypeOrIdent::Ident(node) => node.end(),
7536    }
7537  }
7538}
7539
7540impl<'a> NodeTrait<'a> for TsThisTypeOrIdent<'a> {
7541  fn parent(&self) -> Option<Node<'a>> {
7542    match self {
7543      TsThisTypeOrIdent::TsThisType(node) => NodeTrait::parent(*node),
7544      TsThisTypeOrIdent::Ident(node) => NodeTrait::parent(*node),
7545    }
7546  }
7547
7548  fn children(&self) -> Vec<Node<'a>> {
7549    match self {
7550      TsThisTypeOrIdent::TsThisType(node) => node.children(),
7551      TsThisTypeOrIdent::Ident(node) => node.children(),
7552    }
7553  }
7554
7555  fn as_node(&self) -> Node<'a> {
7556    match self {
7557      TsThisTypeOrIdent::TsThisType(node) => node.as_node(),
7558      TsThisTypeOrIdent::Ident(node) => node.as_node(),
7559    }
7560  }
7561
7562  fn kind(&self) -> NodeKind {
7563    match self {
7564      TsThisTypeOrIdent::TsThisType(_) => NodeKind::TsThisType,
7565      TsThisTypeOrIdent::Ident(_) => NodeKind::Ident,
7566    }
7567  }
7568}
7569
7570impl<'a> From<&TsThisTypeOrIdent<'a>> for Node<'a> {
7571  fn from(node: &TsThisTypeOrIdent<'a>) -> Node<'a> {
7572    match node {
7573      TsThisTypeOrIdent::TsThisType(node) => (*node).into(),
7574      TsThisTypeOrIdent::Ident(node) => (*node).into(),
7575    }
7576  }
7577}
7578
7579impl<'a> From<TsThisTypeOrIdent<'a>> for Node<'a> {
7580  fn from(node: TsThisTypeOrIdent<'a>) -> Node<'a> {
7581    match node {
7582      TsThisTypeOrIdent::TsThisType(node) => node.into(),
7583      TsThisTypeOrIdent::Ident(node) => node.into(),
7584    }
7585  }
7586}
7587
7588fn get_view_for_ts_this_type_or_ident<'a>(inner: &'a swc_ast::TsThisTypeOrIdent, bump: &'a Bump) -> TsThisTypeOrIdent<'a> {
7589  match inner {
7590    swc_ast::TsThisTypeOrIdent::TsThisType(value) => TsThisTypeOrIdent::TsThisType(get_view_for_ts_this_type(value, bump)),
7591    swc_ast::TsThisTypeOrIdent::Ident(value) => TsThisTypeOrIdent::Ident(get_view_for_ident(value, bump)),
7592  }
7593}
7594
7595fn set_parent_for_ts_this_type_or_ident<'a>(node: &TsThisTypeOrIdent<'a>, parent: Node<'a>) {
7596  match node {
7597    TsThisTypeOrIdent::TsThisType(value) => set_parent_for_ts_this_type(value, parent),
7598    TsThisTypeOrIdent::Ident(value) => set_parent_for_ident(value, parent),
7599  }
7600}
7601
7602#[derive(Copy, Clone)]
7603pub enum TsType<'a> {
7604  TsKeywordType(&'a TsKeywordType<'a>),
7605  TsThisType(&'a TsThisType<'a>),
7606  TsFnOrConstructorType(TsFnOrConstructorType<'a>),
7607  TsTypeRef(&'a TsTypeRef<'a>),
7608  TsTypeQuery(&'a TsTypeQuery<'a>),
7609  TsTypeLit(&'a TsTypeLit<'a>),
7610  TsArrayType(&'a TsArrayType<'a>),
7611  TsTupleType(&'a TsTupleType<'a>),
7612  TsOptionalType(&'a TsOptionalType<'a>),
7613  TsRestType(&'a TsRestType<'a>),
7614  TsUnionOrIntersectionType(TsUnionOrIntersectionType<'a>),
7615  TsConditionalType(&'a TsConditionalType<'a>),
7616  TsInferType(&'a TsInferType<'a>),
7617  TsParenthesizedType(&'a TsParenthesizedType<'a>),
7618  TsTypeOperator(&'a TsTypeOperator<'a>),
7619  TsIndexedAccessType(&'a TsIndexedAccessType<'a>),
7620  TsMappedType(&'a TsMappedType<'a>),
7621  TsLitType(&'a TsLitType<'a>),
7622  TsTypePredicate(&'a TsTypePredicate<'a>),
7623  TsImportType(&'a TsImportType<'a>),
7624}
7625
7626impl<'a> TsType<'a> {
7627  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7628    T::to(&self.into())
7629  }
7630
7631  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7632    let node: Node<'a> = self.into();
7633    if let Some(result) = T::to(&node) {
7634      result
7635    } else {
7636      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7637    }
7638  }
7639
7640  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7641    self.kind() == T::kind()
7642  }
7643}
7644
7645impl<'a> SourceRanged for TsType<'a> {
7646  fn start(&self) -> SourcePos {
7647    match self {
7648      TsType::TsKeywordType(node) => node.start(),
7649      TsType::TsThisType(node) => node.start(),
7650      TsType::TsFnOrConstructorType(node) => node.start(),
7651      TsType::TsTypeRef(node) => node.start(),
7652      TsType::TsTypeQuery(node) => node.start(),
7653      TsType::TsTypeLit(node) => node.start(),
7654      TsType::TsArrayType(node) => node.start(),
7655      TsType::TsTupleType(node) => node.start(),
7656      TsType::TsOptionalType(node) => node.start(),
7657      TsType::TsRestType(node) => node.start(),
7658      TsType::TsUnionOrIntersectionType(node) => node.start(),
7659      TsType::TsConditionalType(node) => node.start(),
7660      TsType::TsInferType(node) => node.start(),
7661      TsType::TsParenthesizedType(node) => node.start(),
7662      TsType::TsTypeOperator(node) => node.start(),
7663      TsType::TsIndexedAccessType(node) => node.start(),
7664      TsType::TsMappedType(node) => node.start(),
7665      TsType::TsLitType(node) => node.start(),
7666      TsType::TsTypePredicate(node) => node.start(),
7667      TsType::TsImportType(node) => node.start(),
7668    }
7669  }
7670  fn end(&self) -> SourcePos {
7671    match self {
7672      TsType::TsKeywordType(node) => node.end(),
7673      TsType::TsThisType(node) => node.end(),
7674      TsType::TsFnOrConstructorType(node) => node.end(),
7675      TsType::TsTypeRef(node) => node.end(),
7676      TsType::TsTypeQuery(node) => node.end(),
7677      TsType::TsTypeLit(node) => node.end(),
7678      TsType::TsArrayType(node) => node.end(),
7679      TsType::TsTupleType(node) => node.end(),
7680      TsType::TsOptionalType(node) => node.end(),
7681      TsType::TsRestType(node) => node.end(),
7682      TsType::TsUnionOrIntersectionType(node) => node.end(),
7683      TsType::TsConditionalType(node) => node.end(),
7684      TsType::TsInferType(node) => node.end(),
7685      TsType::TsParenthesizedType(node) => node.end(),
7686      TsType::TsTypeOperator(node) => node.end(),
7687      TsType::TsIndexedAccessType(node) => node.end(),
7688      TsType::TsMappedType(node) => node.end(),
7689      TsType::TsLitType(node) => node.end(),
7690      TsType::TsTypePredicate(node) => node.end(),
7691      TsType::TsImportType(node) => node.end(),
7692    }
7693  }
7694}
7695
7696impl<'a> NodeTrait<'a> for TsType<'a> {
7697  fn parent(&self) -> Option<Node<'a>> {
7698    match self {
7699      TsType::TsKeywordType(node) => NodeTrait::parent(*node),
7700      TsType::TsThisType(node) => NodeTrait::parent(*node),
7701      TsType::TsFnOrConstructorType(node) => NodeTrait::parent(node),
7702      TsType::TsTypeRef(node) => NodeTrait::parent(*node),
7703      TsType::TsTypeQuery(node) => NodeTrait::parent(*node),
7704      TsType::TsTypeLit(node) => NodeTrait::parent(*node),
7705      TsType::TsArrayType(node) => NodeTrait::parent(*node),
7706      TsType::TsTupleType(node) => NodeTrait::parent(*node),
7707      TsType::TsOptionalType(node) => NodeTrait::parent(*node),
7708      TsType::TsRestType(node) => NodeTrait::parent(*node),
7709      TsType::TsUnionOrIntersectionType(node) => NodeTrait::parent(node),
7710      TsType::TsConditionalType(node) => NodeTrait::parent(*node),
7711      TsType::TsInferType(node) => NodeTrait::parent(*node),
7712      TsType::TsParenthesizedType(node) => NodeTrait::parent(*node),
7713      TsType::TsTypeOperator(node) => NodeTrait::parent(*node),
7714      TsType::TsIndexedAccessType(node) => NodeTrait::parent(*node),
7715      TsType::TsMappedType(node) => NodeTrait::parent(*node),
7716      TsType::TsLitType(node) => NodeTrait::parent(*node),
7717      TsType::TsTypePredicate(node) => NodeTrait::parent(*node),
7718      TsType::TsImportType(node) => NodeTrait::parent(*node),
7719    }
7720  }
7721
7722  fn children(&self) -> Vec<Node<'a>> {
7723    match self {
7724      TsType::TsKeywordType(node) => node.children(),
7725      TsType::TsThisType(node) => node.children(),
7726      TsType::TsFnOrConstructorType(node) => node.children(),
7727      TsType::TsTypeRef(node) => node.children(),
7728      TsType::TsTypeQuery(node) => node.children(),
7729      TsType::TsTypeLit(node) => node.children(),
7730      TsType::TsArrayType(node) => node.children(),
7731      TsType::TsTupleType(node) => node.children(),
7732      TsType::TsOptionalType(node) => node.children(),
7733      TsType::TsRestType(node) => node.children(),
7734      TsType::TsUnionOrIntersectionType(node) => node.children(),
7735      TsType::TsConditionalType(node) => node.children(),
7736      TsType::TsInferType(node) => node.children(),
7737      TsType::TsParenthesizedType(node) => node.children(),
7738      TsType::TsTypeOperator(node) => node.children(),
7739      TsType::TsIndexedAccessType(node) => node.children(),
7740      TsType::TsMappedType(node) => node.children(),
7741      TsType::TsLitType(node) => node.children(),
7742      TsType::TsTypePredicate(node) => node.children(),
7743      TsType::TsImportType(node) => node.children(),
7744    }
7745  }
7746
7747  fn as_node(&self) -> Node<'a> {
7748    match self {
7749      TsType::TsKeywordType(node) => node.as_node(),
7750      TsType::TsThisType(node) => node.as_node(),
7751      TsType::TsFnOrConstructorType(node) => node.as_node(),
7752      TsType::TsTypeRef(node) => node.as_node(),
7753      TsType::TsTypeQuery(node) => node.as_node(),
7754      TsType::TsTypeLit(node) => node.as_node(),
7755      TsType::TsArrayType(node) => node.as_node(),
7756      TsType::TsTupleType(node) => node.as_node(),
7757      TsType::TsOptionalType(node) => node.as_node(),
7758      TsType::TsRestType(node) => node.as_node(),
7759      TsType::TsUnionOrIntersectionType(node) => node.as_node(),
7760      TsType::TsConditionalType(node) => node.as_node(),
7761      TsType::TsInferType(node) => node.as_node(),
7762      TsType::TsParenthesizedType(node) => node.as_node(),
7763      TsType::TsTypeOperator(node) => node.as_node(),
7764      TsType::TsIndexedAccessType(node) => node.as_node(),
7765      TsType::TsMappedType(node) => node.as_node(),
7766      TsType::TsLitType(node) => node.as_node(),
7767      TsType::TsTypePredicate(node) => node.as_node(),
7768      TsType::TsImportType(node) => node.as_node(),
7769    }
7770  }
7771
7772  fn kind(&self) -> NodeKind {
7773    match self {
7774      TsType::TsKeywordType(_) => NodeKind::TsKeywordType,
7775      TsType::TsThisType(_) => NodeKind::TsThisType,
7776      TsType::TsFnOrConstructorType(node) => node.kind(),
7777      TsType::TsTypeRef(_) => NodeKind::TsTypeRef,
7778      TsType::TsTypeQuery(_) => NodeKind::TsTypeQuery,
7779      TsType::TsTypeLit(_) => NodeKind::TsTypeLit,
7780      TsType::TsArrayType(_) => NodeKind::TsArrayType,
7781      TsType::TsTupleType(_) => NodeKind::TsTupleType,
7782      TsType::TsOptionalType(_) => NodeKind::TsOptionalType,
7783      TsType::TsRestType(_) => NodeKind::TsRestType,
7784      TsType::TsUnionOrIntersectionType(node) => node.kind(),
7785      TsType::TsConditionalType(_) => NodeKind::TsConditionalType,
7786      TsType::TsInferType(_) => NodeKind::TsInferType,
7787      TsType::TsParenthesizedType(_) => NodeKind::TsParenthesizedType,
7788      TsType::TsTypeOperator(_) => NodeKind::TsTypeOperator,
7789      TsType::TsIndexedAccessType(_) => NodeKind::TsIndexedAccessType,
7790      TsType::TsMappedType(_) => NodeKind::TsMappedType,
7791      TsType::TsLitType(_) => NodeKind::TsLitType,
7792      TsType::TsTypePredicate(_) => NodeKind::TsTypePredicate,
7793      TsType::TsImportType(_) => NodeKind::TsImportType,
7794    }
7795  }
7796}
7797
7798impl<'a> From<&TsType<'a>> for Node<'a> {
7799  fn from(node: &TsType<'a>) -> Node<'a> {
7800    match node {
7801      TsType::TsKeywordType(node) => (*node).into(),
7802      TsType::TsThisType(node) => (*node).into(),
7803      TsType::TsFnOrConstructorType(node) => node.into(),
7804      TsType::TsTypeRef(node) => (*node).into(),
7805      TsType::TsTypeQuery(node) => (*node).into(),
7806      TsType::TsTypeLit(node) => (*node).into(),
7807      TsType::TsArrayType(node) => (*node).into(),
7808      TsType::TsTupleType(node) => (*node).into(),
7809      TsType::TsOptionalType(node) => (*node).into(),
7810      TsType::TsRestType(node) => (*node).into(),
7811      TsType::TsUnionOrIntersectionType(node) => node.into(),
7812      TsType::TsConditionalType(node) => (*node).into(),
7813      TsType::TsInferType(node) => (*node).into(),
7814      TsType::TsParenthesizedType(node) => (*node).into(),
7815      TsType::TsTypeOperator(node) => (*node).into(),
7816      TsType::TsIndexedAccessType(node) => (*node).into(),
7817      TsType::TsMappedType(node) => (*node).into(),
7818      TsType::TsLitType(node) => (*node).into(),
7819      TsType::TsTypePredicate(node) => (*node).into(),
7820      TsType::TsImportType(node) => (*node).into(),
7821    }
7822  }
7823}
7824
7825impl<'a> From<TsType<'a>> for Node<'a> {
7826  fn from(node: TsType<'a>) -> Node<'a> {
7827    match node {
7828      TsType::TsKeywordType(node) => node.into(),
7829      TsType::TsThisType(node) => node.into(),
7830      TsType::TsFnOrConstructorType(node) => node.into(),
7831      TsType::TsTypeRef(node) => node.into(),
7832      TsType::TsTypeQuery(node) => node.into(),
7833      TsType::TsTypeLit(node) => node.into(),
7834      TsType::TsArrayType(node) => node.into(),
7835      TsType::TsTupleType(node) => node.into(),
7836      TsType::TsOptionalType(node) => node.into(),
7837      TsType::TsRestType(node) => node.into(),
7838      TsType::TsUnionOrIntersectionType(node) => node.into(),
7839      TsType::TsConditionalType(node) => node.into(),
7840      TsType::TsInferType(node) => node.into(),
7841      TsType::TsParenthesizedType(node) => node.into(),
7842      TsType::TsTypeOperator(node) => node.into(),
7843      TsType::TsIndexedAccessType(node) => node.into(),
7844      TsType::TsMappedType(node) => node.into(),
7845      TsType::TsLitType(node) => node.into(),
7846      TsType::TsTypePredicate(node) => node.into(),
7847      TsType::TsImportType(node) => node.into(),
7848    }
7849  }
7850}
7851
7852fn get_view_for_ts_type<'a>(inner: &'a swc_ast::TsType, bump: &'a Bump) -> TsType<'a> {
7853  match inner {
7854    swc_ast::TsType::TsKeywordType(value) => TsType::TsKeywordType(get_view_for_ts_keyword_type(value, bump)),
7855    swc_ast::TsType::TsThisType(value) => TsType::TsThisType(get_view_for_ts_this_type(value, bump)),
7856    swc_ast::TsType::TsFnOrConstructorType(value) => TsType::TsFnOrConstructorType(get_view_for_ts_fn_or_constructor_type(value, bump)),
7857    swc_ast::TsType::TsTypeRef(value) => TsType::TsTypeRef(get_view_for_ts_type_ref(value, bump)),
7858    swc_ast::TsType::TsTypeQuery(value) => TsType::TsTypeQuery(get_view_for_ts_type_query(value, bump)),
7859    swc_ast::TsType::TsTypeLit(value) => TsType::TsTypeLit(get_view_for_ts_type_lit(value, bump)),
7860    swc_ast::TsType::TsArrayType(value) => TsType::TsArrayType(get_view_for_ts_array_type(value, bump)),
7861    swc_ast::TsType::TsTupleType(value) => TsType::TsTupleType(get_view_for_ts_tuple_type(value, bump)),
7862    swc_ast::TsType::TsOptionalType(value) => TsType::TsOptionalType(get_view_for_ts_optional_type(value, bump)),
7863    swc_ast::TsType::TsRestType(value) => TsType::TsRestType(get_view_for_ts_rest_type(value, bump)),
7864    swc_ast::TsType::TsUnionOrIntersectionType(value) => TsType::TsUnionOrIntersectionType(get_view_for_ts_union_or_intersection_type(value, bump)),
7865    swc_ast::TsType::TsConditionalType(value) => TsType::TsConditionalType(get_view_for_ts_conditional_type(value, bump)),
7866    swc_ast::TsType::TsInferType(value) => TsType::TsInferType(get_view_for_ts_infer_type(value, bump)),
7867    swc_ast::TsType::TsParenthesizedType(value) => TsType::TsParenthesizedType(get_view_for_ts_parenthesized_type(value, bump)),
7868    swc_ast::TsType::TsTypeOperator(value) => TsType::TsTypeOperator(get_view_for_ts_type_operator(value, bump)),
7869    swc_ast::TsType::TsIndexedAccessType(value) => TsType::TsIndexedAccessType(get_view_for_ts_indexed_access_type(value, bump)),
7870    swc_ast::TsType::TsMappedType(value) => TsType::TsMappedType(get_view_for_ts_mapped_type(value, bump)),
7871    swc_ast::TsType::TsLitType(value) => TsType::TsLitType(get_view_for_ts_lit_type(value, bump)),
7872    swc_ast::TsType::TsTypePredicate(value) => TsType::TsTypePredicate(get_view_for_ts_type_predicate(value, bump)),
7873    swc_ast::TsType::TsImportType(value) => TsType::TsImportType(get_view_for_ts_import_type(value, bump)),
7874  }
7875}
7876
7877fn set_parent_for_ts_type<'a>(node: &TsType<'a>, parent: Node<'a>) {
7878  match node {
7879    TsType::TsKeywordType(value) => set_parent_for_ts_keyword_type(value, parent),
7880    TsType::TsThisType(value) => set_parent_for_ts_this_type(value, parent),
7881    TsType::TsFnOrConstructorType(value) => set_parent_for_ts_fn_or_constructor_type(value, parent),
7882    TsType::TsTypeRef(value) => set_parent_for_ts_type_ref(value, parent),
7883    TsType::TsTypeQuery(value) => set_parent_for_ts_type_query(value, parent),
7884    TsType::TsTypeLit(value) => set_parent_for_ts_type_lit(value, parent),
7885    TsType::TsArrayType(value) => set_parent_for_ts_array_type(value, parent),
7886    TsType::TsTupleType(value) => set_parent_for_ts_tuple_type(value, parent),
7887    TsType::TsOptionalType(value) => set_parent_for_ts_optional_type(value, parent),
7888    TsType::TsRestType(value) => set_parent_for_ts_rest_type(value, parent),
7889    TsType::TsUnionOrIntersectionType(value) => set_parent_for_ts_union_or_intersection_type(value, parent),
7890    TsType::TsConditionalType(value) => set_parent_for_ts_conditional_type(value, parent),
7891    TsType::TsInferType(value) => set_parent_for_ts_infer_type(value, parent),
7892    TsType::TsParenthesizedType(value) => set_parent_for_ts_parenthesized_type(value, parent),
7893    TsType::TsTypeOperator(value) => set_parent_for_ts_type_operator(value, parent),
7894    TsType::TsIndexedAccessType(value) => set_parent_for_ts_indexed_access_type(value, parent),
7895    TsType::TsMappedType(value) => set_parent_for_ts_mapped_type(value, parent),
7896    TsType::TsLitType(value) => set_parent_for_ts_lit_type(value, parent),
7897    TsType::TsTypePredicate(value) => set_parent_for_ts_type_predicate(value, parent),
7898    TsType::TsImportType(value) => set_parent_for_ts_import_type(value, parent),
7899  }
7900}
7901
7902#[derive(Copy, Clone)]
7903pub enum TsTypeElement<'a> {
7904  TsCallSignatureDecl(&'a TsCallSignatureDecl<'a>),
7905  TsConstructSignatureDecl(&'a TsConstructSignatureDecl<'a>),
7906  TsPropertySignature(&'a TsPropertySignature<'a>),
7907  TsGetterSignature(&'a TsGetterSignature<'a>),
7908  TsSetterSignature(&'a TsSetterSignature<'a>),
7909  TsMethodSignature(&'a TsMethodSignature<'a>),
7910  TsIndexSignature(&'a TsIndexSignature<'a>),
7911}
7912
7913impl<'a> TsTypeElement<'a> {
7914  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
7915    T::to(&self.into())
7916  }
7917
7918  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
7919    let node: Node<'a> = self.into();
7920    if let Some(result) = T::to(&node) {
7921      result
7922    } else {
7923      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
7924    }
7925  }
7926
7927  pub fn is<T: CastableNode<'a>>(&self) -> bool {
7928    self.kind() == T::kind()
7929  }
7930  pub fn parent(&self) -> Node<'a> {
7931    NodeTrait::parent(self).unwrap()
7932  }
7933}
7934
7935impl<'a> SourceRanged for TsTypeElement<'a> {
7936  fn start(&self) -> SourcePos {
7937    match self {
7938      TsTypeElement::TsCallSignatureDecl(node) => node.start(),
7939      TsTypeElement::TsConstructSignatureDecl(node) => node.start(),
7940      TsTypeElement::TsPropertySignature(node) => node.start(),
7941      TsTypeElement::TsGetterSignature(node) => node.start(),
7942      TsTypeElement::TsSetterSignature(node) => node.start(),
7943      TsTypeElement::TsMethodSignature(node) => node.start(),
7944      TsTypeElement::TsIndexSignature(node) => node.start(),
7945    }
7946  }
7947  fn end(&self) -> SourcePos {
7948    match self {
7949      TsTypeElement::TsCallSignatureDecl(node) => node.end(),
7950      TsTypeElement::TsConstructSignatureDecl(node) => node.end(),
7951      TsTypeElement::TsPropertySignature(node) => node.end(),
7952      TsTypeElement::TsGetterSignature(node) => node.end(),
7953      TsTypeElement::TsSetterSignature(node) => node.end(),
7954      TsTypeElement::TsMethodSignature(node) => node.end(),
7955      TsTypeElement::TsIndexSignature(node) => node.end(),
7956    }
7957  }
7958}
7959
7960impl<'a> NodeTrait<'a> for TsTypeElement<'a> {
7961  fn parent(&self) -> Option<Node<'a>> {
7962    match self {
7963      TsTypeElement::TsCallSignatureDecl(node) => NodeTrait::parent(*node),
7964      TsTypeElement::TsConstructSignatureDecl(node) => NodeTrait::parent(*node),
7965      TsTypeElement::TsPropertySignature(node) => NodeTrait::parent(*node),
7966      TsTypeElement::TsGetterSignature(node) => NodeTrait::parent(*node),
7967      TsTypeElement::TsSetterSignature(node) => NodeTrait::parent(*node),
7968      TsTypeElement::TsMethodSignature(node) => NodeTrait::parent(*node),
7969      TsTypeElement::TsIndexSignature(node) => NodeTrait::parent(*node),
7970    }
7971  }
7972
7973  fn children(&self) -> Vec<Node<'a>> {
7974    match self {
7975      TsTypeElement::TsCallSignatureDecl(node) => node.children(),
7976      TsTypeElement::TsConstructSignatureDecl(node) => node.children(),
7977      TsTypeElement::TsPropertySignature(node) => node.children(),
7978      TsTypeElement::TsGetterSignature(node) => node.children(),
7979      TsTypeElement::TsSetterSignature(node) => node.children(),
7980      TsTypeElement::TsMethodSignature(node) => node.children(),
7981      TsTypeElement::TsIndexSignature(node) => node.children(),
7982    }
7983  }
7984
7985  fn as_node(&self) -> Node<'a> {
7986    match self {
7987      TsTypeElement::TsCallSignatureDecl(node) => node.as_node(),
7988      TsTypeElement::TsConstructSignatureDecl(node) => node.as_node(),
7989      TsTypeElement::TsPropertySignature(node) => node.as_node(),
7990      TsTypeElement::TsGetterSignature(node) => node.as_node(),
7991      TsTypeElement::TsSetterSignature(node) => node.as_node(),
7992      TsTypeElement::TsMethodSignature(node) => node.as_node(),
7993      TsTypeElement::TsIndexSignature(node) => node.as_node(),
7994    }
7995  }
7996
7997  fn kind(&self) -> NodeKind {
7998    match self {
7999      TsTypeElement::TsCallSignatureDecl(_) => NodeKind::TsCallSignatureDecl,
8000      TsTypeElement::TsConstructSignatureDecl(_) => NodeKind::TsConstructSignatureDecl,
8001      TsTypeElement::TsPropertySignature(_) => NodeKind::TsPropertySignature,
8002      TsTypeElement::TsGetterSignature(_) => NodeKind::TsGetterSignature,
8003      TsTypeElement::TsSetterSignature(_) => NodeKind::TsSetterSignature,
8004      TsTypeElement::TsMethodSignature(_) => NodeKind::TsMethodSignature,
8005      TsTypeElement::TsIndexSignature(_) => NodeKind::TsIndexSignature,
8006    }
8007  }
8008}
8009
8010impl<'a> From<&TsTypeElement<'a>> for Node<'a> {
8011  fn from(node: &TsTypeElement<'a>) -> Node<'a> {
8012    match node {
8013      TsTypeElement::TsCallSignatureDecl(node) => (*node).into(),
8014      TsTypeElement::TsConstructSignatureDecl(node) => (*node).into(),
8015      TsTypeElement::TsPropertySignature(node) => (*node).into(),
8016      TsTypeElement::TsGetterSignature(node) => (*node).into(),
8017      TsTypeElement::TsSetterSignature(node) => (*node).into(),
8018      TsTypeElement::TsMethodSignature(node) => (*node).into(),
8019      TsTypeElement::TsIndexSignature(node) => (*node).into(),
8020    }
8021  }
8022}
8023
8024impl<'a> From<TsTypeElement<'a>> for Node<'a> {
8025  fn from(node: TsTypeElement<'a>) -> Node<'a> {
8026    match node {
8027      TsTypeElement::TsCallSignatureDecl(node) => node.into(),
8028      TsTypeElement::TsConstructSignatureDecl(node) => node.into(),
8029      TsTypeElement::TsPropertySignature(node) => node.into(),
8030      TsTypeElement::TsGetterSignature(node) => node.into(),
8031      TsTypeElement::TsSetterSignature(node) => node.into(),
8032      TsTypeElement::TsMethodSignature(node) => node.into(),
8033      TsTypeElement::TsIndexSignature(node) => node.into(),
8034    }
8035  }
8036}
8037
8038fn get_view_for_ts_type_element<'a>(inner: &'a swc_ast::TsTypeElement, bump: &'a Bump) -> TsTypeElement<'a> {
8039  match inner {
8040    swc_ast::TsTypeElement::TsCallSignatureDecl(value) => TsTypeElement::TsCallSignatureDecl(get_view_for_ts_call_signature_decl(value, bump)),
8041    swc_ast::TsTypeElement::TsConstructSignatureDecl(value) => TsTypeElement::TsConstructSignatureDecl(get_view_for_ts_construct_signature_decl(value, bump)),
8042    swc_ast::TsTypeElement::TsPropertySignature(value) => TsTypeElement::TsPropertySignature(get_view_for_ts_property_signature(value, bump)),
8043    swc_ast::TsTypeElement::TsGetterSignature(value) => TsTypeElement::TsGetterSignature(get_view_for_ts_getter_signature(value, bump)),
8044    swc_ast::TsTypeElement::TsSetterSignature(value) => TsTypeElement::TsSetterSignature(get_view_for_ts_setter_signature(value, bump)),
8045    swc_ast::TsTypeElement::TsMethodSignature(value) => TsTypeElement::TsMethodSignature(get_view_for_ts_method_signature(value, bump)),
8046    swc_ast::TsTypeElement::TsIndexSignature(value) => TsTypeElement::TsIndexSignature(get_view_for_ts_index_signature(value, bump)),
8047  }
8048}
8049
8050fn set_parent_for_ts_type_element<'a>(node: &TsTypeElement<'a>, parent: Node<'a>) {
8051  match node {
8052    TsTypeElement::TsCallSignatureDecl(value) => set_parent_for_ts_call_signature_decl(value, parent),
8053    TsTypeElement::TsConstructSignatureDecl(value) => set_parent_for_ts_construct_signature_decl(value, parent),
8054    TsTypeElement::TsPropertySignature(value) => set_parent_for_ts_property_signature(value, parent),
8055    TsTypeElement::TsGetterSignature(value) => set_parent_for_ts_getter_signature(value, parent),
8056    TsTypeElement::TsSetterSignature(value) => set_parent_for_ts_setter_signature(value, parent),
8057    TsTypeElement::TsMethodSignature(value) => set_parent_for_ts_method_signature(value, parent),
8058    TsTypeElement::TsIndexSignature(value) => set_parent_for_ts_index_signature(value, parent),
8059  }
8060}
8061
8062#[derive(Copy, Clone)]
8063pub enum TsTypeQueryExpr<'a> {
8064  TsEntityName(TsEntityName<'a>),
8065  Import(&'a TsImportType<'a>),
8066}
8067
8068impl<'a> TsTypeQueryExpr<'a> {
8069  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
8070    T::to(&self.into())
8071  }
8072
8073  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
8074    let node: Node<'a> = self.into();
8075    if let Some(result) = T::to(&node) {
8076      result
8077    } else {
8078      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
8079    }
8080  }
8081
8082  pub fn is<T: CastableNode<'a>>(&self) -> bool {
8083    self.kind() == T::kind()
8084  }
8085}
8086
8087impl<'a> SourceRanged for TsTypeQueryExpr<'a> {
8088  fn start(&self) -> SourcePos {
8089    match self {
8090      TsTypeQueryExpr::TsEntityName(node) => node.start(),
8091      TsTypeQueryExpr::Import(node) => node.start(),
8092    }
8093  }
8094  fn end(&self) -> SourcePos {
8095    match self {
8096      TsTypeQueryExpr::TsEntityName(node) => node.end(),
8097      TsTypeQueryExpr::Import(node) => node.end(),
8098    }
8099  }
8100}
8101
8102impl<'a> NodeTrait<'a> for TsTypeQueryExpr<'a> {
8103  fn parent(&self) -> Option<Node<'a>> {
8104    match self {
8105      TsTypeQueryExpr::TsEntityName(node) => NodeTrait::parent(node),
8106      TsTypeQueryExpr::Import(node) => NodeTrait::parent(*node),
8107    }
8108  }
8109
8110  fn children(&self) -> Vec<Node<'a>> {
8111    match self {
8112      TsTypeQueryExpr::TsEntityName(node) => node.children(),
8113      TsTypeQueryExpr::Import(node) => node.children(),
8114    }
8115  }
8116
8117  fn as_node(&self) -> Node<'a> {
8118    match self {
8119      TsTypeQueryExpr::TsEntityName(node) => node.as_node(),
8120      TsTypeQueryExpr::Import(node) => node.as_node(),
8121    }
8122  }
8123
8124  fn kind(&self) -> NodeKind {
8125    match self {
8126      TsTypeQueryExpr::TsEntityName(node) => node.kind(),
8127      TsTypeQueryExpr::Import(_) => NodeKind::TsImportType,
8128    }
8129  }
8130}
8131
8132impl<'a> From<&TsTypeQueryExpr<'a>> for Node<'a> {
8133  fn from(node: &TsTypeQueryExpr<'a>) -> Node<'a> {
8134    match node {
8135      TsTypeQueryExpr::TsEntityName(node) => node.into(),
8136      TsTypeQueryExpr::Import(node) => (*node).into(),
8137    }
8138  }
8139}
8140
8141impl<'a> From<TsTypeQueryExpr<'a>> for Node<'a> {
8142  fn from(node: TsTypeQueryExpr<'a>) -> Node<'a> {
8143    match node {
8144      TsTypeQueryExpr::TsEntityName(node) => node.into(),
8145      TsTypeQueryExpr::Import(node) => node.into(),
8146    }
8147  }
8148}
8149
8150fn get_view_for_ts_type_query_expr<'a>(inner: &'a swc_ast::TsTypeQueryExpr, bump: &'a Bump) -> TsTypeQueryExpr<'a> {
8151  match inner {
8152    swc_ast::TsTypeQueryExpr::TsEntityName(value) => TsTypeQueryExpr::TsEntityName(get_view_for_ts_entity_name(value, bump)),
8153    swc_ast::TsTypeQueryExpr::Import(value) => TsTypeQueryExpr::Import(get_view_for_ts_import_type(value, bump)),
8154  }
8155}
8156
8157fn set_parent_for_ts_type_query_expr<'a>(node: &TsTypeQueryExpr<'a>, parent: Node<'a>) {
8158  match node {
8159    TsTypeQueryExpr::TsEntityName(value) => set_parent_for_ts_entity_name(value, parent),
8160    TsTypeQueryExpr::Import(value) => set_parent_for_ts_import_type(value, parent),
8161  }
8162}
8163
8164#[derive(Copy, Clone)]
8165pub enum TsUnionOrIntersectionType<'a> {
8166  TsUnionType(&'a TsUnionType<'a>),
8167  TsIntersectionType(&'a TsIntersectionType<'a>),
8168}
8169
8170impl<'a> TsUnionOrIntersectionType<'a> {
8171  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
8172    T::to(&self.into())
8173  }
8174
8175  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
8176    let node: Node<'a> = self.into();
8177    if let Some(result) = T::to(&node) {
8178      result
8179    } else {
8180      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
8181    }
8182  }
8183
8184  pub fn is<T: CastableNode<'a>>(&self) -> bool {
8185    self.kind() == T::kind()
8186  }
8187  pub fn parent(&self) -> Node<'a> {
8188    NodeTrait::parent(self).unwrap()
8189  }
8190}
8191
8192impl<'a> SourceRanged for TsUnionOrIntersectionType<'a> {
8193  fn start(&self) -> SourcePos {
8194    match self {
8195      TsUnionOrIntersectionType::TsUnionType(node) => node.start(),
8196      TsUnionOrIntersectionType::TsIntersectionType(node) => node.start(),
8197    }
8198  }
8199  fn end(&self) -> SourcePos {
8200    match self {
8201      TsUnionOrIntersectionType::TsUnionType(node) => node.end(),
8202      TsUnionOrIntersectionType::TsIntersectionType(node) => node.end(),
8203    }
8204  }
8205}
8206
8207impl<'a> NodeTrait<'a> for TsUnionOrIntersectionType<'a> {
8208  fn parent(&self) -> Option<Node<'a>> {
8209    match self {
8210      TsUnionOrIntersectionType::TsUnionType(node) => NodeTrait::parent(*node),
8211      TsUnionOrIntersectionType::TsIntersectionType(node) => NodeTrait::parent(*node),
8212    }
8213  }
8214
8215  fn children(&self) -> Vec<Node<'a>> {
8216    match self {
8217      TsUnionOrIntersectionType::TsUnionType(node) => node.children(),
8218      TsUnionOrIntersectionType::TsIntersectionType(node) => node.children(),
8219    }
8220  }
8221
8222  fn as_node(&self) -> Node<'a> {
8223    match self {
8224      TsUnionOrIntersectionType::TsUnionType(node) => node.as_node(),
8225      TsUnionOrIntersectionType::TsIntersectionType(node) => node.as_node(),
8226    }
8227  }
8228
8229  fn kind(&self) -> NodeKind {
8230    match self {
8231      TsUnionOrIntersectionType::TsUnionType(_) => NodeKind::TsUnionType,
8232      TsUnionOrIntersectionType::TsIntersectionType(_) => NodeKind::TsIntersectionType,
8233    }
8234  }
8235}
8236
8237impl<'a> From<&TsUnionOrIntersectionType<'a>> for Node<'a> {
8238  fn from(node: &TsUnionOrIntersectionType<'a>) -> Node<'a> {
8239    match node {
8240      TsUnionOrIntersectionType::TsUnionType(node) => (*node).into(),
8241      TsUnionOrIntersectionType::TsIntersectionType(node) => (*node).into(),
8242    }
8243  }
8244}
8245
8246impl<'a> From<TsUnionOrIntersectionType<'a>> for Node<'a> {
8247  fn from(node: TsUnionOrIntersectionType<'a>) -> Node<'a> {
8248    match node {
8249      TsUnionOrIntersectionType::TsUnionType(node) => node.into(),
8250      TsUnionOrIntersectionType::TsIntersectionType(node) => node.into(),
8251    }
8252  }
8253}
8254
8255fn get_view_for_ts_union_or_intersection_type<'a>(inner: &'a swc_ast::TsUnionOrIntersectionType, bump: &'a Bump) -> TsUnionOrIntersectionType<'a> {
8256  match inner {
8257    swc_ast::TsUnionOrIntersectionType::TsUnionType(value) => TsUnionOrIntersectionType::TsUnionType(get_view_for_ts_union_type(value, bump)),
8258    swc_ast::TsUnionOrIntersectionType::TsIntersectionType(value) => TsUnionOrIntersectionType::TsIntersectionType(get_view_for_ts_intersection_type(value, bump)),
8259  }
8260}
8261
8262fn set_parent_for_ts_union_or_intersection_type<'a>(node: &TsUnionOrIntersectionType<'a>, parent: Node<'a>) {
8263  match node {
8264    TsUnionOrIntersectionType::TsUnionType(value) => set_parent_for_ts_union_type(value, parent),
8265    TsUnionOrIntersectionType::TsIntersectionType(value) => set_parent_for_ts_intersection_type(value, parent),
8266  }
8267}
8268
8269#[derive(Copy, Clone)]
8270pub enum VarDeclOrExpr<'a> {
8271  VarDecl(&'a VarDecl<'a>),
8272  Expr(Expr<'a>),
8273}
8274
8275impl<'a> VarDeclOrExpr<'a> {
8276  pub fn to<T: CastableNode<'a>>(&self) -> Option<&'a T> {
8277    T::to(&self.into())
8278  }
8279
8280  pub fn expect<T: CastableNode<'a>>(&self) -> &'a T {
8281    let node: Node<'a> = self.into();
8282    if let Some(result) = T::to(&node) {
8283      result
8284    } else {
8285      panic!("Tried to cast node of type {} to {}.", node.kind(), T::kind())
8286    }
8287  }
8288
8289  pub fn is<T: CastableNode<'a>>(&self) -> bool {
8290    self.kind() == T::kind()
8291  }
8292}
8293
8294impl<'a> SourceRanged for VarDeclOrExpr<'a> {
8295  fn start(&self) -> SourcePos {
8296    match self {
8297      VarDeclOrExpr::VarDecl(node) => node.start(),
8298      VarDeclOrExpr::Expr(node) => node.start(),
8299    }
8300  }
8301  fn end(&self) -> SourcePos {
8302    match self {
8303      VarDeclOrExpr::VarDecl(node) => node.end(),
8304      VarDeclOrExpr::Expr(node) => node.end(),
8305    }
8306  }
8307}
8308
8309impl<'a> NodeTrait<'a> for VarDeclOrExpr<'a> {
8310  fn parent(&self) -> Option<Node<'a>> {
8311    match self {
8312      VarDeclOrExpr::VarDecl(node) => NodeTrait::parent(*node),
8313      VarDeclOrExpr::Expr(node) => NodeTrait::parent(node),
8314    }
8315  }
8316
8317  fn children(&self) -> Vec<Node<'a>> {
8318    match self {
8319      VarDeclOrExpr::VarDecl(node) => node.children(),
8320      VarDeclOrExpr::Expr(node) => node.children(),
8321    }
8322  }
8323
8324  fn as_node(&self) -> Node<'a> {
8325    match self {
8326      VarDeclOrExpr::VarDecl(node) => node.as_node(),
8327      VarDeclOrExpr::Expr(node) => node.as_node(),
8328    }
8329  }
8330
8331  fn kind(&self) -> NodeKind {
8332    match self {
8333      VarDeclOrExpr::VarDecl(_) => NodeKind::VarDecl,
8334      VarDeclOrExpr::Expr(node) => node.kind(),
8335    }
8336  }
8337}
8338
8339impl<'a> From<&VarDeclOrExpr<'a>> for Node<'a> {
8340  fn from(node: &VarDeclOrExpr<'a>) -> Node<'a> {
8341    match node {
8342      VarDeclOrExpr::VarDecl(node) => (*node).into(),
8343      VarDeclOrExpr::Expr(node) => node.into(),
8344    }
8345  }
8346}
8347
8348impl<'a> From<VarDeclOrExpr<'a>> for Node<'a> {
8349  fn from(node: VarDeclOrExpr<'a>) -> Node<'a> {
8350    match node {
8351      VarDeclOrExpr::VarDecl(node) => node.into(),
8352      VarDeclOrExpr::Expr(node) => node.into(),
8353    }
8354  }
8355}
8356
8357fn get_view_for_var_decl_or_expr<'a>(inner: &'a swc_ast::VarDeclOrExpr, bump: &'a Bump) -> VarDeclOrExpr<'a> {
8358  match inner {
8359    swc_ast::VarDeclOrExpr::VarDecl(value) => VarDeclOrExpr::VarDecl(get_view_for_var_decl(value, bump)),
8360    swc_ast::VarDeclOrExpr::Expr(value) => VarDeclOrExpr::Expr(get_view_for_expr(value, bump)),
8361  }
8362}
8363
8364fn set_parent_for_var_decl_or_expr<'a>(node: &VarDeclOrExpr<'a>, parent: Node<'a>) {
8365  match node {
8366    VarDeclOrExpr::VarDecl(value) => set_parent_for_var_decl(value, parent),
8367    VarDeclOrExpr::Expr(value) => set_parent_for_expr(value, parent),
8368  }
8369}
8370
8371/// Array literal.
8372#[derive(Clone)]
8373pub struct ArrayLit<'a> {
8374  parent: ParentOnceCell<Node<'a>>,
8375  pub inner: &'a swc_ast::ArrayLit,
8376  pub elems: &'a [Option<&'a ExprOrSpread<'a>>],
8377}
8378
8379impl<'a> ArrayLit<'a> {
8380  pub fn parent(&self) -> Node<'a> {
8381    self.parent.get().unwrap()
8382  }
8383}
8384
8385impl<'a> SourceRanged for ArrayLit<'a> {
8386  fn start(&self) -> SourcePos {
8387    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8388  }
8389  fn end(&self) -> SourcePos {
8390    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8391  }
8392}
8393
8394impl<'a> From<&ArrayLit<'a>> for Node<'a> {
8395  fn from(node: &ArrayLit<'a>) -> Node<'a> {
8396    let node = unsafe { mem::transmute::<&ArrayLit<'a>, &'a ArrayLit<'a>>(node) };
8397    Node::ArrayLit(node)
8398  }
8399}
8400
8401impl<'a> NodeTrait<'a> for ArrayLit<'a> {
8402  fn parent(&self) -> Option<Node<'a>> {
8403    Some(self.parent.get().unwrap().clone())
8404  }
8405
8406  fn children(&self) -> Vec<Node<'a>> {
8407    let mut children = Vec::with_capacity(self.elems.len());
8408    for child in self.elems.iter() {
8409      if let Some(child) = child {
8410        children.push((*child).into());
8411      }
8412    }
8413    children
8414  }
8415
8416  fn as_node(&self) -> Node<'a> {
8417    self.into()
8418  }
8419
8420  fn kind(&self) -> NodeKind {
8421    NodeKind::ArrayLit
8422  }
8423}
8424
8425impl<'a> CastableNode<'a> for ArrayLit<'a> {
8426  fn to(node: &Node<'a>) -> Option<&'a Self> {
8427    if let Node::ArrayLit(node) = node {
8428      Some(node)
8429    } else {
8430      None
8431    }
8432  }
8433
8434  fn kind() -> NodeKind {
8435    NodeKind::ArrayLit
8436  }
8437}
8438
8439fn get_view_for_array_lit<'a>(inner: &'a swc_ast::ArrayLit, bump: &'a Bump) -> &'a ArrayLit<'a> {
8440  let node = bump.alloc(ArrayLit {
8441    inner,
8442    parent: Default::default(),
8443    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 {
8444      Some(value) => Some(get_view_for_expr_or_spread(value, bump)),
8445      None => None,
8446    })); vec }),
8447  });
8448  let parent: Node<'a> = (&*node).into();
8449  for value in node.elems.iter() {
8450    if let Some(value) = value {
8451      set_parent_for_expr_or_spread(value, parent)
8452    }
8453  }
8454  node
8455}
8456
8457fn set_parent_for_array_lit<'a>(node: &ArrayLit<'a>, parent: Node<'a>) {
8458  node.parent.set(parent);
8459}
8460
8461#[derive(Clone)]
8462pub struct ArrayPat<'a> {
8463  parent: ParentOnceCell<Node<'a>>,
8464  pub inner: &'a swc_ast::ArrayPat,
8465  pub elems: &'a [Option<Pat<'a>>],
8466  pub type_ann: Option<&'a TsTypeAnn<'a>>,
8467}
8468
8469impl<'a> ArrayPat<'a> {
8470  pub fn parent(&self) -> Node<'a> {
8471    self.parent.get().unwrap()
8472  }
8473
8474  /// Only in an ambient context
8475  pub fn optional(&self) -> bool {
8476    self.inner.optional
8477  }
8478}
8479
8480impl<'a> SourceRanged for ArrayPat<'a> {
8481  fn start(&self) -> SourcePos {
8482    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8483  }
8484  fn end(&self) -> SourcePos {
8485    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8486  }
8487}
8488
8489impl<'a> From<&ArrayPat<'a>> for Node<'a> {
8490  fn from(node: &ArrayPat<'a>) -> Node<'a> {
8491    let node = unsafe { mem::transmute::<&ArrayPat<'a>, &'a ArrayPat<'a>>(node) };
8492    Node::ArrayPat(node)
8493  }
8494}
8495
8496impl<'a> NodeTrait<'a> for ArrayPat<'a> {
8497  fn parent(&self) -> Option<Node<'a>> {
8498    Some(self.parent.get().unwrap().clone())
8499  }
8500
8501  fn children(&self) -> Vec<Node<'a>> {
8502    let mut children = Vec::with_capacity(self.elems.len() + match &self.type_ann { Some(_value) => 1, None => 0, });
8503    for child in self.elems.iter() {
8504      if let Some(child) = child.as_ref() {
8505        children.push(child.into());
8506      }
8507    }
8508    if let Some(child) = self.type_ann {
8509      children.push(child.into());
8510    }
8511    children
8512  }
8513
8514  fn as_node(&self) -> Node<'a> {
8515    self.into()
8516  }
8517
8518  fn kind(&self) -> NodeKind {
8519    NodeKind::ArrayPat
8520  }
8521}
8522
8523impl<'a> CastableNode<'a> for ArrayPat<'a> {
8524  fn to(node: &Node<'a>) -> Option<&'a Self> {
8525    if let Node::ArrayPat(node) = node {
8526      Some(node)
8527    } else {
8528      None
8529    }
8530  }
8531
8532  fn kind() -> NodeKind {
8533    NodeKind::ArrayPat
8534  }
8535}
8536
8537fn get_view_for_array_pat<'a>(inner: &'a swc_ast::ArrayPat, bump: &'a Bump) -> &'a ArrayPat<'a> {
8538  let node = bump.alloc(ArrayPat {
8539    inner,
8540    parent: Default::default(),
8541    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 {
8542      Some(value) => Some(get_view_for_pat(value, bump)),
8543      None => None,
8544    })); vec }),
8545    type_ann: match &inner.type_ann {
8546      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
8547      None => None,
8548    },
8549  });
8550  let parent: Node<'a> = (&*node).into();
8551  for value in node.elems.iter() {
8552    if let Some(value) = value {
8553      set_parent_for_pat(value, parent)
8554    }
8555  }
8556  if let Some(value) = &node.type_ann {
8557    set_parent_for_ts_type_ann(value, parent)
8558  };
8559  node
8560}
8561
8562fn set_parent_for_array_pat<'a>(node: &ArrayPat<'a>, parent: Node<'a>) {
8563  node.parent.set(parent);
8564}
8565
8566#[derive(Clone)]
8567pub struct ArrowExpr<'a> {
8568  parent: ParentOnceCell<Node<'a>>,
8569  pub inner: &'a swc_ast::ArrowExpr,
8570  pub params: &'a [Pat<'a>],
8571  /// This is boxed to reduce the type size of [Expr].
8572  pub body: BlockStmtOrExpr<'a>,
8573  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
8574  pub return_type: Option<&'a TsTypeAnn<'a>>,
8575}
8576
8577impl<'a> ArrowExpr<'a> {
8578  pub fn parent(&self) -> Node<'a> {
8579    self.parent.get().unwrap()
8580  }
8581
8582  pub fn ctxt(&self) -> swc_common::SyntaxContext {
8583    self.inner.ctxt
8584  }
8585
8586  pub fn is_async(&self) -> bool {
8587    self.inner.is_async
8588  }
8589
8590  pub fn is_generator(&self) -> bool {
8591    self.inner.is_generator
8592  }
8593}
8594
8595impl<'a> SourceRanged for ArrowExpr<'a> {
8596  fn start(&self) -> SourcePos {
8597    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8598  }
8599  fn end(&self) -> SourcePos {
8600    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8601  }
8602}
8603
8604impl<'a> From<&ArrowExpr<'a>> for Node<'a> {
8605  fn from(node: &ArrowExpr<'a>) -> Node<'a> {
8606    let node = unsafe { mem::transmute::<&ArrowExpr<'a>, &'a ArrowExpr<'a>>(node) };
8607    Node::ArrowExpr(node)
8608  }
8609}
8610
8611impl<'a> NodeTrait<'a> for ArrowExpr<'a> {
8612  fn parent(&self) -> Option<Node<'a>> {
8613    Some(self.parent.get().unwrap().clone())
8614  }
8615
8616  fn children(&self) -> Vec<Node<'a>> {
8617    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, });
8618    for child in self.params.iter() {
8619      children.push(child.into());
8620    }
8621    children.push((&self.body).into());
8622    if let Some(child) = self.type_params {
8623      children.push(child.into());
8624    }
8625    if let Some(child) = self.return_type {
8626      children.push(child.into());
8627    }
8628    children
8629  }
8630
8631  fn as_node(&self) -> Node<'a> {
8632    self.into()
8633  }
8634
8635  fn kind(&self) -> NodeKind {
8636    NodeKind::ArrowExpr
8637  }
8638}
8639
8640impl<'a> CastableNode<'a> for ArrowExpr<'a> {
8641  fn to(node: &Node<'a>) -> Option<&'a Self> {
8642    if let Node::ArrowExpr(node) = node {
8643      Some(node)
8644    } else {
8645      None
8646    }
8647  }
8648
8649  fn kind() -> NodeKind {
8650    NodeKind::ArrowExpr
8651  }
8652}
8653
8654fn get_view_for_arrow_expr<'a>(inner: &'a swc_ast::ArrowExpr, bump: &'a Bump) -> &'a ArrowExpr<'a> {
8655  let node = bump.alloc(ArrowExpr {
8656    inner,
8657    parent: Default::default(),
8658    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 }),
8659    body: get_view_for_block_stmt_or_expr(&inner.body, bump),
8660    type_params: match &inner.type_params {
8661      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
8662      None => None,
8663    },
8664    return_type: match &inner.return_type {
8665      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
8666      None => None,
8667    },
8668  });
8669  let parent: Node<'a> = (&*node).into();
8670  for value in node.params.iter() {
8671    set_parent_for_pat(value, parent)
8672  }
8673  set_parent_for_block_stmt_or_expr(&node.body, parent);
8674  if let Some(value) = &node.type_params {
8675    set_parent_for_ts_type_param_decl(value, parent)
8676  };
8677  if let Some(value) = &node.return_type {
8678    set_parent_for_ts_type_ann(value, parent)
8679  };
8680  node
8681}
8682
8683fn set_parent_for_arrow_expr<'a>(node: &ArrowExpr<'a>, parent: Node<'a>) {
8684  node.parent.set(parent);
8685}
8686
8687#[derive(Clone)]
8688pub struct AssignExpr<'a> {
8689  parent: ParentOnceCell<Node<'a>>,
8690  pub inner: &'a swc_ast::AssignExpr,
8691  pub left: AssignTarget<'a>,
8692  pub right: Expr<'a>,
8693}
8694
8695impl<'a> AssignExpr<'a> {
8696  pub fn parent(&self) -> Node<'a> {
8697    self.parent.get().unwrap()
8698  }
8699
8700  pub fn op(&self) -> AssignOp {
8701    self.inner.op
8702  }
8703}
8704
8705impl<'a> SourceRanged for AssignExpr<'a> {
8706  fn start(&self) -> SourcePos {
8707    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8708  }
8709  fn end(&self) -> SourcePos {
8710    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8711  }
8712}
8713
8714impl<'a> From<&AssignExpr<'a>> for Node<'a> {
8715  fn from(node: &AssignExpr<'a>) -> Node<'a> {
8716    let node = unsafe { mem::transmute::<&AssignExpr<'a>, &'a AssignExpr<'a>>(node) };
8717    Node::AssignExpr(node)
8718  }
8719}
8720
8721impl<'a> NodeTrait<'a> for AssignExpr<'a> {
8722  fn parent(&self) -> Option<Node<'a>> {
8723    Some(self.parent.get().unwrap().clone())
8724  }
8725
8726  fn children(&self) -> Vec<Node<'a>> {
8727    let mut children = Vec::with_capacity(2);
8728    children.push((&self.left).into());
8729    children.push((&self.right).into());
8730    children
8731  }
8732
8733  fn as_node(&self) -> Node<'a> {
8734    self.into()
8735  }
8736
8737  fn kind(&self) -> NodeKind {
8738    NodeKind::AssignExpr
8739  }
8740}
8741
8742impl<'a> CastableNode<'a> for AssignExpr<'a> {
8743  fn to(node: &Node<'a>) -> Option<&'a Self> {
8744    if let Node::AssignExpr(node) = node {
8745      Some(node)
8746    } else {
8747      None
8748    }
8749  }
8750
8751  fn kind() -> NodeKind {
8752    NodeKind::AssignExpr
8753  }
8754}
8755
8756fn get_view_for_assign_expr<'a>(inner: &'a swc_ast::AssignExpr, bump: &'a Bump) -> &'a AssignExpr<'a> {
8757  let node = bump.alloc(AssignExpr {
8758    inner,
8759    parent: Default::default(),
8760    left: get_view_for_assign_target(&inner.left, bump),
8761    right: get_view_for_expr(&inner.right, bump),
8762  });
8763  let parent: Node<'a> = (&*node).into();
8764  set_parent_for_assign_target(&node.left, parent);
8765  set_parent_for_expr(&node.right, parent);
8766  node
8767}
8768
8769fn set_parent_for_assign_expr<'a>(node: &AssignExpr<'a>, parent: Node<'a>) {
8770  node.parent.set(parent);
8771}
8772
8773#[derive(Clone)]
8774pub struct AssignPat<'a> {
8775  parent: ParentOnceCell<Node<'a>>,
8776  pub inner: &'a swc_ast::AssignPat,
8777  pub left: Pat<'a>,
8778  pub right: Expr<'a>,
8779}
8780
8781impl<'a> AssignPat<'a> {
8782  pub fn parent(&self) -> Node<'a> {
8783    self.parent.get().unwrap()
8784  }
8785}
8786
8787impl<'a> SourceRanged for AssignPat<'a> {
8788  fn start(&self) -> SourcePos {
8789    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8790  }
8791  fn end(&self) -> SourcePos {
8792    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8793  }
8794}
8795
8796impl<'a> From<&AssignPat<'a>> for Node<'a> {
8797  fn from(node: &AssignPat<'a>) -> Node<'a> {
8798    let node = unsafe { mem::transmute::<&AssignPat<'a>, &'a AssignPat<'a>>(node) };
8799    Node::AssignPat(node)
8800  }
8801}
8802
8803impl<'a> NodeTrait<'a> for AssignPat<'a> {
8804  fn parent(&self) -> Option<Node<'a>> {
8805    Some(self.parent.get().unwrap().clone())
8806  }
8807
8808  fn children(&self) -> Vec<Node<'a>> {
8809    let mut children = Vec::with_capacity(2);
8810    children.push((&self.left).into());
8811    children.push((&self.right).into());
8812    children
8813  }
8814
8815  fn as_node(&self) -> Node<'a> {
8816    self.into()
8817  }
8818
8819  fn kind(&self) -> NodeKind {
8820    NodeKind::AssignPat
8821  }
8822}
8823
8824impl<'a> CastableNode<'a> for AssignPat<'a> {
8825  fn to(node: &Node<'a>) -> Option<&'a Self> {
8826    if let Node::AssignPat(node) = node {
8827      Some(node)
8828    } else {
8829      None
8830    }
8831  }
8832
8833  fn kind() -> NodeKind {
8834    NodeKind::AssignPat
8835  }
8836}
8837
8838fn get_view_for_assign_pat<'a>(inner: &'a swc_ast::AssignPat, bump: &'a Bump) -> &'a AssignPat<'a> {
8839  let node = bump.alloc(AssignPat {
8840    inner,
8841    parent: Default::default(),
8842    left: get_view_for_pat(&inner.left, bump),
8843    right: get_view_for_expr(&inner.right, bump),
8844  });
8845  let parent: Node<'a> = (&*node).into();
8846  set_parent_for_pat(&node.left, parent);
8847  set_parent_for_expr(&node.right, parent);
8848  node
8849}
8850
8851fn set_parent_for_assign_pat<'a>(node: &AssignPat<'a>, parent: Node<'a>) {
8852  node.parent.set(parent);
8853}
8854
8855/// `{key}` or `{key = value}`
8856#[derive(Clone)]
8857pub struct AssignPatProp<'a> {
8858  parent: ParentOnceCell<&'a ObjectPat<'a>>,
8859  pub inner: &'a swc_ast::AssignPatProp,
8860  /// Note: This type is to help implementing visitor and the field `type_ann`
8861  /// is always [None].
8862  pub key: &'a BindingIdent<'a>,
8863  pub value: Option<Expr<'a>>,
8864}
8865
8866impl<'a> AssignPatProp<'a> {
8867  pub fn parent(&self) -> &'a ObjectPat<'a> {
8868    self.parent.get().unwrap()
8869  }
8870}
8871
8872impl<'a> SourceRanged for AssignPatProp<'a> {
8873  fn start(&self) -> SourcePos {
8874    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8875  }
8876  fn end(&self) -> SourcePos {
8877    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8878  }
8879}
8880
8881impl<'a> From<&AssignPatProp<'a>> for Node<'a> {
8882  fn from(node: &AssignPatProp<'a>) -> Node<'a> {
8883    let node = unsafe { mem::transmute::<&AssignPatProp<'a>, &'a AssignPatProp<'a>>(node) };
8884    Node::AssignPatProp(node)
8885  }
8886}
8887
8888impl<'a> NodeTrait<'a> for AssignPatProp<'a> {
8889  fn parent(&self) -> Option<Node<'a>> {
8890    Some(self.parent.get().unwrap().into())
8891  }
8892
8893  fn children(&self) -> Vec<Node<'a>> {
8894    let mut children = Vec::with_capacity(1 + match &self.value { Some(_value) => 1, None => 0, });
8895    children.push(self.key.into());
8896    if let Some(child) = self.value.as_ref() {
8897      children.push(child.into());
8898    }
8899    children
8900  }
8901
8902  fn as_node(&self) -> Node<'a> {
8903    self.into()
8904  }
8905
8906  fn kind(&self) -> NodeKind {
8907    NodeKind::AssignPatProp
8908  }
8909}
8910
8911impl<'a> CastableNode<'a> for AssignPatProp<'a> {
8912  fn to(node: &Node<'a>) -> Option<&'a Self> {
8913    if let Node::AssignPatProp(node) = node {
8914      Some(node)
8915    } else {
8916      None
8917    }
8918  }
8919
8920  fn kind() -> NodeKind {
8921    NodeKind::AssignPatProp
8922  }
8923}
8924
8925fn get_view_for_assign_pat_prop<'a>(inner: &'a swc_ast::AssignPatProp, bump: &'a Bump) -> &'a AssignPatProp<'a> {
8926  let node = bump.alloc(AssignPatProp {
8927    inner,
8928    parent: Default::default(),
8929    key: get_view_for_binding_ident(&inner.key, bump),
8930    value: match &inner.value {
8931      Some(value) => Some(get_view_for_expr(value, bump)),
8932      None => None,
8933    },
8934  });
8935  let parent: Node<'a> = (&*node).into();
8936  set_parent_for_binding_ident(&node.key, parent);
8937  if let Some(value) = &node.value {
8938    set_parent_for_expr(value, parent)
8939  };
8940  node
8941}
8942
8943fn set_parent_for_assign_pat_prop<'a>(node: &AssignPatProp<'a>, parent: Node<'a>) {
8944  node.parent.set(parent.expect::<ObjectPat>());
8945}
8946
8947#[derive(Clone)]
8948pub struct AssignProp<'a> {
8949  parent: ParentOnceCell<&'a ObjectLit<'a>>,
8950  pub inner: &'a swc_ast::AssignProp,
8951  pub key: &'a Ident<'a>,
8952  pub value: Expr<'a>,
8953}
8954
8955impl<'a> AssignProp<'a> {
8956  pub fn parent(&self) -> &'a ObjectLit<'a> {
8957    self.parent.get().unwrap()
8958  }
8959}
8960
8961impl<'a> SourceRanged for AssignProp<'a> {
8962  fn start(&self) -> SourcePos {
8963    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
8964  }
8965  fn end(&self) -> SourcePos {
8966    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
8967  }
8968}
8969
8970impl<'a> From<&AssignProp<'a>> for Node<'a> {
8971  fn from(node: &AssignProp<'a>) -> Node<'a> {
8972    let node = unsafe { mem::transmute::<&AssignProp<'a>, &'a AssignProp<'a>>(node) };
8973    Node::AssignProp(node)
8974  }
8975}
8976
8977impl<'a> NodeTrait<'a> for AssignProp<'a> {
8978  fn parent(&self) -> Option<Node<'a>> {
8979    Some(self.parent.get().unwrap().into())
8980  }
8981
8982  fn children(&self) -> Vec<Node<'a>> {
8983    let mut children = Vec::with_capacity(2);
8984    children.push(self.key.into());
8985    children.push((&self.value).into());
8986    children
8987  }
8988
8989  fn as_node(&self) -> Node<'a> {
8990    self.into()
8991  }
8992
8993  fn kind(&self) -> NodeKind {
8994    NodeKind::AssignProp
8995  }
8996}
8997
8998impl<'a> CastableNode<'a> for AssignProp<'a> {
8999  fn to(node: &Node<'a>) -> Option<&'a Self> {
9000    if let Node::AssignProp(node) = node {
9001      Some(node)
9002    } else {
9003      None
9004    }
9005  }
9006
9007  fn kind() -> NodeKind {
9008    NodeKind::AssignProp
9009  }
9010}
9011
9012fn get_view_for_assign_prop<'a>(inner: &'a swc_ast::AssignProp, bump: &'a Bump) -> &'a AssignProp<'a> {
9013  let node = bump.alloc(AssignProp {
9014    inner,
9015    parent: Default::default(),
9016    key: get_view_for_ident(&inner.key, bump),
9017    value: get_view_for_expr(&inner.value, bump),
9018  });
9019  let parent: Node<'a> = (&*node).into();
9020  set_parent_for_ident(&node.key, parent);
9021  set_parent_for_expr(&node.value, parent);
9022  node
9023}
9024
9025fn set_parent_for_assign_prop<'a>(node: &AssignProp<'a>, parent: Node<'a>) {
9026  node.parent.set(parent.expect::<ObjectLit>());
9027}
9028
9029#[derive(Clone)]
9030pub struct AutoAccessor<'a> {
9031  parent: ParentOnceCell<&'a Class<'a>>,
9032  pub inner: &'a swc_ast::AutoAccessor,
9033  pub key: Key<'a>,
9034  pub value: Option<Expr<'a>>,
9035  pub type_ann: Option<&'a TsTypeAnn<'a>>,
9036  pub decorators: &'a [&'a Decorator<'a>],
9037}
9038
9039impl<'a> AutoAccessor<'a> {
9040  pub fn parent(&self) -> &'a Class<'a> {
9041    self.parent.get().unwrap()
9042  }
9043
9044  pub fn is_static(&self) -> bool {
9045    self.inner.is_static
9046  }
9047
9048  /// Typescript extension.
9049  pub fn accessibility(&self) -> Option<Accessibility> {
9050    self.inner.accessibility
9051  }
9052
9053  pub fn is_abstract(&self) -> bool {
9054    self.inner.is_abstract
9055  }
9056
9057  pub fn is_override(&self) -> bool {
9058    self.inner.is_override
9059  }
9060
9061  pub fn definite(&self) -> bool {
9062    self.inner.definite
9063  }
9064}
9065
9066impl<'a> SourceRanged for AutoAccessor<'a> {
9067  fn start(&self) -> SourcePos {
9068    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9069  }
9070  fn end(&self) -> SourcePos {
9071    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9072  }
9073}
9074
9075impl<'a> From<&AutoAccessor<'a>> for Node<'a> {
9076  fn from(node: &AutoAccessor<'a>) -> Node<'a> {
9077    let node = unsafe { mem::transmute::<&AutoAccessor<'a>, &'a AutoAccessor<'a>>(node) };
9078    Node::AutoAccessor(node)
9079  }
9080}
9081
9082impl<'a> NodeTrait<'a> for AutoAccessor<'a> {
9083  fn parent(&self) -> Option<Node<'a>> {
9084    Some(self.parent.get().unwrap().into())
9085  }
9086
9087  fn children(&self) -> Vec<Node<'a>> {
9088    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());
9089    children.push((&self.key).into());
9090    if let Some(child) = self.value.as_ref() {
9091      children.push(child.into());
9092    }
9093    if let Some(child) = self.type_ann {
9094      children.push(child.into());
9095    }
9096    for child in self.decorators.iter() {
9097      children.push((*child).into());
9098    }
9099    children
9100  }
9101
9102  fn as_node(&self) -> Node<'a> {
9103    self.into()
9104  }
9105
9106  fn kind(&self) -> NodeKind {
9107    NodeKind::AutoAccessor
9108  }
9109}
9110
9111impl<'a> CastableNode<'a> for AutoAccessor<'a> {
9112  fn to(node: &Node<'a>) -> Option<&'a Self> {
9113    if let Node::AutoAccessor(node) = node {
9114      Some(node)
9115    } else {
9116      None
9117    }
9118  }
9119
9120  fn kind() -> NodeKind {
9121    NodeKind::AutoAccessor
9122  }
9123}
9124
9125fn get_view_for_auto_accessor<'a>(inner: &'a swc_ast::AutoAccessor, bump: &'a Bump) -> &'a AutoAccessor<'a> {
9126  let node = bump.alloc(AutoAccessor {
9127    inner,
9128    parent: Default::default(),
9129    key: get_view_for_key(&inner.key, bump),
9130    value: match &inner.value {
9131      Some(value) => Some(get_view_for_expr(value, bump)),
9132      None => None,
9133    },
9134    type_ann: match &inner.type_ann {
9135      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
9136      None => None,
9137    },
9138    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 }),
9139  });
9140  let parent: Node<'a> = (&*node).into();
9141  set_parent_for_key(&node.key, parent);
9142  if let Some(value) = &node.value {
9143    set_parent_for_expr(value, parent)
9144  };
9145  if let Some(value) = &node.type_ann {
9146    set_parent_for_ts_type_ann(value, parent)
9147  };
9148  for value in node.decorators.iter() {
9149    set_parent_for_decorator(value, parent)
9150  }
9151  node
9152}
9153
9154fn set_parent_for_auto_accessor<'a>(node: &AutoAccessor<'a>, parent: Node<'a>) {
9155  node.parent.set(parent.expect::<Class>());
9156}
9157
9158#[derive(Clone)]
9159pub struct AwaitExpr<'a> {
9160  parent: ParentOnceCell<Node<'a>>,
9161  pub inner: &'a swc_ast::AwaitExpr,
9162  pub arg: Expr<'a>,
9163}
9164
9165impl<'a> AwaitExpr<'a> {
9166  pub fn parent(&self) -> Node<'a> {
9167    self.parent.get().unwrap()
9168  }
9169}
9170
9171impl<'a> SourceRanged for AwaitExpr<'a> {
9172  fn start(&self) -> SourcePos {
9173    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9174  }
9175  fn end(&self) -> SourcePos {
9176    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9177  }
9178}
9179
9180impl<'a> From<&AwaitExpr<'a>> for Node<'a> {
9181  fn from(node: &AwaitExpr<'a>) -> Node<'a> {
9182    let node = unsafe { mem::transmute::<&AwaitExpr<'a>, &'a AwaitExpr<'a>>(node) };
9183    Node::AwaitExpr(node)
9184  }
9185}
9186
9187impl<'a> NodeTrait<'a> for AwaitExpr<'a> {
9188  fn parent(&self) -> Option<Node<'a>> {
9189    Some(self.parent.get().unwrap().clone())
9190  }
9191
9192  fn children(&self) -> Vec<Node<'a>> {
9193    let mut children = Vec::with_capacity(1);
9194    children.push((&self.arg).into());
9195    children
9196  }
9197
9198  fn as_node(&self) -> Node<'a> {
9199    self.into()
9200  }
9201
9202  fn kind(&self) -> NodeKind {
9203    NodeKind::AwaitExpr
9204  }
9205}
9206
9207impl<'a> CastableNode<'a> for AwaitExpr<'a> {
9208  fn to(node: &Node<'a>) -> Option<&'a Self> {
9209    if let Node::AwaitExpr(node) = node {
9210      Some(node)
9211    } else {
9212      None
9213    }
9214  }
9215
9216  fn kind() -> NodeKind {
9217    NodeKind::AwaitExpr
9218  }
9219}
9220
9221fn get_view_for_await_expr<'a>(inner: &'a swc_ast::AwaitExpr, bump: &'a Bump) -> &'a AwaitExpr<'a> {
9222  let node = bump.alloc(AwaitExpr {
9223    inner,
9224    parent: Default::default(),
9225    arg: get_view_for_expr(&inner.arg, bump),
9226  });
9227  let parent: Node<'a> = (&*node).into();
9228  set_parent_for_expr(&node.arg, parent);
9229  node
9230}
9231
9232fn set_parent_for_await_expr<'a>(node: &AwaitExpr<'a>, parent: Node<'a>) {
9233  node.parent.set(parent);
9234}
9235
9236#[derive(Clone)]
9237pub struct BigInt<'a> {
9238  parent: ParentOnceCell<Node<'a>>,
9239  pub inner: &'a swc_ast::BigInt,
9240}
9241
9242impl<'a> BigInt<'a> {
9243  pub fn parent(&self) -> Node<'a> {
9244    self.parent.get().unwrap()
9245  }
9246
9247  pub fn value(&self) -> &num_bigint::BigInt {
9248    &self.inner.value
9249  }
9250
9251  /// Use `None` value only for transformations to avoid recalculate
9252  /// characters in big integer
9253  pub fn raw(&self) -> &Option<swc_atoms::Atom> {
9254    &self.inner.raw
9255  }
9256}
9257
9258impl<'a> SourceRanged for BigInt<'a> {
9259  fn start(&self) -> SourcePos {
9260    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9261  }
9262  fn end(&self) -> SourcePos {
9263    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9264  }
9265}
9266
9267impl<'a> From<&BigInt<'a>> for Node<'a> {
9268  fn from(node: &BigInt<'a>) -> Node<'a> {
9269    let node = unsafe { mem::transmute::<&BigInt<'a>, &'a BigInt<'a>>(node) };
9270    Node::BigInt(node)
9271  }
9272}
9273
9274impl<'a> NodeTrait<'a> for BigInt<'a> {
9275  fn parent(&self) -> Option<Node<'a>> {
9276    Some(self.parent.get().unwrap().clone())
9277  }
9278
9279  fn children(&self) -> Vec<Node<'a>> {
9280    Vec::with_capacity(0)
9281  }
9282
9283  fn as_node(&self) -> Node<'a> {
9284    self.into()
9285  }
9286
9287  fn kind(&self) -> NodeKind {
9288    NodeKind::BigInt
9289  }
9290}
9291
9292impl<'a> CastableNode<'a> for BigInt<'a> {
9293  fn to(node: &Node<'a>) -> Option<&'a Self> {
9294    if let Node::BigInt(node) = node {
9295      Some(node)
9296    } else {
9297      None
9298    }
9299  }
9300
9301  fn kind() -> NodeKind {
9302    NodeKind::BigInt
9303  }
9304}
9305
9306fn get_view_for_big_int<'a>(inner: &'a swc_ast::BigInt, bump: &'a Bump) -> &'a BigInt<'a> {
9307  let node = bump.alloc(BigInt {
9308    inner,
9309    parent: Default::default(),
9310  });
9311  node
9312}
9313
9314fn set_parent_for_big_int<'a>(node: &BigInt<'a>, parent: Node<'a>) {
9315  node.parent.set(parent);
9316}
9317
9318#[derive(Clone)]
9319pub struct BinExpr<'a> {
9320  parent: ParentOnceCell<Node<'a>>,
9321  pub inner: &'a swc_ast::BinExpr,
9322  pub left: Expr<'a>,
9323  pub right: Expr<'a>,
9324}
9325
9326impl<'a> BinExpr<'a> {
9327  pub fn parent(&self) -> Node<'a> {
9328    self.parent.get().unwrap()
9329  }
9330
9331  pub fn op(&self) -> BinaryOp {
9332    self.inner.op
9333  }
9334}
9335
9336impl<'a> SourceRanged for BinExpr<'a> {
9337  fn start(&self) -> SourcePos {
9338    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9339  }
9340  fn end(&self) -> SourcePos {
9341    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9342  }
9343}
9344
9345impl<'a> From<&BinExpr<'a>> for Node<'a> {
9346  fn from(node: &BinExpr<'a>) -> Node<'a> {
9347    let node = unsafe { mem::transmute::<&BinExpr<'a>, &'a BinExpr<'a>>(node) };
9348    Node::BinExpr(node)
9349  }
9350}
9351
9352impl<'a> NodeTrait<'a> for BinExpr<'a> {
9353  fn parent(&self) -> Option<Node<'a>> {
9354    Some(self.parent.get().unwrap().clone())
9355  }
9356
9357  fn children(&self) -> Vec<Node<'a>> {
9358    let mut children = Vec::with_capacity(2);
9359    children.push((&self.left).into());
9360    children.push((&self.right).into());
9361    children
9362  }
9363
9364  fn as_node(&self) -> Node<'a> {
9365    self.into()
9366  }
9367
9368  fn kind(&self) -> NodeKind {
9369    NodeKind::BinExpr
9370  }
9371}
9372
9373impl<'a> CastableNode<'a> for BinExpr<'a> {
9374  fn to(node: &Node<'a>) -> Option<&'a Self> {
9375    if let Node::BinExpr(node) = node {
9376      Some(node)
9377    } else {
9378      None
9379    }
9380  }
9381
9382  fn kind() -> NodeKind {
9383    NodeKind::BinExpr
9384  }
9385}
9386
9387fn get_view_for_bin_expr<'a>(inner: &'a swc_ast::BinExpr, bump: &'a Bump) -> &'a BinExpr<'a> {
9388  let node = bump.alloc(BinExpr {
9389    inner,
9390    parent: Default::default(),
9391    left: get_view_for_expr(&inner.left, bump),
9392    right: get_view_for_expr(&inner.right, bump),
9393  });
9394  let parent: Node<'a> = (&*node).into();
9395  set_parent_for_expr(&node.left, parent);
9396  set_parent_for_expr(&node.right, parent);
9397  node
9398}
9399
9400fn set_parent_for_bin_expr<'a>(node: &BinExpr<'a>, parent: Node<'a>) {
9401  node.parent.set(parent);
9402}
9403
9404/// Identifier used as a pattern.
9405#[derive(Clone)]
9406pub struct BindingIdent<'a> {
9407  parent: ParentOnceCell<Node<'a>>,
9408  pub inner: &'a swc_ast::BindingIdent,
9409  pub id: &'a Ident<'a>,
9410  pub type_ann: Option<&'a TsTypeAnn<'a>>,
9411}
9412
9413impl<'a> BindingIdent<'a> {
9414  pub fn parent(&self) -> Node<'a> {
9415    self.parent.get().unwrap()
9416  }
9417}
9418
9419impl<'a> SourceRanged for BindingIdent<'a> {
9420  fn start(&self) -> SourcePos {
9421    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9422  }
9423  fn end(&self) -> SourcePos {
9424    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9425  }
9426}
9427
9428impl<'a> From<&BindingIdent<'a>> for Node<'a> {
9429  fn from(node: &BindingIdent<'a>) -> Node<'a> {
9430    let node = unsafe { mem::transmute::<&BindingIdent<'a>, &'a BindingIdent<'a>>(node) };
9431    Node::BindingIdent(node)
9432  }
9433}
9434
9435impl<'a> NodeTrait<'a> for BindingIdent<'a> {
9436  fn parent(&self) -> Option<Node<'a>> {
9437    Some(self.parent.get().unwrap().clone())
9438  }
9439
9440  fn children(&self) -> Vec<Node<'a>> {
9441    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
9442    children.push(self.id.into());
9443    if let Some(child) = self.type_ann {
9444      children.push(child.into());
9445    }
9446    children
9447  }
9448
9449  fn as_node(&self) -> Node<'a> {
9450    self.into()
9451  }
9452
9453  fn kind(&self) -> NodeKind {
9454    NodeKind::BindingIdent
9455  }
9456}
9457
9458impl<'a> CastableNode<'a> for BindingIdent<'a> {
9459  fn to(node: &Node<'a>) -> Option<&'a Self> {
9460    if let Node::BindingIdent(node) = node {
9461      Some(node)
9462    } else {
9463      None
9464    }
9465  }
9466
9467  fn kind() -> NodeKind {
9468    NodeKind::BindingIdent
9469  }
9470}
9471
9472fn get_view_for_binding_ident<'a>(inner: &'a swc_ast::BindingIdent, bump: &'a Bump) -> &'a BindingIdent<'a> {
9473  let node = bump.alloc(BindingIdent {
9474    inner,
9475    parent: Default::default(),
9476    id: get_view_for_ident(&inner.id, bump),
9477    type_ann: match &inner.type_ann {
9478      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
9479      None => None,
9480    },
9481  });
9482  let parent: Node<'a> = (&*node).into();
9483  set_parent_for_ident(&node.id, parent);
9484  if let Some(value) = &node.type_ann {
9485    set_parent_for_ts_type_ann(value, parent)
9486  };
9487  node
9488}
9489
9490fn set_parent_for_binding_ident<'a>(node: &BindingIdent<'a>, parent: Node<'a>) {
9491  node.parent.set(parent);
9492}
9493
9494/// Use when only block statements are allowed.
9495#[derive(Clone)]
9496pub struct BlockStmt<'a> {
9497  parent: ParentOnceCell<Node<'a>>,
9498  pub inner: &'a swc_ast::BlockStmt,
9499  pub stmts: &'a [Stmt<'a>],
9500}
9501
9502impl<'a> BlockStmt<'a> {
9503  pub fn parent(&self) -> Node<'a> {
9504    self.parent.get().unwrap()
9505  }
9506
9507  pub fn ctxt(&self) -> swc_common::SyntaxContext {
9508    self.inner.ctxt
9509  }
9510}
9511
9512impl<'a> SourceRanged for BlockStmt<'a> {
9513  fn start(&self) -> SourcePos {
9514    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9515  }
9516  fn end(&self) -> SourcePos {
9517    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9518  }
9519}
9520
9521impl<'a> From<&BlockStmt<'a>> for Node<'a> {
9522  fn from(node: &BlockStmt<'a>) -> Node<'a> {
9523    let node = unsafe { mem::transmute::<&BlockStmt<'a>, &'a BlockStmt<'a>>(node) };
9524    Node::BlockStmt(node)
9525  }
9526}
9527
9528impl<'a> NodeTrait<'a> for BlockStmt<'a> {
9529  fn parent(&self) -> Option<Node<'a>> {
9530    Some(self.parent.get().unwrap().clone())
9531  }
9532
9533  fn children(&self) -> Vec<Node<'a>> {
9534    let mut children = Vec::with_capacity(self.stmts.len());
9535    for child in self.stmts.iter() {
9536      children.push(child.into());
9537    }
9538    children
9539  }
9540
9541  fn as_node(&self) -> Node<'a> {
9542    self.into()
9543  }
9544
9545  fn kind(&self) -> NodeKind {
9546    NodeKind::BlockStmt
9547  }
9548}
9549
9550impl<'a> CastableNode<'a> for BlockStmt<'a> {
9551  fn to(node: &Node<'a>) -> Option<&'a Self> {
9552    if let Node::BlockStmt(node) = node {
9553      Some(node)
9554    } else {
9555      None
9556    }
9557  }
9558
9559  fn kind() -> NodeKind {
9560    NodeKind::BlockStmt
9561  }
9562}
9563
9564fn get_view_for_block_stmt<'a>(inner: &'a swc_ast::BlockStmt, bump: &'a Bump) -> &'a BlockStmt<'a> {
9565  let node = bump.alloc(BlockStmt {
9566    inner,
9567    parent: Default::default(),
9568    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 }),
9569  });
9570  let parent: Node<'a> = (&*node).into();
9571  for value in node.stmts.iter() {
9572    set_parent_for_stmt(value, parent)
9573  }
9574  node
9575}
9576
9577fn set_parent_for_block_stmt<'a>(node: &BlockStmt<'a>, parent: Node<'a>) {
9578  node.parent.set(parent);
9579}
9580
9581/// A boolean literal.
9582///
9583///
9584/// # Creation
9585///
9586/// If you are creating a boolean literal with a dummy span, please use
9587/// `true.into()` or `false.into()`, instead of creating this struct directly.
9588///
9589/// All of `Box<Expr>`, `Expr`, `Lit`, `Bool` implements `From<bool>`.
9590#[derive(Clone)]
9591pub struct Bool<'a> {
9592  parent: ParentOnceCell<Node<'a>>,
9593  pub inner: &'a swc_ast::Bool,
9594}
9595
9596impl<'a> Bool<'a> {
9597  pub fn parent(&self) -> Node<'a> {
9598    self.parent.get().unwrap()
9599  }
9600
9601  pub fn value(&self) -> bool {
9602    self.inner.value
9603  }
9604}
9605
9606impl<'a> SourceRanged for Bool<'a> {
9607  fn start(&self) -> SourcePos {
9608    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9609  }
9610  fn end(&self) -> SourcePos {
9611    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9612  }
9613}
9614
9615impl<'a> From<&Bool<'a>> for Node<'a> {
9616  fn from(node: &Bool<'a>) -> Node<'a> {
9617    let node = unsafe { mem::transmute::<&Bool<'a>, &'a Bool<'a>>(node) };
9618    Node::Bool(node)
9619  }
9620}
9621
9622impl<'a> NodeTrait<'a> for Bool<'a> {
9623  fn parent(&self) -> Option<Node<'a>> {
9624    Some(self.parent.get().unwrap().clone())
9625  }
9626
9627  fn children(&self) -> Vec<Node<'a>> {
9628    Vec::with_capacity(0)
9629  }
9630
9631  fn as_node(&self) -> Node<'a> {
9632    self.into()
9633  }
9634
9635  fn kind(&self) -> NodeKind {
9636    NodeKind::Bool
9637  }
9638}
9639
9640impl<'a> CastableNode<'a> for Bool<'a> {
9641  fn to(node: &Node<'a>) -> Option<&'a Self> {
9642    if let Node::Bool(node) = node {
9643      Some(node)
9644    } else {
9645      None
9646    }
9647  }
9648
9649  fn kind() -> NodeKind {
9650    NodeKind::Bool
9651  }
9652}
9653
9654fn get_view_for_bool<'a>(inner: &'a swc_ast::Bool, bump: &'a Bump) -> &'a Bool<'a> {
9655  let node = bump.alloc(Bool {
9656    inner,
9657    parent: Default::default(),
9658  });
9659  node
9660}
9661
9662fn set_parent_for_bool<'a>(node: &Bool<'a>, parent: Node<'a>) {
9663  node.parent.set(parent);
9664}
9665
9666#[derive(Clone)]
9667pub struct BreakStmt<'a> {
9668  parent: ParentOnceCell<Node<'a>>,
9669  pub inner: &'a swc_ast::BreakStmt,
9670  pub label: Option<&'a Ident<'a>>,
9671}
9672
9673impl<'a> BreakStmt<'a> {
9674  pub fn parent(&self) -> Node<'a> {
9675    self.parent.get().unwrap()
9676  }
9677}
9678
9679impl<'a> SourceRanged for BreakStmt<'a> {
9680  fn start(&self) -> SourcePos {
9681    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9682  }
9683  fn end(&self) -> SourcePos {
9684    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9685  }
9686}
9687
9688impl<'a> From<&BreakStmt<'a>> for Node<'a> {
9689  fn from(node: &BreakStmt<'a>) -> Node<'a> {
9690    let node = unsafe { mem::transmute::<&BreakStmt<'a>, &'a BreakStmt<'a>>(node) };
9691    Node::BreakStmt(node)
9692  }
9693}
9694
9695impl<'a> NodeTrait<'a> for BreakStmt<'a> {
9696  fn parent(&self) -> Option<Node<'a>> {
9697    Some(self.parent.get().unwrap().clone())
9698  }
9699
9700  fn children(&self) -> Vec<Node<'a>> {
9701    let mut children = Vec::with_capacity(match &self.label { Some(_value) => 1, None => 0, });
9702    if let Some(child) = self.label {
9703      children.push(child.into());
9704    }
9705    children
9706  }
9707
9708  fn as_node(&self) -> Node<'a> {
9709    self.into()
9710  }
9711
9712  fn kind(&self) -> NodeKind {
9713    NodeKind::BreakStmt
9714  }
9715}
9716
9717impl<'a> CastableNode<'a> for BreakStmt<'a> {
9718  fn to(node: &Node<'a>) -> Option<&'a Self> {
9719    if let Node::BreakStmt(node) = node {
9720      Some(node)
9721    } else {
9722      None
9723    }
9724  }
9725
9726  fn kind() -> NodeKind {
9727    NodeKind::BreakStmt
9728  }
9729}
9730
9731fn get_view_for_break_stmt<'a>(inner: &'a swc_ast::BreakStmt, bump: &'a Bump) -> &'a BreakStmt<'a> {
9732  let node = bump.alloc(BreakStmt {
9733    inner,
9734    parent: Default::default(),
9735    label: match &inner.label {
9736      Some(value) => Some(get_view_for_ident(value, bump)),
9737      None => None,
9738    },
9739  });
9740  let parent: Node<'a> = (&*node).into();
9741  if let Some(value) = &node.label {
9742    set_parent_for_ident(value, parent)
9743  };
9744  node
9745}
9746
9747fn set_parent_for_break_stmt<'a>(node: &BreakStmt<'a>, parent: Node<'a>) {
9748  node.parent.set(parent);
9749}
9750
9751#[derive(Clone)]
9752pub struct CallExpr<'a> {
9753  parent: ParentOnceCell<Node<'a>>,
9754  pub inner: &'a swc_ast::CallExpr,
9755  pub callee: Callee<'a>,
9756  pub args: &'a [&'a ExprOrSpread<'a>],
9757  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
9758}
9759
9760impl<'a> CallExpr<'a> {
9761  pub fn parent(&self) -> Node<'a> {
9762    self.parent.get().unwrap()
9763  }
9764
9765  pub fn ctxt(&self) -> swc_common::SyntaxContext {
9766    self.inner.ctxt
9767  }
9768}
9769
9770impl<'a> SourceRanged for CallExpr<'a> {
9771  fn start(&self) -> SourcePos {
9772    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9773  }
9774  fn end(&self) -> SourcePos {
9775    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9776  }
9777}
9778
9779impl<'a> From<&CallExpr<'a>> for Node<'a> {
9780  fn from(node: &CallExpr<'a>) -> Node<'a> {
9781    let node = unsafe { mem::transmute::<&CallExpr<'a>, &'a CallExpr<'a>>(node) };
9782    Node::CallExpr(node)
9783  }
9784}
9785
9786impl<'a> NodeTrait<'a> for CallExpr<'a> {
9787  fn parent(&self) -> Option<Node<'a>> {
9788    Some(self.parent.get().unwrap().clone())
9789  }
9790
9791  fn children(&self) -> Vec<Node<'a>> {
9792    let mut children = Vec::with_capacity(1 + self.args.len() + match &self.type_args { Some(_value) => 1, None => 0, });
9793    children.push((&self.callee).into());
9794    for child in self.args.iter() {
9795      children.push((*child).into());
9796    }
9797    if let Some(child) = self.type_args {
9798      children.push(child.into());
9799    }
9800    children
9801  }
9802
9803  fn as_node(&self) -> Node<'a> {
9804    self.into()
9805  }
9806
9807  fn kind(&self) -> NodeKind {
9808    NodeKind::CallExpr
9809  }
9810}
9811
9812impl<'a> CastableNode<'a> for CallExpr<'a> {
9813  fn to(node: &Node<'a>) -> Option<&'a Self> {
9814    if let Node::CallExpr(node) = node {
9815      Some(node)
9816    } else {
9817      None
9818    }
9819  }
9820
9821  fn kind() -> NodeKind {
9822    NodeKind::CallExpr
9823  }
9824}
9825
9826fn get_view_for_call_expr<'a>(inner: &'a swc_ast::CallExpr, bump: &'a Bump) -> &'a CallExpr<'a> {
9827  let node = bump.alloc(CallExpr {
9828    inner,
9829    parent: Default::default(),
9830    callee: get_view_for_callee(&inner.callee, bump),
9831    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 }),
9832    type_args: match &inner.type_args {
9833      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
9834      None => None,
9835    },
9836  });
9837  let parent: Node<'a> = (&*node).into();
9838  set_parent_for_callee(&node.callee, parent);
9839  for value in node.args.iter() {
9840    set_parent_for_expr_or_spread(value, parent)
9841  }
9842  if let Some(value) = &node.type_args {
9843    set_parent_for_ts_type_param_instantiation(value, parent)
9844  };
9845  node
9846}
9847
9848fn set_parent_for_call_expr<'a>(node: &CallExpr<'a>, parent: Node<'a>) {
9849  node.parent.set(parent);
9850}
9851
9852#[derive(Clone)]
9853pub struct CatchClause<'a> {
9854  parent: ParentOnceCell<&'a TryStmt<'a>>,
9855  pub inner: &'a swc_ast::CatchClause,
9856  /// es2019
9857  ///
9858  /// The param is null if the catch binding is omitted. E.g., try { foo() }
9859  /// catch { bar() }
9860  pub param: Option<Pat<'a>>,
9861  pub body: &'a BlockStmt<'a>,
9862}
9863
9864impl<'a> CatchClause<'a> {
9865  pub fn parent(&self) -> &'a TryStmt<'a> {
9866    self.parent.get().unwrap()
9867  }
9868}
9869
9870impl<'a> SourceRanged for CatchClause<'a> {
9871  fn start(&self) -> SourcePos {
9872    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9873  }
9874  fn end(&self) -> SourcePos {
9875    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9876  }
9877}
9878
9879impl<'a> From<&CatchClause<'a>> for Node<'a> {
9880  fn from(node: &CatchClause<'a>) -> Node<'a> {
9881    let node = unsafe { mem::transmute::<&CatchClause<'a>, &'a CatchClause<'a>>(node) };
9882    Node::CatchClause(node)
9883  }
9884}
9885
9886impl<'a> NodeTrait<'a> for CatchClause<'a> {
9887  fn parent(&self) -> Option<Node<'a>> {
9888    Some(self.parent.get().unwrap().into())
9889  }
9890
9891  fn children(&self) -> Vec<Node<'a>> {
9892    let mut children = Vec::with_capacity(1 + match &self.param { Some(_value) => 1, None => 0, });
9893    if let Some(child) = self.param.as_ref() {
9894      children.push(child.into());
9895    }
9896    children.push(self.body.into());
9897    children
9898  }
9899
9900  fn as_node(&self) -> Node<'a> {
9901    self.into()
9902  }
9903
9904  fn kind(&self) -> NodeKind {
9905    NodeKind::CatchClause
9906  }
9907}
9908
9909impl<'a> CastableNode<'a> for CatchClause<'a> {
9910  fn to(node: &Node<'a>) -> Option<&'a Self> {
9911    if let Node::CatchClause(node) = node {
9912      Some(node)
9913    } else {
9914      None
9915    }
9916  }
9917
9918  fn kind() -> NodeKind {
9919    NodeKind::CatchClause
9920  }
9921}
9922
9923fn get_view_for_catch_clause<'a>(inner: &'a swc_ast::CatchClause, bump: &'a Bump) -> &'a CatchClause<'a> {
9924  let node = bump.alloc(CatchClause {
9925    inner,
9926    parent: Default::default(),
9927    param: match &inner.param {
9928      Some(value) => Some(get_view_for_pat(value, bump)),
9929      None => None,
9930    },
9931    body: get_view_for_block_stmt(&inner.body, bump),
9932  });
9933  let parent: Node<'a> = (&*node).into();
9934  if let Some(value) = &node.param {
9935    set_parent_for_pat(value, parent)
9936  };
9937  set_parent_for_block_stmt(&node.body, parent);
9938  node
9939}
9940
9941fn set_parent_for_catch_clause<'a>(node: &CatchClause<'a>, parent: Node<'a>) {
9942  node.parent.set(parent.expect::<TryStmt>());
9943}
9944
9945#[derive(Clone)]
9946pub struct Class<'a> {
9947  parent: ParentOnceCell<Node<'a>>,
9948  pub inner: &'a swc_ast::Class,
9949  pub decorators: &'a [&'a Decorator<'a>],
9950  pub body: &'a [ClassMember<'a>],
9951  pub super_class: Option<Expr<'a>>,
9952  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
9953  pub super_type_params: Option<&'a TsTypeParamInstantiation<'a>>,
9954  /// Typescript extension.
9955  pub implements: &'a [&'a TsExprWithTypeArgs<'a>],
9956}
9957
9958impl<'a> Class<'a> {
9959  pub fn parent(&self) -> Node<'a> {
9960    self.parent.get().unwrap()
9961  }
9962
9963  pub fn ctxt(&self) -> swc_common::SyntaxContext {
9964    self.inner.ctxt
9965  }
9966
9967  pub fn is_abstract(&self) -> bool {
9968    self.inner.is_abstract
9969  }
9970}
9971
9972impl<'a> SourceRanged for Class<'a> {
9973  fn start(&self) -> SourcePos {
9974    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
9975  }
9976  fn end(&self) -> SourcePos {
9977    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
9978  }
9979}
9980
9981impl<'a> From<&Class<'a>> for Node<'a> {
9982  fn from(node: &Class<'a>) -> Node<'a> {
9983    let node = unsafe { mem::transmute::<&Class<'a>, &'a Class<'a>>(node) };
9984    Node::Class(node)
9985  }
9986}
9987
9988impl<'a> NodeTrait<'a> for Class<'a> {
9989  fn parent(&self) -> Option<Node<'a>> {
9990    Some(self.parent.get().unwrap().clone())
9991  }
9992
9993  fn children(&self) -> Vec<Node<'a>> {
9994    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());
9995    for child in self.decorators.iter() {
9996      children.push((*child).into());
9997    }
9998    for child in self.body.iter() {
9999      children.push(child.into());
10000    }
10001    if let Some(child) = self.super_class.as_ref() {
10002      children.push(child.into());
10003    }
10004    if let Some(child) = self.type_params {
10005      children.push(child.into());
10006    }
10007    if let Some(child) = self.super_type_params {
10008      children.push(child.into());
10009    }
10010    for child in self.implements.iter() {
10011      children.push((*child).into());
10012    }
10013    children
10014  }
10015
10016  fn as_node(&self) -> Node<'a> {
10017    self.into()
10018  }
10019
10020  fn kind(&self) -> NodeKind {
10021    NodeKind::Class
10022  }
10023}
10024
10025impl<'a> CastableNode<'a> for Class<'a> {
10026  fn to(node: &Node<'a>) -> Option<&'a Self> {
10027    if let Node::Class(node) = node {
10028      Some(node)
10029    } else {
10030      None
10031    }
10032  }
10033
10034  fn kind() -> NodeKind {
10035    NodeKind::Class
10036  }
10037}
10038
10039fn get_view_for_class<'a>(inner: &'a swc_ast::Class, bump: &'a Bump) -> &'a Class<'a> {
10040  let node = bump.alloc(Class {
10041    inner,
10042    parent: Default::default(),
10043    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 }),
10044    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 }),
10045    super_class: match &inner.super_class {
10046      Some(value) => Some(get_view_for_expr(value, bump)),
10047      None => None,
10048    },
10049    type_params: match &inner.type_params {
10050      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
10051      None => None,
10052    },
10053    super_type_params: match &inner.super_type_params {
10054      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
10055      None => None,
10056    },
10057    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 }),
10058  });
10059  let parent: Node<'a> = (&*node).into();
10060  for value in node.decorators.iter() {
10061    set_parent_for_decorator(value, parent)
10062  }
10063  for value in node.body.iter() {
10064    set_parent_for_class_member(value, parent)
10065  }
10066  if let Some(value) = &node.super_class {
10067    set_parent_for_expr(value, parent)
10068  };
10069  if let Some(value) = &node.type_params {
10070    set_parent_for_ts_type_param_decl(value, parent)
10071  };
10072  if let Some(value) = &node.super_type_params {
10073    set_parent_for_ts_type_param_instantiation(value, parent)
10074  };
10075  for value in node.implements.iter() {
10076    set_parent_for_ts_expr_with_type_args(value, parent)
10077  }
10078  node
10079}
10080
10081fn set_parent_for_class<'a>(node: &Class<'a>, parent: Node<'a>) {
10082  node.parent.set(parent);
10083}
10084
10085#[derive(Clone)]
10086pub struct ClassDecl<'a> {
10087  parent: ParentOnceCell<Node<'a>>,
10088  pub inner: &'a swc_ast::ClassDecl,
10089  pub ident: &'a Ident<'a>,
10090  pub class: &'a Class<'a>,
10091}
10092
10093impl<'a> ClassDecl<'a> {
10094  pub fn parent(&self) -> Node<'a> {
10095    self.parent.get().unwrap()
10096  }
10097
10098  pub fn declare(&self) -> bool {
10099    self.inner.declare
10100  }
10101}
10102
10103impl<'a> SourceRanged for ClassDecl<'a> {
10104  fn start(&self) -> SourcePos {
10105    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10106  }
10107  fn end(&self) -> SourcePos {
10108    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10109  }
10110}
10111
10112impl<'a> From<&ClassDecl<'a>> for Node<'a> {
10113  fn from(node: &ClassDecl<'a>) -> Node<'a> {
10114    let node = unsafe { mem::transmute::<&ClassDecl<'a>, &'a ClassDecl<'a>>(node) };
10115    Node::ClassDecl(node)
10116  }
10117}
10118
10119impl<'a> NodeTrait<'a> for ClassDecl<'a> {
10120  fn parent(&self) -> Option<Node<'a>> {
10121    Some(self.parent.get().unwrap().clone())
10122  }
10123
10124  fn children(&self) -> Vec<Node<'a>> {
10125    let mut children = Vec::with_capacity(2);
10126    children.push(self.ident.into());
10127    children.push(self.class.into());
10128    children
10129  }
10130
10131  fn as_node(&self) -> Node<'a> {
10132    self.into()
10133  }
10134
10135  fn kind(&self) -> NodeKind {
10136    NodeKind::ClassDecl
10137  }
10138}
10139
10140impl<'a> CastableNode<'a> for ClassDecl<'a> {
10141  fn to(node: &Node<'a>) -> Option<&'a Self> {
10142    if let Node::ClassDecl(node) = node {
10143      Some(node)
10144    } else {
10145      None
10146    }
10147  }
10148
10149  fn kind() -> NodeKind {
10150    NodeKind::ClassDecl
10151  }
10152}
10153
10154fn get_view_for_class_decl<'a>(inner: &'a swc_ast::ClassDecl, bump: &'a Bump) -> &'a ClassDecl<'a> {
10155  let node = bump.alloc(ClassDecl {
10156    inner,
10157    parent: Default::default(),
10158    ident: get_view_for_ident(&inner.ident, bump),
10159    class: get_view_for_class(&inner.class, bump),
10160  });
10161  let parent: Node<'a> = (&*node).into();
10162  set_parent_for_ident(&node.ident, parent);
10163  set_parent_for_class(&node.class, parent);
10164  node
10165}
10166
10167fn set_parent_for_class_decl<'a>(node: &ClassDecl<'a>, parent: Node<'a>) {
10168  node.parent.set(parent);
10169}
10170
10171/// Class expression.
10172#[derive(Clone)]
10173pub struct ClassExpr<'a> {
10174  parent: ParentOnceCell<Node<'a>>,
10175  pub inner: &'a swc_ast::ClassExpr,
10176  pub ident: Option<&'a Ident<'a>>,
10177  pub class: &'a Class<'a>,
10178}
10179
10180impl<'a> ClassExpr<'a> {
10181  pub fn parent(&self) -> Node<'a> {
10182    self.parent.get().unwrap()
10183  }
10184}
10185
10186impl<'a> SourceRanged for ClassExpr<'a> {
10187  fn start(&self) -> SourcePos {
10188    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10189  }
10190  fn end(&self) -> SourcePos {
10191    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10192  }
10193}
10194
10195impl<'a> From<&ClassExpr<'a>> for Node<'a> {
10196  fn from(node: &ClassExpr<'a>) -> Node<'a> {
10197    let node = unsafe { mem::transmute::<&ClassExpr<'a>, &'a ClassExpr<'a>>(node) };
10198    Node::ClassExpr(node)
10199  }
10200}
10201
10202impl<'a> NodeTrait<'a> for ClassExpr<'a> {
10203  fn parent(&self) -> Option<Node<'a>> {
10204    Some(self.parent.get().unwrap().clone())
10205  }
10206
10207  fn children(&self) -> Vec<Node<'a>> {
10208    let mut children = Vec::with_capacity(1 + match &self.ident { Some(_value) => 1, None => 0, });
10209    if let Some(child) = self.ident {
10210      children.push(child.into());
10211    }
10212    children.push(self.class.into());
10213    children
10214  }
10215
10216  fn as_node(&self) -> Node<'a> {
10217    self.into()
10218  }
10219
10220  fn kind(&self) -> NodeKind {
10221    NodeKind::ClassExpr
10222  }
10223}
10224
10225impl<'a> CastableNode<'a> for ClassExpr<'a> {
10226  fn to(node: &Node<'a>) -> Option<&'a Self> {
10227    if let Node::ClassExpr(node) = node {
10228      Some(node)
10229    } else {
10230      None
10231    }
10232  }
10233
10234  fn kind() -> NodeKind {
10235    NodeKind::ClassExpr
10236  }
10237}
10238
10239fn get_view_for_class_expr<'a>(inner: &'a swc_ast::ClassExpr, bump: &'a Bump) -> &'a ClassExpr<'a> {
10240  let node = bump.alloc(ClassExpr {
10241    inner,
10242    parent: Default::default(),
10243    ident: match &inner.ident {
10244      Some(value) => Some(get_view_for_ident(value, bump)),
10245      None => None,
10246    },
10247    class: get_view_for_class(&inner.class, bump),
10248  });
10249  let parent: Node<'a> = (&*node).into();
10250  if let Some(value) = &node.ident {
10251    set_parent_for_ident(value, parent)
10252  };
10253  set_parent_for_class(&node.class, parent);
10254  node
10255}
10256
10257fn set_parent_for_class_expr<'a>(node: &ClassExpr<'a>, parent: Node<'a>) {
10258  node.parent.set(parent);
10259}
10260
10261#[derive(Clone)]
10262pub struct ClassMethod<'a> {
10263  parent: ParentOnceCell<&'a Class<'a>>,
10264  pub inner: &'a swc_ast::ClassMethod,
10265  pub key: PropName<'a>,
10266  pub function: &'a Function<'a>,
10267}
10268
10269impl<'a> ClassMethod<'a> {
10270  pub fn parent(&self) -> &'a Class<'a> {
10271    self.parent.get().unwrap()
10272  }
10273
10274  pub fn method_kind(&self) -> MethodKind {
10275    self.inner.kind
10276  }
10277
10278  pub fn is_static(&self) -> bool {
10279    self.inner.is_static
10280  }
10281
10282  /// Typescript extension.
10283  pub fn accessibility(&self) -> Option<Accessibility> {
10284    self.inner.accessibility
10285  }
10286
10287  /// Typescript extension.
10288  pub fn is_abstract(&self) -> bool {
10289    self.inner.is_abstract
10290  }
10291
10292  pub fn is_optional(&self) -> bool {
10293    self.inner.is_optional
10294  }
10295
10296  pub fn is_override(&self) -> bool {
10297    self.inner.is_override
10298  }
10299}
10300
10301impl<'a> SourceRanged for ClassMethod<'a> {
10302  fn start(&self) -> SourcePos {
10303    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10304  }
10305  fn end(&self) -> SourcePos {
10306    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10307  }
10308}
10309
10310impl<'a> From<&ClassMethod<'a>> for Node<'a> {
10311  fn from(node: &ClassMethod<'a>) -> Node<'a> {
10312    let node = unsafe { mem::transmute::<&ClassMethod<'a>, &'a ClassMethod<'a>>(node) };
10313    Node::ClassMethod(node)
10314  }
10315}
10316
10317impl<'a> NodeTrait<'a> for ClassMethod<'a> {
10318  fn parent(&self) -> Option<Node<'a>> {
10319    Some(self.parent.get().unwrap().into())
10320  }
10321
10322  fn children(&self) -> Vec<Node<'a>> {
10323    let mut children = Vec::with_capacity(2);
10324    children.push((&self.key).into());
10325    children.push(self.function.into());
10326    children
10327  }
10328
10329  fn as_node(&self) -> Node<'a> {
10330    self.into()
10331  }
10332
10333  fn kind(&self) -> NodeKind {
10334    NodeKind::ClassMethod
10335  }
10336}
10337
10338impl<'a> CastableNode<'a> for ClassMethod<'a> {
10339  fn to(node: &Node<'a>) -> Option<&'a Self> {
10340    if let Node::ClassMethod(node) = node {
10341      Some(node)
10342    } else {
10343      None
10344    }
10345  }
10346
10347  fn kind() -> NodeKind {
10348    NodeKind::ClassMethod
10349  }
10350}
10351
10352fn get_view_for_class_method<'a>(inner: &'a swc_ast::ClassMethod, bump: &'a Bump) -> &'a ClassMethod<'a> {
10353  let node = bump.alloc(ClassMethod {
10354    inner,
10355    parent: Default::default(),
10356    key: get_view_for_prop_name(&inner.key, bump),
10357    function: get_view_for_function(&inner.function, bump),
10358  });
10359  let parent: Node<'a> = (&*node).into();
10360  set_parent_for_prop_name(&node.key, parent);
10361  set_parent_for_function(&node.function, parent);
10362  node
10363}
10364
10365fn set_parent_for_class_method<'a>(node: &ClassMethod<'a>, parent: Node<'a>) {
10366  node.parent.set(parent.expect::<Class>());
10367}
10368
10369#[derive(Clone)]
10370pub struct ClassProp<'a> {
10371  parent: ParentOnceCell<&'a Class<'a>>,
10372  pub inner: &'a swc_ast::ClassProp,
10373  pub key: PropName<'a>,
10374  pub value: Option<Expr<'a>>,
10375  pub type_ann: Option<&'a TsTypeAnn<'a>>,
10376  pub decorators: &'a [&'a Decorator<'a>],
10377}
10378
10379impl<'a> ClassProp<'a> {
10380  pub fn parent(&self) -> &'a Class<'a> {
10381    self.parent.get().unwrap()
10382  }
10383
10384  pub fn is_static(&self) -> bool {
10385    self.inner.is_static
10386  }
10387
10388  /// Typescript extension.
10389  pub fn accessibility(&self) -> Option<Accessibility> {
10390    self.inner.accessibility
10391  }
10392
10393  /// Typescript extension.
10394  pub fn is_abstract(&self) -> bool {
10395    self.inner.is_abstract
10396  }
10397
10398  pub fn is_optional(&self) -> bool {
10399    self.inner.is_optional
10400  }
10401
10402  pub fn is_override(&self) -> bool {
10403    self.inner.is_override
10404  }
10405
10406  pub fn readonly(&self) -> bool {
10407    self.inner.readonly
10408  }
10409
10410  pub fn declare(&self) -> bool {
10411    self.inner.declare
10412  }
10413
10414  pub fn definite(&self) -> bool {
10415    self.inner.definite
10416  }
10417}
10418
10419impl<'a> SourceRanged for ClassProp<'a> {
10420  fn start(&self) -> SourcePos {
10421    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10422  }
10423  fn end(&self) -> SourcePos {
10424    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10425  }
10426}
10427
10428impl<'a> From<&ClassProp<'a>> for Node<'a> {
10429  fn from(node: &ClassProp<'a>) -> Node<'a> {
10430    let node = unsafe { mem::transmute::<&ClassProp<'a>, &'a ClassProp<'a>>(node) };
10431    Node::ClassProp(node)
10432  }
10433}
10434
10435impl<'a> NodeTrait<'a> for ClassProp<'a> {
10436  fn parent(&self) -> Option<Node<'a>> {
10437    Some(self.parent.get().unwrap().into())
10438  }
10439
10440  fn children(&self) -> Vec<Node<'a>> {
10441    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());
10442    children.push((&self.key).into());
10443    if let Some(child) = self.value.as_ref() {
10444      children.push(child.into());
10445    }
10446    if let Some(child) = self.type_ann {
10447      children.push(child.into());
10448    }
10449    for child in self.decorators.iter() {
10450      children.push((*child).into());
10451    }
10452    children
10453  }
10454
10455  fn as_node(&self) -> Node<'a> {
10456    self.into()
10457  }
10458
10459  fn kind(&self) -> NodeKind {
10460    NodeKind::ClassProp
10461  }
10462}
10463
10464impl<'a> CastableNode<'a> for ClassProp<'a> {
10465  fn to(node: &Node<'a>) -> Option<&'a Self> {
10466    if let Node::ClassProp(node) = node {
10467      Some(node)
10468    } else {
10469      None
10470    }
10471  }
10472
10473  fn kind() -> NodeKind {
10474    NodeKind::ClassProp
10475  }
10476}
10477
10478fn get_view_for_class_prop<'a>(inner: &'a swc_ast::ClassProp, bump: &'a Bump) -> &'a ClassProp<'a> {
10479  let node = bump.alloc(ClassProp {
10480    inner,
10481    parent: Default::default(),
10482    key: get_view_for_prop_name(&inner.key, bump),
10483    value: match &inner.value {
10484      Some(value) => Some(get_view_for_expr(value, bump)),
10485      None => None,
10486    },
10487    type_ann: match &inner.type_ann {
10488      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
10489      None => None,
10490    },
10491    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 }),
10492  });
10493  let parent: Node<'a> = (&*node).into();
10494  set_parent_for_prop_name(&node.key, parent);
10495  if let Some(value) = &node.value {
10496    set_parent_for_expr(value, parent)
10497  };
10498  if let Some(value) = &node.type_ann {
10499    set_parent_for_ts_type_ann(value, parent)
10500  };
10501  for value in node.decorators.iter() {
10502    set_parent_for_decorator(value, parent)
10503  }
10504  node
10505}
10506
10507fn set_parent_for_class_prop<'a>(node: &ClassProp<'a>, parent: Node<'a>) {
10508  node.parent.set(parent.expect::<Class>());
10509}
10510
10511#[derive(Clone)]
10512pub struct ComputedPropName<'a> {
10513  parent: ParentOnceCell<Node<'a>>,
10514  pub inner: &'a swc_ast::ComputedPropName,
10515  pub expr: Expr<'a>,
10516}
10517
10518impl<'a> ComputedPropName<'a> {
10519  pub fn parent(&self) -> Node<'a> {
10520    self.parent.get().unwrap()
10521  }
10522}
10523
10524impl<'a> SourceRanged for ComputedPropName<'a> {
10525  fn start(&self) -> SourcePos {
10526    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10527  }
10528  fn end(&self) -> SourcePos {
10529    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10530  }
10531}
10532
10533impl<'a> From<&ComputedPropName<'a>> for Node<'a> {
10534  fn from(node: &ComputedPropName<'a>) -> Node<'a> {
10535    let node = unsafe { mem::transmute::<&ComputedPropName<'a>, &'a ComputedPropName<'a>>(node) };
10536    Node::ComputedPropName(node)
10537  }
10538}
10539
10540impl<'a> NodeTrait<'a> for ComputedPropName<'a> {
10541  fn parent(&self) -> Option<Node<'a>> {
10542    Some(self.parent.get().unwrap().clone())
10543  }
10544
10545  fn children(&self) -> Vec<Node<'a>> {
10546    let mut children = Vec::with_capacity(1);
10547    children.push((&self.expr).into());
10548    children
10549  }
10550
10551  fn as_node(&self) -> Node<'a> {
10552    self.into()
10553  }
10554
10555  fn kind(&self) -> NodeKind {
10556    NodeKind::ComputedPropName
10557  }
10558}
10559
10560impl<'a> CastableNode<'a> for ComputedPropName<'a> {
10561  fn to(node: &Node<'a>) -> Option<&'a Self> {
10562    if let Node::ComputedPropName(node) = node {
10563      Some(node)
10564    } else {
10565      None
10566    }
10567  }
10568
10569  fn kind() -> NodeKind {
10570    NodeKind::ComputedPropName
10571  }
10572}
10573
10574fn get_view_for_computed_prop_name<'a>(inner: &'a swc_ast::ComputedPropName, bump: &'a Bump) -> &'a ComputedPropName<'a> {
10575  let node = bump.alloc(ComputedPropName {
10576    inner,
10577    parent: Default::default(),
10578    expr: get_view_for_expr(&inner.expr, bump),
10579  });
10580  let parent: Node<'a> = (&*node).into();
10581  set_parent_for_expr(&node.expr, parent);
10582  node
10583}
10584
10585fn set_parent_for_computed_prop_name<'a>(node: &ComputedPropName<'a>, parent: Node<'a>) {
10586  node.parent.set(parent);
10587}
10588
10589#[derive(Clone)]
10590pub struct CondExpr<'a> {
10591  parent: ParentOnceCell<Node<'a>>,
10592  pub inner: &'a swc_ast::CondExpr,
10593  pub test: Expr<'a>,
10594  pub cons: Expr<'a>,
10595  pub alt: Expr<'a>,
10596}
10597
10598impl<'a> CondExpr<'a> {
10599  pub fn parent(&self) -> Node<'a> {
10600    self.parent.get().unwrap()
10601  }
10602}
10603
10604impl<'a> SourceRanged for CondExpr<'a> {
10605  fn start(&self) -> SourcePos {
10606    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10607  }
10608  fn end(&self) -> SourcePos {
10609    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10610  }
10611}
10612
10613impl<'a> From<&CondExpr<'a>> for Node<'a> {
10614  fn from(node: &CondExpr<'a>) -> Node<'a> {
10615    let node = unsafe { mem::transmute::<&CondExpr<'a>, &'a CondExpr<'a>>(node) };
10616    Node::CondExpr(node)
10617  }
10618}
10619
10620impl<'a> NodeTrait<'a> for CondExpr<'a> {
10621  fn parent(&self) -> Option<Node<'a>> {
10622    Some(self.parent.get().unwrap().clone())
10623  }
10624
10625  fn children(&self) -> Vec<Node<'a>> {
10626    let mut children = Vec::with_capacity(3);
10627    children.push((&self.test).into());
10628    children.push((&self.cons).into());
10629    children.push((&self.alt).into());
10630    children
10631  }
10632
10633  fn as_node(&self) -> Node<'a> {
10634    self.into()
10635  }
10636
10637  fn kind(&self) -> NodeKind {
10638    NodeKind::CondExpr
10639  }
10640}
10641
10642impl<'a> CastableNode<'a> for CondExpr<'a> {
10643  fn to(node: &Node<'a>) -> Option<&'a Self> {
10644    if let Node::CondExpr(node) = node {
10645      Some(node)
10646    } else {
10647      None
10648    }
10649  }
10650
10651  fn kind() -> NodeKind {
10652    NodeKind::CondExpr
10653  }
10654}
10655
10656fn get_view_for_cond_expr<'a>(inner: &'a swc_ast::CondExpr, bump: &'a Bump) -> &'a CondExpr<'a> {
10657  let node = bump.alloc(CondExpr {
10658    inner,
10659    parent: Default::default(),
10660    test: get_view_for_expr(&inner.test, bump),
10661    cons: get_view_for_expr(&inner.cons, bump),
10662    alt: get_view_for_expr(&inner.alt, bump),
10663  });
10664  let parent: Node<'a> = (&*node).into();
10665  set_parent_for_expr(&node.test, parent);
10666  set_parent_for_expr(&node.cons, parent);
10667  set_parent_for_expr(&node.alt, parent);
10668  node
10669}
10670
10671fn set_parent_for_cond_expr<'a>(node: &CondExpr<'a>, parent: Node<'a>) {
10672  node.parent.set(parent);
10673}
10674
10675#[derive(Clone)]
10676pub struct Constructor<'a> {
10677  parent: ParentOnceCell<&'a Class<'a>>,
10678  pub inner: &'a swc_ast::Constructor,
10679  pub key: PropName<'a>,
10680  pub params: &'a [ParamOrTsParamProp<'a>],
10681  pub body: Option<&'a BlockStmt<'a>>,
10682}
10683
10684impl<'a> Constructor<'a> {
10685  pub fn parent(&self) -> &'a Class<'a> {
10686    self.parent.get().unwrap()
10687  }
10688
10689  pub fn ctxt(&self) -> swc_common::SyntaxContext {
10690    self.inner.ctxt
10691  }
10692
10693  pub fn accessibility(&self) -> Option<Accessibility> {
10694    self.inner.accessibility
10695  }
10696
10697  pub fn is_optional(&self) -> bool {
10698    self.inner.is_optional
10699  }
10700}
10701
10702impl<'a> SourceRanged for Constructor<'a> {
10703  fn start(&self) -> SourcePos {
10704    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10705  }
10706  fn end(&self) -> SourcePos {
10707    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10708  }
10709}
10710
10711impl<'a> From<&Constructor<'a>> for Node<'a> {
10712  fn from(node: &Constructor<'a>) -> Node<'a> {
10713    let node = unsafe { mem::transmute::<&Constructor<'a>, &'a Constructor<'a>>(node) };
10714    Node::Constructor(node)
10715  }
10716}
10717
10718impl<'a> NodeTrait<'a> for Constructor<'a> {
10719  fn parent(&self) -> Option<Node<'a>> {
10720    Some(self.parent.get().unwrap().into())
10721  }
10722
10723  fn children(&self) -> Vec<Node<'a>> {
10724    let mut children = Vec::with_capacity(1 + self.params.len() + match &self.body { Some(_value) => 1, None => 0, });
10725    children.push((&self.key).into());
10726    for child in self.params.iter() {
10727      children.push(child.into());
10728    }
10729    if let Some(child) = self.body {
10730      children.push(child.into());
10731    }
10732    children
10733  }
10734
10735  fn as_node(&self) -> Node<'a> {
10736    self.into()
10737  }
10738
10739  fn kind(&self) -> NodeKind {
10740    NodeKind::Constructor
10741  }
10742}
10743
10744impl<'a> CastableNode<'a> for Constructor<'a> {
10745  fn to(node: &Node<'a>) -> Option<&'a Self> {
10746    if let Node::Constructor(node) = node {
10747      Some(node)
10748    } else {
10749      None
10750    }
10751  }
10752
10753  fn kind() -> NodeKind {
10754    NodeKind::Constructor
10755  }
10756}
10757
10758fn get_view_for_constructor<'a>(inner: &'a swc_ast::Constructor, bump: &'a Bump) -> &'a Constructor<'a> {
10759  let node = bump.alloc(Constructor {
10760    inner,
10761    parent: Default::default(),
10762    key: get_view_for_prop_name(&inner.key, bump),
10763    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 }),
10764    body: match &inner.body {
10765      Some(value) => Some(get_view_for_block_stmt(value, bump)),
10766      None => None,
10767    },
10768  });
10769  let parent: Node<'a> = (&*node).into();
10770  set_parent_for_prop_name(&node.key, parent);
10771  for value in node.params.iter() {
10772    set_parent_for_param_or_ts_param_prop(value, parent)
10773  }
10774  if let Some(value) = &node.body {
10775    set_parent_for_block_stmt(value, parent)
10776  };
10777  node
10778}
10779
10780fn set_parent_for_constructor<'a>(node: &Constructor<'a>, parent: Node<'a>) {
10781  node.parent.set(parent.expect::<Class>());
10782}
10783
10784#[derive(Clone)]
10785pub struct ContinueStmt<'a> {
10786  parent: ParentOnceCell<Node<'a>>,
10787  pub inner: &'a swc_ast::ContinueStmt,
10788  pub label: Option<&'a Ident<'a>>,
10789}
10790
10791impl<'a> ContinueStmt<'a> {
10792  pub fn parent(&self) -> Node<'a> {
10793    self.parent.get().unwrap()
10794  }
10795}
10796
10797impl<'a> SourceRanged for ContinueStmt<'a> {
10798  fn start(&self) -> SourcePos {
10799    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10800  }
10801  fn end(&self) -> SourcePos {
10802    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10803  }
10804}
10805
10806impl<'a> From<&ContinueStmt<'a>> for Node<'a> {
10807  fn from(node: &ContinueStmt<'a>) -> Node<'a> {
10808    let node = unsafe { mem::transmute::<&ContinueStmt<'a>, &'a ContinueStmt<'a>>(node) };
10809    Node::ContinueStmt(node)
10810  }
10811}
10812
10813impl<'a> NodeTrait<'a> for ContinueStmt<'a> {
10814  fn parent(&self) -> Option<Node<'a>> {
10815    Some(self.parent.get().unwrap().clone())
10816  }
10817
10818  fn children(&self) -> Vec<Node<'a>> {
10819    let mut children = Vec::with_capacity(match &self.label { Some(_value) => 1, None => 0, });
10820    if let Some(child) = self.label {
10821      children.push(child.into());
10822    }
10823    children
10824  }
10825
10826  fn as_node(&self) -> Node<'a> {
10827    self.into()
10828  }
10829
10830  fn kind(&self) -> NodeKind {
10831    NodeKind::ContinueStmt
10832  }
10833}
10834
10835impl<'a> CastableNode<'a> for ContinueStmt<'a> {
10836  fn to(node: &Node<'a>) -> Option<&'a Self> {
10837    if let Node::ContinueStmt(node) = node {
10838      Some(node)
10839    } else {
10840      None
10841    }
10842  }
10843
10844  fn kind() -> NodeKind {
10845    NodeKind::ContinueStmt
10846  }
10847}
10848
10849fn get_view_for_continue_stmt<'a>(inner: &'a swc_ast::ContinueStmt, bump: &'a Bump) -> &'a ContinueStmt<'a> {
10850  let node = bump.alloc(ContinueStmt {
10851    inner,
10852    parent: Default::default(),
10853    label: match &inner.label {
10854      Some(value) => Some(get_view_for_ident(value, bump)),
10855      None => None,
10856    },
10857  });
10858  let parent: Node<'a> = (&*node).into();
10859  if let Some(value) = &node.label {
10860    set_parent_for_ident(value, parent)
10861  };
10862  node
10863}
10864
10865fn set_parent_for_continue_stmt<'a>(node: &ContinueStmt<'a>, parent: Node<'a>) {
10866  node.parent.set(parent);
10867}
10868
10869#[derive(Clone)]
10870pub struct DebuggerStmt<'a> {
10871  parent: ParentOnceCell<Node<'a>>,
10872  pub inner: &'a swc_ast::DebuggerStmt,
10873}
10874
10875impl<'a> DebuggerStmt<'a> {
10876  pub fn parent(&self) -> Node<'a> {
10877    self.parent.get().unwrap()
10878  }
10879}
10880
10881impl<'a> SourceRanged for DebuggerStmt<'a> {
10882  fn start(&self) -> SourcePos {
10883    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10884  }
10885  fn end(&self) -> SourcePos {
10886    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10887  }
10888}
10889
10890impl<'a> From<&DebuggerStmt<'a>> for Node<'a> {
10891  fn from(node: &DebuggerStmt<'a>) -> Node<'a> {
10892    let node = unsafe { mem::transmute::<&DebuggerStmt<'a>, &'a DebuggerStmt<'a>>(node) };
10893    Node::DebuggerStmt(node)
10894  }
10895}
10896
10897impl<'a> NodeTrait<'a> for DebuggerStmt<'a> {
10898  fn parent(&self) -> Option<Node<'a>> {
10899    Some(self.parent.get().unwrap().clone())
10900  }
10901
10902  fn children(&self) -> Vec<Node<'a>> {
10903    Vec::with_capacity(0)
10904  }
10905
10906  fn as_node(&self) -> Node<'a> {
10907    self.into()
10908  }
10909
10910  fn kind(&self) -> NodeKind {
10911    NodeKind::DebuggerStmt
10912  }
10913}
10914
10915impl<'a> CastableNode<'a> for DebuggerStmt<'a> {
10916  fn to(node: &Node<'a>) -> Option<&'a Self> {
10917    if let Node::DebuggerStmt(node) = node {
10918      Some(node)
10919    } else {
10920      None
10921    }
10922  }
10923
10924  fn kind() -> NodeKind {
10925    NodeKind::DebuggerStmt
10926  }
10927}
10928
10929fn get_view_for_debugger_stmt<'a>(inner: &'a swc_ast::DebuggerStmt, bump: &'a Bump) -> &'a DebuggerStmt<'a> {
10930  let node = bump.alloc(DebuggerStmt {
10931    inner,
10932    parent: Default::default(),
10933  });
10934  node
10935}
10936
10937fn set_parent_for_debugger_stmt<'a>(node: &DebuggerStmt<'a>, parent: Node<'a>) {
10938  node.parent.set(parent);
10939}
10940
10941#[derive(Clone)]
10942pub struct Decorator<'a> {
10943  parent: ParentOnceCell<Node<'a>>,
10944  pub inner: &'a swc_ast::Decorator,
10945  pub expr: Expr<'a>,
10946}
10947
10948impl<'a> Decorator<'a> {
10949  pub fn parent(&self) -> Node<'a> {
10950    self.parent.get().unwrap()
10951  }
10952}
10953
10954impl<'a> SourceRanged for Decorator<'a> {
10955  fn start(&self) -> SourcePos {
10956    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
10957  }
10958  fn end(&self) -> SourcePos {
10959    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
10960  }
10961}
10962
10963impl<'a> From<&Decorator<'a>> for Node<'a> {
10964  fn from(node: &Decorator<'a>) -> Node<'a> {
10965    let node = unsafe { mem::transmute::<&Decorator<'a>, &'a Decorator<'a>>(node) };
10966    Node::Decorator(node)
10967  }
10968}
10969
10970impl<'a> NodeTrait<'a> for Decorator<'a> {
10971  fn parent(&self) -> Option<Node<'a>> {
10972    Some(self.parent.get().unwrap().clone())
10973  }
10974
10975  fn children(&self) -> Vec<Node<'a>> {
10976    let mut children = Vec::with_capacity(1);
10977    children.push((&self.expr).into());
10978    children
10979  }
10980
10981  fn as_node(&self) -> Node<'a> {
10982    self.into()
10983  }
10984
10985  fn kind(&self) -> NodeKind {
10986    NodeKind::Decorator
10987  }
10988}
10989
10990impl<'a> CastableNode<'a> for Decorator<'a> {
10991  fn to(node: &Node<'a>) -> Option<&'a Self> {
10992    if let Node::Decorator(node) = node {
10993      Some(node)
10994    } else {
10995      None
10996    }
10997  }
10998
10999  fn kind() -> NodeKind {
11000    NodeKind::Decorator
11001  }
11002}
11003
11004fn get_view_for_decorator<'a>(inner: &'a swc_ast::Decorator, bump: &'a Bump) -> &'a Decorator<'a> {
11005  let node = bump.alloc(Decorator {
11006    inner,
11007    parent: Default::default(),
11008    expr: get_view_for_expr(&inner.expr, bump),
11009  });
11010  let parent: Node<'a> = (&*node).into();
11011  set_parent_for_expr(&node.expr, parent);
11012  node
11013}
11014
11015fn set_parent_for_decorator<'a>(node: &Decorator<'a>, parent: Node<'a>) {
11016  node.parent.set(parent);
11017}
11018
11019#[derive(Clone)]
11020pub struct DoWhileStmt<'a> {
11021  parent: ParentOnceCell<Node<'a>>,
11022  pub inner: &'a swc_ast::DoWhileStmt,
11023  pub test: Expr<'a>,
11024  pub body: Stmt<'a>,
11025}
11026
11027impl<'a> DoWhileStmt<'a> {
11028  pub fn parent(&self) -> Node<'a> {
11029    self.parent.get().unwrap()
11030  }
11031}
11032
11033impl<'a> SourceRanged for DoWhileStmt<'a> {
11034  fn start(&self) -> SourcePos {
11035    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11036  }
11037  fn end(&self) -> SourcePos {
11038    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11039  }
11040}
11041
11042impl<'a> From<&DoWhileStmt<'a>> for Node<'a> {
11043  fn from(node: &DoWhileStmt<'a>) -> Node<'a> {
11044    let node = unsafe { mem::transmute::<&DoWhileStmt<'a>, &'a DoWhileStmt<'a>>(node) };
11045    Node::DoWhileStmt(node)
11046  }
11047}
11048
11049impl<'a> NodeTrait<'a> for DoWhileStmt<'a> {
11050  fn parent(&self) -> Option<Node<'a>> {
11051    Some(self.parent.get().unwrap().clone())
11052  }
11053
11054  fn children(&self) -> Vec<Node<'a>> {
11055    let mut children = Vec::with_capacity(2);
11056    children.push((&self.test).into());
11057    children.push((&self.body).into());
11058    children
11059  }
11060
11061  fn as_node(&self) -> Node<'a> {
11062    self.into()
11063  }
11064
11065  fn kind(&self) -> NodeKind {
11066    NodeKind::DoWhileStmt
11067  }
11068}
11069
11070impl<'a> CastableNode<'a> for DoWhileStmt<'a> {
11071  fn to(node: &Node<'a>) -> Option<&'a Self> {
11072    if let Node::DoWhileStmt(node) = node {
11073      Some(node)
11074    } else {
11075      None
11076    }
11077  }
11078
11079  fn kind() -> NodeKind {
11080    NodeKind::DoWhileStmt
11081  }
11082}
11083
11084fn get_view_for_do_while_stmt<'a>(inner: &'a swc_ast::DoWhileStmt, bump: &'a Bump) -> &'a DoWhileStmt<'a> {
11085  let node = bump.alloc(DoWhileStmt {
11086    inner,
11087    parent: Default::default(),
11088    test: get_view_for_expr(&inner.test, bump),
11089    body: get_view_for_stmt(&inner.body, bump),
11090  });
11091  let parent: Node<'a> = (&*node).into();
11092  set_parent_for_expr(&node.test, parent);
11093  set_parent_for_stmt(&node.body, parent);
11094  node
11095}
11096
11097fn set_parent_for_do_while_stmt<'a>(node: &DoWhileStmt<'a>, parent: Node<'a>) {
11098  node.parent.set(parent);
11099}
11100
11101#[derive(Clone)]
11102pub struct EmptyStmt<'a> {
11103  parent: ParentOnceCell<Node<'a>>,
11104  pub inner: &'a swc_ast::EmptyStmt,
11105}
11106
11107impl<'a> EmptyStmt<'a> {
11108  pub fn parent(&self) -> Node<'a> {
11109    self.parent.get().unwrap()
11110  }
11111}
11112
11113impl<'a> SourceRanged for EmptyStmt<'a> {
11114  fn start(&self) -> SourcePos {
11115    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11116  }
11117  fn end(&self) -> SourcePos {
11118    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11119  }
11120}
11121
11122impl<'a> From<&EmptyStmt<'a>> for Node<'a> {
11123  fn from(node: &EmptyStmt<'a>) -> Node<'a> {
11124    let node = unsafe { mem::transmute::<&EmptyStmt<'a>, &'a EmptyStmt<'a>>(node) };
11125    Node::EmptyStmt(node)
11126  }
11127}
11128
11129impl<'a> NodeTrait<'a> for EmptyStmt<'a> {
11130  fn parent(&self) -> Option<Node<'a>> {
11131    Some(self.parent.get().unwrap().clone())
11132  }
11133
11134  fn children(&self) -> Vec<Node<'a>> {
11135    Vec::with_capacity(0)
11136  }
11137
11138  fn as_node(&self) -> Node<'a> {
11139    self.into()
11140  }
11141
11142  fn kind(&self) -> NodeKind {
11143    NodeKind::EmptyStmt
11144  }
11145}
11146
11147impl<'a> CastableNode<'a> for EmptyStmt<'a> {
11148  fn to(node: &Node<'a>) -> Option<&'a Self> {
11149    if let Node::EmptyStmt(node) = node {
11150      Some(node)
11151    } else {
11152      None
11153    }
11154  }
11155
11156  fn kind() -> NodeKind {
11157    NodeKind::EmptyStmt
11158  }
11159}
11160
11161fn get_view_for_empty_stmt<'a>(inner: &'a swc_ast::EmptyStmt, bump: &'a Bump) -> &'a EmptyStmt<'a> {
11162  let node = bump.alloc(EmptyStmt {
11163    inner,
11164    parent: Default::default(),
11165  });
11166  node
11167}
11168
11169fn set_parent_for_empty_stmt<'a>(node: &EmptyStmt<'a>, parent: Node<'a>) {
11170  node.parent.set(parent);
11171}
11172
11173/// `export * from 'mod'`
11174#[derive(Clone)]
11175pub struct ExportAll<'a> {
11176  parent: ParentOnceCell<Node<'a>>,
11177  pub inner: &'a swc_ast::ExportAll,
11178  pub src: &'a Str<'a>,
11179  pub with: Option<&'a ObjectLit<'a>>,
11180}
11181
11182impl<'a> ExportAll<'a> {
11183  pub fn parent(&self) -> Node<'a> {
11184    self.parent.get().unwrap()
11185  }
11186
11187  pub fn type_only(&self) -> bool {
11188    self.inner.type_only
11189  }
11190}
11191
11192impl<'a> SourceRanged for ExportAll<'a> {
11193  fn start(&self) -> SourcePos {
11194    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11195  }
11196  fn end(&self) -> SourcePos {
11197    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11198  }
11199}
11200
11201impl<'a> From<&ExportAll<'a>> for Node<'a> {
11202  fn from(node: &ExportAll<'a>) -> Node<'a> {
11203    let node = unsafe { mem::transmute::<&ExportAll<'a>, &'a ExportAll<'a>>(node) };
11204    Node::ExportAll(node)
11205  }
11206}
11207
11208impl<'a> NodeTrait<'a> for ExportAll<'a> {
11209  fn parent(&self) -> Option<Node<'a>> {
11210    Some(self.parent.get().unwrap().clone())
11211  }
11212
11213  fn children(&self) -> Vec<Node<'a>> {
11214    let mut children = Vec::with_capacity(1 + match &self.with { Some(_value) => 1, None => 0, });
11215    children.push(self.src.into());
11216    if let Some(child) = self.with {
11217      children.push(child.into());
11218    }
11219    children
11220  }
11221
11222  fn as_node(&self) -> Node<'a> {
11223    self.into()
11224  }
11225
11226  fn kind(&self) -> NodeKind {
11227    NodeKind::ExportAll
11228  }
11229}
11230
11231impl<'a> CastableNode<'a> for ExportAll<'a> {
11232  fn to(node: &Node<'a>) -> Option<&'a Self> {
11233    if let Node::ExportAll(node) = node {
11234      Some(node)
11235    } else {
11236      None
11237    }
11238  }
11239
11240  fn kind() -> NodeKind {
11241    NodeKind::ExportAll
11242  }
11243}
11244
11245fn get_view_for_export_all<'a>(inner: &'a swc_ast::ExportAll, bump: &'a Bump) -> &'a ExportAll<'a> {
11246  let node = bump.alloc(ExportAll {
11247    inner,
11248    parent: Default::default(),
11249    src: get_view_for_str(&inner.src, bump),
11250    with: match &inner.with {
11251      Some(value) => Some(get_view_for_object_lit(value, bump)),
11252      None => None,
11253    },
11254  });
11255  let parent: Node<'a> = (&*node).into();
11256  set_parent_for_str(&node.src, parent);
11257  if let Some(value) = &node.with {
11258    set_parent_for_object_lit(value, parent)
11259  };
11260  node
11261}
11262
11263fn set_parent_for_export_all<'a>(node: &ExportAll<'a>, parent: Node<'a>) {
11264  node.parent.set(parent);
11265}
11266
11267#[derive(Clone)]
11268pub struct ExportDecl<'a> {
11269  parent: ParentOnceCell<Node<'a>>,
11270  pub inner: &'a swc_ast::ExportDecl,
11271  pub decl: Decl<'a>,
11272}
11273
11274impl<'a> ExportDecl<'a> {
11275  pub fn parent(&self) -> Node<'a> {
11276    self.parent.get().unwrap()
11277  }
11278}
11279
11280impl<'a> SourceRanged for ExportDecl<'a> {
11281  fn start(&self) -> SourcePos {
11282    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11283  }
11284  fn end(&self) -> SourcePos {
11285    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11286  }
11287}
11288
11289impl<'a> From<&ExportDecl<'a>> for Node<'a> {
11290  fn from(node: &ExportDecl<'a>) -> Node<'a> {
11291    let node = unsafe { mem::transmute::<&ExportDecl<'a>, &'a ExportDecl<'a>>(node) };
11292    Node::ExportDecl(node)
11293  }
11294}
11295
11296impl<'a> NodeTrait<'a> for ExportDecl<'a> {
11297  fn parent(&self) -> Option<Node<'a>> {
11298    Some(self.parent.get().unwrap().clone())
11299  }
11300
11301  fn children(&self) -> Vec<Node<'a>> {
11302    let mut children = Vec::with_capacity(1);
11303    children.push((&self.decl).into());
11304    children
11305  }
11306
11307  fn as_node(&self) -> Node<'a> {
11308    self.into()
11309  }
11310
11311  fn kind(&self) -> NodeKind {
11312    NodeKind::ExportDecl
11313  }
11314}
11315
11316impl<'a> CastableNode<'a> for ExportDecl<'a> {
11317  fn to(node: &Node<'a>) -> Option<&'a Self> {
11318    if let Node::ExportDecl(node) = node {
11319      Some(node)
11320    } else {
11321      None
11322    }
11323  }
11324
11325  fn kind() -> NodeKind {
11326    NodeKind::ExportDecl
11327  }
11328}
11329
11330fn get_view_for_export_decl<'a>(inner: &'a swc_ast::ExportDecl, bump: &'a Bump) -> &'a ExportDecl<'a> {
11331  let node = bump.alloc(ExportDecl {
11332    inner,
11333    parent: Default::default(),
11334    decl: get_view_for_decl(&inner.decl, bump),
11335  });
11336  let parent: Node<'a> = (&*node).into();
11337  set_parent_for_decl(&node.decl, parent);
11338  node
11339}
11340
11341fn set_parent_for_export_decl<'a>(node: &ExportDecl<'a>, parent: Node<'a>) {
11342  node.parent.set(parent);
11343}
11344
11345#[derive(Clone)]
11346pub struct ExportDefaultDecl<'a> {
11347  parent: ParentOnceCell<Node<'a>>,
11348  pub inner: &'a swc_ast::ExportDefaultDecl,
11349  pub decl: DefaultDecl<'a>,
11350}
11351
11352impl<'a> ExportDefaultDecl<'a> {
11353  pub fn parent(&self) -> Node<'a> {
11354    self.parent.get().unwrap()
11355  }
11356}
11357
11358impl<'a> SourceRanged for ExportDefaultDecl<'a> {
11359  fn start(&self) -> SourcePos {
11360    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11361  }
11362  fn end(&self) -> SourcePos {
11363    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11364  }
11365}
11366
11367impl<'a> From<&ExportDefaultDecl<'a>> for Node<'a> {
11368  fn from(node: &ExportDefaultDecl<'a>) -> Node<'a> {
11369    let node = unsafe { mem::transmute::<&ExportDefaultDecl<'a>, &'a ExportDefaultDecl<'a>>(node) };
11370    Node::ExportDefaultDecl(node)
11371  }
11372}
11373
11374impl<'a> NodeTrait<'a> for ExportDefaultDecl<'a> {
11375  fn parent(&self) -> Option<Node<'a>> {
11376    Some(self.parent.get().unwrap().clone())
11377  }
11378
11379  fn children(&self) -> Vec<Node<'a>> {
11380    let mut children = Vec::with_capacity(1);
11381    children.push((&self.decl).into());
11382    children
11383  }
11384
11385  fn as_node(&self) -> Node<'a> {
11386    self.into()
11387  }
11388
11389  fn kind(&self) -> NodeKind {
11390    NodeKind::ExportDefaultDecl
11391  }
11392}
11393
11394impl<'a> CastableNode<'a> for ExportDefaultDecl<'a> {
11395  fn to(node: &Node<'a>) -> Option<&'a Self> {
11396    if let Node::ExportDefaultDecl(node) = node {
11397      Some(node)
11398    } else {
11399      None
11400    }
11401  }
11402
11403  fn kind() -> NodeKind {
11404    NodeKind::ExportDefaultDecl
11405  }
11406}
11407
11408fn get_view_for_export_default_decl<'a>(inner: &'a swc_ast::ExportDefaultDecl, bump: &'a Bump) -> &'a ExportDefaultDecl<'a> {
11409  let node = bump.alloc(ExportDefaultDecl {
11410    inner,
11411    parent: Default::default(),
11412    decl: get_view_for_default_decl(&inner.decl, bump),
11413  });
11414  let parent: Node<'a> = (&*node).into();
11415  set_parent_for_default_decl(&node.decl, parent);
11416  node
11417}
11418
11419fn set_parent_for_export_default_decl<'a>(node: &ExportDefaultDecl<'a>, parent: Node<'a>) {
11420  node.parent.set(parent);
11421}
11422
11423/// Default exports other than **direct** function expression or class
11424/// expression.
11425///
11426///
11427/// # Note
11428///
11429/// ```ts
11430/// export default function Foo() {
11431/// }
11432/// ```
11433///
11434/// is [`ExportDefaultDecl`] and it's hoisted.
11435///
11436/// ```ts
11437/// export default (function Foo() {
11438/// })
11439/// ```
11440///
11441/// is [`ExportDefaultExpr`] and it's not hoisted.
11442#[derive(Clone)]
11443pub struct ExportDefaultExpr<'a> {
11444  parent: ParentOnceCell<Node<'a>>,
11445  pub inner: &'a swc_ast::ExportDefaultExpr,
11446  pub expr: Expr<'a>,
11447}
11448
11449impl<'a> ExportDefaultExpr<'a> {
11450  pub fn parent(&self) -> Node<'a> {
11451    self.parent.get().unwrap()
11452  }
11453}
11454
11455impl<'a> SourceRanged for ExportDefaultExpr<'a> {
11456  fn start(&self) -> SourcePos {
11457    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11458  }
11459  fn end(&self) -> SourcePos {
11460    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11461  }
11462}
11463
11464impl<'a> From<&ExportDefaultExpr<'a>> for Node<'a> {
11465  fn from(node: &ExportDefaultExpr<'a>) -> Node<'a> {
11466    let node = unsafe { mem::transmute::<&ExportDefaultExpr<'a>, &'a ExportDefaultExpr<'a>>(node) };
11467    Node::ExportDefaultExpr(node)
11468  }
11469}
11470
11471impl<'a> NodeTrait<'a> for ExportDefaultExpr<'a> {
11472  fn parent(&self) -> Option<Node<'a>> {
11473    Some(self.parent.get().unwrap().clone())
11474  }
11475
11476  fn children(&self) -> Vec<Node<'a>> {
11477    let mut children = Vec::with_capacity(1);
11478    children.push((&self.expr).into());
11479    children
11480  }
11481
11482  fn as_node(&self) -> Node<'a> {
11483    self.into()
11484  }
11485
11486  fn kind(&self) -> NodeKind {
11487    NodeKind::ExportDefaultExpr
11488  }
11489}
11490
11491impl<'a> CastableNode<'a> for ExportDefaultExpr<'a> {
11492  fn to(node: &Node<'a>) -> Option<&'a Self> {
11493    if let Node::ExportDefaultExpr(node) = node {
11494      Some(node)
11495    } else {
11496      None
11497    }
11498  }
11499
11500  fn kind() -> NodeKind {
11501    NodeKind::ExportDefaultExpr
11502  }
11503}
11504
11505fn get_view_for_export_default_expr<'a>(inner: &'a swc_ast::ExportDefaultExpr, bump: &'a Bump) -> &'a ExportDefaultExpr<'a> {
11506  let node = bump.alloc(ExportDefaultExpr {
11507    inner,
11508    parent: Default::default(),
11509    expr: get_view_for_expr(&inner.expr, bump),
11510  });
11511  let parent: Node<'a> = (&*node).into();
11512  set_parent_for_expr(&node.expr, parent);
11513  node
11514}
11515
11516fn set_parent_for_export_default_expr<'a>(node: &ExportDefaultExpr<'a>, parent: Node<'a>) {
11517  node.parent.set(parent);
11518}
11519
11520#[derive(Clone)]
11521pub struct ExportDefaultSpecifier<'a> {
11522  parent: ParentOnceCell<&'a NamedExport<'a>>,
11523  pub inner: &'a swc_ast::ExportDefaultSpecifier,
11524  pub exported: &'a Ident<'a>,
11525}
11526
11527impl<'a> ExportDefaultSpecifier<'a> {
11528  pub fn parent(&self) -> &'a NamedExport<'a> {
11529    self.parent.get().unwrap()
11530  }
11531}
11532
11533impl<'a> SourceRanged for ExportDefaultSpecifier<'a> {
11534  fn start(&self) -> SourcePos {
11535    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11536  }
11537  fn end(&self) -> SourcePos {
11538    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11539  }
11540}
11541
11542impl<'a> From<&ExportDefaultSpecifier<'a>> for Node<'a> {
11543  fn from(node: &ExportDefaultSpecifier<'a>) -> Node<'a> {
11544    let node = unsafe { mem::transmute::<&ExportDefaultSpecifier<'a>, &'a ExportDefaultSpecifier<'a>>(node) };
11545    Node::ExportDefaultSpecifier(node)
11546  }
11547}
11548
11549impl<'a> NodeTrait<'a> for ExportDefaultSpecifier<'a> {
11550  fn parent(&self) -> Option<Node<'a>> {
11551    Some(self.parent.get().unwrap().into())
11552  }
11553
11554  fn children(&self) -> Vec<Node<'a>> {
11555    let mut children = Vec::with_capacity(1);
11556    children.push(self.exported.into());
11557    children
11558  }
11559
11560  fn as_node(&self) -> Node<'a> {
11561    self.into()
11562  }
11563
11564  fn kind(&self) -> NodeKind {
11565    NodeKind::ExportDefaultSpecifier
11566  }
11567}
11568
11569impl<'a> CastableNode<'a> for ExportDefaultSpecifier<'a> {
11570  fn to(node: &Node<'a>) -> Option<&'a Self> {
11571    if let Node::ExportDefaultSpecifier(node) = node {
11572      Some(node)
11573    } else {
11574      None
11575    }
11576  }
11577
11578  fn kind() -> NodeKind {
11579    NodeKind::ExportDefaultSpecifier
11580  }
11581}
11582
11583fn get_view_for_export_default_specifier<'a>(inner: &'a swc_ast::ExportDefaultSpecifier, bump: &'a Bump) -> &'a ExportDefaultSpecifier<'a> {
11584  let node = bump.alloc(ExportDefaultSpecifier {
11585    inner,
11586    parent: Default::default(),
11587    exported: get_view_for_ident(&inner.exported, bump),
11588  });
11589  let parent: Node<'a> = (&*node).into();
11590  set_parent_for_ident(&node.exported, parent);
11591  node
11592}
11593
11594fn set_parent_for_export_default_specifier<'a>(node: &ExportDefaultSpecifier<'a>, parent: Node<'a>) {
11595  node.parent.set(parent.expect::<NamedExport>());
11596}
11597
11598#[derive(Clone)]
11599pub struct ExportNamedSpecifier<'a> {
11600  parent: ParentOnceCell<&'a NamedExport<'a>>,
11601  pub inner: &'a swc_ast::ExportNamedSpecifier,
11602  /// `foo` in `export { foo as bar }`
11603  pub orig: ModuleExportName<'a>,
11604  /// `Some(bar)` in `export { foo as bar }`
11605  pub exported: Option<ModuleExportName<'a>>,
11606}
11607
11608impl<'a> ExportNamedSpecifier<'a> {
11609  pub fn parent(&self) -> &'a NamedExport<'a> {
11610    self.parent.get().unwrap()
11611  }
11612
11613  /// `type` in `export { type foo as bar }`
11614  pub fn is_type_only(&self) -> bool {
11615    self.inner.is_type_only
11616  }
11617}
11618
11619impl<'a> SourceRanged for ExportNamedSpecifier<'a> {
11620  fn start(&self) -> SourcePos {
11621    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11622  }
11623  fn end(&self) -> SourcePos {
11624    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11625  }
11626}
11627
11628impl<'a> From<&ExportNamedSpecifier<'a>> for Node<'a> {
11629  fn from(node: &ExportNamedSpecifier<'a>) -> Node<'a> {
11630    let node = unsafe { mem::transmute::<&ExportNamedSpecifier<'a>, &'a ExportNamedSpecifier<'a>>(node) };
11631    Node::ExportNamedSpecifier(node)
11632  }
11633}
11634
11635impl<'a> NodeTrait<'a> for ExportNamedSpecifier<'a> {
11636  fn parent(&self) -> Option<Node<'a>> {
11637    Some(self.parent.get().unwrap().into())
11638  }
11639
11640  fn children(&self) -> Vec<Node<'a>> {
11641    let mut children = Vec::with_capacity(1 + match &self.exported { Some(_value) => 1, None => 0, });
11642    children.push((&self.orig).into());
11643    if let Some(child) = self.exported.as_ref() {
11644      children.push(child.into());
11645    }
11646    children
11647  }
11648
11649  fn as_node(&self) -> Node<'a> {
11650    self.into()
11651  }
11652
11653  fn kind(&self) -> NodeKind {
11654    NodeKind::ExportNamedSpecifier
11655  }
11656}
11657
11658impl<'a> CastableNode<'a> for ExportNamedSpecifier<'a> {
11659  fn to(node: &Node<'a>) -> Option<&'a Self> {
11660    if let Node::ExportNamedSpecifier(node) = node {
11661      Some(node)
11662    } else {
11663      None
11664    }
11665  }
11666
11667  fn kind() -> NodeKind {
11668    NodeKind::ExportNamedSpecifier
11669  }
11670}
11671
11672fn get_view_for_export_named_specifier<'a>(inner: &'a swc_ast::ExportNamedSpecifier, bump: &'a Bump) -> &'a ExportNamedSpecifier<'a> {
11673  let node = bump.alloc(ExportNamedSpecifier {
11674    inner,
11675    parent: Default::default(),
11676    orig: get_view_for_module_export_name(&inner.orig, bump),
11677    exported: match &inner.exported {
11678      Some(value) => Some(get_view_for_module_export_name(value, bump)),
11679      None => None,
11680    },
11681  });
11682  let parent: Node<'a> = (&*node).into();
11683  set_parent_for_module_export_name(&node.orig, parent);
11684  if let Some(value) = &node.exported {
11685    set_parent_for_module_export_name(value, parent)
11686  };
11687  node
11688}
11689
11690fn set_parent_for_export_named_specifier<'a>(node: &ExportNamedSpecifier<'a>, parent: Node<'a>) {
11691  node.parent.set(parent.expect::<NamedExport>());
11692}
11693
11694/// `export * as foo from 'src';`
11695#[derive(Clone)]
11696pub struct ExportNamespaceSpecifier<'a> {
11697  parent: ParentOnceCell<&'a NamedExport<'a>>,
11698  pub inner: &'a swc_ast::ExportNamespaceSpecifier,
11699  pub name: ModuleExportName<'a>,
11700}
11701
11702impl<'a> ExportNamespaceSpecifier<'a> {
11703  pub fn parent(&self) -> &'a NamedExport<'a> {
11704    self.parent.get().unwrap()
11705  }
11706}
11707
11708impl<'a> SourceRanged for ExportNamespaceSpecifier<'a> {
11709  fn start(&self) -> SourcePos {
11710    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11711  }
11712  fn end(&self) -> SourcePos {
11713    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11714  }
11715}
11716
11717impl<'a> From<&ExportNamespaceSpecifier<'a>> for Node<'a> {
11718  fn from(node: &ExportNamespaceSpecifier<'a>) -> Node<'a> {
11719    let node = unsafe { mem::transmute::<&ExportNamespaceSpecifier<'a>, &'a ExportNamespaceSpecifier<'a>>(node) };
11720    Node::ExportNamespaceSpecifier(node)
11721  }
11722}
11723
11724impl<'a> NodeTrait<'a> for ExportNamespaceSpecifier<'a> {
11725  fn parent(&self) -> Option<Node<'a>> {
11726    Some(self.parent.get().unwrap().into())
11727  }
11728
11729  fn children(&self) -> Vec<Node<'a>> {
11730    let mut children = Vec::with_capacity(1);
11731    children.push((&self.name).into());
11732    children
11733  }
11734
11735  fn as_node(&self) -> Node<'a> {
11736    self.into()
11737  }
11738
11739  fn kind(&self) -> NodeKind {
11740    NodeKind::ExportNamespaceSpecifier
11741  }
11742}
11743
11744impl<'a> CastableNode<'a> for ExportNamespaceSpecifier<'a> {
11745  fn to(node: &Node<'a>) -> Option<&'a Self> {
11746    if let Node::ExportNamespaceSpecifier(node) = node {
11747      Some(node)
11748    } else {
11749      None
11750    }
11751  }
11752
11753  fn kind() -> NodeKind {
11754    NodeKind::ExportNamespaceSpecifier
11755  }
11756}
11757
11758fn get_view_for_export_namespace_specifier<'a>(inner: &'a swc_ast::ExportNamespaceSpecifier, bump: &'a Bump) -> &'a ExportNamespaceSpecifier<'a> {
11759  let node = bump.alloc(ExportNamespaceSpecifier {
11760    inner,
11761    parent: Default::default(),
11762    name: get_view_for_module_export_name(&inner.name, bump),
11763  });
11764  let parent: Node<'a> = (&*node).into();
11765  set_parent_for_module_export_name(&node.name, parent);
11766  node
11767}
11768
11769fn set_parent_for_export_namespace_specifier<'a>(node: &ExportNamespaceSpecifier<'a>, parent: Node<'a>) {
11770  node.parent.set(parent.expect::<NamedExport>());
11771}
11772
11773#[derive(Clone)]
11774pub struct ExprOrSpread<'a> {
11775  parent: ParentOnceCell<Node<'a>>,
11776  pub inner: &'a swc_ast::ExprOrSpread,
11777  pub expr: Expr<'a>,
11778}
11779
11780impl<'a> ExprOrSpread<'a> {
11781  pub fn parent(&self) -> Node<'a> {
11782    self.parent.get().unwrap()
11783  }
11784
11785  pub fn spread(&self) -> &Option<swc_common::Span> {
11786    &self.inner.spread
11787  }
11788}
11789
11790impl<'a> SourceRanged for ExprOrSpread<'a> {
11791  fn start(&self) -> SourcePos {
11792    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11793  }
11794  fn end(&self) -> SourcePos {
11795    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11796  }
11797}
11798
11799impl<'a> From<&ExprOrSpread<'a>> for Node<'a> {
11800  fn from(node: &ExprOrSpread<'a>) -> Node<'a> {
11801    let node = unsafe { mem::transmute::<&ExprOrSpread<'a>, &'a ExprOrSpread<'a>>(node) };
11802    Node::ExprOrSpread(node)
11803  }
11804}
11805
11806impl<'a> NodeTrait<'a> for ExprOrSpread<'a> {
11807  fn parent(&self) -> Option<Node<'a>> {
11808    Some(self.parent.get().unwrap().clone())
11809  }
11810
11811  fn children(&self) -> Vec<Node<'a>> {
11812    let mut children = Vec::with_capacity(1);
11813    children.push((&self.expr).into());
11814    children
11815  }
11816
11817  fn as_node(&self) -> Node<'a> {
11818    self.into()
11819  }
11820
11821  fn kind(&self) -> NodeKind {
11822    NodeKind::ExprOrSpread
11823  }
11824}
11825
11826impl<'a> CastableNode<'a> for ExprOrSpread<'a> {
11827  fn to(node: &Node<'a>) -> Option<&'a Self> {
11828    if let Node::ExprOrSpread(node) = node {
11829      Some(node)
11830    } else {
11831      None
11832    }
11833  }
11834
11835  fn kind() -> NodeKind {
11836    NodeKind::ExprOrSpread
11837  }
11838}
11839
11840fn get_view_for_expr_or_spread<'a>(inner: &'a swc_ast::ExprOrSpread, bump: &'a Bump) -> &'a ExprOrSpread<'a> {
11841  let node = bump.alloc(ExprOrSpread {
11842    inner,
11843    parent: Default::default(),
11844    expr: get_view_for_expr(&inner.expr, bump),
11845  });
11846  let parent: Node<'a> = (&*node).into();
11847  set_parent_for_expr(&node.expr, parent);
11848  node
11849}
11850
11851fn set_parent_for_expr_or_spread<'a>(node: &ExprOrSpread<'a>, parent: Node<'a>) {
11852  node.parent.set(parent);
11853}
11854
11855#[derive(Clone)]
11856pub struct ExprStmt<'a> {
11857  parent: ParentOnceCell<Node<'a>>,
11858  pub inner: &'a swc_ast::ExprStmt,
11859  pub expr: Expr<'a>,
11860}
11861
11862impl<'a> ExprStmt<'a> {
11863  pub fn parent(&self) -> Node<'a> {
11864    self.parent.get().unwrap()
11865  }
11866}
11867
11868impl<'a> SourceRanged for ExprStmt<'a> {
11869  fn start(&self) -> SourcePos {
11870    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11871  }
11872  fn end(&self) -> SourcePos {
11873    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11874  }
11875}
11876
11877impl<'a> From<&ExprStmt<'a>> for Node<'a> {
11878  fn from(node: &ExprStmt<'a>) -> Node<'a> {
11879    let node = unsafe { mem::transmute::<&ExprStmt<'a>, &'a ExprStmt<'a>>(node) };
11880    Node::ExprStmt(node)
11881  }
11882}
11883
11884impl<'a> NodeTrait<'a> for ExprStmt<'a> {
11885  fn parent(&self) -> Option<Node<'a>> {
11886    Some(self.parent.get().unwrap().clone())
11887  }
11888
11889  fn children(&self) -> Vec<Node<'a>> {
11890    let mut children = Vec::with_capacity(1);
11891    children.push((&self.expr).into());
11892    children
11893  }
11894
11895  fn as_node(&self) -> Node<'a> {
11896    self.into()
11897  }
11898
11899  fn kind(&self) -> NodeKind {
11900    NodeKind::ExprStmt
11901  }
11902}
11903
11904impl<'a> CastableNode<'a> for ExprStmt<'a> {
11905  fn to(node: &Node<'a>) -> Option<&'a Self> {
11906    if let Node::ExprStmt(node) = node {
11907      Some(node)
11908    } else {
11909      None
11910    }
11911  }
11912
11913  fn kind() -> NodeKind {
11914    NodeKind::ExprStmt
11915  }
11916}
11917
11918fn get_view_for_expr_stmt<'a>(inner: &'a swc_ast::ExprStmt, bump: &'a Bump) -> &'a ExprStmt<'a> {
11919  let node = bump.alloc(ExprStmt {
11920    inner,
11921    parent: Default::default(),
11922    expr: get_view_for_expr(&inner.expr, bump),
11923  });
11924  let parent: Node<'a> = (&*node).into();
11925  set_parent_for_expr(&node.expr, parent);
11926  node
11927}
11928
11929fn set_parent_for_expr_stmt<'a>(node: &ExprStmt<'a>, parent: Node<'a>) {
11930  node.parent.set(parent);
11931}
11932
11933#[derive(Clone)]
11934pub struct FnDecl<'a> {
11935  parent: ParentOnceCell<Node<'a>>,
11936  pub inner: &'a swc_ast::FnDecl,
11937  pub ident: &'a Ident<'a>,
11938  pub function: &'a Function<'a>,
11939}
11940
11941impl<'a> FnDecl<'a> {
11942  pub fn parent(&self) -> Node<'a> {
11943    self.parent.get().unwrap()
11944  }
11945
11946  pub fn declare(&self) -> bool {
11947    self.inner.declare
11948  }
11949}
11950
11951impl<'a> SourceRanged for FnDecl<'a> {
11952  fn start(&self) -> SourcePos {
11953    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
11954  }
11955  fn end(&self) -> SourcePos {
11956    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
11957  }
11958}
11959
11960impl<'a> From<&FnDecl<'a>> for Node<'a> {
11961  fn from(node: &FnDecl<'a>) -> Node<'a> {
11962    let node = unsafe { mem::transmute::<&FnDecl<'a>, &'a FnDecl<'a>>(node) };
11963    Node::FnDecl(node)
11964  }
11965}
11966
11967impl<'a> NodeTrait<'a> for FnDecl<'a> {
11968  fn parent(&self) -> Option<Node<'a>> {
11969    Some(self.parent.get().unwrap().clone())
11970  }
11971
11972  fn children(&self) -> Vec<Node<'a>> {
11973    let mut children = Vec::with_capacity(2);
11974    children.push(self.ident.into());
11975    children.push(self.function.into());
11976    children
11977  }
11978
11979  fn as_node(&self) -> Node<'a> {
11980    self.into()
11981  }
11982
11983  fn kind(&self) -> NodeKind {
11984    NodeKind::FnDecl
11985  }
11986}
11987
11988impl<'a> CastableNode<'a> for FnDecl<'a> {
11989  fn to(node: &Node<'a>) -> Option<&'a Self> {
11990    if let Node::FnDecl(node) = node {
11991      Some(node)
11992    } else {
11993      None
11994    }
11995  }
11996
11997  fn kind() -> NodeKind {
11998    NodeKind::FnDecl
11999  }
12000}
12001
12002fn get_view_for_fn_decl<'a>(inner: &'a swc_ast::FnDecl, bump: &'a Bump) -> &'a FnDecl<'a> {
12003  let node = bump.alloc(FnDecl {
12004    inner,
12005    parent: Default::default(),
12006    ident: get_view_for_ident(&inner.ident, bump),
12007    function: get_view_for_function(&inner.function, bump),
12008  });
12009  let parent: Node<'a> = (&*node).into();
12010  set_parent_for_ident(&node.ident, parent);
12011  set_parent_for_function(&node.function, parent);
12012  node
12013}
12014
12015fn set_parent_for_fn_decl<'a>(node: &FnDecl<'a>, parent: Node<'a>) {
12016  node.parent.set(parent);
12017}
12018
12019/// Function expression.
12020#[derive(Clone)]
12021pub struct FnExpr<'a> {
12022  parent: ParentOnceCell<Node<'a>>,
12023  pub inner: &'a swc_ast::FnExpr,
12024  pub ident: Option<&'a Ident<'a>>,
12025  pub function: &'a Function<'a>,
12026}
12027
12028impl<'a> FnExpr<'a> {
12029  pub fn parent(&self) -> Node<'a> {
12030    self.parent.get().unwrap()
12031  }
12032}
12033
12034impl<'a> SourceRanged for FnExpr<'a> {
12035  fn start(&self) -> SourcePos {
12036    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12037  }
12038  fn end(&self) -> SourcePos {
12039    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12040  }
12041}
12042
12043impl<'a> From<&FnExpr<'a>> for Node<'a> {
12044  fn from(node: &FnExpr<'a>) -> Node<'a> {
12045    let node = unsafe { mem::transmute::<&FnExpr<'a>, &'a FnExpr<'a>>(node) };
12046    Node::FnExpr(node)
12047  }
12048}
12049
12050impl<'a> NodeTrait<'a> for FnExpr<'a> {
12051  fn parent(&self) -> Option<Node<'a>> {
12052    Some(self.parent.get().unwrap().clone())
12053  }
12054
12055  fn children(&self) -> Vec<Node<'a>> {
12056    let mut children = Vec::with_capacity(1 + match &self.ident { Some(_value) => 1, None => 0, });
12057    if let Some(child) = self.ident {
12058      children.push(child.into());
12059    }
12060    children.push(self.function.into());
12061    children
12062  }
12063
12064  fn as_node(&self) -> Node<'a> {
12065    self.into()
12066  }
12067
12068  fn kind(&self) -> NodeKind {
12069    NodeKind::FnExpr
12070  }
12071}
12072
12073impl<'a> CastableNode<'a> for FnExpr<'a> {
12074  fn to(node: &Node<'a>) -> Option<&'a Self> {
12075    if let Node::FnExpr(node) = node {
12076      Some(node)
12077    } else {
12078      None
12079    }
12080  }
12081
12082  fn kind() -> NodeKind {
12083    NodeKind::FnExpr
12084  }
12085}
12086
12087fn get_view_for_fn_expr<'a>(inner: &'a swc_ast::FnExpr, bump: &'a Bump) -> &'a FnExpr<'a> {
12088  let node = bump.alloc(FnExpr {
12089    inner,
12090    parent: Default::default(),
12091    ident: match &inner.ident {
12092      Some(value) => Some(get_view_for_ident(value, bump)),
12093      None => None,
12094    },
12095    function: get_view_for_function(&inner.function, bump),
12096  });
12097  let parent: Node<'a> = (&*node).into();
12098  if let Some(value) = &node.ident {
12099    set_parent_for_ident(value, parent)
12100  };
12101  set_parent_for_function(&node.function, parent);
12102  node
12103}
12104
12105fn set_parent_for_fn_expr<'a>(node: &FnExpr<'a>, parent: Node<'a>) {
12106  node.parent.set(parent);
12107}
12108
12109#[derive(Clone)]
12110pub struct ForInStmt<'a> {
12111  parent: ParentOnceCell<Node<'a>>,
12112  pub inner: &'a swc_ast::ForInStmt,
12113  pub left: ForHead<'a>,
12114  pub right: Expr<'a>,
12115  pub body: Stmt<'a>,
12116}
12117
12118impl<'a> ForInStmt<'a> {
12119  pub fn parent(&self) -> Node<'a> {
12120    self.parent.get().unwrap()
12121  }
12122}
12123
12124impl<'a> SourceRanged for ForInStmt<'a> {
12125  fn start(&self) -> SourcePos {
12126    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12127  }
12128  fn end(&self) -> SourcePos {
12129    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12130  }
12131}
12132
12133impl<'a> From<&ForInStmt<'a>> for Node<'a> {
12134  fn from(node: &ForInStmt<'a>) -> Node<'a> {
12135    let node = unsafe { mem::transmute::<&ForInStmt<'a>, &'a ForInStmt<'a>>(node) };
12136    Node::ForInStmt(node)
12137  }
12138}
12139
12140impl<'a> NodeTrait<'a> for ForInStmt<'a> {
12141  fn parent(&self) -> Option<Node<'a>> {
12142    Some(self.parent.get().unwrap().clone())
12143  }
12144
12145  fn children(&self) -> Vec<Node<'a>> {
12146    let mut children = Vec::with_capacity(3);
12147    children.push((&self.left).into());
12148    children.push((&self.right).into());
12149    children.push((&self.body).into());
12150    children
12151  }
12152
12153  fn as_node(&self) -> Node<'a> {
12154    self.into()
12155  }
12156
12157  fn kind(&self) -> NodeKind {
12158    NodeKind::ForInStmt
12159  }
12160}
12161
12162impl<'a> CastableNode<'a> for ForInStmt<'a> {
12163  fn to(node: &Node<'a>) -> Option<&'a Self> {
12164    if let Node::ForInStmt(node) = node {
12165      Some(node)
12166    } else {
12167      None
12168    }
12169  }
12170
12171  fn kind() -> NodeKind {
12172    NodeKind::ForInStmt
12173  }
12174}
12175
12176fn get_view_for_for_in_stmt<'a>(inner: &'a swc_ast::ForInStmt, bump: &'a Bump) -> &'a ForInStmt<'a> {
12177  let node = bump.alloc(ForInStmt {
12178    inner,
12179    parent: Default::default(),
12180    left: get_view_for_for_head(&inner.left, bump),
12181    right: get_view_for_expr(&inner.right, bump),
12182    body: get_view_for_stmt(&inner.body, bump),
12183  });
12184  let parent: Node<'a> = (&*node).into();
12185  set_parent_for_for_head(&node.left, parent);
12186  set_parent_for_expr(&node.right, parent);
12187  set_parent_for_stmt(&node.body, parent);
12188  node
12189}
12190
12191fn set_parent_for_for_in_stmt<'a>(node: &ForInStmt<'a>, parent: Node<'a>) {
12192  node.parent.set(parent);
12193}
12194
12195#[derive(Clone)]
12196pub struct ForOfStmt<'a> {
12197  parent: ParentOnceCell<Node<'a>>,
12198  pub inner: &'a swc_ast::ForOfStmt,
12199  pub left: ForHead<'a>,
12200  pub right: Expr<'a>,
12201  pub body: Stmt<'a>,
12202}
12203
12204impl<'a> ForOfStmt<'a> {
12205  pub fn parent(&self) -> Node<'a> {
12206    self.parent.get().unwrap()
12207  }
12208
12209  /// Span of the await token.
12210  ///
12211  /// es2018
12212  ///
12213  /// for-await-of statements, e.g., `for await (const x of xs) {`
12214  pub fn is_await(&self) -> bool {
12215    self.inner.is_await
12216  }
12217}
12218
12219impl<'a> SourceRanged for ForOfStmt<'a> {
12220  fn start(&self) -> SourcePos {
12221    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12222  }
12223  fn end(&self) -> SourcePos {
12224    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12225  }
12226}
12227
12228impl<'a> From<&ForOfStmt<'a>> for Node<'a> {
12229  fn from(node: &ForOfStmt<'a>) -> Node<'a> {
12230    let node = unsafe { mem::transmute::<&ForOfStmt<'a>, &'a ForOfStmt<'a>>(node) };
12231    Node::ForOfStmt(node)
12232  }
12233}
12234
12235impl<'a> NodeTrait<'a> for ForOfStmt<'a> {
12236  fn parent(&self) -> Option<Node<'a>> {
12237    Some(self.parent.get().unwrap().clone())
12238  }
12239
12240  fn children(&self) -> Vec<Node<'a>> {
12241    let mut children = Vec::with_capacity(3);
12242    children.push((&self.left).into());
12243    children.push((&self.right).into());
12244    children.push((&self.body).into());
12245    children
12246  }
12247
12248  fn as_node(&self) -> Node<'a> {
12249    self.into()
12250  }
12251
12252  fn kind(&self) -> NodeKind {
12253    NodeKind::ForOfStmt
12254  }
12255}
12256
12257impl<'a> CastableNode<'a> for ForOfStmt<'a> {
12258  fn to(node: &Node<'a>) -> Option<&'a Self> {
12259    if let Node::ForOfStmt(node) = node {
12260      Some(node)
12261    } else {
12262      None
12263    }
12264  }
12265
12266  fn kind() -> NodeKind {
12267    NodeKind::ForOfStmt
12268  }
12269}
12270
12271fn get_view_for_for_of_stmt<'a>(inner: &'a swc_ast::ForOfStmt, bump: &'a Bump) -> &'a ForOfStmt<'a> {
12272  let node = bump.alloc(ForOfStmt {
12273    inner,
12274    parent: Default::default(),
12275    left: get_view_for_for_head(&inner.left, bump),
12276    right: get_view_for_expr(&inner.right, bump),
12277    body: get_view_for_stmt(&inner.body, bump),
12278  });
12279  let parent: Node<'a> = (&*node).into();
12280  set_parent_for_for_head(&node.left, parent);
12281  set_parent_for_expr(&node.right, parent);
12282  set_parent_for_stmt(&node.body, parent);
12283  node
12284}
12285
12286fn set_parent_for_for_of_stmt<'a>(node: &ForOfStmt<'a>, parent: Node<'a>) {
12287  node.parent.set(parent);
12288}
12289
12290#[derive(Clone)]
12291pub struct ForStmt<'a> {
12292  parent: ParentOnceCell<Node<'a>>,
12293  pub inner: &'a swc_ast::ForStmt,
12294  pub init: Option<VarDeclOrExpr<'a>>,
12295  pub test: Option<Expr<'a>>,
12296  pub update: Option<Expr<'a>>,
12297  pub body: Stmt<'a>,
12298}
12299
12300impl<'a> ForStmt<'a> {
12301  pub fn parent(&self) -> Node<'a> {
12302    self.parent.get().unwrap()
12303  }
12304}
12305
12306impl<'a> SourceRanged for ForStmt<'a> {
12307  fn start(&self) -> SourcePos {
12308    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12309  }
12310  fn end(&self) -> SourcePos {
12311    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12312  }
12313}
12314
12315impl<'a> From<&ForStmt<'a>> for Node<'a> {
12316  fn from(node: &ForStmt<'a>) -> Node<'a> {
12317    let node = unsafe { mem::transmute::<&ForStmt<'a>, &'a ForStmt<'a>>(node) };
12318    Node::ForStmt(node)
12319  }
12320}
12321
12322impl<'a> NodeTrait<'a> for ForStmt<'a> {
12323  fn parent(&self) -> Option<Node<'a>> {
12324    Some(self.parent.get().unwrap().clone())
12325  }
12326
12327  fn children(&self) -> Vec<Node<'a>> {
12328    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, });
12329    if let Some(child) = self.init.as_ref() {
12330      children.push(child.into());
12331    }
12332    if let Some(child) = self.test.as_ref() {
12333      children.push(child.into());
12334    }
12335    if let Some(child) = self.update.as_ref() {
12336      children.push(child.into());
12337    }
12338    children.push((&self.body).into());
12339    children
12340  }
12341
12342  fn as_node(&self) -> Node<'a> {
12343    self.into()
12344  }
12345
12346  fn kind(&self) -> NodeKind {
12347    NodeKind::ForStmt
12348  }
12349}
12350
12351impl<'a> CastableNode<'a> for ForStmt<'a> {
12352  fn to(node: &Node<'a>) -> Option<&'a Self> {
12353    if let Node::ForStmt(node) = node {
12354      Some(node)
12355    } else {
12356      None
12357    }
12358  }
12359
12360  fn kind() -> NodeKind {
12361    NodeKind::ForStmt
12362  }
12363}
12364
12365fn get_view_for_for_stmt<'a>(inner: &'a swc_ast::ForStmt, bump: &'a Bump) -> &'a ForStmt<'a> {
12366  let node = bump.alloc(ForStmt {
12367    inner,
12368    parent: Default::default(),
12369    init: match &inner.init {
12370      Some(value) => Some(get_view_for_var_decl_or_expr(value, bump)),
12371      None => None,
12372    },
12373    test: match &inner.test {
12374      Some(value) => Some(get_view_for_expr(value, bump)),
12375      None => None,
12376    },
12377    update: match &inner.update {
12378      Some(value) => Some(get_view_for_expr(value, bump)),
12379      None => None,
12380    },
12381    body: get_view_for_stmt(&inner.body, bump),
12382  });
12383  let parent: Node<'a> = (&*node).into();
12384  if let Some(value) = &node.init {
12385    set_parent_for_var_decl_or_expr(value, parent)
12386  };
12387  if let Some(value) = &node.test {
12388    set_parent_for_expr(value, parent)
12389  };
12390  if let Some(value) = &node.update {
12391    set_parent_for_expr(value, parent)
12392  };
12393  set_parent_for_stmt(&node.body, parent);
12394  node
12395}
12396
12397fn set_parent_for_for_stmt<'a>(node: &ForStmt<'a>, parent: Node<'a>) {
12398  node.parent.set(parent);
12399}
12400
12401/// Common parts of function and method.
12402#[derive(Clone)]
12403pub struct Function<'a> {
12404  parent: ParentOnceCell<Node<'a>>,
12405  pub inner: &'a swc_ast::Function,
12406  pub params: &'a [&'a Param<'a>],
12407  pub decorators: &'a [&'a Decorator<'a>],
12408  pub body: Option<&'a BlockStmt<'a>>,
12409  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
12410  pub return_type: Option<&'a TsTypeAnn<'a>>,
12411}
12412
12413impl<'a> Function<'a> {
12414  pub fn parent(&self) -> Node<'a> {
12415    self.parent.get().unwrap()
12416  }
12417
12418  pub fn ctxt(&self) -> swc_common::SyntaxContext {
12419    self.inner.ctxt
12420  }
12421
12422  /// if it's a generator.
12423  pub fn is_generator(&self) -> bool {
12424    self.inner.is_generator
12425  }
12426
12427  /// if it's an async function.
12428  pub fn is_async(&self) -> bool {
12429    self.inner.is_async
12430  }
12431}
12432
12433impl<'a> SourceRanged for Function<'a> {
12434  fn start(&self) -> SourcePos {
12435    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12436  }
12437  fn end(&self) -> SourcePos {
12438    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12439  }
12440}
12441
12442impl<'a> From<&Function<'a>> for Node<'a> {
12443  fn from(node: &Function<'a>) -> Node<'a> {
12444    let node = unsafe { mem::transmute::<&Function<'a>, &'a Function<'a>>(node) };
12445    Node::Function(node)
12446  }
12447}
12448
12449impl<'a> NodeTrait<'a> for Function<'a> {
12450  fn parent(&self) -> Option<Node<'a>> {
12451    Some(self.parent.get().unwrap().clone())
12452  }
12453
12454  fn children(&self) -> Vec<Node<'a>> {
12455    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, });
12456    for child in self.params.iter() {
12457      children.push((*child).into());
12458    }
12459    for child in self.decorators.iter() {
12460      children.push((*child).into());
12461    }
12462    if let Some(child) = self.body {
12463      children.push(child.into());
12464    }
12465    if let Some(child) = self.type_params {
12466      children.push(child.into());
12467    }
12468    if let Some(child) = self.return_type {
12469      children.push(child.into());
12470    }
12471    children
12472  }
12473
12474  fn as_node(&self) -> Node<'a> {
12475    self.into()
12476  }
12477
12478  fn kind(&self) -> NodeKind {
12479    NodeKind::Function
12480  }
12481}
12482
12483impl<'a> CastableNode<'a> for Function<'a> {
12484  fn to(node: &Node<'a>) -> Option<&'a Self> {
12485    if let Node::Function(node) = node {
12486      Some(node)
12487    } else {
12488      None
12489    }
12490  }
12491
12492  fn kind() -> NodeKind {
12493    NodeKind::Function
12494  }
12495}
12496
12497fn get_view_for_function<'a>(inner: &'a swc_ast::Function, bump: &'a Bump) -> &'a Function<'a> {
12498  let node = bump.alloc(Function {
12499    inner,
12500    parent: Default::default(),
12501    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 }),
12502    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 }),
12503    body: match &inner.body {
12504      Some(value) => Some(get_view_for_block_stmt(value, bump)),
12505      None => None,
12506    },
12507    type_params: match &inner.type_params {
12508      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
12509      None => None,
12510    },
12511    return_type: match &inner.return_type {
12512      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
12513      None => None,
12514    },
12515  });
12516  let parent: Node<'a> = (&*node).into();
12517  for value in node.params.iter() {
12518    set_parent_for_param(value, parent)
12519  }
12520  for value in node.decorators.iter() {
12521    set_parent_for_decorator(value, parent)
12522  }
12523  if let Some(value) = &node.body {
12524    set_parent_for_block_stmt(value, parent)
12525  };
12526  if let Some(value) = &node.type_params {
12527    set_parent_for_ts_type_param_decl(value, parent)
12528  };
12529  if let Some(value) = &node.return_type {
12530    set_parent_for_ts_type_ann(value, parent)
12531  };
12532  node
12533}
12534
12535fn set_parent_for_function<'a>(node: &Function<'a>, parent: Node<'a>) {
12536  node.parent.set(parent);
12537}
12538
12539#[derive(Clone)]
12540pub struct GetterProp<'a> {
12541  parent: ParentOnceCell<&'a ObjectLit<'a>>,
12542  pub inner: &'a swc_ast::GetterProp,
12543  pub key: PropName<'a>,
12544  pub type_ann: Option<&'a TsTypeAnn<'a>>,
12545  pub body: Option<&'a BlockStmt<'a>>,
12546}
12547
12548impl<'a> GetterProp<'a> {
12549  pub fn parent(&self) -> &'a ObjectLit<'a> {
12550    self.parent.get().unwrap()
12551  }
12552}
12553
12554impl<'a> SourceRanged for GetterProp<'a> {
12555  fn start(&self) -> SourcePos {
12556    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12557  }
12558  fn end(&self) -> SourcePos {
12559    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12560  }
12561}
12562
12563impl<'a> From<&GetterProp<'a>> for Node<'a> {
12564  fn from(node: &GetterProp<'a>) -> Node<'a> {
12565    let node = unsafe { mem::transmute::<&GetterProp<'a>, &'a GetterProp<'a>>(node) };
12566    Node::GetterProp(node)
12567  }
12568}
12569
12570impl<'a> NodeTrait<'a> for GetterProp<'a> {
12571  fn parent(&self) -> Option<Node<'a>> {
12572    Some(self.parent.get().unwrap().into())
12573  }
12574
12575  fn children(&self) -> Vec<Node<'a>> {
12576    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, } + match &self.body { Some(_value) => 1, None => 0, });
12577    children.push((&self.key).into());
12578    if let Some(child) = self.type_ann {
12579      children.push(child.into());
12580    }
12581    if let Some(child) = self.body {
12582      children.push(child.into());
12583    }
12584    children
12585  }
12586
12587  fn as_node(&self) -> Node<'a> {
12588    self.into()
12589  }
12590
12591  fn kind(&self) -> NodeKind {
12592    NodeKind::GetterProp
12593  }
12594}
12595
12596impl<'a> CastableNode<'a> for GetterProp<'a> {
12597  fn to(node: &Node<'a>) -> Option<&'a Self> {
12598    if let Node::GetterProp(node) = node {
12599      Some(node)
12600    } else {
12601      None
12602    }
12603  }
12604
12605  fn kind() -> NodeKind {
12606    NodeKind::GetterProp
12607  }
12608}
12609
12610fn get_view_for_getter_prop<'a>(inner: &'a swc_ast::GetterProp, bump: &'a Bump) -> &'a GetterProp<'a> {
12611  let node = bump.alloc(GetterProp {
12612    inner,
12613    parent: Default::default(),
12614    key: get_view_for_prop_name(&inner.key, bump),
12615    type_ann: match &inner.type_ann {
12616      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
12617      None => None,
12618    },
12619    body: match &inner.body {
12620      Some(value) => Some(get_view_for_block_stmt(value, bump)),
12621      None => None,
12622    },
12623  });
12624  let parent: Node<'a> = (&*node).into();
12625  set_parent_for_prop_name(&node.key, parent);
12626  if let Some(value) = &node.type_ann {
12627    set_parent_for_ts_type_ann(value, parent)
12628  };
12629  if let Some(value) = &node.body {
12630    set_parent_for_block_stmt(value, parent)
12631  };
12632  node
12633}
12634
12635fn set_parent_for_getter_prop<'a>(node: &GetterProp<'a>, parent: Node<'a>) {
12636  node.parent.set(parent.expect::<ObjectLit>());
12637}
12638
12639/// A complete identifier with span.
12640///
12641/// Identifier of swc consists of two parts. The first one is symbol, which is
12642/// stored using an interned string, [Atom] . The second
12643/// one is [SyntaxContext][swc_common::SyntaxContext], which can be
12644/// used to distinguish identifier with same symbol.
12645///
12646/// Let me explain this with an example.
12647///
12648/// ```ts
12649/// let a = 5
12650/// {
12651///     let a = 3;
12652/// }
12653/// ```
12654/// In the code above, there are two variables with the symbol a.
12655///
12656///
12657/// Other compilers typically uses type like `Scope`, and store them nested, but
12658/// in rust, type like `Scope`  requires [Arc<Mutex<Scope>>] so swc uses
12659/// different approach. Instead of passing scopes, swc annotates two variables
12660/// with different tag, which is named
12661/// [SyntaxContext]. The notation for the syntax
12662/// context is #n where n is a number. e.g. `foo#1`
12663///
12664/// For the example above, after applying resolver pass, it becomes.
12665///
12666/// ```ts
12667/// let a#1 = 5
12668/// {
12669///     let a#2 = 3;
12670/// }
12671/// ```
12672///
12673/// Thanks to the `tag` we attached, we can now distinguish them.
12674///
12675/// ([Atom], [SyntaxContext])
12676///
12677/// See [Id], which is a type alias for this.
12678///
12679/// This can be used to store all variables in a module to single hash map.
12680///
12681/// # Comparison
12682///
12683/// While comparing two identifiers, you can use `.to_id()`.
12684///
12685/// # HashMap
12686///
12687/// There's a type named [Id] which only contains minimal information to
12688/// distinguish identifiers.
12689#[derive(Clone)]
12690pub struct Ident<'a> {
12691  parent: ParentOnceCell<Node<'a>>,
12692  pub inner: &'a swc_ast::Ident,
12693}
12694
12695impl<'a> Ident<'a> {
12696  pub fn parent(&self) -> Node<'a> {
12697    self.parent.get().unwrap()
12698  }
12699
12700  pub fn ctxt(&self) -> swc_common::SyntaxContext {
12701    self.inner.ctxt
12702  }
12703
12704  pub fn sym(&self) -> &swc_atoms::Atom {
12705    &self.inner.sym
12706  }
12707
12708  /// TypeScript only. Used in case of an optional parameter.
12709  pub fn optional(&self) -> bool {
12710    self.inner.optional
12711  }
12712}
12713
12714impl<'a> SourceRanged for Ident<'a> {
12715  fn start(&self) -> SourcePos {
12716    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12717  }
12718  fn end(&self) -> SourcePos {
12719    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12720  }
12721}
12722
12723impl<'a> From<&Ident<'a>> for Node<'a> {
12724  fn from(node: &Ident<'a>) -> Node<'a> {
12725    let node = unsafe { mem::transmute::<&Ident<'a>, &'a Ident<'a>>(node) };
12726    Node::Ident(node)
12727  }
12728}
12729
12730impl<'a> NodeTrait<'a> for Ident<'a> {
12731  fn parent(&self) -> Option<Node<'a>> {
12732    Some(self.parent.get().unwrap().clone())
12733  }
12734
12735  fn children(&self) -> Vec<Node<'a>> {
12736    Vec::with_capacity(0)
12737  }
12738
12739  fn as_node(&self) -> Node<'a> {
12740    self.into()
12741  }
12742
12743  fn kind(&self) -> NodeKind {
12744    NodeKind::Ident
12745  }
12746}
12747
12748impl<'a> CastableNode<'a> for Ident<'a> {
12749  fn to(node: &Node<'a>) -> Option<&'a Self> {
12750    if let Node::Ident(node) = node {
12751      Some(node)
12752    } else {
12753      None
12754    }
12755  }
12756
12757  fn kind() -> NodeKind {
12758    NodeKind::Ident
12759  }
12760}
12761
12762fn get_view_for_ident<'a>(inner: &'a swc_ast::Ident, bump: &'a Bump) -> &'a Ident<'a> {
12763  let node = bump.alloc(Ident {
12764    inner,
12765    parent: Default::default(),
12766  });
12767  node
12768}
12769
12770fn set_parent_for_ident<'a>(node: &Ident<'a>, parent: Node<'a>) {
12771  node.parent.set(parent);
12772}
12773
12774#[derive(Clone)]
12775pub struct IdentName<'a> {
12776  parent: ParentOnceCell<Node<'a>>,
12777  pub inner: &'a swc_ast::IdentName,
12778}
12779
12780impl<'a> IdentName<'a> {
12781  pub fn parent(&self) -> Node<'a> {
12782    self.parent.get().unwrap()
12783  }
12784
12785  pub fn sym(&self) -> &swc_atoms::Atom {
12786    &self.inner.sym
12787  }
12788}
12789
12790impl<'a> SourceRanged for IdentName<'a> {
12791  fn start(&self) -> SourcePos {
12792    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12793  }
12794  fn end(&self) -> SourcePos {
12795    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12796  }
12797}
12798
12799impl<'a> From<&IdentName<'a>> for Node<'a> {
12800  fn from(node: &IdentName<'a>) -> Node<'a> {
12801    let node = unsafe { mem::transmute::<&IdentName<'a>, &'a IdentName<'a>>(node) };
12802    Node::IdentName(node)
12803  }
12804}
12805
12806impl<'a> NodeTrait<'a> for IdentName<'a> {
12807  fn parent(&self) -> Option<Node<'a>> {
12808    Some(self.parent.get().unwrap().clone())
12809  }
12810
12811  fn children(&self) -> Vec<Node<'a>> {
12812    Vec::with_capacity(0)
12813  }
12814
12815  fn as_node(&self) -> Node<'a> {
12816    self.into()
12817  }
12818
12819  fn kind(&self) -> NodeKind {
12820    NodeKind::IdentName
12821  }
12822}
12823
12824impl<'a> CastableNode<'a> for IdentName<'a> {
12825  fn to(node: &Node<'a>) -> Option<&'a Self> {
12826    if let Node::IdentName(node) = node {
12827      Some(node)
12828    } else {
12829      None
12830    }
12831  }
12832
12833  fn kind() -> NodeKind {
12834    NodeKind::IdentName
12835  }
12836}
12837
12838fn get_view_for_ident_name<'a>(inner: &'a swc_ast::IdentName, bump: &'a Bump) -> &'a IdentName<'a> {
12839  let node = bump.alloc(IdentName {
12840    inner,
12841    parent: Default::default(),
12842  });
12843  node
12844}
12845
12846fn set_parent_for_ident_name<'a>(node: &IdentName<'a>, parent: Node<'a>) {
12847  node.parent.set(parent);
12848}
12849
12850#[derive(Clone)]
12851pub struct IfStmt<'a> {
12852  parent: ParentOnceCell<Node<'a>>,
12853  pub inner: &'a swc_ast::IfStmt,
12854  pub test: Expr<'a>,
12855  pub cons: Stmt<'a>,
12856  pub alt: Option<Stmt<'a>>,
12857}
12858
12859impl<'a> IfStmt<'a> {
12860  pub fn parent(&self) -> Node<'a> {
12861    self.parent.get().unwrap()
12862  }
12863}
12864
12865impl<'a> SourceRanged for IfStmt<'a> {
12866  fn start(&self) -> SourcePos {
12867    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12868  }
12869  fn end(&self) -> SourcePos {
12870    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12871  }
12872}
12873
12874impl<'a> From<&IfStmt<'a>> for Node<'a> {
12875  fn from(node: &IfStmt<'a>) -> Node<'a> {
12876    let node = unsafe { mem::transmute::<&IfStmt<'a>, &'a IfStmt<'a>>(node) };
12877    Node::IfStmt(node)
12878  }
12879}
12880
12881impl<'a> NodeTrait<'a> for IfStmt<'a> {
12882  fn parent(&self) -> Option<Node<'a>> {
12883    Some(self.parent.get().unwrap().clone())
12884  }
12885
12886  fn children(&self) -> Vec<Node<'a>> {
12887    let mut children = Vec::with_capacity(2 + match &self.alt { Some(_value) => 1, None => 0, });
12888    children.push((&self.test).into());
12889    children.push((&self.cons).into());
12890    if let Some(child) = self.alt.as_ref() {
12891      children.push(child.into());
12892    }
12893    children
12894  }
12895
12896  fn as_node(&self) -> Node<'a> {
12897    self.into()
12898  }
12899
12900  fn kind(&self) -> NodeKind {
12901    NodeKind::IfStmt
12902  }
12903}
12904
12905impl<'a> CastableNode<'a> for IfStmt<'a> {
12906  fn to(node: &Node<'a>) -> Option<&'a Self> {
12907    if let Node::IfStmt(node) = node {
12908      Some(node)
12909    } else {
12910      None
12911    }
12912  }
12913
12914  fn kind() -> NodeKind {
12915    NodeKind::IfStmt
12916  }
12917}
12918
12919fn get_view_for_if_stmt<'a>(inner: &'a swc_ast::IfStmt, bump: &'a Bump) -> &'a IfStmt<'a> {
12920  let node = bump.alloc(IfStmt {
12921    inner,
12922    parent: Default::default(),
12923    test: get_view_for_expr(&inner.test, bump),
12924    cons: get_view_for_stmt(&inner.cons, bump),
12925    alt: match &inner.alt {
12926      Some(value) => Some(get_view_for_stmt(value, bump)),
12927      None => None,
12928    },
12929  });
12930  let parent: Node<'a> = (&*node).into();
12931  set_parent_for_expr(&node.test, parent);
12932  set_parent_for_stmt(&node.cons, parent);
12933  if let Some(value) = &node.alt {
12934    set_parent_for_stmt(value, parent)
12935  };
12936  node
12937}
12938
12939fn set_parent_for_if_stmt<'a>(node: &IfStmt<'a>, parent: Node<'a>) {
12940  node.parent.set(parent);
12941}
12942
12943#[derive(Clone)]
12944pub struct Import<'a> {
12945  parent: ParentOnceCell<&'a CallExpr<'a>>,
12946  pub inner: &'a swc_ast::Import,
12947}
12948
12949impl<'a> Import<'a> {
12950  pub fn parent(&self) -> &'a CallExpr<'a> {
12951    self.parent.get().unwrap()
12952  }
12953
12954  pub fn phase(&self) -> ImportPhase {
12955    self.inner.phase
12956  }
12957}
12958
12959impl<'a> SourceRanged for Import<'a> {
12960  fn start(&self) -> SourcePos {
12961    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
12962  }
12963  fn end(&self) -> SourcePos {
12964    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
12965  }
12966}
12967
12968impl<'a> From<&Import<'a>> for Node<'a> {
12969  fn from(node: &Import<'a>) -> Node<'a> {
12970    let node = unsafe { mem::transmute::<&Import<'a>, &'a Import<'a>>(node) };
12971    Node::Import(node)
12972  }
12973}
12974
12975impl<'a> NodeTrait<'a> for Import<'a> {
12976  fn parent(&self) -> Option<Node<'a>> {
12977    Some(self.parent.get().unwrap().into())
12978  }
12979
12980  fn children(&self) -> Vec<Node<'a>> {
12981    Vec::with_capacity(0)
12982  }
12983
12984  fn as_node(&self) -> Node<'a> {
12985    self.into()
12986  }
12987
12988  fn kind(&self) -> NodeKind {
12989    NodeKind::Import
12990  }
12991}
12992
12993impl<'a> CastableNode<'a> for Import<'a> {
12994  fn to(node: &Node<'a>) -> Option<&'a Self> {
12995    if let Node::Import(node) = node {
12996      Some(node)
12997    } else {
12998      None
12999    }
13000  }
13001
13002  fn kind() -> NodeKind {
13003    NodeKind::Import
13004  }
13005}
13006
13007fn get_view_for_import<'a>(inner: &'a swc_ast::Import, bump: &'a Bump) -> &'a Import<'a> {
13008  let node = bump.alloc(Import {
13009    inner,
13010    parent: Default::default(),
13011  });
13012  node
13013}
13014
13015fn set_parent_for_import<'a>(node: &Import<'a>, parent: Node<'a>) {
13016  node.parent.set(parent.expect::<CallExpr>());
13017}
13018
13019#[derive(Clone)]
13020pub struct ImportDecl<'a> {
13021  parent: ParentOnceCell<Node<'a>>,
13022  pub inner: &'a swc_ast::ImportDecl,
13023  pub specifiers: &'a [ImportSpecifier<'a>],
13024  pub src: &'a Str<'a>,
13025  pub with: Option<&'a ObjectLit<'a>>,
13026}
13027
13028impl<'a> ImportDecl<'a> {
13029  pub fn parent(&self) -> Node<'a> {
13030    self.parent.get().unwrap()
13031  }
13032
13033  pub fn type_only(&self) -> bool {
13034    self.inner.type_only
13035  }
13036
13037  pub fn phase(&self) -> ImportPhase {
13038    self.inner.phase
13039  }
13040}
13041
13042impl<'a> SourceRanged for ImportDecl<'a> {
13043  fn start(&self) -> SourcePos {
13044    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13045  }
13046  fn end(&self) -> SourcePos {
13047    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13048  }
13049}
13050
13051impl<'a> From<&ImportDecl<'a>> for Node<'a> {
13052  fn from(node: &ImportDecl<'a>) -> Node<'a> {
13053    let node = unsafe { mem::transmute::<&ImportDecl<'a>, &'a ImportDecl<'a>>(node) };
13054    Node::ImportDecl(node)
13055  }
13056}
13057
13058impl<'a> NodeTrait<'a> for ImportDecl<'a> {
13059  fn parent(&self) -> Option<Node<'a>> {
13060    Some(self.parent.get().unwrap().clone())
13061  }
13062
13063  fn children(&self) -> Vec<Node<'a>> {
13064    let mut children = Vec::with_capacity(1 + self.specifiers.len() + match &self.with { Some(_value) => 1, None => 0, });
13065    for child in self.specifiers.iter() {
13066      children.push(child.into());
13067    }
13068    children.push(self.src.into());
13069    if let Some(child) = self.with {
13070      children.push(child.into());
13071    }
13072    children
13073  }
13074
13075  fn as_node(&self) -> Node<'a> {
13076    self.into()
13077  }
13078
13079  fn kind(&self) -> NodeKind {
13080    NodeKind::ImportDecl
13081  }
13082}
13083
13084impl<'a> CastableNode<'a> for ImportDecl<'a> {
13085  fn to(node: &Node<'a>) -> Option<&'a Self> {
13086    if let Node::ImportDecl(node) = node {
13087      Some(node)
13088    } else {
13089      None
13090    }
13091  }
13092
13093  fn kind() -> NodeKind {
13094    NodeKind::ImportDecl
13095  }
13096}
13097
13098fn get_view_for_import_decl<'a>(inner: &'a swc_ast::ImportDecl, bump: &'a Bump) -> &'a ImportDecl<'a> {
13099  let node = bump.alloc(ImportDecl {
13100    inner,
13101    parent: Default::default(),
13102    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 }),
13103    src: get_view_for_str(&inner.src, bump),
13104    with: match &inner.with {
13105      Some(value) => Some(get_view_for_object_lit(value, bump)),
13106      None => None,
13107    },
13108  });
13109  let parent: Node<'a> = (&*node).into();
13110  for value in node.specifiers.iter() {
13111    set_parent_for_import_specifier(value, parent)
13112  }
13113  set_parent_for_str(&node.src, parent);
13114  if let Some(value) = &node.with {
13115    set_parent_for_object_lit(value, parent)
13116  };
13117  node
13118}
13119
13120fn set_parent_for_import_decl<'a>(node: &ImportDecl<'a>, parent: Node<'a>) {
13121  node.parent.set(parent);
13122}
13123
13124/// e.g. `import foo from 'mod.js'`
13125#[derive(Clone)]
13126pub struct ImportDefaultSpecifier<'a> {
13127  parent: ParentOnceCell<&'a ImportDecl<'a>>,
13128  pub inner: &'a swc_ast::ImportDefaultSpecifier,
13129  pub local: &'a Ident<'a>,
13130}
13131
13132impl<'a> ImportDefaultSpecifier<'a> {
13133  pub fn parent(&self) -> &'a ImportDecl<'a> {
13134    self.parent.get().unwrap()
13135  }
13136}
13137
13138impl<'a> SourceRanged for ImportDefaultSpecifier<'a> {
13139  fn start(&self) -> SourcePos {
13140    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13141  }
13142  fn end(&self) -> SourcePos {
13143    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13144  }
13145}
13146
13147impl<'a> From<&ImportDefaultSpecifier<'a>> for Node<'a> {
13148  fn from(node: &ImportDefaultSpecifier<'a>) -> Node<'a> {
13149    let node = unsafe { mem::transmute::<&ImportDefaultSpecifier<'a>, &'a ImportDefaultSpecifier<'a>>(node) };
13150    Node::ImportDefaultSpecifier(node)
13151  }
13152}
13153
13154impl<'a> NodeTrait<'a> for ImportDefaultSpecifier<'a> {
13155  fn parent(&self) -> Option<Node<'a>> {
13156    Some(self.parent.get().unwrap().into())
13157  }
13158
13159  fn children(&self) -> Vec<Node<'a>> {
13160    let mut children = Vec::with_capacity(1);
13161    children.push(self.local.into());
13162    children
13163  }
13164
13165  fn as_node(&self) -> Node<'a> {
13166    self.into()
13167  }
13168
13169  fn kind(&self) -> NodeKind {
13170    NodeKind::ImportDefaultSpecifier
13171  }
13172}
13173
13174impl<'a> CastableNode<'a> for ImportDefaultSpecifier<'a> {
13175  fn to(node: &Node<'a>) -> Option<&'a Self> {
13176    if let Node::ImportDefaultSpecifier(node) = node {
13177      Some(node)
13178    } else {
13179      None
13180    }
13181  }
13182
13183  fn kind() -> NodeKind {
13184    NodeKind::ImportDefaultSpecifier
13185  }
13186}
13187
13188fn get_view_for_import_default_specifier<'a>(inner: &'a swc_ast::ImportDefaultSpecifier, bump: &'a Bump) -> &'a ImportDefaultSpecifier<'a> {
13189  let node = bump.alloc(ImportDefaultSpecifier {
13190    inner,
13191    parent: Default::default(),
13192    local: get_view_for_ident(&inner.local, bump),
13193  });
13194  let parent: Node<'a> = (&*node).into();
13195  set_parent_for_ident(&node.local, parent);
13196  node
13197}
13198
13199fn set_parent_for_import_default_specifier<'a>(node: &ImportDefaultSpecifier<'a>, parent: Node<'a>) {
13200  node.parent.set(parent.expect::<ImportDecl>());
13201}
13202
13203/// e.g. local = foo, imported = None `import { foo } from 'mod.js'`
13204/// e.g. local = bar, imported = Some(foo) for `import { foo as bar } from
13205/// 'mod.js'`
13206#[derive(Clone)]
13207pub struct ImportNamedSpecifier<'a> {
13208  parent: ParentOnceCell<&'a ImportDecl<'a>>,
13209  pub inner: &'a swc_ast::ImportNamedSpecifier,
13210  pub local: &'a Ident<'a>,
13211  pub imported: Option<ModuleExportName<'a>>,
13212}
13213
13214impl<'a> ImportNamedSpecifier<'a> {
13215  pub fn parent(&self) -> &'a ImportDecl<'a> {
13216    self.parent.get().unwrap()
13217  }
13218
13219  pub fn is_type_only(&self) -> bool {
13220    self.inner.is_type_only
13221  }
13222}
13223
13224impl<'a> SourceRanged for ImportNamedSpecifier<'a> {
13225  fn start(&self) -> SourcePos {
13226    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13227  }
13228  fn end(&self) -> SourcePos {
13229    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13230  }
13231}
13232
13233impl<'a> From<&ImportNamedSpecifier<'a>> for Node<'a> {
13234  fn from(node: &ImportNamedSpecifier<'a>) -> Node<'a> {
13235    let node = unsafe { mem::transmute::<&ImportNamedSpecifier<'a>, &'a ImportNamedSpecifier<'a>>(node) };
13236    Node::ImportNamedSpecifier(node)
13237  }
13238}
13239
13240impl<'a> NodeTrait<'a> for ImportNamedSpecifier<'a> {
13241  fn parent(&self) -> Option<Node<'a>> {
13242    Some(self.parent.get().unwrap().into())
13243  }
13244
13245  fn children(&self) -> Vec<Node<'a>> {
13246    let mut children = Vec::with_capacity(1 + match &self.imported { Some(_value) => 1, None => 0, });
13247    children.push(self.local.into());
13248    if let Some(child) = self.imported.as_ref() {
13249      children.push(child.into());
13250    }
13251    children
13252  }
13253
13254  fn as_node(&self) -> Node<'a> {
13255    self.into()
13256  }
13257
13258  fn kind(&self) -> NodeKind {
13259    NodeKind::ImportNamedSpecifier
13260  }
13261}
13262
13263impl<'a> CastableNode<'a> for ImportNamedSpecifier<'a> {
13264  fn to(node: &Node<'a>) -> Option<&'a Self> {
13265    if let Node::ImportNamedSpecifier(node) = node {
13266      Some(node)
13267    } else {
13268      None
13269    }
13270  }
13271
13272  fn kind() -> NodeKind {
13273    NodeKind::ImportNamedSpecifier
13274  }
13275}
13276
13277fn get_view_for_import_named_specifier<'a>(inner: &'a swc_ast::ImportNamedSpecifier, bump: &'a Bump) -> &'a ImportNamedSpecifier<'a> {
13278  let node = bump.alloc(ImportNamedSpecifier {
13279    inner,
13280    parent: Default::default(),
13281    local: get_view_for_ident(&inner.local, bump),
13282    imported: match &inner.imported {
13283      Some(value) => Some(get_view_for_module_export_name(value, bump)),
13284      None => None,
13285    },
13286  });
13287  let parent: Node<'a> = (&*node).into();
13288  set_parent_for_ident(&node.local, parent);
13289  if let Some(value) = &node.imported {
13290    set_parent_for_module_export_name(value, parent)
13291  };
13292  node
13293}
13294
13295fn set_parent_for_import_named_specifier<'a>(node: &ImportNamedSpecifier<'a>, parent: Node<'a>) {
13296  node.parent.set(parent.expect::<ImportDecl>());
13297}
13298
13299/// e.g. `import * as foo from 'mod.js'`.
13300#[derive(Clone)]
13301pub struct ImportStarAsSpecifier<'a> {
13302  parent: ParentOnceCell<&'a ImportDecl<'a>>,
13303  pub inner: &'a swc_ast::ImportStarAsSpecifier,
13304  pub local: &'a Ident<'a>,
13305}
13306
13307impl<'a> ImportStarAsSpecifier<'a> {
13308  pub fn parent(&self) -> &'a ImportDecl<'a> {
13309    self.parent.get().unwrap()
13310  }
13311}
13312
13313impl<'a> SourceRanged for ImportStarAsSpecifier<'a> {
13314  fn start(&self) -> SourcePos {
13315    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13316  }
13317  fn end(&self) -> SourcePos {
13318    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13319  }
13320}
13321
13322impl<'a> From<&ImportStarAsSpecifier<'a>> for Node<'a> {
13323  fn from(node: &ImportStarAsSpecifier<'a>) -> Node<'a> {
13324    let node = unsafe { mem::transmute::<&ImportStarAsSpecifier<'a>, &'a ImportStarAsSpecifier<'a>>(node) };
13325    Node::ImportStarAsSpecifier(node)
13326  }
13327}
13328
13329impl<'a> NodeTrait<'a> for ImportStarAsSpecifier<'a> {
13330  fn parent(&self) -> Option<Node<'a>> {
13331    Some(self.parent.get().unwrap().into())
13332  }
13333
13334  fn children(&self) -> Vec<Node<'a>> {
13335    let mut children = Vec::with_capacity(1);
13336    children.push(self.local.into());
13337    children
13338  }
13339
13340  fn as_node(&self) -> Node<'a> {
13341    self.into()
13342  }
13343
13344  fn kind(&self) -> NodeKind {
13345    NodeKind::ImportStarAsSpecifier
13346  }
13347}
13348
13349impl<'a> CastableNode<'a> for ImportStarAsSpecifier<'a> {
13350  fn to(node: &Node<'a>) -> Option<&'a Self> {
13351    if let Node::ImportStarAsSpecifier(node) = node {
13352      Some(node)
13353    } else {
13354      None
13355    }
13356  }
13357
13358  fn kind() -> NodeKind {
13359    NodeKind::ImportStarAsSpecifier
13360  }
13361}
13362
13363fn get_view_for_import_star_as_specifier<'a>(inner: &'a swc_ast::ImportStarAsSpecifier, bump: &'a Bump) -> &'a ImportStarAsSpecifier<'a> {
13364  let node = bump.alloc(ImportStarAsSpecifier {
13365    inner,
13366    parent: Default::default(),
13367    local: get_view_for_ident(&inner.local, bump),
13368  });
13369  let parent: Node<'a> = (&*node).into();
13370  set_parent_for_ident(&node.local, parent);
13371  node
13372}
13373
13374fn set_parent_for_import_star_as_specifier<'a>(node: &ImportStarAsSpecifier<'a>, parent: Node<'a>) {
13375  node.parent.set(parent.expect::<ImportDecl>());
13376}
13377
13378/// Represents a invalid node.
13379#[derive(Clone)]
13380pub struct Invalid<'a> {
13381  parent: ParentOnceCell<Node<'a>>,
13382  pub inner: &'a swc_ast::Invalid,
13383}
13384
13385impl<'a> Invalid<'a> {
13386  pub fn parent(&self) -> Node<'a> {
13387    self.parent.get().unwrap()
13388  }
13389}
13390
13391impl<'a> SourceRanged for Invalid<'a> {
13392  fn start(&self) -> SourcePos {
13393    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13394  }
13395  fn end(&self) -> SourcePos {
13396    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13397  }
13398}
13399
13400impl<'a> From<&Invalid<'a>> for Node<'a> {
13401  fn from(node: &Invalid<'a>) -> Node<'a> {
13402    let node = unsafe { mem::transmute::<&Invalid<'a>, &'a Invalid<'a>>(node) };
13403    Node::Invalid(node)
13404  }
13405}
13406
13407impl<'a> NodeTrait<'a> for Invalid<'a> {
13408  fn parent(&self) -> Option<Node<'a>> {
13409    Some(self.parent.get().unwrap().clone())
13410  }
13411
13412  fn children(&self) -> Vec<Node<'a>> {
13413    Vec::with_capacity(0)
13414  }
13415
13416  fn as_node(&self) -> Node<'a> {
13417    self.into()
13418  }
13419
13420  fn kind(&self) -> NodeKind {
13421    NodeKind::Invalid
13422  }
13423}
13424
13425impl<'a> CastableNode<'a> for Invalid<'a> {
13426  fn to(node: &Node<'a>) -> Option<&'a Self> {
13427    if let Node::Invalid(node) = node {
13428      Some(node)
13429    } else {
13430      None
13431    }
13432  }
13433
13434  fn kind() -> NodeKind {
13435    NodeKind::Invalid
13436  }
13437}
13438
13439fn get_view_for_invalid<'a>(inner: &'a swc_ast::Invalid, bump: &'a Bump) -> &'a Invalid<'a> {
13440  let node = bump.alloc(Invalid {
13441    inner,
13442    parent: Default::default(),
13443  });
13444  node
13445}
13446
13447fn set_parent_for_invalid<'a>(node: &Invalid<'a>, parent: Node<'a>) {
13448  node.parent.set(parent);
13449}
13450
13451#[derive(Clone)]
13452pub struct JSXAttr<'a> {
13453  parent: ParentOnceCell<&'a JSXOpeningElement<'a>>,
13454  pub inner: &'a swc_ast::JSXAttr,
13455  pub name: JSXAttrName<'a>,
13456  /// Babel uses Expr instead of JSXAttrValue
13457  pub value: Option<JSXAttrValue<'a>>,
13458}
13459
13460impl<'a> JSXAttr<'a> {
13461  pub fn parent(&self) -> &'a JSXOpeningElement<'a> {
13462    self.parent.get().unwrap()
13463  }
13464}
13465
13466impl<'a> SourceRanged for JSXAttr<'a> {
13467  fn start(&self) -> SourcePos {
13468    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13469  }
13470  fn end(&self) -> SourcePos {
13471    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13472  }
13473}
13474
13475impl<'a> From<&JSXAttr<'a>> for Node<'a> {
13476  fn from(node: &JSXAttr<'a>) -> Node<'a> {
13477    let node = unsafe { mem::transmute::<&JSXAttr<'a>, &'a JSXAttr<'a>>(node) };
13478    Node::JSXAttr(node)
13479  }
13480}
13481
13482impl<'a> NodeTrait<'a> for JSXAttr<'a> {
13483  fn parent(&self) -> Option<Node<'a>> {
13484    Some(self.parent.get().unwrap().into())
13485  }
13486
13487  fn children(&self) -> Vec<Node<'a>> {
13488    let mut children = Vec::with_capacity(1 + match &self.value { Some(_value) => 1, None => 0, });
13489    children.push((&self.name).into());
13490    if let Some(child) = self.value.as_ref() {
13491      children.push(child.into());
13492    }
13493    children
13494  }
13495
13496  fn as_node(&self) -> Node<'a> {
13497    self.into()
13498  }
13499
13500  fn kind(&self) -> NodeKind {
13501    NodeKind::JSXAttr
13502  }
13503}
13504
13505impl<'a> CastableNode<'a> for JSXAttr<'a> {
13506  fn to(node: &Node<'a>) -> Option<&'a Self> {
13507    if let Node::JSXAttr(node) = node {
13508      Some(node)
13509    } else {
13510      None
13511    }
13512  }
13513
13514  fn kind() -> NodeKind {
13515    NodeKind::JSXAttr
13516  }
13517}
13518
13519fn get_view_for_jsxattr<'a>(inner: &'a swc_ast::JSXAttr, bump: &'a Bump) -> &'a JSXAttr<'a> {
13520  let node = bump.alloc(JSXAttr {
13521    inner,
13522    parent: Default::default(),
13523    name: get_view_for_jsxattr_name(&inner.name, bump),
13524    value: match &inner.value {
13525      Some(value) => Some(get_view_for_jsxattr_value(value, bump)),
13526      None => None,
13527    },
13528  });
13529  let parent: Node<'a> = (&*node).into();
13530  set_parent_for_jsxattr_name(&node.name, parent);
13531  if let Some(value) = &node.value {
13532    set_parent_for_jsxattr_value(value, parent)
13533  };
13534  node
13535}
13536
13537fn set_parent_for_jsxattr<'a>(node: &JSXAttr<'a>, parent: Node<'a>) {
13538  node.parent.set(parent.expect::<JSXOpeningElement>());
13539}
13540
13541#[derive(Clone)]
13542pub struct JSXClosingElement<'a> {
13543  parent: ParentOnceCell<&'a JSXElement<'a>>,
13544  pub inner: &'a swc_ast::JSXClosingElement,
13545  pub name: JSXElementName<'a>,
13546}
13547
13548impl<'a> JSXClosingElement<'a> {
13549  pub fn parent(&self) -> &'a JSXElement<'a> {
13550    self.parent.get().unwrap()
13551  }
13552}
13553
13554impl<'a> SourceRanged for JSXClosingElement<'a> {
13555  fn start(&self) -> SourcePos {
13556    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13557  }
13558  fn end(&self) -> SourcePos {
13559    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13560  }
13561}
13562
13563impl<'a> From<&JSXClosingElement<'a>> for Node<'a> {
13564  fn from(node: &JSXClosingElement<'a>) -> Node<'a> {
13565    let node = unsafe { mem::transmute::<&JSXClosingElement<'a>, &'a JSXClosingElement<'a>>(node) };
13566    Node::JSXClosingElement(node)
13567  }
13568}
13569
13570impl<'a> NodeTrait<'a> for JSXClosingElement<'a> {
13571  fn parent(&self) -> Option<Node<'a>> {
13572    Some(self.parent.get().unwrap().into())
13573  }
13574
13575  fn children(&self) -> Vec<Node<'a>> {
13576    let mut children = Vec::with_capacity(1);
13577    children.push((&self.name).into());
13578    children
13579  }
13580
13581  fn as_node(&self) -> Node<'a> {
13582    self.into()
13583  }
13584
13585  fn kind(&self) -> NodeKind {
13586    NodeKind::JSXClosingElement
13587  }
13588}
13589
13590impl<'a> CastableNode<'a> for JSXClosingElement<'a> {
13591  fn to(node: &Node<'a>) -> Option<&'a Self> {
13592    if let Node::JSXClosingElement(node) = node {
13593      Some(node)
13594    } else {
13595      None
13596    }
13597  }
13598
13599  fn kind() -> NodeKind {
13600    NodeKind::JSXClosingElement
13601  }
13602}
13603
13604fn get_view_for_jsxclosing_element<'a>(inner: &'a swc_ast::JSXClosingElement, bump: &'a Bump) -> &'a JSXClosingElement<'a> {
13605  let node = bump.alloc(JSXClosingElement {
13606    inner,
13607    parent: Default::default(),
13608    name: get_view_for_jsxelement_name(&inner.name, bump),
13609  });
13610  let parent: Node<'a> = (&*node).into();
13611  set_parent_for_jsxelement_name(&node.name, parent);
13612  node
13613}
13614
13615fn set_parent_for_jsxclosing_element<'a>(node: &JSXClosingElement<'a>, parent: Node<'a>) {
13616  node.parent.set(parent.expect::<JSXElement>());
13617}
13618
13619#[derive(Clone)]
13620pub struct JSXClosingFragment<'a> {
13621  parent: ParentOnceCell<&'a JSXFragment<'a>>,
13622  pub inner: &'a swc_ast::JSXClosingFragment,
13623}
13624
13625impl<'a> JSXClosingFragment<'a> {
13626  pub fn parent(&self) -> &'a JSXFragment<'a> {
13627    self.parent.get().unwrap()
13628  }
13629}
13630
13631impl<'a> SourceRanged for JSXClosingFragment<'a> {
13632  fn start(&self) -> SourcePos {
13633    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13634  }
13635  fn end(&self) -> SourcePos {
13636    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13637  }
13638}
13639
13640impl<'a> From<&JSXClosingFragment<'a>> for Node<'a> {
13641  fn from(node: &JSXClosingFragment<'a>) -> Node<'a> {
13642    let node = unsafe { mem::transmute::<&JSXClosingFragment<'a>, &'a JSXClosingFragment<'a>>(node) };
13643    Node::JSXClosingFragment(node)
13644  }
13645}
13646
13647impl<'a> NodeTrait<'a> for JSXClosingFragment<'a> {
13648  fn parent(&self) -> Option<Node<'a>> {
13649    Some(self.parent.get().unwrap().into())
13650  }
13651
13652  fn children(&self) -> Vec<Node<'a>> {
13653    Vec::with_capacity(0)
13654  }
13655
13656  fn as_node(&self) -> Node<'a> {
13657    self.into()
13658  }
13659
13660  fn kind(&self) -> NodeKind {
13661    NodeKind::JSXClosingFragment
13662  }
13663}
13664
13665impl<'a> CastableNode<'a> for JSXClosingFragment<'a> {
13666  fn to(node: &Node<'a>) -> Option<&'a Self> {
13667    if let Node::JSXClosingFragment(node) = node {
13668      Some(node)
13669    } else {
13670      None
13671    }
13672  }
13673
13674  fn kind() -> NodeKind {
13675    NodeKind::JSXClosingFragment
13676  }
13677}
13678
13679fn get_view_for_jsxclosing_fragment<'a>(inner: &'a swc_ast::JSXClosingFragment, bump: &'a Bump) -> &'a JSXClosingFragment<'a> {
13680  let node = bump.alloc(JSXClosingFragment {
13681    inner,
13682    parent: Default::default(),
13683  });
13684  node
13685}
13686
13687fn set_parent_for_jsxclosing_fragment<'a>(node: &JSXClosingFragment<'a>, parent: Node<'a>) {
13688  node.parent.set(parent.expect::<JSXFragment>());
13689}
13690
13691#[derive(Clone)]
13692pub struct JSXElement<'a> {
13693  parent: ParentOnceCell<Node<'a>>,
13694  pub inner: &'a swc_ast::JSXElement,
13695  pub opening: &'a JSXOpeningElement<'a>,
13696  pub children: &'a [JSXElementChild<'a>],
13697  pub closing: Option<&'a JSXClosingElement<'a>>,
13698}
13699
13700impl<'a> JSXElement<'a> {
13701  pub fn parent(&self) -> Node<'a> {
13702    self.parent.get().unwrap()
13703  }
13704}
13705
13706impl<'a> SourceRanged for JSXElement<'a> {
13707  fn start(&self) -> SourcePos {
13708    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13709  }
13710  fn end(&self) -> SourcePos {
13711    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13712  }
13713}
13714
13715impl<'a> From<&JSXElement<'a>> for Node<'a> {
13716  fn from(node: &JSXElement<'a>) -> Node<'a> {
13717    let node = unsafe { mem::transmute::<&JSXElement<'a>, &'a JSXElement<'a>>(node) };
13718    Node::JSXElement(node)
13719  }
13720}
13721
13722impl<'a> NodeTrait<'a> for JSXElement<'a> {
13723  fn parent(&self) -> Option<Node<'a>> {
13724    Some(self.parent.get().unwrap().clone())
13725  }
13726
13727  fn children(&self) -> Vec<Node<'a>> {
13728    let mut children = Vec::with_capacity(1 + self.children.len() + match &self.closing { Some(_value) => 1, None => 0, });
13729    children.push(self.opening.into());
13730    for child in self.children.iter() {
13731      children.push(child.into());
13732    }
13733    if let Some(child) = self.closing {
13734      children.push(child.into());
13735    }
13736    children
13737  }
13738
13739  fn as_node(&self) -> Node<'a> {
13740    self.into()
13741  }
13742
13743  fn kind(&self) -> NodeKind {
13744    NodeKind::JSXElement
13745  }
13746}
13747
13748impl<'a> CastableNode<'a> for JSXElement<'a> {
13749  fn to(node: &Node<'a>) -> Option<&'a Self> {
13750    if let Node::JSXElement(node) = node {
13751      Some(node)
13752    } else {
13753      None
13754    }
13755  }
13756
13757  fn kind() -> NodeKind {
13758    NodeKind::JSXElement
13759  }
13760}
13761
13762fn get_view_for_jsxelement<'a>(inner: &'a swc_ast::JSXElement, bump: &'a Bump) -> &'a JSXElement<'a> {
13763  let node = bump.alloc(JSXElement {
13764    inner,
13765    parent: Default::default(),
13766    opening: get_view_for_jsxopening_element(&inner.opening, bump),
13767    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 }),
13768    closing: match &inner.closing {
13769      Some(value) => Some(get_view_for_jsxclosing_element(value, bump)),
13770      None => None,
13771    },
13772  });
13773  let parent: Node<'a> = (&*node).into();
13774  set_parent_for_jsxopening_element(&node.opening, parent);
13775  for value in node.children.iter() {
13776    set_parent_for_jsxelement_child(value, parent)
13777  }
13778  if let Some(value) = &node.closing {
13779    set_parent_for_jsxclosing_element(value, parent)
13780  };
13781  node
13782}
13783
13784fn set_parent_for_jsxelement<'a>(node: &JSXElement<'a>, parent: Node<'a>) {
13785  node.parent.set(parent);
13786}
13787
13788#[derive(Clone)]
13789pub struct JSXEmptyExpr<'a> {
13790  parent: ParentOnceCell<Node<'a>>,
13791  pub inner: &'a swc_ast::JSXEmptyExpr,
13792}
13793
13794impl<'a> JSXEmptyExpr<'a> {
13795  pub fn parent(&self) -> Node<'a> {
13796    self.parent.get().unwrap()
13797  }
13798}
13799
13800impl<'a> SourceRanged for JSXEmptyExpr<'a> {
13801  fn start(&self) -> SourcePos {
13802    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13803  }
13804  fn end(&self) -> SourcePos {
13805    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13806  }
13807}
13808
13809impl<'a> From<&JSXEmptyExpr<'a>> for Node<'a> {
13810  fn from(node: &JSXEmptyExpr<'a>) -> Node<'a> {
13811    let node = unsafe { mem::transmute::<&JSXEmptyExpr<'a>, &'a JSXEmptyExpr<'a>>(node) };
13812    Node::JSXEmptyExpr(node)
13813  }
13814}
13815
13816impl<'a> NodeTrait<'a> for JSXEmptyExpr<'a> {
13817  fn parent(&self) -> Option<Node<'a>> {
13818    Some(self.parent.get().unwrap().clone())
13819  }
13820
13821  fn children(&self) -> Vec<Node<'a>> {
13822    Vec::with_capacity(0)
13823  }
13824
13825  fn as_node(&self) -> Node<'a> {
13826    self.into()
13827  }
13828
13829  fn kind(&self) -> NodeKind {
13830    NodeKind::JSXEmptyExpr
13831  }
13832}
13833
13834impl<'a> CastableNode<'a> for JSXEmptyExpr<'a> {
13835  fn to(node: &Node<'a>) -> Option<&'a Self> {
13836    if let Node::JSXEmptyExpr(node) = node {
13837      Some(node)
13838    } else {
13839      None
13840    }
13841  }
13842
13843  fn kind() -> NodeKind {
13844    NodeKind::JSXEmptyExpr
13845  }
13846}
13847
13848fn get_view_for_jsxempty_expr<'a>(inner: &'a swc_ast::JSXEmptyExpr, bump: &'a Bump) -> &'a JSXEmptyExpr<'a> {
13849  let node = bump.alloc(JSXEmptyExpr {
13850    inner,
13851    parent: Default::default(),
13852  });
13853  node
13854}
13855
13856fn set_parent_for_jsxempty_expr<'a>(node: &JSXEmptyExpr<'a>, parent: Node<'a>) {
13857  node.parent.set(parent);
13858}
13859
13860#[derive(Clone)]
13861pub struct JSXExprContainer<'a> {
13862  parent: ParentOnceCell<Node<'a>>,
13863  pub inner: &'a swc_ast::JSXExprContainer,
13864  pub expr: JSXExpr<'a>,
13865}
13866
13867impl<'a> JSXExprContainer<'a> {
13868  pub fn parent(&self) -> Node<'a> {
13869    self.parent.get().unwrap()
13870  }
13871}
13872
13873impl<'a> SourceRanged for JSXExprContainer<'a> {
13874  fn start(&self) -> SourcePos {
13875    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13876  }
13877  fn end(&self) -> SourcePos {
13878    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13879  }
13880}
13881
13882impl<'a> From<&JSXExprContainer<'a>> for Node<'a> {
13883  fn from(node: &JSXExprContainer<'a>) -> Node<'a> {
13884    let node = unsafe { mem::transmute::<&JSXExprContainer<'a>, &'a JSXExprContainer<'a>>(node) };
13885    Node::JSXExprContainer(node)
13886  }
13887}
13888
13889impl<'a> NodeTrait<'a> for JSXExprContainer<'a> {
13890  fn parent(&self) -> Option<Node<'a>> {
13891    Some(self.parent.get().unwrap().clone())
13892  }
13893
13894  fn children(&self) -> Vec<Node<'a>> {
13895    let mut children = Vec::with_capacity(1);
13896    children.push((&self.expr).into());
13897    children
13898  }
13899
13900  fn as_node(&self) -> Node<'a> {
13901    self.into()
13902  }
13903
13904  fn kind(&self) -> NodeKind {
13905    NodeKind::JSXExprContainer
13906  }
13907}
13908
13909impl<'a> CastableNode<'a> for JSXExprContainer<'a> {
13910  fn to(node: &Node<'a>) -> Option<&'a Self> {
13911    if let Node::JSXExprContainer(node) = node {
13912      Some(node)
13913    } else {
13914      None
13915    }
13916  }
13917
13918  fn kind() -> NodeKind {
13919    NodeKind::JSXExprContainer
13920  }
13921}
13922
13923fn get_view_for_jsxexpr_container<'a>(inner: &'a swc_ast::JSXExprContainer, bump: &'a Bump) -> &'a JSXExprContainer<'a> {
13924  let node = bump.alloc(JSXExprContainer {
13925    inner,
13926    parent: Default::default(),
13927    expr: get_view_for_jsxexpr(&inner.expr, bump),
13928  });
13929  let parent: Node<'a> = (&*node).into();
13930  set_parent_for_jsxexpr(&node.expr, parent);
13931  node
13932}
13933
13934fn set_parent_for_jsxexpr_container<'a>(node: &JSXExprContainer<'a>, parent: Node<'a>) {
13935  node.parent.set(parent);
13936}
13937
13938#[derive(Clone)]
13939pub struct JSXFragment<'a> {
13940  parent: ParentOnceCell<Node<'a>>,
13941  pub inner: &'a swc_ast::JSXFragment,
13942  pub opening: &'a JSXOpeningFragment<'a>,
13943  pub children: &'a [JSXElementChild<'a>],
13944  pub closing: &'a JSXClosingFragment<'a>,
13945}
13946
13947impl<'a> JSXFragment<'a> {
13948  pub fn parent(&self) -> Node<'a> {
13949    self.parent.get().unwrap()
13950  }
13951}
13952
13953impl<'a> SourceRanged for JSXFragment<'a> {
13954  fn start(&self) -> SourcePos {
13955    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
13956  }
13957  fn end(&self) -> SourcePos {
13958    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
13959  }
13960}
13961
13962impl<'a> From<&JSXFragment<'a>> for Node<'a> {
13963  fn from(node: &JSXFragment<'a>) -> Node<'a> {
13964    let node = unsafe { mem::transmute::<&JSXFragment<'a>, &'a JSXFragment<'a>>(node) };
13965    Node::JSXFragment(node)
13966  }
13967}
13968
13969impl<'a> NodeTrait<'a> for JSXFragment<'a> {
13970  fn parent(&self) -> Option<Node<'a>> {
13971    Some(self.parent.get().unwrap().clone())
13972  }
13973
13974  fn children(&self) -> Vec<Node<'a>> {
13975    let mut children = Vec::with_capacity(2 + self.children.len());
13976    children.push(self.opening.into());
13977    for child in self.children.iter() {
13978      children.push(child.into());
13979    }
13980    children.push(self.closing.into());
13981    children
13982  }
13983
13984  fn as_node(&self) -> Node<'a> {
13985    self.into()
13986  }
13987
13988  fn kind(&self) -> NodeKind {
13989    NodeKind::JSXFragment
13990  }
13991}
13992
13993impl<'a> CastableNode<'a> for JSXFragment<'a> {
13994  fn to(node: &Node<'a>) -> Option<&'a Self> {
13995    if let Node::JSXFragment(node) = node {
13996      Some(node)
13997    } else {
13998      None
13999    }
14000  }
14001
14002  fn kind() -> NodeKind {
14003    NodeKind::JSXFragment
14004  }
14005}
14006
14007fn get_view_for_jsxfragment<'a>(inner: &'a swc_ast::JSXFragment, bump: &'a Bump) -> &'a JSXFragment<'a> {
14008  let node = bump.alloc(JSXFragment {
14009    inner,
14010    parent: Default::default(),
14011    opening: get_view_for_jsxopening_fragment(&inner.opening, bump),
14012    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 }),
14013    closing: get_view_for_jsxclosing_fragment(&inner.closing, bump),
14014  });
14015  let parent: Node<'a> = (&*node).into();
14016  set_parent_for_jsxopening_fragment(&node.opening, parent);
14017  for value in node.children.iter() {
14018    set_parent_for_jsxelement_child(value, parent)
14019  }
14020  set_parent_for_jsxclosing_fragment(&node.closing, parent);
14021  node
14022}
14023
14024fn set_parent_for_jsxfragment<'a>(node: &JSXFragment<'a>, parent: Node<'a>) {
14025  node.parent.set(parent);
14026}
14027
14028#[derive(Clone)]
14029pub struct JSXMemberExpr<'a> {
14030  parent: ParentOnceCell<Node<'a>>,
14031  pub inner: &'a swc_ast::JSXMemberExpr,
14032  pub obj: JSXObject<'a>,
14033  pub prop: &'a IdentName<'a>,
14034}
14035
14036impl<'a> JSXMemberExpr<'a> {
14037  pub fn parent(&self) -> Node<'a> {
14038    self.parent.get().unwrap()
14039  }
14040}
14041
14042impl<'a> SourceRanged for JSXMemberExpr<'a> {
14043  fn start(&self) -> SourcePos {
14044    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14045  }
14046  fn end(&self) -> SourcePos {
14047    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14048  }
14049}
14050
14051impl<'a> From<&JSXMemberExpr<'a>> for Node<'a> {
14052  fn from(node: &JSXMemberExpr<'a>) -> Node<'a> {
14053    let node = unsafe { mem::transmute::<&JSXMemberExpr<'a>, &'a JSXMemberExpr<'a>>(node) };
14054    Node::JSXMemberExpr(node)
14055  }
14056}
14057
14058impl<'a> NodeTrait<'a> for JSXMemberExpr<'a> {
14059  fn parent(&self) -> Option<Node<'a>> {
14060    Some(self.parent.get().unwrap().clone())
14061  }
14062
14063  fn children(&self) -> Vec<Node<'a>> {
14064    let mut children = Vec::with_capacity(2);
14065    children.push((&self.obj).into());
14066    children.push(self.prop.into());
14067    children
14068  }
14069
14070  fn as_node(&self) -> Node<'a> {
14071    self.into()
14072  }
14073
14074  fn kind(&self) -> NodeKind {
14075    NodeKind::JSXMemberExpr
14076  }
14077}
14078
14079impl<'a> CastableNode<'a> for JSXMemberExpr<'a> {
14080  fn to(node: &Node<'a>) -> Option<&'a Self> {
14081    if let Node::JSXMemberExpr(node) = node {
14082      Some(node)
14083    } else {
14084      None
14085    }
14086  }
14087
14088  fn kind() -> NodeKind {
14089    NodeKind::JSXMemberExpr
14090  }
14091}
14092
14093fn get_view_for_jsxmember_expr<'a>(inner: &'a swc_ast::JSXMemberExpr, bump: &'a Bump) -> &'a JSXMemberExpr<'a> {
14094  let node = bump.alloc(JSXMemberExpr {
14095    inner,
14096    parent: Default::default(),
14097    obj: get_view_for_jsxobject(&inner.obj, bump),
14098    prop: get_view_for_ident_name(&inner.prop, bump),
14099  });
14100  let parent: Node<'a> = (&*node).into();
14101  set_parent_for_jsxobject(&node.obj, parent);
14102  set_parent_for_ident_name(&node.prop, parent);
14103  node
14104}
14105
14106fn set_parent_for_jsxmember_expr<'a>(node: &JSXMemberExpr<'a>, parent: Node<'a>) {
14107  node.parent.set(parent);
14108}
14109
14110/// XML-based namespace syntax:
14111#[derive(Clone)]
14112pub struct JSXNamespacedName<'a> {
14113  parent: ParentOnceCell<Node<'a>>,
14114  pub inner: &'a swc_ast::JSXNamespacedName,
14115  pub ns: &'a IdentName<'a>,
14116  pub name: &'a IdentName<'a>,
14117}
14118
14119impl<'a> JSXNamespacedName<'a> {
14120  pub fn parent(&self) -> Node<'a> {
14121    self.parent.get().unwrap()
14122  }
14123}
14124
14125impl<'a> SourceRanged for JSXNamespacedName<'a> {
14126  fn start(&self) -> SourcePos {
14127    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14128  }
14129  fn end(&self) -> SourcePos {
14130    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14131  }
14132}
14133
14134impl<'a> From<&JSXNamespacedName<'a>> for Node<'a> {
14135  fn from(node: &JSXNamespacedName<'a>) -> Node<'a> {
14136    let node = unsafe { mem::transmute::<&JSXNamespacedName<'a>, &'a JSXNamespacedName<'a>>(node) };
14137    Node::JSXNamespacedName(node)
14138  }
14139}
14140
14141impl<'a> NodeTrait<'a> for JSXNamespacedName<'a> {
14142  fn parent(&self) -> Option<Node<'a>> {
14143    Some(self.parent.get().unwrap().clone())
14144  }
14145
14146  fn children(&self) -> Vec<Node<'a>> {
14147    let mut children = Vec::with_capacity(2);
14148    children.push(self.ns.into());
14149    children.push(self.name.into());
14150    children
14151  }
14152
14153  fn as_node(&self) -> Node<'a> {
14154    self.into()
14155  }
14156
14157  fn kind(&self) -> NodeKind {
14158    NodeKind::JSXNamespacedName
14159  }
14160}
14161
14162impl<'a> CastableNode<'a> for JSXNamespacedName<'a> {
14163  fn to(node: &Node<'a>) -> Option<&'a Self> {
14164    if let Node::JSXNamespacedName(node) = node {
14165      Some(node)
14166    } else {
14167      None
14168    }
14169  }
14170
14171  fn kind() -> NodeKind {
14172    NodeKind::JSXNamespacedName
14173  }
14174}
14175
14176fn get_view_for_jsxnamespaced_name<'a>(inner: &'a swc_ast::JSXNamespacedName, bump: &'a Bump) -> &'a JSXNamespacedName<'a> {
14177  let node = bump.alloc(JSXNamespacedName {
14178    inner,
14179    parent: Default::default(),
14180    ns: get_view_for_ident_name(&inner.ns, bump),
14181    name: get_view_for_ident_name(&inner.name, bump),
14182  });
14183  let parent: Node<'a> = (&*node).into();
14184  set_parent_for_ident_name(&node.ns, parent);
14185  set_parent_for_ident_name(&node.name, parent);
14186  node
14187}
14188
14189fn set_parent_for_jsxnamespaced_name<'a>(node: &JSXNamespacedName<'a>, parent: Node<'a>) {
14190  node.parent.set(parent);
14191}
14192
14193#[derive(Clone)]
14194pub struct JSXOpeningElement<'a> {
14195  parent: ParentOnceCell<&'a JSXElement<'a>>,
14196  pub inner: &'a swc_ast::JSXOpeningElement,
14197  pub name: JSXElementName<'a>,
14198  pub attrs: &'a [JSXAttrOrSpread<'a>],
14199  /// Note: This field's name is different from one from babel because it is
14200  /// misleading
14201  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
14202}
14203
14204impl<'a> JSXOpeningElement<'a> {
14205  pub fn parent(&self) -> &'a JSXElement<'a> {
14206    self.parent.get().unwrap()
14207  }
14208
14209  pub fn self_closing(&self) -> bool {
14210    self.inner.self_closing
14211  }
14212}
14213
14214impl<'a> SourceRanged for JSXOpeningElement<'a> {
14215  fn start(&self) -> SourcePos {
14216    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14217  }
14218  fn end(&self) -> SourcePos {
14219    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14220  }
14221}
14222
14223impl<'a> From<&JSXOpeningElement<'a>> for Node<'a> {
14224  fn from(node: &JSXOpeningElement<'a>) -> Node<'a> {
14225    let node = unsafe { mem::transmute::<&JSXOpeningElement<'a>, &'a JSXOpeningElement<'a>>(node) };
14226    Node::JSXOpeningElement(node)
14227  }
14228}
14229
14230impl<'a> NodeTrait<'a> for JSXOpeningElement<'a> {
14231  fn parent(&self) -> Option<Node<'a>> {
14232    Some(self.parent.get().unwrap().into())
14233  }
14234
14235  fn children(&self) -> Vec<Node<'a>> {
14236    let mut children = Vec::with_capacity(1 + self.attrs.len() + match &self.type_args { Some(_value) => 1, None => 0, });
14237    children.push((&self.name).into());
14238    for child in self.attrs.iter() {
14239      children.push(child.into());
14240    }
14241    if let Some(child) = self.type_args {
14242      children.push(child.into());
14243    }
14244    children
14245  }
14246
14247  fn as_node(&self) -> Node<'a> {
14248    self.into()
14249  }
14250
14251  fn kind(&self) -> NodeKind {
14252    NodeKind::JSXOpeningElement
14253  }
14254}
14255
14256impl<'a> CastableNode<'a> for JSXOpeningElement<'a> {
14257  fn to(node: &Node<'a>) -> Option<&'a Self> {
14258    if let Node::JSXOpeningElement(node) = node {
14259      Some(node)
14260    } else {
14261      None
14262    }
14263  }
14264
14265  fn kind() -> NodeKind {
14266    NodeKind::JSXOpeningElement
14267  }
14268}
14269
14270fn get_view_for_jsxopening_element<'a>(inner: &'a swc_ast::JSXOpeningElement, bump: &'a Bump) -> &'a JSXOpeningElement<'a> {
14271  let node = bump.alloc(JSXOpeningElement {
14272    inner,
14273    parent: Default::default(),
14274    name: get_view_for_jsxelement_name(&inner.name, bump),
14275    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 }),
14276    type_args: match &inner.type_args {
14277      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
14278      None => None,
14279    },
14280  });
14281  let parent: Node<'a> = (&*node).into();
14282  set_parent_for_jsxelement_name(&node.name, parent);
14283  for value in node.attrs.iter() {
14284    set_parent_for_jsxattr_or_spread(value, parent)
14285  }
14286  if let Some(value) = &node.type_args {
14287    set_parent_for_ts_type_param_instantiation(value, parent)
14288  };
14289  node
14290}
14291
14292fn set_parent_for_jsxopening_element<'a>(node: &JSXOpeningElement<'a>, parent: Node<'a>) {
14293  node.parent.set(parent.expect::<JSXElement>());
14294}
14295
14296#[derive(Clone)]
14297pub struct JSXOpeningFragment<'a> {
14298  parent: ParentOnceCell<&'a JSXFragment<'a>>,
14299  pub inner: &'a swc_ast::JSXOpeningFragment,
14300}
14301
14302impl<'a> JSXOpeningFragment<'a> {
14303  pub fn parent(&self) -> &'a JSXFragment<'a> {
14304    self.parent.get().unwrap()
14305  }
14306}
14307
14308impl<'a> SourceRanged for JSXOpeningFragment<'a> {
14309  fn start(&self) -> SourcePos {
14310    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14311  }
14312  fn end(&self) -> SourcePos {
14313    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14314  }
14315}
14316
14317impl<'a> From<&JSXOpeningFragment<'a>> for Node<'a> {
14318  fn from(node: &JSXOpeningFragment<'a>) -> Node<'a> {
14319    let node = unsafe { mem::transmute::<&JSXOpeningFragment<'a>, &'a JSXOpeningFragment<'a>>(node) };
14320    Node::JSXOpeningFragment(node)
14321  }
14322}
14323
14324impl<'a> NodeTrait<'a> for JSXOpeningFragment<'a> {
14325  fn parent(&self) -> Option<Node<'a>> {
14326    Some(self.parent.get().unwrap().into())
14327  }
14328
14329  fn children(&self) -> Vec<Node<'a>> {
14330    Vec::with_capacity(0)
14331  }
14332
14333  fn as_node(&self) -> Node<'a> {
14334    self.into()
14335  }
14336
14337  fn kind(&self) -> NodeKind {
14338    NodeKind::JSXOpeningFragment
14339  }
14340}
14341
14342impl<'a> CastableNode<'a> for JSXOpeningFragment<'a> {
14343  fn to(node: &Node<'a>) -> Option<&'a Self> {
14344    if let Node::JSXOpeningFragment(node) = node {
14345      Some(node)
14346    } else {
14347      None
14348    }
14349  }
14350
14351  fn kind() -> NodeKind {
14352    NodeKind::JSXOpeningFragment
14353  }
14354}
14355
14356fn get_view_for_jsxopening_fragment<'a>(inner: &'a swc_ast::JSXOpeningFragment, bump: &'a Bump) -> &'a JSXOpeningFragment<'a> {
14357  let node = bump.alloc(JSXOpeningFragment {
14358    inner,
14359    parent: Default::default(),
14360  });
14361  node
14362}
14363
14364fn set_parent_for_jsxopening_fragment<'a>(node: &JSXOpeningFragment<'a>, parent: Node<'a>) {
14365  node.parent.set(parent.expect::<JSXFragment>());
14366}
14367
14368#[derive(Clone)]
14369pub struct JSXSpreadChild<'a> {
14370  parent: ParentOnceCell<Node<'a>>,
14371  pub inner: &'a swc_ast::JSXSpreadChild,
14372  pub expr: Expr<'a>,
14373}
14374
14375impl<'a> JSXSpreadChild<'a> {
14376  pub fn parent(&self) -> Node<'a> {
14377    self.parent.get().unwrap()
14378  }
14379}
14380
14381impl<'a> SourceRanged for JSXSpreadChild<'a> {
14382  fn start(&self) -> SourcePos {
14383    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14384  }
14385  fn end(&self) -> SourcePos {
14386    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14387  }
14388}
14389
14390impl<'a> From<&JSXSpreadChild<'a>> for Node<'a> {
14391  fn from(node: &JSXSpreadChild<'a>) -> Node<'a> {
14392    let node = unsafe { mem::transmute::<&JSXSpreadChild<'a>, &'a JSXSpreadChild<'a>>(node) };
14393    Node::JSXSpreadChild(node)
14394  }
14395}
14396
14397impl<'a> NodeTrait<'a> for JSXSpreadChild<'a> {
14398  fn parent(&self) -> Option<Node<'a>> {
14399    Some(self.parent.get().unwrap().clone())
14400  }
14401
14402  fn children(&self) -> Vec<Node<'a>> {
14403    let mut children = Vec::with_capacity(1);
14404    children.push((&self.expr).into());
14405    children
14406  }
14407
14408  fn as_node(&self) -> Node<'a> {
14409    self.into()
14410  }
14411
14412  fn kind(&self) -> NodeKind {
14413    NodeKind::JSXSpreadChild
14414  }
14415}
14416
14417impl<'a> CastableNode<'a> for JSXSpreadChild<'a> {
14418  fn to(node: &Node<'a>) -> Option<&'a Self> {
14419    if let Node::JSXSpreadChild(node) = node {
14420      Some(node)
14421    } else {
14422      None
14423    }
14424  }
14425
14426  fn kind() -> NodeKind {
14427    NodeKind::JSXSpreadChild
14428  }
14429}
14430
14431fn get_view_for_jsxspread_child<'a>(inner: &'a swc_ast::JSXSpreadChild, bump: &'a Bump) -> &'a JSXSpreadChild<'a> {
14432  let node = bump.alloc(JSXSpreadChild {
14433    inner,
14434    parent: Default::default(),
14435    expr: get_view_for_expr(&inner.expr, bump),
14436  });
14437  let parent: Node<'a> = (&*node).into();
14438  set_parent_for_expr(&node.expr, parent);
14439  node
14440}
14441
14442fn set_parent_for_jsxspread_child<'a>(node: &JSXSpreadChild<'a>, parent: Node<'a>) {
14443  node.parent.set(parent);
14444}
14445
14446#[derive(Clone)]
14447pub struct JSXText<'a> {
14448  parent: ParentOnceCell<Node<'a>>,
14449  pub inner: &'a swc_ast::JSXText,
14450}
14451
14452impl<'a> JSXText<'a> {
14453  pub fn parent(&self) -> Node<'a> {
14454    self.parent.get().unwrap()
14455  }
14456
14457  pub fn value(&self) -> &swc_atoms::Atom {
14458    &self.inner.value
14459  }
14460
14461  pub fn raw(&self) -> &swc_atoms::Atom {
14462    &self.inner.raw
14463  }
14464}
14465
14466impl<'a> SourceRanged for JSXText<'a> {
14467  fn start(&self) -> SourcePos {
14468    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14469  }
14470  fn end(&self) -> SourcePos {
14471    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14472  }
14473}
14474
14475impl<'a> From<&JSXText<'a>> for Node<'a> {
14476  fn from(node: &JSXText<'a>) -> Node<'a> {
14477    let node = unsafe { mem::transmute::<&JSXText<'a>, &'a JSXText<'a>>(node) };
14478    Node::JSXText(node)
14479  }
14480}
14481
14482impl<'a> NodeTrait<'a> for JSXText<'a> {
14483  fn parent(&self) -> Option<Node<'a>> {
14484    Some(self.parent.get().unwrap().clone())
14485  }
14486
14487  fn children(&self) -> Vec<Node<'a>> {
14488    Vec::with_capacity(0)
14489  }
14490
14491  fn as_node(&self) -> Node<'a> {
14492    self.into()
14493  }
14494
14495  fn kind(&self) -> NodeKind {
14496    NodeKind::JSXText
14497  }
14498}
14499
14500impl<'a> CastableNode<'a> for JSXText<'a> {
14501  fn to(node: &Node<'a>) -> Option<&'a Self> {
14502    if let Node::JSXText(node) = node {
14503      Some(node)
14504    } else {
14505      None
14506    }
14507  }
14508
14509  fn kind() -> NodeKind {
14510    NodeKind::JSXText
14511  }
14512}
14513
14514fn get_view_for_jsxtext<'a>(inner: &'a swc_ast::JSXText, bump: &'a Bump) -> &'a JSXText<'a> {
14515  let node = bump.alloc(JSXText {
14516    inner,
14517    parent: Default::default(),
14518  });
14519  node
14520}
14521
14522fn set_parent_for_jsxtext<'a>(node: &JSXText<'a>, parent: Node<'a>) {
14523  node.parent.set(parent);
14524}
14525
14526/// `{key: value}`
14527#[derive(Clone)]
14528pub struct KeyValuePatProp<'a> {
14529  parent: ParentOnceCell<&'a ObjectPat<'a>>,
14530  pub inner: &'a swc_ast::KeyValuePatProp,
14531  pub key: PropName<'a>,
14532  pub value: Pat<'a>,
14533}
14534
14535impl<'a> KeyValuePatProp<'a> {
14536  pub fn parent(&self) -> &'a ObjectPat<'a> {
14537    self.parent.get().unwrap()
14538  }
14539}
14540
14541impl<'a> SourceRanged for KeyValuePatProp<'a> {
14542  fn start(&self) -> SourcePos {
14543    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14544  }
14545  fn end(&self) -> SourcePos {
14546    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14547  }
14548}
14549
14550impl<'a> From<&KeyValuePatProp<'a>> for Node<'a> {
14551  fn from(node: &KeyValuePatProp<'a>) -> Node<'a> {
14552    let node = unsafe { mem::transmute::<&KeyValuePatProp<'a>, &'a KeyValuePatProp<'a>>(node) };
14553    Node::KeyValuePatProp(node)
14554  }
14555}
14556
14557impl<'a> NodeTrait<'a> for KeyValuePatProp<'a> {
14558  fn parent(&self) -> Option<Node<'a>> {
14559    Some(self.parent.get().unwrap().into())
14560  }
14561
14562  fn children(&self) -> Vec<Node<'a>> {
14563    let mut children = Vec::with_capacity(2);
14564    children.push((&self.key).into());
14565    children.push((&self.value).into());
14566    children
14567  }
14568
14569  fn as_node(&self) -> Node<'a> {
14570    self.into()
14571  }
14572
14573  fn kind(&self) -> NodeKind {
14574    NodeKind::KeyValuePatProp
14575  }
14576}
14577
14578impl<'a> CastableNode<'a> for KeyValuePatProp<'a> {
14579  fn to(node: &Node<'a>) -> Option<&'a Self> {
14580    if let Node::KeyValuePatProp(node) = node {
14581      Some(node)
14582    } else {
14583      None
14584    }
14585  }
14586
14587  fn kind() -> NodeKind {
14588    NodeKind::KeyValuePatProp
14589  }
14590}
14591
14592fn get_view_for_key_value_pat_prop<'a>(inner: &'a swc_ast::KeyValuePatProp, bump: &'a Bump) -> &'a KeyValuePatProp<'a> {
14593  let node = bump.alloc(KeyValuePatProp {
14594    inner,
14595    parent: Default::default(),
14596    key: get_view_for_prop_name(&inner.key, bump),
14597    value: get_view_for_pat(&inner.value, bump),
14598  });
14599  let parent: Node<'a> = (&*node).into();
14600  set_parent_for_prop_name(&node.key, parent);
14601  set_parent_for_pat(&node.value, parent);
14602  node
14603}
14604
14605fn set_parent_for_key_value_pat_prop<'a>(node: &KeyValuePatProp<'a>, parent: Node<'a>) {
14606  node.parent.set(parent.expect::<ObjectPat>());
14607}
14608
14609#[derive(Clone)]
14610pub struct KeyValueProp<'a> {
14611  parent: ParentOnceCell<&'a ObjectLit<'a>>,
14612  pub inner: &'a swc_ast::KeyValueProp,
14613  pub key: PropName<'a>,
14614  pub value: Expr<'a>,
14615}
14616
14617impl<'a> KeyValueProp<'a> {
14618  pub fn parent(&self) -> &'a ObjectLit<'a> {
14619    self.parent.get().unwrap()
14620  }
14621}
14622
14623impl<'a> SourceRanged for KeyValueProp<'a> {
14624  fn start(&self) -> SourcePos {
14625    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14626  }
14627  fn end(&self) -> SourcePos {
14628    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14629  }
14630}
14631
14632impl<'a> From<&KeyValueProp<'a>> for Node<'a> {
14633  fn from(node: &KeyValueProp<'a>) -> Node<'a> {
14634    let node = unsafe { mem::transmute::<&KeyValueProp<'a>, &'a KeyValueProp<'a>>(node) };
14635    Node::KeyValueProp(node)
14636  }
14637}
14638
14639impl<'a> NodeTrait<'a> for KeyValueProp<'a> {
14640  fn parent(&self) -> Option<Node<'a>> {
14641    Some(self.parent.get().unwrap().into())
14642  }
14643
14644  fn children(&self) -> Vec<Node<'a>> {
14645    let mut children = Vec::with_capacity(2);
14646    children.push((&self.key).into());
14647    children.push((&self.value).into());
14648    children
14649  }
14650
14651  fn as_node(&self) -> Node<'a> {
14652    self.into()
14653  }
14654
14655  fn kind(&self) -> NodeKind {
14656    NodeKind::KeyValueProp
14657  }
14658}
14659
14660impl<'a> CastableNode<'a> for KeyValueProp<'a> {
14661  fn to(node: &Node<'a>) -> Option<&'a Self> {
14662    if let Node::KeyValueProp(node) = node {
14663      Some(node)
14664    } else {
14665      None
14666    }
14667  }
14668
14669  fn kind() -> NodeKind {
14670    NodeKind::KeyValueProp
14671  }
14672}
14673
14674fn get_view_for_key_value_prop<'a>(inner: &'a swc_ast::KeyValueProp, bump: &'a Bump) -> &'a KeyValueProp<'a> {
14675  let node = bump.alloc(KeyValueProp {
14676    inner,
14677    parent: Default::default(),
14678    key: get_view_for_prop_name(&inner.key, bump),
14679    value: get_view_for_expr(&inner.value, bump),
14680  });
14681  let parent: Node<'a> = (&*node).into();
14682  set_parent_for_prop_name(&node.key, parent);
14683  set_parent_for_expr(&node.value, parent);
14684  node
14685}
14686
14687fn set_parent_for_key_value_prop<'a>(node: &KeyValueProp<'a>, parent: Node<'a>) {
14688  node.parent.set(parent.expect::<ObjectLit>());
14689}
14690
14691#[derive(Clone)]
14692pub struct LabeledStmt<'a> {
14693  parent: ParentOnceCell<Node<'a>>,
14694  pub inner: &'a swc_ast::LabeledStmt,
14695  pub label: &'a Ident<'a>,
14696  pub body: Stmt<'a>,
14697}
14698
14699impl<'a> LabeledStmt<'a> {
14700  pub fn parent(&self) -> Node<'a> {
14701    self.parent.get().unwrap()
14702  }
14703}
14704
14705impl<'a> SourceRanged for LabeledStmt<'a> {
14706  fn start(&self) -> SourcePos {
14707    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14708  }
14709  fn end(&self) -> SourcePos {
14710    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14711  }
14712}
14713
14714impl<'a> From<&LabeledStmt<'a>> for Node<'a> {
14715  fn from(node: &LabeledStmt<'a>) -> Node<'a> {
14716    let node = unsafe { mem::transmute::<&LabeledStmt<'a>, &'a LabeledStmt<'a>>(node) };
14717    Node::LabeledStmt(node)
14718  }
14719}
14720
14721impl<'a> NodeTrait<'a> for LabeledStmt<'a> {
14722  fn parent(&self) -> Option<Node<'a>> {
14723    Some(self.parent.get().unwrap().clone())
14724  }
14725
14726  fn children(&self) -> Vec<Node<'a>> {
14727    let mut children = Vec::with_capacity(2);
14728    children.push(self.label.into());
14729    children.push((&self.body).into());
14730    children
14731  }
14732
14733  fn as_node(&self) -> Node<'a> {
14734    self.into()
14735  }
14736
14737  fn kind(&self) -> NodeKind {
14738    NodeKind::LabeledStmt
14739  }
14740}
14741
14742impl<'a> CastableNode<'a> for LabeledStmt<'a> {
14743  fn to(node: &Node<'a>) -> Option<&'a Self> {
14744    if let Node::LabeledStmt(node) = node {
14745      Some(node)
14746    } else {
14747      None
14748    }
14749  }
14750
14751  fn kind() -> NodeKind {
14752    NodeKind::LabeledStmt
14753  }
14754}
14755
14756fn get_view_for_labeled_stmt<'a>(inner: &'a swc_ast::LabeledStmt, bump: &'a Bump) -> &'a LabeledStmt<'a> {
14757  let node = bump.alloc(LabeledStmt {
14758    inner,
14759    parent: Default::default(),
14760    label: get_view_for_ident(&inner.label, bump),
14761    body: get_view_for_stmt(&inner.body, bump),
14762  });
14763  let parent: Node<'a> = (&*node).into();
14764  set_parent_for_ident(&node.label, parent);
14765  set_parent_for_stmt(&node.body, parent);
14766  node
14767}
14768
14769fn set_parent_for_labeled_stmt<'a>(node: &LabeledStmt<'a>, parent: Node<'a>) {
14770  node.parent.set(parent);
14771}
14772
14773#[derive(Clone)]
14774pub struct MemberExpr<'a> {
14775  parent: ParentOnceCell<Node<'a>>,
14776  pub inner: &'a swc_ast::MemberExpr,
14777  pub obj: Expr<'a>,
14778  pub prop: MemberProp<'a>,
14779}
14780
14781impl<'a> MemberExpr<'a> {
14782  pub fn parent(&self) -> Node<'a> {
14783    self.parent.get().unwrap()
14784  }
14785}
14786
14787impl<'a> SourceRanged for MemberExpr<'a> {
14788  fn start(&self) -> SourcePos {
14789    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14790  }
14791  fn end(&self) -> SourcePos {
14792    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14793  }
14794}
14795
14796impl<'a> From<&MemberExpr<'a>> for Node<'a> {
14797  fn from(node: &MemberExpr<'a>) -> Node<'a> {
14798    let node = unsafe { mem::transmute::<&MemberExpr<'a>, &'a MemberExpr<'a>>(node) };
14799    Node::MemberExpr(node)
14800  }
14801}
14802
14803impl<'a> NodeTrait<'a> for MemberExpr<'a> {
14804  fn parent(&self) -> Option<Node<'a>> {
14805    Some(self.parent.get().unwrap().clone())
14806  }
14807
14808  fn children(&self) -> Vec<Node<'a>> {
14809    let mut children = Vec::with_capacity(2);
14810    children.push((&self.obj).into());
14811    children.push((&self.prop).into());
14812    children
14813  }
14814
14815  fn as_node(&self) -> Node<'a> {
14816    self.into()
14817  }
14818
14819  fn kind(&self) -> NodeKind {
14820    NodeKind::MemberExpr
14821  }
14822}
14823
14824impl<'a> CastableNode<'a> for MemberExpr<'a> {
14825  fn to(node: &Node<'a>) -> Option<&'a Self> {
14826    if let Node::MemberExpr(node) = node {
14827      Some(node)
14828    } else {
14829      None
14830    }
14831  }
14832
14833  fn kind() -> NodeKind {
14834    NodeKind::MemberExpr
14835  }
14836}
14837
14838fn get_view_for_member_expr<'a>(inner: &'a swc_ast::MemberExpr, bump: &'a Bump) -> &'a MemberExpr<'a> {
14839  let node = bump.alloc(MemberExpr {
14840    inner,
14841    parent: Default::default(),
14842    obj: get_view_for_expr(&inner.obj, bump),
14843    prop: get_view_for_member_prop(&inner.prop, bump),
14844  });
14845  let parent: Node<'a> = (&*node).into();
14846  set_parent_for_expr(&node.obj, parent);
14847  set_parent_for_member_prop(&node.prop, parent);
14848  node
14849}
14850
14851fn set_parent_for_member_expr<'a>(node: &MemberExpr<'a>, parent: Node<'a>) {
14852  node.parent.set(parent);
14853}
14854
14855#[derive(Clone)]
14856pub struct MetaPropExpr<'a> {
14857  parent: ParentOnceCell<Node<'a>>,
14858  pub inner: &'a swc_ast::MetaPropExpr,
14859}
14860
14861impl<'a> MetaPropExpr<'a> {
14862  pub fn parent(&self) -> Node<'a> {
14863    self.parent.get().unwrap()
14864  }
14865
14866  pub fn prop_kind(&self) -> MetaPropKind {
14867    self.inner.kind
14868  }
14869}
14870
14871impl<'a> SourceRanged for MetaPropExpr<'a> {
14872  fn start(&self) -> SourcePos {
14873    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14874  }
14875  fn end(&self) -> SourcePos {
14876    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14877  }
14878}
14879
14880impl<'a> From<&MetaPropExpr<'a>> for Node<'a> {
14881  fn from(node: &MetaPropExpr<'a>) -> Node<'a> {
14882    let node = unsafe { mem::transmute::<&MetaPropExpr<'a>, &'a MetaPropExpr<'a>>(node) };
14883    Node::MetaPropExpr(node)
14884  }
14885}
14886
14887impl<'a> NodeTrait<'a> for MetaPropExpr<'a> {
14888  fn parent(&self) -> Option<Node<'a>> {
14889    Some(self.parent.get().unwrap().clone())
14890  }
14891
14892  fn children(&self) -> Vec<Node<'a>> {
14893    Vec::with_capacity(0)
14894  }
14895
14896  fn as_node(&self) -> Node<'a> {
14897    self.into()
14898  }
14899
14900  fn kind(&self) -> NodeKind {
14901    NodeKind::MetaPropExpr
14902  }
14903}
14904
14905impl<'a> CastableNode<'a> for MetaPropExpr<'a> {
14906  fn to(node: &Node<'a>) -> Option<&'a Self> {
14907    if let Node::MetaPropExpr(node) = node {
14908      Some(node)
14909    } else {
14910      None
14911    }
14912  }
14913
14914  fn kind() -> NodeKind {
14915    NodeKind::MetaPropExpr
14916  }
14917}
14918
14919fn get_view_for_meta_prop_expr<'a>(inner: &'a swc_ast::MetaPropExpr, bump: &'a Bump) -> &'a MetaPropExpr<'a> {
14920  let node = bump.alloc(MetaPropExpr {
14921    inner,
14922    parent: Default::default(),
14923  });
14924  node
14925}
14926
14927fn set_parent_for_meta_prop_expr<'a>(node: &MetaPropExpr<'a>, parent: Node<'a>) {
14928  node.parent.set(parent);
14929}
14930
14931#[derive(Clone)]
14932pub struct MethodProp<'a> {
14933  parent: ParentOnceCell<&'a ObjectLit<'a>>,
14934  pub inner: &'a swc_ast::MethodProp,
14935  pub key: PropName<'a>,
14936  pub function: &'a Function<'a>,
14937}
14938
14939impl<'a> MethodProp<'a> {
14940  pub fn parent(&self) -> &'a ObjectLit<'a> {
14941    self.parent.get().unwrap()
14942  }
14943}
14944
14945impl<'a> SourceRanged for MethodProp<'a> {
14946  fn start(&self) -> SourcePos {
14947    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
14948  }
14949  fn end(&self) -> SourcePos {
14950    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
14951  }
14952}
14953
14954impl<'a> From<&MethodProp<'a>> for Node<'a> {
14955  fn from(node: &MethodProp<'a>) -> Node<'a> {
14956    let node = unsafe { mem::transmute::<&MethodProp<'a>, &'a MethodProp<'a>>(node) };
14957    Node::MethodProp(node)
14958  }
14959}
14960
14961impl<'a> NodeTrait<'a> for MethodProp<'a> {
14962  fn parent(&self) -> Option<Node<'a>> {
14963    Some(self.parent.get().unwrap().into())
14964  }
14965
14966  fn children(&self) -> Vec<Node<'a>> {
14967    let mut children = Vec::with_capacity(2);
14968    children.push((&self.key).into());
14969    children.push(self.function.into());
14970    children
14971  }
14972
14973  fn as_node(&self) -> Node<'a> {
14974    self.into()
14975  }
14976
14977  fn kind(&self) -> NodeKind {
14978    NodeKind::MethodProp
14979  }
14980}
14981
14982impl<'a> CastableNode<'a> for MethodProp<'a> {
14983  fn to(node: &Node<'a>) -> Option<&'a Self> {
14984    if let Node::MethodProp(node) = node {
14985      Some(node)
14986    } else {
14987      None
14988    }
14989  }
14990
14991  fn kind() -> NodeKind {
14992    NodeKind::MethodProp
14993  }
14994}
14995
14996fn get_view_for_method_prop<'a>(inner: &'a swc_ast::MethodProp, bump: &'a Bump) -> &'a MethodProp<'a> {
14997  let node = bump.alloc(MethodProp {
14998    inner,
14999    parent: Default::default(),
15000    key: get_view_for_prop_name(&inner.key, bump),
15001    function: get_view_for_function(&inner.function, bump),
15002  });
15003  let parent: Node<'a> = (&*node).into();
15004  set_parent_for_prop_name(&node.key, parent);
15005  set_parent_for_function(&node.function, parent);
15006  node
15007}
15008
15009fn set_parent_for_method_prop<'a>(node: &MethodProp<'a>, parent: Node<'a>) {
15010  node.parent.set(parent.expect::<ObjectLit>());
15011}
15012
15013#[derive(Clone)]
15014pub struct Module<'a> {
15015  pub text_info: Option<&'a SourceTextInfo>,
15016  pub tokens: Option<&'a TokenContainer<'a>>,
15017  pub comments: Option<&'a CommentContainer<'a>>,
15018  pub inner: &'a swc_ast::Module,
15019  pub body: &'a [ModuleItem<'a>],
15020}
15021
15022impl<'a> Module<'a> {
15023  pub fn shebang(&self) -> &Option<swc_atoms::Atom> {
15024    &self.inner.shebang
15025  }
15026}
15027
15028impl<'a> SourceRanged for Module<'a> {
15029  fn start(&self) -> SourcePos {
15030    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15031  }
15032  fn end(&self) -> SourcePos {
15033    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15034  }
15035}
15036
15037impl<'a> From<&Module<'a>> for Node<'a> {
15038  fn from(node: &Module<'a>) -> Node<'a> {
15039    let node = unsafe { mem::transmute::<&Module<'a>, &'a Module<'a>>(node) };
15040    Node::Module(node)
15041  }
15042}
15043
15044impl<'a> NodeTrait<'a> for Module<'a> {
15045  fn parent(&self) -> Option<Node<'a>> {
15046    None
15047  }
15048
15049  fn children(&self) -> Vec<Node<'a>> {
15050    let mut children = Vec::with_capacity(self.body.len());
15051    for child in self.body.iter() {
15052      children.push(child.into());
15053    }
15054    children
15055  }
15056
15057  fn as_node(&self) -> Node<'a> {
15058    self.into()
15059  }
15060
15061  fn kind(&self) -> NodeKind {
15062    NodeKind::Module
15063  }
15064}
15065
15066impl<'a> CastableNode<'a> for Module<'a> {
15067  fn to(node: &Node<'a>) -> Option<&'a Self> {
15068    if let Node::Module(node) = node {
15069      Some(node)
15070    } else {
15071      None
15072    }
15073  }
15074
15075  fn kind() -> NodeKind {
15076    NodeKind::Module
15077  }
15078}
15079
15080fn 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> {
15081  let inner = source_file_info.module;
15082  let node = bump.alloc(Module {
15083    inner,
15084    text_info: source_file_info.text_info,
15085    tokens,
15086    comments,
15087    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 }),
15088  });
15089  let parent: Node<'a> = (&*node).into();
15090  for value in node.body.iter() {
15091    set_parent_for_module_item(value, parent)
15092  }
15093  node
15094}
15095
15096/// `export { foo } from 'mod'`
15097/// `export { foo as bar } from 'mod'`
15098#[derive(Clone)]
15099pub struct NamedExport<'a> {
15100  parent: ParentOnceCell<Node<'a>>,
15101  pub inner: &'a swc_ast::NamedExport,
15102  pub specifiers: &'a [ExportSpecifier<'a>],
15103  pub src: Option<&'a Str<'a>>,
15104  pub with: Option<&'a ObjectLit<'a>>,
15105}
15106
15107impl<'a> NamedExport<'a> {
15108  pub fn parent(&self) -> Node<'a> {
15109    self.parent.get().unwrap()
15110  }
15111
15112  pub fn type_only(&self) -> bool {
15113    self.inner.type_only
15114  }
15115}
15116
15117impl<'a> SourceRanged for NamedExport<'a> {
15118  fn start(&self) -> SourcePos {
15119    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15120  }
15121  fn end(&self) -> SourcePos {
15122    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15123  }
15124}
15125
15126impl<'a> From<&NamedExport<'a>> for Node<'a> {
15127  fn from(node: &NamedExport<'a>) -> Node<'a> {
15128    let node = unsafe { mem::transmute::<&NamedExport<'a>, &'a NamedExport<'a>>(node) };
15129    Node::NamedExport(node)
15130  }
15131}
15132
15133impl<'a> NodeTrait<'a> for NamedExport<'a> {
15134  fn parent(&self) -> Option<Node<'a>> {
15135    Some(self.parent.get().unwrap().clone())
15136  }
15137
15138  fn children(&self) -> Vec<Node<'a>> {
15139    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, });
15140    for child in self.specifiers.iter() {
15141      children.push(child.into());
15142    }
15143    if let Some(child) = self.src {
15144      children.push(child.into());
15145    }
15146    if let Some(child) = self.with {
15147      children.push(child.into());
15148    }
15149    children
15150  }
15151
15152  fn as_node(&self) -> Node<'a> {
15153    self.into()
15154  }
15155
15156  fn kind(&self) -> NodeKind {
15157    NodeKind::NamedExport
15158  }
15159}
15160
15161impl<'a> CastableNode<'a> for NamedExport<'a> {
15162  fn to(node: &Node<'a>) -> Option<&'a Self> {
15163    if let Node::NamedExport(node) = node {
15164      Some(node)
15165    } else {
15166      None
15167    }
15168  }
15169
15170  fn kind() -> NodeKind {
15171    NodeKind::NamedExport
15172  }
15173}
15174
15175fn get_view_for_named_export<'a>(inner: &'a swc_ast::NamedExport, bump: &'a Bump) -> &'a NamedExport<'a> {
15176  let node = bump.alloc(NamedExport {
15177    inner,
15178    parent: Default::default(),
15179    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 }),
15180    src: match &inner.src {
15181      Some(value) => Some(get_view_for_str(value, bump)),
15182      None => None,
15183    },
15184    with: match &inner.with {
15185      Some(value) => Some(get_view_for_object_lit(value, bump)),
15186      None => None,
15187    },
15188  });
15189  let parent: Node<'a> = (&*node).into();
15190  for value in node.specifiers.iter() {
15191    set_parent_for_export_specifier(value, parent)
15192  }
15193  if let Some(value) = &node.src {
15194    set_parent_for_str(value, parent)
15195  };
15196  if let Some(value) = &node.with {
15197    set_parent_for_object_lit(value, parent)
15198  };
15199  node
15200}
15201
15202fn set_parent_for_named_export<'a>(node: &NamedExport<'a>, parent: Node<'a>) {
15203  node.parent.set(parent);
15204}
15205
15206#[derive(Clone)]
15207pub struct NewExpr<'a> {
15208  parent: ParentOnceCell<Node<'a>>,
15209  pub inner: &'a swc_ast::NewExpr,
15210  pub callee: Expr<'a>,
15211  pub args: Option<&'a [&'a ExprOrSpread<'a>]>,
15212  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
15213}
15214
15215impl<'a> NewExpr<'a> {
15216  pub fn parent(&self) -> Node<'a> {
15217    self.parent.get().unwrap()
15218  }
15219
15220  pub fn ctxt(&self) -> swc_common::SyntaxContext {
15221    self.inner.ctxt
15222  }
15223}
15224
15225impl<'a> SourceRanged for NewExpr<'a> {
15226  fn start(&self) -> SourcePos {
15227    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15228  }
15229  fn end(&self) -> SourcePos {
15230    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15231  }
15232}
15233
15234impl<'a> From<&NewExpr<'a>> for Node<'a> {
15235  fn from(node: &NewExpr<'a>) -> Node<'a> {
15236    let node = unsafe { mem::transmute::<&NewExpr<'a>, &'a NewExpr<'a>>(node) };
15237    Node::NewExpr(node)
15238  }
15239}
15240
15241impl<'a> NodeTrait<'a> for NewExpr<'a> {
15242  fn parent(&self) -> Option<Node<'a>> {
15243    Some(self.parent.get().unwrap().clone())
15244  }
15245
15246  fn children(&self) -> Vec<Node<'a>> {
15247    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, });
15248    children.push((&self.callee).into());
15249    if let Some(child) = self.args.as_ref() {
15250      for child in child.iter() {
15251        children.push((*child).into());
15252      }
15253    }
15254    if let Some(child) = self.type_args {
15255      children.push(child.into());
15256    }
15257    children
15258  }
15259
15260  fn as_node(&self) -> Node<'a> {
15261    self.into()
15262  }
15263
15264  fn kind(&self) -> NodeKind {
15265    NodeKind::NewExpr
15266  }
15267}
15268
15269impl<'a> CastableNode<'a> for NewExpr<'a> {
15270  fn to(node: &Node<'a>) -> Option<&'a Self> {
15271    if let Node::NewExpr(node) = node {
15272      Some(node)
15273    } else {
15274      None
15275    }
15276  }
15277
15278  fn kind() -> NodeKind {
15279    NodeKind::NewExpr
15280  }
15281}
15282
15283fn get_view_for_new_expr<'a>(inner: &'a swc_ast::NewExpr, bump: &'a Bump) -> &'a NewExpr<'a> {
15284  let node = bump.alloc(NewExpr {
15285    inner,
15286    parent: Default::default(),
15287    callee: get_view_for_expr(&inner.callee, bump),
15288    args: match &inner.args {
15289      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 })),
15290      None => None,
15291    },
15292    type_args: match &inner.type_args {
15293      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
15294      None => None,
15295    },
15296  });
15297  let parent: Node<'a> = (&*node).into();
15298  set_parent_for_expr(&node.callee, parent);
15299  if let Some(value) = &node.args {
15300    for value in value.iter() {
15301      set_parent_for_expr_or_spread(value, parent)
15302    }
15303  };
15304  if let Some(value) = &node.type_args {
15305    set_parent_for_ts_type_param_instantiation(value, parent)
15306  };
15307  node
15308}
15309
15310fn set_parent_for_new_expr<'a>(node: &NewExpr<'a>, parent: Node<'a>) {
15311  node.parent.set(parent);
15312}
15313
15314#[derive(Clone)]
15315pub struct Null<'a> {
15316  parent: ParentOnceCell<Node<'a>>,
15317  pub inner: &'a swc_ast::Null,
15318}
15319
15320impl<'a> Null<'a> {
15321  pub fn parent(&self) -> Node<'a> {
15322    self.parent.get().unwrap()
15323  }
15324}
15325
15326impl<'a> SourceRanged for Null<'a> {
15327  fn start(&self) -> SourcePos {
15328    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15329  }
15330  fn end(&self) -> SourcePos {
15331    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15332  }
15333}
15334
15335impl<'a> From<&Null<'a>> for Node<'a> {
15336  fn from(node: &Null<'a>) -> Node<'a> {
15337    let node = unsafe { mem::transmute::<&Null<'a>, &'a Null<'a>>(node) };
15338    Node::Null(node)
15339  }
15340}
15341
15342impl<'a> NodeTrait<'a> for Null<'a> {
15343  fn parent(&self) -> Option<Node<'a>> {
15344    Some(self.parent.get().unwrap().clone())
15345  }
15346
15347  fn children(&self) -> Vec<Node<'a>> {
15348    Vec::with_capacity(0)
15349  }
15350
15351  fn as_node(&self) -> Node<'a> {
15352    self.into()
15353  }
15354
15355  fn kind(&self) -> NodeKind {
15356    NodeKind::Null
15357  }
15358}
15359
15360impl<'a> CastableNode<'a> for Null<'a> {
15361  fn to(node: &Node<'a>) -> Option<&'a Self> {
15362    if let Node::Null(node) = node {
15363      Some(node)
15364    } else {
15365      None
15366    }
15367  }
15368
15369  fn kind() -> NodeKind {
15370    NodeKind::Null
15371  }
15372}
15373
15374fn get_view_for_null<'a>(inner: &'a swc_ast::Null, bump: &'a Bump) -> &'a Null<'a> {
15375  let node = bump.alloc(Null {
15376    inner,
15377    parent: Default::default(),
15378  });
15379  node
15380}
15381
15382fn set_parent_for_null<'a>(node: &Null<'a>, parent: Node<'a>) {
15383  node.parent.set(parent);
15384}
15385
15386/// A numeric literal.
15387///
15388///
15389/// # Creation
15390///
15391/// If you are creating a numeric literal with a dummy span, please use
15392/// `literal.into()`, instead of creating this struct directly.
15393///
15394/// All of `Box<Expr>`, `Expr`, `Lit`, `Number` implements `From<64>` and
15395/// `From<usize>`.
15396#[derive(Clone)]
15397pub struct Number<'a> {
15398  parent: ParentOnceCell<Node<'a>>,
15399  pub inner: &'a swc_ast::Number,
15400}
15401
15402impl<'a> Number<'a> {
15403  pub fn parent(&self) -> Node<'a> {
15404    self.parent.get().unwrap()
15405  }
15406
15407  /// **Note**: This should not be `NaN`. Use [crate::Ident] to represent NaN.
15408  ///
15409  /// If you store `NaN` in this field, a hash map will behave strangely.
15410  pub fn value(&self) -> f64 {
15411    self.inner.value
15412  }
15413
15414  /// Use `None` value only for transformations to avoid recalculate
15415  /// characters in number literal
15416  pub fn raw(&self) -> &Option<swc_atoms::Atom> {
15417    &self.inner.raw
15418  }
15419}
15420
15421impl<'a> SourceRanged for Number<'a> {
15422  fn start(&self) -> SourcePos {
15423    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15424  }
15425  fn end(&self) -> SourcePos {
15426    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15427  }
15428}
15429
15430impl<'a> From<&Number<'a>> for Node<'a> {
15431  fn from(node: &Number<'a>) -> Node<'a> {
15432    let node = unsafe { mem::transmute::<&Number<'a>, &'a Number<'a>>(node) };
15433    Node::Number(node)
15434  }
15435}
15436
15437impl<'a> NodeTrait<'a> for Number<'a> {
15438  fn parent(&self) -> Option<Node<'a>> {
15439    Some(self.parent.get().unwrap().clone())
15440  }
15441
15442  fn children(&self) -> Vec<Node<'a>> {
15443    Vec::with_capacity(0)
15444  }
15445
15446  fn as_node(&self) -> Node<'a> {
15447    self.into()
15448  }
15449
15450  fn kind(&self) -> NodeKind {
15451    NodeKind::Number
15452  }
15453}
15454
15455impl<'a> CastableNode<'a> for Number<'a> {
15456  fn to(node: &Node<'a>) -> Option<&'a Self> {
15457    if let Node::Number(node) = node {
15458      Some(node)
15459    } else {
15460      None
15461    }
15462  }
15463
15464  fn kind() -> NodeKind {
15465    NodeKind::Number
15466  }
15467}
15468
15469fn get_view_for_number<'a>(inner: &'a swc_ast::Number, bump: &'a Bump) -> &'a Number<'a> {
15470  let node = bump.alloc(Number {
15471    inner,
15472    parent: Default::default(),
15473  });
15474  node
15475}
15476
15477fn set_parent_for_number<'a>(node: &Number<'a>, parent: Node<'a>) {
15478  node.parent.set(parent);
15479}
15480
15481/// Object literal.
15482#[derive(Clone)]
15483pub struct ObjectLit<'a> {
15484  parent: ParentOnceCell<Node<'a>>,
15485  pub inner: &'a swc_ast::ObjectLit,
15486  pub props: &'a [PropOrSpread<'a>],
15487}
15488
15489impl<'a> ObjectLit<'a> {
15490  pub fn parent(&self) -> Node<'a> {
15491    self.parent.get().unwrap()
15492  }
15493}
15494
15495impl<'a> SourceRanged for ObjectLit<'a> {
15496  fn start(&self) -> SourcePos {
15497    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15498  }
15499  fn end(&self) -> SourcePos {
15500    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15501  }
15502}
15503
15504impl<'a> From<&ObjectLit<'a>> for Node<'a> {
15505  fn from(node: &ObjectLit<'a>) -> Node<'a> {
15506    let node = unsafe { mem::transmute::<&ObjectLit<'a>, &'a ObjectLit<'a>>(node) };
15507    Node::ObjectLit(node)
15508  }
15509}
15510
15511impl<'a> NodeTrait<'a> for ObjectLit<'a> {
15512  fn parent(&self) -> Option<Node<'a>> {
15513    Some(self.parent.get().unwrap().clone())
15514  }
15515
15516  fn children(&self) -> Vec<Node<'a>> {
15517    let mut children = Vec::with_capacity(self.props.len());
15518    for child in self.props.iter() {
15519      children.push(child.into());
15520    }
15521    children
15522  }
15523
15524  fn as_node(&self) -> Node<'a> {
15525    self.into()
15526  }
15527
15528  fn kind(&self) -> NodeKind {
15529    NodeKind::ObjectLit
15530  }
15531}
15532
15533impl<'a> CastableNode<'a> for ObjectLit<'a> {
15534  fn to(node: &Node<'a>) -> Option<&'a Self> {
15535    if let Node::ObjectLit(node) = node {
15536      Some(node)
15537    } else {
15538      None
15539    }
15540  }
15541
15542  fn kind() -> NodeKind {
15543    NodeKind::ObjectLit
15544  }
15545}
15546
15547fn get_view_for_object_lit<'a>(inner: &'a swc_ast::ObjectLit, bump: &'a Bump) -> &'a ObjectLit<'a> {
15548  let node = bump.alloc(ObjectLit {
15549    inner,
15550    parent: Default::default(),
15551    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 }),
15552  });
15553  let parent: Node<'a> = (&*node).into();
15554  for value in node.props.iter() {
15555    set_parent_for_prop_or_spread(value, parent)
15556  }
15557  node
15558}
15559
15560fn set_parent_for_object_lit<'a>(node: &ObjectLit<'a>, parent: Node<'a>) {
15561  node.parent.set(parent);
15562}
15563
15564#[derive(Clone)]
15565pub struct ObjectPat<'a> {
15566  parent: ParentOnceCell<Node<'a>>,
15567  pub inner: &'a swc_ast::ObjectPat,
15568  pub props: &'a [ObjectPatProp<'a>],
15569  pub type_ann: Option<&'a TsTypeAnn<'a>>,
15570}
15571
15572impl<'a> ObjectPat<'a> {
15573  pub fn parent(&self) -> Node<'a> {
15574    self.parent.get().unwrap()
15575  }
15576
15577  /// Only in an ambient context
15578  pub fn optional(&self) -> bool {
15579    self.inner.optional
15580  }
15581}
15582
15583impl<'a> SourceRanged for ObjectPat<'a> {
15584  fn start(&self) -> SourcePos {
15585    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15586  }
15587  fn end(&self) -> SourcePos {
15588    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15589  }
15590}
15591
15592impl<'a> From<&ObjectPat<'a>> for Node<'a> {
15593  fn from(node: &ObjectPat<'a>) -> Node<'a> {
15594    let node = unsafe { mem::transmute::<&ObjectPat<'a>, &'a ObjectPat<'a>>(node) };
15595    Node::ObjectPat(node)
15596  }
15597}
15598
15599impl<'a> NodeTrait<'a> for ObjectPat<'a> {
15600  fn parent(&self) -> Option<Node<'a>> {
15601    Some(self.parent.get().unwrap().clone())
15602  }
15603
15604  fn children(&self) -> Vec<Node<'a>> {
15605    let mut children = Vec::with_capacity(self.props.len() + match &self.type_ann { Some(_value) => 1, None => 0, });
15606    for child in self.props.iter() {
15607      children.push(child.into());
15608    }
15609    if let Some(child) = self.type_ann {
15610      children.push(child.into());
15611    }
15612    children
15613  }
15614
15615  fn as_node(&self) -> Node<'a> {
15616    self.into()
15617  }
15618
15619  fn kind(&self) -> NodeKind {
15620    NodeKind::ObjectPat
15621  }
15622}
15623
15624impl<'a> CastableNode<'a> for ObjectPat<'a> {
15625  fn to(node: &Node<'a>) -> Option<&'a Self> {
15626    if let Node::ObjectPat(node) = node {
15627      Some(node)
15628    } else {
15629      None
15630    }
15631  }
15632
15633  fn kind() -> NodeKind {
15634    NodeKind::ObjectPat
15635  }
15636}
15637
15638fn get_view_for_object_pat<'a>(inner: &'a swc_ast::ObjectPat, bump: &'a Bump) -> &'a ObjectPat<'a> {
15639  let node = bump.alloc(ObjectPat {
15640    inner,
15641    parent: Default::default(),
15642    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 }),
15643    type_ann: match &inner.type_ann {
15644      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
15645      None => None,
15646    },
15647  });
15648  let parent: Node<'a> = (&*node).into();
15649  for value in node.props.iter() {
15650    set_parent_for_object_pat_prop(value, parent)
15651  }
15652  if let Some(value) = &node.type_ann {
15653    set_parent_for_ts_type_ann(value, parent)
15654  };
15655  node
15656}
15657
15658fn set_parent_for_object_pat<'a>(node: &ObjectPat<'a>, parent: Node<'a>) {
15659  node.parent.set(parent);
15660}
15661
15662#[derive(Clone)]
15663pub struct OptCall<'a> {
15664  parent: ParentOnceCell<&'a OptChainExpr<'a>>,
15665  pub inner: &'a swc_ast::OptCall,
15666  pub callee: Expr<'a>,
15667  pub args: &'a [&'a ExprOrSpread<'a>],
15668  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
15669}
15670
15671impl<'a> OptCall<'a> {
15672  pub fn parent(&self) -> &'a OptChainExpr<'a> {
15673    self.parent.get().unwrap()
15674  }
15675
15676  pub fn ctxt(&self) -> swc_common::SyntaxContext {
15677    self.inner.ctxt
15678  }
15679}
15680
15681impl<'a> SourceRanged for OptCall<'a> {
15682  fn start(&self) -> SourcePos {
15683    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15684  }
15685  fn end(&self) -> SourcePos {
15686    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15687  }
15688}
15689
15690impl<'a> From<&OptCall<'a>> for Node<'a> {
15691  fn from(node: &OptCall<'a>) -> Node<'a> {
15692    let node = unsafe { mem::transmute::<&OptCall<'a>, &'a OptCall<'a>>(node) };
15693    Node::OptCall(node)
15694  }
15695}
15696
15697impl<'a> NodeTrait<'a> for OptCall<'a> {
15698  fn parent(&self) -> Option<Node<'a>> {
15699    Some(self.parent.get().unwrap().into())
15700  }
15701
15702  fn children(&self) -> Vec<Node<'a>> {
15703    let mut children = Vec::with_capacity(1 + self.args.len() + match &self.type_args { Some(_value) => 1, None => 0, });
15704    children.push((&self.callee).into());
15705    for child in self.args.iter() {
15706      children.push((*child).into());
15707    }
15708    if let Some(child) = self.type_args {
15709      children.push(child.into());
15710    }
15711    children
15712  }
15713
15714  fn as_node(&self) -> Node<'a> {
15715    self.into()
15716  }
15717
15718  fn kind(&self) -> NodeKind {
15719    NodeKind::OptCall
15720  }
15721}
15722
15723impl<'a> CastableNode<'a> for OptCall<'a> {
15724  fn to(node: &Node<'a>) -> Option<&'a Self> {
15725    if let Node::OptCall(node) = node {
15726      Some(node)
15727    } else {
15728      None
15729    }
15730  }
15731
15732  fn kind() -> NodeKind {
15733    NodeKind::OptCall
15734  }
15735}
15736
15737fn get_view_for_opt_call<'a>(inner: &'a swc_ast::OptCall, bump: &'a Bump) -> &'a OptCall<'a> {
15738  let node = bump.alloc(OptCall {
15739    inner,
15740    parent: Default::default(),
15741    callee: get_view_for_expr(&inner.callee, bump),
15742    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 }),
15743    type_args: match &inner.type_args {
15744      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
15745      None => None,
15746    },
15747  });
15748  let parent: Node<'a> = (&*node).into();
15749  set_parent_for_expr(&node.callee, parent);
15750  for value in node.args.iter() {
15751    set_parent_for_expr_or_spread(value, parent)
15752  }
15753  if let Some(value) = &node.type_args {
15754    set_parent_for_ts_type_param_instantiation(value, parent)
15755  };
15756  node
15757}
15758
15759fn set_parent_for_opt_call<'a>(node: &OptCall<'a>, parent: Node<'a>) {
15760  node.parent.set(parent.expect::<OptChainExpr>());
15761}
15762
15763#[derive(Clone)]
15764pub struct OptChainExpr<'a> {
15765  parent: ParentOnceCell<Node<'a>>,
15766  pub inner: &'a swc_ast::OptChainExpr,
15767  /// This is boxed to reduce the type size of [Expr].
15768  pub base: OptChainBase<'a>,
15769}
15770
15771impl<'a> OptChainExpr<'a> {
15772  pub fn parent(&self) -> Node<'a> {
15773    self.parent.get().unwrap()
15774  }
15775
15776  pub fn optional(&self) -> bool {
15777    self.inner.optional
15778  }
15779}
15780
15781impl<'a> SourceRanged for OptChainExpr<'a> {
15782  fn start(&self) -> SourcePos {
15783    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15784  }
15785  fn end(&self) -> SourcePos {
15786    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15787  }
15788}
15789
15790impl<'a> From<&OptChainExpr<'a>> for Node<'a> {
15791  fn from(node: &OptChainExpr<'a>) -> Node<'a> {
15792    let node = unsafe { mem::transmute::<&OptChainExpr<'a>, &'a OptChainExpr<'a>>(node) };
15793    Node::OptChainExpr(node)
15794  }
15795}
15796
15797impl<'a> NodeTrait<'a> for OptChainExpr<'a> {
15798  fn parent(&self) -> Option<Node<'a>> {
15799    Some(self.parent.get().unwrap().clone())
15800  }
15801
15802  fn children(&self) -> Vec<Node<'a>> {
15803    let mut children = Vec::with_capacity(1);
15804    children.push((&self.base).into());
15805    children
15806  }
15807
15808  fn as_node(&self) -> Node<'a> {
15809    self.into()
15810  }
15811
15812  fn kind(&self) -> NodeKind {
15813    NodeKind::OptChainExpr
15814  }
15815}
15816
15817impl<'a> CastableNode<'a> for OptChainExpr<'a> {
15818  fn to(node: &Node<'a>) -> Option<&'a Self> {
15819    if let Node::OptChainExpr(node) = node {
15820      Some(node)
15821    } else {
15822      None
15823    }
15824  }
15825
15826  fn kind() -> NodeKind {
15827    NodeKind::OptChainExpr
15828  }
15829}
15830
15831fn get_view_for_opt_chain_expr<'a>(inner: &'a swc_ast::OptChainExpr, bump: &'a Bump) -> &'a OptChainExpr<'a> {
15832  let node = bump.alloc(OptChainExpr {
15833    inner,
15834    parent: Default::default(),
15835    base: get_view_for_opt_chain_base(&inner.base, bump),
15836  });
15837  let parent: Node<'a> = (&*node).into();
15838  set_parent_for_opt_chain_base(&node.base, parent);
15839  node
15840}
15841
15842fn set_parent_for_opt_chain_expr<'a>(node: &OptChainExpr<'a>, parent: Node<'a>) {
15843  node.parent.set(parent);
15844}
15845
15846#[derive(Clone)]
15847pub struct Param<'a> {
15848  parent: ParentOnceCell<Node<'a>>,
15849  pub inner: &'a swc_ast::Param,
15850  pub decorators: &'a [&'a Decorator<'a>],
15851  pub pat: Pat<'a>,
15852}
15853
15854impl<'a> Param<'a> {
15855  pub fn parent(&self) -> Node<'a> {
15856    self.parent.get().unwrap()
15857  }
15858}
15859
15860impl<'a> SourceRanged for Param<'a> {
15861  fn start(&self) -> SourcePos {
15862    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15863  }
15864  fn end(&self) -> SourcePos {
15865    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15866  }
15867}
15868
15869impl<'a> From<&Param<'a>> for Node<'a> {
15870  fn from(node: &Param<'a>) -> Node<'a> {
15871    let node = unsafe { mem::transmute::<&Param<'a>, &'a Param<'a>>(node) };
15872    Node::Param(node)
15873  }
15874}
15875
15876impl<'a> NodeTrait<'a> for Param<'a> {
15877  fn parent(&self) -> Option<Node<'a>> {
15878    Some(self.parent.get().unwrap().clone())
15879  }
15880
15881  fn children(&self) -> Vec<Node<'a>> {
15882    let mut children = Vec::with_capacity(1 + self.decorators.len());
15883    for child in self.decorators.iter() {
15884      children.push((*child).into());
15885    }
15886    children.push((&self.pat).into());
15887    children
15888  }
15889
15890  fn as_node(&self) -> Node<'a> {
15891    self.into()
15892  }
15893
15894  fn kind(&self) -> NodeKind {
15895    NodeKind::Param
15896  }
15897}
15898
15899impl<'a> CastableNode<'a> for Param<'a> {
15900  fn to(node: &Node<'a>) -> Option<&'a Self> {
15901    if let Node::Param(node) = node {
15902      Some(node)
15903    } else {
15904      None
15905    }
15906  }
15907
15908  fn kind() -> NodeKind {
15909    NodeKind::Param
15910  }
15911}
15912
15913fn get_view_for_param<'a>(inner: &'a swc_ast::Param, bump: &'a Bump) -> &'a Param<'a> {
15914  let node = bump.alloc(Param {
15915    inner,
15916    parent: Default::default(),
15917    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 }),
15918    pat: get_view_for_pat(&inner.pat, bump),
15919  });
15920  let parent: Node<'a> = (&*node).into();
15921  for value in node.decorators.iter() {
15922    set_parent_for_decorator(value, parent)
15923  }
15924  set_parent_for_pat(&node.pat, parent);
15925  node
15926}
15927
15928fn set_parent_for_param<'a>(node: &Param<'a>, parent: Node<'a>) {
15929  node.parent.set(parent);
15930}
15931
15932#[derive(Clone)]
15933pub struct ParenExpr<'a> {
15934  parent: ParentOnceCell<Node<'a>>,
15935  pub inner: &'a swc_ast::ParenExpr,
15936  pub expr: Expr<'a>,
15937}
15938
15939impl<'a> ParenExpr<'a> {
15940  pub fn parent(&self) -> Node<'a> {
15941    self.parent.get().unwrap()
15942  }
15943}
15944
15945impl<'a> SourceRanged for ParenExpr<'a> {
15946  fn start(&self) -> SourcePos {
15947    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
15948  }
15949  fn end(&self) -> SourcePos {
15950    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
15951  }
15952}
15953
15954impl<'a> From<&ParenExpr<'a>> for Node<'a> {
15955  fn from(node: &ParenExpr<'a>) -> Node<'a> {
15956    let node = unsafe { mem::transmute::<&ParenExpr<'a>, &'a ParenExpr<'a>>(node) };
15957    Node::ParenExpr(node)
15958  }
15959}
15960
15961impl<'a> NodeTrait<'a> for ParenExpr<'a> {
15962  fn parent(&self) -> Option<Node<'a>> {
15963    Some(self.parent.get().unwrap().clone())
15964  }
15965
15966  fn children(&self) -> Vec<Node<'a>> {
15967    let mut children = Vec::with_capacity(1);
15968    children.push((&self.expr).into());
15969    children
15970  }
15971
15972  fn as_node(&self) -> Node<'a> {
15973    self.into()
15974  }
15975
15976  fn kind(&self) -> NodeKind {
15977    NodeKind::ParenExpr
15978  }
15979}
15980
15981impl<'a> CastableNode<'a> for ParenExpr<'a> {
15982  fn to(node: &Node<'a>) -> Option<&'a Self> {
15983    if let Node::ParenExpr(node) = node {
15984      Some(node)
15985    } else {
15986      None
15987    }
15988  }
15989
15990  fn kind() -> NodeKind {
15991    NodeKind::ParenExpr
15992  }
15993}
15994
15995fn get_view_for_paren_expr<'a>(inner: &'a swc_ast::ParenExpr, bump: &'a Bump) -> &'a ParenExpr<'a> {
15996  let node = bump.alloc(ParenExpr {
15997    inner,
15998    parent: Default::default(),
15999    expr: get_view_for_expr(&inner.expr, bump),
16000  });
16001  let parent: Node<'a> = (&*node).into();
16002  set_parent_for_expr(&node.expr, parent);
16003  node
16004}
16005
16006fn set_parent_for_paren_expr<'a>(node: &ParenExpr<'a>, parent: Node<'a>) {
16007  node.parent.set(parent);
16008}
16009
16010#[derive(Clone)]
16011pub struct PrivateMethod<'a> {
16012  parent: ParentOnceCell<&'a Class<'a>>,
16013  pub inner: &'a swc_ast::PrivateMethod,
16014  pub key: &'a PrivateName<'a>,
16015  pub function: &'a Function<'a>,
16016}
16017
16018impl<'a> PrivateMethod<'a> {
16019  pub fn parent(&self) -> &'a Class<'a> {
16020    self.parent.get().unwrap()
16021  }
16022
16023  pub fn method_kind(&self) -> MethodKind {
16024    self.inner.kind
16025  }
16026
16027  pub fn is_static(&self) -> bool {
16028    self.inner.is_static
16029  }
16030
16031  /// Typescript extension.
16032  pub fn accessibility(&self) -> Option<Accessibility> {
16033    self.inner.accessibility
16034  }
16035
16036  /// Typescript extension.
16037  pub fn is_abstract(&self) -> bool {
16038    self.inner.is_abstract
16039  }
16040
16041  pub fn is_optional(&self) -> bool {
16042    self.inner.is_optional
16043  }
16044
16045  pub fn is_override(&self) -> bool {
16046    self.inner.is_override
16047  }
16048}
16049
16050impl<'a> SourceRanged for PrivateMethod<'a> {
16051  fn start(&self) -> SourcePos {
16052    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16053  }
16054  fn end(&self) -> SourcePos {
16055    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16056  }
16057}
16058
16059impl<'a> From<&PrivateMethod<'a>> for Node<'a> {
16060  fn from(node: &PrivateMethod<'a>) -> Node<'a> {
16061    let node = unsafe { mem::transmute::<&PrivateMethod<'a>, &'a PrivateMethod<'a>>(node) };
16062    Node::PrivateMethod(node)
16063  }
16064}
16065
16066impl<'a> NodeTrait<'a> for PrivateMethod<'a> {
16067  fn parent(&self) -> Option<Node<'a>> {
16068    Some(self.parent.get().unwrap().into())
16069  }
16070
16071  fn children(&self) -> Vec<Node<'a>> {
16072    let mut children = Vec::with_capacity(2);
16073    children.push(self.key.into());
16074    children.push(self.function.into());
16075    children
16076  }
16077
16078  fn as_node(&self) -> Node<'a> {
16079    self.into()
16080  }
16081
16082  fn kind(&self) -> NodeKind {
16083    NodeKind::PrivateMethod
16084  }
16085}
16086
16087impl<'a> CastableNode<'a> for PrivateMethod<'a> {
16088  fn to(node: &Node<'a>) -> Option<&'a Self> {
16089    if let Node::PrivateMethod(node) = node {
16090      Some(node)
16091    } else {
16092      None
16093    }
16094  }
16095
16096  fn kind() -> NodeKind {
16097    NodeKind::PrivateMethod
16098  }
16099}
16100
16101fn get_view_for_private_method<'a>(inner: &'a swc_ast::PrivateMethod, bump: &'a Bump) -> &'a PrivateMethod<'a> {
16102  let node = bump.alloc(PrivateMethod {
16103    inner,
16104    parent: Default::default(),
16105    key: get_view_for_private_name(&inner.key, bump),
16106    function: get_view_for_function(&inner.function, bump),
16107  });
16108  let parent: Node<'a> = (&*node).into();
16109  set_parent_for_private_name(&node.key, parent);
16110  set_parent_for_function(&node.function, parent);
16111  node
16112}
16113
16114fn set_parent_for_private_method<'a>(node: &PrivateMethod<'a>, parent: Node<'a>) {
16115  node.parent.set(parent.expect::<Class>());
16116}
16117
16118#[derive(Clone)]
16119pub struct PrivateName<'a> {
16120  parent: ParentOnceCell<Node<'a>>,
16121  pub inner: &'a swc_ast::PrivateName,
16122}
16123
16124impl<'a> PrivateName<'a> {
16125  pub fn parent(&self) -> Node<'a> {
16126    self.parent.get().unwrap()
16127  }
16128
16129  pub fn name(&self) -> &swc_atoms::Atom {
16130    &self.inner.name
16131  }
16132}
16133
16134impl<'a> SourceRanged for PrivateName<'a> {
16135  fn start(&self) -> SourcePos {
16136    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16137  }
16138  fn end(&self) -> SourcePos {
16139    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16140  }
16141}
16142
16143impl<'a> From<&PrivateName<'a>> for Node<'a> {
16144  fn from(node: &PrivateName<'a>) -> Node<'a> {
16145    let node = unsafe { mem::transmute::<&PrivateName<'a>, &'a PrivateName<'a>>(node) };
16146    Node::PrivateName(node)
16147  }
16148}
16149
16150impl<'a> NodeTrait<'a> for PrivateName<'a> {
16151  fn parent(&self) -> Option<Node<'a>> {
16152    Some(self.parent.get().unwrap().clone())
16153  }
16154
16155  fn children(&self) -> Vec<Node<'a>> {
16156    Vec::with_capacity(0)
16157  }
16158
16159  fn as_node(&self) -> Node<'a> {
16160    self.into()
16161  }
16162
16163  fn kind(&self) -> NodeKind {
16164    NodeKind::PrivateName
16165  }
16166}
16167
16168impl<'a> CastableNode<'a> for PrivateName<'a> {
16169  fn to(node: &Node<'a>) -> Option<&'a Self> {
16170    if let Node::PrivateName(node) = node {
16171      Some(node)
16172    } else {
16173      None
16174    }
16175  }
16176
16177  fn kind() -> NodeKind {
16178    NodeKind::PrivateName
16179  }
16180}
16181
16182fn get_view_for_private_name<'a>(inner: &'a swc_ast::PrivateName, bump: &'a Bump) -> &'a PrivateName<'a> {
16183  let node = bump.alloc(PrivateName {
16184    inner,
16185    parent: Default::default(),
16186  });
16187  node
16188}
16189
16190fn set_parent_for_private_name<'a>(node: &PrivateName<'a>, parent: Node<'a>) {
16191  node.parent.set(parent);
16192}
16193
16194#[derive(Clone)]
16195pub struct PrivateProp<'a> {
16196  parent: ParentOnceCell<&'a Class<'a>>,
16197  pub inner: &'a swc_ast::PrivateProp,
16198  pub key: &'a PrivateName<'a>,
16199  pub value: Option<Expr<'a>>,
16200  pub type_ann: Option<&'a TsTypeAnn<'a>>,
16201  pub decorators: &'a [&'a Decorator<'a>],
16202}
16203
16204impl<'a> PrivateProp<'a> {
16205  pub fn parent(&self) -> &'a Class<'a> {
16206    self.parent.get().unwrap()
16207  }
16208
16209  pub fn ctxt(&self) -> swc_common::SyntaxContext {
16210    self.inner.ctxt
16211  }
16212
16213  pub fn is_static(&self) -> bool {
16214    self.inner.is_static
16215  }
16216
16217  /// Typescript extension.
16218  pub fn accessibility(&self) -> Option<Accessibility> {
16219    self.inner.accessibility
16220  }
16221
16222  pub fn is_optional(&self) -> bool {
16223    self.inner.is_optional
16224  }
16225
16226  pub fn is_override(&self) -> bool {
16227    self.inner.is_override
16228  }
16229
16230  pub fn readonly(&self) -> bool {
16231    self.inner.readonly
16232  }
16233
16234  pub fn definite(&self) -> bool {
16235    self.inner.definite
16236  }
16237}
16238
16239impl<'a> SourceRanged for PrivateProp<'a> {
16240  fn start(&self) -> SourcePos {
16241    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16242  }
16243  fn end(&self) -> SourcePos {
16244    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16245  }
16246}
16247
16248impl<'a> From<&PrivateProp<'a>> for Node<'a> {
16249  fn from(node: &PrivateProp<'a>) -> Node<'a> {
16250    let node = unsafe { mem::transmute::<&PrivateProp<'a>, &'a PrivateProp<'a>>(node) };
16251    Node::PrivateProp(node)
16252  }
16253}
16254
16255impl<'a> NodeTrait<'a> for PrivateProp<'a> {
16256  fn parent(&self) -> Option<Node<'a>> {
16257    Some(self.parent.get().unwrap().into())
16258  }
16259
16260  fn children(&self) -> Vec<Node<'a>> {
16261    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());
16262    children.push(self.key.into());
16263    if let Some(child) = self.value.as_ref() {
16264      children.push(child.into());
16265    }
16266    if let Some(child) = self.type_ann {
16267      children.push(child.into());
16268    }
16269    for child in self.decorators.iter() {
16270      children.push((*child).into());
16271    }
16272    children
16273  }
16274
16275  fn as_node(&self) -> Node<'a> {
16276    self.into()
16277  }
16278
16279  fn kind(&self) -> NodeKind {
16280    NodeKind::PrivateProp
16281  }
16282}
16283
16284impl<'a> CastableNode<'a> for PrivateProp<'a> {
16285  fn to(node: &Node<'a>) -> Option<&'a Self> {
16286    if let Node::PrivateProp(node) = node {
16287      Some(node)
16288    } else {
16289      None
16290    }
16291  }
16292
16293  fn kind() -> NodeKind {
16294    NodeKind::PrivateProp
16295  }
16296}
16297
16298fn get_view_for_private_prop<'a>(inner: &'a swc_ast::PrivateProp, bump: &'a Bump) -> &'a PrivateProp<'a> {
16299  let node = bump.alloc(PrivateProp {
16300    inner,
16301    parent: Default::default(),
16302    key: get_view_for_private_name(&inner.key, bump),
16303    value: match &inner.value {
16304      Some(value) => Some(get_view_for_expr(value, bump)),
16305      None => None,
16306    },
16307    type_ann: match &inner.type_ann {
16308      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
16309      None => None,
16310    },
16311    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 }),
16312  });
16313  let parent: Node<'a> = (&*node).into();
16314  set_parent_for_private_name(&node.key, parent);
16315  if let Some(value) = &node.value {
16316    set_parent_for_expr(value, parent)
16317  };
16318  if let Some(value) = &node.type_ann {
16319    set_parent_for_ts_type_ann(value, parent)
16320  };
16321  for value in node.decorators.iter() {
16322    set_parent_for_decorator(value, parent)
16323  }
16324  node
16325}
16326
16327fn set_parent_for_private_prop<'a>(node: &PrivateProp<'a>, parent: Node<'a>) {
16328  node.parent.set(parent.expect::<Class>());
16329}
16330
16331#[derive(Clone)]
16332pub struct Regex<'a> {
16333  parent: ParentOnceCell<Node<'a>>,
16334  pub inner: &'a swc_ast::Regex,
16335}
16336
16337impl<'a> Regex<'a> {
16338  pub fn parent(&self) -> Node<'a> {
16339    self.parent.get().unwrap()
16340  }
16341
16342  pub fn exp(&self) -> &swc_atoms::Atom {
16343    &self.inner.exp
16344  }
16345
16346  pub fn flags(&self) -> &swc_atoms::Atom {
16347    &self.inner.flags
16348  }
16349}
16350
16351impl<'a> SourceRanged for Regex<'a> {
16352  fn start(&self) -> SourcePos {
16353    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16354  }
16355  fn end(&self) -> SourcePos {
16356    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16357  }
16358}
16359
16360impl<'a> From<&Regex<'a>> for Node<'a> {
16361  fn from(node: &Regex<'a>) -> Node<'a> {
16362    let node = unsafe { mem::transmute::<&Regex<'a>, &'a Regex<'a>>(node) };
16363    Node::Regex(node)
16364  }
16365}
16366
16367impl<'a> NodeTrait<'a> for Regex<'a> {
16368  fn parent(&self) -> Option<Node<'a>> {
16369    Some(self.parent.get().unwrap().clone())
16370  }
16371
16372  fn children(&self) -> Vec<Node<'a>> {
16373    Vec::with_capacity(0)
16374  }
16375
16376  fn as_node(&self) -> Node<'a> {
16377    self.into()
16378  }
16379
16380  fn kind(&self) -> NodeKind {
16381    NodeKind::Regex
16382  }
16383}
16384
16385impl<'a> CastableNode<'a> for Regex<'a> {
16386  fn to(node: &Node<'a>) -> Option<&'a Self> {
16387    if let Node::Regex(node) = node {
16388      Some(node)
16389    } else {
16390      None
16391    }
16392  }
16393
16394  fn kind() -> NodeKind {
16395    NodeKind::Regex
16396  }
16397}
16398
16399fn get_view_for_regex<'a>(inner: &'a swc_ast::Regex, bump: &'a Bump) -> &'a Regex<'a> {
16400  let node = bump.alloc(Regex {
16401    inner,
16402    parent: Default::default(),
16403  });
16404  node
16405}
16406
16407fn set_parent_for_regex<'a>(node: &Regex<'a>, parent: Node<'a>) {
16408  node.parent.set(parent);
16409}
16410
16411/// EsTree `RestElement`
16412#[derive(Clone)]
16413pub struct RestPat<'a> {
16414  parent: ParentOnceCell<Node<'a>>,
16415  pub inner: &'a swc_ast::RestPat,
16416  pub arg: Pat<'a>,
16417  pub type_ann: Option<&'a TsTypeAnn<'a>>,
16418}
16419
16420impl<'a> RestPat<'a> {
16421  pub fn parent(&self) -> Node<'a> {
16422    self.parent.get().unwrap()
16423  }
16424
16425  pub fn dot3_token(&self) -> &swc_common::Span {
16426    &self.inner.dot3_token
16427  }
16428}
16429
16430impl<'a> SourceRanged for RestPat<'a> {
16431  fn start(&self) -> SourcePos {
16432    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16433  }
16434  fn end(&self) -> SourcePos {
16435    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16436  }
16437}
16438
16439impl<'a> From<&RestPat<'a>> for Node<'a> {
16440  fn from(node: &RestPat<'a>) -> Node<'a> {
16441    let node = unsafe { mem::transmute::<&RestPat<'a>, &'a RestPat<'a>>(node) };
16442    Node::RestPat(node)
16443  }
16444}
16445
16446impl<'a> NodeTrait<'a> for RestPat<'a> {
16447  fn parent(&self) -> Option<Node<'a>> {
16448    Some(self.parent.get().unwrap().clone())
16449  }
16450
16451  fn children(&self) -> Vec<Node<'a>> {
16452    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
16453    children.push((&self.arg).into());
16454    if let Some(child) = self.type_ann {
16455      children.push(child.into());
16456    }
16457    children
16458  }
16459
16460  fn as_node(&self) -> Node<'a> {
16461    self.into()
16462  }
16463
16464  fn kind(&self) -> NodeKind {
16465    NodeKind::RestPat
16466  }
16467}
16468
16469impl<'a> CastableNode<'a> for RestPat<'a> {
16470  fn to(node: &Node<'a>) -> Option<&'a Self> {
16471    if let Node::RestPat(node) = node {
16472      Some(node)
16473    } else {
16474      None
16475    }
16476  }
16477
16478  fn kind() -> NodeKind {
16479    NodeKind::RestPat
16480  }
16481}
16482
16483fn get_view_for_rest_pat<'a>(inner: &'a swc_ast::RestPat, bump: &'a Bump) -> &'a RestPat<'a> {
16484  let node = bump.alloc(RestPat {
16485    inner,
16486    parent: Default::default(),
16487    arg: get_view_for_pat(&inner.arg, bump),
16488    type_ann: match &inner.type_ann {
16489      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
16490      None => None,
16491    },
16492  });
16493  let parent: Node<'a> = (&*node).into();
16494  set_parent_for_pat(&node.arg, parent);
16495  if let Some(value) = &node.type_ann {
16496    set_parent_for_ts_type_ann(value, parent)
16497  };
16498  node
16499}
16500
16501fn set_parent_for_rest_pat<'a>(node: &RestPat<'a>, parent: Node<'a>) {
16502  node.parent.set(parent);
16503}
16504
16505#[derive(Clone)]
16506pub struct ReturnStmt<'a> {
16507  parent: ParentOnceCell<Node<'a>>,
16508  pub inner: &'a swc_ast::ReturnStmt,
16509  pub arg: Option<Expr<'a>>,
16510}
16511
16512impl<'a> ReturnStmt<'a> {
16513  pub fn parent(&self) -> Node<'a> {
16514    self.parent.get().unwrap()
16515  }
16516}
16517
16518impl<'a> SourceRanged for ReturnStmt<'a> {
16519  fn start(&self) -> SourcePos {
16520    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16521  }
16522  fn end(&self) -> SourcePos {
16523    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16524  }
16525}
16526
16527impl<'a> From<&ReturnStmt<'a>> for Node<'a> {
16528  fn from(node: &ReturnStmt<'a>) -> Node<'a> {
16529    let node = unsafe { mem::transmute::<&ReturnStmt<'a>, &'a ReturnStmt<'a>>(node) };
16530    Node::ReturnStmt(node)
16531  }
16532}
16533
16534impl<'a> NodeTrait<'a> for ReturnStmt<'a> {
16535  fn parent(&self) -> Option<Node<'a>> {
16536    Some(self.parent.get().unwrap().clone())
16537  }
16538
16539  fn children(&self) -> Vec<Node<'a>> {
16540    let mut children = Vec::with_capacity(match &self.arg { Some(_value) => 1, None => 0, });
16541    if let Some(child) = self.arg.as_ref() {
16542      children.push(child.into());
16543    }
16544    children
16545  }
16546
16547  fn as_node(&self) -> Node<'a> {
16548    self.into()
16549  }
16550
16551  fn kind(&self) -> NodeKind {
16552    NodeKind::ReturnStmt
16553  }
16554}
16555
16556impl<'a> CastableNode<'a> for ReturnStmt<'a> {
16557  fn to(node: &Node<'a>) -> Option<&'a Self> {
16558    if let Node::ReturnStmt(node) = node {
16559      Some(node)
16560    } else {
16561      None
16562    }
16563  }
16564
16565  fn kind() -> NodeKind {
16566    NodeKind::ReturnStmt
16567  }
16568}
16569
16570fn get_view_for_return_stmt<'a>(inner: &'a swc_ast::ReturnStmt, bump: &'a Bump) -> &'a ReturnStmt<'a> {
16571  let node = bump.alloc(ReturnStmt {
16572    inner,
16573    parent: Default::default(),
16574    arg: match &inner.arg {
16575      Some(value) => Some(get_view_for_expr(value, bump)),
16576      None => None,
16577    },
16578  });
16579  let parent: Node<'a> = (&*node).into();
16580  if let Some(value) = &node.arg {
16581    set_parent_for_expr(value, parent)
16582  };
16583  node
16584}
16585
16586fn set_parent_for_return_stmt<'a>(node: &ReturnStmt<'a>, parent: Node<'a>) {
16587  node.parent.set(parent);
16588}
16589
16590#[derive(Clone)]
16591pub struct Script<'a> {
16592  pub text_info: Option<&'a SourceTextInfo>,
16593  pub tokens: Option<&'a TokenContainer<'a>>,
16594  pub comments: Option<&'a CommentContainer<'a>>,
16595  pub inner: &'a swc_ast::Script,
16596  pub body: &'a [Stmt<'a>],
16597}
16598
16599impl<'a> Script<'a> {
16600  pub fn shebang(&self) -> &Option<swc_atoms::Atom> {
16601    &self.inner.shebang
16602  }
16603}
16604
16605impl<'a> SourceRanged for Script<'a> {
16606  fn start(&self) -> SourcePos {
16607    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16608  }
16609  fn end(&self) -> SourcePos {
16610    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16611  }
16612}
16613
16614impl<'a> From<&Script<'a>> for Node<'a> {
16615  fn from(node: &Script<'a>) -> Node<'a> {
16616    let node = unsafe { mem::transmute::<&Script<'a>, &'a Script<'a>>(node) };
16617    Node::Script(node)
16618  }
16619}
16620
16621impl<'a> NodeTrait<'a> for Script<'a> {
16622  fn parent(&self) -> Option<Node<'a>> {
16623    None
16624  }
16625
16626  fn children(&self) -> Vec<Node<'a>> {
16627    let mut children = Vec::with_capacity(self.body.len());
16628    for child in self.body.iter() {
16629      children.push(child.into());
16630    }
16631    children
16632  }
16633
16634  fn as_node(&self) -> Node<'a> {
16635    self.into()
16636  }
16637
16638  fn kind(&self) -> NodeKind {
16639    NodeKind::Script
16640  }
16641}
16642
16643impl<'a> CastableNode<'a> for Script<'a> {
16644  fn to(node: &Node<'a>) -> Option<&'a Self> {
16645    if let Node::Script(node) = node {
16646      Some(node)
16647    } else {
16648      None
16649    }
16650  }
16651
16652  fn kind() -> NodeKind {
16653    NodeKind::Script
16654  }
16655}
16656
16657fn 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> {
16658  let inner = source_file_info.script;
16659  let node = bump.alloc(Script {
16660    inner,
16661    text_info: source_file_info.text_info,
16662    tokens,
16663    comments,
16664    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 }),
16665  });
16666  let parent: Node<'a> = (&*node).into();
16667  for value in node.body.iter() {
16668    set_parent_for_stmt(value, parent)
16669  }
16670  node
16671}
16672
16673#[derive(Clone)]
16674pub struct SeqExpr<'a> {
16675  parent: ParentOnceCell<Node<'a>>,
16676  pub inner: &'a swc_ast::SeqExpr,
16677  pub exprs: &'a [Expr<'a>],
16678}
16679
16680impl<'a> SeqExpr<'a> {
16681  pub fn parent(&self) -> Node<'a> {
16682    self.parent.get().unwrap()
16683  }
16684}
16685
16686impl<'a> SourceRanged for SeqExpr<'a> {
16687  fn start(&self) -> SourcePos {
16688    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16689  }
16690  fn end(&self) -> SourcePos {
16691    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16692  }
16693}
16694
16695impl<'a> From<&SeqExpr<'a>> for Node<'a> {
16696  fn from(node: &SeqExpr<'a>) -> Node<'a> {
16697    let node = unsafe { mem::transmute::<&SeqExpr<'a>, &'a SeqExpr<'a>>(node) };
16698    Node::SeqExpr(node)
16699  }
16700}
16701
16702impl<'a> NodeTrait<'a> for SeqExpr<'a> {
16703  fn parent(&self) -> Option<Node<'a>> {
16704    Some(self.parent.get().unwrap().clone())
16705  }
16706
16707  fn children(&self) -> Vec<Node<'a>> {
16708    let mut children = Vec::with_capacity(self.exprs.len());
16709    for child in self.exprs.iter() {
16710      children.push(child.into());
16711    }
16712    children
16713  }
16714
16715  fn as_node(&self) -> Node<'a> {
16716    self.into()
16717  }
16718
16719  fn kind(&self) -> NodeKind {
16720    NodeKind::SeqExpr
16721  }
16722}
16723
16724impl<'a> CastableNode<'a> for SeqExpr<'a> {
16725  fn to(node: &Node<'a>) -> Option<&'a Self> {
16726    if let Node::SeqExpr(node) = node {
16727      Some(node)
16728    } else {
16729      None
16730    }
16731  }
16732
16733  fn kind() -> NodeKind {
16734    NodeKind::SeqExpr
16735  }
16736}
16737
16738fn get_view_for_seq_expr<'a>(inner: &'a swc_ast::SeqExpr, bump: &'a Bump) -> &'a SeqExpr<'a> {
16739  let node = bump.alloc(SeqExpr {
16740    inner,
16741    parent: Default::default(),
16742    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 }),
16743  });
16744  let parent: Node<'a> = (&*node).into();
16745  for value in node.exprs.iter() {
16746    set_parent_for_expr(value, parent)
16747  }
16748  node
16749}
16750
16751fn set_parent_for_seq_expr<'a>(node: &SeqExpr<'a>, parent: Node<'a>) {
16752  node.parent.set(parent);
16753}
16754
16755#[derive(Clone)]
16756pub struct SetterProp<'a> {
16757  parent: ParentOnceCell<&'a ObjectLit<'a>>,
16758  pub inner: &'a swc_ast::SetterProp,
16759  pub key: PropName<'a>,
16760  pub this_param: Option<Pat<'a>>,
16761  pub param: Pat<'a>,
16762  pub body: Option<&'a BlockStmt<'a>>,
16763}
16764
16765impl<'a> SetterProp<'a> {
16766  pub fn parent(&self) -> &'a ObjectLit<'a> {
16767    self.parent.get().unwrap()
16768  }
16769}
16770
16771impl<'a> SourceRanged for SetterProp<'a> {
16772  fn start(&self) -> SourcePos {
16773    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16774  }
16775  fn end(&self) -> SourcePos {
16776    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16777  }
16778}
16779
16780impl<'a> From<&SetterProp<'a>> for Node<'a> {
16781  fn from(node: &SetterProp<'a>) -> Node<'a> {
16782    let node = unsafe { mem::transmute::<&SetterProp<'a>, &'a SetterProp<'a>>(node) };
16783    Node::SetterProp(node)
16784  }
16785}
16786
16787impl<'a> NodeTrait<'a> for SetterProp<'a> {
16788  fn parent(&self) -> Option<Node<'a>> {
16789    Some(self.parent.get().unwrap().into())
16790  }
16791
16792  fn children(&self) -> Vec<Node<'a>> {
16793    let mut children = Vec::with_capacity(2 + match &self.this_param { Some(_value) => 1, None => 0, } + match &self.body { Some(_value) => 1, None => 0, });
16794    children.push((&self.key).into());
16795    if let Some(child) = self.this_param.as_ref() {
16796      children.push(child.into());
16797    }
16798    children.push((&self.param).into());
16799    if let Some(child) = self.body {
16800      children.push(child.into());
16801    }
16802    children
16803  }
16804
16805  fn as_node(&self) -> Node<'a> {
16806    self.into()
16807  }
16808
16809  fn kind(&self) -> NodeKind {
16810    NodeKind::SetterProp
16811  }
16812}
16813
16814impl<'a> CastableNode<'a> for SetterProp<'a> {
16815  fn to(node: &Node<'a>) -> Option<&'a Self> {
16816    if let Node::SetterProp(node) = node {
16817      Some(node)
16818    } else {
16819      None
16820    }
16821  }
16822
16823  fn kind() -> NodeKind {
16824    NodeKind::SetterProp
16825  }
16826}
16827
16828fn get_view_for_setter_prop<'a>(inner: &'a swc_ast::SetterProp, bump: &'a Bump) -> &'a SetterProp<'a> {
16829  let node = bump.alloc(SetterProp {
16830    inner,
16831    parent: Default::default(),
16832    key: get_view_for_prop_name(&inner.key, bump),
16833    this_param: match &inner.this_param {
16834      Some(value) => Some(get_view_for_pat(value, bump)),
16835      None => None,
16836    },
16837    param: get_view_for_pat(&inner.param, bump),
16838    body: match &inner.body {
16839      Some(value) => Some(get_view_for_block_stmt(value, bump)),
16840      None => None,
16841    },
16842  });
16843  let parent: Node<'a> = (&*node).into();
16844  set_parent_for_prop_name(&node.key, parent);
16845  if let Some(value) = &node.this_param {
16846    set_parent_for_pat(value, parent)
16847  };
16848  set_parent_for_pat(&node.param, parent);
16849  if let Some(value) = &node.body {
16850    set_parent_for_block_stmt(value, parent)
16851  };
16852  node
16853}
16854
16855fn set_parent_for_setter_prop<'a>(node: &SetterProp<'a>, parent: Node<'a>) {
16856  node.parent.set(parent.expect::<ObjectLit>());
16857}
16858
16859#[derive(Clone)]
16860pub struct SpreadElement<'a> {
16861  parent: ParentOnceCell<Node<'a>>,
16862  pub inner: &'a swc_ast::SpreadElement,
16863  pub expr: Expr<'a>,
16864}
16865
16866impl<'a> SpreadElement<'a> {
16867  pub fn parent(&self) -> Node<'a> {
16868    self.parent.get().unwrap()
16869  }
16870
16871  pub fn dot3_token(&self) -> &swc_common::Span {
16872    &self.inner.dot3_token
16873  }
16874}
16875
16876impl<'a> SourceRanged for SpreadElement<'a> {
16877  fn start(&self) -> SourcePos {
16878    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16879  }
16880  fn end(&self) -> SourcePos {
16881    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16882  }
16883}
16884
16885impl<'a> From<&SpreadElement<'a>> for Node<'a> {
16886  fn from(node: &SpreadElement<'a>) -> Node<'a> {
16887    let node = unsafe { mem::transmute::<&SpreadElement<'a>, &'a SpreadElement<'a>>(node) };
16888    Node::SpreadElement(node)
16889  }
16890}
16891
16892impl<'a> NodeTrait<'a> for SpreadElement<'a> {
16893  fn parent(&self) -> Option<Node<'a>> {
16894    Some(self.parent.get().unwrap().clone())
16895  }
16896
16897  fn children(&self) -> Vec<Node<'a>> {
16898    let mut children = Vec::with_capacity(1);
16899    children.push((&self.expr).into());
16900    children
16901  }
16902
16903  fn as_node(&self) -> Node<'a> {
16904    self.into()
16905  }
16906
16907  fn kind(&self) -> NodeKind {
16908    NodeKind::SpreadElement
16909  }
16910}
16911
16912impl<'a> CastableNode<'a> for SpreadElement<'a> {
16913  fn to(node: &Node<'a>) -> Option<&'a Self> {
16914    if let Node::SpreadElement(node) = node {
16915      Some(node)
16916    } else {
16917      None
16918    }
16919  }
16920
16921  fn kind() -> NodeKind {
16922    NodeKind::SpreadElement
16923  }
16924}
16925
16926fn get_view_for_spread_element<'a>(inner: &'a swc_ast::SpreadElement, bump: &'a Bump) -> &'a SpreadElement<'a> {
16927  let node = bump.alloc(SpreadElement {
16928    inner,
16929    parent: Default::default(),
16930    expr: get_view_for_expr(&inner.expr, bump),
16931  });
16932  let parent: Node<'a> = (&*node).into();
16933  set_parent_for_expr(&node.expr, parent);
16934  node
16935}
16936
16937fn set_parent_for_spread_element<'a>(node: &SpreadElement<'a>, parent: Node<'a>) {
16938  node.parent.set(parent);
16939}
16940
16941#[derive(Clone)]
16942pub struct StaticBlock<'a> {
16943  parent: ParentOnceCell<&'a Class<'a>>,
16944  pub inner: &'a swc_ast::StaticBlock,
16945  pub body: &'a BlockStmt<'a>,
16946}
16947
16948impl<'a> StaticBlock<'a> {
16949  pub fn parent(&self) -> &'a Class<'a> {
16950    self.parent.get().unwrap()
16951  }
16952}
16953
16954impl<'a> SourceRanged for StaticBlock<'a> {
16955  fn start(&self) -> SourcePos {
16956    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
16957  }
16958  fn end(&self) -> SourcePos {
16959    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
16960  }
16961}
16962
16963impl<'a> From<&StaticBlock<'a>> for Node<'a> {
16964  fn from(node: &StaticBlock<'a>) -> Node<'a> {
16965    let node = unsafe { mem::transmute::<&StaticBlock<'a>, &'a StaticBlock<'a>>(node) };
16966    Node::StaticBlock(node)
16967  }
16968}
16969
16970impl<'a> NodeTrait<'a> for StaticBlock<'a> {
16971  fn parent(&self) -> Option<Node<'a>> {
16972    Some(self.parent.get().unwrap().into())
16973  }
16974
16975  fn children(&self) -> Vec<Node<'a>> {
16976    let mut children = Vec::with_capacity(1);
16977    children.push(self.body.into());
16978    children
16979  }
16980
16981  fn as_node(&self) -> Node<'a> {
16982    self.into()
16983  }
16984
16985  fn kind(&self) -> NodeKind {
16986    NodeKind::StaticBlock
16987  }
16988}
16989
16990impl<'a> CastableNode<'a> for StaticBlock<'a> {
16991  fn to(node: &Node<'a>) -> Option<&'a Self> {
16992    if let Node::StaticBlock(node) = node {
16993      Some(node)
16994    } else {
16995      None
16996    }
16997  }
16998
16999  fn kind() -> NodeKind {
17000    NodeKind::StaticBlock
17001  }
17002}
17003
17004fn get_view_for_static_block<'a>(inner: &'a swc_ast::StaticBlock, bump: &'a Bump) -> &'a StaticBlock<'a> {
17005  let node = bump.alloc(StaticBlock {
17006    inner,
17007    parent: Default::default(),
17008    body: get_view_for_block_stmt(&inner.body, bump),
17009  });
17010  let parent: Node<'a> = (&*node).into();
17011  set_parent_for_block_stmt(&node.body, parent);
17012  node
17013}
17014
17015fn set_parent_for_static_block<'a>(node: &StaticBlock<'a>, parent: Node<'a>) {
17016  node.parent.set(parent.expect::<Class>());
17017}
17018
17019/// A string literal.
17020#[derive(Clone)]
17021pub struct Str<'a> {
17022  parent: ParentOnceCell<Node<'a>>,
17023  pub inner: &'a swc_ast::Str,
17024}
17025
17026impl<'a> Str<'a> {
17027  pub fn parent(&self) -> Node<'a> {
17028    self.parent.get().unwrap()
17029  }
17030
17031  pub fn value(&self) -> &swc_atoms::Atom {
17032    &self.inner.value
17033  }
17034
17035  /// Use `None` value only for transformations to avoid recalculate escaped
17036  /// characters in strings
17037  pub fn raw(&self) -> &Option<swc_atoms::Atom> {
17038    &self.inner.raw
17039  }
17040}
17041
17042impl<'a> SourceRanged for Str<'a> {
17043  fn start(&self) -> SourcePos {
17044    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17045  }
17046  fn end(&self) -> SourcePos {
17047    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17048  }
17049}
17050
17051impl<'a> From<&Str<'a>> for Node<'a> {
17052  fn from(node: &Str<'a>) -> Node<'a> {
17053    let node = unsafe { mem::transmute::<&Str<'a>, &'a Str<'a>>(node) };
17054    Node::Str(node)
17055  }
17056}
17057
17058impl<'a> NodeTrait<'a> for Str<'a> {
17059  fn parent(&self) -> Option<Node<'a>> {
17060    Some(self.parent.get().unwrap().clone())
17061  }
17062
17063  fn children(&self) -> Vec<Node<'a>> {
17064    Vec::with_capacity(0)
17065  }
17066
17067  fn as_node(&self) -> Node<'a> {
17068    self.into()
17069  }
17070
17071  fn kind(&self) -> NodeKind {
17072    NodeKind::Str
17073  }
17074}
17075
17076impl<'a> CastableNode<'a> for Str<'a> {
17077  fn to(node: &Node<'a>) -> Option<&'a Self> {
17078    if let Node::Str(node) = node {
17079      Some(node)
17080    } else {
17081      None
17082    }
17083  }
17084
17085  fn kind() -> NodeKind {
17086    NodeKind::Str
17087  }
17088}
17089
17090fn get_view_for_str<'a>(inner: &'a swc_ast::Str, bump: &'a Bump) -> &'a Str<'a> {
17091  let node = bump.alloc(Str {
17092    inner,
17093    parent: Default::default(),
17094  });
17095  node
17096}
17097
17098fn set_parent_for_str<'a>(node: &Str<'a>, parent: Node<'a>) {
17099  node.parent.set(parent);
17100}
17101
17102#[derive(Clone)]
17103pub struct Super<'a> {
17104  parent: ParentOnceCell<Node<'a>>,
17105  pub inner: &'a swc_ast::Super,
17106}
17107
17108impl<'a> Super<'a> {
17109  pub fn parent(&self) -> Node<'a> {
17110    self.parent.get().unwrap()
17111  }
17112}
17113
17114impl<'a> SourceRanged for Super<'a> {
17115  fn start(&self) -> SourcePos {
17116    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17117  }
17118  fn end(&self) -> SourcePos {
17119    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17120  }
17121}
17122
17123impl<'a> From<&Super<'a>> for Node<'a> {
17124  fn from(node: &Super<'a>) -> Node<'a> {
17125    let node = unsafe { mem::transmute::<&Super<'a>, &'a Super<'a>>(node) };
17126    Node::Super(node)
17127  }
17128}
17129
17130impl<'a> NodeTrait<'a> for Super<'a> {
17131  fn parent(&self) -> Option<Node<'a>> {
17132    Some(self.parent.get().unwrap().clone())
17133  }
17134
17135  fn children(&self) -> Vec<Node<'a>> {
17136    Vec::with_capacity(0)
17137  }
17138
17139  fn as_node(&self) -> Node<'a> {
17140    self.into()
17141  }
17142
17143  fn kind(&self) -> NodeKind {
17144    NodeKind::Super
17145  }
17146}
17147
17148impl<'a> CastableNode<'a> for Super<'a> {
17149  fn to(node: &Node<'a>) -> Option<&'a Self> {
17150    if let Node::Super(node) = node {
17151      Some(node)
17152    } else {
17153      None
17154    }
17155  }
17156
17157  fn kind() -> NodeKind {
17158    NodeKind::Super
17159  }
17160}
17161
17162fn get_view_for_super<'a>(inner: &'a swc_ast::Super, bump: &'a Bump) -> &'a Super<'a> {
17163  let node = bump.alloc(Super {
17164    inner,
17165    parent: Default::default(),
17166  });
17167  node
17168}
17169
17170fn set_parent_for_super<'a>(node: &Super<'a>, parent: Node<'a>) {
17171  node.parent.set(parent);
17172}
17173
17174#[derive(Clone)]
17175pub struct SuperPropExpr<'a> {
17176  parent: ParentOnceCell<Node<'a>>,
17177  pub inner: &'a swc_ast::SuperPropExpr,
17178  pub obj: &'a Super<'a>,
17179  pub prop: SuperProp<'a>,
17180}
17181
17182impl<'a> SuperPropExpr<'a> {
17183  pub fn parent(&self) -> Node<'a> {
17184    self.parent.get().unwrap()
17185  }
17186}
17187
17188impl<'a> SourceRanged for SuperPropExpr<'a> {
17189  fn start(&self) -> SourcePos {
17190    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17191  }
17192  fn end(&self) -> SourcePos {
17193    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17194  }
17195}
17196
17197impl<'a> From<&SuperPropExpr<'a>> for Node<'a> {
17198  fn from(node: &SuperPropExpr<'a>) -> Node<'a> {
17199    let node = unsafe { mem::transmute::<&SuperPropExpr<'a>, &'a SuperPropExpr<'a>>(node) };
17200    Node::SuperPropExpr(node)
17201  }
17202}
17203
17204impl<'a> NodeTrait<'a> for SuperPropExpr<'a> {
17205  fn parent(&self) -> Option<Node<'a>> {
17206    Some(self.parent.get().unwrap().clone())
17207  }
17208
17209  fn children(&self) -> Vec<Node<'a>> {
17210    let mut children = Vec::with_capacity(2);
17211    children.push(self.obj.into());
17212    children.push((&self.prop).into());
17213    children
17214  }
17215
17216  fn as_node(&self) -> Node<'a> {
17217    self.into()
17218  }
17219
17220  fn kind(&self) -> NodeKind {
17221    NodeKind::SuperPropExpr
17222  }
17223}
17224
17225impl<'a> CastableNode<'a> for SuperPropExpr<'a> {
17226  fn to(node: &Node<'a>) -> Option<&'a Self> {
17227    if let Node::SuperPropExpr(node) = node {
17228      Some(node)
17229    } else {
17230      None
17231    }
17232  }
17233
17234  fn kind() -> NodeKind {
17235    NodeKind::SuperPropExpr
17236  }
17237}
17238
17239fn get_view_for_super_prop_expr<'a>(inner: &'a swc_ast::SuperPropExpr, bump: &'a Bump) -> &'a SuperPropExpr<'a> {
17240  let node = bump.alloc(SuperPropExpr {
17241    inner,
17242    parent: Default::default(),
17243    obj: get_view_for_super(&inner.obj, bump),
17244    prop: get_view_for_super_prop(&inner.prop, bump),
17245  });
17246  let parent: Node<'a> = (&*node).into();
17247  set_parent_for_super(&node.obj, parent);
17248  set_parent_for_super_prop(&node.prop, parent);
17249  node
17250}
17251
17252fn set_parent_for_super_prop_expr<'a>(node: &SuperPropExpr<'a>, parent: Node<'a>) {
17253  node.parent.set(parent);
17254}
17255
17256#[derive(Clone)]
17257pub struct SwitchCase<'a> {
17258  parent: ParentOnceCell<&'a SwitchStmt<'a>>,
17259  pub inner: &'a swc_ast::SwitchCase,
17260  /// None for `default:`
17261  pub test: Option<Expr<'a>>,
17262  pub cons: &'a [Stmt<'a>],
17263}
17264
17265impl<'a> SwitchCase<'a> {
17266  pub fn parent(&self) -> &'a SwitchStmt<'a> {
17267    self.parent.get().unwrap()
17268  }
17269}
17270
17271impl<'a> SourceRanged for SwitchCase<'a> {
17272  fn start(&self) -> SourcePos {
17273    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17274  }
17275  fn end(&self) -> SourcePos {
17276    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17277  }
17278}
17279
17280impl<'a> From<&SwitchCase<'a>> for Node<'a> {
17281  fn from(node: &SwitchCase<'a>) -> Node<'a> {
17282    let node = unsafe { mem::transmute::<&SwitchCase<'a>, &'a SwitchCase<'a>>(node) };
17283    Node::SwitchCase(node)
17284  }
17285}
17286
17287impl<'a> NodeTrait<'a> for SwitchCase<'a> {
17288  fn parent(&self) -> Option<Node<'a>> {
17289    Some(self.parent.get().unwrap().into())
17290  }
17291
17292  fn children(&self) -> Vec<Node<'a>> {
17293    let mut children = Vec::with_capacity(match &self.test { Some(_value) => 1, None => 0, } + self.cons.len());
17294    if let Some(child) = self.test.as_ref() {
17295      children.push(child.into());
17296    }
17297    for child in self.cons.iter() {
17298      children.push(child.into());
17299    }
17300    children
17301  }
17302
17303  fn as_node(&self) -> Node<'a> {
17304    self.into()
17305  }
17306
17307  fn kind(&self) -> NodeKind {
17308    NodeKind::SwitchCase
17309  }
17310}
17311
17312impl<'a> CastableNode<'a> for SwitchCase<'a> {
17313  fn to(node: &Node<'a>) -> Option<&'a Self> {
17314    if let Node::SwitchCase(node) = node {
17315      Some(node)
17316    } else {
17317      None
17318    }
17319  }
17320
17321  fn kind() -> NodeKind {
17322    NodeKind::SwitchCase
17323  }
17324}
17325
17326fn get_view_for_switch_case<'a>(inner: &'a swc_ast::SwitchCase, bump: &'a Bump) -> &'a SwitchCase<'a> {
17327  let node = bump.alloc(SwitchCase {
17328    inner,
17329    parent: Default::default(),
17330    test: match &inner.test {
17331      Some(value) => Some(get_view_for_expr(value, bump)),
17332      None => None,
17333    },
17334    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 }),
17335  });
17336  let parent: Node<'a> = (&*node).into();
17337  if let Some(value) = &node.test {
17338    set_parent_for_expr(value, parent)
17339  };
17340  for value in node.cons.iter() {
17341    set_parent_for_stmt(value, parent)
17342  }
17343  node
17344}
17345
17346fn set_parent_for_switch_case<'a>(node: &SwitchCase<'a>, parent: Node<'a>) {
17347  node.parent.set(parent.expect::<SwitchStmt>());
17348}
17349
17350#[derive(Clone)]
17351pub struct SwitchStmt<'a> {
17352  parent: ParentOnceCell<Node<'a>>,
17353  pub inner: &'a swc_ast::SwitchStmt,
17354  pub discriminant: Expr<'a>,
17355  pub cases: &'a [&'a SwitchCase<'a>],
17356}
17357
17358impl<'a> SwitchStmt<'a> {
17359  pub fn parent(&self) -> Node<'a> {
17360    self.parent.get().unwrap()
17361  }
17362}
17363
17364impl<'a> SourceRanged for SwitchStmt<'a> {
17365  fn start(&self) -> SourcePos {
17366    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17367  }
17368  fn end(&self) -> SourcePos {
17369    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17370  }
17371}
17372
17373impl<'a> From<&SwitchStmt<'a>> for Node<'a> {
17374  fn from(node: &SwitchStmt<'a>) -> Node<'a> {
17375    let node = unsafe { mem::transmute::<&SwitchStmt<'a>, &'a SwitchStmt<'a>>(node) };
17376    Node::SwitchStmt(node)
17377  }
17378}
17379
17380impl<'a> NodeTrait<'a> for SwitchStmt<'a> {
17381  fn parent(&self) -> Option<Node<'a>> {
17382    Some(self.parent.get().unwrap().clone())
17383  }
17384
17385  fn children(&self) -> Vec<Node<'a>> {
17386    let mut children = Vec::with_capacity(1 + self.cases.len());
17387    children.push((&self.discriminant).into());
17388    for child in self.cases.iter() {
17389      children.push((*child).into());
17390    }
17391    children
17392  }
17393
17394  fn as_node(&self) -> Node<'a> {
17395    self.into()
17396  }
17397
17398  fn kind(&self) -> NodeKind {
17399    NodeKind::SwitchStmt
17400  }
17401}
17402
17403impl<'a> CastableNode<'a> for SwitchStmt<'a> {
17404  fn to(node: &Node<'a>) -> Option<&'a Self> {
17405    if let Node::SwitchStmt(node) = node {
17406      Some(node)
17407    } else {
17408      None
17409    }
17410  }
17411
17412  fn kind() -> NodeKind {
17413    NodeKind::SwitchStmt
17414  }
17415}
17416
17417fn get_view_for_switch_stmt<'a>(inner: &'a swc_ast::SwitchStmt, bump: &'a Bump) -> &'a SwitchStmt<'a> {
17418  let node = bump.alloc(SwitchStmt {
17419    inner,
17420    parent: Default::default(),
17421    discriminant: get_view_for_expr(&inner.discriminant, bump),
17422    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 }),
17423  });
17424  let parent: Node<'a> = (&*node).into();
17425  set_parent_for_expr(&node.discriminant, parent);
17426  for value in node.cases.iter() {
17427    set_parent_for_switch_case(value, parent)
17428  }
17429  node
17430}
17431
17432fn set_parent_for_switch_stmt<'a>(node: &SwitchStmt<'a>, parent: Node<'a>) {
17433  node.parent.set(parent);
17434}
17435
17436#[derive(Clone)]
17437pub struct TaggedTpl<'a> {
17438  parent: ParentOnceCell<Node<'a>>,
17439  pub inner: &'a swc_ast::TaggedTpl,
17440  pub tag: Expr<'a>,
17441  pub type_params: Option<&'a TsTypeParamInstantiation<'a>>,
17442  /// This is boxed to reduce the type size of [Expr].
17443  pub tpl: &'a Tpl<'a>,
17444}
17445
17446impl<'a> TaggedTpl<'a> {
17447  pub fn parent(&self) -> Node<'a> {
17448    self.parent.get().unwrap()
17449  }
17450
17451  pub fn ctxt(&self) -> swc_common::SyntaxContext {
17452    self.inner.ctxt
17453  }
17454}
17455
17456impl<'a> SourceRanged for TaggedTpl<'a> {
17457  fn start(&self) -> SourcePos {
17458    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17459  }
17460  fn end(&self) -> SourcePos {
17461    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17462  }
17463}
17464
17465impl<'a> From<&TaggedTpl<'a>> for Node<'a> {
17466  fn from(node: &TaggedTpl<'a>) -> Node<'a> {
17467    let node = unsafe { mem::transmute::<&TaggedTpl<'a>, &'a TaggedTpl<'a>>(node) };
17468    Node::TaggedTpl(node)
17469  }
17470}
17471
17472impl<'a> NodeTrait<'a> for TaggedTpl<'a> {
17473  fn parent(&self) -> Option<Node<'a>> {
17474    Some(self.parent.get().unwrap().clone())
17475  }
17476
17477  fn children(&self) -> Vec<Node<'a>> {
17478    let mut children = Vec::with_capacity(2 + match &self.type_params { Some(_value) => 1, None => 0, });
17479    children.push((&self.tag).into());
17480    if let Some(child) = self.type_params {
17481      children.push(child.into());
17482    }
17483    children.push(self.tpl.into());
17484    children
17485  }
17486
17487  fn as_node(&self) -> Node<'a> {
17488    self.into()
17489  }
17490
17491  fn kind(&self) -> NodeKind {
17492    NodeKind::TaggedTpl
17493  }
17494}
17495
17496impl<'a> CastableNode<'a> for TaggedTpl<'a> {
17497  fn to(node: &Node<'a>) -> Option<&'a Self> {
17498    if let Node::TaggedTpl(node) = node {
17499      Some(node)
17500    } else {
17501      None
17502    }
17503  }
17504
17505  fn kind() -> NodeKind {
17506    NodeKind::TaggedTpl
17507  }
17508}
17509
17510fn get_view_for_tagged_tpl<'a>(inner: &'a swc_ast::TaggedTpl, bump: &'a Bump) -> &'a TaggedTpl<'a> {
17511  let node = bump.alloc(TaggedTpl {
17512    inner,
17513    parent: Default::default(),
17514    tag: get_view_for_expr(&inner.tag, bump),
17515    type_params: match &inner.type_params {
17516      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
17517      None => None,
17518    },
17519    tpl: get_view_for_tpl(&inner.tpl, bump),
17520  });
17521  let parent: Node<'a> = (&*node).into();
17522  set_parent_for_expr(&node.tag, parent);
17523  if let Some(value) = &node.type_params {
17524    set_parent_for_ts_type_param_instantiation(value, parent)
17525  };
17526  set_parent_for_tpl(&node.tpl, parent);
17527  node
17528}
17529
17530fn set_parent_for_tagged_tpl<'a>(node: &TaggedTpl<'a>, parent: Node<'a>) {
17531  node.parent.set(parent);
17532}
17533
17534#[derive(Clone)]
17535pub struct ThisExpr<'a> {
17536  parent: ParentOnceCell<Node<'a>>,
17537  pub inner: &'a swc_ast::ThisExpr,
17538}
17539
17540impl<'a> ThisExpr<'a> {
17541  pub fn parent(&self) -> Node<'a> {
17542    self.parent.get().unwrap()
17543  }
17544}
17545
17546impl<'a> SourceRanged for ThisExpr<'a> {
17547  fn start(&self) -> SourcePos {
17548    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17549  }
17550  fn end(&self) -> SourcePos {
17551    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17552  }
17553}
17554
17555impl<'a> From<&ThisExpr<'a>> for Node<'a> {
17556  fn from(node: &ThisExpr<'a>) -> Node<'a> {
17557    let node = unsafe { mem::transmute::<&ThisExpr<'a>, &'a ThisExpr<'a>>(node) };
17558    Node::ThisExpr(node)
17559  }
17560}
17561
17562impl<'a> NodeTrait<'a> for ThisExpr<'a> {
17563  fn parent(&self) -> Option<Node<'a>> {
17564    Some(self.parent.get().unwrap().clone())
17565  }
17566
17567  fn children(&self) -> Vec<Node<'a>> {
17568    Vec::with_capacity(0)
17569  }
17570
17571  fn as_node(&self) -> Node<'a> {
17572    self.into()
17573  }
17574
17575  fn kind(&self) -> NodeKind {
17576    NodeKind::ThisExpr
17577  }
17578}
17579
17580impl<'a> CastableNode<'a> for ThisExpr<'a> {
17581  fn to(node: &Node<'a>) -> Option<&'a Self> {
17582    if let Node::ThisExpr(node) = node {
17583      Some(node)
17584    } else {
17585      None
17586    }
17587  }
17588
17589  fn kind() -> NodeKind {
17590    NodeKind::ThisExpr
17591  }
17592}
17593
17594fn get_view_for_this_expr<'a>(inner: &'a swc_ast::ThisExpr, bump: &'a Bump) -> &'a ThisExpr<'a> {
17595  let node = bump.alloc(ThisExpr {
17596    inner,
17597    parent: Default::default(),
17598  });
17599  node
17600}
17601
17602fn set_parent_for_this_expr<'a>(node: &ThisExpr<'a>, parent: Node<'a>) {
17603  node.parent.set(parent);
17604}
17605
17606#[derive(Clone)]
17607pub struct ThrowStmt<'a> {
17608  parent: ParentOnceCell<Node<'a>>,
17609  pub inner: &'a swc_ast::ThrowStmt,
17610  pub arg: Expr<'a>,
17611}
17612
17613impl<'a> ThrowStmt<'a> {
17614  pub fn parent(&self) -> Node<'a> {
17615    self.parent.get().unwrap()
17616  }
17617}
17618
17619impl<'a> SourceRanged for ThrowStmt<'a> {
17620  fn start(&self) -> SourcePos {
17621    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17622  }
17623  fn end(&self) -> SourcePos {
17624    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17625  }
17626}
17627
17628impl<'a> From<&ThrowStmt<'a>> for Node<'a> {
17629  fn from(node: &ThrowStmt<'a>) -> Node<'a> {
17630    let node = unsafe { mem::transmute::<&ThrowStmt<'a>, &'a ThrowStmt<'a>>(node) };
17631    Node::ThrowStmt(node)
17632  }
17633}
17634
17635impl<'a> NodeTrait<'a> for ThrowStmt<'a> {
17636  fn parent(&self) -> Option<Node<'a>> {
17637    Some(self.parent.get().unwrap().clone())
17638  }
17639
17640  fn children(&self) -> Vec<Node<'a>> {
17641    let mut children = Vec::with_capacity(1);
17642    children.push((&self.arg).into());
17643    children
17644  }
17645
17646  fn as_node(&self) -> Node<'a> {
17647    self.into()
17648  }
17649
17650  fn kind(&self) -> NodeKind {
17651    NodeKind::ThrowStmt
17652  }
17653}
17654
17655impl<'a> CastableNode<'a> for ThrowStmt<'a> {
17656  fn to(node: &Node<'a>) -> Option<&'a Self> {
17657    if let Node::ThrowStmt(node) = node {
17658      Some(node)
17659    } else {
17660      None
17661    }
17662  }
17663
17664  fn kind() -> NodeKind {
17665    NodeKind::ThrowStmt
17666  }
17667}
17668
17669fn get_view_for_throw_stmt<'a>(inner: &'a swc_ast::ThrowStmt, bump: &'a Bump) -> &'a ThrowStmt<'a> {
17670  let node = bump.alloc(ThrowStmt {
17671    inner,
17672    parent: Default::default(),
17673    arg: get_view_for_expr(&inner.arg, bump),
17674  });
17675  let parent: Node<'a> = (&*node).into();
17676  set_parent_for_expr(&node.arg, parent);
17677  node
17678}
17679
17680fn set_parent_for_throw_stmt<'a>(node: &ThrowStmt<'a>, parent: Node<'a>) {
17681  node.parent.set(parent);
17682}
17683
17684#[derive(Clone)]
17685pub struct Tpl<'a> {
17686  parent: ParentOnceCell<Node<'a>>,
17687  pub inner: &'a swc_ast::Tpl,
17688  pub exprs: &'a [Expr<'a>],
17689  pub quasis: &'a [&'a TplElement<'a>],
17690}
17691
17692impl<'a> Tpl<'a> {
17693  pub fn parent(&self) -> Node<'a> {
17694    self.parent.get().unwrap()
17695  }
17696}
17697
17698impl<'a> SourceRanged for Tpl<'a> {
17699  fn start(&self) -> SourcePos {
17700    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17701  }
17702  fn end(&self) -> SourcePos {
17703    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17704  }
17705}
17706
17707impl<'a> From<&Tpl<'a>> for Node<'a> {
17708  fn from(node: &Tpl<'a>) -> Node<'a> {
17709    let node = unsafe { mem::transmute::<&Tpl<'a>, &'a Tpl<'a>>(node) };
17710    Node::Tpl(node)
17711  }
17712}
17713
17714impl<'a> NodeTrait<'a> for Tpl<'a> {
17715  fn parent(&self) -> Option<Node<'a>> {
17716    Some(self.parent.get().unwrap().clone())
17717  }
17718
17719  fn children(&self) -> Vec<Node<'a>> {
17720    let mut children = Vec::with_capacity(self.exprs.len() + self.quasis.len());
17721    for child in self.exprs.iter() {
17722      children.push(child.into());
17723    }
17724    for child in self.quasis.iter() {
17725      children.push((*child).into());
17726    }
17727    children
17728  }
17729
17730  fn as_node(&self) -> Node<'a> {
17731    self.into()
17732  }
17733
17734  fn kind(&self) -> NodeKind {
17735    NodeKind::Tpl
17736  }
17737}
17738
17739impl<'a> CastableNode<'a> for Tpl<'a> {
17740  fn to(node: &Node<'a>) -> Option<&'a Self> {
17741    if let Node::Tpl(node) = node {
17742      Some(node)
17743    } else {
17744      None
17745    }
17746  }
17747
17748  fn kind() -> NodeKind {
17749    NodeKind::Tpl
17750  }
17751}
17752
17753fn get_view_for_tpl<'a>(inner: &'a swc_ast::Tpl, bump: &'a Bump) -> &'a Tpl<'a> {
17754  let node = bump.alloc(Tpl {
17755    inner,
17756    parent: Default::default(),
17757    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 }),
17758    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 }),
17759  });
17760  let parent: Node<'a> = (&*node).into();
17761  for value in node.exprs.iter() {
17762    set_parent_for_expr(value, parent)
17763  }
17764  for value in node.quasis.iter() {
17765    set_parent_for_tpl_element(value, parent)
17766  }
17767  node
17768}
17769
17770fn set_parent_for_tpl<'a>(node: &Tpl<'a>, parent: Node<'a>) {
17771  node.parent.set(parent);
17772}
17773
17774#[derive(Clone)]
17775pub struct TplElement<'a> {
17776  parent: ParentOnceCell<Node<'a>>,
17777  pub inner: &'a swc_ast::TplElement,
17778}
17779
17780impl<'a> TplElement<'a> {
17781  pub fn parent(&self) -> Node<'a> {
17782    self.parent.get().unwrap()
17783  }
17784
17785  pub fn tail(&self) -> bool {
17786    self.inner.tail
17787  }
17788
17789  /// This value is never used by `swc_ecma_codegen`, and this fact is
17790  /// considered as a public API.
17791  ///
17792  /// If you are going to use codegen right after creating a [TplElement], you
17793  /// don't have to worry about this value.
17794  pub fn cooked(&self) -> &Option<swc_atoms::Atom> {
17795    &self.inner.cooked
17796  }
17797
17798  /// You may need to perform. `.replace("\r\n", "\n").replace('\r', "\n")` on
17799  /// this value.
17800  pub fn raw(&self) -> &swc_atoms::Atom {
17801    &self.inner.raw
17802  }
17803}
17804
17805impl<'a> SourceRanged for TplElement<'a> {
17806  fn start(&self) -> SourcePos {
17807    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17808  }
17809  fn end(&self) -> SourcePos {
17810    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17811  }
17812}
17813
17814impl<'a> From<&TplElement<'a>> for Node<'a> {
17815  fn from(node: &TplElement<'a>) -> Node<'a> {
17816    let node = unsafe { mem::transmute::<&TplElement<'a>, &'a TplElement<'a>>(node) };
17817    Node::TplElement(node)
17818  }
17819}
17820
17821impl<'a> NodeTrait<'a> for TplElement<'a> {
17822  fn parent(&self) -> Option<Node<'a>> {
17823    Some(self.parent.get().unwrap().clone())
17824  }
17825
17826  fn children(&self) -> Vec<Node<'a>> {
17827    Vec::with_capacity(0)
17828  }
17829
17830  fn as_node(&self) -> Node<'a> {
17831    self.into()
17832  }
17833
17834  fn kind(&self) -> NodeKind {
17835    NodeKind::TplElement
17836  }
17837}
17838
17839impl<'a> CastableNode<'a> for TplElement<'a> {
17840  fn to(node: &Node<'a>) -> Option<&'a Self> {
17841    if let Node::TplElement(node) = node {
17842      Some(node)
17843    } else {
17844      None
17845    }
17846  }
17847
17848  fn kind() -> NodeKind {
17849    NodeKind::TplElement
17850  }
17851}
17852
17853fn get_view_for_tpl_element<'a>(inner: &'a swc_ast::TplElement, bump: &'a Bump) -> &'a TplElement<'a> {
17854  let node = bump.alloc(TplElement {
17855    inner,
17856    parent: Default::default(),
17857  });
17858  node
17859}
17860
17861fn set_parent_for_tpl_element<'a>(node: &TplElement<'a>, parent: Node<'a>) {
17862  node.parent.set(parent);
17863}
17864
17865#[derive(Clone)]
17866pub struct TryStmt<'a> {
17867  parent: ParentOnceCell<Node<'a>>,
17868  pub inner: &'a swc_ast::TryStmt,
17869  pub block: &'a BlockStmt<'a>,
17870  pub handler: Option<&'a CatchClause<'a>>,
17871  pub finalizer: Option<&'a BlockStmt<'a>>,
17872}
17873
17874impl<'a> TryStmt<'a> {
17875  pub fn parent(&self) -> Node<'a> {
17876    self.parent.get().unwrap()
17877  }
17878}
17879
17880impl<'a> SourceRanged for TryStmt<'a> {
17881  fn start(&self) -> SourcePos {
17882    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17883  }
17884  fn end(&self) -> SourcePos {
17885    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17886  }
17887}
17888
17889impl<'a> From<&TryStmt<'a>> for Node<'a> {
17890  fn from(node: &TryStmt<'a>) -> Node<'a> {
17891    let node = unsafe { mem::transmute::<&TryStmt<'a>, &'a TryStmt<'a>>(node) };
17892    Node::TryStmt(node)
17893  }
17894}
17895
17896impl<'a> NodeTrait<'a> for TryStmt<'a> {
17897  fn parent(&self) -> Option<Node<'a>> {
17898    Some(self.parent.get().unwrap().clone())
17899  }
17900
17901  fn children(&self) -> Vec<Node<'a>> {
17902    let mut children = Vec::with_capacity(1 + match &self.handler { Some(_value) => 1, None => 0, } + match &self.finalizer { Some(_value) => 1, None => 0, });
17903    children.push(self.block.into());
17904    if let Some(child) = self.handler {
17905      children.push(child.into());
17906    }
17907    if let Some(child) = self.finalizer {
17908      children.push(child.into());
17909    }
17910    children
17911  }
17912
17913  fn as_node(&self) -> Node<'a> {
17914    self.into()
17915  }
17916
17917  fn kind(&self) -> NodeKind {
17918    NodeKind::TryStmt
17919  }
17920}
17921
17922impl<'a> CastableNode<'a> for TryStmt<'a> {
17923  fn to(node: &Node<'a>) -> Option<&'a Self> {
17924    if let Node::TryStmt(node) = node {
17925      Some(node)
17926    } else {
17927      None
17928    }
17929  }
17930
17931  fn kind() -> NodeKind {
17932    NodeKind::TryStmt
17933  }
17934}
17935
17936fn get_view_for_try_stmt<'a>(inner: &'a swc_ast::TryStmt, bump: &'a Bump) -> &'a TryStmt<'a> {
17937  let node = bump.alloc(TryStmt {
17938    inner,
17939    parent: Default::default(),
17940    block: get_view_for_block_stmt(&inner.block, bump),
17941    handler: match &inner.handler {
17942      Some(value) => Some(get_view_for_catch_clause(value, bump)),
17943      None => None,
17944    },
17945    finalizer: match &inner.finalizer {
17946      Some(value) => Some(get_view_for_block_stmt(value, bump)),
17947      None => None,
17948    },
17949  });
17950  let parent: Node<'a> = (&*node).into();
17951  set_parent_for_block_stmt(&node.block, parent);
17952  if let Some(value) = &node.handler {
17953    set_parent_for_catch_clause(value, parent)
17954  };
17955  if let Some(value) = &node.finalizer {
17956    set_parent_for_block_stmt(value, parent)
17957  };
17958  node
17959}
17960
17961fn set_parent_for_try_stmt<'a>(node: &TryStmt<'a>, parent: Node<'a>) {
17962  node.parent.set(parent);
17963}
17964
17965#[derive(Clone)]
17966pub struct TsArrayType<'a> {
17967  parent: ParentOnceCell<Node<'a>>,
17968  pub inner: &'a swc_ast::TsArrayType,
17969  pub elem_type: TsType<'a>,
17970}
17971
17972impl<'a> TsArrayType<'a> {
17973  pub fn parent(&self) -> Node<'a> {
17974    self.parent.get().unwrap()
17975  }
17976}
17977
17978impl<'a> SourceRanged for TsArrayType<'a> {
17979  fn start(&self) -> SourcePos {
17980    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
17981  }
17982  fn end(&self) -> SourcePos {
17983    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
17984  }
17985}
17986
17987impl<'a> From<&TsArrayType<'a>> for Node<'a> {
17988  fn from(node: &TsArrayType<'a>) -> Node<'a> {
17989    let node = unsafe { mem::transmute::<&TsArrayType<'a>, &'a TsArrayType<'a>>(node) };
17990    Node::TsArrayType(node)
17991  }
17992}
17993
17994impl<'a> NodeTrait<'a> for TsArrayType<'a> {
17995  fn parent(&self) -> Option<Node<'a>> {
17996    Some(self.parent.get().unwrap().clone())
17997  }
17998
17999  fn children(&self) -> Vec<Node<'a>> {
18000    let mut children = Vec::with_capacity(1);
18001    children.push((&self.elem_type).into());
18002    children
18003  }
18004
18005  fn as_node(&self) -> Node<'a> {
18006    self.into()
18007  }
18008
18009  fn kind(&self) -> NodeKind {
18010    NodeKind::TsArrayType
18011  }
18012}
18013
18014impl<'a> CastableNode<'a> for TsArrayType<'a> {
18015  fn to(node: &Node<'a>) -> Option<&'a Self> {
18016    if let Node::TsArrayType(node) = node {
18017      Some(node)
18018    } else {
18019      None
18020    }
18021  }
18022
18023  fn kind() -> NodeKind {
18024    NodeKind::TsArrayType
18025  }
18026}
18027
18028fn get_view_for_ts_array_type<'a>(inner: &'a swc_ast::TsArrayType, bump: &'a Bump) -> &'a TsArrayType<'a> {
18029  let node = bump.alloc(TsArrayType {
18030    inner,
18031    parent: Default::default(),
18032    elem_type: get_view_for_ts_type(&inner.elem_type, bump),
18033  });
18034  let parent: Node<'a> = (&*node).into();
18035  set_parent_for_ts_type(&node.elem_type, parent);
18036  node
18037}
18038
18039fn set_parent_for_ts_array_type<'a>(node: &TsArrayType<'a>, parent: Node<'a>) {
18040  node.parent.set(parent);
18041}
18042
18043#[derive(Clone)]
18044pub struct TsAsExpr<'a> {
18045  parent: ParentOnceCell<Node<'a>>,
18046  pub inner: &'a swc_ast::TsAsExpr,
18047  pub expr: Expr<'a>,
18048  pub type_ann: TsType<'a>,
18049}
18050
18051impl<'a> TsAsExpr<'a> {
18052  pub fn parent(&self) -> Node<'a> {
18053    self.parent.get().unwrap()
18054  }
18055}
18056
18057impl<'a> SourceRanged for TsAsExpr<'a> {
18058  fn start(&self) -> SourcePos {
18059    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18060  }
18061  fn end(&self) -> SourcePos {
18062    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18063  }
18064}
18065
18066impl<'a> From<&TsAsExpr<'a>> for Node<'a> {
18067  fn from(node: &TsAsExpr<'a>) -> Node<'a> {
18068    let node = unsafe { mem::transmute::<&TsAsExpr<'a>, &'a TsAsExpr<'a>>(node) };
18069    Node::TsAsExpr(node)
18070  }
18071}
18072
18073impl<'a> NodeTrait<'a> for TsAsExpr<'a> {
18074  fn parent(&self) -> Option<Node<'a>> {
18075    Some(self.parent.get().unwrap().clone())
18076  }
18077
18078  fn children(&self) -> Vec<Node<'a>> {
18079    let mut children = Vec::with_capacity(2);
18080    children.push((&self.expr).into());
18081    children.push((&self.type_ann).into());
18082    children
18083  }
18084
18085  fn as_node(&self) -> Node<'a> {
18086    self.into()
18087  }
18088
18089  fn kind(&self) -> NodeKind {
18090    NodeKind::TsAsExpr
18091  }
18092}
18093
18094impl<'a> CastableNode<'a> for TsAsExpr<'a> {
18095  fn to(node: &Node<'a>) -> Option<&'a Self> {
18096    if let Node::TsAsExpr(node) = node {
18097      Some(node)
18098    } else {
18099      None
18100    }
18101  }
18102
18103  fn kind() -> NodeKind {
18104    NodeKind::TsAsExpr
18105  }
18106}
18107
18108fn get_view_for_ts_as_expr<'a>(inner: &'a swc_ast::TsAsExpr, bump: &'a Bump) -> &'a TsAsExpr<'a> {
18109  let node = bump.alloc(TsAsExpr {
18110    inner,
18111    parent: Default::default(),
18112    expr: get_view_for_expr(&inner.expr, bump),
18113    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
18114  });
18115  let parent: Node<'a> = (&*node).into();
18116  set_parent_for_expr(&node.expr, parent);
18117  set_parent_for_ts_type(&node.type_ann, parent);
18118  node
18119}
18120
18121fn set_parent_for_ts_as_expr<'a>(node: &TsAsExpr<'a>, parent: Node<'a>) {
18122  node.parent.set(parent);
18123}
18124
18125#[derive(Clone)]
18126pub struct TsCallSignatureDecl<'a> {
18127  parent: ParentOnceCell<Node<'a>>,
18128  pub inner: &'a swc_ast::TsCallSignatureDecl,
18129  pub params: &'a [TsFnParam<'a>],
18130  pub type_ann: Option<&'a TsTypeAnn<'a>>,
18131  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
18132}
18133
18134impl<'a> TsCallSignatureDecl<'a> {
18135  pub fn parent(&self) -> Node<'a> {
18136    self.parent.get().unwrap()
18137  }
18138}
18139
18140impl<'a> SourceRanged for TsCallSignatureDecl<'a> {
18141  fn start(&self) -> SourcePos {
18142    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18143  }
18144  fn end(&self) -> SourcePos {
18145    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18146  }
18147}
18148
18149impl<'a> From<&TsCallSignatureDecl<'a>> for Node<'a> {
18150  fn from(node: &TsCallSignatureDecl<'a>) -> Node<'a> {
18151    let node = unsafe { mem::transmute::<&TsCallSignatureDecl<'a>, &'a TsCallSignatureDecl<'a>>(node) };
18152    Node::TsCallSignatureDecl(node)
18153  }
18154}
18155
18156impl<'a> NodeTrait<'a> for TsCallSignatureDecl<'a> {
18157  fn parent(&self) -> Option<Node<'a>> {
18158    Some(self.parent.get().unwrap().clone())
18159  }
18160
18161  fn children(&self) -> Vec<Node<'a>> {
18162    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, });
18163    for child in self.params.iter() {
18164      children.push(child.into());
18165    }
18166    if let Some(child) = self.type_ann {
18167      children.push(child.into());
18168    }
18169    if let Some(child) = self.type_params {
18170      children.push(child.into());
18171    }
18172    children
18173  }
18174
18175  fn as_node(&self) -> Node<'a> {
18176    self.into()
18177  }
18178
18179  fn kind(&self) -> NodeKind {
18180    NodeKind::TsCallSignatureDecl
18181  }
18182}
18183
18184impl<'a> CastableNode<'a> for TsCallSignatureDecl<'a> {
18185  fn to(node: &Node<'a>) -> Option<&'a Self> {
18186    if let Node::TsCallSignatureDecl(node) = node {
18187      Some(node)
18188    } else {
18189      None
18190    }
18191  }
18192
18193  fn kind() -> NodeKind {
18194    NodeKind::TsCallSignatureDecl
18195  }
18196}
18197
18198fn get_view_for_ts_call_signature_decl<'a>(inner: &'a swc_ast::TsCallSignatureDecl, bump: &'a Bump) -> &'a TsCallSignatureDecl<'a> {
18199  let node = bump.alloc(TsCallSignatureDecl {
18200    inner,
18201    parent: Default::default(),
18202    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 }),
18203    type_ann: match &inner.type_ann {
18204      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
18205      None => None,
18206    },
18207    type_params: match &inner.type_params {
18208      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
18209      None => None,
18210    },
18211  });
18212  let parent: Node<'a> = (&*node).into();
18213  for value in node.params.iter() {
18214    set_parent_for_ts_fn_param(value, parent)
18215  }
18216  if let Some(value) = &node.type_ann {
18217    set_parent_for_ts_type_ann(value, parent)
18218  };
18219  if let Some(value) = &node.type_params {
18220    set_parent_for_ts_type_param_decl(value, parent)
18221  };
18222  node
18223}
18224
18225fn set_parent_for_ts_call_signature_decl<'a>(node: &TsCallSignatureDecl<'a>, parent: Node<'a>) {
18226  node.parent.set(parent);
18227}
18228
18229#[derive(Clone)]
18230pub struct TsConditionalType<'a> {
18231  parent: ParentOnceCell<Node<'a>>,
18232  pub inner: &'a swc_ast::TsConditionalType,
18233  pub check_type: TsType<'a>,
18234  pub extends_type: TsType<'a>,
18235  pub true_type: TsType<'a>,
18236  pub false_type: TsType<'a>,
18237}
18238
18239impl<'a> TsConditionalType<'a> {
18240  pub fn parent(&self) -> Node<'a> {
18241    self.parent.get().unwrap()
18242  }
18243}
18244
18245impl<'a> SourceRanged for TsConditionalType<'a> {
18246  fn start(&self) -> SourcePos {
18247    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18248  }
18249  fn end(&self) -> SourcePos {
18250    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18251  }
18252}
18253
18254impl<'a> From<&TsConditionalType<'a>> for Node<'a> {
18255  fn from(node: &TsConditionalType<'a>) -> Node<'a> {
18256    let node = unsafe { mem::transmute::<&TsConditionalType<'a>, &'a TsConditionalType<'a>>(node) };
18257    Node::TsConditionalType(node)
18258  }
18259}
18260
18261impl<'a> NodeTrait<'a> for TsConditionalType<'a> {
18262  fn parent(&self) -> Option<Node<'a>> {
18263    Some(self.parent.get().unwrap().clone())
18264  }
18265
18266  fn children(&self) -> Vec<Node<'a>> {
18267    let mut children = Vec::with_capacity(4);
18268    children.push((&self.check_type).into());
18269    children.push((&self.extends_type).into());
18270    children.push((&self.true_type).into());
18271    children.push((&self.false_type).into());
18272    children
18273  }
18274
18275  fn as_node(&self) -> Node<'a> {
18276    self.into()
18277  }
18278
18279  fn kind(&self) -> NodeKind {
18280    NodeKind::TsConditionalType
18281  }
18282}
18283
18284impl<'a> CastableNode<'a> for TsConditionalType<'a> {
18285  fn to(node: &Node<'a>) -> Option<&'a Self> {
18286    if let Node::TsConditionalType(node) = node {
18287      Some(node)
18288    } else {
18289      None
18290    }
18291  }
18292
18293  fn kind() -> NodeKind {
18294    NodeKind::TsConditionalType
18295  }
18296}
18297
18298fn get_view_for_ts_conditional_type<'a>(inner: &'a swc_ast::TsConditionalType, bump: &'a Bump) -> &'a TsConditionalType<'a> {
18299  let node = bump.alloc(TsConditionalType {
18300    inner,
18301    parent: Default::default(),
18302    check_type: get_view_for_ts_type(&inner.check_type, bump),
18303    extends_type: get_view_for_ts_type(&inner.extends_type, bump),
18304    true_type: get_view_for_ts_type(&inner.true_type, bump),
18305    false_type: get_view_for_ts_type(&inner.false_type, bump),
18306  });
18307  let parent: Node<'a> = (&*node).into();
18308  set_parent_for_ts_type(&node.check_type, parent);
18309  set_parent_for_ts_type(&node.extends_type, parent);
18310  set_parent_for_ts_type(&node.true_type, parent);
18311  set_parent_for_ts_type(&node.false_type, parent);
18312  node
18313}
18314
18315fn set_parent_for_ts_conditional_type<'a>(node: &TsConditionalType<'a>, parent: Node<'a>) {
18316  node.parent.set(parent);
18317}
18318
18319#[derive(Clone)]
18320pub struct TsConstAssertion<'a> {
18321  parent: ParentOnceCell<Node<'a>>,
18322  pub inner: &'a swc_ast::TsConstAssertion,
18323  pub expr: Expr<'a>,
18324}
18325
18326impl<'a> TsConstAssertion<'a> {
18327  pub fn parent(&self) -> Node<'a> {
18328    self.parent.get().unwrap()
18329  }
18330}
18331
18332impl<'a> SourceRanged for TsConstAssertion<'a> {
18333  fn start(&self) -> SourcePos {
18334    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18335  }
18336  fn end(&self) -> SourcePos {
18337    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18338  }
18339}
18340
18341impl<'a> From<&TsConstAssertion<'a>> for Node<'a> {
18342  fn from(node: &TsConstAssertion<'a>) -> Node<'a> {
18343    let node = unsafe { mem::transmute::<&TsConstAssertion<'a>, &'a TsConstAssertion<'a>>(node) };
18344    Node::TsConstAssertion(node)
18345  }
18346}
18347
18348impl<'a> NodeTrait<'a> for TsConstAssertion<'a> {
18349  fn parent(&self) -> Option<Node<'a>> {
18350    Some(self.parent.get().unwrap().clone())
18351  }
18352
18353  fn children(&self) -> Vec<Node<'a>> {
18354    let mut children = Vec::with_capacity(1);
18355    children.push((&self.expr).into());
18356    children
18357  }
18358
18359  fn as_node(&self) -> Node<'a> {
18360    self.into()
18361  }
18362
18363  fn kind(&self) -> NodeKind {
18364    NodeKind::TsConstAssertion
18365  }
18366}
18367
18368impl<'a> CastableNode<'a> for TsConstAssertion<'a> {
18369  fn to(node: &Node<'a>) -> Option<&'a Self> {
18370    if let Node::TsConstAssertion(node) = node {
18371      Some(node)
18372    } else {
18373      None
18374    }
18375  }
18376
18377  fn kind() -> NodeKind {
18378    NodeKind::TsConstAssertion
18379  }
18380}
18381
18382fn get_view_for_ts_const_assertion<'a>(inner: &'a swc_ast::TsConstAssertion, bump: &'a Bump) -> &'a TsConstAssertion<'a> {
18383  let node = bump.alloc(TsConstAssertion {
18384    inner,
18385    parent: Default::default(),
18386    expr: get_view_for_expr(&inner.expr, bump),
18387  });
18388  let parent: Node<'a> = (&*node).into();
18389  set_parent_for_expr(&node.expr, parent);
18390  node
18391}
18392
18393fn set_parent_for_ts_const_assertion<'a>(node: &TsConstAssertion<'a>, parent: Node<'a>) {
18394  node.parent.set(parent);
18395}
18396
18397#[derive(Clone)]
18398pub struct TsConstructSignatureDecl<'a> {
18399  parent: ParentOnceCell<Node<'a>>,
18400  pub inner: &'a swc_ast::TsConstructSignatureDecl,
18401  pub params: &'a [TsFnParam<'a>],
18402  pub type_ann: Option<&'a TsTypeAnn<'a>>,
18403  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
18404}
18405
18406impl<'a> TsConstructSignatureDecl<'a> {
18407  pub fn parent(&self) -> Node<'a> {
18408    self.parent.get().unwrap()
18409  }
18410}
18411
18412impl<'a> SourceRanged for TsConstructSignatureDecl<'a> {
18413  fn start(&self) -> SourcePos {
18414    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18415  }
18416  fn end(&self) -> SourcePos {
18417    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18418  }
18419}
18420
18421impl<'a> From<&TsConstructSignatureDecl<'a>> for Node<'a> {
18422  fn from(node: &TsConstructSignatureDecl<'a>) -> Node<'a> {
18423    let node = unsafe { mem::transmute::<&TsConstructSignatureDecl<'a>, &'a TsConstructSignatureDecl<'a>>(node) };
18424    Node::TsConstructSignatureDecl(node)
18425  }
18426}
18427
18428impl<'a> NodeTrait<'a> for TsConstructSignatureDecl<'a> {
18429  fn parent(&self) -> Option<Node<'a>> {
18430    Some(self.parent.get().unwrap().clone())
18431  }
18432
18433  fn children(&self) -> Vec<Node<'a>> {
18434    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, });
18435    for child in self.params.iter() {
18436      children.push(child.into());
18437    }
18438    if let Some(child) = self.type_ann {
18439      children.push(child.into());
18440    }
18441    if let Some(child) = self.type_params {
18442      children.push(child.into());
18443    }
18444    children
18445  }
18446
18447  fn as_node(&self) -> Node<'a> {
18448    self.into()
18449  }
18450
18451  fn kind(&self) -> NodeKind {
18452    NodeKind::TsConstructSignatureDecl
18453  }
18454}
18455
18456impl<'a> CastableNode<'a> for TsConstructSignatureDecl<'a> {
18457  fn to(node: &Node<'a>) -> Option<&'a Self> {
18458    if let Node::TsConstructSignatureDecl(node) = node {
18459      Some(node)
18460    } else {
18461      None
18462    }
18463  }
18464
18465  fn kind() -> NodeKind {
18466    NodeKind::TsConstructSignatureDecl
18467  }
18468}
18469
18470fn get_view_for_ts_construct_signature_decl<'a>(inner: &'a swc_ast::TsConstructSignatureDecl, bump: &'a Bump) -> &'a TsConstructSignatureDecl<'a> {
18471  let node = bump.alloc(TsConstructSignatureDecl {
18472    inner,
18473    parent: Default::default(),
18474    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 }),
18475    type_ann: match &inner.type_ann {
18476      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
18477      None => None,
18478    },
18479    type_params: match &inner.type_params {
18480      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
18481      None => None,
18482    },
18483  });
18484  let parent: Node<'a> = (&*node).into();
18485  for value in node.params.iter() {
18486    set_parent_for_ts_fn_param(value, parent)
18487  }
18488  if let Some(value) = &node.type_ann {
18489    set_parent_for_ts_type_ann(value, parent)
18490  };
18491  if let Some(value) = &node.type_params {
18492    set_parent_for_ts_type_param_decl(value, parent)
18493  };
18494  node
18495}
18496
18497fn set_parent_for_ts_construct_signature_decl<'a>(node: &TsConstructSignatureDecl<'a>, parent: Node<'a>) {
18498  node.parent.set(parent);
18499}
18500
18501#[derive(Clone)]
18502pub struct TsConstructorType<'a> {
18503  parent: ParentOnceCell<Node<'a>>,
18504  pub inner: &'a swc_ast::TsConstructorType,
18505  pub params: &'a [TsFnParam<'a>],
18506  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
18507  pub type_ann: &'a TsTypeAnn<'a>,
18508}
18509
18510impl<'a> TsConstructorType<'a> {
18511  pub fn parent(&self) -> Node<'a> {
18512    self.parent.get().unwrap()
18513  }
18514
18515  pub fn is_abstract(&self) -> bool {
18516    self.inner.is_abstract
18517  }
18518}
18519
18520impl<'a> SourceRanged for TsConstructorType<'a> {
18521  fn start(&self) -> SourcePos {
18522    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18523  }
18524  fn end(&self) -> SourcePos {
18525    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18526  }
18527}
18528
18529impl<'a> From<&TsConstructorType<'a>> for Node<'a> {
18530  fn from(node: &TsConstructorType<'a>) -> Node<'a> {
18531    let node = unsafe { mem::transmute::<&TsConstructorType<'a>, &'a TsConstructorType<'a>>(node) };
18532    Node::TsConstructorType(node)
18533  }
18534}
18535
18536impl<'a> NodeTrait<'a> for TsConstructorType<'a> {
18537  fn parent(&self) -> Option<Node<'a>> {
18538    Some(self.parent.get().unwrap().clone())
18539  }
18540
18541  fn children(&self) -> Vec<Node<'a>> {
18542    let mut children = Vec::with_capacity(1 + self.params.len() + match &self.type_params { Some(_value) => 1, None => 0, });
18543    for child in self.params.iter() {
18544      children.push(child.into());
18545    }
18546    if let Some(child) = self.type_params {
18547      children.push(child.into());
18548    }
18549    children.push(self.type_ann.into());
18550    children
18551  }
18552
18553  fn as_node(&self) -> Node<'a> {
18554    self.into()
18555  }
18556
18557  fn kind(&self) -> NodeKind {
18558    NodeKind::TsConstructorType
18559  }
18560}
18561
18562impl<'a> CastableNode<'a> for TsConstructorType<'a> {
18563  fn to(node: &Node<'a>) -> Option<&'a Self> {
18564    if let Node::TsConstructorType(node) = node {
18565      Some(node)
18566    } else {
18567      None
18568    }
18569  }
18570
18571  fn kind() -> NodeKind {
18572    NodeKind::TsConstructorType
18573  }
18574}
18575
18576fn get_view_for_ts_constructor_type<'a>(inner: &'a swc_ast::TsConstructorType, bump: &'a Bump) -> &'a TsConstructorType<'a> {
18577  let node = bump.alloc(TsConstructorType {
18578    inner,
18579    parent: Default::default(),
18580    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 }),
18581    type_params: match &inner.type_params {
18582      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
18583      None => None,
18584    },
18585    type_ann: get_view_for_ts_type_ann(&inner.type_ann, bump),
18586  });
18587  let parent: Node<'a> = (&*node).into();
18588  for value in node.params.iter() {
18589    set_parent_for_ts_fn_param(value, parent)
18590  }
18591  if let Some(value) = &node.type_params {
18592    set_parent_for_ts_type_param_decl(value, parent)
18593  };
18594  set_parent_for_ts_type_ann(&node.type_ann, parent);
18595  node
18596}
18597
18598fn set_parent_for_ts_constructor_type<'a>(node: &TsConstructorType<'a>, parent: Node<'a>) {
18599  node.parent.set(parent);
18600}
18601
18602#[derive(Clone)]
18603pub struct TsEnumDecl<'a> {
18604  parent: ParentOnceCell<Node<'a>>,
18605  pub inner: &'a swc_ast::TsEnumDecl,
18606  pub id: &'a Ident<'a>,
18607  pub members: &'a [&'a TsEnumMember<'a>],
18608}
18609
18610impl<'a> TsEnumDecl<'a> {
18611  pub fn parent(&self) -> Node<'a> {
18612    self.parent.get().unwrap()
18613  }
18614
18615  pub fn declare(&self) -> bool {
18616    self.inner.declare
18617  }
18618
18619  pub fn is_const(&self) -> bool {
18620    self.inner.is_const
18621  }
18622}
18623
18624impl<'a> SourceRanged for TsEnumDecl<'a> {
18625  fn start(&self) -> SourcePos {
18626    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18627  }
18628  fn end(&self) -> SourcePos {
18629    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18630  }
18631}
18632
18633impl<'a> From<&TsEnumDecl<'a>> for Node<'a> {
18634  fn from(node: &TsEnumDecl<'a>) -> Node<'a> {
18635    let node = unsafe { mem::transmute::<&TsEnumDecl<'a>, &'a TsEnumDecl<'a>>(node) };
18636    Node::TsEnumDecl(node)
18637  }
18638}
18639
18640impl<'a> NodeTrait<'a> for TsEnumDecl<'a> {
18641  fn parent(&self) -> Option<Node<'a>> {
18642    Some(self.parent.get().unwrap().clone())
18643  }
18644
18645  fn children(&self) -> Vec<Node<'a>> {
18646    let mut children = Vec::with_capacity(1 + self.members.len());
18647    children.push(self.id.into());
18648    for child in self.members.iter() {
18649      children.push((*child).into());
18650    }
18651    children
18652  }
18653
18654  fn as_node(&self) -> Node<'a> {
18655    self.into()
18656  }
18657
18658  fn kind(&self) -> NodeKind {
18659    NodeKind::TsEnumDecl
18660  }
18661}
18662
18663impl<'a> CastableNode<'a> for TsEnumDecl<'a> {
18664  fn to(node: &Node<'a>) -> Option<&'a Self> {
18665    if let Node::TsEnumDecl(node) = node {
18666      Some(node)
18667    } else {
18668      None
18669    }
18670  }
18671
18672  fn kind() -> NodeKind {
18673    NodeKind::TsEnumDecl
18674  }
18675}
18676
18677fn get_view_for_ts_enum_decl<'a>(inner: &'a swc_ast::TsEnumDecl, bump: &'a Bump) -> &'a TsEnumDecl<'a> {
18678  let node = bump.alloc(TsEnumDecl {
18679    inner,
18680    parent: Default::default(),
18681    id: get_view_for_ident(&inner.id, bump),
18682    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 }),
18683  });
18684  let parent: Node<'a> = (&*node).into();
18685  set_parent_for_ident(&node.id, parent);
18686  for value in node.members.iter() {
18687    set_parent_for_ts_enum_member(value, parent)
18688  }
18689  node
18690}
18691
18692fn set_parent_for_ts_enum_decl<'a>(node: &TsEnumDecl<'a>, parent: Node<'a>) {
18693  node.parent.set(parent);
18694}
18695
18696#[derive(Clone)]
18697pub struct TsEnumMember<'a> {
18698  parent: ParentOnceCell<&'a TsEnumDecl<'a>>,
18699  pub inner: &'a swc_ast::TsEnumMember,
18700  pub id: TsEnumMemberId<'a>,
18701  pub init: Option<Expr<'a>>,
18702}
18703
18704impl<'a> TsEnumMember<'a> {
18705  pub fn parent(&self) -> &'a TsEnumDecl<'a> {
18706    self.parent.get().unwrap()
18707  }
18708}
18709
18710impl<'a> SourceRanged for TsEnumMember<'a> {
18711  fn start(&self) -> SourcePos {
18712    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18713  }
18714  fn end(&self) -> SourcePos {
18715    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18716  }
18717}
18718
18719impl<'a> From<&TsEnumMember<'a>> for Node<'a> {
18720  fn from(node: &TsEnumMember<'a>) -> Node<'a> {
18721    let node = unsafe { mem::transmute::<&TsEnumMember<'a>, &'a TsEnumMember<'a>>(node) };
18722    Node::TsEnumMember(node)
18723  }
18724}
18725
18726impl<'a> NodeTrait<'a> for TsEnumMember<'a> {
18727  fn parent(&self) -> Option<Node<'a>> {
18728    Some(self.parent.get().unwrap().into())
18729  }
18730
18731  fn children(&self) -> Vec<Node<'a>> {
18732    let mut children = Vec::with_capacity(1 + match &self.init { Some(_value) => 1, None => 0, });
18733    children.push((&self.id).into());
18734    if let Some(child) = self.init.as_ref() {
18735      children.push(child.into());
18736    }
18737    children
18738  }
18739
18740  fn as_node(&self) -> Node<'a> {
18741    self.into()
18742  }
18743
18744  fn kind(&self) -> NodeKind {
18745    NodeKind::TsEnumMember
18746  }
18747}
18748
18749impl<'a> CastableNode<'a> for TsEnumMember<'a> {
18750  fn to(node: &Node<'a>) -> Option<&'a Self> {
18751    if let Node::TsEnumMember(node) = node {
18752      Some(node)
18753    } else {
18754      None
18755    }
18756  }
18757
18758  fn kind() -> NodeKind {
18759    NodeKind::TsEnumMember
18760  }
18761}
18762
18763fn get_view_for_ts_enum_member<'a>(inner: &'a swc_ast::TsEnumMember, bump: &'a Bump) -> &'a TsEnumMember<'a> {
18764  let node = bump.alloc(TsEnumMember {
18765    inner,
18766    parent: Default::default(),
18767    id: get_view_for_ts_enum_member_id(&inner.id, bump),
18768    init: match &inner.init {
18769      Some(value) => Some(get_view_for_expr(value, bump)),
18770      None => None,
18771    },
18772  });
18773  let parent: Node<'a> = (&*node).into();
18774  set_parent_for_ts_enum_member_id(&node.id, parent);
18775  if let Some(value) = &node.init {
18776    set_parent_for_expr(value, parent)
18777  };
18778  node
18779}
18780
18781fn set_parent_for_ts_enum_member<'a>(node: &TsEnumMember<'a>, parent: Node<'a>) {
18782  node.parent.set(parent.expect::<TsEnumDecl>());
18783}
18784
18785/// TypeScript's own parser uses ExportAssignment for both `export default` and
18786/// `export =`. But for @babel/parser, `export default` is an ExportDefaultDecl,
18787/// so a TsExportAssignment is always `export =`.
18788#[derive(Clone)]
18789pub struct TsExportAssignment<'a> {
18790  parent: ParentOnceCell<Node<'a>>,
18791  pub inner: &'a swc_ast::TsExportAssignment,
18792  pub expr: Expr<'a>,
18793}
18794
18795impl<'a> TsExportAssignment<'a> {
18796  pub fn parent(&self) -> Node<'a> {
18797    self.parent.get().unwrap()
18798  }
18799}
18800
18801impl<'a> SourceRanged for TsExportAssignment<'a> {
18802  fn start(&self) -> SourcePos {
18803    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18804  }
18805  fn end(&self) -> SourcePos {
18806    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18807  }
18808}
18809
18810impl<'a> From<&TsExportAssignment<'a>> for Node<'a> {
18811  fn from(node: &TsExportAssignment<'a>) -> Node<'a> {
18812    let node = unsafe { mem::transmute::<&TsExportAssignment<'a>, &'a TsExportAssignment<'a>>(node) };
18813    Node::TsExportAssignment(node)
18814  }
18815}
18816
18817impl<'a> NodeTrait<'a> for TsExportAssignment<'a> {
18818  fn parent(&self) -> Option<Node<'a>> {
18819    Some(self.parent.get().unwrap().clone())
18820  }
18821
18822  fn children(&self) -> Vec<Node<'a>> {
18823    let mut children = Vec::with_capacity(1);
18824    children.push((&self.expr).into());
18825    children
18826  }
18827
18828  fn as_node(&self) -> Node<'a> {
18829    self.into()
18830  }
18831
18832  fn kind(&self) -> NodeKind {
18833    NodeKind::TsExportAssignment
18834  }
18835}
18836
18837impl<'a> CastableNode<'a> for TsExportAssignment<'a> {
18838  fn to(node: &Node<'a>) -> Option<&'a Self> {
18839    if let Node::TsExportAssignment(node) = node {
18840      Some(node)
18841    } else {
18842      None
18843    }
18844  }
18845
18846  fn kind() -> NodeKind {
18847    NodeKind::TsExportAssignment
18848  }
18849}
18850
18851fn get_view_for_ts_export_assignment<'a>(inner: &'a swc_ast::TsExportAssignment, bump: &'a Bump) -> &'a TsExportAssignment<'a> {
18852  let node = bump.alloc(TsExportAssignment {
18853    inner,
18854    parent: Default::default(),
18855    expr: get_view_for_expr(&inner.expr, bump),
18856  });
18857  let parent: Node<'a> = (&*node).into();
18858  set_parent_for_expr(&node.expr, parent);
18859  node
18860}
18861
18862fn set_parent_for_ts_export_assignment<'a>(node: &TsExportAssignment<'a>, parent: Node<'a>) {
18863  node.parent.set(parent);
18864}
18865
18866#[derive(Clone)]
18867pub struct TsExprWithTypeArgs<'a> {
18868  parent: ParentOnceCell<Node<'a>>,
18869  pub inner: &'a swc_ast::TsExprWithTypeArgs,
18870  pub expr: Expr<'a>,
18871  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
18872}
18873
18874impl<'a> TsExprWithTypeArgs<'a> {
18875  pub fn parent(&self) -> Node<'a> {
18876    self.parent.get().unwrap()
18877  }
18878}
18879
18880impl<'a> SourceRanged for TsExprWithTypeArgs<'a> {
18881  fn start(&self) -> SourcePos {
18882    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18883  }
18884  fn end(&self) -> SourcePos {
18885    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18886  }
18887}
18888
18889impl<'a> From<&TsExprWithTypeArgs<'a>> for Node<'a> {
18890  fn from(node: &TsExprWithTypeArgs<'a>) -> Node<'a> {
18891    let node = unsafe { mem::transmute::<&TsExprWithTypeArgs<'a>, &'a TsExprWithTypeArgs<'a>>(node) };
18892    Node::TsExprWithTypeArgs(node)
18893  }
18894}
18895
18896impl<'a> NodeTrait<'a> for TsExprWithTypeArgs<'a> {
18897  fn parent(&self) -> Option<Node<'a>> {
18898    Some(self.parent.get().unwrap().clone())
18899  }
18900
18901  fn children(&self) -> Vec<Node<'a>> {
18902    let mut children = Vec::with_capacity(1 + match &self.type_args { Some(_value) => 1, None => 0, });
18903    children.push((&self.expr).into());
18904    if let Some(child) = self.type_args {
18905      children.push(child.into());
18906    }
18907    children
18908  }
18909
18910  fn as_node(&self) -> Node<'a> {
18911    self.into()
18912  }
18913
18914  fn kind(&self) -> NodeKind {
18915    NodeKind::TsExprWithTypeArgs
18916  }
18917}
18918
18919impl<'a> CastableNode<'a> for TsExprWithTypeArgs<'a> {
18920  fn to(node: &Node<'a>) -> Option<&'a Self> {
18921    if let Node::TsExprWithTypeArgs(node) = node {
18922      Some(node)
18923    } else {
18924      None
18925    }
18926  }
18927
18928  fn kind() -> NodeKind {
18929    NodeKind::TsExprWithTypeArgs
18930  }
18931}
18932
18933fn get_view_for_ts_expr_with_type_args<'a>(inner: &'a swc_ast::TsExprWithTypeArgs, bump: &'a Bump) -> &'a TsExprWithTypeArgs<'a> {
18934  let node = bump.alloc(TsExprWithTypeArgs {
18935    inner,
18936    parent: Default::default(),
18937    expr: get_view_for_expr(&inner.expr, bump),
18938    type_args: match &inner.type_args {
18939      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
18940      None => None,
18941    },
18942  });
18943  let parent: Node<'a> = (&*node).into();
18944  set_parent_for_expr(&node.expr, parent);
18945  if let Some(value) = &node.type_args {
18946    set_parent_for_ts_type_param_instantiation(value, parent)
18947  };
18948  node
18949}
18950
18951fn set_parent_for_ts_expr_with_type_args<'a>(node: &TsExprWithTypeArgs<'a>, parent: Node<'a>) {
18952  node.parent.set(parent);
18953}
18954
18955#[derive(Clone)]
18956pub struct TsExternalModuleRef<'a> {
18957  parent: ParentOnceCell<&'a TsImportEqualsDecl<'a>>,
18958  pub inner: &'a swc_ast::TsExternalModuleRef,
18959  pub expr: &'a Str<'a>,
18960}
18961
18962impl<'a> TsExternalModuleRef<'a> {
18963  pub fn parent(&self) -> &'a TsImportEqualsDecl<'a> {
18964    self.parent.get().unwrap()
18965  }
18966}
18967
18968impl<'a> SourceRanged for TsExternalModuleRef<'a> {
18969  fn start(&self) -> SourcePos {
18970    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
18971  }
18972  fn end(&self) -> SourcePos {
18973    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
18974  }
18975}
18976
18977impl<'a> From<&TsExternalModuleRef<'a>> for Node<'a> {
18978  fn from(node: &TsExternalModuleRef<'a>) -> Node<'a> {
18979    let node = unsafe { mem::transmute::<&TsExternalModuleRef<'a>, &'a TsExternalModuleRef<'a>>(node) };
18980    Node::TsExternalModuleRef(node)
18981  }
18982}
18983
18984impl<'a> NodeTrait<'a> for TsExternalModuleRef<'a> {
18985  fn parent(&self) -> Option<Node<'a>> {
18986    Some(self.parent.get().unwrap().into())
18987  }
18988
18989  fn children(&self) -> Vec<Node<'a>> {
18990    let mut children = Vec::with_capacity(1);
18991    children.push(self.expr.into());
18992    children
18993  }
18994
18995  fn as_node(&self) -> Node<'a> {
18996    self.into()
18997  }
18998
18999  fn kind(&self) -> NodeKind {
19000    NodeKind::TsExternalModuleRef
19001  }
19002}
19003
19004impl<'a> CastableNode<'a> for TsExternalModuleRef<'a> {
19005  fn to(node: &Node<'a>) -> Option<&'a Self> {
19006    if let Node::TsExternalModuleRef(node) = node {
19007      Some(node)
19008    } else {
19009      None
19010    }
19011  }
19012
19013  fn kind() -> NodeKind {
19014    NodeKind::TsExternalModuleRef
19015  }
19016}
19017
19018fn get_view_for_ts_external_module_ref<'a>(inner: &'a swc_ast::TsExternalModuleRef, bump: &'a Bump) -> &'a TsExternalModuleRef<'a> {
19019  let node = bump.alloc(TsExternalModuleRef {
19020    inner,
19021    parent: Default::default(),
19022    expr: get_view_for_str(&inner.expr, bump),
19023  });
19024  let parent: Node<'a> = (&*node).into();
19025  set_parent_for_str(&node.expr, parent);
19026  node
19027}
19028
19029fn set_parent_for_ts_external_module_ref<'a>(node: &TsExternalModuleRef<'a>, parent: Node<'a>) {
19030  node.parent.set(parent.expect::<TsImportEqualsDecl>());
19031}
19032
19033#[derive(Clone)]
19034pub struct TsFnType<'a> {
19035  parent: ParentOnceCell<Node<'a>>,
19036  pub inner: &'a swc_ast::TsFnType,
19037  pub params: &'a [TsFnParam<'a>],
19038  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
19039  pub type_ann: &'a TsTypeAnn<'a>,
19040}
19041
19042impl<'a> TsFnType<'a> {
19043  pub fn parent(&self) -> Node<'a> {
19044    self.parent.get().unwrap()
19045  }
19046}
19047
19048impl<'a> SourceRanged for TsFnType<'a> {
19049  fn start(&self) -> SourcePos {
19050    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19051  }
19052  fn end(&self) -> SourcePos {
19053    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19054  }
19055}
19056
19057impl<'a> From<&TsFnType<'a>> for Node<'a> {
19058  fn from(node: &TsFnType<'a>) -> Node<'a> {
19059    let node = unsafe { mem::transmute::<&TsFnType<'a>, &'a TsFnType<'a>>(node) };
19060    Node::TsFnType(node)
19061  }
19062}
19063
19064impl<'a> NodeTrait<'a> for TsFnType<'a> {
19065  fn parent(&self) -> Option<Node<'a>> {
19066    Some(self.parent.get().unwrap().clone())
19067  }
19068
19069  fn children(&self) -> Vec<Node<'a>> {
19070    let mut children = Vec::with_capacity(1 + self.params.len() + match &self.type_params { Some(_value) => 1, None => 0, });
19071    for child in self.params.iter() {
19072      children.push(child.into());
19073    }
19074    if let Some(child) = self.type_params {
19075      children.push(child.into());
19076    }
19077    children.push(self.type_ann.into());
19078    children
19079  }
19080
19081  fn as_node(&self) -> Node<'a> {
19082    self.into()
19083  }
19084
19085  fn kind(&self) -> NodeKind {
19086    NodeKind::TsFnType
19087  }
19088}
19089
19090impl<'a> CastableNode<'a> for TsFnType<'a> {
19091  fn to(node: &Node<'a>) -> Option<&'a Self> {
19092    if let Node::TsFnType(node) = node {
19093      Some(node)
19094    } else {
19095      None
19096    }
19097  }
19098
19099  fn kind() -> NodeKind {
19100    NodeKind::TsFnType
19101  }
19102}
19103
19104fn get_view_for_ts_fn_type<'a>(inner: &'a swc_ast::TsFnType, bump: &'a Bump) -> &'a TsFnType<'a> {
19105  let node = bump.alloc(TsFnType {
19106    inner,
19107    parent: Default::default(),
19108    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 }),
19109    type_params: match &inner.type_params {
19110      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
19111      None => None,
19112    },
19113    type_ann: get_view_for_ts_type_ann(&inner.type_ann, bump),
19114  });
19115  let parent: Node<'a> = (&*node).into();
19116  for value in node.params.iter() {
19117    set_parent_for_ts_fn_param(value, parent)
19118  }
19119  if let Some(value) = &node.type_params {
19120    set_parent_for_ts_type_param_decl(value, parent)
19121  };
19122  set_parent_for_ts_type_ann(&node.type_ann, parent);
19123  node
19124}
19125
19126fn set_parent_for_ts_fn_type<'a>(node: &TsFnType<'a>, parent: Node<'a>) {
19127  node.parent.set(parent);
19128}
19129
19130#[derive(Clone)]
19131pub struct TsGetterSignature<'a> {
19132  parent: ParentOnceCell<Node<'a>>,
19133  pub inner: &'a swc_ast::TsGetterSignature,
19134  pub key: Expr<'a>,
19135  pub type_ann: Option<&'a TsTypeAnn<'a>>,
19136}
19137
19138impl<'a> TsGetterSignature<'a> {
19139  pub fn parent(&self) -> Node<'a> {
19140    self.parent.get().unwrap()
19141  }
19142
19143  pub fn computed(&self) -> bool {
19144    self.inner.computed
19145  }
19146}
19147
19148impl<'a> SourceRanged for TsGetterSignature<'a> {
19149  fn start(&self) -> SourcePos {
19150    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19151  }
19152  fn end(&self) -> SourcePos {
19153    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19154  }
19155}
19156
19157impl<'a> From<&TsGetterSignature<'a>> for Node<'a> {
19158  fn from(node: &TsGetterSignature<'a>) -> Node<'a> {
19159    let node = unsafe { mem::transmute::<&TsGetterSignature<'a>, &'a TsGetterSignature<'a>>(node) };
19160    Node::TsGetterSignature(node)
19161  }
19162}
19163
19164impl<'a> NodeTrait<'a> for TsGetterSignature<'a> {
19165  fn parent(&self) -> Option<Node<'a>> {
19166    Some(self.parent.get().unwrap().clone())
19167  }
19168
19169  fn children(&self) -> Vec<Node<'a>> {
19170    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
19171    children.push((&self.key).into());
19172    if let Some(child) = self.type_ann {
19173      children.push(child.into());
19174    }
19175    children
19176  }
19177
19178  fn as_node(&self) -> Node<'a> {
19179    self.into()
19180  }
19181
19182  fn kind(&self) -> NodeKind {
19183    NodeKind::TsGetterSignature
19184  }
19185}
19186
19187impl<'a> CastableNode<'a> for TsGetterSignature<'a> {
19188  fn to(node: &Node<'a>) -> Option<&'a Self> {
19189    if let Node::TsGetterSignature(node) = node {
19190      Some(node)
19191    } else {
19192      None
19193    }
19194  }
19195
19196  fn kind() -> NodeKind {
19197    NodeKind::TsGetterSignature
19198  }
19199}
19200
19201fn get_view_for_ts_getter_signature<'a>(inner: &'a swc_ast::TsGetterSignature, bump: &'a Bump) -> &'a TsGetterSignature<'a> {
19202  let node = bump.alloc(TsGetterSignature {
19203    inner,
19204    parent: Default::default(),
19205    key: get_view_for_expr(&inner.key, bump),
19206    type_ann: match &inner.type_ann {
19207      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
19208      None => None,
19209    },
19210  });
19211  let parent: Node<'a> = (&*node).into();
19212  set_parent_for_expr(&node.key, parent);
19213  if let Some(value) = &node.type_ann {
19214    set_parent_for_ts_type_ann(value, parent)
19215  };
19216  node
19217}
19218
19219fn set_parent_for_ts_getter_signature<'a>(node: &TsGetterSignature<'a>, parent: Node<'a>) {
19220  node.parent.set(parent);
19221}
19222
19223#[derive(Clone)]
19224pub struct TsImportCallOptions<'a> {
19225  parent: ParentOnceCell<&'a TsImportType<'a>>,
19226  pub inner: &'a swc_ast::TsImportCallOptions,
19227  pub with: &'a ObjectLit<'a>,
19228}
19229
19230impl<'a> TsImportCallOptions<'a> {
19231  pub fn parent(&self) -> &'a TsImportType<'a> {
19232    self.parent.get().unwrap()
19233  }
19234}
19235
19236impl<'a> SourceRanged for TsImportCallOptions<'a> {
19237  fn start(&self) -> SourcePos {
19238    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19239  }
19240  fn end(&self) -> SourcePos {
19241    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19242  }
19243}
19244
19245impl<'a> From<&TsImportCallOptions<'a>> for Node<'a> {
19246  fn from(node: &TsImportCallOptions<'a>) -> Node<'a> {
19247    let node = unsafe { mem::transmute::<&TsImportCallOptions<'a>, &'a TsImportCallOptions<'a>>(node) };
19248    Node::TsImportCallOptions(node)
19249  }
19250}
19251
19252impl<'a> NodeTrait<'a> for TsImportCallOptions<'a> {
19253  fn parent(&self) -> Option<Node<'a>> {
19254    Some(self.parent.get().unwrap().into())
19255  }
19256
19257  fn children(&self) -> Vec<Node<'a>> {
19258    let mut children = Vec::with_capacity(1);
19259    children.push(self.with.into());
19260    children
19261  }
19262
19263  fn as_node(&self) -> Node<'a> {
19264    self.into()
19265  }
19266
19267  fn kind(&self) -> NodeKind {
19268    NodeKind::TsImportCallOptions
19269  }
19270}
19271
19272impl<'a> CastableNode<'a> for TsImportCallOptions<'a> {
19273  fn to(node: &Node<'a>) -> Option<&'a Self> {
19274    if let Node::TsImportCallOptions(node) = node {
19275      Some(node)
19276    } else {
19277      None
19278    }
19279  }
19280
19281  fn kind() -> NodeKind {
19282    NodeKind::TsImportCallOptions
19283  }
19284}
19285
19286fn get_view_for_ts_import_call_options<'a>(inner: &'a swc_ast::TsImportCallOptions, bump: &'a Bump) -> &'a TsImportCallOptions<'a> {
19287  let node = bump.alloc(TsImportCallOptions {
19288    inner,
19289    parent: Default::default(),
19290    with: get_view_for_object_lit(&inner.with, bump),
19291  });
19292  let parent: Node<'a> = (&*node).into();
19293  set_parent_for_object_lit(&node.with, parent);
19294  node
19295}
19296
19297fn set_parent_for_ts_import_call_options<'a>(node: &TsImportCallOptions<'a>, parent: Node<'a>) {
19298  node.parent.set(parent.expect::<TsImportType>());
19299}
19300
19301#[derive(Clone)]
19302pub struct TsImportEqualsDecl<'a> {
19303  parent: ParentOnceCell<Node<'a>>,
19304  pub inner: &'a swc_ast::TsImportEqualsDecl,
19305  pub id: &'a Ident<'a>,
19306  pub module_ref: TsModuleRef<'a>,
19307}
19308
19309impl<'a> TsImportEqualsDecl<'a> {
19310  pub fn parent(&self) -> Node<'a> {
19311    self.parent.get().unwrap()
19312  }
19313
19314  pub fn is_export(&self) -> bool {
19315    self.inner.is_export
19316  }
19317
19318  pub fn is_type_only(&self) -> bool {
19319    self.inner.is_type_only
19320  }
19321}
19322
19323impl<'a> SourceRanged for TsImportEqualsDecl<'a> {
19324  fn start(&self) -> SourcePos {
19325    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19326  }
19327  fn end(&self) -> SourcePos {
19328    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19329  }
19330}
19331
19332impl<'a> From<&TsImportEqualsDecl<'a>> for Node<'a> {
19333  fn from(node: &TsImportEqualsDecl<'a>) -> Node<'a> {
19334    let node = unsafe { mem::transmute::<&TsImportEqualsDecl<'a>, &'a TsImportEqualsDecl<'a>>(node) };
19335    Node::TsImportEqualsDecl(node)
19336  }
19337}
19338
19339impl<'a> NodeTrait<'a> for TsImportEqualsDecl<'a> {
19340  fn parent(&self) -> Option<Node<'a>> {
19341    Some(self.parent.get().unwrap().clone())
19342  }
19343
19344  fn children(&self) -> Vec<Node<'a>> {
19345    let mut children = Vec::with_capacity(2);
19346    children.push(self.id.into());
19347    children.push((&self.module_ref).into());
19348    children
19349  }
19350
19351  fn as_node(&self) -> Node<'a> {
19352    self.into()
19353  }
19354
19355  fn kind(&self) -> NodeKind {
19356    NodeKind::TsImportEqualsDecl
19357  }
19358}
19359
19360impl<'a> CastableNode<'a> for TsImportEqualsDecl<'a> {
19361  fn to(node: &Node<'a>) -> Option<&'a Self> {
19362    if let Node::TsImportEqualsDecl(node) = node {
19363      Some(node)
19364    } else {
19365      None
19366    }
19367  }
19368
19369  fn kind() -> NodeKind {
19370    NodeKind::TsImportEqualsDecl
19371  }
19372}
19373
19374fn get_view_for_ts_import_equals_decl<'a>(inner: &'a swc_ast::TsImportEqualsDecl, bump: &'a Bump) -> &'a TsImportEqualsDecl<'a> {
19375  let node = bump.alloc(TsImportEqualsDecl {
19376    inner,
19377    parent: Default::default(),
19378    id: get_view_for_ident(&inner.id, bump),
19379    module_ref: get_view_for_ts_module_ref(&inner.module_ref, bump),
19380  });
19381  let parent: Node<'a> = (&*node).into();
19382  set_parent_for_ident(&node.id, parent);
19383  set_parent_for_ts_module_ref(&node.module_ref, parent);
19384  node
19385}
19386
19387fn set_parent_for_ts_import_equals_decl<'a>(node: &TsImportEqualsDecl<'a>, parent: Node<'a>) {
19388  node.parent.set(parent);
19389}
19390
19391#[derive(Clone)]
19392pub struct TsImportType<'a> {
19393  parent: ParentOnceCell<Node<'a>>,
19394  pub inner: &'a swc_ast::TsImportType,
19395  pub arg: &'a Str<'a>,
19396  pub qualifier: Option<TsEntityName<'a>>,
19397  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
19398  pub attributes: Option<&'a TsImportCallOptions<'a>>,
19399}
19400
19401impl<'a> TsImportType<'a> {
19402  pub fn parent(&self) -> Node<'a> {
19403    self.parent.get().unwrap()
19404  }
19405}
19406
19407impl<'a> SourceRanged for TsImportType<'a> {
19408  fn start(&self) -> SourcePos {
19409    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19410  }
19411  fn end(&self) -> SourcePos {
19412    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19413  }
19414}
19415
19416impl<'a> From<&TsImportType<'a>> for Node<'a> {
19417  fn from(node: &TsImportType<'a>) -> Node<'a> {
19418    let node = unsafe { mem::transmute::<&TsImportType<'a>, &'a TsImportType<'a>>(node) };
19419    Node::TsImportType(node)
19420  }
19421}
19422
19423impl<'a> NodeTrait<'a> for TsImportType<'a> {
19424  fn parent(&self) -> Option<Node<'a>> {
19425    Some(self.parent.get().unwrap().clone())
19426  }
19427
19428  fn children(&self) -> Vec<Node<'a>> {
19429    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, });
19430    children.push(self.arg.into());
19431    if let Some(child) = self.qualifier.as_ref() {
19432      children.push(child.into());
19433    }
19434    if let Some(child) = self.type_args {
19435      children.push(child.into());
19436    }
19437    if let Some(child) = self.attributes {
19438      children.push(child.into());
19439    }
19440    children
19441  }
19442
19443  fn as_node(&self) -> Node<'a> {
19444    self.into()
19445  }
19446
19447  fn kind(&self) -> NodeKind {
19448    NodeKind::TsImportType
19449  }
19450}
19451
19452impl<'a> CastableNode<'a> for TsImportType<'a> {
19453  fn to(node: &Node<'a>) -> Option<&'a Self> {
19454    if let Node::TsImportType(node) = node {
19455      Some(node)
19456    } else {
19457      None
19458    }
19459  }
19460
19461  fn kind() -> NodeKind {
19462    NodeKind::TsImportType
19463  }
19464}
19465
19466fn get_view_for_ts_import_type<'a>(inner: &'a swc_ast::TsImportType, bump: &'a Bump) -> &'a TsImportType<'a> {
19467  let node = bump.alloc(TsImportType {
19468    inner,
19469    parent: Default::default(),
19470    arg: get_view_for_str(&inner.arg, bump),
19471    qualifier: match &inner.qualifier {
19472      Some(value) => Some(get_view_for_ts_entity_name(value, bump)),
19473      None => None,
19474    },
19475    type_args: match &inner.type_args {
19476      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
19477      None => None,
19478    },
19479    attributes: match &inner.attributes {
19480      Some(value) => Some(get_view_for_ts_import_call_options(value, bump)),
19481      None => None,
19482    },
19483  });
19484  let parent: Node<'a> = (&*node).into();
19485  set_parent_for_str(&node.arg, parent);
19486  if let Some(value) = &node.qualifier {
19487    set_parent_for_ts_entity_name(value, parent)
19488  };
19489  if let Some(value) = &node.type_args {
19490    set_parent_for_ts_type_param_instantiation(value, parent)
19491  };
19492  if let Some(value) = &node.attributes {
19493    set_parent_for_ts_import_call_options(value, parent)
19494  };
19495  node
19496}
19497
19498fn set_parent_for_ts_import_type<'a>(node: &TsImportType<'a>, parent: Node<'a>) {
19499  node.parent.set(parent);
19500}
19501
19502#[derive(Clone)]
19503pub struct TsIndexSignature<'a> {
19504  parent: ParentOnceCell<Node<'a>>,
19505  pub inner: &'a swc_ast::TsIndexSignature,
19506  pub params: &'a [TsFnParam<'a>],
19507  pub type_ann: Option<&'a TsTypeAnn<'a>>,
19508}
19509
19510impl<'a> TsIndexSignature<'a> {
19511  pub fn parent(&self) -> Node<'a> {
19512    self.parent.get().unwrap()
19513  }
19514
19515  pub fn readonly(&self) -> bool {
19516    self.inner.readonly
19517  }
19518
19519  pub fn is_static(&self) -> bool {
19520    self.inner.is_static
19521  }
19522}
19523
19524impl<'a> SourceRanged for TsIndexSignature<'a> {
19525  fn start(&self) -> SourcePos {
19526    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19527  }
19528  fn end(&self) -> SourcePos {
19529    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19530  }
19531}
19532
19533impl<'a> From<&TsIndexSignature<'a>> for Node<'a> {
19534  fn from(node: &TsIndexSignature<'a>) -> Node<'a> {
19535    let node = unsafe { mem::transmute::<&TsIndexSignature<'a>, &'a TsIndexSignature<'a>>(node) };
19536    Node::TsIndexSignature(node)
19537  }
19538}
19539
19540impl<'a> NodeTrait<'a> for TsIndexSignature<'a> {
19541  fn parent(&self) -> Option<Node<'a>> {
19542    Some(self.parent.get().unwrap().clone())
19543  }
19544
19545  fn children(&self) -> Vec<Node<'a>> {
19546    let mut children = Vec::with_capacity(self.params.len() + match &self.type_ann { Some(_value) => 1, None => 0, });
19547    for child in self.params.iter() {
19548      children.push(child.into());
19549    }
19550    if let Some(child) = self.type_ann {
19551      children.push(child.into());
19552    }
19553    children
19554  }
19555
19556  fn as_node(&self) -> Node<'a> {
19557    self.into()
19558  }
19559
19560  fn kind(&self) -> NodeKind {
19561    NodeKind::TsIndexSignature
19562  }
19563}
19564
19565impl<'a> CastableNode<'a> for TsIndexSignature<'a> {
19566  fn to(node: &Node<'a>) -> Option<&'a Self> {
19567    if let Node::TsIndexSignature(node) = node {
19568      Some(node)
19569    } else {
19570      None
19571    }
19572  }
19573
19574  fn kind() -> NodeKind {
19575    NodeKind::TsIndexSignature
19576  }
19577}
19578
19579fn get_view_for_ts_index_signature<'a>(inner: &'a swc_ast::TsIndexSignature, bump: &'a Bump) -> &'a TsIndexSignature<'a> {
19580  let node = bump.alloc(TsIndexSignature {
19581    inner,
19582    parent: Default::default(),
19583    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 }),
19584    type_ann: match &inner.type_ann {
19585      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
19586      None => None,
19587    },
19588  });
19589  let parent: Node<'a> = (&*node).into();
19590  for value in node.params.iter() {
19591    set_parent_for_ts_fn_param(value, parent)
19592  }
19593  if let Some(value) = &node.type_ann {
19594    set_parent_for_ts_type_ann(value, parent)
19595  };
19596  node
19597}
19598
19599fn set_parent_for_ts_index_signature<'a>(node: &TsIndexSignature<'a>, parent: Node<'a>) {
19600  node.parent.set(parent);
19601}
19602
19603#[derive(Clone)]
19604pub struct TsIndexedAccessType<'a> {
19605  parent: ParentOnceCell<Node<'a>>,
19606  pub inner: &'a swc_ast::TsIndexedAccessType,
19607  pub obj_type: TsType<'a>,
19608  pub index_type: TsType<'a>,
19609}
19610
19611impl<'a> TsIndexedAccessType<'a> {
19612  pub fn parent(&self) -> Node<'a> {
19613    self.parent.get().unwrap()
19614  }
19615
19616  pub fn readonly(&self) -> bool {
19617    self.inner.readonly
19618  }
19619}
19620
19621impl<'a> SourceRanged for TsIndexedAccessType<'a> {
19622  fn start(&self) -> SourcePos {
19623    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19624  }
19625  fn end(&self) -> SourcePos {
19626    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19627  }
19628}
19629
19630impl<'a> From<&TsIndexedAccessType<'a>> for Node<'a> {
19631  fn from(node: &TsIndexedAccessType<'a>) -> Node<'a> {
19632    let node = unsafe { mem::transmute::<&TsIndexedAccessType<'a>, &'a TsIndexedAccessType<'a>>(node) };
19633    Node::TsIndexedAccessType(node)
19634  }
19635}
19636
19637impl<'a> NodeTrait<'a> for TsIndexedAccessType<'a> {
19638  fn parent(&self) -> Option<Node<'a>> {
19639    Some(self.parent.get().unwrap().clone())
19640  }
19641
19642  fn children(&self) -> Vec<Node<'a>> {
19643    let mut children = Vec::with_capacity(2);
19644    children.push((&self.obj_type).into());
19645    children.push((&self.index_type).into());
19646    children
19647  }
19648
19649  fn as_node(&self) -> Node<'a> {
19650    self.into()
19651  }
19652
19653  fn kind(&self) -> NodeKind {
19654    NodeKind::TsIndexedAccessType
19655  }
19656}
19657
19658impl<'a> CastableNode<'a> for TsIndexedAccessType<'a> {
19659  fn to(node: &Node<'a>) -> Option<&'a Self> {
19660    if let Node::TsIndexedAccessType(node) = node {
19661      Some(node)
19662    } else {
19663      None
19664    }
19665  }
19666
19667  fn kind() -> NodeKind {
19668    NodeKind::TsIndexedAccessType
19669  }
19670}
19671
19672fn get_view_for_ts_indexed_access_type<'a>(inner: &'a swc_ast::TsIndexedAccessType, bump: &'a Bump) -> &'a TsIndexedAccessType<'a> {
19673  let node = bump.alloc(TsIndexedAccessType {
19674    inner,
19675    parent: Default::default(),
19676    obj_type: get_view_for_ts_type(&inner.obj_type, bump),
19677    index_type: get_view_for_ts_type(&inner.index_type, bump),
19678  });
19679  let parent: Node<'a> = (&*node).into();
19680  set_parent_for_ts_type(&node.obj_type, parent);
19681  set_parent_for_ts_type(&node.index_type, parent);
19682  node
19683}
19684
19685fn set_parent_for_ts_indexed_access_type<'a>(node: &TsIndexedAccessType<'a>, parent: Node<'a>) {
19686  node.parent.set(parent);
19687}
19688
19689#[derive(Clone)]
19690pub struct TsInferType<'a> {
19691  parent: ParentOnceCell<Node<'a>>,
19692  pub inner: &'a swc_ast::TsInferType,
19693  pub type_param: &'a TsTypeParam<'a>,
19694}
19695
19696impl<'a> TsInferType<'a> {
19697  pub fn parent(&self) -> Node<'a> {
19698    self.parent.get().unwrap()
19699  }
19700}
19701
19702impl<'a> SourceRanged for TsInferType<'a> {
19703  fn start(&self) -> SourcePos {
19704    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19705  }
19706  fn end(&self) -> SourcePos {
19707    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19708  }
19709}
19710
19711impl<'a> From<&TsInferType<'a>> for Node<'a> {
19712  fn from(node: &TsInferType<'a>) -> Node<'a> {
19713    let node = unsafe { mem::transmute::<&TsInferType<'a>, &'a TsInferType<'a>>(node) };
19714    Node::TsInferType(node)
19715  }
19716}
19717
19718impl<'a> NodeTrait<'a> for TsInferType<'a> {
19719  fn parent(&self) -> Option<Node<'a>> {
19720    Some(self.parent.get().unwrap().clone())
19721  }
19722
19723  fn children(&self) -> Vec<Node<'a>> {
19724    let mut children = Vec::with_capacity(1);
19725    children.push(self.type_param.into());
19726    children
19727  }
19728
19729  fn as_node(&self) -> Node<'a> {
19730    self.into()
19731  }
19732
19733  fn kind(&self) -> NodeKind {
19734    NodeKind::TsInferType
19735  }
19736}
19737
19738impl<'a> CastableNode<'a> for TsInferType<'a> {
19739  fn to(node: &Node<'a>) -> Option<&'a Self> {
19740    if let Node::TsInferType(node) = node {
19741      Some(node)
19742    } else {
19743      None
19744    }
19745  }
19746
19747  fn kind() -> NodeKind {
19748    NodeKind::TsInferType
19749  }
19750}
19751
19752fn get_view_for_ts_infer_type<'a>(inner: &'a swc_ast::TsInferType, bump: &'a Bump) -> &'a TsInferType<'a> {
19753  let node = bump.alloc(TsInferType {
19754    inner,
19755    parent: Default::default(),
19756    type_param: get_view_for_ts_type_param(&inner.type_param, bump),
19757  });
19758  let parent: Node<'a> = (&*node).into();
19759  set_parent_for_ts_type_param(&node.type_param, parent);
19760  node
19761}
19762
19763fn set_parent_for_ts_infer_type<'a>(node: &TsInferType<'a>, parent: Node<'a>) {
19764  node.parent.set(parent);
19765}
19766
19767#[derive(Clone)]
19768pub struct TsInstantiation<'a> {
19769  parent: ParentOnceCell<Node<'a>>,
19770  pub inner: &'a swc_ast::TsInstantiation,
19771  pub expr: Expr<'a>,
19772  pub type_args: &'a TsTypeParamInstantiation<'a>,
19773}
19774
19775impl<'a> TsInstantiation<'a> {
19776  pub fn parent(&self) -> Node<'a> {
19777    self.parent.get().unwrap()
19778  }
19779}
19780
19781impl<'a> SourceRanged for TsInstantiation<'a> {
19782  fn start(&self) -> SourcePos {
19783    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19784  }
19785  fn end(&self) -> SourcePos {
19786    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19787  }
19788}
19789
19790impl<'a> From<&TsInstantiation<'a>> for Node<'a> {
19791  fn from(node: &TsInstantiation<'a>) -> Node<'a> {
19792    let node = unsafe { mem::transmute::<&TsInstantiation<'a>, &'a TsInstantiation<'a>>(node) };
19793    Node::TsInstantiation(node)
19794  }
19795}
19796
19797impl<'a> NodeTrait<'a> for TsInstantiation<'a> {
19798  fn parent(&self) -> Option<Node<'a>> {
19799    Some(self.parent.get().unwrap().clone())
19800  }
19801
19802  fn children(&self) -> Vec<Node<'a>> {
19803    let mut children = Vec::with_capacity(2);
19804    children.push((&self.expr).into());
19805    children.push(self.type_args.into());
19806    children
19807  }
19808
19809  fn as_node(&self) -> Node<'a> {
19810    self.into()
19811  }
19812
19813  fn kind(&self) -> NodeKind {
19814    NodeKind::TsInstantiation
19815  }
19816}
19817
19818impl<'a> CastableNode<'a> for TsInstantiation<'a> {
19819  fn to(node: &Node<'a>) -> Option<&'a Self> {
19820    if let Node::TsInstantiation(node) = node {
19821      Some(node)
19822    } else {
19823      None
19824    }
19825  }
19826
19827  fn kind() -> NodeKind {
19828    NodeKind::TsInstantiation
19829  }
19830}
19831
19832fn get_view_for_ts_instantiation<'a>(inner: &'a swc_ast::TsInstantiation, bump: &'a Bump) -> &'a TsInstantiation<'a> {
19833  let node = bump.alloc(TsInstantiation {
19834    inner,
19835    parent: Default::default(),
19836    expr: get_view_for_expr(&inner.expr, bump),
19837    type_args: get_view_for_ts_type_param_instantiation(&inner.type_args, bump),
19838  });
19839  let parent: Node<'a> = (&*node).into();
19840  set_parent_for_expr(&node.expr, parent);
19841  set_parent_for_ts_type_param_instantiation(&node.type_args, parent);
19842  node
19843}
19844
19845fn set_parent_for_ts_instantiation<'a>(node: &TsInstantiation<'a>, parent: Node<'a>) {
19846  node.parent.set(parent);
19847}
19848
19849#[derive(Clone)]
19850pub struct TsInterfaceBody<'a> {
19851  parent: ParentOnceCell<&'a TsInterfaceDecl<'a>>,
19852  pub inner: &'a swc_ast::TsInterfaceBody,
19853  pub body: &'a [TsTypeElement<'a>],
19854}
19855
19856impl<'a> TsInterfaceBody<'a> {
19857  pub fn parent(&self) -> &'a TsInterfaceDecl<'a> {
19858    self.parent.get().unwrap()
19859  }
19860}
19861
19862impl<'a> SourceRanged for TsInterfaceBody<'a> {
19863  fn start(&self) -> SourcePos {
19864    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19865  }
19866  fn end(&self) -> SourcePos {
19867    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19868  }
19869}
19870
19871impl<'a> From<&TsInterfaceBody<'a>> for Node<'a> {
19872  fn from(node: &TsInterfaceBody<'a>) -> Node<'a> {
19873    let node = unsafe { mem::transmute::<&TsInterfaceBody<'a>, &'a TsInterfaceBody<'a>>(node) };
19874    Node::TsInterfaceBody(node)
19875  }
19876}
19877
19878impl<'a> NodeTrait<'a> for TsInterfaceBody<'a> {
19879  fn parent(&self) -> Option<Node<'a>> {
19880    Some(self.parent.get().unwrap().into())
19881  }
19882
19883  fn children(&self) -> Vec<Node<'a>> {
19884    let mut children = Vec::with_capacity(self.body.len());
19885    for child in self.body.iter() {
19886      children.push(child.into());
19887    }
19888    children
19889  }
19890
19891  fn as_node(&self) -> Node<'a> {
19892    self.into()
19893  }
19894
19895  fn kind(&self) -> NodeKind {
19896    NodeKind::TsInterfaceBody
19897  }
19898}
19899
19900impl<'a> CastableNode<'a> for TsInterfaceBody<'a> {
19901  fn to(node: &Node<'a>) -> Option<&'a Self> {
19902    if let Node::TsInterfaceBody(node) = node {
19903      Some(node)
19904    } else {
19905      None
19906    }
19907  }
19908
19909  fn kind() -> NodeKind {
19910    NodeKind::TsInterfaceBody
19911  }
19912}
19913
19914fn get_view_for_ts_interface_body<'a>(inner: &'a swc_ast::TsInterfaceBody, bump: &'a Bump) -> &'a TsInterfaceBody<'a> {
19915  let node = bump.alloc(TsInterfaceBody {
19916    inner,
19917    parent: Default::default(),
19918    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 }),
19919  });
19920  let parent: Node<'a> = (&*node).into();
19921  for value in node.body.iter() {
19922    set_parent_for_ts_type_element(value, parent)
19923  }
19924  node
19925}
19926
19927fn set_parent_for_ts_interface_body<'a>(node: &TsInterfaceBody<'a>, parent: Node<'a>) {
19928  node.parent.set(parent.expect::<TsInterfaceDecl>());
19929}
19930
19931#[derive(Clone)]
19932pub struct TsInterfaceDecl<'a> {
19933  parent: ParentOnceCell<Node<'a>>,
19934  pub inner: &'a swc_ast::TsInterfaceDecl,
19935  pub id: &'a Ident<'a>,
19936  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
19937  pub extends: &'a [&'a TsExprWithTypeArgs<'a>],
19938  pub body: &'a TsInterfaceBody<'a>,
19939}
19940
19941impl<'a> TsInterfaceDecl<'a> {
19942  pub fn parent(&self) -> Node<'a> {
19943    self.parent.get().unwrap()
19944  }
19945
19946  pub fn declare(&self) -> bool {
19947    self.inner.declare
19948  }
19949}
19950
19951impl<'a> SourceRanged for TsInterfaceDecl<'a> {
19952  fn start(&self) -> SourcePos {
19953    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
19954  }
19955  fn end(&self) -> SourcePos {
19956    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
19957  }
19958}
19959
19960impl<'a> From<&TsInterfaceDecl<'a>> for Node<'a> {
19961  fn from(node: &TsInterfaceDecl<'a>) -> Node<'a> {
19962    let node = unsafe { mem::transmute::<&TsInterfaceDecl<'a>, &'a TsInterfaceDecl<'a>>(node) };
19963    Node::TsInterfaceDecl(node)
19964  }
19965}
19966
19967impl<'a> NodeTrait<'a> for TsInterfaceDecl<'a> {
19968  fn parent(&self) -> Option<Node<'a>> {
19969    Some(self.parent.get().unwrap().clone())
19970  }
19971
19972  fn children(&self) -> Vec<Node<'a>> {
19973    let mut children = Vec::with_capacity(2 + match &self.type_params { Some(_value) => 1, None => 0, } + self.extends.len());
19974    children.push(self.id.into());
19975    if let Some(child) = self.type_params {
19976      children.push(child.into());
19977    }
19978    for child in self.extends.iter() {
19979      children.push((*child).into());
19980    }
19981    children.push(self.body.into());
19982    children
19983  }
19984
19985  fn as_node(&self) -> Node<'a> {
19986    self.into()
19987  }
19988
19989  fn kind(&self) -> NodeKind {
19990    NodeKind::TsInterfaceDecl
19991  }
19992}
19993
19994impl<'a> CastableNode<'a> for TsInterfaceDecl<'a> {
19995  fn to(node: &Node<'a>) -> Option<&'a Self> {
19996    if let Node::TsInterfaceDecl(node) = node {
19997      Some(node)
19998    } else {
19999      None
20000    }
20001  }
20002
20003  fn kind() -> NodeKind {
20004    NodeKind::TsInterfaceDecl
20005  }
20006}
20007
20008fn get_view_for_ts_interface_decl<'a>(inner: &'a swc_ast::TsInterfaceDecl, bump: &'a Bump) -> &'a TsInterfaceDecl<'a> {
20009  let node = bump.alloc(TsInterfaceDecl {
20010    inner,
20011    parent: Default::default(),
20012    id: get_view_for_ident(&inner.id, bump),
20013    type_params: match &inner.type_params {
20014      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
20015      None => None,
20016    },
20017    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 }),
20018    body: get_view_for_ts_interface_body(&inner.body, bump),
20019  });
20020  let parent: Node<'a> = (&*node).into();
20021  set_parent_for_ident(&node.id, parent);
20022  if let Some(value) = &node.type_params {
20023    set_parent_for_ts_type_param_decl(value, parent)
20024  };
20025  for value in node.extends.iter() {
20026    set_parent_for_ts_expr_with_type_args(value, parent)
20027  }
20028  set_parent_for_ts_interface_body(&node.body, parent);
20029  node
20030}
20031
20032fn set_parent_for_ts_interface_decl<'a>(node: &TsInterfaceDecl<'a>, parent: Node<'a>) {
20033  node.parent.set(parent);
20034}
20035
20036#[derive(Clone)]
20037pub struct TsIntersectionType<'a> {
20038  parent: ParentOnceCell<Node<'a>>,
20039  pub inner: &'a swc_ast::TsIntersectionType,
20040  pub types: &'a [TsType<'a>],
20041}
20042
20043impl<'a> TsIntersectionType<'a> {
20044  pub fn parent(&self) -> Node<'a> {
20045    self.parent.get().unwrap()
20046  }
20047}
20048
20049impl<'a> SourceRanged for TsIntersectionType<'a> {
20050  fn start(&self) -> SourcePos {
20051    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20052  }
20053  fn end(&self) -> SourcePos {
20054    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20055  }
20056}
20057
20058impl<'a> From<&TsIntersectionType<'a>> for Node<'a> {
20059  fn from(node: &TsIntersectionType<'a>) -> Node<'a> {
20060    let node = unsafe { mem::transmute::<&TsIntersectionType<'a>, &'a TsIntersectionType<'a>>(node) };
20061    Node::TsIntersectionType(node)
20062  }
20063}
20064
20065impl<'a> NodeTrait<'a> for TsIntersectionType<'a> {
20066  fn parent(&self) -> Option<Node<'a>> {
20067    Some(self.parent.get().unwrap().clone())
20068  }
20069
20070  fn children(&self) -> Vec<Node<'a>> {
20071    let mut children = Vec::with_capacity(self.types.len());
20072    for child in self.types.iter() {
20073      children.push(child.into());
20074    }
20075    children
20076  }
20077
20078  fn as_node(&self) -> Node<'a> {
20079    self.into()
20080  }
20081
20082  fn kind(&self) -> NodeKind {
20083    NodeKind::TsIntersectionType
20084  }
20085}
20086
20087impl<'a> CastableNode<'a> for TsIntersectionType<'a> {
20088  fn to(node: &Node<'a>) -> Option<&'a Self> {
20089    if let Node::TsIntersectionType(node) = node {
20090      Some(node)
20091    } else {
20092      None
20093    }
20094  }
20095
20096  fn kind() -> NodeKind {
20097    NodeKind::TsIntersectionType
20098  }
20099}
20100
20101fn get_view_for_ts_intersection_type<'a>(inner: &'a swc_ast::TsIntersectionType, bump: &'a Bump) -> &'a TsIntersectionType<'a> {
20102  let node = bump.alloc(TsIntersectionType {
20103    inner,
20104    parent: Default::default(),
20105    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 }),
20106  });
20107  let parent: Node<'a> = (&*node).into();
20108  for value in node.types.iter() {
20109    set_parent_for_ts_type(value, parent)
20110  }
20111  node
20112}
20113
20114fn set_parent_for_ts_intersection_type<'a>(node: &TsIntersectionType<'a>, parent: Node<'a>) {
20115  node.parent.set(parent);
20116}
20117
20118#[derive(Clone)]
20119pub struct TsKeywordType<'a> {
20120  parent: ParentOnceCell<Node<'a>>,
20121  pub inner: &'a swc_ast::TsKeywordType,
20122}
20123
20124impl<'a> TsKeywordType<'a> {
20125  pub fn parent(&self) -> Node<'a> {
20126    self.parent.get().unwrap()
20127  }
20128
20129  pub fn keyword_kind(&self) -> TsKeywordTypeKind {
20130    self.inner.kind
20131  }
20132}
20133
20134impl<'a> SourceRanged for TsKeywordType<'a> {
20135  fn start(&self) -> SourcePos {
20136    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20137  }
20138  fn end(&self) -> SourcePos {
20139    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20140  }
20141}
20142
20143impl<'a> From<&TsKeywordType<'a>> for Node<'a> {
20144  fn from(node: &TsKeywordType<'a>) -> Node<'a> {
20145    let node = unsafe { mem::transmute::<&TsKeywordType<'a>, &'a TsKeywordType<'a>>(node) };
20146    Node::TsKeywordType(node)
20147  }
20148}
20149
20150impl<'a> NodeTrait<'a> for TsKeywordType<'a> {
20151  fn parent(&self) -> Option<Node<'a>> {
20152    Some(self.parent.get().unwrap().clone())
20153  }
20154
20155  fn children(&self) -> Vec<Node<'a>> {
20156    Vec::with_capacity(0)
20157  }
20158
20159  fn as_node(&self) -> Node<'a> {
20160    self.into()
20161  }
20162
20163  fn kind(&self) -> NodeKind {
20164    NodeKind::TsKeywordType
20165  }
20166}
20167
20168impl<'a> CastableNode<'a> for TsKeywordType<'a> {
20169  fn to(node: &Node<'a>) -> Option<&'a Self> {
20170    if let Node::TsKeywordType(node) = node {
20171      Some(node)
20172    } else {
20173      None
20174    }
20175  }
20176
20177  fn kind() -> NodeKind {
20178    NodeKind::TsKeywordType
20179  }
20180}
20181
20182fn get_view_for_ts_keyword_type<'a>(inner: &'a swc_ast::TsKeywordType, bump: &'a Bump) -> &'a TsKeywordType<'a> {
20183  let node = bump.alloc(TsKeywordType {
20184    inner,
20185    parent: Default::default(),
20186  });
20187  node
20188}
20189
20190fn set_parent_for_ts_keyword_type<'a>(node: &TsKeywordType<'a>, parent: Node<'a>) {
20191  node.parent.set(parent);
20192}
20193
20194#[derive(Clone)]
20195pub struct TsLitType<'a> {
20196  parent: ParentOnceCell<Node<'a>>,
20197  pub inner: &'a swc_ast::TsLitType,
20198  pub lit: TsLit<'a>,
20199}
20200
20201impl<'a> TsLitType<'a> {
20202  pub fn parent(&self) -> Node<'a> {
20203    self.parent.get().unwrap()
20204  }
20205}
20206
20207impl<'a> SourceRanged for TsLitType<'a> {
20208  fn start(&self) -> SourcePos {
20209    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20210  }
20211  fn end(&self) -> SourcePos {
20212    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20213  }
20214}
20215
20216impl<'a> From<&TsLitType<'a>> for Node<'a> {
20217  fn from(node: &TsLitType<'a>) -> Node<'a> {
20218    let node = unsafe { mem::transmute::<&TsLitType<'a>, &'a TsLitType<'a>>(node) };
20219    Node::TsLitType(node)
20220  }
20221}
20222
20223impl<'a> NodeTrait<'a> for TsLitType<'a> {
20224  fn parent(&self) -> Option<Node<'a>> {
20225    Some(self.parent.get().unwrap().clone())
20226  }
20227
20228  fn children(&self) -> Vec<Node<'a>> {
20229    let mut children = Vec::with_capacity(1);
20230    children.push((&self.lit).into());
20231    children
20232  }
20233
20234  fn as_node(&self) -> Node<'a> {
20235    self.into()
20236  }
20237
20238  fn kind(&self) -> NodeKind {
20239    NodeKind::TsLitType
20240  }
20241}
20242
20243impl<'a> CastableNode<'a> for TsLitType<'a> {
20244  fn to(node: &Node<'a>) -> Option<&'a Self> {
20245    if let Node::TsLitType(node) = node {
20246      Some(node)
20247    } else {
20248      None
20249    }
20250  }
20251
20252  fn kind() -> NodeKind {
20253    NodeKind::TsLitType
20254  }
20255}
20256
20257fn get_view_for_ts_lit_type<'a>(inner: &'a swc_ast::TsLitType, bump: &'a Bump) -> &'a TsLitType<'a> {
20258  let node = bump.alloc(TsLitType {
20259    inner,
20260    parent: Default::default(),
20261    lit: get_view_for_ts_lit(&inner.lit, bump),
20262  });
20263  let parent: Node<'a> = (&*node).into();
20264  set_parent_for_ts_lit(&node.lit, parent);
20265  node
20266}
20267
20268fn set_parent_for_ts_lit_type<'a>(node: &TsLitType<'a>, parent: Node<'a>) {
20269  node.parent.set(parent);
20270}
20271
20272#[derive(Clone)]
20273pub struct TsMappedType<'a> {
20274  parent: ParentOnceCell<Node<'a>>,
20275  pub inner: &'a swc_ast::TsMappedType,
20276  pub type_param: &'a TsTypeParam<'a>,
20277  pub name_type: Option<TsType<'a>>,
20278  pub type_ann: Option<TsType<'a>>,
20279}
20280
20281impl<'a> TsMappedType<'a> {
20282  pub fn parent(&self) -> Node<'a> {
20283    self.parent.get().unwrap()
20284  }
20285
20286  pub fn readonly(&self) -> Option<TruePlusMinus> {
20287    self.inner.readonly
20288  }
20289
20290  pub fn optional(&self) -> Option<TruePlusMinus> {
20291    self.inner.optional
20292  }
20293}
20294
20295impl<'a> SourceRanged for TsMappedType<'a> {
20296  fn start(&self) -> SourcePos {
20297    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20298  }
20299  fn end(&self) -> SourcePos {
20300    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20301  }
20302}
20303
20304impl<'a> From<&TsMappedType<'a>> for Node<'a> {
20305  fn from(node: &TsMappedType<'a>) -> Node<'a> {
20306    let node = unsafe { mem::transmute::<&TsMappedType<'a>, &'a TsMappedType<'a>>(node) };
20307    Node::TsMappedType(node)
20308  }
20309}
20310
20311impl<'a> NodeTrait<'a> for TsMappedType<'a> {
20312  fn parent(&self) -> Option<Node<'a>> {
20313    Some(self.parent.get().unwrap().clone())
20314  }
20315
20316  fn children(&self) -> Vec<Node<'a>> {
20317    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, });
20318    children.push(self.type_param.into());
20319    if let Some(child) = self.name_type.as_ref() {
20320      children.push(child.into());
20321    }
20322    if let Some(child) = self.type_ann.as_ref() {
20323      children.push(child.into());
20324    }
20325    children
20326  }
20327
20328  fn as_node(&self) -> Node<'a> {
20329    self.into()
20330  }
20331
20332  fn kind(&self) -> NodeKind {
20333    NodeKind::TsMappedType
20334  }
20335}
20336
20337impl<'a> CastableNode<'a> for TsMappedType<'a> {
20338  fn to(node: &Node<'a>) -> Option<&'a Self> {
20339    if let Node::TsMappedType(node) = node {
20340      Some(node)
20341    } else {
20342      None
20343    }
20344  }
20345
20346  fn kind() -> NodeKind {
20347    NodeKind::TsMappedType
20348  }
20349}
20350
20351fn get_view_for_ts_mapped_type<'a>(inner: &'a swc_ast::TsMappedType, bump: &'a Bump) -> &'a TsMappedType<'a> {
20352  let node = bump.alloc(TsMappedType {
20353    inner,
20354    parent: Default::default(),
20355    type_param: get_view_for_ts_type_param(&inner.type_param, bump),
20356    name_type: match &inner.name_type {
20357      Some(value) => Some(get_view_for_ts_type(value, bump)),
20358      None => None,
20359    },
20360    type_ann: match &inner.type_ann {
20361      Some(value) => Some(get_view_for_ts_type(value, bump)),
20362      None => None,
20363    },
20364  });
20365  let parent: Node<'a> = (&*node).into();
20366  set_parent_for_ts_type_param(&node.type_param, parent);
20367  if let Some(value) = &node.name_type {
20368    set_parent_for_ts_type(value, parent)
20369  };
20370  if let Some(value) = &node.type_ann {
20371    set_parent_for_ts_type(value, parent)
20372  };
20373  node
20374}
20375
20376fn set_parent_for_ts_mapped_type<'a>(node: &TsMappedType<'a>, parent: Node<'a>) {
20377  node.parent.set(parent);
20378}
20379
20380#[derive(Clone)]
20381pub struct TsMethodSignature<'a> {
20382  parent: ParentOnceCell<Node<'a>>,
20383  pub inner: &'a swc_ast::TsMethodSignature,
20384  pub key: Expr<'a>,
20385  pub params: &'a [TsFnParam<'a>],
20386  pub type_ann: Option<&'a TsTypeAnn<'a>>,
20387  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
20388}
20389
20390impl<'a> TsMethodSignature<'a> {
20391  pub fn parent(&self) -> Node<'a> {
20392    self.parent.get().unwrap()
20393  }
20394
20395  pub fn computed(&self) -> bool {
20396    self.inner.computed
20397  }
20398
20399  pub fn optional(&self) -> bool {
20400    self.inner.optional
20401  }
20402}
20403
20404impl<'a> SourceRanged for TsMethodSignature<'a> {
20405  fn start(&self) -> SourcePos {
20406    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20407  }
20408  fn end(&self) -> SourcePos {
20409    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20410  }
20411}
20412
20413impl<'a> From<&TsMethodSignature<'a>> for Node<'a> {
20414  fn from(node: &TsMethodSignature<'a>) -> Node<'a> {
20415    let node = unsafe { mem::transmute::<&TsMethodSignature<'a>, &'a TsMethodSignature<'a>>(node) };
20416    Node::TsMethodSignature(node)
20417  }
20418}
20419
20420impl<'a> NodeTrait<'a> for TsMethodSignature<'a> {
20421  fn parent(&self) -> Option<Node<'a>> {
20422    Some(self.parent.get().unwrap().clone())
20423  }
20424
20425  fn children(&self) -> Vec<Node<'a>> {
20426    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, });
20427    children.push((&self.key).into());
20428    for child in self.params.iter() {
20429      children.push(child.into());
20430    }
20431    if let Some(child) = self.type_ann {
20432      children.push(child.into());
20433    }
20434    if let Some(child) = self.type_params {
20435      children.push(child.into());
20436    }
20437    children
20438  }
20439
20440  fn as_node(&self) -> Node<'a> {
20441    self.into()
20442  }
20443
20444  fn kind(&self) -> NodeKind {
20445    NodeKind::TsMethodSignature
20446  }
20447}
20448
20449impl<'a> CastableNode<'a> for TsMethodSignature<'a> {
20450  fn to(node: &Node<'a>) -> Option<&'a Self> {
20451    if let Node::TsMethodSignature(node) = node {
20452      Some(node)
20453    } else {
20454      None
20455    }
20456  }
20457
20458  fn kind() -> NodeKind {
20459    NodeKind::TsMethodSignature
20460  }
20461}
20462
20463fn get_view_for_ts_method_signature<'a>(inner: &'a swc_ast::TsMethodSignature, bump: &'a Bump) -> &'a TsMethodSignature<'a> {
20464  let node = bump.alloc(TsMethodSignature {
20465    inner,
20466    parent: Default::default(),
20467    key: get_view_for_expr(&inner.key, bump),
20468    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 }),
20469    type_ann: match &inner.type_ann {
20470      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
20471      None => None,
20472    },
20473    type_params: match &inner.type_params {
20474      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
20475      None => None,
20476    },
20477  });
20478  let parent: Node<'a> = (&*node).into();
20479  set_parent_for_expr(&node.key, parent);
20480  for value in node.params.iter() {
20481    set_parent_for_ts_fn_param(value, parent)
20482  }
20483  if let Some(value) = &node.type_ann {
20484    set_parent_for_ts_type_ann(value, parent)
20485  };
20486  if let Some(value) = &node.type_params {
20487    set_parent_for_ts_type_param_decl(value, parent)
20488  };
20489  node
20490}
20491
20492fn set_parent_for_ts_method_signature<'a>(node: &TsMethodSignature<'a>, parent: Node<'a>) {
20493  node.parent.set(parent);
20494}
20495
20496#[derive(Clone)]
20497pub struct TsModuleBlock<'a> {
20498  parent: ParentOnceCell<Node<'a>>,
20499  pub inner: &'a swc_ast::TsModuleBlock,
20500  pub body: &'a [ModuleItem<'a>],
20501}
20502
20503impl<'a> TsModuleBlock<'a> {
20504  pub fn parent(&self) -> Node<'a> {
20505    self.parent.get().unwrap()
20506  }
20507}
20508
20509impl<'a> SourceRanged for TsModuleBlock<'a> {
20510  fn start(&self) -> SourcePos {
20511    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20512  }
20513  fn end(&self) -> SourcePos {
20514    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20515  }
20516}
20517
20518impl<'a> From<&TsModuleBlock<'a>> for Node<'a> {
20519  fn from(node: &TsModuleBlock<'a>) -> Node<'a> {
20520    let node = unsafe { mem::transmute::<&TsModuleBlock<'a>, &'a TsModuleBlock<'a>>(node) };
20521    Node::TsModuleBlock(node)
20522  }
20523}
20524
20525impl<'a> NodeTrait<'a> for TsModuleBlock<'a> {
20526  fn parent(&self) -> Option<Node<'a>> {
20527    Some(self.parent.get().unwrap().clone())
20528  }
20529
20530  fn children(&self) -> Vec<Node<'a>> {
20531    let mut children = Vec::with_capacity(self.body.len());
20532    for child in self.body.iter() {
20533      children.push(child.into());
20534    }
20535    children
20536  }
20537
20538  fn as_node(&self) -> Node<'a> {
20539    self.into()
20540  }
20541
20542  fn kind(&self) -> NodeKind {
20543    NodeKind::TsModuleBlock
20544  }
20545}
20546
20547impl<'a> CastableNode<'a> for TsModuleBlock<'a> {
20548  fn to(node: &Node<'a>) -> Option<&'a Self> {
20549    if let Node::TsModuleBlock(node) = node {
20550      Some(node)
20551    } else {
20552      None
20553    }
20554  }
20555
20556  fn kind() -> NodeKind {
20557    NodeKind::TsModuleBlock
20558  }
20559}
20560
20561fn get_view_for_ts_module_block<'a>(inner: &'a swc_ast::TsModuleBlock, bump: &'a Bump) -> &'a TsModuleBlock<'a> {
20562  let node = bump.alloc(TsModuleBlock {
20563    inner,
20564    parent: Default::default(),
20565    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 }),
20566  });
20567  let parent: Node<'a> = (&*node).into();
20568  for value in node.body.iter() {
20569    set_parent_for_module_item(value, parent)
20570  }
20571  node
20572}
20573
20574fn set_parent_for_ts_module_block<'a>(node: &TsModuleBlock<'a>, parent: Node<'a>) {
20575  node.parent.set(parent);
20576}
20577
20578#[derive(Clone)]
20579pub struct TsModuleDecl<'a> {
20580  parent: ParentOnceCell<Node<'a>>,
20581  pub inner: &'a swc_ast::TsModuleDecl,
20582  pub id: TsModuleName<'a>,
20583  pub body: Option<TsNamespaceBody<'a>>,
20584}
20585
20586impl<'a> TsModuleDecl<'a> {
20587  pub fn parent(&self) -> Node<'a> {
20588    self.parent.get().unwrap()
20589  }
20590
20591  pub fn declare(&self) -> bool {
20592    self.inner.declare
20593  }
20594
20595  /// In TypeScript, this is only available through`node.flags`.
20596  pub fn global(&self) -> bool {
20597    self.inner.global
20598  }
20599
20600  pub fn namespace(&self) -> bool {
20601    self.inner.namespace
20602  }
20603}
20604
20605impl<'a> SourceRanged for TsModuleDecl<'a> {
20606  fn start(&self) -> SourcePos {
20607    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20608  }
20609  fn end(&self) -> SourcePos {
20610    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20611  }
20612}
20613
20614impl<'a> From<&TsModuleDecl<'a>> for Node<'a> {
20615  fn from(node: &TsModuleDecl<'a>) -> Node<'a> {
20616    let node = unsafe { mem::transmute::<&TsModuleDecl<'a>, &'a TsModuleDecl<'a>>(node) };
20617    Node::TsModuleDecl(node)
20618  }
20619}
20620
20621impl<'a> NodeTrait<'a> for TsModuleDecl<'a> {
20622  fn parent(&self) -> Option<Node<'a>> {
20623    Some(self.parent.get().unwrap().clone())
20624  }
20625
20626  fn children(&self) -> Vec<Node<'a>> {
20627    let mut children = Vec::with_capacity(1 + match &self.body { Some(_value) => 1, None => 0, });
20628    children.push((&self.id).into());
20629    if let Some(child) = self.body.as_ref() {
20630      children.push(child.into());
20631    }
20632    children
20633  }
20634
20635  fn as_node(&self) -> Node<'a> {
20636    self.into()
20637  }
20638
20639  fn kind(&self) -> NodeKind {
20640    NodeKind::TsModuleDecl
20641  }
20642}
20643
20644impl<'a> CastableNode<'a> for TsModuleDecl<'a> {
20645  fn to(node: &Node<'a>) -> Option<&'a Self> {
20646    if let Node::TsModuleDecl(node) = node {
20647      Some(node)
20648    } else {
20649      None
20650    }
20651  }
20652
20653  fn kind() -> NodeKind {
20654    NodeKind::TsModuleDecl
20655  }
20656}
20657
20658fn get_view_for_ts_module_decl<'a>(inner: &'a swc_ast::TsModuleDecl, bump: &'a Bump) -> &'a TsModuleDecl<'a> {
20659  let node = bump.alloc(TsModuleDecl {
20660    inner,
20661    parent: Default::default(),
20662    id: get_view_for_ts_module_name(&inner.id, bump),
20663    body: match &inner.body {
20664      Some(value) => Some(get_view_for_ts_namespace_body(value, bump)),
20665      None => None,
20666    },
20667  });
20668  let parent: Node<'a> = (&*node).into();
20669  set_parent_for_ts_module_name(&node.id, parent);
20670  if let Some(value) = &node.body {
20671    set_parent_for_ts_namespace_body(value, parent)
20672  };
20673  node
20674}
20675
20676fn set_parent_for_ts_module_decl<'a>(node: &TsModuleDecl<'a>, parent: Node<'a>) {
20677  node.parent.set(parent);
20678}
20679
20680#[derive(Clone)]
20681pub struct TsNamespaceDecl<'a> {
20682  parent: ParentOnceCell<Node<'a>>,
20683  pub inner: &'a swc_ast::TsNamespaceDecl,
20684  pub id: &'a Ident<'a>,
20685  pub body: TsNamespaceBody<'a>,
20686}
20687
20688impl<'a> TsNamespaceDecl<'a> {
20689  pub fn parent(&self) -> Node<'a> {
20690    self.parent.get().unwrap()
20691  }
20692
20693  pub fn declare(&self) -> bool {
20694    self.inner.declare
20695  }
20696
20697  /// In TypeScript, this is only available through`node.flags`.
20698  pub fn global(&self) -> bool {
20699    self.inner.global
20700  }
20701}
20702
20703impl<'a> SourceRanged for TsNamespaceDecl<'a> {
20704  fn start(&self) -> SourcePos {
20705    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20706  }
20707  fn end(&self) -> SourcePos {
20708    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20709  }
20710}
20711
20712impl<'a> From<&TsNamespaceDecl<'a>> for Node<'a> {
20713  fn from(node: &TsNamespaceDecl<'a>) -> Node<'a> {
20714    let node = unsafe { mem::transmute::<&TsNamespaceDecl<'a>, &'a TsNamespaceDecl<'a>>(node) };
20715    Node::TsNamespaceDecl(node)
20716  }
20717}
20718
20719impl<'a> NodeTrait<'a> for TsNamespaceDecl<'a> {
20720  fn parent(&self) -> Option<Node<'a>> {
20721    Some(self.parent.get().unwrap().clone())
20722  }
20723
20724  fn children(&self) -> Vec<Node<'a>> {
20725    let mut children = Vec::with_capacity(2);
20726    children.push(self.id.into());
20727    children.push((&self.body).into());
20728    children
20729  }
20730
20731  fn as_node(&self) -> Node<'a> {
20732    self.into()
20733  }
20734
20735  fn kind(&self) -> NodeKind {
20736    NodeKind::TsNamespaceDecl
20737  }
20738}
20739
20740impl<'a> CastableNode<'a> for TsNamespaceDecl<'a> {
20741  fn to(node: &Node<'a>) -> Option<&'a Self> {
20742    if let Node::TsNamespaceDecl(node) = node {
20743      Some(node)
20744    } else {
20745      None
20746    }
20747  }
20748
20749  fn kind() -> NodeKind {
20750    NodeKind::TsNamespaceDecl
20751  }
20752}
20753
20754fn get_view_for_ts_namespace_decl<'a>(inner: &'a swc_ast::TsNamespaceDecl, bump: &'a Bump) -> &'a TsNamespaceDecl<'a> {
20755  let node = bump.alloc(TsNamespaceDecl {
20756    inner,
20757    parent: Default::default(),
20758    id: get_view_for_ident(&inner.id, bump),
20759    body: get_view_for_ts_namespace_body(&inner.body, bump),
20760  });
20761  let parent: Node<'a> = (&*node).into();
20762  set_parent_for_ident(&node.id, parent);
20763  set_parent_for_ts_namespace_body(&node.body, parent);
20764  node
20765}
20766
20767fn set_parent_for_ts_namespace_decl<'a>(node: &TsNamespaceDecl<'a>, parent: Node<'a>) {
20768  node.parent.set(parent);
20769}
20770
20771#[derive(Clone)]
20772pub struct TsNamespaceExportDecl<'a> {
20773  parent: ParentOnceCell<Node<'a>>,
20774  pub inner: &'a swc_ast::TsNamespaceExportDecl,
20775  pub id: &'a Ident<'a>,
20776}
20777
20778impl<'a> TsNamespaceExportDecl<'a> {
20779  pub fn parent(&self) -> Node<'a> {
20780    self.parent.get().unwrap()
20781  }
20782}
20783
20784impl<'a> SourceRanged for TsNamespaceExportDecl<'a> {
20785  fn start(&self) -> SourcePos {
20786    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20787  }
20788  fn end(&self) -> SourcePos {
20789    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20790  }
20791}
20792
20793impl<'a> From<&TsNamespaceExportDecl<'a>> for Node<'a> {
20794  fn from(node: &TsNamespaceExportDecl<'a>) -> Node<'a> {
20795    let node = unsafe { mem::transmute::<&TsNamespaceExportDecl<'a>, &'a TsNamespaceExportDecl<'a>>(node) };
20796    Node::TsNamespaceExportDecl(node)
20797  }
20798}
20799
20800impl<'a> NodeTrait<'a> for TsNamespaceExportDecl<'a> {
20801  fn parent(&self) -> Option<Node<'a>> {
20802    Some(self.parent.get().unwrap().clone())
20803  }
20804
20805  fn children(&self) -> Vec<Node<'a>> {
20806    let mut children = Vec::with_capacity(1);
20807    children.push(self.id.into());
20808    children
20809  }
20810
20811  fn as_node(&self) -> Node<'a> {
20812    self.into()
20813  }
20814
20815  fn kind(&self) -> NodeKind {
20816    NodeKind::TsNamespaceExportDecl
20817  }
20818}
20819
20820impl<'a> CastableNode<'a> for TsNamespaceExportDecl<'a> {
20821  fn to(node: &Node<'a>) -> Option<&'a Self> {
20822    if let Node::TsNamespaceExportDecl(node) = node {
20823      Some(node)
20824    } else {
20825      None
20826    }
20827  }
20828
20829  fn kind() -> NodeKind {
20830    NodeKind::TsNamespaceExportDecl
20831  }
20832}
20833
20834fn get_view_for_ts_namespace_export_decl<'a>(inner: &'a swc_ast::TsNamespaceExportDecl, bump: &'a Bump) -> &'a TsNamespaceExportDecl<'a> {
20835  let node = bump.alloc(TsNamespaceExportDecl {
20836    inner,
20837    parent: Default::default(),
20838    id: get_view_for_ident(&inner.id, bump),
20839  });
20840  let parent: Node<'a> = (&*node).into();
20841  set_parent_for_ident(&node.id, parent);
20842  node
20843}
20844
20845fn set_parent_for_ts_namespace_export_decl<'a>(node: &TsNamespaceExportDecl<'a>, parent: Node<'a>) {
20846  node.parent.set(parent);
20847}
20848
20849#[derive(Clone)]
20850pub struct TsNonNullExpr<'a> {
20851  parent: ParentOnceCell<Node<'a>>,
20852  pub inner: &'a swc_ast::TsNonNullExpr,
20853  pub expr: Expr<'a>,
20854}
20855
20856impl<'a> TsNonNullExpr<'a> {
20857  pub fn parent(&self) -> Node<'a> {
20858    self.parent.get().unwrap()
20859  }
20860}
20861
20862impl<'a> SourceRanged for TsNonNullExpr<'a> {
20863  fn start(&self) -> SourcePos {
20864    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20865  }
20866  fn end(&self) -> SourcePos {
20867    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20868  }
20869}
20870
20871impl<'a> From<&TsNonNullExpr<'a>> for Node<'a> {
20872  fn from(node: &TsNonNullExpr<'a>) -> Node<'a> {
20873    let node = unsafe { mem::transmute::<&TsNonNullExpr<'a>, &'a TsNonNullExpr<'a>>(node) };
20874    Node::TsNonNullExpr(node)
20875  }
20876}
20877
20878impl<'a> NodeTrait<'a> for TsNonNullExpr<'a> {
20879  fn parent(&self) -> Option<Node<'a>> {
20880    Some(self.parent.get().unwrap().clone())
20881  }
20882
20883  fn children(&self) -> Vec<Node<'a>> {
20884    let mut children = Vec::with_capacity(1);
20885    children.push((&self.expr).into());
20886    children
20887  }
20888
20889  fn as_node(&self) -> Node<'a> {
20890    self.into()
20891  }
20892
20893  fn kind(&self) -> NodeKind {
20894    NodeKind::TsNonNullExpr
20895  }
20896}
20897
20898impl<'a> CastableNode<'a> for TsNonNullExpr<'a> {
20899  fn to(node: &Node<'a>) -> Option<&'a Self> {
20900    if let Node::TsNonNullExpr(node) = node {
20901      Some(node)
20902    } else {
20903      None
20904    }
20905  }
20906
20907  fn kind() -> NodeKind {
20908    NodeKind::TsNonNullExpr
20909  }
20910}
20911
20912fn get_view_for_ts_non_null_expr<'a>(inner: &'a swc_ast::TsNonNullExpr, bump: &'a Bump) -> &'a TsNonNullExpr<'a> {
20913  let node = bump.alloc(TsNonNullExpr {
20914    inner,
20915    parent: Default::default(),
20916    expr: get_view_for_expr(&inner.expr, bump),
20917  });
20918  let parent: Node<'a> = (&*node).into();
20919  set_parent_for_expr(&node.expr, parent);
20920  node
20921}
20922
20923fn set_parent_for_ts_non_null_expr<'a>(node: &TsNonNullExpr<'a>, parent: Node<'a>) {
20924  node.parent.set(parent);
20925}
20926
20927#[derive(Clone)]
20928pub struct TsOptionalType<'a> {
20929  parent: ParentOnceCell<Node<'a>>,
20930  pub inner: &'a swc_ast::TsOptionalType,
20931  pub type_ann: TsType<'a>,
20932}
20933
20934impl<'a> TsOptionalType<'a> {
20935  pub fn parent(&self) -> Node<'a> {
20936    self.parent.get().unwrap()
20937  }
20938}
20939
20940impl<'a> SourceRanged for TsOptionalType<'a> {
20941  fn start(&self) -> SourcePos {
20942    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
20943  }
20944  fn end(&self) -> SourcePos {
20945    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
20946  }
20947}
20948
20949impl<'a> From<&TsOptionalType<'a>> for Node<'a> {
20950  fn from(node: &TsOptionalType<'a>) -> Node<'a> {
20951    let node = unsafe { mem::transmute::<&TsOptionalType<'a>, &'a TsOptionalType<'a>>(node) };
20952    Node::TsOptionalType(node)
20953  }
20954}
20955
20956impl<'a> NodeTrait<'a> for TsOptionalType<'a> {
20957  fn parent(&self) -> Option<Node<'a>> {
20958    Some(self.parent.get().unwrap().clone())
20959  }
20960
20961  fn children(&self) -> Vec<Node<'a>> {
20962    let mut children = Vec::with_capacity(1);
20963    children.push((&self.type_ann).into());
20964    children
20965  }
20966
20967  fn as_node(&self) -> Node<'a> {
20968    self.into()
20969  }
20970
20971  fn kind(&self) -> NodeKind {
20972    NodeKind::TsOptionalType
20973  }
20974}
20975
20976impl<'a> CastableNode<'a> for TsOptionalType<'a> {
20977  fn to(node: &Node<'a>) -> Option<&'a Self> {
20978    if let Node::TsOptionalType(node) = node {
20979      Some(node)
20980    } else {
20981      None
20982    }
20983  }
20984
20985  fn kind() -> NodeKind {
20986    NodeKind::TsOptionalType
20987  }
20988}
20989
20990fn get_view_for_ts_optional_type<'a>(inner: &'a swc_ast::TsOptionalType, bump: &'a Bump) -> &'a TsOptionalType<'a> {
20991  let node = bump.alloc(TsOptionalType {
20992    inner,
20993    parent: Default::default(),
20994    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
20995  });
20996  let parent: Node<'a> = (&*node).into();
20997  set_parent_for_ts_type(&node.type_ann, parent);
20998  node
20999}
21000
21001fn set_parent_for_ts_optional_type<'a>(node: &TsOptionalType<'a>, parent: Node<'a>) {
21002  node.parent.set(parent);
21003}
21004
21005#[derive(Clone)]
21006pub struct TsParamProp<'a> {
21007  parent: ParentOnceCell<&'a Constructor<'a>>,
21008  pub inner: &'a swc_ast::TsParamProp,
21009  pub decorators: &'a [&'a Decorator<'a>],
21010  pub param: TsParamPropParam<'a>,
21011}
21012
21013impl<'a> TsParamProp<'a> {
21014  pub fn parent(&self) -> &'a Constructor<'a> {
21015    self.parent.get().unwrap()
21016  }
21017
21018  /// At least one of `accessibility` or `readonly` must be set.
21019  pub fn accessibility(&self) -> Option<Accessibility> {
21020    self.inner.accessibility
21021  }
21022
21023  pub fn is_override(&self) -> bool {
21024    self.inner.is_override
21025  }
21026
21027  pub fn readonly(&self) -> bool {
21028    self.inner.readonly
21029  }
21030}
21031
21032impl<'a> SourceRanged for TsParamProp<'a> {
21033  fn start(&self) -> SourcePos {
21034    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21035  }
21036  fn end(&self) -> SourcePos {
21037    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21038  }
21039}
21040
21041impl<'a> From<&TsParamProp<'a>> for Node<'a> {
21042  fn from(node: &TsParamProp<'a>) -> Node<'a> {
21043    let node = unsafe { mem::transmute::<&TsParamProp<'a>, &'a TsParamProp<'a>>(node) };
21044    Node::TsParamProp(node)
21045  }
21046}
21047
21048impl<'a> NodeTrait<'a> for TsParamProp<'a> {
21049  fn parent(&self) -> Option<Node<'a>> {
21050    Some(self.parent.get().unwrap().into())
21051  }
21052
21053  fn children(&self) -> Vec<Node<'a>> {
21054    let mut children = Vec::with_capacity(1 + self.decorators.len());
21055    for child in self.decorators.iter() {
21056      children.push((*child).into());
21057    }
21058    children.push((&self.param).into());
21059    children
21060  }
21061
21062  fn as_node(&self) -> Node<'a> {
21063    self.into()
21064  }
21065
21066  fn kind(&self) -> NodeKind {
21067    NodeKind::TsParamProp
21068  }
21069}
21070
21071impl<'a> CastableNode<'a> for TsParamProp<'a> {
21072  fn to(node: &Node<'a>) -> Option<&'a Self> {
21073    if let Node::TsParamProp(node) = node {
21074      Some(node)
21075    } else {
21076      None
21077    }
21078  }
21079
21080  fn kind() -> NodeKind {
21081    NodeKind::TsParamProp
21082  }
21083}
21084
21085fn get_view_for_ts_param_prop<'a>(inner: &'a swc_ast::TsParamProp, bump: &'a Bump) -> &'a TsParamProp<'a> {
21086  let node = bump.alloc(TsParamProp {
21087    inner,
21088    parent: Default::default(),
21089    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 }),
21090    param: get_view_for_ts_param_prop_param(&inner.param, bump),
21091  });
21092  let parent: Node<'a> = (&*node).into();
21093  for value in node.decorators.iter() {
21094    set_parent_for_decorator(value, parent)
21095  }
21096  set_parent_for_ts_param_prop_param(&node.param, parent);
21097  node
21098}
21099
21100fn set_parent_for_ts_param_prop<'a>(node: &TsParamProp<'a>, parent: Node<'a>) {
21101  node.parent.set(parent.expect::<Constructor>());
21102}
21103
21104#[derive(Clone)]
21105pub struct TsParenthesizedType<'a> {
21106  parent: ParentOnceCell<Node<'a>>,
21107  pub inner: &'a swc_ast::TsParenthesizedType,
21108  pub type_ann: TsType<'a>,
21109}
21110
21111impl<'a> TsParenthesizedType<'a> {
21112  pub fn parent(&self) -> Node<'a> {
21113    self.parent.get().unwrap()
21114  }
21115}
21116
21117impl<'a> SourceRanged for TsParenthesizedType<'a> {
21118  fn start(&self) -> SourcePos {
21119    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21120  }
21121  fn end(&self) -> SourcePos {
21122    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21123  }
21124}
21125
21126impl<'a> From<&TsParenthesizedType<'a>> for Node<'a> {
21127  fn from(node: &TsParenthesizedType<'a>) -> Node<'a> {
21128    let node = unsafe { mem::transmute::<&TsParenthesizedType<'a>, &'a TsParenthesizedType<'a>>(node) };
21129    Node::TsParenthesizedType(node)
21130  }
21131}
21132
21133impl<'a> NodeTrait<'a> for TsParenthesizedType<'a> {
21134  fn parent(&self) -> Option<Node<'a>> {
21135    Some(self.parent.get().unwrap().clone())
21136  }
21137
21138  fn children(&self) -> Vec<Node<'a>> {
21139    let mut children = Vec::with_capacity(1);
21140    children.push((&self.type_ann).into());
21141    children
21142  }
21143
21144  fn as_node(&self) -> Node<'a> {
21145    self.into()
21146  }
21147
21148  fn kind(&self) -> NodeKind {
21149    NodeKind::TsParenthesizedType
21150  }
21151}
21152
21153impl<'a> CastableNode<'a> for TsParenthesizedType<'a> {
21154  fn to(node: &Node<'a>) -> Option<&'a Self> {
21155    if let Node::TsParenthesizedType(node) = node {
21156      Some(node)
21157    } else {
21158      None
21159    }
21160  }
21161
21162  fn kind() -> NodeKind {
21163    NodeKind::TsParenthesizedType
21164  }
21165}
21166
21167fn get_view_for_ts_parenthesized_type<'a>(inner: &'a swc_ast::TsParenthesizedType, bump: &'a Bump) -> &'a TsParenthesizedType<'a> {
21168  let node = bump.alloc(TsParenthesizedType {
21169    inner,
21170    parent: Default::default(),
21171    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
21172  });
21173  let parent: Node<'a> = (&*node).into();
21174  set_parent_for_ts_type(&node.type_ann, parent);
21175  node
21176}
21177
21178fn set_parent_for_ts_parenthesized_type<'a>(node: &TsParenthesizedType<'a>, parent: Node<'a>) {
21179  node.parent.set(parent);
21180}
21181
21182#[derive(Clone)]
21183pub struct TsPropertySignature<'a> {
21184  parent: ParentOnceCell<Node<'a>>,
21185  pub inner: &'a swc_ast::TsPropertySignature,
21186  pub key: Expr<'a>,
21187  pub type_ann: Option<&'a TsTypeAnn<'a>>,
21188}
21189
21190impl<'a> TsPropertySignature<'a> {
21191  pub fn parent(&self) -> Node<'a> {
21192    self.parent.get().unwrap()
21193  }
21194
21195  pub fn readonly(&self) -> bool {
21196    self.inner.readonly
21197  }
21198
21199  pub fn computed(&self) -> bool {
21200    self.inner.computed
21201  }
21202
21203  pub fn optional(&self) -> bool {
21204    self.inner.optional
21205  }
21206}
21207
21208impl<'a> SourceRanged for TsPropertySignature<'a> {
21209  fn start(&self) -> SourcePos {
21210    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21211  }
21212  fn end(&self) -> SourcePos {
21213    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21214  }
21215}
21216
21217impl<'a> From<&TsPropertySignature<'a>> for Node<'a> {
21218  fn from(node: &TsPropertySignature<'a>) -> Node<'a> {
21219    let node = unsafe { mem::transmute::<&TsPropertySignature<'a>, &'a TsPropertySignature<'a>>(node) };
21220    Node::TsPropertySignature(node)
21221  }
21222}
21223
21224impl<'a> NodeTrait<'a> for TsPropertySignature<'a> {
21225  fn parent(&self) -> Option<Node<'a>> {
21226    Some(self.parent.get().unwrap().clone())
21227  }
21228
21229  fn children(&self) -> Vec<Node<'a>> {
21230    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
21231    children.push((&self.key).into());
21232    if let Some(child) = self.type_ann {
21233      children.push(child.into());
21234    }
21235    children
21236  }
21237
21238  fn as_node(&self) -> Node<'a> {
21239    self.into()
21240  }
21241
21242  fn kind(&self) -> NodeKind {
21243    NodeKind::TsPropertySignature
21244  }
21245}
21246
21247impl<'a> CastableNode<'a> for TsPropertySignature<'a> {
21248  fn to(node: &Node<'a>) -> Option<&'a Self> {
21249    if let Node::TsPropertySignature(node) = node {
21250      Some(node)
21251    } else {
21252      None
21253    }
21254  }
21255
21256  fn kind() -> NodeKind {
21257    NodeKind::TsPropertySignature
21258  }
21259}
21260
21261fn get_view_for_ts_property_signature<'a>(inner: &'a swc_ast::TsPropertySignature, bump: &'a Bump) -> &'a TsPropertySignature<'a> {
21262  let node = bump.alloc(TsPropertySignature {
21263    inner,
21264    parent: Default::default(),
21265    key: get_view_for_expr(&inner.key, bump),
21266    type_ann: match &inner.type_ann {
21267      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
21268      None => None,
21269    },
21270  });
21271  let parent: Node<'a> = (&*node).into();
21272  set_parent_for_expr(&node.key, parent);
21273  if let Some(value) = &node.type_ann {
21274    set_parent_for_ts_type_ann(value, parent)
21275  };
21276  node
21277}
21278
21279fn set_parent_for_ts_property_signature<'a>(node: &TsPropertySignature<'a>, parent: Node<'a>) {
21280  node.parent.set(parent);
21281}
21282
21283#[derive(Clone)]
21284pub struct TsQualifiedName<'a> {
21285  parent: ParentOnceCell<Node<'a>>,
21286  pub inner: &'a swc_ast::TsQualifiedName,
21287  pub left: TsEntityName<'a>,
21288  pub right: &'a IdentName<'a>,
21289}
21290
21291impl<'a> TsQualifiedName<'a> {
21292  pub fn parent(&self) -> Node<'a> {
21293    self.parent.get().unwrap()
21294  }
21295}
21296
21297impl<'a> SourceRanged for TsQualifiedName<'a> {
21298  fn start(&self) -> SourcePos {
21299    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21300  }
21301  fn end(&self) -> SourcePos {
21302    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21303  }
21304}
21305
21306impl<'a> From<&TsQualifiedName<'a>> for Node<'a> {
21307  fn from(node: &TsQualifiedName<'a>) -> Node<'a> {
21308    let node = unsafe { mem::transmute::<&TsQualifiedName<'a>, &'a TsQualifiedName<'a>>(node) };
21309    Node::TsQualifiedName(node)
21310  }
21311}
21312
21313impl<'a> NodeTrait<'a> for TsQualifiedName<'a> {
21314  fn parent(&self) -> Option<Node<'a>> {
21315    Some(self.parent.get().unwrap().clone())
21316  }
21317
21318  fn children(&self) -> Vec<Node<'a>> {
21319    let mut children = Vec::with_capacity(2);
21320    children.push((&self.left).into());
21321    children.push(self.right.into());
21322    children
21323  }
21324
21325  fn as_node(&self) -> Node<'a> {
21326    self.into()
21327  }
21328
21329  fn kind(&self) -> NodeKind {
21330    NodeKind::TsQualifiedName
21331  }
21332}
21333
21334impl<'a> CastableNode<'a> for TsQualifiedName<'a> {
21335  fn to(node: &Node<'a>) -> Option<&'a Self> {
21336    if let Node::TsQualifiedName(node) = node {
21337      Some(node)
21338    } else {
21339      None
21340    }
21341  }
21342
21343  fn kind() -> NodeKind {
21344    NodeKind::TsQualifiedName
21345  }
21346}
21347
21348fn get_view_for_ts_qualified_name<'a>(inner: &'a swc_ast::TsQualifiedName, bump: &'a Bump) -> &'a TsQualifiedName<'a> {
21349  let node = bump.alloc(TsQualifiedName {
21350    inner,
21351    parent: Default::default(),
21352    left: get_view_for_ts_entity_name(&inner.left, bump),
21353    right: get_view_for_ident_name(&inner.right, bump),
21354  });
21355  let parent: Node<'a> = (&*node).into();
21356  set_parent_for_ts_entity_name(&node.left, parent);
21357  set_parent_for_ident_name(&node.right, parent);
21358  node
21359}
21360
21361fn set_parent_for_ts_qualified_name<'a>(node: &TsQualifiedName<'a>, parent: Node<'a>) {
21362  node.parent.set(parent);
21363}
21364
21365#[derive(Clone)]
21366pub struct TsRestType<'a> {
21367  parent: ParentOnceCell<Node<'a>>,
21368  pub inner: &'a swc_ast::TsRestType,
21369  pub type_ann: TsType<'a>,
21370}
21371
21372impl<'a> TsRestType<'a> {
21373  pub fn parent(&self) -> Node<'a> {
21374    self.parent.get().unwrap()
21375  }
21376}
21377
21378impl<'a> SourceRanged for TsRestType<'a> {
21379  fn start(&self) -> SourcePos {
21380    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21381  }
21382  fn end(&self) -> SourcePos {
21383    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21384  }
21385}
21386
21387impl<'a> From<&TsRestType<'a>> for Node<'a> {
21388  fn from(node: &TsRestType<'a>) -> Node<'a> {
21389    let node = unsafe { mem::transmute::<&TsRestType<'a>, &'a TsRestType<'a>>(node) };
21390    Node::TsRestType(node)
21391  }
21392}
21393
21394impl<'a> NodeTrait<'a> for TsRestType<'a> {
21395  fn parent(&self) -> Option<Node<'a>> {
21396    Some(self.parent.get().unwrap().clone())
21397  }
21398
21399  fn children(&self) -> Vec<Node<'a>> {
21400    let mut children = Vec::with_capacity(1);
21401    children.push((&self.type_ann).into());
21402    children
21403  }
21404
21405  fn as_node(&self) -> Node<'a> {
21406    self.into()
21407  }
21408
21409  fn kind(&self) -> NodeKind {
21410    NodeKind::TsRestType
21411  }
21412}
21413
21414impl<'a> CastableNode<'a> for TsRestType<'a> {
21415  fn to(node: &Node<'a>) -> Option<&'a Self> {
21416    if let Node::TsRestType(node) = node {
21417      Some(node)
21418    } else {
21419      None
21420    }
21421  }
21422
21423  fn kind() -> NodeKind {
21424    NodeKind::TsRestType
21425  }
21426}
21427
21428fn get_view_for_ts_rest_type<'a>(inner: &'a swc_ast::TsRestType, bump: &'a Bump) -> &'a TsRestType<'a> {
21429  let node = bump.alloc(TsRestType {
21430    inner,
21431    parent: Default::default(),
21432    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
21433  });
21434  let parent: Node<'a> = (&*node).into();
21435  set_parent_for_ts_type(&node.type_ann, parent);
21436  node
21437}
21438
21439fn set_parent_for_ts_rest_type<'a>(node: &TsRestType<'a>, parent: Node<'a>) {
21440  node.parent.set(parent);
21441}
21442
21443#[derive(Clone)]
21444pub struct TsSatisfiesExpr<'a> {
21445  parent: ParentOnceCell<Node<'a>>,
21446  pub inner: &'a swc_ast::TsSatisfiesExpr,
21447  pub expr: Expr<'a>,
21448  pub type_ann: TsType<'a>,
21449}
21450
21451impl<'a> TsSatisfiesExpr<'a> {
21452  pub fn parent(&self) -> Node<'a> {
21453    self.parent.get().unwrap()
21454  }
21455}
21456
21457impl<'a> SourceRanged for TsSatisfiesExpr<'a> {
21458  fn start(&self) -> SourcePos {
21459    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21460  }
21461  fn end(&self) -> SourcePos {
21462    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21463  }
21464}
21465
21466impl<'a> From<&TsSatisfiesExpr<'a>> for Node<'a> {
21467  fn from(node: &TsSatisfiesExpr<'a>) -> Node<'a> {
21468    let node = unsafe { mem::transmute::<&TsSatisfiesExpr<'a>, &'a TsSatisfiesExpr<'a>>(node) };
21469    Node::TsSatisfiesExpr(node)
21470  }
21471}
21472
21473impl<'a> NodeTrait<'a> for TsSatisfiesExpr<'a> {
21474  fn parent(&self) -> Option<Node<'a>> {
21475    Some(self.parent.get().unwrap().clone())
21476  }
21477
21478  fn children(&self) -> Vec<Node<'a>> {
21479    let mut children = Vec::with_capacity(2);
21480    children.push((&self.expr).into());
21481    children.push((&self.type_ann).into());
21482    children
21483  }
21484
21485  fn as_node(&self) -> Node<'a> {
21486    self.into()
21487  }
21488
21489  fn kind(&self) -> NodeKind {
21490    NodeKind::TsSatisfiesExpr
21491  }
21492}
21493
21494impl<'a> CastableNode<'a> for TsSatisfiesExpr<'a> {
21495  fn to(node: &Node<'a>) -> Option<&'a Self> {
21496    if let Node::TsSatisfiesExpr(node) = node {
21497      Some(node)
21498    } else {
21499      None
21500    }
21501  }
21502
21503  fn kind() -> NodeKind {
21504    NodeKind::TsSatisfiesExpr
21505  }
21506}
21507
21508fn get_view_for_ts_satisfies_expr<'a>(inner: &'a swc_ast::TsSatisfiesExpr, bump: &'a Bump) -> &'a TsSatisfiesExpr<'a> {
21509  let node = bump.alloc(TsSatisfiesExpr {
21510    inner,
21511    parent: Default::default(),
21512    expr: get_view_for_expr(&inner.expr, bump),
21513    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
21514  });
21515  let parent: Node<'a> = (&*node).into();
21516  set_parent_for_expr(&node.expr, parent);
21517  set_parent_for_ts_type(&node.type_ann, parent);
21518  node
21519}
21520
21521fn set_parent_for_ts_satisfies_expr<'a>(node: &TsSatisfiesExpr<'a>, parent: Node<'a>) {
21522  node.parent.set(parent);
21523}
21524
21525#[derive(Clone)]
21526pub struct TsSetterSignature<'a> {
21527  parent: ParentOnceCell<Node<'a>>,
21528  pub inner: &'a swc_ast::TsSetterSignature,
21529  pub key: Expr<'a>,
21530  pub param: TsFnParam<'a>,
21531}
21532
21533impl<'a> TsSetterSignature<'a> {
21534  pub fn parent(&self) -> Node<'a> {
21535    self.parent.get().unwrap()
21536  }
21537
21538  pub fn computed(&self) -> bool {
21539    self.inner.computed
21540  }
21541}
21542
21543impl<'a> SourceRanged for TsSetterSignature<'a> {
21544  fn start(&self) -> SourcePos {
21545    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21546  }
21547  fn end(&self) -> SourcePos {
21548    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21549  }
21550}
21551
21552impl<'a> From<&TsSetterSignature<'a>> for Node<'a> {
21553  fn from(node: &TsSetterSignature<'a>) -> Node<'a> {
21554    let node = unsafe { mem::transmute::<&TsSetterSignature<'a>, &'a TsSetterSignature<'a>>(node) };
21555    Node::TsSetterSignature(node)
21556  }
21557}
21558
21559impl<'a> NodeTrait<'a> for TsSetterSignature<'a> {
21560  fn parent(&self) -> Option<Node<'a>> {
21561    Some(self.parent.get().unwrap().clone())
21562  }
21563
21564  fn children(&self) -> Vec<Node<'a>> {
21565    let mut children = Vec::with_capacity(2);
21566    children.push((&self.key).into());
21567    children.push((&self.param).into());
21568    children
21569  }
21570
21571  fn as_node(&self) -> Node<'a> {
21572    self.into()
21573  }
21574
21575  fn kind(&self) -> NodeKind {
21576    NodeKind::TsSetterSignature
21577  }
21578}
21579
21580impl<'a> CastableNode<'a> for TsSetterSignature<'a> {
21581  fn to(node: &Node<'a>) -> Option<&'a Self> {
21582    if let Node::TsSetterSignature(node) = node {
21583      Some(node)
21584    } else {
21585      None
21586    }
21587  }
21588
21589  fn kind() -> NodeKind {
21590    NodeKind::TsSetterSignature
21591  }
21592}
21593
21594fn get_view_for_ts_setter_signature<'a>(inner: &'a swc_ast::TsSetterSignature, bump: &'a Bump) -> &'a TsSetterSignature<'a> {
21595  let node = bump.alloc(TsSetterSignature {
21596    inner,
21597    parent: Default::default(),
21598    key: get_view_for_expr(&inner.key, bump),
21599    param: get_view_for_ts_fn_param(&inner.param, bump),
21600  });
21601  let parent: Node<'a> = (&*node).into();
21602  set_parent_for_expr(&node.key, parent);
21603  set_parent_for_ts_fn_param(&node.param, parent);
21604  node
21605}
21606
21607fn set_parent_for_ts_setter_signature<'a>(node: &TsSetterSignature<'a>, parent: Node<'a>) {
21608  node.parent.set(parent);
21609}
21610
21611#[derive(Clone)]
21612pub struct TsThisType<'a> {
21613  parent: ParentOnceCell<Node<'a>>,
21614  pub inner: &'a swc_ast::TsThisType,
21615}
21616
21617impl<'a> TsThisType<'a> {
21618  pub fn parent(&self) -> Node<'a> {
21619    self.parent.get().unwrap()
21620  }
21621}
21622
21623impl<'a> SourceRanged for TsThisType<'a> {
21624  fn start(&self) -> SourcePos {
21625    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21626  }
21627  fn end(&self) -> SourcePos {
21628    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21629  }
21630}
21631
21632impl<'a> From<&TsThisType<'a>> for Node<'a> {
21633  fn from(node: &TsThisType<'a>) -> Node<'a> {
21634    let node = unsafe { mem::transmute::<&TsThisType<'a>, &'a TsThisType<'a>>(node) };
21635    Node::TsThisType(node)
21636  }
21637}
21638
21639impl<'a> NodeTrait<'a> for TsThisType<'a> {
21640  fn parent(&self) -> Option<Node<'a>> {
21641    Some(self.parent.get().unwrap().clone())
21642  }
21643
21644  fn children(&self) -> Vec<Node<'a>> {
21645    Vec::with_capacity(0)
21646  }
21647
21648  fn as_node(&self) -> Node<'a> {
21649    self.into()
21650  }
21651
21652  fn kind(&self) -> NodeKind {
21653    NodeKind::TsThisType
21654  }
21655}
21656
21657impl<'a> CastableNode<'a> for TsThisType<'a> {
21658  fn to(node: &Node<'a>) -> Option<&'a Self> {
21659    if let Node::TsThisType(node) = node {
21660      Some(node)
21661    } else {
21662      None
21663    }
21664  }
21665
21666  fn kind() -> NodeKind {
21667    NodeKind::TsThisType
21668  }
21669}
21670
21671fn get_view_for_ts_this_type<'a>(inner: &'a swc_ast::TsThisType, bump: &'a Bump) -> &'a TsThisType<'a> {
21672  let node = bump.alloc(TsThisType {
21673    inner,
21674    parent: Default::default(),
21675  });
21676  node
21677}
21678
21679fn set_parent_for_ts_this_type<'a>(node: &TsThisType<'a>, parent: Node<'a>) {
21680  node.parent.set(parent);
21681}
21682
21683#[derive(Clone)]
21684pub struct TsTplLitType<'a> {
21685  parent: ParentOnceCell<&'a TsLitType<'a>>,
21686  pub inner: &'a swc_ast::TsTplLitType,
21687  pub types: &'a [TsType<'a>],
21688  pub quasis: &'a [&'a TplElement<'a>],
21689}
21690
21691impl<'a> TsTplLitType<'a> {
21692  pub fn parent(&self) -> &'a TsLitType<'a> {
21693    self.parent.get().unwrap()
21694  }
21695}
21696
21697impl<'a> SourceRanged for TsTplLitType<'a> {
21698  fn start(&self) -> SourcePos {
21699    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21700  }
21701  fn end(&self) -> SourcePos {
21702    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21703  }
21704}
21705
21706impl<'a> From<&TsTplLitType<'a>> for Node<'a> {
21707  fn from(node: &TsTplLitType<'a>) -> Node<'a> {
21708    let node = unsafe { mem::transmute::<&TsTplLitType<'a>, &'a TsTplLitType<'a>>(node) };
21709    Node::TsTplLitType(node)
21710  }
21711}
21712
21713impl<'a> NodeTrait<'a> for TsTplLitType<'a> {
21714  fn parent(&self) -> Option<Node<'a>> {
21715    Some(self.parent.get().unwrap().into())
21716  }
21717
21718  fn children(&self) -> Vec<Node<'a>> {
21719    let mut children = Vec::with_capacity(self.types.len() + self.quasis.len());
21720    for child in self.types.iter() {
21721      children.push(child.into());
21722    }
21723    for child in self.quasis.iter() {
21724      children.push((*child).into());
21725    }
21726    children
21727  }
21728
21729  fn as_node(&self) -> Node<'a> {
21730    self.into()
21731  }
21732
21733  fn kind(&self) -> NodeKind {
21734    NodeKind::TsTplLitType
21735  }
21736}
21737
21738impl<'a> CastableNode<'a> for TsTplLitType<'a> {
21739  fn to(node: &Node<'a>) -> Option<&'a Self> {
21740    if let Node::TsTplLitType(node) = node {
21741      Some(node)
21742    } else {
21743      None
21744    }
21745  }
21746
21747  fn kind() -> NodeKind {
21748    NodeKind::TsTplLitType
21749  }
21750}
21751
21752fn get_view_for_ts_tpl_lit_type<'a>(inner: &'a swc_ast::TsTplLitType, bump: &'a Bump) -> &'a TsTplLitType<'a> {
21753  let node = bump.alloc(TsTplLitType {
21754    inner,
21755    parent: Default::default(),
21756    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 }),
21757    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 }),
21758  });
21759  let parent: Node<'a> = (&*node).into();
21760  for value in node.types.iter() {
21761    set_parent_for_ts_type(value, parent)
21762  }
21763  for value in node.quasis.iter() {
21764    set_parent_for_tpl_element(value, parent)
21765  }
21766  node
21767}
21768
21769fn set_parent_for_ts_tpl_lit_type<'a>(node: &TsTplLitType<'a>, parent: Node<'a>) {
21770  node.parent.set(parent.expect::<TsLitType>());
21771}
21772
21773#[derive(Clone)]
21774pub struct TsTupleElement<'a> {
21775  parent: ParentOnceCell<&'a TsTupleType<'a>>,
21776  pub inner: &'a swc_ast::TsTupleElement,
21777  /// `Ident` or `RestPat { arg: Ident }`
21778  pub label: Option<Pat<'a>>,
21779  pub ty: TsType<'a>,
21780}
21781
21782impl<'a> TsTupleElement<'a> {
21783  pub fn parent(&self) -> &'a TsTupleType<'a> {
21784    self.parent.get().unwrap()
21785  }
21786}
21787
21788impl<'a> SourceRanged for TsTupleElement<'a> {
21789  fn start(&self) -> SourcePos {
21790    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21791  }
21792  fn end(&self) -> SourcePos {
21793    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21794  }
21795}
21796
21797impl<'a> From<&TsTupleElement<'a>> for Node<'a> {
21798  fn from(node: &TsTupleElement<'a>) -> Node<'a> {
21799    let node = unsafe { mem::transmute::<&TsTupleElement<'a>, &'a TsTupleElement<'a>>(node) };
21800    Node::TsTupleElement(node)
21801  }
21802}
21803
21804impl<'a> NodeTrait<'a> for TsTupleElement<'a> {
21805  fn parent(&self) -> Option<Node<'a>> {
21806    Some(self.parent.get().unwrap().into())
21807  }
21808
21809  fn children(&self) -> Vec<Node<'a>> {
21810    let mut children = Vec::with_capacity(1 + match &self.label { Some(_value) => 1, None => 0, });
21811    if let Some(child) = self.label.as_ref() {
21812      children.push(child.into());
21813    }
21814    children.push((&self.ty).into());
21815    children
21816  }
21817
21818  fn as_node(&self) -> Node<'a> {
21819    self.into()
21820  }
21821
21822  fn kind(&self) -> NodeKind {
21823    NodeKind::TsTupleElement
21824  }
21825}
21826
21827impl<'a> CastableNode<'a> for TsTupleElement<'a> {
21828  fn to(node: &Node<'a>) -> Option<&'a Self> {
21829    if let Node::TsTupleElement(node) = node {
21830      Some(node)
21831    } else {
21832      None
21833    }
21834  }
21835
21836  fn kind() -> NodeKind {
21837    NodeKind::TsTupleElement
21838  }
21839}
21840
21841fn get_view_for_ts_tuple_element<'a>(inner: &'a swc_ast::TsTupleElement, bump: &'a Bump) -> &'a TsTupleElement<'a> {
21842  let node = bump.alloc(TsTupleElement {
21843    inner,
21844    parent: Default::default(),
21845    label: match &inner.label {
21846      Some(value) => Some(get_view_for_pat(value, bump)),
21847      None => None,
21848    },
21849    ty: get_view_for_ts_type(&inner.ty, bump),
21850  });
21851  let parent: Node<'a> = (&*node).into();
21852  if let Some(value) = &node.label {
21853    set_parent_for_pat(value, parent)
21854  };
21855  set_parent_for_ts_type(&node.ty, parent);
21856  node
21857}
21858
21859fn set_parent_for_ts_tuple_element<'a>(node: &TsTupleElement<'a>, parent: Node<'a>) {
21860  node.parent.set(parent.expect::<TsTupleType>());
21861}
21862
21863#[derive(Clone)]
21864pub struct TsTupleType<'a> {
21865  parent: ParentOnceCell<Node<'a>>,
21866  pub inner: &'a swc_ast::TsTupleType,
21867  pub elem_types: &'a [&'a TsTupleElement<'a>],
21868}
21869
21870impl<'a> TsTupleType<'a> {
21871  pub fn parent(&self) -> Node<'a> {
21872    self.parent.get().unwrap()
21873  }
21874}
21875
21876impl<'a> SourceRanged for TsTupleType<'a> {
21877  fn start(&self) -> SourcePos {
21878    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21879  }
21880  fn end(&self) -> SourcePos {
21881    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21882  }
21883}
21884
21885impl<'a> From<&TsTupleType<'a>> for Node<'a> {
21886  fn from(node: &TsTupleType<'a>) -> Node<'a> {
21887    let node = unsafe { mem::transmute::<&TsTupleType<'a>, &'a TsTupleType<'a>>(node) };
21888    Node::TsTupleType(node)
21889  }
21890}
21891
21892impl<'a> NodeTrait<'a> for TsTupleType<'a> {
21893  fn parent(&self) -> Option<Node<'a>> {
21894    Some(self.parent.get().unwrap().clone())
21895  }
21896
21897  fn children(&self) -> Vec<Node<'a>> {
21898    let mut children = Vec::with_capacity(self.elem_types.len());
21899    for child in self.elem_types.iter() {
21900      children.push((*child).into());
21901    }
21902    children
21903  }
21904
21905  fn as_node(&self) -> Node<'a> {
21906    self.into()
21907  }
21908
21909  fn kind(&self) -> NodeKind {
21910    NodeKind::TsTupleType
21911  }
21912}
21913
21914impl<'a> CastableNode<'a> for TsTupleType<'a> {
21915  fn to(node: &Node<'a>) -> Option<&'a Self> {
21916    if let Node::TsTupleType(node) = node {
21917      Some(node)
21918    } else {
21919      None
21920    }
21921  }
21922
21923  fn kind() -> NodeKind {
21924    NodeKind::TsTupleType
21925  }
21926}
21927
21928fn get_view_for_ts_tuple_type<'a>(inner: &'a swc_ast::TsTupleType, bump: &'a Bump) -> &'a TsTupleType<'a> {
21929  let node = bump.alloc(TsTupleType {
21930    inner,
21931    parent: Default::default(),
21932    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 }),
21933  });
21934  let parent: Node<'a> = (&*node).into();
21935  for value in node.elem_types.iter() {
21936    set_parent_for_ts_tuple_element(value, parent)
21937  }
21938  node
21939}
21940
21941fn set_parent_for_ts_tuple_type<'a>(node: &TsTupleType<'a>, parent: Node<'a>) {
21942  node.parent.set(parent);
21943}
21944
21945#[derive(Clone)]
21946pub struct TsTypeAliasDecl<'a> {
21947  parent: ParentOnceCell<Node<'a>>,
21948  pub inner: &'a swc_ast::TsTypeAliasDecl,
21949  pub id: &'a Ident<'a>,
21950  pub type_params: Option<&'a TsTypeParamDecl<'a>>,
21951  pub type_ann: TsType<'a>,
21952}
21953
21954impl<'a> TsTypeAliasDecl<'a> {
21955  pub fn parent(&self) -> Node<'a> {
21956    self.parent.get().unwrap()
21957  }
21958
21959  pub fn declare(&self) -> bool {
21960    self.inner.declare
21961  }
21962}
21963
21964impl<'a> SourceRanged for TsTypeAliasDecl<'a> {
21965  fn start(&self) -> SourcePos {
21966    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
21967  }
21968  fn end(&self) -> SourcePos {
21969    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
21970  }
21971}
21972
21973impl<'a> From<&TsTypeAliasDecl<'a>> for Node<'a> {
21974  fn from(node: &TsTypeAliasDecl<'a>) -> Node<'a> {
21975    let node = unsafe { mem::transmute::<&TsTypeAliasDecl<'a>, &'a TsTypeAliasDecl<'a>>(node) };
21976    Node::TsTypeAliasDecl(node)
21977  }
21978}
21979
21980impl<'a> NodeTrait<'a> for TsTypeAliasDecl<'a> {
21981  fn parent(&self) -> Option<Node<'a>> {
21982    Some(self.parent.get().unwrap().clone())
21983  }
21984
21985  fn children(&self) -> Vec<Node<'a>> {
21986    let mut children = Vec::with_capacity(2 + match &self.type_params { Some(_value) => 1, None => 0, });
21987    children.push(self.id.into());
21988    if let Some(child) = self.type_params {
21989      children.push(child.into());
21990    }
21991    children.push((&self.type_ann).into());
21992    children
21993  }
21994
21995  fn as_node(&self) -> Node<'a> {
21996    self.into()
21997  }
21998
21999  fn kind(&self) -> NodeKind {
22000    NodeKind::TsTypeAliasDecl
22001  }
22002}
22003
22004impl<'a> CastableNode<'a> for TsTypeAliasDecl<'a> {
22005  fn to(node: &Node<'a>) -> Option<&'a Self> {
22006    if let Node::TsTypeAliasDecl(node) = node {
22007      Some(node)
22008    } else {
22009      None
22010    }
22011  }
22012
22013  fn kind() -> NodeKind {
22014    NodeKind::TsTypeAliasDecl
22015  }
22016}
22017
22018fn get_view_for_ts_type_alias_decl<'a>(inner: &'a swc_ast::TsTypeAliasDecl, bump: &'a Bump) -> &'a TsTypeAliasDecl<'a> {
22019  let node = bump.alloc(TsTypeAliasDecl {
22020    inner,
22021    parent: Default::default(),
22022    id: get_view_for_ident(&inner.id, bump),
22023    type_params: match &inner.type_params {
22024      Some(value) => Some(get_view_for_ts_type_param_decl(value, bump)),
22025      None => None,
22026    },
22027    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
22028  });
22029  let parent: Node<'a> = (&*node).into();
22030  set_parent_for_ident(&node.id, parent);
22031  if let Some(value) = &node.type_params {
22032    set_parent_for_ts_type_param_decl(value, parent)
22033  };
22034  set_parent_for_ts_type(&node.type_ann, parent);
22035  node
22036}
22037
22038fn set_parent_for_ts_type_alias_decl<'a>(node: &TsTypeAliasDecl<'a>, parent: Node<'a>) {
22039  node.parent.set(parent);
22040}
22041
22042#[derive(Clone)]
22043pub struct TsTypeAnn<'a> {
22044  parent: ParentOnceCell<Node<'a>>,
22045  pub inner: &'a swc_ast::TsTypeAnn,
22046  pub type_ann: TsType<'a>,
22047}
22048
22049impl<'a> TsTypeAnn<'a> {
22050  pub fn parent(&self) -> Node<'a> {
22051    self.parent.get().unwrap()
22052  }
22053}
22054
22055impl<'a> SourceRanged for TsTypeAnn<'a> {
22056  fn start(&self) -> SourcePos {
22057    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22058  }
22059  fn end(&self) -> SourcePos {
22060    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22061  }
22062}
22063
22064impl<'a> From<&TsTypeAnn<'a>> for Node<'a> {
22065  fn from(node: &TsTypeAnn<'a>) -> Node<'a> {
22066    let node = unsafe { mem::transmute::<&TsTypeAnn<'a>, &'a TsTypeAnn<'a>>(node) };
22067    Node::TsTypeAnn(node)
22068  }
22069}
22070
22071impl<'a> NodeTrait<'a> for TsTypeAnn<'a> {
22072  fn parent(&self) -> Option<Node<'a>> {
22073    Some(self.parent.get().unwrap().clone())
22074  }
22075
22076  fn children(&self) -> Vec<Node<'a>> {
22077    let mut children = Vec::with_capacity(1);
22078    children.push((&self.type_ann).into());
22079    children
22080  }
22081
22082  fn as_node(&self) -> Node<'a> {
22083    self.into()
22084  }
22085
22086  fn kind(&self) -> NodeKind {
22087    NodeKind::TsTypeAnn
22088  }
22089}
22090
22091impl<'a> CastableNode<'a> for TsTypeAnn<'a> {
22092  fn to(node: &Node<'a>) -> Option<&'a Self> {
22093    if let Node::TsTypeAnn(node) = node {
22094      Some(node)
22095    } else {
22096      None
22097    }
22098  }
22099
22100  fn kind() -> NodeKind {
22101    NodeKind::TsTypeAnn
22102  }
22103}
22104
22105fn get_view_for_ts_type_ann<'a>(inner: &'a swc_ast::TsTypeAnn, bump: &'a Bump) -> &'a TsTypeAnn<'a> {
22106  let node = bump.alloc(TsTypeAnn {
22107    inner,
22108    parent: Default::default(),
22109    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
22110  });
22111  let parent: Node<'a> = (&*node).into();
22112  set_parent_for_ts_type(&node.type_ann, parent);
22113  node
22114}
22115
22116fn set_parent_for_ts_type_ann<'a>(node: &TsTypeAnn<'a>, parent: Node<'a>) {
22117  node.parent.set(parent);
22118}
22119
22120#[derive(Clone)]
22121pub struct TsTypeAssertion<'a> {
22122  parent: ParentOnceCell<Node<'a>>,
22123  pub inner: &'a swc_ast::TsTypeAssertion,
22124  pub expr: Expr<'a>,
22125  pub type_ann: TsType<'a>,
22126}
22127
22128impl<'a> TsTypeAssertion<'a> {
22129  pub fn parent(&self) -> Node<'a> {
22130    self.parent.get().unwrap()
22131  }
22132}
22133
22134impl<'a> SourceRanged for TsTypeAssertion<'a> {
22135  fn start(&self) -> SourcePos {
22136    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22137  }
22138  fn end(&self) -> SourcePos {
22139    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22140  }
22141}
22142
22143impl<'a> From<&TsTypeAssertion<'a>> for Node<'a> {
22144  fn from(node: &TsTypeAssertion<'a>) -> Node<'a> {
22145    let node = unsafe { mem::transmute::<&TsTypeAssertion<'a>, &'a TsTypeAssertion<'a>>(node) };
22146    Node::TsTypeAssertion(node)
22147  }
22148}
22149
22150impl<'a> NodeTrait<'a> for TsTypeAssertion<'a> {
22151  fn parent(&self) -> Option<Node<'a>> {
22152    Some(self.parent.get().unwrap().clone())
22153  }
22154
22155  fn children(&self) -> Vec<Node<'a>> {
22156    let mut children = Vec::with_capacity(2);
22157    children.push((&self.expr).into());
22158    children.push((&self.type_ann).into());
22159    children
22160  }
22161
22162  fn as_node(&self) -> Node<'a> {
22163    self.into()
22164  }
22165
22166  fn kind(&self) -> NodeKind {
22167    NodeKind::TsTypeAssertion
22168  }
22169}
22170
22171impl<'a> CastableNode<'a> for TsTypeAssertion<'a> {
22172  fn to(node: &Node<'a>) -> Option<&'a Self> {
22173    if let Node::TsTypeAssertion(node) = node {
22174      Some(node)
22175    } else {
22176      None
22177    }
22178  }
22179
22180  fn kind() -> NodeKind {
22181    NodeKind::TsTypeAssertion
22182  }
22183}
22184
22185fn get_view_for_ts_type_assertion<'a>(inner: &'a swc_ast::TsTypeAssertion, bump: &'a Bump) -> &'a TsTypeAssertion<'a> {
22186  let node = bump.alloc(TsTypeAssertion {
22187    inner,
22188    parent: Default::default(),
22189    expr: get_view_for_expr(&inner.expr, bump),
22190    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
22191  });
22192  let parent: Node<'a> = (&*node).into();
22193  set_parent_for_expr(&node.expr, parent);
22194  set_parent_for_ts_type(&node.type_ann, parent);
22195  node
22196}
22197
22198fn set_parent_for_ts_type_assertion<'a>(node: &TsTypeAssertion<'a>, parent: Node<'a>) {
22199  node.parent.set(parent);
22200}
22201
22202#[derive(Clone)]
22203pub struct TsTypeLit<'a> {
22204  parent: ParentOnceCell<Node<'a>>,
22205  pub inner: &'a swc_ast::TsTypeLit,
22206  pub members: &'a [TsTypeElement<'a>],
22207}
22208
22209impl<'a> TsTypeLit<'a> {
22210  pub fn parent(&self) -> Node<'a> {
22211    self.parent.get().unwrap()
22212  }
22213}
22214
22215impl<'a> SourceRanged for TsTypeLit<'a> {
22216  fn start(&self) -> SourcePos {
22217    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22218  }
22219  fn end(&self) -> SourcePos {
22220    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22221  }
22222}
22223
22224impl<'a> From<&TsTypeLit<'a>> for Node<'a> {
22225  fn from(node: &TsTypeLit<'a>) -> Node<'a> {
22226    let node = unsafe { mem::transmute::<&TsTypeLit<'a>, &'a TsTypeLit<'a>>(node) };
22227    Node::TsTypeLit(node)
22228  }
22229}
22230
22231impl<'a> NodeTrait<'a> for TsTypeLit<'a> {
22232  fn parent(&self) -> Option<Node<'a>> {
22233    Some(self.parent.get().unwrap().clone())
22234  }
22235
22236  fn children(&self) -> Vec<Node<'a>> {
22237    let mut children = Vec::with_capacity(self.members.len());
22238    for child in self.members.iter() {
22239      children.push(child.into());
22240    }
22241    children
22242  }
22243
22244  fn as_node(&self) -> Node<'a> {
22245    self.into()
22246  }
22247
22248  fn kind(&self) -> NodeKind {
22249    NodeKind::TsTypeLit
22250  }
22251}
22252
22253impl<'a> CastableNode<'a> for TsTypeLit<'a> {
22254  fn to(node: &Node<'a>) -> Option<&'a Self> {
22255    if let Node::TsTypeLit(node) = node {
22256      Some(node)
22257    } else {
22258      None
22259    }
22260  }
22261
22262  fn kind() -> NodeKind {
22263    NodeKind::TsTypeLit
22264  }
22265}
22266
22267fn get_view_for_ts_type_lit<'a>(inner: &'a swc_ast::TsTypeLit, bump: &'a Bump) -> &'a TsTypeLit<'a> {
22268  let node = bump.alloc(TsTypeLit {
22269    inner,
22270    parent: Default::default(),
22271    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 }),
22272  });
22273  let parent: Node<'a> = (&*node).into();
22274  for value in node.members.iter() {
22275    set_parent_for_ts_type_element(value, parent)
22276  }
22277  node
22278}
22279
22280fn set_parent_for_ts_type_lit<'a>(node: &TsTypeLit<'a>, parent: Node<'a>) {
22281  node.parent.set(parent);
22282}
22283
22284#[derive(Clone)]
22285pub struct TsTypeOperator<'a> {
22286  parent: ParentOnceCell<Node<'a>>,
22287  pub inner: &'a swc_ast::TsTypeOperator,
22288  pub type_ann: TsType<'a>,
22289}
22290
22291impl<'a> TsTypeOperator<'a> {
22292  pub fn parent(&self) -> Node<'a> {
22293    self.parent.get().unwrap()
22294  }
22295
22296  pub fn op(&self) -> TsTypeOperatorOp {
22297    self.inner.op
22298  }
22299}
22300
22301impl<'a> SourceRanged for TsTypeOperator<'a> {
22302  fn start(&self) -> SourcePos {
22303    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22304  }
22305  fn end(&self) -> SourcePos {
22306    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22307  }
22308}
22309
22310impl<'a> From<&TsTypeOperator<'a>> for Node<'a> {
22311  fn from(node: &TsTypeOperator<'a>) -> Node<'a> {
22312    let node = unsafe { mem::transmute::<&TsTypeOperator<'a>, &'a TsTypeOperator<'a>>(node) };
22313    Node::TsTypeOperator(node)
22314  }
22315}
22316
22317impl<'a> NodeTrait<'a> for TsTypeOperator<'a> {
22318  fn parent(&self) -> Option<Node<'a>> {
22319    Some(self.parent.get().unwrap().clone())
22320  }
22321
22322  fn children(&self) -> Vec<Node<'a>> {
22323    let mut children = Vec::with_capacity(1);
22324    children.push((&self.type_ann).into());
22325    children
22326  }
22327
22328  fn as_node(&self) -> Node<'a> {
22329    self.into()
22330  }
22331
22332  fn kind(&self) -> NodeKind {
22333    NodeKind::TsTypeOperator
22334  }
22335}
22336
22337impl<'a> CastableNode<'a> for TsTypeOperator<'a> {
22338  fn to(node: &Node<'a>) -> Option<&'a Self> {
22339    if let Node::TsTypeOperator(node) = node {
22340      Some(node)
22341    } else {
22342      None
22343    }
22344  }
22345
22346  fn kind() -> NodeKind {
22347    NodeKind::TsTypeOperator
22348  }
22349}
22350
22351fn get_view_for_ts_type_operator<'a>(inner: &'a swc_ast::TsTypeOperator, bump: &'a Bump) -> &'a TsTypeOperator<'a> {
22352  let node = bump.alloc(TsTypeOperator {
22353    inner,
22354    parent: Default::default(),
22355    type_ann: get_view_for_ts_type(&inner.type_ann, bump),
22356  });
22357  let parent: Node<'a> = (&*node).into();
22358  set_parent_for_ts_type(&node.type_ann, parent);
22359  node
22360}
22361
22362fn set_parent_for_ts_type_operator<'a>(node: &TsTypeOperator<'a>, parent: Node<'a>) {
22363  node.parent.set(parent);
22364}
22365
22366#[derive(Clone)]
22367pub struct TsTypeParam<'a> {
22368  parent: ParentOnceCell<Node<'a>>,
22369  pub inner: &'a swc_ast::TsTypeParam,
22370  pub name: &'a Ident<'a>,
22371  pub constraint: Option<TsType<'a>>,
22372  pub default: Option<TsType<'a>>,
22373}
22374
22375impl<'a> TsTypeParam<'a> {
22376  pub fn parent(&self) -> Node<'a> {
22377    self.parent.get().unwrap()
22378  }
22379
22380  pub fn is_in(&self) -> bool {
22381    self.inner.is_in
22382  }
22383
22384  pub fn is_out(&self) -> bool {
22385    self.inner.is_out
22386  }
22387
22388  pub fn is_const(&self) -> bool {
22389    self.inner.is_const
22390  }
22391}
22392
22393impl<'a> SourceRanged for TsTypeParam<'a> {
22394  fn start(&self) -> SourcePos {
22395    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22396  }
22397  fn end(&self) -> SourcePos {
22398    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22399  }
22400}
22401
22402impl<'a> From<&TsTypeParam<'a>> for Node<'a> {
22403  fn from(node: &TsTypeParam<'a>) -> Node<'a> {
22404    let node = unsafe { mem::transmute::<&TsTypeParam<'a>, &'a TsTypeParam<'a>>(node) };
22405    Node::TsTypeParam(node)
22406  }
22407}
22408
22409impl<'a> NodeTrait<'a> for TsTypeParam<'a> {
22410  fn parent(&self) -> Option<Node<'a>> {
22411    Some(self.parent.get().unwrap().clone())
22412  }
22413
22414  fn children(&self) -> Vec<Node<'a>> {
22415    let mut children = Vec::with_capacity(1 + match &self.constraint { Some(_value) => 1, None => 0, } + match &self.default { Some(_value) => 1, None => 0, });
22416    children.push(self.name.into());
22417    if let Some(child) = self.constraint.as_ref() {
22418      children.push(child.into());
22419    }
22420    if let Some(child) = self.default.as_ref() {
22421      children.push(child.into());
22422    }
22423    children
22424  }
22425
22426  fn as_node(&self) -> Node<'a> {
22427    self.into()
22428  }
22429
22430  fn kind(&self) -> NodeKind {
22431    NodeKind::TsTypeParam
22432  }
22433}
22434
22435impl<'a> CastableNode<'a> for TsTypeParam<'a> {
22436  fn to(node: &Node<'a>) -> Option<&'a Self> {
22437    if let Node::TsTypeParam(node) = node {
22438      Some(node)
22439    } else {
22440      None
22441    }
22442  }
22443
22444  fn kind() -> NodeKind {
22445    NodeKind::TsTypeParam
22446  }
22447}
22448
22449fn get_view_for_ts_type_param<'a>(inner: &'a swc_ast::TsTypeParam, bump: &'a Bump) -> &'a TsTypeParam<'a> {
22450  let node = bump.alloc(TsTypeParam {
22451    inner,
22452    parent: Default::default(),
22453    name: get_view_for_ident(&inner.name, bump),
22454    constraint: match &inner.constraint {
22455      Some(value) => Some(get_view_for_ts_type(value, bump)),
22456      None => None,
22457    },
22458    default: match &inner.default {
22459      Some(value) => Some(get_view_for_ts_type(value, bump)),
22460      None => None,
22461    },
22462  });
22463  let parent: Node<'a> = (&*node).into();
22464  set_parent_for_ident(&node.name, parent);
22465  if let Some(value) = &node.constraint {
22466    set_parent_for_ts_type(value, parent)
22467  };
22468  if let Some(value) = &node.default {
22469    set_parent_for_ts_type(value, parent)
22470  };
22471  node
22472}
22473
22474fn set_parent_for_ts_type_param<'a>(node: &TsTypeParam<'a>, parent: Node<'a>) {
22475  node.parent.set(parent);
22476}
22477
22478#[derive(Clone)]
22479pub struct TsTypeParamDecl<'a> {
22480  parent: ParentOnceCell<Node<'a>>,
22481  pub inner: &'a swc_ast::TsTypeParamDecl,
22482  pub params: &'a [&'a TsTypeParam<'a>],
22483}
22484
22485impl<'a> TsTypeParamDecl<'a> {
22486  pub fn parent(&self) -> Node<'a> {
22487    self.parent.get().unwrap()
22488  }
22489}
22490
22491impl<'a> SourceRanged for TsTypeParamDecl<'a> {
22492  fn start(&self) -> SourcePos {
22493    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22494  }
22495  fn end(&self) -> SourcePos {
22496    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22497  }
22498}
22499
22500impl<'a> From<&TsTypeParamDecl<'a>> for Node<'a> {
22501  fn from(node: &TsTypeParamDecl<'a>) -> Node<'a> {
22502    let node = unsafe { mem::transmute::<&TsTypeParamDecl<'a>, &'a TsTypeParamDecl<'a>>(node) };
22503    Node::TsTypeParamDecl(node)
22504  }
22505}
22506
22507impl<'a> NodeTrait<'a> for TsTypeParamDecl<'a> {
22508  fn parent(&self) -> Option<Node<'a>> {
22509    Some(self.parent.get().unwrap().clone())
22510  }
22511
22512  fn children(&self) -> Vec<Node<'a>> {
22513    let mut children = Vec::with_capacity(self.params.len());
22514    for child in self.params.iter() {
22515      children.push((*child).into());
22516    }
22517    children
22518  }
22519
22520  fn as_node(&self) -> Node<'a> {
22521    self.into()
22522  }
22523
22524  fn kind(&self) -> NodeKind {
22525    NodeKind::TsTypeParamDecl
22526  }
22527}
22528
22529impl<'a> CastableNode<'a> for TsTypeParamDecl<'a> {
22530  fn to(node: &Node<'a>) -> Option<&'a Self> {
22531    if let Node::TsTypeParamDecl(node) = node {
22532      Some(node)
22533    } else {
22534      None
22535    }
22536  }
22537
22538  fn kind() -> NodeKind {
22539    NodeKind::TsTypeParamDecl
22540  }
22541}
22542
22543fn get_view_for_ts_type_param_decl<'a>(inner: &'a swc_ast::TsTypeParamDecl, bump: &'a Bump) -> &'a TsTypeParamDecl<'a> {
22544  let node = bump.alloc(TsTypeParamDecl {
22545    inner,
22546    parent: Default::default(),
22547    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 }),
22548  });
22549  let parent: Node<'a> = (&*node).into();
22550  for value in node.params.iter() {
22551    set_parent_for_ts_type_param(value, parent)
22552  }
22553  node
22554}
22555
22556fn set_parent_for_ts_type_param_decl<'a>(node: &TsTypeParamDecl<'a>, parent: Node<'a>) {
22557  node.parent.set(parent);
22558}
22559
22560#[derive(Clone)]
22561pub struct TsTypeParamInstantiation<'a> {
22562  parent: ParentOnceCell<Node<'a>>,
22563  pub inner: &'a swc_ast::TsTypeParamInstantiation,
22564  pub params: &'a [TsType<'a>],
22565}
22566
22567impl<'a> TsTypeParamInstantiation<'a> {
22568  pub fn parent(&self) -> Node<'a> {
22569    self.parent.get().unwrap()
22570  }
22571}
22572
22573impl<'a> SourceRanged for TsTypeParamInstantiation<'a> {
22574  fn start(&self) -> SourcePos {
22575    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22576  }
22577  fn end(&self) -> SourcePos {
22578    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22579  }
22580}
22581
22582impl<'a> From<&TsTypeParamInstantiation<'a>> for Node<'a> {
22583  fn from(node: &TsTypeParamInstantiation<'a>) -> Node<'a> {
22584    let node = unsafe { mem::transmute::<&TsTypeParamInstantiation<'a>, &'a TsTypeParamInstantiation<'a>>(node) };
22585    Node::TsTypeParamInstantiation(node)
22586  }
22587}
22588
22589impl<'a> NodeTrait<'a> for TsTypeParamInstantiation<'a> {
22590  fn parent(&self) -> Option<Node<'a>> {
22591    Some(self.parent.get().unwrap().clone())
22592  }
22593
22594  fn children(&self) -> Vec<Node<'a>> {
22595    let mut children = Vec::with_capacity(self.params.len());
22596    for child in self.params.iter() {
22597      children.push(child.into());
22598    }
22599    children
22600  }
22601
22602  fn as_node(&self) -> Node<'a> {
22603    self.into()
22604  }
22605
22606  fn kind(&self) -> NodeKind {
22607    NodeKind::TsTypeParamInstantiation
22608  }
22609}
22610
22611impl<'a> CastableNode<'a> for TsTypeParamInstantiation<'a> {
22612  fn to(node: &Node<'a>) -> Option<&'a Self> {
22613    if let Node::TsTypeParamInstantiation(node) = node {
22614      Some(node)
22615    } else {
22616      None
22617    }
22618  }
22619
22620  fn kind() -> NodeKind {
22621    NodeKind::TsTypeParamInstantiation
22622  }
22623}
22624
22625fn get_view_for_ts_type_param_instantiation<'a>(inner: &'a swc_ast::TsTypeParamInstantiation, bump: &'a Bump) -> &'a TsTypeParamInstantiation<'a> {
22626  let node = bump.alloc(TsTypeParamInstantiation {
22627    inner,
22628    parent: Default::default(),
22629    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 }),
22630  });
22631  let parent: Node<'a> = (&*node).into();
22632  for value in node.params.iter() {
22633    set_parent_for_ts_type(value, parent)
22634  }
22635  node
22636}
22637
22638fn set_parent_for_ts_type_param_instantiation<'a>(node: &TsTypeParamInstantiation<'a>, parent: Node<'a>) {
22639  node.parent.set(parent);
22640}
22641
22642#[derive(Clone)]
22643pub struct TsTypePredicate<'a> {
22644  parent: ParentOnceCell<Node<'a>>,
22645  pub inner: &'a swc_ast::TsTypePredicate,
22646  pub param_name: TsThisTypeOrIdent<'a>,
22647  pub type_ann: Option<&'a TsTypeAnn<'a>>,
22648}
22649
22650impl<'a> TsTypePredicate<'a> {
22651  pub fn parent(&self) -> Node<'a> {
22652    self.parent.get().unwrap()
22653  }
22654
22655  pub fn asserts(&self) -> bool {
22656    self.inner.asserts
22657  }
22658}
22659
22660impl<'a> SourceRanged for TsTypePredicate<'a> {
22661  fn start(&self) -> SourcePos {
22662    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22663  }
22664  fn end(&self) -> SourcePos {
22665    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22666  }
22667}
22668
22669impl<'a> From<&TsTypePredicate<'a>> for Node<'a> {
22670  fn from(node: &TsTypePredicate<'a>) -> Node<'a> {
22671    let node = unsafe { mem::transmute::<&TsTypePredicate<'a>, &'a TsTypePredicate<'a>>(node) };
22672    Node::TsTypePredicate(node)
22673  }
22674}
22675
22676impl<'a> NodeTrait<'a> for TsTypePredicate<'a> {
22677  fn parent(&self) -> Option<Node<'a>> {
22678    Some(self.parent.get().unwrap().clone())
22679  }
22680
22681  fn children(&self) -> Vec<Node<'a>> {
22682    let mut children = Vec::with_capacity(1 + match &self.type_ann { Some(_value) => 1, None => 0, });
22683    children.push((&self.param_name).into());
22684    if let Some(child) = self.type_ann {
22685      children.push(child.into());
22686    }
22687    children
22688  }
22689
22690  fn as_node(&self) -> Node<'a> {
22691    self.into()
22692  }
22693
22694  fn kind(&self) -> NodeKind {
22695    NodeKind::TsTypePredicate
22696  }
22697}
22698
22699impl<'a> CastableNode<'a> for TsTypePredicate<'a> {
22700  fn to(node: &Node<'a>) -> Option<&'a Self> {
22701    if let Node::TsTypePredicate(node) = node {
22702      Some(node)
22703    } else {
22704      None
22705    }
22706  }
22707
22708  fn kind() -> NodeKind {
22709    NodeKind::TsTypePredicate
22710  }
22711}
22712
22713fn get_view_for_ts_type_predicate<'a>(inner: &'a swc_ast::TsTypePredicate, bump: &'a Bump) -> &'a TsTypePredicate<'a> {
22714  let node = bump.alloc(TsTypePredicate {
22715    inner,
22716    parent: Default::default(),
22717    param_name: get_view_for_ts_this_type_or_ident(&inner.param_name, bump),
22718    type_ann: match &inner.type_ann {
22719      Some(value) => Some(get_view_for_ts_type_ann(value, bump)),
22720      None => None,
22721    },
22722  });
22723  let parent: Node<'a> = (&*node).into();
22724  set_parent_for_ts_this_type_or_ident(&node.param_name, parent);
22725  if let Some(value) = &node.type_ann {
22726    set_parent_for_ts_type_ann(value, parent)
22727  };
22728  node
22729}
22730
22731fn set_parent_for_ts_type_predicate<'a>(node: &TsTypePredicate<'a>, parent: Node<'a>) {
22732  node.parent.set(parent);
22733}
22734
22735/// `typeof` operator
22736#[derive(Clone)]
22737pub struct TsTypeQuery<'a> {
22738  parent: ParentOnceCell<Node<'a>>,
22739  pub inner: &'a swc_ast::TsTypeQuery,
22740  pub expr_name: TsTypeQueryExpr<'a>,
22741  pub type_args: Option<&'a TsTypeParamInstantiation<'a>>,
22742}
22743
22744impl<'a> TsTypeQuery<'a> {
22745  pub fn parent(&self) -> Node<'a> {
22746    self.parent.get().unwrap()
22747  }
22748}
22749
22750impl<'a> SourceRanged for TsTypeQuery<'a> {
22751  fn start(&self) -> SourcePos {
22752    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22753  }
22754  fn end(&self) -> SourcePos {
22755    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22756  }
22757}
22758
22759impl<'a> From<&TsTypeQuery<'a>> for Node<'a> {
22760  fn from(node: &TsTypeQuery<'a>) -> Node<'a> {
22761    let node = unsafe { mem::transmute::<&TsTypeQuery<'a>, &'a TsTypeQuery<'a>>(node) };
22762    Node::TsTypeQuery(node)
22763  }
22764}
22765
22766impl<'a> NodeTrait<'a> for TsTypeQuery<'a> {
22767  fn parent(&self) -> Option<Node<'a>> {
22768    Some(self.parent.get().unwrap().clone())
22769  }
22770
22771  fn children(&self) -> Vec<Node<'a>> {
22772    let mut children = Vec::with_capacity(1 + match &self.type_args { Some(_value) => 1, None => 0, });
22773    children.push((&self.expr_name).into());
22774    if let Some(child) = self.type_args {
22775      children.push(child.into());
22776    }
22777    children
22778  }
22779
22780  fn as_node(&self) -> Node<'a> {
22781    self.into()
22782  }
22783
22784  fn kind(&self) -> NodeKind {
22785    NodeKind::TsTypeQuery
22786  }
22787}
22788
22789impl<'a> CastableNode<'a> for TsTypeQuery<'a> {
22790  fn to(node: &Node<'a>) -> Option<&'a Self> {
22791    if let Node::TsTypeQuery(node) = node {
22792      Some(node)
22793    } else {
22794      None
22795    }
22796  }
22797
22798  fn kind() -> NodeKind {
22799    NodeKind::TsTypeQuery
22800  }
22801}
22802
22803fn get_view_for_ts_type_query<'a>(inner: &'a swc_ast::TsTypeQuery, bump: &'a Bump) -> &'a TsTypeQuery<'a> {
22804  let node = bump.alloc(TsTypeQuery {
22805    inner,
22806    parent: Default::default(),
22807    expr_name: get_view_for_ts_type_query_expr(&inner.expr_name, bump),
22808    type_args: match &inner.type_args {
22809      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
22810      None => None,
22811    },
22812  });
22813  let parent: Node<'a> = (&*node).into();
22814  set_parent_for_ts_type_query_expr(&node.expr_name, parent);
22815  if let Some(value) = &node.type_args {
22816    set_parent_for_ts_type_param_instantiation(value, parent)
22817  };
22818  node
22819}
22820
22821fn set_parent_for_ts_type_query<'a>(node: &TsTypeQuery<'a>, parent: Node<'a>) {
22822  node.parent.set(parent);
22823}
22824
22825#[derive(Clone)]
22826pub struct TsTypeRef<'a> {
22827  parent: ParentOnceCell<Node<'a>>,
22828  pub inner: &'a swc_ast::TsTypeRef,
22829  pub type_name: TsEntityName<'a>,
22830  pub type_params: Option<&'a TsTypeParamInstantiation<'a>>,
22831}
22832
22833impl<'a> TsTypeRef<'a> {
22834  pub fn parent(&self) -> Node<'a> {
22835    self.parent.get().unwrap()
22836  }
22837}
22838
22839impl<'a> SourceRanged for TsTypeRef<'a> {
22840  fn start(&self) -> SourcePos {
22841    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22842  }
22843  fn end(&self) -> SourcePos {
22844    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22845  }
22846}
22847
22848impl<'a> From<&TsTypeRef<'a>> for Node<'a> {
22849  fn from(node: &TsTypeRef<'a>) -> Node<'a> {
22850    let node = unsafe { mem::transmute::<&TsTypeRef<'a>, &'a TsTypeRef<'a>>(node) };
22851    Node::TsTypeRef(node)
22852  }
22853}
22854
22855impl<'a> NodeTrait<'a> for TsTypeRef<'a> {
22856  fn parent(&self) -> Option<Node<'a>> {
22857    Some(self.parent.get().unwrap().clone())
22858  }
22859
22860  fn children(&self) -> Vec<Node<'a>> {
22861    let mut children = Vec::with_capacity(1 + match &self.type_params { Some(_value) => 1, None => 0, });
22862    children.push((&self.type_name).into());
22863    if let Some(child) = self.type_params {
22864      children.push(child.into());
22865    }
22866    children
22867  }
22868
22869  fn as_node(&self) -> Node<'a> {
22870    self.into()
22871  }
22872
22873  fn kind(&self) -> NodeKind {
22874    NodeKind::TsTypeRef
22875  }
22876}
22877
22878impl<'a> CastableNode<'a> for TsTypeRef<'a> {
22879  fn to(node: &Node<'a>) -> Option<&'a Self> {
22880    if let Node::TsTypeRef(node) = node {
22881      Some(node)
22882    } else {
22883      None
22884    }
22885  }
22886
22887  fn kind() -> NodeKind {
22888    NodeKind::TsTypeRef
22889  }
22890}
22891
22892fn get_view_for_ts_type_ref<'a>(inner: &'a swc_ast::TsTypeRef, bump: &'a Bump) -> &'a TsTypeRef<'a> {
22893  let node = bump.alloc(TsTypeRef {
22894    inner,
22895    parent: Default::default(),
22896    type_name: get_view_for_ts_entity_name(&inner.type_name, bump),
22897    type_params: match &inner.type_params {
22898      Some(value) => Some(get_view_for_ts_type_param_instantiation(value, bump)),
22899      None => None,
22900    },
22901  });
22902  let parent: Node<'a> = (&*node).into();
22903  set_parent_for_ts_entity_name(&node.type_name, parent);
22904  if let Some(value) = &node.type_params {
22905    set_parent_for_ts_type_param_instantiation(value, parent)
22906  };
22907  node
22908}
22909
22910fn set_parent_for_ts_type_ref<'a>(node: &TsTypeRef<'a>, parent: Node<'a>) {
22911  node.parent.set(parent);
22912}
22913
22914#[derive(Clone)]
22915pub struct TsUnionType<'a> {
22916  parent: ParentOnceCell<Node<'a>>,
22917  pub inner: &'a swc_ast::TsUnionType,
22918  pub types: &'a [TsType<'a>],
22919}
22920
22921impl<'a> TsUnionType<'a> {
22922  pub fn parent(&self) -> Node<'a> {
22923    self.parent.get().unwrap()
22924  }
22925}
22926
22927impl<'a> SourceRanged for TsUnionType<'a> {
22928  fn start(&self) -> SourcePos {
22929    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
22930  }
22931  fn end(&self) -> SourcePos {
22932    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
22933  }
22934}
22935
22936impl<'a> From<&TsUnionType<'a>> for Node<'a> {
22937  fn from(node: &TsUnionType<'a>) -> Node<'a> {
22938    let node = unsafe { mem::transmute::<&TsUnionType<'a>, &'a TsUnionType<'a>>(node) };
22939    Node::TsUnionType(node)
22940  }
22941}
22942
22943impl<'a> NodeTrait<'a> for TsUnionType<'a> {
22944  fn parent(&self) -> Option<Node<'a>> {
22945    Some(self.parent.get().unwrap().clone())
22946  }
22947
22948  fn children(&self) -> Vec<Node<'a>> {
22949    let mut children = Vec::with_capacity(self.types.len());
22950    for child in self.types.iter() {
22951      children.push(child.into());
22952    }
22953    children
22954  }
22955
22956  fn as_node(&self) -> Node<'a> {
22957    self.into()
22958  }
22959
22960  fn kind(&self) -> NodeKind {
22961    NodeKind::TsUnionType
22962  }
22963}
22964
22965impl<'a> CastableNode<'a> for TsUnionType<'a> {
22966  fn to(node: &Node<'a>) -> Option<&'a Self> {
22967    if let Node::TsUnionType(node) = node {
22968      Some(node)
22969    } else {
22970      None
22971    }
22972  }
22973
22974  fn kind() -> NodeKind {
22975    NodeKind::TsUnionType
22976  }
22977}
22978
22979fn get_view_for_ts_union_type<'a>(inner: &'a swc_ast::TsUnionType, bump: &'a Bump) -> &'a TsUnionType<'a> {
22980  let node = bump.alloc(TsUnionType {
22981    inner,
22982    parent: Default::default(),
22983    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 }),
22984  });
22985  let parent: Node<'a> = (&*node).into();
22986  for value in node.types.iter() {
22987    set_parent_for_ts_type(value, parent)
22988  }
22989  node
22990}
22991
22992fn set_parent_for_ts_union_type<'a>(node: &TsUnionType<'a>, parent: Node<'a>) {
22993  node.parent.set(parent);
22994}
22995
22996#[derive(Clone)]
22997pub struct UnaryExpr<'a> {
22998  parent: ParentOnceCell<Node<'a>>,
22999  pub inner: &'a swc_ast::UnaryExpr,
23000  pub arg: Expr<'a>,
23001}
23002
23003impl<'a> UnaryExpr<'a> {
23004  pub fn parent(&self) -> Node<'a> {
23005    self.parent.get().unwrap()
23006  }
23007
23008  pub fn op(&self) -> UnaryOp {
23009    self.inner.op
23010  }
23011}
23012
23013impl<'a> SourceRanged for UnaryExpr<'a> {
23014  fn start(&self) -> SourcePos {
23015    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23016  }
23017  fn end(&self) -> SourcePos {
23018    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23019  }
23020}
23021
23022impl<'a> From<&UnaryExpr<'a>> for Node<'a> {
23023  fn from(node: &UnaryExpr<'a>) -> Node<'a> {
23024    let node = unsafe { mem::transmute::<&UnaryExpr<'a>, &'a UnaryExpr<'a>>(node) };
23025    Node::UnaryExpr(node)
23026  }
23027}
23028
23029impl<'a> NodeTrait<'a> for UnaryExpr<'a> {
23030  fn parent(&self) -> Option<Node<'a>> {
23031    Some(self.parent.get().unwrap().clone())
23032  }
23033
23034  fn children(&self) -> Vec<Node<'a>> {
23035    let mut children = Vec::with_capacity(1);
23036    children.push((&self.arg).into());
23037    children
23038  }
23039
23040  fn as_node(&self) -> Node<'a> {
23041    self.into()
23042  }
23043
23044  fn kind(&self) -> NodeKind {
23045    NodeKind::UnaryExpr
23046  }
23047}
23048
23049impl<'a> CastableNode<'a> for UnaryExpr<'a> {
23050  fn to(node: &Node<'a>) -> Option<&'a Self> {
23051    if let Node::UnaryExpr(node) = node {
23052      Some(node)
23053    } else {
23054      None
23055    }
23056  }
23057
23058  fn kind() -> NodeKind {
23059    NodeKind::UnaryExpr
23060  }
23061}
23062
23063fn get_view_for_unary_expr<'a>(inner: &'a swc_ast::UnaryExpr, bump: &'a Bump) -> &'a UnaryExpr<'a> {
23064  let node = bump.alloc(UnaryExpr {
23065    inner,
23066    parent: Default::default(),
23067    arg: get_view_for_expr(&inner.arg, bump),
23068  });
23069  let parent: Node<'a> = (&*node).into();
23070  set_parent_for_expr(&node.arg, parent);
23071  node
23072}
23073
23074fn set_parent_for_unary_expr<'a>(node: &UnaryExpr<'a>, parent: Node<'a>) {
23075  node.parent.set(parent);
23076}
23077
23078#[derive(Clone)]
23079pub struct UpdateExpr<'a> {
23080  parent: ParentOnceCell<Node<'a>>,
23081  pub inner: &'a swc_ast::UpdateExpr,
23082  pub arg: Expr<'a>,
23083}
23084
23085impl<'a> UpdateExpr<'a> {
23086  pub fn parent(&self) -> Node<'a> {
23087    self.parent.get().unwrap()
23088  }
23089
23090  pub fn op(&self) -> UpdateOp {
23091    self.inner.op
23092  }
23093
23094  pub fn prefix(&self) -> bool {
23095    self.inner.prefix
23096  }
23097}
23098
23099impl<'a> SourceRanged for UpdateExpr<'a> {
23100  fn start(&self) -> SourcePos {
23101    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23102  }
23103  fn end(&self) -> SourcePos {
23104    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23105  }
23106}
23107
23108impl<'a> From<&UpdateExpr<'a>> for Node<'a> {
23109  fn from(node: &UpdateExpr<'a>) -> Node<'a> {
23110    let node = unsafe { mem::transmute::<&UpdateExpr<'a>, &'a UpdateExpr<'a>>(node) };
23111    Node::UpdateExpr(node)
23112  }
23113}
23114
23115impl<'a> NodeTrait<'a> for UpdateExpr<'a> {
23116  fn parent(&self) -> Option<Node<'a>> {
23117    Some(self.parent.get().unwrap().clone())
23118  }
23119
23120  fn children(&self) -> Vec<Node<'a>> {
23121    let mut children = Vec::with_capacity(1);
23122    children.push((&self.arg).into());
23123    children
23124  }
23125
23126  fn as_node(&self) -> Node<'a> {
23127    self.into()
23128  }
23129
23130  fn kind(&self) -> NodeKind {
23131    NodeKind::UpdateExpr
23132  }
23133}
23134
23135impl<'a> CastableNode<'a> for UpdateExpr<'a> {
23136  fn to(node: &Node<'a>) -> Option<&'a Self> {
23137    if let Node::UpdateExpr(node) = node {
23138      Some(node)
23139    } else {
23140      None
23141    }
23142  }
23143
23144  fn kind() -> NodeKind {
23145    NodeKind::UpdateExpr
23146  }
23147}
23148
23149fn get_view_for_update_expr<'a>(inner: &'a swc_ast::UpdateExpr, bump: &'a Bump) -> &'a UpdateExpr<'a> {
23150  let node = bump.alloc(UpdateExpr {
23151    inner,
23152    parent: Default::default(),
23153    arg: get_view_for_expr(&inner.arg, bump),
23154  });
23155  let parent: Node<'a> = (&*node).into();
23156  set_parent_for_expr(&node.arg, parent);
23157  node
23158}
23159
23160fn set_parent_for_update_expr<'a>(node: &UpdateExpr<'a>, parent: Node<'a>) {
23161  node.parent.set(parent);
23162}
23163
23164#[derive(Clone)]
23165pub struct UsingDecl<'a> {
23166  parent: ParentOnceCell<Node<'a>>,
23167  pub inner: &'a swc_ast::UsingDecl,
23168  pub decls: &'a [&'a VarDeclarator<'a>],
23169}
23170
23171impl<'a> UsingDecl<'a> {
23172  pub fn parent(&self) -> Node<'a> {
23173    self.parent.get().unwrap()
23174  }
23175
23176  pub fn is_await(&self) -> bool {
23177    self.inner.is_await
23178  }
23179}
23180
23181impl<'a> SourceRanged for UsingDecl<'a> {
23182  fn start(&self) -> SourcePos {
23183    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23184  }
23185  fn end(&self) -> SourcePos {
23186    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23187  }
23188}
23189
23190impl<'a> From<&UsingDecl<'a>> for Node<'a> {
23191  fn from(node: &UsingDecl<'a>) -> Node<'a> {
23192    let node = unsafe { mem::transmute::<&UsingDecl<'a>, &'a UsingDecl<'a>>(node) };
23193    Node::UsingDecl(node)
23194  }
23195}
23196
23197impl<'a> NodeTrait<'a> for UsingDecl<'a> {
23198  fn parent(&self) -> Option<Node<'a>> {
23199    Some(self.parent.get().unwrap().clone())
23200  }
23201
23202  fn children(&self) -> Vec<Node<'a>> {
23203    let mut children = Vec::with_capacity(self.decls.len());
23204    for child in self.decls.iter() {
23205      children.push((*child).into());
23206    }
23207    children
23208  }
23209
23210  fn as_node(&self) -> Node<'a> {
23211    self.into()
23212  }
23213
23214  fn kind(&self) -> NodeKind {
23215    NodeKind::UsingDecl
23216  }
23217}
23218
23219impl<'a> CastableNode<'a> for UsingDecl<'a> {
23220  fn to(node: &Node<'a>) -> Option<&'a Self> {
23221    if let Node::UsingDecl(node) = node {
23222      Some(node)
23223    } else {
23224      None
23225    }
23226  }
23227
23228  fn kind() -> NodeKind {
23229    NodeKind::UsingDecl
23230  }
23231}
23232
23233fn get_view_for_using_decl<'a>(inner: &'a swc_ast::UsingDecl, bump: &'a Bump) -> &'a UsingDecl<'a> {
23234  let node = bump.alloc(UsingDecl {
23235    inner,
23236    parent: Default::default(),
23237    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 }),
23238  });
23239  let parent: Node<'a> = (&*node).into();
23240  for value in node.decls.iter() {
23241    set_parent_for_var_declarator(value, parent)
23242  }
23243  node
23244}
23245
23246fn set_parent_for_using_decl<'a>(node: &UsingDecl<'a>, parent: Node<'a>) {
23247  node.parent.set(parent);
23248}
23249
23250#[derive(Clone)]
23251pub struct VarDecl<'a> {
23252  parent: ParentOnceCell<Node<'a>>,
23253  pub inner: &'a swc_ast::VarDecl,
23254  pub decls: &'a [&'a VarDeclarator<'a>],
23255}
23256
23257impl<'a> VarDecl<'a> {
23258  pub fn parent(&self) -> Node<'a> {
23259    self.parent.get().unwrap()
23260  }
23261
23262  pub fn ctxt(&self) -> swc_common::SyntaxContext {
23263    self.inner.ctxt
23264  }
23265
23266  pub fn decl_kind(&self) -> VarDeclKind {
23267    self.inner.kind
23268  }
23269
23270  pub fn declare(&self) -> bool {
23271    self.inner.declare
23272  }
23273}
23274
23275impl<'a> SourceRanged for VarDecl<'a> {
23276  fn start(&self) -> SourcePos {
23277    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23278  }
23279  fn end(&self) -> SourcePos {
23280    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23281  }
23282}
23283
23284impl<'a> From<&VarDecl<'a>> for Node<'a> {
23285  fn from(node: &VarDecl<'a>) -> Node<'a> {
23286    let node = unsafe { mem::transmute::<&VarDecl<'a>, &'a VarDecl<'a>>(node) };
23287    Node::VarDecl(node)
23288  }
23289}
23290
23291impl<'a> NodeTrait<'a> for VarDecl<'a> {
23292  fn parent(&self) -> Option<Node<'a>> {
23293    Some(self.parent.get().unwrap().clone())
23294  }
23295
23296  fn children(&self) -> Vec<Node<'a>> {
23297    let mut children = Vec::with_capacity(self.decls.len());
23298    for child in self.decls.iter() {
23299      children.push((*child).into());
23300    }
23301    children
23302  }
23303
23304  fn as_node(&self) -> Node<'a> {
23305    self.into()
23306  }
23307
23308  fn kind(&self) -> NodeKind {
23309    NodeKind::VarDecl
23310  }
23311}
23312
23313impl<'a> CastableNode<'a> for VarDecl<'a> {
23314  fn to(node: &Node<'a>) -> Option<&'a Self> {
23315    if let Node::VarDecl(node) = node {
23316      Some(node)
23317    } else {
23318      None
23319    }
23320  }
23321
23322  fn kind() -> NodeKind {
23323    NodeKind::VarDecl
23324  }
23325}
23326
23327fn get_view_for_var_decl<'a>(inner: &'a swc_ast::VarDecl, bump: &'a Bump) -> &'a VarDecl<'a> {
23328  let node = bump.alloc(VarDecl {
23329    inner,
23330    parent: Default::default(),
23331    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 }),
23332  });
23333  let parent: Node<'a> = (&*node).into();
23334  for value in node.decls.iter() {
23335    set_parent_for_var_declarator(value, parent)
23336  }
23337  node
23338}
23339
23340fn set_parent_for_var_decl<'a>(node: &VarDecl<'a>, parent: Node<'a>) {
23341  node.parent.set(parent);
23342}
23343
23344#[derive(Clone)]
23345pub struct VarDeclarator<'a> {
23346  parent: ParentOnceCell<Node<'a>>,
23347  pub inner: &'a swc_ast::VarDeclarator,
23348  pub name: Pat<'a>,
23349  /// Initialization expression.
23350  pub init: Option<Expr<'a>>,
23351}
23352
23353impl<'a> VarDeclarator<'a> {
23354  pub fn parent(&self) -> Node<'a> {
23355    self.parent.get().unwrap()
23356  }
23357
23358  /// Typescript only
23359  pub fn definite(&self) -> bool {
23360    self.inner.definite
23361  }
23362}
23363
23364impl<'a> SourceRanged for VarDeclarator<'a> {
23365  fn start(&self) -> SourcePos {
23366    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23367  }
23368  fn end(&self) -> SourcePos {
23369    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23370  }
23371}
23372
23373impl<'a> From<&VarDeclarator<'a>> for Node<'a> {
23374  fn from(node: &VarDeclarator<'a>) -> Node<'a> {
23375    let node = unsafe { mem::transmute::<&VarDeclarator<'a>, &'a VarDeclarator<'a>>(node) };
23376    Node::VarDeclarator(node)
23377  }
23378}
23379
23380impl<'a> NodeTrait<'a> for VarDeclarator<'a> {
23381  fn parent(&self) -> Option<Node<'a>> {
23382    Some(self.parent.get().unwrap().clone())
23383  }
23384
23385  fn children(&self) -> Vec<Node<'a>> {
23386    let mut children = Vec::with_capacity(1 + match &self.init { Some(_value) => 1, None => 0, });
23387    children.push((&self.name).into());
23388    if let Some(child) = self.init.as_ref() {
23389      children.push(child.into());
23390    }
23391    children
23392  }
23393
23394  fn as_node(&self) -> Node<'a> {
23395    self.into()
23396  }
23397
23398  fn kind(&self) -> NodeKind {
23399    NodeKind::VarDeclarator
23400  }
23401}
23402
23403impl<'a> CastableNode<'a> for VarDeclarator<'a> {
23404  fn to(node: &Node<'a>) -> Option<&'a Self> {
23405    if let Node::VarDeclarator(node) = node {
23406      Some(node)
23407    } else {
23408      None
23409    }
23410  }
23411
23412  fn kind() -> NodeKind {
23413    NodeKind::VarDeclarator
23414  }
23415}
23416
23417fn get_view_for_var_declarator<'a>(inner: &'a swc_ast::VarDeclarator, bump: &'a Bump) -> &'a VarDeclarator<'a> {
23418  let node = bump.alloc(VarDeclarator {
23419    inner,
23420    parent: Default::default(),
23421    name: get_view_for_pat(&inner.name, bump),
23422    init: match &inner.init {
23423      Some(value) => Some(get_view_for_expr(value, bump)),
23424      None => None,
23425    },
23426  });
23427  let parent: Node<'a> = (&*node).into();
23428  set_parent_for_pat(&node.name, parent);
23429  if let Some(value) = &node.init {
23430    set_parent_for_expr(value, parent)
23431  };
23432  node
23433}
23434
23435fn set_parent_for_var_declarator<'a>(node: &VarDeclarator<'a>, parent: Node<'a>) {
23436  node.parent.set(parent);
23437}
23438
23439#[derive(Clone)]
23440pub struct WhileStmt<'a> {
23441  parent: ParentOnceCell<Node<'a>>,
23442  pub inner: &'a swc_ast::WhileStmt,
23443  pub test: Expr<'a>,
23444  pub body: Stmt<'a>,
23445}
23446
23447impl<'a> WhileStmt<'a> {
23448  pub fn parent(&self) -> Node<'a> {
23449    self.parent.get().unwrap()
23450  }
23451}
23452
23453impl<'a> SourceRanged for WhileStmt<'a> {
23454  fn start(&self) -> SourcePos {
23455    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23456  }
23457  fn end(&self) -> SourcePos {
23458    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23459  }
23460}
23461
23462impl<'a> From<&WhileStmt<'a>> for Node<'a> {
23463  fn from(node: &WhileStmt<'a>) -> Node<'a> {
23464    let node = unsafe { mem::transmute::<&WhileStmt<'a>, &'a WhileStmt<'a>>(node) };
23465    Node::WhileStmt(node)
23466  }
23467}
23468
23469impl<'a> NodeTrait<'a> for WhileStmt<'a> {
23470  fn parent(&self) -> Option<Node<'a>> {
23471    Some(self.parent.get().unwrap().clone())
23472  }
23473
23474  fn children(&self) -> Vec<Node<'a>> {
23475    let mut children = Vec::with_capacity(2);
23476    children.push((&self.test).into());
23477    children.push((&self.body).into());
23478    children
23479  }
23480
23481  fn as_node(&self) -> Node<'a> {
23482    self.into()
23483  }
23484
23485  fn kind(&self) -> NodeKind {
23486    NodeKind::WhileStmt
23487  }
23488}
23489
23490impl<'a> CastableNode<'a> for WhileStmt<'a> {
23491  fn to(node: &Node<'a>) -> Option<&'a Self> {
23492    if let Node::WhileStmt(node) = node {
23493      Some(node)
23494    } else {
23495      None
23496    }
23497  }
23498
23499  fn kind() -> NodeKind {
23500    NodeKind::WhileStmt
23501  }
23502}
23503
23504fn get_view_for_while_stmt<'a>(inner: &'a swc_ast::WhileStmt, bump: &'a Bump) -> &'a WhileStmt<'a> {
23505  let node = bump.alloc(WhileStmt {
23506    inner,
23507    parent: Default::default(),
23508    test: get_view_for_expr(&inner.test, bump),
23509    body: get_view_for_stmt(&inner.body, bump),
23510  });
23511  let parent: Node<'a> = (&*node).into();
23512  set_parent_for_expr(&node.test, parent);
23513  set_parent_for_stmt(&node.body, parent);
23514  node
23515}
23516
23517fn set_parent_for_while_stmt<'a>(node: &WhileStmt<'a>, parent: Node<'a>) {
23518  node.parent.set(parent);
23519}
23520
23521#[derive(Clone)]
23522pub struct WithStmt<'a> {
23523  parent: ParentOnceCell<Node<'a>>,
23524  pub inner: &'a swc_ast::WithStmt,
23525  pub obj: Expr<'a>,
23526  pub body: Stmt<'a>,
23527}
23528
23529impl<'a> WithStmt<'a> {
23530  pub fn parent(&self) -> Node<'a> {
23531    self.parent.get().unwrap()
23532  }
23533}
23534
23535impl<'a> SourceRanged for WithStmt<'a> {
23536  fn start(&self) -> SourcePos {
23537    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23538  }
23539  fn end(&self) -> SourcePos {
23540    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23541  }
23542}
23543
23544impl<'a> From<&WithStmt<'a>> for Node<'a> {
23545  fn from(node: &WithStmt<'a>) -> Node<'a> {
23546    let node = unsafe { mem::transmute::<&WithStmt<'a>, &'a WithStmt<'a>>(node) };
23547    Node::WithStmt(node)
23548  }
23549}
23550
23551impl<'a> NodeTrait<'a> for WithStmt<'a> {
23552  fn parent(&self) -> Option<Node<'a>> {
23553    Some(self.parent.get().unwrap().clone())
23554  }
23555
23556  fn children(&self) -> Vec<Node<'a>> {
23557    let mut children = Vec::with_capacity(2);
23558    children.push((&self.obj).into());
23559    children.push((&self.body).into());
23560    children
23561  }
23562
23563  fn as_node(&self) -> Node<'a> {
23564    self.into()
23565  }
23566
23567  fn kind(&self) -> NodeKind {
23568    NodeKind::WithStmt
23569  }
23570}
23571
23572impl<'a> CastableNode<'a> for WithStmt<'a> {
23573  fn to(node: &Node<'a>) -> Option<&'a Self> {
23574    if let Node::WithStmt(node) = node {
23575      Some(node)
23576    } else {
23577      None
23578    }
23579  }
23580
23581  fn kind() -> NodeKind {
23582    NodeKind::WithStmt
23583  }
23584}
23585
23586fn get_view_for_with_stmt<'a>(inner: &'a swc_ast::WithStmt, bump: &'a Bump) -> &'a WithStmt<'a> {
23587  let node = bump.alloc(WithStmt {
23588    inner,
23589    parent: Default::default(),
23590    obj: get_view_for_expr(&inner.obj, bump),
23591    body: get_view_for_stmt(&inner.body, bump),
23592  });
23593  let parent: Node<'a> = (&*node).into();
23594  set_parent_for_expr(&node.obj, parent);
23595  set_parent_for_stmt(&node.body, parent);
23596  node
23597}
23598
23599fn set_parent_for_with_stmt<'a>(node: &WithStmt<'a>, parent: Node<'a>) {
23600  node.parent.set(parent);
23601}
23602
23603#[derive(Clone)]
23604pub struct YieldExpr<'a> {
23605  parent: ParentOnceCell<Node<'a>>,
23606  pub inner: &'a swc_ast::YieldExpr,
23607  pub arg: Option<Expr<'a>>,
23608}
23609
23610impl<'a> YieldExpr<'a> {
23611  pub fn parent(&self) -> Node<'a> {
23612    self.parent.get().unwrap()
23613  }
23614
23615  pub fn delegate(&self) -> bool {
23616    self.inner.delegate
23617  }
23618}
23619
23620impl<'a> SourceRanged for YieldExpr<'a> {
23621  fn start(&self) -> SourcePos {
23622    SourcePos::unsafely_from_byte_pos(self.inner.span().lo)
23623  }
23624  fn end(&self) -> SourcePos {
23625    SourcePos::unsafely_from_byte_pos(self.inner.span().hi)
23626  }
23627}
23628
23629impl<'a> From<&YieldExpr<'a>> for Node<'a> {
23630  fn from(node: &YieldExpr<'a>) -> Node<'a> {
23631    let node = unsafe { mem::transmute::<&YieldExpr<'a>, &'a YieldExpr<'a>>(node) };
23632    Node::YieldExpr(node)
23633  }
23634}
23635
23636impl<'a> NodeTrait<'a> for YieldExpr<'a> {
23637  fn parent(&self) -> Option<Node<'a>> {
23638    Some(self.parent.get().unwrap().clone())
23639  }
23640
23641  fn children(&self) -> Vec<Node<'a>> {
23642    let mut children = Vec::with_capacity(match &self.arg { Some(_value) => 1, None => 0, });
23643    if let Some(child) = self.arg.as_ref() {
23644      children.push(child.into());
23645    }
23646    children
23647  }
23648
23649  fn as_node(&self) -> Node<'a> {
23650    self.into()
23651  }
23652
23653  fn kind(&self) -> NodeKind {
23654    NodeKind::YieldExpr
23655  }
23656}
23657
23658impl<'a> CastableNode<'a> for YieldExpr<'a> {
23659  fn to(node: &Node<'a>) -> Option<&'a Self> {
23660    if let Node::YieldExpr(node) = node {
23661      Some(node)
23662    } else {
23663      None
23664    }
23665  }
23666
23667  fn kind() -> NodeKind {
23668    NodeKind::YieldExpr
23669  }
23670}
23671
23672fn get_view_for_yield_expr<'a>(inner: &'a swc_ast::YieldExpr, bump: &'a Bump) -> &'a YieldExpr<'a> {
23673  let node = bump.alloc(YieldExpr {
23674    inner,
23675    parent: Default::default(),
23676    arg: match &inner.arg {
23677      Some(value) => Some(get_view_for_expr(value, bump)),
23678      None => None,
23679    },
23680  });
23681  let parent: Node<'a> = (&*node).into();
23682  if let Some(value) = &node.arg {
23683    set_parent_for_expr(value, parent)
23684  };
23685  node
23686}
23687
23688fn set_parent_for_yield_expr<'a>(node: &YieldExpr<'a>, parent: Node<'a>) {
23689  node.parent.set(parent);
23690}
23691
23692struct ParentOnceCell<T> {
23693  cell: std::cell::UnsafeCell<Option<T>>,
23694}
23695
23696impl<T> ParentOnceCell<T> {
23697  pub fn get(&self) -> &Option<T> {
23698    unsafe { &*self.cell.get() }
23699  }
23700
23701  #[cold]
23702  pub fn set(&self, value: T) {
23703    unsafe {
23704      let inner = self.cell.get();
23705      inner.replace(Some(value));
23706    }
23707  }
23708}
23709
23710impl<T> Default for ParentOnceCell<T> {
23711  fn default() -> Self {
23712    Self {
23713      cell: std::cell::UnsafeCell::new(None),
23714    }
23715  }
23716}
23717
23718impl<T: Clone> Clone for ParentOnceCell<T> {
23719  fn clone(&self) -> Self {
23720    Self {
23721      cell: std::cell::UnsafeCell::new(self.get().clone()),
23722    }
23723  }
23724}
23725