scrapinghub / js2xml

Convert Javascript code to an XML document
MIT License
186 stars 23 forks source link

SyntaxError for "const Foo;" #35

Closed crille1006 closed 4 years ago

crille1006 commented 4 years ago

When I try to parse Javascript with const declaration js2xml.parse('const FOO;') I get this SyntaxError:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/js2xml/__init__.py", line 17, in parse
    tree = _parser.parse(text, debug=debug)
  File "/usr/local/lib/python3.7/dist-packages/js2xml/parser.py", line 36, in parse
    result = super(CustomParser, self).parse(text, debug=debug)
  File "/usr/local/lib/python3.7/dist-packages/slimit/parser.py", line 93, in parse
    return self.parser.parse(text, lexer=self.lexer, debug=debug)
  File "/usr/local/lib/python3.7/dist-packages/ply/yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/local/lib/python3.7/dist-packages/ply/yacc.py", line 1201, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/local/lib/python3.7/dist-packages/ply/yacc.py", line 192, in call_errorfunc
    r = errorfunc(token)
  File "/usr/local/lib/python3.7/dist-packages/slimit/parser.py", line 116, in p_error
    self._raise_syntax_error(token)
  File "/usr/local/lib/python3.7/dist-packages/slimit/parser.py", line 89, in _raise_syntax_error
    self.lexer.prev_token, self.lexer.token())
  File "<string>", line None
SyntaxError: Unexpected token (CONST, 'const') at 1:0 between LexToken(ID,'FOO',1,6) and LexToken(ID,'FOO',1,6)
Gallaecio commented 4 years ago

Could you check if https://github.com/scrapinghub/js2xml/pull/33 fixes this issue for you?