From f16d4af8f2d53f23139d1b60996de2fb0561e300 Mon Sep 17 00:00:00 2001 From: wdsmini Date: Thu, 26 Mar 2026 22:52:28 +0800 Subject: [PATCH] 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 --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0567712f11da3..3f3291a5f0917 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -53030,7 +53030,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let current: Node = node; while (current) { if (isFunctionLikeOrClassStaticBlockDeclaration(current)) { - return grammarErrorOnNode(node, Diagnostics.Jump_target_cannot_cross_function_boundary); + return grammarErrorOnNode(node, Diagnostics.Jump_target_0_cannot_cross_function_boundary, node.label ? node.label.text : ""); } switch (current.kind) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 46c280799d7f9..a7ee23c49b69d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -307,6 +307,10 @@ "category": "Error", "code": 1107 }, + "Jump target '{0}' cannot cross function boundary.": { + "category": "Error", + "code": 1107 + }, "A 'return' statement can only be used within a function body.": { "category": "Error", "code": 1108