emit this capturing as a first action in the constructor
This commit is contained in:
parent
13bda5247b
commit
c0b3efbbb4
|
@ -1371,6 +1371,7 @@ module ts {
|
|||
write(" {");
|
||||
scopeEmitStart(node, "constructor");
|
||||
increaseIndent();
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
if (ctor) {
|
||||
emitDefaultValueAssignments(ctor);
|
||||
emitRestParameter(ctor);
|
||||
|
@ -1390,8 +1391,7 @@ module ts {
|
|||
write("_super.apply(this, arguments);");
|
||||
emitEnd(node.baseType);
|
||||
}
|
||||
}
|
||||
emitCaptureThisForNodeIfNecessary(node);
|
||||
}
|
||||
emitMemberAssignments(node, /*nonstatic*/0);
|
||||
if (ctor) {
|
||||
var statements: Node[] = (<Block>ctor.body).statements;
|
||||
|
|
|
@ -114,8 +114,8 @@ var Base = (function () {
|
|||
var Derived = (function (_super) {
|
||||
__extends(Derived, _super);
|
||||
function Derived() {
|
||||
_super.call(this, function () { return _this; });
|
||||
var _this = this;
|
||||
_super.call(this, function () { return _this; });
|
||||
}
|
||||
return Derived;
|
||||
})(Base);
|
||||
|
@ -147,8 +147,8 @@ var M2;
|
|||
var Derived = (function (_super) {
|
||||
__extends(Derived, _super);
|
||||
function Derived() {
|
||||
_super.call(this, function () { return _this; });
|
||||
var _this = this;
|
||||
_super.call(this, function () { return _this; });
|
||||
}
|
||||
return Derived;
|
||||
})(Base);
|
||||
|
|
32
tests/baselines/reference/captureThisInSuperCall.js
Normal file
32
tests/baselines/reference/captureThisInSuperCall.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
//// [captureThisInSuperCall.ts]
|
||||
class A {
|
||||
constructor(p:any) {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor() { super({ test: () => this.someMethod()}); }
|
||||
someMethod() {}
|
||||
}
|
||||
|
||||
//// [captureThisInSuperCall.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var A = (function () {
|
||||
function A(p) {
|
||||
}
|
||||
return A;
|
||||
})();
|
||||
var B = (function (_super) {
|
||||
__extends(B, _super);
|
||||
function B() {
|
||||
var _this = this;
|
||||
_super.call(this, { test: function () { return _this.someMethod(); } });
|
||||
}
|
||||
B.prototype.someMethod = function () {
|
||||
};
|
||||
return B;
|
||||
})(A);
|
|
@ -33,8 +33,8 @@ class Test1 {
|
|||
//// [classMemberInitializerWithLamdaScoping.js]
|
||||
var Test = (function () {
|
||||
function Test(field) {
|
||||
this.field = field;
|
||||
var _this = this;
|
||||
this.field = field;
|
||||
this.messageHandler = function () {
|
||||
var field = _this.field;
|
||||
console.log(field);
|
||||
|
|
|
@ -47,8 +47,8 @@ var Foo2 = (function () {
|
|||
})();
|
||||
var Foo3 = (function () {
|
||||
function Foo3(_this) {
|
||||
this._this = _this;
|
||||
var _this = this;
|
||||
this._this = _this;
|
||||
var lambda = function () {
|
||||
return function (x) { return _this; };
|
||||
};
|
||||
|
@ -66,8 +66,8 @@ var Foo4 = (function () {
|
|||
})();
|
||||
var Foo5 = (function () {
|
||||
function Foo5(_this) {
|
||||
this._this = _this;
|
||||
var _this = this;
|
||||
this._this = _this;
|
||||
var lambda = function () {
|
||||
return function (x) { return _this; };
|
||||
};
|
||||
|
|
|
@ -58,9 +58,9 @@ var Derived2 = (function (_super) {
|
|||
var Derived3 = (function (_super) {
|
||||
__extends(Derived3, _super);
|
||||
function Derived3(a) {
|
||||
var _this = this;
|
||||
_super.call(this, function () { return _this; });
|
||||
this.a = a;
|
||||
var _this = this;
|
||||
}
|
||||
return Derived3;
|
||||
})(Base);
|
||||
|
|
|
@ -26,8 +26,8 @@ module M {
|
|||
//// [lambdaPropSelf.js]
|
||||
var Person = (function () {
|
||||
function Person(name, children) {
|
||||
this.name = name;
|
||||
var _this = this;
|
||||
this.name = name;
|
||||
this.addChild = function () { return _this.children.push("New child"); };
|
||||
this.children = ko.observableArray(children);
|
||||
}
|
||||
|
|
|
@ -36,9 +36,9 @@ var M;
|
|||
(function (M) {
|
||||
var C = (function () {
|
||||
function C(c1, c2, c3) {
|
||||
var _this = this;
|
||||
this.c1 = c1;
|
||||
this.c2 = c2;
|
||||
var _this = this;
|
||||
this.x = C.y + this.c1 + this.c2 + c3;
|
||||
this.g = function (v) { return C.f(_this.x + C.y + v + _this.c1 + _this.c2 + C.pub); };
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ var Base = (function () {
|
|||
var Super = (function (_super) {
|
||||
__extends(Super, _super);
|
||||
function Super() {
|
||||
_super.call(this, (function () { return _this; })());
|
||||
var _this = this;
|
||||
_super.call(this, (function () { return _this; })());
|
||||
}
|
||||
return Super;
|
||||
})(Base);
|
||||
|
|
8
tests/cases/compiler/captureThisInSuperCall.ts
Normal file
8
tests/cases/compiler/captureThisInSuperCall.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
class A {
|
||||
constructor(p:any) {}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor() { super({ test: () => this.someMethod()}); }
|
||||
someMethod() {}
|
||||
}
|
Loading…
Reference in a new issue