From 54ede5cf48e705de33d448a55a35523303531852 Mon Sep 17 00:00:00 2001 From: Florin Daneliuc Date: Thu, 30 Jun 2016 11:27:50 +0300 Subject: [PATCH] allow to stringify a single node --- lib/stringify/compiler.js | 6 +++++- lib/stringify/identity.js | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/stringify/compiler.js b/lib/stringify/compiler.js index 6d01a14d..6939f0bb 100644 --- a/lib/stringify/compiler.js +++ b/lib/stringify/compiler.js @@ -41,10 +41,14 @@ Compiler.prototype.mapVisit = function(nodes, delim){ var buf = ''; delim = delim || ''; + if (Array.isArray(nodes)) { for (var i = 0, length = nodes.length; i < length; i++) { buf += this.visit(nodes[i]); if (delim && i < length - 1) buf += this.emit(delim); } - + } else { + buf += this.visit(nodes); + buf += this.emit(delim); + } return buf; }; diff --git a/lib/stringify/identity.js b/lib/stringify/identity.js index b390c91e..8b7d4f06 100644 --- a/lib/stringify/identity.js +++ b/lib/stringify/identity.js @@ -41,7 +41,8 @@ Compiler.prototype.compile = function(node){ */ Compiler.prototype.stylesheet = function(node){ - return this.mapVisit(node.stylesheet.rules, '\n\n'); + var passedParameter = node.stylesheet ? node.stylesheet.rules : node; + return this.mapVisit(passedParameter, '\n\n'); }; /**