mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(semantic): analyze ReferenceFlags incorrectly when there are nested AssignmentTarget (#5847)
close: #5801
This commit is contained in:
parent
c3e0fb68c5
commit
a23879cb96
3 changed files with 53 additions and 1 deletions
|
|
@ -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),
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
40
crates/oxc_semantic/tests/fixtures/oxc/assignment/nested-assignment.snap
vendored
Normal file
40
crates/oxc_semantic/tests/fixtures/oxc/assignment/nested-assignment.snap
vendored
Normal file
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
4
crates/oxc_semantic/tests/fixtures/oxc/assignment/nested-assignment.ts
vendored
Normal file
4
crates/oxc_semantic/tests/fixtures/oxc/assignment/nested-assignment.ts
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let y;
|
||||
({ y } = {});
|
||||
({ 0: {}, y } = {0: {}});
|
||||
([[], y] = [[]])
|
||||
Loading…
Reference in a new issue