From ec2467025b5f721f33eaa9ed7778b4554bb078cd Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 12 Apr 2015 14:46:23 +0100 Subject: [PATCH] Disables compacting when property is inherited. See #525 for follow up. --- lib/properties/has-inherit.js | 10 ++++++++++ lib/properties/override-compactor.js | 14 +++----------- lib/properties/shorthand-compactor.js | 4 ++++ test/properties/shorthand-compacting-test.js | 11 +++++++++++ 4 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 lib/properties/has-inherit.js diff --git a/lib/properties/has-inherit.js b/lib/properties/has-inherit.js new file mode 100644 index 00000000..96a103ba --- /dev/null +++ b/lib/properties/has-inherit.js @@ -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; diff --git a/lib/properties/override-compactor.js b/lib/properties/override-compactor.js index e93e040a..ca7f85b5 100644 --- a/lib/properties/override-compactor.js +++ b/lib/properties/override-compactor.js @@ -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)) diff --git a/lib/properties/shorthand-compactor.js b/lib/properties/shorthand-compactor.js index 640db069..3c87a3c2 100644 --- a/lib/properties/shorthand-compactor.js +++ b/lib/properties/shorthand-compactor.js @@ -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; diff --git a/test/properties/shorthand-compacting-test.js b/test/properties/shorthand-compacting-test.js index 245bcb84..c66e7030 100644 --- a/test/properties/shorthand-compacting-test.js +++ b/test/properties/shorthand-compacting-test.js @@ -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) { -- 2.34.1