Skip to content

Commit

Permalink
clear flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Nov 22, 2024
1 parent 4144e53 commit 8c295bd
Show file tree
Hide file tree
Showing 6 changed files with 2,002 additions and 7,241 deletions.
21 changes: 14 additions & 7 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,14 +891,16 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
let kind = AstKind::AssignmentExpression(self.alloc(expr));
self.enter_node(kind);

// Only when the operator is not an `=` operator, the left-hand side is both read and write.
// <https://tc39.es/ecma262/#sec-assignment-operators-runtime-semantics-evaluation>
if !expr.operator.is_assign() {
self.current_reference_flags = ReferenceFlags::Read;
// Only when the operator is not an `=` operator, the left-hand side is both read and write.
// <https://tc39.es/ecma262/#sec-assignment-operators-runtime-semantics-evaluation>
self.current_reference_flags = ReferenceFlags::read_write();
}

self.visit_assignment_target(&expr.left);

self.current_reference_flags = ReferenceFlags::empty();

/* cfg */
let cfg_ixs = control_flow!(self, |cfg| {
if expr.operator.is_logical() {
Expand Down Expand Up @@ -1773,9 +1775,9 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
self.enter_node(kind);
// `++a` or `a--`
// ^ ^ We always treat `a` as Read and Write reference,
// the Write flags will add in `visit_simple_assignment_target`
self.current_reference_flags = ReferenceFlags::Read;
self.current_reference_flags = ReferenceFlags::read_write();
self.visit_simple_assignment_target(&it.argument);
self.current_reference_flags = ReferenceFlags::empty();
self.leave_node(kind);
}

Expand All @@ -1801,7 +1803,12 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
let kind = AstKind::SimpleAssignmentTarget(self.alloc(it));
self.enter_node(kind);
let prev_reference_flags = self.current_reference_flags;
self.current_reference_flags |= ReferenceFlags::Write;
// Except that the read-write flags has been set in visit_assignment_expression
// and visit_update_expression, this is always a write-only reference here.
if !self.current_reference_flags.is_write() {
self.current_reference_flags = ReferenceFlags::Write;
}

match it {
SimpleAssignmentTarget::AssignmentTargetIdentifier(it) => {
self.visit_identifier_reference(it);
Expand Down Expand Up @@ -1835,7 +1842,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
) {
// NOTE: AstKind doesn't exists!
let prev_reference_flags = self.current_reference_flags;
self.current_reference_flags |= ReferenceFlags::Write;
self.current_reference_flags = ReferenceFlags::Write;
self.visit_identifier_reference(&it.binding);
self.current_reference_flags = prev_reference_flags;
if let Some(init) = &it.init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/assignments/ts-syntax-left
"node_id": 12
},
{
"flags": "ReferenceFlags(Read | Write)",
"flags": "ReferenceFlags(Write)",
"id": 1,
"name": "Foo",
"node_id": 19
},
{
"flags": "ReferenceFlags(Read | Write)",
"flags": "ReferenceFlags(Write)",
"id": 2,
"name": "Foo",
"node_id": 27
},
{
"flags": "ReferenceFlags(Read | Write)",
"flags": "ReferenceFlags(Write)",
"id": 3,
"name": "Foo",
"node_id": 35
Expand Down
Loading

0 comments on commit 8c295bd

Please sign in to comment.