Skip to content

Commit 0b4228e

Browse files
author
hartsantler
committed
Merge branch 'master' of https://github.com/PythonJS/PythonJS
2 parents b865ae3 + a633347 commit 0b4228e

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

pythonjs/python_to_pythonjs.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,18 +1096,30 @@ def visit_FunctionDef(self, node):
10961096
## this is kept here as an option to be sure we are compatible with the
10971097
## old-style code in runtime/pythonpythonjs.py and runtime/builtins.py
10981098
if not GLOBAL_VARIABLE_SCOPE:
1099-
local_vars = set()
1100-
global_vars = set()
1101-
for n in node.body:
1102-
if isinstance(n, Assign) and isinstance(n.targets[0], Name): ## assignment to local
1103-
local_vars.add( n.targets[0].id )
1104-
elif isinstance(n, Global):
1105-
global_vars.update( n.names )
1106-
elif isinstance(n, With) and isinstance( n.context_expr, Name ) and n.context_expr.id == 'javascript':
1107-
for c in n.body:
1108-
if isinstance(c, Assign) and isinstance(c.targets[0], Name): ## assignment to local
1109-
local_vars.add( c.targets[0].id )
1110-
1099+
def retrieve_vars(body):
1100+
local_vars = set()
1101+
global_vars = set()
1102+
for n in body:
1103+
if isinstance(n, Assign) and isinstance(n.targets[0], Name): ## assignment to local
1104+
local_vars.add( n.targets[0].id )
1105+
elif isinstance(n, Global):
1106+
global_vars.update( n.names )
1107+
elif isinstance(n, With) and isinstance( n.context_expr, Name ) and n.context_expr.id == 'javascript':
1108+
for c in n.body:
1109+
if isinstance(c, Assign) and isinstance(c.targets[0], Name): ## assignment to local
1110+
local_vars.add( c.targets[0].id )
1111+
elif hasattr(n, 'body') and not isinstance(n, FunctionDef):
1112+
# do a recursive search inside new block except function def
1113+
l, g = retrieve_vars(n.body)
1114+
local_vars.update(l)
1115+
global_vars.update(g)
1116+
if hasattr(n, 'orelse'):
1117+
l, g = retrieve_vars(n.orelse)
1118+
local_vars.update(l)
1119+
global_vars.update(g)
1120+
return local_vars, global_vars
1121+
1122+
local_vars, global_vars = retrieve_vars(node.body)
11111123
if local_vars-global_vars:
11121124
a = ','.join( local_vars-global_vars )
11131125
writer.write('var(%s)' %a)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='PythonJS',
6-
version='0.8',
6+
version='0.8.2',
77
description='Python translator for the browser',
88
author='Amirouche Boubekki',
99
author_email='amirouche.boubekki@gmail.com',

0 commit comments

Comments
 (0)