Skip to content

Commit 0e765ac

Browse files
TypeScript Bota-tarasyuk
TypeScript Bot
andauthored
🤖 Pick PR #53268 (fix(53204): Bug: __runInitializers(...) into release-5.0 (#53273)
Co-authored-by: Oleksandr T <[email protected]>
1 parent cb69c8a commit 0e765ac

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

‎src/compiler/transformers/esDecorators.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
Expression,
3737
ExpressionStatement,
3838
findComputedPropertyNameCacheAssignment,
39+
findSuperStatementIndex,
3940
firstOrUndefined,
4041
forEachEntry,
4142
ForStatement,
@@ -1072,8 +1073,11 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
10721073
if (initializerStatements) {
10731074
const statements: Statement[] = [];
10741075
const nonPrologueStart = factory.copyPrologue(node.body.statements, statements, /*ensureUseStrict*/ false, visitor);
1076+
const superStatementIndex = findSuperStatementIndex(node.body.statements, nonPrologueStart);
1077+
const indexOfFirstStatementAfterSuper = superStatementIndex >= 0 ? superStatementIndex + 1 : undefined;
1078+
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, nonPrologueStart, indexOfFirstStatementAfterSuper ? indexOfFirstStatementAfterSuper - nonPrologueStart : undefined));
10751079
addRange(statements, initializerStatements);
1076-
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, nonPrologueStart));
1080+
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, indexOfFirstStatementAfterSuper));
10771081
body = factory.createBlock(statements, /*multiLine*/ true);
10781082
setOriginalNode(body, node.body);
10791083
setTextRange(body, node.body);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//// [esDecorators-classExpression-classSuper.7.ts]
2+
class A {}
3+
class B extends A {
4+
public constructor() {
5+
'inject';
6+
super();
7+
const a = 1;
8+
const b = 1;
9+
}
10+
11+
@foo
12+
public m(): void {}
13+
}
14+
15+
function foo(method: any, _context: any): any {
16+
return function (this: any) {
17+
method.call(this);
18+
};
19+
}
20+
21+
new B();
22+
23+
24+
//// [esDecorators-classExpression-classSuper.7.js]
25+
class A {
26+
}
27+
let B = (() => {
28+
let _instanceExtraInitializers = [];
29+
let _m_decorators;
30+
return class B extends A {
31+
static {
32+
_m_decorators = [foo];
33+
__esDecorate(this, null, _m_decorators, { kind: "method", name: "m", static: false, private: false, access: { has: obj => "m" in obj, get: obj => obj.m } }, null, _instanceExtraInitializers);
34+
}
35+
constructor() {
36+
'inject';
37+
super();
38+
__runInitializers(this, _instanceExtraInitializers);
39+
const a = 1;
40+
const b = 1;
41+
}
42+
m() { }
43+
};
44+
})();
45+
function foo(method, _context) {
46+
return function () {
47+
method.call(this);
48+
};
49+
}
50+
new B();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// @target: es2022
2+
// @noEmitHelpers: true
3+
// @noTypesAndSymbols: true
4+
5+
class A {}
6+
class B extends A {
7+
public constructor() {
8+
'inject';
9+
super();
10+
const a = 1;
11+
const b = 1;
12+
}
13+
14+
@foo
15+
public m(): void {}
16+
}
17+
18+
function foo(method: any, _context: any): any {
19+
return function (this: any) {
20+
method.call(this);
21+
};
22+
}
23+
24+
new B();

0 commit comments

Comments
 (0)