@@ -202,36 +202,9 @@ impl CatchErrorName {
202
202
return ;
203
203
}
204
204
205
- if binding_ident. name . starts_with ( '_' ) {
206
- let mut iter =
207
- ctx. semantic ( ) . symbol_references ( binding_ident. symbol_id ( ) ) . peekable ( ) ;
208
-
209
- if iter. peek ( ) . is_some ( ) {
210
- ctx. diagnostic_with_fix (
211
- catch_error_name_diagnostic (
212
- binding_ident. name . as_str ( ) ,
213
- & self . name ,
214
- binding_ident. span ,
215
- ) ,
216
- |fixer| {
217
- let fixer = fixer. for_multifix ( ) ;
218
- let mut declaration_fix = fixer. new_fix_with_capacity ( 2 ) ;
219
-
220
- declaration_fix
221
- . push ( fixer. replace ( binding_ident. span , self . name . clone ( ) ) ) ;
222
-
223
- for reference in iter {
224
- let node = ctx. nodes ( ) . get_node ( reference. node_id ( ) ) . kind ( ) ;
225
- let Some ( id) = node. as_identifier_reference ( ) else { continue } ;
226
-
227
- declaration_fix. push ( fixer. replace ( id. span , self . name . clone ( ) ) ) ;
228
- }
229
-
230
- declaration_fix
231
- } ,
232
- ) ;
233
- }
234
-
205
+ let symbol_id = binding_ident. symbol_id ( ) ;
206
+ let mut iter = ctx. semantic ( ) . symbol_references ( symbol_id) . peekable ( ) ;
207
+ if binding_ident. name . starts_with ( '_' ) && iter. peek ( ) . is_none ( ) {
235
208
return ;
236
209
}
237
210
@@ -241,7 +214,27 @@ impl CatchErrorName {
241
214
& self . name ,
242
215
binding_ident. span ,
243
216
) ,
244
- |fixer| fixer. replace ( binding_ident. span , self . name . clone ( ) ) ,
217
+ |fixer| {
218
+ let basic_fix = fixer. replace ( binding_ident. span , self . name . clone ( ) ) ;
219
+ if iter. peek ( ) . is_none ( ) {
220
+ return basic_fix;
221
+ }
222
+
223
+ let fixer = fixer. for_multifix ( ) ;
224
+ let capacity = ctx. scoping ( ) . get_resolved_reference_ids ( symbol_id) . len ( ) + 1 ;
225
+
226
+ let mut declaration_fix = fixer. new_fix_with_capacity ( capacity) ;
227
+
228
+ declaration_fix. push ( basic_fix) ;
229
+ for reference in iter {
230
+ let node = ctx. nodes ( ) . get_node ( reference. node_id ( ) ) . kind ( ) ;
231
+ let Some ( id) = node. as_identifier_reference ( ) else { continue } ;
232
+
233
+ declaration_fix. push ( fixer. replace ( id. span , self . name . clone ( ) ) ) ;
234
+ }
235
+
236
+ declaration_fix
237
+ } ,
245
238
) ;
246
239
}
247
240
}
@@ -306,6 +299,7 @@ fn test() {
306
299
( "try { } catch (notMatching) { }" , Some ( serde_json:: json!( [ { "ignore" : [ "unicorn" ] } ] ) ) ) ,
307
300
( "try { } catch (notMatching) { }" , Some ( serde_json:: json!( [ { "ignore" : [ "unicorn" ] } ] ) ) ) ,
308
301
( "try { } catch (_) { console.log(_) }" , None ) ,
302
+ ( "try { } catch (err) { console.error(err) }" , None ) ,
309
303
( "promise.catch(notMatching => { })" , Some ( serde_json:: json!( [ { "ignore" : [ "unicorn" ] } ] ) ) ) ,
310
304
( "promise.catch((foo) => { })" , None ) ,
311
305
( "promise.catch(function (foo) { })" , None ) ,
@@ -356,6 +350,11 @@ fn test() {
356
350
"try { } catch (error) { console.log(error) }" ,
357
351
None ,
358
352
) ,
353
+ (
354
+ "try { } catch (err) { console.error(err) }" ,
355
+ "try { } catch (error) { console.error(error) }" ,
356
+ None ,
357
+ ) ,
359
358
(
360
359
"promise.catch(notMatching => { })" ,
361
360
"promise.catch(error => { })" ,
0 commit comments