Js2Py
Js2Py copied to clipboard
Support for translating Jquery?
Hi, I was hoping to use Js2Py to translate a JS module to Python. However, the module itself depends on Jquery. So, I tried translating the Jquery js to python first. The conversion of code from JS to python works fine for both the modules.
However, on importing the jquery module, Js2Py throws an exception which I cannot work around.
Here's what I did:
js2py.translate_file('jquery-3.3.1.min.js', 'jquery.py')
from jquery import jquery
Here's the exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/abhishek/tests/jquery.py", line 5893, in <module>
PyJs_anonymous_651_((var.get('window') if (Js('undefined')!=var.get('window',throw=False).typeof()) else var.get(u"this")), PyJs_anonymous_0_).neg()
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 949, in __call__
return self.call(self.GlobalObject, args)
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 1463, in call
return Js(self.code(*args))
File "/home/abhishek/tests/jquery.py", line 5891, in PyJs_anonymous_651_
(var.get('module').put('exports', (var.get('t')(var.get('e'), Js(0.0).neg()) if var.get('e').get('document') else PyJs_anonymous_652_)) if ((Js('object')==var.get('module',throw=False).typeof()) and (Js('object')==var.get('module').get('exports').typeof())) else var.get('t')(var.get('e')))
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 949, in __call__
return self.call(self.GlobalObject, args)
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 1463, in call
return Js(self.code(*args))
File "/home/abhishek/tests/jquery.py", line 2616, in PyJs_anonymous_0_
var.put('E', PyJs_anonymous_35_(var.get('e')))
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 949, in __call__
return self.call(self.GlobalObject, args)
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 1463, in call
return Js(self.code(*args))
File "/home/abhishek/tests/jquery.py", line 2614, in PyJs_anonymous_35_
return PyJs_LONG_159_()
File "/home/abhishek/tests/jquery.py", line 2613, in PyJs_LONG_159_
return PyJsComma(PyJsComma(PyJsComma(PyJsComma(PyJsComma(PyJsComma(PyJsComma(PyJsComma(PyJsComma(var.put('s', var.get('oe').put('compile', PyJs_anonymous_150_)),var.put('u', var.get('oe').put('select', PyJs_anonymous_151_))),var.get('n').put('sortStable', PyJsStrictEq(var.get('b').callprop('split', Js('')).callprop('sort', var.get('D')).callprop('join', Js('')),var.get('b')))),var.get('n').put('detectDuplicates', var.get('f').neg().neg())),var.get('p')()),var.get('n').put('sortDetached', var.get('ue')(PyJs_anonymous_152_))),(var.get('ue')(PyJs_anonymous_153_) or var.get('le')(Js('type|href|height|width'), PyJs_anonymous_154_))),((var.get('n').get('attributes') and var.get('ue')(PyJs_anonymous_155_)) or var.get('le')(Js('value'), PyJs_anonymous_156_))),(var.get('ue')(PyJs_anonymous_157_) or var.get('le')(var.get('P'), PyJs_anonymous_158_))),var.get('oe'))
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 949, in __call__
return self.call(self.GlobalObject, args)
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 1463, in call
return Js(self.code(*args))
File "/home/abhishek/tests/jquery.py", line 1354, in PyJsHoisted_ue_
var.put('t', var.get('d').callprop('createElement', Js('fieldset')))
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 991, in callprop
cand = self.get(prop)
File "/home/abhishek/env/lib/python3.7/site-packages/js2py/base.py", line 322, in get
'Undefined and null dont have properties!')
js2py.internals.simplex.JsException: TypeError: Undefined and null dont have properties!