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

Open
kindaro opened this Issue Jul 26, 2016 · 0 comments

Projects

None yet

1 participant

@kindaro
kindaro commented Jul 26, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment