Fixes #758 - ignores rules with empty selectors.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 22 Dec 2016 21:18:33 +0000 (22:18 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 22 Dec 2016 21:18:33 +0000 (22:18 +0100)
History.md
lib/optimizer/tidy-rules.js
test/optimizer/basic-test.js

index 35cad47..378b51e 100644 (file)
@@ -12,6 +12,7 @@
 * Fixed issue [#657](https://github.com/jakubpawlowicz/clean-css/issues/657) - adds property name validation.
 * Fixed issue [#686](https://github.com/jakubpawlowicz/clean-css/issues/686) - adds rounding precision for all units.
 * Fixed issue [#756](https://github.com/jakubpawlowicz/clean-css/issues/756) - adds disabling font-weight optimizations.
+* Fixed issue [#758](https://github.com/jakubpawlowicz/clean-css/issues/758) - ignores rules with empty selector.
 * Fixed issue [#817](https://github.com/jakubpawlowicz/clean-css/issues/817) - makes `off` disable rounding.
 * Fixed issue [#818](https://github.com/jakubpawlowicz/clean-css/issues/818) - disables `px` rounding by default.
 * Fixed issue [#834](https://github.com/jakubpawlowicz/clean-css/issues/834) - adds extra line break in nested blocks.
index 38bbb3b..296b757 100644 (file)
@@ -187,6 +187,11 @@ function tidyRules(rules, removeUnsupported, adjacentSpace, beautify, warnings)
     list.push(rule);
   }
 
+  if (list.length == 1 && list[0][1].length === 0) {
+    warnings.push('Empty selector \'' + list[0][1] + '\' at ' + formatPosition(list[0][2][0]) + '. Ignoring.');
+    list = [];
+  }
+
   return list.sort(ruleSorter);
 }
 
index ba712e9..4c9cd54 100644 (file)
@@ -100,6 +100,10 @@ vows.describe('simple optimizations')
       'quotes #2': [
         '.b[data-json=\'"aaaa":"bbbb"\']{color:red}',
         '.b[data-json=\'"aaaa":"bbbb"\']{color:red}'
+      ],
+      'no rule scope': [
+        '{overflow:hidden}',
+        ''
       ]
     }, { advanced: false })
   )