Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maintaining comments in .js files after compilation from .coffee

I'd like to keep the comments I write in my CoffeeScript files intact in the outputted JavaScript files. How can I do that?

#!/usr/bin/env bash

./node_modules/.bin/coffee --output lib/ --compile --bare --watch src/
like image 803
typeoneerror Avatar asked Mar 15 '12 16:03

typeoneerror


2 Answers

From the coffee-script documentation:

Block comments, which mirror the syntax for heredocs, are preserved in the generated code.

This (borrowing from typeonerror's reply below - neat!):

###*
# This will be preserved in a block comment in the javascript
###

Compiles to this:

/**
 * This will be preserved in a block comment in the javascript
 */
like image 156
Linus Thiel Avatar answered Oct 29 '22 08:10

Linus Thiel


Expanding on Linus's answer above, I've found this to be the best style to get the comment style I wanted:

###*
# Hello world
# @param Object object
# @return String
###

Adding the first ### gate starts the comment and the additional * gives us

/**
 * Hello world
 * @param Object object
 * @return String
 */
like image 39
typeoneerror Avatar answered Oct 29 '22 09:10

typeoneerror