js2coffee / js2coffee

Compile JavaScript to CoffeeScript

Home Page:http://js2.coffee

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

js2coffee breaks with javascript ternary operator inside of method call

daraosn opened this issue · comments

Using this javascript code:

ctx.drawImage(this.chase ? THEME_CHASE : THEME_NORMAL, -THEME_SPRITE.width/2, -THEME_SPRITE.height/2*1.5);

js2coffee outputs:

ctx.drawImage if @chase then THEME_CHASE else THEME_NORMAL, -THEME_SPRITE.width / 2, -THEME_SPRITE.height / 2 * 1.5

# ---
# generated by js2coffee 2.1.0

If you try to compile back that from Coffeescript to Javascript, it will break.

A suggested fix would be to output:

ctx.drawImage (if @chase then THEME_CHASE else THEME_NORMAL), -THEME_SPRITE.width / 2, -THEME_SPRITE.height / 2 * 1.5

I could reproduce using http://js2.coffee/ and on my local environment (OSX 10.10):

$ js2coffee -v
2.1.0
$ node -v
v0.12.6