js2coffee breaks with javascript ternary operator inside of method call #395

Open
daraosn opened this Issue Aug 29, 2015 · 0 comments

Projects

None yet

1 participant

@daraosn
daraosn commented Aug 29, 2015

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment