Skip to main content

swc_ecma_ast/
typescript.rs

1#![allow(clippy::vec_box)]
2#![allow(missing_copy_implementations)]
3
4#[cfg(feature = "serde-impl")]
5use std::fmt;
6
7use is_macro::Is;
8#[cfg(feature = "serde-impl")]
9use serde::{
10    de::{self, Unexpected, Visitor},
11    Deserialize, Deserializer, Serialize,
12};
13use string_enum::StringEnum;
14use swc_common::{ast_node, EqIgnoreSpan, Span};
15
16use crate::{
17    class::Decorator,
18    expr::{Expr, ObjectLit},
19    ident::Ident,
20    lit::{Bool, Number, Str},
21    module::ModuleItem,
22    pat::{ArrayPat, AssignPat, ObjectPat, Pat, RestPat},
23    BigInt, BindingIdent, IdentName, TplElement,
24};
25
26#[ast_node("TsTypeAnnotation")]
27#[derive(Eq, Hash, EqIgnoreSpan)]
28#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
29#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
30pub struct TsTypeAnn {
31    pub span: Span,
32    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
33    pub type_ann: Box<TsType>,
34}
35
36/// TypeScript or Flow `this` parameter of a function.
37///
38/// This parameter describes the type of `this` inside the function and is not
39/// emitted as a JavaScript runtime parameter.
40#[ast_node("TsThisParameter")]
41#[derive(Eq, Hash, EqIgnoreSpan)]
42#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
43#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
44pub struct TsThisParam {
45    pub span: Span,
46    #[cfg_attr(feature = "serde-impl", serde(rename = "thisSpan"))]
47    pub this_span: Span,
48    #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
49    #[cfg_attr(
50        feature = "encoding-impl",
51        encoding(with = "cbor4ii::core::types::Maybe")
52    )]
53    pub type_ann: Option<Box<TsTypeAnn>>,
54}
55
56#[ast_node("TsTypeParameterDeclaration")]
57#[derive(Eq, Hash, EqIgnoreSpan)]
58#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
59#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
60pub struct TsTypeParamDecl {
61    pub span: Span,
62    #[cfg_attr(feature = "serde-impl", serde(rename = "parameters"))]
63    pub params: Vec<TsTypeParam>,
64}
65
66#[ast_node("TsTypeParameter")]
67#[derive(Eq, Hash, EqIgnoreSpan)]
68#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
69#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
70pub struct TsTypeParam {
71    pub span: Span,
72    pub name: Ident,
73
74    #[cfg_attr(feature = "serde-impl", serde(default, rename = "in"))]
75    pub is_in: bool,
76
77    #[cfg_attr(feature = "serde-impl", serde(default, rename = "out"))]
78    pub is_out: bool,
79
80    #[cfg_attr(feature = "serde-impl", serde(default, rename = "const"))]
81    pub is_const: bool,
82
83    #[cfg_attr(feature = "serde-impl", serde(default))]
84    #[cfg_attr(
85        feature = "encoding-impl",
86        encoding(with = "cbor4ii::core::types::Maybe")
87    )]
88    pub constraint: Option<Box<TsType>>,
89
90    #[cfg_attr(feature = "serde-impl", serde(default))]
91    #[cfg_attr(
92        feature = "encoding-impl",
93        encoding(with = "cbor4ii::core::types::Maybe")
94    )]
95    pub default: Option<Box<TsType>>,
96}
97
98#[ast_node("TsTypeParameterInstantiation")]
99#[derive(Eq, Hash, EqIgnoreSpan)]
100#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
101#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
102pub struct TsTypeParamInstantiation {
103    pub span: Span,
104    pub params: Vec<Box<TsType>>,
105}
106
107#[ast_node("TsParameterProperty")]
108#[derive(Eq, Hash, EqIgnoreSpan)]
109#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
110#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
111pub struct TsParamProp {
112    pub span: Span,
113    #[cfg_attr(feature = "serde-impl", serde(default))]
114    pub decorators: Vec<Decorator>,
115    /// At least one of `accessibility` or `readonly` must be set.
116    #[cfg_attr(feature = "serde-impl", serde(default))]
117    #[cfg_attr(
118        feature = "encoding-impl",
119        encoding(with = "cbor4ii::core::types::Maybe")
120    )]
121    pub accessibility: Option<Accessibility>,
122    #[cfg_attr(feature = "serde-impl", serde(rename = "override"))]
123    pub is_override: bool,
124    pub readonly: bool,
125    pub param: TsParamPropParam,
126}
127
128#[ast_node]
129#[derive(Eq, Hash, Is, EqIgnoreSpan)]
130#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
131#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
132pub enum TsParamPropParam {
133    #[tag("Identifier")]
134    Ident(BindingIdent),
135
136    #[tag("AssignmentPattern")]
137    Assign(AssignPat),
138}
139
140#[ast_node("TsQualifiedName")]
141#[derive(Eq, Hash, EqIgnoreSpan)]
142#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
143#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
144pub struct TsQualifiedName {
145    pub span: Span,
146    pub left: TsEntityName,
147    pub right: IdentName,
148}
149
150#[ast_node]
151#[derive(Eq, Hash, Is, EqIgnoreSpan)]
152#[allow(variant_size_differences)]
153#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
154#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
155pub enum TsEntityName {
156    #[tag("TsQualifiedName")]
157    TsQualifiedName(Box<TsQualifiedName>),
158
159    #[tag("Identifier")]
160    Ident(Ident),
161}
162
163// ================
164// TypeScript type members (for type literal / interface / class)
165// ================
166
167#[ast_node]
168#[derive(Eq, Hash, Is, EqIgnoreSpan)]
169#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
170#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
171pub enum TsTypeElement {
172    #[tag("TsCallSignatureDeclaration")]
173    TsCallSignatureDecl(TsCallSignatureDecl),
174
175    #[tag("TsConstructSignatureDeclaration")]
176    TsConstructSignatureDecl(TsConstructSignatureDecl),
177
178    #[tag("TsPropertySignature")]
179    TsPropertySignature(TsPropertySignature),
180
181    #[tag("TsGetterSignature")]
182    TsGetterSignature(TsGetterSignature),
183
184    #[tag("TsSetterSignature")]
185    TsSetterSignature(TsSetterSignature),
186
187    #[tag("TsMethodSignature")]
188    TsMethodSignature(TsMethodSignature),
189
190    #[tag("TsIndexSignature")]
191    TsIndexSignature(TsIndexSignature),
192}
193
194#[ast_node("TsCallSignatureDeclaration")]
195#[derive(Eq, Hash, EqIgnoreSpan)]
196#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
197#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
198pub struct TsCallSignatureDecl {
199    pub span: Span,
200    pub params: Vec<TsFnParam>,
201    #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
202    #[cfg_attr(
203        feature = "encoding-impl",
204        encoding(with = "cbor4ii::core::types::Maybe")
205    )]
206    pub type_ann: Option<Box<TsTypeAnn>>,
207    #[cfg_attr(feature = "serde-impl", serde(default))]
208    #[cfg_attr(
209        feature = "encoding-impl",
210        encoding(with = "cbor4ii::core::types::Maybe")
211    )]
212    pub type_params: Option<Box<TsTypeParamDecl>>,
213}
214
215#[ast_node("TsConstructSignatureDeclaration")]
216#[derive(Eq, Hash, EqIgnoreSpan)]
217#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
218#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
219pub struct TsConstructSignatureDecl {
220    pub span: Span,
221    pub params: Vec<TsFnParam>,
222    #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
223    #[cfg_attr(
224        feature = "encoding-impl",
225        encoding(with = "cbor4ii::core::types::Maybe")
226    )]
227    pub type_ann: Option<Box<TsTypeAnn>>,
228    #[cfg_attr(feature = "serde-impl", serde(default))]
229    #[cfg_attr(
230        feature = "encoding-impl",
231        encoding(with = "cbor4ii::core::types::Maybe")
232    )]
233    pub type_params: Option<Box<TsTypeParamDecl>>,
234}
235
236#[ast_node("TsPropertySignature")]
237#[derive(Eq, Hash, EqIgnoreSpan)]
238#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
239#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
240pub struct TsPropertySignature {
241    pub span: Span,
242    pub readonly: bool,
243    pub key: Box<Expr>,
244    pub computed: bool,
245    pub optional: bool,
246    #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
247    #[cfg_attr(
248        feature = "encoding-impl",
249        encoding(with = "cbor4ii::core::types::Maybe")
250    )]
251    pub type_ann: Option<Box<TsTypeAnn>>,
252}
253
254#[ast_node("TsGetterSignature")]
255#[derive(Eq, Hash, EqIgnoreSpan)]
256#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
257#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
258pub struct TsGetterSignature {
259    pub span: Span,
260    pub key: Box<Expr>,
261    pub computed: bool,
262    #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
263    #[cfg_attr(
264        feature = "encoding-impl",
265        encoding(with = "cbor4ii::core::types::Maybe")
266    )]
267    pub type_ann: Option<Box<TsTypeAnn>>,
268}
269
270#[ast_node("TsSetterSignature")]
271#[derive(Eq, Hash, EqIgnoreSpan)]
272#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
273#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
274pub struct TsSetterSignature {
275    pub span: Span,
276    pub key: Box<Expr>,
277    pub computed: bool,
278    pub param: TsFnParam,
279}
280
281#[ast_node("TsMethodSignature")]
282#[derive(Eq, Hash, EqIgnoreSpan)]
283#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
284#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
285pub struct TsMethodSignature {
286    pub span: Span,
287    pub key: Box<Expr>,
288    pub computed: bool,
289    pub optional: bool,
290    pub params: Vec<TsFnParam>,
291    #[cfg_attr(feature = "serde-impl", serde(default))]
292    #[cfg_attr(
293        feature = "encoding-impl",
294        encoding(with = "cbor4ii::core::types::Maybe")
295    )]
296    pub type_ann: Option<Box<TsTypeAnn>>,
297    #[cfg_attr(feature = "serde-impl", serde(default))]
298    #[cfg_attr(
299        feature = "encoding-impl",
300        encoding(with = "cbor4ii::core::types::Maybe")
301    )]
302    pub type_params: Option<Box<TsTypeParamDecl>>,
303}
304
305#[ast_node("TsIndexSignature")]
306#[derive(Eq, Hash, EqIgnoreSpan)]
307#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
308#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
309pub struct TsIndexSignature {
310    pub params: Vec<TsFnParam>,
311    #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
312    #[cfg_attr(
313        feature = "encoding-impl",
314        encoding(with = "cbor4ii::core::types::Maybe")
315    )]
316    pub type_ann: Option<Box<TsTypeAnn>>,
317
318    pub readonly: bool,
319    #[cfg_attr(feature = "serde-impl", serde(rename = "static"))]
320    pub is_static: bool,
321    pub span: Span,
322}
323
324// ================
325// TypeScript types
326// ================
327
328#[ast_node(no_clone)]
329#[derive(Eq, Hash, Is, EqIgnoreSpan)]
330#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
331#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
332pub enum TsType {
333    #[tag("TsKeywordType")]
334    TsKeywordType(TsKeywordType),
335
336    #[tag("TsThisType")]
337    TsThisType(TsThisType),
338
339    #[tag("TsFunctionType")]
340    #[tag("TsConstructorType")]
341    TsFnOrConstructorType(TsFnOrConstructorType),
342
343    #[tag("TsTypeReference")]
344    TsTypeRef(TsTypeRef),
345
346    #[tag("TsTypeQuery")]
347    TsTypeQuery(TsTypeQuery),
348
349    #[tag("TsTypeLiteral")]
350    TsTypeLit(TsTypeLit),
351
352    #[tag("TsArrayType")]
353    TsArrayType(TsArrayType),
354
355    #[tag("TsTupleType")]
356    TsTupleType(TsTupleType),
357
358    #[tag("TsOptionalType")]
359    TsOptionalType(TsOptionalType),
360
361    #[tag("TsRestType")]
362    TsRestType(TsRestType),
363
364    #[tag("TsUnionType")]
365    #[tag("TsIntersectionType")]
366    TsUnionOrIntersectionType(TsUnionOrIntersectionType),
367
368    #[tag("TsConditionalType")]
369    TsConditionalType(TsConditionalType),
370
371    #[tag("TsInferType")]
372    TsInferType(TsInferType),
373
374    #[tag("TsParenthesizedType")]
375    TsParenthesizedType(TsParenthesizedType),
376
377    #[tag("TsTypeOperator")]
378    TsTypeOperator(TsTypeOperator),
379
380    #[tag("TsIndexedAccessType")]
381    TsIndexedAccessType(TsIndexedAccessType),
382
383    #[tag("TsMappedType")]
384    TsMappedType(TsMappedType),
385
386    #[tag("TsLiteralType")]
387    TsLitType(TsLitType),
388
389    #[tag("TsTypePredicate")]
390    TsTypePredicate(TsTypePredicate),
391
392    #[tag("TsImportType")]
393    TsImportType(TsImportType),
394}
395
396// Implement Clone without inline to avoid multiple copies of the
397// implementation.
398impl Clone for TsType {
399    fn clone(&self) -> Self {
400        use TsType::*;
401        match self {
402            #[cfg(all(swc_ast_unknown, feature = "encoding-impl"))]
403            Unknown(tag, v) => Unknown(*tag, v.clone()),
404            TsKeywordType(t) => TsKeywordType(t.clone()),
405            TsThisType(t) => TsThisType(t.clone()),
406            TsFnOrConstructorType(t) => TsFnOrConstructorType(t.clone()),
407            TsTypeRef(t) => TsTypeRef(t.clone()),
408            TsTypeQuery(t) => TsTypeQuery(t.clone()),
409            TsTypeLit(t) => TsTypeLit(t.clone()),
410            TsArrayType(t) => TsArrayType(t.clone()),
411            TsTupleType(t) => TsTupleType(t.clone()),
412            TsOptionalType(t) => TsOptionalType(t.clone()),
413            TsRestType(t) => TsRestType(t.clone()),
414            TsUnionOrIntersectionType(t) => TsUnionOrIntersectionType(t.clone()),
415            TsConditionalType(t) => TsConditionalType(t.clone()),
416            TsInferType(t) => TsInferType(t.clone()),
417            TsParenthesizedType(t) => TsParenthesizedType(t.clone()),
418            TsTypeOperator(t) => TsTypeOperator(t.clone()),
419            TsIndexedAccessType(t) => TsIndexedAccessType(t.clone()),
420            TsMappedType(t) => TsMappedType(t.clone()),
421            TsLitType(t) => TsLitType(t.clone()),
422            TsTypePredicate(t) => TsTypePredicate(t.clone()),
423            TsImportType(t) => TsImportType(t.clone()),
424        }
425    }
426}
427
428#[ast_node]
429#[derive(Eq, Hash, Is, EqIgnoreSpan)]
430#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
431#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
432pub enum TsFnOrConstructorType {
433    #[tag("TsFunctionType")]
434    TsFnType(TsFnType),
435    #[tag("TsConstructorType")]
436    TsConstructorType(TsConstructorType),
437}
438
439impl From<TsFnType> for TsType {
440    fn from(t: TsFnType) -> Self {
441        TsFnOrConstructorType::TsFnType(t).into()
442    }
443}
444
445impl From<TsConstructorType> for TsType {
446    fn from(t: TsConstructorType) -> Self {
447        TsFnOrConstructorType::TsConstructorType(t).into()
448    }
449}
450
451impl From<TsUnionType> for TsType {
452    fn from(t: TsUnionType) -> Self {
453        TsUnionOrIntersectionType::TsUnionType(t).into()
454    }
455}
456
457impl From<TsIntersectionType> for TsType {
458    fn from(t: TsIntersectionType) -> Self {
459        TsUnionOrIntersectionType::TsIntersectionType(t).into()
460    }
461}
462
463#[ast_node("TsKeywordType")]
464#[derive(Eq, Hash, EqIgnoreSpan)]
465#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
466#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
467pub struct TsKeywordType {
468    pub span: Span,
469    pub kind: TsKeywordTypeKind,
470}
471
472#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, EqIgnoreSpan)]
473#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
474#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
475#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
476#[cfg_attr(
477    feature = "encoding-impl",
478    derive(::swc_common::Encode, ::swc_common::Decode)
479)]
480#[cfg_attr(swc_ast_unknown, non_exhaustive)]
481pub enum TsKeywordTypeKind {
482    #[cfg_attr(feature = "serde-impl", serde(rename = "any"))]
483    TsAnyKeyword,
484
485    #[cfg_attr(feature = "serde-impl", serde(rename = "unknown"))]
486    TsUnknownKeyword,
487
488    #[cfg_attr(feature = "serde-impl", serde(rename = "number"))]
489    TsNumberKeyword,
490
491    #[cfg_attr(feature = "serde-impl", serde(rename = "object"))]
492    TsObjectKeyword,
493
494    #[cfg_attr(feature = "serde-impl", serde(rename = "boolean"))]
495    TsBooleanKeyword,
496
497    #[cfg_attr(feature = "serde-impl", serde(rename = "bigint"))]
498    TsBigIntKeyword,
499
500    #[cfg_attr(feature = "serde-impl", serde(rename = "string"))]
501    TsStringKeyword,
502
503    #[cfg_attr(feature = "serde-impl", serde(rename = "symbol"))]
504    TsSymbolKeyword,
505
506    #[cfg_attr(feature = "serde-impl", serde(rename = "void"))]
507    TsVoidKeyword,
508
509    #[cfg_attr(feature = "serde-impl", serde(rename = "undefined"))]
510    TsUndefinedKeyword,
511
512    #[cfg_attr(feature = "serde-impl", serde(rename = "null"))]
513    TsNullKeyword,
514
515    #[cfg_attr(feature = "serde-impl", serde(rename = "never"))]
516    TsNeverKeyword,
517
518    #[cfg_attr(feature = "serde-impl", serde(rename = "intrinsic"))]
519    TsIntrinsicKeyword,
520}
521
522#[ast_node("TsThisType")]
523#[derive(Copy, Eq, Hash, EqIgnoreSpan)]
524#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
525#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
526pub struct TsThisType {
527    pub span: Span,
528}
529
530#[ast_node]
531#[derive(Eq, Hash, Is, EqIgnoreSpan)]
532#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
533#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
534pub enum TsFnParam {
535    #[tag("Identifier")]
536    Ident(BindingIdent),
537
538    #[tag("ArrayPattern")]
539    Array(ArrayPat),
540
541    #[tag("RestElement")]
542    Rest(RestPat),
543
544    #[tag("ObjectPattern")]
545    Object(ObjectPat),
546}
547
548#[ast_node("TsFunctionType")]
549#[derive(Eq, Hash, EqIgnoreSpan)]
550#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
551#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
552pub struct TsFnType {
553    pub span: Span,
554    pub params: Vec<TsFnParam>,
555
556    #[cfg_attr(feature = "serde-impl", serde(default))]
557    #[cfg_attr(
558        feature = "encoding-impl",
559        encoding(with = "cbor4ii::core::types::Maybe")
560    )]
561    pub type_params: Option<Box<TsTypeParamDecl>>,
562    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
563    pub type_ann: Box<TsTypeAnn>,
564}
565
566#[ast_node("TsConstructorType")]
567#[derive(Eq, Hash, EqIgnoreSpan)]
568#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
569#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
570pub struct TsConstructorType {
571    pub span: Span,
572    pub params: Vec<TsFnParam>,
573    #[cfg_attr(feature = "serde-impl", serde(default))]
574    #[cfg_attr(
575        feature = "encoding-impl",
576        encoding(with = "cbor4ii::core::types::Maybe")
577    )]
578    pub type_params: Option<Box<TsTypeParamDecl>>,
579    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
580    pub type_ann: Box<TsTypeAnn>,
581    pub is_abstract: bool,
582}
583
584#[ast_node("TsTypeReference")]
585#[derive(Eq, Hash, EqIgnoreSpan)]
586#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
587#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
588pub struct TsTypeRef {
589    pub span: Span,
590    pub type_name: TsEntityName,
591    #[cfg_attr(feature = "serde-impl", serde(default))]
592    #[cfg_attr(
593        feature = "encoding-impl",
594        encoding(with = "cbor4ii::core::types::Maybe")
595    )]
596    pub type_params: Option<Box<TsTypeParamInstantiation>>,
597}
598
599#[ast_node("TsTypePredicate")]
600#[derive(Eq, Hash, EqIgnoreSpan)]
601#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
602#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
603pub struct TsTypePredicate {
604    pub span: Span,
605    pub asserts: bool,
606    pub param_name: TsThisTypeOrIdent,
607    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
608    #[cfg_attr(
609        feature = "encoding-impl",
610        encoding(with = "cbor4ii::core::types::Maybe")
611    )]
612    pub type_ann: Option<Box<TsTypeAnn>>,
613}
614
615#[ast_node]
616#[derive(Eq, Hash, Is, EqIgnoreSpan)]
617#[allow(variant_size_differences)]
618#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
619#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
620pub enum TsThisTypeOrIdent {
621    #[tag("TsThisType")]
622    TsThisType(TsThisType),
623
624    #[tag("Identifier")]
625    Ident(Ident),
626}
627
628/// `typeof` operator
629#[ast_node("TsTypeQuery")]
630#[derive(Eq, Hash, EqIgnoreSpan)]
631#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
632#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
633pub struct TsTypeQuery {
634    pub span: Span,
635    pub expr_name: TsTypeQueryExpr,
636    #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeArguments"))]
637    #[cfg_attr(
638        feature = "encoding-impl",
639        encoding(with = "cbor4ii::core::types::Maybe")
640    )]
641    pub type_args: Option<Box<TsTypeParamInstantiation>>,
642}
643
644#[ast_node]
645#[derive(Eq, Hash, Is, EqIgnoreSpan)]
646#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
647#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
648pub enum TsTypeQueryExpr {
649    #[tag("TsQualifiedName")]
650    #[tag("Identifier")]
651    TsEntityName(TsEntityName),
652    #[tag("TsImportType")]
653    Import(TsImportType),
654}
655
656#[ast_node("TsImportCallOptions")]
657#[derive(Eq, Hash, EqIgnoreSpan)]
658#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
659#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
660pub struct TsImportCallOptions {
661    pub span: Span,
662    #[cfg_attr(feature = "serde-impl", serde(default))]
663    pub with: Box<ObjectLit>,
664}
665
666#[ast_node("TsImportType")]
667#[derive(Eq, Hash, EqIgnoreSpan)]
668#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
669#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
670pub struct TsImportType {
671    pub span: Span,
672    #[cfg_attr(feature = "serde-impl", serde(rename = "argument"))]
673    pub arg: Str,
674    #[cfg_attr(
675        feature = "encoding-impl",
676        encoding(with = "cbor4ii::core::types::Maybe")
677    )]
678    pub qualifier: Option<TsEntityName>,
679    #[cfg_attr(feature = "serde-impl", serde(rename = "typeArguments"))]
680    #[cfg_attr(
681        feature = "encoding-impl",
682        encoding(with = "cbor4ii::core::types::Maybe")
683    )]
684    pub type_args: Option<Box<TsTypeParamInstantiation>>,
685    #[cfg_attr(feature = "serde-impl", serde(default))]
686    #[cfg_attr(
687        feature = "encoding-impl",
688        encoding(with = "cbor4ii::core::types::Maybe")
689    )]
690    pub attributes: Option<TsImportCallOptions>,
691}
692
693#[ast_node("TsTypeLiteral")]
694#[derive(Eq, Hash, EqIgnoreSpan)]
695#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
696#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
697pub struct TsTypeLit {
698    pub span: Span,
699    pub members: Vec<TsTypeElement>,
700}
701
702#[ast_node("TsArrayType")]
703#[derive(Eq, Hash, EqIgnoreSpan)]
704#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
705#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
706pub struct TsArrayType {
707    pub span: Span,
708    pub elem_type: Box<TsType>,
709}
710
711#[ast_node("TsTupleType")]
712#[derive(Eq, Hash, EqIgnoreSpan)]
713#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
714#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
715pub struct TsTupleType {
716    pub span: Span,
717    pub elem_types: Vec<TsTupleElement>,
718}
719
720#[ast_node("TsTupleElement")]
721#[derive(Eq, Hash, EqIgnoreSpan)]
722#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
723#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
724pub struct TsTupleElement {
725    pub span: Span,
726    /// `Ident` or `RestPat { arg: Ident }`
727    #[cfg_attr(
728        feature = "encoding-impl",
729        encoding(with = "cbor4ii::core::types::Maybe")
730    )]
731    pub label: Option<Pat>,
732    pub ty: Box<TsType>,
733}
734
735#[ast_node("TsOptionalType")]
736#[derive(Eq, Hash, EqIgnoreSpan)]
737#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
738#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
739pub struct TsOptionalType {
740    pub span: Span,
741    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
742    pub type_ann: Box<TsType>,
743}
744
745#[ast_node("TsRestType")]
746#[derive(Eq, Hash, EqIgnoreSpan)]
747#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
748#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
749pub struct TsRestType {
750    pub span: Span,
751    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
752    pub type_ann: Box<TsType>,
753}
754
755#[ast_node]
756#[derive(Eq, Hash, Is, EqIgnoreSpan)]
757#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
758#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
759pub enum TsUnionOrIntersectionType {
760    #[tag("TsUnionType")]
761    TsUnionType(TsUnionType),
762
763    #[tag("TsIntersectionType")]
764    TsIntersectionType(TsIntersectionType),
765}
766
767#[ast_node("TsUnionType")]
768#[derive(Eq, Hash, EqIgnoreSpan)]
769#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
770#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
771pub struct TsUnionType {
772    pub span: Span,
773    pub types: Vec<Box<TsType>>,
774}
775
776#[ast_node("TsIntersectionType")]
777#[derive(Eq, Hash, EqIgnoreSpan)]
778#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
779#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
780pub struct TsIntersectionType {
781    pub span: Span,
782    pub types: Vec<Box<TsType>>,
783}
784
785#[ast_node("TsConditionalType")]
786#[derive(Eq, Hash, EqIgnoreSpan)]
787#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
788#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
789pub struct TsConditionalType {
790    pub span: Span,
791    pub check_type: Box<TsType>,
792    pub extends_type: Box<TsType>,
793    pub true_type: Box<TsType>,
794    pub false_type: Box<TsType>,
795}
796
797#[ast_node("TsInferType")]
798#[derive(Eq, Hash, EqIgnoreSpan)]
799#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
800#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
801pub struct TsInferType {
802    pub span: Span,
803    pub type_param: TsTypeParam,
804}
805
806#[ast_node("TsParenthesizedType")]
807#[derive(Eq, Hash, EqIgnoreSpan)]
808#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
809#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
810pub struct TsParenthesizedType {
811    pub span: Span,
812    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
813    pub type_ann: Box<TsType>,
814}
815
816#[ast_node("TsTypeOperator")]
817#[derive(Eq, Hash, EqIgnoreSpan)]
818#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
819#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
820pub struct TsTypeOperator {
821    pub span: Span,
822    pub op: TsTypeOperatorOp,
823    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
824    pub type_ann: Box<TsType>,
825}
826
827#[derive(StringEnum, Clone, Copy, PartialEq, Eq, Hash, EqIgnoreSpan)]
828#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
829#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
830#[cfg_attr(
831    feature = "encoding-impl",
832    derive(::swc_common::Encode, ::swc_common::Decode)
833)]
834#[cfg_attr(swc_ast_unknown, non_exhaustive)]
835pub enum TsTypeOperatorOp {
836    /// `keyof`
837    KeyOf,
838    /// `unique`
839    Unique,
840    /// `readonly`
841    ReadOnly,
842}
843
844#[ast_node("TsIndexedAccessType")]
845#[derive(Eq, Hash, EqIgnoreSpan)]
846#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
847#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
848pub struct TsIndexedAccessType {
849    pub span: Span,
850    pub readonly: bool,
851    #[cfg_attr(feature = "serde-impl", serde(rename = "objectType"))]
852    pub obj_type: Box<TsType>,
853    pub index_type: Box<TsType>,
854}
855
856#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EqIgnoreSpan)]
857#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
858#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
859#[cfg_attr(
860    feature = "encoding-impl",
861    derive(::swc_common::Encode, ::swc_common::Decode)
862)]
863#[cfg_attr(swc_ast_unknown, non_exhaustive)]
864pub enum TruePlusMinus {
865    True,
866    Plus,
867    Minus,
868}
869
870#[cfg(feature = "serde-impl")]
871impl Serialize for TruePlusMinus {
872    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
873    where
874        S: ::serde::Serializer,
875    {
876        match *self {
877            TruePlusMinus::True => serializer.serialize_bool(true),
878            TruePlusMinus::Plus => serializer.serialize_str("+"),
879            TruePlusMinus::Minus => serializer.serialize_str("-"),
880        }
881    }
882}
883
884#[cfg(feature = "serde-impl")]
885impl<'de> Deserialize<'de> for TruePlusMinus {
886    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
887    where
888        D: Deserializer<'de>,
889    {
890        struct TruePlusMinusVisitor;
891
892        impl Visitor<'_> for TruePlusMinusVisitor {
893            type Value = TruePlusMinus;
894
895            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
896                formatter.write_str("one of '+', '-', true")
897            }
898
899            fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
900            where
901                E: de::Error,
902            {
903                match value {
904                    "+" => Ok(TruePlusMinus::Plus),
905                    "-" => Ok(TruePlusMinus::Minus),
906                    "true" => Ok(TruePlusMinus::True),
907                    _ => Err(de::Error::invalid_value(Unexpected::Str(value), &self)),
908                }
909            }
910
911            fn visit_bool<E>(self, value: bool) -> Result<Self::Value, E>
912            where
913                E: de::Error,
914            {
915                if value {
916                    Ok(TruePlusMinus::True)
917                } else {
918                    Err(de::Error::invalid_value(Unexpected::Bool(value), &self))
919                }
920            }
921        }
922
923        deserializer.deserialize_any(TruePlusMinusVisitor)
924    }
925}
926
927#[ast_node("TsMappedType")]
928#[derive(Eq, Hash, EqIgnoreSpan)]
929#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
930#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
931pub struct TsMappedType {
932    pub span: Span,
933    #[cfg_attr(feature = "serde-impl", serde(default))]
934    #[cfg_attr(
935        feature = "encoding-impl",
936        encoding(with = "cbor4ii::core::types::Maybe")
937    )]
938    pub readonly: Option<TruePlusMinus>,
939    pub type_param: TsTypeParam,
940    #[cfg_attr(feature = "serde-impl", serde(default, rename = "nameType"))]
941    #[cfg_attr(
942        feature = "encoding-impl",
943        encoding(with = "cbor4ii::core::types::Maybe")
944    )]
945    pub name_type: Option<Box<TsType>>,
946    #[cfg_attr(feature = "serde-impl", serde(default))]
947    #[cfg_attr(
948        feature = "encoding-impl",
949        encoding(with = "cbor4ii::core::types::Maybe")
950    )]
951    pub optional: Option<TruePlusMinus>,
952    #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
953    #[cfg_attr(
954        feature = "encoding-impl",
955        encoding(with = "cbor4ii::core::types::Maybe")
956    )]
957    pub type_ann: Option<Box<TsType>>,
958}
959
960#[ast_node("TsLiteralType")]
961#[derive(Eq, Hash, EqIgnoreSpan)]
962#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
963#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
964pub struct TsLitType {
965    pub span: Span,
966    #[cfg_attr(feature = "serde-impl", serde(rename = "literal"))]
967    pub lit: TsLit,
968}
969
970#[ast_node]
971#[derive(Eq, Hash, Is, EqIgnoreSpan)]
972#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
973#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
974pub enum TsLit {
975    #[tag("NumericLiteral")]
976    Number(Number),
977
978    #[tag("StringLiteral")]
979    Str(Str),
980
981    #[tag("BooleanLiteral")]
982    Bool(Bool),
983
984    #[tag("BigIntLiteral")]
985    BigInt(BigInt),
986
987    #[tag("TemplateLiteral")]
988    Tpl(TsTplLitType),
989}
990
991#[ast_node("TemplateLiteral")]
992#[derive(Eq, Hash, EqIgnoreSpan)]
993#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
994#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
995pub struct TsTplLitType {
996    pub span: Span,
997
998    pub types: Vec<Box<TsType>>,
999
1000    pub quasis: Vec<TplElement>,
1001}
1002
1003// // ================
1004// // TypeScript declarations
1005// // ================
1006
1007#[ast_node("TsInterfaceDeclaration")]
1008#[derive(Eq, Hash, EqIgnoreSpan)]
1009#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1010#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1011pub struct TsInterfaceDecl {
1012    pub span: Span,
1013    pub id: Ident,
1014    pub declare: bool,
1015    #[cfg_attr(feature = "serde-impl", serde(default))]
1016    #[cfg_attr(
1017        feature = "encoding-impl",
1018        encoding(with = "cbor4ii::core::types::Maybe")
1019    )]
1020    pub type_params: Option<Box<TsTypeParamDecl>>,
1021    pub extends: Vec<TsExprWithTypeArgs>,
1022    pub body: TsInterfaceBody,
1023}
1024
1025#[ast_node("TsInterfaceBody")]
1026#[derive(Eq, Hash, EqIgnoreSpan)]
1027#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1028#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1029pub struct TsInterfaceBody {
1030    pub span: Span,
1031    pub body: Vec<TsTypeElement>,
1032}
1033
1034#[ast_node("TsExpressionWithTypeArguments")]
1035#[derive(Eq, Hash, EqIgnoreSpan)]
1036#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1037#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1038pub struct TsExprWithTypeArgs {
1039    pub span: Span,
1040    #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
1041    pub expr: Box<Expr>,
1042    #[cfg_attr(feature = "serde-impl", serde(default, rename = "typeArguments"))]
1043    #[cfg_attr(
1044        feature = "encoding-impl",
1045        encoding(with = "cbor4ii::core::types::Maybe")
1046    )]
1047    pub type_args: Option<Box<TsTypeParamInstantiation>>,
1048}
1049
1050#[ast_node("TsTypeAliasDeclaration")]
1051#[derive(Eq, Hash, EqIgnoreSpan)]
1052#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1053#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1054pub struct TsTypeAliasDecl {
1055    pub span: Span,
1056    pub declare: bool,
1057    pub id: Ident,
1058    #[cfg_attr(feature = "serde-impl", serde(default))]
1059    #[cfg_attr(
1060        feature = "encoding-impl",
1061        encoding(with = "cbor4ii::core::types::Maybe")
1062    )]
1063    pub type_params: Option<Box<TsTypeParamDecl>>,
1064    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
1065    pub type_ann: Box<TsType>,
1066}
1067
1068#[ast_node("TsEnumDeclaration")]
1069#[derive(Eq, Hash, EqIgnoreSpan)]
1070#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1071#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1072pub struct TsEnumDecl {
1073    pub span: Span,
1074    pub declare: bool,
1075    pub is_const: bool,
1076    pub id: Ident,
1077    pub members: Vec<TsEnumMember>,
1078}
1079
1080#[ast_node("TsEnumMember")]
1081#[derive(Eq, Hash, EqIgnoreSpan)]
1082#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1083#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1084pub struct TsEnumMember {
1085    pub span: Span,
1086    pub id: TsEnumMemberId,
1087    #[cfg_attr(feature = "serde-impl", serde(default))]
1088    #[cfg_attr(
1089        feature = "encoding-impl",
1090        encoding(with = "cbor4ii::core::types::Maybe")
1091    )]
1092    pub init: Option<Box<Expr>>,
1093}
1094
1095///
1096/// - Invalid: [Ident] with empty symbol.
1097#[ast_node]
1098#[derive(Eq, Hash, Is, EqIgnoreSpan)]
1099#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1100#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1101pub enum TsEnumMemberId {
1102    #[tag("Identifier")]
1103    Ident(Ident),
1104
1105    #[tag("StringLiteral")]
1106    Str(Str),
1107}
1108
1109#[ast_node("TsModuleDeclaration")]
1110#[derive(Eq, Hash, EqIgnoreSpan)]
1111#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1112#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1113pub struct TsModuleDecl {
1114    pub span: Span,
1115    pub declare: bool,
1116    /// In TypeScript, this is only available through`node.flags`.
1117    pub global: bool,
1118    pub namespace: bool,
1119
1120    pub id: TsModuleName,
1121    #[cfg_attr(feature = "serde-impl", serde(default))]
1122    #[cfg_attr(
1123        feature = "encoding-impl",
1124        encoding(with = "cbor4ii::core::types::Maybe")
1125    )]
1126    pub body: Option<TsNamespaceBody>,
1127}
1128
1129/// `namespace A.B { }` is a namespace named `A` with another TsNamespaceDecl as
1130/// its body.
1131#[ast_node]
1132#[derive(Eq, Hash, Is, EqIgnoreSpan)]
1133#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1134#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1135pub enum TsNamespaceBody {
1136    #[tag("TsModuleBlock")]
1137    TsModuleBlock(TsModuleBlock),
1138
1139    #[tag("TsNamespaceDeclaration")]
1140    TsNamespaceDecl(TsNamespaceDecl),
1141}
1142
1143#[ast_node("TsModuleBlock")]
1144#[derive(Eq, Hash, EqIgnoreSpan)]
1145#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1146#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1147pub struct TsModuleBlock {
1148    pub span: Span,
1149    pub body: Vec<ModuleItem>,
1150}
1151
1152#[ast_node("TsNamespaceDeclaration")]
1153#[derive(Eq, Hash, EqIgnoreSpan)]
1154#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1155#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1156pub struct TsNamespaceDecl {
1157    pub span: Span,
1158    pub declare: bool,
1159    /// In TypeScript, this is only available through`node.flags`.
1160    pub global: bool,
1161    pub id: Ident,
1162    pub body: Box<TsNamespaceBody>,
1163}
1164
1165#[ast_node]
1166#[derive(Eq, Hash, Is, EqIgnoreSpan)]
1167#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1168#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1169pub enum TsModuleName {
1170    #[tag("Identifier")]
1171    Ident(Ident),
1172
1173    #[tag("StringLiteral")]
1174    Str(Str),
1175}
1176
1177#[ast_node("TsImportEqualsDeclaration")]
1178#[derive(Eq, Hash, EqIgnoreSpan)]
1179#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1180#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1181pub struct TsImportEqualsDecl {
1182    pub span: Span,
1183    pub is_export: bool,
1184    pub is_type_only: bool,
1185    pub id: Ident,
1186    pub module_ref: TsModuleRef,
1187}
1188
1189#[ast_node]
1190#[derive(Eq, Hash, Is, EqIgnoreSpan)]
1191#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1192#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1193pub enum TsModuleRef {
1194    #[tag("TsQualifiedName")]
1195    #[tag("Identifier")]
1196    TsEntityName(TsEntityName),
1197
1198    #[tag("TsExternalModuleReference")]
1199    TsExternalModuleRef(TsExternalModuleRef),
1200}
1201
1202#[ast_node("TsExternalModuleReference")]
1203#[derive(Eq, Hash, EqIgnoreSpan)]
1204#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1205#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1206pub struct TsExternalModuleRef {
1207    pub span: Span,
1208    #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
1209    pub expr: Str,
1210}
1211
1212/// TypeScript's own parser uses ExportAssignment for both `export default` and
1213/// `export =`. But for @babel/parser, `export default` is an ExportDefaultDecl,
1214/// so a TsExportAssignment is always `export =`.
1215#[ast_node("TsExportAssignment")]
1216#[derive(Eq, Hash, EqIgnoreSpan)]
1217#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1218#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1219pub struct TsExportAssignment {
1220    pub span: Span,
1221    #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
1222    pub expr: Box<Expr>,
1223}
1224
1225#[ast_node("TsNamespaceExportDeclaration")]
1226#[derive(Eq, Hash, EqIgnoreSpan)]
1227#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1228#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1229pub struct TsNamespaceExportDecl {
1230    pub span: Span,
1231    pub id: Ident,
1232}
1233
1234// // ================
1235// // TypeScript exprs
1236// // ================
1237
1238#[ast_node("TsAsExpression")]
1239#[derive(Eq, Hash, EqIgnoreSpan)]
1240#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1241#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1242pub struct TsAsExpr {
1243    pub span: Span,
1244    #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
1245    pub expr: Box<Expr>,
1246    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
1247    pub type_ann: Box<TsType>,
1248}
1249
1250#[ast_node("TsTypeAssertion")]
1251#[derive(Eq, Hash, EqIgnoreSpan)]
1252#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1253#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1254pub struct TsTypeAssertion {
1255    pub span: Span,
1256    #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
1257    pub expr: Box<Expr>,
1258    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
1259    pub type_ann: Box<TsType>,
1260}
1261
1262#[ast_node("TsNonNullExpression")]
1263#[derive(Eq, Hash, EqIgnoreSpan)]
1264#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1265#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1266pub struct TsNonNullExpr {
1267    pub span: Span,
1268    #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
1269    pub expr: Box<Expr>,
1270}
1271
1272#[ast_node("TsSatisfiesExpression")]
1273#[derive(Eq, Hash, EqIgnoreSpan)]
1274#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1275#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1276pub struct TsSatisfiesExpr {
1277    pub span: Span,
1278    #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
1279    pub expr: Box<Expr>,
1280    #[cfg_attr(feature = "serde-impl", serde(rename = "typeAnnotation"))]
1281    pub type_ann: Box<TsType>,
1282}
1283
1284#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EqIgnoreSpan)]
1285#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1286#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
1287#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1288#[cfg_attr(
1289    feature = "encoding-impl",
1290    derive(::swc_common::Encode, ::swc_common::Decode)
1291)]
1292#[cfg_attr(swc_ast_unknown, non_exhaustive)]
1293pub enum Accessibility {
1294    #[cfg_attr(feature = "serde-impl", serde(rename = "public"))]
1295    Public,
1296    #[cfg_attr(feature = "serde-impl", serde(rename = "protected"))]
1297    Protected,
1298    #[cfg_attr(feature = "serde-impl", serde(rename = "private"))]
1299    Private,
1300}
1301
1302#[ast_node("TsConstAssertion")]
1303#[derive(Eq, Hash, EqIgnoreSpan)]
1304#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1305#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1306pub struct TsConstAssertion {
1307    pub span: Span,
1308    #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
1309    pub expr: Box<Expr>,
1310}
1311
1312#[ast_node("TsInstantiation")]
1313#[derive(Eq, Hash, EqIgnoreSpan)]
1314#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1315#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
1316pub struct TsInstantiation {
1317    pub span: Span,
1318    #[cfg_attr(feature = "serde-impl", serde(rename = "expression"))]
1319    pub expr: Box<Expr>,
1320    #[cfg_attr(feature = "serde-impl", serde(rename = "typeArguments"))]
1321    pub type_args: Box<TsTypeParamInstantiation>,
1322}