Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
namesJS['rand'] = 'Math.random'
namesJS['random'] = 'Math.random'
class TupleTransformer(ast.NodeTransformer):
""" An ast subclass that walks the abstract syntax tree and
allows modification of nodes.
This class transforms a tuple to a list.
:returns node
"""
def visit_Tuple(self, node):
return ast.List(node.elts, node.ctx)
class Unparser(astunparse.Unparser):
"""astunparser had buried the future_imports option underneath its init()
so we need to override that method and change it."""
def __init__(self, tree, file):
"""Unparser(tree, file=sys.stdout) -> None.
Print the source for tree to file."""
self.f = file
self.future_imports = ['unicode_literals']
self._indent = 0
self.dispatch(tree)
self.f.flush()
def unparse(tree):
v = StringIO()
Unparser(tree, file=v)
def _unparse(node):
"""Prints Python code which could parse to `node`.
Args:
* node (ast.AST) - The AST to produce Python code for.
Returns a str with the formatted code.
"""
assert isinstance(node, ast.AST), type(node)
buf = StringIO()
astunparse.Unparser(node, buf)
return buf.getvalue()
print env.cf.path
TypeInfer(env, args, func.func_globals).run()
print env.cf.blocks
InsertCoerceNode(env).run()
#CoerceReturn(env).run()
print ast.dump(node)
RewriteName(env).run()
RewriteSubscript(env).run()
InsertArrayInfo(env).run()
InsertDefination(env).run()
buf=StringIO()
Unparser(node,buf)
print buf.getvalue()
#print get_return_type(env.return_node_infos)