Skip to content

Commit

Permalink
refactor(traverse)!: remove TraverseCtx::is_static
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Dec 9, 2024
1 parent 71ed650 commit 2bcaebc
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 41 deletions.
15 changes: 0 additions & 15 deletions crates/oxc_traverse/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,21 +589,6 @@ impl<'a> TraverseCtx<'a> {
pub fn delete_reference_for_identifier(&mut self, ident: &IdentifierReference) {
self.scoping.delete_reference_for_identifier(ident);
}

/// Determine whether evaluating the specific input `node` is a consequenceless reference.
///
/// i.e. evaluating it won't result in potentially arbitrary code from being run.
/// The following are allowed and determined not to cause side effects:
///
/// - `this` expressions
/// - `super` expressions
/// - Bound identifiers which are not mutated
///
/// This is a shortcut for `ctx.scoping.is_static`.
#[inline]
pub fn is_static(&self, expr: &Expression) -> bool {
self.scoping.is_static(expr)
}
}

// Methods used internally within crate
Expand Down
26 changes: 0 additions & 26 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,32 +362,6 @@ impl TraverseScoping {
pub fn delete_reference_for_identifier(&mut self, ident: &IdentifierReference) {
self.delete_reference(ident.reference_id(), &ident.name);
}

/// Determine whether evaluating the specific input `node` is a consequenceless reference.
///
/// i.e. evaluating it won't result in potentially arbitrary code from being run.
/// The following are allowed and determined not to cause side effects:
///
/// - `this` expressions
/// - `super` expressions
/// - Bound identifiers which are not mutated
///
/// Based on Babel's `scope.isStatic` logic.
/// <https://github.com/babel/babel/blob/419644f27c5c59deb19e71aaabd417a3bc5483ca/packages/babel-traverse/src/scope/index.ts#L557>
#[inline]
pub fn is_static(&self, expr: &Expression) -> bool {
match expr {
Expression::ThisExpression(_) | Expression::Super(_) => true,
Expression::Identifier(ident) => {
self.symbols.get_reference(ident.reference_id()).symbol_id().is_some_and(
|symbol_id| {
self.symbols.get_resolved_references(symbol_id).all(|r| !r.is_write())
},
)
}
_ => false,
}
}
}

// Methods used internally within crate
Expand Down

0 comments on commit 2bcaebc

Please sign in to comment.