This commit is contained in:
Timothy Jones
2010-10-20 07:43:07 +13:00
3 changed files with 26 additions and 7 deletions

View File

@@ -1650,7 +1650,7 @@
return '';
};
For.prototype.compileNode = function(o) {
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lastLine, lvar, name, namePart, nvar, range, ref, resultPart, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lastLine, lvar, name, namePart, nvar, range, ref, resultPart, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, unstepPart, varPart, vars;
topLevel = del(o, 'top') && !this.returns;
range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
source = range ? this.source.base : this.source;
@@ -1682,6 +1682,7 @@
}
varPart = '';
guardPart = '';
unstepPart = '';
body = Expressions.wrap([this.body]);
idt1 = this.idt(1);
if (range) {
@@ -1717,10 +1718,12 @@
if (this.guard) {
body = Expressions.wrap([new If(this.guard, body)]);
}
if (codeInBody && !body.containsPureStatement()) {
if (codeInBody) {
if (range) {
body.unshift(new Literal("var " + name + " = " + ivar));
}
}
if (codeInBody && !body.containsPureStatement()) {
if (namePart) {
body.unshift(new Literal("var " + namePart));
}
@@ -1747,6 +1750,10 @@
if (namePart) {
varPart = ("" + idt1 + namePart + ";\n");
}
if (forPart && name === ivar) {
unstepPart = this.step ? ("" + name + " -= " + (this.step.compile(o)) + ";") : ("" + name + "--;");
unstepPart = ("\n" + (this.tab)) + unstepPart;
}
}
if (this.object) {
forPart = ("" + ivar + " in " + sourcePart);
@@ -1759,7 +1766,7 @@
top: true
}));
vars = range ? name : ("" + name + ", " + ivar);
return "" + resultPart + (this.tab) + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + (this.tab) + "}" + returnResult;
return "" + resultPart + (this.tab) + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + (this.tab) + "}" + unstepPart + returnResult;
};
return For;
})();