From 512cdc691b2b35d166211f27c2e6d229ce9fb6b1 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Fri, 14 Jul 2017 14:42:04 +0200 Subject: [PATCH] Fixes #957 - `0%` minification of `width` property. Why: * Apparently `width` and `max-width` `0%` value cannot be turned into `0`, see: https://codepen.io/judowalker/pen/xrMxWj --- History.md | 5 +++++ lib/optimizer/level-1/optimize.js | 2 +- test/optimizer/level-1/optimize-test.js | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index 3a38aa87a..eb9ba8066 100644 --- a/History.md +++ b/History.md @@ -6,6 +6,11 @@ * Fixed issue [#895](https://github.com/jakubpawlowicz/clean-css/issues/895) - ignoring specific styles. * Fixed issue [#947](https://github.com/jakubpawlowicz/clean-css/issues/947) - selector based filtering. +[4.1.7 / 2017-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.6...4.1) +================== + +* Fixed issue [#957](https://github.com/jakubpawlowicz/clean-css/issues/957) - `0%` minification of `width` property. + [4.1.6 / 2017-07-08](https://github.com/jakubpawlowicz/clean-css/compare/v4.1.5...v4.1.6) ================== diff --git a/lib/optimizer/level-1/optimize.js b/lib/optimizer/level-1/optimize.js index 2d08bc746..574267c2d 100644 --- a/lib/optimizer/level-1/optimize.js +++ b/lib/optimizer/level-1/optimize.js @@ -271,7 +271,7 @@ function optimizeUnits(name, value, unitsRegexp) { return value; } - if (value.indexOf('%') > 0 && (name == 'height' || name == 'max-height')) { + if (value.indexOf('%') > 0 && (name == 'height' || name == 'max-height' || name == 'width' || name == 'max-width')) { return value; } diff --git a/test/optimizer/level-1/optimize-test.js b/test/optimizer/level-1/optimize-test.js index 8b85c61b1..9dd549d15 100644 --- a/test/optimizer/level-1/optimize-test.js +++ b/test/optimizer/level-1/optimize-test.js @@ -894,8 +894,8 @@ vows.describe('level 1 optimizations') 'a{margin:0}' ], '-0% to 0': [ - 'a{width:-0%}', - 'a{width:0}' + 'a{min-width:-0%}', + 'a{min-width:0}' ], 'missing': [ 'a{opacity:1.}', @@ -968,6 +968,18 @@ vows.describe('level 1 optimizations') 'max-height': [ 'a{max-height:0%}', 'a{max-height:0%}' + ], + 'width': [ + 'a{width:0%}', + 'a{width:0%}' + ], + 'min-width': [ + 'a{min-width:0%}', + 'a{min-width:0}' + ], + 'max-width': [ + 'a{max-width:0%}', + 'a{max-width:0%}' ] }, { level: 1 }) )