Skip to content
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

Reform operator spread #863

Merged
merged 4 commits into from
Mar 15, 2016
Merged

Conversation

rhendric
Copy link
Collaborator

Per conversation in #831, these commits make breaking changes to operator spreading.

  • Operator spreading now requires a splat: typeof ...[0] => [typeof 0]
  • Operator spreading now supports objects: typeof ...{a: 0} => {a: typeof 0}
  • The LHS of assignment operators can also be spread: ++...a{b, c} can be written as ...a{b, c} += 1

foo ...+...a<[b c]> => foo.apply(null, [+a['b'], +a['c']]) works.
(...a=b) -> never really worked (an array, even empty, will never be nullish) but is now an explicit error.

Close #831

Prior to this commit, unary operator spreading happened implicitly,
leading to surprises like typeof [] != typeof [0] (== [typeof 0]).

With this commit, a splat is required prior to the array being spread
over: typeof ...[0] == [typeof 0]. Implicit operator spreading is no
longer handled; typeof [0] is just typeof [0].
This enables ...[a, b] += 1 to have the same meaning as ++..[a, b].
@vendethiel
Copy link
Contributor

That looks good! It might take me a few days before I can actually review it though.
I'd gladly hear anyone's opinions on this PR. Especially if someone happens to find a case where syntaxes conflict :).

I might also want to add a few more tests. It's a pretty big change.

When merged, I'll also create an issue to track the docs state about this.

@vendethiel vendethiel mentioned this pull request Mar 2, 2016
8 tasks
@dead-claudia
Copy link
Contributor

I like the DRY aspect of this. And I can't think of any way this could currently conflict with standard argument spreading. And +1 for making odd edge cases explicit errors.

vendethiel added a commit that referenced this pull request Mar 15, 2016
@vendethiel vendethiel merged commit 18e3e72 into gkz:master Mar 15, 2016
@vendethiel
Copy link
Contributor

Seems like no one objected, so I'm just gonna merge it :). Thanks.

@rhendric rhendric mentioned this pull request May 17, 2017
This was referenced Jan 11, 2018
@rhendric rhendric deleted the reform-operator-spread branch May 4, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants