Fixes #229 - adds improved processing of fraction numbers.
authorGoalSmashers <jakub@goalsmashers.com>
Mon, 3 Feb 2014 06:24:07 +0000 (06:24 +0000)
committerGoalSmashers <jakub@goalsmashers.com>
Mon, 3 Feb 2014 20:38:35 +0000 (20:38 +0000)
opacity:1. => opacity:1
opacity:.0 => opacity:0

History.md
lib/clean.js
test/unit-test.js

index 8138ce9..cc3dc5a 100644 (file)
@@ -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)
 ==================
index 07fb88e..f4c2175 100644 (file)
@@ -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
index 976435b..ec9a477 100644 (file)
@@ -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({