use crate::g as G;
use crate::{
Case, Catch, ClauseItem, EnumValue, ExprNodeIndex, Finally, LocRef, Ref, StmtData,
StmtNodeIndex, StmtNodeList, StmtOrExpr,
};
use crate::{StoreSlice, StoreStr};
pub struct Block {
pub stmts: StmtNodeList,
pub close_brace_loc: crate::Loc, }
impl Default for Block {
fn default() -> Self {
Self {
stmts: StmtNodeList::EMPTY,
close_brace_loc: crate::Loc::EMPTY,
}
}
}
#[derive(Default)]
pub struct SExpr {
pub value: ExprNodeIndex,
pub does_not_affect_tree_shaking: bool, }
pub struct Comment {
pub text: StoreStr, }
pub struct Directive {
pub value: StoreStr, }
#[derive(Default)]
pub struct ExportClause {
pub items: StoreSlice<ClauseItem>, pub is_single_line: bool,
}
#[derive(Clone, Copy, Default)]
pub struct Empty {}
pub struct ExportStar {
pub namespace_ref: Ref,
pub alias: Option<G::ExportStarAlias>, pub import_record_index: u32,
}
pub struct ExportEquals {
pub value: ExprNodeIndex,
}
pub struct Label {
pub name: LocRef,
pub stmt: StmtNodeIndex,
}
#[derive(Clone, Copy, Default)]
pub struct TypeScript {}
#[derive(Clone, Copy, Default)]
pub struct Debugger {}
pub struct ExportFrom {
pub items: StoreSlice<ClauseItem>, pub namespace_ref: Ref,
pub import_record_index: u32,
pub is_single_line: bool,
}
pub struct ExportDefault {
pub default_name: LocRef, pub value: StmtOrExpr,
}
impl ExportDefault {
pub fn can_be_moved(&self) -> bool {
match &self.value {
StmtOrExpr::Expr(e) => e.can_be_moved(),
StmtOrExpr::Stmt(s) => match &s.data {
StmtData::SClass(class) => class.class.can_be_moved(),
StmtData::SFunction(_) => true,
_ => false,
},
}
}
}
pub struct Enum {
pub name: LocRef,
pub arg: Ref,
pub values: StoreSlice<EnumValue>, pub is_export: bool,
}
pub struct Namespace {
pub name: LocRef,
pub arg: Ref,
pub stmts: StmtNodeList,
pub is_export: bool,
}
pub struct Function {
pub func: G::Fn,
}
#[derive(Default)]
pub struct Class {
pub class: G::Class,
pub is_export: bool, }
pub struct If {
pub test_: ExprNodeIndex,
pub yes: StmtNodeIndex,
pub no: Option<StmtNodeIndex>,
}
pub struct For {
pub init: Option<StmtNodeIndex>, pub test_: Option<ExprNodeIndex>, pub update: Option<ExprNodeIndex>, pub body: StmtNodeIndex,
}
pub struct ForIn {
pub init: StmtNodeIndex,
pub value: ExprNodeIndex,
pub body: StmtNodeIndex,
}
pub struct ForOf {
pub is_await: bool, pub init: StmtNodeIndex,
pub value: ExprNodeIndex,
pub body: StmtNodeIndex,
}
pub struct DoWhile {
pub body: StmtNodeIndex,
pub test_: ExprNodeIndex,
}
pub struct While {
pub test_: ExprNodeIndex,
pub body: StmtNodeIndex,
}
pub struct With {
pub value: ExprNodeIndex,
pub body: StmtNodeIndex,
pub body_loc: crate::Loc, }
pub struct Try {
pub body_loc: crate::Loc,
pub body: StmtNodeList,
pub catch_: Option<Catch>, pub finally: Option<Finally>, }
pub struct Switch {
pub test_: ExprNodeIndex,
pub body_loc: crate::Loc,
pub cases: StoreSlice<Case>, }
pub struct Import {
pub namespace_ref: Ref,
pub default_name: Option<LocRef>, pub items: StoreSlice<ClauseItem>, pub star_name_loc: Option<crate::Loc>, pub import_record_index: u32,
pub is_single_line: bool, pub phase_defer: bool, }
impl Default for Import {
fn default() -> Self {
Self {
namespace_ref: Ref::NONE,
default_name: None,
items: StoreSlice::EMPTY,
star_name_loc: None,
import_record_index: u32::MAX,
is_single_line: false,
phase_defer: false,
}
}
}
#[derive(Default)]
pub struct Return {
pub value: Option<ExprNodeIndex>, }
pub struct Throw {
pub value: ExprNodeIndex,
}
pub struct Local {
pub kind: Kind, pub decls: G::DeclList, pub is_export: bool, pub was_ts_import_equals: bool,
pub was_commonjs_export: bool, }
impl Default for Local {
fn default() -> Self {
Self {
kind: Kind::default(),
decls: bun_alloc::AstAlloc::vec(),
is_export: false,
was_ts_import_equals: false,
was_commonjs_export: false,
}
}
}
impl Local {
pub fn can_merge_with(&self, other: &Local) -> bool {
if self.kind.is_using() {
return false;
}
self.kind == other.kind
&& self.is_export == other.is_export
&& self.was_commonjs_export == other.was_commonjs_export
}
}
#[derive(Clone, Copy, PartialEq, Eq, Default, strum::IntoStaticStr)]
pub enum Kind {
#[default]
#[strum(serialize = "k_var")]
KVar,
#[strum(serialize = "k_let")]
KLet,
#[strum(serialize = "k_const")]
KConst,
#[strum(serialize = "k_using")]
KUsing,
#[strum(serialize = "k_await_using")]
KAwaitUsing,
}
impl Kind {
pub fn is_using(self) -> bool {
matches!(self, Kind::KUsing | Kind::KAwaitUsing)
}
pub fn is_reassignable(self) -> bool {
matches!(self, Kind::KVar | Kind::KLet)
}
}
#[derive(Default)]
pub struct Break {
pub label: Option<LocRef>, }
#[derive(Default)]
pub struct Continue {
pub label: Option<LocRef>, }