Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cf4f34c

Browse filesBrowse files
committed
Add parser tests for computed properties
1 parent 9d5c86a commit cf4f34c
Copy full SHA for cf4f34c

95 files changed

+626-78Lines changed: 626 additions & 78 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/parser.ts‎

Copy file name to clipboardExpand all lines: src/compiler/parser.ts
+8-10Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4528,14 +4528,12 @@ module ts {
45284528
var inStrictMode = (node.parserContextFlags & ParserContextFlags.StrictMode) !== 0;
45294529

45304530
for (var i = 0, n = node.properties.length; i < n; i++) {
4531-
var prop = node.properties[i];
4532-
if (prop.kind === SyntaxKind.OmittedExpression || p.name.kind === SyntaxKind.ComputedPropertyName) {
4531+
var prop = <Declaration>node.properties[i];
4532+
var name = <Identifier>prop.name;
4533+
if (prop.kind === SyntaxKind.OmittedExpression || name.kind === SyntaxKind.ComputedPropertyName) {
45334534
continue;
45344535
}
45354536

4536-
var p = <Declaration>prop;
4537-
var name = <Identifier>p.name;
4538-
45394537
// ECMA-262 11.1.5 Object Initialiser
45404538
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
45414539
// a.This production is contained in strict code and IsDataDescriptor(previous) is true and
@@ -4545,20 +4543,20 @@ module ts {
45454543
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
45464544
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
45474545
var currentKind: number;
4548-
if (p.kind === SyntaxKind.PropertyAssignment) {
4546+
if (prop.kind === SyntaxKind.PropertyAssignment) {
45494547
currentKind = Property;
45504548
}
4551-
else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) {
4549+
else if (prop.kind === SyntaxKind.ShorthandPropertyAssignment) {
45524550
currentKind = Property;
45534551
}
4554-
else if (p.kind === SyntaxKind.GetAccessor) {
4552+
else if (prop.kind === SyntaxKind.GetAccessor) {
45554553
currentKind = GetAccessor;
45564554
}
4557-
else if (p.kind === SyntaxKind.SetAccessor) {
4555+
else if (prop.kind === SyntaxKind.SetAccessor) {
45584556
currentKind = SetAccesor;
45594557
}
45604558
else {
4561-
Debug.fail("Unexpected syntax kind:" + p.kind);
4559+
Debug.fail("Unexpected syntax kind:" + prop.kind);
45624560
}
45634561

45644562
if (!hasProperty(seen, name.text)) {
Collapse file

‎tests/baselines/reference/giant.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/giant.errors.txt
+24-24Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tests/cases/compiler/giant.ts(28,17): error TS1056: Accessors are only available
44
tests/cases/compiler/giant.ts(30,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
55
tests/cases/compiler/giant.ts(34,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
66
tests/cases/compiler/giant.ts(36,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
7-
tests/cases/compiler/giant.ts(61,6): error TS1022: An index signature parameter must have a type annotation.
7+
tests/cases/compiler/giant.ts(61,5): error TS1161: Computed property names are not allowed in interfaces or type literals.
88
tests/cases/compiler/giant.ts(62,5): error TS1021: An index signature must have a type annotation.
99
tests/cases/compiler/giant.ts(63,6): error TS1096: An index signature must have exactly one parameter.
1010
tests/cases/compiler/giant.ts(88,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
@@ -13,7 +13,7 @@ tests/cases/compiler/giant.ts(92,21): error TS1056: Accessors are only available
1313
tests/cases/compiler/giant.ts(94,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
1414
tests/cases/compiler/giant.ts(98,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
1515
tests/cases/compiler/giant.ts(100,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
16-
tests/cases/compiler/giant.ts(125,10): error TS1022: An index signature parameter must have a type annotation.
16+
tests/cases/compiler/giant.ts(125,9): error TS1161: Computed property names are not allowed in interfaces or type literals.
1717
tests/cases/compiler/giant.ts(126,9): error TS1021: An index signature must have a type annotation.
1818
tests/cases/compiler/giant.ts(127,10): error TS1096: An index signature must have exactly one parameter.
1919
tests/cases/compiler/giant.ts(154,39): error TS1037: A function implementation cannot be declared in an ambient context.
@@ -23,7 +23,7 @@ tests/cases/compiler/giant.ts(171,21): error TS1056: Accessors are only availabl
2323
tests/cases/compiler/giant.ts(173,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2424
tests/cases/compiler/giant.ts(177,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
2525
tests/cases/compiler/giant.ts(179,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
26-
tests/cases/compiler/giant.ts(204,10): error TS1022: An index signature parameter must have a type annotation.
26+
tests/cases/compiler/giant.ts(204,9): error TS1161: Computed property names are not allowed in interfaces or type literals.
2727
tests/cases/compiler/giant.ts(205,9): error TS1021: An index signature must have a type annotation.
2828
tests/cases/compiler/giant.ts(206,10): error TS1096: An index signature must have exactly one parameter.
2929
tests/cases/compiler/giant.ts(233,39): error TS1037: A function implementation cannot be declared in an ambient context.
@@ -54,7 +54,7 @@ tests/cases/compiler/giant.ts(286,17): error TS1056: Accessors are only availabl
5454
tests/cases/compiler/giant.ts(288,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
5555
tests/cases/compiler/giant.ts(292,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
5656
tests/cases/compiler/giant.ts(294,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
57-
tests/cases/compiler/giant.ts(319,6): error TS1022: An index signature parameter must have a type annotation.
57+
tests/cases/compiler/giant.ts(319,5): error TS1161: Computed property names are not allowed in interfaces or type literals.
5858
tests/cases/compiler/giant.ts(320,5): error TS1021: An index signature must have a type annotation.
5959
tests/cases/compiler/giant.ts(321,6): error TS1096: An index signature must have exactly one parameter.
6060
tests/cases/compiler/giant.ts(346,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
@@ -63,7 +63,7 @@ tests/cases/compiler/giant.ts(350,21): error TS1056: Accessors are only availabl
6363
tests/cases/compiler/giant.ts(352,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
6464
tests/cases/compiler/giant.ts(356,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
6565
tests/cases/compiler/giant.ts(358,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
66-
tests/cases/compiler/giant.ts(383,10): error TS1022: An index signature parameter must have a type annotation.
66+
tests/cases/compiler/giant.ts(383,9): error TS1161: Computed property names are not allowed in interfaces or type literals.
6767
tests/cases/compiler/giant.ts(384,9): error TS1021: An index signature must have a type annotation.
6868
tests/cases/compiler/giant.ts(385,10): error TS1096: An index signature must have exactly one parameter.
6969
tests/cases/compiler/giant.ts(412,39): error TS1037: A function implementation cannot be declared in an ambient context.
@@ -73,7 +73,7 @@ tests/cases/compiler/giant.ts(429,21): error TS1056: Accessors are only availabl
7373
tests/cases/compiler/giant.ts(431,21): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
7474
tests/cases/compiler/giant.ts(435,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
7575
tests/cases/compiler/giant.ts(437,20): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
76-
tests/cases/compiler/giant.ts(462,10): error TS1022: An index signature parameter must have a type annotation.
76+
tests/cases/compiler/giant.ts(462,9): error TS1161: Computed property names are not allowed in interfaces or type literals.
7777
tests/cases/compiler/giant.ts(463,9): error TS1021: An index signature must have a type annotation.
7878
tests/cases/compiler/giant.ts(464,10): error TS1096: An index signature must have exactly one parameter.
7979
tests/cases/compiler/giant.ts(491,39): error TS1037: A function implementation cannot be declared in an ambient context.
@@ -120,7 +120,7 @@ tests/cases/compiler/giant.ts(556,21): error TS1036: Statements are not allowed
120120
tests/cases/compiler/giant.ts(558,24): error TS1111: A constructor implementation cannot be declared in an ambient context.
121121
tests/cases/compiler/giant.ts(561,21): error TS1037: A function implementation cannot be declared in an ambient context.
122122
tests/cases/compiler/giant.ts(563,21): error TS1037: A function implementation cannot be declared in an ambient context.
123-
tests/cases/compiler/giant.ts(587,10): error TS1022: An index signature parameter must have a type annotation.
123+
tests/cases/compiler/giant.ts(587,9): error TS1161: Computed property names are not allowed in interfaces or type literals.
124124
tests/cases/compiler/giant.ts(588,9): error TS1021: An index signature must have a type annotation.
125125
tests/cases/compiler/giant.ts(589,10): error TS1096: An index signature must have exactly one parameter.
126126
tests/cases/compiler/giant.ts(606,22): error TS1037: A function implementation cannot be declared in an ambient context.
@@ -137,7 +137,7 @@ tests/cases/compiler/giant.ts(621,29): error TS1036: Statements are not allowed
137137
tests/cases/compiler/giant.ts(623,24): error TS1111: A constructor implementation cannot be declared in an ambient context.
138138
tests/cases/compiler/giant.ts(626,21): error TS1037: A function implementation cannot be declared in an ambient context.
139139
tests/cases/compiler/giant.ts(628,21): error TS1037: A function implementation cannot be declared in an ambient context.
140-
tests/cases/compiler/giant.ts(653,10): error TS1022: An index signature parameter must have a type annotation.
140+
tests/cases/compiler/giant.ts(653,9): error TS1161: Computed property names are not allowed in interfaces or type literals.
141141
tests/cases/compiler/giant.ts(654,9): error TS1021: An index signature must have a type annotation.
142142
tests/cases/compiler/giant.ts(655,10): error TS1096: An index signature must have exactly one parameter.
143143
tests/cases/compiler/giant.ts(672,22): error TS1037: A function implementation cannot be declared in an ambient context.
@@ -360,8 +360,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all
360360

361361
//Index Signature
362362
[p];
363-
~
364-
!!! error TS1022: An index signature parameter must have a type annotation.
363+
~~~
364+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
365365
[p1: string];
366366
~~~~~~~~~~~~~
367367
!!! error TS1021: An index signature must have a type annotation.
@@ -468,8 +468,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all
468468

469469
//Index Signature
470470
[p];
471-
~
472-
!!! error TS1022: An index signature parameter must have a type annotation.
471+
~~~
472+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
473473
[p1: string];
474474
~~~~~~~~~~~~~
475475
!!! error TS1021: An index signature must have a type annotation.
@@ -593,8 +593,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all
593593

594594
//Index Signature
595595
[p];
596-
~
597-
!!! error TS1022: An index signature parameter must have a type annotation.
596+
~~~
597+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
598598
[p1: string];
599599
~~~~~~~~~~~~~
600600
!!! error TS1021: An index signature must have a type annotation.
@@ -820,8 +820,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all
820820

821821
//Index Signature
822822
[p];
823-
~
824-
!!! error TS1022: An index signature parameter must have a type annotation.
823+
~~~
824+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
825825
[p1: string];
826826
~~~~~~~~~~~~~
827827
!!! error TS1021: An index signature must have a type annotation.
@@ -928,8 +928,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all
928928

929929
//Index Signature
930930
[p];
931-
~
932-
!!! error TS1022: An index signature parameter must have a type annotation.
931+
~~~
932+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
933933
[p1: string];
934934
~~~~~~~~~~~~~
935935
!!! error TS1021: An index signature must have a type annotation.
@@ -1053,8 +1053,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all
10531053

10541054
//Index Signature
10551055
[p];
1056-
~
1057-
!!! error TS1022: An index signature parameter must have a type annotation.
1056+
~~~
1057+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
10581058
[p1: string];
10591059
~~~~~~~~~~~~~
10601060
!!! error TS1021: An index signature must have a type annotation.
@@ -1322,8 +1322,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all
13221322

13231323
//Index Signature
13241324
[p];
1325-
~
1326-
!!! error TS1022: An index signature parameter must have a type annotation.
1325+
~~~
1326+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
13271327
[p1: string];
13281328
~~~~~~~~~~~~~
13291329
!!! error TS1021: An index signature must have a type annotation.
@@ -1424,8 +1424,8 @@ tests/cases/compiler/giant.ts(668,9): error TS2386: Overload signatures must all
14241424

14251425
//Index Signature
14261426
[p];
1427-
~
1428-
!!! error TS1022: An index signature parameter must have a type annotation.
1427+
~~~
1428+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
14291429
[p1: string];
14301430
~~~~~~~~~~~~~
14311431
!!! error TS1021: An index signature must have a type annotation.
Collapse file

‎tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/indexSignatureMustHaveTypeAnnotation.errors.txt
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(2,6): error TS1022: An index signature parameter must have a type annotation.
1+
tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(2,5): error TS1161: Computed property names are not allowed in interfaces or type literals.
22
tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(3,5): error TS1021: An index signature must have a type annotation.
3-
tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(7,6): error TS1022: An index signature parameter must have a type annotation.
3+
tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(7,5): error TS1164: Computed property names are not allowed in class property declarations.
44
tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts(12,5): error TS1021: An index signature must have a type annotation.
55

66

77
==== tests/cases/compiler/indexSignatureMustHaveTypeAnnotation.ts (4 errors) ====
88
interface I {
99
[x]: string;
10-
~
11-
!!! error TS1022: An index signature parameter must have a type annotation.
10+
~~~
11+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
1212
[x: string];
1313
~~~~~~~~~~~~
1414
!!! error TS1021: An index signature must have a type annotation.
1515
}
1616

1717
class C {
1818
[x]: string
19-
~
20-
!!! error TS1022: An index signature parameter must have a type annotation.
19+
~~~
20+
!!! error TS1164: Computed property names are not allowed in class property declarations.
2121

2222
}
2323

Collapse file
+7-13Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
tests/cases/compiler/indexSignatureWithInitializer.ts(2,6): error TS1020: An index signature parameter cannot have an initializer.
2-
tests/cases/compiler/indexSignatureWithInitializer.ts(6,6): error TS1020: An index signature parameter cannot have an initializer.
3-
tests/cases/compiler/indexSignatureWithInitializer.ts(2,6): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
4-
tests/cases/compiler/indexSignatureWithInitializer.ts(6,6): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
1+
tests/cases/compiler/indexSignatureWithInitializer.ts(2,5): error TS1161: Computed property names are not allowed in interfaces or type literals.
2+
tests/cases/compiler/indexSignatureWithInitializer.ts(6,5): error TS1164: Computed property names are not allowed in class property declarations.
53

64

7-
==== tests/cases/compiler/indexSignatureWithInitializer.ts (4 errors) ====
5+
==== tests/cases/compiler/indexSignatureWithInitializer.ts (2 errors) ====
86
interface I {
97
[x = '']: string;
10-
~
11-
!!! error TS1020: An index signature parameter cannot have an initializer.
12-
~~~~~~
13-
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
8+
~~~~~~~~
9+
!!! error TS1161: Computed property names are not allowed in interfaces or type literals.
1410
}
1511

1612
class C {
1713
[x = 0]: string
18-
~
19-
!!! error TS1020: An index signature parameter cannot have an initializer.
20-
~~~~~
21-
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
14+
~~~~~~~
15+
!!! error TS1164: Computed property names are not allowed in class property declarations.
2216
}
Collapse file
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/compiler/indexWithoutParamType2.ts(2,6): error TS1022: An index signature parameter must have a type annotation.
1+
tests/cases/compiler/indexWithoutParamType2.ts(2,5): error TS1164: Computed property names are not allowed in class property declarations.
22

33

44
==== tests/cases/compiler/indexWithoutParamType2.ts (1 errors) ====
55
class C {
66
[x]: string
7-
~
8-
!!! error TS1022: An index signature parameter must have a type annotation.
7+
~~~
8+
!!! error TS1164: Computed property names are not allowed in class property declarations.
99
}
Collapse file
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/compiler/objectTypeWithOptionalProperty1.ts(2,10): error TS1162: An object member cannot be declared optional.
1+
tests/cases/compiler/objectTypeWithOptionalProperty1.ts(2,10): error TS1160: An object member cannot be declared optional.
22

33

44
==== tests/cases/compiler/objectTypeWithOptionalProperty1.ts (1 errors) ====
55
var b = {
66
x?: 1 // error
77
~
8-
!!! error TS1162: An object member cannot be declared optional.
8+
!!! error TS1160: An object member cannot be declared optional.
99
}
Collapse file

‎tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/objectTypesWithOptionalProperties.errors.txt
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(12,6): error TS1112: A class member cannot be declared optional.
22
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(20,6): error TS1112: A class member cannot be declared optional.
3-
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1162: An object member cannot be declared optional.
3+
tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts(24,6): error TS1160: An object member cannot be declared optional.
44

55

66
==== tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWithOptionalProperties.ts (3 errors) ====
@@ -33,5 +33,5 @@ tests/cases/conformance/types/objectTypeLiteral/methodSignatures/objectTypesWith
3333
var b = {
3434
x?: 1 // error
3535
~
36-
!!! error TS1162: An object member cannot be declared optional.
36+
!!! error TS1160: An object member cannot be declared optional.
3737
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.