diff --git a/CHANGELOG.md b/CHANGELOG.md index ebec3d3c..59ac3f3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## next +- Trim Custom Property values when possible (#393) - Fixed removing unit for zero-length dimentions in `min()`, `max()` and `clamp()` functions (#426) - Fixed crash on bad value in TRBL declaration value (#412) diff --git a/lib/clean/Declaration.js b/lib/clean/Declaration.js index 28253a64..f3cac374 100644 --- a/lib/clean/Declaration.js +++ b/lib/clean/Declaration.js @@ -1,5 +1,14 @@ +var property = require('css-tree').property; + module.exports = function cleanDeclartion(node, item, list) { if (node.value.children && node.value.children.isEmpty()) { list.remove(item); + return; + } + + if (property(node.property).custom) { + if (/\S/.test(node.value.value)) { + node.value.value = node.value.value.trim(); + } } }; diff --git a/test/fixture/compress/custom-property.min.css b/test/fixture/compress/custom-property.min.css index 69a1f64d..494e815c 100644 --- a/test/fixture/compress/custom-property.min.css +++ b/test/fixture/compress/custom-property.min.css @@ -1 +1 @@ -:root{--mainColor: #fb4c42;--test-var: 5px;--foo: if(x > 5) this.width = 10}.test{color:var(--mainColor, blue);border:1px solid var(--test-var)}a::after{content:" (" var(--external-link) ")"}.example7{--main-color: #c06;--accent-background: linear-gradient(to top, var(--main-color), white)}.example8{--one: calc(var(--two) + 20px);--two: calc(var(--one) - 20px)}one{--foo: 10px}two{--bar: calc(var(--foo) + 10px)}three{--foo: calc(var(--bar) + 10px)} +:root{--mainColor:#fb4c42;--test-var:5px;--foo:if(x > 5) this.width = 10}.test{color:var(--mainColor, blue);border:1px solid var(--test-var)}a::after{content:" (" var(--external-link) ")"}.example7{--main-color:#c06;--accent-background:linear-gradient(to top, var(--main-color), white)}.example8{--one:calc(var(--two) + 20px);--two:calc(var(--one) - 20px)}one{--foo:10px}two{--bar:calc(var(--foo) + 10px)}three{--foo:calc(var(--bar) + 10px)}