diff --git a/index.js b/index.js index 7425bdf..3bb9636 100644 --- a/index.js +++ b/index.js @@ -22,11 +22,20 @@ const { utils } = lib; class Comments extends Emitter { constructor(options = {}) { super(); - this.options = options; + this.options = Object.assign({commentStart: '/*'}, options); this.comments = []; this.parsers = {}; this.tokens = []; this.ast = {}; + + console.log(this.options) + + if (this.options.commentStart) { + this.options.commentStart = this.options.commentStart.replace(/([\*\/\(\)])/g, "\\$1") + } + if (this.options.commentEnd) { + this.options.commentEnd = this.options.commentEnd.replace(/([\*\/\(\)])/g, "\\$1") + } } /** @@ -45,7 +54,9 @@ class Comments extends Emitter { tokenize(input, options) { let opts = Object.assign({}, this.options, options); // this only needs to be roughly correct. the tokenizer is smarter - let isComment = str => /^(\s*\/\*|\*\s*@| {4,})/gm.test(str); + // let isComment = str => /^(\s*\/\*|\*\s*@| {4,})/gm.test(str); + var re = new RegExp("^(\\s*" + opts.commentStart + "|\\*\\s*@| {4,})", "gm"); + let isComment = str => re.test(str); if (opts.stripStars === void 0 && input && !isComment(input)) { opts.stripStars = false; } diff --git a/lib/utils.js b/lib/utils.js index 139b5ce..1d9cc68 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -78,8 +78,8 @@ exports.last = (arr = [], n = 1) => arr[arr.length - n]; * @return {Boolean} */ -exports.isProtectedComment = str => /^\/\*{1,2}\s*!/.test(str);; - +// exports.isProtectedComment = str => /^\/\*{1,2}\s*!/.test(str);; +exports.isProtectedComment = str => /^\(\*{1,2}\s*!/.test(str);; /** * Returns true if the given comment `str` is a config comment that contains * `eslint`, `global`, `jshint`, `jslint` etc. @@ -103,7 +103,8 @@ exports.isConfigComment = (str, names = '[ej]s[hl]int') => { */ exports.isValidBlockComment = (comment, options = {}) => { - let regex = options.allowSingleStar ? /^\s*\/\*/ : /^\s*\/\*\*/; + // let regex = options.allowSingleStar ? /^\s*\/\*/ : /^\s*\/\*\*/; + let regex = options.allowSingleStar ? new RegExp("/^\\s*" + options.commentStart + "/") : new RegExp("/^\\s*" + options.commentStart + "\\*/"); if (typeof comment === 'string') { return regex.test(comment); } @@ -111,9 +112,9 @@ exports.isValidBlockComment = (comment, options = {}) => { case 'block': case 'commentblock': case 'blockcomment': - if (!options.allowSingleStar) { - return comment.raw[0] === '*'; - } + // if (!options.allowSingleStar) { + // return comment.raw[0] === '*'; + // } return true; default: { return false;