From 1e9587710efa8e9338bcf0bc794b4b45f286231d Mon Sep 17 00:00:00 2001 From: Roman Dvornov Date: Tue, 21 Mar 2017 23:55:21 +0300 Subject: [PATCH] tweak node generation --- lib/syntax/node/AnPlusB.js | 29 ++++++++++++++-------------- lib/syntax/node/AttributeSelector.js | 2 +- lib/syntax/node/Function.js | 2 +- lib/syntax/node/MediaFeature.js | 4 ++-- lib/syntax/node/Ratio.js | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/syntax/node/AnPlusB.js b/lib/syntax/node/AnPlusB.js index d91341d6..1bd186ef 100644 --- a/lib/syntax/node/AnPlusB.js +++ b/lib/syntax/node/AnPlusB.js @@ -152,25 +152,26 @@ module.exports = { }; }, generate: function(node) { - var result = ''; var a = node.a !== null && node.a !== undefined; var b = node.b !== null && node.b !== undefined; + var result; if (a) { - result += node.a === '+1' || node.a === '1' ? 'n' : - node.a === '-1' ? '-n' : - node.a + 'n'; - } - - if (a && b) { - if (String(node.b).charAt(0) !== '-' && - String(node.b).charAt(0) !== '+') { - result += '+'; + result = + node.a === '+1' || node.a === '1' ? 'n' : + node.a === '-1' ? '-n' : + node.a + 'n'; + + if (b) { + b = String(node.b); + if (b.charAt(0) === '-' || b.charAt(0) === '+') { + result = [result, b.charAt(0), b.substr(1)]; + } else { + result = [result, '+', b]; + } } - } - - if (b) { - result += node.b; + } else { + result = String(node.b); } return result; diff --git a/lib/syntax/node/AttributeSelector.js b/lib/syntax/node/AttributeSelector.js index 4ae41f27..f26a5a70 100644 --- a/lib/syntax/node/AttributeSelector.js +++ b/lib/syntax/node/AttributeSelector.js @@ -151,7 +151,7 @@ module.exports = { } if (node.flags !== null) { - result.push(flagsPrefix + node.flags); + result.push(flagsPrefix, node.flags); } result.push(']'); diff --git a/lib/syntax/node/Function.js b/lib/syntax/node/Function.js index 3d14ae70..a7f0b110 100644 --- a/lib/syntax/node/Function.js +++ b/lib/syntax/node/Function.js @@ -33,7 +33,7 @@ module.exports = { }; }, generate: function(node) { - return [].concat(node.name, '(', this.each(node.children), ')'); + return [].concat(node.name + '(', this.each(node.children), ')'); }, walkContext: 'function' }; diff --git a/lib/syntax/node/MediaFeature.js b/lib/syntax/node/MediaFeature.js index 4bd9c83b..26100792 100644 --- a/lib/syntax/node/MediaFeature.js +++ b/lib/syntax/node/MediaFeature.js @@ -63,7 +63,7 @@ module.exports = { }, generate: function(node) { return node.value !== null - ? ['(' + node.name + ':', this.generate(node.value), ')'] - : '(' + node.name + ')'; + ? ['(', node.name, ':', this.generate(node.value), ')'] + : ['(', node.name, ')']; } }; diff --git a/lib/syntax/node/Ratio.js b/lib/syntax/node/Ratio.js index b298f597..cdc5ffa3 100644 --- a/lib/syntax/node/Ratio.js +++ b/lib/syntax/node/Ratio.js @@ -50,6 +50,6 @@ module.exports = { }; }, generate: function(node) { - return node.left + '/' + node.right; + return [node.left, '/', node.right]; } };