Skip to content

Commit f16d4af

Browse files
author
wdsmini
committed
fix(30408): improve error message for labels used before definition
The error message 'Jump target cannot cross function boundary' was confusing because it didn't indicate which label was causing the issue. This change adds the label name to the error message when available. Before: 'Jump target cannot cross function boundary.' After: 'Jump target 'loopend' cannot cross function boundary.' Fixes #30408
1 parent 77ddb5b commit f16d4af

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53030,7 +53030,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
5303053030
let current: Node = node;
5303153031
while (current) {
5303253032
if (isFunctionLikeOrClassStaticBlockDeclaration(current)) {
53033-
return grammarErrorOnNode(node, Diagnostics.Jump_target_cannot_cross_function_boundary);
53033+
return grammarErrorOnNode(node, Diagnostics.Jump_target_0_cannot_cross_function_boundary, node.label ? node.label.text : "");
5303453034
}
5303553035

5303653036
switch (current.kind) {

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@
307307
"category": "Error",
308308
"code": 1107
309309
},
310+
"Jump target '{0}' cannot cross function boundary.": {
311+
"category": "Error",
312+
"code": 1107
313+
},
310314
"A 'return' statement can only be used within a function body.": {
311315
"category": "Error",
312316
"code": 1108

0 commit comments

Comments
 (0)