Fixes #186 - strips unit from `0rem` unless in ie8 compatibility mode.
authorGoalSmashers <jakub@goalsmashers.com>
Wed, 11 Dec 2013 18:24:08 +0000 (19:24 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Wed, 11 Dec 2013 19:04:11 +0000 (20:04 +0100)
History.md
lib/clean.js
test/unit-test.js

index 2933e80..bfd4060 100644 (file)
@@ -7,6 +7,7 @@
 * Fixed issue [#161](https://github.com/GoalSmashers/clean-css/issues/161) - improves tokenizer performance.
 * Fixed issue [#163](https://github.com/GoalSmashers/clean-css/issues/163) - round pixels to 2nd decimal place.
 * Fixed issue [#165](https://github.com/GoalSmashers/clean-css/issues/165) - extra space after trailing parenthesis.
+* Fixed issue [#186](https://github.com/GoalSmashers/clean-css/issues/186) - strip unit from 0rem.
 
 [2.0.2 / 2013-11-18](https://github.com/GoalSmashers/clean-css/compare/v2.0.1...v2.0.2)
 ==================
index 6ea60f1..8722544 100644 (file)
@@ -230,8 +230,12 @@ CleanCSS.prototype.minify = function(data) {
   });
 
   // zero + unit to zero
-  replace(/(\s|:|,)0(?:px|em|ex|cm|mm|in|pt|pc|%)/g, '$1' + '0');
-  replace(/rect\(0(?:px|em|ex|cm|mm|in|pt|pc|%)/g, 'rect(0');
+  var units = ['px', 'em', 'ex', 'cm', 'mm', 'in', 'pt', 'pc', '%'];
+  if ('ie8' != options.compatibility)
+    units.push('rem');
+
+  replace(new RegExp('(\\s|:|,)0(?:' + units.join('|') + ')', 'g'), '$1' + '0');
+  replace(new RegExp('rect\\(0(?:' + units.join('|') + ')', 'g'), 'rect(0');
 
   // round pixels to 2nd decimal place
   replace(/\.(\d{3,})px/g, function(match, decimalPlaces) {
index 59f7e44..d872288 100644 (file)
@@ -405,11 +405,24 @@ vows.describe('clean-units').addBatch({
       'a{box-shadow:0 0 0 0}',
       'a{box-shadow:0 0}'
     ],
+    'rems': [
+      'div{width:0rem;height:0rem}',
+      'div{width:0;height:0}'
+    ],
     '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 values in ie8 compatibility mode': cssContext({
+    'rems': 'div{width:0rem;height:0rem}'
+  }, { compatibility: 'ie8' }),
+  'zero values in any other compatibility mode': cssContext({
+    'rems': [
+      'div{width:0rem;height:0rem}',
+      'div{width:0;height:0}'
+    ]
+  }, { compatibility: '*' }),
   'shorthands': cssContext({
     'padding - same 4 values': [
       'div{padding:1px 1px 1px 1px}',