Skip to content

Commit 9ce2780

Browse files
committed
call __runInitializers exclusively after super() call
1 parent 71f24f3 commit 9ce2780

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/compiler/transformers/esDecorators.ts

Lines changed: 5 additions & 1 deletion
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);
1075-
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, nonPrologueStart));
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));
10761079
addRange(statements, initializerStatements);
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);

tests/baselines/reference/esDecorators-classExpression-classSuper.7.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
class A {}
33
class B extends A {
44
public constructor() {
5+
'inject';
56
super();
7+
const a = 1;
8+
const b = 1;
69
}
710

811
@foo
@@ -30,8 +33,11 @@ let B = (() => {
3033
__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);
3134
}
3235
constructor() {
36+
'inject';
3337
super();
3438
__runInitializers(this, _instanceExtraInitializers);
39+
const a = 1;
40+
const b = 1;
3541
}
3642
m() { }
3743
};

tests/cases/conformance/esDecorators/classExpression/classSuper/esDecorators-classExpression-classSuper.7.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
class A {}
66
class B extends A {
77
public constructor() {
8+
'inject';
89
super();
10+
const a = 1;
11+
const b = 1;
912
}
1013

1114
@foo

0 commit comments

Comments
 (0)