From: Jakub Pawlowicz Date: Sat, 25 Apr 2015 08:33:54 +0000 (+0100) Subject: Fixes #549 - keeping special comments in source maps. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=932faf50a56d73e2ee7cbd1037e2d0a42eadd75c;p=clean-css.git Fixes #549 - keeping special comments in source maps. Since in source maps we restore content multiple times, the total important comment counter was not kept as a state thus handled incorrectly. --- diff --git a/History.md b/History.md index ba02a06c..f4461efd 100644 --- a/History.md +++ b/History.md @@ -14,6 +14,7 @@ * Fixed issue [#543](https://github.com/jakubpawlowicz/clean-css/issues/543) - better "comment in body" handling. * Fixed issue [#548](https://github.com/jakubpawlowicz/clean-css/issues/548) - regression in font minifying. +* Fixed issue [#549](https://github.com/jakubpawlowicz/clean-css/issues/549) - special comments in source maps. [3.2.4 / 2015-04-24](https://github.com/jakubpawlowicz/clean-css/compare/v3.2.3...v3.2.4) ================== diff --git a/lib/text/comments-processor.js b/lib/text/comments-processor.js index dd0b07c0..874a216b 100644 --- a/lib/text/comments-processor.js +++ b/lib/text/comments-processor.js @@ -12,6 +12,7 @@ function CommentsProcessor(context, keepSpecialComments, keepBreaks, saveWaypoin this.specialComments = new EscapeStore('COMMENT_SPECIAL'); this.context = context; + this.restored = 0; this.keepAll = keepSpecialComments == '*'; this.keepOne = keepSpecialComments == '1' || keepSpecialComments === 1; this.keepBreaks = keepBreaks; @@ -96,7 +97,6 @@ CommentsProcessor.prototype.escape = function (data) { function restore(context, data, from, isSpecial) { var tempData = []; - var restored = 0; var cursor = 0; var addBreak; @@ -108,8 +108,8 @@ function restore(context, data, from, isSpecial) { tempData.push(data.substring(cursor, nextMatch.start)); var comment = from.restore(nextMatch.match); - if (isSpecial && (context.keepAll || (context.keepOne && restored === 0))) { - restored++; + if (isSpecial && (context.keepAll || (context.keepOne && context.restored === 0))) { + context.restored++; addBreak = context.keepBreaks && data[nextMatch.end] != '\n' && data.lastIndexOf('\r\n', nextMatch.end + 1) != nextMatch.end; tempData.push(comment, addBreak ? lineBreak : ''); } else { diff --git a/test/source-map-test.js b/test/source-map-test.js index ec6c8f09..f369d133 100644 --- a/test/source-map-test.js +++ b/test/source-map-test.js @@ -1033,6 +1033,14 @@ vows.describe('source-map') 'has right output': function (errors, minified) { assert.equal(minified.styles, 'div{color:red!important/*!1*//*!2*/}'); } + }, + 'important comments after a property with remove comments': { + 'topic': function () { + return new CleanCSS({ sourceMap: true, keepSpecialComments: 1 }).minify('div { color: #f00 !important; /*!1*/} /*!2*/ a{/*!3*/}'); + }, + 'has right output': function (errors, minified) { + assert.equal(minified.styles, 'div{color:red!important/*!1*/}a{}'); + } } }) .addBatch({