Skip to content

Commit

Permalink
call __runInitializers exclusively after super() call
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed Mar 15, 2023
1 parent 71f24f3 commit 9ce2780
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/compiler/transformers/esDecorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
Expression,
ExpressionStatement,
findComputedPropertyNameCacheAssignment,
findSuperStatementIndex,
firstOrUndefined,
forEachEntry,
ForStatement,
Expand Down Expand Up @@ -1072,8 +1073,11 @@ export function transformESDecorators(context: TransformationContext): (x: Sourc
if (initializerStatements) {
const statements: Statement[] = [];
const nonPrologueStart = factory.copyPrologue(node.body.statements, statements, /*ensureUseStrict*/ false, visitor);
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, nonPrologueStart));
const superStatementIndex = findSuperStatementIndex(node.body.statements, nonPrologueStart);
const indexOfFirstStatementAfterSuper = superStatementIndex >= 0 ? superStatementIndex + 1 : undefined;
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, nonPrologueStart, indexOfFirstStatementAfterSuper ? indexOfFirstStatementAfterSuper - nonPrologueStart : undefined));
addRange(statements, initializerStatements);
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, indexOfFirstStatementAfterSuper));
body = factory.createBlock(statements, /*multiLine*/ true);
setOriginalNode(body, node.body);
setTextRange(body, node.body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
class A {}
class B extends A {
public constructor() {
'inject';
super();
const a = 1;
const b = 1;
}

@foo
Expand Down Expand Up @@ -30,8 +33,11 @@ let B = (() => {
__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);
}
constructor() {
'inject';
super();
__runInitializers(this, _instanceExtraInitializers);
const a = 1;
const b = 1;
}
m() { }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
class A {}
class B extends A {
public constructor() {
'inject';
super();
const a = 1;
const b = 1;
}

@foo
Expand Down

0 comments on commit 9ce2780

Please sign in to comment.