Skip to content

Commit

Permalink
Bug fix for issue microsoft#14696, things changed are;
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
chozzz committed Mar 24, 2017
1 parent a9d8df2 commit 6b5330f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = <ArrowFunction>node;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
}
10 changes: 10 additions & 0 deletions tests/baselines/reference/classWithEmptyTypeParameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [classWithEmptyTypeParameter.ts]
class C<> {
}

//// [classWithEmptyTypeParameter.js]
var C = (function () {
function C() {
}
return C;
}());
Original file line number Diff line number Diff line change
@@ -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<T,> {
~
!!! error TS1009: Trailing comma not allowed.
}
2 changes: 2 additions & 0 deletions tests/cases/compiler/classWithEmptyTypeParameter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class C<> {
}

0 comments on commit 6b5330f

Please sign in to comment.