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

Implement CS2 behavior when not enough values are given to an expansion assignment #1283

Open
alangpierce opened this issue Mar 19, 2018 · 2 comments

Comments

@alangpierce
Copy link
Member

decaffeinate is producing the wrong JavaScript based on my CoffeeScript input:

f = (a, ..., b, c, d) ->
  return [a, b, c, d]
console.log(f(1, 2))
[a, ..., b, c, d] = [1, 2]
console.log([a, b, c, d])

(repl)

When run through CS1 or decaffeinate, the code prints this:

[1, undefined, 1, 2]
[1, undefined, 1, 2]

But CS2 gives this output:

[1, 2, undefined, undefined]
[1, 1, 2, undefined]

CS2 switched to a slice-and-destructure approach that behaves differently here, so the straightforward approach is to replicate that behavior when in CS2 mode.

@alangpierce alangpierce changed the title Implement CS2 behavior when not enough values are given to an expansion node Implement CS2 behavior when not enough values are given to an expansion assignment Mar 19, 2018
@alangpierce
Copy link
Member Author

cc @GeoffreyBooth in case you consider this an unintentional breaking change in CS2. (It's hopefully pretty obscure and not something people would rely on in practice anyway.)

@GeoffreyBooth
Copy link

There have been a bunch of bugfixes regarding this in the last few weeks; see the changelog for 2.2.0 and newer. There’s one more bugfix on master I’ll be releasing soon, but I don’t think it affects this issue.

So I guess please make sure you’re on the latest CoffeeScript, maybe even master, and open an issue on the CoffeeScript repo if you think the output is incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants