Fixes #660 - override compacting of !important properties.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 5 Sep 2015 19:00:23 +0000 (20:00 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 14 Sep 2015 12:12:37 +0000 (13:12 +0100)
We were not copying properties when assigning in four-values tokens.
As a result we were adding !important value to all components as they
were referencing the same object.

History.md
lib/properties/break-up.js
test/properties/shorthand-compacting-test.js

index c470d12..a3aa7be 100644 (file)
@@ -1,3 +1,8 @@
+[3.4.2 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.1...3.4)
+==================
+
+* Fixed issue [#660](https://github.com/jakubpawlowicz/clean-css/issues/660) - !important token overriding.
+
 [3.4.1 / 2015-08-27](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.0...v3.4.1)
 ==================
 
index ae9701d..d803536 100644 (file)
@@ -159,11 +159,11 @@ function fourValues(property, compactable) {
     return [];
 
   if (value.length < 2)
-    value[1] = value[0];
+    value[1] = value[0].slice(0);
   if (value.length < 3)
-    value[2] = value[0];
+    value[2] = value[0].slice(0);
   if (value.length < 4)
-    value[3] = value[1];
+    value[3] = value[1].slice(0);
 
   for (var i = componentNames.length - 1; i >= 0; i--) {
     var component = wrapSingle([[componentNames[i], property.important]]);
index 11893e1..bee1225 100644 (file)
@@ -85,6 +85,14 @@ vows.describe(optimize)
         ]);
       }
     },
+    'shorthand multiple !important': {
+      'topic': 'a{border-color:#123 !important;border-top-color: #456 !important}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['border-color'], ['#456'], ['#123'], ['#123!important']]
+        ]);
+      }
+    },
     'shorthand list-style #1': {
       'topic': 'a{list-style-type:circle;list-style-position:outside;list-style-image:__ESCAPED_URL_CLEAN_CSS0__}',
       'into': function (topic) {