Skip to content

Fix destructuring assignment when assignment target is RHS#21219

Merged
rbuckton merged 2 commits into
masterfrom
fix19020
Jan 17, 2018
Merged

Fix destructuring assignment when assignment target is RHS#21219
rbuckton merged 2 commits into
masterfrom
fix19020

Conversation

@rbuckton

Copy link
Copy Markdown
Contributor

This fixes destructuring assignments and variable destructuring when the assignment target is the same identifier as the RHS.

Fixes #19020

@rbuckton rbuckton requested a review from weswigham January 17, 2018 01:00

@weswigham weswigham left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs the typescriptserver.d.ts api update included, but otherwise seems good.

@ajafff

ajafff commented Jan 17, 2018

Copy link
Copy Markdown
Contributor

AFAICT this PR only handles identifiers. This is an issue for property access as well.

({foo, bar} = foo.bar);
// or
({foo: foo.bar, bar} = foo.bar);

I don't know if this is really necessary or just theoretically possible but never actually used in real world code.

@rbuckton

Copy link
Copy Markdown
Contributor Author

@ajafff we already handle ({ foo, bar } = foo.bar), but you are correct that this doesn't resolve ({foo: foo.bar, bar} = foo.bar), however it looks like babel doesn't handle this case either. Also, neither TS nor Babel supports ({ foo: foo.bar, bar } = foo) correctly either. There's also no way to know whether ({ foo: foo.bar, bar } = baz) will have the wrong semantics if baz points to the same object as foo.

For now I'd consider this "good enough". The only other change we could make would be to create temporaries for every result before we begin assignments, however this can generate a lot of temporaries.

@rbuckton rbuckton merged commit 004f18f into master Jan 17, 2018
@rbuckton rbuckton deleted the fix19020 branch January 17, 2018 19:22
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong emit for destructuring assignment

4 participants