### */ ### #1050

satyr opened this Issue Jan 16, 2011 · 11 comments


None yet
6 participants

satyr commented Jan 16, 2011

$ coffee -e '### */ ###'

  /* */ */
SyntaxError: Unexpected token *

michaelficarra commented Jan 16, 2011

Nice catch.


TrevorBurnham commented Jan 16, 2011

But how should this be fixed? Generate a compiler error if a block comment contains */? Change each instance of */ to *//*? (What would then happen to /*/?) How can the user's intent best be preserved?

I'm guessing that if someone puts */ in a block comment, they'd like it to show up as */ in a documentation generator, e.g. Docco. Also, the * should be preserved because they might be using Markdown. So, my proposal is to replace */ with */ (where / is the HTML escape sequence for /). It's not a perfect solution, but it should cover most cases.


michaelficarra commented Jan 16, 2011

I agree, Trevor. Using the escape sequence for an asterisk is also a solution. Any reasons to pick one over the other?

Rixius commented Jan 17, 2011

the reason he suggested using the escape for '/' becaue the * may be used in Markdown evaluation.


michaelficarra commented Jan 17, 2011

Well, that's a good enough reason for me.

Looks like we can just change line 433 of nodes.coffee to

code = '/*' + multident(@comment.replace(/\*\//g,'*/'), @tab) + '*/'

michaelficarra commented Jan 17, 2011

Opened pull request #1053, fixing this issue.


jashkenas commented Jan 19, 2011

I'm afraid that translating to HTML entities isn't an acceptable solution. This is CoffeeScript to JavaScript -- not CoffeeScript to JS-that-might-be-displayed-within-HTML. If */ is an illegal sequence within a JS block comment, and there's no way to escape the slash (being a comment, with purely visual value), then it should be an illegal sequence in CoffeeScript as well. Patched at SHA: 4b78790


satyr commented Jan 19, 2011

FYI, Coco went ahead and fixed the syntax to /* */.
### ### was inadequate for several reasons:

  • Interferes with line comment, complicating both syntaxes.
  • Oddball as a hereX variant (all others take the form QQ -> QQQQQQ).
  • Awkward when you want:
  • This bug.

michaelficarra commented Jan 19, 2011

I wouldn't be against changing coffee's multiline comments to use /* */ syntax, but I'm probably alone.


TrevorBurnham commented Jan 19, 2011

I'd be fine with that, too. Can't think of any reason to prefer ###, really.

ozra commented Jan 27, 2011

Agreed. Heck - why not both!? AND I still like the proposition of converting */ to / - perhaps an optional modifier character after ### to mark the block for safe guarding?

Documentary stuff
* Below you'll find code for the magic things that has soon to work!


# Yeah! Everybody wins!

commented out and safe guarded */ */ */

function whyPhpStinks($beVerbose) {
    return "It's the scopes and..." /* let's just leave it! */
    function someJSFunction(param /*, thisp*/) { doStuff(param) }

@geraldalewis geraldalewis pushed a commit to geraldalewis/coffee-script that referenced this issue May 2, 2011

@jashkenas jashkenas Making #1050 a syntax error. 4b78790

This issue was closed.

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