This repository provides a patch for the js2py library to ensure compatibility with Python versions 3.12 and above. The js2py library, a popular JavaScript-to-Python transpiler, has compatibility issues with newer Python versions due to changes in bytecode and opcode mappings. This patch addresses these issues to restore functionality.
-
Apply the compatibility patch: Run the provided Python script to modify the necessary files in the
js2pypackage:python apply_patch.py
js2py/translators/translating_nodes.py: Updates the random number generation for compatibility.js2py/utils/injector.py: AddsLOAD_ATTRopcode mapping and adjusts bytecode handling for newer Python versions.
To demonstrate the use of this patched js2py library, here is a basic example:
from js2py import eval_js
js_code = 'function add(a, b) { return a + b; }'
js_function = eval_js(js_code)
result = js_function(5, 3)
print(result) # Output should be 8