Skip to content

Commit 017de5d

Browse files
committed
fix(parser): update error code for type annotation in for...in statement (#19882)
1 parent 1b7a937 commit 017de5d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

crates/oxc_semantic/src/diagnostics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,12 @@ pub fn accessor_without_body(span: Span) -> OxcDiagnostic {
425425
}
426426

427427
/// The left-hand side of a 'for...of' statement cannot use a type annotation. (2483)
428+
/// The left-hand side of a 'for...in' statement cannot use a type annotation. (2404)
428429
#[cold]
429430
pub fn type_annotation_in_for_left(span: Span, is_for_in: bool) -> OxcDiagnostic {
430-
let for_of_or_in = if is_for_in { "for...in" } else { "for...of" };
431+
let (for_of_or_in, code) = if is_for_in { ("for...in", "2404") } else { ("for...of", "2483") };
431432
ts_error(
432-
"2483",
433+
code,
433434
format!(
434435
"The left-hand side of a '{for_of_or_in}' statement cannot use a type annotation.",
435436
),

tasks/coverage/snapshots/parser_typescript.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6600,7 +6600,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
66006600
30 │ }
66016601
╰────
66026602

6603-
× TS(2483): The left-hand side of a 'for...in' statement cannot use a type annotation.
6603+
× TS(2404): The left-hand side of a 'for...in' statement cannot use a type annotation.
66046604
╭─[typescript/tests/cases/compiler/forIn.ts:2:10]
66056605
1 │ var arr = null;
66066606
2 │ for (var i:number in arr) { // error
@@ -6609,7 +6609,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
66096609
╰────
66106610
help: This iterator's type will be inferred from the iterable. You can safely remove the type annotation.
66116611

6612-
× TS(2483): The left-hand side of a 'for...in' statement cannot use a type annotation.
6612+
× TS(2404): The left-hand side of a 'for...in' statement cannot use a type annotation.
66136613
╭─[typescript/tests/cases/compiler/forInStatement4.ts:2:10]
66146614
1 │ var expr: any;
66156615
2 │ for (var a: number in expr) {
@@ -24886,7 +24886,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
2488624886
2 │ }
2488724887
╰────
2488824888

24889-
× TS(2483): The left-hand side of a 'for...in' statement cannot use a type annotation.
24889+
× TS(2404): The left-hand side of a 'for...in' statement cannot use a type annotation.
2489024890
╭─[typescript/tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement5.ts:1:10]
2489124891
1 │ for (var a: number in X) {
2489224892
· ─
@@ -24908,15 +24908,15 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
2490824908
2 │ }
2490924909
╰────
2491024910

24911-
× TS(2483): The left-hand side of a 'for...in' statement cannot use a type annotation.
24911+
× TS(2404): The left-hand side of a 'for...in' statement cannot use a type annotation.
2491224912
╭─[typescript/tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts:1:10]
2491324913
1 │ for (var a: number = 1, b: string = "" in X) {
2491424914
· ─
2491524915
2 │ }
2491624916
╰────
2491724917
help: This iterator's type will be inferred from the iterable. You can safely remove the type annotation.
2491824918

24919-
× TS(2483): The left-hand side of a 'for...in' statement cannot use a type annotation.
24919+
× TS(2404): The left-hand side of a 'for...in' statement cannot use a type annotation.
2492024920
╭─[typescript/tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement7.ts:1:25]
2492124921
1 │ for (var a: number = 1, b: string = "" in X) {
2492224922
· ─
@@ -26462,7 +26462,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
2646226462
38 │ }
2646326463
╰────
2646426464

26465-
× TS(2483): The left-hand side of a 'for...in' statement cannot use a type annotation.
26465+
× TS(2404): The left-hand side of a 'for...in' statement cannot use a type annotation.
2646626466
╭─[typescript/tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts:10:10]
2646726467
9 │
2646826468
10 │ for (var idx : number in {}) { }

0 commit comments

Comments
 (0)