Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(53204): Bug: __runInitializers(this) is emitted before super() call #53268

Merged
merged 2 commits into from Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/transformers/esDecorators.ts
Expand Up @@ -1072,8 +1072,8 @@ 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, initializerStatements);
addRange(statements, visitNodes(node.body.statements, visitor, isStatement, nonPrologueStart));
addRange(statements, initializerStatements);
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
body = factory.createBlock(statements, /*multiLine*/ true);
setOriginalNode(body, node.body);
setTextRange(body, node.body);
Expand Down
@@ -0,0 +1,44 @@
//// [esDecorators-classExpression-classSuper.7.ts]
class A {}
class B extends A {
public constructor() {
super();
}

@foo
public m(): void {}
}

function foo(method: any, _context: any): any {
return function (this: any) {
method.call(this);
};
}

new B();


//// [esDecorators-classExpression-classSuper.7.js]
class A {
}
let B = (() => {
let _instanceExtraInitializers = [];
let _m_decorators;
return class B extends A {
static {
_m_decorators = [foo];
__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() {
super();
__runInitializers(this, _instanceExtraInitializers);
}
m() { }
};
})();
function foo(method, _context) {
return function () {
method.call(this);
};
}
new B();
@@ -0,0 +1,21 @@
// @target: es2022
// @noEmitHelpers: true
// @noTypesAndSymbols: true

class A {}
class B extends A {
public constructor() {
super();
}

@foo
public m(): void {}
}

function foo(method: any, _context: any): any {
return function (this: any) {
method.call(this);
};
}

new B();