From 640ba7d69e6adec8464e21b4dc3a16900294679d Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sat, 18 Dec 2010 10:41:44 -0500 Subject: [PATCH] Issue #948. A plucked direct call should not have shared scope. (kinda defeats the whole point.) --- lib/command.js | 3 ++- lib/nodes.js | 1 - src/nodes.coffee | 1 - test/test_comprehensions.coffee | 9 +++++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/command.js b/lib/command.js index f2ac91b8..7611ef24 100644 --- a/lib/command.js +++ b/lib/command.js @@ -50,8 +50,9 @@ return compileScripts(); }; compileScripts = function() { - var base, compile, source, _fn, _i, _len, _results; + var source, _fn, _i, _len, _results; _fn = function(source) { + var base, compile; base = path.join(source); compile = function(source, topLevel) { return path.exists(source, function(exists) { diff --git a/lib/nodes.js b/lib/nodes.js index a4600433..d33c5c6f 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1884,7 +1884,6 @@ args.unshift(new Literal('this')); } body.expressions[idx] = new Call(base, args); - o.sharedScope = true; defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n'; } return defs; diff --git a/src/nodes.coffee b/src/nodes.coffee index 8b10ca72..b29ba950 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1500,7 +1500,6 @@ exports.For = class For extends Base [val.base, base] = [base, val] args.unshift new Literal 'this' body.expressions[idx] = new Call base, args - o.sharedScope = yes defs += @tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n' defs diff --git a/test/test_comprehensions.coffee b/test/test_comprehensions.coffee index 37467962..22690020 100644 --- a/test/test_comprehensions.coffee +++ b/test/test_comprehensions.coffee @@ -249,3 +249,12 @@ for d in a.b?.c e = d eq e, 3 + + +# Issue #948. Capturing loop variables. +funcs = [] +for y in [1, 2, 3] + z = y + funcs.push -> "y is #{y} and z is #{z}" + +eq funcs[1](), "y is 2 and z is 2"