Fixes #572 - empty elements removal.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 14 May 2015 17:43:53 +0000 (18:43 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 14 May 2015 20:27:34 +0000 (21:27 +0100)
So we shared `token` variable among more than one context, which was
causing issues when removing empty elements.

History.md
lib/selectors/optimizers/simple.js
test/media-queries-test.js

index c8a6b9e..49b5289 100644 (file)
 * Fixed issue [#517](https://github.com/jakubpawlowicz/clean-css/issues/517) - turning off color optimizations.
 * Fixed issue [#542](https://github.com/jakubpawlowicz/clean-css/issues/542) - space after closing brace in IE.
 
+[3.2.10 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.2.9...3.2)
+==================
+
+* Fixed issue [#572](https://github.com/jakubpawlowicz/clean-css/issues/572) - empty elements removal.
+
 [3.2.9 / 2015-05-08](https://github.com/jakubpawlowicz/clean-css/compare/v3.2.8...v3.2.9)
 ==================
 
index 888e95b..6582d83 100644 (file)
@@ -290,11 +290,10 @@ SimpleOptimizer.prototype.optimize = function(tokens) {
   var ie7Hack = options.compatibility.selectors.ie7Hack;
   var adjacentSpace = options.compatibility.selectors.adjacentSpace;
   var spaceAfterClosingBrace = options.compatibility.properties.spaceAfterClosingBrace;
-  var token;
 
   function _cleanupCharsets(tokens) {
     for (var i = 0, l = tokens.length; i < l; i++) {
-      token = tokens[i];
+      var token = tokens[i];
 
       if (token[0] != 'at-rule')
         continue;
@@ -317,7 +316,7 @@ SimpleOptimizer.prototype.optimize = function(tokens) {
     var mayHaveCharset = false;
 
     for (var i = 0, l = tokens.length; i < l; i++) {
-      token = tokens[i];
+      var token = tokens[i];
 
       switch (token[0]) {
         case 'selector':
index 3a54c9a..13a8943 100644 (file)
@@ -19,6 +19,14 @@ vows.describe('media queries')
       'get merged': function(minified) {
         assert.equal(minified.styles, '@font-face{font-family:A}@font-face{font-family:B}');
       }
+    },
+    'with empty selector': {
+      'topic': function () {
+        return new CleanCSS().minify('@media screen{a{color:red}div{}}');
+      },
+      'get merged': function(minified) {
+        assert.equal(minified.styles, '@media screen{a{color:red}}');
+      }
     }
   })
   .addBatch({