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

[couchdb-esprima] 06/10: Fix duplicate tokens peeked by attachComments.

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 b2247253d3b063bcb04666263c3cf38fad358f51
Author: Bei Zhang <ik...@gmail.com>
AuthorDate: Wed May 7 09:11:08 2014 -0700

    Fix duplicate tokens peeked by attachComments.
    
    https://code.google.com/p/esprima/issues/detail?id=537
---
 esprima.js   |   2 -
 test/test.js | 281 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 279 insertions(+), 4 deletions(-)

diff --git a/esprima.js b/esprima.js
index 84a5e98..2a60ad6 100644
--- a/esprima.js
+++ b/esprima.js
@@ -1401,8 +1401,6 @@ parseStatement: true, parseSourceElement: true */
                 }
             }
 
-            peek();
-
             if (extra.trailingComments.length > 0) {
                 if (extra.trailingComments[0].range[0] >= node.range[1]) {
                     trailingComments = extra.trailingComments;
diff --git a/test/test.js b/test/test.js
index 5523b4a..2e5831c 100644
--- a/test/test.js
+++ b/test/test.js
@@ -3423,9 +3423,287 @@ var testFixture = {
                         46
                     ]
                 }
+            ],
+            "tokens": [
+                {
+                    "type": "Numeric",
+                    "range": [
+                        0,
+                        2
+                    ],
+                    "value": "42"
+                }
+            ]
+        },
+
+        'var p1;/* block comment 1 */ /* block comment 2 */': {
+            "range": [
+                0,
+                7
+            ],
+            "loc": {
+                "start": {
+                    "line": 1,
+                    "column": 0
+                },
+                "end": {
+                    "line": 1,
+                    "column": 7
+                }
+            },
+            "type": "Program",
+            "body": [
+                {
+                    "range": [
+                        0,
+                        7
+                    ],
+                    "loc": {
+                        "start": {
+                            "line": 1,
+                            "column": 0
+                        },
+                        "end": {
+                            "line": 1,
+                            "column": 7
+                        }
+                    },
+                    "type": "VariableDeclaration",
+                    "declarations": [
+                        {
+                            "range": [
+                                4,
+                                6
+                            ],
+                            "loc": {
+                                "start": {
+                                    "line": 1,
+                                    "column": 4
+                                },
+                                "end": {
+                                    "line": 1,
+                                    "column": 6
+                                }
+                            },
+                            "type": "VariableDeclarator",
+                            "id": {
+                                "range": [
+                                    4,
+                                    6
+                                ],
+                                "loc": {
+                                    "start": {
+                                        "line": 1,
+                                        "column": 4
+                                    },
+                                    "end": {
+                                        "line": 1,
+                                        "column": 6
+                                    }
+                                },
+                                "type": "Identifier",
+                                "name": "p1"
+                            },
+                            "init": null
+                        }
+                    ],
+                    "kind": "var",
+                    "trailingComments": [
+                        {
+                            "range": [
+                                7,
+                                28
+                            ],
+                            "loc": {
+                                "start": {
+                                    "line": 1,
+                                    "column": 7
+                                },
+                                "end": {
+                                    "line": 1,
+                                    "column": 28
+                                }
+                            },
+                            "type": "Block",
+                            "value": " block comment 1 "
+                        },
+                        {
+                            "range": [
+                                29,
+                                50
+                            ],
+                            "loc": {
+                                "start": {
+                                    "line": 1,
+                                    "column": 29
+                                },
+                                "end": {
+                                    "line": 1,
+                                    "column": 50
+                                }
+                            },
+                            "type": "Block",
+                            "value": " block comment 2 "
+                        }
+                    ]
+                }
+            ],
+            "comments": [
+                {
+                    "range": [
+                        7,
+                        28
+                    ],
+                    "loc": {
+                        "start": {
+                            "line": 1,
+                            "column": 7
+                        },
+                        "end": {
+                            "line": 1,
+                            "column": 28
+                        }
+                    },
+                    "type": "Block",
+                    "value": " block comment 1 "
+                },
+                {
+                    "range": [
+                        29,
+                        50
+                    ],
+                    "loc": {
+                        "start": {
+                            "line": 1,
+                            "column": 29
+                        },
+                        "end": {
+                            "line": 1,
+                            "column": 50
+                        }
+                    },
+                    "type": "Block",
+                    "value": " block comment 2 "
+                }
+            ],
+            "tokens": [
+                {
+                    "range": [
+                        0,
+                        3
+                    ],
+                    "loc": {
+                        "start": {
+                            "line": 1,
+                            "column": 0
+                        },
+                        "end": {
+                            "line": 1,
+                            "column": 3
+                        }
+                    },
+                    "type": "Keyword",
+                    "value": "var"
+                },
+                {
+                    "range": [
+                        4,
+                        6
+                    ],
+                    "loc": {
+                        "start": {
+                            "line": 1,
+                            "column": 4
+                        },
+                        "end": {
+                            "line": 1,
+                            "column": 6
+                        }
+                    },
+                    "type": "Identifier",
+                    "value": "p1"
+                },
+                {
+                    "range": [
+                        6,
+                        7
+                    ],
+                    "loc": {
+                        "start": {
+                            "line": 1,
+                            "column": 6
+                        },
+                        "end": {
+                            "line": 1,
+                            "column": 7
+                        }
+                    },
+                    "type": "Punctuator",
+                    "value": ";"
+                }
             ]
         },
 
+        '/*42*/': {
+            "range": [
+                6,
+                6
+            ],
+            "loc": {
+                "start": {
+                    "line": 1,
+                    "column": 6
+                },
+                "end": {
+                    "line": 1,
+                    "column": 6
+                }
+            },
+            "type": "Program",
+            "body": [],
+            "leadingComments": [
+                {
+                    "range": [
+                        0,
+                        6
+                    ],
+                    "loc": {
+                        "start": {
+                            "line": 1,
+                            "column": 0
+                        },
+                        "end": {
+                            "line": 1,
+                            "column": 6
+                        }
+                    },
+                    "type": "Block",
+                    "value": "42"
+                }
+            ],
+            "comments": [
+                {
+                    "range": [
+                        0,
+                        6
+                    ],
+                    "loc": {
+                        "start": {
+                            "line": 1,
+                            "column": 0
+                        },
+                        "end": {
+                            "line": 1,
+                            "column": 6
+                        }
+                    },
+                    "type": "Block",
+                    "value": "42"
+                }
+            ],
+            "tokens": []
+        },
+
         '(a + /* assignmenr */b ) * c': {
             "type": "Program",
             "body": [
@@ -21808,8 +22086,7 @@ var testFixture = {
             type: 'Boolean',
             value: 'true'
           }]
-        },
-
+        }
     },
 
     'Tolerant parse': {