First draft at loop block scoping again ... works for functions that mention 'this'

This commit is contained in:
Jeremy Ashkenas
2010-11-03 22:05:24 -04:00
parent 58cac0ca39
commit 9fc3f8593e
2 changed files with 27 additions and 16 deletions

View File

@@ -1534,19 +1534,24 @@
return '';
};
For.prototype.compileNode = function(o) {
var body, code, cond, defPart, forPart, guardPart, idt, index, ivar, lvar, name, namePart, pvar, retPart, rvar, scope, sourcePart, step, svar, tail, tvar, varPart, vars, _ref, _ref2, _ref3, _ref4, _ref5;
var body, code, cond, defPart, forPart, guardPart, hasCode, idt, index, ivar, lvar, name, namePart, pvar, retPart, rvar, scope, sourcePart, step, svar, tail, tvar, varPart, vars, _ref, _ref2, _ref3, _ref4, _ref5;
scope = o.scope;
body = this.body;
hasCode = this.body.contains(function(node) {
return node instanceof Code;
});
name = !this.pattern && ((_ref = this.name) != null ? _ref.compile(o) : void 0);
index = (_ref2 = this.index) != null ? _ref2.compile(o) : void 0;
ivar = !index ? scope.freeVariable('i') : index;
ivar = !index || hasCode ? scope.freeVariable('i') : index;
varPart = guardPart = defPart = retPart = '';
idt = this.idt(1);
if (name) {
scope.find(name, true);
}
if (index) {
scope.find(index, true);
if (!hasCode) {
if (name) {
scope.find(name, true);
}
if (index) {
scope.find(index, true);
}
}
if (this.step) {
_ref3 = this.step.compileLoopReference(o, 'step'), step = _ref3[0], pvar = _ref3[1];
@@ -1597,6 +1602,9 @@
}
})();
}
if (hasCode) {
body = Closure.wrap(body, true);
}
if (namePart) {
varPart = idt + namePart + ';\n';
}
@@ -1633,10 +1641,10 @@
continue;
}
val = expr.variable.unwrapAll();
if (!(val instanceof Code && !expr.args.length || val instanceof Value && val.base instanceof Code && val.properties.length === 1 && ((_ref2 = val.properties[0].name) != null ? _ref2.value : void 0) === 'call')) {
if (!((val instanceof Code && !expr.args.length) || (val instanceof Value && val.base.unwrapAll() instanceof Code && val.properties.length === 1 && ((_ref2 = val.properties[0].name) != null ? _ref2.value : void 0) === 'call'))) {
continue;
}
fn = val.base || val;
fn = val.base.unwrapAll() || val;
ref = new Literal(o.scope.freeVariable('fn'));
base = new Value(ref);
args = compact([name, index]);