swc_estree_ast/
flow.rs

1use serde::{Deserialize, Serialize};
2use swc_atoms::Atom;
3use swc_common::ast_serde;
4
5use crate::{
6    common::{BaseNode, IdOrQualifiedId, IdOrString, Identifier},
7    expr::TypeCastExpression,
8    lit::StringLiteral,
9    module::{ExportKind, ExportNamespaceSpecifier, ExportSpecifier},
10    stmt::BlockStatement,
11};
12
13#[derive(Debug, Clone, PartialEq)]
14#[ast_serde]
15pub enum Flow {
16    #[tag("AnyTypeAnnotation")]
17    AnyTypeAnnotation(AnyTypeAnnotation),
18    #[tag("ArrayTypeAnnotation")]
19    ArrayTypeAnnotation(ArrayTypeAnnotation),
20    #[tag("BooleanTypeAnnotation")]
21    BooleanTypeAnnotation(BooleanTypeAnnotation),
22    #[tag("BooleanLiteralTypeAnnotation")]
23    BooleanLiteralTypeAnnotation(BooleanLiteralTypeAnnotation),
24    #[tag("NullLiteralTypeAnnotation")]
25    NullLiteralTypeAnnotation(NullLiteralTypeAnnotation),
26    #[tag("ClassImplements")]
27    ClassImplements(ClassImplements),
28    #[tag("DeclareClass")]
29    DeclareClass(DeclareClass),
30    #[tag("DeclareFunction")]
31    DeclareFunction(DeclareFunction),
32    #[tag("DeclareInterface")]
33    DeclareInterface(DeclareInterface),
34    #[tag("DeclareModule")]
35    DeclareModule(DeclareModule),
36    #[tag("DeclareModuleExports")]
37    DeclareModuleExports(DeclareModuleExports),
38    #[tag("DeclareTypeAlias")]
39    DeclareTypeAlias(DeclareTypeAlias),
40    #[tag("DeclareOpaqueType")]
41    DeclareOpaqueType(DeclareOpaqueType),
42    #[tag("DeclareVariable")]
43    DeclareVariable(DeclareVariable),
44    #[tag("DeclareExportDeclaration")]
45    DeclareExportDeclaration(DeclareExportDeclaration),
46    #[tag("DeclareExportAllDeclaration")]
47    DeclareExportAllDeclaration(DeclareExportAllDeclaration),
48    #[tag("DeclaredPredicate")]
49    DeclaredPredicate(DeclaredPredicate),
50    #[tag("ExistsTypeAnnotation")]
51    ExistsTypeAnnotation(ExistsTypeAnnotation),
52    #[tag("FunctionTypeAnnotation")]
53    FunctionTypeAnnotation(FunctionTypeAnnotation),
54    #[tag("FunctionTypeParam")]
55    FunctionTypeParam(FunctionTypeParam),
56    #[tag("GenericTypeAnnotation")]
57    GenericTypeAnnotation(GenericTypeAnnotation),
58    #[tag("InferredPredicate")]
59    InferredPredicate(InferredPredicate),
60    #[tag("InterfaceExtends")]
61    InterfaceExtends(InterfaceExtends),
62    #[tag("InterfaceDeclaration")]
63    InterfaceDeclaration(InterfaceDeclaration),
64    #[tag("InterfaceTypeAnnotation")]
65    InterfaceTypeAnnotation(InterfaceTypeAnnotation),
66    #[tag("IntersectionTypeAnnotation")]
67    IntersectionTypeAnnotation(IntersectionTypeAnnotation),
68    #[tag("MixedTypeAnnotation")]
69    MixedTypeAnnotation(MixedTypeAnnotation),
70    #[tag("EmptyTypeAnnotation")]
71    EmptyTypeAnnotation(EmptyTypeAnnotation),
72    #[tag("NullableTypeAnnotation")]
73    NullableTypeAnnotation(NullableTypeAnnotation),
74    #[tag("NumberLiteralTypeAnnotation")]
75    NumberLiteralTypeAnnotation(NumberLiteralTypeAnnotation),
76    #[tag("NumberTypeAnnotation")]
77    NumberTypeAnnotation(NumberTypeAnnotation),
78    #[tag("ObjectTypeAnnotation")]
79    ObjectTypeAnnotation(ObjectTypeAnnotation),
80    #[tag("ObjectTypeInternalSlot")]
81    ObjectTypeInternalSlot(ObjectTypeInternalSlot),
82    #[tag("ObjectTypeCallProperty")]
83    ObjectTypeCallProperty(ObjectTypeCallProperty),
84    #[tag("ObjectTypeIndexer")]
85    ObjectTypeIndexer(ObjectTypeIndexer),
86    #[tag("ObjectTypeProperty")]
87    ObjectTypeProperty(ObjectTypeProperty),
88    #[tag("ObjectTypeSpreadProperty")]
89    ObjectTypeSpreadProperty(ObjectTypeSpreadProperty),
90    #[tag("OpaqueType")]
91    OpaqueType(OpaqueType),
92    #[tag("QualifiedTypeIdentifier")]
93    QualifiedTypeIdentifier(QualifiedTypeIdentifier),
94    #[tag("StringLiteralTypeAnnotation")]
95    StringLiteralTypeAnnotation(StringLiteralTypeAnnotation),
96    #[tag("StringTypeAnnotation")]
97    StringTypeAnnotation(StringTypeAnnotation),
98    #[tag("SymbolTypeAnnotation")]
99    SymbolTypeAnnotation(SymbolTypeAnnotation),
100    #[tag("ThisTypeAnnotation")]
101    ThisTypeAnnotation(ThisTypeAnnotation),
102    #[tag("TupleTypeAnnotation")]
103    TupleTypeAnnotation(TupleTypeAnnotation),
104    #[tag("TypeofTypeAnnotation")]
105    TypeofTypeAnnotation(TypeofTypeAnnotation),
106    #[tag("TypeAlias")]
107    TypeAlias(TypeAlias),
108    #[tag("TypeAnnotation")]
109    TypeAnnotation(TypeAnnotation),
110    #[tag("TypeCastExpression")]
111    TypeCastExpression(TypeCastExpression),
112    #[tag("TypeParameter")]
113    TypeParameter(TypeParameter),
114    #[tag("TypeParameterDeclaration")]
115    TypeParameterDeclaration(TypeParameterDeclaration),
116    #[tag("TypeParameterInstantiation")]
117    TypeParameterInstantiation(TypeParameterInstantiation),
118    #[tag("UnionTypeAnnotation")]
119    UnionTypeAnnotation(UnionTypeAnnotation),
120    #[tag("Variance")]
121    Variance(Variance),
122    #[tag("VoidTypeAnnotation")]
123    VoidTypeAnnotation(VoidTypeAnnotation),
124}
125
126#[derive(Debug, Clone, PartialEq)]
127#[ast_serde]
128pub enum FlowType {
129    #[tag("AnyTypeAnnotation")]
130    Any(AnyTypeAnnotation),
131    #[tag("ArrayTypeAnnotation")]
132    Array(ArrayTypeAnnotation),
133    #[tag("BooleanTypeAnnotation")]
134    Boolean(BooleanTypeAnnotation),
135    #[tag("BooleanLiteralTypeAnnotation")]
136    BooleanLiteral(BooleanLiteralTypeAnnotation),
137    #[tag("NullLiteralTypeAnnotation")]
138    NullLiteral(NullLiteralTypeAnnotation),
139    #[tag("ExistsTypeAnnotation")]
140    Exists(ExistsTypeAnnotation),
141    #[tag("FunctionTypeAnnotation")]
142    Function(FunctionTypeAnnotation),
143    #[tag("GenericTypeAnnotation")]
144    Generic(GenericTypeAnnotation),
145    #[tag("InterfaceTypeAnnotation")]
146    Interface(InterfaceTypeAnnotation),
147    #[tag("IntersectionTypeAnnotation")]
148    Intersection(IntersectionTypeAnnotation),
149    #[tag("MixedTypeAnnotation")]
150    Mixed(MixedTypeAnnotation),
151    #[tag("EmptyTypeAnnotation")]
152    Empty(EmptyTypeAnnotation),
153    #[tag("NullableTypeAnnotation")]
154    Nullable(NullableTypeAnnotation),
155    #[tag("NumberLiteralTypeAnnotation")]
156    NumerLiteral(NumberLiteralTypeAnnotation),
157    #[tag("NumberTypeAnnotation")]
158    Number(NumberTypeAnnotation),
159    #[tag("ObjectTypeAnnotation")]
160    Object(ObjectTypeAnnotation),
161    #[tag("StringLiteralTypeAnnotation")]
162    StringLiteral(StringLiteralTypeAnnotation),
163    #[tag("StringTypeAnnotation")]
164    String(StringTypeAnnotation),
165    #[tag("SymbolTypeAnnotation")]
166    Symbol(SymbolTypeAnnotation),
167    #[tag("ThisTypeAnnotation")]
168    This(ThisTypeAnnotation),
169    #[tag("TupleTypeAnnotation")]
170    Tuple(TupleTypeAnnotation),
171    #[tag("TypeofTypeAnnotation")]
172    Typeof(TypeofTypeAnnotation),
173    #[tag("UnionTypeAnnotation")]
174    Union(UnionTypeAnnotation),
175    #[tag("VoidTypeAnnotation")]
176    Void(VoidTypeAnnotation),
177}
178
179#[derive(Debug, Clone, PartialEq, Eq)]
180#[ast_serde]
181pub enum FlowBaseAnnotation {
182    #[tag("AnyTypeAnnotation")]
183    Any(AnyTypeAnnotation),
184    #[tag("BooleanTypeAnnotation")]
185    Boolean(BooleanTypeAnnotation),
186    #[tag("NullLiteralTypeAnnotation")]
187    NullLiteral(NullLiteralTypeAnnotation),
188    #[tag("MixedTypeAnnotation")]
189    Mixed(MixedTypeAnnotation),
190    #[tag("EmptyTypeAnnotation")]
191    Empty(EmptyTypeAnnotation),
192    #[tag("NumberTypeAnnotation")]
193    Number(NumberTypeAnnotation),
194    #[tag("StringTypeAnnotation")]
195    String(StringTypeAnnotation),
196    #[tag("SymbolTypeAnnotation")]
197    Symbol(SymbolTypeAnnotation),
198    #[tag("ThisTypeAnnotation")]
199    This(ThisTypeAnnotation),
200    #[tag("VoidTypeAnnotation")]
201    Void(VoidTypeAnnotation),
202}
203
204#[derive(Debug, Clone, PartialEq)]
205#[ast_serde]
206pub enum FlowDeclaration {
207    #[tag("DeclareClass")]
208    Class(DeclareClass),
209    #[tag("DeclareFunction")]
210    Func(DeclareFunction),
211    #[tag("DeclareInterface")]
212    Interface(DeclareInterface),
213    #[tag("DeclareModule")]
214    Module(DeclareModule),
215    #[tag("DeclareModuleExports")]
216    ModuleExports(DeclareModuleExports),
217    #[tag("DeclareTypeAlias")]
218    DeclareTypeAlias(DeclareTypeAlias),
219    #[tag("DeclareOpaqueType")]
220    DeclareOpaqueType(DeclareOpaqueType),
221    #[tag("DeclareVariable")]
222    Var(DeclareVariable),
223    #[tag("DeclareExportDeclaration")]
224    ExportDecl(DeclareExportDeclaration),
225    #[tag("DeclareExportAllDeclaration")]
226    ExportAllDecl(DeclareExportAllDeclaration),
227    #[tag("InterfaceDeclaration")]
228    InterfaceDeclaration(InterfaceDeclaration),
229    #[tag("OpaqueType")]
230    OpaqueType(OpaqueType),
231    #[tag("TypeAlias")]
232    TypeAlias(TypeAlias),
233}
234
235#[derive(Debug, Clone, PartialEq)]
236#[ast_serde]
237pub enum FlowPredicate {
238    #[tag("DeclaredPredicate")]
239    DeclaredPredicate(DeclaredPredicate),
240    #[tag("InferredPredicate")]
241    InferredPredicate(InferredPredicate),
242}
243
244#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
245#[serde(rename_all = "camelCase")]
246#[serde(tag = "type")]
247pub struct TypeAnnotation {
248    #[serde(flatten)]
249    pub base: BaseNode,
250    pub type_annotation: FlowType,
251}
252
253#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
254#[serde(tag = "type")]
255pub struct AnyTypeAnnotation {
256    #[serde(flatten)]
257    pub base: BaseNode,
258}
259
260#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
261#[serde(rename_all = "camelCase")]
262#[serde(tag = "type")]
263pub struct ArrayTypeAnnotation {
264    #[serde(flatten)]
265    pub base: BaseNode,
266    pub element_type: Box<FlowType>,
267}
268
269#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
270#[serde(tag = "type")]
271pub struct BooleanTypeAnnotation {
272    #[serde(flatten)]
273    pub base: BaseNode,
274}
275
276#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
277#[serde(tag = "type")]
278pub struct BooleanLiteralTypeAnnotation {
279    #[serde(flatten)]
280    pub base: BaseNode,
281    #[serde(default)]
282    pub value: bool,
283}
284
285#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
286#[serde(tag = "type")]
287pub struct NullLiteralTypeAnnotation {
288    #[serde(flatten)]
289    pub base: BaseNode,
290}
291
292#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
293#[serde(tag = "type")]
294pub struct ExistsTypeAnnotation {
295    #[serde(flatten)]
296    pub base: BaseNode,
297}
298
299#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
300#[serde(rename_all = "camelCase")]
301#[serde(tag = "type")]
302pub struct FunctionTypeParam {
303    #[serde(flatten)]
304    pub base: BaseNode,
305    #[serde(default)]
306    pub name: Option<Identifier>,
307    pub type_annotation: Box<FlowType>,
308    #[serde(default)]
309    pub optional: Option<bool>,
310}
311
312#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
313#[serde(rename_all = "camelCase")]
314#[serde(tag = "type")]
315pub struct FunctionTypeAnnotation {
316    #[serde(flatten)]
317    pub base: BaseNode,
318    #[serde(default)]
319    pub type_parameters: Option<TypeParameterDeclaration>,
320    #[serde(default)]
321    pub params: Vec<FunctionTypeParam>,
322    #[serde(default)]
323    pub rest: Option<Box<FunctionTypeParam>>,
324    pub return_type: Box<FlowType>,
325    #[serde(default)]
326    pub optional: Option<bool>,
327}
328
329#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
330#[serde(tag = "type")]
331pub struct TypeParameterDeclaration {
332    #[serde(flatten)]
333    pub base: BaseNode,
334    #[serde(default)]
335    pub params: Vec<TypeParameter>,
336}
337
338#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
339#[serde(rename_all = "lowercase")]
340pub enum PlusOrMinus {
341    Plus,
342    Minus,
343}
344
345#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
346#[serde(tag = "type")]
347pub struct Variance {
348    #[serde(flatten)]
349    pub base: BaseNode,
350    pub kind: PlusOrMinus,
351}
352
353#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
354#[serde(tag = "type")]
355pub struct TypeParameter {
356    #[serde(flatten)]
357    pub base: BaseNode,
358    #[serde(default)]
359    pub bound: Option<TypeAnnotation>,
360    #[serde(default)]
361    pub default: Option<FlowType>,
362    #[serde(default)]
363    pub variance: Option<Variance>,
364    #[serde(default)]
365    pub name: Atom,
366}
367
368#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
369#[serde(tag = "type")]
370pub struct TypeParameterInstantiation {
371    #[serde(flatten)]
372    pub base: BaseNode,
373    #[serde(default)]
374    pub params: Vec<FlowType>,
375}
376
377#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
378#[serde(rename_all = "camelCase")]
379#[serde(tag = "type")]
380pub struct GenericTypeAnnotation {
381    #[serde(flatten)]
382    pub base: BaseNode,
383    pub id: IdOrQualifiedId,
384    #[serde(default)]
385    pub type_parameters: Option<TypeParameterInstantiation>,
386}
387
388#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
389#[serde(rename_all = "camelCase")]
390#[serde(tag = "type")]
391pub struct InterfaceExtends {
392    #[serde(flatten)]
393    pub base: BaseNode,
394    pub id: IdOrQualifiedId,
395    #[serde(default)]
396    pub type_parameters: Option<TypeParameterInstantiation>,
397}
398
399#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
400#[serde(rename_all = "lowercase")]
401pub enum ObjectTypePropKind {
402    Init,
403    Get,
404    Set,
405}
406
407#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
408#[serde(tag = "type")]
409pub struct ObjectTypeProperty {
410    #[serde(flatten)]
411    pub base: BaseNode,
412    pub key: IdOrString,
413    pub value: FlowType,
414    #[serde(default)]
415    pub variance: Option<Variance>,
416    pub kind: ObjectTypePropKind,
417    #[serde(default)]
418    pub method: bool,
419    #[serde(default)]
420    pub optional: bool,
421    #[serde(default)]
422    pub proto: bool,
423    #[serde(default, rename = "static")]
424    pub is_static: bool,
425}
426
427#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
428#[serde(tag = "type")]
429pub struct ObjectTypeSpreadProperty {
430    #[serde(flatten)]
431    pub base: BaseNode,
432    pub argument: FlowType,
433}
434
435#[derive(Debug, Clone, PartialEq)]
436#[ast_serde]
437pub enum ObjectTypeAnnotProp {
438    #[tag("ObjectTypeProperty")]
439    Prop(ObjectTypeProperty),
440    #[tag("ObjectTypeSpreadProperty")]
441    Spread(ObjectTypeSpreadProperty),
442}
443
444#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
445#[serde(tag = "type")]
446pub struct ObjectTypeIndexer {
447    #[serde(flatten)]
448    pub base: BaseNode,
449    #[serde(default)]
450    pub id: Option<Identifier>,
451    pub key: FlowType,
452    pub value: FlowType,
453    #[serde(default)]
454    pub variance: Option<Variance>,
455    #[serde(default, rename = "static")]
456    pub is_static: bool,
457}
458
459#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
460#[serde(tag = "type")]
461pub struct ObjectTypeCallProperty {
462    #[serde(flatten)]
463    pub base: BaseNode,
464    pub value: FlowType,
465    #[serde(rename = "static")]
466    pub is_static: bool,
467}
468
469#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
470#[serde(tag = "type")]
471pub struct ObjectTypeInternalSlot {
472    #[serde(flatten)]
473    pub base: BaseNode,
474    pub id: Identifier,
475    pub value: FlowType,
476    #[serde(default)]
477    pub optional: bool,
478    #[serde(default, rename = "static")]
479    pub is_static: bool,
480    #[serde(default)]
481    pub method: bool,
482}
483
484#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
485#[serde(rename_all = "camelCase")]
486#[serde(tag = "type")]
487pub struct ObjectTypeAnnotation {
488    #[serde(flatten)]
489    pub base: BaseNode,
490    #[serde(default)]
491    pub properties: Vec<ObjectTypeAnnotProp>,
492    #[serde(default)]
493    pub indexers: Option<Vec<ObjectTypeIndexer>>,
494    #[serde(default)]
495    pub call_properties: Option<Vec<ObjectTypeCallProperty>>,
496    #[serde(default)]
497    pub internal_slots: Option<Vec<ObjectTypeInternalSlot>>,
498    #[serde(default)]
499    pub exact: bool,
500    #[serde(default)]
501    pub inexact: Option<bool>,
502}
503
504#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
505#[serde(rename_all = "camelCase")]
506#[serde(tag = "type")]
507pub struct InterfaceTypeAnnotation {
508    #[serde(flatten)]
509    pub base: BaseNode,
510    #[serde(flatten)]
511    pub extends: Option<Vec<InterfaceExtends>>,
512    pub body: ObjectTypeAnnotation,
513}
514
515#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
516#[serde(tag = "type")]
517pub struct IntersectionTypeAnnotation {
518    #[serde(flatten)]
519    pub base: BaseNode,
520    #[serde(flatten)]
521    pub types: Vec<FlowType>,
522}
523
524#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
525#[serde(tag = "type")]
526pub struct MixedTypeAnnotation {
527    #[serde(flatten)]
528    pub base: BaseNode,
529}
530
531#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
532#[serde(tag = "type")]
533pub struct EmptyTypeAnnotation {
534    #[serde(flatten)]
535    pub base: BaseNode,
536}
537
538#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
539#[serde(rename_all = "camelCase")]
540#[serde(tag = "type")]
541pub struct NullableTypeAnnotation {
542    #[serde(flatten)]
543    pub base: BaseNode,
544    pub type_annotation: Box<FlowType>,
545}
546
547#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
548#[serde(tag = "type")]
549pub struct NumberLiteralTypeAnnotation {
550    #[serde(flatten)]
551    pub base: BaseNode,
552    pub value: f64,
553}
554
555#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
556#[serde(tag = "type")]
557pub struct NumberTypeAnnotation {
558    #[serde(flatten)]
559    pub base: BaseNode,
560}
561
562#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
563#[serde(tag = "type")]
564pub struct StringLiteralTypeAnnotation {
565    #[serde(flatten)]
566    pub base: BaseNode,
567    #[serde(default)]
568    pub value: Atom,
569}
570
571#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
572#[serde(tag = "type")]
573pub struct StringTypeAnnotation {
574    #[serde(flatten)]
575    pub base: BaseNode,
576}
577
578#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
579#[serde(tag = "type")]
580pub struct SymbolTypeAnnotation {
581    #[serde(flatten)]
582    pub base: BaseNode,
583}
584
585#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
586#[serde(tag = "type")]
587pub struct ThisTypeAnnotation {
588    #[serde(flatten)]
589    pub base: BaseNode,
590}
591
592#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
593#[serde(tag = "type")]
594pub struct TupleTypeAnnotation {
595    #[serde(flatten)]
596    pub base: BaseNode,
597    #[serde(default)]
598    pub types: Vec<FlowType>,
599}
600
601#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
602#[serde(tag = "type")]
603pub struct TypeofTypeAnnotation {
604    #[serde(flatten)]
605    pub base: BaseNode,
606    pub argument: Box<FlowType>,
607}
608
609#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
610#[serde(tag = "type")]
611pub struct UnionTypeAnnotation {
612    #[serde(flatten)]
613    pub base: BaseNode,
614    #[serde(default)]
615    pub types: Vec<FlowType>,
616}
617
618#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
619#[serde(tag = "type")]
620pub struct VoidTypeAnnotation {
621    #[serde(flatten)]
622    pub base: BaseNode,
623}
624
625#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
626#[serde(rename_all = "camelCase")]
627#[serde(tag = "type")]
628pub struct OpaqueType {
629    #[serde(flatten)]
630    pub base: BaseNode,
631    pub id: Identifier,
632    #[serde(default)]
633    pub type_parameters: Option<TypeParameterDeclaration>,
634    #[serde(default)]
635    pub supertype: Option<FlowType>,
636    pub impltype: FlowType,
637}
638
639#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
640#[serde(rename_all = "camelCase")]
641#[serde(tag = "type")]
642pub struct DeclareOpaqueType {
643    #[serde(flatten)]
644    pub base: BaseNode,
645    pub id: Identifier,
646    #[serde(default)]
647    pub type_parameters: Option<TypeParameterDeclaration>,
648    #[serde(default)]
649    pub supertype: Option<FlowType>,
650}
651
652#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
653#[serde(rename_all = "camelCase")]
654#[serde(tag = "type")]
655pub struct TypeAlias {
656    #[serde(flatten)]
657    pub base: BaseNode,
658    pub id: Identifier,
659    #[serde(default)]
660    pub type_parameters: Option<TypeParameterDeclaration>,
661    pub right: FlowType,
662}
663
664#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
665#[serde(rename_all = "camelCase")]
666#[serde(tag = "type")]
667pub struct ClassImplements {
668    #[serde(flatten)]
669    pub base: BaseNode,
670    pub id: Identifier,
671    #[serde(default)]
672    pub type_parameters: Option<TypeParameterInstantiation>,
673}
674
675#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
676#[serde(rename_all = "camelCase")]
677#[serde(tag = "type")]
678pub struct DeclareClass {
679    #[serde(flatten)]
680    pub base: BaseNode,
681    pub id: Identifier,
682    #[serde(default, skip_serializing_if = "crate::flavor::Flavor::skip_none")]
683    pub type_parameters: Option<TypeParameterInstantiation>,
684    #[serde(default, skip_serializing_if = "crate::flavor::Flavor::skip_empty")]
685    pub extends: Option<Vec<InterfaceExtends>>,
686    pub body: ObjectTypeAnnotation,
687    #[serde(default, skip_serializing_if = "crate::flavor::Flavor::skip_empty")]
688    pub implements: Option<Vec<ClassImplements>>,
689    #[serde(default, skip_serializing_if = "crate::flavor::Flavor::skip_none")]
690    pub mixins: Option<Vec<InterfaceExtends>>,
691}
692
693#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
694#[serde(tag = "type")]
695pub struct DeclareFunction {
696    #[serde(flatten)]
697    pub base: BaseNode,
698    pub id: Identifier,
699    #[serde(default)]
700    pub predicate: Option<Box<DeclaredPredicate>>,
701}
702
703#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
704#[serde(rename_all = "camelCase")]
705#[serde(tag = "type")]
706pub struct DeclareInterface {
707    #[serde(flatten)]
708    pub base: BaseNode,
709    pub id: Identifier,
710    #[serde(default)]
711    pub type_parameters: Option<TypeParameterInstantiation>,
712    #[serde(default)]
713    pub extends: Option<Vec<InterfaceExtends>>,
714    pub body: ObjectTypeAnnotation,
715    #[serde(default)]
716    pub implements: Option<Vec<ClassImplements>>,
717    #[serde(default, skip_serializing_if = "crate::flavor::Flavor::skip_empty")]
718    pub mixins: Option<Vec<InterfaceExtends>>,
719}
720
721#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
722pub enum ModuleKind {
723    #[serde(rename = "CommonJS")]
724    CommonJs,
725    #[serde(rename = "ES")]
726    Es,
727}
728
729#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
730#[serde(tag = "type")]
731pub struct DeclareModule {
732    #[serde(flatten)]
733    pub base: BaseNode,
734    pub id: IdOrString,
735    pub body: BlockStatement,
736    #[serde(default)]
737    pub kind: Option<ModuleKind>,
738}
739
740#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
741#[serde(rename_all = "camelCase")]
742#[serde(tag = "type")]
743pub struct DeclareModuleExports {
744    #[serde(flatten)]
745    pub base: BaseNode,
746    pub type_annotation: TypeAnnotation,
747}
748
749#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
750#[serde(rename_all = "camelCase")]
751#[serde(tag = "type")]
752pub struct DeclareTypeAlias {
753    #[serde(flatten)]
754    pub base: BaseNode,
755    pub id: Identifier,
756    #[serde(default)]
757    pub type_parameters: Option<TypeParameterDeclaration>,
758    pub right: FlowType,
759}
760
761#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
762#[serde(tag = "type")]
763pub struct DeclareVariable {
764    #[serde(flatten)]
765    pub base: BaseNode,
766    pub id: Identifier,
767}
768
769#[derive(Debug, Clone, PartialEq)]
770#[ast_serde]
771pub enum DeclareExportDeclSpecifier {
772    #[tag("ExportSpecifier")]
773    Export(ExportSpecifier),
774    #[tag("ExportNamespaceSpecifier")]
775    Namespace(ExportNamespaceSpecifier),
776}
777
778#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
779#[serde(tag = "type")]
780pub struct DeclareExportDeclaration {
781    #[serde(flatten)]
782    pub base: BaseNode,
783    #[serde(default)]
784    pub declaration: Option<Box<Flow>>,
785    #[serde(default)]
786    pub specifiers: Option<Vec<DeclareExportDeclSpecifier>>,
787    #[serde(default)]
788    pub source: Option<StringLiteral>,
789    #[serde(default)]
790    pub default: Option<bool>,
791}
792
793#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
794#[serde(rename_all = "camelCase")]
795#[serde(tag = "type")]
796pub struct DeclareExportAllDeclaration {
797    #[serde(flatten)]
798    pub base: BaseNode,
799    pub source: StringLiteral,
800    #[serde(default)]
801    pub export_kind: Option<ExportKind>,
802}
803
804#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
805#[serde(tag = "type")]
806pub struct DeclaredPredicate {
807    #[serde(flatten)]
808    pub base: BaseNode,
809    pub value: Box<Flow>,
810}
811
812#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
813#[serde(tag = "type")]
814pub struct InferredPredicate {
815    #[serde(flatten)]
816    pub base: BaseNode,
817}
818
819#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
820#[serde(rename_all = "camelCase")]
821#[serde(tag = "type")]
822pub struct InterfaceDeclaration {
823    #[serde(flatten)]
824    pub base: BaseNode,
825    pub id: Identifier,
826    #[serde(default)]
827    pub type_parameters: Option<TypeParameterDeclaration>,
828    #[serde(default)]
829    pub extends: Option<Vec<InterfaceExtends>>,
830    pub body: ObjectTypeAnnotation,
831    #[serde(default)]
832    pub implements: Option<Vec<ClassImplements>>,
833    #[serde(default, skip_serializing_if = "crate::flavor::Flavor::skip_empty")]
834    pub mixins: Option<Vec<InterfaceExtends>>,
835}
836
837#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
838#[serde(tag = "type")]
839pub struct QualifiedTypeIdentifier {
840    #[serde(flatten)]
841    pub base: BaseNode,
842    pub id: Identifier,
843    pub qualification: Box<IdOrQualifiedId>,
844}