Fixed issue with cleaning up spaces inside calc/-moz-calc declarations.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 27 Nov 2011 08:54:58 +0000 (09:54 +0100)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 27 Nov 2011 08:54:58 +0000 (09:54 +0100)
lib/clean.js
test/unit-test.js

index 39ae837..396bc39 100644 (file)
@@ -114,7 +114,10 @@ var CleanCSS = {
     replace(/ {/g, '{') // whitespace before definition
     replace(/\} /g, '}') // whitespace after definition
     
-    // Get the special comments && content back
+    // Get the special comments, content content, and spaces inside calc back
+    replace(/calc\((.+)\)([;\}\w])/, function(match) {
+      return match.replace(/\+/g, ' + ');
+    });
     replace(/__CSSCOMMENT__/g, function() { return specialComments.shift(); });
     replace(/__CSSCONTENT__/g, function() { return contentBlocks.shift(); });
     
index 659a23a..1f52852 100644 (file)
@@ -78,6 +78,22 @@ vows.describe('clean-units').addBatch({
     'at end': [
       'a{color:#fff } ',
       'a{color:#fff}'
+    ],
+    'not inside calc method #1': [
+      'a{width:-moz-calc(100% - 1em);width:calc(100% - 1em)}',
+      'a{width:-moz-calc(100% - 1em);width:calc(100% - 1em)}'
+    ],
+    'not inside calc method #2': [
+      'div{margin:-moz-calc(50% + 15px) -moz-calc(50% + 15px);margin:calc(50% + .5rem) calc(50% + .5rem)}',
+      'div{margin:-moz-calc(50% + 15px) -moz-calc(50% + 15px);margin:calc(50% + .5rem) calc(50% + .5rem)}'
+    ],
+    'not inside calc method with more parentheses': [
+      'div{height:-moz-calc((10% + 12px)/2 + 10em)}',
+      'div{height:-moz-calc((10% + 12px)/2 + 10em)}'
+    ],
+    'not inside calc method with multiplication': [
+      'div{height:-moz-calc(3 * 2em + 10px)}',
+      'div{height:-moz-calc(3 * 2em + 10px)}'
     ]
   }),
   'empty elements': cssContext({