Skip to content

Commit c26f402

Browse files
committed
Merge pull request #13277 from Microsoft/fix13276
1 parent f412e10 commit c26f402

File tree

585 files changed

+1227
-1225
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

+1227
-1225
lines changed

src/compiler/transformers/es2015.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,10 @@ namespace ts {
882882

883883
}
884884

885-
const superCaptureStatus = declareOrCaptureOrReturnThisForConstructorIfNeeded(statements, constructor, !!extendsClauseElement, hasSynthesizedSuper, statementOffset);
885+
// determine whether the class is known syntactically to be a derived class (e.g. a
886+
// class that extends a value that is not syntactically known to be `null`).
887+
const isDerivedClass = extendsClauseElement && skipOuterExpressions(extendsClauseElement.expression).kind !== SyntaxKind.NullKeyword;
888+
const superCaptureStatus = declareOrCaptureOrReturnThisForConstructorIfNeeded(statements, constructor, isDerivedClass, hasSynthesizedSuper, statementOffset);
886889

887890
// The last statement expression was replaced. Skip it.
888891
if (superCaptureStatus === SuperCaptureResult.ReplaceSuperCapture || superCaptureStatus === SuperCaptureResult.ReplaceWithReturn) {
@@ -899,7 +902,7 @@ namespace ts {
899902

900903
// Return `_this` unless we're sure enough that it would be pointless to add a return statement.
901904
// If there's a constructor that we can tell returns in enough places, then we *do not* want to add a return.
902-
if (extendsClauseElement
905+
if (isDerivedClass
903906
&& superCaptureStatus !== SuperCaptureResult.ReplaceWithReturn
904907
&& !(constructor && isSufficientlyCoveredByReturnStatements(constructor.body))) {
905908
statements.push(
@@ -963,11 +966,11 @@ namespace ts {
963966
function declareOrCaptureOrReturnThisForConstructorIfNeeded(
964967
statements: Statement[],
965968
ctor: ConstructorDeclaration | undefined,
966-
hasExtendsClause: boolean,
969+
isDerivedClass: boolean,
967970
hasSynthesizedSuper: boolean,
968971
statementOffset: number) {
969972
// If this isn't a derived class, just capture 'this' for arrow functions if necessary.
970-
if (!hasExtendsClause) {
973+
if (!isDerivedClass) {
971974
if (ctor) {
972975
addCaptureThisForNodeIfNeeded(statements, ctor);
973976
}
@@ -1047,7 +1050,7 @@ namespace ts {
10471050
}
10481051

10491052
// Perform the capture.
1050-
captureThisForNode(statements, ctor, superCallExpression, firstStatement);
1053+
captureThisForNode(statements, ctor, superCallExpression || createActualThis(), firstStatement);
10511054

10521055
// If we're actually replacing the original statement, we need to signal this to the caller.
10531056
if (superCallExpression) {
@@ -1057,15 +1060,25 @@ namespace ts {
10571060
return SuperCaptureResult.NoReplacement;
10581061
}
10591062

1063+
function createActualThis() {
1064+
return setEmitFlags(createThis(), EmitFlags.NoSubstitution);
1065+
}
1066+
10601067
function createDefaultSuperCallOrThis() {
1061-
const actualThis = createThis();
1062-
setEmitFlags(actualThis, EmitFlags.NoSubstitution);
1063-
const superCall = createFunctionApply(
1064-
createIdentifier("_super"),
1065-
actualThis,
1066-
createIdentifier("arguments"),
1068+
return createLogicalOr(
1069+
createLogicalAnd(
1070+
createStrictInequality(
1071+
createIdentifier("_super"),
1072+
createNull()
1073+
),
1074+
createFunctionApply(
1075+
createIdentifier("_super"),
1076+
createActualThis(),
1077+
createIdentifier("arguments")
1078+
)
1079+
),
1080+
createActualThis()
10671081
);
1068-
return createLogicalOr(superCall, actualThis);
10691082
}
10701083

10711084
/**

tests/baselines/reference/ExportClassWithAccessibleTypesInTypeParameterConstraintsClassHeritageListMemberTypeAnnotations.js

Lines changed: 1 addition & 1 deletion
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-
return _super.apply(this, arguments) || this;
41+
return _super !== null && _super.apply(this, arguments) || this;
4242
}
4343
return Point3d;
4444
}(Point));

tests/baselines/reference/ExportClassWithInaccessibleTypeInTypeParameterConstraint.js

Lines changed: 1 addition & 1 deletion
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-
return _super.apply(this, arguments) || this;
44+
return _super !== null && _super.apply(this, arguments) || this;
4545
}
4646
return Point3d;
4747
}(Point));

tests/baselines/reference/abstractClassInLocalScope.js

Lines changed: 1 addition & 1 deletion
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-
return _super.apply(this, arguments) || this;
25+
return _super !== null && _super.apply(this, arguments) || this;
2626
}
2727
return B;
2828
}(A));

tests/baselines/reference/abstractClassInLocalScopeIsAbstract.js

Lines changed: 1 addition & 1 deletion
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-
return _super.apply(this, arguments) || this;
25+
return _super !== null && _super.apply(this, arguments) || this;
2626
}
2727
return B;
2828
}(A));

tests/baselines/reference/abstractProperty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var B = (function () {
3535
var C = (function (_super) {
3636
__extends(C, _super);
3737
function C() {
38-
var _this = _super.apply(this, arguments) || this;
38+
var _this = _super !== null && _super.apply(this, arguments) || this;
3939
_this.raw = "edge";
4040
_this.ro = "readonly please";
4141
return _this;

tests/baselines/reference/abstractPropertyNegative.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var B = (function () {
5757
var C = (function (_super) {
5858
__extends(C, _super);
5959
function C() {
60-
var _this = _super.apply(this, arguments) || this;
60+
var _this = _super !== null && _super.apply(this, arguments) || this;
6161
_this.ro = "readonly please";
6262
return _this;
6363
}
@@ -78,7 +78,7 @@ var WrongTypeProperty = (function () {
7878
var WrongTypePropertyImpl = (function (_super) {
7979
__extends(WrongTypePropertyImpl, _super);
8080
function WrongTypePropertyImpl() {
81-
var _this = _super.apply(this, arguments) || this;
81+
var _this = _super !== null && _super.apply(this, arguments) || this;
8282
_this.num = "nope, wrong";
8383
return _this;
8484
}
@@ -92,7 +92,7 @@ var WrongTypeAccessor = (function () {
9292
var WrongTypeAccessorImpl = (function (_super) {
9393
__extends(WrongTypeAccessorImpl, _super);
9494
function WrongTypeAccessorImpl() {
95-
return _super.apply(this, arguments) || this;
95+
return _super !== null && _super.apply(this, arguments) || this;
9696
}
9797
Object.defineProperty(WrongTypeAccessorImpl.prototype, "num", {
9898
get: function () { return "nope, wrong"; },
@@ -104,7 +104,7 @@ var WrongTypeAccessorImpl = (function (_super) {
104104
var WrongTypeAccessorImpl2 = (function (_super) {
105105
__extends(WrongTypeAccessorImpl2, _super);
106106
function WrongTypeAccessorImpl2() {
107-
var _this = _super.apply(this, arguments) || this;
107+
var _this = _super !== null && _super.apply(this, arguments) || this;
108108
_this.num = "nope, wrong";
109109
return _this;
110110
}

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

Lines changed: 1 addition & 1 deletion
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-
return _super.apply(this, arguments) || this;
41+
return _super !== null && _super.apply(this, arguments) || this;
4242
}
4343
return B;
4444
}(A));

tests/baselines/reference/aliasUsageInAccessorsOfClass.js

Lines changed: 1 addition & 1 deletion
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-
return _super.apply(this, arguments) || this;
49+
return _super !== null && _super.apply(this, arguments) || this;
5050
}
5151
return VisualizationModel;
5252
}(Backbone.Model));

tests/baselines/reference/aliasUsageInArray.js

Lines changed: 1 addition & 1 deletion
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-
return _super.apply(this, arguments) || this;
43+
return _super !== null && _super.apply(this, arguments) || this;
4444
}
4545
return VisualizationModel;
4646
}(Backbone.Model));

0 commit comments

Comments
 (0)