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
plugin-transform-modules-commonjs: export binding not updated by 'for...in' and 'for...of' #10941
Comments
Hey @ajafff! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
I'll take a shot at this. |
@ajafff How did you test the given code sample in Node.js. I tried running it, but Node.js does not support I think I'm confused, but it seems like in Node.js, the expected behavior is not for For example:
Outputs
not
Or are you referring to the fact that if I run the following two files in the browser (without transpilation): lib.js
index.js
the output will be
Whereas, if Babel compiles these files + the files are bundled with a bundler, the output will just be:
If so, I tested with a bable + a bundler (parcel), and the output Javascript indicated that Sidenote, if I set the preset to "es2015", the output seems to update Output with preset es2015:
|
You can run the untranspiled code in Node.js by using the Since the transpiled code should be semantically identical, it should update I don't know exactly how these presets work. It seems like "es2015" is transpiling the |
@ajafff It seems like the solution to this issue, is make Babel replace
with
It seems like you've solved this issue in the Typescript compiler, so I was wondering if you have any thoughts on a potential fix. |
@vedantroy while your suggested fix works, there's another case that it doesn't cover: You can export the same variable multiple times with different names: export let foo;
export {foo as bar};
for (foo of [1, 2]) {} should give roughly this code: let foo;
for (foo of [1, 2]) {
exports.foo = exports.bar = foo;
} |
PR: #11074 |
Bug Report
Current Behavior
If an exported binding is used as LHS in a ForOfStatement or ForInStatement, only the local variable is updated. The exported binding stays the same.
Input Code
Expected behavior/code
exports.foo
should be updated every timefoo
is assigned a new value.I tested the code without transpilation in Node.js and it works as expected.
The text was updated successfully, but these errors were encountered: