Skip to content

Commit

Permalink
Fixes #887 - edge case in serializing comments.
Browse files Browse the repository at this point in the history
Why:

* When `removeEmpty: false` is used then comments are not properly
  removed from a list of tokens.
  • Loading branch information
jakubpawlowicz committed Jul 8, 2017
1 parent a6e7757 commit 01f3626
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions History.md
Expand Up @@ -6,6 +6,11 @@
* Fixed issue [#895](https://github.com/jakubpawlowicz/clean-css/issues/895) - ignoring specific styles.
* Fixed issue [#947](https://github.com/jakubpawlowicz/clean-css/issues/947) - selector based filtering.

[4.1.6 / 2017-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.5...4.1)
==================

* Fixed issue [#887](https://github.com/jakubpawlowicz/clean-css/issues/887) - edge case in serializing comments.

[4.1.5 / 2017-06-29](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.4...v4.1.5)
==================

Expand Down
7 changes: 2 additions & 5 deletions lib/optimizer/level-1/optimize.js
Expand Up @@ -494,10 +494,7 @@ function optimizeBody(rule, properties, context) {

restoreFromOptimizing(_properties);
removeUnused(_properties);

if (_properties.length != properties.length) {
removeComments(properties, options);
}
removeComments(properties, options);
}

function removeComments(tokens, options) {
Expand Down Expand Up @@ -657,7 +654,7 @@ function level1Optimize(tokens, context) {
break;
}

if (levelOptions.removeEmpty && (token[1].length === 0 || (token[2] && token[2].length === 0))) {
if (token[0] == Token.COMMENT && token[1].length === 0 || levelOptions.removeEmpty && (token[1].length === 0 || (token[2] && token[2].length === 0))) {
tokens.splice(i, 1);
i--;
l--;
Expand Down
8 changes: 8 additions & 0 deletions test/optimizer/level-1/optimize-test.js
Expand Up @@ -261,6 +261,14 @@ vows.describe('level 1 optimizations')
'a{/* a comment */}',
'a{}'
],
'body with comment and ignored value': [
'.block{/* a comment */_color: red}',
'.block{}'
],
'top level comment': [
'/* comment */.block{}',
'.block{}'
],
'@media query': [
'@media screen{}',
'@media screen{}'
Expand Down

0 comments on commit 01f3626

Please sign in to comment.