I found an strange behavior of coffee compiler on an simple expression, which differs from a interactive compiler reaction at coffeescript.org site.
When I try to compile next string with coffee:
(console.log i; break) for i in [0..10]
I got:
SyntaxError: In repl, cannot use a pure statement in an expression.at SyntaxError (unknown source) ...
But the same expression in interactive compiler at coffescript.org compiled just fine, as expected by me to:
var i, _i;
for (i = _i = 0; _i <= 10; i = ++_i) {
console.log(i);
break;
}
Why coffee don't like () grouping here?
UPD
Another strange thing - it happens not always, sometimes, after a lot of tries and variations, coffee starts to compile absolutely the same expression normally, without errors.
But seems like in interactive mode, coffee fails always.
Another strange thing I found - this error happens only when I use the 'break' keyword. Expression '(console.log i; i+1) for i in [0..5]' works just fine and returns an array.
The problem is that the REPL tries to give you the result of every expression (and save it as _
). So internally, it's compiling
_ = ((console.log i; break) for i in [0..10])
which breaks the compiler because you can't use break
in a list comprehension.
I would recommend creating myfile.coffee
in your favorite editor and running it (coffee myfile.coffee
) rather than using the REPL.