Skip to content

Commit

Permalink
refactor(transformer/object-rest-spread): avoid multiple symbol looku…
Browse files Browse the repository at this point in the history
…ps (#7420)

`IdentifierReference::is_global_reference` and `MaybeBoundIdentifier::from_identifier_reference` both look up the symbol for the identifier. Do this lookup only once, rather than twice.
  • Loading branch information
overlookmotel committed Nov 23, 2024
1 parent 779f479 commit 6fd0fcb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/oxc_transformer/src/es2018/object_rest_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use oxc_allocator::{CloneIn, GetAddress, Vec as ArenaVec};
use oxc_ast::{ast::*, NONE};
use oxc_diagnostics::OxcDiagnostic;
use oxc_ecmascript::{BoundNames, ToJsString};
use oxc_semantic::{IsGlobalReference, ScopeFlags, ScopeId, SymbolFlags};
use oxc_semantic::{ScopeFlags, ScopeId, SymbolFlags};
use oxc_span::{GetSpan, SPAN};
use oxc_traverse::{Ancestor, MaybeBoundIdentifier, Traverse, TraverseCtx};

Expand Down Expand Up @@ -998,9 +998,9 @@ impl<'a, 'ctx> ObjectRestSpread<'a, 'ctx> {
}
*all_primitives = false;
if let Expression::Identifier(ident) = expr {
if !ident.is_global_reference(ctx.symbols()) {
let expr = MaybeBoundIdentifier::from_identifier_reference(ident, ctx)
.create_read_expression(ctx);
let binding = MaybeBoundIdentifier::from_identifier_reference(ident, ctx);
if let Some(binding) = binding.to_bound_identifier() {
let expr = binding.create_read_expression(ctx);
return Some(ArrayExpressionElement::from(expr));
}
}
Expand Down

0 comments on commit 6fd0fcb

Please sign in to comment.