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:54 UTC

[couchdb-escodegen] reference refs/pull/247/head created (now 1f2e826)

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

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


      at 1f2e826  Fix inline comments edge case with preseveBlankLines

This reference includes the following new commits:

     new 1f2e826  Fix inline comments edge case with preseveBlankLines

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb-escodegen] 01/01: Fix inline comments edge case with preseveBlankLines

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 1f2e8265d1beb851b20fd804b570e0fe6e767517
Author: Dennis Li <de...@gmail.com>
AuthorDate: Sun Aug 9 01:16:01 2015 -0700

    Fix inline comments edge case with preseveBlankLines
    
    Fix extra trailing comma
    
    Lint errors
---
 escodegen.js                                                 | 12 +++++++++---
 .../trailing-comment-in-object.expected.js                   |  3 +++
 test/preserve-blank-lines/trailing-comment-in-object.js      |  3 +++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/escodegen.js b/escodegen.js
index f706c05..d7adfe1 100644
--- a/escodegen.js
+++ b/escodegen.js
@@ -739,6 +739,10 @@
                 prefix = sourceCode.substring(extRange[0], range[0]);
                 count = (prefix.match(/\n/g) || []).length;
 
+                if (typeof result === 'string') {
+                    result = [result];
+                }
+
                 if (count > 0) {
                     result.push(stringRepeat('\n', count));
                     result.push(addIndent(generateComment(comment)));
@@ -2132,18 +2136,20 @@
         },
 
         ObjectExpression: function (expr, precedence, flags) {
-            var multiline, result, fragment, that = this;
+            var multiline, result, fragment, trailingCommentExists, that = this;
 
             if (!expr.properties.length) {
                 return '{}';
             }
+
+            trailingCommentExists = extra.comment && expr.properties.length === 1 && expr.properties[0].value.trailingComments;
             multiline = expr.properties.length > 1;
 
             withIndent(function () {
                 fragment = that.generateExpression(expr.properties[0], Precedence.Sequence, E_TTT);
             });
 
-            if (!multiline) {
+            if (!(multiline || trailingCommentExists)) {
                 // issues 4
                 // Do not transform from
                 //   dejavu.Class.declare({
@@ -2166,6 +2172,7 @@
                     for (i = 1, iz = expr.properties.length; i < iz; ++i) {
                         result.push(indent);
                         result.push(that.generateExpression(expr.properties[i], Precedence.Sequence, E_TTT));
+
                         if (i + 1 < iz) {
                             result.push(',' + newline);
                         }
@@ -2410,7 +2417,6 @@
 
         result = this[type](expr, precedence, flags);
 
-
         if (extra.comment) {
             result = addComments(expr, result);
         }
diff --git a/test/preserve-blank-lines/trailing-comment-in-object.expected.js b/test/preserve-blank-lines/trailing-comment-in-object.expected.js
new file mode 100644
index 0000000..c72507e
--- /dev/null
+++ b/test/preserve-blank-lines/trailing-comment-in-object.expected.js
@@ -0,0 +1,3 @@
+var x = {
+    a: 2 // this is a comment
+};
\ No newline at end of file
diff --git a/test/preserve-blank-lines/trailing-comment-in-object.js b/test/preserve-blank-lines/trailing-comment-in-object.js
new file mode 100644
index 0000000..7b6e3f6
--- /dev/null
+++ b/test/preserve-blank-lines/trailing-comment-in-object.js
@@ -0,0 +1,3 @@
+var x = {
+    a: 2 // this is a comment
+};