commentConvert.js 562 B

123456789101112131415161718192021
  1. /* eslint-disable spaced-comment */
  2. /**
  3. * Demonstrate how to modify the source code before the parser sees it.
  4. *
  5. * @module plugins/commentConvert
  6. */
  7. exports.handlers = {
  8. ///
  9. /// Convert ///-style comments into jsdoc comments.
  10. /// @param e
  11. /// @param e.filename
  12. /// @param e.source
  13. ///
  14. beforeParse(e) {
  15. e.source = e.source.replace(/(\n[ \t]*\/\/\/[^\n]*)+/g, $ => {
  16. const replacement = `\n/**${$.replace(/^[ \t]*\/\/\//mg, '').replace(/(\n$|$)/, '*/$1')}`;
  17. return replacement;
  18. });
  19. }
  20. };