Skip to content

Commit 6c29e58

Browse files
committed
Fix super/this capture for extends null
1 parent 700d724 commit 6c29e58

File tree

585 files changed

+1223
-1213
lines changed

Some content is hidden

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

585 files changed

+1223
-1213
lines changed

src/compiler/transformers/es2015.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ namespace ts {
10911091
}
10921092

10931093
// Perform the capture.
1094-
captureThisForNode(statements, ctor, superCallExpression, firstStatement);
1094+
captureThisForNode(statements, ctor, superCallExpression || createActualThis(), firstStatement);
10951095

10961096
// If we're actually replacing the original statement, we need to signal this to the caller.
10971097
if (superCallExpression) {
@@ -1101,15 +1101,25 @@ namespace ts {
11011101
return SuperCaptureResult.NoReplacement;
11021102
}
11031103

1104+
function createActualThis() {
1105+
return setEmitFlags(createThis(), EmitFlags.NoSubstitution);
1106+
}
1107+
11041108
function createDefaultSuperCallOrThis() {
1105-
const actualThis = createThis();
1106-
setEmitFlags(actualThis, EmitFlags.NoSubstitution);
1107-
const superCall = createFunctionApply(
1108-
createIdentifier("_super"),
1109-
actualThis,
1110-
createIdentifier("arguments"),
1109+
return createLogicalOr(
1110+
createLogicalAnd(
1111+
createStrictInequality(
1112+
createIdentifier("_super"),
1113+
createNull()
1114+
),
1115+
createFunctionApply(
1116+
createIdentifier("_super"),
1117+
createActualThis(),
1118+
createIdentifier("arguments"),
1119+
)
1120+
),
1121+
createActualThis()
11111122
);
1112-
return createLogicalOr(superCall, actualThis);
11131123
}
11141124

11151125
/**

tests/baselines/reference/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var A;
4343
var Point3d = (function (_super) {
4444
__extends(Point3d, _super);
4545
function Point3d() {
46-
return _super.apply(this, arguments) || this;
46+
return _super !== null && _super.apply(this, arguments) || this;
4747
}
4848
return Point3d;
4949
}(Point));

tests/baselines/reference/ExportClassWithInaccessibleTypeInTypeParameterConstraint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var A;
4646
var Point3d = (function (_super) {
4747
__extends(Point3d, _super);
4848
function Point3d() {
49-
return _super.apply(this, arguments) || this;
49+
return _super !== null && _super.apply(this, arguments) || this;
5050
}
5151
return Point3d;
5252
}(Point));

tests/baselines/reference/abstractClassInLocalScope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var __extends = (this && this.__extends) || (function () {
2727
var B = (function (_super) {
2828
__extends(B, _super);
2929
function B() {
30-
return _super.apply(this, arguments) || this;
30+
return _super !== null && _super.apply(this, arguments) || this;
3131
}
3232
return B;
3333
}(A));

tests/baselines/reference/abstractClassInLocalScopeIsAbstract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var __extends = (this && this.__extends) || (function () {
2727
var B = (function (_super) {
2828
__extends(B, _super);
2929
function B() {
30-
return _super.apply(this, arguments) || this;
30+
return _super !== null && _super.apply(this, arguments) || this;
3131
}
3232
return B;
3333
}(A));

tests/baselines/reference/abstractProperty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var B = (function () {
4040
var C = (function (_super) {
4141
__extends(C, _super);
4242
function C() {
43-
var _this = _super.apply(this, arguments) || this;
43+
var _this = _super !== null && _super.apply(this, arguments) || this;
4444
_this.raw = "edge";
4545
_this.ro = "readonly please";
4646
return _this;

tests/baselines/reference/abstractPropertyNegative.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var B = (function () {
6262
var C = (function (_super) {
6363
__extends(C, _super);
6464
function C() {
65-
var _this = _super.apply(this, arguments) || this;
65+
var _this = _super !== null && _super.apply(this, arguments) || this;
6666
_this.ro = "readonly please";
6767
return _this;
6868
}
@@ -83,7 +83,7 @@ var WrongTypeProperty = (function () {
8383
var WrongTypePropertyImpl = (function (_super) {
8484
__extends(WrongTypePropertyImpl, _super);
8585
function WrongTypePropertyImpl() {
86-
var _this = _super.apply(this, arguments) || this;
86+
var _this = _super !== null && _super.apply(this, arguments) || this;
8787
_this.num = "nope, wrong";
8888
return _this;
8989
}
@@ -97,7 +97,7 @@ var WrongTypeAccessor = (function () {
9797
var WrongTypeAccessorImpl = (function (_super) {
9898
__extends(WrongTypeAccessorImpl, _super);
9999
function WrongTypeAccessorImpl() {
100-
return _super.apply(this, arguments) || this;
100+
return _super !== null && _super.apply(this, arguments) || this;
101101
}
102102
Object.defineProperty(WrongTypeAccessorImpl.prototype, "num", {
103103
get: function () { return "nope, wrong"; },
@@ -109,7 +109,7 @@ var WrongTypeAccessorImpl = (function (_super) {
109109
var WrongTypeAccessorImpl2 = (function (_super) {
110110
__extends(WrongTypeAccessorImpl2, _super);
111111
function WrongTypeAccessorImpl2() {
112-
var _this = _super.apply(this, arguments) || this;
112+
var _this = _super !== null && _super.apply(this, arguments) || this;
113113
_this.num = "nope, wrong";
114114
return _this;
115115
}

tests/baselines/reference/accessors_spec_section-4.5_inference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var A = (function () {
4343
var B = (function (_super) {
4444
__extends(B, _super);
4545
function B() {
46-
return _super.apply(this, arguments) || this;
46+
return _super !== null && _super.apply(this, arguments) || this;
4747
}
4848
return B;
4949
}(A));

tests/baselines/reference/aliasUsageInAccessorsOfClass.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var Backbone = require("./aliasUsage1_backbone");
5151
var VisualizationModel = (function (_super) {
5252
__extends(VisualizationModel, _super);
5353
function VisualizationModel() {
54-
return _super.apply(this, arguments) || this;
54+
return _super !== null && _super.apply(this, arguments) || this;
5555
}
5656
return VisualizationModel;
5757
}(Backbone.Model));

tests/baselines/reference/aliasUsageInArray.js

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

0 commit comments

Comments
 (0)