-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite void-returning statements in constructors that capture result…
… of super call (#11868) * rewrite void-returning statements in constructors that capture result of super call * linter
- Loading branch information
Showing
5 changed files
with
410 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
tests/baselines/reference/constructorWithCapturedSuper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
//// [constructorWithCapturedSuper.ts] | ||
let oneA: A; | ||
|
||
class A { | ||
constructor() { | ||
return oneA; | ||
} | ||
} | ||
|
||
class B extends A { | ||
constructor(x: number) { | ||
super(); | ||
if (x === 1) { | ||
return; | ||
} | ||
while (x < 2) { | ||
return; | ||
} | ||
try { | ||
return | ||
} | ||
catch (e) { | ||
return; | ||
} | ||
finally { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
class C extends A { | ||
constructor(x: number) { | ||
super(); | ||
for (let i = 0; i < 10; ++i) { | ||
() => i + x; | ||
if (x === 1) { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
class D extends A { | ||
constructor(x: number) { | ||
super(); | ||
() => { | ||
return; | ||
} | ||
function foo() { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
//// [constructorWithCapturedSuper.js] | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
var oneA; | ||
var A = (function () { | ||
function A() { | ||
return oneA; | ||
} | ||
return A; | ||
}()); | ||
var B = (function (_super) { | ||
__extends(B, _super); | ||
function B(x) { | ||
var _this = _super.call(this) || this; | ||
if (x === 1) { | ||
return _this; | ||
} | ||
while (x < 2) { | ||
return _this; | ||
} | ||
try { | ||
return _this; | ||
} | ||
catch (e) { | ||
return _this; | ||
} | ||
finally { | ||
return _this; | ||
} | ||
return _this; | ||
} | ||
return B; | ||
}(A)); | ||
var C = (function (_super) { | ||
__extends(C, _super); | ||
function C(x) { | ||
var _this = _super.call(this) || this; | ||
var _loop_1 = function (i) { | ||
(function () { return i + x; }); | ||
if (x === 1) { | ||
return { value: _this }; | ||
} | ||
}; | ||
for (var i = 0; i < 10; ++i) { | ||
var state_1 = _loop_1(i); | ||
if (typeof state_1 === "object") | ||
return state_1.value; | ||
} | ||
return _this; | ||
} | ||
return C; | ||
}(A)); | ||
var D = (function (_super) { | ||
__extends(D, _super); | ||
function D(x) { | ||
var _this = _super.call(this) || this; | ||
(function () { | ||
return; | ||
}); | ||
function foo() { | ||
return; | ||
} | ||
return _this; | ||
} | ||
return D; | ||
}(A)); |
96 changes: 96 additions & 0 deletions
96
tests/baselines/reference/constructorWithCapturedSuper.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
=== tests/cases/compiler/constructorWithCapturedSuper.ts === | ||
let oneA: A; | ||
>oneA : Symbol(oneA, Decl(constructorWithCapturedSuper.ts, 0, 3)) | ||
>A : Symbol(A, Decl(constructorWithCapturedSuper.ts, 0, 12)) | ||
|
||
class A { | ||
>A : Symbol(A, Decl(constructorWithCapturedSuper.ts, 0, 12)) | ||
|
||
constructor() { | ||
return oneA; | ||
>oneA : Symbol(oneA, Decl(constructorWithCapturedSuper.ts, 0, 3)) | ||
} | ||
} | ||
|
||
class B extends A { | ||
>B : Symbol(B, Decl(constructorWithCapturedSuper.ts, 6, 1)) | ||
>A : Symbol(A, Decl(constructorWithCapturedSuper.ts, 0, 12)) | ||
|
||
constructor(x: number) { | ||
>x : Symbol(x, Decl(constructorWithCapturedSuper.ts, 9, 16)) | ||
|
||
super(); | ||
>super : Symbol(A, Decl(constructorWithCapturedSuper.ts, 0, 12)) | ||
|
||
if (x === 1) { | ||
>x : Symbol(x, Decl(constructorWithCapturedSuper.ts, 9, 16)) | ||
|
||
return; | ||
} | ||
while (x < 2) { | ||
>x : Symbol(x, Decl(constructorWithCapturedSuper.ts, 9, 16)) | ||
|
||
return; | ||
} | ||
try { | ||
return | ||
} | ||
catch (e) { | ||
>e : Symbol(e, Decl(constructorWithCapturedSuper.ts, 20, 15)) | ||
|
||
return; | ||
} | ||
finally { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
class C extends A { | ||
>C : Symbol(C, Decl(constructorWithCapturedSuper.ts, 27, 1)) | ||
>A : Symbol(A, Decl(constructorWithCapturedSuper.ts, 0, 12)) | ||
|
||
constructor(x: number) { | ||
>x : Symbol(x, Decl(constructorWithCapturedSuper.ts, 30, 16)) | ||
|
||
super(); | ||
>super : Symbol(A, Decl(constructorWithCapturedSuper.ts, 0, 12)) | ||
|
||
for (let i = 0; i < 10; ++i) { | ||
>i : Symbol(i, Decl(constructorWithCapturedSuper.ts, 32, 16)) | ||
>i : Symbol(i, Decl(constructorWithCapturedSuper.ts, 32, 16)) | ||
>i : Symbol(i, Decl(constructorWithCapturedSuper.ts, 32, 16)) | ||
|
||
() => i + x; | ||
>i : Symbol(i, Decl(constructorWithCapturedSuper.ts, 32, 16)) | ||
>x : Symbol(x, Decl(constructorWithCapturedSuper.ts, 30, 16)) | ||
|
||
if (x === 1) { | ||
>x : Symbol(x, Decl(constructorWithCapturedSuper.ts, 30, 16)) | ||
|
||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
class D extends A { | ||
>D : Symbol(D, Decl(constructorWithCapturedSuper.ts, 39, 1)) | ||
>A : Symbol(A, Decl(constructorWithCapturedSuper.ts, 0, 12)) | ||
|
||
constructor(x: number) { | ||
>x : Symbol(x, Decl(constructorWithCapturedSuper.ts, 42, 16)) | ||
|
||
super(); | ||
>super : Symbol(A, Decl(constructorWithCapturedSuper.ts, 0, 12)) | ||
|
||
() => { | ||
return; | ||
} | ||
function foo() { | ||
>foo : Symbol(foo, Decl(constructorWithCapturedSuper.ts, 46, 9)) | ||
|
||
return; | ||
} | ||
} | ||
} |
Oops, something went wrong.