Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When fn arguments are reassigned, do not redeclare with 'var' #882

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
When fn arguments are reassigned, do not redeclare with 'var'
JGreenlee committed Sep 3, 2024
commit 0d941d1b1db6598115811ade8a4bd3d9d7395c62
4 changes: 3 additions & 1 deletion transcrypt/modules/org/transcrypt/compiler.py
Original file line number Diff line number Diff line change
@@ -1020,7 +1020,7 @@ def visit_arguments (self, node): # Visited for def's, not for calls
self.emit ('if (typeof {0} == \'undefined\' || ({0} != null && {0}.hasOwnProperty ("__kwargtrans__"))) {{;\n', self.filterId (arg.arg))

self.indent ()
self.emit ('var {} = ', self.filterId (arg.arg))
self.emit ('{} = ', self.filterId (arg.arg))
self.visit (expr)
self.emit (';\n')
self.dedent ()
@@ -1161,6 +1161,8 @@ def emitPathIndices ():
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:
pass
elif (fnscope := self.getScope(ast.FunctionDef, ast.AsyncFunctionDef)) and target.id in [a.arg for a in fnscope.node.args.args]:
pass
else:
if type (self.getScope () .node) == ast.Module: # Redundant but regular
if hasattr (node, 'parentNode') and type (node.parentNode) == ast.Module and not target.id in self.allOwnNames: