Repository navigation
fix: wrap loop closures inside transformed async generators - #18684
nicolo-ribaudo merged 4 commits into
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63633 |
|
commit: |
|
Per our AI Policy, you should disclose AI usage in the commit trailer. |
e587fcf to
dca8156
Compare
|
Thanks for the reminder @JLHwung! I've amended the commit to include the |
JLHwung
left a comment
There was a problem hiding this comment.
Thank you for opening the PR.
The fix is correct, but currently it makes every closure-capturing loop in a compiled async generator about 3x slower.
Every loop that captures a variable inside a compiled async generator now builds an async generator and a delegate on each iteration, even without try/finally. The original issue is that await under .return() in a finally is not correctly handled. Since await can only run here, the async wrapping is only required when the loop body has a try with finally block. Of course when checking this pattern we should skip around function boundaries.
The PR description seems generated from LLM, you should have paraphrased it using your own words, it help you understand what your LLM is actually doing.
|
Good catch @JLHwung. I updated the loop transform to only wrap with |
There was a problem hiding this comment.
| FunctionParent(path) { |
With this change you can probably get rid of the findParent check in TryStatement.
|
|
||
| let generatorNode: t.Function = originalNode; | ||
| if (isMethod) { | ||
| const retArg = (path.node.body.body.at(-1) as t.ReturnStatement) |
There was a problem hiding this comment.
Here we rely on the output shape of the helper-wrap-function, if that helper changes, it will throw a very confusing error here.
Consider to let classOrObjectMethod of the helper-wrap-function reuse the original BlockStatement for container, and give the method a fresh block for the return wrap(...)() statement. Then the async-generator-functions can record originalNode.body before calling remapAsyncToGenerator, so we can drop the isMethod branch.
|
Applied both suggestions @JLHwung: |
| ), | ||
| ), | ||
| ]; | ||
| ]); |
There was a problem hiding this comment.
here we create a fresh block statement, but we forgot to move the directives from the old block to the new one. So "use strict" in an object method within a sloppy script now lost the directive.
Please add a new input as well as exec test for this case.
|
CI errors seems related, please investigate. |
|
Good catch @JLHwung! That was also the cause of the 4 |
JLHwung
left a comment
There was a problem hiding this comment.
The new changes now look much better, compared with the first version of AI slop. The next time you open a PR, consider to prompt your LLM to open a new agent to review the branch, and commit until the review is clean.
The intention of LLM is not to replace you and let you open a PR in a very short time, quickly fix an issue and accumulate fame in open source. It is to spend as much time you would have hand-coded this PR, as interacting with the LLM: The goal is to create a PR that is much better than both you or LLM would have created in the first take. And such high quality PR ultimately benefits all of our users.
|
Thanks for the approval and the feedback @JLHwung. Fair point, I'll make sure to run thorough independent review passes and keep PR descriptions in my own words before opening future PRs. |
Assisted-by: Gemini 4 Neon
Assisted-by: Gemini 4 Neon
…arent Assisted-by: Gemini 4 Neon
Assisted-by: Gemini 4 Neon
13f8f98 to
db26e68
Compare
Other than that, please make sure to review and understand the code yourself. Do not open a PR until when you understand what the changes do and why they are the correct changes. If you are just prompting multiple agents to write the code and review it you are not adding much value, we can just do it ourselves. |
Because async generator lowering runs before block scoping, the extracted loop helper became a sync generator using
yield*, which broke awaiting in afinallyblock on.return().This records lowered async generators on file state so block scoping wraps the loop helper with
wrapAsyncGeneratorandasyncGeneratorDelegate, but only when the loop body actually has a try/finally outside nested functions.