diff --git a/tests/baselines/reference/capturedLetConstInLoop13.js b/tests/baselines/reference/capturedLetConstInLoop13.js new file mode 100644 index 00000000000..a2e0921ab1d --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop13.js @@ -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(); diff --git a/tests/baselines/reference/capturedLetConstInLoop13.symbols b/tests/baselines/reference/capturedLetConstInLoop13.symbols new file mode 100644 index 00000000000..c7a824d26fa --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop13.symbols @@ -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)) + diff --git a/tests/baselines/reference/capturedLetConstInLoop13.types b/tests/baselines/reference/capturedLetConstInLoop13.types new file mode 100644 index 00000000000..e6f97255d75 --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop13.types @@ -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 + diff --git a/tests/cases/compiler/capturedLetConstInLoop13.ts b/tests/cases/compiler/capturedLetConstInLoop13.ts new file mode 100644 index 00000000000..0aa00b0e1a0 --- /dev/null +++ b/tests/cases/compiler/capturedLetConstInLoop13.ts @@ -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(); \ No newline at end of file