More reliable mechanism for _this/_super simplification (#56130)

This commit is contained in:
Ron Buckton
2023-10-23 21:01:11 -04:00
committed by GitHub
parent e5e7cbba79
commit 8e37e4b853
38 changed files with 770 additions and 350 deletions
+22
View File
@@ -1,5 +1,6 @@
import {
__String,
AccessorDeclaration,
addRange,
append,
appendIfUnique,
@@ -1180,6 +1181,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
mergeLexicalEnvironment,
replaceModifiers,
replaceDecoratorsAndModifiers,
replacePropertyName,
};
forEach(nodeFactoryPatchers, fn => fn(factory));
@@ -7149,6 +7151,26 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
Debug.assertNever(node);
}
function replacePropertyName<T extends AccessorDeclaration | MethodDeclaration | MethodSignature | PropertyDeclaration | PropertySignature | PropertyAssignment>(node: T, name: T["name"]): T;
function replacePropertyName(node: AccessorDeclaration | MethodDeclaration | MethodSignature | PropertyDeclaration | PropertySignature | PropertyAssignment, name: PropertyName) {
switch (node.kind) {
case SyntaxKind.GetAccessor:
return updateGetAccessorDeclaration(node, node.modifiers, name, node.parameters, node.type, node.body);
case SyntaxKind.SetAccessor:
return updateSetAccessorDeclaration(node, node.modifiers, name, node.parameters, node.body);
case SyntaxKind.MethodDeclaration:
return updateMethodDeclaration(node, node.modifiers, node.asteriskToken, name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body);
case SyntaxKind.MethodSignature:
return updateMethodSignature(node, node.modifiers, name, node.questionToken, node.typeParameters, node.parameters, node.type);
case SyntaxKind.PropertyDeclaration:
return updatePropertyDeclaration(node, node.modifiers, name, node.questionToken ?? node.exclamationToken, node.type, node.initializer);
case SyntaxKind.PropertySignature:
return updatePropertySignature(node, node.modifiers, name, node.questionToken, node.type);
case SyntaxKind.PropertyAssignment:
return updatePropertyAssignment(node, name, node.initializer);
}
}
function asNodeArray<T extends Node>(array: readonly T[]): NodeArray<T>;
function asNodeArray<T extends Node>(array: readonly T[] | undefined): NodeArray<T> | undefined;
function asNodeArray<T extends Node>(array: readonly T[] | undefined): NodeArray<T> | undefined {
File diff suppressed because it is too large Load Diff
+4
View File
@@ -9080,6 +9080,10 @@ export interface NodeFactory {
* Updates a node that may contain decorators or modifiers, replacing only the decorators and modifiers of the node.
*/
replaceDecoratorsAndModifiers<T extends HasModifiers & HasDecorators>(node: T, modifiers: readonly ModifierLike[] | undefined): T;
/**
* Updates a node that contains a property name, replacing only the name of the node.
*/
replacePropertyName<T extends AccessorDeclaration | MethodDeclaration | MethodSignature | PropertyDeclaration | PropertySignature | PropertyAssignment>(node: T, name: T["name"]): T;
}
/** @internal */
+4
View File
@@ -8394,6 +8394,10 @@ declare namespace ts {
* Updates a node that may contain decorators or modifiers, replacing only the decorators and modifiers of the node.
*/
replaceDecoratorsAndModifiers<T extends HasModifiers & HasDecorators>(node: T, modifiers: readonly ModifierLike[] | undefined): T;
/**
* Updates a node that contains a property name, replacing only the name of the node.
*/
replacePropertyName<T extends AccessorDeclaration | MethodDeclaration | MethodSignature | PropertyDeclaration | PropertySignature | PropertyAssignment>(node: T, name: T["name"]): T;
}
interface CoreTransformationContext {
readonly factory: NodeFactory;
+1 -2
View File
@@ -136,8 +136,7 @@ var D = /** @class */ (function (_super) {
__extends(D, _super);
function D() {
var _this = _super.call(this, 1, 2) || this;
_this = _super.apply(this, __spreadArray([1, 2], a, false)) || this;
return _this;
return _super.apply(this, __spreadArray([1, 2], a, false)) || this;
}
D.prototype.foo = function () {
_super.prototype.foo.call(this, 1, 2);
@@ -42,8 +42,7 @@ var Super = /** @class */ (function (_super) {
function Super() {
var _this = this;
(function () { return _this; }); // No Error
_this = _super.call(this) || this;
return _this;
return _this = _super.call(this) || this;
}
return Super;
}(Base));
@@ -35,7 +35,7 @@ var Base = /** @class */ (function () {
var Super = /** @class */ (function (_super) {
__extends(Super, _super);
function Super() {
var _this = _super.call(this, (function () { return _this; })) || this;
var _this = _super.call(this, (function () { return _this; })) || this; // No error
return _this;
}
return Super;
@@ -42,8 +42,7 @@ var Super = /** @class */ (function (_super) {
function Super() {
var _this = this;
var that = _this;
_this = _super.call(this) || this;
return _this;
return _this = _super.call(this) || this;
}
return Super;
}(Base));
@@ -208,7 +208,7 @@ var I = /** @class */ (function (_super) {
var J = /** @class */ (function (_super) {
__extends(J, _super);
function J(p1) {
var _this = _super.call(this) || this;
var _this = _super.call(this) || this; // NO ERROR
_this.p1 = p1;
return _this;
}
@@ -228,7 +228,7 @@ var K = /** @class */ (function (_super) {
var L = /** @class */ (function (_super) {
__extends(L, _super);
function L(p1) {
var _this = _super.call(this) || this;
var _this = _super.call(this) || this; // NO ERROR
_this.p1 = p1;
return _this;
}
@@ -1,3 +1,3 @@
//// [derivedClassConstructorWithExplicitReturns01.js.map]
{"version":3,"file":"derivedClassConstructorWithExplicitReturns01.js","sourceRoot":"","sources":["derivedClassConstructorWithExplicitReturns01.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;IAKI,WAAY,KAAa;QAJzB,UAAK,GAAG,EAAE,CAAC;QAKP,OAAO;YACH,KAAK,EAAE,KAAK;YACZ,GAAG;gBACC,OAAO,8BAA8B,CAAC;YAC1C,CAAC;SACJ,CAAA;IACL,CAAC;IATD,eAAG,GAAH,cAAQ,OAAO,uBAAuB,CAAC,CAAC,CAAC;IAU7C,QAAC;AAAD,CAAC,AAbD,IAaC;AAED;IAAgB,qBAAC;IAGb,WAAY,CAAO;QAAP,kBAAA,EAAA,OAAO;QAAnB,YACI,kBAAM,CAAC,CAAC,SAYX;QAfD,WAAK,GAAG,cAAM,OAAA,KAAI,EAAJ,CAAI,CAAC;QAKf,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC;YACtB,UAAU,CAAA;YACV,OAAO;gBACH,KAAK,EAAE,CAAC;gBACR,KAAK,EAAE,cAAM,OAAA,KAAI,EAAJ,CAAI;gBACjB,GAAG,gBAAK,OAAO,cAAc,CAAA,CAAC,CAAC;aAClC,CAAC;QACN,CAAC;;YAEG,OAAO,IAAI,CAAC;IACpB,CAAC;IACL,QAAC;AAAD,CAAC,AAjBD,CAAgB,CAAC,GAiBhB"}
//// https://sokra.github.io/source-map-visualization#base64,dmFyIF9fZXh0ZW5kcyA9ICh0aGlzICYmIHRoaXMuX19leHRlbmRzKSB8fCAoZnVuY3Rpb24gKCkgew0KICAgIHZhciBleHRlbmRTdGF0aWNzID0gZnVuY3Rpb24gKGQsIGIpIHsNCiAgICAgICAgZXh0ZW5kU3RhdGljcyA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiB8fA0KICAgICAgICAgICAgKHsgX19wcm90b19fOiBbXSB9IGluc3RhbmNlb2YgQXJyYXkgJiYgZnVuY3Rpb24gKGQsIGIpIHsgZC5fX3Byb3RvX18gPSBiOyB9KSB8fA0KICAgICAgICAgICAgZnVuY3Rpb24gKGQsIGIpIHsgZm9yICh2YXIgcCBpbiBiKSBpZiAoT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKGIsIHApKSBkW3BdID0gYltwXTsgfTsNCiAgICAgICAgcmV0dXJuIGV4dGVuZFN0YXRpY3MoZCwgYik7DQogICAgfTsNCiAgICByZXR1cm4gZnVuY3Rpb24gKGQsIGIpIHsNCiAgICAgICAgaWYgKHR5cGVvZiBiICE9PSAiZnVuY3Rpb24iICYmIGIgIT09IG51bGwpDQogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJDbGFzcyBleHRlbmRzIHZhbHVlICIgKyBTdHJpbmcoYikgKyAiIGlzIG5vdCBhIGNvbnN0cnVjdG9yIG9yIG51bGwiKTsNCiAgICAgICAgZXh0ZW5kU3RhdGljcyhkLCBiKTsNCiAgICAgICAgZnVuY3Rpb24gX18oKSB7IHRoaXMuY29uc3RydWN0b3IgPSBkOyB9DQogICAgICAgIGQucHJvdG90eXBlID0gYiA9PT0gbnVsbCA/IE9iamVjdC5jcmVhdGUoYikgOiAoX18ucHJvdG90eXBlID0gYi5wcm90b3R5cGUsIG5ldyBfXygpKTsNCiAgICB9Ow0KfSkoKTsNCnZhciBDID0gLyoqIEBjbGFzcyAqLyAoZnVuY3Rpb24gKCkgew0KICAgIGZ1bmN0aW9uIEModmFsdWUpIHsNCiAgICAgICAgdGhpcy5jUHJvcCA9IDEwOw0KICAgICAgICByZXR1cm4gew0KICAgICAgICAgICAgY1Byb3A6IHZhbHVlLA0KICAgICAgICAgICAgZm9vOiBmdW5jdGlvbiAoKSB7DQogICAgICAgICAgICAgICAgcmV0dXJuICJ3ZWxsIHRoaXMgbG9va3Mga2luZGEgQy1pc2guIjsNCiAgICAgICAgICAgIH0NCiAgICAgICAgfTsNCiAgICB9DQogICAgQy5wcm90b3R5cGUuZm9vID0gZnVuY3Rpb24gKCkgeyByZXR1cm4gInRoaXMgbmV2ZXIgZ2V0cyB1c2VkLiI7IH07DQogICAgcmV0dXJuIEM7DQp9KCkpOw0KdmFyIEQgPSAvKiogQGNsYXNzICovIChmdW5jdGlvbiAoX3N1cGVyKSB7DQogICAgX19leHRlbmRzKEQsIF9zdXBlcik7DQogICAgZnVuY3Rpb24gRChhKSB7DQogICAgICAgIGlmIChhID09PSB2b2lkIDApIHsgYSA9IDEwMDsgfQ0KICAgICAgICB2YXIgX3RoaXMgPSBfc3VwZXIuY2FsbCh0aGlzLCBhKSB8fCB0aGlzOw0KICAgICAgICBfdGhpcy5kUHJvcCA9IGZ1bmN0aW9uICgpIHsgcmV0dXJuIF90aGlzOyB9Ow0KICAgICAgICBpZiAoTWF0aC5yYW5kb20oKSA8IDAuNSkgew0KICAgICAgICAgICAgIllvdSB3aW4hIjsNCiAgICAgICAgICAgIHJldHVybiB7DQogICAgICAgICAgICAgICAgY1Byb3A6IDEsDQogICAgICAgICAgICAgICAgZFByb3A6IGZ1bmN0aW9uICgpIHsgcmV0dXJuIF90aGlzOyB9LA0KICAgICAgICAgICAgICAgIGZvbzogZnVuY3Rpb24gKCkgeyByZXR1cm4gIllvdSB3aW4hISEhISI7IH0NCiAgICAgICAgICAgI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UFBRSxjQUFNLE9BQUEsS0FBSSxFQUFKLENBQUk7Z0JBQ2pCLEdBQUcsZ0JBQUssT0FBTyxjQUFjLENBQUEsQ0FBQyxDQUFDO2FBQ2xDLENBQUM7UUFDTixDQUFDOztZQUVHLE9BQU8sSUFBSSxDQUFDO0lBQ3BCLENBQUM7SUFDTCxRQUFDO0FBQUQsQ0FBQyxBQWpCRCxDQUFnQixDQUFDLEdBaUJoQiJ9,Y2xhc3MgQyB7CiAgICBjUHJvcCA9IDEwOwoKICAgIGZvbygpIHsgcmV0dXJuICJ0aGlzIG5ldmVyIGdldHMgdXNlZC4iOyB9CgogICAgY29uc3RydWN0b3IodmFsdWU6IG51bWJlcikgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICAgIGNQcm9wOiB2YWx1ZSwKICAgICAgICAgICAgZm9vKCkgewogICAgICAgICAgICAgICAgcmV0dXJuICJ3ZWxsIHRoaXMgbG9va3Mga2luZGEgQy1pc2guIjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQoKY2xhc3MgRCBleHRlbmRzIEMgewogICAgZFByb3AgPSAoKSA9PiB0aGlzOwoKICAgIGNvbnN0cnVjdG9yKGEgPSAxMDApIHsKICAgICAgICBzdXBlcihhKTsKCiAgICAgICAgaWYgKE1hdGgucmFuZG9tKCkgPCAwLjUpIHsKICAgICAgICAgICAgIllvdSB3aW4hIgogICAgICAgICAgICByZXR1cm4gewogICAgICAgICAgICAgICAgY1Byb3A6IDEsCiAgICAgICAgICAgICAgICBkUHJvcDogKCkgPT4gdGhpcywKICAgICAgICAgICAgICAgIGZvbygpIHsgcmV0dXJuICJZb3Ugd2luISEhISEiIH0KICAgICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgIH0KfQ==
{"version":3,"file":"derivedClassConstructorWithExplicitReturns01.js","sourceRoot":"","sources":["derivedClassConstructorWithExplicitReturns01.ts"],"names":[],"mappings":";;;;;;;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ZWxsIHRoaXMgbG9va3Mga2luZGEgQy1pc2guIjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQoKY2xhc3MgRCBleHRlbmRzIEMgewogICAgZFByb3AgPSAoKSA9PiB0aGlzOwoKICAgIGNvbnN0cnVjdG9yKGEgPSAxMDApIHsKICAgICAgICBzdXBlcihhKTsKCiAgICAgICAgaWYgKE1hdGgucmFuZG9tKCkgPCAwLjUpIHsKICAgICAgICAgICAgIllvdSB3aW4hIgogICAgICAgICAgICByZXR1cm4gewogICAgICAgICAgICAgICAgY1Byb3A6IDEsCiAgICAgICAgICAgICAgICBkUHJvcDogKCkgPT4gdGhpcywKICAgICAgICAgICAgICAgIGZvbygpIHsgcmV0dXJuICJZb3Ugd2luISEhISEiIH0KICAgICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgIH0KfQ==
@@ -270,36 +270,27 @@ sourceFile:derivedClassConstructorWithExplicitReturns01.ts
>>> var _this = _super.call(this, a) || this;
1->^^^^^^^^
2 > ^^^^^^^^^^^^
3 > ^^^^^^^^^^^^^^^^^^
4 > ^
5 > ^
6 > ^^^^^^^^^
7 > ^^^^->
1->
2 > constructor(a = 100) {
>
3 > super(
4 > a
5 > )
6 > ;
>
> if (Math.random() < 0.5) {
> "You win!"
> return {
> cProp: 1,
> dProp: () => this,
> foo() { return "You win!!!!!" }
> };
> }
> else
> return null;
> }
1->Emitted(33, 9) Source(19, 5) + SourceIndex(0)
3 > ^^^^^^
4 > ^^^^^^^^^^^^
5 > ^
6 > ^
7 > ^^^^^^^^^
8 > ^^^^->
1->) {
>
2 >
3 > super
4 > (
5 > a
6 > )
7 > ;
1->Emitted(33, 9) Source(20, 9) + SourceIndex(0)
2 >Emitted(33, 21) Source(20, 9) + SourceIndex(0)
3 >Emitted(33, 39) Source(20, 15) + SourceIndex(0)
4 >Emitted(33, 40) Source(20, 16) + SourceIndex(0)
5 >Emitted(33, 41) Source(20, 17) + SourceIndex(0)
6 >Emitted(33, 50) Source(32, 6) + SourceIndex(0)
3 >Emitted(33, 27) Source(20, 14) + SourceIndex(0)
4 >Emitted(33, 39) Source(20, 15) + SourceIndex(0)
5 >Emitted(33, 40) Source(20, 16) + SourceIndex(0)
6 >Emitted(33, 41) Source(20, 17) + SourceIndex(0)
7 >Emitted(33, 50) Source(20, 18) + SourceIndex(0)
---
>>> _this.dProp = function () { return _this; };
1->^^^^^^^^
@@ -174,8 +174,7 @@ var Derived6 = /** @class */ (function (_super) {
var _this = this;
_this.a = 1;
var b = 2;
_this = _super.call(this) || this;
return _this;
return _this = _super.call(this) || this;
}
return Derived6;
}(Base));
@@ -54,7 +54,7 @@ var Base = /** @class */ (function () {
var Derived = /** @class */ (function (_super) {
__extends(Derived, _super);
function Derived() {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // ok
return _this;
}
return Derived;
@@ -62,7 +62,7 @@ var Derived = /** @class */ (function (_super) {
var Derived2 = /** @class */ (function (_super) {
__extends(Derived2, _super);
function Derived2(a) {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // error
_this.a = a;
return _this;
}
@@ -71,7 +71,7 @@ var Derived2 = /** @class */ (function (_super) {
var Derived3 = /** @class */ (function (_super) {
__extends(Derived3, _super);
function Derived3(a) {
var _this = _super.call(this, function () { return _this; }) || this;
var _this = _super.call(this, function () { return _this; }) || this; // error
_this.a = a;
return _this;
}
@@ -80,7 +80,7 @@ var Derived3 = /** @class */ (function (_super) {
var Derived4 = /** @class */ (function (_super) {
__extends(Derived4, _super);
function Derived4(a) {
var _this = _super.call(this, function () { return this; }) || this;
var _this = _super.call(this, function () { return this; }) || this; // ok
_this.a = a;
return _this;
}
@@ -638,7 +638,7 @@ var DerivedWithFunctionExpression = /** @class */ (function (_super) {
var DerivedWithParenthesis = /** @class */ (function (_super) {
__extends(DerivedWithParenthesis, _super);
function DerivedWithParenthesis() {
var _this = _super.call(this) || this;
var _this = (_this = _super.call(this) || this);
_this.prop = true;
return _this;
}
@@ -649,7 +649,7 @@ var DerivedWithParenthesisAfterStatement = /** @class */ (function (_super) {
function DerivedWithParenthesisAfterStatement() {
var _this = this;
_this.prop;
_this = _super.call(this) || this;
(_this = _super.call(this) || this);
_this.prop = true;
return _this;
}
@@ -658,7 +658,7 @@ var DerivedWithParenthesisAfterStatement = /** @class */ (function (_super) {
var DerivedWithParenthesisBeforeStatement = /** @class */ (function (_super) {
__extends(DerivedWithParenthesisBeforeStatement, _super);
function DerivedWithParenthesisBeforeStatement() {
var _this = _super.call(this) || this;
var _this = (_this = _super.call(this) || this);
_this.prop = true;
_this.prop;
return _this;
@@ -126,8 +126,8 @@ var DerivedBasic = /** @class */ (function (_super) {
var DerivedAfterParameterDefault = /** @class */ (function (_super) {
__extends(DerivedAfterParameterDefault, _super);
function DerivedAfterParameterDefault(x) {
var _this = this;
if (x === void 0) { x = false; }
var _this = this;
_this.x1 = x;
_this = _super.call(this, x) || this;
_this.x2 = x;
@@ -138,11 +138,11 @@ var DerivedAfterParameterDefault = /** @class */ (function (_super) {
var DerivedAfterRestParameter = /** @class */ (function (_super) {
__extends(DerivedAfterRestParameter, _super);
function DerivedAfterRestParameter() {
var _this = this;
var x = [];
for (var _i = 0; _i < arguments.length; _i++) {
x[_i] = arguments[_i];
}
var _this = this;
_this.x1 = x;
_this = _super.call(this, x) || this;
_this.x2 = x;
+1 -2
View File
@@ -146,8 +146,7 @@ var Derived = /** @class */ (function (_super) {
//super call with type arguments
function Derived() {
var _this = _super.call(this) || this;
_this = _super.call(this) || this;
return _this;
return _super.call(this) || this;
}
return Derived;
}(Base));
@@ -0,0 +1,74 @@
//// [tests/cases/compiler/nestedSuperCallEmit.ts] ////
//// [nestedSuperCallEmit.ts]
// https://github.com/microsoft/TypeScript/issues/55646
abstract class Foo {
constructor(shouldThrow: boolean) {
if (shouldThrow) {
throw new Error('Please retry');
} else {
console.log('OK');
}
}
}
class Bar extends Foo {
constructor() {
try {
super(true);
} catch (e: unknown) {
console.log('Error: ' + (e as Error).message);
// retry
super(false);
}
}
}
new Bar();
//// [nestedSuperCallEmit.js]
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// https://github.com/microsoft/TypeScript/issues/55646
var Foo = /** @class */ (function () {
function Foo(shouldThrow) {
if (shouldThrow) {
throw new Error('Please retry');
}
else {
console.log('OK');
}
}
return Foo;
}());
var Bar = /** @class */ (function (_super) {
__extends(Bar, _super);
function Bar() {
var _this = this;
try {
_this = _super.call(this, true) || this;
}
catch (e) {
console.log('Error: ' + e.message);
// retry
_this = _super.call(this, false) || this;
}
return _this;
}
return Bar;
}(Foo));
new Bar();
@@ -1,3 +1,3 @@
//// [sourceMapValidationClassWithDefaultConstructorAndExtendsClause.js.map]
{"version":3,"file":"sourceMapValidationClassWithDefaultConstructorAndExtendsClause.js","sourceRoot":"","sources":["sourceMapValidationClassWithDefaultConstructorAndExtendsClause.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;IAAA;IACA,CAAC;IAAD,sBAAC;AAAD,CAAC,AADD,IACC;AAED;IAAsB,2BAAe;IAArC;QAAA,qEAGC;QAFU,OAAC,GAAG,EAAE,CAAC;QACP,WAAK,GAAG,KAAK,CAAC;;IACzB,CAAC;IAAD,cAAC;AAAD,CAAC,AAHD,CAAsB,eAAe,GAGpC"}
//// https://sokra.github.io/source-map-visualization#base64,dmFyIF9fZXh0ZW5kcyA9ICh0aGlzICYmIHRoaXMuX19leHRlbmRzKSB8fC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LENBQUM7SUFBRCxjQUFDO0FBQUQsQ0FBQyxBQUhELENBQXNCLGVBQWUsR0FHcEMifQ==,Y2xhc3MgQWJzdHJhY3RHcmVldGVyIHsKfQoKY2xhc3MgR3JlZXRlciBleHRlbmRzIEFic3RyYWN0R3JlZXRlciB7CiAgICBwdWJsaWMgYSA9IDEwOwogICAgcHVibGljIG5hbWVBID0gIlRlbiI7Cn0=
{"version":3,"file":"sourceMapValidationClassWithDefaultConstructorAndExtendsClause.js","sourceRoot":"","sources":["sourceMapValidationClassWithDefaultConstructorAndExtendsClause.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;IAAA;IACA,CAAC;IAAD,sBAAC;AAAD,CAAC,AADD,IACC;AAED;IAAsB,2BAAe;IAArC;;QACW,OAAC,GAAG,EAAE,CAAC;QACP,WAAK,GAAG,KAAK,CAAC;;IACzB,CAAC;IAAD,cAAC;AAAD,CAAC,AAHD,CAAsB,eAAe,GAGpC"}
//// https://sokra.github.io/source-map-visualization#base64,dmFyIF9fZXh0ZW5kcyA9ICh0aGlzICYmIHRoaXMuX19leHRlbmRzKSB8fCAoZnVuY3Rpb24gKCkgew0KICAgIHZhciBleHRlbmRTdGF0aWNzID0gZnVuY3Rpb24gKGQsIGIpIHsNCiAgICAgICAgZXh0ZW5kU3RhdGljcyA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiB8fA0KICAgICAgICAgICAgKHsgX19wcm90b19fOiBbXSB9IGluc3RhbmNlb2YgQXJyYXkgJiYgZnVuY3Rpb24gKGQsIGIpIHsgZC5fX3Byb3RvX18gPSBiOyB9KSB8fA0KICAgICAgICAgICAgZnVuY3Rpb24gKGQsIGIpIHsgZm9yICh2YXIgcCBpbiBiKSBpZiAoT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKGIsIHApKSBkW3BdID0gYltwXTsgfTsNCiAgICAgICAgcmV0dXJuIGV4dGVuZFN0YXRpY3MoZCwgYik7DQogICAgfTsNCiA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HBpbmdVUkw9c291cmNlTWFwVmFsaWRhdGlvbkNsYXNzV2l0aERlZmF1bHRDb25zdHJ1Y3RvckFuZEV4dGVuZHNDbGF1c2UuanMubWFw,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic291cmNlTWFwVmFsaWRhdGlvbkNsYXNzV2l0aERlZmF1bHRDb25zdHJ1Y3RvckFuZEV4dGVuZHNDbGF1c2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJzb3VyY2VNYXBWYWxpZGF0aW9uQ2xhc3NXaXRoRGVmYXVsdENvbnN0cnVjdG9yQW5kRXh0ZW5kc0NsYXVzZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7QUFBQTtJQUFBO0lBQ0EsQ0FBQztJQUFELHNCQUFDO0FBQUQsQ0FBQyxBQURELElBQ0M7QUFFRDtJQUFzQiwyQkFBZTtJQUFyQzs7UUFDVyxPQUFDLEdBQUcsRUFBRSxDQUFDO1FBQ1AsV0FBSyxHQUFHLEtBQUssQ0FBQzs7SUFDekIsQ0FBQztJQUFELGNBQUM7QUFBRCxDQUFDLEFBSEQsQ0FBc0IsZUFBZSxHQUdwQyJ9,Y2xhc3MgQWJzdHJhY3RHcmVldGVyIHsKfQoKY2xhc3MgR3JlZXRlciBleHRlbmRzIEFic3RyYWN0R3JlZXRlciB7CiAgICBwdWJsaWMgYSA9IDEwOwogICAgcHVibGljIG5hbWVBID0gIlRlbiI7Cn0=
@@ -92,29 +92,20 @@ sourceFile:sourceMapValidationClassWithDefaultConstructorAndExtendsClause.ts
1 >Emitted(23, 5) Source(4, 1) + SourceIndex(0)
---
>>> var _this = _super !== null && _super.apply(this, arguments) || this;
1->^^^^^^^^
2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1->
2 > class Greeter extends AbstractGreeter {
> public a = 10;
> public nameA = "Ten";
> }
1->Emitted(24, 9) Source(4, 1) + SourceIndex(0)
2 >Emitted(24, 78) Source(7, 2) + SourceIndex(0)
---
>>> _this.a = 10;
1 >^^^^^^^^
1->^^^^^^^^
2 > ^^^^^^^
3 > ^^^
4 > ^^
5 > ^
6 > ^^^^^^^^->
1 >
1->class Greeter extends AbstractGreeter {
> public
2 > a
3 > =
4 > 10
5 > ;
1 >Emitted(25, 9) Source(5, 12) + SourceIndex(0)
1->Emitted(25, 9) Source(5, 12) + SourceIndex(0)
2 >Emitted(25, 16) Source(5, 13) + SourceIndex(0)
3 >Emitted(25, 19) Source(5, 16) + SourceIndex(0)
4 >Emitted(25, 21) Source(5, 18) + SourceIndex(0)
@@ -97,7 +97,7 @@ var B = /** @class */ (function (_super) {
var C = /** @class */ (function (_super) {
__extends(C, _super);
function C() {
var _this = _super.call(this) || this;
var _this = _super.call(this) || this; // No error
_this.s = 9;
"use strict";
return _this;
@@ -129,7 +129,7 @@ var Bs = /** @class */ (function (_super) {
var Cs = /** @class */ (function (_super) {
__extends(Cs, _super);
function Cs() {
var _this = _super.call(this) || this;
var _this = _super.call(this) || this; // No error
"use strict";
return _this;
}
@@ -52,10 +52,9 @@ var T5 = /** @class */ (function () {
var T6 = /** @class */ (function (_super) {
__extends(T6, _super);
function T6() {
var _this =
// Should error; base constructor has type T for first arg,
// which is instantiated with 'number' in the extends clause
_super.call(this, "hi") || this;
var _this = _super.call(this, "hi") || this;
var x = _this.foo;
return _this;
}
@@ -36,7 +36,7 @@ var Base = /** @class */ (function () {
var D = /** @class */ (function (_super) {
__extends(D, _super);
function D() {
var _this = _super.call(this, function () { _this._t; }) || this;
var _this = _super.call(this, function () { _this._t; }) || this; // no error. only check when this is directly accessing in constructor
return _this;
}
return D;
@@ -43,8 +43,7 @@ var D = /** @class */ (function (_super) {
var x = function () { _this._t; };
x(); // no error; we only check super is called before this when the container is a constructor
_this._t; // error
_this = _super.call(this, undefined) || this;
return _this;
return _this = _super.call(this, undefined) || this;
}
return D;
}(Base));
@@ -38,8 +38,7 @@ var D = /** @class */ (function (_super) {
function D() {
var _this = this;
_this._t;
_this = _super.call(this) || this;
return _this;
return _this = _super.call(this) || this;
}
return D;
}(null));
@@ -43,8 +43,7 @@ var D = /** @class */ (function (_super) {
var x = {
j: _this._t,
};
_this = _super.call(this, undefined) || this;
return _this;
return _this = _super.call(this, undefined) || this;
}
return D;
}(Base));
@@ -13,7 +13,7 @@ class Foo {
//// [superCallFromClassThatHasNoBaseTypeButWithSameSymbolInterface.js]
var Foo = /** @class */ (function () {
function Foo() {
return _super.call(this) || this;
return _super.call(this) || this; // error
}
return Foo;
}());
@@ -16,13 +16,13 @@ class D<T> {
//// [superCallInConstructorWithNoBaseType.js]
var C = /** @class */ (function () {
function C() {
return _super.call(this) || this;
return _super.call(this) || this; // error
}
return C;
}());
var D = /** @class */ (function () {
function D(x) {
var _this = _super.call(this) || this;
var _this = _super.call(this) || this; // error
this.x = x;
return _this;
}
@@ -59,10 +59,9 @@ var CBase = /** @class */ (function () {
var C = /** @class */ (function (_super) {
__extends(C, _super);
function C() {
var _this =
// Should be okay.
// 'p' should have type 'string'.
_super.call(this, {
var _this = _super.call(this, {
method: function (p) {
p.length;
}
@@ -40,7 +40,7 @@ var C = /** @class */ (function () {
var D = /** @class */ (function (_super) {
__extends(D, _super);
function D() {
return _super.call(this) || this;
return _super.call(this) || this; // uses the type parameter type of the base class, ie string
}
return D;
}(C));
@@ -16,13 +16,13 @@ class P {
//// [thisInConstructorParameter2.js]
var P = /** @class */ (function () {
function P(z, zz, zzz) {
var _this = this;
if (z === void 0) { z = this; }
if (zz === void 0) { zz = this; }
if (zzz === void 0) { zzz = function (p) {
if (p === void 0) { p = _this; }
return _this;
}; }
var _this = this;
this.z = z;
this.x = this;
zzz = function (p) {
@@ -70,7 +70,7 @@ var ClassWithNoInitializer = /** @class */ (function (_super) {
__extends(ClassWithNoInitializer, _super);
//'this' in optional super call
function ClassWithNoInitializer() {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // Error
return _this;
}
return ClassWithNoInitializer;
@@ -79,7 +79,7 @@ var ClassWithInitializer = /** @class */ (function (_super) {
__extends(ClassWithInitializer, _super);
//'this' in required super call
function ClassWithInitializer() {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // Error
_this.t = 4;
return _this;
}
@@ -71,7 +71,7 @@ var ClassWithNoInitializer = /** @class */ (function (_super) {
__extends(ClassWithNoInitializer, _super);
//'this' in optional super call
function ClassWithNoInitializer() {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // error: "super" has to be called before "this" accessing
return _this;
}
return ClassWithNoInitializer;
@@ -80,7 +80,7 @@ var ClassWithInitializer = /** @class */ (function (_super) {
__extends(ClassWithInitializer, _super);
//'this' in required super call
function ClassWithInitializer() {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // Error
_this.t = 4;
return _this;
}
+3 -3
View File
@@ -48,7 +48,7 @@ var Base = /** @class */ (function () {
var Foo = /** @class */ (function (_super) {
__extends(Foo, _super);
function Foo() {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // error: "super" has to be called before "this" accessing
return _this;
}
return Foo;
@@ -56,7 +56,7 @@ var Foo = /** @class */ (function (_super) {
var Foo2 = /** @class */ (function (_super) {
__extends(Foo2, _super);
function Foo2() {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // error
_this.p = 0;
return _this;
}
@@ -65,7 +65,7 @@ var Foo2 = /** @class */ (function (_super) {
var Foo3 = /** @class */ (function (_super) {
__extends(Foo3, _super);
function Foo3(p) {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // error
_this.p = p;
return _this;
}
@@ -45,7 +45,7 @@ var Base = /** @class */ (function () {
var Foo = /** @class */ (function (_super) {
__extends(Foo, _super);
function Foo() {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // error: "super" has to be called before "this" accessing
return _this;
}
return Foo;
@@ -53,7 +53,7 @@ var Foo = /** @class */ (function (_super) {
var Foo2 = /** @class */ (function (_super) {
__extends(Foo2, _super);
function Foo2() {
var _this = _super.call(this, _this) || this;
var _this = _super.call(this, _this) || this; // error
_this.x = 0;
return _this;
}
@@ -572,10 +572,11 @@ try {
__extends(C2, _super);
function C2() {
var _a;
var _this = this;
var env_29 = { stack: [], error: void 0, hasError: false };
try {
var d16 = __addDisposableResource(env_29, (_a = {}, _a[Symbol.dispose] = function () { }, _a), false);
return _super.call(this) || this;
_this = _super.call(this) || this;
}
catch (e_29) {
env_29.error = e_29;
@@ -584,6 +585,7 @@ try {
finally {
__disposeResources(env_29);
}
return _this;
}
return C2;
}(C1));
@@ -591,10 +593,11 @@ try {
__extends(C3, _super);
function C3() {
var _a;
var _this = this;
var env_30 = { stack: [], error: void 0, hasError: false };
try {
var _this = _super.call(this) || this;
var d17 = __addDisposableResource(env_30, (_a = {}, _a[Symbol.dispose] = function () { }, _a), false);
_this = _super.call(this) || this;
_this.y = 1;
}
catch (e_30) {
@@ -105,10 +105,11 @@ var A = /** @class */ (function () {
var C1 = /** @class */ (function (_super) {
__extends(C1, _super);
function C1() {
var _this = this;
var env_1 = { stack: [], error: void 0, hasError: false };
try {
var x = __addDisposableResource(env_1, null, false);
return _super.call(this) || this;
_this = _super.call(this) || this;
}
catch (e_1) {
env_1.error = e_1;
@@ -117,15 +118,17 @@ var C1 = /** @class */ (function (_super) {
finally {
__disposeResources(env_1);
}
return _this;
}
return C1;
}(A));
var C2 = /** @class */ (function (_super) {
__extends(C2, _super);
function C2() {
var _this = this;
var env_2 = { stack: [], error: void 0, hasError: false };
try {
var _this = _super.call(this) || this;
_this = _super.call(this) || this;
var x = __addDisposableResource(env_2, null, false);
}
catch (e_2) {
@@ -142,10 +145,11 @@ var C2 = /** @class */ (function (_super) {
var C3 = /** @class */ (function (_super) {
__extends(C3, _super);
function C3() {
var _this = this;
var env_3 = { stack: [], error: void 0, hasError: false };
try {
var _this = _super.call(this) || this;
var x = __addDisposableResource(env_3, null, false);
_this = _super.call(this) || this;
_this.y = 1;
}
catch (e_3) {
@@ -162,10 +166,11 @@ var C3 = /** @class */ (function (_super) {
var C4 = /** @class */ (function (_super) {
__extends(C4, _super);
function C4(y) {
var _this = this;
var env_4 = { stack: [], error: void 0, hasError: false };
try {
var _this = _super.call(this) || this;
var x = __addDisposableResource(env_4, null, false);
_this = _super.call(this) || this;
_this.y = y;
}
catch (e_4) {
@@ -182,10 +187,11 @@ var C4 = /** @class */ (function (_super) {
var C5 = /** @class */ (function (_super) {
__extends(C5, _super);
function C5(y) {
var _this = this;
var env_5 = { stack: [], error: void 0, hasError: false };
try {
var _this = _super.call(this) || this;
var x = __addDisposableResource(env_5, null, false);
_this = _super.call(this) || this;
_this.y = y;
_this.z = 1;
}
@@ -36,7 +36,7 @@ var Base = /** @class */ (function () {
var Super = /** @class */ (function (_super) {
__extends(Super, _super);
function Super() {
var _this = _super.call(this, (function () { return _this; })()) || this;
var _this = _super.call(this, (function () { return _this; })()) || this; // ok since this is not the case: The constructor declares parameter properties or the containing class declares instance member variables with initializers.
return _this;
}
return Super;
@@ -0,0 +1,27 @@
// @target: es5
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/55646
abstract class Foo {
constructor(shouldThrow: boolean) {
if (shouldThrow) {
throw new Error('Please retry');
} else {
console.log('OK');
}
}
}
class Bar extends Foo {
constructor() {
try {
super(true);
} catch (e: unknown) {
console.log('Error: ' + (e as Error).message);
// retry
super(false);
}
}
}
new Bar();