jashkenas/coffee-script — Issue #1772: x = y /* z */
Author: TrevorBurnham
Created: 2011-10-16 03:05:39+00:00
State: open

Someone on Stack Overflow recently posted [a question on comments](http://stackoverflow.com/questions/7781685/coffeescript-how-to-comment), where they said that

/* comment goes here */

seems to work when it's not on its own line. An example would be

x = y /* z */

which compiles to

x = y(/* z */);

Of course, a JS interpreter will just see that as `x = y();`. A more harmful example is

x = /* z */

which compiles fine but will obviously cause a runtime error.

The sensible solution is to add a compile-time error for such block comments or, ideally, for all invalid regexes. Note that `new RegExp('* z *')` gives you the helpful feedback `SyntaxError: Invalid regular expression: /* z */: Nothing to repeat`.