Fixes #563 - `background:inherit` restoring.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 19 May 2015 19:33:04 +0000 (20:33 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 19 May 2015 19:33:04 +0000 (20:33 +0100)
Restoring inherit background were done incorrectly (to expanded form).

History.md
lib/properties/restore.js
test/properties/shorthand-compacting-test.js

index 321e8e7..c9677d4 100644 (file)
@@ -12,6 +12,7 @@
 * Fixed issue [#448](https://github.com/jakubpawlowicz/clean-css/issues/448) - rebasing no protocol URIs.
 * Fixed issue [#517](https://github.com/jakubpawlowicz/clean-css/issues/517) - turning off color optimizations.
 * Fixed issue [#542](https://github.com/jakubpawlowicz/clean-css/issues/542) - space after closing brace in IE.
+* Fixed issue [#563](https://github.com/jakubpawlowicz/clean-css/issues/563) - `background:inherit` restoring.
 * Fixed issue [#574](https://github.com/jakubpawlowicz/clean-css/issues/574) - rewriting internal URLs.
 * Fixed issue [#575](https://github.com/jakubpawlowicz/clean-css/issues/575) - missing directory as a `target`.
 
index 5b66e37..8d49c7b 100644 (file)
@@ -1,5 +1,6 @@
 var shallowClone = require('./clone').shallow;
 var MULTIPLEX_SEPARATOR = ',';
+var SIZE_POSITION_SEPARATOR = '/';
 
 function background(property, compactable, lastInMultiplex) {
   var components = property.components;
@@ -58,7 +59,7 @@ function background(property, compactable, lastInMultiplex) {
         restoreValue(positionComponent);
       } else if (needsBoth) {
         restoreValue(component);
-        restored.unshift(['/']);
+        restored.unshift([SIZE_POSITION_SEPARATOR]);
         restoreValue(positionComponent);
       } else if (positionComponent.value.length == 1) {
         restoreValue(positionComponent);
@@ -79,9 +80,23 @@ function background(property, compactable, lastInMultiplex) {
   if (restored.length === 0)
     restored.push([compactable[property.name].defaultValue]);
 
+  if (_isInheritBackground(restored))
+    return [restored[0]];
+
   return restored;
 }
 
+function _isInheritBackground(values) {
+  for (var i = 0, l = values.length; i < l; i++) {
+    var value = values[i][0];
+
+    if (value != 'inherit' && value != MULTIPLEX_SEPARATOR && value != SIZE_POSITION_SEPARATOR)
+      return false;
+  }
+
+  return true;
+}
+
 function borderRadius(property, compactable) {
   if (property.multiplex) {
     var horizontal = shallowClone(property);
index 52fa421..feb6a75 100644 (file)
@@ -148,6 +148,14 @@ vows.describe(optimize)
           [['padding-right', false, 'underscore'], ['2px']]
         ]);
       }
+    },
+    'just inherit': {
+      'topic': 'a{background:inherit}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['background', false, false], ['inherit']]
+        ]);
+      }
     }
   })
   .addBatch({