Skip to content

Commit 13f319b

Browse files
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.
1 parent 6a4927c commit 13f319b

21 files changed

Lines changed: 274 additions & 159 deletions

src/compiler/parser.ts

Lines changed: 201 additions & 62 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ module ts {
514514

515515
export interface IndexedAccess extends Expression {
516516
object: Expression;
517+
openBracketToken: Node;
517518
index: Expression;
519+
closeBracketToken: Node;
518520
}
519521

520522
export interface CallExpression extends Expression {

tests/baselines/reference/assignmentLHSIsValue.errors.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(3
2020
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(31,1): error TS2364: Invalid left-hand side of assignment expression.
2121
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(32,1): error TS2364: Invalid left-hand side of assignment expression.
2222
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(38,1): error TS2364: Invalid left-hand side of assignment expression.
23-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(42,30): error TS2364: Invalid left-hand side of assignment expression.
24-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(44,13): error TS2364: Invalid left-hand side of assignment expression.
25-
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(46,21): error TS2364: Invalid left-hand side of assignment expression.
2623
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(54,1): error TS2364: Invalid left-hand side of assignment expression.
2724
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(57,1): error TS2364: Invalid left-hand side of assignment expression.
2825
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
4037
tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(70,1): error TS2364: Invalid left-hand side of assignment expression.
4138

4239

43-
==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (40 errors) ====
40+
==== tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts (37 errors) ====
4441
// expected error for all the LHS of assignments
4542
var value;
4643

@@ -119,20 +116,14 @@ tests/cases/conformance/expressions/assignmentOperator/assignmentLHSIsValue.ts(7
119116
constructor() { super(); super = value; }
120117
~
121118
!!! error TS1034: 'super' must be followed by an argument list or member access.
122-
~~~~~
123-
!!! error TS2364: Invalid left-hand side of assignment expression.
124119

125120
foo() { super = value }
126121
~
127122
!!! error TS1034: 'super' must be followed by an argument list or member access.
128-
~~~~~
129-
!!! error TS2364: Invalid left-hand side of assignment expression.
130123

131124
static sfoo() { super = value; }
132125
~
133126
!!! error TS1034: 'super' must be followed by an argument list or member access.
134-
~~~~~
135-
!!! error TS2364: Invalid left-hand side of assignment expression.
136127
}
137128

138129
// function expression
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/compiler/badArraySyntax.ts(6,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2-
tests/cases/compiler/badArraySyntax.ts(7,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
3-
tests/cases/compiler/badArraySyntax.ts(8,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
4-
tests/cases/compiler/badArraySyntax.ts(9,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
5-
tests/cases/compiler/badArraySyntax.ts(10,17): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
1+
tests/cases/compiler/badArraySyntax.ts(6,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2+
tests/cases/compiler/badArraySyntax.ts(7,15): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
3+
tests/cases/compiler/badArraySyntax.ts(8,20): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
4+
tests/cases/compiler/badArraySyntax.ts(9,20): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
5+
tests/cases/compiler/badArraySyntax.ts(10,40): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
66

77

88
==== tests/cases/compiler/badArraySyntax.ts (5 errors) ====
@@ -12,18 +12,18 @@ tests/cases/compiler/badArraySyntax.ts(10,17): error TS1150: 'new T[]' cannot be
1212

1313
var a1: Z[] = [];
1414
var a2 = new Z[];
15-
~~~~~~~
15+
~~
1616
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
1717
var a3 = new Z[]();
18-
~~~~~~~
18+
~~
1919
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2020
var a4: Z[] = new Z[];
21-
~~~~~~~
21+
~~
2222
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2323
var a5: Z[] = new Z[]();
24-
~~~~~~~
24+
~~
2525
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2626
var a6: Z[][] = new Z [ ] [ ];
27-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
~~~~
2828
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2929

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,9): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
1+
tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,21): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
22
tests/cases/compiler/cannotInvokeNewOnErrorExpression.ts(5,15): error TS2339: Property 'ClassA' does not exist on type 'typeof M'.
33

44

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

tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa
4242
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(55,1): error TS2364: Invalid left-hand side of assignment expression.
4343
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.
4444
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(63,1): error TS2364: Invalid left-hand side of assignment expression.
45-
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.
46-
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(70,9): error TS2364: Invalid left-hand side of assignment expression.
47-
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.
48-
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(75,9): error TS2364: Invalid left-hand side of assignment expression.
49-
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.
50-
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(80,9): error TS2364: Invalid left-hand side of assignment expression.
5145
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.
5246
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(92,1): error TS2364: Invalid left-hand side of assignment expression.
5347
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
8074
tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(122,1): error TS2364: Invalid left-hand side of assignment expression.
8175

8276

83-
==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (80 errors) ====
77+
==== tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts (74 errors) ====
8478
// expected error for all the LHS of compound assignments (arithmetic and addition)
8579
var value;
8680

@@ -220,39 +214,27 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa
220214
super *= value;
221215
~~
222216
!!! error TS1034: 'super' must be followed by an argument list or member access.
223-
~~~~~
224-
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
225217
super += value;
226218
~~
227219
!!! error TS1034: 'super' must be followed by an argument list or member access.
228-
~~~~~
229-
!!! error TS2364: Invalid left-hand side of assignment expression.
230220
}
231221

232222
foo() {
233223
super *= value;
234224
~~
235225
!!! error TS1034: 'super' must be followed by an argument list or member access.
236-
~~~~~
237-
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
238226
super += value;
239227
~~
240228
!!! error TS1034: 'super' must be followed by an argument list or member access.
241-
~~~~~
242-
!!! error TS2364: Invalid left-hand side of assignment expression.
243229
}
244230

245231
static sfoo() {
246232
super *= value;
247233
~~
248234
!!! error TS1034: 'super' must be followed by an argument list or member access.
249-
~~~~~
250-
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
251235
super += value;
252236
~~
253237
!!! error TS1034: 'super' must be followed by an argument list or member access.
254-
~~~~~
255-
!!! error TS2364: Invalid left-hand side of assignment expression.
256238
}
257239
}
258240

tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,9): error TS
4242
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,27): error TS1135: Argument expression expected.
4343
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,33): error TS1005: '(' expected.
4444
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,43): error TS1109: Expression expected.
45-
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,59): error TS1109: Expression expected.
4645
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,60): error TS1005: ';' expected.
4746
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(257,65): error TS1129: Statement expected.
4847
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,9): error TS1129: Statement expected.
@@ -88,7 +87,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,29): error T
8887
tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error TS2304: Cannot find name 'string'.
8988

9089

91-
==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (88 errors) ====
90+
==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (87 errors) ====
9291
declare module "fs" {
9392
export class File {
9493
constructor(filename: string);
@@ -498,8 +497,6 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(259,37): error T
498497
~
499498
!!! error TS1005: '(' expected.
500499
~~~
501-
!!! error TS1109: Expression expected.
502-
~
503500
!!! error TS1109: Expression expected.
504501
~
505502
!!! error TS1005: ';' expected.

tests/baselines/reference/createArray.errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
tests/cases/compiler/createArray.ts(1,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2-
tests/cases/compiler/createArray.ts(6,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
3-
tests/cases/compiler/createArray.ts(7,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
4-
tests/cases/compiler/createArray.ts(8,8): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
1+
tests/cases/compiler/createArray.ts(1,18): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2+
tests/cases/compiler/createArray.ts(6,6): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
3+
tests/cases/compiler/createArray.ts(7,19): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
4+
tests/cases/compiler/createArray.ts(8,18): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
55
tests/cases/compiler/createArray.ts(1,12): error TS2304: Cannot find name 'number'.
66
tests/cases/compiler/createArray.ts(7,12): error TS2304: Cannot find name 'boolean'.
77
tests/cases/compiler/createArray.ts(8,12): error TS2304: Cannot find name 'string'.
88

99

1010
==== tests/cases/compiler/createArray.ts (7 errors) ====
1111
var na=new number[];
12-
~~~~~~~~~~~~
12+
~~
1313
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
1414
~~~~~~
1515
!!! error TS2304: Cannot find name 'number'.
@@ -18,15 +18,15 @@ tests/cases/compiler/createArray.ts(8,12): error TS2304: Cannot find name 'strin
1818
}
1919

2020
new C[];
21-
~~~~~~~
21+
~~
2222
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2323
var ba=new boolean[];
24-
~~~~~~~~~~~~~
24+
~~
2525
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2626
~~~~~~~
2727
!!! error TS2304: Cannot find name 'boolean'.
2828
var sa=new string[];
29-
~~~~~~~~~~~~
29+
~~
3030
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
3131
~~~~~~
3232
!!! error TS2304: Cannot find name 'string'.

tests/baselines/reference/libMembers.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/libMembers.ts(9,11): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
1+
tests/cases/compiler/libMembers.ts(9,16): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
22
tests/cases/compiler/libMembers.ts(4,3): error TS2339: Property 'subby' does not exist on type 'string'.
33
tests/cases/compiler/libMembers.ts(12,15): error TS2339: Property 'prototype' does not exist on type 'C'.
44

@@ -15,7 +15,7 @@ tests/cases/compiler/libMembers.ts(12,15): error TS2339: Property 'prototype' do
1515
export class C {
1616
}
1717
var a=new C[];
18-
~~~~~~~
18+
~~
1919
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2020
a.length;
2121
a.push(new C());

tests/baselines/reference/newOperator.errors.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/compiler/newOperator.ts(18,10): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2-
tests/cases/compiler/newOperator.ts(20,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
1+
tests/cases/compiler/newOperator.ts(18,20): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
2+
tests/cases/compiler/newOperator.ts(22,1): error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
33
tests/cases/compiler/newOperator.ts(44,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
44
tests/cases/compiler/newOperator.ts(3,13): error TS2304: Cannot find name 'ifc'.
55
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
3838

3939
// Various spacing
4040
var t3 = new string[]( );
41-
~~~~~~~~~~~~
41+
~~
4242
!!! error TS1150: 'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.
4343
~~~~~~
4444
!!! error TS2304: Cannot find name 'string'.
4545
var t4 =
4646
new
47-
~~~
4847
string
4948
~~~~~~
50-
~~~~~~
5149
!!! error TS2304: Cannot find name 'string'.
5250
[
5351
~

0 commit comments

Comments
 (0)