Fixes #795 - `!important` and override compacting.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 25 Jul 2016 04:28:28 +0000 (06:28 +0200)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 25 Jul 2016 04:34:35 +0000 (06:34 +0200)
There was a broken test rule which didn't catch the bug, which is
now fixed.

History.md
lib/properties/override-compactor.js
test/properties/override-compacting-test.js

index 2cc3eb7..543a8f5 100644 (file)
@@ -3,6 +3,11 @@
 
 * Requires Node.js 4.0+ to run.
 
+[3.4.19 / 2016-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.18...3.4)
+==================
+
+* Fixed issue [#795](https://github.com/jakubpawlowicz/clean-css/issues/795) - `!important` and override compacting.
+
 [3.4.18 / 2016-06-15](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.17...v3.4.18)
 ==================
 
index 3028bfc..bbf13ed 100644 (file)
@@ -273,6 +273,11 @@ function compactOverrides(properties, compatibility, validator) {
         if (right.important && !left.important)
           continue;
 
+        if (!right.important && left.important) {
+          right.unused = true;
+          continue;
+        }
+
         // Pending more clever algorithm in #527
         if (moreSameShorthands(properties, i - 1, left.name))
           continue;
index 1e039c2..d9bafae 100644 (file)
@@ -142,10 +142,10 @@ vows.describe(optimize)
       }
     },
     'shorthand then longhand - important then non-important': {
-      'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__ repeat!important;background-repeat:no-repeat}',
+      'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__ repeat-x!important;background-repeat:no-repeat}',
       'into': function (topic) {
         assert.deepEqual(_optimize(topic), [
-          [['background'], ['__ESCAPED_URL_CLEAN_CSS0__'], ['no-repeat!important']]
+          [['background'], ['__ESCAPED_URL_CLEAN_CSS0__'], ['repeat-x!important']]
         ]);
       }
     },
@@ -713,6 +713,16 @@ vows.describe(optimize)
       }
     }
   })
+  .addBatch({
+    'padding !important then not !important': {
+      'topic': 'a{padding:0!important;padding-left:3px}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['padding'], ['0!important']]
+        ]);
+      }
+    }
+  })
   .addBatch({
     'overriding !important by a star hack': {
       'topic': 'a{color:red!important;display:block;*color:#fff}',