extract-comments
Version:
Uses esprima to extract line and block comments from a string of JavaScript. Also optionally parses code context (the next line of code after a comment).
24 lines (19 loc) • 416 B
JavaScript
;
/**
* Create a new LineComment.
*
* @param {String} `str` string of JavaScript
* @param {Object} `token` Parsed AST token
*/
class LineComment {
constructor(str, token) {
Object.assign(this, token);
this.range = token.range || [token.start, token.end];
this.raw = token.value;
this.value = this.raw.trim();
}
}
/**
* expose `LineComment`
*/
module.exports = LineComment;