Fixing Issue #643. Be a little bit safer about declaring block variables as close to the block scope as possible.

This commit is contained in:
Jeremy Ashkenas
2010-08-24 22:19:53 -04:00
parent e2c46d14f0
commit fa95f743f3
5 changed files with 33 additions and 14 deletions

View File

@@ -1357,8 +1357,8 @@ exports.ForNode = class ForNode extends BaseNode
scope = o.scope
name = (@name and @name.compile(o)) or scope.freeVariable()
index = @index and @index.compile o
scope.find name if name and not @pattern and (range or not codeInBody)
scope.find index if index
scope.find(name, immediate: yes) if name and not @pattern and (range or not codeInBody)
scope.find(index, immediate: yes) if index
rvar = scope.freeVariable() unless topLevel
ivar = if codeInBody then scope.freeVariable() else if range then name else index or scope.freeVariable()
varPart = ''