From 38c40c61a6ae45c6be42262b9c70a56dcb21377d Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 3 Jan 2016 13:08:56 +0000 Subject: [PATCH] Fixes #714 - stringifying property level at rules. There was an edge case when a property level `@apply` rule was not stringified properly. --- History.md | 1 + lib/stringifier/helpers.js | 11 ++++++++++- test/integration-test.js | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 91fd2572..9965dc0d 100644 --- a/History.md +++ b/History.md @@ -8,6 +8,7 @@ * Fixed issue [#693](https://github.com/jakubpawlowicz/clean-css/issues/693) - restructuring edge case. * Fixed issue [#711](https://github.com/jakubpawlowicz/clean-css/issues/711) - border fuzzy matching. +* Fixed issue [#714](https://github.com/jakubpawlowicz/clean-css/issues/714) - stringifying property level at rules. [3.4.8 / 2015-11-13](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.7...v3.4.8) ================== diff --git a/lib/stringifier/helpers.js b/lib/stringifier/helpers.js index 32b331ef..3f89a950 100644 --- a/lib/stringifier/helpers.js +++ b/lib/stringifier/helpers.js @@ -97,7 +97,7 @@ function value(tokens, position, isLast, context) { var token = tokens[position]; var isVariableDeclaration = token[0][0].indexOf('--') === 0; - if (isVariableDeclaration && Array.isArray(token[1][0][0])) { + if (isVariableDeclaration && atRulesOrProperties(token[1])) { store('{', context); body(token[1], context); store('};', context); @@ -115,6 +115,15 @@ function value(tokens, position, isLast, context) { } } +function atRulesOrProperties(values) { + for (var i = 0, l = values.length; i < l; i++) { + if (values[i][0] == AT_RULE || Array.isArray(values[i][0])) + return true; + } + + return false; +} + function all(tokens, context) { var joinCharacter = context.keepBreaks ? lineBreak : ''; var store = context.store; diff --git a/test/integration-test.js b/test/integration-test.js index 9de944dc..ecc8ef9e 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -2207,6 +2207,10 @@ vows.describe('integration tests') 'multiple @apply with whitespace': [ 'a{' + lineBreak + '@apply(--rule1);' + lineBreak + ' @apply(--rule2);' + lineBreak + 'color:red;display:block}', 'a{@apply(--rule1);@apply(--rule2);color:red;display:block}' + ], + '@apply another rule within :root context 123': [ + ':root{--layout:{display:flex};--layout-horizontal:{@apply(--layout)};}', + ':root{--layout:{display:flex};--layout-horizontal:{@apply(--layout)};}' ] }) ) -- 2.34.1