-
-
Notifications
You must be signed in to change notification settings - Fork 477
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
Invalid output from async-to-generator transform when async arrow function in class constructor #7792
Comments
And I found another bug in Babel: Babel REPL (that would be really hard to fix) |
If we fix this, we should be able to remove 2 overrides from class properties transform fixtures:
|
For this case, I prefer to diverge with Babel's output and always put |
That's a good idea. But if the 1st async function is nested, then you'd need to add it before all generator functions until you find one which is unconditionally executed: class C extends S {
constructor() {
super();
if (condition) {
// `_this = this` required here
this.fn = async () => { return [this, 1]; };
}
for (let x in array) {
// `_this = this` required here
this.fns.push(async () => { return [this, x]; });
}
// `_this = this` required here
this.otherFn = async () => { return [this, 2]; };
// `_this = this` NOT required here
this.yetAnotherFn = async () => { return [this, 3]; };
}
} A simpler solution would be that when async arrow function is in a constructor of a class with a super class, convert it to That'd be more lengthy output if constructor contains multiple async arrow functions, but it'd be correct, and easier/faster than trying to find all the If you do want to find all the oxc/crates/oxc_transformer/src/es2022/class_properties/constructor.rs Lines 659 to 826 in 862838f
|
Actually both my suggestions don't work! The async arrow function can be before the class C extends S {
constructor() {
const fn = async () => this;
super();
this.fn = fn;
}
} so Async function can even be inside class C extends S {
constructor() {
super(async () => this);
}
} Maybe there's another way different from Babel's, but probably it's just as complicated as Babel's method... At least the visitor (that class properties uses) is not so expensive in most cases, because most of the time |
Input:
Transformed by async-to-generator:
Oxc Playground
Problem is that
this
is now accessed beforesuper()
, which is an error.Babel puts
_this = this
aftersuper()
:Note it gets a bit more complicated than that: Babel REPL
The text was updated successfully, but these errors were encountered: