Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Trailing Commas #7747

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17244,7 +17244,8 @@ namespace ts {
}

function checkGrammarForDisallowedTrailingComma(list: NodeArray<Node>): boolean {
if (list && list.hasTrailingComma) {
if (list && list.hasTrailingComma &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just remove the calls in checkGrammarArguments and checkGrammarParameterList ?

!(list[0].parent.kind === SyntaxKind.FunctionDeclaration || list[0].parent.kind === SyntaxKind.ArrowFunction)) {
const start = list.end - ",".length;
const end = list.end;
const sourceFile = getSourceFileOfNode(list[0]);
Expand Down
5 changes: 1 addition & 4 deletions tests/baselines/reference/ArrowFunction2.errors.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction2.ts(1,13): error TS2304: Cannot find name 'b'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction2.ts(1,14): error TS1009: Trailing comma not allowed.


==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction2.ts (2 errors) ====
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction2.ts (1 errors) ====
var v = (a: b,) => {
~
!!! error TS2304: Cannot find name 'b'.
~
!!! error TS1009: Trailing comma not allowed.

};

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions tests/baselines/reference/parserParameterList12.errors.txt

This file was deleted.

5 changes: 5 additions & 0 deletions tests/baselines/reference/parserParameterList12.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== tests/cases/conformance/parser/ecmascript5/ParameterLists/parserParameterList12.ts ===
function F(a,) {
>F : Symbol(F, Decl(parserParameterList12.ts, 0, 0))
>a : Symbol(a, Decl(parserParameterList12.ts, 0, 11))
}
5 changes: 5 additions & 0 deletions tests/baselines/reference/parserParameterList12.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== tests/cases/conformance/parser/ecmascript5/ParameterLists/parserParameterList12.ts ===
function F(a,) {
>F : (a: any) => void
>a : any
}
5 changes: 1 addition & 4 deletions tests/baselines/reference/parserX_ArrowFunction2.errors.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction2.ts(1,13): error TS2304: Cannot find name 'b'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction2.ts(1,14): error TS1009: Trailing comma not allowed.


==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction2.ts (2 errors) ====
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction2.ts (1 errors) ====
var v = (a: b,) => {
~
!!! error TS2304: Cannot find name 'b'.
~
!!! error TS1009: Trailing comma not allowed.

};
14 changes: 14 additions & 0 deletions tests/baselines/reference/trailingCommasInFunctionParameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [trailingCommasInFunctionParameter.ts]
function f1(x, y,) {
}

function f2() {
return (x,) => {}
}

//// [trailingCommasInFunctionParameter.js]
function f1(x, y) {
}
function f2() {
return function (x) { };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/conformance/es7/trailingCommasInFunctionParamLists/trailingCommasInFunctionParameter.ts ===
function f1(x, y,) {
>f1 : Symbol(f1, Decl(trailingCommasInFunctionParameter.ts, 0, 0))
>x : Symbol(x, Decl(trailingCommasInFunctionParameter.ts, 0, 12))
>y : Symbol(y, Decl(trailingCommasInFunctionParameter.ts, 0, 14))
}

function f2() {
>f2 : Symbol(f2, Decl(trailingCommasInFunctionParameter.ts, 1, 1))

return (x,) => {}
>x : Symbol(x, Decl(trailingCommasInFunctionParameter.ts, 4, 12))
}
14 changes: 14 additions & 0 deletions tests/baselines/reference/trailingCommasInFunctionParameter.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== tests/cases/conformance/es7/trailingCommasInFunctionParamLists/trailingCommasInFunctionParameter.ts ===
function f1(x, y,) {
>f1 : (x: any, y: any) => void
>x : any
>y : any
}

function f2() {
>f2 : () => (x: any) => void

return (x,) => {}
>(x,) => {} : (x: any) => void
>x : any
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @target: es5
function f1(x, y,) {
}

function f2() {
return (x,) => {}
}

This file was deleted.