mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Move grammar check: InterfaceDeclaration, HeritageClause
This commit is contained in:
@@ -8468,6 +8468,9 @@ module ts {
|
||||
}
|
||||
|
||||
function checkInterfaceDeclaration(node: InterfaceDeclaration) {
|
||||
// Grammar checking
|
||||
checkGrammarInterfaceDeclaration(node);
|
||||
|
||||
checkTypeParameters(node.typeParameters);
|
||||
if (fullTypeCheck) {
|
||||
checkTypeNameIsReserved(node.name, Diagnostics.Interface_name_cannot_be_0);
|
||||
@@ -10008,6 +10011,18 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarHeritageClause(node: HeritageClause): boolean {
|
||||
var types = node.types;
|
||||
if (checkGrammarForDisallowedTrailingComma(types)) {
|
||||
return true;
|
||||
}
|
||||
var listType = tokenToString(node.token);
|
||||
if (types && types.length === 0) {
|
||||
var sourceFile = getSourceFileOfNode(node);
|
||||
return grammarErrorAtPos(sourceFile, types.pos, 0, Diagnostics._0_list_cannot_be_empty, listType)
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarClassDeclarationHeritageClauses(node: ClassDeclaration) {
|
||||
var seenExtendsClause = false;
|
||||
var seenImplementsClause = false;
|
||||
@@ -10044,10 +10059,41 @@ module ts {
|
||||
|
||||
seenImplementsClause = true;
|
||||
}
|
||||
|
||||
// Grammar checking heritageClause inside class declaration
|
||||
checkGrammarHeritageClause(heritageClause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarInterfaceDeclaration(node: InterfaceDeclaration) {
|
||||
var seenExtendsClause = false;
|
||||
|
||||
if (node.heritageClauses) {
|
||||
for (var i = 0, n = node.heritageClauses.length; i < n; i++) {
|
||||
Debug.assert(i <= 1);
|
||||
var heritageClause = node.heritageClauses[i];
|
||||
|
||||
if (heritageClause.token === SyntaxKind.ExtendsKeyword) {
|
||||
if (seenExtendsClause) {
|
||||
return grammarErrorOnFirstToken(heritageClause, Diagnostics.extends_clause_already_seen);
|
||||
}
|
||||
|
||||
seenExtendsClause = true;
|
||||
}
|
||||
else {
|
||||
Debug.assert(heritageClause.token === SyntaxKind.ImplementsKeyword);
|
||||
return grammarErrorOnFirstToken(heritageClause, Diagnostics.Interface_declaration_cannot_have_implements_clause);
|
||||
}
|
||||
|
||||
// Grammar checking heritageClause inside class declaration
|
||||
checkGrammarHeritageClause(heritageClause);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
@@ -4649,8 +4649,8 @@ module ts {
|
||||
case SyntaxKind.FunctionDeclaration: return checkFunctionDeclaration(<FunctionLikeDeclaration>node);
|
||||
//case SyntaxKind.FunctionExpression: return checkFunctionExpression(<FunctionExpression>node);
|
||||
case SyntaxKind.GetAccessor: return checkGetAccessor(<MethodDeclaration>node);
|
||||
case SyntaxKind.HeritageClause: return checkHeritageClause(<HeritageClause>node);
|
||||
case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(<InterfaceDeclaration>node);
|
||||
//case SyntaxKind.HeritageClause: return checkHeritageClause(<HeritageClause>node);
|
||||
//case SyntaxKind.InterfaceDeclaration: return checkInterfaceDeclaration(<InterfaceDeclaration>node);
|
||||
case SyntaxKind.LabeledStatement: return checkLabeledStatement(<LabeledStatement>node);
|
||||
case SyntaxKind.PropertyAssignment: return checkPropertyAssignment(<PropertyAssignment>node);
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
|
||||
Reference in New Issue
Block a user