jashkenas/coffee-script — Issue #2108: Functions in loops and conditionals fail unless parenthesized
Author: joliss
Created: 2012-02-06 19:30:16+00:00
State: open

$ coffee -bsc
if func -> e
0
Error: Parse error on line 1: Unexpected 'POST_IF'
at Object.parseError (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/parser.js:470:11)
at Object.parse (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/parser.js:546:22)
at Object.compile (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/coffee-script.js:40:22)
at /usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/command.js:140:33
at ReadStream. (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/command.js:167:14)
at ReadStream.emit (events.js:61:17)
at ReadStream._onReadable (net.js:658:51)
at IOWatcher.onReadable [as callback] (net.js:177:10)
$ coffee -bsc
for i in func -> e
0
Error: Parse error on line 1: Unexpected 'INDENT'
at Object.parseError (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/parser.js:470:11)
at Object.parse (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/parser.js:546:22)
at Object.compile (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/coffee-script.js:40:22)
at /usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/command.js:140:33
at ReadStream. (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/command.js:167:14)
at ReadStream.emit (events.js:61:17)
at ReadStream._onReadable (net.js:658:51)
at IOWatcher.onReadable [as callback] (net.js:177:10)

Adding parentheses like `func(-> e)` makes it work as expected.

It seems to me that this is an issue with the parser, and the code above should in fact be legal CoffeeScript.