mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter/no-unused-vars): false positive when a variable used as a computed member property (#5722)
close: #5671
This commit is contained in:
parent
748e6f80fe
commit
e9c084a705
2 changed files with 14 additions and 0 deletions
|
|
@ -37,6 +37,13 @@ fn test_vars_simple() {
|
||||||
",
|
",
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"
|
||||||
|
const a = 0
|
||||||
|
obj[a]++;
|
||||||
|
",
|
||||||
|
None,
|
||||||
|
),
|
||||||
];
|
];
|
||||||
let fail = vec![
|
let fail = vec![
|
||||||
("let a = 1", None),
|
("let a = 1", None),
|
||||||
|
|
|
||||||
|
|
@ -412,6 +412,13 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
||||||
// a = yield a // <- still considered used b/c it's propagated to the caller
|
// a = yield a // <- still considered used b/c it's propagated to the caller
|
||||||
// }
|
// }
|
||||||
AstKind::YieldExpression(_) => return false,
|
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 */ }
|
_ => { /* continue up tree */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue