Fixes #466 - rebuilding background shorthand.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 1 Mar 2015 17:56:57 +0000 (17:56 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 1 Mar 2015 18:07:57 +0000 (18:07 +0000)
In case of multi-value shorthands (comma separated) we reuse tokens
instead of cloning when splitting / rebuilding values.

There was an edge case in rebuilding when having more than one
`background` in a rule.

History.md
lib/properties/processable.js
test/fixtures/issue-466-min.css [new file with mode: 0644]
test/fixtures/issue-466.css [new file with mode: 0644]

index 414159f..a34d149 100644 (file)
@@ -7,6 +7,7 @@
 ==================
 
 * Refixed issue [#471](https://github.com/jakubpawlowicz/clean-css/issues/471) - correct order after restructuring.
+* Fixes issue [#466](https://github.com/jakubpawlowicz/clean-css/issues/466) - rebuilding background shorthand.
 * Fixes issue [#462](https://github.com/jakubpawlowicz/clean-css/issues/462) - escaped apostrophes in selectors.
 
 [3.1.1 / 2015-02-27](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.0...v3.1.1)
index f27e791..ea30c79 100644 (file)
@@ -147,11 +147,14 @@ module.exports = (function () {
       var values = new Splitter(',').split(token.value);
       var components = [];
 
+      // TODO: we should be rather clonging elements than reusing them!
       for (var i = 0, l = values.length; i < l; i++) {
         token.value = values[i];
         components.push(splitfunc(token));
       }
 
+      token.value = values.join(',');
+
       for (var j = 0, m = components[0].length; j < m; j++) {
         for (var k = 0, n = components.length, newValues = []; k < n; k++) {
           newValues.push(components[k][j].value);
diff --git a/test/fixtures/issue-466-min.css b/test/fixtures/issue-466-min.css
new file mode 100644 (file)
index 0000000..c4bc93e
--- /dev/null
@@ -0,0 +1 @@
+div{background:url(image.png);background:linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.5)),url(image.png)}
diff --git a/test/fixtures/issue-466.css b/test/fixtures/issue-466.css
new file mode 100644 (file)
index 0000000..5e2ca82
--- /dev/null
@@ -0,0 +1,4 @@
+div {
+  background: url(image.png);
+  background-image: linear-gradient(rgba(0,0,0,.1), rgba(0,0,0,.5)), url(image.png);
+}