js2coffee / js2coffee

Compile JavaScript to CoffeeScript

Home Page:http://js2.coffee

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: parentheses are removed when converting `+` expressions

marnen opened this issue · comments

JavaScript input:

var x = 5;
'Chapter ' + (x + 1);

(returns Chapter 6)

Expected CoffeeScript output:

x = 5
'Chapter ' + (x + 1)

Actual CoffeeScript output:

x = 5
'Chapter ' + x + 1

(returns Chapter 51)

The issue here is that + is overloaded in JavaScript to have different semantics with numbers and strings. If all operands are of one type, then parentheses don't matter, but when both numbers and strings are involved, the values are converted at different times, leading to different results depending on parenthesization.

It's been over a month with no response. Any update? Do you need more info or help from me?

🎤 Hello? Is this thing on? :)
Anyway, the issue still exists, even though one might guess that a343552 would have dealt with it...what can I do to help?

I just stumbled over the very same issue. Those parens are important.They shouldn't be removed.