sourcetag.js 1.6 KB

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