Commit 98d5745
committed
fix: skip block-scoped variable check for label identifiers
Labels and variables occupy separate namespaces in JavaScript/TypeScript.
When a label name coincides with a later let/const variable declaration,
the compiler incorrectly reports "Block-scoped variable used before its
declaration" on the label identifier or break/continue target.
This adds a guard in checkResolvedBlockScopedVariable to skip the check
when the error location is the label of a LabeledStatement, BreakStatement,
or ContinueStatement, since these reference labels, not variables.
Fixes #304081 parent 7b8cb3b commit 98d5745
2 files changed
Lines changed: 37 additions & 0 deletions
File tree
- src/compiler
- tests/cases/conformance/statements/labeledStatements
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3603 | 3603 | | |
3604 | 3604 | | |
3605 | 3605 | | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
| 3612 | + | |
| 3613 | + | |
| 3614 | + | |
| 3615 | + | |
| 3616 | + | |
| 3617 | + | |
3606 | 3618 | | |
3607 | 3619 | | |
3608 | 3620 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
0 commit comments