From 4281bf5752b58ac466723e2339e49aad0f3ac298 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Thu, 2 Jun 2016 07:35:58 -0700 Subject: [PATCH 1/5] Allow trailing commas in function parameter and argument lists --- src/compiler/checker.ts | 20 +++++++------------ .../reference/ArrowFunction2.errors.txt | 3 --- ...serErrorRecovery_ParameterList3.errors.txt | 8 -------- .../parserErrorRecovery_ParameterList3.js | 7 ------- .../parserParameterList12.errors.txt | 8 -------- .../reference/parserParameterList12.symbols | 5 +++++ .../reference/parserParameterList12.types | 5 +++++ ...gCommasInFunctionParametersAndArguments.js | 9 +++++++++ ...asInFunctionParametersAndArguments.symbols | 8 ++++++++ ...mmasInFunctionParametersAndArguments.types | 10 ++++++++++ ...gCommasInFunctionParametersAndArguments.ts | 3 +++ .../parserErrorRecovery_ParameterList3.ts | 2 -- .../fourslash/trailingCommaSignatureHelp.ts | 15 ++++++++++++++ 13 files changed, 62 insertions(+), 41 deletions(-) delete mode 100644 tests/baselines/reference/parserErrorRecovery_ParameterList3.errors.txt delete mode 100644 tests/baselines/reference/parserErrorRecovery_ParameterList3.js delete mode 100644 tests/baselines/reference/parserParameterList12.errors.txt create mode 100644 tests/baselines/reference/parserParameterList12.symbols create mode 100644 tests/baselines/reference/parserParameterList12.types create mode 100644 tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js create mode 100644 tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols create mode 100644 tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types create mode 100644 tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts delete mode 100644 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList3.ts create mode 100644 tests/cases/fourslash/trailingCommaSignatureHelp.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 06ef246340252..402d64553877c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10322,7 +10322,7 @@ namespace ts { } function hasCorrectArity(node: CallLikeExpression, args: Expression[], signature: Signature) { - let adjustedArgCount: number; // Apparent number of arguments we will have in this call + let argCount: number; // Apparent number of arguments we will have in this call let typeArguments: NodeArray; // Type arguments (undefined if none) let callIsIncomplete: boolean; // In incomplete call we want to be lenient when we have too few arguments let isDecorator: boolean; @@ -10333,7 +10333,7 @@ namespace ts { // Even if the call is incomplete, we'll have a missing expression as our last argument, // so we can say the count is just the arg list length - adjustedArgCount = args.length; + argCount = args.length; typeArguments = undefined; if (tagExpression.template.kind === SyntaxKind.TemplateExpression) { @@ -10356,7 +10356,7 @@ namespace ts { else if (node.kind === SyntaxKind.Decorator) { isDecorator = true; typeArguments = undefined; - adjustedArgCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature); + argCount = getEffectiveArgumentCount(node, /*args*/ undefined, signature); } else { const callExpression = node; @@ -10367,8 +10367,7 @@ namespace ts { return signature.minArgumentCount === 0; } - // For IDE scenarios we may have an incomplete call, so a trailing comma is tantamount to adding another argument. - adjustedArgCount = callExpression.arguments.hasTrailingComma ? args.length + 1 : args.length; + argCount = args.length; // If we are missing the close paren, the call is incomplete. callIsIncomplete = (callExpression).arguments.end === callExpression.end; @@ -10392,12 +10391,12 @@ namespace ts { } // Too many arguments implies incorrect arity. - if (!signature.hasRestParameter && adjustedArgCount > signature.parameters.length) { + if (!signature.hasRestParameter && argCount > signature.parameters.length) { return false; } // If the call is incomplete, we should skip the lower bound check. - const hasEnoughArguments = adjustedArgCount >= signature.minArgumentCount; + const hasEnoughArguments = argCount >= signature.minArgumentCount; return callIsIncomplete || hasEnoughArguments; } @@ -18027,10 +18026,6 @@ namespace ts { } function checkGrammarParameterList(parameters: NodeArray) { - if (checkGrammarForDisallowedTrailingComma(parameters)) { - return true; - } - let seenOptionalParameter = false; const parameterCount = parameters.length; @@ -18149,8 +18144,7 @@ namespace ts { } function checkGrammarArguments(node: CallExpression, args: NodeArray): boolean { - return checkGrammarForDisallowedTrailingComma(args) || - checkGrammarForOmittedArgument(node, args); + return checkGrammarForOmittedArgument(node, args); } function checkGrammarHeritageClause(node: HeritageClause): boolean { diff --git a/tests/baselines/reference/ArrowFunction2.errors.txt b/tests/baselines/reference/ArrowFunction2.errors.txt index 3b9ba21f15af9..d18bc483accff 100644 --- a/tests/baselines/reference/ArrowFunction2.errors.txt +++ b/tests/baselines/reference/ArrowFunction2.errors.txt @@ -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) ==== var v = (a: b,) => { ~ !!! error TS2304: Cannot find name 'b'. - ~ -!!! error TS1009: Trailing comma not allowed. }; \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ParameterList3.errors.txt b/tests/baselines/reference/parserErrorRecovery_ParameterList3.errors.txt deleted file mode 100644 index df73dc51ce15a..0000000000000 --- a/tests/baselines/reference/parserErrorRecovery_ParameterList3.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList3.ts(1,13): error TS1009: Trailing comma not allowed. - - -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList3.ts (1 errors) ==== - function f(a,) { - ~ -!!! error TS1009: Trailing comma not allowed. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ParameterList3.js b/tests/baselines/reference/parserErrorRecovery_ParameterList3.js deleted file mode 100644 index 4c20e676f40ba..0000000000000 --- a/tests/baselines/reference/parserErrorRecovery_ParameterList3.js +++ /dev/null @@ -1,7 +0,0 @@ -//// [parserErrorRecovery_ParameterList3.ts] -function f(a,) { -} - -//// [parserErrorRecovery_ParameterList3.js] -function f(a) { -} diff --git a/tests/baselines/reference/parserParameterList12.errors.txt b/tests/baselines/reference/parserParameterList12.errors.txt deleted file mode 100644 index 686b29f63b18f..0000000000000 --- a/tests/baselines/reference/parserParameterList12.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/ParameterLists/parserParameterList12.ts(1,13): error TS1009: Trailing comma not allowed. - - -==== tests/cases/conformance/parser/ecmascript5/ParameterLists/parserParameterList12.ts (1 errors) ==== - function F(a,) { - ~ -!!! error TS1009: Trailing comma not allowed. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserParameterList12.symbols b/tests/baselines/reference/parserParameterList12.symbols new file mode 100644 index 0000000000000..efaab7d1b13b1 --- /dev/null +++ b/tests/baselines/reference/parserParameterList12.symbols @@ -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)) +} diff --git a/tests/baselines/reference/parserParameterList12.types b/tests/baselines/reference/parserParameterList12.types new file mode 100644 index 0000000000000..7ff43cd6a15c7 --- /dev/null +++ b/tests/baselines/reference/parserParameterList12.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/parser/ecmascript5/ParameterLists/parserParameterList12.ts === +function F(a,) { +>F : (a: any) => void +>a : any +} diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js new file mode 100644 index 0000000000000..5fb4b7d638f17 --- /dev/null +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js @@ -0,0 +1,9 @@ +//// [trailingCommasInFunctionParametersAndArguments.ts] +function f1(x,) {} + +f1(1,); + + +//// [trailingCommasInFunctionParametersAndArguments.js] +function f1(x) { } +f1(1); diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols new file mode 100644 index 0000000000000..5eb9d75807b51 --- /dev/null +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols @@ -0,0 +1,8 @@ +=== 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)) + diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types new file mode 100644 index 0000000000000..4af2326076b0c --- /dev/null +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts === +function f1(x,) {} +>f1 : (x: any) => void +>x : any + +f1(1,); +>f1(1,) : void +>f1 : (x: any) => void +>1 : number + diff --git a/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts new file mode 100644 index 0000000000000..0492ed989e362 --- /dev/null +++ b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts @@ -0,0 +1,3 @@ +function f1(x,) {} + +f1(1,); diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList3.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList3.ts deleted file mode 100644 index c51a52ef83ef2..0000000000000 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ParameterLists/parserErrorRecovery_ParameterList3.ts +++ /dev/null @@ -1,2 +0,0 @@ -function f(a,) { -} \ No newline at end of file diff --git a/tests/cases/fourslash/trailingCommaSignatureHelp.ts b/tests/cases/fourslash/trailingCommaSignatureHelp.ts new file mode 100644 index 0000000000000..4881571cd2b0b --- /dev/null +++ b/tests/cases/fourslash/trailingCommaSignatureHelp.ts @@ -0,0 +1,15 @@ +/// + +////function str(n: number): string; +/////** +//// * Stringifies a number with radix +//// * @param radix The radix +//// */ +////function str(n: number, radix: number): string; +////function str(n: number, radix?: number): string { return ""; } + +edit.insert("str(1,"); +verify.currentParameterHelpArgumentNameIs("radix"); +verify.currentParameterHelpArgumentDocCommentIs("The radix"); +verify.currentSignatureHelpIs("str(n: number, radix: number): string"); +verify.currentSignatureHelpDocCommentIs("Stringifies a number with radix"); From 8b0974a77e6317891fc11259dd06f721b621be5d Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 3 Jun 2016 09:29:21 -0700 Subject: [PATCH 2/5] Update tests --- .../reference/ArrowFunction2.errors.txt | 9 ------- tests/baselines/reference/ArrowFunction2.js | 8 ------- ...rserErrorRecovery_ArgumentList5.errors.txt | 16 ------------- .../parserErrorRecovery_ArgumentList5.js | 11 --------- .../parserX_ArrowFunction2.errors.txt | 12 ---------- .../reference/parserX_ArrowFunction2.js | 8 ------- ...gCommasInFunctionParametersAndArguments.js | 11 +++++++++ ...asInFunctionParametersAndArguments.symbols | 7 ++++++ ...mmasInFunctionParametersAndArguments.types | 10 ++++++++ ...trailingSeparatorInFunctionCall.errors.txt | 24 ------------------- .../trailingSeparatorInFunctionCall.js | 18 -------------- .../trailingSeparatorInFunctionCall.ts | 9 ------- ...gCommasInFunctionParametersAndArguments.ts | 4 ++++ .../parserErrorRecovery_ArgumentList5.ts | 4 ---- .../ArrowFunctions/ArrowFunction2.ts | 3 --- .../ArrowFunctions/parserX_ArrowFunction2.ts | 3 --- 16 files changed, 32 insertions(+), 125 deletions(-) delete mode 100644 tests/baselines/reference/ArrowFunction2.errors.txt delete mode 100644 tests/baselines/reference/ArrowFunction2.js delete mode 100644 tests/baselines/reference/parserErrorRecovery_ArgumentList5.errors.txt delete mode 100644 tests/baselines/reference/parserErrorRecovery_ArgumentList5.js delete mode 100644 tests/baselines/reference/parserX_ArrowFunction2.errors.txt delete mode 100644 tests/baselines/reference/parserX_ArrowFunction2.js delete mode 100644 tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt delete mode 100644 tests/baselines/reference/trailingSeparatorInFunctionCall.js delete mode 100644 tests/cases/compiler/trailingSeparatorInFunctionCall.ts delete mode 100644 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts delete mode 100644 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction2.ts delete mode 100644 tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction2.ts diff --git a/tests/baselines/reference/ArrowFunction2.errors.txt b/tests/baselines/reference/ArrowFunction2.errors.txt deleted file mode 100644 index d18bc483accff..0000000000000 --- a/tests/baselines/reference/ArrowFunction2.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -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 (2 errors) ==== - var v = (a: b,) => { - ~ -!!! error TS2304: Cannot find name 'b'. - - }; \ No newline at end of file diff --git a/tests/baselines/reference/ArrowFunction2.js b/tests/baselines/reference/ArrowFunction2.js deleted file mode 100644 index fa6b8bf3b9ea8..0000000000000 --- a/tests/baselines/reference/ArrowFunction2.js +++ /dev/null @@ -1,8 +0,0 @@ -//// [ArrowFunction2.ts] -var v = (a: b,) => { - -}; - -//// [ArrowFunction2.js] -var v = function (a) { -}; diff --git a/tests/baselines/reference/parserErrorRecovery_ArgumentList5.errors.txt b/tests/baselines/reference/parserErrorRecovery_ArgumentList5.errors.txt deleted file mode 100644 index 5113807faa856..0000000000000 --- a/tests/baselines/reference/parserErrorRecovery_ArgumentList5.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,4): error TS2304: Cannot find name 'bar'. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,8): error TS2304: Cannot find name 'a'. -tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts(2,9): error TS1009: Trailing comma not allowed. - - -==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts (3 errors) ==== - function foo() { - bar(a,) - ~~~ -!!! error TS2304: Cannot find name 'bar'. - ~ -!!! error TS2304: Cannot find name 'a'. - ~ -!!! error TS1009: Trailing comma not allowed. - return; - } \ No newline at end of file diff --git a/tests/baselines/reference/parserErrorRecovery_ArgumentList5.js b/tests/baselines/reference/parserErrorRecovery_ArgumentList5.js deleted file mode 100644 index bbb65a44e078c..0000000000000 --- a/tests/baselines/reference/parserErrorRecovery_ArgumentList5.js +++ /dev/null @@ -1,11 +0,0 @@ -//// [parserErrorRecovery_ArgumentList5.ts] -function foo() { - bar(a,) - return; -} - -//// [parserErrorRecovery_ArgumentList5.js] -function foo() { - bar(a); - return; -} diff --git a/tests/baselines/reference/parserX_ArrowFunction2.errors.txt b/tests/baselines/reference/parserX_ArrowFunction2.errors.txt deleted file mode 100644 index 20b4cb45e453c..0000000000000 --- a/tests/baselines/reference/parserX_ArrowFunction2.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -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) ==== - var v = (a: b,) => { - ~ -!!! error TS2304: Cannot find name 'b'. - ~ -!!! error TS1009: Trailing comma not allowed. - - }; \ No newline at end of file diff --git a/tests/baselines/reference/parserX_ArrowFunction2.js b/tests/baselines/reference/parserX_ArrowFunction2.js deleted file mode 100644 index a30294b658b9c..0000000000000 --- a/tests/baselines/reference/parserX_ArrowFunction2.js +++ /dev/null @@ -1,8 +0,0 @@ -//// [parserX_ArrowFunction2.ts] -var v = (a: b,) => { - -}; - -//// [parserX_ArrowFunction2.js] -var v = function (a) { -}; diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js index 5fb4b7d638f17..a9b173f9db225 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js @@ -2,8 +2,19 @@ function f1(x,) {} f1(1,); + +function f2(...args,) {} + +f2(...[],); //// [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, []); diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols index 5eb9d75807b51..dd9ce5319c9b3 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols @@ -6,3 +6,10 @@ function f1(x,) {} 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)) + diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types index 4af2326076b0c..0a8d34d1df277 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types @@ -8,3 +8,13 @@ f1(1,); >f1 : (x: any) => void >1 : number +function f2(...args,) {} +>f2 : (...args: any[]) => void +>args : any[] + +f2(...[],); +>f2(...[],) : void +>f2 : (...args: any[]) => void +>...[] : undefined +>[] : undefined[] + diff --git a/tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt b/tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt deleted file mode 100644 index 76e09a1a4de3f..0000000000000 --- a/tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,7): error TS1009: Trailing comma not allowed. -tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,8): error TS1009: Trailing comma not allowed. - - -==== tests/cases/compiler/trailingSeparatorInFunctionCall.ts (4 errors) ==== - function f(x, y) { - } - - f(1, 2, ); - ~~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. - ~ -!!! error TS1009: Trailing comma not allowed. - - function f2(x: T, y: T) { - } - - f2(1, 2, ); - ~~~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. - ~ -!!! error TS1009: Trailing comma not allowed. \ No newline at end of file diff --git a/tests/baselines/reference/trailingSeparatorInFunctionCall.js b/tests/baselines/reference/trailingSeparatorInFunctionCall.js deleted file mode 100644 index 4b531479837b2..0000000000000 --- a/tests/baselines/reference/trailingSeparatorInFunctionCall.js +++ /dev/null @@ -1,18 +0,0 @@ -//// [trailingSeparatorInFunctionCall.ts] -function f(x, y) { -} - -f(1, 2, ); - -function f2(x: T, y: T) { -} - -f2(1, 2, ); - -//// [trailingSeparatorInFunctionCall.js] -function f(x, y) { -} -f(1, 2); -function f2(x, y) { -} -f2(1, 2); diff --git a/tests/cases/compiler/trailingSeparatorInFunctionCall.ts b/tests/cases/compiler/trailingSeparatorInFunctionCall.ts deleted file mode 100644 index b9f62e1e8cccb..0000000000000 --- a/tests/cases/compiler/trailingSeparatorInFunctionCall.ts +++ /dev/null @@ -1,9 +0,0 @@ -function f(x, y) { -} - -f(1, 2, ); - -function f2(x: T, y: T) { -} - -f2(1, 2, ); \ No newline at end of file diff --git a/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts index 0492ed989e362..4b628e7e55961 100644 --- a/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts +++ b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts @@ -1,3 +1,7 @@ function f1(x,) {} f1(1,); + +function f2(...args,) {} + +f2(...[],); diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts deleted file mode 100644 index 0270f766fefe2..0000000000000 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArgumentLists/parserErrorRecovery_ArgumentList5.ts +++ /dev/null @@ -1,4 +0,0 @@ -function foo() { - bar(a,) - return; -} \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction2.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction2.ts deleted file mode 100644 index 8b4d99e2ef5d5..0000000000000 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/ArrowFunction2.ts +++ /dev/null @@ -1,3 +0,0 @@ -var v = (a: b,) => { - -}; \ No newline at end of file diff --git a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction2.ts b/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction2.ts deleted file mode 100644 index 8b4d99e2ef5d5..0000000000000 --- a/tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ArrowFunctions/parserX_ArrowFunction2.ts +++ /dev/null @@ -1,3 +0,0 @@ -var v = (a: b,) => { - -}; \ No newline at end of file From 2fc2f5c4b975f05e46cf0193b345607ea4983d76 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 6 Jun 2016 07:50:32 -0700 Subject: [PATCH 3/5] Fix signature help --- src/compiler/checker.ts | 17 +++++---- ...gCommasInFunctionParametersAndArguments.js | 22 ++++++++++++ ...asInFunctionParametersAndArguments.symbols | 26 ++++++++++++++ ...mmasInFunctionParametersAndArguments.types | 35 +++++++++++++++++++ ...gCommasInFunctionParametersAndArguments.ts | 13 +++++++ 5 files changed, 107 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 402d64553877c..524b9b2f505e2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10321,7 +10321,7 @@ namespace ts { return -1; } - function hasCorrectArity(node: CallLikeExpression, args: Expression[], signature: Signature) { + function hasCorrectArity(node: CallLikeExpression, args: Expression[], signature: Signature, signatureHelpTrailingComma = false) { let argCount: number; // Apparent number of arguments we will have in this call let typeArguments: NodeArray; // Type arguments (undefined if none) let callIsIncomplete: boolean; // In incomplete call we want to be lenient when we have too few arguments @@ -10367,7 +10367,7 @@ namespace ts { return signature.minArgumentCount === 0; } - argCount = args.length; + argCount = signatureHelpTrailingComma ? args.length + 1 : args.length; // If we are missing the close paren, the call is incomplete. callIsIncomplete = (callExpression).arguments.end === callExpression.end; @@ -10968,6 +10968,11 @@ namespace ts { let resultOfFailedInference: InferenceContext; let result: Signature; + // If we are in signature help, a trailing comma indicates that we intend to provide another argument, + // so we will only accept overloads with arity at least 1 higher than the current number of provided arguments. + const signatureHelpTrailingComma = + candidatesOutArray && node.kind === SyntaxKind.CallExpression && (node).arguments.hasTrailingComma; + // Section 4.12.1: // if the candidate list contains one or more signatures for which the type of each argument // expression is a subtype of each corresponding parameter type, the return type of the first @@ -10979,14 +10984,14 @@ namespace ts { // is just important for choosing the best signature. So in the case where there is only one // signature, the subtype pass is useless. So skipping it is an optimization. if (candidates.length > 1) { - result = chooseOverload(candidates, subtypeRelation); + result = chooseOverload(candidates, subtypeRelation, signatureHelpTrailingComma); } if (!result) { // Reinitialize these pointers for round two candidateForArgumentError = undefined; candidateForTypeArgumentError = undefined; resultOfFailedInference = undefined; - result = chooseOverload(candidates, assignableRelation); + result = chooseOverload(candidates, assignableRelation, signatureHelpTrailingComma); } if (result) { return result; @@ -11057,9 +11062,9 @@ namespace ts { diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo)); } - function chooseOverload(candidates: Signature[], relation: Map) { + function chooseOverload(candidates: Signature[], relation: Map, signatureHelpTrailingComma = false) { for (const originalCandidate of candidates) { - if (!hasCorrectArity(node, args, originalCandidate)) { + if (!hasCorrectArity(node, args, originalCandidate, signatureHelpTrailingComma)) { continue; } diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js index a9b173f9db225..87c925fb22b5a 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js @@ -6,6 +6,19 @@ f1(1,); function f2(...args,) {} f2(...[],); + +// Not confused by overloads +declare function f3(x, ): number; +declare function f3(x, y,): string; + +f3(1,); +f3(1, 2,); + +// Works for constructors too +class X { + constructor(a,) { } +} +new X(1,); //// [trailingCommasInFunctionParametersAndArguments.js] @@ -18,3 +31,12 @@ function f2() { } } f2.apply(void 0, []); +f3(1); +f3(1, 2); +// Works for constructors too +var X = (function () { + function X(a) { + } + return X; +}()); +new X(1); diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols index dd9ce5319c9b3..b146d230bac4b 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols @@ -13,3 +13,29 @@ function f2(...args,) {} 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)) + +f3(1,); +>f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 6, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 9, 33)) + +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)) + diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types index 0a8d34d1df277..36de78fc8b892 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types @@ -18,3 +18,38 @@ f2(...[],); >...[] : undefined >[] : undefined[] +// Not confused by overloads +declare function f3(x, ): number; +>f3 : { (x: any): number; (x: any, y: any): string; } +>x : any + +declare function f3(x, y,): string; +>f3 : { (x: any): number; (x: any, y: any): string; } +>x : any +>y : any + +f3(1,); +>f3(1,) : number +>f3(1,) : number +>f3 : { (x: any): number; (x: any, y: any): string; } +>1 : number + +f3(1, 2,); +>f3(1, 2,) : string +>f3(1, 2,) : string +>f3 : { (x: any): number; (x: any, y: any): string; } +>1 : number +>2 : number + +// Works for constructors too +class X { +>X : X + + constructor(a,) { } +>a : any +} +new X(1,); +>new X(1,) : X +>X : typeof X +>1 : number + diff --git a/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts index 4b628e7e55961..9c21d7f24ea45 100644 --- a/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts +++ b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts @@ -5,3 +5,16 @@ f1(1,); function f2(...args,) {} f2(...[],); + +// Not confused by overloads +declare function f3(x, ): number; +declare function f3(x, y,): string; + +f3(1,); +f3(1, 2,); + +// Works for constructors too +class X { + constructor(a,) { } +} +new X(1,); From 693cb9c6ca6ad7adf5b05a91a213595c03ad7ff3 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 6 Jun 2016 13:20:32 -0700 Subject: [PATCH 4/5] Add additional tests --- ...nFunctionParametersAndArguments.errors.txt | 35 +++++++++++++++++++ ...gCommasInFunctionParametersAndArguments.js | 15 ++++++++ ...gCommasInFunctionParametersAndArguments.ts | 8 +++++ 3 files changed, 58 insertions(+) create mode 100644 tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.errors.txt diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.errors.txt b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.errors.txt new file mode 100644 index 0000000000000..02e44fa09762b --- /dev/null +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.errors.txt @@ -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; + + f3(1,); + 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,); + \ No newline at end of file diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js index 87c925fb22b5a..70e3e1ccf425f 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js @@ -17,7 +17,15 @@ declare function f3(x, y,): string; // 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,); @@ -37,6 +45,13 @@ f3(1, 2); 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); diff --git a/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts index 9c21d7f24ea45..5f48920e4dd88 100644 --- a/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts +++ b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts @@ -16,5 +16,13 @@ declare function f3(x, y,): string; // 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,); From ed48e58a387dcde1c259a6a9f0d4842c6322114c Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 7 Jun 2016 06:10:47 -0700 Subject: [PATCH 5/5] Fix test --- ...nFunctionParametersAndArguments.errors.txt | 35 --------------- ...gCommasInFunctionParametersAndArguments.js | 7 ++- ...asInFunctionParametersAndArguments.symbols | 44 +++++++++++++------ ...mmasInFunctionParametersAndArguments.types | 16 +++++++ .../trailingCommasInGetter.errors.txt | 10 +++++ .../reference/trailingCommasInGetter.js | 17 +++++++ ...gCommasInFunctionParametersAndArguments.ts | 5 ++- .../conformance/es7/trailingCommasInGetter.ts | 3 ++ 8 files changed, 82 insertions(+), 55 deletions(-) delete mode 100644 tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.errors.txt create mode 100644 tests/baselines/reference/trailingCommasInGetter.errors.txt create mode 100644 tests/baselines/reference/trailingCommasInGetter.js create mode 100644 tests/cases/conformance/es7/trailingCommasInGetter.ts diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.errors.txt b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.errors.txt deleted file mode 100644 index 02e44fa09762b..0000000000000 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.errors.txt +++ /dev/null @@ -1,35 +0,0 @@ -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; - - f3(1,); - 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,); - \ No newline at end of file diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js index 70e3e1ccf425f..6f30140c63ec1 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.js @@ -1,4 +1,5 @@ //// [trailingCommasInFunctionParametersAndArguments.ts] + function f1(x,) {} f1(1,); @@ -17,8 +18,7 @@ declare function f3(x, y,): string; // Works for constructors too class X { constructor(a,) { } - // *Not* allowed in getter - get x(,) { return 0; } + // See trailingCommasInGetter.ts set x(value,) { } } interface Y { @@ -46,8 +46,7 @@ var X = (function () { function X(a) { } Object.defineProperty(X.prototype, "x", { - // *Not* allowed in getter - get: function () { return 0; }, + // See trailingCommasInGetter.ts set: function (value) { }, enumerable: true, configurable: true diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols index b146d230bac4b..2ee58a747b72d 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.symbols @@ -1,41 +1,57 @@ === 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)) +>x : Symbol(x, Decl(trailingCommasInFunctionParametersAndArguments.ts, 1, 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 : Symbol(f2, Decl(trailingCommasInFunctionParametersAndArguments.ts, 3, 7)) +>args : Symbol(args, Decl(trailingCommasInFunctionParametersAndArguments.ts, 5, 12)) f2(...[],); ->f2 : Symbol(f2, Decl(trailingCommasInFunctionParametersAndArguments.ts, 2, 7)) +>f2 : Symbol(f2, Decl(trailingCommasInFunctionParametersAndArguments.ts, 3, 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)) +>f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 7, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 10, 33)) +>x : Symbol(x, Decl(trailingCommasInFunctionParametersAndArguments.ts, 10, 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)) +>f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 7, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 10, 33)) +>x : Symbol(x, Decl(trailingCommasInFunctionParametersAndArguments.ts, 11, 20)) +>y : Symbol(y, Decl(trailingCommasInFunctionParametersAndArguments.ts, 11, 22)) f3(1,); ->f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 6, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 9, 33)) +>f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 7, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 10, 33)) f3(1, 2,); ->f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 6, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 9, 33)) +>f3 : Symbol(f3, Decl(trailingCommasInFunctionParametersAndArguments.ts, 7, 11), Decl(trailingCommasInFunctionParametersAndArguments.ts, 10, 33)) // Works for constructors too class X { ->X : Symbol(X, Decl(trailingCommasInFunctionParametersAndArguments.ts, 13, 18)) +>X : Symbol(X, Decl(trailingCommasInFunctionParametersAndArguments.ts, 14, 18)) constructor(a,) { } ->a : Symbol(a, Decl(trailingCommasInFunctionParametersAndArguments.ts, 17, 16)) +>a : Symbol(a, Decl(trailingCommasInFunctionParametersAndArguments.ts, 18, 16)) + + // See trailingCommasInGetter.ts + set x(value,) { } +>x : Symbol(X.x, Decl(trailingCommasInFunctionParametersAndArguments.ts, 18, 23)) +>value : Symbol(value, Decl(trailingCommasInFunctionParametersAndArguments.ts, 20, 10)) } +interface Y { +>Y : Symbol(Y, Decl(trailingCommasInFunctionParametersAndArguments.ts, 21, 1)) + + new(x,); +>x : Symbol(x, Decl(trailingCommasInFunctionParametersAndArguments.ts, 23, 8)) + + (x,); +>x : Symbol(x, Decl(trailingCommasInFunctionParametersAndArguments.ts, 24, 5)) +} + new X(1,); ->X : Symbol(X, Decl(trailingCommasInFunctionParametersAndArguments.ts, 13, 18)) +>X : Symbol(X, Decl(trailingCommasInFunctionParametersAndArguments.ts, 14, 18)) diff --git a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types index 36de78fc8b892..9e2aa0abd8a63 100644 --- a/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types +++ b/tests/baselines/reference/trailingCommasInFunctionParametersAndArguments.types @@ -1,4 +1,5 @@ === tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts === + function f1(x,) {} >f1 : (x: any) => void >x : any @@ -47,7 +48,22 @@ class X { constructor(a,) { } >a : any + + // See trailingCommasInGetter.ts + set x(value,) { } +>x : any +>value : any } +interface Y { +>Y : Y + + new(x,); +>x : any + + (x,); +>x : any +} + new X(1,); >new X(1,) : X >X : typeof X diff --git a/tests/baselines/reference/trailingCommasInGetter.errors.txt b/tests/baselines/reference/trailingCommasInGetter.errors.txt new file mode 100644 index 0000000000000..c4c491a73b74b --- /dev/null +++ b/tests/baselines/reference/trailingCommasInGetter.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/es7/trailingCommasInGetter.ts(2,11): error TS1138: Parameter declaration expected. + + +==== tests/cases/conformance/es7/trailingCommasInGetter.ts (1 errors) ==== + class X { + get x(,) { return 0; } + ~ +!!! error TS1138: Parameter declaration expected. + } + \ No newline at end of file diff --git a/tests/baselines/reference/trailingCommasInGetter.js b/tests/baselines/reference/trailingCommasInGetter.js new file mode 100644 index 0000000000000..926545a8cbae6 --- /dev/null +++ b/tests/baselines/reference/trailingCommasInGetter.js @@ -0,0 +1,17 @@ +//// [trailingCommasInGetter.ts] +class X { + get x(,) { return 0; } +} + + +//// [trailingCommasInGetter.js] +var X = (function () { + function X() { + } + Object.defineProperty(X.prototype, "x", { + get: function () { return 0; }, + enumerable: true, + configurable: true + }); + return X; +}()); diff --git a/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts index 5f48920e4dd88..6b57235cbeb52 100644 --- a/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts +++ b/tests/cases/conformance/es7/trailingCommasInFunctionParametersAndArguments.ts @@ -1,3 +1,5 @@ +// @target: es5 + function f1(x,) {} f1(1,); @@ -16,8 +18,7 @@ declare function f3(x, y,): string; // Works for constructors too class X { constructor(a,) { } - // *Not* allowed in getter - get x(,) { return 0; } + // See trailingCommasInGetter.ts set x(value,) { } } interface Y { diff --git a/tests/cases/conformance/es7/trailingCommasInGetter.ts b/tests/cases/conformance/es7/trailingCommasInGetter.ts new file mode 100644 index 0000000000000..a1b2cf60b2cae --- /dev/null +++ b/tests/cases/conformance/es7/trailingCommasInGetter.ts @@ -0,0 +1,3 @@ +class X { + get x(,) { return 0; } +}