From 1a4b201ecb0f91dae566bfb44427df56bf61224f Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Wed, 5 Aug 2015 08:20:20 +0100 Subject: [PATCH] Fixes #629 - source maps & background shorthands. Properly handles cases when `background-color` is broken up in the presence of source maps. That happened because value array was coerced into a string which, in presence of a source map, has also source info. --- History.md | 1 + lib/properties/break-up.js | 2 +- test/source-map-test.js | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index bfaac34e..c053ea64 100644 --- a/History.md +++ b/History.md @@ -7,6 +7,7 @@ [3.3.8 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.3.6...3.3) ================== +* Fixed issue [#629](https://github.com/jakubpawlowicz/clean-css/issues/629) - source maps & background shorthands. * Fixed issue [#630](https://github.com/jakubpawlowicz/clean-css/issues/630) - vendor prefixed flex optimizations. * Fixed issue [#633](https://github.com/jakubpawlowicz/clean-css/issues/633) - handling data URI with brackets. diff --git a/lib/properties/break-up.js b/lib/properties/break-up.js index bfb95d3c..f1535585 100644 --- a/lib/properties/break-up.js +++ b/lib/properties/break-up.js @@ -107,7 +107,7 @@ function background(property, compactable, validator) { // NOTE: we do this slicing as value may contain metadata too, like for source maps size.value = [[sizeValue.pop()].concat(value.slice(1))]; position.value = [[sizeValue.pop()].concat(value.slice(1))]; - } else if ((color.value == compactable[color.name].defaultValue || color.value == 'none') && validator.isValidColor(value[0])) { + } else if ((color.value[0][0] == compactable[color.name].defaultValue || color.value[0][0] == 'none') && validator.isValidColor(value[0])) { color.value = [value]; } else if (validator.isValidUrl(value[0]) || validator.isValidFunction(value[0])) { image.value = [value]; diff --git a/test/source-map-test.js b/test/source-map-test.js index c4a1ac0f..6844846e 100644 --- a/test/source-map-test.js +++ b/test/source-map-test.js @@ -36,6 +36,14 @@ vows.describe('source-map') assert.equal(minified.styles, 'a{background:linear-gradient(to bottom,rgba(0,0,0,.1) 0,rgba(0,0,0,.1))}'); } }, + 'background shorthand defaults': { + 'topic': function () { + return new CleanCSS({ sourceMap: true }).minify('a{background: #ffffff none repeat scroll 0 0}'); + }, + 'gets right output': function (minified) { + assert.equal(minified.styles, 'a{background:#fff}'); + } + }, 'important': { 'topic': function () { return new CleanCSS({ sourceMap: true }).minify('@font-face{font-family:si}a{font-family:si!important}'); -- 2.34.1