Add a lot of clarifying comments in the parser.

Simplify parser and avoid the need to pass around 'inNewExpression' information.

Make error span smaller for "new Foo[]" errors.
This commit is contained in:
Cyrus Najmabadi 2014-11-29 14:51:25 -08:00
parent 6a4927cef7
commit 13f319b6ec
21 changed files with 277 additions and 162 deletions

View File

@ -1151,12 +1151,18 @@ module ts {
return inStrictModeContext() ? token > SyntaxKind.LastFutureReservedWord : token > SyntaxKind.LastReservedWord;
}
function parseExpected(t: SyntaxKind): boolean {
function parseExpected(t: SyntaxKind, diagnosticMessage?: DiagnosticMessage): boolean {
if (token === t) {
nextToken();
return true;
}
error(Diagnostics._0_expected, tokenToString(t));
if (diagnosticMessage) {
error(diagnosticMessage);
}
else {
error(Diagnostics._0_expected, tokenToString(t));
}
return false;
}
@ -1551,12 +1557,21 @@ module ts {
return entity;
}
function parseTokenNode(): Node {
function parseAnyTokenNode(): Node {
var node = createNode(token);
nextToken();
return finishNode(node);
}
function parseTokenNode(kind: SyntaxKind): Node {
if (token === kind) {
return parseAnyTokenNode();
}
parseExpected(kind);
return createMissingNode();
}
function parseTemplateExpression() {
var template = <TemplateExpression>createNode(SyntaxKind.TemplateExpression);
@ -1997,7 +2012,7 @@ module ts {
}
function parseKeywordAndNoDot(): Node {
var node = parseTokenNode();
var node = parseAnyTokenNode();
return token === SyntaxKind.DotToken ? undefined : node;
}
@ -2649,30 +2664,133 @@ module ts {
return finishNode(node);
case SyntaxKind.LessThanToken:
return parseTypeAssertion();
default:
return parsePostfixExpressionOrHigher();
}
}
var primaryExpression = parsePrimaryExpression();
// TS 1.0 spec (2014): 4.8
// CallExpression: ( Modified )
// super ( ArgumentListopt )
// super . IdentifierName
var illegalUsageOfSuperKeyword =
primaryExpression.kind === SyntaxKind.SuperKeyword && token !== SyntaxKind.OpenParenToken && token !== SyntaxKind.DotToken;
function parsePostfixExpressionOrHigher(): Expression {
var expression = parseLeftHandSideExpressionOrHigher();
if (illegalUsageOfSuperKeyword) {
error(Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
}
var expr = parseCallAndAccess(primaryExpression, /* inNewExpression */ false);
Debug.assert(isLeftHandSideExpression(expr));
Debug.assert(isLeftHandSideExpression(expression));
if ((token === SyntaxKind.PlusPlusToken || token === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) {
var operator = token;
nextToken();
expr = makeUnaryExpression(SyntaxKind.PostfixOperator, expr.pos, operator, expr);
return makeUnaryExpression(SyntaxKind.PostfixOperator, expression.pos, operator, expression);
}
return expr;
return expression;
}
function parseLeftHandSideExpressionOrHigher(): Expression {
// Original Ecma:
// LeftHandSideExpression: See 11.2
// NewExpression
// CallExpression
//
// Our simplification:
//
// LeftHandSideExpression: See 11.2
// MemberExpression
// CallExpression
//
// See comment in parseMemberExpressionOrHigher on how we replaced NewExpression with
// MemberExpression to make our lives easier.
//
// to best understand the below code, it's important to see how CallExpression expands
// out into its own productions:
//
// CallExpression:
// MemberExpression Arguments
// CallExpression Arguments
// CallExpression[Expression]
// CallExpression.IdentifierName
// super ( ArgumentListopt )
// super.IdentifierName
//
// Because of the recursion in these calls, we need to bottom out first. There are two
// bottom out states we can run into. Either we see 'super' which must start either of
// the last two CallExpression productions. Or we have a MemberExpression which either
// completes the LeftHandSideExpression, or starts the beginning of the first four
// CallExpression productions.
var expression: Expression;
if (token === SyntaxKind.SuperKeyword) {
expression = parseSuperExpression();
}
else {
expression = parseMemberExpressionOrHigher();
}
// Now, we *may* be complete. However, we might have consumed the start of a
// CallExpression. As such, we need to consume the rest of it here to be complete.
return parseCallExpressionRest(expression);
}
function parseMemberExpressionOrHigher(): Expression {
// Note: to make our lives simpler, we decompose the the NewExpression productions and
// place ObjectCreationExpression and FunctionExpression into PrimaryExpression.
// like so:
//
// PrimaryExpression : See 11.1
// this
// Identifier
// Literal
// ArrayLiteral
// ObjectLiteral
// (Expression)
// FunctionExpression
// new MemberExpression Arguments?
//
// MemberExpression : See 11.2
// PrimaryExpression
// MemberExpression[Expression]
// MemberExpression.IdentifierName
//
// CallExpression : See 11.2
// MemberExpression
// CallExpression Arguments
// CallExpression[Expression]
// CallExpression.IdentifierName
//
// Technically this is ambiguous. i.e. CallExpression defines:
//
// CallExpression:
// CallExpression Arguments
//
// If you see: "new Foo()"
//
// Then that could be treated as a single ObjectCreationExpression, or it could be
// treated as the invocation of "new Foo". We disambiguate that in code (to match
// the original grammar) by making sure that if we see an ObjectCreationExpression
// we always consume arguments if they are there. So we treat "new Foo()" as an
// object creation only, and not at all as an invocation) Another way to think
// about this is that for every "new" that we see, we will consume an argument list if
// it is there as part of the *associated* object creation node. Any additional
// argument lists we see, will become invocation expressions.
//
// Because there are no other places in the grammar now that refer to FunctionExpression
// or ObjectCreationExpression, it is safe to push down into the PrimaryExpression
// production.
//
// Because CallExpression and MemberExpression are left recursive, we need to bottom out
// of the recursion immediately. So we parse out a primary expression to start with.
var expression = parsePrimaryExpression();
return parseMemberExpressionRest(expression);
}
function parseSuperExpression(): Expression {
var expression = parseAnyTokenNode();
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.DotToken) {
return expression;
}
// If we have seen "super" it must be followed by '(' or '.'.
// If it wasn't then just try to parse out a '.' and report an error.
var node = <PropertyAccess>createNode(SyntaxKind.PropertyAccess, expression.pos);
node.left = expression;
parseExpected(SyntaxKind.DotToken, Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access);
node.right = parseIdentifierName();
return finishNode(node);
}
function parseTypeAssertion(): TypeAssertion {
@ -2691,11 +2809,11 @@ module ts {
return finishNode(node);
}
function parseCallAndAccess(expr: Expression, inNewExpression: boolean): Expression {
function parseMemberExpressionRest(expression: Expression): Expression {
while (true) {
var dotOrBracketStart = scanner.getTokenPos();
if (parseOptional(SyntaxKind.DotToken)) {
var propertyAccess = <PropertyAccess>createNode(SyntaxKind.PropertyAccess, expr.pos);
var propertyAccess = <PropertyAccess>createNode(SyntaxKind.PropertyAccess, expression.pos);
// Technically a keyword is valid here as all keywords are identifier names.
// However, often we'll encounter this in error situations when the keyword
// is actually starting another valid construct.
@ -2728,63 +2846,80 @@ module ts {
}
}
propertyAccess.left = expr;
propertyAccess.left = expression;
propertyAccess.right = id || parseIdentifierName();
expr = finishNode(propertyAccess);
expression = finishNode(propertyAccess);
continue;
}
if (parseOptional(SyntaxKind.OpenBracketToken)) {
var indexedAccess = <IndexedAccess>createNode(SyntaxKind.IndexedAccess, expr.pos);
indexedAccess.object = expr;
if (token === SyntaxKind.OpenBracketToken) {
var indexedAccess = <IndexedAccess>createNode(SyntaxKind.IndexedAccess, expression.pos);
indexedAccess.object = expression;
indexedAccess.openBracketToken = parseTokenNode(SyntaxKind.OpenBracketToken);
// It's not uncommon for a user to write: "new Type[]".
// Check for that common pattern and report a better error message.
if (inNewExpression && parseOptional(SyntaxKind.CloseBracketToken)) {
indexedAccess.index = createMissingNode();
}
else {
if (token !== SyntaxKind.CloseBracketToken) {
indexedAccess.index = allowInAnd(parseExpression);
if (indexedAccess.index.kind === SyntaxKind.StringLiteral || indexedAccess.index.kind === SyntaxKind.NumericLiteral) {
var literal = <LiteralExpression>indexedAccess.index;
literal.text = internIdentifier(literal.text);
}
parseExpected(SyntaxKind.CloseBracketToken);
}
expr = finishNode(indexedAccess);
continue;
}
// Try to parse a Call Expression unless we are in a New Expression.
// If we are parsing a New Expression, then parentheses are optional,
// and is taken care of by the 'parseNewExpression' caller.
if ((token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) && !inNewExpression) {
var callExpr = <CallExpression>createNode(SyntaxKind.CallExpression, expr.pos);
callExpr.func = expr;
if (token === SyntaxKind.LessThanToken) {
if (!(callExpr.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) return expr;
}
else {
parseExpected(SyntaxKind.OpenParenToken);
indexedAccess.index = createMissingNode();
}
callExpr.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions, parseArgumentExpression);
parseExpected(SyntaxKind.CloseParenToken);
expr = finishNode(callExpr);
indexedAccess.closeBracketToken = parseTokenNode(SyntaxKind.CloseBracketToken);
expression = finishNode(indexedAccess);
continue;
}
if (token === SyntaxKind.NoSubstitutionTemplateLiteral || token === SyntaxKind.TemplateHead) {
var tagExpression = <TaggedTemplateExpression>createNode(SyntaxKind.TaggedTemplateExpression, expr.pos);
tagExpression.tag = expr;
var tagExpression = <TaggedTemplateExpression>createNode(SyntaxKind.TaggedTemplateExpression, expression.pos);
tagExpression.tag = expression;
tagExpression.template = token === SyntaxKind.NoSubstitutionTemplateLiteral
? parseLiteralNode()
: parseTemplateExpression();
expr = finishNode(tagExpression);
? parseLiteralNode()
: parseTemplateExpression();
expression = finishNode(tagExpression);
continue;
}
return expr;
return expression;
}
}
function parseCallExpressionRest(expression: Expression): Expression {
while (true) {
expression = parseMemberExpressionRest(expression);
if (token === SyntaxKind.LessThanToken) {
// Might be arithmetic, or it might be a type argument list.
var typeArguments = tryParse(parseTypeArgumentsAndOpenParen);
if (!typeArguments) {
return expression;
}
var callExpr = <CallExpression>createNode(SyntaxKind.CallExpression, expression.pos);
callExpr.func = expression;
callExpr.typeArguments = typeArguments;
callExpr.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions, parseArgumentExpression);
parseExpected(SyntaxKind.CloseParenToken);
expression = finishNode(callExpr);
continue;
}
if (token === SyntaxKind.OpenParenToken) {
var callExpr = <CallExpression>createNode(SyntaxKind.CallExpression, expression.pos);
callExpr.func = expression;
parseExpected(SyntaxKind.OpenParenToken);
callExpr.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions, parseArgumentExpression);
parseExpected(SyntaxKind.CloseParenToken);
expression = finishNode(callExpr);
continue;
}
return expression;
}
}
@ -2822,7 +2957,7 @@ module ts {
case SyntaxKind.NullKeyword:
case SyntaxKind.TrueKeyword:
case SyntaxKind.FalseKeyword:
return parseTokenNode();
return parseAnyTokenNode();
case SyntaxKind.NumericLiteral:
case SyntaxKind.StringLiteral:
case SyntaxKind.NoSubstitutionTemplateLiteral:
@ -2988,8 +3123,8 @@ module ts {
function parseNewExpression(): NewExpression {
var node = <NewExpression>createNode(SyntaxKind.NewExpression);
parseExpected(SyntaxKind.NewKeyword);
node.func = parseCallAndAccess(parsePrimaryExpression(), /* inNewExpression */ true);
if (parseOptional(SyntaxKind.OpenParenToken) || token === SyntaxKind.LessThanToken && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) {
node.func = parseMemberExpressionOrHigher();
if (parseOptional(SyntaxKind.OpenParenToken) || (token === SyntaxKind.LessThanToken && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen)))) {
node.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions, parseArgumentExpression);
parseExpected(SyntaxKind.CloseParenToken);
}
@ -4498,13 +4633,17 @@ module ts {
}
function checkIndexedAccess(node: IndexedAccess) {
if (node.index.kind === SyntaxKind.Missing &&
node.parent.kind === SyntaxKind.NewExpression &&
(<NewExpression>node.parent).func === node) {
if (node.index.kind === SyntaxKind.Missing) {
if (node.parent.kind === SyntaxKind.NewExpression &&
(<NewExpression>node.parent).func === node) {
var start = skipTrivia(sourceText, node.parent.pos);
var end = node.end;
return grammarErrorAtPos(start, end - start, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
var start = skipTrivia(sourceText, node.openBracketToken.pos);
var end = node.closeBracketToken.end;
return grammarErrorAtPos(start, end - start, Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
}
else {
return grammarErrorOnNode(node.closeBracketToken, Diagnostics.Expression_expected);
}
}
}

View File

@ -514,7 +514,9 @@ module ts {
export interface IndexedAccess extends Expression {
object: Expression;
openBracketToken: Node;
index: Expression;
closeBracketToken: Node;
}
export interface CallExpression extends Expression {

View File

@ -20,9 +20,6 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(3
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(42,30): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(44,13): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(46,21): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(54,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(57,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(58,1): error TS2364: Invalid left-hand side of assignment expression.
@ -40,7 +37,7 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(6
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: Invalid left-hand side of assignment expression.
==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (40 errors) ====
==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (37 errors) ====
// expected error for all the LHS of assignments
var value;
@ -119,20 +116,14 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7
constructor() { super(); super = value; }
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~
!!! error TS2364: Invalid left-hand side of assignment expression.
foo() { super = value }
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~
!!! error TS2364: Invalid left-hand side of assignment expression.
static sfoo() { super = value; }
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~
!!! error TS2364: Invalid left-hand side of assignment expression.
}
// function expression

View File

@ -1,8 +1,8 @@
tests/cases/compiler/badArraySyntax.ts(6,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/badArraySyntax.ts(7,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/badArraySyntax.ts(8,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/badArraySyntax.ts(9,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/badArraySyntax.ts(10,17): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/badArraySyntax.ts(6,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/badArraySyntax.ts(7,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/badArraySyntax.ts(8,20): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/badArraySyntax.ts(9,20): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/badArraySyntax.ts(10,40): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
==== tests/cases/compiler/badArraySyntax.ts (5 errors) ====
@ -12,18 +12,18 @@ tests/cases/compiler/badArraySyntax.ts(10,17): error TS1150: 'new T[]' cannot be
var a1: Z[] = [];
var a2 = new Z[];
~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
var a3 = new Z[]();
~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
var a4: Z[] = new Z[];
~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
var a5: Z[] = new Z[]();
~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
var a6: Z[][] = new Z [ ] [ ];
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.

View File

@ -1,4 +1,4 @@
tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,9): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,21): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,15): error TS2339: Property 'ClassA' does not exist on type 'typeof M'.
@ -8,7 +8,7 @@ tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,15): error TS2339: Pr
class ClassA {}
}
var t = new M.ClassA[];
~~~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~~~
!!! error TS2339: Property 'ClassA' does not exist on type 'typeof M'.

View File

@ -42,12 +42,6 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(55,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(62,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(63,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(69,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(70,9): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(74,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(75,9): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(79,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(80,9): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(91,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(92,1): error TS2364: Invalid left-hand side of assignment expression.
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(95,1): error TS2364: Invalid left-hand side of assignment expression.
@ -80,7 +74,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(122,1): error TS2364: Invalid left-hand side of assignment expression.
==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (80 errors) ====
==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (74 errors) ====
// expected error for all the LHS of compound assignments (arithmetic and addition)
var value;
@ -220,39 +214,27 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa
super *= value;
~~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
super += value;
~~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~
!!! error TS2364: Invalid left-hand side of assignment expression.
}
foo() {
super *= value;
~~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
super += value;
~~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~
!!! error TS2364: Invalid left-hand side of assignment expression.
}
static sfoo() {
super *= value;
~~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
super += value;
~~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~
!!! error TS2364: Invalid left-hand side of assignment expression.
}
}

View File

@ -42,7 +42,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,9): error TS
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,27): error TS1135: Argument expression expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,33): error TS1005: '(' expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,43): error TS1109: Expression expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,59): error TS1109: Expression expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,60): error TS1005: ';' expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1129: Statement expected.
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS1129: Statement expected.
@ -88,7 +87,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error T
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'.
==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (88 errors) ====
==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (87 errors) ====
declare module "fs" {
export class File {
constructor(filename: string);
@ -498,8 +497,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T
~
!!! error TS1005: '(' expected.
~~~
!!! error TS1109: Expression expected.
~
!!! error TS1109: Expression expected.
~
!!! error TS1005: ';' expected.

View File

@ -1,7 +1,7 @@
tests/cases/compiler/createArray.ts(1,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/createArray.ts(6,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/createArray.ts(7,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/createArray.ts(8,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/createArray.ts(1,18): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/createArray.ts(6,6): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/createArray.ts(7,19): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/createArray.ts(8,18): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/createArray.ts(1,12): error TS2304: Cannot find name 'number'.
tests/cases/compiler/createArray.ts(7,12): error TS2304: Cannot find name 'boolean'.
tests/cases/compiler/createArray.ts(8,12): error TS2304: Cannot find name 'string'.
@ -9,7 +9,7 @@ tests/cases/compiler/createArray.ts(8,12): error TS2304: Cannot find name 'strin
==== tests/cases/compiler/createArray.ts (7 errors) ====
var na=new number[];
~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~~~
!!! error TS2304: Cannot find name 'number'.
@ -18,15 +18,15 @@ tests/cases/compiler/createArray.ts(8,12): error TS2304: Cannot find name 'strin
}
new C[];
~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
var ba=new boolean[];
~~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~~~~
!!! error TS2304: Cannot find name 'boolean'.
var sa=new string[];
~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~~~
!!! error TS2304: Cannot find name 'string'.

View File

@ -1,4 +1,4 @@
tests/cases/compiler/libMembers.ts(9,11): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/libMembers.ts(9,16): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/libMembers.ts(4,3): error TS2339: Property 'subby' does not exist on type 'string'.
tests/cases/compiler/libMembers.ts(12,15): error TS2339: Property 'prototype' does not exist on type 'C'.
@ -15,7 +15,7 @@ tests/cases/compiler/libMembers.ts(12,15): error TS2339: Property 'prototype' do
export class C {
}
var a=new C[];
~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
a.length;
a.push(new C());

View File

@ -1,5 +1,5 @@
tests/cases/compiler/newOperator.ts(18,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/newOperator.ts(20,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/newOperator.ts(18,20): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/newOperator.ts(22,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/compiler/newOperator.ts(44,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/newOperator.ts(3,13): error TS2304: Cannot find name 'ifc'.
tests/cases/compiler/newOperator.ts(10,10): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
@ -38,16 +38,14 @@ tests/cases/compiler/newOperator.ts(31,10): error TS2351: Cannot use 'new' with
// Various spacing
var t3 = new string[]( );
~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~~~
!!! error TS2304: Cannot find name 'string'.
var t4 =
new
~~~
string
~~~~~~
~~~~~~
!!! error TS2304: Cannot find name 'string'.
[
~

View File

@ -1,8 +1,7 @@
tests/cases/compiler/objectLitArrayDeclNoNew.ts(22,20): error TS1109: Expression expected.
tests/cases/compiler/objectLitArrayDeclNoNew.ts(27,1): error TS1128: Declaration or statement expected.
==== tests/cases/compiler/objectLitArrayDeclNoNew.ts (2 errors) ====
==== tests/cases/compiler/objectLitArrayDeclNoNew.ts (1 errors) ====
declare var console;
"use strict";
module Test {
@ -25,8 +24,6 @@ tests/cases/compiler/objectLitArrayDeclNoNew.ts(27,1): error TS1128: Declaration
var state:IState= null;
return {
tokens: Gar[],//IToken[], // Missing new. Correct syntax is: tokens: new IToken[]
~
!!! error TS1109: Expression expected.
endState: state
};
}

View File

@ -1,10 +1,10 @@
tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral1.ts(1,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral1.ts(1,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral1.ts(1,5): error TS2304: Cannot find name 'Foo'.
==== tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral1.ts (2 errors) ====
new Foo[];
~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~
!!! error TS2304: Cannot find name 'Foo'.

View File

@ -1,10 +1,10 @@
tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral3.ts(1,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral3.ts(1,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral3.ts(1,5): error TS2304: Cannot find name 'Foo'.
==== tests/cases/conformance/parser/ecmascript5/parserObjectCreationArrayLiteral3.ts (2 errors) ====
new Foo[]();
~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~
!!! error TS2304: Cannot find name 'Foo'.

View File

@ -1,9 +1,9 @@
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(127,29): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(128,32): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(129,37): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(130,31): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(449,31): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(127,42): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(128,42): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(129,47): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(130,42): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(449,40): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(128,36): error TS2304: Cannot find name 'string'.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(129,41): error TS2304: Cannot find name 'number'.
tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(130,35): error TS2304: Cannot find name 'boolean'.
@ -472,20 +472,20 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(356,53): error
}
export var tokenTable = new TokenInfo[];
~~~~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
export var nodeTypeTable = new string[];
~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~~~
!!! error TS2304: Cannot find name 'string'.
export var nodeTypeToTokTable = new number[];
~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~~~
!!! error TS2304: Cannot find name 'number'.
export var noRegexTable = new boolean[];
~~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~~~~
!!! error TS2304: Cannot find name 'boolean'.
@ -1474,7 +1474,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource10.ts(356,53): error
// TODO: new with length TokenID.LimFixed
export var staticTokens = new Token[];
~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
export function initializeStaticTokens() {
for (var i = 0; i <= TokenID.LimFixed; i++) {

View File

@ -1,8 +1,8 @@
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(193,33): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(193,40): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(867,29): error TS1015: Parameter cannot have question mark and initializer.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1009,31): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1024,33): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1009,45): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(1024,47): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(13,22): error TS2304: Cannot find name 'Type'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(14,24): error TS2304: Cannot find name 'ASTFlags'.
tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(17,38): error TS2304: Cannot find name 'CompilerDiagnostics'.
@ -793,7 +793,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'SymbolScope'.
public members: AST[] = new AST[];
~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
constructor () {
@ -2029,7 +2029,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error
!!! error TS2304: Cannot find name 'Symbol'.
if (this.envids == null) {
this.envids = new Identifier[];
~~~~~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
}
this.envids[this.envids.length] = id;
@ -2048,7 +2048,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource11.ts(2356,48): error
!!! error TS2304: Cannot find name 'Symbol'.
if (this.jumpRefs == null) {
this.jumpRefs = new Identifier[];
~~~~~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
}
var id = new Identifier(sym.name);

View File

@ -1,5 +1,5 @@
tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts(195,24): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts(195,37): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
==== tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts (2 errors) ====
@ -200,7 +200,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource4.ts(195,24): error T
export class HashTable {
public itemCount: number = 0;
public table = new HashEntry[];
~~~~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
constructor (public size: number, public hashFn: (key) =>number,

View File

@ -1,5 +1,5 @@
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(16,33): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(16,45): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(12,38): error TS2304: Cannot find name 'ASTList'.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(12,62): error TS2304: Cannot find name 'TypeLink'.
tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(16,37): error TS2304: Cannot find name 'TypeLink'.
@ -326,7 +326,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource7.ts(828,13): error T
var len = bases.members.length;
if (baseTypeLinks == null) {
baseTypeLinks = new TypeLink[];
~~~~~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~~~~~
!!! error TS2304: Cannot find name 'TypeLink'.

View File

@ -1,5 +1,5 @@
tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(4,1): error TS6053: File 'tests/cases/conformance/parser/ecmascript5/typescript.ts' not found.
tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(12,31): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(12,39): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(8,38): error TS2304: Cannot find name 'TypeChecker'.
tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(9,48): error TS2304: Cannot find name 'TypeLink'.
tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(9,67): error TS2304: Cannot find name 'SymbolScope'.
@ -56,7 +56,7 @@ tests/cases/conformance/parser/ecmascript5/parserRealSource9.ts(200,48): error T
!!! error TS2304: Cannot find name 'Type'.
if (typeLinks) {
extendsList = new Type[];
~~~~~~~~~~
~~
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
~~~~
!!! error TS2304: Cannot find name 'Type'.

View File

@ -1,5 +1,5 @@
tests/cases/compiler/superWithTypeArgument.ts(7,14): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superWithTypeArgument.ts(7,9): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/superWithTypeArgument.ts(6,5): error TS2377: Constructors for derived classes must contain a 'super' call.
==== tests/cases/compiler/superWithTypeArgument.ts (2 errors) ====
@ -9,10 +9,12 @@ tests/cases/compiler/superWithTypeArgument.ts(7,9): error TS2346: Supplied param
class D<T> extends C {
constructor() {
~~~~~~~~~~~~~~~
super<T>();
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}

View File

@ -1,5 +1,5 @@
tests/cases/compiler/superWithTypeArgument2.ts(7,14): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superWithTypeArgument2.ts(7,9): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/superWithTypeArgument2.ts(6,5): error TS2377: Constructors for derived classes must contain a 'super' call.
==== tests/cases/compiler/superWithTypeArgument2.ts (2 errors) ====
@ -9,10 +9,12 @@ tests/cases/compiler/superWithTypeArgument2.ts(7,9): error TS2346: Supplied para
class D<T> extends C<T> {
constructor(x) {
~~~~~~~~~~~~~~~~
super<T>(x);
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
~~~~~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
}

View File

@ -1,7 +1,8 @@
tests/cases/compiler/superWithTypeArgument3.ts(8,14): error TS1034: 'super' must be followed by an argument list or member access.
tests/cases/compiler/superWithTypeArgument3.ts(7,5): error TS2377: Constructors for derived classes must contain a 'super' call.
==== tests/cases/compiler/superWithTypeArgument3.ts (1 errors) ====
==== tests/cases/compiler/superWithTypeArgument3.ts (2 errors) ====
class C<T> {
foo: T;
bar<U>(x: U) { }
@ -9,10 +10,14 @@ tests/cases/compiler/superWithTypeArgument3.ts(8,14): error TS1034: 'super' must
class D<T> extends C<T> {
constructor() {
~~~~~~~~~~~~~~~
super<T>();
~
!!! error TS1034: 'super' must be followed by an argument list or member access.
~~~~~~~~~~~~~~~~~~~
}
~~~~~
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
bar() {
super.bar<T>(null);
}