UNPKG

1.61 kBJavaScriptView Raw
1/**
2 * @module plugins/sourcetag
3 */
4'use strict';
5
6var logger = require('jsdoc/util/logger');
7
8exports.handlers = {
9 /**
10 * Support @source tag. Expected value like:
11 *
12 * { "filename": "myfile.js", "lineno": 123 }
13 *
14 * Modifies the corresponding meta values on the given doclet.
15 *
16 * WARNING: If you are using a JSDoc template that generates pretty-printed source files,
17 * such as JSDoc's default template, this plugin can cause JSDoc to crash. To fix this issue,
18 * update your template settings to disable pretty-printed source files.
19 *
20 * @source { "filename": "sourcetag.js", "lineno": 9 }
21 */
22 newDoclet: function(e) {
23 var tags = e.doclet.tags;
24 var tag;
25 var value;
26
27 // any user-defined tags in this doclet?
28 if (typeof tags !== 'undefined') {
29 // only interested in the @source tags
30 tags = tags.filter(function($) {
31 return $.title === 'source';
32 });
33
34 if (tags.length) {
35 // take the first one
36 tag = tags[0];
37
38 try {
39 value = JSON.parse(tag.value);
40 }
41 catch (ex) {
42 logger.error('@source tag expects a valid JSON value, like { "filename": "myfile.js", "lineno": 123 }.');
43
44 return;
45 }
46
47 e.doclet.meta = e.doclet.meta || {};
48 e.doclet.meta.filename = value.filename || '';
49 e.doclet.meta.lineno = value.lineno || '';
50 }
51 }
52 }
53};