Mystery comma before close-paren


#1

The following code appears to be legal (at least sketch.sh manages to produce the value 4).

let f = x => x + 1;
f(3,);  

This “extra comma” is also sometimes inserted during reformatting of code, probably by merlin or something.

I’m wondering what’s going on here – can someone enlighten me?


#2

Reason supports trailing commas. But it shouldn’t insert trailing commas when the code fits on a single line. If it does you may want to check if there’s an existing bug report or file one.


#3

Thanks!

Is there an explanation for the choice to accept trailing commas? If it’s “It was a really big pain to disallow them,” that’s fine. But if it was intentional, I’d love to see a reason why one would ever want this – it sure looks ugly to my eye.

I’ll see if I can find an example of the toolchain inserting a comma where there was not one previously, and file a report if I can.


#4

One of (if not the) main reason for trailing commas, when spanning multiple lines, is the ability to add more arguments at the end of the list without causing an extra changed line in your git diff to add the required comma after the preceding argument.