You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2019/12/18 17:59:50 UTC

[couchdb-escodegen] 01/02: Add realJson option. Closes #304

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to reference refs/pull/305/head
in repository https://gitbox.apache.org/repos/asf/couchdb-escodegen.git

commit 9655d370bfef53d6901bf274908172f0121fa582
Author: Александр invntrm@ <a-...@users.noreply.github.com>
AuthorDate: Mon Jul 4 00:55:41 2016 +0400

    Add realJson option. Closes #304
---
 escodegen.js | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/escodegen.js b/escodegen.js
index 0360521..35f653a 100644
--- a/escodegen.js
+++ b/escodegen.js
@@ -47,6 +47,7 @@
         base,
         indent,
         json,
+        realJson,
         renumber,
         hexadecimal,
         quotes,
@@ -182,6 +183,7 @@
                 newline: '\n',
                 space: ' ',
                 json: false,
+                realJson: false,
                 renumber: false,
                 hexadecimal: false,
                 quotes: 'single',
@@ -2147,8 +2149,12 @@
                 ];
             }
 
+            var wrapQuotesIfJson = function(key) {
+                return realJson ? ('"' + key + '"') : key;
+            };
+
             return [
-                this.generatePropertyKey(expr.key, expr.computed),
+                wrapQuotesIfJson(this.generatePropertyKey(expr.key, expr.computed)),
                 ':' + space,
                 this.generateExpression(expr.value, Precedence.Assignment, E_TTT)
             ];
@@ -2520,7 +2526,8 @@
             indent = options.format.indent.style;
             base = stringRepeat(indent, options.format.indent.base);
         }
-        json = options.format.json;
+        realJson = options.format.realjson;
+        json = realJson || options.format.json;
         renumber = options.format.renumber;
         hexadecimal = json ? false : options.format.hexadecimal;
         quotes = json ? 'double' : options.format.quotes;