From f9f3e0fa6d8d2d862033c437176760bfdd52def7 Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Mon, 3 Feb 2014 06:24:07 +0000 Subject: [PATCH] Fixes #229 - adds improved processing of fraction numbers. opacity:1. => opacity:1 opacity:.0 => opacity:0 --- History.md | 1 + lib/clean.js | 6 +++++- test/unit-test.js | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 8138ce9a..cc3dc5a6 100644 --- a/History.md +++ b/History.md @@ -17,6 +17,7 @@ * Fixed issue [#217](https://github.com/GoalSmashers/clean-css/issues/217) - whitespace inside attribute selectors and urls. * Fixed issue [#218](https://github.com/GoalSmashers/clean-css/issues/218) - `@import` statements cleanup. * Fixed issue [#220](https://github.com/GoalSmashers/clean-css/issues/220) - selector between comments. +* Fixed issue [#229](https://github.com/GoalSmashers/clean-css/issues/229) - improved processing of fraction numbers. [2.0.7 / 2014-01-16](https://github.com/GoalSmashers/clean-css/compare/v2.0.6...v2.0.7) ================== diff --git a/lib/clean.js b/lib/clean.js index 07fb88e4..f4c21753 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -265,6 +265,7 @@ var minify = function(data, callback) { units.push('rem'); replace(new RegExp('(\\s|:|,)0(?:' + units.join('|') + ')', 'g'), '$1' + '0'); + replace(new RegExp('(\\s|:|,)(\\d)\\.(\\D)', 'g'), '$1$2$3'); replace(new RegExp('rect\\(0(?:' + units.join('|') + ')', 'g'), 'rect(0'); // zero(s) + value to value @@ -275,9 +276,12 @@ var minify = function(data, callback) { return '.' + Math.round(parseFloat('.' + decimalPlaces) * 100) + 'px'; }); + // .0 to 0 + replace(/(\D)\.0+(,|\}|\))/g, '$10$2'); + // fraction zeros removal replace(/\.([1-9]*)0+(\D)/g, function(match, nonZeroPart, suffix) { - return (nonZeroPart ? '.' : '') + nonZeroPart + suffix; + return (nonZeroPart.length > 0 ? '.' : '') + nonZeroPart + suffix; }); // restore % in rgb/rgba and hsl/hsla diff --git a/test/unit-test.js b/test/unit-test.js index 976435ba..ec9a4771 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -416,6 +416,22 @@ vows.describe('clean-units').addBatch({ 'prefixed box shadow zeros': [ 'a{-webkit-box-shadow:0 0 0 0; -moz-box-shadow:0 0 0 0}', 'a{-webkit-box-shadow:0 0;-moz-box-shadow:0 0}' + ], + 'zero as .0 #1': [ + 'a{color:rgba(0,0,0,.0)}', + 'a{color:rgba(0,0,0,0)}' + ], + 'zero as .0 #2': [ + 'body{margin:.0}', + 'body{margin:0}' + ], + 'missing #1': [ + 'body{margin:2.em}', + 'body{margin:2em}' + ], + 'missing #2': [ + 'p{opacity:1.}', + 'p{opacity:1}' ] }), 'zero values in ie8 compatibility mode': cssContext({ -- 2.34.1