jetcrab\ast/
node.rs

1use crate::ast::common::Span;
2use crate::ast::expressions::*;
3use crate::ast::literals::*;
4use crate::ast::statements::*;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8pub struct Program {
9    pub body: Vec<Node>,
10    pub source_type: String,
11    pub span: Option<Span>,
12}
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15pub struct ImportDeclaration {
16    pub specifiers: Vec<Node>,
17    pub source: Box<Node>,
18    pub span: Option<Span>,
19}
20
21#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
22pub struct ImportSpecifier {
23    pub local: Box<Node>,
24    pub imported: Box<Node>,
25    pub span: Option<Span>,
26}
27
28#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
29pub struct ImportDefaultSpecifier {
30    pub local: Box<Node>,
31    pub span: Option<Span>,
32}
33
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
35pub struct ImportNamespaceSpecifier {
36    pub local: Box<Node>,
37    pub span: Option<Span>,
38}
39
40#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
41pub struct ExportDeclaration {
42    pub declaration: Option<Box<Node>>,
43    pub specifiers: Vec<Node>,
44    pub source: Option<Box<Node>>,
45    pub default: bool,
46    pub span: Option<Span>,
47}
48
49#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
50pub struct ExportSpecifier {
51    pub local: Box<Node>,
52    pub exported: Box<Node>,
53    pub span: Option<Span>,
54}
55
56#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
57pub enum Node {
58    Program(Program),
59
60    VariableDeclaration(VariableDeclaration),
61    FunctionDeclaration(FunctionDeclaration),
62    ClassDeclaration(ClassDeclaration),
63    ImportDeclaration(ImportDeclaration),
64    ExportDeclaration(ExportDeclaration),
65
66    BinaryExpression(BinaryExpression),
67    UnaryExpression(UnaryExpression),
68    UpdateExpression(UpdateExpression),
69    LogicalExpression(LogicalExpression),
70    ConditionalExpression(ConditionalExpression),
71    AssignmentExpression(AssignmentExpression),
72    CallExpression(CallExpression),
73    NewExpression(NewExpression),
74    MemberExpression(MemberExpression),
75    ArrowFunctionExpression(ArrowFunctionExpression),
76    FunctionExpression(FunctionExpression),
77    ClassExpression(ClassExpression),
78    YieldExpression(YieldExpression),
79    AwaitExpression(AwaitExpression),
80
81    BlockStatement(BlockStatement),
82    IfStatement(IfStatement),
83    ForStatement(ForStatement),
84    ForInStatement(ForInStatement),
85    ForOfStatement(ForOfStatement),
86    WhileStatement(WhileStatement),
87    DoWhileStatement(DoWhileStatement),
88    SwitchStatement(SwitchStatement),
89    TryStatement(TryStatement),
90    CatchClause(CatchClause),
91    ThrowStatement(ThrowStatement),
92    ReturnStatement(ReturnStatement),
93    BreakStatement(BreakStatement),
94    ContinueStatement(ContinueStatement),
95    LabeledStatement(LabeledStatement),
96    WithStatement(WithStatement),
97    DebuggerStatement(DebuggerStatement),
98    ExpressionStatement(ExpressionStatement),
99
100    ArrayLiteral(ArrayLiteral),
101    ObjectLiteral(ObjectLiteral),
102    TemplateLiteral(TemplateLiteral),
103    TaggedTemplateExpression(TaggedTemplateExpression),
104
105    Property(Property),
106    SpreadElement(SpreadElement),
107    RestElement(RestElement),
108    Super(Super),
109    MetaProperty(MetaProperty),
110    Identifier(String),
111    Number(f64),
112    String(String),
113    Boolean(bool),
114    Null,
115    Undefined,
116    This,
117    RegExp(RegExp),
118    BigInt(String),
119}