fix(49854): fix start index to emit statements after super (#49858)

This commit is contained in:
Oleksandr T 2022-07-21 02:02:30 +03:00 committed by GitHub
parent 5702941c2f
commit 5d2e62a810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 322 additions and 19 deletions

View File

@ -1113,7 +1113,8 @@ namespace ts {
}
// Add remaining statements from the body, skipping the super() call if it was found and any (already added) prologue statements
addRange(statements, visitNodes(body.statements, visitor, isStatement, superStatementIndex + 1 + prologueStatementCount));
const start = superStatementIndex >= 0 ? superStatementIndex + 1 : prologueStatementCount;
addRange(statements, visitNodes(body.statements, visitor, isStatement, start));
// End the lexical environment.
statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());

View File

@ -1,6 +1,8 @@
//// [parameterPropertyInConstructorWithPrologues.ts]
// https://github.com/microsoft/TypeScript/issues/48671
class C {}
class Foo1 {
constructor(private A: string) {
"ngInject1";
@ -43,10 +45,65 @@ class Foo6 {
console.log("hi");
}
}
class Foo7 extends C {
constructor(
private member: boolean,
) {
"ngInject1";
super();
console.log("hi");
}
}
class Foo8 extends C {
constructor(
private member: boolean,
) {
"ngInject1";
super();
this.m();
console.log("hi");
}
m() {}
}
class Foo9 extends C {
constructor() {
"ngInject1";
"ngInject2";
super();
this.m();
console.log("hi");
}
m() {}
}
//// [parameterPropertyInConstructorWithPrologues.js]
// https://github.com/microsoft/TypeScript/issues/48671
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 __());
};
})();
var C = /** @class */ (function () {
function C() {
}
return C;
}());
var Foo1 = /** @class */ (function () {
function Foo1(A) {
"ngInject1";
@ -102,3 +159,40 @@ var Foo6 = /** @class */ (function () {
}
return Foo6;
}());
var Foo7 = /** @class */ (function (_super) {
__extends(Foo7, _super);
function Foo7(member) {
"ngInject1";
var _this = _super.call(this) || this;
_this.member = member;
console.log("hi");
return _this;
}
return Foo7;
}(C));
var Foo8 = /** @class */ (function (_super) {
__extends(Foo8, _super);
function Foo8(member) {
"ngInject1";
var _this = _super.call(this) || this;
_this.member = member;
_this.m();
console.log("hi");
return _this;
}
Foo8.prototype.m = function () { };
return Foo8;
}(C));
var Foo9 = /** @class */ (function (_super) {
__extends(Foo9, _super);
function Foo9() {
"ngInject1";
"ngInject2";
var _this = _super.call(this) || this;
_this.m();
console.log("hi");
return _this;
}
Foo9.prototype.m = function () { };
return Foo9;
}(C));

View File

@ -1,22 +1,25 @@
=== tests/cases/compiler/parameterPropertyInConstructorWithPrologues.ts ===
// https://github.com/microsoft/TypeScript/issues/48671
class C {}
>C : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
class Foo1 {
>Foo1 : Symbol(Foo1, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
>Foo1 : Symbol(Foo1, Decl(parameterPropertyInConstructorWithPrologues.ts, 2, 10))
constructor(private A: string) {
>A : Symbol(Foo1.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 3, 14))
>A : Symbol(Foo1.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 5, 14))
"ngInject1";
}
}
class Foo2 {
>Foo2 : Symbol(Foo2, Decl(parameterPropertyInConstructorWithPrologues.ts, 6, 1))
>Foo2 : Symbol(Foo2, Decl(parameterPropertyInConstructorWithPrologues.ts, 8, 1))
constructor(private A: string, private B: string) {
>A : Symbol(Foo2.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 9, 14))
>B : Symbol(Foo2.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 9, 32))
>A : Symbol(Foo2.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 11, 14))
>B : Symbol(Foo2.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 11, 32))
"ngInject1";
"ngInject2";
@ -24,12 +27,12 @@ class Foo2 {
}
class Foo3 {
>Foo3 : Symbol(Foo3, Decl(parameterPropertyInConstructorWithPrologues.ts, 13, 1))
>Foo3 : Symbol(Foo3, Decl(parameterPropertyInConstructorWithPrologues.ts, 15, 1))
constructor(private A: string, private B: string, private C: string) {
>A : Symbol(Foo3.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 16, 14))
>B : Symbol(Foo3.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 16, 32))
>C : Symbol(Foo3.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 16, 51))
>A : Symbol(Foo3.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 18, 14))
>B : Symbol(Foo3.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 18, 32))
>C : Symbol(Foo3.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 18, 51))
"ngInject1";
"ngInject2";
@ -37,10 +40,10 @@ class Foo3 {
}
class Foo4 {
>Foo4 : Symbol(Foo4, Decl(parameterPropertyInConstructorWithPrologues.ts, 20, 1))
>Foo4 : Symbol(Foo4, Decl(parameterPropertyInConstructorWithPrologues.ts, 22, 1))
constructor(private A: string) {
>A : Symbol(Foo4.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 23, 14))
>A : Symbol(Foo4.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 25, 14))
"ngInject1";
console.log("hi");
@ -51,11 +54,11 @@ class Foo4 {
}
class Foo5 {
>Foo5 : Symbol(Foo5, Decl(parameterPropertyInConstructorWithPrologues.ts, 27, 1))
>Foo5 : Symbol(Foo5, Decl(parameterPropertyInConstructorWithPrologues.ts, 29, 1))
constructor(private A: string, private B: string) {
>A : Symbol(Foo5.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 30, 14))
>B : Symbol(Foo5.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 30, 32))
>A : Symbol(Foo5.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 32, 14))
>B : Symbol(Foo5.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 32, 32))
"ngInject1";
"ngInject2";
@ -67,12 +70,12 @@ class Foo5 {
}
class Foo6 {
>Foo6 : Symbol(Foo6, Decl(parameterPropertyInConstructorWithPrologues.ts, 35, 1))
>Foo6 : Symbol(Foo6, Decl(parameterPropertyInConstructorWithPrologues.ts, 37, 1))
constructor(private A: string, private B: string, private C: string) {
>A : Symbol(Foo6.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 38, 14))
>B : Symbol(Foo6.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 38, 32))
>C : Symbol(Foo6.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 38, 51))
>A : Symbol(Foo6.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 40, 14))
>B : Symbol(Foo6.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 40, 32))
>C : Symbol(Foo6.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 40, 51))
"ngInject1";
"ngInject2";
@ -83,3 +86,76 @@ class Foo6 {
}
}
class Foo7 extends C {
>Foo7 : Symbol(Foo7, Decl(parameterPropertyInConstructorWithPrologues.ts, 45, 1))
>C : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
constructor(
private member: boolean,
>member : Symbol(Foo7.member, Decl(parameterPropertyInConstructorWithPrologues.ts, 48, 14))
) {
"ngInject1";
super();
>super : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
console.log("hi");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
}
}
class Foo8 extends C {
>Foo8 : Symbol(Foo8, Decl(parameterPropertyInConstructorWithPrologues.ts, 55, 1))
>C : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
constructor(
private member: boolean,
>member : Symbol(Foo8.member, Decl(parameterPropertyInConstructorWithPrologues.ts, 58, 14))
) {
"ngInject1";
super();
>super : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
this.m();
>this.m : Symbol(Foo8.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 65, 3))
>this : Symbol(Foo8, Decl(parameterPropertyInConstructorWithPrologues.ts, 55, 1))
>m : Symbol(Foo8.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 65, 3))
console.log("hi");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
}
m() {}
>m : Symbol(Foo8.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 65, 3))
}
class Foo9 extends C {
>Foo9 : Symbol(Foo9, Decl(parameterPropertyInConstructorWithPrologues.ts, 68, 1))
>C : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
constructor() {
"ngInject1";
"ngInject2";
super();
>super : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
this.m();
>this.m : Symbol(Foo9.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 77, 3))
>this : Symbol(Foo9, Decl(parameterPropertyInConstructorWithPrologues.ts, 68, 1))
>m : Symbol(Foo9.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 77, 3))
console.log("hi");
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
}
m() {}
>m : Symbol(Foo9.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 77, 3))
}

View File

@ -1,6 +1,9 @@
=== tests/cases/compiler/parameterPropertyInConstructorWithPrologues.ts ===
// https://github.com/microsoft/TypeScript/issues/48671
class C {}
>C : C
class Foo1 {
>Foo1 : Foo1
@ -106,3 +109,95 @@ class Foo6 {
}
}
class Foo7 extends C {
>Foo7 : Foo7
>C : C
constructor(
private member: boolean,
>member : boolean
) {
"ngInject1";
>"ngInject1" : "ngInject1"
super();
>super() : void
>super : typeof C
console.log("hi");
>console.log("hi") : void
>console.log : (...data: any[]) => void
>console : Console
>log : (...data: any[]) => void
>"hi" : "hi"
}
}
class Foo8 extends C {
>Foo8 : Foo8
>C : C
constructor(
private member: boolean,
>member : boolean
) {
"ngInject1";
>"ngInject1" : "ngInject1"
super();
>super() : void
>super : typeof C
this.m();
>this.m() : void
>this.m : () => void
>this : this
>m : () => void
console.log("hi");
>console.log("hi") : void
>console.log : (...data: any[]) => void
>console : Console
>log : (...data: any[]) => void
>"hi" : "hi"
}
m() {}
>m : () => void
}
class Foo9 extends C {
>Foo9 : Foo9
>C : C
constructor() {
"ngInject1";
>"ngInject1" : "ngInject1"
"ngInject2";
>"ngInject2" : "ngInject2"
super();
>super() : void
>super : typeof C
this.m();
>this.m() : void
>this.m : () => void
>this : this
>m : () => void
console.log("hi");
>console.log("hi") : void
>console.log : (...data: any[]) => void
>console : Console
>log : (...data: any[]) => void
>"hi" : "hi"
}
m() {}
>m : () => void
}

View File

@ -1,5 +1,7 @@
// https://github.com/microsoft/TypeScript/issues/48671
class C {}
class Foo1 {
constructor(private A: string) {
"ngInject1";
@ -42,3 +44,38 @@ class Foo6 {
console.log("hi");
}
}
class Foo7 extends C {
constructor(
private member: boolean,
) {
"ngInject1";
super();
console.log("hi");
}
}
class Foo8 extends C {
constructor(
private member: boolean,
) {
"ngInject1";
super();
this.m();
console.log("hi");
}
m() {}
}
class Foo9 extends C {
constructor() {
"ngInject1";
"ngInject2";
super();
this.m();
console.log("hi");
}
m() {}
}