Skip to content

Commit

Permalink
Fix duplicate tokens peeked by attachComments.
Browse files Browse the repository at this point in the history
ikarienator committed May 7, 2014
1 parent 0b180f7 commit 1812a76
Showing 2 changed files with 279 additions and 4 deletions.
2 changes: 0 additions & 2 deletions esprima.js
Original file line number Diff line number Diff line change
@@ -1490,8 +1490,6 @@ parseStatement: true, parseSourceElement: true */
}
}

peek();

if (extra.trailingComments.length > 0) {
if (extra.trailingComments[0].range[0] >= this.range[1]) {
trailingComments = extra.trailingComments;
281 changes: 279 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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": [
@@ -23415,8 +23693,7 @@ var testFixture = {
type: 'Boolean',
value: 'true'
}]
},

}
},

'Tolerant parse': {

0 comments on commit 1812a76

Please sign in to comment.