- Notifications
You must be signed in to change notification settings - Fork2k
[CS2] Destructuring object spreads#4493
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…ipt into destructuring
…ture `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[`
This dramatically improves the appearance of destructured imports.
…ture `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[`
GeoffreyBooth commentedApr 9, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@zdenko Can you please merge If it’s easier to start a new branch that branches off of |
danielbayley commentedApr 9, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
What about when merging objects like this? letobj={a:1,b:2,c:3,d:4}letoverride={b:'b',d:'d'}constmerged={...obj, ...override} Whichworks with the |
OK, that's definitely me done now@GeoffreyBooth. My last concern was the grammar, which didn't account for things like I didn't add tests for those things, and it's really late here now. Other than that, I think this is good to go (of course, as a contributor to the PR I now can't be trusted to be impartial 😄). |
At this point I’d rather merge it in and handle additional edge cases as further PRs. This has become an epic. Last call! |
…ing_object# Conflicts:#test/argument-parsing.coffee
So I was writing the documentation for this, and the example I came up with doesn’t compile: user=name:'Werner Heisenberg'occupation:'theoretical physicist'currentUser= user...status:'Uncertain'
However changing |
@GeoffreyBooth this works
I've tried to make it work without the |
Okay, well at least it just throws a compiler error for now. So if we figure out how to support that syntax later, we can add it in a later PR. |
That's probably related to Tbh we probably want to leave it like this, or we'll need to face down ambiguities in expressions like fk: v, rest... Which, currently, will compile to two arguments (an object literal and a splat param) but would be ambiguous if we allowed splats to exist in implicit objects. |
Replacing#4473 andGeoffreyBooth#4. From original descriptions by@zdenko:
Connected to#3894.
In CS2 emit
to
Improve destructuring assignment for object literal:
Basically, implement proposal forrest properties for ECMAScript in CS:
{a, b, c...} = x
Since this proposal isn't yet at stage-4, CS doesn't compile to ES.
In my PR I catch rest element and assign remaining values to it:
{a, b, c...} = x
compiles to:a = x.a, b = x.b, c = extractObjectWithoutKeys(x, ['a', 'b'])
Multiple rest elements are disallowed. ES also requires the rest element to be the last, so compiler currently throws an error.
IMHO, CS should allow rest element anywhere, just like for arrays.
Later, when proposal reaches stage-4 we could implement similar conversion as you did for the function parameters, and ensure rest element is the last in the compiled JS.