Move indexer modifier checks to the grammar checker.
This commit is contained in:
parent
7716535511
commit
6b866e719e
3 changed files with 21 additions and 15 deletions
|
@ -1541,8 +1541,12 @@ module ts {
|
||||||
return finishNode(node);
|
return finishNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseIndexSignatureMember(): SignatureDeclaration {
|
function parseIndexSignatureMember(flags: NodeFlags, pos?: number): SignatureDeclaration {
|
||||||
var node = <SignatureDeclaration>createNode(SyntaxKind.IndexSignature);
|
var node = <SignatureDeclaration>createNode(SyntaxKind.IndexSignature, pos);
|
||||||
|
if (flags) {
|
||||||
|
node.flags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
node.parameters = parseParameterList(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken);
|
node.parameters = parseParameterList(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken);
|
||||||
node.type = parseTypeAnnotation();
|
node.type = parseTypeAnnotation();
|
||||||
parseSemicolon();
|
parseSemicolon();
|
||||||
|
@ -1588,7 +1592,7 @@ module ts {
|
||||||
case SyntaxKind.LessThanToken:
|
case SyntaxKind.LessThanToken:
|
||||||
return parseSignatureMember(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
return parseSignatureMember(SyntaxKind.CallSignature, SyntaxKind.ColonToken);
|
||||||
case SyntaxKind.OpenBracketToken:
|
case SyntaxKind.OpenBracketToken:
|
||||||
return parseIndexSignatureMember();
|
return parseIndexSignatureMember(/*flags:*/ 0);
|
||||||
case SyntaxKind.NewKeyword:
|
case SyntaxKind.NewKeyword:
|
||||||
if (lookAhead(() => nextToken() === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken)) {
|
if (lookAhead(() => nextToken() === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken)) {
|
||||||
return parseSignatureMember(SyntaxKind.ConstructSignature, SyntaxKind.ColonToken);
|
return parseSignatureMember(SyntaxKind.ConstructSignature, SyntaxKind.ColonToken);
|
||||||
|
@ -3238,12 +3242,7 @@ module ts {
|
||||||
return parsePropertyMemberDeclaration(pos, flags);
|
return parsePropertyMemberDeclaration(pos, flags);
|
||||||
}
|
}
|
||||||
if (token === SyntaxKind.OpenBracketToken) {
|
if (token === SyntaxKind.OpenBracketToken) {
|
||||||
if (flags) {
|
return parseIndexSignatureMember(flags, pos);
|
||||||
var start = getTokenPos(pos);
|
|
||||||
var length = getNodePos() - start;
|
|
||||||
errorAtPos(start, length, Diagnostics.Modifiers_not_permitted_on_index_signature_members);
|
|
||||||
}
|
|
||||||
return parseIndexSignatureMember();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 'isClassMemberStart' should have hinted not to attempt parsing.
|
// 'isClassMemberStart' should have hinted not to attempt parsing.
|
||||||
|
@ -4137,7 +4136,14 @@ module ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
function visitIndexSignature(node: SignatureDeclaration): void {
|
function visitIndexSignature(node: SignatureDeclaration): void {
|
||||||
checkIndexSignatureParameters(node);
|
checkIndexSignatureParameters(node) ||
|
||||||
|
checkForIndexSignatureModifiers(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkForIndexSignatureModifiers(node: SignatureDeclaration): boolean {
|
||||||
|
if (node.flags & NodeFlags.Modifier) {
|
||||||
|
return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_not_permitted_on_index_signature_members);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkIndexSignatureParameters(node: SignatureDeclaration): boolean {
|
function checkIndexSignatureParameters(node: SignatureDeclaration): boolean {
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,4): error TS1145: Modifiers not permitted on index signature members.
|
|
||||||
tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,11): error TS1030: 'static' modifier already seen.
|
tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts(2,11): error TS1030: 'static' modifier already seen.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (2 errors) ====
|
==== tests/cases/conformance/parser/ecmascript5/IndexMemberDeclarations/parserIndexMemberDeclaration10.ts (1 errors) ====
|
||||||
class C {
|
class C {
|
||||||
static static [x: string]: string;
|
static static [x: string]: string;
|
||||||
~~~~~~~~~~~~~
|
|
||||||
!!! error TS1145: Modifiers not permitted on index signature members.
|
|
||||||
~~~~~~
|
~~~~~~
|
||||||
!!! error TS1030: 'static' modifier already seen.
|
!!! error TS1030: 'static' modifier already seen.
|
||||||
}
|
}
|
|
@ -1,9 +1,10 @@
|
||||||
tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(4,5): error TS1145: Modifiers not permitted on index signature members.
|
tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(4,5): error TS1145: Modifiers not permitted on index signature members.
|
||||||
tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(8,5): error TS1145: Modifiers not permitted on index signature members.
|
tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(8,5): error TS1145: Modifiers not permitted on index signature members.
|
||||||
tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,5): error TS1145: Modifiers not permitted on index signature members.
|
tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,5): error TS1145: Modifiers not permitted on index signature members.
|
||||||
|
tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,25): error TS2302: Static members cannot reference class type parameters.
|
||||||
|
|
||||||
|
|
||||||
==== tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts (3 errors) ====
|
==== tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts (4 errors) ====
|
||||||
// static indexers not allowed
|
// static indexers not allowed
|
||||||
|
|
||||||
class C {
|
class C {
|
||||||
|
@ -22,4 +23,6 @@ tests/cases/conformance/classes/indexMemberDeclarations/staticIndexers.ts(12,5):
|
||||||
static [x: string]: T;
|
static [x: string]: T;
|
||||||
~~~~~~
|
~~~~~~
|
||||||
!!! error TS1145: Modifiers not permitted on index signature members.
|
!!! error TS1145: Modifiers not permitted on index signature members.
|
||||||
|
~
|
||||||
|
!!! error TS2302: Static members cannot reference class type parameters.
|
||||||
}
|
}
|
Loading…
Reference in a new issue