Skip to content

Commit

Permalink
fix(transformer): fix reference flags in logical assignment operator …
Browse files Browse the repository at this point in the history
…transform (#5903)
  • Loading branch information
overlookmotel committed Sep 20, 2024
1 parent 2cf5607 commit 4d5c4f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 143 deletions.
24 changes: 18 additions & 6 deletions crates/oxc_transformer/src/es2021/logical_assignment_operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl<'a> LogicalAssignmentOperators<'a> {

let assign_target =
AssignmentTarget::from(ctx.ast.simple_assignment_target_from_identifier_reference(
ctx.clone_identifier_reference(ident, ReferenceFlags::Write),
ctx.clone_identifier_reference(ident, ReferenceFlags::read_write()),
));
(left_expr, assign_target)
}
Expand All @@ -173,7 +173,7 @@ impl<'a> LogicalAssignmentOperators<'a> {
let right = ctx.ast.move_expression(&mut static_expr.object);
let target =
AssignmentTarget::from(ctx.ast.simple_assignment_target_from_identifier_reference(
ctx.clone_identifier_reference(&ident, ReferenceFlags::Write),
ctx.clone_identifier_reference(&ident, ReferenceFlags::read_write()),
));
let object =
ctx.ast.expression_assignment(SPAN, AssignmentOperator::Assign, target, right);
Expand All @@ -185,6 +185,9 @@ impl<'a> LogicalAssignmentOperators<'a> {
));

// (_o.a = 1)
let reference = ctx.symbols_mut().get_reference_mut(ident.reference_id().unwrap());
*reference.flags_mut() = ReferenceFlags::Read;

let assign_expr = ctx.ast.member_expression_static(
SPAN,
ctx.ast.expression_from_identifier_reference(ident),
Expand Down Expand Up @@ -238,7 +241,7 @@ impl<'a> LogicalAssignmentOperators<'a> {
let right = ctx.ast.move_expression(&mut computed_expr.object);
let target =
AssignmentTarget::from(ctx.ast.simple_assignment_target_from_identifier_reference(
ctx.clone_identifier_reference(&ident, ReferenceFlags::Write),
ctx.clone_identifier_reference(&ident, ReferenceFlags::read_write()),
));
let object =
ctx.ast.expression_assignment(SPAN, AssignmentOperator::Assign, target, right);
Expand All @@ -251,7 +254,7 @@ impl<'a> LogicalAssignmentOperators<'a> {
if let Some(ref property) = property {
let left = AssignmentTarget::from(
ctx.ast.simple_assignment_target_from_identifier_reference(
ctx.clone_identifier_reference(property, ReferenceFlags::Write),
ctx.clone_identifier_reference(property, ReferenceFlags::read_write()),
),
);
expression = ctx.ast.expression_assignment(
Expand All @@ -270,7 +273,12 @@ impl<'a> LogicalAssignmentOperators<'a> {
),
property.map_or_else(
|| expression.clone_in(ctx.ast.allocator),
|ident| ctx.ast.expression_from_identifier_reference(ident),
|ident| {
let reference =
ctx.symbols_mut().get_reference_mut(ident.reference_id().unwrap());
*reference.flags_mut() = ReferenceFlags::Read;
ctx.ast.expression_from_identifier_reference(ident)
},
),
false,
));
Expand Down Expand Up @@ -299,7 +307,7 @@ impl<'a> LogicalAssignmentOperators<'a> {
ctx.ast.simple_assignment_target_from_identifier_reference(
ctx.clone_identifier_reference(
property_ident,
ReferenceFlags::Write,
ReferenceFlags::read_write(),
),
),
);
Expand All @@ -326,6 +334,10 @@ impl<'a> LogicalAssignmentOperators<'a> {
object,
{
if let Some(property_ident) = property_ident {
let reference = ctx
.symbols_mut()
.get_reference_mut(property_ident.reference_id().unwrap());
*reference.flags_mut() = ReferenceFlags::Read;
ctx.ast.expression_from_identifier_reference(property_ident)
} else {
expression
Expand Down
139 changes: 2 additions & 137 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 3bcfee23

Passed: 330/1022
Passed: 333/1022

# All Passed:
* babel-plugin-transform-optional-catch-binding
Expand Down Expand Up @@ -1440,29 +1440,7 @@ x Output mismatch
x Output mismatch


# babel-plugin-transform-logical-assignment-operators (0/6)
* logical-assignment/anonymous-functions-transform/input.js
Reference flags mismatch:
after transform: ReferenceId(3): ReferenceFlags(Write)
rebuilt : ReferenceId(1): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(4): ReferenceFlags(Write)
rebuilt : ReferenceId(3): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(5): ReferenceFlags(Write)
rebuilt : ReferenceId(5): ReferenceFlags(Read | Write)

* logical-assignment/arrow-functions-transform/input.js
Reference flags mismatch:
after transform: ReferenceId(3): ReferenceFlags(Write)
rebuilt : ReferenceId(1): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(4): ReferenceFlags(Write)
rebuilt : ReferenceId(3): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(5): ReferenceFlags(Write)
rebuilt : ReferenceId(5): ReferenceFlags(Read | Write)

# babel-plugin-transform-logical-assignment-operators (3/6)
* logical-assignment/general-semantics/input.js
Symbol reference IDs mismatch:
after transform: SymbolId(15): [ReferenceId(117), ReferenceId(118), ReferenceId(121)]
Expand All @@ -1476,101 +1454,6 @@ rebuilt : SymbolId(12): [ReferenceId(111), ReferenceId(115)]
Symbol reference IDs mismatch:
after transform: SymbolId(21): [ReferenceId(132), ReferenceId(133), ReferenceId(136)]
rebuilt : SymbolId(14): [ReferenceId(123), ReferenceId(127)]
Reference flags mismatch:
after transform: ReferenceId(98): ReferenceFlags(Write)
rebuilt : ReferenceId(27): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(97): ReferenceFlags(Write)
rebuilt : ReferenceId(29): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(100): ReferenceFlags(Write)
rebuilt : ReferenceId(33): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(99): ReferenceFlags(Write)
rebuilt : ReferenceId(35): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(102): ReferenceFlags(Write)
rebuilt : ReferenceId(39): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(101): ReferenceFlags(Write)
rebuilt : ReferenceId(41): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(104): ReferenceFlags(Write)
rebuilt : ReferenceId(45): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(103): ReferenceFlags(Write)
rebuilt : ReferenceId(47): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(107): ReferenceFlags(Write)
rebuilt : ReferenceId(52): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(105): ReferenceFlags(Write)
rebuilt : ReferenceId(55): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(110): ReferenceFlags(Write)
rebuilt : ReferenceId(61): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(108): ReferenceFlags(Write)
rebuilt : ReferenceId(64): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(113): ReferenceFlags(Write)
rebuilt : ReferenceId(70): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(111): ReferenceFlags(Write)
rebuilt : ReferenceId(73): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(116): ReferenceFlags(Write)
rebuilt : ReferenceId(79): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(114): ReferenceFlags(Write)
rebuilt : ReferenceId(82): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(118): ReferenceFlags(Write)
rebuilt : ReferenceId(87): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(120): ReferenceFlags(Write)
rebuilt : ReferenceId(89): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(119): ReferenceFlags(Write)
rebuilt : ReferenceId(92): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(123): ReferenceFlags(Write)
rebuilt : ReferenceId(99): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(125): ReferenceFlags(Write)
rebuilt : ReferenceId(101): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(124): ReferenceFlags(Write)
rebuilt : ReferenceId(104): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(128): ReferenceFlags(Write)
rebuilt : ReferenceId(111): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(130): ReferenceFlags(Write)
rebuilt : ReferenceId(113): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(129): ReferenceFlags(Write)
rebuilt : ReferenceId(116): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(133): ReferenceFlags(Write)
rebuilt : ReferenceId(123): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(135): ReferenceFlags(Write)
rebuilt : ReferenceId(125): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(134): ReferenceFlags(Write)
rebuilt : ReferenceId(128): ReferenceFlags(Read)

* logical-assignment/named-functions-transform/input.js
Reference flags mismatch:
after transform: ReferenceId(3): ReferenceFlags(Write)
rebuilt : ReferenceId(1): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(4): ReferenceFlags(Write)
rebuilt : ReferenceId(3): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(5): ReferenceFlags(Write)
rebuilt : ReferenceId(5): ReferenceFlags(Read | Write)

* logical-assignment/null-coalescing/input.js
x Output mismatch
Expand All @@ -1579,24 +1462,6 @@ x Output mismatch
Symbol reference IDs mismatch:
after transform: SymbolId(2): [ReferenceId(6), ReferenceId(7), ReferenceId(10)]
rebuilt : SymbolId(1): [ReferenceId(5), ReferenceId(8)]
Reference flags mismatch:
after transform: ReferenceId(3): ReferenceFlags(Write)
rebuilt : ReferenceId(1): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(5): ReferenceFlags(Write)
rebuilt : ReferenceId(2): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(4): ReferenceFlags(Write)
rebuilt : ReferenceId(4): ReferenceFlags(Read)
Reference flags mismatch:
after transform: ReferenceId(7): ReferenceFlags(Write)
rebuilt : ReferenceId(5): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(9): ReferenceFlags(Write)
rebuilt : ReferenceId(7): ReferenceFlags(Read | Write)
Reference flags mismatch:
after transform: ReferenceId(8): ReferenceFlags(Write)
rebuilt : ReferenceId(9): ReferenceFlags(Read)


# babel-plugin-transform-nullish-coalescing-operator (5/12)
Expand Down

0 comments on commit 4d5c4f6

Please sign in to comment.