Simplify how type members are represented in the tree.

Conflicts:
	src/services/syntax/SyntaxGenerator.js.map
This commit is contained in:
Cyrus Najmabadi
2014-11-28 14:38:57 -08:00
parent aaaa078199
commit 749501e8bf
9 changed files with 121 additions and 107 deletions
+8 -6
View File
@@ -1196,7 +1196,7 @@ var definitions = [
interfaces: ['ITypeSyntax'],
children: [
{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
{ name: 'typeMembers', isSeparatedList: true, elementType: 'ITypeMemberSyntax' },
{ name: 'typeMembers', isList: true, elementType: 'ITypeMemberSyntax' },
{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
],
isTypeScriptSpecific: true
@@ -1422,7 +1422,8 @@ var definitions = [
{ name: 'openBracketToken', isToken: true },
{ name: 'parameters', isSeparatedList: true, elementType: 'ParameterSyntax' },
{ name: 'closeBracketToken', isToken: true },
{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true }
{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true },
{ name: 'semicolonOrCommaToken', isToken: true, isOptional: true }
],
isTypeScriptSpecific: true
},
@@ -1433,7 +1434,8 @@ var definitions = [
children: [
{ name: 'propertyName', type: 'IPropertyNameSyntax' },
{ name: 'questionToken', isToken: true, isOptional: true },
{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true }
{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true },
{ name: 'semicolonOrCommaToken', isToken: true, isOptional: true }
],
isTypeScriptSpecific: true
},
@@ -1444,7 +1446,8 @@ var definitions = [
children: [
{ name: 'typeParameterList', type: 'TypeParameterListSyntax', isOptional: true, isTypeScriptSpecific: true },
{ name: 'parameterList', type: 'ParameterListSyntax' },
{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true, isTypeScriptSpecific: true }
{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true, isTypeScriptSpecific: true },
{ name: 'semicolonOrCommaToken', isToken: true, isOptional: true }
]
},
{
@@ -1581,8 +1584,7 @@ var definitions = [
interfaces: ['IClassElementSyntax'],
children: [
{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
{ name: 'indexSignature', type: 'IndexSignatureSyntax' },
{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
{ name: 'indexSignature', type: 'IndexSignatureSyntax' }
],
isTypeScriptSpecific: true
},
File diff suppressed because one or more lines are too long
+44 -53
View File
@@ -1269,14 +1269,14 @@ module TypeScript.Parser {
function parseGetAccessor(modifiers: ISyntaxToken[], getKeyword: ISyntaxToken): GetAccessorSyntax {
return new GetAccessorSyntax(contextFlags,
modifiers, consumeToken(getKeyword), parsePropertyName(),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
parseCallSignatureWithoutSemicolonOrComma(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
parseFunctionBody(/*isGenerator:*/ false, /*asyncContext:*/ false));
}
function parseSetAccessor(modifiers: ISyntaxToken[], setKeyword: ISyntaxToken): SetAccessorSyntax {
return new SetAccessorSyntax(contextFlags,
modifiers, consumeToken(setKeyword), parsePropertyName(),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
parseCallSignatureWithoutSemicolonOrComma(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
parseFunctionBody(/*isGenerator:*/ false, /*asyncContext:*/ false));
}
@@ -1401,7 +1401,7 @@ module TypeScript.Parser {
return new ConstructorDeclarationSyntax(contextFlags,
modifiers,
eatToken(SyntaxKind.ConstructorKeyword),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
parseCallSignatureWithoutSemicolonOrComma(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false),
parseFunctionBody(/*isGenerator:*/ false, /*asyncContext:*/ false));
}
@@ -1415,7 +1415,7 @@ module TypeScript.Parser {
modifiers,
asteriskToken,
propertyName,
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, /*asyncContext:*/ asyncContext),
parseCallSignatureWithoutSemicolonOrComma(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, /*asyncContext:*/ asyncContext),
parseFunctionBody(isGenerator, asyncContext));
}
@@ -1445,8 +1445,7 @@ module TypeScript.Parser {
function parseIndexMemberDeclaration(modifiers: ISyntaxToken[]): IndexMemberDeclarationSyntax {
return new IndexMemberDeclarationSyntax(contextFlags,
modifiers,
parseIndexSignature(),
eatExplicitOrAutomaticSemicolon(/*allowWithoutNewLine:*/ false));
parseIndexSignature());
}
function isFunctionDeclaration(modifierCount: number): boolean {
@@ -1471,7 +1470,7 @@ module TypeScript.Parser {
functionKeyword,
asteriskToken,
eatIdentifierToken(),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, /*asyncContext:*/ asyncContext),
parseCallSignatureWithoutSemicolonOrComma(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ isGenerator, /*asyncContext:*/ asyncContext),
parseFunctionBody(isGenerator, asyncContext));
}
@@ -1523,7 +1522,7 @@ module TypeScript.Parser {
return new ObjectTypeSyntax(contextFlags,
openBraceToken = eatToken(SyntaxKind.OpenBraceToken),
openBraceToken.fullWidth() > 0 ? parseSeparatedSyntaxList<ITypeMemberSyntax>(ListParsingState.ObjectType_TypeMembers) : [],
openBraceToken.fullWidth() > 0 ? parseSyntaxList<ITypeMemberSyntax>(ListParsingState.ObjectType_TypeMembers) : [],
eatToken(SyntaxKind.CloseBraceToken));
}
@@ -1585,7 +1584,10 @@ module TypeScript.Parser {
// A call signature for a type member can both use 'yield' as a parameter name, and
// does not have parameter initializers. So we can pass 'false' for both [Yield]
// and [GeneratorParameter].
return parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false);
//
// Also, when this is a call signature used as a type member, then a semicolon is
// required.
return parseCallSignatureWithSemicolonOrComma(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false);
}
else if (isConstructSignature()) {
return parseConstructSignature();
@@ -1613,14 +1615,16 @@ module TypeScript.Parser {
// Construct signatures have no [Yield] or [GeneratorParameter] restrictions.
return new ConstructSignatureSyntax(contextFlags,
eatToken(SyntaxKind.NewKeyword),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false));
parseCallSignatureWithSemicolonOrComma(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false));
}
function parseIndexSignature(): IndexSignatureSyntax {
return new IndexSignatureSyntax(contextFlags,
eatToken(SyntaxKind.OpenBracketToken),
parseSeparatedSyntaxList<ParameterSyntax>(ListParsingState.IndexSignature_Parameters),
eatToken(SyntaxKind.CloseBracketToken), parseOptionalTypeAnnotation(/*allowStringLiteral:*/ false));
eatToken(SyntaxKind.CloseBracketToken),
parseOptionalTypeAnnotation(/*allowStringLiteral:*/ false),
eatExplicitOrAutomaticSemicolonOrComma());
}
function parseMethodSignature(propertyName: IPropertyNameSyntax, questionToken: ISyntaxToken): MethodSignatureSyntax {
@@ -1629,12 +1633,15 @@ module TypeScript.Parser {
return new MethodSignatureSyntax(contextFlags,
propertyName,
questionToken,
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false));
parseCallSignatureWithSemicolonOrComma(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ false, /*asyncContext:*/ false));
}
function parsePropertySignature(propertyName: IPropertyNameSyntax, questionToken: ISyntaxToken): PropertySignatureSyntax {
return new PropertySignatureSyntax(contextFlags,
propertyName, questionToken, parseOptionalTypeAnnotation(/*allowStringLiteral:*/ false));
propertyName,
questionToken,
parseOptionalTypeAnnotation(/*allowStringLiteral:*/ false),
eatExplicitOrAutomaticSemicolonOrComma());
}
function isCallSignature(peekIndex: number): boolean {
@@ -3250,7 +3257,7 @@ module TypeScript.Parser {
eatToken(SyntaxKind.FunctionKeyword),
asteriskToken = tryEatToken(SyntaxKind.AsteriskToken),
tryEatFunctionExpressionIdentifier(!!asteriskToken, !!asyncKeyword),
parseCallSignature(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, /*asyncContext:*/ !!asyncKeyword),
parseCallSignatureWithoutSemicolonOrComma(/*requireCompleteTypeParameterList:*/ false, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, /*asyncContext:*/ !!asyncKeyword),
parseFunctionBody(!!asteriskToken, !!asyncKeyword));
}
@@ -3386,7 +3393,7 @@ module TypeScript.Parser {
// 2.If the [Yield] grammar parameter is not present for CoverParenthesizedExpressionAndArrowParameterList[Yield]
// return the result of parsing the lexical token stream matched by CoverParenthesizedExpressionAndArrowParameterList
// using ArrowFormalParameters as the goal symbol.
var callSignature = parseCallSignature(/*requireCompleteTypeParameterList:*/ true, /*yieldAndGeneratorParameterContext:*/ inYieldContext(), /*asyncContext:*/ !!asyncKeyword);
var callSignature = parseCallSignatureWithoutSemicolonOrComma(/*requireCompleteTypeParameterList:*/ true, /*yieldAndGeneratorParameterContext:*/ inYieldContext(), /*asyncContext:*/ !!asyncKeyword);
if (requireArrow && currentToken().kind !== SyntaxKind.EqualsGreaterThanToken) {
return undefined;
@@ -3874,11 +3881,29 @@ module TypeScript.Parser {
return statements;
}
function parseCallSignature(requireCompleteTypeParameterList: boolean, yieldAndGeneratorParameterContext: boolean, asyncContext: boolean): CallSignatureSyntax {
function parseCallSignatureWithoutSemicolonOrComma(requireCompleteTypeParameterList: boolean, yieldAndGeneratorParameterContext: boolean, asyncContext: boolean): CallSignatureSyntax {
return parseCallSignatureWorker(requireCompleteTypeParameterList, yieldAndGeneratorParameterContext, asyncContext, /*withSemicolon:*/ false);
}
function parseCallSignatureWithSemicolonOrComma(requireCompleteTypeParameterList: boolean, yieldAndGeneratorParameterContext: boolean, asyncContext: boolean): CallSignatureSyntax {
return parseCallSignatureWorker(requireCompleteTypeParameterList, yieldAndGeneratorParameterContext, asyncContext, /*withSemicolon:*/ true);
}
function parseCallSignatureWorker(requireCompleteTypeParameterList: boolean, yieldAndGeneratorParameterContext: boolean, asyncContext: boolean, withSemicolonOrComma: boolean): CallSignatureSyntax {
return new CallSignatureSyntax(contextFlags,
tryParseTypeParameterList(requireCompleteTypeParameterList),
parseParameterList(yieldAndGeneratorParameterContext, asyncContext),
parseOptionalTypeAnnotation(/*allowStringLiteral:*/ false));
parseOptionalTypeAnnotation(/*allowStringLiteral:*/ false),
withSemicolonOrComma ? eatExplicitOrAutomaticSemicolonOrComma() : undefined);
}
function eatExplicitOrAutomaticSemicolonOrComma() {
var _currentToken = currentToken();
if (_currentToken.kind === SyntaxKind.CommaToken) {
return consumeToken(_currentToken);
}
return eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false);
}
function tryParseTypeParameterList(requireCompleteTypeParameterList: boolean): TypeParameterListSyntax {
@@ -4411,17 +4436,6 @@ module TypeScript.Parser {
function parseSeparatedSyntaxListWorker<T extends ISyntaxNodeOrToken>(currentListType: ListParsingState): ISeparatedSyntaxList<T> {
var nodesAndSeparators: ISyntaxNodeOrToken[] = [];
// Debug.assert(nodes.length === 0);
// Debug.assert(separators.length === 0);
// Debug.assert(skippedTokens.length === 0);
// Debug.assert(<any>skippedTokens !== nodes);
// Debug.assert(skippedTokens !== separators);
// Debug.assert(<any>nodes !== separators);
var _separatorKind = currentListType === ListParsingState.ObjectType_TypeMembers ? SyntaxKind.SemicolonToken : SyntaxKind.CommaToken;
var allowAutomaticSemicolonInsertion = _separatorKind === SyntaxKind.SemicolonToken;
var inErrorRecovery = false;
while (true) {
// Try to parse an item of the list. If we fail then decide if we need to abort or
@@ -4465,8 +4479,7 @@ module TypeScript.Parser {
// allow 'comma' as a separator (for error tolerance). We will later do a post pass
// to report when a comma was used improperly in a list that needed semicolons.
var _currentToken = currentToken();
var tokenKind = _currentToken.kind;
if (tokenKind === _separatorKind || tokenKind === SyntaxKind.CommaToken) {
if (_currentToken.kind === SyntaxKind.CommaToken) {
// Consume the last separator and continue parsing list elements.
nodesAndSeparators.push(consumeToken(_currentToken));
continue;
@@ -4479,34 +4492,12 @@ module TypeScript.Parser {
break;
}
// Otherwise, it might be a case where we can parse out an implicit semicolon.
// Note: it's important that we check this *after* the check above for
// 'listIsTerminated'. Consider the following case:
//
// {
// a // <-- just finished parsing 'a'
// }
//
// Automatic semicolon insertion rules state: "When, as the program is parsed from
// left to right, a token (called the offending token) is encountered that is not
// allowed by any production of the grammar". So we should only ever insert a
// semicolon if we couldn't consume something normally. in the above case, we can
// consume the '}' just fine. So ASI doesn't apply.
if (allowAutomaticSemicolonInsertion && canEatAutomaticSemicolon(/*allowWithoutNewline:*/ false)) {
var semicolonToken = eatExplicitOrAutomaticSemicolon(/*allowWithoutNewline:*/ false) || createEmptyToken(SyntaxKind.SemicolonToken);
nodesAndSeparators.push(semicolonToken);
// Debug.assert(items.length % 2 === 0);
continue;
}
// We weren't at the end of the list. And thre was no separator we could parse out.
// Try parse the separator we expected, and continue parsing more list elements.
// This time mark that we're in error recovery mode though.
//
// Note: trying to eat this token will emit the appropriate diagnostic.
nodesAndSeparators.push(eatToken(_separatorKind));
nodesAndSeparators.push(eatToken(SyntaxKind.CommaToken));
// Now that we're in 'error recovery' mode we cantweak some parsing rules as
// appropriate. For example, if we have:
+3 -1
View File
@@ -604,12 +604,14 @@ module TypeScript.PrettyPrinter {
this.appendSeparatorSpaceList(node.parameters)
this.appendToken(node.closeBracketToken);
this.appendNode(node.typeAnnotation);
this.appendToken(node.semicolonOrCommaToken);
}
public visitPropertySignature(node: PropertySignatureSyntax): void {
visitNodeOrToken(this, node.propertyName);
this.appendToken(node.questionToken);
this.appendNode(node.typeAnnotation);
this.appendToken(node.semicolonOrCommaToken);
}
public visitParameterList(node: ParameterListSyntax): void {
@@ -622,6 +624,7 @@ module TypeScript.PrettyPrinter {
this.appendNode(node.typeParameterList);
visitNodeOrToken(this, node.parameterList);
this.appendNode(node.typeAnnotation);
this.appendToken(node.semicolonOrCommaToken);
}
public visitTypeParameterList(node: TypeParameterListSyntax): void {
@@ -693,7 +696,6 @@ module TypeScript.PrettyPrinter {
this.appendSpaceList(node.modifiers);
this.ensureSpace();
visitNodeOrToken(this, node.indexSignature);
this.appendToken(node.semicolonToken);
}
public visitMemberFunctionDeclaration(node: MemberFunctionDeclarationSyntax): void {
+8 -6
View File
@@ -334,7 +334,7 @@ var definitions:ITypeDefinition[] = [
interfaces: ['ITypeSyntax'],
children: [
<any>{ name: 'openBraceToken', isToken: true, excludeFromAST: true },
<any>{ name: 'typeMembers', isSeparatedList: true, elementType: 'ITypeMemberSyntax' },
<any>{ name: 'typeMembers', isList: true, elementType: 'ITypeMemberSyntax' },
<any>{ name: 'closeBraceToken', isToken: true, excludeFromAST: true }
],
isTypeScriptSpecific: true
@@ -560,7 +560,8 @@ var definitions:ITypeDefinition[] = [
<any>{ name: 'openBracketToken', isToken: true },
<any>{ name: 'parameters', isSeparatedList: true, elementType: 'ParameterSyntax' },
<any>{ name: 'closeBracketToken', isToken: true },
<any>{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true }
<any>{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true },
<any>{ name: 'semicolonOrCommaToken', isToken: true, isOptional: true }
],
isTypeScriptSpecific: true
},
@@ -571,7 +572,8 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'propertyName', type: 'IPropertyNameSyntax' },
<any>{ name: 'questionToken', isToken: true, isOptional: true },
<any>{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true }
<any>{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true },
<any>{ name: 'semicolonOrCommaToken', isToken: true, isOptional: true }
],
isTypeScriptSpecific: true
},
@@ -582,7 +584,8 @@ var definitions:ITypeDefinition[] = [
children: [
<any>{ name: 'typeParameterList', type: 'TypeParameterListSyntax', isOptional: true, isTypeScriptSpecific: true },
<any>{ name: 'parameterList', type: 'ParameterListSyntax' },
<any>{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true, isTypeScriptSpecific: true }
<any>{ name: 'typeAnnotation', type: 'TypeAnnotationSyntax', isOptional: true, isTypeScriptSpecific: true },
<any>{ name: 'semicolonOrCommaToken', isToken: true, isOptional: true }
]
},
<any>{
@@ -720,8 +723,7 @@ var definitions:ITypeDefinition[] = [
interfaces: ['IClassElementSyntax'],
children: [
<any>{ name: 'modifiers', isList: true, elementType: 'ISyntaxToken' },
<any>{ name: 'indexSignature', type: 'IndexSignatureSyntax' },
<any>{ name: 'semicolonToken', isToken: true, isOptional: true, excludeFromAST: true }
<any>{ name: 'indexSignature', type: 'IndexSignatureSyntax' }
],
isTypeScriptSpecific: true
},
@@ -17,10 +17,10 @@ module TypeScript {
export interface ObjectTypeSyntax extends ISyntaxNode, ITypeSyntax {
openBraceToken: ISyntaxToken;
typeMembers: ISeparatedSyntaxList<ITypeMemberSyntax>;
typeMembers: ITypeMemberSyntax[];
closeBraceToken: ISyntaxToken;
}
export interface ObjectTypeConstructor { new (data: number, openBraceToken: ISyntaxToken, typeMembers: ISeparatedSyntaxList<ITypeMemberSyntax>, closeBraceToken: ISyntaxToken): ObjectTypeSyntax }
export interface ObjectTypeConstructor { new (data: number, openBraceToken: ISyntaxToken, typeMembers: ITypeMemberSyntax[], closeBraceToken: ISyntaxToken): ObjectTypeSyntax }
export interface FunctionTypeSyntax extends ISyntaxNode, ITypeSyntax {
typeParameterList: TypeParameterListSyntax;
@@ -177,9 +177,8 @@ module TypeScript {
export interface IndexMemberDeclarationSyntax extends ISyntaxNode, IClassElementSyntax {
modifiers: ISyntaxToken[];
indexSignature: IndexSignatureSyntax;
semicolonToken: ISyntaxToken;
}
export interface IndexMemberDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], indexSignature: IndexSignatureSyntax, semicolonToken: ISyntaxToken): IndexMemberDeclarationSyntax }
export interface IndexMemberDeclarationConstructor { new (data: number, modifiers: ISyntaxToken[], indexSignature: IndexSignatureSyntax): IndexMemberDeclarationSyntax }
export interface GetAccessorSyntax extends ISyntaxNode, IAccessorSyntax {
modifiers: ISyntaxToken[];
@@ -203,15 +202,17 @@ module TypeScript {
propertyName: IPropertyNameSyntax;
questionToken: ISyntaxToken;
typeAnnotation: TypeAnnotationSyntax;
semicolonOrCommaToken: ISyntaxToken;
}
export interface PropertySignatureConstructor { new (data: number, propertyName: IPropertyNameSyntax, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax): PropertySignatureSyntax }
export interface PropertySignatureConstructor { new (data: number, propertyName: IPropertyNameSyntax, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, semicolonOrCommaToken: ISyntaxToken): PropertySignatureSyntax }
export interface CallSignatureSyntax extends ISyntaxNode, ITypeMemberSyntax {
typeParameterList: TypeParameterListSyntax;
parameterList: ParameterListSyntax;
typeAnnotation: TypeAnnotationSyntax;
semicolonOrCommaToken: ISyntaxToken;
}
export interface CallSignatureConstructor { new (data: number, typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax): CallSignatureSyntax }
export interface CallSignatureConstructor { new (data: number, typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax, semicolonOrCommaToken: ISyntaxToken): CallSignatureSyntax }
export interface ConstructSignatureSyntax extends ISyntaxNode, ITypeMemberSyntax {
newKeyword: ISyntaxToken;
@@ -224,8 +225,9 @@ module TypeScript {
parameters: ISeparatedSyntaxList<ParameterSyntax>;
closeBracketToken: ISyntaxToken;
typeAnnotation: TypeAnnotationSyntax;
semicolonOrCommaToken: ISyntaxToken;
}
export interface IndexSignatureConstructor { new (data: number, openBracketToken: ISyntaxToken, parameters: ISeparatedSyntaxList<ParameterSyntax>, closeBracketToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax): IndexSignatureSyntax }
export interface IndexSignatureConstructor { new (data: number, openBracketToken: ISyntaxToken, parameters: ISeparatedSyntaxList<ParameterSyntax>, closeBracketToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, semicolonOrCommaToken: ISyntaxToken): IndexSignatureSyntax }
export interface MethodSignatureSyntax extends ISyntaxNode, ITypeMemberSyntax {
propertyName: IPropertyNameSyntax;
@@ -36,7 +36,7 @@ module TypeScript {
}
}
export var ObjectTypeSyntax: ObjectTypeConstructor = <any>function(data: number, openBraceToken: ISyntaxToken, typeMembers: ISeparatedSyntaxList<ITypeMemberSyntax>, closeBraceToken: ISyntaxToken) {
export var ObjectTypeSyntax: ObjectTypeConstructor = <any>function(data: number, openBraceToken: ISyntaxToken, typeMembers: ITypeMemberSyntax[], closeBraceToken: ISyntaxToken) {
if (data) { this.__data = data; }
this.openBraceToken = openBraceToken,
this.typeMembers = typeMembers,
@@ -475,22 +475,19 @@ module TypeScript {
}
}
export var IndexMemberDeclarationSyntax: IndexMemberDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], indexSignature: IndexSignatureSyntax, semicolonToken: ISyntaxToken) {
export var IndexMemberDeclarationSyntax: IndexMemberDeclarationConstructor = <any>function(data: number, modifiers: ISyntaxToken[], indexSignature: IndexSignatureSyntax) {
if (data) { this.__data = data; }
this.modifiers = modifiers,
this.indexSignature = indexSignature,
this.semicolonToken = semicolonToken,
modifiers.parent = this,
indexSignature.parent = this,
semicolonToken && (semicolonToken.parent = this);
indexSignature.parent = this;
};
IndexMemberDeclarationSyntax.prototype.kind = SyntaxKind.IndexMemberDeclaration;
IndexMemberDeclarationSyntax.prototype.childCount = 3;
IndexMemberDeclarationSyntax.prototype.childCount = 2;
IndexMemberDeclarationSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.modifiers;
case 1: return this.indexSignature;
case 2: return this.semicolonToken;
}
}
@@ -544,41 +541,47 @@ module TypeScript {
}
}
export var PropertySignatureSyntax: PropertySignatureConstructor = <any>function(data: number, propertyName: IPropertyNameSyntax, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax) {
export var PropertySignatureSyntax: PropertySignatureConstructor = <any>function(data: number, propertyName: IPropertyNameSyntax, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, semicolonOrCommaToken: ISyntaxToken) {
if (data) { this.__data = data; }
this.propertyName = propertyName,
this.questionToken = questionToken,
this.typeAnnotation = typeAnnotation,
this.semicolonOrCommaToken = semicolonOrCommaToken,
propertyName.parent = this,
questionToken && (questionToken.parent = this),
typeAnnotation && (typeAnnotation.parent = this);
typeAnnotation && (typeAnnotation.parent = this),
semicolonOrCommaToken && (semicolonOrCommaToken.parent = this);
};
PropertySignatureSyntax.prototype.kind = SyntaxKind.PropertySignature;
PropertySignatureSyntax.prototype.childCount = 3;
PropertySignatureSyntax.prototype.childCount = 4;
PropertySignatureSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.propertyName;
case 1: return this.questionToken;
case 2: return this.typeAnnotation;
case 3: return this.semicolonOrCommaToken;
}
}
export var CallSignatureSyntax: CallSignatureConstructor = <any>function(data: number, typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax) {
export var CallSignatureSyntax: CallSignatureConstructor = <any>function(data: number, typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax, semicolonOrCommaToken: ISyntaxToken) {
if (data) { this.__data = data; }
this.typeParameterList = typeParameterList,
this.parameterList = parameterList,
this.typeAnnotation = typeAnnotation,
this.semicolonOrCommaToken = semicolonOrCommaToken,
typeParameterList && (typeParameterList.parent = this),
parameterList.parent = this,
typeAnnotation && (typeAnnotation.parent = this);
typeAnnotation && (typeAnnotation.parent = this),
semicolonOrCommaToken && (semicolonOrCommaToken.parent = this);
};
CallSignatureSyntax.prototype.kind = SyntaxKind.CallSignature;
CallSignatureSyntax.prototype.childCount = 3;
CallSignatureSyntax.prototype.childCount = 4;
CallSignatureSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.typeParameterList;
case 1: return this.parameterList;
case 2: return this.typeAnnotation;
case 3: return this.semicolonOrCommaToken;
}
}
@@ -598,25 +601,28 @@ module TypeScript {
}
}
export var IndexSignatureSyntax: IndexSignatureConstructor = <any>function(data: number, openBracketToken: ISyntaxToken, parameters: ISeparatedSyntaxList<ParameterSyntax>, closeBracketToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax) {
export var IndexSignatureSyntax: IndexSignatureConstructor = <any>function(data: number, openBracketToken: ISyntaxToken, parameters: ISeparatedSyntaxList<ParameterSyntax>, closeBracketToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, semicolonOrCommaToken: ISyntaxToken) {
if (data) { this.__data = data; }
this.openBracketToken = openBracketToken,
this.parameters = parameters,
this.closeBracketToken = closeBracketToken,
this.typeAnnotation = typeAnnotation,
this.semicolonOrCommaToken = semicolonOrCommaToken,
openBracketToken.parent = this,
parameters.parent = this,
closeBracketToken.parent = this,
typeAnnotation && (typeAnnotation.parent = this);
typeAnnotation && (typeAnnotation.parent = this),
semicolonOrCommaToken && (semicolonOrCommaToken.parent = this);
};
IndexSignatureSyntax.prototype.kind = SyntaxKind.IndexSignature;
IndexSignatureSyntax.prototype.childCount = 4;
IndexSignatureSyntax.prototype.childCount = 5;
IndexSignatureSyntax.prototype.childAt = function(index: number): ISyntaxElement {
switch (index) {
case 0: return this.openBracketToken;
case 1: return this.parameters;
case 2: return this.closeBracketToken;
case 3: return this.typeAnnotation;
case 4: return this.semicolonOrCommaToken;
}
}
+20 -17
View File
@@ -147,6 +147,14 @@ module TypeScript {
return true;
}
public visitCallSignature(node: CallSignatureSyntax): void {
if (this.checkForCommaInsteadOfSemicolon(node.semicolonOrCommaToken)) {
return;
}
super.visitCallSignature(node);
}
public visitCatchClause(node: CatchClauseSyntax): void {
if (this.checkForCatchClauseTypeAnnotation(node) ||
this.checkForDisallowedEvalOrArguments(node, node.identifier)) {
@@ -351,8 +359,17 @@ module TypeScript {
return false;
}
private checkForCommaInsteadOfSemicolon(commaOrSemicolon: ISyntaxToken) {
if (commaOrSemicolon && commaOrSemicolon.kind === SyntaxKind.CommaToken) {
return this.pushDiagnostic(commaOrSemicolon, DiagnosticCode._0_expected, [SyntaxFacts.getText(SyntaxKind.SemicolonToken)]);
}
return false;
}
public visitIndexSignature(node: IndexSignatureSyntax): void {
if (this.checkIndexSignatureParameter(node)) {
if (this.checkIndexSignatureParameter(node) ||
this.checkForCommaInsteadOfSemicolon(node.semicolonOrCommaToken)) {
return;
}
@@ -553,7 +570,8 @@ module TypeScript {
public visitPropertySignature(node: PropertySignatureSyntax): void {
if (this.checkForDisallowedTemplatePropertyName(node.propertyName) ||
this.checkForDisallowedComputedPropertyName(node.propertyName)) {
this.checkForDisallowedComputedPropertyName(node.propertyName) ||
this.checkForCommaInsteadOfSemicolon(node.semicolonOrCommaToken)) {
return;
}
@@ -1486,22 +1504,7 @@ module TypeScript {
this.inAmbientDeclaration = savedInAmbientDeclaration;
}
private checkListSeparators<T extends ISyntaxNodeOrToken>(list: ISeparatedSyntaxList<T>, kind: SyntaxKind): boolean {
for (var i = 0, n = separatorCount(list); i < n; i++) {
var child = separatorAt(list, i);
if (child.kind !== kind) {
this.pushDiagnostic(child, DiagnosticCode._0_expected, [SyntaxFacts.getText(kind)]);
}
}
return false;
}
public visitObjectType(node: ObjectTypeSyntax): void {
if (this.checkListSeparators(node.typeMembers, SyntaxKind.SemicolonToken)) {
return;
}
// All code in an object type is implicitly ambient. (i.e. parameters can't have initializer, etc.)
var savedInAmbientDeclaration = this.inAmbientDeclaration;
this.inAmbientDeclaration = true;
@@ -173,7 +173,6 @@ module TypeScript {
public visitIndexMemberDeclaration(node: IndexMemberDeclarationSyntax): void {
this.visitList(node.modifiers);
visitNodeOrToken(this, node.indexSignature);
this.visitOptionalToken(node.semicolonToken);
}
public visitGetAccessor(node: GetAccessorSyntax): void {
@@ -196,12 +195,14 @@ module TypeScript {
visitNodeOrToken(this, node.propertyName);
this.visitOptionalToken(node.questionToken);
visitNodeOrToken(this, node.typeAnnotation);
this.visitOptionalToken(node.semicolonOrCommaToken);
}
public visitCallSignature(node: CallSignatureSyntax): void {
visitNodeOrToken(this, node.typeParameterList);
visitNodeOrToken(this, node.parameterList);
visitNodeOrToken(this, node.typeAnnotation);
this.visitOptionalToken(node.semicolonOrCommaToken);
}
public visitConstructSignature(node: ConstructSignatureSyntax): void {
@@ -214,6 +215,7 @@ module TypeScript {
this.visitList(node.parameters);
this.visitToken(node.closeBracketToken);
visitNodeOrToken(this, node.typeAnnotation);
this.visitOptionalToken(node.semicolonOrCommaToken);
}
public visitMethodSignature(node: MethodSignatureSyntax): void {