satyr / coco

Unfancy CoffeeScript
http://satyr.github.com/coco/
MIT License
497 stars 48 forks source link

array slice + array repetition #147

Closed jedilando closed 12 years ago

jedilando commented 12 years ago

example1.co

[x[a], x[b]]*2

compiles correctly into

example1.js

var ref, ref1; [ref = x[a], ref1 = x[b], ref, ref1];

but

example2.co

x[a, b]*2

compiles into

example2.js

[x[a], x[b]] * 2;

As far as I understand example2.co should compile into example1.js

Coco 0.7.5 Windows XP

satyr commented 12 years ago

This was intentional (the additions currently says the left operand needs to be a literal) because correctly deducing the operand type is impossible in complex/dynamic cases.

Though seeing that string repetition does deduce to some extent and unary spread works on array slice, making this work probably doesn't hurt.

$ coco -bce '(x + "" + y) * 2'
var __ref;
(__ref = x + "" + y) + __ref;

$ coco -bce '+x[a, b]'
+x[a], +x[b];
jedilando commented 12 years ago

Ok, thanks for answer!