Move grammar check: InterfaceDeclaration, HeritageClause
This commit is contained in:
parent
5b98eba3d8
commit
3903a65062
7 changed files with 64 additions and 18 deletions
|
@ -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:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceThatInheritsFromItself.ts(10,15): error TS1176: Interface declaration cannot have 'implements' clause.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceThatInheritsFromItself.ts(1,11): error TS2310: Type 'Foo' recursively references itself as a base type.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceThatInheritsFromItself.ts(4,11): error TS2310: Type 'Foo2<T>' recursively references itself as a base type.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceThatInheritsFromItself.ts(7,11): error TS2310: Type 'Foo3<T>' recursively references itself as a base type.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceThatInheritsFromItself.ts(10,15): error TS1176: Interface declaration cannot have 'implements' clause.
|
||||
|
||||
|
||||
==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceThatInheritsFromItself.ts (4 errors) ====
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause2.ts(1,18): error TS1009: Trailing comma not allowed.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause2.ts(1,17): error TS2304: Cannot find name 'A'.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause2.ts(1,18): error TS1009: Trailing comma not allowed.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause2.ts (2 errors) ====
|
||||
class C extends A, {
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'A'.
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause4.ts(1,29): error TS1097: 'implements' list cannot be empty.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause4.ts(1,17): error TS2304: Cannot find name 'A'.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause4.ts(1,29): error TS1097: 'implements' list cannot be empty.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause4.ts (2 errors) ====
|
||||
class C extends A implements {
|
||||
|
||||
!!! error TS1097: 'implements' list cannot be empty.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'A'.
|
||||
|
||||
!!! error TS1097: 'implements' list cannot be empty.
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause5.ts(1,18): error TS1009: Trailing comma not allowed.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause5.ts(1,32): error TS1009: Trailing comma not allowed.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause5.ts(1,17): error TS2304: Cannot find name 'A'.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause5.ts(1,18): error TS1009: Trailing comma not allowed.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause5.ts(1,31): error TS2304: Cannot find name 'B'.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause5.ts(1,32): error TS1009: Trailing comma not allowed.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/ExtendsOrImplementsClauses/parserErrorRecovery_ExtendsOrImplementsClause5.ts (4 errors) ====
|
||||
class C extends A, implements B, {
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'A'.
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'B'.
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration1.ts(1,23): error TS1172: 'extends' clause already seen.
|
||||
tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration1.ts(1,21): error TS2304: Cannot find name 'A'.
|
||||
tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration1.ts(1,23): error TS1172: 'extends' clause already seen.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration1.ts (2 errors) ====
|
||||
interface I extends A extends B {
|
||||
~~~~~~~
|
||||
!!! error TS1172: 'extends' clause already seen.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'A'.
|
||||
~~~~~~~
|
||||
!!! error TS1172: 'extends' clause already seen.
|
||||
}
|
Loading…
Reference in a new issue