Skip to content

Commit

Permalink
feat: 🎸 update ast tools
Browse files Browse the repository at this point in the history
  • Loading branch information
IWANABETHATGUY committed Jan 22, 2025
1 parent 153e7b4 commit 091b93a
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 20 deletions.
6 changes: 6 additions & 0 deletions crates/oxc_allocator/src/clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ pub trait CloneIn<'new_alloc>: Sized {
/// Clone `self` into the given `allocator`. `allocator` may be the same one
/// that `self` is already in.
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned;

/// Almost same as `clone_in`, but for some special type, it will also clone the semantic ids.
#[inline]
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
self.clone_in(allocator)
}
}

impl<'alloc, T, C> CloneIn<'alloc> for Option<T>
Expand Down
13 changes: 13 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct Program<'a> {
pub directives: Vec<'a, Directive<'a>>,
pub body: Vec<'a, Statement<'a>>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -226,6 +227,7 @@ pub struct IdentifierReference<'a> {
/// set in the bind step of semantic analysis, and will always be [`None`]
/// immediately after parsing.
#[estree(skip)]
#[clone_in(default)]
pub reference_id: Cell<Option<ReferenceId>>,
}

Expand All @@ -249,6 +251,7 @@ pub struct BindingIdentifier<'a> {
///
/// [`semantic analysis`]: <https://docs.rs/oxc_semantic/latest/oxc_semantic/struct.SemanticBuilder.html>
#[estree(skip)]
#[clone_in(default)]
pub symbol_id: Cell<Option<SymbolId>>,
}

Expand Down Expand Up @@ -1040,6 +1043,7 @@ pub struct BlockStatement<'a> {
pub span: Span,
pub body: Vec<'a, Statement<'a>>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -1183,6 +1187,7 @@ pub struct ForStatement<'a> {
pub update: Option<Expression<'a>>,
pub body: Statement<'a>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -1213,6 +1218,7 @@ pub struct ForInStatement<'a> {
pub right: Expression<'a>,
pub body: Statement<'a>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -1243,6 +1249,7 @@ pub struct ForOfStatement<'a> {
pub right: Expression<'a>,
pub body: Statement<'a>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -1294,6 +1301,7 @@ pub struct SwitchStatement<'a> {
#[scope(enter_before)]
pub cases: Vec<'a, SwitchCase<'a>>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -1383,6 +1391,7 @@ pub struct CatchClause<'a> {
/// The statements run when an error is caught
pub body: Box<'a, BlockStatement<'a>>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -1616,6 +1625,7 @@ pub struct Function<'a> {
/// ```
pub body: Option<Box<'a, FunctionBody<'a>>>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -1707,6 +1717,7 @@ pub struct ArrowFunctionExpression<'a> {
/// See `expression` for whether this arrow expression returns an expression.
pub body: Box<'a, FunctionBody<'a>>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -1793,6 +1804,7 @@ pub struct Class<'a> {
/// Id of the scope created by the [`Class`], including type parameters and
/// statements within the [`ClassBody`].
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down Expand Up @@ -2044,6 +2056,7 @@ pub struct StaticBlock<'a> {
pub span: Span,
pub body: Vec<'a, Statement<'a>>,
#[estree(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}

Expand Down
Loading

0 comments on commit 091b93a

Please sign in to comment.