mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Simplify emit for syntactic 'extends null' case
This commit is contained in:
@@ -925,7 +925,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) {
|
||||
@@ -942,7 +945,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(
|
||||
@@ -1011,11 +1014,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);
|
||||
}
|
||||
|
||||
@@ -17,14 +17,12 @@ var __extends = (this && this.__extends) || (function () {
|
||||
var C1 = (function (_super) {
|
||||
__extends(C1, _super);
|
||||
function C1() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return C1;
|
||||
}(null));
|
||||
var C2 = (function (_super) {
|
||||
__extends(C2, _super);
|
||||
function C2() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return C2;
|
||||
}((null)));
|
||||
|
||||
@@ -70,7 +70,6 @@ var C5 = (function (_super) {
|
||||
var C5a = (function (_super) {
|
||||
__extends(C5a, _super);
|
||||
function C5a() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return C5a;
|
||||
}(null));
|
||||
|
||||
@@ -25,7 +25,6 @@ void {};
|
||||
var C5a = (function (_super) {
|
||||
__extends(C5a, _super);
|
||||
function C5a() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return C5a;
|
||||
}(null));
|
||||
|
||||
@@ -26,7 +26,7 @@ var __extends = (this && this.__extends) || (function () {
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this = _super.call(this) || this;
|
||||
return Object.create(null);
|
||||
}
|
||||
return C;
|
||||
@@ -34,7 +34,6 @@ var C = (function (_super) {
|
||||
var D = (function (_super) {
|
||||
__extends(D, _super);
|
||||
function D() {
|
||||
var _this = this;
|
||||
return Object.create(null);
|
||||
}
|
||||
return D;
|
||||
|
||||
@@ -17,7 +17,6 @@ var __extends = (this && this.__extends) || (function () {
|
||||
var ExtendsNull = (function (_super) {
|
||||
__extends(ExtendsNull, _super);
|
||||
function ExtendsNull() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return ExtendsNull;
|
||||
}(null));
|
||||
|
||||
@@ -29,19 +29,16 @@ var __extends = (this && this.__extends) || (function () {
|
||||
var D = (function (_super) {
|
||||
__extends(D, _super);
|
||||
function D() {
|
||||
var _this = this;
|
||||
_this._t;
|
||||
this._t;
|
||||
_this = _super.call(this) || this;
|
||||
return _this;
|
||||
}
|
||||
return D;
|
||||
}(null));
|
||||
var E = (function (_super) {
|
||||
__extends(E, _super);
|
||||
function E() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this._t;
|
||||
return _this;
|
||||
_this = _super.call(this) || this;
|
||||
this._t;
|
||||
}
|
||||
return E;
|
||||
}(null));
|
||||
|
||||
@@ -21,9 +21,7 @@ var __extends = (this && this.__extends) || (function () {
|
||||
var D = (function (_super) {
|
||||
__extends(D, _super);
|
||||
function D() {
|
||||
var _this = this;
|
||||
_this._t; // No error
|
||||
return _this;
|
||||
this._t; // No error
|
||||
}
|
||||
return D;
|
||||
}(null));
|
||||
|
||||
Reference in New Issue
Block a user