Skip to content

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

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

Closed
magic-akari opened this issue Apr 13, 2025 · 0 comments · Fixed by #4142
Closed

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

magic-akari opened this issue Apr 13, 2025 · 0 comments · Fixed by #4142

Comments

@magic-akari
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant