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
2 changes: 2 additions & 0 deletions crates/swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ fn downgrade_flow_script_like_module(program: Program) -> Result<Program, Error>
}

let Module {
node_id,
span,
body,
shebang,
Expand All @@ -311,6 +312,7 @@ fn downgrade_flow_script_like_module(program: Program) -> Result<Program, Error>
.collect::<Result<_, Error>>()?;

Ok(Program::Script(Script {
node_id,
span,
body,
shebang,
Expand Down
1 change: 1 addition & 0 deletions crates/swc_bundler/src/bundler/chunk/cjs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ where
info.id,
Module {
span: DUMMY_SP,
node_id: Default::default(),
body: vec![stmt],
shebang: None,
},
Expand Down
1 change: 1 addition & 0 deletions crates/swc_bundler/src/bundler/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ where

Module {
span: DUMMY_SP,
node_id: Default::default(),
shebang: None,
body: vec![ModuleItem::Stmt(Stmt::Expr(ExprStmt {
span: DUMMY_SP,
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_bundler/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ impl Modules {
cm,
&Module {
span: DUMMY_SP,
node_id: Default::default(),
body: stmts,
shebang: None,
},
Expand All @@ -304,6 +305,7 @@ impl From<Modules> for Module {
// TODO
Self {
span: DUMMY_SP,
node_id: Default::default(),
body: modules.into_items(),
shebang: None,
}
Expand Down
1 change: 1 addition & 0 deletions crates/swc_bundler/src/modules/sort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl Modules {

let module = Module {
span: DUMMY_SP,
node_id: Default::default(),
body: buf,
shebang: None,
};
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_bundler/src/modules/sort/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ mod tests {
"first item",
&t.cm,
&Module {
node_id: Default::default(),
span: DUMMY_SP,
body: vec![module.body[dep].clone()],
shebang: None,
Expand All @@ -850,6 +851,7 @@ mod tests {
"second item",
&t.cm,
&Module {
node_id: Default::default(),
span: DUMMY_SP,
body: vec![module.body[i].clone()],
shebang: None,
Expand Down
1 change: 1 addition & 0 deletions crates/swc_bundler/src/modules/sort/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn assert_sorted_with_free(src: &[&str], free: &str, res: &str) {
let sorted = sort_stmts(t.bundler.injected_ctxt, modules, &t.cm);

let actual: Module = drop_span(Module {
node_id: Default::default(),
span: DUMMY_SP,
body: sorted,
shebang: None,
Expand Down
8 changes: 7 additions & 1 deletion crates/swc_ecma_ast/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
Accessibility, TsExprWithTypeArgs, TsIndexSignature, TsTypeAnn, TsTypeParamDecl,
TsTypeParamInstantiation,
},
BigInt, ComputedPropName, EmptyStmt, Id, Ident, IdentName, Number,
BigInt, ComputedPropName, EmptyStmt, Id, Ident, IdentName, NodeId, Number,
};

#[ast_node]
Expand All @@ -23,6 +23,9 @@ pub struct Class {

pub ctxt: SyntaxContext,

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

#[cfg_attr(feature = "serde-impl", serde(default))]
pub decorators: Vec<Decorator>,

Expand Down Expand Up @@ -280,6 +283,9 @@ pub struct Constructor {

pub ctxt: SyntaxContext,

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

pub key: PropName,

pub params: Vec<ParamOrTsParamProp>,
Expand Down
5 changes: 4 additions & 1 deletion crates/swc_ecma_ast/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
TsTypeAssertion, TsTypeParamDecl, TsTypeParamInstantiation,
},
ArrayPat, BindingIdent, ComputedPropName, Id, IdentName, ImportPhase, Invalid, KeyValueProp,
Number, ObjectPat, PropName, Str,
NodeId, Number, ObjectPat, PropName, Str,
};

#[ast_node(no_clone)]
Expand Down Expand Up @@ -1081,6 +1081,9 @@ pub struct ArrowExpr {

pub ctxt: SyntaxContext,

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

pub params: Vec<Pat>,

/// This is boxed to reduce the type size of [Expr].
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_ecma_ast/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
pat::Pat,
stmt::BlockStmt,
typescript::{TsParamProp, TsTypeAnn, TsTypeParamDecl},
NodeId,
};

/// Common parts of function and method.
Expand All @@ -23,6 +24,9 @@ pub struct Function {

pub ctxt: SyntaxContext,

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

#[cfg_attr(feature = "serde-impl", serde(default))]
#[cfg_attr(
feature = "encoding-impl",
Expand Down
18 changes: 17 additions & 1 deletion crates/swc_ecma_ast/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use swc_common::{
ast_node, util::take::Take, BytePos, EqIgnoreSpan, Mark, Span, Spanned, SyntaxContext, DUMMY_SP,
};

use crate::{typescript::TsTypeAnn, Expr};
use crate::{typescript::TsTypeAnn, BindingId, Expr, ScopeId};

/// Identifier used as a pattern.
#[derive(Clone, Debug, PartialEq, Eq, Hash, EqIgnoreSpan, Default)]
Expand Down Expand Up @@ -97,6 +97,7 @@ impl From<&'_ BindingIdent> for Ident {
Ident {
span: bi.span,
ctxt: bi.ctxt,
scope_id: bi.scope_id,
sym: bi.sym.clone(),
optional: bi.optional,
}
Expand Down Expand Up @@ -185,8 +186,13 @@ pub struct Ident {
pub span: Span,

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

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

#[cfg_attr(feature = "serde-impl", serde(rename = "value"))]
pub sym: Atom,

Expand Down Expand Up @@ -269,6 +275,14 @@ impl Ident {
(self.sym.clone(), self.ctxt)
}

/// Creates an id using the resolver-assigned scope id of `self`.
pub fn to_binding_id(&self) -> BindingId {
BindingId {
sym: self.sym.clone(),
scope_id: self.scope_id,
}
}

#[inline]
pub fn is_valid_ascii_start(c: u8) -> bool {
debug_assert!(c.is_ascii());
Expand Down Expand Up @@ -573,6 +587,7 @@ impl<'a> arbitrary::Arbitrary<'a> for Ident {
sym,
optional,
ctxt: Default::default(),
scope_id: Default::default(),
})
}
}
Expand All @@ -598,6 +613,7 @@ impl Ident {
Ident {
span,
ctxt,
scope_id: ScopeId::INVALID,
sym,
optional: false,
}
Expand Down
Loading
Loading