From 6b5330f3432bc35dfb19963bfdc3cc317e495fdd Mon Sep 17 00:00:00 2001 From: Vadi Taslim Date: Fri, 24 Mar 2017 12:39:36 +0800 Subject: [PATCH] Bug fix for issue #14696, things changed are; - Empty class type will now throw an error, - Trailing comma in class type will also throw an error, - Added tests for empty class type parameter, - Updated tests for class type parameters with trailing comma This behavior is consistently following function or method like when its type parameter is either empty or has trailing comma. --- src/compiler/checker.ts | 7 ++++++- .../reference/classWithEmptyTypeParameter.errors.txt | 8 ++++++++ .../baselines/reference/classWithEmptyTypeParameter.js | 10 ++++++++++ .../typeParameterListWithTrailingComma1.errors.txt | 8 ++++++++ tests/cases/compiler/classWithEmptyTypeParameter.ts | 2 ++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/classWithEmptyTypeParameter.errors.txt create mode 100644 tests/baselines/reference/classWithEmptyTypeParameter.js create mode 100644 tests/baselines/reference/typeParameterListWithTrailingComma1.errors.txt create mode 100644 tests/cases/compiler/classWithEmptyTypeParameter.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 70cbda14f6d..448a15e513b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19559,7 +19559,7 @@ namespace ts { } function checkClassLikeDeclaration(node: ClassLikeDeclaration) { - checkGrammarClassDeclarationHeritageClauses(node); + checkGrammarClassLikeDeclaration(node); checkDecorators(node); if (node.name) { checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); @@ -22520,6 +22520,11 @@ namespace ts { checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); } + function checkGrammarClassLikeDeclaration(node: ClassLikeDeclaration): boolean { + const file = getSourceFileOfNode(node); + return checkGrammarClassDeclarationHeritageClauses(node) || checkGrammarTypeParameterList(node.typeParameters, file); + } + function checkGrammarArrowFunction(node: FunctionLikeDeclaration, file: SourceFile): boolean { if (node.kind === SyntaxKind.ArrowFunction) { const arrowFunction = node; diff --git a/tests/baselines/reference/classWithEmptyTypeParameter.errors.txt b/tests/baselines/reference/classWithEmptyTypeParameter.errors.txt new file mode 100644 index 00000000000..8114bbd7ba0 --- /dev/null +++ b/tests/baselines/reference/classWithEmptyTypeParameter.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/classWithEmptyTypeParameter.ts(1,8): error TS1098: Type parameter list cannot be empty. + + +==== tests/cases/compiler/classWithEmptyTypeParameter.ts (1 errors) ==== + class C<> { + ~~ +!!! error TS1098: Type parameter list cannot be empty. + } \ No newline at end of file diff --git a/tests/baselines/reference/classWithEmptyTypeParameter.js b/tests/baselines/reference/classWithEmptyTypeParameter.js new file mode 100644 index 00000000000..c25ace495b4 --- /dev/null +++ b/tests/baselines/reference/classWithEmptyTypeParameter.js @@ -0,0 +1,10 @@ +//// [classWithEmptyTypeParameter.ts] +class C<> { +} + +//// [classWithEmptyTypeParameter.js] +var C = (function () { + function C() { + } + return C; +}()); diff --git a/tests/baselines/reference/typeParameterListWithTrailingComma1.errors.txt b/tests/baselines/reference/typeParameterListWithTrailingComma1.errors.txt new file mode 100644 index 00000000000..ac20e826969 --- /dev/null +++ b/tests/baselines/reference/typeParameterListWithTrailingComma1.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/typeParameterListWithTrailingComma1.ts(1,10): error TS1009: Trailing comma not allowed. + + +==== tests/cases/compiler/typeParameterListWithTrailingComma1.ts (1 errors) ==== + class C { + ~ +!!! error TS1009: Trailing comma not allowed. + } \ No newline at end of file diff --git a/tests/cases/compiler/classWithEmptyTypeParameter.ts b/tests/cases/compiler/classWithEmptyTypeParameter.ts new file mode 100644 index 00000000000..42541c8e467 --- /dev/null +++ b/tests/cases/compiler/classWithEmptyTypeParameter.ts @@ -0,0 +1,2 @@ +class C<> { +} \ No newline at end of file