Civet icon indicating copy to clipboard operation
Civet copied to clipboard

`jsCompat` flag for single-argument arrow functions without parens

Open edemaine opened this issue 2 years ago • 2 comments
trafficstars

We're planning to add a "civet jsCompat" directive (or esCompat?) that enables support for single-argument arrow functions without a paren, at the cost of no longer supporting zero-argument arrow functions without parens. Like coffeeCompat, this will be useful for gradually converting an existing code base. Also, many people are probably used to this notation so it's a useful alternative to offer.

Originally posted by @edemaine in https://github.com/DanielXMoore/Civet/issues/269#issuecomment-1399515111

Daniel suggested that jsCompat might also turn on a flag to disable all implicit (parenless) function calls, which would handle other weird behavior like for a of b {}.

More things for jsCompat flag:

  • More arrow stuff #667
  • catch with braced block #400
  • Braced blocks not always making object literals #1816

edemaine avatar Jan 22 '23 16:01 edemaine

Low priority for me; I just hope any weird non-JS compatible syntax is well documented. (eg mentioned on website 1-2 times, in blog posts, etc)

tomByrer avatar Jan 30 '23 20:01 tomByrer

For anyone migrating TS code in the meantime you can use this RegEx and replacement to wrap single non-parenthesized arrow arguments:

([a-zA-Z]*[^)]) =>
($1) =>

STRd6 avatar Aug 30 '23 02:08 STRd6