Re-adds shorthand-shorthand merging for `border`.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 10 Apr 2015 09:11:09 +0000 (10:11 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 12 Apr 2015 11:15:29 +0000 (12:15 +0100)
`border` is a special case as any of its components are shorthands too.

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

index 23442a5..059a4c8 100644 (file)
@@ -172,6 +172,9 @@ function compactOverrides(properties, compatibility) {
       if (left.unused || right.unused)
         continue;
 
+      if (hasInherits(right))
+        continue;
+
       if (!left.shorthand && right.shorthand && isComponentOf(right, left)) {
         // maybe `left` can be overridden by `right` which is a shorthand?
         if (!right.important && left.important)
@@ -234,6 +237,24 @@ function compactOverrides(properties, compatibility) {
 
         overrideShorthand(left, right);
         left.dirty = true;
+      } else if (left.shorthand && right.shorthand && isComponentOf(left, right)) {
+        // border is a shorthand but any of its components is a shorthand too
+
+        if (!left.important && right.important)
+          continue;
+
+        if (left.important && !right.important) {
+          right.unused = true;
+          continue;
+        }
+
+        var rightRestored = compactable[right.name].restore(right, compactable);
+        if (rightRestored.length > 1)
+          continue;
+
+        component = left.components.filter(nameMatchFilter(right))[0];
+        override(component, right);
+        right.dirty = true;
       }
     }
   }
index 69edfb5..ab0874e 100644 (file)
@@ -174,6 +174,50 @@ vows.describe(optimize)
       }
     }
   })
+  .addBatch({
+    'border': {
+      'topic': 'a{border:1px solid red;border-style:dotted}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['border', false , false], ['1px'], ['dotted'], ['red']]
+        ]);
+      }
+    },
+    'border - multivalue righthand': {
+      'topic': 'a{border:1px solid red;border-style:dotted solid}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['border', false , false], ['1px'], ['solid'], ['red']],
+          [['border-style', false , false], ['dotted'], ['solid']]
+        ]);
+      }
+    },
+    'border - important righthand': {
+      'topic': 'a{border:1px solid red;border-style:dotted!important}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['border', false , false], ['1px'], ['solid'], ['red']],
+          [['border-style', true , false], ['dotted']]
+        ]);
+      }
+    },
+    'border - important lefthand': {
+      'topic': 'a{border:1px solid red!important;border-style:dotted}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['border', true , false], ['1px'], ['solid'], ['red']]
+        ]);
+      }
+    },
+    'border - both important': {
+      'topic': 'a{border:1px solid red!important;border-style:dotted!important}',
+      'into': function (topic) {
+        assert.deepEqual(_optimize(topic), [
+          [['border', true , false], ['1px'], ['dotted'], ['red']]
+        ]);
+      }
+    }
+  })
   .addBatch({
     'shorthand then longhand multiplex': {
       'topic': 'p{background:top left;background-repeat:no-repeat,no-repeat}',