2019-11-17 07:21:53 +03:00
|
|
|
#![allow(clippy::vec_box)]
|
2019-01-07 13:43:47 +03:00
|
|
|
use crate::{
|
|
|
|
class::Class,
|
|
|
|
function::Function,
|
2019-01-29 17:56:16 +03:00
|
|
|
ident::{Ident, PrivateName},
|
2019-01-07 13:43:47 +03:00
|
|
|
jsx::{JSXElement, JSXEmptyExpr, JSXFragment, JSXMemberExpr, JSXNamespacedName},
|
2019-02-05 06:50:19 +03:00
|
|
|
lit::{Bool, Lit, Number, Str},
|
2019-01-07 13:43:47 +03:00
|
|
|
operators::{AssignOp, BinaryOp, UnaryOp, UpdateOp},
|
|
|
|
pat::Pat,
|
|
|
|
prop::Prop,
|
|
|
|
stmt::BlockStmt,
|
|
|
|
typescript::{
|
2019-11-15 08:34:48 +03:00
|
|
|
TsAsExpr, TsConstAssertion, TsNonNullExpr, TsOptChain, TsTypeAnn, TsTypeAssertion,
|
|
|
|
TsTypeCastExpr, TsTypeParamDecl, TsTypeParamInstantiation,
|
2019-01-07 13:43:47 +03:00
|
|
|
},
|
2018-06-02 12:01:00 +03:00
|
|
|
};
|
2019-02-24 08:12:04 +03:00
|
|
|
use serde::{self, Deserialize, Serialize};
|
2019-01-17 17:17:16 +03:00
|
|
|
#[cfg(feature = "fold")]
|
|
|
|
use swc_common::Fold;
|
2019-02-05 06:50:19 +03:00
|
|
|
use swc_common::{ast_node, Span, Spanned, DUMMY_SP};
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
#[ast_node]
|
2018-03-03 13:00:57 +03:00
|
|
|
pub enum Expr {
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("ThisExpression")]
|
2018-03-03 13:00:57 +03:00
|
|
|
This(ThisExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("ArrayExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Array(ArrayLit),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("ObjectExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Object(ObjectLit),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("FunctionExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Fn(FnExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("UnaryExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Unary(UnaryExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
/// `++v`, `--v`, `v++`, `v--`
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("UpdateExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Update(UpdateExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("BinaryExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Bin(BinExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("AssignmentExpression")]
|
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.
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("MemberExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Member(MemberExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
/// true ? 'a' : 'b'
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("ConditionalExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Cond(CondExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("CallExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Call(CallExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
|
|
|
/// `new Cat()`
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("NewExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
New(NewExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("SequenceExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Seq(SeqExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("Identifier")]
|
2018-01-12 10:53:06 +03:00
|
|
|
Ident(Ident),
|
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("StringLiteral")]
|
|
|
|
#[tag("BooleanLiteral")]
|
|
|
|
#[tag("NullLiteral")]
|
|
|
|
#[tag("NumericLiteral")]
|
|
|
|
#[tag("RegExpLiteral")]
|
|
|
|
#[tag("JSXText")]
|
2018-01-12 10:53:06 +03:00
|
|
|
Lit(Lit),
|
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("TemplateLiteral")]
|
2019-01-07 13:43:47 +03:00
|
|
|
Tpl(Tpl),
|
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("TaggedTemplateExpression")]
|
2019-01-07 13:43:47 +03:00
|
|
|
TaggedTpl(TaggedTpl),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("ArrowFunctionExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Arrow(ArrowExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("ClassExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Class(ClassExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("YieldExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Yield(YieldExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("MetaProperty")]
|
2018-01-16 05:35:05 +03:00
|
|
|
MetaProp(MetaPropExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("AwaitExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
Await(AwaitExpr),
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("ParenthesisExpression")]
|
2018-03-03 13:00:57 +03:00
|
|
|
Paren(ParenExpr),
|
2018-12-30 05:57:27 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("JSXMemberExpression")]
|
2018-12-30 05:57:27 +03:00
|
|
|
JSXMebmer(JSXMemberExpr),
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("JSXNamespacedName")]
|
2018-12-30 05:57:27 +03:00
|
|
|
JSXNamespacedName(JSXNamespacedName),
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("JSXEmptyExpression")]
|
2018-12-30 05:57:27 +03:00
|
|
|
JSXEmpty(JSXEmptyExpr),
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("JSXElement")]
|
2019-11-17 07:21:53 +03:00
|
|
|
JSXElement(Box<JSXElement>),
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("JSXFragment")]
|
2018-12-30 05:57:27 +03:00
|
|
|
JSXFragment(JSXFragment),
|
2019-01-07 13:43:47 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("TsTypeAssertion")]
|
2019-01-07 13:43:47 +03:00
|
|
|
TsTypeAssertion(TsTypeAssertion),
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-09-18 16:54:12 +03:00
|
|
|
#[tag("TsConstAssertion")]
|
|
|
|
TsConstAssertion(TsConstAssertion),
|
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("TsNonNullExpression")]
|
2019-01-07 13:43:47 +03:00
|
|
|
TsNonNull(TsNonNullExpr),
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("TsTypeCastExpression")]
|
2019-01-07 13:43:47 +03:00
|
|
|
TsTypeCast(TsTypeCastExpr),
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("TsAsExpression")]
|
2019-01-07 13:43:47 +03:00
|
|
|
TsAs(TsAsExpr),
|
2019-01-29 17:56:16 +03:00
|
|
|
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("PrivateName")]
|
2019-01-29 17:56:16 +03:00
|
|
|
PrivateName(PrivateName),
|
2019-11-15 08:34:48 +03:00
|
|
|
|
|
|
|
#[tag("TsOptionalChainingExpression")]
|
|
|
|
TsOptChain(TsOptChain),
|
2018-03-03 13:00:57 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("ThisExpression")]
|
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.
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("ArrayExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct ArrayLit {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
|
|
|
#[serde(default, rename = "elements", skip_serializing_if = "Vec::is_empty")]
|
2019-11-17 07:21:53 +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.
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("ObjectExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct ObjectLit {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
|
|
|
#[serde(default, rename = "properties", skip_serializing_if = "Vec::is_empty")]
|
2018-11-17 06:30:49 +03:00
|
|
|
pub props: Vec<PropOrSpread>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub enum PropOrSpread {
|
|
|
|
/// Spread properties, e.g., `{a: 1, ...obj, b: 2}`.
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("SpreadElement")]
|
2018-11-17 06:30:49 +03:00
|
|
|
Spread(SpreadElement),
|
2019-03-05 17:16:45 +03:00
|
|
|
|
|
|
|
#[tag("*")]
|
|
|
|
Prop(Box<Prop>),
|
2018-11-17 06:30:49 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("SpreadElement")]
|
2018-11-17 06:30:49 +03:00
|
|
|
pub struct SpreadElement {
|
2019-02-20 05:35:41 +03:00
|
|
|
#[serde(rename = "spread")]
|
2018-11-17 06:30:49 +03:00
|
|
|
#[span(lo)]
|
|
|
|
pub dot3_token: Span,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[serde(rename = "arguments")]
|
2018-11-17 06:30:49 +03:00
|
|
|
#[span(hi)]
|
|
|
|
pub expr: Box<Expr>,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("UnaryExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct UnaryExpr {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "operator")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub op: UnaryOp,
|
2018-01-12 10:53:06 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[serde(rename = "argument")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub arg: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("UpdateExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct UpdateExpr {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "operator")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub op: UpdateOp,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub prefix: bool,
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[serde(rename = "argument")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub arg: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("BinaryExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct BinExpr {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "operator")]
|
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.
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("FunctionExpression")]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub struct FnExpr {
|
2019-02-25 13:07:20 +03:00
|
|
|
#[serde(
|
|
|
|
default,
|
|
|
|
rename = "identifier",
|
|
|
|
skip_serializing_if = "Option::is_none"
|
|
|
|
)]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub ident: Option<Ident>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(flatten)]
|
2018-03-04 09:17:52 +03:00
|
|
|
#[span]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub function: Function,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Class expression.
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("ClassExpression")]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub struct ClassExpr {
|
2019-02-25 13:07:20 +03:00
|
|
|
#[serde(
|
|
|
|
default,
|
|
|
|
rename = "identifier",
|
|
|
|
skip_serializing_if = "Option::is_none"
|
|
|
|
)]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub ident: Option<Ident>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(flatten)]
|
2018-03-04 09:17:52 +03:00
|
|
|
#[span]
|
2018-01-12 10:53:06 +03:00
|
|
|
pub class: Class,
|
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("AssignmentExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct AssignExpr {
|
2018-03-03 13:00:57 +03:00
|
|
|
pub span: Span,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[serde(rename = "operator")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub op: AssignOp,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub left: PatOrExpr,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub right: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("MemberExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct MemberExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "object")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub obj: ExprOrSuper,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "property")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub prop: Box<Expr>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub computed: bool,
|
|
|
|
}
|
2018-11-03 10:56:43 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("ConditionalExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct CondExpr {
|
2018-11-03 10:56:43 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub test: Box<Expr>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "consequent")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub cons: Box<Expr>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "alternate")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub alt: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("CallExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct CallExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub callee: ExprOrSuper,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[serde(default, rename = "arguments")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub args: Vec<ExprOrSpread>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[serde(default, rename = "typeArguments")]
|
2019-01-07 13:43:47 +03:00
|
|
|
pub type_args: Option<TsTypeParamInstantiation>,
|
|
|
|
// pub type_params: Option<TsTypeParamInstantiation>,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
2018-12-30 05:57:27 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("NewExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct NewExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub callee: Box<Expr>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[serde(default, rename = "arguments")]
|
2019-11-17 07:21:53 +03:00
|
|
|
pub args: Option<Vec<ExprOrSpread>>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[serde(default, rename = "typeArguments")]
|
2019-01-07 13:43:47 +03:00
|
|
|
pub type_args: Option<TsTypeParamInstantiation>,
|
|
|
|
// pub type_params: Option<TsTypeParamInstantiation>,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
2018-12-30 05:57:27 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("SequenceExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct SeqExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "expressions")]
|
2019-02-24 08:12:04 +03:00
|
|
|
pub exprs: Vec<Box<Expr>>,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
2018-03-04 09:17:52 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("ArrowFunctionExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct ArrowExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub params: Vec<Pat>,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2018-01-16 05:35:05 +03:00
|
|
|
pub body: BlockStmtOrExpr,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-02-25 13:07:20 +03:00
|
|
|
#[serde(default, rename = "async")]
|
2018-12-21 10:54:36 +03:00
|
|
|
pub is_async: bool,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-02-25 13:07:20 +03:00
|
|
|
#[serde(default, rename = "generator")]
|
2018-12-21 10:54:36 +03:00
|
|
|
pub is_generator: bool,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[serde(
|
|
|
|
default,
|
|
|
|
rename = "typeParameters",
|
|
|
|
skip_serializing_if = "Option::is_none"
|
|
|
|
)]
|
2019-01-07 13:43:47 +03:00
|
|
|
pub type_params: Option<TsTypeParamDecl>,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
|
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
2019-01-07 13:43:47 +03:00
|
|
|
pub return_type: Option<TsTypeAnn>,
|
2018-01-16 05:35:05 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("YieldExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct YieldExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[serde(default, rename = "argument", skip_serializing_if = "Option::is_none")]
|
|
|
|
pub arg: Option<Box<Expr>>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[serde(default)]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub delegate: bool,
|
|
|
|
}
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("MetaProperty")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct MetaPropExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
#[span(lo)]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub meta: Ident,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[serde(rename = "property")]
|
2018-03-04 09:17:52 +03:00
|
|
|
#[span(hi)]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub prop: Ident,
|
|
|
|
}
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[ast_node("AwaitExpression")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub struct AwaitExpr {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "argument")]
|
2018-01-16 05:35:05 +03:00
|
|
|
pub arg: Box<Expr>,
|
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("TemplateLiteral")]
|
2019-01-07 13:43:47 +03:00
|
|
|
pub struct Tpl {
|
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "expressions")]
|
2019-02-24 08:12:04 +03:00
|
|
|
pub exprs: Vec<Box<Expr>>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-01-07 13:43:47 +03:00
|
|
|
pub quasis: Vec<TplElement>,
|
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("TaggedTemplateExpression")]
|
2019-01-07 13:43:47 +03:00
|
|
|
pub struct TaggedTpl {
|
2018-03-04 09:17:52 +03:00
|
|
|
pub span: Span,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-01-07 13:43:47 +03:00
|
|
|
pub tag: Box<Expr>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
|
|
|
#[serde(rename = "expressions")]
|
2019-02-24 08:12:04 +03:00
|
|
|
pub exprs: Vec<Box<Expr>>,
|
2018-01-12 10:53:06 +03:00
|
|
|
pub quasis: Vec<TplElement>,
|
2019-02-20 05:35:41 +03:00
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[serde(
|
|
|
|
default,
|
|
|
|
rename = "typeParameters",
|
|
|
|
skip_serializing_if = "Option::is_none"
|
|
|
|
)]
|
2019-01-07 13:43:47 +03:00
|
|
|
pub type_params: Option<TsTypeParamInstantiation>,
|
2018-01-12 10:53:06 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 05:35:41 +03:00
|
|
|
#[ast_node("TemplateElement")]
|
2018-01-12 10:53:06 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[ast_node("ParenthesisExpression")]
|
2018-03-03 13:00:57 +03:00
|
|
|
pub struct ParenExpr {
|
|
|
|
pub span: Span,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2019-02-25 13:07:20 +03:00
|
|
|
#[serde(rename = "expression")]
|
2018-03-03 13:00:57 +03:00
|
|
|
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 {
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("Super")]
|
|
|
|
Super(Super),
|
|
|
|
|
|
|
|
#[tag("*")]
|
2018-01-12 10:53:06 +03:00
|
|
|
Expr(Box<Expr>),
|
2019-03-05 17:16:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node("Super")]
|
|
|
|
#[derive(Copy)]
|
|
|
|
pub struct Super {
|
|
|
|
pub span: Span,
|
2018-01-12 10:53:06 +03:00
|
|
|
}
|
|
|
|
|
2019-02-24 08:12:04 +03:00
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2019-01-17 17:17:16 +03:00
|
|
|
#[cfg_attr(feature = "fold", derive(Fold))]
|
2018-03-03 13:00:57 +03:00
|
|
|
pub struct ExprOrSpread {
|
2019-02-24 08:12:04 +03:00
|
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
2018-03-03 13:00:57 +03:00
|
|
|
pub spread: Option<Span>,
|
2019-02-24 08:12:04 +03:00
|
|
|
|
2018-03-03 13:00:57 +03:00
|
|
|
pub expr: Box<Expr>,
|
2018-01-12 10:53:06 +03:00
|
|
|
}
|
2019-02-24 08:12:04 +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 {
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("BlockStatement")]
|
2018-01-12 10:53:06 +03:00
|
|
|
BlockStmt(BlockStmt),
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("*")]
|
2018-01-12 10:53:06 +03:00
|
|
|
Expr(Box<Expr>),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[ast_node]
|
|
|
|
pub enum PatOrExpr {
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("ThisExpression")]
|
|
|
|
#[tag("ArrayExpression")]
|
|
|
|
#[tag("ObjectExpression")]
|
|
|
|
#[tag("FunctionExpression")]
|
|
|
|
#[tag("UnaryExpression")]
|
|
|
|
#[tag("UpdateExpression")]
|
|
|
|
#[tag("BinaryExpression")]
|
|
|
|
#[tag("AssignmentExpression")]
|
|
|
|
#[tag("MemberExpression")]
|
|
|
|
#[tag("ConditionalExpression")]
|
|
|
|
#[tag("CallExpression")]
|
|
|
|
#[tag("NewExpression")]
|
|
|
|
#[tag("SequenceExpression")]
|
|
|
|
#[tag("StringLiteral")]
|
|
|
|
#[tag("BooleanLiteral")]
|
|
|
|
#[tag("NullLiteral")]
|
|
|
|
#[tag("NumericLiteral")]
|
|
|
|
#[tag("RegExpLiteral")]
|
|
|
|
#[tag("JSXText")]
|
|
|
|
#[tag("TemplateLiteral")]
|
|
|
|
#[tag("TaggedTemplateLiteral")]
|
|
|
|
#[tag("ArrowFunctionExpression")]
|
|
|
|
#[tag("ClassExpression")]
|
|
|
|
#[tag("YieldExpression")]
|
|
|
|
#[tag("MetaProperty")]
|
|
|
|
#[tag("AwaitExpression")]
|
|
|
|
#[tag("ParenthesisExpression")]
|
|
|
|
#[tag("JSXMemberExpression")]
|
|
|
|
#[tag("JSXNamespacedName")]
|
|
|
|
#[tag("JSXEmptyExpression")]
|
|
|
|
#[tag("JSXElement")]
|
|
|
|
#[tag("JSXFragment")]
|
|
|
|
#[tag("TsTypeAssertion")]
|
2019-09-18 16:54:12 +03:00
|
|
|
#[tag("TsConstAssertion")]
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("TsNonNullExpression")]
|
|
|
|
#[tag("TsTypeCastExpression")]
|
|
|
|
#[tag("TsAsExpression")]
|
|
|
|
#[tag("PrivateName")]
|
2018-01-12 10:53:06 +03:00
|
|
|
Expr(Box<Expr>),
|
2019-03-05 17:16:45 +03:00
|
|
|
#[tag("*")]
|
2019-02-24 08:12:04 +03:00
|
|
|
Pat(Box<Pat>),
|
2018-01-12 10:53:06 +03:00
|
|
|
}
|
2019-02-05 06:50:19 +03:00
|
|
|
|
|
|
|
impl From<bool> for Expr {
|
|
|
|
fn from(value: bool) -> Self {
|
|
|
|
Expr::Lit(Lit::Bool(Bool {
|
|
|
|
span: DUMMY_SP,
|
|
|
|
value,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<f64> for Expr {
|
|
|
|
fn from(value: f64) -> Self {
|
|
|
|
Expr::Lit(Lit::Num(Number {
|
|
|
|
span: DUMMY_SP,
|
|
|
|
value,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Bool> for Expr {
|
|
|
|
fn from(v: Bool) -> Self {
|
|
|
|
Expr::Lit(Lit::Bool(v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Number> for Expr {
|
|
|
|
fn from(v: Number) -> Self {
|
|
|
|
Expr::Lit(Lit::Num(v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Str> for Expr {
|
|
|
|
fn from(v: Str) -> Self {
|
|
|
|
Expr::Lit(Lit::Str(v))
|
|
|
|
}
|
|
|
|
}
|
2019-02-24 08:12:04 +03:00
|
|
|
|
|
|
|
test_de!(
|
|
|
|
jsx_element,
|
|
|
|
JSXElement,
|
|
|
|
r#"{
|
|
|
|
"type": "JSXElement",
|
|
|
|
"span": {
|
|
|
|
"start": 0,
|
|
|
|
"end": 5,
|
|
|
|
"ctxt": 0
|
|
|
|
},
|
|
|
|
"opening": {
|
|
|
|
"type": "JSXOpeningElement",
|
|
|
|
"name": {
|
|
|
|
"type": "Identifier",
|
|
|
|
"span": {
|
|
|
|
"start": 1,
|
|
|
|
"end": 2,
|
|
|
|
"ctxt": 0
|
|
|
|
},
|
|
|
|
"value": "a",
|
|
|
|
"optional": false
|
|
|
|
},
|
|
|
|
"span": {
|
|
|
|
"start": 1,
|
|
|
|
"end": 5,
|
|
|
|
"ctxt": 0
|
|
|
|
},
|
|
|
|
"selfClosing": true
|
|
|
|
},
|
|
|
|
"children": [],
|
|
|
|
"closing": null
|
|
|
|
}"#
|
|
|
|
);
|