Fixes #314 - handling spaces inside calc expressions.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 11 Jan 2015 10:26:13 +0000 (10:26 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 11 Jan 2015 10:36:31 +0000 (10:36 +0000)
History.md
lib/utils/extractors.js
test/integration-test.js

index 38b1e8d..2c5689c 100644 (file)
@@ -1,4 +1,4 @@
-[3.1.0 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.3...v3.1.0)
+[3.1.0 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.4...v3.1.0)
 ==================
 
 * Adds 0deg to 0 minification where possible.
@@ -7,6 +7,11 @@
 * Fixed issue [#182](https://github.com/GoalSmashers/clean-css/issues/182) - removing space after closing brace.
 * Fixed issue [#357](https://github.com/GoalSmashers/clean-css/issues/357) - non-standard but valid URLs.
 
+[3.0.4 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.3...v3.0.4)
+==================
+
+* Fixed issue [#314](https://github.com/GoalSmashers/clean-css/issues/314) - spaces inside calc.
+
 [3.0.3 / 2015-01-07](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.2...v3.0.3)
 ==================
 
index de4f544..d8b4c47 100644 (file)
@@ -14,6 +14,7 @@ var Extractors = {
     var isSpecial;
     var wasSpecial;
     var current;
+    var secondToLast;
     var wasCloseParenthesis;
     var isEscape;
     var token;
@@ -63,7 +64,9 @@ var Extractors = {
         isSpecial = current === ':' || current === '[' || current === ']' || current === ',' || current === '(' || current === ')';
 
         if (wasWhitespace && isSpecial) {
-          buffer.pop();
+          secondToLast = buffer[buffer.length - 2];
+          if (secondToLast != '+' && secondToLast != '-' && secondToLast != '/' && secondToLast != '*')
+            buffer.pop();
           buffer.push(current);
         } else if (isWhitespace && wasSpecial && !wasCloseParenthesis) {
         } else if (isWhitespace && !wasWhitespace && buffer.length > 0) {
index ea779bf..4ff1be1 100644 (file)
@@ -132,6 +132,10 @@ vows.describe('integration tests').addBatch({
       'div{height:-moz-calc(3 * 2em + 10px)}',
       'div{height:-moz-calc(3 * 2em + 10px)}'
     ],
+    'not inside calc method with brackets': [
+      'body{margin-left:calc(50vw + (1024px/2))}',
+      'body{margin-left:calc(50vw + (1024px/2))}'
+    ],
     'before colon': [
       '#test{padding-left :0}',
       '#test{padding-left:0}'