From: Jakub Pawlowicz Date: Tue, 19 May 2015 19:33:04 +0000 (+0100) Subject: Fixes #563 - `background:inherit` restoring. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=4ad09b68fbab6cf6461e7a554041b24b4f966c7e;p=clean-css.git Fixes #563 - `background:inherit` restoring. Restoring inherit background were done incorrectly (to expanded form). --- diff --git a/History.md b/History.md index 321e8e78..c9677d4d 100644 --- a/History.md +++ b/History.md @@ -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`. diff --git a/lib/properties/restore.js b/lib/properties/restore.js index 5b66e373..8d49c7be 100644 --- a/lib/properties/restore.js +++ b/lib/properties/restore.js @@ -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); diff --git a/test/properties/shorthand-compacting-test.js b/test/properties/shorthand-compacting-test.js index 52fa4213..feb6a751 100644 --- a/test/properties/shorthand-compacting-test.js +++ b/test/properties/shorthand-compacting-test.js @@ -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({