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

[CS2] Array destructuring bug #4657

Closed
boris-petrov opened this issue Aug 21, 2017 · 7 comments
Closed

[CS2] Array destructuring bug #4657

boris-petrov opened this issue Aug 21, 2017 · 7 comments
Labels

Comments

@boris-petrov
Copy link

boris-petrov commented Aug 21, 2017

x = ([a..., b]) ->
  console.log a, b

x [1, 2, 3, 4]

This produces the incorrect:

var x,
  slice = [].slice;

x = function(arg) {
  var arg, i;
  a = 2 <= arg.length ? slice.call(arg, 0, i = arg.length - 1) : (i = 0, []), b = arg[i++];
  return console.log(a, b);
};

x([1, 2, 3, 4]);

As you can see, the variable a is not defined anywhere and this blows up.

Using CoffeeScript 2.0.0-beta4.

PS. Actually b is not defined either.

@vendethiel
Copy link
Collaborator

Fixed by #4640. Not yet released.

@boris-petrov
Copy link
Author

@vendethiel - is this supposed to be fixed in beta5? I have a case where it doesn't work with it. Should I try to create a small reproduction or the fix for this is not merged in beta5?

@vendethiel
Copy link
Collaborator

Please try to create a repro

@helixbass
Copy link
Collaborator

@GeoffreyBooth this seems to have been introduced by #4478. Should be reopened

([a..., b]) -> illustrates the problem - a and b aren't declared in the compilation:

var slice = [].slice;

(function(arg) {
  var arg, i;
  a = 2 <= arg.length ? slice.call(arg, 0, i = arg.length - 1) : (i = 0, []), b = arg[i++];
});

@helixbass
Copy link
Collaborator

Should be fixed by #4683

@GeoffreyBooth GeoffreyBooth reopened this Sep 3, 2017
GeoffreyBooth added a commit to helixbass/copheescript that referenced this issue Sep 3, 2017
@boris-petrov
Copy link
Author

Thanks for the quick fixes. I'll wait for beta6 then, hopefully it comes out soon. :)

GeoffreyBooth pushed a commit that referenced this issue Sep 7, 2017
* destructuring fixes [Fixes #4673] [Fixes #4657]

* test for destructured @prop

* Add another test to cover #4657 cases

* don't declare actual params
@GeoffreyBooth
Copy link
Collaborator

Fixed by #4683.

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

No branches or pull requests

4 participants