Fixes #867 - skips optimizing variable values.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 24 Jan 2017 14:43:33 +0000 (15:43 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 25 Jan 2017 10:27:55 +0000 (11:27 +0100)
Why:

* It may not be the best idea as we don't know what a value
  represents and where it'll end up.

History.md
lib/optimizer/level-1/optimize.js
test/optimizer/level-1/optimize-test.js

index e301ef5..39f73e9 100644 (file)
@@ -2,6 +2,7 @@
 ==================
 
 * Fixed issue [#866](https://github.com/jakubpawlowicz/clean-css/issues/866) - edge case in `inline` option.
+* Fixed issue [#867](https://github.com/jakubpawlowicz/clean-css/issues/867) - skip optimizing variable values.
 
 [4.0.0 / 2017-01-23](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.24...v4.0.0)
 ==================
index 01dce3f..ced1d6d 100644 (file)
@@ -38,6 +38,7 @@ var IMPORT_PREFIX_PATTERN = /^@import/i;
 var QUOTED_PATTERN = /^('.*'|".*")$/;
 var QUOTED_BUT_SAFE_PATTERN = /^['"][a-zA-Z][a-zA-Z\d\-_]+['"]$/;
 var URL_PREFIX_PATTERN = /^url\(/i;
+var VARIABLE_NAME_PATTERN = /^--\S+$/;
 
 function isNegative(value) {
   return value && value[1][0] == '-' && parseFloat(value[1]) < 0;
@@ -468,6 +469,10 @@ function optimizeBody(properties, context) {
       continue;
     }
 
+    if (VARIABLE_NAME_PATTERN.test(name)) {
+      continue;
+    }
+
     for (var j = 0, m = property.value.length; j < m; j++) {
       type = property.value[j][0];
       value = property.value[j][1];
index 399ea1d..d37d34e 100644 (file)
@@ -1075,6 +1075,18 @@ vows.describe('level 1 optimizations')
       ]
     }, { level: 1 })
   )
+  .addBatch(
+    optimizerContext('quotes', {
+      'font-family': [
+        '.block{font-family:"Arial"}',
+        '.block{font-family:Arial}'
+      ],
+      'variable': [
+        '.block{--font-family:"Arial"}',
+        '.block{--font-family:"Arial"}'
+      ]
+    }, { level: 1 })
+  )
   .addBatch(
     optimizerContext('@charset cleanup off', {
       'stays where it is': [