Fixes #629 - source maps & background shorthands.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 5 Aug 2015 07:20:20 +0000 (08:20 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 6 Aug 2015 08:39:44 +0000 (09:39 +0100)
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
lib/properties/break-up.js
test/source-map-test.js

index bfaac34..c053ea6 100644 (file)
@@ -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.
 
index bfb95d3..f153558 100644 (file)
@@ -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];
index c4a1ac0..6844846 100644 (file)
@@ -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}');