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

js2py can't understan **of** #307

Closed Ella16 closed 1 year ago

Ella16 commented 1 year ago

js2py can't understan for loop of

code

import js2py

tmp_js = 'for (var a of [1,2,3,4]){ \
     console.log(a) \
     } \
    '
eval_res, tempfile = js2py.eval_js(tmp_js)

error msg

Exception has occurred: JsException SyntaxError: Line 1: Unexpected identifier

when i print the problematic token from throwUnexpectedToken it shows, {'type': 3, 'value': 'of', 'raw': 'of', 'lineNumber': 1, 'lineStart': 0, 'start': 11, 'end': 13}

worstperson commented 1 year ago

for...of is an es6 feature

import js2py

tmp_js = 'for (var a of [1,2,3,4]){ \
     console.log(a) \
     } \
    '
js2py.eval_js6(tmp_js)

Better to convert it to es5 if possible, babel adds a lot of overhead.