From b75b0d7fa6a010c008862708c230cba5ec702311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Mon, 5 Mar 2018 18:17:16 +0800 Subject: [PATCH] allow trailing comman in type arguments list --- src/compiler/checker.ts | 3 +-- .../allowTrailingCommasInTypeArguments.js | 17 +++++++++++++ ...allowTrailingCommasInTypeArguments.symbols | 24 ++++++++++++++++++ .../allowTrailingCommasInTypeArguments.types | 25 +++++++++++++++++++ .../reference/syntaxErrors.errors.txt | 5 +--- .../allowTrailingCommasInTypeArguments.ts | 7 ++++++ 6 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/allowTrailingCommasInTypeArguments.js create mode 100644 tests/baselines/reference/allowTrailingCommasInTypeArguments.symbols create mode 100644 tests/baselines/reference/allowTrailingCommasInTypeArguments.types create mode 100644 tests/cases/compiler/allowTrailingCommasInTypeArguments.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2c4999e516fd7..e4331b2b531ee 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27027,8 +27027,7 @@ namespace ts { } function checkGrammarTypeArguments(node: Node, typeArguments: NodeArray): boolean { - return checkGrammarForDisallowedTrailingComma(typeArguments) || - checkGrammarForAtLeastOneTypeArgument(node, typeArguments); + return checkGrammarForAtLeastOneTypeArgument(node, typeArguments); } function checkGrammarForOmittedArgument(args: NodeArray): boolean { diff --git a/tests/baselines/reference/allowTrailingCommasInTypeArguments.js b/tests/baselines/reference/allowTrailingCommasInTypeArguments.js new file mode 100644 index 0000000000000..5c3b845db47bd --- /dev/null +++ b/tests/baselines/reference/allowTrailingCommasInTypeArguments.js @@ -0,0 +1,17 @@ +//// [allowTrailingCommasInTypeArguments.ts] +class FooClass { + a: A; + b: B; + c: C; +} + +var a = new FooClass(); + + +//// [allowTrailingCommasInTypeArguments.js] +var FooClass = /** @class */ (function () { + function FooClass() { + } + return FooClass; +}()); +var a = new FooClass(); diff --git a/tests/baselines/reference/allowTrailingCommasInTypeArguments.symbols b/tests/baselines/reference/allowTrailingCommasInTypeArguments.symbols new file mode 100644 index 0000000000000..acc5884057d90 --- /dev/null +++ b/tests/baselines/reference/allowTrailingCommasInTypeArguments.symbols @@ -0,0 +1,24 @@ +=== tests/cases/compiler/allowTrailingCommasInTypeArguments.ts === +class FooClass { +>FooClass : Symbol(FooClass, Decl(allowTrailingCommasInTypeArguments.ts, 0, 0)) +>A : Symbol(A, Decl(allowTrailingCommasInTypeArguments.ts, 0, 15)) +>B : Symbol(B, Decl(allowTrailingCommasInTypeArguments.ts, 0, 17)) +>C : Symbol(C, Decl(allowTrailingCommasInTypeArguments.ts, 0, 20)) + + a: A; +>a : Symbol(FooClass.a, Decl(allowTrailingCommasInTypeArguments.ts, 0, 26)) +>A : Symbol(A, Decl(allowTrailingCommasInTypeArguments.ts, 0, 15)) + + b: B; +>b : Symbol(FooClass.b, Decl(allowTrailingCommasInTypeArguments.ts, 1, 6)) +>B : Symbol(B, Decl(allowTrailingCommasInTypeArguments.ts, 0, 17)) + + c: C; +>c : Symbol(FooClass.c, Decl(allowTrailingCommasInTypeArguments.ts, 2, 6)) +>C : Symbol(C, Decl(allowTrailingCommasInTypeArguments.ts, 0, 20)) +} + +var a = new FooClass(); +>a : Symbol(a, Decl(allowTrailingCommasInTypeArguments.ts, 6, 3)) +>FooClass : Symbol(FooClass, Decl(allowTrailingCommasInTypeArguments.ts, 0, 0)) + diff --git a/tests/baselines/reference/allowTrailingCommasInTypeArguments.types b/tests/baselines/reference/allowTrailingCommasInTypeArguments.types new file mode 100644 index 0000000000000..8b9ecff6ac859 --- /dev/null +++ b/tests/baselines/reference/allowTrailingCommasInTypeArguments.types @@ -0,0 +1,25 @@ +=== tests/cases/compiler/allowTrailingCommasInTypeArguments.ts === +class FooClass { +>FooClass : FooClass +>A : A +>B : B +>C : C + + a: A; +>a : A +>A : A + + b: B; +>b : B +>B : B + + c: C; +>c : C +>C : C +} + +var a = new FooClass(); +>a : FooClass +>new FooClass() : FooClass +>FooClass : typeof FooClass + diff --git a/tests/baselines/reference/syntaxErrors.errors.txt b/tests/baselines/reference/syntaxErrors.errors.txt index 25276af3956e5..ebb7ba25acd82 100644 --- a/tests/baselines/reference/syntaxErrors.errors.txt +++ b/tests/baselines/reference/syntaxErrors.errors.txt @@ -1,17 +1,14 @@ tests/cases/conformance/jsdoc/badTypeArguments.js(1,15): error TS1099: Type argument list cannot be empty. -tests/cases/conformance/jsdoc/badTypeArguments.js(2,22): error TS1009: Trailing comma not allowed. ==== tests/cases/conformance/jsdoc/dummyType.d.ts (0 errors) ==== declare class C { t: T } -==== tests/cases/conformance/jsdoc/badTypeArguments.js (2 errors) ==== +==== tests/cases/conformance/jsdoc/badTypeArguments.js (1 errors) ==== /** @param {C.<>} x */ ~~ !!! error TS1099: Type argument list cannot be empty. /** @param {C.} y */ - ~ -!!! error TS1009: Trailing comma not allowed. // @ts-ignore /** @param {C.} skipped */ function f(x, y, skipped) { diff --git a/tests/cases/compiler/allowTrailingCommasInTypeArguments.ts b/tests/cases/compiler/allowTrailingCommasInTypeArguments.ts new file mode 100644 index 0000000000000..691992e84993a --- /dev/null +++ b/tests/cases/compiler/allowTrailingCommasInTypeArguments.ts @@ -0,0 +1,7 @@ +class FooClass { + a: A; + b: B; + c: C; +} + +var a = new FooClass();