fixing comprehensions to also close over the index variable, if used in an inner function...

This commit is contained in:
Jeremy Ashkenas
2010-06-13 21:43:04 -04:00
parent b0a45e5b93
commit d0948e5586
3 changed files with 20 additions and 8 deletions

View File

@@ -1196,9 +1196,9 @@ exports.ForNode: class ForNode extends BaseNode
name: @name and @name.compile o
index: @index and @index.compile o
scope.find name if name and not @pattern and not codeInBody
scope.find index if index and not codeInBody
scope.find index if index
rvar: scope.freeVariable() unless topLevel
ivar: if range then name else index or scope.freeVariable()
ivar: if range then name else if codeInBody then scope.freeVariable() else index or scope.freeVariable()
varPart: ''
body: Expressions.wrap([@body])
if range
@@ -1224,6 +1224,7 @@ exports.ForNode: class ForNode extends BaseNode
body: Expressions.wrap([new IfNode(@guard, body)])
if codeInBody
body.unshift literal "var $namePart" if namePart
body.unshift literal "var $index = $ivar" if index
body: ClosureNode.wrap(body, true)
else
varPart: "${@idt(1)}$namePart;\n" if namePart