Closed millermedeiros closed 10 years ago
the tokens issue can be easily replicated:
var rnotwhite = /\S/;
generates:
[
{
"type": "Keyword",
"value": "var",
"range": [
0,
3
]
},
{
"type": "Identifier",
"value": "rnotwhite",
"range": [
4,
13
]
},
{
"type": "Punctuator",
"value": "=",
"range": [
14,
15
]
},
{
"type": "Punctuator",
"value": "/",
"range": [
16,
17
]
},
{
"type": "Punctuator",
"value": ";",
"range": [
20,
21
]
},
{
"type": "RegularExpression",
"value": "/\\S/",
"range": [
16,
20
]
}
]
Note that tokens aren't sorted by "range" and that { "type": "Punctuator", "value": "/", "range": [ 16, 17 ] }
should not exist
submitted the issue to Esprima, now lets hope they fix it: https://code.google.com/p/esprima/issues/detail?id=407
since it's not my fault, and was already reported to esprima, I'm going to close it.
there is some weird bug on Esprima itself related to RegExp and running it on the browser.
Paste jQuery 1.7.2 here http://esprima.org/demo/parse.html and check the "tokens" tab, the tokens inside the range 1716-1755 are messed up, there is a "Punctuator" with value "/" which shouldn't be there and the "," is at the wrong index as well (it should come after RegExp)… also since there is a gap in the "range" between "/" and "," there is a "WhiteSpace" token being created by rocambole which contains the whole RegExp, so calling
toString()
will give the wrong output (RegExp is duplicated):PS: we need to report this bug to esprima.