Fixes #907 - compatibility of space after closing brace.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 14 Mar 2017 09:19:35 +0000 (10:19 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 15 Mar 2017 10:07:40 +0000 (11:07 +0100)
Why:

* Apparently `@supports` doesn't like stripping that extra space
  after `)` character.

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

index 596954b..454c826 100644 (file)
@@ -8,6 +8,7 @@
 [4.0.9 / 2017-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v4.0.8...4.0)
 ==================
 
+* Fixed issue [#907](https://github.com/jakubpawlowicz/clean-css/issues/907) - space after closing brace in `@supports`.
 * Fixed issue [#910](https://github.com/jakubpawlowicz/clean-css/issues/910) - too aggressive precision optimizations.
 
 [4.0.8 / 2017-02-22](https://github.com/jakubpawlowicz/clean-css/compare/v4.0.7...v4.0.8)
index f5cd6c6..8322aec 100644 (file)
@@ -1,7 +1,12 @@
+var SUPPORTED_COMPACT_BLOCK_MATCHER = /^@media\W/;
+
 function tidyBlock(values, spaceAfterClosingBrace) {
+  var withoutSpaceAfterClosingBrace;
   var i;
 
   for (i = values.length - 1; i >= 0; i--) {
+    withoutSpaceAfterClosingBrace = !spaceAfterClosingBrace && SUPPORTED_COMPACT_BLOCK_MATCHER.test(values[i][1]);
+
     values[i][1] = values[i][1]
       .replace(/\n|\r\n/g, ' ')
       .replace(/\s+/g, ' ')
@@ -9,7 +14,7 @@ function tidyBlock(values, spaceAfterClosingBrace) {
       .replace(/ \)/g, ')')
       .replace(/'([a-zA-Z][a-zA-Z\d\-_]+)'/, '$1')
       .replace(/"([a-zA-Z][a-zA-Z\d\-_]+)"/, '$1')
-      .replace(spaceAfterClosingBrace ? null : /\) /g, ')');
+      .replace(withoutSpaceAfterClosingBrace ? /\) /g : null, ')');
   }
 
   return values;
index ee86a6f..bedebdb 100644 (file)
@@ -1259,6 +1259,18 @@ vows.describe('level 1 optimizations')
       ]
     }, { level: { 1: { tidyBlockScopes: false } } })
   )
+  .addBatch(
+    optimizerContext('tidy block space after closing brace', {
+      'removes space in @media': [
+        '@media (min-width:50px) and print{.block{color:red}}',
+        '@media (min-width:50px)and print{.block{color:red}}'
+      ],
+      'keeps space in @supports': [
+        '@supports (filter:blur(1px)) or (-webkit-filter:blur(1px)){.block{color:red}}',
+        '@supports (filter:blur(1px)) or (-webkit-filter:blur(1px)){.block{color:red}}'
+      ]
+    }, { compatibility: { properties: { spaceAfterClosingBrace: false } }, level: 1 })
+  )
   .addBatch(
     optimizerContext('tidy block scopes optimizations off', {
       'stays as it is': [