js2coffee / js2coffee

Compile JavaScript to CoffeeScript

Home Page:http://js2.coffee

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In expressions such as "text" + (1 + 2), parentheses are lost.

kindaro opened this issue · comments

Hello.

Let me commence with an example.

% cat > example.js
console.log ( "text" + (1+2) );
% node example.js
text3
% js2coffee example.js > example.coffee
% coffee example.coffee
text12

What happens here is:

  • In JS case, the numeric sum in parentheses is calculated, then casted to string.
  • In CoffeeScript case, the numbers are casted to strings one by one.

I believe the (+) operator is generally not associative in JavaScript because of the possibility of implicit casts. So maybe we should preserve parentheses.