Skip to content

Commit bcdf1dc

Browse files
Merge pull request #10762 from Microsoft/useReturnedThisFromSuperCalls
Use returned values from super calls as 'this'
2 parents edd8eb8 + 02b9917 commit bcdf1dc

File tree

680 files changed

+3489
-1959
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

680 files changed

+3489
-1959
lines changed

Diff for: src/compiler/checker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9421,8 +9421,8 @@ namespace ts {
94219421
let container = getSuperContainer(node, /*stopOnFunctions*/ true);
94229422
let needToCaptureLexicalThis = false;
94239423

9424+
// adjust the container reference in case if super is used inside arrow functions with arbitrarily deep nesting
94249425
if (!isCallExpression) {
9425-
// adjust the container reference in case if super is used inside arrow functions with arbitrary deep nesting
94269426
while (container && container.kind === SyntaxKind.ArrowFunction) {
94279427
container = getSuperContainer(container, /*stopOnFunctions*/ true);
94289428
needToCaptureLexicalThis = languageVersion < ScriptTarget.ES6;
@@ -14439,6 +14439,7 @@ namespace ts {
1443914439
// constructors of derived classes must contain at least one super call somewhere in their function body.
1444014440
const containingClassDecl = <ClassDeclaration>node.parent;
1444114441
if (getClassExtendsHeritageClauseElement(containingClassDecl)) {
14442+
captureLexicalThis(node.parent, containingClassDecl);
1444214443
const classExtendsNull = classDeclarationExtendsNull(containingClassDecl);
1444314444
const superCall = getSuperCallInConstructor(node);
1444414445
if (superCall) {

Diff for: src/compiler/transformers/es6.ts

+234-54
Large diffs are not rendered by default.

Diff for: src/compiler/utilities.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -982,11 +982,11 @@ namespace ts {
982982
}
983983

984984
/**
985-
* Given an super call\property node returns a closest node where either
986-
* - super call\property is legal in the node and not legal in the parent node the node.
985+
* Given an super call/property node, returns the closest node where
986+
* - a super call/property access is legal in the node and not legal in the parent node the node.
987987
* i.e. super call is legal in constructor but not legal in the class body.
988-
* - node is arrow function (so caller might need to call getSuperContainer in case it needs to climb higher)
989-
* - super call\property is definitely illegal in the node (but might be legal in some subnode)
988+
* - the container is an arrow function (so caller might need to call getSuperContainer again in case it needs to climb higher)
989+
* - a super call/property is definitely illegal in the container (but might be legal in some subnode)
990990
* i.e. super property access is illegal in function declaration but can be legal in the statement list
991991
*/
992992
export function getSuperContainer(node: Node, stopOnFunctions: boolean): Node {

Diff for: tests/baselines/reference/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var A;
3838
var Point3d = (function (_super) {
3939
__extends(Point3d, _super);
4040
function Point3d() {
41-
_super.apply(this, arguments);
41+
return _super.apply(this, arguments) || this;
4242
}
4343
return Point3d;
4444
}(Point));

Diff for: tests/baselines/reference/ExportClassWithInaccessibleTypeInTypeParameterConstraint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var A;
4141
var Point3d = (function (_super) {
4242
__extends(Point3d, _super);
4343
function Point3d() {
44-
_super.apply(this, arguments);
44+
return _super.apply(this, arguments) || this;
4545
}
4646
return Point3d;
4747
}(Point));

Diff for: tests/baselines/reference/abstractClassInLocalScope.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var __extends = (this && this.__extends) || function (d, b) {
2222
var B = (function (_super) {
2323
__extends(B, _super);
2424
function B() {
25-
_super.apply(this, arguments);
25+
return _super.apply(this, arguments) || this;
2626
}
2727
return B;
2828
}(A));

Diff for: tests/baselines/reference/abstractClassInLocalScopeIsAbstract.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var __extends = (this && this.__extends) || function (d, b) {
2222
var B = (function (_super) {
2323
__extends(B, _super);
2424
function B() {
25-
_super.apply(this, arguments);
25+
return _super.apply(this, arguments) || this;
2626
}
2727
return B;
2828
}(A));

Diff for: tests/baselines/reference/abstractProperty.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ var B = (function () {
3535
var C = (function (_super) {
3636
__extends(C, _super);
3737
function C() {
38-
_super.apply(this, arguments);
39-
this.raw = "edge";
40-
this.ro = "readonly please";
38+
var _this = _super.apply(this, arguments) || this;
39+
_this.raw = "edge";
40+
_this.ro = "readonly please";
41+
return _this;
4142
}
4243
Object.defineProperty(C.prototype, "prop", {
4344
get: function () { return "foo"; },

Diff for: tests/baselines/reference/abstractPropertyNegative.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ var B = (function () {
5757
var C = (function (_super) {
5858
__extends(C, _super);
5959
function C() {
60-
_super.apply(this, arguments);
61-
this.ro = "readonly please";
60+
var _this = _super.apply(this, arguments) || this;
61+
_this.ro = "readonly please";
62+
return _this;
6263
}
6364
Object.defineProperty(C.prototype, "concreteWithNoBody", {
6465
get: function () { },
@@ -77,8 +78,9 @@ var WrongTypeProperty = (function () {
7778
var WrongTypePropertyImpl = (function (_super) {
7879
__extends(WrongTypePropertyImpl, _super);
7980
function WrongTypePropertyImpl() {
80-
_super.apply(this, arguments);
81-
this.num = "nope, wrong";
81+
var _this = _super.apply(this, arguments) || this;
82+
_this.num = "nope, wrong";
83+
return _this;
8284
}
8385
return WrongTypePropertyImpl;
8486
}(WrongTypeProperty));
@@ -90,7 +92,7 @@ var WrongTypeAccessor = (function () {
9092
var WrongTypeAccessorImpl = (function (_super) {
9193
__extends(WrongTypeAccessorImpl, _super);
9294
function WrongTypeAccessorImpl() {
93-
_super.apply(this, arguments);
95+
return _super.apply(this, arguments) || this;
9496
}
9597
Object.defineProperty(WrongTypeAccessorImpl.prototype, "num", {
9698
get: function () { return "nope, wrong"; },
@@ -102,8 +104,9 @@ var WrongTypeAccessorImpl = (function (_super) {
102104
var WrongTypeAccessorImpl2 = (function (_super) {
103105
__extends(WrongTypeAccessorImpl2, _super);
104106
function WrongTypeAccessorImpl2() {
105-
_super.apply(this, arguments);
106-
this.num = "nope, wrong";
107+
var _this = _super.apply(this, arguments) || this;
108+
_this.num = "nope, wrong";
109+
return _this;
107110
}
108111
return WrongTypeAccessorImpl2;
109112
}(WrongTypeAccessor));

Diff for: tests/baselines/reference/accessOverriddenBaseClassMember1.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ var Point = (function () {
3434
var ColoredPoint = (function (_super) {
3535
__extends(ColoredPoint, _super);
3636
function ColoredPoint(x, y, color) {
37-
_super.call(this, x, y);
38-
this.color = color;
37+
var _this = _super.call(this, x, y) || this;
38+
_this.color = color;
39+
return _this;
3940
}
4041
ColoredPoint.prototype.toString = function () {
4142
return _super.prototype.toString.call(this) + " color=" + this.color;

Diff for: tests/baselines/reference/accessors_spec_section-4.5_inference.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var A = (function () {
3838
var B = (function (_super) {
3939
__extends(B, _super);
4040
function B() {
41-
_super.apply(this, arguments);
41+
return _super.apply(this, arguments) || this;
4242
}
4343
return B;
4444
}(A));

Diff for: tests/baselines/reference/aliasUsageInAccessorsOfClass.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var Backbone = require("./aliasUsage1_backbone");
4646
var VisualizationModel = (function (_super) {
4747
__extends(VisualizationModel, _super);
4848
function VisualizationModel() {
49-
_super.apply(this, arguments);
49+
return _super.apply(this, arguments) || this;
5050
}
5151
return VisualizationModel;
5252
}(Backbone.Model));

Diff for: tests/baselines/reference/aliasUsageInArray.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var Backbone = require("./aliasUsageInArray_backbone");
4040
var VisualizationModel = (function (_super) {
4141
__extends(VisualizationModel, _super);
4242
function VisualizationModel() {
43-
_super.apply(this, arguments);
43+
return _super.apply(this, arguments) || this;
4444
}
4545
return VisualizationModel;
4646
}(Backbone.Model));

Diff for: tests/baselines/reference/aliasUsageInFunctionExpression.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var Backbone = require("./aliasUsageInFunctionExpression_backbone");
3939
var VisualizationModel = (function (_super) {
4040
__extends(VisualizationModel, _super);
4141
function VisualizationModel() {
42-
_super.apply(this, arguments);
42+
return _super.apply(this, arguments) || this;
4343
}
4444
return VisualizationModel;
4545
}(Backbone.Model));

Diff for: tests/baselines/reference/aliasUsageInGenericFunction.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var Backbone = require("./aliasUsageInGenericFunction_backbone");
4343
var VisualizationModel = (function (_super) {
4444
__extends(VisualizationModel, _super);
4545
function VisualizationModel() {
46-
_super.apply(this, arguments);
46+
return _super.apply(this, arguments) || this;
4747
}
4848
return VisualizationModel;
4949
}(Backbone.Model));

Diff for: tests/baselines/reference/aliasUsageInIndexerOfClass.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var Backbone = require("./aliasUsageInIndexerOfClass_backbone");
4545
var VisualizationModel = (function (_super) {
4646
__extends(VisualizationModel, _super);
4747
function VisualizationModel() {
48-
_super.apply(this, arguments);
48+
return _super.apply(this, arguments) || this;
4949
}
5050
return VisualizationModel;
5151
}(Backbone.Model));

Diff for: tests/baselines/reference/aliasUsageInObjectLiteral.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var Backbone = require("./aliasUsageInObjectLiteral_backbone");
4040
var VisualizationModel = (function (_super) {
4141
__extends(VisualizationModel, _super);
4242
function VisualizationModel() {
43-
_super.apply(this, arguments);
43+
return _super.apply(this, arguments) || this;
4444
}
4545
return VisualizationModel;
4646
}(Backbone.Model));

Diff for: tests/baselines/reference/aliasUsageInOrExpression.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var Backbone = require("./aliasUsageInOrExpression_backbone");
4343
var VisualizationModel = (function (_super) {
4444
__extends(VisualizationModel, _super);
4545
function VisualizationModel() {
46-
_super.apply(this, arguments);
46+
return _super.apply(this, arguments) || this;
4747
}
4848
return VisualizationModel;
4949
}(Backbone.Model));

Diff for: tests/baselines/reference/aliasUsageInTypeArgumentOfExtendsClause.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var Backbone = require("./aliasUsageInTypeArgumentOfExtendsClause_backbone");
4343
var VisualizationModel = (function (_super) {
4444
__extends(VisualizationModel, _super);
4545
function VisualizationModel() {
46-
_super.apply(this, arguments);
46+
return _super.apply(this, arguments) || this;
4747
}
4848
return VisualizationModel;
4949
}(Backbone.Model));
@@ -64,8 +64,9 @@ var C = (function () {
6464
var D = (function (_super) {
6565
__extends(D, _super);
6666
function D() {
67-
_super.apply(this, arguments);
68-
this.x = moduleA;
67+
var _this = _super.apply(this, arguments) || this;
68+
_this.x = moduleA;
69+
return _this;
6970
}
7071
return D;
7172
}(C));

Diff for: tests/baselines/reference/aliasUsageInVarAssignment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var Backbone = require("./aliasUsageInVarAssignment_backbone");
3939
var VisualizationModel = (function (_super) {
4040
__extends(VisualizationModel, _super);
4141
function VisualizationModel() {
42-
_super.apply(this, arguments);
42+
return _super.apply(this, arguments) || this;
4343
}
4444
return VisualizationModel;
4545
}(Backbone.Model));

Diff for: tests/baselines/reference/ambiguousOverloadResolution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var A = (function () {
2222
var B = (function (_super) {
2323
__extends(B, _super);
2424
function B() {
25-
_super.apply(this, arguments);
25+
return _super.apply(this, arguments) || this;
2626
}
2727
return B;
2828
}(A));

Diff for: tests/baselines/reference/apparentTypeSubtyping.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var Base = (function () {
3838
var Derived = (function (_super) {
3939
__extends(Derived, _super);
4040
function Derived() {
41-
_super.apply(this, arguments);
41+
return _super.apply(this, arguments) || this;
4242
}
4343
return Derived;
4444
}(Base));
@@ -51,7 +51,7 @@ var Base2 = (function () {
5151
var Derived2 = (function (_super) {
5252
__extends(Derived2, _super);
5353
function Derived2() {
54-
_super.apply(this, arguments);
54+
return _super.apply(this, arguments) || this;
5555
}
5656
return Derived2;
5757
}(Base2));

Diff for: tests/baselines/reference/apparentTypeSupertype.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Base = (function () {
2828
var Derived = (function (_super) {
2929
__extends(Derived, _super);
3030
function Derived() {
31-
_super.apply(this, arguments);
31+
return _super.apply(this, arguments) || this;
3232
}
3333
return Derived;
3434
}(Base));

Diff for: tests/baselines/reference/arrayAssignmentTest1.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ var C1 = (function () {
101101
var C2 = (function (_super) {
102102
__extends(C2, _super);
103103
function C2() {
104-
_super.apply(this, arguments);
104+
return _super.apply(this, arguments) || this;
105105
}
106106
C2.prototype.C2M1 = function () { return null; };
107107
return C2;

Diff for: tests/baselines/reference/arrayAssignmentTest2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var C1 = (function () {
7575
var C2 = (function (_super) {
7676
__extends(C2, _super);
7777
function C2() {
78-
_super.apply(this, arguments);
78+
return _super.apply(this, arguments) || this;
7979
}
8080
C2.prototype.C2M1 = function () { return null; };
8181
return C2;

Diff for: tests/baselines/reference/arrayBestCommonTypes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ var EmptyTypes;
128128
var derived = (function (_super) {
129129
__extends(derived, _super);
130130
function derived() {
131-
_super.apply(this, arguments);
131+
return _super.apply(this, arguments) || this;
132132
}
133133
return derived;
134134
}(base));
@@ -187,7 +187,7 @@ var NonEmptyTypes;
187187
var derived = (function (_super) {
188188
__extends(derived, _super);
189189
function derived() {
190-
_super.apply(this, arguments);
190+
return _super.apply(this, arguments) || this;
191191
}
192192
return derived;
193193
}(base));

Diff for: tests/baselines/reference/arrayLiteralTypeInference.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ var Action = (function () {
6565
var ActionA = (function (_super) {
6666
__extends(ActionA, _super);
6767
function ActionA() {
68-
_super.apply(this, arguments);
68+
return _super.apply(this, arguments) || this;
6969
}
7070
return ActionA;
7171
}(Action));
7272
var ActionB = (function (_super) {
7373
__extends(ActionB, _super);
7474
function ActionB() {
75-
_super.apply(this, arguments);
75+
return _super.apply(this, arguments) || this;
7676
}
7777
return ActionB;
7878
}(Action));

Diff for: tests/baselines/reference/arrayLiterals.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ var Base = (function () {
7070
var Derived1 = (function (_super) {
7171
__extends(Derived1, _super);
7272
function Derived1() {
73-
_super.apply(this, arguments);
73+
return _super.apply(this, arguments) || this;
7474
}
7575
return Derived1;
7676
}(Base));
7777
;
7878
var Derived2 = (function (_super) {
7979
__extends(Derived2, _super);
8080
function Derived2() {
81-
_super.apply(this, arguments);
81+
return _super.apply(this, arguments) || this;
8282
}
8383
return Derived2;
8484
}(Base));

Diff for: tests/baselines/reference/arrayLiteralsWithRecursiveGenerics.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var List = (function () {
3939
var DerivedList = (function (_super) {
4040
__extends(DerivedList, _super);
4141
function DerivedList() {
42-
_super.apply(this, arguments);
42+
return _super.apply(this, arguments) || this;
4343
}
4444
return DerivedList;
4545
}(List));

Diff for: tests/baselines/reference/arrayOfSubtypeIsAssignableToReadonlyArray.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ var A = (function () {
3333
var B = (function (_super) {
3434
__extends(B, _super);
3535
function B() {
36-
_super.apply(this, arguments);
36+
return _super.apply(this, arguments) || this;
3737
}
3838
return B;
3939
}(A));
4040
var C = (function (_super) {
4141
__extends(C, _super);
4242
function C() {
43-
_super.apply(this, arguments);
43+
return _super.apply(this, arguments) || this;
4444
}
4545
return C;
4646
}(Array));

Diff for: tests/baselines/reference/arrowFunctionContexts.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ var Base = (function () {
116116
var Derived = (function (_super) {
117117
__extends(Derived, _super);
118118
function Derived() {
119-
var _this = this;
120-
_super.call(this, function () { return _this; });
119+
return _super.call(this, function () { return _this; }) || this;
121120
}
122121
return Derived;
123122
}(Base));
@@ -158,8 +157,7 @@ var M2;
158157
var Derived = (function (_super) {
159158
__extends(Derived, _super);
160159
function Derived() {
161-
var _this = this;
162-
_super.call(this, function () { return _this; });
160+
return _super.call(this, function () { return _this; }) || this;
163161
}
164162
return Derived;
165163
}(Base));

0 commit comments

Comments
 (0)