Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions transcrypt/modules/org/transcrypt/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ def inscope (self, node):
self.scopes.append (utils.Any (
node = node,
nonlocals = set (),
locals_ = set (),
containsYield = False
))

Expand Down Expand Up @@ -1161,15 +1162,17 @@ def emitPathIndices ():
self.emit (')')
else:
if type (target) == ast.Name:
if type (self.getScope () .node) == ast.ClassDef and target.id != self.getTemp ('left'):
scope = self.getScope ()
if type (scope.node) == ast.ClassDef and target.id != self.getTemp ('left'):
self.emit ('{}.'.format ('.'.join ([scope.node.name for scope in self.getAdjacentClassScopes ()]))) # The target is a class attribute
elif target.id in self.getScope () .nonlocals:
elif target.id in scope .nonlocals or target.id in scope.locals_:
pass
else:
if type (self.getScope () .node) == ast.Module: # Redundant but regular
if type (scope.node) == ast.Module: # Redundant but regular
if hasattr (node, 'parentNode') and type (node.parentNode) == ast.Module and not target.id in self.allOwnNames:
self.emit ('export ')
self.emit ('var ')
scope.locals_ .add (target.id) # Add to locals, so it can be used in the function body
self.visit (target)
self.emit (' = ')
self.visit (value)
Expand Down Expand Up @@ -2593,6 +2596,7 @@ def visit_AsyncFunctionDef (self, node):
def visit_FunctionDef (self, node, anAsync = False):
def emitScopedBody ():
self.inscope (node)
self.getScope () .locals_.update(a.arg for a in node.args.args)
self.emitBody (node.body)
self.dedent ()
if self.getScope (ast.AsyncFunctionDef if anAsync else ast.FunctionDef) .containsYield:
Expand Down