fix(linter/no-unused-vars): panic in fixer when removing destructures (#4923)

Closes #4839
This commit is contained in:
Don Isaac 2024-08-15 17:30:33 -04:00 committed by GitHub
parent c21d735c3d
commit 4081293ce7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 1 deletions

View file

@ -19,7 +19,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
Symbol<'s, 'a>: PartialEq<T>,
{
let Some(own_position) = list.iter().position(|el| self == el) else {
debug_assert!(false, "Symbol not found within its own parent declaration list");
// Happens when the symbol is in a destructuring pattern.
return fixer.noop();
};
let mut delete_range = own.span();

View file

@ -293,6 +293,8 @@ fn test_vars_destructure() {
"const { a: { b }, ...rest } = obj; console.log(rest)",
Some(json!( [{ "ignoreRestSiblings": true }] )),
),
// https://github.com/oxc-project/oxc/issues/4839
(r#"const l="",{e}=r"#, None),
];
let fix = vec![
@ -339,6 +341,8 @@ fn test_vars_destructure() {
None,
FixKind::DangerousSuggestion,
),
// TODO: destructures in VariableDeclarations with more than one declarator
(r#"const l="",{e}=r"#, r"const {e}=r", None, FixKind::All),
// renaming
// (
// "let a = 1; a = 2;",

View file

@ -48,3 +48,19 @@ source: crates/oxc_linter/src/tester.rs
· ╰── 'b' is declared here
╰────
help: Consider removing this declaration.
⚠ eslint(no-unused-vars): Variable 'l' is declared but never used.
╭─[no_unused_vars.tsx:1:7]
1 │ const l="",{e}=r
· ┬
· ╰── 'l' is declared here
╰────
help: Consider removing this declaration.
⚠ eslint(no-unused-vars): Variable 'e' is declared but never used.
╭─[no_unused_vars.tsx:1:13]
1 │ const l="",{e}=r
· ┬
· ╰── 'e' is declared here
╰────
help: Consider removing this declaration.