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 b532b4e commit 98254d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
[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 @@ -491,10 +491,7 @@ function optimizeBody(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 @@ -654,7 +651,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 98254d1

Please sign in to comment.