Skip to content

Commit

Permalink
Merge pull request #13277 from Microsoft/fix13276
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Jan 5, 2017
1 parent f412e10 commit c26f402
Show file tree
Hide file tree
Showing 585 changed files with 1,227 additions and 1,225 deletions.
37 changes: 25 additions & 12 deletions src/compiler/transformers/es2015.ts
Expand Up @@ -882,7 +882,10 @@ namespace ts {

}

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

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

// Return `_this` unless we're sure enough that it would be pointless to add a return statement.
// If there's a constructor that we can tell returns in enough places, then we *do not* want to add a return.
if (extendsClauseElement
if (isDerivedClass
&& superCaptureStatus !== SuperCaptureResult.ReplaceWithReturn
&& !(constructor && isSufficientlyCoveredByReturnStatements(constructor.body))) {
statements.push(
Expand Down Expand Up @@ -963,11 +966,11 @@ namespace ts {
function declareOrCaptureOrReturnThisForConstructorIfNeeded(
statements: Statement[],
ctor: ConstructorDeclaration | undefined,
hasExtendsClause: boolean,
isDerivedClass: boolean,
hasSynthesizedSuper: boolean,
statementOffset: number) {
// If this isn't a derived class, just capture 'this' for arrow functions if necessary.
if (!hasExtendsClause) {
if (!isDerivedClass) {
if (ctor) {
addCaptureThisForNodeIfNeeded(statements, ctor);
}
Expand Down Expand Up @@ -1047,7 +1050,7 @@ namespace ts {
}

// Perform the capture.
captureThisForNode(statements, ctor, superCallExpression, firstStatement);
captureThisForNode(statements, ctor, superCallExpression || createActualThis(), firstStatement);

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

function createActualThis() {
return setEmitFlags(createThis(), EmitFlags.NoSubstitution);
}

function createDefaultSuperCallOrThis() {
const actualThis = createThis();
setEmitFlags(actualThis, EmitFlags.NoSubstitution);
const superCall = createFunctionApply(
createIdentifier("_super"),
actualThis,
createIdentifier("arguments"),
return createLogicalOr(
createLogicalAnd(
createStrictInequality(
createIdentifier("_super"),
createNull()
),
createFunctionApply(
createIdentifier("_super"),
createActualThis(),
createIdentifier("arguments")
)
),
createActualThis()
);
return createLogicalOr(superCall, actualThis);
}

/**
Expand Down
Expand Up @@ -38,7 +38,7 @@ var A;
var Point3d = (function (_super) {
__extends(Point3d, _super);
function Point3d() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return Point3d;
}(Point));
Expand Down
Expand Up @@ -41,7 +41,7 @@ var A;
var Point3d = (function (_super) {
__extends(Point3d, _super);
function Point3d() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return Point3d;
}(Point));
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/abstractClassInLocalScope.js
Expand Up @@ -22,7 +22,7 @@ var __extends = (this && this.__extends) || function (d, b) {
var B = (function (_super) {
__extends(B, _super);
function B() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return B;
}(A));
Expand Down
Expand Up @@ -22,7 +22,7 @@ var __extends = (this && this.__extends) || function (d, b) {
var B = (function (_super) {
__extends(B, _super);
function B() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return B;
}(A));
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/abstractProperty.js
Expand Up @@ -35,7 +35,7 @@ var B = (function () {
var C = (function (_super) {
__extends(C, _super);
function C() {
var _this = _super.apply(this, arguments) || this;
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.raw = "edge";
_this.ro = "readonly please";
return _this;
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/abstractPropertyNegative.js
Expand Up @@ -57,7 +57,7 @@ var B = (function () {
var C = (function (_super) {
__extends(C, _super);
function C() {
var _this = _super.apply(this, arguments) || this;
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.ro = "readonly please";
return _this;
}
Expand All @@ -78,7 +78,7 @@ var WrongTypeProperty = (function () {
var WrongTypePropertyImpl = (function (_super) {
__extends(WrongTypePropertyImpl, _super);
function WrongTypePropertyImpl() {
var _this = _super.apply(this, arguments) || this;
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.num = "nope, wrong";
return _this;
}
Expand All @@ -92,7 +92,7 @@ var WrongTypeAccessor = (function () {
var WrongTypeAccessorImpl = (function (_super) {
__extends(WrongTypeAccessorImpl, _super);
function WrongTypeAccessorImpl() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(WrongTypeAccessorImpl.prototype, "num", {
get: function () { return "nope, wrong"; },
Expand All @@ -104,7 +104,7 @@ var WrongTypeAccessorImpl = (function (_super) {
var WrongTypeAccessorImpl2 = (function (_super) {
__extends(WrongTypeAccessorImpl2, _super);
function WrongTypeAccessorImpl2() {
var _this = _super.apply(this, arguments) || this;
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.num = "nope, wrong";
return _this;
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ var A = (function () {
var B = (function (_super) {
__extends(B, _super);
function B() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return B;
}(A));
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasUsageInAccessorsOfClass.js
Expand Up @@ -46,7 +46,7 @@ var Backbone = require("./aliasUsage1_backbone");
var VisualizationModel = (function (_super) {
__extends(VisualizationModel, _super);
function VisualizationModel() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return VisualizationModel;
}(Backbone.Model));
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasUsageInArray.js
Expand Up @@ -40,7 +40,7 @@ var Backbone = require("./aliasUsageInArray_backbone");
var VisualizationModel = (function (_super) {
__extends(VisualizationModel, _super);
function VisualizationModel() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return VisualizationModel;
}(Backbone.Model));
Expand Down
Expand Up @@ -39,7 +39,7 @@ var Backbone = require("./aliasUsageInFunctionExpression_backbone");
var VisualizationModel = (function (_super) {
__extends(VisualizationModel, _super);
function VisualizationModel() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return VisualizationModel;
}(Backbone.Model));
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasUsageInGenericFunction.js
Expand Up @@ -43,7 +43,7 @@ var Backbone = require("./aliasUsageInGenericFunction_backbone");
var VisualizationModel = (function (_super) {
__extends(VisualizationModel, _super);
function VisualizationModel() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return VisualizationModel;
}(Backbone.Model));
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasUsageInIndexerOfClass.js
Expand Up @@ -45,7 +45,7 @@ var Backbone = require("./aliasUsageInIndexerOfClass_backbone");
var VisualizationModel = (function (_super) {
__extends(VisualizationModel, _super);
function VisualizationModel() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return VisualizationModel;
}(Backbone.Model));
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasUsageInObjectLiteral.js
Expand Up @@ -40,7 +40,7 @@ var Backbone = require("./aliasUsageInObjectLiteral_backbone");
var VisualizationModel = (function (_super) {
__extends(VisualizationModel, _super);
function VisualizationModel() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return VisualizationModel;
}(Backbone.Model));
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasUsageInOrExpression.js
Expand Up @@ -43,7 +43,7 @@ var Backbone = require("./aliasUsageInOrExpression_backbone");
var VisualizationModel = (function (_super) {
__extends(VisualizationModel, _super);
function VisualizationModel() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return VisualizationModel;
}(Backbone.Model));
Expand Down
Expand Up @@ -43,7 +43,7 @@ var Backbone = require("./aliasUsageInTypeArgumentOfExtendsClause_backbone");
var VisualizationModel = (function (_super) {
__extends(VisualizationModel, _super);
function VisualizationModel() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return VisualizationModel;
}(Backbone.Model));
Expand All @@ -64,7 +64,7 @@ var C = (function () {
var D = (function (_super) {
__extends(D, _super);
function D() {
var _this = _super.apply(this, arguments) || this;
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.x = moduleA;
return _this;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasUsageInVarAssignment.js
Expand Up @@ -39,7 +39,7 @@ var Backbone = require("./aliasUsageInVarAssignment_backbone");
var VisualizationModel = (function (_super) {
__extends(VisualizationModel, _super);
function VisualizationModel() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return VisualizationModel;
}(Backbone.Model));
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/ambiguousOverloadResolution.js
Expand Up @@ -22,7 +22,7 @@ var A = (function () {
var B = (function (_super) {
__extends(B, _super);
function B() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return B;
}(A));
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/apparentTypeSubtyping.js
Expand Up @@ -38,7 +38,7 @@ var Base = (function () {
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return Derived;
}(Base));
Expand All @@ -51,7 +51,7 @@ var Base2 = (function () {
var Derived2 = (function (_super) {
__extends(Derived2, _super);
function Derived2() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return Derived2;
}(Base2));
2 changes: 1 addition & 1 deletion tests/baselines/reference/apparentTypeSupertype.js
Expand Up @@ -28,7 +28,7 @@ var Base = (function () {
var Derived = (function (_super) {
__extends(Derived, _super);
function Derived() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return Derived;
}(Base));
2 changes: 1 addition & 1 deletion tests/baselines/reference/arrayAssignmentTest1.js
Expand Up @@ -101,7 +101,7 @@ var C1 = (function () {
var C2 = (function (_super) {
__extends(C2, _super);
function C2() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
C2.prototype.C2M1 = function () { return null; };
return C2;
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/arrayAssignmentTest2.js
Expand Up @@ -75,7 +75,7 @@ var C1 = (function () {
var C2 = (function (_super) {
__extends(C2, _super);
function C2() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
C2.prototype.C2M1 = function () { return null; };
return C2;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayBestCommonTypes.js
Expand Up @@ -128,7 +128,7 @@ var EmptyTypes;
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return derived;
}(base));
Expand Down Expand Up @@ -187,7 +187,7 @@ var NonEmptyTypes;
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return derived;
}(base));
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayLiteralTypeInference.js
Expand Up @@ -65,14 +65,14 @@ var Action = (function () {
var ActionA = (function (_super) {
__extends(ActionA, _super);
function ActionA() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return ActionA;
}(Action));
var ActionB = (function (_super) {
__extends(ActionB, _super);
function ActionB() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return ActionB;
}(Action));
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayLiterals.js
Expand Up @@ -70,15 +70,15 @@ var Base = (function () {
var Derived1 = (function (_super) {
__extends(Derived1, _super);
function Derived1() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return Derived1;
}(Base));
;
var Derived2 = (function (_super) {
__extends(Derived2, _super);
function Derived2() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return Derived2;
}(Base));
Expand Down
Expand Up @@ -39,7 +39,7 @@ var List = (function () {
var DerivedList = (function (_super) {
__extends(DerivedList, _super);
function DerivedList() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return DerivedList;
}(List));
Expand Down
Expand Up @@ -33,14 +33,14 @@ var A = (function () {
var B = (function (_super) {
__extends(B, _super);
function B() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return B;
}(A));
var C = (function (_super) {
__extends(C, _super);
function C() {
return _super.apply(this, arguments) || this;
return _super !== null && _super.apply(this, arguments) || this;
}
return C;
}(Array));
Expand Down

0 comments on commit c26f402

Please sign in to comment.