Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit 'for...of' statements in ES3/ES5 #2207

Merged
merged 20 commits into from
Mar 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e417e1d
Emit 'for...of' loop when LHS is a var
JsonFreeman Mar 3, 2015
76e9b6a
Make createTempVariable call into generateUniqueNameForLocation
JsonFreeman Mar 3, 2015
61224e9
Add tests for 'for...of' emit when LHS is a var
JsonFreeman Mar 3, 2015
5a87864
Accept baselines
JsonFreeman Mar 3, 2015
9b76a02
Remove tempCount
JsonFreeman Mar 3, 2015
f915efa
Emit for...of when LHS is expression
JsonFreeman Mar 3, 2015
a0f108c
Emit 'for...of' statements with let/const initializers
JsonFreeman Mar 4, 2015
a99449a
Support destructuring in 'for...of' loops
JsonFreeman Mar 4, 2015
9288424
Accept baselines
JsonFreeman Mar 4, 2015
4d32650
Revert change to createTempVariable
JsonFreeman Mar 4, 2015
4bb0587
Fix createTempVariable to always record the name in the currentScopeN…
JsonFreeman Mar 4, 2015
905f350
Do not create a temp for RHS if it's an identifier
JsonFreeman Mar 5, 2015
ed3ab96
Add tests for destructuring 'for...of'
JsonFreeman Mar 5, 2015
946dc0e
Accept error baselines and API breaks
JsonFreeman Mar 5, 2015
fecd20a
Fix sourcemaps for 'for...of' and no source maps for synthesized nodes
JsonFreeman Mar 5, 2015
835c84f
Minor baseline adjustment
JsonFreeman Mar 5, 2015
a27fbff
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
JsonFreeman Mar 9, 2015
b15d8aa
Address PR feedback
JsonFreeman Mar 9, 2015
1349a19
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
JsonFreeman Mar 10, 2015
f389aef
Fix call to emitNode after merge with master
JsonFreeman Mar 10, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!
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