What steps will reproduce the problem? 1. create a file.js with "var a = /[a-z]/;" 2. esparse file.js
What is the expected output?
{ "type": "Program", "body": [ { "type": "VariableDeclaration", "declarations": [ { "type": "VariableDeclarator", "id": { "type": "Identifier", "name": "a" }, "init": { "type": "Literal", "value": "/[a-z]/", "raw": "/[a-z]/" } } ], "kind": "var" } ] }
What do you see instead?
{ "type": "Program", "body": [ { "type": "VariableDeclaration", "declarations": [ { "type": "VariableDeclarator", "id": { "type": "Identifier", "name": "a" }, "init": { "type": "Literal", "value": {} } } ], "kind": "var" } ] }
What version of the product are you using? On what operating system? Which browser?
1.0.4 and 1.1.0
Please provide any additional information below.
The online parser uses the JSON.stringify "replacer" argument that calls the .toString() on the regular expression. I think "esparse" should do this too.
I added a .diff adding the replacer function.
Using that will fix "esparse file.js | uglifyjs --spidermonkey".
- esparse.diff 947
Comment #1
Posted on Nov 27, 2013 by Quick Rabbitesparse should handle regular expression literals. https://github.com/ariya/esprima/commit/79fbc3a4fc
Status: Fixed
Labels:
Type-Defect
Priority-Medium
Component-Example