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
transform-es2015-modules-commonjs destructuring error #5768
Comments
Hey @jonhartnett! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
@jonhartnett this is interesting. Do you know whether this is even expected behaviour of javascript? I'm not 100% up to scratch with how the bindings work, but it may be because in this case For example, if we're dealing with an object reference instead of a value: let y = exports.y = { val: 1 };
function f2 () {
[y.val] = [2]
} calling If anyone can weigh in on whether this is expected behaviour according to the module spec, that would be very helpful :) |
As far as I know module bindings should be "live", any updates should be visible from outside the module. Furthermore, the line in f3 should behave as nothing more than syntactic sugar for |
- adds a failing test based on description in babel#5768 - handles ObjectPattern and ArrayPattern
@jonhartnett ahh you're right - I was thinking from the point of view of the commonjs module but I see what you mean now. I think I've got something working for this, just pushing a PR for review now. |
@jonhartnett when you have a moment please try #5811 and see if that works for you. |
@joshwnj That works perfectly |
* Fix destructured exports - adds a failing test based on description in #5768 - handles ObjectPattern and ArrayPattern * use export assignment template
When destructuring into an exported variable, transform-es2015-modules-commonjs fails to generate code to keep the local variable and the exports value in sync.
Input Code
Babel Configuration (.babelrc, package.json, cli command)
Expected Generated Code
Current Generated Code
Possible Solution
Add a line to keep the local variable and the export value in sync when destructuring into export variables.
The text was updated successfully, but these errors were encountered: