From d14ba6ac53a2f97994c0a84020e71a83d6d82ca0 Mon Sep 17 00:00:00 2001 From: Timothy Jones Date: Wed, 20 Oct 2010 03:59:01 +1300 Subject: [PATCH] Fixed comprehension magic's scoping. --- lib/command.js | 3 +-- lib/nodes.js | 5 +++-- src/nodes.coffee | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/command.js b/lib/command.js index 17b3116e..c369f751 100644 --- a/lib/command.js +++ b/lib/command.js @@ -48,11 +48,10 @@ return compileScripts(); }; compileScripts = function() { - var _i, _j, _len, _ref2, _result, source; + var _i, _j, _len, _ref2, _result, base, compile, source; _result = []; for (_i = 0, _len = (_ref2 = sources).length; _i < _len; _i++) { (function() { - var base, compile; var source = _ref2[_i]; _j = source; return _result.push((function() { diff --git a/lib/nodes.js b/lib/nodes.js index 99a925fb..2b027cc4 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1724,7 +1724,7 @@ if (this.guard) { body = Expressions.wrap([new If(this.guard, body)]); } - if (codeInBody) { + if (codeInBody && !body.containsPureStatement()) { if (range) { body.unshift(new Literal("var " + name + " = " + ivar)); } @@ -1742,7 +1742,8 @@ body.push(new Assign(new Literal(nvar), new Literal(name))); } body.push(lastLine); - body = Closure.wrap(body, true, true); + o.indent = this.idt(1); + body = Expressions.wrap([new Literal(body.compile(o))]); if (index) { body.push(new Assign(new Literal(index), new Literal(ivar))); } diff --git a/src/nodes.coffee b/src/nodes.coffee index 7edb8013..d377620b 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1452,7 +1452,7 @@ exports.For = class For extends Base body = Push.wrap(rvar, body) unless topLevel if @guard body = Expressions.wrap([new If(@guard, body)]) - if codeInBody + if codeInBody and not body.containsPureStatement() body.unshift new Literal "var #{name} = #{ivar}" if range body.unshift new Literal "var #{namePart}" if namePart body.unshift new Literal "var #{index} = #{ivar}" if index @@ -1460,9 +1460,8 @@ exports.For = class For extends Base body.push new Assign new Literal(ivar), new Literal index if index body.push new Assign new Literal(nvar), new Literal name if nvar body.push lastLine - # o.indent = @idt 1 - # comp = new Literal body.compile o - body = Closure.wrap(body, yes, yes) + o.indent = @idt 1 + body = Expressions.wrap [new Literal body.compile o] body.push new Assign new Literal(index), new Literal ivar if index body.push new Assign new Literal(name), new Literal nvar or ivar if name else