From 1ff71e51111a20f8f22b8fa2dd2aa078825a8d2c Mon Sep 17 00:00:00 2001 From: dcode Date: Fri, 6 Jan 2023 23:50:00 +0100 Subject: [PATCH] fix: Support trailing comma in function type parameters (#2608) --- src/parser.ts | 1 + tests/parser/function-type.ts | 1 + tests/parser/function-type.ts.fixture.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/src/parser.ts b/src/parser.ts index 166c3d4132..cade050161 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -797,6 +797,7 @@ export class Parser extends DiagnosticEmitter { } } else { if (isSignature) { + if (tn.peek() == Token.CloseParen) break; // allow trailing comma this.error( DiagnosticCode.Identifier_expected, tn.range() diff --git a/tests/parser/function-type.ts b/tests/parser/function-type.ts index 4c9a385fe5..f547cdeefa 100644 --- a/tests/parser/function-type.ts +++ b/tests/parser/function-type.ts @@ -3,3 +3,4 @@ var b: (a: i32, b: i32) => void; var c: (a: i32, b: i32) => (a: i32, b: i32) => void; var d: (a: i32, a: i32) => void; // NOTE: duplicates in type signatures doesn't in TypeScript var e: (a) => void; // TS1110 +var f: (a: i32, b: i32,) => (a: i32, b: i32,) => void; diff --git a/tests/parser/function-type.ts.fixture.ts b/tests/parser/function-type.ts.fixture.ts index 061e00711d..e4e6aa7888 100644 --- a/tests/parser/function-type.ts.fixture.ts +++ b/tests/parser/function-type.ts.fixture.ts @@ -3,4 +3,5 @@ var b: (a: i32, b: i32) => void; var c: (a: i32, b: i32) => (a: i32, b: i32) => void; var d: (a: i32, a: i32) => void; var e: (a) => void; +var f: (a: i32, b: i32) => (a: i32, b: i32) => void; // ERROR 1110: "Type expected." in function-type.ts(5,10+0)