Parser changes to parse omitted types correctly

This commit is contained in:
Jason Freeman
2014-10-02 11:24:11 -07:00
parent 09f0755dc1
commit 08f9a0148a

View File

@@ -1078,7 +1078,7 @@ module ts {
return isParameter();
case ParsingContext.TypeArguments:
case ParsingContext.TupleElementTypes:
return isType();
return token === SyntaxKind.CommaToken || isType();
}
Debug.fail("Non-exhaustive case in 'isListElement'.");
@@ -2344,13 +2344,24 @@ module ts {
function parseTypeArguments(): NodeArray<TypeNode> {
var typeArgumentListStart = scanner.getTokenPos();
var errorCountBeforeTypeParameterList = file.syntacticErrors.length;
var result = parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken);
var result = parseBracketedList(ParsingContext.TypeArguments, parseSingleTypeArgument, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken);
if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) {
grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, Diagnostics.Type_argument_list_cannot_be_empty);
}
return result;
}
function parseSingleTypeArgument(): TypeNode {
if (token === SyntaxKind.CommaToken) {
var errorStart = scanner.getTokenPos();
var errorLength = scanner.getTextPos() - errorStart;
grammarErrorAtPos(errorStart, errorLength, Diagnostics.Type_expected);
return createNode(SyntaxKind.OmittedType);
}
return parseType();
}
function parsePrimaryExpression(): Expression {
switch (token) {
case SyntaxKind.ThisKeyword: