mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(linter/no-unused-vars): writes to members triggering false positive (#5744)
close: #5246 similar to #5722
This commit is contained in:
parent
19790dbc9c
commit
b4ed564a35
2 changed files with 16 additions and 9 deletions
|
|
@ -41,6 +41,16 @@ fn test_vars_simple() {
|
|||
"
|
||||
const a = 0
|
||||
obj[a]++;
|
||||
obj[a] += 1;
|
||||
",
|
||||
None,
|
||||
),
|
||||
(
|
||||
"
|
||||
const obj = 0
|
||||
obj.a++;
|
||||
obj.a += 1;
|
||||
obj.b.c++;
|
||||
",
|
||||
None,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -341,8 +341,12 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
|||
}
|
||||
// When symbol is being assigned a new value, we flag the reference
|
||||
// as only affecting itself until proven otherwise.
|
||||
AstKind::UpdateExpression(_) | AstKind::SimpleAssignmentTarget(_) => {
|
||||
is_used_by_others = false;
|
||||
AstKind::UpdateExpression(UpdateExpression { argument, .. })
|
||||
| AstKind::SimpleAssignmentTarget(argument) => {
|
||||
// `a.b++` or `a[b] + 1` are not reassignment of `a`
|
||||
if !argument.is_member_expression() {
|
||||
is_used_by_others = false;
|
||||
}
|
||||
}
|
||||
// RHS usage when LHS != reference's symbol is definitely used by
|
||||
// others
|
||||
|
|
@ -412,13 +416,6 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
|||
// a = yield a // <- still considered used b/c it's propagated to the caller
|
||||
// }
|
||||
AstKind::YieldExpression(_) => return false,
|
||||
AstKind::MemberExpression(MemberExpression::ComputedMemberExpression(computed)) => {
|
||||
// obj[a]++;
|
||||
// ^ the reference is used as property
|
||||
if computed.expression.span().contains_inclusive(ref_span) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_ => { /* continue up tree */ }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue