jarandaf jarandaf - 10 months ago 103
CoffeeScript Question

CoffeeScript comments in JavaScript output

Is there out any flag in the CoffeeScript compiler to add single-line coffee comments to Javascript output? I read some time ago it would be supported but it turns out this option still remains unavailable.

Answer Source

The easiest option is just to use block comments everywhere. A search/replace across your code base could take care of this in a trivially short time. You would change

# coffeescript one-line comment, not passed through to js

into this

### coffeescript block comment, which IS passed through to js ###

A harder option would be to mod coffeescript itself. For instance, the coffeescript lexer is very well documented, and shows that the regex used to identify block comments is:

COMMENT    = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)$)|^(?:\s*#(?!##[^#]).*)+/

By carefully modifying that regex, I imagine you could convince coffeescript that your single line comments were block comments, which again, are already passed through to js. I haven't tried this, however.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download