Skip to content

Commit 5d2e62a

Browse files
authored
fix(49854): fix start index to emit statements after super (microsoft#49858)
1 parent 5702941 commit 5d2e62a

File tree

5 files changed

+322
-19
lines changed

5 files changed

+322
-19
lines changed

src/compiler/transformers/ts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,8 @@ namespace ts {
11131113
}
11141114

11151115
// Add remaining statements from the body, skipping the super() call if it was found and any (already added) prologue statements
1116-
addRange(statements, visitNodes(body.statements, visitor, isStatement, superStatementIndex + 1 + prologueStatementCount));
1116+
const start = superStatementIndex >= 0 ? superStatementIndex + 1 : prologueStatementCount;
1117+
addRange(statements, visitNodes(body.statements, visitor, isStatement, start));
11171118

11181119
// End the lexical environment.
11191120
statements = factory.mergeLexicalEnvironment(statements, endLexicalEnvironment());

tests/baselines/reference/parameterPropertyInConstructorWithPrologues.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//// [parameterPropertyInConstructorWithPrologues.ts]
22
// https://github.com/microsoft/TypeScript/issues/48671
33

4+
class C {}
5+
46
class Foo1 {
57
constructor(private A: string) {
68
"ngInject1";
@@ -43,10 +45,65 @@ class Foo6 {
4345
console.log("hi");
4446
}
4547
}
48+
49+
class Foo7 extends C {
50+
constructor(
51+
private member: boolean,
52+
) {
53+
"ngInject1";
54+
super();
55+
console.log("hi");
56+
}
57+
}
58+
59+
class Foo8 extends C {
60+
constructor(
61+
private member: boolean,
62+
) {
63+
"ngInject1";
64+
super();
65+
this.m();
66+
console.log("hi");
67+
}
68+
69+
m() {}
70+
}
71+
72+
class Foo9 extends C {
73+
constructor() {
74+
"ngInject1";
75+
"ngInject2";
76+
super();
77+
this.m();
78+
console.log("hi");
79+
}
80+
81+
m() {}
82+
}
4683

4784

4885
//// [parameterPropertyInConstructorWithPrologues.js]
4986
// https://github.com/microsoft/TypeScript/issues/48671
87+
var __extends = (this && this.__extends) || (function () {
88+
var extendStatics = function (d, b) {
89+
extendStatics = Object.setPrototypeOf ||
90+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
91+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
92+
return extendStatics(d, b);
93+
};
94+
return function (d, b) {
95+
if (typeof b !== "function" && b !== null)
96+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
97+
extendStatics(d, b);
98+
function __() { this.constructor = d; }
99+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
100+
};
101+
})();
102+
var C = /** @class */ (function () {
103+
function C() {
104+
}
105+
return C;
106+
}());
50107
var Foo1 = /** @class */ (function () {
51108
function Foo1(A) {
52109
"ngInject1";
@@ -102,3 +159,40 @@ var Foo6 = /** @class */ (function () {
102159
}
103160
return Foo6;
104161
}());
162+
var Foo7 = /** @class */ (function (_super) {
163+
__extends(Foo7, _super);
164+
function Foo7(member) {
165+
"ngInject1";
166+
var _this = _super.call(this) || this;
167+
_this.member = member;
168+
console.log("hi");
169+
return _this;
170+
}
171+
return Foo7;
172+
}(C));
173+
var Foo8 = /** @class */ (function (_super) {
174+
__extends(Foo8, _super);
175+
function Foo8(member) {
176+
"ngInject1";
177+
var _this = _super.call(this) || this;
178+
_this.member = member;
179+
_this.m();
180+
console.log("hi");
181+
return _this;
182+
}
183+
Foo8.prototype.m = function () { };
184+
return Foo8;
185+
}(C));
186+
var Foo9 = /** @class */ (function (_super) {
187+
__extends(Foo9, _super);
188+
function Foo9() {
189+
"ngInject1";
190+
"ngInject2";
191+
var _this = _super.call(this) || this;
192+
_this.m();
193+
console.log("hi");
194+
return _this;
195+
}
196+
Foo9.prototype.m = function () { };
197+
return Foo9;
198+
}(C));
Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
11
=== tests/cases/compiler/parameterPropertyInConstructorWithPrologues.ts ===
22
// https://github.com/microsoft/TypeScript/issues/48671
33

4+
class C {}
5+
>C : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
6+
47
class Foo1 {
5-
>Foo1 : Symbol(Foo1, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
8+
>Foo1 : Symbol(Foo1, Decl(parameterPropertyInConstructorWithPrologues.ts, 2, 10))
69

710
constructor(private A: string) {
8-
>A : Symbol(Foo1.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 3, 14))
11+
>A : Symbol(Foo1.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 5, 14))
912

1013
"ngInject1";
1114
}
1215
}
1316

1417
class Foo2 {
15-
>Foo2 : Symbol(Foo2, Decl(parameterPropertyInConstructorWithPrologues.ts, 6, 1))
18+
>Foo2 : Symbol(Foo2, Decl(parameterPropertyInConstructorWithPrologues.ts, 8, 1))
1619

1720
constructor(private A: string, private B: string) {
18-
>A : Symbol(Foo2.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 9, 14))
19-
>B : Symbol(Foo2.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 9, 32))
21+
>A : Symbol(Foo2.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 11, 14))
22+
>B : Symbol(Foo2.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 11, 32))
2023

2124
"ngInject1";
2225
"ngInject2";
2326
}
2427
}
2528

2629
class Foo3 {
27-
>Foo3 : Symbol(Foo3, Decl(parameterPropertyInConstructorWithPrologues.ts, 13, 1))
30+
>Foo3 : Symbol(Foo3, Decl(parameterPropertyInConstructorWithPrologues.ts, 15, 1))
2831

2932
constructor(private A: string, private B: string, private C: string) {
30-
>A : Symbol(Foo3.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 16, 14))
31-
>B : Symbol(Foo3.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 16, 32))
32-
>C : Symbol(Foo3.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 16, 51))
33+
>A : Symbol(Foo3.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 18, 14))
34+
>B : Symbol(Foo3.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 18, 32))
35+
>C : Symbol(Foo3.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 18, 51))
3336

3437
"ngInject1";
3538
"ngInject2";
3639
}
3740
}
3841

3942
class Foo4 {
40-
>Foo4 : Symbol(Foo4, Decl(parameterPropertyInConstructorWithPrologues.ts, 20, 1))
43+
>Foo4 : Symbol(Foo4, Decl(parameterPropertyInConstructorWithPrologues.ts, 22, 1))
4144

4245
constructor(private A: string) {
43-
>A : Symbol(Foo4.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 23, 14))
46+
>A : Symbol(Foo4.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 25, 14))
4447

4548
"ngInject1";
4649
console.log("hi");
@@ -51,11 +54,11 @@ class Foo4 {
5154
}
5255

5356
class Foo5 {
54-
>Foo5 : Symbol(Foo5, Decl(parameterPropertyInConstructorWithPrologues.ts, 27, 1))
57+
>Foo5 : Symbol(Foo5, Decl(parameterPropertyInConstructorWithPrologues.ts, 29, 1))
5558

5659
constructor(private A: string, private B: string) {
57-
>A : Symbol(Foo5.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 30, 14))
58-
>B : Symbol(Foo5.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 30, 32))
60+
>A : Symbol(Foo5.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 32, 14))
61+
>B : Symbol(Foo5.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 32, 32))
5962

6063
"ngInject1";
6164
"ngInject2";
@@ -67,19 +70,92 @@ class Foo5 {
6770
}
6871

6972
class Foo6 {
70-
>Foo6 : Symbol(Foo6, Decl(parameterPropertyInConstructorWithPrologues.ts, 35, 1))
73+
>Foo6 : Symbol(Foo6, Decl(parameterPropertyInConstructorWithPrologues.ts, 37, 1))
7174

7275
constructor(private A: string, private B: string, private C: string) {
73-
>A : Symbol(Foo6.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 38, 14))
74-
>B : Symbol(Foo6.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 38, 32))
75-
>C : Symbol(Foo6.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 38, 51))
76+
>A : Symbol(Foo6.A, Decl(parameterPropertyInConstructorWithPrologues.ts, 40, 14))
77+
>B : Symbol(Foo6.B, Decl(parameterPropertyInConstructorWithPrologues.ts, 40, 32))
78+
>C : Symbol(Foo6.C, Decl(parameterPropertyInConstructorWithPrologues.ts, 40, 51))
79+
80+
"ngInject1";
81+
"ngInject2";
82+
console.log("hi");
83+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
84+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
85+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
86+
}
87+
}
88+
89+
class Foo7 extends C {
90+
>Foo7 : Symbol(Foo7, Decl(parameterPropertyInConstructorWithPrologues.ts, 45, 1))
91+
>C : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
92+
93+
constructor(
94+
private member: boolean,
95+
>member : Symbol(Foo7.member, Decl(parameterPropertyInConstructorWithPrologues.ts, 48, 14))
96+
97+
) {
98+
"ngInject1";
99+
super();
100+
>super : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
101+
102+
console.log("hi");
103+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
104+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
105+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
106+
}
107+
}
108+
109+
class Foo8 extends C {
110+
>Foo8 : Symbol(Foo8, Decl(parameterPropertyInConstructorWithPrologues.ts, 55, 1))
111+
>C : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
76112

113+
constructor(
114+
private member: boolean,
115+
>member : Symbol(Foo8.member, Decl(parameterPropertyInConstructorWithPrologues.ts, 58, 14))
116+
117+
) {
118+
"ngInject1";
119+
super();
120+
>super : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
121+
122+
this.m();
123+
>this.m : Symbol(Foo8.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 65, 3))
124+
>this : Symbol(Foo8, Decl(parameterPropertyInConstructorWithPrologues.ts, 55, 1))
125+
>m : Symbol(Foo8.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 65, 3))
126+
127+
console.log("hi");
128+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
129+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
130+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
131+
}
132+
133+
m() {}
134+
>m : Symbol(Foo8.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 65, 3))
135+
}
136+
137+
class Foo9 extends C {
138+
>Foo9 : Symbol(Foo9, Decl(parameterPropertyInConstructorWithPrologues.ts, 68, 1))
139+
>C : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
140+
141+
constructor() {
77142
"ngInject1";
78143
"ngInject2";
144+
super();
145+
>super : Symbol(C, Decl(parameterPropertyInConstructorWithPrologues.ts, 0, 0))
146+
147+
this.m();
148+
>this.m : Symbol(Foo9.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 77, 3))
149+
>this : Symbol(Foo9, Decl(parameterPropertyInConstructorWithPrologues.ts, 68, 1))
150+
>m : Symbol(Foo9.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 77, 3))
151+
79152
console.log("hi");
80153
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
81154
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
82155
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
83156
}
157+
158+
m() {}
159+
>m : Symbol(Foo9.m, Decl(parameterPropertyInConstructorWithPrologues.ts, 77, 3))
84160
}
85161

0 commit comments

Comments
 (0)