2012-10-15 53 views
5

我試圖記錄與JSDoc JavaScript文件(3)像這樣:JSDoc - 標記一些代碼不被解析但保留文檔?

/** 1 if gnome-bluetooth is available, 0 otherwise        
* @type {boolean}                
* @const                                   
*/                    
const HAVE_BLUETOOTH = @[email protected];          

現在的文件(稱爲config.js.in)是不是對自己有效的JavaScript;該文件將通過一個Makefile替換適當的值爲@[email protected]

當我嘗試在此上運行JSdoc時,它(可以理解)由於文件中的語法錯誤而變得遲鈍。

是否有某種方式來告訴JSDoc忽視在這個文件中的所有代碼,但單純考慮註釋? (我可能需要爲每個doclet添加@name標記,以將代碼中的文檔完全分開;這很好)。

喜歡的東西:

/** 1 if gnome-bluetooth is available, 0 otherwise        
* @name HAVE_BLUETOOTH 
* @type {boolean}                
* @const                 
*/      
/** @ignore */ // somehow ignore from here onwards 
const HAVE_BLUETOOTH = @[email protected]; 
/** [email protected] */ // somehow don't ignore from here onwards (although I'd be happy 
       // to ignore the entire file) 

我寧願不修改文件的代碼的一部分,如果可能的話(我的文檔添加到現有的項目)。例如,我也許可以繞過它與

const HAVE_BLUETOOTH = parseInt('@[email protected]', 10); 

這將使該文件又具有有效的JS語法,這樣分析器不抱怨,但是這也意味着我修改原始文件的代碼這是我想避免的(我更喜歡只是添加文檔)。

歡呼

+1

您是否找到解決方法? –

+0

難道你不能改變管道,以便jsdoc在你縮小之前在一箇中間的編譯版本上運行嗎?如果沒有,那麼一個不太侵入性的代碼破解是const HAVE_BLUETOOTH = +'@ HAVE_BLUETHOOTH @'; – lemonzi

回答

0

我的情況是類似的,因爲我使用JSDoc評論我.less.css文件。當我在一組文件上運行JSDoc時,我遇到了同樣的問題。

所以,我解決我的問題(與JSDoc 3.3.3)與commentsOnly JSDoc插件

我創建這個config.json

{ 
    "source": { 
     "includePattern": ".+\\.(css|less)?$" 
    }, 
    "plugins": [ 
     "plugin/commentsOnly" 
    ] 
} 

commentsOnly.js文件轉換成plugin/目錄(考慮plugin/config.json在同一文件夾),該文件夾我執行以下CLI命令在:

jsdoc -c ./config.json ./assets/stylesheets/common.less 

而且它的工作!沒有理由不對你的文件起作用。

希望我能幫到您;)