-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Allow trailing commas in function parameter and argument lists #8942
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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)) | ||
} |
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 | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts(20,11): error TS1138: Parameter declaration expected. | ||
|
||
|
||
==== tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts (1 errors) ==== | ||
function f1(x,) {} | ||
|
||
f1(1,); | ||
|
||
function f2(...args,) {} | ||
|
||
f2(...[],); | ||
|
||
// Not confused by overloads | ||
declare function f3(x, ): number; | ||
declare function f3(x, y,): string; | ||
|
||
<number>f3(1,); | ||
<string>f3(1, 2,); | ||
|
||
// Works for constructors too | ||
class X { | ||
constructor(a,) { } | ||
// *Not* allowed in getter | ||
get x(,) { return 0; } | ||
~ | ||
!!! error TS1138: Parameter declaration expected. | ||
set x(value,) { } | ||
} | ||
interface Y { | ||
new(x,); | ||
(x,); | ||
} | ||
|
||
new X(1,); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//// [trailingCommasInFunctionParametersAndArguments.ts] | ||
function f1(x,) {} | ||
|
||
f1(1,); | ||
|
||
function f2(...args,) {} | ||
|
||
f2(...[],); | ||
|
||
// Not confused by overloads | ||
declare function f3(x, ): number; | ||
declare function f3(x, y,): string; | ||
|
||
<number>f3(1,); | ||
<string>f3(1, 2,); | ||
|
||
// Works for constructors too | ||
class X { | ||
constructor(a,) { } | ||
// *Not* allowed in getter | ||
get x(,) { return 0; } | ||
set x(value,) { } | ||
} | ||
interface Y { | ||
new(x,); | ||
(x,); | ||
} | ||
|
||
new X(1,); | ||
|
||
|
||
//// [trailingCommasInFunctionParametersAndArguments.js] | ||
function f1(x) { } | ||
f1(1); | ||
function f2() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i - 0] = arguments[_i]; | ||
} | ||
} | ||
f2.apply(void 0, []); | ||
f3(1); | ||
f3(1, 2); | ||
// Works for constructors too | ||
var X = (function () { | ||
function X(a) { | ||
} | ||
Object.defineProperty(X.prototype, "x", { | ||
// *Not* allowed in getter | ||
get: function () { return 0; }, | ||
set: function (value) { }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return X; | ||
}()); | ||
new X(1); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
=== tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts === | ||
function f1(x,) {} | ||
>f1 : Symbol(f1, Decl(trailingCommasInFunctionParametersAndArguments.ts, 0, 0)) | ||
>x : Symbol(x, Decl(trailingCommasInFunctionParametersAndArguments.ts, 0, 12)) | ||
|
||
f1(1,); | ||
>f1 : Symbol(f1, Decl(trailingCommasInFunctionParametersAndArguments.ts, 0, 0)) | ||
|
||
function f2(...args,) {} | ||
>f2 : Symbol(f2, Decl(trailingCommasInFunctionParametersAndArguments.ts, 2, 7)) | ||
>args : Symbol(args, Decl(trailingCommasInFunctionParametersAndArguments.ts, 4, 12)) | ||
|
||
f2(...[],); | ||
>f2 : Symbol(f2, Decl(trailingCommasInFunctionParametersAndArguments.ts, 2, 7)) | ||
|
||
// Not confused by overloads | ||
declare function f3(x, ): number; | ||
>f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 6, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 9, 33)) | ||
>x : Symbol(x, Decl(trailingCommasInFunctionParametersAndArguments.ts, 9, 20)) | ||
|
||
declare function f3(x, y,): string; | ||
>f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 6, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 9, 33)) | ||
>x : Symbol(x, Decl(trailingCommasInFunctionParametersAndArguments.ts, 10, 20)) | ||
>y : Symbol(y, Decl(trailingCommasInFunctionParametersAndArguments.ts, 10, 22)) | ||
|
||
<number>f3(1,); | ||
>f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 6, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 9, 33)) | ||
|
||
<string>f3(1, 2,); | ||
>f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 6, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 9, 33)) | ||
|
||
// Works for constructors too | ||
class X { | ||
>X : Symbol(X, Decl(trailingCommasInFunctionParametersAndArguments.ts, 13, 18)) | ||
|
||
constructor(a,) { } | ||
>a : Symbol(a, Decl(trailingCommasInFunctionParametersAndArguments.ts, 17, 16)) | ||
} | ||
new X(1,); | ||
>X : Symbol(X, Decl(trailingCommasInFunctionParametersAndArguments.ts, 13, 18)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's weird, I wasn't expecting to see a .errors.txt and a .types. Usually they are mutually exclusive. Did the .types file manage to skip the broken getter/setter pair?