documentation/lib/is_jsdoc_comment.js
Tom MacWright 7b156d8769 Babel! 🙌
cc @jfirebaugh for the review

This was easier than expected.
2015-10-04 21:55:54 -04:00

21 lines
729 B
JavaScript

'use strict';
/**
* Detect whether a comment is a JSDoc comment: it must be a block
* comment which starts with two asterisks, not any other number of asterisks.
*
* The code parser automatically strips out the first asterisk that's
* required for the comment to be a comment at all, so we count the remaining
* comments.
*
* @name isJSDocComment
* @param {Object} comment an ast-types node of the comment
* @return {boolean} whether it is valid
*/
module.exports = function isJSDocComment(comment) {
var asterisks = comment.value.match(/^(\*+)/);
return (comment.type === 'CommentBlock' || // estree
comment.type === 'Block') // get-comments / traditional
&& asterisks && asterisks[ 1 ].length === 1;
};