Skip to content

Commit

Permalink
Fixes #549 - keeping special comments in source maps.
Browse files Browse the repository at this point in the history
Since in source maps we restore content multiple times, the total
important comment counter was not kept as a state thus handled
incorrectly.
  • Loading branch information
jakubpawlowicz committed Apr 25, 2015
1 parent 05aac31 commit 932faf5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -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)
==================
Expand Down
6 changes: 3 additions & 3 deletions lib/text/comments-processor.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions test/source-map-test.js
Expand Up @@ -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({
Expand Down

0 comments on commit 932faf5

Please sign in to comment.