commentsOnly.js 602 B

1234567891011121314151617
  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. exports.handlers = {
  7. beforeParse(e) {
  8. // a JSDoc comment looks like: /**[one or more chars]*/
  9. const comments = e.source.match(/\/\*\*[\s\S]+?\*\//g);
  10. if (comments) {
  11. e.source = comments.join('\n\n');
  12. } else {
  13. e.source = ''; // If file has no comments, parser should still receive no code
  14. }
  15. }
  16. };