PiotrDabkowski / Js2Py

JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online:
http://piter.io/projects/js2py
MIT License
2.47k stars 261 forks source link

ClassDeclaration is not supported by ECMA 5.1 #248

Open hesoyamhh opened 3 years ago

hesoyamhh commented 3 years ago

Evaluating functions work fine but as soon as Classes are introduced, js2py.eval_js starts giving Error: js2py.internals.simplex.JsException: SyntaxError: Line 2: ClassDeclaration is not supported by ECMA 5.1

simple functions working: image

When Classes are executed in Try It Yourself area in http://piter.io/projects/js2py, it gives NotImplementedError

image

ClassDeclaration in python script:

Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\pyjsparser\parser.py", line 3008, in parse
    program = self.parseProgram()
  File "C:\Python38\lib\site-packages\pyjsparser\parser.py", line 2974, in parseProgram
    body = self.parseScriptBody()
  File "C:\Python38\lib\site-packages\pyjsparser\parser.py", line 2963, in parseScriptBody
    statement = self.parseStatementListItem()
  File "C:\Python38\lib\site-packages\pyjsparser\parser.py", line 2107, in parseStatementListItem
    raise Ecma51NotSupported('ClassDeclaration')
pyjsparser.std_nodes.Ecma51NotSupported: ClassDeclaration is not supported by ECMA 5.1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python38\lib\site-packages\js2py\evaljs.py", line 115, in eval_js
    return e.eval(js)
  File "C:\Python38\lib\site-packages\js2py\evaljs.py", line 204, in eval
    self.execute(code, use_compilation_plan=use_compilation_plan)
  File "C:\Python38\lib\site-packages\js2py\evaljs.py", line 199, in execute
    exec (compiled, self._context)
  File "<EvalJS snippet>", line 2, in <module>
  File "C:\Python38\lib\site-packages\js2py\base.py", line 949, in __call__
    return self.call(self.GlobalObject, args)
  File "C:\Python38\lib\site-packages\js2py\base.py", line 1464, in call
    return Js(self.code(*args))
  File "C:\Python38\lib\site-packages\js2py\host\jseval.py", line 17, in Eval
    py_code = translate_js(code.to_string().value, '')
  File "C:\Python38\lib\site-packages\js2py\translators\translator.py", line 70, in translate_js
    parsed = parse_fn(js)
  File "C:\Python38\lib\site-packages\js2py\translators\translator.py", line 62, in pyjsparser_parse_fn
    return parser.parse(code)
  File "C:\Python38\lib\site-packages\pyjsparser\parser.py", line 3010, in parse
    raise self.createError(self.lineNumber, self.lastIndex, unicode(e))
js2py.internals.simplex.JsException: SyntaxError: Line 2: ClassDeclaration is not supported by ECMA 5.1.

So, Just want to know if this will/can be supported in future releases ?

As, you have already mentioned multiple times that eval_js6 is extremely slow. For me its stuck since 5 minutes for the Animal class.

yellowjs0304 commented 2 years ago

@hesoyamhh Is this solved? I got same error.

jkmaaal commented 1 year ago

Any updates..? I'm also facing same error.

THEGOLDENPRO commented 1 year ago

yep, I'm also getting the same error, I really hope this issue is being looked into.

marcguetg commented 1 year ago

There seems to be a eval_js6 function which does seem to do the trick.

httplups commented 1 year ago

I am having the same error. Any fixes?