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
Fix export bindings not updated by 'for ... in' and 'for ... of' #11074
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be easier if we transform
for (PATTERN in {}) {}
to
for (let _foo in {}) {
PATTERN = _foo
}
Then all the existing logic would work for this case, without needing to distinguish the case when PATTERN is a simple identifier or when it's using destructuring.
packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/for-of-in-export/output.js
Outdated
Show resolved
Hide resolved
Btw, you can use |
@nicolo-ribaudo I think moving
because this would be transformed into
and Babel would transform that into
which results in an error, since you are assigning to |
I was proposing to do something like this:
|
I changed the code to use your method, it's a lot better now! |
packages/babel-helper-module-transforms/src/rewrite-live-references.js
Outdated
Show resolved
Hide resolved
Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
packages/babel-helper-module-transforms/src/rewrite-live-references.js
Outdated
Show resolved
Hide resolved
* Correctly transpile export bindings for some for-of loops * Correctly transform non-destructured for of loops to update exported variables * Add tests * Don't replace entire for of loop * Correctly transform destructured for-of/for-in exports * Update exported variables in array pattern and more fixes * Refresh test output * Update tests and rebase on master * Refactor ForOf|ForIn visitor * Don't transform re-declared exported vars * Generate better name for loop id Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> * Idiomatically generate UidIdentifier * Update scope after replacing loop declaration Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
…1074) * Correctly transpile export bindings for some for-of loops * Correctly transform non-destructured for of loops to update exported variables * Add tests * Don't replace entire for of loop * Correctly transform destructured for-of/for-in exports * Update exported variables in array pattern and more fixes * Refresh test output * Update tests and rebase on master * Refactor ForOf|ForIn visitor * Don't transform re-declared exported vars * Generate better name for loop id Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> * Idiomatically generate UidIdentifier * Update scope after replacing loop declaration Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This PR makes Babel correctly transform exported variables in
for of
andfor in
loops.