mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
Fixing closures-generated-within-comprehensions to preserve block local scope for range comprehensions
This commit is contained in:
@@ -1305,10 +1305,10 @@ 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 not codeInBody
|
||||
scope.find name if name and not @pattern and (range or not codeInBody)
|
||||
scope.find index if index
|
||||
rvar = scope.freeVariable() unless topLevel
|
||||
ivar = if range then name else if codeInBody then scope.freeVariable() else index or scope.freeVariable()
|
||||
ivar = if codeInBody then scope.freeVariable() else if range then name else index or scope.freeVariable()
|
||||
varPart = ''
|
||||
guardPart = ''
|
||||
body = Expressions.wrap([@body])
|
||||
@@ -1334,6 +1334,7 @@ exports.ForNode = class ForNode extends BaseNode
|
||||
if @guard
|
||||
body = Expressions.wrap([new IfNode(@guard, body)])
|
||||
if codeInBody
|
||||
body.unshift literal "var #{name} = #{ivar}" if range
|
||||
body.unshift literal "var #{namePart}" if namePart
|
||||
body.unshift literal "var #{index} = #{ivar}" if index
|
||||
body = ClosureNode.wrap(body, true)
|
||||
|
||||
Reference in New Issue
Block a user