coffeescript icon indicating copy to clipboard operation
coffeescript copied to clipboard

[[]] = f()

Open satyr opened this issue 15 years ago • 8 comments

$ coffee -bpe '[[]] = f()'
false;

satyr avatar Feb 01 '11 06:02 satyr

Related (?):

$ coffee -bpe 'for k, {} of o then'
var k;
for (k in o) {
  false;
}

satyr avatar Feb 01 '11 14:02 satyr

Also this one

[] = 1
{} = [1, 3, 5]
[] = {}

I think is has to do with attempting destructuring assignment.

OnesimusUnbound avatar Mar 23 '11 06:03 OnesimusUnbound

[] = 1 ...

Those are expected.

$ js -e 'print([] = 1)'
1

$ coffee -e 'console.log [] = 1'
1

satyr avatar Mar 23 '11 10:03 satyr

The expression [] = 1 will generate the JavaScript false;

> coffee -bpe "[] = 1"
false;

Using your first example, when the expression [[]] = f() is a parameter of console.log

> coffee -bpe "console.log [[]] = f()"
var _ref;
console.log((_ref = f(), _ref));

Again, the false; statement seems to appear in {} = expr or [] = expr. one - liner.

OnesimusUnbound avatar Mar 23 '11 12:03 OnesimusUnbound

The expression [] = 1 will generate the JavaScript false;

Oh right. Was assuming those were unaffected from the regression (at 4ce374be25f9d4c0698288bd65f46d24ad707712); not the case apparently.

satyr avatar Mar 23 '11 12:03 satyr

Looks like all the cases in this ticket were fixed by 230dea1243b544fdcf9aa2647cbb7128a03187a9 as well. Closing.

michaelficarra avatar Apr 09 '11 14:04 michaelficarra

230dea1243b544fdcf9aa2647cbb7128a03187a9

This effectively reverts #870. $ bin/coffee -bpe '[a, [], b] = c' var a, b; a = c[0], c[1], b = c[2];

satyr avatar Apr 09 '11 14:04 satyr

@satyr: Yeah, that optimization is now gone. But it was breaking other things anyway, so it was a bad optimization. I will open #870 so that someone can make a good optimization or just implement the [first, ..., last] syntax.

michaelficarra avatar Apr 09 '11 14:04 michaelficarra