mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Comprehensions over break and continue
This commit is contained in:
21
lib/nodes.js
21
lib/nodes.js
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user