mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
removed extra lines from trailing then compilations
This commit is contained in:
64
lib/nodes.js
64
lib/nodes.js
@@ -187,8 +187,8 @@
|
||||
Expressions.prototype.unwrap = function() {
|
||||
return this.expressions.length === 1 ? this.expressions[0] : this;
|
||||
};
|
||||
Expressions.prototype.empty = function() {
|
||||
return this.expressions.length === 0;
|
||||
Expressions.prototype.isEmpty = function() {
|
||||
return !this.expressions.length;
|
||||
};
|
||||
Expressions.prototype.makeReturn = function() {
|
||||
var _ref2, end, idx;
|
||||
@@ -845,7 +845,7 @@
|
||||
constScope || (constScope = new Scope(o.scope, constructor.body, constructor));
|
||||
me || (me = constScope.freeVariable('this'));
|
||||
pname = pvar.compile(o);
|
||||
if (constructor.body.empty()) {
|
||||
if (constructor.body.isEmpty()) {
|
||||
constructor.body.push(new Return(new Literal('this')));
|
||||
}
|
||||
constructor.body.unshift(new Literal("this." + pname + " = function(){ return " + className + ".prototype." + pname + ".apply(" + me + ", arguments); }"));
|
||||
@@ -867,7 +867,7 @@
|
||||
if (extension) {
|
||||
construct += '\n' + this.tab + extension.compile(o) + ';';
|
||||
}
|
||||
if (!props.empty()) {
|
||||
if (!props.isEmpty()) {
|
||||
construct += '\n' + props.compile(o);
|
||||
}
|
||||
if (this.returns) {
|
||||
@@ -1235,17 +1235,22 @@
|
||||
o.indent = this.idt(1);
|
||||
set = '';
|
||||
body = this.body;
|
||||
if (o.level > LEVEL_TOP || this.returns) {
|
||||
rvar = o.scope.freeVariable('result');
|
||||
set = "" + this.tab + rvar + " = [];\n";
|
||||
if (body) {
|
||||
body = Push.wrap(rvar, body);
|
||||
if (body.isEmpty()) {
|
||||
body = '';
|
||||
} else {
|
||||
if (o.level > LEVEL_TOP || this.returns) {
|
||||
rvar = o.scope.freeVariable('result');
|
||||
set = "" + this.tab + rvar + " = [];\n";
|
||||
if (body) {
|
||||
body = Push.wrap(rvar, body);
|
||||
}
|
||||
}
|
||||
if (this.guard) {
|
||||
body = Expressions.wrap([new If(this.guard, body)]);
|
||||
}
|
||||
body = "\n" + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab;
|
||||
}
|
||||
if (this.guard) {
|
||||
body = Expressions.wrap([new If(this.guard, body)]);
|
||||
}
|
||||
code = set + this.tab + ("while (" + (this.condition.compile(o, LEVEL_PAREN)) + ") {\n" + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}");
|
||||
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);
|
||||
@@ -1545,7 +1550,7 @@
|
||||
return '';
|
||||
};
|
||||
For.prototype.compileNode = function(o) {
|
||||
var _ref2, _ref3, _ref4, _ref5, _ref6, body, cond, defPart, forPart, guardPart, idt, index, ivar, lvar, name, namePart, pvar, retPart, rvar, scope, sourcePart, step, svar, tail, tvar, varPart, vars;
|
||||
var _ref2, _ref3, _ref4, _ref5, _ref6, body, code, cond, defPart, forPart, guardPart, idt, index, ivar, lvar, name, namePart, pvar, retPart, rvar, scope, sourcePart, step, svar, tail, tvar, varPart, vars;
|
||||
scope = o.scope;
|
||||
name = !this.pattern && ((_ref2 = this.name) != null ? _ref2.compile(o) : undefined);
|
||||
index = (_ref3 = this.index) != null ? _ref3.compile(o) : undefined;
|
||||
@@ -1612,20 +1617,27 @@
|
||||
}
|
||||
})();
|
||||
}
|
||||
if (o.level > LEVEL_TOP || this.returns) {
|
||||
rvar = scope.freeVariable('result');
|
||||
defPart += this.tab + rvar + ' = [];\n';
|
||||
retPart = this.compileReturnValue(rvar, o);
|
||||
body = Push.wrap(rvar, body);
|
||||
}
|
||||
if (this.guard) {
|
||||
body = Expressions.wrap([new If(this.guard, body)]);
|
||||
}
|
||||
if (namePart) {
|
||||
varPart = idt + namePart + ';\n';
|
||||
}
|
||||
o.indent = idt;
|
||||
return defPart + ("" + this.tab + "for (" + forPart + ") {\n" + (guardPart || '') + varPart + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}") + retPart;
|
||||
code = guardPart + varPart;
|
||||
if (!body.isEmpty()) {
|
||||
if (o.level > LEVEL_TOP || this.returns) {
|
||||
rvar = scope.freeVariable('result');
|
||||
defPart += this.tab + rvar + ' = [];\n';
|
||||
retPart = this.compileReturnValue(rvar, o);
|
||||
body = Push.wrap(rvar, body);
|
||||
}
|
||||
if (this.guard) {
|
||||
body = Expressions.wrap([new If(this.guard, body)]);
|
||||
}
|
||||
o.indent = idt;
|
||||
code += body.compile(o, LEVEL_TOP);
|
||||
}
|
||||
if (code) {
|
||||
code = '\n' + code + '\n' + this.tab;
|
||||
}
|
||||
return defPart + this.tab + ("for (" + forPart + ") {" + code + "}") + retPart;
|
||||
};
|
||||
return For;
|
||||
})();
|
||||
@@ -1782,7 +1794,7 @@
|
||||
}).call(this);
|
||||
Push = {
|
||||
wrap: function(name, expressions) {
|
||||
if (expressions.empty() || last(expressions.expressions).containsPureStatement()) {
|
||||
if (expressions.isEmpty() || last(expressions.expressions).containsPureStatement()) {
|
||||
return expressions;
|
||||
}
|
||||
return expressions.push(new Call(new Value(new Literal(name), [new Accessor(new Literal('push'))]), [expressions.pop()]));
|
||||
|
||||
Reference in New Issue
Block a user