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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
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.

2 changes: 2 additions & 0 deletions bindings/binding_core_wasm/__tests__/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe("parse", () => {
"decorators": [],
"identifier": {
"ctxt": 2,
"nodeId": 4294967295,
"optional": false,
"span": {
"end": 254,
Expand Down Expand Up @@ -157,6 +158,7 @@ describe("parse", () => {
"decorators": [],
"identifier": {
"ctxt": 2,
"nodeId": 4294967295,
"optional": false,
"span": {
"end": 267,
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_bundler/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ impl Id {
}

impl IdentLike for Id {
type Id = (Atom, SyntaxContext);

fn from_ident(i: &Ident) -> Self {
i.into()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_bundler/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ pub(crate) trait ExprExt: Into<Expr> {
#[track_caller]
fn assign_to<T>(self, lhs: T) -> VarDeclarator
where
T: IdentLike,
T: IdentLike<Id = Id>,
{
let init = self.into();
let lhs = lhs.into_id();
let lhs: Id = lhs.into_id();

if cfg!(debug_assertions) {
if let Expr::Ident(rhs) = &init {
Expand Down
2 changes: 2 additions & 0 deletions crates/swc_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub use swc_eq_ignore_macros::{EqIgnoreSpan, TypeEq};
pub use self::{
eq::{EqIgnoreSpan, TypeEq},
errors::{SourceMapper, SourceMapperDyn},
node_id::NodeId,
pos::{
hygiene, BytePos, CharPos, FileName, Globals, Loc, LocWithOpt, Mark, MultiSpan, SourceFile,
SourceFileAndBytePos, SourceFileAndLine, Span, SpanLinesError, Spanned, SyntaxContext,
Expand All @@ -59,6 +60,7 @@ mod eq;
pub mod errors;
pub mod input;
pub mod iter;
mod node_id;
pub mod pass;
pub mod plugin;
mod pos;
Expand Down
37 changes: 37 additions & 0 deletions crates/swc_common/src/node_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::util::take::Take;

#[derive(Eq, Hash, Debug, PartialEq, Clone, Copy, serde::Serialize, serde::Deserialize)]
#[cfg_attr(
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))]
#[cfg_attr(feature = "rkyv-impl", repr(C))]
#[cfg_attr(feature = "shrink-to-fit", derive(shrink_to_fit::ShrinkToFit))]
pub struct NodeId(#[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))] u32);

impl NodeId {
pub const DUMMY: NodeId = NodeId(u32::MAX);

#[inline]
pub fn from_u32(id: u32) -> Self {
NodeId(id)
}

#[inline]
pub fn as_u32(self) -> u32 {
self.0
}
}

impl Default for NodeId {
fn default() -> Self {
NodeId::DUMMY
}
}

impl Take for NodeId {
fn dummy() -> Self {
NodeId::DUMMY
}
}
9 changes: 8 additions & 1 deletion crates/swc_ecma_ast/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use phf::phf_set;
use rustc_hash::FxHashSet;
use swc_atoms::{atom, Atom, UnsafeAtom};
use swc_common::{
ast_node, util::take::Take, BytePos, EqIgnoreSpan, Mark, Span, Spanned, SyntaxContext, DUMMY_SP,
ast_node, util::take::Take, BytePos, EqIgnoreSpan, Mark, NodeId, Span, Spanned, SyntaxContext,
DUMMY_SP,
};

use crate::{typescript::TsTypeAnn, Expr};
Expand Down Expand Up @@ -91,6 +92,7 @@ impl From<&'_ BindingIdent> for Ident {
ctxt: bi.ctxt,
sym: bi.sym.clone(),
optional: bi.optional,
node_id: bi.node_id,
}
}
}
Expand Down Expand Up @@ -179,6 +181,9 @@ pub struct Ident {
#[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))]
pub ctxt: SyntaxContext,

#[cfg_attr(feature = "__rkyv", rkyv(omit_bounds))]
pub node_id: NodeId,

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

Expand Down Expand Up @@ -565,6 +570,7 @@ impl<'a> arbitrary::Arbitrary<'a> for Ident {
sym,
optional,
ctxt: Default::default(),
node_id: NodeId::DUMMY,
})
}
}
Expand Down Expand Up @@ -592,6 +598,7 @@ impl Ident {
ctxt,
sym,
optional: false,
node_id: NodeId::DUMMY,
}
}

Expand Down
Loading
Loading