Merge pull request #13946 from Microsoft/AddTestFor13925

Add test for #13925
This commit is contained in:
Mohamed Hegazy 2017-02-08 15:25:11 -08:00 committed by GitHub
commit de71002c8e
4 changed files with 181 additions and 0 deletions

View File

@ -0,0 +1,52 @@
//// [capturedLetConstInLoop13.ts]
class Main {
constructor() {
this.register("a", "b", "c");
}
private register(...names: string[]): void {
for (let name of names) {
this.bar({
[name + ".a"]: () => { this.foo(name); },
});
}
}
private bar(a: any): void { }
private foo(name: string): void { }
}
new Main();
//// [capturedLetConstInLoop13.js]
var Main = (function () {
function Main() {
this.register("a", "b", "c");
}
Main.prototype.register = function () {
var _this = this;
var names = [];
for (var _i = 0; _i < arguments.length; _i++) {
names[_i] = arguments[_i];
}
var _loop_1 = function (name) {
this_1.bar((_a = {},
_a[name + ".a"] = function () { _this.foo(name); },
_a));
var _a;
};
var this_1 = this;
for (var _a = 0, names_1 = names; _a < names_1.length; _a++) {
var name = names_1[_a];
_loop_1(name);
}
};
Main.prototype.bar = function (a) { };
Main.prototype.foo = function (name) { };
return Main;
}());
new Main();

View File

@ -0,0 +1,48 @@
=== tests/cases/compiler/capturedLetConstInLoop13.ts ===
class Main {
>Main : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0))
constructor() {
this.register("a", "b", "c");
>this.register : Symbol(Main.register, Decl(capturedLetConstInLoop13.ts, 4, 5))
>this : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0))
>register : Symbol(Main.register, Decl(capturedLetConstInLoop13.ts, 4, 5))
}
private register(...names: string[]): void {
>register : Symbol(Main.register, Decl(capturedLetConstInLoop13.ts, 4, 5))
>names : Symbol(names, Decl(capturedLetConstInLoop13.ts, 6, 21))
for (let name of names) {
>name : Symbol(name, Decl(capturedLetConstInLoop13.ts, 7, 16))
>names : Symbol(names, Decl(capturedLetConstInLoop13.ts, 6, 21))
this.bar({
>this.bar : Symbol(Main.bar, Decl(capturedLetConstInLoop13.ts, 13, 5))
>this : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0))
>bar : Symbol(Main.bar, Decl(capturedLetConstInLoop13.ts, 13, 5))
[name + ".a"]: () => { this.foo(name); },
>name : Symbol(name, Decl(capturedLetConstInLoop13.ts, 7, 16))
>this.foo : Symbol(Main.foo, Decl(capturedLetConstInLoop13.ts, 15, 33))
>this : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0))
>foo : Symbol(Main.foo, Decl(capturedLetConstInLoop13.ts, 15, 33))
>name : Symbol(name, Decl(capturedLetConstInLoop13.ts, 7, 16))
});
}
}
private bar(a: any): void { }
>bar : Symbol(Main.bar, Decl(capturedLetConstInLoop13.ts, 13, 5))
>a : Symbol(a, Decl(capturedLetConstInLoop13.ts, 15, 16))
private foo(name: string): void { }
>foo : Symbol(Main.foo, Decl(capturedLetConstInLoop13.ts, 15, 33))
>name : Symbol(name, Decl(capturedLetConstInLoop13.ts, 17, 16))
}
new Main();
>Main : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0))

View File

@ -0,0 +1,59 @@
=== tests/cases/compiler/capturedLetConstInLoop13.ts ===
class Main {
>Main : Main
constructor() {
this.register("a", "b", "c");
>this.register("a", "b", "c") : void
>this.register : (...names: string[]) => void
>this : this
>register : (...names: string[]) => void
>"a" : "a"
>"b" : "b"
>"c" : "c"
}
private register(...names: string[]): void {
>register : (...names: string[]) => void
>names : string[]
for (let name of names) {
>name : string
>names : string[]
this.bar({
>this.bar({ [name + ".a"]: () => { this.foo(name); }, }) : void
>this.bar : (a: any) => void
>this : this
>bar : (a: any) => void
>{ [name + ".a"]: () => { this.foo(name); }, } : { [x: string]: () => void; }
[name + ".a"]: () => { this.foo(name); },
>name + ".a" : string
>name : string
>".a" : ".a"
>() => { this.foo(name); } : () => void
>this.foo(name) : void
>this.foo : (name: string) => void
>this : this
>foo : (name: string) => void
>name : string
});
}
}
private bar(a: any): void { }
>bar : (a: any) => void
>a : any
private foo(name: string): void { }
>foo : (name: string) => void
>name : string
}
new Main();
>new Main() : Main
>Main : typeof Main

View File

@ -0,0 +1,22 @@
class Main {
constructor() {
this.register("a", "b", "c");
}
private register(...names: string[]): void {
for (let name of names) {
this.bar({
[name + ".a"]: () => { this.foo(name); },
});
}
}
private bar(a: any): void { }
private foo(name: string): void { }
}
new Main();