From: Jakub Pawlowicz Date: Tue, 14 Mar 2017 09:19:35 +0000 (+0100) Subject: Fixes #907 - compatibility of space after closing brace. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=adcc95cfda0412dce2912c0b8ffc953a207aa1ab;p=clean-css.git Fixes #907 - compatibility of space after closing brace. Why: * Apparently `@supports` doesn't like stripping that extra space after `)` character. --- diff --git a/History.md b/History.md index 596954ba..454c8264 100644 --- a/History.md +++ b/History.md @@ -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) diff --git a/lib/optimizer/level-1/tidy-block.js b/lib/optimizer/level-1/tidy-block.js index f5cd6c6c..8322aeca 100644 --- a/lib/optimizer/level-1/tidy-block.js +++ b/lib/optimizer/level-1/tidy-block.js @@ -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; diff --git a/test/optimizer/level-1/optimize-test.js b/test/optimizer/level-1/optimize-test.js index ee86a6f0..bedebdba 100644 --- a/test/optimizer/level-1/optimize-test.js +++ b/test/optimizer/level-1/optimize-test.js @@ -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': [