+
Skip to content

Async transformation causes this access before super() call #4141

@magic-akari

Description

@magic-akari

Input code

new (class Foo extends class { } {
	constructor() {
		let x = 1;
		(async () => {
			console.log("before super", x);  // (1) Sync phase
			await 1;
			console.log("after super", x);   // (2) Async phase
		})();
		super();
		x = 2;
	}
})();

Esbuild playground

https://esbuild.github.io/try/#dAAwLjI1LjIALS10YXJnZXQ9ZXMyMDE2AG5ldyAoY2xhc3MgRm9vIGV4dGVuZHMgY2xhc3MgeyB9IHsKCWNvbnN0cnVjdG9yKCkgewoJCWxldCB4ID0gMTsKCQkoYXN5bmMgKCkgPT4gewoJCQljb25zb2xlLmxvZygiYmVmb3JlIHN1cGVyIiwgeCk7CgkJCWF3YWl0IDE7CgkJCWNvbnNvbGUubG9nKCJhZnRlciBzdXBlciIsIHgpOwoJCX0pKCk7CgkJc3VwZXIoKTsKCQl4ID0gMjsKCX0KfSkoKTsK

Expected Behavior

The code should output:

before super 1
after super 2

Actual Behavior

Throws a reference error:

Uncaught ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载