merging the range-killer to master

This commit is contained in:
Jeremy Ashkenas
2010-10-21 21:27:45 -04:00
23 changed files with 639 additions and 1035 deletions

View File

@@ -1,5 +1,5 @@
(function() {
var Accessor, ArrayLiteral, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, Literal, NO, NUMBER, ObjectLiteral, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, _ref, compact, del, ends, flatten, last, merge, starts, utility;
var Accessor, ArrayLiteral, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, Literal, NO, NUMBER, ObjectLiteral, Op, Param, Parens, Push, Return, SIMPLENUM, Scope, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, _ref, compact, del, ends, extend, flatten, last, merge, starts, utility;
var __extends = function(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
@@ -11,7 +11,8 @@
return -1;
};
Scope = require('./scope').Scope;
_ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, merge = _ref.merge, del = _ref.del, starts = _ref.starts, ends = _ref.ends, last = _ref.last;
_ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, extend = _ref.extend, merge = _ref.merge, del = _ref.del, starts = _ref.starts, ends = _ref.ends, last = _ref.last;
exports.extend = extend;
YES = function() {
return true;
};
@@ -57,7 +58,7 @@
}
}).call(this);
if ((options != null) ? options.precompile : undefined) {
for (i = 0, _len = pair.length; i < _len; i++) {
for (i = 0, _len = pair.length; i < _len; ++i) {
node = pair[i];
(pair[i] = node.compile(o));
}
@@ -68,6 +69,16 @@
this.parenthetical = true;
return this.compile(o);
};
Base.prototype.compileLoopReference = function(o, name) {
var src, tmp;
src = tmp = this.compile(o);
if (!(NUMBER.test(src) || IDENTIFIER.test(src) && o.scope.check(src, {
immediate: true
}))) {
src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src;
}
return [src, tmp];
};
Base.prototype.idt = function(tabs) {
return (this.tab || '') + Array((tabs || 0) + 1).join(TAB);
};
@@ -103,7 +114,7 @@
idt || (idt = '');
children = (function() {
_result = [];
for (_i = 0, _len = (_ref2 = this.collectChildren()).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.collectChildren()).length; _i < _len; ++_i) {
child = _ref2[_i];
_result.push(child.toString(idt + TAB));
}
@@ -117,10 +128,10 @@
if (!this.children) {
return;
}
for (_i = 0, _len = (_ref2 = this.children).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.children).length; _i < _len; ++_i) {
attr = _ref2[_i];
if (this[attr]) {
for (_j = 0, _len2 = (_ref3 = flatten([this[attr]])).length; _j < _len2; _j++) {
for (_j = 0, _len2 = (_ref3 = flatten([this[attr]])).length; _j < _len2; ++_j) {
child = _ref3[_j];
if (func(child) === false) {
return;
@@ -205,7 +216,7 @@
var _i, _len, _ref2, _result, node;
return (function() {
_result = [];
for (_i = 0, _len = (_ref2 = this.expressions).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.expressions).length; _i < _len; ++_i) {
node = _ref2[_i];
_result.push(this.compileExpression(node, merge(o)));
}
@@ -348,15 +359,12 @@
Value.prototype.isObject = function() {
return this.base instanceof ObjectLiteral && !this.properties.length;
};
Value.prototype.isSplice = function() {
return last(this.properties) instanceof Slice;
};
Value.prototype.isComplex = function() {
return this.base.isComplex() || this.hasProperties();
};
Value.prototype.isAtomic = function() {
var _i, _len, _ref2, node;
for (_i = 0, _len = (_ref2 = this.properties.concat(this.base)).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.properties.concat(this.base)).length; _i < _len; ++_i) {
node = _ref2[_i];
if (node.soakNode || node instanceof Call) {
return false;
@@ -417,7 +425,7 @@
if (props[0] instanceof Accessor && this.isSimpleNumber()) {
code = "(" + code + ")";
}
for (_i = 0, _len = props.length; _i < _len; _i++) {
for (_i = 0, _len = props.length; _i < _len; ++_i) {
prop = props[_i];
(code += prop.compile(o));
}
@@ -429,7 +437,7 @@
Array.prototype.push.apply(ifn.body.properties, this.properties);
return ifn;
}
for (i = 0, _len = (_ref2 = this.properties).length; i < _len; i++) {
for (i = 0, _len = (_ref2 = this.properties).length; i < _len; ++i) {
prop = _ref2[i];
if (prop.soakNode) {
prop.soakNode = false;
@@ -544,7 +552,7 @@
break;
}
}
for (_i = 0, _len = (_ref3 = list.reverse()).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref3 = list.reverse()).length; _i < _len; ++_i) {
call = _ref3[_i];
if (ifn) {
if (call.variable instanceof Call) {
@@ -563,7 +571,7 @@
return ifn.compile(o);
}
((_ref2 = this.variable) != null) ? _ref2.tags.front = this.tags.front : undefined;
for (_i = 0, _len = (_ref3 = this.args).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref3 = this.args).length; _i < _len; ++_i) {
arg = _ref3[_i];
if (arg instanceof Splat) {
return this.compileSplat(o);
@@ -571,7 +579,7 @@
}
args = (function() {
_result = [];
for (_j = 0, _len2 = (_ref4 = this.args).length; _j < _len2; _j++) {
for (_j = 0, _len2 = (_ref4 = this.args).length; _j < _len2; ++_j) {
arg = _ref4[_j];
_result.push(arg.compileBare(o));
}
@@ -663,117 +671,6 @@
};
return Index;
})();
exports.Range = (function() {
Range = (function() {
function Range(_arg, _arg2, tag) {
this.to = _arg2;
this.from = _arg;
Range.__super__.constructor.call(this);
this.exclusive = tag === 'exclusive';
this.equals = this.exclusive ? '' : '=';
return this;
};
return Range;
})();
__extends(Range, Base);
Range.prototype.children = ['from', 'to'];
Range.prototype.compileVariables = function(o) {
var _ref2, _ref3, _ref4, parts;
o = merge(o, {
top: true
});
_ref2 = this.from.compileReference(o, {
precompile: true
}), this.from = _ref2[0], this.fromVar = _ref2[1];
_ref3 = this.to.compileReference(o, {
precompile: true
}), this.to = _ref3[0], this.toVar = _ref3[1];
_ref4 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref4[0], this.toNum = _ref4[1];
parts = [];
if (this.from !== this.fromVar) {
parts.push(this.from);
}
return this.to !== this.toVar ? parts.push(this.to) : undefined;
};
Range.prototype.compileNode = function(o) {
var compare, idx, incr, intro, step, stepPart, vars;
this.compileVariables(o);
if (!o.index) {
return this.compileArray(o);
}
if (this.fromNum && this.toNum) {
return this.compileSimple(o);
}
idx = del(o, 'index');
step = del(o, 'step');
vars = ("" + idx + " = " + this.from) + (this.to !== this.toVar ? ", " + this.to : '');
intro = "(" + this.fromVar + " <= " + this.toVar + " ? " + idx;
compare = "" + intro + " <" + this.equals + " " + this.toVar + " : " + idx + " >" + this.equals + " " + this.toVar + ")";
stepPart = step ? step.compile(o) : '1';
incr = step ? "" + idx + " += " + stepPart : "" + intro + " += " + stepPart + " : " + idx + " -= " + stepPart + ")";
return "" + vars + "; " + compare + "; " + incr;
};
Range.prototype.compileSimple = function(o) {
var _ref2, from, idx, step, to;
_ref2 = [+this.fromNum, +this.toNum], from = _ref2[0], to = _ref2[1];
idx = del(o, 'index');
step = del(o, 'step');
step && (step = "" + idx + " += " + (step.compile(o)));
return from <= to ? "" + idx + " = " + from + "; " + idx + " <" + this.equals + " " + to + "; " + (step || ("" + idx + "++")) : "" + idx + " = " + from + "; " + idx + " >" + this.equals + " " + to + "; " + (step || ("" + idx + "--"));
};
Range.prototype.compileArray = function(o) {
var _i, _ref2, _ref3, _result, body, clause, i, idt, post, pre, range, result, vars;
if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
range = (function() {
_result = [];
for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i += 1 : _i -= 1){ _result.push(_i); }
return _result;
}).call(this);
if (this.exclusive) {
range.pop();
}
return "[" + (range.join(', ')) + "]";
}
idt = this.idt(1);
i = o.scope.freeVariable('i');
result = o.scope.freeVariable('result');
pre = "\n" + idt + result + " = [];";
if (this.fromNum && this.toNum) {
o.index = i;
body = this.compileSimple(o);
} else {
vars = ("" + i + " = " + this.from) + (this.to !== this.toVar ? ", " + this.to : '');
clause = "" + this.fromVar + " <= " + this.toVar + " ?";
body = "var " + vars + "; " + clause + " " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + clause + " " + i + " += 1 : " + i + " -= 1";
}
post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;
return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).call(this)";
};
return Range;
})();
exports.Slice = (function() {
Slice = (function() {
function Slice(_arg) {
this.range = _arg;
Slice.__super__.constructor.call(this);
return this;
};
return Slice;
})();
__extends(Slice, Base);
Slice.prototype.children = ['range'];
Slice.prototype.compileNode = function(o) {
var from, to;
from = this.range.from ? this.range.from.compile(o) : '0';
to = this.range.to ? this.range.to.compile(o) : '';
to += !to || this.range.exclusive ? '' : ' + 1';
if (to) {
to = ', ' + to;
}
return ".slice(" + from + to + ")";
};
return Slice;
})();
exports.ObjectLiteral = (function() {
ObjectLiteral = (function() {
function ObjectLiteral(props) {
@@ -791,7 +688,7 @@
o.indent = this.idt(1);
nonComments = (function() {
_result = [];
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; ++_i) {
prop = _ref2[_i];
if (!(prop instanceof Comment)) {
_result.push(prop);
@@ -802,7 +699,7 @@
lastNoncom = last(nonComments);
props = (function() {
_result = [];
for (i = 0, _len = (_ref2 = this.properties).length; i < _len; i++) {
for (i = 0, _len = (_ref2 = this.properties).length; i < _len; ++i) {
prop = _ref2[i];
_result.push((function() {
join = i === this.properties.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
@@ -823,7 +720,7 @@
};
ObjectLiteral.prototype.assigns = function(name) {
var _i, _len, _ref2, prop;
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; ++_i) {
prop = _ref2[_i];
if (prop.assigns(name)) {
return true;
@@ -850,14 +747,14 @@
ArrayLiteral.prototype.compileNode = function(o) {
var _i, _len, _len2, _ref2, _ref3, code, i, obj, objects;
o.indent = this.idt(1);
for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; ++_i) {
obj = _ref2[_i];
if (obj instanceof Splat) {
return this.compileSplatLiteral(o);
}
}
objects = [];
for (i = 0, _len2 = (_ref3 = this.objects).length; i < _len2; i++) {
for (i = 0, _len2 = (_ref3 = this.objects).length; i < _len2; ++i) {
obj = _ref3[i];
code = obj.compileBare(o);
objects.push(obj instanceof Comment ? "\n" + code + "\n" + o.indent : i === this.objects.length - 1 ? code : code + ', ');
@@ -867,7 +764,7 @@
};
ArrayLiteral.prototype.assigns = function(name) {
var _i, _len, _ref2, obj;
for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; ++_i) {
obj = _ref2[_i];
if (obj.assigns(name)) {
return true;
@@ -914,7 +811,7 @@
} else {
constructor = new Code([], new Expressions([new Return(new Literal('this'))]));
}
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; ++_i) {
prop = _ref2[_i];
pvar = prop.variable, func = prop.value;
if (pvar && pvar.base.value === 'constructor') {
@@ -996,9 +893,6 @@
if (this.variable.isArray() || this.variable.isObject()) {
return this.compilePatternMatch(o);
}
if (this.variable.isSplice()) {
return this.compileSplice(o);
}
if (ifn = If.unfoldSoak(o, this, 'variable')) {
delete o.top;
return ifn.compile(o);
@@ -1058,7 +952,7 @@
assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + valVar);
valVar = ref;
}
for (i = 0, _len = objects.length; i < _len; i++) {
for (i = 0, _len = objects.length; i < _len; ++i) {
obj = objects[i];
idx = i;
if (isObject) {
@@ -1089,17 +983,6 @@
code = assigns.join(', ');
return top || this.parenthetical ? code : "(" + code + ")";
};
Assign.prototype.compileSplice = function(o) {
var from, name, plus, range, ref, to, val;
range = this.variable.properties.pop().range;
name = this.variable.compile(o);
plus = range.exclusive ? '' : ' + 1';
from = range.from ? range.from.compile(o) : '0';
to = range.to ? range.to.compile(o) + ' - ' + from + plus : "" + name + ".length";
ref = o.scope.freeVariable('ref');
val = this.value.compile(o);
return "([].splice.apply(" + name + ", [" + from + ", " + to + "].concat(" + ref + " = " + val + ")), " + ref + ")";
};
Assign.prototype.compileConditional = function(o) {
var _ref2, left, rite;
_ref2 = this.variable.cacheReference(o), left = _ref2[0], rite = _ref2[1];
@@ -1140,7 +1023,7 @@
delete o.globals;
splat = undefined;
params = [];
for (i = 0, _len = (_ref2 = this.params).length; i < _len; i++) {
for (i = 0, _len = (_ref2 = this.params).length; i < _len; ++i) {
param = _ref2[i];
if (splat) {
if (param.attach) {
@@ -1168,7 +1051,7 @@
o.scope.startLevel();
params = (function() {
_result = [];
for (_i = 0, _len2 = params.length; _i < _len2; _i++) {
for (_i = 0, _len2 = params.length; _i < _len2; ++_i) {
param = params[_i];
_result.push(param.compile(o));
}
@@ -1177,7 +1060,7 @@
if (!(empty || this.noReturn)) {
this.body.makeReturn();
}
for (_i = 0, _len2 = params.length; _i < _len2; _i++) {
for (_i = 0, _len2 = params.length; _i < _len2; ++_i) {
param = params[_i];
o.scope.parameter(param);
}
@@ -1258,7 +1141,7 @@
variadic = o.scope.freeVariable('result');
o.scope.assign(variadic, len + ' >= ' + this.arglength);
end = this.trailings.length ? ", " + len + " - " + this.trailings.length : undefined;
for (idx = 0, _len = (_ref2 = this.trailings).length; idx < _len; idx++) {
for (idx = 0, _len = (_ref2 = this.trailings).length; idx < _len; ++idx) {
trailing = _ref2[idx];
if (trailing.attach) {
assign = trailing.assign;
@@ -1280,7 +1163,7 @@
var _len, arg, args, code, end, i, prev;
args = [];
end = -1;
for (i = 0, _len = list.length; i < _len; i++) {
for (i = 0, _len = list.length; i < _len; ++i) {
arg = list[i];
code = arg.compile(o);
prev = args[end];
@@ -1480,7 +1363,7 @@
_ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
tests = (function() {
_result = [];
for (i = 0, _len = (_ref4 = this.array.base.objects).length; i < _len; i++) {
for (i = 0, _len = (_ref4 = this.array.base.objects).length; i < _len; ++i) {
item = _ref4[i];
_result.push((i ? ref : sub) + cmp + item.compile(o));
}
@@ -1616,22 +1499,16 @@
})();
exports.For = (function() {
For = (function() {
function For(_arg, source, _arg2, _arg3) {
var _ref2;
this.index = _arg3;
this.name = _arg2;
function For(_arg, head) {
this.body = _arg;
For.__super__.constructor.call(this);
this.source = source.source, this.guard = source.guard, this.step = source.step;
this.raw = !!source.raw;
this.object = !!source.object;
if (this.object) {
_ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1];
}
if (this.index instanceof Value) {
if (head.index instanceof Value) {
throw SyntaxError('index cannot be a pattern matching expression');
}
this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
For.__super__.constructor.call(this);
extend(this, head);
if (!this.object) {
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');
@@ -1642,7 +1519,7 @@
return For;
})();
__extends(For, Base);
For.prototype.children = ['body', 'source', 'guard'];
For.prototype.children = ['body', 'source', 'guard', 'step', 'from', 'to'];
For.prototype.topSensitive = YES;
For.prototype.isStatement = YES;
For.prototype.makeReturn = function() {
@@ -1659,16 +1536,16 @@
return '';
};
For.prototype.compileNode = function(o) {
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lastLine, lvar, name, namePart, nvar, ref, resultPart, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, unstepPart, varPart, vars;
topLevel = del(o, 'top') && !this.returns;
source = this.range ? this.source.base : this.source;
codeInBody = !this.body.containsPureStatement() && this.body.contains(function(node) {
return node instanceof Code;
});
var _ref2, _ref3, _ref4, _ref5, _ref6, body, cond, forPart, guardPart, idt, index, ivar, lvar, name, namePart, pvar, resultDef, resultRet, rvar, scope, sourcePart, step, svar, tail, top, tvar, varPart, vars;
scope = o.scope;
name = this.name && this.name.compile(o);
index = this.index && this.index.compile(o);
if (name && !this.pattern && (this.range || !codeInBody)) {
top = del(o, 'top') && !this.returns;
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 = '';
body = Expressions.wrap([this.body]);
idt = this.idt(1);
if (name) {
scope.find(name, {
immediate: true
});
@@ -1678,101 +1555,73 @@
immediate: true
});
}
if (!topLevel) {
rvar = scope.freeVariable('result');
if (this.step) {
_ref4 = this.step.compileLoopReference(o, 'step'), step = _ref4[0], pvar = _ref4[1];
}
ivar = this.range ? name : index;
if (!ivar || codeInBody) {
ivar = scope.freeVariable('i');
}
if (name && !this.range && codeInBody) {
nvar = scope.freeVariable('i');
}
varPart = '';
guardPart = '';
unstepPart = '';
body = Expressions.wrap([this.body]);
idt1 = this.idt(1);
if (this.range) {
forPart = source.compile(merge(o, {
index: ivar,
step: this.step
}));
if (this.from) {
_ref5 = this.to.compileLoopReference(o, 'to'), tail = _ref5[0], tvar = _ref5[1];
vars = "" + ivar + " = " + (this.from.compile(o));
if (tail !== tvar) {
vars += ", " + tail;
}
cond = +pvar ? "" + ivar + " " + (pvar < 0 ? '>' : '<') + "= " + tvar : "" + pvar + " < 0 ? " + ivar + " >= " + tvar + " : " + ivar + " <= " + tvar;
} else {
svar = sourcePart = this.source.compile(o);
if ((name || !this.raw) && !(IDENTIFIER.test(svar) && scope.check(svar, {
immediate: true
}))) {
sourcePart = "" + (ref = scope.freeVariable('ref')) + " = " + svar;
if (!this.object) {
if (name || !this.raw) {
_ref6 = this.source.compileLoopReference(o, 'ref'), sourcePart = _ref6[0], svar = _ref6[1];
if (!(sourcePart === svar || this.object)) {
sourcePart = "(" + sourcePart + ")";
}
svar = ref;
} else {
sourcePart = svar = this.source.compile(o);
}
namePart = this.pattern ? new Assign(this.name, new Literal("" + svar + "[" + ivar + "]")).compile(merge(o, {
top: true
})) : name ? "" + name + " = " + svar + "[" + ivar + "]" : undefined;
if (!this.object) {
lvar = scope.freeVariable('len');
stepPart = this.step ? "" + ivar + " += " + (this.step.compile(o)) : "" + ivar + "++";
forPart = "" + ivar + " = 0, " + lvar + " = " + sourcePart + ".length; " + ivar + " < " + lvar + "; " + stepPart;
if (0 > pvar && (pvar | 0) === +pvar) {
vars = "" + ivar + " = " + sourcePart + ".length - 1";
cond = "" + ivar + " >= 0";
} else {
lvar = scope.freeVariable('len');
vars = "" + ivar + " = 0, " + lvar + " = " + sourcePart + ".length";
cond = "" + ivar + " < " + lvar;
}
}
}
resultPart = rvar ? "" + this.tab + rvar + " = [];\n" : '';
returnResult = this.compileReturnValue(rvar, o);
if (!topLevel) {
if (this.object) {
forPart = "" + ivar + " in " + sourcePart;
guardPart = !this.raw && ("" + idt + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;\n");
} else {
if (step !== pvar) {
vars += ", " + step;
}
forPart = ("" + vars + "; " + cond + "; ") + (function() {
switch (+pvar) {
case 1:
return '++' + ivar;
case -1:
return '--' + ivar;
default:
return ivar + (pvar < 0 ? ' -= ' + pvar.slice(1) : ' += ' + pvar);
}
})();
}
if (!top) {
rvar = scope.freeVariable('result');
resultDef = "" + this.tab + rvar + " = [];\n";
resultRet = this.compileReturnValue(rvar, o);
body = Push.wrap(rvar, body);
}
if (this.guard) {
body = Expressions.wrap([new If(this.guard, body)]);
}
if (codeInBody) {
if (this.range) {
body.unshift(new Literal("var " + name + " = " + ivar));
}
if (namePart) {
body.unshift(new Literal("var " + namePart));
}
if (index) {
body.unshift(new Literal("var " + index + " = " + ivar));
}
lastLine = body.expressions.pop();
if (index) {
body.push(new Assign(new Literal(ivar), new Literal(index)));
}
if (nvar) {
body.push(new Assign(new Literal(nvar), new Literal(name)));
}
body.push(lastLine);
o.indent = this.idt(1);
body = Expressions.wrap([new Literal(body.compile(o))]);
if (index) {
body.push(new Assign(this.index, new Literal(ivar)));
}
if (name) {
body.push(new Assign(this.name, new Literal(nvar || ivar)));
}
} else {
if (namePart) {
varPart = "" + idt1 + namePart + ";\n";
}
if (forPart && name === ivar) {
unstepPart = this.step ? "" + name + " -= " + (this.step.compile(o)) + ";" : "" + name + "--;";
unstepPart = ("\n" + this.tab) + unstepPart;
}
if (namePart) {
varPart = "" + idt + namePart + ";\n";
}
if (this.object) {
forPart = "" + ivar + " in " + sourcePart;
if (!this.raw) {
guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;";
}
}
body = body.compile(merge(o, {
indent: idt1,
return "" + (resultDef || '') + this.tab + "for (" + forPart + ") {\n" + (guardPart || '') + varPart + (body.compile(merge(o, {
indent: idt,
top: true
}));
vars = this.range ? name : "" + name + ", " + ivar;
return "" + resultPart + this.tab + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + this.tab + "}" + unstepPart + returnResult;
}))) + "\n" + this.tab + "}" + (resultRet || '');
};
return For;
})();
@@ -1792,7 +1641,7 @@
Switch.prototype.isStatement = YES;
Switch.prototype.makeReturn = function() {
var _i, _len, _ref2, pair;
for (_i = 0, _len = (_ref2 = this.cases).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.cases).length; _i < _len; ++_i) {
pair = _ref2[_i];
pair[1].makeReturn();
}
@@ -1807,9 +1656,9 @@
idt2 = o.indent = this.idt(2);
o.top = true;
code = "" + this.tab + "switch (" + ((((_ref2 = this.subject) != null) ? _ref2.compile(o) : undefined) || true) + ") {";
for (_i = 0, _len = (_ref3 = this.cases).length; _i < _len; _i++) {
for (_i = 0, _len = (_ref3 = this.cases).length; _i < _len; ++_i) {
_ref4 = _ref3[_i], conditions = _ref4[0], block = _ref4[1];
for (_j = 0, _len2 = (_ref5 = flatten([conditions])).length; _j < _len2; _j++) {
for (_j = 0, _len2 = (_ref5 = flatten([conditions])).length; _j < _len2; ++_j) {
condition = _ref5[_j];
if (!this.subject) {
condition = condition.invert().invert();
@@ -1968,7 +1817,7 @@
TAB = ' ';
TRAILING_WHITESPACE = /[ \t]+$/gm;
IDENTIFIER = /^[$A-Za-z_][$\w]*$/;
NUMBER = /^0x[\da-f]+$|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?$/i;
NUMBER = /^-?(?:0x[\da-f]+|(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?)$/i;
SIMPLENUM = /^[+-]?\d+$/;
IS_STRING = /^['"]/;
utility = function(name) {