Fixes restoring `background-color` in layered `background`.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 10 Apr 2015 09:42:55 +0000 (10:42 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 12 Apr 2015 11:15:30 +0000 (12:15 +0100)
Only the last layer can have a color set.

lib/properties/restore.js
test/properties/override-compacting-test.js
test/properties/restore-test.js

index 61af307..13823b2 100644 (file)
@@ -1,6 +1,6 @@
 var shallowClone = require('./clone').shallow;
 
-function background(property, compactable) {
+function background(property, compactable, lastInMultiplex) {
   var components = property.components;
   var restored = [];
   var needsOne, needsBoth;
@@ -65,8 +65,10 @@ function background(property, compactable) {
 
       i--;
     } else {
-      if (!isDefault)
-        restoreValue(component);
+      if (isDefault || compactable[component.name].multiplexLastOnly && !lastInMultiplex)
+        continue;
+
+      restoreValue(component);
     }
   }
 
@@ -134,7 +136,7 @@ function fourValues(property) {
 function multipleValues(restoreWith) {
   return function (property, compactable) {
     if (!property.multiplex)
-      return restoreWith(property, compactable);
+      return restoreWith(property, compactable, true);
 
     var repeatCounts = property.components[0].value.length;
     var restored = [];
@@ -148,7 +150,8 @@ function multipleValues(restoreWith) {
         _property.components.push(_component);
       }
 
-      var _restored = restoreWith(_property, compactable);
+      var lastInMultiplex = i == repeatCounts - 1;
+      var _restored = restoreWith(_property, compactable, lastInMultiplex);
       Array.prototype.push.apply(restored, _restored);
 
       if (i < repeatCounts - 1)
index 1c51493..9bbdc2f 100644 (file)
@@ -382,7 +382,7 @@ vows.describe(optimize)
       'topic': 'p{background:red;background-repeat:__ESCAPED_URL_CLEAN_CSS0__,__ESCAPED_URL_CLEAN_CSS1__}',
       'into': function (topic) {
         assert.deepEqual(_optimize(topic), [
-          [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS0__'], ['red'], [','], ['__ESCAPED_URL_CLEAN_CSS1__'], ['red']],
+          [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS0__'], [','], ['__ESCAPED_URL_CLEAN_CSS1__'], ['red']],
         ]);
       }
     }
index 8563b90..2d3f982 100644 (file)
@@ -102,6 +102,14 @@ vows.describe(restore)
           assert.deepEqual(restoredValue, [['0']]);
         }
       },
+      'background color in multiplex': {
+        'topic': function () {
+          return _restore(_breakUp([['background'], ['__ESCAPED_URL_CLEAN_CSS0__'], ['blue'], [','], ['__ESCAPED_URL_CLEAN_CSS1__'], ['red']]));
+        },
+        'gives right value back': function (restoredValue) {
+          assert.deepEqual(restoredValue, [['__ESCAPED_URL_CLEAN_CSS0__'], [','], ['__ESCAPED_URL_CLEAN_CSS1__'], ['red']]);
+        }
+      }
     },
     'border radius': {
       '4 values': {
@@ -209,7 +217,7 @@ vows.describe(restore)
           return _restore(_breakUp([['background'], ['no-repeat'], ['padding-box'], [','], ['repeat'], ['10px'], ['10px'], ['/'], ['auto'], ['red'], [','], ['top'], ['left'], ['/'], ['30%']]));
         },
         'gives right value back': function (restoredValue) {
-          assert.deepEqual(restoredValue, [['no-repeat'], ['padding-box'], [','], ['10px'], ['10px'], ['red'], [','], ['top'], ['left'], ['/'], ['30%']]);
+          assert.deepEqual(restoredValue, [['no-repeat'], ['padding-box'], [','], ['10px'], ['10px'], [','], ['top'], ['left'], ['/'], ['30%']]);
         }
       }
     },