Skip to content

Commit cc3db8f

Browse files
committed
Merge branch 'Saulzi-master'
2 parents 7adc175 + 3ff0a24 commit cc3db8f

22 files changed

+338
-198
lines changed

src/compiler/factory.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3636,15 +3636,16 @@ namespace ts {
36363636
name: "typescript:values",
36373637
scoped: false,
36383638
text: `
3639-
var __values = (this && this.__values) || function (o) {
3640-
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
3639+
var __values = (this && this.__values) || function(o) {
3640+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
36413641
if (m) return m.call(o);
3642-
return {
3642+
if (o && typeof o.length === "number") return {
36433643
next: function () {
36443644
if (o && i >= o.length) o = void 0;
36453645
return { value: o && o[i++], done: !o };
36463646
}
36473647
};
3648+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
36483649
};`
36493650
};
36503651

src/testRunner/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"unittests/evaluation/asyncGenerator.ts",
7575
"unittests/evaluation/awaiter.ts",
7676
"unittests/evaluation/forAwaitOf.ts",
77+
"unittests/evaluation/forOf.ts",
7778
"unittests/evaluation/objectRest.ts",
7879
"unittests/services/cancellableLanguageServiceOperations.ts",
7980
"unittests/services/colorization.ts",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
describe("unittests:: evaluation:: forOfEvaluation", () => {
2+
it("es5 over a array with no Symbol", () => {
3+
const result = evaluator.evaluateTypeScript(`
4+
Symbol = undefined;
5+
export var output = [];
6+
export function main() {
7+
let x = [1,2,3];
8+
9+
for (let value of x) {
10+
output.push(value);
11+
}
12+
}
13+
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
14+
15+
result.main();
16+
17+
assert.strictEqual(result.output[0], 1);
18+
assert.strictEqual(result.output[1], 2);
19+
assert.strictEqual(result.output[2], 3);
20+
21+
});
22+
23+
it("es5 over a string with no Symbol", () => {
24+
const result = evaluator.evaluateTypeScript(`
25+
Symbol = undefined;
26+
export var output = [];
27+
export function main() {
28+
let x = "hello";
29+
30+
for (let value of x) {
31+
output.push(value);
32+
}
33+
}
34+
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
35+
36+
result.main();
37+
38+
assert.strictEqual(result.output[0], "h");
39+
assert.strictEqual(result.output[1], "e");
40+
assert.strictEqual(result.output[2], "l");
41+
assert.strictEqual(result.output[3], "l");
42+
assert.strictEqual(result.output[4], "o");
43+
});
44+
45+
it("es5 over undefined with no Symbol", () => {
46+
const result = evaluator.evaluateTypeScript(`
47+
Symbol = undefined;
48+
export function main() {
49+
let x = undefined;
50+
51+
for (let value of x) {
52+
}
53+
}
54+
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
55+
56+
assert.throws(() => result.main(), "Symbol.iterator is not defined");
57+
});
58+
59+
it("es5 over undefined with Symbol", () => {
60+
const result = evaluator.evaluateTypeScript(`
61+
export function main() {
62+
let x = undefined;
63+
64+
for (let value of x) {
65+
}
66+
}
67+
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
68+
69+
assert.throws(() => result.main(), /cannot read property.*Symbol\(Symbol\.iterator\).*/i);
70+
});
71+
72+
it("es5 over object with no Symbol.iterator with no Symbol", () => {
73+
const result = evaluator.evaluateTypeScript(`
74+
Symbol = undefined;
75+
export function main() {
76+
let x = {} as any;
77+
78+
for (let value of x) {
79+
}
80+
}
81+
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
82+
83+
assert.throws(() => result.main(), "Symbol.iterator is not defined");
84+
});
85+
86+
it("es5 over object with no Symbol.iterator with Symbol", () => {
87+
const result = evaluator.evaluateTypeScript(`
88+
export function main() {
89+
let x = {} as any;
90+
91+
for (let value of x) {
92+
}
93+
}
94+
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
95+
96+
assert.throws(() => result.main(), "Object is not iterable");
97+
});
98+
99+
it("es5 over object with Symbol.iterator", () => {
100+
const result = evaluator.evaluateTypeScript(`
101+
export var output = [];
102+
export function main() {
103+
let thing : any = {};
104+
thing[Symbol.iterator] = () => {
105+
let i = 0;
106+
return { next() { i++; return this; }, value: i, done: i < 10 };
107+
};
108+
109+
for (let value of thing)
110+
{
111+
output.push(value)
112+
}
113+
114+
}`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
115+
116+
result.main();
117+
});
118+
119+
});

tests/baselines/reference/ES5For-of33.js

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

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

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

tests/baselines/reference/ES5For-of33.sourcemap.txt

+32-31
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ sources: ES5For-of33.ts
88
emittedFile:tests/cases/conformance/statements/for-ofStatements/ES5For-of33.js
99
sourceFile:ES5For-of33.ts
1010
-------------------------------------------------------------------
11-
>>>var __values = (this && this.__values) || function (o) {
12-
>>> var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
11+
>>>var __values = (this && this.__values) || function(o) {
12+
>>> var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1313
>>> if (m) return m.call(o);
14-
>>> return {
14+
>>> if (o && typeof o.length === "number") return {
1515
>>> next: function () {
1616
>>> if (o && i >= o.length) o = void 0;
1717
>>> return { value: o && o[i++], done: !o };
1818
>>> }
1919
>>> };
20+
>>> throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
2021
>>>};
2122
>>>var e_1, _a;
2223
>>>try {
@@ -51,21 +52,21 @@ sourceFile:ES5For-of33.ts
5152
13>
5253
14>
5354
15> )
54-
1 >Emitted(13, 5) Source(1, 1) + SourceIndex(0)
55-
2 >Emitted(13, 10) Source(1, 15) + SourceIndex(0)
56-
3 >Emitted(13, 14) Source(1, 15) + SourceIndex(0)
57-
4 >Emitted(13, 19) Source(1, 15) + SourceIndex(0)
58-
5 >Emitted(13, 28) Source(1, 15) + SourceIndex(0)
59-
6 >Emitted(13, 29) Source(1, 16) + SourceIndex(0)
60-
7 >Emitted(13, 32) Source(1, 19) + SourceIndex(0)
61-
8 >Emitted(13, 34) Source(1, 21) + SourceIndex(0)
62-
9 >Emitted(13, 37) Source(1, 24) + SourceIndex(0)
63-
10>Emitted(13, 39) Source(1, 26) + SourceIndex(0)
64-
11>Emitted(13, 42) Source(1, 29) + SourceIndex(0)
65-
12>Emitted(13, 43) Source(1, 30) + SourceIndex(0)
66-
13>Emitted(13, 44) Source(1, 30) + SourceIndex(0)
67-
14>Emitted(13, 60) Source(1, 30) + SourceIndex(0)
68-
15>Emitted(13, 88) Source(1, 32) + SourceIndex(0)
55+
1 >Emitted(14, 5) Source(1, 1) + SourceIndex(0)
56+
2 >Emitted(14, 10) Source(1, 15) + SourceIndex(0)
57+
3 >Emitted(14, 14) Source(1, 15) + SourceIndex(0)
58+
4 >Emitted(14, 19) Source(1, 15) + SourceIndex(0)
59+
5 >Emitted(14, 28) Source(1, 15) + SourceIndex(0)
60+
6 >Emitted(14, 29) Source(1, 16) + SourceIndex(0)
61+
7 >Emitted(14, 32) Source(1, 19) + SourceIndex(0)
62+
8 >Emitted(14, 34) Source(1, 21) + SourceIndex(0)
63+
9 >Emitted(14, 37) Source(1, 24) + SourceIndex(0)
64+
10>Emitted(14, 39) Source(1, 26) + SourceIndex(0)
65+
11>Emitted(14, 42) Source(1, 29) + SourceIndex(0)
66+
12>Emitted(14, 43) Source(1, 30) + SourceIndex(0)
67+
13>Emitted(14, 44) Source(1, 30) + SourceIndex(0)
68+
14>Emitted(14, 60) Source(1, 30) + SourceIndex(0)
69+
15>Emitted(14, 88) Source(1, 32) + SourceIndex(0)
6970
---
7071
>>> var v = _c.value;
7172
1 >^^^^^^^^
@@ -76,10 +77,10 @@ sourceFile:ES5For-of33.ts
7677
2 > var
7778
3 > v
7879
4 >
79-
1 >Emitted(14, 9) Source(1, 6) + SourceIndex(0)
80-
2 >Emitted(14, 13) Source(1, 10) + SourceIndex(0)
81-
3 >Emitted(14, 14) Source(1, 11) + SourceIndex(0)
82-
4 >Emitted(14, 25) Source(1, 11) + SourceIndex(0)
80+
1 >Emitted(15, 9) Source(1, 6) + SourceIndex(0)
81+
2 >Emitted(15, 13) Source(1, 10) + SourceIndex(0)
82+
3 >Emitted(15, 14) Source(1, 11) + SourceIndex(0)
83+
4 >Emitted(15, 25) Source(1, 11) + SourceIndex(0)
8384
---
8485
>>> console.log(v);
8586
1 >^^^^^^^^
@@ -99,20 +100,20 @@ sourceFile:ES5For-of33.ts
99100
6 > v
100101
7 > )
101102
8 > ;
102-
1 >Emitted(15, 9) Source(2, 5) + SourceIndex(0)
103-
2 >Emitted(15, 16) Source(2, 12) + SourceIndex(0)
104-
3 >Emitted(15, 17) Source(2, 13) + SourceIndex(0)
105-
4 >Emitted(15, 20) Source(2, 16) + SourceIndex(0)
106-
5 >Emitted(15, 21) Source(2, 17) + SourceIndex(0)
107-
6 >Emitted(15, 22) Source(2, 18) + SourceIndex(0)
108-
7 >Emitted(15, 23) Source(2, 19) + SourceIndex(0)
109-
8 >Emitted(15, 24) Source(2, 20) + SourceIndex(0)
103+
1 >Emitted(16, 9) Source(2, 5) + SourceIndex(0)
104+
2 >Emitted(16, 16) Source(2, 12) + SourceIndex(0)
105+
3 >Emitted(16, 17) Source(2, 13) + SourceIndex(0)
106+
4 >Emitted(16, 20) Source(2, 16) + SourceIndex(0)
107+
5 >Emitted(16, 21) Source(2, 17) + SourceIndex(0)
108+
6 >Emitted(16, 22) Source(2, 18) + SourceIndex(0)
109+
7 >Emitted(16, 23) Source(2, 19) + SourceIndex(0)
110+
8 >Emitted(16, 24) Source(2, 20) + SourceIndex(0)
110111
---
111112
>>> }
112113
1 >^^^^^
113114
1 >
114115
>}
115-
1 >Emitted(16, 6) Source(3, 2) + SourceIndex(0)
116+
1 >Emitted(17, 6) Source(3, 2) + SourceIndex(0)
116117
---
117118
>>>}
118119
>>>catch (e_1_1) { e_1 = { error: e_1_1 }; }

tests/baselines/reference/ES5For-of34.js

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

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

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

0 commit comments

Comments
 (0)