Comprehensions over break and continue

This commit is contained in:
Jeremy Ashkenas
2010-12-23 08:50:34 -08:00
parent 34b16699fa
commit b56b08387d
4 changed files with 47 additions and 14 deletions

View File

@@ -210,7 +210,7 @@
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
exp = _ref[_i];
if (exp.jumps(o)) {
return true;
return exp;
}
}
};
@@ -338,7 +338,11 @@
if ((_ref = this.value) !== 'break' && _ref !== 'continue' && _ref !== 'debugger') {
return false;
}
return !(o && (o.loop || o.block && (this.value !== 'continue')));
if (!(o && (o.loop || o.block && (this.value !== 'continue')))) {
return this;
} else {
return false;
}
};
Literal.prototype.compile = function() {
if (this.value.reserved) {
@@ -360,7 +364,7 @@
Return.prototype.children = ['expression'];
Return.prototype.isStatement = YES;
Return.prototype.makeReturn = THIS;
Return.prototype.jumps = YES;
Return.prototype.jumps = THIS;
Return.prototype.compile = function(o, level) {
var expr, _ref;
expr = (_ref = this.expression) != null ? _ref.makeReturn() : void 0;
@@ -1445,7 +1449,7 @@
if (node.jumps({
loop: true
})) {
return true;
return node;
}
}
return false;
@@ -1795,6 +1799,9 @@
var body, defPart, forPart, guardPart, idt1, index, ivar, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, svar, varPart, _ref;
body = Expressions.wrap([this.body]);
lastJumps = (_ref = last(body.expressions)) != null ? _ref.jumps() : void 0;
if (lastJumps && lastJumps instanceof Return) {
this.returns = false;
}
source = this.range ? this.source.base : this.source;
scope = o.scope;
name = this.name && this.name.compile(o, LEVEL_LIST);
@@ -1809,7 +1816,7 @@
immediate: true
});
}
if (this.returns && !lastJumps) {
if (this.returns) {
rvar = scope.freeVariable('results');
}
ivar = (this.range ? name : index) || scope.freeVariable('i');
@@ -1843,7 +1850,7 @@
forPart = "" + ivar + " = 0, " + lvar + " = " + svar + ".length; " + ivar + " < " + lvar + "; " + stepPart;
}
}
if (this.returns && !lastJumps) {
if (this.returns) {
resultPart = "" + this.tab + rvar + " = [];\n";
returnResult = "\n" + this.tab + "return " + rvar + ";";
body = Push.wrap(rvar, body);
@@ -1931,7 +1938,7 @@
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_ref2 = _ref[_i], conds = _ref2[0], block = _ref2[1];
if (block.jumps(o)) {
return true;
return block;
}
}
return (_ref3 = this.otherwise) != null ? _ref3.jumps(o) : void 0;