Fixes #714 - stringifying property level at rules.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 3 Jan 2016 13:08:56 +0000 (13:08 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 3 Jan 2016 15:30:36 +0000 (15:30 +0000)
There was an edge case when a property level `@apply` rule was
not stringified properly.

History.md
lib/stringifier/helpers.js
test/integration-test.js

index 91fd257..9965dc0 100644 (file)
@@ -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)
 ==================
index 32b331e..3f89a95 100644 (file)
@@ -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;
index 9de944d..ecc8ef9 100644 (file)
@@ -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)};}'
       ]
     })
   )