Skip to content

Commit

Permalink
refactor(transformer/logical-assignment-operator): use `ctx.clone_ide…
Browse files Browse the repository at this point in the history
…ntifier_reference` (#5014)

Use TraverseCtx's built-in `clone_identifier_reference`
  • Loading branch information
Dunqing committed Aug 21, 2024
1 parent 3f9433c commit bcc8da9
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions crates/oxc_transformer/src/es2021/logical_assignment_operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ impl<'a> Traverse<'a> for LogicalAssignmentOperators<'a> {
match &mut assignment_expr.left {
AssignmentTarget::AssignmentTargetIdentifier(ident) => {
left_expr = ctx.ast.expression_from_identifier_reference(
Self::clone_identifier_reference(ident, ctx),
ctx.clone_identifier_reference(ident, ReferenceFlags::Read),
);
assign_target = AssignmentTarget::from(
ctx.ast.simple_assignment_target_from_identifier_reference(
Self::clone_identifier_reference(ident, ctx),
ctx.clone_identifier_reference(ident, ReferenceFlags::Write),
),
);
}
Expand All @@ -142,7 +142,7 @@ impl<'a> Traverse<'a> for LogicalAssignmentOperators<'a> {
let right = ctx.ast.move_expression(&mut static_expr.object);
let target = AssignmentTarget::from(
ctx.ast.simple_assignment_target_from_identifier_reference(
Self::clone_identifier_reference(&ident, ctx),
ctx.clone_identifier_reference(&ident, ReferenceFlags::Write),
),
);
let object = ctx.ast.expression_assignment(SPAN, op, target, right);
Expand Down Expand Up @@ -184,7 +184,7 @@ impl<'a> Traverse<'a> for LogicalAssignmentOperators<'a> {
let right = ctx.ast.move_expression(&mut computed_expr.object);
let target = AssignmentTarget::from(
ctx.ast.simple_assignment_target_from_identifier_reference(
Self::clone_identifier_reference(&ident, ctx),
ctx.clone_identifier_reference(&ident, ReferenceFlags::Write),
),
);
let object = ctx.ast.expression_assignment(SPAN, op, target, right);
Expand All @@ -198,7 +198,10 @@ impl<'a> Traverse<'a> for LogicalAssignmentOperators<'a> {
if let Some(ref property) = property {
let left = AssignmentTarget::from(
ctx.ast.simple_assignment_target_from_identifier_reference(
Self::clone_identifier_reference(property, ctx),
ctx.clone_identifier_reference(
property,
ReferenceFlags::Write,
),
),
);
expression =
Expand All @@ -210,7 +213,10 @@ impl<'a> Traverse<'a> for LogicalAssignmentOperators<'a> {
AssignmentTarget::from(ctx.ast.member_expression_computed(
SPAN,
ctx.ast.expression_from_identifier_reference(
Self::clone_identifier_reference(&ident, ctx),
ctx.clone_identifier_reference(
&ident,
ReferenceFlags::Read,
),
),
property.map_or_else(
|| expression.clone_in(ctx.ast.allocator),
Expand Down Expand Up @@ -273,16 +279,6 @@ impl<'a> Traverse<'a> for LogicalAssignmentOperators<'a> {
}

impl<'a> LogicalAssignmentOperators<'a> {
fn clone_identifier_reference(
ident: &IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) -> IdentifierReference<'a> {
let reference = ctx.symbols().get_reference(ident.reference_id.get().unwrap());
let symbol_id = reference.symbol_id();
let flags = reference.flags();
ctx.create_reference_id(ident.span, ident.name.clone(), symbol_id, flags)
}

pub fn maybe_generate_memoised(
&mut self,
expr: &Expression<'a>,
Expand Down

0 comments on commit bcc8da9

Please sign in to comment.