UNPKG

625 BJavaScriptView Raw
1/**
2 * Remove everything in a file except JSDoc-style comments. By enabling this plugin, you can
3 * document source files that are not valid JavaScript (including source files for other languages).
4 * @module plugins/commentsOnly
5 */
6'use strict';
7
8exports.handlers = {
9 beforeParse: function(e) {
10 // a JSDoc comment looks like: /**[one or more chars]*/
11 var comments = e.source.match(/\/\*\*[\s\S]+?\*\//g);
12
13 if (comments) {
14 e.source = comments.join('\n\n');
15 } else {
16 e.source = ''; // If file has no comments, parser should still receive no code
17 }
18 }
19};