esprima icon indicating copy to clipboard operation
esprima copied to clipboard

Unexpected token ILLEGAL on /^

Open tolkushkin opened this issue 5 years ago • 2 comments

Unexpected token ILLEGAL on /^

I try parse following js

isImage=function(e){return/^image\//.test(e.type)
and get ParserExeption Line 1: Unexpected token ILLEGAL This code works in chrome without any errors.

Code to parse

var s = new Scanner(@"isImage=function(e){return/^image\//.test(e.type)}");
var tokens = new List();
Token token;
do
{
	s.ScanComments();
	token = s.Lex();
	tokens.Add(token);
} while (token.Type != TokenType.EOF);

tolkushkin avatar Aug 24 '20 10:08 tolkushkin

Hi @tolkushkin, thanks for the report.

Did you try it on https://esprima.org/demo/parse.html to see if it works there? When I did that and use the following (note that I added the closing curly brace), everything works as expected.

isImage=function(e){return/^image\//.test(e.type)}

Also, for using the pure tokenizer, the same thing happens (working as expected) from the command line (try it with https://npm.runkit.com/esprima):

esprima.tokenize('isImage=function(e){return/^image\//.test(e.type)}')

ariya avatar Sep 14 '20 13:09 ariya

Hi @ariya , It would be better to know which branch was being used in web https://esprima.org/demo/parse.html

Certain code is being parsed in web but throws errors while using npm or direct source code

Eg: esprima/dist/esprima.js:3781 throw e; ^

Error: Line 2: Unexpected reserved word

TejaswiniU avatar Sep 28 '20 17:09 TejaswiniU