Skip to content

Commit

Permalink
Merge pull request #2207 from Microsoft/for-ofES5
Browse files Browse the repository at this point in the history
Emit 'for...of' statements in ES3/ES5
  • Loading branch information
JsonFreeman committed Mar 10, 2015
2 parents 3e4955b + f389aef commit 07a893d
Show file tree
Hide file tree
Showing 133 changed files with 2,109 additions and 165 deletions.
2 changes: 2 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10912,6 +10912,8 @@ module ts {
}

function isUnknownIdentifier(location: Node, name: string): boolean {
// Do not call resolveName on a synthesized node!

This comment has been minimized.

Copy link
@mihailik

mihailik Mar 11, 2015

Contributor

Quite confusing comment.

Written for people who already know why this assertion is there. It closely repeats the assertion message with a puzzling variation of wording.

Either it should be clearer (telling why calling isUnknownIdentifier on synthesized location is wrong), or removed.

This comment has been minimized.

Copy link
@JsonFreeman

JsonFreeman Mar 11, 2015

Author Contributor

I'll remove it.

Debug.assert(!nodeIsSynthesized(location), "isUnknownIdentifier called with a synthesized location");
return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) &&
!hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name);
}
Expand Down
209 changes: 195 additions & 14 deletions src/compiler/emitter.ts

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tests/baselines/reference/ES5For-of1.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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.


==== tests/cases/conformance/statements/for-ofStatements/ES5For-of1.ts (1 errors) ====
for (var v of ['a', 'b', 'c']) {
~~~
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
console.log(v);
}
15 changes: 15 additions & 0 deletions tests/baselines/reference/ES5For-of1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/baselines/reference/ES5For-of1.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions tests/baselines/reference/ES5For-of1.sourcemap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
===================================================================
JsFile: ES5For-of1.js
mapUrl: ES5For-of1.js.map
sourceRoot:
sources: ES5For-of1.ts
===================================================================
-------------------------------------------------------------------
emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of1.js
sourceFile:ES5For-of1.ts
-------------------------------------------------------------------
>>>for (var _i = 0, _a = [
1 >
2 >^^^
3 > ^
4 > ^
5 > ^^^^^^^^^^
6 > ^^
1 >
2 >for
3 >
4 > (var v of
5 > ['a', 'b', 'c']
6 >
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 4) Source(1, 4) + SourceIndex(0)
3 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
4 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
5 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
6 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
---
>>> 'a',
1 >^^^^
2 > ^^^
3 > ^^->
1 >[
2 > 'a'
1 >Emitted(2, 5) Source(1, 16) + SourceIndex(0)
2 >Emitted(2, 8) Source(1, 19) + SourceIndex(0)
---
>>> 'b',
1->^^^^
2 > ^^^
3 > ^->
1->,
2 > 'b'
1->Emitted(3, 5) Source(1, 21) + SourceIndex(0)
2 >Emitted(3, 8) Source(1, 24) + SourceIndex(0)
---
>>> 'c'
1->^^^^
2 > ^^^
3 > ^^^^^^^^^^^^^^^^^^^^->
1->,
2 > 'c'
1->Emitted(4, 5) Source(1, 26) + SourceIndex(0)
2 >Emitted(4, 8) Source(1, 29) + SourceIndex(0)
---
>>>]; _i < _a.length; _i++) {
1->^
2 > ^^
3 > ^^^^^^^^^^^^^^
4 > ^^
5 > ^^^^
6 > ^
1->]
2 >
3 > var v
4 >
5 > var v of ['a', 'b', 'c']
6 > )
1->Emitted(5, 2) Source(1, 30) + SourceIndex(0)
2 >Emitted(5, 4) Source(1, 6) + SourceIndex(0)
3 >Emitted(5, 18) Source(1, 11) + SourceIndex(0)
4 >Emitted(5, 20) Source(1, 6) + SourceIndex(0)
5 >Emitted(5, 24) Source(1, 30) + SourceIndex(0)
6 >Emitted(5, 25) Source(1, 31) + SourceIndex(0)
---
>>> var v = _a[_i];
1 >^^^^
2 > ^^^^
3 > ^
4 > ^^^^^^^^^
5 > ^^->
1 >
2 > var
3 > v
4 >
1 >Emitted(6, 5) Source(1, 6) + SourceIndex(0)
2 >Emitted(6, 9) Source(1, 10) + SourceIndex(0)
3 >Emitted(6, 10) Source(1, 11) + SourceIndex(0)
4 >Emitted(6, 19) Source(1, 11) + SourceIndex(0)
---
>>> console.log(v);
1->^^^^
2 > ^^^^^^^
3 > ^
4 > ^^^
5 > ^
6 > ^
7 > ^
8 > ^
1-> of ['a', 'b', 'c']) {
>
2 > console
3 > .
4 > log
5 > (
6 > v
7 > )
8 > ;
1->Emitted(7, 5) Source(2, 5) + SourceIndex(0)
2 >Emitted(7, 12) Source(2, 12) + SourceIndex(0)
3 >Emitted(7, 13) Source(2, 13) + SourceIndex(0)
4 >Emitted(7, 16) Source(2, 16) + SourceIndex(0)
5 >Emitted(7, 17) Source(2, 17) + SourceIndex(0)
6 >Emitted(7, 18) Source(2, 18) + SourceIndex(0)
7 >Emitted(7, 19) Source(2, 19) + SourceIndex(0)
8 >Emitted(7, 20) Source(2, 20) + SourceIndex(0)
---
>>>}
1 >^
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
>}
1 >Emitted(8, 2) Source(3, 2) + SourceIndex(0)
---
>>>//# sourceMappingURL=ES5For-of1.js.map
13 changes: 13 additions & 0 deletions tests/baselines/reference/ES5For-of10.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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.


==== tests/cases/conformance/statements/for-ofStatements/ES5For-of10.ts (1 errors) ====
function foo() {
return { x: 0 };
}
for (foo().x of []) {
~~~
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
for (foo().x of [])
var p = foo().x;
}
22 changes: 22 additions & 0 deletions tests/baselines/reference/ES5For-of10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//// [ES5For-of10.ts]
function foo() {
return { x: 0 };
}
for (foo().x of []) {
for (foo().x of [])
var p = foo().x;
}

//// [ES5For-of10.js]
function foo() {
return {
x: 0
};
}
for (var _i = 0, _a = []; _i < _a.length; _i++) {
foo().x = _a[_i];
for (var _b = 0, _c = []; _b < _c.length; _b++) {
foo().x = _c[_b];
var p = foo().x;
}
}
8 changes: 8 additions & 0 deletions tests/baselines/reference/ES5For-of11.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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.


==== tests/cases/conformance/statements/for-ofStatements/ES5For-of11.ts (1 errors) ====
var v;
for (v of []) { }
~~~
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
9 changes: 9 additions & 0 deletions tests/baselines/reference/ES5For-of11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//// [ES5For-of11.ts]
var v;
for (v of []) { }

//// [ES5For-of11.js]
var v;
for (var _i = 0, _a = []; _i < _a.length; _i++) {
v = _a[_i];
}
7 changes: 7 additions & 0 deletions tests/baselines/reference/ES5For-of12.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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.


==== tests/cases/conformance/statements/for-ofStatements/ES5For-of12.ts (1 errors) ====
for ([""] of []) { }
~~~
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
7 changes: 7 additions & 0 deletions tests/baselines/reference/ES5For-of12.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [ES5For-of12.ts]
for ([""] of []) { }

//// [ES5For-of12.js]
for (var _i = 0, _a = []; _i < _a.length; _i++) {
"" = _a[_i][0];
}
9 changes: 9 additions & 0 deletions tests/baselines/reference/ES5For-of13.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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.


==== tests/cases/conformance/statements/for-ofStatements/ES5For-of13.ts (1 errors) ====
for (let v of ['a', 'b', 'c']) {
~~~
!!! error TS2482: 'for...of' statements are only available when targeting ECMAScript 6 or higher.
var x = v;
}
15 changes: 15 additions & 0 deletions tests/baselines/reference/ES5For-of13.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/baselines/reference/ES5For-of13.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 120 additions & 0 deletions tests/baselines/reference/ES5For-of13.sourcemap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
===================================================================
JsFile: ES5For-of13.js
mapUrl: ES5For-of13.js.map
sourceRoot:
sources: ES5For-of13.ts
===================================================================
-------------------------------------------------------------------
emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of13.js
sourceFile:ES5For-of13.ts
-------------------------------------------------------------------
>>>for (var _i = 0, _a = [
1 >
2 >^^^
3 > ^
4 > ^
5 > ^^^^^^^^^^
6 > ^^
1 >
2 >for
3 >
4 > (let v of
5 > ['a', 'b', 'c']
6 >
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 4) Source(1, 4) + SourceIndex(0)
3 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
4 >Emitted(1, 6) Source(1, 15) + SourceIndex(0)
5 >Emitted(1, 16) Source(1, 30) + SourceIndex(0)
6 >Emitted(1, 18) Source(1, 15) + SourceIndex(0)
---
>>> 'a',
1 >^^^^
2 > ^^^
3 > ^^->
1 >[
2 > 'a'
1 >Emitted(2, 5) Source(1, 16) + SourceIndex(0)
2 >Emitted(2, 8) Source(1, 19) + SourceIndex(0)
---
>>> 'b',
1->^^^^
2 > ^^^
3 > ^->
1->,
2 > 'b'
1->Emitted(3, 5) Source(1, 21) + SourceIndex(0)
2 >Emitted(3, 8) Source(1, 24) + SourceIndex(0)
---
>>> 'c'
1->^^^^
2 > ^^^
3 > ^^^^^^^^^^^^^^^^^^^^->
1->,
2 > 'c'
1->Emitted(4, 5) Source(1, 26) + SourceIndex(0)
2 >Emitted(4, 8) Source(1, 29) + SourceIndex(0)
---
>>>]; _i < _a.length; _i++) {
1->^
2 > ^^
3 > ^^^^^^^^^^^^^^
4 > ^^
5 > ^^^^
6 > ^
1->]
2 >
3 > let v
4 >
5 > let v of ['a', 'b', 'c']
6 > )
1->Emitted(5, 2) Source(1, 30) + SourceIndex(0)
2 >Emitted(5, 4) Source(1, 6) + SourceIndex(0)
3 >Emitted(5, 18) Source(1, 11) + SourceIndex(0)
4 >Emitted(5, 20) Source(1, 6) + SourceIndex(0)
5 >Emitted(5, 24) Source(1, 30) + SourceIndex(0)
6 >Emitted(5, 25) Source(1, 31) + SourceIndex(0)
---
>>> var v = _a[_i];
1 >^^^^
2 > ^^^^
3 > ^
4 > ^^^^^^^^^
1 >
2 > let
3 > v
4 >
1 >Emitted(6, 5) Source(1, 6) + SourceIndex(0)
2 >Emitted(6, 9) Source(1, 10) + SourceIndex(0)
3 >Emitted(6, 10) Source(1, 11) + SourceIndex(0)
4 >Emitted(6, 19) Source(1, 11) + SourceIndex(0)
---
>>> var x = v;
1 >^^^^
2 > ^^^^
3 > ^
4 > ^^^
5 > ^
6 > ^
1 > of ['a', 'b', 'c']) {
>
2 > var
3 > x
4 > =
5 > v
6 > ;
1 >Emitted(7, 5) Source(2, 5) + SourceIndex(0)
2 >Emitted(7, 9) Source(2, 9) + SourceIndex(0)
3 >Emitted(7, 10) Source(2, 10) + SourceIndex(0)
4 >Emitted(7, 13) Source(2, 13) + SourceIndex(0)
5 >Emitted(7, 14) Source(2, 14) + SourceIndex(0)
6 >Emitted(7, 15) Source(2, 15) + SourceIndex(0)
---
>>>}
1 >^
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
>}
1 >Emitted(8, 2) Source(3, 2) + SourceIndex(0)
---
>>>//# sourceMappingURL=ES5For-of13.js.map
Loading

0 comments on commit 07a893d

Please sign in to comment.