fix(linter/no-unused-vars): panic in variable declarator usage checks (#5160)

Part of #5129
This commit is contained in:
DonIsaac 2024-08-24 04:49:30 +00:00
parent e3561127fe
commit 36e4a2875c

View file

@ -333,12 +333,9 @@ impl<'s, 'a> Symbol<'s, 'a> {
match node.kind() {
// references used in declaration of another variable are definitely
// used by others
AstKind::VariableDeclarator(v) => {
// let a = a; is a static semantic error, even if `a` is shadowed.
debug_assert!(
v.id.kind.get_identifier().map_or_else(|| true, |id| id != name),
"While traversing {name}'s reference's parent nodes, found {name}'s declaration. This algorithm assumes that variable declarations do not appear in references."
);
AstKind::VariableDeclarator(_)
| AstKind::JSXExpressionContainer(_)
| AstKind::Argument(_) => {
// definitely used, short-circuit
return false;
}
@ -382,9 +379,6 @@ impl<'s, 'a> Symbol<'s, 'a> {
| AstKind::WhileStatement(_) => {
break;
}
AstKind::JSXExpressionContainer(_) | AstKind::Argument(_) => {
return false;
}
// this is needed to handle `return () => foo++`
AstKind::ExpressionStatement(_) => {
if self.is_in_return_statement(node.id()) {