Skip to content

Commit

Permalink
fix: Support trailing comma in function type parameters (#2608)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO authored Jan 6, 2023
1 parent 4b3b390 commit 1ff71e5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/parser/function-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions tests/parser/function-type.ts.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1ff71e5

Please sign in to comment.