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

+25-12
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

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

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

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

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

+1-1
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

+4-4
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

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

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

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

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-
return _super.apply(this, arguments) || this;
42+
return _super !== null && _super.apply(this, arguments) || this;
4343
}
4444
return VisualizationModel;
4545
}(Backbone.Model));

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-
return _super.apply(this, arguments) || this;
46+
return _super !== null && _super.apply(this, arguments) || this;
4747
}
4848
return VisualizationModel;
4949
}(Backbone.Model));

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-
return _super.apply(this, arguments) || this;
48+
return _super !== null && _super.apply(this, arguments) || this;
4949
}
5050
return VisualizationModel;
5151
}(Backbone.Model));

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

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-
return _super.apply(this, arguments) || this;
46+
return _super !== null && _super.apply(this, arguments) || this;
4747
}
4848
return VisualizationModel;
4949
}(Backbone.Model));

tests/baselines/reference/aliasUsageInTypeArgumentOfExtendsClause.js

+2-2
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-
return _super.apply(this, arguments) || this;
46+
return _super !== null && _super.apply(this, arguments) || this;
4747
}
4848
return VisualizationModel;
4949
}(Backbone.Model));
@@ -64,7 +64,7 @@ var C = (function () {
6464
var D = (function (_super) {
6565
__extends(D, _super);
6666
function D() {
67-
var _this = _super.apply(this, arguments) || this;
67+
var _this = _super !== null && _super.apply(this, arguments) || this;
6868
_this.x = moduleA;
6969
return _this;
7070
}

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-
return _super.apply(this, arguments) || this;
42+
return _super !== null && _super.apply(this, arguments) || this;
4343
}
4444
return VisualizationModel;
4545
}(Backbone.Model));

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

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-
return _super.apply(this, arguments) || this;
41+
return _super !== null && _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-
return _super.apply(this, arguments) || this;
54+
return _super !== null && _super.apply(this, arguments) || this;
5555
}
5656
return Derived2;
5757
}(Base2));

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-
return _super.apply(this, arguments) || this;
31+
return _super !== null && _super.apply(this, arguments) || this;
3232
}
3333
return Derived;
3434
}(Base));

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-
return _super.apply(this, arguments) || this;
104+
return _super !== null && _super.apply(this, arguments) || this;
105105
}
106106
C2.prototype.C2M1 = function () { return null; };
107107
return C2;

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-
return _super.apply(this, arguments) || this;
78+
return _super !== null && _super.apply(this, arguments) || this;
7979
}
8080
C2.prototype.C2M1 = function () { return null; };
8181
return C2;

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-
return _super.apply(this, arguments) || this;
131+
return _super !== null && _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-
return _super.apply(this, arguments) || this;
190+
return _super !== null && _super.apply(this, arguments) || this;
191191
}
192192
return derived;
193193
}(base));

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-
return _super.apply(this, arguments) || this;
68+
return _super !== null && _super.apply(this, arguments) || this;
6969
}
7070
return ActionA;
7171
}(Action));
7272
var ActionB = (function (_super) {
7373
__extends(ActionB, _super);
7474
function ActionB() {
75-
return _super.apply(this, arguments) || this;
75+
return _super !== null && _super.apply(this, arguments) || this;
7676
}
7777
return ActionB;
7878
}(Action));

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-
return _super.apply(this, arguments) || this;
73+
return _super !== null && _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-
return _super.apply(this, arguments) || this;
81+
return _super !== null && _super.apply(this, arguments) || this;
8282
}
8383
return Derived2;
8484
}(Base));

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-
return _super.apply(this, arguments) || this;
42+
return _super !== null && _super.apply(this, arguments) || this;
4343
}
4444
return DerivedList;
4545
}(List));

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-
return _super.apply(this, arguments) || this;
36+
return _super !== null && _super.apply(this, arguments) || this;
3737
}
3838
return B;
3939
}(A));
4040
var C = (function (_super) {
4141
__extends(C, _super);
4242
function C() {
43-
return _super.apply(this, arguments) || this;
43+
return _super !== null && _super.apply(this, arguments) || this;
4444
}
4545
return C;
4646
}(Array));

0 commit comments

Comments
 (0)