From 39250550fa8ea993716d8a5b93a5512ef2aa05bf Mon Sep 17 00:00:00 2001 From: Alexander Miller Date: Sun, 28 Nov 2021 09:51:17 -0600 Subject: [PATCH] Add deparseString to allow deparsing within browser --- lib/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 3fdd263..b66fad2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,7 @@ -module.exports = deparse_stream +module.exports = { + deparse: deparse, + deparseString: deparseString +}; var through = require('through') , language = require('cssauron-glsl') @@ -82,6 +85,14 @@ function deparse_stream(with_whitespace, indent) { } } +function deparseString(n, with_whitespace, indent) { + output.length = 0; + with_whitespace = with_whitespace === undefined ? true : with_whitespace; + ws = new WSManager(with_whitespace, indent || ' '); + deparse(n); + return output.join(''); +} + function deparse(n) { return types[n.type](n) } @@ -376,7 +387,7 @@ function deparse_stmt(node) { } function deparse_stmtlist(node) { - var has_parent = node.parent !== null + var has_parent = node.parent !== null && node.parent !== undefined; if(has_parent) { output.push('{')