@@ -34,10 +34,26 @@ impl NoUnusedVars {
34
34
return fixer. noop ( ) ;
35
35
}
36
36
37
- let Some ( AstKind :: VariableDeclaration ( declaration) ) =
38
- symbol. nodes ( ) . parent_node ( decl_id) . map ( AstNode :: kind)
39
- else {
40
- panic ! ( "VariableDeclarator nodes should always be direct children of VariableDeclaration nodes" ) ;
37
+ let Some ( parent) = symbol. nodes ( ) . parent_node ( decl_id) . map ( AstNode :: kind) else {
38
+ #[ cfg( debug_assertions) ]
39
+ panic ! ( "VariableDeclarator nodes should always have a parent node" ) ;
40
+ #[ cfg( not( debug_assertions) ) ]
41
+ return fixer. noop ( ) ;
42
+ } ;
43
+ let ( span, declarations) = match parent {
44
+ AstKind :: VariableDeclaration ( decl) => ( decl. span , & decl. declarations ) ,
45
+ AstKind :: UsingDeclaration ( decl) => {
46
+ if decl. is_await {
47
+ return fixer. noop ( ) ;
48
+ }
49
+ ( decl. span , & decl. declarations )
50
+ }
51
+ _ => {
52
+ #[ cfg( debug_assertions) ]
53
+ panic ! ( "VariableDeclarator nodes should always be direct children of VariableDeclaration or UsingDeclaration nodes" ) ;
54
+ #[ cfg( not( debug_assertions) ) ]
55
+ return fixer. noop ( ) ;
56
+ }
41
57
} ;
42
58
43
59
// `true` even if references aren't considered a usage.
@@ -48,18 +64,16 @@ impl NoUnusedVars {
48
64
// for `let x = 1;` or `const { x } = obj; the whole declaration can
49
65
// be removed, but for `const { x, y } = obj;` or `let x = 1, y = 2`
50
66
// we need to keep the other declarations
51
- let has_neighbors = declaration . declarations . len ( ) > 1 ;
52
- debug_assert ! ( !declaration . declarations. is_empty( ) ) ;
67
+ let has_neighbors = declarations. len ( ) > 1 ;
68
+ debug_assert ! ( !declarations. is_empty( ) ) ;
53
69
let binding_info = symbol. get_binding_info ( & decl. id . kind ) ;
54
70
55
71
match binding_info {
56
72
BindingInfo :: SingleDestructure | BindingInfo :: NotDestructure => {
57
73
if has_neighbors {
58
- return symbol
59
- . delete_from_list ( fixer, & declaration. declarations , decl)
60
- . dangerously ( ) ;
74
+ return symbol. delete_from_list ( fixer, declarations, decl) . dangerously ( ) ;
61
75
}
62
- return fixer. delete ( declaration ) . dangerously ( ) ;
76
+ return fixer. delete_range ( span ) . dangerously ( ) ;
63
77
}
64
78
BindingInfo :: MultiDestructure ( mut span, is_object, is_last) => {
65
79
let source_after = & fixer. source_text ( ) [ ( span. end as usize ) ..] ;
0 commit comments