Here is the test code and functioning equivalent:
js2py.eval_js('''console.log(eval('('+function(){return "works!"}+')')())''')
js2py.eval_js('''console.log(eval((function(){return "works!"}))())''')
Still trying to find this in the spec and understand what's missing, from what I gather js2py can't yet parse mixed code/text function declaration and tries to handle it as an argumentlist
Traceback (most recent call last):
File "", line 1, in
File "js2py/evaljs.py", line 167, in execute
exec(compiled, self._context)
File "<EvalJS snippet>", line 8, in
File "js2py/base.py", line 835, in call
return self.call(self.GlobalObject, args)
File "js2py/base.py", line 1281, in call
return Js(self.code(*args))
File "js2py/host/jseval.py", line 16, in Eval
py_code = translate_js(code.to_string().value, '')
File "js2py/translators/translator.py", line 62, in translate_js
parsed = parser.parse(js) # js to esprima syntax tree
File "js2py/translators/pyjsparser.py", line 2862, in parse
program = self.parseProgram();
File "js2py/translators/pyjsparser.py", line 2833, in parseProgram
body = self.parseScriptBody()
File "js2py/translators/pyjsparser.py", line 2822, in parseScriptBody
statement = self.parseStatementListItem();
File "js2py/translators/pyjsparser.py", line 1978, in parseStatementListItem
return self.parseFunctionDeclaration(Node());
File "js2py/translators/pyjsparser.py", line 2738, in parseFunctionDeclaration
body = self.parseFunctionSourceElements();
File "js2py/translators/pyjsparser.py", line 2627, in parseFunctionSourceElements
body.append(self.parseStatementListItem())
File "js2py/translators/pyjsparser.py", line 1983, in parseStatementListItem
return self.parseStatement();
File "js2py/translators/pyjsparser.py", line 2568, in parseStatement
expr = self.parseExpression();
File "js2py/translators/pyjsparser.py", line 1949, in parseExpression
expr = self.isolateCoverGrammar(self.parseAssignmentExpression)
File "js2py/translators/pyjsparser.py", line 1126, in isolateCoverGrammar
result = parser()
File "js2py/translators/pyjsparser.py", line 1916, in parseAssignmentExpression
expr = self.parseConditionalExpression();
File "js2py/translators/pyjsparser.py", line 1817, in parseConditionalExpression
expr = self.inheritCoverGrammar(self.parseBinaryExpression);
File "js2py/translators/pyjsparser.py", line 1141, in inheritCoverGrammar
result = parser()
File "js2py/translators/pyjsparser.py", line 1765, in parseBinaryExpression
left = self.inheritCoverGrammar(self.parseUnaryExpression);
File "js2py/translators/pyjsparser.py", line 1141, in inheritCoverGrammar
result = parser()
File "js2py/translators/pyjsparser.py", line 1741, in parseUnaryExpression
expr = self.parsePostfixExpression()
File "js2py/translators/pyjsparser.py", line 1694, in parsePostfixExpression
expr = self.inheritCoverGrammar(self.parseLeftHandSideExpressionAllowCall)
File "js2py/translators/pyjsparser.py", line 1141, in inheritCoverGrammar
result = parser()
File "js2py/translators/pyjsparser.py", line 1631, in parseLeftHandSideExpressionAllowCall
expr = self.inheritCoverGrammar(self.parseNewExpression if self.matchKeyword('new') else self.parsePrimaryExpression)
File "js2py/translators/pyjsparser.py", line 1141, in inheritCoverGrammar
result = parser()
File "js2py/translators/pyjsparser.py", line 1525, in parsePrimaryExpression
return self.inheritCoverGrammar(self.parseArrayInitialiser)
File "js2py/translators/pyjsparser.py", line 1141, in inheritCoverGrammar
result = parser()
File "js2py/translators/pyjsparser.py", line 1241, in parseArrayInitialiser
self.expect(',')
File "js2py/translators/pyjsparser.py", line 1024, in expect
self.throwUnexpectedToken(token)
File "js2py/translators/pyjsparser.py", line 1013, in throwUnexpectedToken
raise self.unexpectedTokenError(token, message)
hey, this is because function.toString method always returns function() { [python code] }. Of course this is invalid syntax for eval ;) You cant as of yet print actual function code, but if i have time I might add it in the future
any update?i need get js function code,thanks