UNPKG

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