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:58:14 UTC

[couchdb-escodegen] 01/01: FIX Constellation/escodegen#187

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

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

commit 24c332c559c80cbf62448c7fd597facba1d64436
Author: leeight <le...@gmail.com>
AuthorDate: Sun Jun 29 22:02:20 2014 +0800

    FIX Constellation/escodegen#187
---
 escodegen.js                             | 10 ++++++++++
 test/comment/object_comments.expected.js | 22 +++++++++++-----------
 test/harmony.js                          |  2 +-
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/escodegen.js b/escodegen.js
index b95e1e6..11690f9 100644
--- a/escodegen.js
+++ b/escodegen.js
@@ -568,6 +568,10 @@
         return result;
     }
 
+    function restoreIndent() {
+        base = base.slice(0, -indent.length);
+    }
+
     function calculateSpaces(str) {
         var i;
         for (i = str.length - 1; i >= 0; --i) {
@@ -1796,6 +1800,12 @@
                 // So if comment is attached to target node, we should specialize.
                 withIndent(function () {
                     node = stmt.declarations[0];
+                    if (node.type === Syntax.VariableDeclarator &&
+                        node.init &&
+                        node.init.type === Syntax.ObjectExpression) {
+                        restoreIndent();
+                    }
+
                     if (extra.comment && node.leadingComments) {
                         result.push('\n');
                         result.push(addIndent(generateStatement(node, {
diff --git a/test/comment/object_comments.expected.js b/test/comment/object_comments.expected.js
index 8c5fcc6..2c62424 100644
--- a/test/comment/object_comments.expected.js
+++ b/test/comment/object_comments.expected.js
@@ -1,12 +1,12 @@
 var test = {
-        /**
-         * Test 2
-         */
-        a: '1',
-        /*
-         * Test 1
-         */
-        b: '2',
-        // Test 3
-        c: '3'
-    };
+    /**
+     * Test 2
+     */
+    a: '1',
+    /*
+     * Test 1
+     */
+    b: '2',
+    // Test 3
+    c: '3'
+};
diff --git a/test/harmony.js b/test/harmony.js
index 57a145a..706521b 100644
--- a/test/harmony.js
+++ b/test/harmony.js
@@ -894,7 +894,7 @@ data = {
 
 
     'Object destructuring (and aliasing)':  {
-        'var {\n        a,\n        b: C\n    } = {};' : {
+        'var {\n    a,\n    b: C\n} = {};' : {
             generateFrom: {
                 type: 'Program',
                 body: [{