Js2Py
Js2Py copied to clipboard
JsException: SyntaxError: Line 2: ObjectPattern is not supported by ECMA 5.1.
js = """
const { spawn } = require('child_process');
const ls = spawn('command', ['-m 117M g 'hello' -l 500'], {shell: true});
ls.stdout.on('data', data => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', data => {
console.log(`stderr: ${data}`);
});
ls.on('error', (error) => {
console.log(`error: ${error.message}`);
});
ls.on('close', code => {
console.log(`child process exited with code ${code}`);
});
"""
import js2py
js2py.eval_js(js)
JsException: SyntaxError: Line 2: ObjectPattern is not supported by ECMA 5.1.
How can this be solved?
You have to use Babel to support ECMA6; from the readme:
>>> js2py.eval_js6('let a = () => 11; a()')
11