Skip to content

Commit

Permalink
fix(linter/no-unused-vars): panic in variable declarator usage checks (
Browse files Browse the repository at this point in the history
…#5160)

Part of #5129
  • Loading branch information
DonIsaac committed Aug 24, 2024
1 parent e356112 commit 36e4a28
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 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 @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 36e4a28

Please sign in to comment.