From 1d8069ce303a9fd7765599b6351dec94b6805804 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Wed, 1 Jun 2016 09:00:28 +0200 Subject: [PATCH] Fixes #780 - space after inlined variables. Let's not assume variables are functions to stay. Polymer inlines variables so removing a space after a variable can break styling. --- History.md | 1 + lib/stringifier/helpers.js | 6 +----- test/integration-test.js | 6 +++++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/History.md b/History.md index 7c6cd74d..07658eb5 100644 --- a/History.md +++ b/History.md @@ -7,6 +7,7 @@ ================== * Fixed issue [#779](https://github.com/jakubpawlowicz/clean-css/issues/779) - merging `background-(position|size)`. +* Fixed issue [#780](https://github.com/jakubpawlowicz/clean-css/issues/780) - space after inlined variables. [3.4.14 / 2016-05-31](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.13...v3.4.14) ================== diff --git a/lib/stringifier/helpers.js b/lib/stringifier/helpers.js index 5e9f1176..d3f4abef 100644 --- a/lib/stringifier/helpers.js +++ b/lib/stringifier/helpers.js @@ -16,10 +16,6 @@ function supportsAfterClosingBrace(token) { return token[0][0] == 'background' || token[0][0] == 'transform' || token[0][0] == 'src'; } -function isVariable(token, valueIndex) { - return token[valueIndex][0].indexOf('var(') === 0; -} - function afterClosingBrace(token, valueIndex) { return token[valueIndex][0][token[valueIndex][0].length - 1] == ')' || token[valueIndex][0].indexOf('__ESCAPED_URL_CLEAN_CSS') === 0; } @@ -45,7 +41,7 @@ function inFilter(token) { } function inSpecialContext(token, valueIndex, context) { - return (!context.spaceAfterClosingBrace && supportsAfterClosingBrace(token) || isVariable(token, valueIndex)) && afterClosingBrace(token, valueIndex) || + return !context.spaceAfterClosingBrace && supportsAfterClosingBrace(token) && afterClosingBrace(token, valueIndex) || beforeSlash(token, valueIndex) || afterSlash(token, valueIndex) || beforeComma(token, valueIndex) || diff --git a/test/integration-test.js b/test/integration-test.js index efc240ed..419fb05d 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -2649,7 +2649,7 @@ vows.describe('integration tests') ], 'all values': [ 'a{--width:1px;--style:solid;--color:#000}.one{border:var(--width)var(--style)var(--color)}', - 'a{--width:1px;--style:solid;--color:#000}.one{border:var(--width)var(--style)var(--color)}' + 'a{--width:1px;--style:solid;--color:#000}.one{border:var(--width) var(--style) var(--color)}' ], 'Polymer mixins - simple optimizations': [ 'a{ display:block; --my-toolbar: { color:#f00; width:96px }; color:blue}', @@ -2666,6 +2666,10 @@ vows.describe('integration tests') 'Polymer mixins - not fitting into a single chunk of 128 bytes': [ ':host{--live-head-theme: { line-height: 40px !important; vertical-align: middle; background: transparent; height: 40px; z-index: 999; }; }', ':host{--live-head-theme:{line-height:40px!important;vertical-align:middle;background:0 0;height:40px;z-index:999};}' + ], + 'Polymer mixins - inlined variables': [ + '.spinner{-webkit-animation:container-rotate var(--paper-spinner-container-rotation-duration) linear infinite}', + '.spinner{-webkit-animation:container-rotate var(--paper-spinner-container-rotation-duration) linear infinite}' ] }) ) -- 2.34.1