Repository navigation
fix: wrap enclosing loop when a nested for head closure captures its bindings - #18331
Conversation
…bindings Signed-off-by: Joelle Mahfoud <joelle_mahfoud@live.com>
Thanks for opening this pull request! 🎉We really appreciate you taking the time to contribute, @joelle-a-dev. A maintainer will take a look as soon as they can. In the meantime, please make sure that:
If anything needs adjusting we'll leave comments here. Thanks again! |
|
commit: |
|
@nicolo-ribaudo @JLHwung if you can please review this, addressing the todo from previous PR |
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/62395 |
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Can you also add an input/output test?
Signed-off-by: Joelle Mahfoud <joelle_mahfoud@live.com>
|
@nicolo-ribaudo done |
|
This PR builds on #18195 (closures in for-loop init capture wrong binding), which is not on Conflicting file:
This PR needs to be backported manually, after #18195 is backported.
|
|
Backported to 7.x in #18370. |
When a let binding in a nested for loop's head is captured by a closure in that same head (ex: for (let i = k, f = () => i; ...)), the binding becomes a function-scoped var and is shared across iterations of the enclosing loop, so every f returns the last value. The enclosing loop body is now wrapped in _loop() in this case, so each outer iteration gets fresh head bindings. This resolves the TODO in the for-head-closure-nested fixture and adds a fixture for the case where the binding isn't mutated.