mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Issue #843. If a for-body ends in a pure-statement, no need to try and return results.
This commit is contained in:
15
lib/nodes.js
15
lib/nodes.js
@@ -1754,10 +1754,12 @@
|
||||
};
|
||||
For.prototype.containsPureStatement = While.prototype.containsPureStatement;
|
||||
For.prototype.compileNode = function(o) {
|
||||
var body, defPart, forPart, guardPart, hasCode, idt1, index, ivar, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, svar, varPart;
|
||||
hasCode = this.body.contains(function(node) {
|
||||
var body, defPart, forPart, guardPart, hasCode, hasPure, idt1, index, ivar, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, svar, varPart, _ref;
|
||||
body = Expressions.wrap([this.body]);
|
||||
hasCode = body.contains(function(node) {
|
||||
return node instanceof Code;
|
||||
});
|
||||
hasPure = (_ref = last(body.expressions)) != null ? _ref.containsPureStatement() : void 0;
|
||||
source = this.range ? this.source.base : this.source;
|
||||
scope = o.scope;
|
||||
name = this.name && this.name.compile(o, LEVEL_LIST);
|
||||
@@ -1774,14 +1776,13 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
if (this.returns) {
|
||||
if (this.returns && !hasPure) {
|
||||
rvar = scope.freeVariable('results');
|
||||
}
|
||||
ivar = (this.range ? name : index) || scope.freeVariable('i');
|
||||
varPart = '';
|
||||
guardPart = '';
|
||||
defPart = '';
|
||||
body = Expressions.wrap([this.body]);
|
||||
idt1 = this.tab + TAB;
|
||||
if (this.range) {
|
||||
forPart = source.compile(merge(o, {
|
||||
@@ -1803,12 +1804,10 @@
|
||||
forPart = "" + ivar + " = 0, " + lvar + " = " + svar + ".length; " + ivar + " < " + lvar + "; " + stepPart;
|
||||
}
|
||||
}
|
||||
if (this.returns) {
|
||||
if (this.returns && !hasPure) {
|
||||
resultPart = "" + this.tab + rvar + " = [];\n";
|
||||
returnResult = '\n' + (new Return(new Literal(rvar)).compile(o, LEVEL_PAREN));
|
||||
if (this.returns) {
|
||||
body = Push.wrap(rvar, body);
|
||||
}
|
||||
body = Push.wrap(rvar, body);
|
||||
}
|
||||
if (this.guard) {
|
||||
body = Expressions.wrap([new If(this.guard, body)]);
|
||||
|
||||
Reference in New Issue
Block a user