From 9977e1fc3257aab23f61805ea59f4368a61fa4b6 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Wed, 8 Jan 2025 16:30:36 +0800 Subject: [PATCH] refactor(transformer/arrow-function): create a new ident instead of clone --- .../src/common/arrow_function_converter.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/oxc_transformer/src/common/arrow_function_converter.rs b/crates/oxc_transformer/src/common/arrow_function_converter.rs index 1c5c92b53e42d9..92083584fbd498 100644 --- a/crates/oxc_transformer/src/common/arrow_function_converter.rs +++ b/crates/oxc_transformer/src/common/arrow_function_converter.rs @@ -1008,17 +1008,20 @@ impl<'a> ArrowFunctionConverter<'a> { } Self::adjust_binding_scope(target_scope_id, &arguments_var, ctx); - let reference = + + let ident = ctx.create_unbound_ident_reference(SPAN, Atom::from("arguments"), ReferenceFlags::Read); - // TODO: We shouldn't be cloning `IdentifierReference` here. - // We'll end up with 2 x `IdentifierReference`s with same `ReferenceId`. - // I guess we don't have a test that covers this, or transform semantic checker would have flagged it. - let mut init = Expression::Identifier(ctx.ast.alloc(reference.clone())); + let mut init = Expression::Identifier(ctx.ast.alloc(ident)); - // Top level may doesn't have `arguments`, so we need to check it. + // Top level may not have `arguments`, so we need to check it. // `typeof arguments === "undefined" ? void 0 : arguments;` if ctx.scopes().root_scope_id() == target_scope_id { - let argument = Expression::Identifier(ctx.ast.alloc(reference)); + let ident = ctx.create_unbound_ident_reference( + SPAN, + Atom::from("arguments"), + ReferenceFlags::Read, + ); + let argument = Expression::Identifier(ctx.ast.alloc(ident)); let typeof_arguments = ctx.ast.expression_unary(SPAN, UnaryOperator::Typeof, argument); let undefined_literal = ctx.ast.expression_string_literal(SPAN, "undefined", None); let test = ctx.ast.expression_binary(