Merge branch 'master' of https://github.com/Saulzi/TypeScript into Saulzi-master

This commit is contained in:
Ron Buckton
2019-08-05 11:17:32 -07:00
22 changed files with 338 additions and 198 deletions

View File

@@ -3636,15 +3636,16 @@ namespace ts {
name: "typescript:values",
scoped: false,
text: `
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
return {
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object not iterable." : "Symbol.iterator is not defined.");
};`
};

View File

@@ -74,6 +74,7 @@
"unittests/evaluation/asyncGenerator.ts",
"unittests/evaluation/awaiter.ts",
"unittests/evaluation/forAwaitOf.ts",
"unittests/evaluation/forOf.ts",
"unittests/evaluation/objectRest.ts",
"unittests/services/cancellableLanguageServiceOperations.ts",
"unittests/services/colorization.ts",

View File

@@ -0,0 +1,119 @@
describe("unittests:: evaluation:: forOfEvaluation", () => {
it("es5 over a array with no Symbol", () => {
const result = evaluator.evaluateTypeScript(`
Symbol = undefined;
export var output = [];
export function main() {
let x = [1,2,3];
for (let value of x) {
output.push(value);
}
}
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
result.main();
assert.strictEqual(result.output[0], 1);
assert.strictEqual(result.output[1], 2);
assert.strictEqual(result.output[2], 3);
});
it("es5 over a string with no Symbol", () => {
const result = evaluator.evaluateTypeScript(`
Symbol = undefined;
export var output = [];
export function main() {
let x = "hello";
for (let value of x) {
output.push(value);
}
}
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
result.main();
assert.strictEqual(result.output[0], "h");
assert.strictEqual(result.output[1], "e");
assert.strictEqual(result.output[2], "l");
assert.strictEqual(result.output[3], "l");
assert.strictEqual(result.output[4], "o");
});
it("es5 over undefined with no Symbol", () => {
const result = evaluator.evaluateTypeScript(`
Symbol = undefined;
export function main() {
let x = undefined;
for (let value of x) {
}
}
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
assert.throws(() => result.main(), "Symbol.iterator is not defined");
});
it("es5 over undefined with Symbol", () => {
const result = evaluator.evaluateTypeScript(`
export function main() {
let x = undefined;
for (let value of x) {
}
}
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
assert.throws(() => result.main(), "undefined is not iterable (cannot read property Symbol(Symbol.iterator))");
});
it("es5 over object with no Symbol.iterator with no Symbol", () => {
const result = evaluator.evaluateTypeScript(`
Symbol = undefined;
export function main() {
let x = {} as any;
for (let value of x) {
}
}
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
assert.throws(() => result.main(), "Symbol.iterator is not defined");
});
it("es5 over object with no Symbol.iterator with Symbol", () => {
const result = evaluator.evaluateTypeScript(`
export function main() {
let x = {} as any;
for (let value of x) {
}
}
`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
assert.throws(() => result.main(), "Object not iterable");
});
it("es5 over object with Symbol.iterator", () => {
const result = evaluator.evaluateTypeScript(`
export var output = [];
export function main() {
let thing : any = {};
thing[Symbol.iterator] = () => {
let i = 0;
return { next() { i++; return this; }, value: i, done: i < 10 };
};
for (let value of thing)
{
output.push(value)
}
}`, { downlevelIteration: true, target: ts.ScriptTarget.ES5 });
result.main();
});
});