2018-06-02 12:01:00 +03:00
|
|
|
use super::{
|
2018-12-30 05:57:27 +03:00
|
|
|
AssignOp, BinaryOp, BlockStmt, Class, Function, Ident, JSXElement, JSXEmptyExpr, JSXFragment,
|
|
|
|
JSXMemberExpr, JSXNamespacedName, Lit, Pat, Prop, Str, UnaryOp, UpdateOp,
|
2018-06-02 12:01:00 +03:00
|
|
|
};
|
2018-11-17 10:38:23 +03:00
|
|
|
use swc_common::{ast_node, Fold, Span, Spanned};
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
#[ast_node]
|
2018-03-03 13:00:57 +03:00
|
|
|
pub enum Expr {
|
|
|
|
This(ThisExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Array(ArrayLit),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Object(ObjectLit),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Fn(FnExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Unary(UnaryExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
/// `++v`, `--v`, `v++`, `v--`
|
2018-01-16 05:35:05 +03:00
|
|
|
Update(UpdateExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Bin(BinExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Assign(AssignExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// Logical {
|
|
|
|
//
|
|
|
|
// op: LogicalOp,
|
|
|
|
// left: Box<Expr>,
|
|
|
|
// right: Box<Expr>,
|
|
|
|
// },
|
2018-06-02 12:01:00 +03:00
|
|
|
/// A member expression. If computed is true, the node corresponds to a
|
|
|
|
/// computed (a[b]) member expression and property is an Expression. If
|
|
|
|
/// computed is false, the node corresponds to a static (a.b) member
|
|
|
|
/// expression and property is an Identifier.
|
2018-01-16 05:35:05 +03:00
|
|
|
Member(MemberExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
/// true ? 'a' : 'b'
|
2018-01-16 05:35:05 +03:00
|
|
|
Cond(CondExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Call(CallExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
/// `new Cat()`
|
2018-01-16 05:35:05 +03:00
|
|
|
New(NewExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Seq(SeqExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
Ident(Ident),
|
|
|
|
|
|
|
|
Lit(Lit),
|
|
|
|
|
|
|
|
Tpl(TplLit),
|
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Arrow(ArrowExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Class(ClassExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Yield(YieldExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
MetaProp(MetaPropExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
Await(AwaitExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-03-03 13:00:57 +03:00
|
|
|
Paren(ParenExpr),
|
2018-12-30 05:57:27 +03:00
|
|
|
|
|
|
|
JSXMebmer(JSXMemberExpr),
|
|
|
|
JSXNamespacedName(JSXNamespacedName),
|
|
|
|
JSXEmpty(JSXEmptyExpr),
|
|
|
|
JSXElement(JSXElement),
|
|
|
|
JSXFragment(JSXFragment),
|
2018-03-03 13:00:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
2018-03-07 08:05:09 +03:00
|
|
|
#[derive(Copy)]
|
2018-03-03 13:00:57 +03:00
|
|
|
pub struct ThisExpr {
|
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
/// Array literal.
|
|
|
|
#[ast_node]
|
|
|
|
pub struct ArrayLit {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2018-02-03 13:56:23 +03:00
|
|
|
pub elems: Vec<(Option<ExprOrSpread>)>,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
/// Object literal.
|
|
|
|
#[ast_node]
|
|
|
|
pub struct ObjectLit {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2018-11-17 06:30:49 +03:00
|
|
|
pub props: Vec<PropOrSpread>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub enum PropOrSpread {
|
|
|
|
Prop(Box<Prop>),
|
|
|
|
/// Spread properties, e.g., `{a: 1, ...obj, b: 2}`.
|
|
|
|
Spread(SpreadElement),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub struct SpreadElement {
|
|
|
|
#[span(lo)]
|
|
|
|
pub dot3_token: Span,
|
|
|
|
#[span(hi)]
|
|
|
|
pub expr: Box<Expr>,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
#[ast_node]
|
|
|
|
pub struct UnaryExpr {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub op: UnaryOp,
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub arg: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub struct UpdateExpr {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub op: UpdateOp,
|
|
|
|
pub prefix: bool,
|
|
|
|
|
|
|
|
pub arg: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub struct BinExpr {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub op: BinaryOp,
|
|
|
|
|
|
|
|
pub left: Box<Expr>,
|
|
|
|
|
|
|
|
pub right: Box<Expr>,
|
2018-01-12 10:53:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Function expression.
|
|
|
|
#[ast_node]
|
|
|
|
pub struct FnExpr {
|
|
|
|
pub ident: Option<Ident>,
|
2018-03-04 09:17:52 +03:00
|
|
|
#[span]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub function: Function,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Class expression.
|
|
|
|
#[ast_node]
|
|
|
|
pub struct ClassExpr {
|
|
|
|
pub ident: Option<Ident>,
|
2018-03-04 09:17:52 +03:00
|
|
|
#[span]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub class: Class,
|
|
|
|
}
|
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
#[ast_node]
|
|
|
|
pub struct AssignExpr {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub op: AssignOp,
|
|
|
|
pub left: PatOrExpr,
|
|
|
|
pub right: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub struct MemberExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub obj: ExprOrSuper,
|
|
|
|
pub prop: Box<Expr>,
|
|
|
|
pub computed: bool,
|
|
|
|
}
|
2018-11-03 10:56:43 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
#[ast_node]
|
|
|
|
pub struct CondExpr {
|
2018-11-03 10:56:43 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub test: Box<Expr>,
|
|
|
|
pub cons: Box<Expr>,
|
|
|
|
pub alt: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub struct CallExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub callee: ExprOrSuper,
|
|
|
|
pub args: Vec<ExprOrSpread>,
|
|
|
|
}
|
2018-12-30 05:57:27 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
#[ast_node]
|
|
|
|
pub struct NewExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub callee: Box<Expr>,
|
2018-02-03 13:56:23 +03:00
|
|
|
pub args: Option<(Vec<ExprOrSpread>)>,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
2018-12-30 05:57:27 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
#[ast_node]
|
|
|
|
pub struct SeqExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
/// TODO: Calculate
|
|
|
|
pub span: Span,
|
2018-02-03 13:56:23 +03:00
|
|
|
pub exprs: Vec<(Box<Expr>)>,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
2018-03-04 09:17:52 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
#[ast_node]
|
|
|
|
pub struct ArrowExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub params: Vec<Pat>,
|
|
|
|
pub body: BlockStmtOrExpr,
|
2018-12-21 10:54:36 +03:00
|
|
|
pub is_async: bool,
|
|
|
|
pub is_generator: bool,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub struct YieldExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2018-02-03 13:56:23 +03:00
|
|
|
pub arg: Option<(Box<Expr>)>,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub delegate: bool,
|
|
|
|
}
|
|
|
|
#[ast_node]
|
|
|
|
pub struct MetaPropExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
#[span(lo)]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub meta: Ident,
|
2018-03-04 09:17:52 +03:00
|
|
|
#[span(hi)]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub prop: Ident,
|
|
|
|
}
|
|
|
|
#[ast_node]
|
|
|
|
pub struct AwaitExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2018-01-16 05:35:05 +03:00
|
|
|
pub arg: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
2018-01-12 10:53:06 +03:00
|
|
|
#[ast_node]
|
|
|
|
pub struct TplLit {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2018-02-03 13:56:23 +03:00
|
|
|
pub tag: Option<(Box<Expr>)>,
|
|
|
|
pub exprs: Vec<(Box<Expr>)>,
|
2018-01-12 10:53:06 +03:00
|
|
|
pub quasis: Vec<TplElement>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub struct TplElement {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2018-01-12 10:53:06 +03:00
|
|
|
pub tail: bool,
|
2018-11-25 05:31:48 +03:00
|
|
|
pub cooked: Option<Str>,
|
|
|
|
pub raw: Str,
|
2018-01-12 10:53:06 +03:00
|
|
|
}
|
|
|
|
|
2018-03-03 13:00:57 +03:00
|
|
|
#[ast_node]
|
|
|
|
pub struct ParenExpr {
|
|
|
|
pub span: Span,
|
|
|
|
pub expr: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
2018-01-12 10:53:06 +03:00
|
|
|
#[ast_node]
|
2018-03-07 08:05:09 +03:00
|
|
|
#[allow(variant_size_differences)]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub enum ExprOrSuper {
|
|
|
|
Super(Span),
|
|
|
|
Expr(Box<Expr>),
|
|
|
|
}
|
|
|
|
|
2018-03-04 09:17:52 +03:00
|
|
|
#[derive(Fold, Clone, Debug, PartialEq)]
|
2018-03-03 13:00:57 +03:00
|
|
|
pub struct ExprOrSpread {
|
|
|
|
pub spread: Option<Span>,
|
|
|
|
pub expr: Box<Expr>,
|
2018-01-12 10:53:06 +03:00
|
|
|
}
|
2018-03-04 09:17:52 +03:00
|
|
|
impl Spanned for ExprOrSpread {
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
let expr = self.expr.span();
|
|
|
|
match self.spread {
|
|
|
|
Some(spread) => expr.with_lo(spread.lo()),
|
|
|
|
None => expr,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
#[ast_node]
|
2018-03-07 08:05:09 +03:00
|
|
|
#[allow(variant_size_differences)]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub enum BlockStmtOrExpr {
|
|
|
|
BlockStmt(BlockStmt),
|
|
|
|
Expr(Box<Expr>),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub enum PatOrExpr {
|
2018-03-07 08:05:09 +03:00
|
|
|
Pat(Box<Pat>),
|
2018-01-12 10:53:06 +03:00
|
|
|
Expr(Box<Expr>),
|
|
|
|
}
|