From 4acac5a9591eeb0776b3bef53357781a793b9535 Mon Sep 17 00:00:00 2001 From: jiangyanfu Date: Wed, 25 Jul 2018 11:20:16 +0800 Subject: [PATCH] Remove a single line of code with a single line comment. The format of the comment is `removeSingleIf(conditions)` --- index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.js b/index.js index 49e68ac..c3d3fbb 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,7 @@ function applyReplacements (buffer, {commentTypes, conditions}) { if (buffer.length > 0) { for (const [key, value] of conditions) { for (const [commentStart, commentEnd] of commentTypes) { + // console.log(commentStart + commentEnd); const regex = getRemovalTagsRegExp(commentStart, commentEnd, key) contents = contents.replace(regex, function (ignore, original, capture) { @@ -56,6 +57,7 @@ function getRemovalTagsRegExp (commentStart, commentEnd, key) { const escapedCommentStart = escapeStringRegexp(commentStart) const escapedKey = escapeStringRegexp(key) const escapedCommentEnd = escapeStringRegexp(commentEnd) + const pattern = [ '(', escapedCommentStart, @@ -70,6 +72,15 @@ function getRemovalTagsRegExp (commentStart, commentEnd, key) { escapedKey, '\\)\\s*', escapedCommentEnd, + ')', + '|', + '(', + '.*', + escapedCommentStart, + '\\s*removeSingleIf\\((!?)', + escapedKey, + '\\)\\s*', + escapedCommentEnd, ')' ].join('') const re = new RegExp(pattern, 'gi')