Address code review; check class heritage clause into its own function
This commit is contained in:
parent
56cf566f89
commit
5b98eba3d8
1 changed files with 41 additions and 37 deletions
|
@ -8263,43 +8263,7 @@ module ts {
|
|||
|
||||
function checkClassDeclaration(node: ClassDeclaration) {
|
||||
// Grammar checking
|
||||
var seenExtendsClause = false;
|
||||
var seenImplementsClause = false;
|
||||
|
||||
if (!checkGrammarModifiers(node) && node.heritageClauses) {
|
||||
for (var i = 0, n = node.heritageClauses.length; i < n; i++) {
|
||||
Debug.assert(i <= 2);
|
||||
var heritageClause = node.heritageClauses[i];
|
||||
|
||||
if (heritageClause.token === SyntaxKind.ExtendsKeyword) {
|
||||
if (seenExtendsClause) {
|
||||
grammarErrorOnFirstToken(heritageClause, Diagnostics.extends_clause_already_seen)
|
||||
break;
|
||||
}
|
||||
|
||||
if (seenImplementsClause) {
|
||||
grammarErrorOnFirstToken(heritageClause, Diagnostics.extends_clause_must_precede_implements_clause);
|
||||
break;
|
||||
}
|
||||
|
||||
if (heritageClause.types.length > 1) {
|
||||
grammarErrorOnFirstToken(heritageClause.types[1], Diagnostics.Classes_can_only_extend_a_single_class);
|
||||
break;
|
||||
}
|
||||
|
||||
seenExtendsClause = true;
|
||||
}
|
||||
else {
|
||||
Debug.assert(heritageClause.token === SyntaxKind.ImplementsKeyword);
|
||||
if (seenImplementsClause) {
|
||||
grammarErrorOnFirstToken(heritageClause, Diagnostics.implements_clause_already_seen);
|
||||
break;
|
||||
}
|
||||
|
||||
seenImplementsClause = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
checkGrammarClassDeclarationHeritageClauses(node);
|
||||
|
||||
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0);
|
||||
checkTypeParameters(node.typeParameters);
|
||||
|
@ -10044,6 +10008,46 @@ module ts {
|
|||
}
|
||||
}
|
||||
|
||||
function checkGrammarClassDeclarationHeritageClauses(node: ClassDeclaration) {
|
||||
var seenExtendsClause = false;
|
||||
var seenImplementsClause = false;
|
||||
|
||||
if (!checkGrammarModifiers(node) && node.heritageClauses) {
|
||||
for (var i = 0, n = node.heritageClauses.length; i < n; i++) {
|
||||
Debug.assert(i <= 2);
|
||||
var heritageClause = node.heritageClauses[i];
|
||||
|
||||
if (heritageClause.token === SyntaxKind.ExtendsKeyword) {
|
||||
if (seenExtendsClause) {
|
||||
grammarErrorOnFirstToken(heritageClause, Diagnostics.extends_clause_already_seen)
|
||||
break;
|
||||
}
|
||||
|
||||
if (seenImplementsClause) {
|
||||
grammarErrorOnFirstToken(heritageClause, Diagnostics.extends_clause_must_precede_implements_clause);
|
||||
break;
|
||||
}
|
||||
|
||||
if (heritageClause.types.length > 1) {
|
||||
grammarErrorOnFirstToken(heritageClause.types[1], Diagnostics.Classes_can_only_extend_a_single_class);
|
||||
break;
|
||||
}
|
||||
|
||||
seenExtendsClause = true;
|
||||
}
|
||||
else {
|
||||
Debug.assert(heritageClause.token === SyntaxKind.ImplementsKeyword);
|
||||
if (seenImplementsClause) {
|
||||
grammarErrorOnFirstToken(heritageClause, Diagnostics.implements_clause_already_seen);
|
||||
break;
|
||||
}
|
||||
|
||||
seenImplementsClause = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarComputedPropertyName(node: ComputedPropertyName): void {
|
||||
// Since computed properties are not supported in the type checker, disallow them in TypeScript 1.4
|
||||
// Once full support is added, remove this error.
|
||||
|
|
Loading…
Reference in a new issue