use crate::lexer::Span;
use crate::parser::{Literal, ObjectPatternProp};
use super::swc_metadata::*;
#[derive(Debug, Clone)]
pub struct DecoratedPattern {
pub kind: DecoratedPatternKind,
pub metadata: SwcPatternMetadata,
}
#[derive(Debug, Clone)]
pub enum DecoratedPatternKind {
Literal(Literal),
Ident(String),
Wildcard,
Tuple(Vec<DecoratedPattern>),
Struct {
name: String,
fields: Vec<(String, DecoratedPattern)>,
},
Variant {
name: String,
inner: Option<Box<DecoratedPattern>>,
},
Array(Vec<DecoratedPattern>),
Object(Vec<ObjectPatternProp>),
Rest(Box<DecoratedPattern>),
Or(Vec<DecoratedPattern>),
Ref {
is_mut: bool,
pattern: Box<DecoratedPattern>,
},
}
#[derive(Debug, Clone)]
pub struct DecoratedExpr {
pub kind: DecoratedExprKind,
pub metadata: SwcExprMetadata,
}
#[derive(Debug, Clone)]
pub enum DecoratedExprKind {
Literal(Literal),
Ident {
name: String,
ident_metadata: SwcIdentifierMetadata,
},
Binary {
left: Box<DecoratedExpr>,
op: crate::parser::BinaryOp,
right: Box<DecoratedExpr>,
binary_metadata: SwcBinaryMetadata,
},
Unary {
op: crate::parser::UnaryOp,
operand: Box<DecoratedExpr>,
unary_metadata: SwcUnaryMetadata,
},
Call(Box<DecoratedCallExpr>),
Member {
object: Box<DecoratedExpr>,
property: String,
optional: bool,
computed: bool,
is_path: bool,
field_metadata: SwcFieldMetadata,
},
Index {
object: Box<DecoratedExpr>,
index: Box<DecoratedExpr>,
},
StructInit(DecoratedStructInit),
VecInit(Vec<DecoratedExpr>),
If(Box<DecoratedIfExpr>),
Match(Box<DecoratedMatchExpr>),
Closure(DecoratedClosureExpr),
Ref {
mutable: bool,
expr: Box<DecoratedExpr>,
},
Deref(Box<DecoratedExpr>),
Assign {
left: Box<DecoratedExpr>,
right: Box<DecoratedExpr>,
},
CompoundAssign {
left: Box<DecoratedExpr>,
op: crate::parser::CompoundAssignOp,
right: Box<DecoratedExpr>,
},
Range {
start: Option<Box<DecoratedExpr>>,
end: Option<Box<DecoratedExpr>>,
inclusive: bool,
},
Paren(Box<DecoratedExpr>),
Block(DecoratedBlock),
Try(Box<DecoratedExpr>),
Tuple(Vec<DecoratedExpr>),
Matches {
expr: Box<DecoratedExpr>,
pattern: DecoratedPattern,
},
Return(Option<Box<DecoratedExpr>>),
Break,
Continue,
RegexCall(Box<DecoratedRegexCall>),
CustomPropAccess(Box<DecoratedCustomPropAccess>),
}
#[derive(Debug, Clone)]
pub struct DecoratedCallExpr {
pub callee: DecoratedExpr,
pub args: Vec<DecoratedExpr>,
pub type_args: Vec<crate::parser::TsType>,
pub optional: bool,
pub is_macro: bool,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct DecoratedRegexCall {
pub method: crate::parser::RegexMethod,
pub text_arg: DecoratedExpr,
pub pattern: String,
pub replacement_arg: Option<DecoratedExpr>,
pub metadata: SwcRegexMetadata,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct DecoratedStructInit {
pub name: String,
pub fields: Vec<(String, DecoratedExpr)>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct DecoratedIfStmt {
pub condition: DecoratedExpr,
pub pattern: Option<DecoratedPattern>,
pub then_branch: DecoratedBlock,
pub else_branch: Option<DecoratedBlock>,
pub if_let_metadata: Option<SwcIfLetMetadata>,
}
#[derive(Debug, Clone)]
pub struct DecoratedBlock {
pub stmts: Vec<DecoratedStmt>,
}
#[derive(Debug, Clone)]
pub struct DecoratedClosureExpr {
pub params: Vec<crate::parser::ClosureParam>,
pub body: Box<DecoratedExpr>,
pub span: crate::lexer::Span,
}
#[derive(Debug, Clone)]
pub struct DecoratedNestedFnDecl {
pub is_pub: bool,
pub name: String,
pub type_params: Vec<crate::parser::GenericParam>,
pub params: Vec<crate::parser::Param>,
pub return_type: Option<crate::parser::Type>,
pub where_clause: Vec<crate::parser::WherePredicate>,
pub body: DecoratedBlock,
pub span: crate::lexer::Span,
}
#[derive(Debug, Clone)]
pub enum DecoratedStmt {
Let(DecoratedLetStmt),
Const(DecoratedConstStmt),
Expr(DecoratedExpr),
If(DecoratedIfStmt),
Match(DecoratedMatchStmt),
For(DecoratedForStmt),
While(DecoratedWhileStmt),
Loop(DecoratedBlock),
Return(Option<DecoratedExpr>),
Break,
Continue,
Traverse(Box<DecoratedTraverseStmt>),
Function(DecoratedNestedFnDecl),
Verbatim(crate::parser::VerbatimStmt), CustomPropAssignment(Box<DecoratedCustomPropAssignment>),
Unsafe(DecoratedUnsafeBlock),
}
#[derive(Debug, Clone)]
pub struct DecoratedUnsafeBlock {
pub stmts: Vec<DecoratedStmt>,
}
#[derive(Debug, Clone)]
pub struct DecoratedLetStmt {
pub mutable: bool,
pub pattern: DecoratedPattern,
pub ty: Option<crate::parser::Type>,
pub init: Option<DecoratedExpr>,
}
#[derive(Debug, Clone)]
pub struct DecoratedConstStmt {
pub name: String,
pub ty: Option<crate::parser::Type>,
pub init: DecoratedExpr,
}
#[derive(Debug, Clone)]
pub struct DecoratedMatchStmt {
pub expr: DecoratedExpr,
pub arms: Vec<DecoratedMatchArm>,
}
#[derive(Debug, Clone)]
pub struct DecoratedMatchArm {
pub pattern: DecoratedPattern,
pub guard: Option<DecoratedExpr>,
pub body: DecoratedBlock,
}
#[derive(Debug, Clone)]
pub struct DecoratedForStmt {
pub pattern: DecoratedPattern,
pub iter: DecoratedExpr,
pub body: DecoratedBlock,
}
#[derive(Debug, Clone)]
pub struct DecoratedWhileStmt {
pub condition: DecoratedExpr,
pub body: DecoratedBlock,
}
#[derive(Debug, Clone)]
pub struct DecoratedIfExpr {
pub condition: DecoratedExpr,
pub pattern: Option<DecoratedPattern>,
pub then_branch: DecoratedBlock,
pub else_branch: Option<DecoratedBlock>,
}
#[derive(Debug, Clone)]
pub struct DecoratedMatchExpr {
pub expr: DecoratedExpr,
pub arms: Vec<DecoratedMatchArm>,
}
impl DecoratedPattern {
pub fn new(kind: DecoratedPatternKind, metadata: SwcPatternMetadata) -> Self {
Self { kind, metadata }
}
}
impl DecoratedExpr {
pub fn new(kind: DecoratedExprKind, metadata: SwcExprMetadata) -> Self {
Self { kind, metadata }
}
}
#[derive(Debug, Clone)]
pub struct DecoratedCustomPropAssignment {
pub node: DecoratedExpr,
pub property: String,
pub value: DecoratedExpr,
pub metadata: SwcCustomPropAssignmentMetadata,
}
#[derive(Debug, Clone)]
pub struct DecoratedCustomPropAccess {
pub node: Box<DecoratedExpr>,
pub property: String,
pub metadata: SwcCustomPropAccessMetadata,
}
#[derive(Debug, Clone)]
pub struct DecoratedTraverseStmt {
pub target: DecoratedExpr,
pub captures: Vec<crate::parser::Capture>,
pub kind: DecoratedTraverseKind,
pub span: crate::lexer::Span,
}
#[derive(Debug, Clone)]
pub enum DecoratedTraverseKind {
Inline(DecoratedInlineVisitor),
Delegated(String),
}
#[derive(Debug, Clone)]
pub struct DecoratedInlineVisitor {
pub state: Vec<crate::parser::LetStmt>, pub methods: Vec<DecoratedVisitorMethod>,
}
#[derive(Debug, Clone)]
pub struct DecoratedVisitorMethod {
pub name: String,
pub params: Vec<crate::parser::Param>,
pub body: DecoratedBlock,
}