Fixed comprehension magic's scoping.

This commit is contained in:
Timothy Jones 2010-10-20 03:59:01 +13:00
parent 7b1902183c
commit d14ba6ac53
3 changed files with 7 additions and 8 deletions

View File

@ -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() {

View File

@ -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)));
}

View File

@ -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