Fixes #546 - IE<11 `calc()` issue.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 24 Apr 2015 07:47:02 +0000 (08:47 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 24 Apr 2015 09:23:21 +0000 (10:23 +0100)
So IE<11 does not support a space between calc() and whatever comes
after it.

There's gonna be a follow up with #547 in 3.3.

History.md
lib/stringifier/helpers.js
test/integration-test.js
test/selectors/optimizer-test.js

index 2742310..4c2fadb 100644 (file)
@@ -13,6 +13,7 @@
 ==================
 
 * Fixed issue [#544](https://github.com/jakubpawlowicz/clean-css/issues/544) - regression in same value merging.
+* Fixed issue [#546](https://github.com/jakubpawlowicz/clean-css/issues/546) - IE<11 `calc()` issue.
 
 [3.2.3 / 2015-04-22](https://github.com/jakubpawlowicz/clean-css/compare/v3.2.2...v3.2.3)
 ==================
index ffb6b81..8c2a244 100644 (file)
@@ -17,6 +17,10 @@ function afterClosingBrace(token, valueIndex) {
   return token[valueIndex][0][token[valueIndex][0].length - 1] == ')' || token[valueIndex][0].indexOf('__ESCAPED_URL_CLEAN_CSS') === 0;
 }
 
+function afterCalc(token, valueIndex) {
+  return token[valueIndex][0].indexOf('calc(') === 0;
+}
+
 function afterComma(token, valueIndex) {
   return token[valueIndex][0] == ',';
 }
@@ -38,7 +42,7 @@ function inFilter(token) {
 }
 
 function inSpecialContext(token, valueIndex, context) {
-  return !context.spaceAfterClosingBrace && afterClosingBrace(token, valueIndex) ||
+  return !context.spaceAfterClosingBrace && afterClosingBrace(token, valueIndex) && !afterCalc(token, valueIndex) ||
     beforeSlash(token, valueIndex) ||
     afterSlash(token, valueIndex) ||
     beforeComma(token, valueIndex) ||
index 84de7b2..a7fdce0 100644 (file)
@@ -161,15 +161,15 @@ vows.describe('integration tests').addBatch({
     'after hsla': 'a{text-shadow:hsla(240,100%,40%,.5)-1px 1px}',
     'inside background': [
       'a{background:calc(100% - 2px) 10px no-repeat}',
-      'a{background:calc(100% - 2px)10px no-repeat}'
+      'a{background:calc(100% - 2px) 10px no-repeat}'
     ],
     'inside background with fraction unit': [
-      'a{background:calc(100% - 2px).5em no-repeat}',
-      'a{background:calc(100% - 2px).5em no-repeat}'
+      'a{background:calc(100% - 2px) .5em no-repeat}',
+      'a{background:calc(100% - 2px) .5em no-repeat}'
     ],
     'inside margin': [
       'a{margin:calc(100% - 2px) calc(100% - 5px)}',
-      'a{margin:calc(100% - 2px)calc(100% - 5px)}'
+      'a{margin:calc(100% - 2px) calc(100% - 5px)}'
     ],
     'after :not #1': [
       'li:not(.foo).bar{color:red}',
@@ -629,7 +629,7 @@ vows.describe('integration tests').addBatch({
     ],
     'negative padding in calculations': [
       'div{padding:calc(100% - 5px) 0 0 0}',
-      'div{padding:calc(100% - 5px)0 0}'
+      'div{padding:calc(100% - 5px) 0 0}'
     ]
   }),
   'floats': cssContext({
@@ -2011,7 +2011,7 @@ title']{display:block}",
   'background position': cssContext({
     'calc as a value': [
       '*{background:white calc(100% - 10px) center no-repeat;background-image:url(test.png)}',
-      '*{background:calc(100% - 10px)center no-repeat #fff;background-image:url(test.png)}'
+      '*{background:calc(100% - 10px) center no-repeat #fff;background-image:url(test.png)}'
     ]
   }),
   'background-clip': cssContext({
index 0390840..e5fc14b 100644 (file)
@@ -232,6 +232,10 @@ vows.describe(SelectorsOptimizer)
       'whitespace body': [
         'a{   \n }',
         ''
+      ],
+      'whitespace after calc()': [
+        'div{margin:calc(100% - 20px) 1px}',
+        'div{margin:calc(100% - 20px) 1px}'
       ]
     })
   )