Fixes #354 - !important overriding in shorthands.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 14 Sep 2014 15:43:14 +0000 (16:43 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 16 Sep 2014 07:49:56 +0000 (08:49 +0100)
Follow up to #346 for overriding important property by another important one in shorthand declarations.

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

index dc40874..ea4a762 100644 (file)
@@ -9,6 +9,7 @@
 
 * Fixed issue [#359](https://github.com/GoalSmashers/clean-css/issues/359) - handling escaped double backslash.
 * Fixed issue [#356](https://github.com/GoalSmashers/clean-css/issues/356) - preserving *+html hack.
+* Fixed issue [#354](https://github.com/GoalSmashers/clean-css/issues/354) - !important overriding in shorthands.
 
 [2.2.15 / 2014-09-01](https://github.com/jakubpawlowicz/clean-css/compare/v2.2.14...v2.2.15)
 ==================
index 7c6186c..8b65f6e 100644 (file)
@@ -114,6 +114,10 @@ module.exports = (function () {
               result.push(t);
               break;
             }
+            if (t.components[iiii].isImportant && token.components[iiii].isImportant && (validator.isValidFunction(t.components[iiii].value) ^ validator.isValidFunction(token.components[iiii].value))) {
+              result.push(t);
+              break;
+            }
           }
         } else if (t.prop !== token.prop || !can(t.value, token.value)) {
           // in every other case, use the override mechanism
index 29215cc..c4b44c1 100644 (file)
@@ -1600,6 +1600,8 @@ title']{display:block}",
     ],
     'of two properties in one declaration with both as !important but 2nd less understandable': 'a{color:red!important;display:block;color:rgba(0,255,0,.5)!important}',
     'of two properties in one declaration with both as !important but 2nd more understandable': 'a{color:rgba(0,255,0,.5)!important;display:block;color:red!important}',
+    'of two shorthand properties in one declaration with both as !important but 2nd less understandable': 'a{background:red!important;background:rgba(0,255,0,.5)!important}',
+    'of two shorthand properties in one declaration with both as !important but 2nd more understandable': 'a{background:rgba(0,255,0,.5)!important;background:red!important}',
     'of many properties in one declaration': [
       'a{display:inline-block;color:red;font-weight:bolder;font-weight:700;display:block!important;color:#fff}',
       'a{font-weight:bolder;font-weight:700;display:block!important;color:#fff}'