Skip to content

Commit 07a893d

Browse files
committed
Merge pull request #2207 from Microsoft/for-ofES5
Emit 'for...of' statements in ES3/ES5
2 parents 3e4955b + f389aef commit 07a893d

File tree

133 files changed

+2109
-165
lines changed

Some content is hidden

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

133 files changed

+2109
-165
lines changed

src/compiler/checker.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10912,6 +10912,8 @@ module ts {
1091210912
}
1091310913

1091410914
function isUnknownIdentifier(location: Node, name: string): boolean {
10915+
// Do not call resolveName on a synthesized node!
10916+
Debug.assert(!nodeIsSynthesized(location), "isUnknownIdentifier called with a synthesized location");
1091510917
return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) &&
1091610918
!hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name);
1091710919
}

src/compiler/emitter.ts

+195-14
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/conformance/statements/for-ofStatements/ES5For-of1.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
2+
3+
4+
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of1.ts (1 errors) ====
5+
for (var v of ['a', 'b', 'c']) {
6+
~~~
7+
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
8+
console.log(v);
9+
}

tests/baselines/reference/ES5For-of1.js

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of1.js.map

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
===================================================================
2+
JsFile: ES5For-of1.js
3+
mapUrl: ES5For-of1.js.map
4+
sourceRoot:
5+
sources: ES5For-of1.ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of1.js
9+
sourceFile:ES5For-of1.ts
10+
-------------------------------------------------------------------
11+
>>>for (var _i = 0, _a = [
12+
1 >
13+
2 >^^^
14+
3 > ^
15+
4 > ^
16+
5 > ^^^^^^^^^^
17+
6 > ^^
18+
1 >
19+
2 >for
20+
3 >
21+
4 > (var v of
22+
5 > ['a', 'b', 'c']
23+
6 >
24+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
25+
2 >Emitted(1, 4) Source(1, 4) + SourceIndex(0)
26+
3 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
27+
4 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
28+
5 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
29+
6 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
30+
---
31+
>>> 'a',
32+
1 >^^^^
33+
2 > ^^^
34+
3 > ^^->
35+
1 >[
36+
2 > 'a'
37+
1 >Emitted(2, 5) Source(1, 16) + SourceIndex(0)
38+
2 >Emitted(2, 8) Source(1, 19) + SourceIndex(0)
39+
---
40+
>>> 'b',
41+
1->^^^^
42+
2 > ^^^
43+
3 > ^->
44+
1->,
45+
2 > 'b'
46+
1->Emitted(3, 5) Source(1, 21) + SourceIndex(0)
47+
2 >Emitted(3, 8) Source(1, 24) + SourceIndex(0)
48+
---
49+
>>> 'c'
50+
1->^^^^
51+
2 > ^^^
52+
3 > ^^^^^^^^^^^^^^^^^^^^->
53+
1->,
54+
2 > 'c'
55+
1->Emitted(4, 5) Source(1, 26) + SourceIndex(0)
56+
2 >Emitted(4, 8) Source(1, 29) + SourceIndex(0)
57+
---
58+
>>>]; _i < _a.length; _i++) {
59+
1->^
60+
2 > ^^
61+
3 > ^^^^^^^^^^^^^^
62+
4 > ^^
63+
5 > ^^^^
64+
6 > ^
65+
1->]
66+
2 >
67+
3 > var v
68+
4 >
69+
5 > var v of ['a', 'b', 'c']
70+
6 > )
71+
1->Emitted(5, 2) Source(1, 30) + SourceIndex(0)
72+
2 >Emitted(5, 4) Source(1, 6) + SourceIndex(0)
73+
3 >Emitted(5, 18) Source(1, 11) + SourceIndex(0)
74+
4 >Emitted(5, 20) Source(1, 6) + SourceIndex(0)
75+
5 >Emitted(5, 24) Source(1, 30) + SourceIndex(0)
76+
6 >Emitted(5, 25) Source(1, 31) + SourceIndex(0)
77+
---
78+
>>> var v = _a[_i];
79+
1 >^^^^
80+
2 > ^^^^
81+
3 > ^
82+
4 > ^^^^^^^^^
83+
5 > ^^->
84+
1 >
85+
2 > var
86+
3 > v
87+
4 >
88+
1 >Emitted(6, 5) Source(1, 6) + SourceIndex(0)
89+
2 >Emitted(6, 9) Source(1, 10) + SourceIndex(0)
90+
3 >Emitted(6, 10) Source(1, 11) + SourceIndex(0)
91+
4 >Emitted(6, 19) Source(1, 11) + SourceIndex(0)
92+
---
93+
>>> console.log(v);
94+
1->^^^^
95+
2 > ^^^^^^^
96+
3 > ^
97+
4 > ^^^
98+
5 > ^
99+
6 > ^
100+
7 > ^
101+
8 > ^
102+
1-> of ['a', 'b', 'c']) {
103+
>
104+
2 > console
105+
3 > .
106+
4 > log
107+
5 > (
108+
6 > v
109+
7 > )
110+
8 > ;
111+
1->Emitted(7, 5) Source(2, 5) + SourceIndex(0)
112+
2 >Emitted(7, 12) Source(2, 12) + SourceIndex(0)
113+
3 >Emitted(7, 13) Source(2, 13) + SourceIndex(0)
114+
4 >Emitted(7, 16) Source(2, 16) + SourceIndex(0)
115+
5 >Emitted(7, 17) Source(2, 17) + SourceIndex(0)
116+
6 >Emitted(7, 18) Source(2, 18) + SourceIndex(0)
117+
7 >Emitted(7, 19) Source(2, 19) + SourceIndex(0)
118+
8 >Emitted(7, 20) Source(2, 20) + SourceIndex(0)
119+
---
120+
>>>}
121+
1 >^
122+
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
123+
1 >
124+
>}
125+
1 >Emitted(8, 2) Source(3, 2) + SourceIndex(0)
126+
---
127+
>>>//# sourceMappingURL=ES5For-of1.js.map
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/conformance/statements/for-ofStatements/ES5For-of10.ts(4,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
2+
3+
4+
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of10.ts (1 errors) ====
5+
function foo() {
6+
return { x: 0 };
7+
}
8+
for (foo().x of []) {
9+
~~~
10+
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
11+
for (foo().x of [])
12+
var p = foo().x;
13+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//// [ES5For-of10.ts]
2+
function foo() {
3+
return { x: 0 };
4+
}
5+
for (foo().x of []) {
6+
for (foo().x of [])
7+
var p = foo().x;
8+
}
9+
10+
//// [ES5For-of10.js]
11+
function foo() {
12+
return {
13+
x: 0
14+
};
15+
}
16+
for (var _i = 0, _a = []; _i < _a.length; _i++) {
17+
foo().x = _a[_i];
18+
for (var _b = 0, _c = []; _b < _c.length; _b++) {
19+
foo().x = _c[_b];
20+
var p = foo().x;
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/conformance/statements/for-ofStatements/ES5For-of11.ts(2,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
2+
3+
4+
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of11.ts (1 errors) ====
5+
var v;
6+
for (v of []) { }
7+
~~~
8+
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [ES5For-of11.ts]
2+
var v;
3+
for (v of []) { }
4+
5+
//// [ES5For-of11.js]
6+
var v;
7+
for (var _i = 0, _a = []; _i < _a.length; _i++) {
8+
v = _a[_i];
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tests/cases/conformance/statements/for-ofStatements/ES5For-of12.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
2+
3+
4+
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of12.ts (1 errors) ====
5+
for ([""] of []) { }
6+
~~~
7+
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [ES5For-of12.ts]
2+
for ([""] of []) { }
3+
4+
//// [ES5For-of12.js]
5+
for (var _i = 0, _a = []; _i < _a.length; _i++) {
6+
"" = _a[_i][0];
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/conformance/statements/for-ofStatements/ES5For-of13.ts(1,1): error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
2+
3+
4+
==== tests/cases/conformance/statements/for-ofStatements/ES5For-of13.ts (1 errors) ====
5+
for (let v of ['a', 'b', 'c']) {
6+
~~~
7+
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
8+
var x = v;
9+
}

tests/baselines/reference/ES5For-of13.js

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/ES5For-of13.js.map

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
===================================================================
2+
JsFile: ES5For-of13.js
3+
mapUrl: ES5For-of13.js.map
4+
sourceRoot:
5+
sources: ES5For-of13.ts
6+
===================================================================
7+
-------------------------------------------------------------------
8+
emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of13.js
9+
sourceFile:ES5For-of13.ts
10+
-------------------------------------------------------------------
11+
>>>for (var _i = 0, _a = [
12+
1 >
13+
2 >^^^
14+
3 > ^
15+
4 > ^
16+
5 > ^^^^^^^^^^
17+
6 > ^^
18+
1 >
19+
2 >for
20+
3 >
21+
4 > (let v of
22+
5 > ['a', 'b', 'c']
23+
6 >
24+
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
25+
2 >Emitted(1, 4) Source(1, 4) + SourceIndex(0)
26+
3 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
27+
4 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
28+
5 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
29+
6 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
30+
---
31+
>>> 'a',
32+
1 >^^^^
33+
2 > ^^^
34+
3 > ^^->
35+
1 >[
36+
2 > 'a'
37+
1 >Emitted(2, 5) Source(1, 16) + SourceIndex(0)
38+
2 >Emitted(2, 8) Source(1, 19) + SourceIndex(0)
39+
---
40+
>>> 'b',
41+
1->^^^^
42+
2 > ^^^
43+
3 > ^->
44+
1->,
45+
2 > 'b'
46+
1->Emitted(3, 5) Source(1, 21) + SourceIndex(0)
47+
2 >Emitted(3, 8) Source(1, 24) + SourceIndex(0)
48+
---
49+
>>> 'c'
50+
1->^^^^
51+
2 > ^^^
52+
3 > ^^^^^^^^^^^^^^^^^^^^->
53+
1->,
54+
2 > 'c'
55+
1->Emitted(4, 5) Source(1, 26) + SourceIndex(0)
56+
2 >Emitted(4, 8) Source(1, 29) + SourceIndex(0)
57+
---
58+
>>>]; _i < _a.length; _i++) {
59+
1->^
60+
2 > ^^
61+
3 > ^^^^^^^^^^^^^^
62+
4 > ^^
63+
5 > ^^^^
64+
6 > ^
65+
1->]
66+
2 >
67+
3 > let v
68+
4 >
69+
5 > let v of ['a', 'b', 'c']
70+
6 > )
71+
1->Emitted(5, 2) Source(1, 30) + SourceIndex(0)
72+
2 >Emitted(5, 4) Source(1, 6) + SourceIndex(0)
73+
3 >Emitted(5, 18) Source(1, 11) + SourceIndex(0)
74+
4 >Emitted(5, 20) Source(1, 6) + SourceIndex(0)
75+
5 >Emitted(5, 24) Source(1, 30) + SourceIndex(0)
76+
6 >Emitted(5, 25) Source(1, 31) + SourceIndex(0)
77+
---
78+
>>> var v = _a[_i];
79+
1 >^^^^
80+
2 > ^^^^
81+
3 > ^
82+
4 > ^^^^^^^^^
83+
1 >
84+
2 > let
85+
3 > v
86+
4 >
87+
1 >Emitted(6, 5) Source(1, 6) + SourceIndex(0)
88+
2 >Emitted(6, 9) Source(1, 10) + SourceIndex(0)
89+
3 >Emitted(6, 10) Source(1, 11) + SourceIndex(0)
90+
4 >Emitted(6, 19) Source(1, 11) + SourceIndex(0)
91+
---
92+
>>> var x = v;
93+
1 >^^^^
94+
2 > ^^^^
95+
3 > ^
96+
4 > ^^^
97+
5 > ^
98+
6 > ^
99+
1 > of ['a', 'b', 'c']) {
100+
>
101+
2 > var
102+
3 > x
103+
4 > =
104+
5 > v
105+
6 > ;
106+
1 >Emitted(7, 5) Source(2, 5) + SourceIndex(0)
107+
2 >Emitted(7, 9) Source(2, 9) + SourceIndex(0)
108+
3 >Emitted(7, 10) Source(2, 10) + SourceIndex(0)
109+
4 >Emitted(7, 13) Source(2, 13) + SourceIndex(0)
110+
5 >Emitted(7, 14) Source(2, 14) + SourceIndex(0)
111+
6 >Emitted(7, 15) Source(2, 15) + SourceIndex(0)
112+
---
113+
>>>}
114+
1 >^
115+
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
116+
1 >
117+
>}
118+
1 >Emitted(8, 2) Source(3, 2) + SourceIndex(0)
119+
---
120+
>>>//# sourceMappingURL=ES5For-of13.js.map

0 commit comments

Comments
 (0)