mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter/no-unused-vars): panic in fixer when removing destructures (#4923)
Closes #4839
This commit is contained in:
parent
c21d735c3d
commit
4081293ce7
3 changed files with 21 additions and 1 deletions
|
|
@ -19,7 +19,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
|
||||||
Symbol<'s, 'a>: PartialEq<T>,
|
Symbol<'s, 'a>: PartialEq<T>,
|
||||||
{
|
{
|
||||||
let Some(own_position) = list.iter().position(|el| self == el) else {
|
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();
|
return fixer.noop();
|
||||||
};
|
};
|
||||||
let mut delete_range = own.span();
|
let mut delete_range = own.span();
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,8 @@ fn test_vars_destructure() {
|
||||||
"const { a: { b }, ...rest } = obj; console.log(rest)",
|
"const { a: { b }, ...rest } = obj; console.log(rest)",
|
||||||
Some(json!( [{ "ignoreRestSiblings": true }] )),
|
Some(json!( [{ "ignoreRestSiblings": true }] )),
|
||||||
),
|
),
|
||||||
|
// https://github.com/oxc-project/oxc/issues/4839
|
||||||
|
(r#"const l="",{e}=r"#, None),
|
||||||
];
|
];
|
||||||
|
|
||||||
let fix = vec![
|
let fix = vec![
|
||||||
|
|
@ -339,6 +341,8 @@ fn test_vars_destructure() {
|
||||||
None,
|
None,
|
||||||
FixKind::DangerousSuggestion,
|
FixKind::DangerousSuggestion,
|
||||||
),
|
),
|
||||||
|
// TODO: destructures in VariableDeclarations with more than one declarator
|
||||||
|
(r#"const l="",{e}=r"#, r"const {e}=r", None, FixKind::All),
|
||||||
// renaming
|
// renaming
|
||||||
// (
|
// (
|
||||||
// "let a = 1; a = 2;",
|
// "let a = 1; a = 2;",
|
||||||
|
|
|
||||||
|
|
@ -48,3 +48,19 @@ source: crates/oxc_linter/src/tester.rs
|
||||||
· ╰── 'b' is declared here
|
· ╰── 'b' is declared here
|
||||||
╰────
|
╰────
|
||||||
help: Consider removing this declaration.
|
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.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue