From: Jakub Pawlowicz Date: Fri, 10 Apr 2015 09:42:55 +0000 (+0100) Subject: Fixes restoring `background-color` in layered `background`. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=bab72475f48e416f383c838f3a4fb965a791da3b;p=clean-css.git Fixes restoring `background-color` in layered `background`. Only the last layer can have a color set. --- diff --git a/lib/properties/restore.js b/lib/properties/restore.js index 61af307d..13823b2e 100644 --- a/lib/properties/restore.js +++ b/lib/properties/restore.js @@ -1,6 +1,6 @@ var shallowClone = require('./clone').shallow; -function background(property, compactable) { +function background(property, compactable, lastInMultiplex) { var components = property.components; var restored = []; var needsOne, needsBoth; @@ -65,8 +65,10 @@ function background(property, compactable) { i--; } else { - if (!isDefault) - restoreValue(component); + if (isDefault || compactable[component.name].multiplexLastOnly && !lastInMultiplex) + continue; + + restoreValue(component); } } @@ -134,7 +136,7 @@ function fourValues(property) { function multipleValues(restoreWith) { return function (property, compactable) { if (!property.multiplex) - return restoreWith(property, compactable); + return restoreWith(property, compactable, true); var repeatCounts = property.components[0].value.length; var restored = []; @@ -148,7 +150,8 @@ function multipleValues(restoreWith) { _property.components.push(_component); } - var _restored = restoreWith(_property, compactable); + var lastInMultiplex = i == repeatCounts - 1; + var _restored = restoreWith(_property, compactable, lastInMultiplex); Array.prototype.push.apply(restored, _restored); if (i < repeatCounts - 1) diff --git a/test/properties/override-compacting-test.js b/test/properties/override-compacting-test.js index 1c514935..9bbdc2fd 100644 --- a/test/properties/override-compacting-test.js +++ b/test/properties/override-compacting-test.js @@ -382,7 +382,7 @@ vows.describe(optimize) 'topic': 'p{background:red;background-repeat:__ESCAPED_URL_CLEAN_CSS0__,__ESCAPED_URL_CLEAN_CSS1__}', 'into': function (topic) { assert.deepEqual(_optimize(topic), [ - [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS0__'], ['red'], [','], ['__ESCAPED_URL_CLEAN_CSS1__'], ['red']], + [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS0__'], [','], ['__ESCAPED_URL_CLEAN_CSS1__'], ['red']], ]); } } diff --git a/test/properties/restore-test.js b/test/properties/restore-test.js index 8563b907..2d3f9826 100644 --- a/test/properties/restore-test.js +++ b/test/properties/restore-test.js @@ -102,6 +102,14 @@ vows.describe(restore) assert.deepEqual(restoredValue, [['0']]); } }, + 'background color in multiplex': { + 'topic': function () { + return _restore(_breakUp([['background'], ['__ESCAPED_URL_CLEAN_CSS0__'], ['blue'], [','], ['__ESCAPED_URL_CLEAN_CSS1__'], ['red']])); + }, + 'gives right value back': function (restoredValue) { + assert.deepEqual(restoredValue, [['__ESCAPED_URL_CLEAN_CSS0__'], [','], ['__ESCAPED_URL_CLEAN_CSS1__'], ['red']]); + } + } }, 'border radius': { '4 values': { @@ -209,7 +217,7 @@ vows.describe(restore) return _restore(_breakUp([['background'], ['no-repeat'], ['padding-box'], [','], ['repeat'], ['10px'], ['10px'], ['/'], ['auto'], ['red'], [','], ['top'], ['left'], ['/'], ['30%']])); }, 'gives right value back': function (restoredValue) { - assert.deepEqual(restoredValue, [['no-repeat'], ['padding-box'], [','], ['10px'], ['10px'], ['red'], [','], ['top'], ['left'], ['/'], ['30%']]); + assert.deepEqual(restoredValue, [['no-repeat'], ['padding-box'], [','], ['10px'], ['10px'], [','], ['top'], ['left'], ['/'], ['30%']]); } } },