Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document CoffeeScript source code with JSDoc?

I have some code written in CoffeeScript and I want to optimize the generated JavaScript with the Google Closure Compiler, so these files need to be documented with JSDoc.

My question is, how can I document the *.coffee files to generate javascript containing working JSDoc for the closure compiler?

One more question: is there a way to keep a single-line comment in *.coffee ?

like image 984
aztack Avatar asked Oct 20 '11 08:10

aztack


People also ask

What is JSDoc comment?

JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.

What is JSDoc in Nodejs?

JSDoc is an open source API documentation generator for Javascript. It allows developers to document their code through comments.

Why is JSDoc important?

JSDoc's purpose is to document the API of your JavaScript application or library. It is assumed that you will want to document things like modules, namespaces, classes, methods, method parameters, and so on. JSDoc comments should generally be placed immediately before the code being documented.


1 Answers

CoffeeScript Input:

### define function variable before block to avoid code being appended to closing part of JSDoc comment ### cube = null  ###*  * Function to calculate cube of input  * @param {number} Number to operate on  * @return {number} Cube of input  ###  cube = (x) -> x*x*x 

JavaScript Output from windows cmd prompt for: coffee -cpb src.coffee

// Generated by CoffeeScript 1.6.3 /* define function variable before block to avoid code being appended to closing part of JSDoc comment*/  var cube;  cube = null;  /**  * Function to calculate cube of input  * @param {number} Number to operate on  * @return {number} Cube of input */  cube = function(x) {   return x * x * x; }; 

Edit

As detailed in other answer CoffeeScript 1.7.1 has better method available to solve this problem.

like image 158
Billy Moon Avatar answered Sep 23 '22 20:09

Billy Moon