Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(transformer/object-rest-spread): avoid multiple symbol lookups #7420

Merged
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
refactor(transformer/object-rest-spread): avoid multiple symbol looku…
…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
commit 6fd0fcb4ff052116031868c9b4cb1e5e34cd8cbe
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
Loading