Disables compacting when property is inherited.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 12 Apr 2015 13:46:23 +0000 (14:46 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 12 Apr 2015 16:58:11 +0000 (17:58 +0100)
See #525 for follow up.

lib/properties/has-inherit.js [new file with mode: 0644]
lib/properties/override-compactor.js
lib/properties/shorthand-compactor.js
test/properties/shorthand-compacting-test.js

diff --git a/lib/properties/has-inherit.js b/lib/properties/has-inherit.js
new file mode 100644 (file)
index 0000000..96a103b
--- /dev/null
@@ -0,0 +1,10 @@
+function hasInherit(property) {
+  for (var i = property.value.length - 1; i >= 0; i--) {
+    if (property.value[i][0] == 'inherit')
+      return true;
+  }
+
+  return false;
+}
+
+module.exports = hasInherit;
index e93e040..ca7f85b 100644 (file)
@@ -2,6 +2,7 @@ var canOverride = require('./can-override');
 var compactable = require('./compactable');
 var deepClone = require('./clone').deep;
 var shallowClone = require('./clone').shallow;
+var hasInherit = require('./has-inherit');
 var restoreShorthands = require('./restore-shorthands');
 
 var stringifyProperty = require('../stringifier/one-time').property;
@@ -70,15 +71,6 @@ function overrideShorthand(property, by) {
   }
 }
 
-function hasInherits(property) {
-  for (var i = property.value.length - 1; i >= 0; i--) {
-    if (property.value[i] == 'inherit')
-      return true;
-  }
-
-  return false;
-}
-
 function turnIntoMultiplex(property, size) {
   property.multiplex = true;
 
@@ -170,7 +162,7 @@ function compactOverrides(properties, compatibility, validator) {
       if (left.unused || right.unused)
         continue;
 
-      if (hasInherits(right))
+      if (hasInherit(right))
         continue;
 
       if (!left.shorthand && right.shorthand && isComponentOf(right, left)) {
@@ -199,7 +191,7 @@ function compactOverrides(properties, compatibility, validator) {
           if (!compatibility.properties.merging && wouldBreakCompatibility(left, validator))
             continue;
 
-          if (component.value[0][0] != right.value[0][0] && (hasInherits(left) || hasInherits(right)))
+          if (component.value[0][0] != right.value[0][0] && (hasInherit(left) || hasInherit(right)))
             continue;
 
           if (wouldResultInLongerValue(left, right))
index 640db06..3c87a3c 100644 (file)
@@ -1,5 +1,6 @@
 var compactable = require('./compactable');
 var deepClone = require('./clone').deep;
+var hasInherit = require('./has-inherit');
 var populateComponents = require('./populate-components');
 var wrapSingle = require('./wrap-for-optimizing').single;
 
@@ -31,6 +32,9 @@ function replaceWithShorthand(properties, candidateComponents, name, validator)
     var component = candidateComponents[descriptor.components[i]];
     var canOverride = compactable[component.name].canOverride;
 
+    if (hasInherit(component))
+      return;
+
     if (!canOverride(newProperty.components[i], component, validator))
       return;
 
index 245bcb8..c66e703 100644 (file)
@@ -150,6 +150,17 @@ vows.describe(optimize)
         ]);
       }
     },
+    'with inherit - pending #525': {
+      'topic': 'a{padding-top:10px;padding-left:5px;padding-bottom:3px;padding-right:inherit}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['padding-top', false , false], ['10px']],
+          [['padding-left', false , false], ['5px']],
+          [['padding-bottom', false , false], ['3px']],
+          [['padding-right', false , false], ['inherit']]
+        ]);
+      }
+    },
     'mixed importance': {
       'topic': 'a{padding-top:10px;padding-left:5px;padding-bottom:3px;padding-right:2px!important}',
       'into': function (topic) {