mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Removed the last bits of pureStatements
This commit is contained in:
34
lib/nodes.js
34
lib/nodes.js
@@ -34,7 +34,7 @@
|
||||
}
|
||||
node = this.unfoldSoak(o) || this;
|
||||
node.tab = o.indent;
|
||||
if (o.level === LEVEL_TOP || node.isPureStatement() || !node.isStatement(o)) {
|
||||
if (o.level === LEVEL_TOP || !node.isStatement(o)) {
|
||||
return node.compileNode(o);
|
||||
} else {
|
||||
return node.compileClosure(o);
|
||||
@@ -157,7 +157,6 @@
|
||||
};
|
||||
Base.prototype.children = [];
|
||||
Base.prototype.isStatement = NO;
|
||||
Base.prototype.isPureStatement = NO;
|
||||
Base.prototype.jumps = NO;
|
||||
Base.prototype.isComplex = YES;
|
||||
Base.prototype.isChainable = NO;
|
||||
@@ -199,7 +198,7 @@
|
||||
_ref = this.expressions;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
exp = _ref[_i];
|
||||
if (exp.isPureStatement() || exp.isStatement(o)) {
|
||||
if (exp.isStatement(o)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -321,16 +320,12 @@
|
||||
this.value = value;
|
||||
}
|
||||
Literal.prototype.makeReturn = function() {
|
||||
if (this.isPureStatement()) {
|
||||
if (this.jumps()) {
|
||||
return this;
|
||||
} else {
|
||||
return new Return(this);
|
||||
}
|
||||
};
|
||||
Literal.prototype.isPureStatement = function() {
|
||||
var _ref;
|
||||
return (_ref = this.value) === 'break' || _ref === 'continue' || _ref === 'debugger';
|
||||
};
|
||||
Literal.prototype.isAssignable = function() {
|
||||
return IDENTIFIER.test(this.value);
|
||||
};
|
||||
@@ -339,7 +334,11 @@
|
||||
return name === this.value;
|
||||
};
|
||||
Literal.prototype.jumps = function(o) {
|
||||
return this.isPureStatement() && !(o && (o.loop || o.block && (this.value !== 'continue')));
|
||||
var _ref;
|
||||
if ((_ref = this.value) !== 'break' && _ref !== 'continue' && _ref !== 'debugger') {
|
||||
return false;
|
||||
}
|
||||
return !(o && (o.loop || o.block && (this.value !== 'continue')));
|
||||
};
|
||||
Literal.prototype.compile = function() {
|
||||
if (this.value.reserved) {
|
||||
@@ -360,7 +359,6 @@
|
||||
}
|
||||
Return.prototype.children = ['expression'];
|
||||
Return.prototype.isStatement = YES;
|
||||
Return.prototype.isPureStatement = YES;
|
||||
Return.prototype.makeReturn = THIS;
|
||||
Return.prototype.jumps = YES;
|
||||
Return.prototype.compile = function(o, level) {
|
||||
@@ -521,7 +519,6 @@
|
||||
function Comment(comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
Comment.prototype.isPureStatement = YES;
|
||||
Comment.prototype.isStatement = YES;
|
||||
Comment.prototype.makeReturn = THIS;
|
||||
Comment.prototype.compileNode = function(o, level) {
|
||||
@@ -1471,8 +1468,7 @@
|
||||
}
|
||||
code = set + this.tab + ("while (" + (this.condition.compile(o, LEVEL_PAREN)) + ") {" + body + "}");
|
||||
if (this.returns) {
|
||||
o.indent = this.tab;
|
||||
code += '\n' + new Return(new Literal(rvar)).compile(o);
|
||||
code += "\n" + this.tab + "return " + rvar + ";";
|
||||
}
|
||||
return code;
|
||||
};
|
||||
@@ -1791,9 +1787,9 @@
|
||||
return this;
|
||||
};
|
||||
For.prototype.compileNode = function(o) {
|
||||
var body, defPart, forPart, guardPart, hasPureLast, idt1, index, ivar, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, svar, varPart, _ref;
|
||||
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]);
|
||||
hasPureLast = (_ref = last(body.expressions)) != null ? _ref.jumps() : void 0;
|
||||
lastJumps = (_ref = last(body.expressions)) != null ? _ref.jumps() : void 0;
|
||||
source = this.range ? this.source.base : this.source;
|
||||
scope = o.scope;
|
||||
name = this.name && this.name.compile(o, LEVEL_LIST);
|
||||
@@ -1808,7 +1804,7 @@
|
||||
immediate: true
|
||||
});
|
||||
}
|
||||
if (this.returns && !hasPureLast) {
|
||||
if (this.returns && !lastJumps) {
|
||||
rvar = scope.freeVariable('results');
|
||||
}
|
||||
ivar = (this.range ? name : index) || scope.freeVariable('i');
|
||||
@@ -1842,9 +1838,9 @@
|
||||
forPart = "" + ivar + " = 0, " + lvar + " = " + svar + ".length; " + ivar + " < " + lvar + "; " + stepPart;
|
||||
}
|
||||
}
|
||||
if (this.returns && !hasPureLast) {
|
||||
if (this.returns && !lastJumps) {
|
||||
resultPart = "" + this.tab + rvar + " = [];\n";
|
||||
returnResult = '\n' + (new Return(new Literal(rvar)).compile(o, LEVEL_PAREN));
|
||||
returnResult = "\n" + this.tab + "return " + rvar + ";";
|
||||
body = Push.wrap(rvar, body);
|
||||
}
|
||||
if (this.guard) {
|
||||
@@ -1970,7 +1966,7 @@
|
||||
break;
|
||||
}
|
||||
expr = this.lastNonComment(block.expressions);
|
||||
if (!expr || !expr.isPureStatement()) {
|
||||
if (!expr || !expr.jumps()) {
|
||||
code += idt2 + 'break;\n';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user