Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,7 @@ module ts {
write(" {");
scopeEmitStart(node, "constructor");
increaseIndent();
emitCaptureThisForNodeIfNecessary(node);
if (ctor) {
emitDefaultValueAssignments(ctor);
emitRestParameter(ctor);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrowFunctionContexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions tests/baselines/reference/captureThisInSuperCall.js
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
};
Expand All @@ -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; };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/lambdaPropSelf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/statics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); };
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/validUseOfThisInSuper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 8 additions & 0 deletions tests/cases/compiler/captureThisInSuperCall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class A {
constructor(p:any) {}
}

class B extends A {
constructor() { super({ test: () => this.someMethod()}); }
someMethod() {}
}