Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
15 changes: 6 additions & 9 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */ }
}
}
Expand Down