Repository navigation
Commit 8e69622
authored
fix: Prevent no-var autofix when var is shadowed by catch parameter (#21204)
* fix: Prevent no-var autofix when var is shadowed by catch parameter
A `var` declaration may reuse the name of a simple catch clause parameter,
but the equivalent `let` declaration may not. Directly inside the catch
block, `let` is a syntax error. In a nested block, `let` is valid but
assigns a separate binding and leaves the catch parameter untouched.
The catch parameter and the `var` are distinct variables in distinct
scopes, so neither has more than one definition and `isRedeclared` does
not detect the conflict.
Fixes #21194
* fix: Simplify catch parameter check with getVariableByName
Resolve the declared name from the scope of the declaration instead of
walking the scope chain looking for a catch scope. A simple catch parameter
is the only binding a `var` is allowed to shadow, so a name that does not
resolve to the variable being declared is shadowed by one.1 parent 684b579 commit 8e69622
2 files changed
Lines changed: 89 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
224 | 248 | | |
225 | 249 | | |
226 | 250 | | |
| |||
276 | 300 | | |
277 | 301 | | |
278 | 302 | | |
| 303 | + | |
279 | 304 | | |
280 | 305 | | |
281 | 306 | | |
| |||
312 | 337 | | |
313 | 338 | | |
314 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
315 | 349 | | |
316 | 350 | | |
317 | 351 | | |
| |||
330 | 364 | | |
331 | 365 | | |
332 | 366 | | |
333 | | - | |
| 367 | + | |
| 368 | + | |
334 | 369 | | |
335 | 370 | | |
336 | 371 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
508 | 561 | | |
509 | 562 | | |
510 | 563 | | |
| |||
0 commit comments