Skip to content

Commit d6b2c6d

Browse files
Stop erroring on computed properties for ES3/ES5 emit.
1 parent 657d465 commit d6b2c6d

File tree

103 files changed

+918
-1057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+918
-1057
lines changed

src/compiler/checker.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -10626,10 +10626,7 @@ module ts {
1062610626
}
1062710627

1062810628
var computedPropertyName = <ComputedPropertyName>node;
10629-
if (languageVersion < ScriptTarget.ES6) {
10630-
return grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher);
10631-
}
10632-
else if (computedPropertyName.expression.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>computedPropertyName.expression).operator === SyntaxKind.CommaToken) {
10629+
if (computedPropertyName.expression.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>computedPropertyName.expression).operator === SyntaxKind.CommaToken) {
1063310630
return grammarErrorOnNode(computedPropertyName.expression, Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name);
1063410631
}
1063510632
}

tests/baselines/reference/FunctionDeclaration8_es6.errors.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,11): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
21
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,12): error TS2304: Cannot find name 'yield'.
32
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,20): error TS2304: Cannot find name 'foo'.
43

54

6-
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts (3 errors) ====
5+
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts (2 errors) ====
76
var v = { [yield]: foo }
8-
~~~~~~~
9-
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
107
~~~~~
118
!!! error TS2304: Cannot find name 'yield'.
129
~~~
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS9001: Generators are not currently supported.
2-
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,13): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
32
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,14): error TS9000: 'yield' expressions are not currently supported.
43

54

6-
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (3 errors) ====
5+
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (2 errors) ====
76
function * foo() {
87
~
98
!!! error TS9001: Generators are not currently supported.
109
var v = { [yield]: foo }
11-
~~~~~~~
12-
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
1310
~~~~~
1411
!!! error TS9000: 'yield' expressions are not currently supported.
1512
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS9001: Generators are not currently supported.
2-
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,12): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
32
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,13): error TS2304: Cannot find name 'foo'.
43

54

6-
==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (3 errors) ====
5+
==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (2 errors) ====
76
var v = { *[foo()]() { } }
87
~
98
!!! error TS9001: Generators are not currently supported.
10-
~~~~~~~
11-
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
129
~~~
1310
!!! error TS2304: Cannot find name 'foo'.

tests/baselines/reference/computedPropertyNames10_ES5.errors.txt

-52
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames10_ES5.ts ===
2+
var s: string;
3+
>s : string
4+
5+
var n: number;
6+
>n : number
7+
8+
var a: any;
9+
>a : any
10+
11+
var v = {
12+
>v : {}
13+
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : {}
14+
15+
[s]() { },
16+
>s : string
17+
18+
[n]() { },
19+
>n : number
20+
21+
[s + s]() { },
22+
>s + s : string
23+
>s : string
24+
>s : string
25+
26+
[s + n]() { },
27+
>s + n : string
28+
>s : string
29+
>n : number
30+
31+
[+s]() { },
32+
>+s : number
33+
>s : string
34+
35+
[""]() { },
36+
[0]() { },
37+
[a]() { },
38+
>a : any
39+
40+
[<any>true]() { },
41+
><any>true : any
42+
43+
[`hello bye`]() { },
44+
[`hello ${a} bye`]() { }
45+
>a : any
46+
}

tests/baselines/reference/computedPropertyNames11_ES5.errors.txt

-85
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames11_ES5.ts ===
2+
var s: string;
3+
>s : string
4+
5+
var n: number;
6+
>n : number
7+
8+
var a: any;
9+
>a : any
10+
11+
var v = {
12+
>v : {}
13+
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : {}
14+
15+
get [s]() { return 0; },
16+
>s : string
17+
18+
set [n](v) { },
19+
>n : number
20+
>v : any
21+
22+
get [s + s]() { return 0; },
23+
>s + s : string
24+
>s : string
25+
>s : string
26+
27+
set [s + n](v) { },
28+
>s + n : string
29+
>s : string
30+
>n : number
31+
>v : any
32+
33+
get [+s]() { return 0; },
34+
>+s : number
35+
>s : string
36+
37+
set [""](v) { },
38+
>v : any
39+
40+
get [0]() { return 0; },
41+
set [a](v) { },
42+
>a : any
43+
>v : any
44+
45+
get [<any>true]() { return 0; },
46+
><any>true : any
47+
48+
set [`hello bye`](v) { },
49+
>v : any
50+
51+
get [`hello ${a} bye`]() { return 0; }
52+
>a : any
53+
}

0 commit comments

Comments
 (0)