From ec35efb41311ed19da873f662abaff37129691d1 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Fri, 10 Apr 2015 10:11:09 +0100 Subject: [PATCH] Re-adds shorthand-shorthand merging for `border`. `border` is a special case as any of its components are shorthands too. --- lib/properties/override-compactor.js | 21 ++++++++++ test/properties/override-compacting-test.js | 44 +++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/lib/properties/override-compactor.js b/lib/properties/override-compactor.js index 23442a57..059a4c83 100644 --- a/lib/properties/override-compactor.js +++ b/lib/properties/override-compactor.js @@ -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; } } } diff --git a/test/properties/override-compacting-test.js b/test/properties/override-compacting-test.js index 69edfb57..ab0874e2 100644 --- a/test/properties/override-compacting-test.js +++ b/test/properties/override-compacting-test.js @@ -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}', -- 2.34.1