Merge branch 'master' of github.com:jashkenas/coffee-script

This commit is contained in:
Timothy Jones
2010-10-24 02:17:44 +13:00
4 changed files with 37 additions and 40 deletions

View File

@@ -1463,9 +1463,6 @@
this.step || (this.step = new Literal(1));
}
this.pattern = this.name instanceof Value;
if (this.range && this.pattern) {
throw SyntaxError('cannot pattern match a range loop');
}
this.returns = false;
return this;
};
@@ -1488,12 +1485,12 @@
return '';
};
For.prototype.compileNode = function(o) {
var _ref2, _ref3, _ref4, _ref5, _ref6, body, cond, defPart, forPart, guardPart, idt, index, ivar, lvar, name, namePart, pvar, resultRet, rvar, scope, sourcePart, step, svar, tail, tvar, varPart, vars;
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;
scope = o.scope;
name = !this.pattern && ((_ref2 = this.name) != null ? _ref2.compile(o) : undefined);
index = (_ref3 = this.index) != null ? _ref3.compile(o) : undefined;
ivar = !index ? scope.freeVariable('i') : index;
varPart = '';
varPart = guardPart = defPart = retPart = '';
body = Expressions.wrap([this.body]);
idt = this.idt(1);
if (name) {
@@ -1511,13 +1508,13 @@
}
if (this.from) {
_ref5 = this.to.compileLoopReference(o, 'to'), tail = _ref5[0], tvar = _ref5[1];
vars = "" + ivar + " = " + (this.from.compile(o));
vars = ivar + ' = ' + this.from.compile(o);
if (tail !== tvar) {
vars += ", " + tail;
vars += ', ' + tail;
}
cond = +pvar ? "" + ivar + " " + (pvar < 0 ? '>' : '<') + "= " + tvar : "" + pvar + " < 0 ? " + ivar + " >= " + tvar + " : " + ivar + " <= " + tvar;
} else {
if (name) {
if (name || this.object && !this.raw) {
_ref6 = this.source.compileLoopReference(o, 'ref'), sourcePart = _ref6[0], svar = _ref6[1];
} else {
sourcePart = svar = this.source.compile(o, LVL_PAREN);
@@ -1534,18 +1531,17 @@
}
}
}
defPart = '';
if (this.object) {
forPart = "" + ivar + " in " + sourcePart;
guardPart = !this.raw && ("" + idt + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;\n");
forPart = ivar + ' in ' + sourcePart;
guardPart = this.raw ? '' : idt + ("if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;\n");
} else {
if (step !== pvar) {
vars += ", " + step;
vars += ', ' + step;
}
if (svar !== sourcePart) {
defPart = "" + this.tab + sourcePart + ";\n";
defPart = this.tab + sourcePart + ';\n';
}
forPart = ("" + vars + "; " + cond + "; ") + ivar + (function() {
forPart = vars + ("; " + cond + "; ") + ivar + (function() {
switch (+pvar) {
case 1:
return '++';
@@ -1558,18 +1554,18 @@
}
if (o.level > LVL_TOP || this.returns) {
rvar = scope.freeVariable('result');
defPart += "" + this.tab + rvar + " = [];\n";
resultRet = this.compileReturnValue(rvar, o);
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";
varPart = idt + namePart + ';\n';
}
o.indent = idt;
return "" + (defPart || '') + this.tab + "for (" + forPart + ") {\n" + (guardPart || '') + varPart + (body.compile(o, LVL_TOP)) + "\n" + this.tab + "}" + (resultRet || '');
return defPart + ("" + this.tab + "for (" + forPart + ") {\n" + (guardPart || '') + varPart + (body.compile(o, LVL_TOP)) + "\n" + this.tab + "}") + retPart;
};
return For;
})();