-
Notifications
You must be signed in to change notification settings - Fork 2k
[CS2] Fix #4651: object spread destructuring bug #4652
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f9367ba
fix object spread destructuring bug: #4651
2664c2c
small fix
232041d
fixed issue with nested properties
2149c35
ensure Value; breaking test for {a={b...}} = c
helixbass 1a6477a
resolve merge conflicts
helixbass 2491d32
fix assign in nested properties
5a709ed
improve variable declaration
c212e6e
refactor
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think this is needed any more? I was having no problems without any of the
valueRefTempstuff.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.
Also - in the PR description you mention that object literals were not being cached, however they do appear to be on
2currently:http://coffeescript.org/v2/#try:%7Ba%2C%20r...%7D%20%3D%20%7Ba%3A1%2C%20b%3A2%7D
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.
@connec how did you get rid of the
valueRefTempreferences? How did you revise theline?
@zdenko please ignore the polyfill discussion, that’s been taken care of in a separate PR. Do you have time to address these last few notes so that we can merge this?
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.
@GeoffreyBooth yes, I'll take a look a.s.a.p.
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.
@connec I was wrong regarding the caching. It was probably my mistake in the code.
::shouldCache()andvalueRefTempare used to assign object literalvaluetorefvariable, e.g.{p: {m, q..., t = {obj...}}, r...} = c: 2=>({p: {m, t = Object.assign({}, obj)}} = ref = { c: 2}).The reason for use
valueRefTemphere, are cases where there are no rest elements in the destructuring, e.g.{a = {b...}} = c:1=>({a = Object.assign({}, b)} = {c: 1}).So, tests will pass if you remove
valueRefTempand use@valueas a parameter for thetraverseRest(), only the compiled code will be different.With
traverseRestTempand::shouldCache(){p: {m, q..., t = {obj...}}, r...} = c: 2 ### ({ p: {m, t = Object.assign({}, obj)} } = ref = { c: 2 }); q = objectWithoutKeys(ref.p, ['m', 't']); r = objectWithoutKeys(ref, ['p']); ###and without
{p: {m, q..., t = {obj...}}, r...} = c: 2 ### ({ p: {m, t = Object.assign({}, obj)} } = { c: 2 }); q = objectWithoutKeys({ c: 2 }.p, ['m', 't']); r = objectWithoutKeys({ c: 2 }, ['p']); ###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.
Sorry @zdenko, I think I must be misunderstanding something. If I remove the
valueTempRefstuff:And run the example you gave:
I get the desired output:
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.
Edit: in fact, I see that that output 'double-cached'
{c:2}(asrefandref1). I guess this is because@valueis assigned even if the function returns. The following patch avoids the double-cache:Sorry to be fussy about this, but I'd rather not proliferate manual caching code (e.g.
new IndentifierLiteral o.scope.freeVariable) whenNode::cachecould be used instead.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.
I've tried that before. With this approach
refvariable is still declared in the scope by call from::cachemethod:Check the full output:
{a = {b...}} = c:1 ### var a, ref; ^^^ ({a = Object.assign({}, b)} = { c: 1 }); ### {p: {m, q..., t = {obj...}}, r...} = c: 2 ### var m, q, r, ref, ref1, t, ^^^^ objectWithoutKeys = function(o, ks) { var res = {}; for (var k in o) ([].indexOf.call(ks, k) < 0 && {}.hasOwnProperty.call(o, k)) && (res[k] = o[k]); return res; }; ({ p: {m, t = Object.assign({}, obj)} } = ref = { c: 2 }); q = objectWithoutKeys(ref.p, ['m', 't']); r = objectWithoutKeys(ref, ['p']); ###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.
Aha, good catch 😢
In that case, this LGTM!