Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion crates/swc_ecma_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rkyv-impl = [
"swc_atoms/rkyv-impl",
"swc_common/rkyv-impl",
]
serde-impl = ["serde"]
serde-impl = ["serde", "dep:serde_json"]
shrink-to-fit = [
"dep:shrink-to-fit",
"swc_atoms/shrink-to-fit",
Expand All @@ -54,6 +54,7 @@ rancor = { workspace = true, optional = true }
rkyv = { workspace = true, optional = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"], optional = true }
serde_json = { workspace = true, optional = true }
shrink-to-fit = { workspace = true, optional = true }
unicode-id-start = { workspace = true }

Expand All @@ -66,3 +67,4 @@ cbor4ii = { workspace = true, features = ["use_std"], optional = true }

[dev-dependencies]
serde_json = { workspace = true }
swc_ecma_parser = { version = "38.0.0", path = "../swc_ecma_parser", features = ["typescript"] }
2 changes: 2 additions & 0 deletions crates/swc_ecma_ast/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
pub struct Class {
pub span: Span,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub ctxt: SyntaxContext,

#[cfg_attr(feature = "serde-impl", serde(default))]
Expand Down Expand Up @@ -278,6 +279,7 @@ pub struct PrivateMethod {
pub struct Constructor {
pub span: Span,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub ctxt: SyntaxContext,

pub key: PropName,
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_ast/src/decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl Take for ClassDecl {
pub struct VarDecl {
pub span: Span,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub ctxt: SyntaxContext,

pub kind: VarDeclKind,
Expand Down
5 changes: 5 additions & 0 deletions crates/swc_ecma_ast/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ impl Take for CondExpr {
#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
pub struct CallExpr {
pub span: Span,
#[cfg_attr(feature = "serde-impl", serde(default))]
pub ctxt: SyntaxContext,

pub callee: Callee,
Expand Down Expand Up @@ -1026,6 +1027,7 @@ impl Take for CallExpr {
pub struct NewExpr {
pub span: Span,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub ctxt: SyntaxContext,

pub callee: Box<Expr>,
Expand Down Expand Up @@ -1079,6 +1081,7 @@ impl Take for SeqExpr {
pub struct ArrowExpr {
pub span: Span,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub ctxt: SyntaxContext,

pub params: Vec<Pat>,
Expand Down Expand Up @@ -1214,6 +1217,7 @@ impl Take for Tpl {
pub struct TaggedTpl {
pub span: Span,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub ctxt: SyntaxContext,

pub tag: Box<Expr>,
Expand Down Expand Up @@ -1748,6 +1752,7 @@ impl Default for OptChainBase {
pub struct OptCall {
pub span: Span,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub ctxt: SyntaxContext,

pub callee: Box<Expr>,
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_ast/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Function {

pub span: Span,

#[cfg_attr(feature = "serde-impl", serde(default))]
pub ctxt: SyntaxContext,

#[cfg_attr(feature = "serde-impl", serde(default))]
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_ast/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub struct Ident {
#[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))]
pub span: Span,

#[cfg_attr(feature = "serde-impl", serde(default))]
#[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))]
pub ctxt: SyntaxContext,

Expand Down
2 changes: 2 additions & 0 deletions crates/swc_ecma_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ mod module_decl;
mod operators;
mod pat;
mod prop;
#[cfg(feature = "serde-impl")]
mod serde_impl;
mod source_map;
mod stmt;
mod typescript;
Expand Down
51 changes: 49 additions & 2 deletions crates/swc_ecma_ast/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,58 @@ use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span, DUMMY_SP};

use crate::{module_decl::ModuleDecl, stmt::Stmt};

#[ast_node]
#[derive(Eq, Hash, Is, EqIgnoreSpan)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
::swc_common::FromVariant,
::swc_common::Spanned,
Debug,
PartialEq,
::swc_common::DeserializeEnum,
Clone,
Eq,
Hash,
Is,
EqIgnoreSpan,
)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
#[cfg_attr(swc_ast_unknown, non_exhaustive)]
#[cfg_attr(
feature = "rkyv-impl",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(
feature = "rkyv-impl",
rkyv(deserialize_bounds(__D::Error: rkyv::rancor::Source))
)]
#[cfg_attr(feature = "rkyv-impl", repr(u32))]
#[cfg_attr(
feature = "rkyv-impl",
rkyv(
serialize_bounds(
__S: rkyv::ser::Writer + rkyv::ser::Allocator,
__S::Error: rkyv::rancor::Source
)
)
)]
#[cfg_attr(
feature = "rkyv-impl",
rkyv(bytecheck(bounds(
__C: rkyv::validation::ArchiveContext,
__C::Error: rkyv::rancor::Source
)))
)]
#[cfg_attr(
feature = "encoding-impl",
derive(::swc_common::Encode, ::swc_common::Decode)
)]
pub enum Program {
#[cfg(all(swc_ast_unknown, feature = "encoding-impl"))]
#[from_variant(ignore)]
#[span(unknown)]
#[encoding(unknown)]
Unknown(u32, swc_common::unknown::Unknown),

#[tag("Module")]
Module(Module),
#[tag("Script")]
Expand Down
Loading
Loading