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 18:15:51 UTC

[couchdb-esprima] 02/10: Ensure that the Program node may still have leading comments.

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

davisp pushed a commit to branch 1.x
in repository https://gitbox.apache.org/repos/asf/couchdb-esprima.git

commit e7ec3f6e0d2abb2db9caa9a61dd4cafc12f4447f
Author: Ariya Hidayat <ar...@gmail.com>
AuthorDate: Sat May 3 21:20:02 2014 -0700

    Ensure that the Program node may still have leading comments.
    
    https://code.google.com/p/esprima/issues/detail?id=536
---
 esprima.js   |  7 +++++--
 test/test.js | 28 ++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/esprima.js b/esprima.js
index 5e808f6..84a5e98 100644
--- a/esprima.js
+++ b/esprima.js
@@ -1394,8 +1394,11 @@ parseStatement: true, parseSourceElement: true */
 
         processComment: function (node) {
             var lastChild, trailingComments;
-            if (typeof node.type === 'undefined' || node.type === Syntax.Program) {
-                return;
+
+            if (node.type === Syntax.Program) {
+                if (node.body.length > 0) {
+                    return;
+                }
             }
 
             peek();
diff --git a/test/test.js b/test/test.js
index cbd7b2a..5523b4a 100644
--- a/test/test.js
+++ b/test/test.js
@@ -4037,6 +4037,34 @@ var testFixture = {
             }]
         },
 
+        '// one\\n': {
+            type: 'Program',
+            body: [],
+            range: [8, 8],
+            loc: {
+                start: { line: 1, column: 8 },
+                end: { line: 1, column: 8 }
+            },
+            leadingComments: [{
+                type: 'Line',
+                value: ' one\\n',
+                range: [0, 8],
+                loc: {
+                    start: { line: 1, column: 0 },
+                    end: { line: 1, column: 8 }
+                }
+            }],
+            comments: [{
+                type: 'Line',
+                value: ' one\\n',
+                range: [0, 8],
+                loc: {
+                    start: { line: 1, column: 0 },
+                    end: { line: 1, column: 8 }
+                }
+            }]
+        },
+
         '// line comment\n42': {
             type: 'ExpressionStatement',
             expression: {