Skip to content

Commit

Permalink
fix(semantic): analyze ReferenceFlags incorrectly when there are ne…
Browse files Browse the repository at this point in the history
…sted `AssignmentTarget` (#5847)

close: #5801
  • Loading branch information
Dunqing committed Sep 21, 2024
1 parent c3e0fb6 commit a23879c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,15 @@ impl<'a> SemanticBuilder<'a> {
| AstKind::PropertyKey(_) => {
self.current_reference_flags = ReferenceFlags::empty();
}
AstKind::AssignmentTarget(_) => self.current_reference_flags -= ReferenceFlags::Write,
AstKind::AssignmentTarget(_) =>{
// Handle nested assignment targets like `({a: b} = obj)`
if !matches!(
self.nodes.parent_kind(self.current_node_id),
Some(AstKind::ObjectAssignmentTarget(_) | AstKind::ArrayAssignmentTarget(_))
) {
self.current_reference_flags -= ReferenceFlags::Write;
}
},
AstKind::LabeledStatement(_) => self.unused_labels.mark_unused(self.current_node_id),
_ => {}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/oxc/assignment/nested-assignment.ts
---
[
{
"children": [],
"flags": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(BlockScopedVariable)",
"id": 0,
"name": "y",
"node": "VariableDeclarator(y)",
"references": [
{
"flags": "ReferenceFlags(Write)",
"id": 0,
"name": "y",
"node_id": 10
},
{
"flags": "ReferenceFlags(Write)",
"id": 1,
"name": "y",
"node_id": 23
},
{
"flags": "ReferenceFlags(Write)",
"id": 2,
"name": "y",
"node_id": 40
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let y;
({ y } = {});
({ 0: {}, y } = {0: {}});
([[], y] = [[]])

0 comments on commit a23879c

Please sign in to comment.