Fixes #675 - overriding with `!important`.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 27 Sep 2015 11:14:12 +0000 (12:14 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 28 Sep 2015 09:46:55 +0000 (10:46 +0100)
There was an edge case with overriding properties with `!important`
modifier.

It's a regression introduced in 2ba023dd151d9c494a3cffbda538ca46f7e36f5b.

History.md
lib/properties/optimizer.js
test/selectors/advanced-test.js

index 0278f48..113e7b1 100644 (file)
@@ -3,6 +3,11 @@
 
 * Requires Node.js 4.0+ to run.
 
+[3.4.5 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.4...3.4)
+==================
+
+* Fixed issue [#675](https://github.com/jakubpawlowicz/clean-css/issues/675) - overriding with `!important`.
+
 [3.4.4 / 2015-09-21](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.3...v3.4.4)
 ==================
 
index accf121..d244ad8 100644 (file)
@@ -162,7 +162,10 @@ function _optimize(properties, mergeAdjacent, aggressiveMerging, validator) {
 
       if (anyRemoved) {
         position = -1;
+        lastProperty = null;
+        lastName = null;
         overrideMapping = {};
+        continue;
       }
     } else {
       overrideMapping[_name] = overrideMapping[_name] || [];
index ee55c6a..33c842f 100644 (file)
@@ -7,6 +7,10 @@ vows.describe('advanced optimizer')
       'adjacent': [
         'a{display:none}a{display:none;visibility:hidden}',
         'a{display:none;visibility:hidden}'
+      ],
+      'overriding by !important': [
+        'a{margin:0}a{margin:0!important}',
+        'a{margin:0!important}'
       ]
     }, { advanced: true })
   )