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
Properly export destructured export declarations in SystemJS #2587
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.
Great! Looks good to me
Thanks! Just after pushing the first version, I came up with a way to handle destructuring assignment expressions involving exported variables so this should hopefully solve this issue completely. |
2ba7577
to
63cfa96
Compare
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.
Amazing work @lukastaegert thanks so much for this.
If you have any ideas re how this could be done more nicely in the format do let me know. We could for example add some other export
variations if there is something that can help with this.
Well, I am not sure this would be useful to anyone except us and it might seem confusing why it exists, but one way to make it simpler could be if // input
export let a, b;
console.log({a, b} = someObject);
// output
let a, b;
console.log(exports({a, b} = someObject, {a: a, b: b})); JS semantics will make sure the first argument is evaluated before the second is evaluated. This could be the "inline expression form" of exports where you list the updates contained in an expression inline with an expression. Could also have a three argument version for single updates, e.g. exports({a} = someObject, 'a', a) |
63cfa96
to
472c60f
Compare
Could also be an additional handler attached to |
@lukastaegert good suggestions. I like the idea of switching the object form to take an expression first a lot. There may well be a format update to use generators at some point (systemjs/systemjs#1826). If this happens we could update to use object-setters only like |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Closes #2556
Description
This will make sure variables defined via a destructuring assignment are exported when building SystemJS output. Example:
The exports are added inline with the declaration as otherwise the rendering logic would have become quite a bit more complex to get the indentation right.
Update: This will now also update exported variables which are reassigned in a non-declaration destructuring assignment via injecting an IIFE! Example:
As far as I can see, this transformation should always produce valid, though not 100% readable, code but please check if I missed something.