mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
fixes #1910: loop index should be mutable within a loop iteration and immutable between loop iterations
This commit is contained in:
parent
0f1dbffa40
commit
fc0a169a9a
18 changed files with 183 additions and 123 deletions
|
@ -42,7 +42,7 @@
|
|||
coffees = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = scripts.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = scripts.length; _i < _len; ++_i) {
|
||||
s = scripts[_i];
|
||||
if (s.type === 'text/coffeescript') _results.push(s);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
}
|
||||
_ref = options.arguments;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; ++_i) {
|
||||
arg = _ref[_i];
|
||||
_results.push(invoke(arg));
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@
|
|||
};
|
||||
_module.filename = sandbox.__filename;
|
||||
_ref3 = Object.getOwnPropertyNames(require);
|
||||
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref3.length; _i < _len; ++_i) {
|
||||
r = _ref3[_i];
|
||||
if (r !== 'paths') _require[r] = require[r];
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
process.argv[0] = 'coffee';
|
||||
process.execPath = require.main.filename;
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = sources.length; _i < _len; ++_i) {
|
||||
source = sources[_i];
|
||||
_results.push(compilePath(source, true, path.normalize(source)));
|
||||
}
|
||||
|
@ -96,7 +96,7 @@
|
|||
return null;
|
||||
}))), _ref2;
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = files.length; _i < _len; ++_i) {
|
||||
file = files[_i];
|
||||
_results.push(compilePath(file, false, base));
|
||||
}
|
||||
|
@ -187,7 +187,7 @@
|
|||
realFilename = module.filename;
|
||||
module.filename = '.';
|
||||
_ref2 = opts.require;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
req = _ref2[_i];
|
||||
require(req);
|
||||
}
|
||||
|
@ -267,7 +267,7 @@
|
|||
return path.join(source, file);
|
||||
});
|
||||
_results = [];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = files.length; _i < _len; ++_i) {
|
||||
file = files[_i];
|
||||
if (!(!notSources[file])) continue;
|
||||
if (sources.some(function(s) {
|
||||
|
@ -294,13 +294,13 @@
|
|||
toRemove = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = sources.length; _i < _len; ++_i) {
|
||||
file = sources[_i];
|
||||
if (file.indexOf(source) >= 0) _results.push(file);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
for (_i = 0, _len = toRemove.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = toRemove.length; _i < _len; ++_i) {
|
||||
file = toRemove[_i];
|
||||
removeSource(file, base, true);
|
||||
}
|
||||
|
@ -388,7 +388,7 @@
|
|||
strings = (function() {
|
||||
var _i, _len, _ref2, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = tokens.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = tokens.length; _i < _len; ++_i) {
|
||||
token = tokens[_i];
|
||||
_ref2 = [token[0], token[1].toString().replace(/\n/, '\\n')], tag = _ref2[0], value = _ref2[1];
|
||||
_results.push("[" + tag + " " + value + "]");
|
||||
|
@ -399,14 +399,14 @@
|
|||
};
|
||||
|
||||
parseOptions = function() {
|
||||
var i, o, source, _len;
|
||||
var i, o, source, _i, _len;
|
||||
optionParser = new optparse.OptionParser(SWITCHES, BANNER);
|
||||
o = opts = optionParser.parse(process.argv.slice(2));
|
||||
o.compile || (o.compile = !!o.output);
|
||||
o.run = !(o.compile || o.print || o.lint);
|
||||
o.print = !!(o.print || (o.eval || o.stdio && o.compile));
|
||||
sources = o.arguments;
|
||||
for (i = 0, _len = sources.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = sources.length; _i < _len; i = ++_i) {
|
||||
source = sources[i];
|
||||
sourceCode[i] = null;
|
||||
}
|
||||
|
|
|
@ -568,10 +568,10 @@
|
|||
grammar[name] = (function() {
|
||||
var _i, _j, _len, _len2, _ref, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = alternatives.length; _i < _len; ++_i) {
|
||||
alt = alternatives[_i];
|
||||
_ref = alt[0].split(' ');
|
||||
for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) {
|
||||
for (_j = 0, _len2 = _ref.length; _j < _len2; ++_j) {
|
||||
token = _ref[_j];
|
||||
if (!grammar[token]) tokens.push(token);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
exports.compact = function(array) {
|
||||
var item, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = array.length; _i < _len; ++_i) {
|
||||
item = array[_i];
|
||||
if (item) _results.push(item);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@
|
|||
exports.flatten = flatten = function(array) {
|
||||
var element, flattened, _i, _len;
|
||||
flattened = [];
|
||||
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = array.length; _i < _len; ++_i) {
|
||||
element = array[_i];
|
||||
if (element instanceof Array) {
|
||||
flattened = flattened.concat(flatten(element));
|
||||
|
|
|
@ -222,7 +222,7 @@
|
|||
_ref3 = this.interpolateString(body, {
|
||||
regex: true
|
||||
});
|
||||
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref3.length; _i < _len; ++_i) {
|
||||
_ref4 = _ref3[_i], tag = _ref4[0], value = _ref4[1];
|
||||
if (tag === 'TOKENS') {
|
||||
tokens.push.apply(tokens, value);
|
||||
|
@ -451,12 +451,17 @@
|
|||
};
|
||||
|
||||
Lexer.prototype.balancedString = function(str, end) {
|
||||
var i, letter, match, prev, stack, _ref3;
|
||||
var continueCount, i, letter, match, prev, stack, _i, _ref3;
|
||||
continueCount = 0;
|
||||
stack = [end];
|
||||
for (i = 1, _ref3 = str.length; 1 <= _ref3 ? i < _ref3 : i > _ref3; 1 <= _ref3 ? i++ : i--) {
|
||||
for (i = _i = 1, _ref3 = str.length; 1 <= _ref3 ? _i < _ref3 : _i > _ref3; i = 1 <= _ref3 ? ++_i : --_i) {
|
||||
if (continueCount) {
|
||||
--continueCount;
|
||||
continue;
|
||||
}
|
||||
switch (letter = str.charAt(i)) {
|
||||
case '\\':
|
||||
i++;
|
||||
++continueCount;
|
||||
continue;
|
||||
case end:
|
||||
stack.pop();
|
||||
|
@ -467,7 +472,7 @@
|
|||
if (end === '}' && (letter === '"' || letter === "'")) {
|
||||
stack.push(end = letter);
|
||||
} else if (end === '}' && letter === '/' && (match = HEREGEX.exec(str.slice(i)) || REGEX.exec(str.slice(i)))) {
|
||||
i += match[0].length - 1;
|
||||
continueCount += match[0].length - 1;
|
||||
} else if (end === '}' && letter === '{') {
|
||||
stack.push(end = '}');
|
||||
} else if (end === '"' && prev === '#' && letter === '{') {
|
||||
|
@ -479,7 +484,7 @@
|
|||
};
|
||||
|
||||
Lexer.prototype.interpolateString = function(str, options) {
|
||||
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _len, _ref3, _ref4, _ref5;
|
||||
var expr, heredoc, i, inner, interpolated, len, letter, nested, pi, regex, tag, tokens, value, _i, _len, _ref3, _ref4, _ref5;
|
||||
if (options == null) options = {};
|
||||
heredoc = options.heredoc, regex = options.regex;
|
||||
tokens = [];
|
||||
|
@ -520,7 +525,7 @@
|
|||
if (!tokens.length) return this.token('STRING', '""');
|
||||
if (tokens[0][0] !== 'NEOSTRING') tokens.unshift(['', '']);
|
||||
if (interpolated = tokens.length > 1) this.token('(', '(');
|
||||
for (i = 0, _len = tokens.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = tokens.length; _i < _len; i = ++_i) {
|
||||
_ref4 = tokens[i], tag = _ref4[0], value = _ref4[1];
|
||||
if (i) this.token('+', '+');
|
||||
if (tag === 'TOKENS') {
|
||||
|
|
|
@ -132,11 +132,11 @@
|
|||
var attr, child, _i, _j, _len, _len2, _ref2, _ref3;
|
||||
if (!this.children) return this;
|
||||
_ref2 = this.children;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
attr = _ref2[_i];
|
||||
if (this[attr]) {
|
||||
_ref3 = flatten([this[attr]]);
|
||||
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
|
||||
for (_j = 0, _len2 = _ref3.length; _j < _len2; ++_j) {
|
||||
child = _ref3[_j];
|
||||
if (func(child) === false) return this;
|
||||
}
|
||||
|
@ -228,7 +228,7 @@
|
|||
Block.prototype.isStatement = function(o) {
|
||||
var exp, _i, _len, _ref2;
|
||||
_ref2 = this.expressions;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
exp = _ref2[_i];
|
||||
if (exp.isStatement(o)) return true;
|
||||
}
|
||||
|
@ -238,7 +238,7 @@
|
|||
Block.prototype.jumps = function(o) {
|
||||
var exp, _i, _len, _ref2;
|
||||
_ref2 = this.expressions;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
exp = _ref2[_i];
|
||||
if (exp.jumps(o)) return exp;
|
||||
}
|
||||
|
@ -275,7 +275,7 @@
|
|||
top = o.level === LEVEL_TOP;
|
||||
codes = [];
|
||||
_ref2 = this.expressions;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
node = _ref2[_i];
|
||||
node = node.unwrapAll();
|
||||
node = node.unfoldSoak(o) || node;
|
||||
|
@ -313,10 +313,10 @@
|
|||
prelude = "";
|
||||
if (!o.bare) {
|
||||
preludeExps = (function() {
|
||||
var _len, _ref2, _results;
|
||||
var _i, _len, _ref2, _results;
|
||||
_ref2 = this.expressions;
|
||||
_results = [];
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
||||
exp = _ref2[i];
|
||||
if (!(exp.unwrap() instanceof Comment)) break;
|
||||
_results.push(exp);
|
||||
|
@ -338,10 +338,10 @@
|
|||
};
|
||||
|
||||
Block.prototype.compileWithDeclarations = function(o) {
|
||||
var assigns, code, declars, exp, i, post, rest, scope, spaced, _len, _ref2, _ref3, _ref4;
|
||||
var assigns, code, declars, exp, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;
|
||||
code = post = '';
|
||||
_ref2 = this.expressions;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
||||
exp = _ref2[i];
|
||||
exp = exp.unwrap();
|
||||
if (!(exp instanceof Comment || exp instanceof Literal)) break;
|
||||
|
@ -521,7 +521,7 @@
|
|||
Value.prototype.isAtomic = function() {
|
||||
var node, _i, _len, _ref2;
|
||||
_ref2 = this.properties.concat(this.base);
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
node = _ref2[_i];
|
||||
if (node.soak || node instanceof Call) return false;
|
||||
}
|
||||
|
@ -585,7 +585,7 @@
|
|||
if ((this.base instanceof Parens || props.length) && SIMPLENUM.test(code)) {
|
||||
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);
|
||||
}
|
||||
|
@ -597,13 +597,13 @@
|
|||
_this = this;
|
||||
if (this.unfoldedSoak != null) return this.unfoldedSoak;
|
||||
result = (function() {
|
||||
var fst, i, ifn, prop, ref, snd, _len, _ref2;
|
||||
var fst, i, ifn, prop, ref, snd, _i, _len, _ref2;
|
||||
if (ifn = _this.base.unfoldSoak(o)) {
|
||||
Array.prototype.push.apply(ifn.body.properties, _this.properties);
|
||||
return ifn;
|
||||
}
|
||||
_ref2 = _this.properties;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
||||
prop = _ref2[i];
|
||||
if (!prop.soak) continue;
|
||||
prop.soak = false;
|
||||
|
@ -727,7 +727,7 @@
|
|||
if (!((call = call.variable.base) instanceof Call)) break;
|
||||
}
|
||||
_ref3 = list.reverse();
|
||||
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref3.length; _i < _len; ++_i) {
|
||||
call = _ref3[_i];
|
||||
if (ifn) {
|
||||
if (call.variable instanceof Call) {
|
||||
|
@ -744,7 +744,7 @@
|
|||
Call.prototype.filterImplicitObjects = function(list) {
|
||||
var node, nodes, obj, prop, properties, _i, _j, _len, _len2, _ref2;
|
||||
nodes = [];
|
||||
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = list.length; _i < _len; ++_i) {
|
||||
node = list[_i];
|
||||
if (!((typeof node.isObject === "function" ? node.isObject() : void 0) && node.base.generated)) {
|
||||
nodes.push(node);
|
||||
|
@ -752,7 +752,7 @@
|
|||
}
|
||||
obj = null;
|
||||
_ref2 = node.base.properties;
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; ++_j) {
|
||||
prop = _ref2[_j];
|
||||
if (prop instanceof Assign || prop instanceof Comment) {
|
||||
if (!obj) nodes.push(obj = new Obj(properties = [], true));
|
||||
|
@ -776,7 +776,7 @@
|
|||
args = ((function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = args.length; _i < _len; ++_i) {
|
||||
arg = args[_i];
|
||||
_results.push(arg.compile(o, LEVEL_LIST));
|
||||
}
|
||||
|
@ -928,17 +928,20 @@
|
|||
};
|
||||
|
||||
Range.prototype.compileNode = function(o) {
|
||||
var cond, condPart, from, gt, idx, known, lt, stepPart, to, varPart, _ref2, _ref3;
|
||||
var cond, condPart, from, gt, idx, idxName, known, lt, stepPart, to, varPart, _ref2, _ref3;
|
||||
if (!this.fromVar) this.compileVariables(o);
|
||||
if (!o.index) return this.compileArray(o);
|
||||
known = this.fromNum && this.toNum;
|
||||
idx = del(o, 'index');
|
||||
idxName = del(o, 'name');
|
||||
varPart = "" + idx + " = " + this.fromC;
|
||||
if (this.toC !== this.toVar) varPart += ", " + this.toC;
|
||||
if (this.step !== this.stepVar) varPart += ", " + this.step;
|
||||
if (idxName && idxName !== idx) varPart = "" + idxName + " = " + varPart;
|
||||
_ref2 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref2[0], gt = _ref2[1];
|
||||
condPart = this.stepNum ? +this.stepNum > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref3 = [+this.fromNum, +this.toNum], from = _ref3[0], to = _ref3[1], _ref3), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);
|
||||
stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? from <= to ? "" + idx + "++" : "" + idx + "--" : "" + cond + " ? " + idx + "++ : " + idx + "--";
|
||||
stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? from <= to ? "++" + idx : "--" + idx : "" + cond + " ? ++" + idx + " : --" + idx;
|
||||
if (idxName && idxName !== idx) stepPart = "" + idxName + " = " + stepPart;
|
||||
return "" + varPart + "; " + condPart + "; " + stepPart;
|
||||
};
|
||||
|
||||
|
@ -1025,7 +1028,7 @@
|
|||
props = this.properties;
|
||||
if (!props.length) return (this.front ? '({})' : '{}');
|
||||
if (this.generated) {
|
||||
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = props.length; _i < _len; ++_i) {
|
||||
node = props[_i];
|
||||
if (node instanceof Value) {
|
||||
throw new Error('cannot have an implicit value in an implicit object');
|
||||
|
@ -1035,9 +1038,9 @@
|
|||
idt = o.indent += TAB;
|
||||
lastNoncom = this.lastNonComment(this.properties);
|
||||
props = (function() {
|
||||
var _len2, _results;
|
||||
var _j, _len2, _results;
|
||||
_results = [];
|
||||
for (i = 0, _len2 = props.length; i < _len2; i++) {
|
||||
for (i = _j = 0, _len2 = props.length; _j < _len2; i = ++_j) {
|
||||
prop = props[i];
|
||||
join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
|
||||
indent = prop instanceof Comment ? '' : idt;
|
||||
|
@ -1064,7 +1067,7 @@
|
|||
Obj.prototype.assigns = function(name) {
|
||||
var prop, _i, _len, _ref2;
|
||||
_ref2 = this.properties;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
prop = _ref2[_i];
|
||||
if (prop.assigns(name)) return true;
|
||||
}
|
||||
|
@ -1098,7 +1101,7 @@
|
|||
code = ((function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = objs.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = objs.length; _i < _len; ++_i) {
|
||||
obj = objs[_i];
|
||||
_results.push(obj.compile(o, LEVEL_LIST));
|
||||
}
|
||||
|
@ -1114,7 +1117,7 @@
|
|||
Arr.prototype.assigns = function(name) {
|
||||
var obj, _i, _len, _ref2;
|
||||
_ref2 = this.objects;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
obj = _ref2[_i];
|
||||
if (obj.assigns(name)) return true;
|
||||
}
|
||||
|
@ -1165,7 +1168,7 @@
|
|||
if (this.boundFuncs.length) {
|
||||
_ref2 = this.boundFuncs;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
bvar = _ref2[_i];
|
||||
lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o);
|
||||
_results.push(this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)")));
|
||||
|
@ -1221,11 +1224,11 @@
|
|||
Class.prototype.walkBody = function(name, o) {
|
||||
var _this = this;
|
||||
return this.traverseChildren(false, function(child) {
|
||||
var exps, i, node, _len, _ref2;
|
||||
var exps, i, node, _i, _len, _ref2;
|
||||
if (child instanceof Class) return false;
|
||||
if (child instanceof Block) {
|
||||
_ref2 = exps = child.expressions;
|
||||
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
||||
node = _ref2[i];
|
||||
if (node instanceof Value && node.isObject(true)) {
|
||||
exps[i] = _this.addProperties(node, name, o);
|
||||
|
@ -1351,7 +1354,7 @@
|
|||
};
|
||||
|
||||
Assign.prototype.compilePatternMatch = function(o) {
|
||||
var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
||||
var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
||||
top = o.level === LEVEL_TOP;
|
||||
value = this.value;
|
||||
objects = this.variable.base.objects;
|
||||
|
@ -1391,7 +1394,7 @@
|
|||
assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + vvar);
|
||||
vvar = ref;
|
||||
}
|
||||
for (i = 0, _len = objects.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = objects.length; _i < _len; i = ++_i) {
|
||||
obj = objects[i];
|
||||
idx = i;
|
||||
if (isObject) {
|
||||
|
@ -1506,7 +1509,7 @@
|
|||
Code.prototype.jumps = NO;
|
||||
|
||||
Code.prototype.compileNode = function(o) {
|
||||
var code, exprs, i, idt, lit, p, param, ref, splats, v, val, vars, wasEmpty, _i, _j, _k, _len, _len2, _len3, _len4, _ref2, _ref3, _ref4, _ref5, _ref6;
|
||||
var code, exprs, i, idt, lit, p, param, ref, splats, v, val, vars, wasEmpty, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref2, _ref3, _ref4, _ref5, _ref6;
|
||||
o.scope = new Scope(o.scope, this.body, this);
|
||||
o.scope.shared = del(o, 'sharedScope');
|
||||
o.indent += TAB;
|
||||
|
@ -1514,11 +1517,11 @@
|
|||
vars = [];
|
||||
exprs = [];
|
||||
_ref2 = this.params;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
param = _ref2[_i];
|
||||
if (!param.splat) continue;
|
||||
_ref3 = this.params;
|
||||
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
|
||||
for (_j = 0, _len2 = _ref3.length; _j < _len2; ++_j) {
|
||||
p = _ref3[_j];
|
||||
if (p.name.value) o.scope.add(p.name.value, 'var', true);
|
||||
}
|
||||
|
@ -1526,7 +1529,7 @@
|
|||
var _k, _len3, _ref4, _results;
|
||||
_ref4 = this.params;
|
||||
_results = [];
|
||||
for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) {
|
||||
for (_k = 0, _len3 = _ref4.length; _k < _len3; ++_k) {
|
||||
p = _ref4[_k];
|
||||
_results.push(p.asReference(o));
|
||||
}
|
||||
|
@ -1535,7 +1538,7 @@
|
|||
break;
|
||||
}
|
||||
_ref4 = this.params;
|
||||
for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) {
|
||||
for (_k = 0, _len3 = _ref4.length; _k < _len3; ++_k) {
|
||||
param = _ref4[_k];
|
||||
if (param.isComplex()) {
|
||||
val = ref = param.asReference(o);
|
||||
|
@ -1559,7 +1562,7 @@
|
|||
(_ref5 = this.body.expressions).unshift.apply(_ref5, exprs);
|
||||
}
|
||||
if (!splats) {
|
||||
for (i = 0, _len4 = vars.length; i < _len4; i++) {
|
||||
for (i = _l = 0, _len4 = vars.length; _l < _len4; i = ++_l) {
|
||||
v = vars[i];
|
||||
o.scope.parameter(vars[i] = v.compile(o));
|
||||
}
|
||||
|
@ -1670,7 +1673,7 @@
|
|||
};
|
||||
|
||||
Splat.compileSplattedArray = function(o, list, apply) {
|
||||
var args, base, code, i, index, node, _len;
|
||||
var args, base, code, i, index, node, _i, _len;
|
||||
index = -1;
|
||||
while ((node = list[++index]) && !(node instanceof Splat)) {
|
||||
continue;
|
||||
|
@ -1682,7 +1685,7 @@
|
|||
return "" + (utility('slice')) + ".call(" + code + ")";
|
||||
}
|
||||
args = list.slice(index);
|
||||
for (i = 0, _len = args.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {
|
||||
node = args[i];
|
||||
code = node.compile(o, LEVEL_LIST);
|
||||
args[i] = node instanceof Splat ? "" + (utility('slice')) + ".call(" + code + ")" : "[" + code + "]";
|
||||
|
@ -1691,11 +1694,11 @@
|
|||
return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")");
|
||||
}
|
||||
base = (function() {
|
||||
var _i, _len2, _ref2, _results;
|
||||
var _j, _len2, _ref2, _results;
|
||||
_ref2 = list.slice(0, index);
|
||||
_results = [];
|
||||
for (_i = 0, _len2 = _ref2.length; _i < _len2; _i++) {
|
||||
node = _ref2[_i];
|
||||
for (_j = 0, _len2 = _ref2.length; _j < _len2; ++_j) {
|
||||
node = _ref2[_j];
|
||||
_results.push(node.compile(o, LEVEL_LIST));
|
||||
}
|
||||
return _results;
|
||||
|
@ -1742,7 +1745,7 @@
|
|||
var expressions, node, _i, _len;
|
||||
expressions = this.body.expressions;
|
||||
if (!expressions.length) return false;
|
||||
for (_i = 0, _len = expressions.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = expressions.length; _i < _len; ++_i) {
|
||||
node = expressions[_i];
|
||||
if (node.jumps({
|
||||
loop: true
|
||||
|
@ -1875,7 +1878,7 @@
|
|||
passedParams = [];
|
||||
func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;
|
||||
_ref2 = func.params || [];
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
param = _ref2[_i];
|
||||
if (param.value) {
|
||||
passedParams.push(param.value);
|
||||
|
@ -1968,7 +1971,7 @@
|
|||
var hasSplat, obj, _i, _len, _ref2;
|
||||
if (this.array instanceof Value && this.array.isArray()) {
|
||||
_ref2 = this.array.base.objects;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
obj = _ref2[_i];
|
||||
if (!(obj instanceof Splat)) continue;
|
||||
hasSplat = true;
|
||||
|
@ -1985,10 +1988,10 @@
|
|||
_ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1];
|
||||
_ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
|
||||
tests = (function() {
|
||||
var _len, _ref4, _results;
|
||||
var _i, _len, _ref4, _results;
|
||||
_ref4 = this.array.base.objects;
|
||||
_results = [];
|
||||
for (i = 0, _len = _ref4.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {
|
||||
item = _ref4[i];
|
||||
_results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_ACCESS));
|
||||
}
|
||||
|
@ -2198,7 +2201,7 @@
|
|||
For.prototype.children = ['body', 'source', 'guard', 'step'];
|
||||
|
||||
For.prototype.compileNode = function(o) {
|
||||
var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2;
|
||||
var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2;
|
||||
body = Block.wrap([this.body]);
|
||||
lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0;
|
||||
if (lastJumps && lastJumps instanceof Return) this.returns = false;
|
||||
|
@ -2217,7 +2220,9 @@
|
|||
});
|
||||
}
|
||||
if (this.returns) rvar = scope.freeVariable('results');
|
||||
ivar = (this.range ? name : index) || scope.freeVariable('i');
|
||||
ivar = (this.object && index) || scope.freeVariable('i');
|
||||
kvar = (this.range && name) || index || ivar;
|
||||
kvarAssign = kvar !== ivar ? "" + kvar + " = " : "";
|
||||
if (this.step && !this.range) stepvar = scope.freeVariable("step");
|
||||
if (this.pattern) name = ivar;
|
||||
varPart = '';
|
||||
|
@ -2227,6 +2232,7 @@
|
|||
if (this.range) {
|
||||
forPart = source.compile(merge(o, {
|
||||
index: ivar,
|
||||
name: name,
|
||||
step: this.step
|
||||
}));
|
||||
} else {
|
||||
|
@ -2236,12 +2242,15 @@
|
|||
svar = ref;
|
||||
}
|
||||
if (name && !this.pattern) {
|
||||
namePart = "" + name + " = " + svar + "[" + ivar + "]";
|
||||
namePart = "" + name + " = " + svar + "[" + kvar + "]";
|
||||
}
|
||||
if (!this.object) {
|
||||
lvar = scope.freeVariable('len');
|
||||
forVarPart = ("" + ivar + " = 0, " + lvar + " = " + svar + ".length") + (this.step ? ", " + stepvar + " = " + (this.step.compile(o, LEVEL_OP)) : '');
|
||||
stepPart = this.step ? "" + ivar + " += " + stepvar : "" + ivar + "++";
|
||||
forVarPart = "" + kvarAssign + ivar + " = 0, " + lvar + " = " + svar + ".length";
|
||||
if (this.step) {
|
||||
forVarPart += ", " + stepvar + " = " + (this.step.compile(o, LEVEL_OP));
|
||||
}
|
||||
stepPart = "" + kvarAssign + (this.step ? "" + ivar + " += " + stepvar : "++" + ivar);
|
||||
forPart = "" + forVarPart + "; " + ivar + " < " + lvar + "; " + stepPart;
|
||||
}
|
||||
}
|
||||
|
@ -2258,14 +2267,14 @@
|
|||
}
|
||||
}
|
||||
if (this.pattern) {
|
||||
body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + ivar + "]")));
|
||||
body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + kvar + "]")));
|
||||
}
|
||||
defPart += this.pluckDirectCall(o, body);
|
||||
if (namePart) varPart = "\n" + idt1 + namePart + ";";
|
||||
if (this.object) {
|
||||
forPart = "" + ivar + " in " + svar;
|
||||
forPart = "" + kvar + " in " + svar;
|
||||
if (this.own) {
|
||||
guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;";
|
||||
guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + kvar + ")) continue;";
|
||||
}
|
||||
}
|
||||
body = body.compile(merge(o, {
|
||||
|
@ -2276,10 +2285,10 @@
|
|||
};
|
||||
|
||||
For.prototype.pluckDirectCall = function(o, body) {
|
||||
var base, defs, expr, fn, idx, ref, val, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
||||
var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
||||
defs = '';
|
||||
_ref2 = body.expressions;
|
||||
for (idx = 0, _len = _ref2.length; idx < _len; idx++) {
|
||||
for (idx = _i = 0, _len = _ref2.length; _i < _len; idx = ++_i) {
|
||||
expr = _ref2[idx];
|
||||
expr = expr.unwrapAll();
|
||||
if (!(expr instanceof Call)) continue;
|
||||
|
@ -2325,7 +2334,7 @@
|
|||
};
|
||||
}
|
||||
_ref2 = this.cases;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
_ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1];
|
||||
if (block.jumps(o)) return block;
|
||||
}
|
||||
|
@ -2335,7 +2344,7 @@
|
|||
Switch.prototype.makeReturn = function(res) {
|
||||
var pair, _i, _len, _ref2, _ref3;
|
||||
_ref2 = this.cases;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
pair = _ref2[_i];
|
||||
pair[1].makeReturn(res);
|
||||
}
|
||||
|
@ -2347,16 +2356,16 @@
|
|||
};
|
||||
|
||||
Switch.prototype.compileNode = function(o) {
|
||||
var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _len, _len2, _ref2, _ref3, _ref4, _ref5;
|
||||
var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _j, _len, _len2, _ref2, _ref3, _ref4, _ref5;
|
||||
idt1 = o.indent + TAB;
|
||||
idt2 = o.indent = idt1 + TAB;
|
||||
code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n");
|
||||
_ref3 = this.cases;
|
||||
for (i = 0, _len = _ref3.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
|
||||
_ref4 = _ref3[i], conditions = _ref4[0], block = _ref4[1];
|
||||
_ref5 = flatten([conditions]);
|
||||
for (_i = 0, _len2 = _ref5.length; _i < _len2; _i++) {
|
||||
cond = _ref5[_i];
|
||||
for (_j = 0, _len2 = _ref5.length; _j < _len2; ++_j) {
|
||||
cond = _ref5[_j];
|
||||
if (!this.subject) cond = cond.invert();
|
||||
code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
|
||||
}
|
||||
|
|
|
@ -9,15 +9,20 @@
|
|||
}
|
||||
|
||||
OptionParser.prototype.parse = function(args) {
|
||||
var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, value, _i, _len, _len2, _ref;
|
||||
var arg, i, isOption, matchedRule, options, originalArgs, pos, rule, skippingArgument, value, _i, _j, _len, _len2, _ref;
|
||||
options = {
|
||||
arguments: [],
|
||||
literals: []
|
||||
};
|
||||
skippingArgument = false;
|
||||
originalArgs = args;
|
||||
args = normalizeArguments(args);
|
||||
for (i = 0, _len = args.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {
|
||||
arg = args[i];
|
||||
if (skippingArgument) {
|
||||
skippingArgument = false;
|
||||
continue;
|
||||
}
|
||||
if (arg === '--') {
|
||||
pos = originalArgs.indexOf('--');
|
||||
options.arguments = [originalArgs[1 + pos]];
|
||||
|
@ -27,10 +32,10 @@
|
|||
isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
|
||||
matchedRule = false;
|
||||
_ref = this.rules;
|
||||
for (_i = 0, _len2 = _ref.length; _i < _len2; _i++) {
|
||||
rule = _ref[_i];
|
||||
for (_j = 0, _len2 = _ref.length; _j < _len2; ++_j) {
|
||||
rule = _ref[_j];
|
||||
if (rule.shortFlag === arg || rule.longFlag === arg) {
|
||||
value = rule.hasArgument ? args[i += 1] : true;
|
||||
value = rule.hasArgument ? (skippingArgument = true, args[i + 1]) : true;
|
||||
options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value;
|
||||
matchedRule = true;
|
||||
break;
|
||||
|
@ -52,7 +57,7 @@
|
|||
lines = [];
|
||||
if (this.banner) lines.unshift("" + this.banner + "\n");
|
||||
_ref = this.rules;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref.length; _i < _len; ++_i) {
|
||||
rule = _ref[_i];
|
||||
spaces = 15 - rule.longFlag.length;
|
||||
spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';
|
||||
|
@ -77,7 +82,7 @@
|
|||
buildRules = function(rules) {
|
||||
var tuple, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = rules.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = rules.length; _i < _len; ++_i) {
|
||||
tuple = rules[_i];
|
||||
if (tuple.length < 3) tuple.unshift(null);
|
||||
_results.push(buildRule.apply(null, tuple));
|
||||
|
@ -104,11 +109,11 @@
|
|||
var arg, l, match, result, _i, _j, _len, _len2, _ref;
|
||||
args = args.slice(0);
|
||||
result = [];
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = args.length; _i < _len; ++_i) {
|
||||
arg = args[_i];
|
||||
if (match = arg.match(MULTI_FLAG)) {
|
||||
_ref = match[1].split('');
|
||||
for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) {
|
||||
for (_j = 0, _len2 = _ref.length; _j < _len2; ++_j) {
|
||||
l = _ref[_j];
|
||||
result.push('-' + l);
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
var _i, _len, _ref2, _results;
|
||||
_ref2 = CoffeeScript.RESERVED;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
r = _ref2[_i];
|
||||
if (r.slice(0, 2) !== '__') _results.push(r);
|
||||
}
|
||||
|
@ -106,7 +106,7 @@
|
|||
getCompletions = function(prefix, candidates) {
|
||||
var el, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = candidates.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = candidates.length; _i < _len; ++_i) {
|
||||
el = candidates[_i];
|
||||
if (el.indexOf(prefix) === 0) _results.push(el);
|
||||
}
|
||||
|
|
|
@ -50,9 +50,9 @@
|
|||
};
|
||||
|
||||
Rewriter.prototype.removeLeadingNewlines = function() {
|
||||
var i, tag, _len, _ref;
|
||||
var i, tag, _i, _len, _ref;
|
||||
_ref = this.tokens;
|
||||
for (i = 0, _len = _ref.length; i < _len; i++) {
|
||||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||||
tag = _ref[i][0];
|
||||
if (tag !== 'TERMINATOR') break;
|
||||
}
|
||||
|
@ -283,7 +283,7 @@
|
|||
|
||||
EXPRESSION_END = [];
|
||||
|
||||
for (_i = 0, _len = BALANCED_PAIRS.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = BALANCED_PAIRS.length; _i < _len; ++_i) {
|
||||
_ref = BALANCED_PAIRS[_i], left = _ref[0], rite = _ref[1];
|
||||
EXPRESSION_START.push(INVERSES[rite] = left);
|
||||
EXPRESSION_END.push(INVERSES[left] = rite);
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
Scope.prototype.type = function(name) {
|
||||
var v, _i, _len, _ref2;
|
||||
_ref2 = this.variables;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
v = _ref2[_i];
|
||||
if (v.name === name) return v.type;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@
|
|||
realVars = [];
|
||||
tempVars = [];
|
||||
_ref2 = this.variables;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
v = _ref2[_i];
|
||||
if (v.type === 'var') {
|
||||
(v.name.charAt(0) === '_' ? tempVars : realVars).push(v.name);
|
||||
|
@ -110,7 +110,7 @@
|
|||
var v, _i, _len, _ref2, _results;
|
||||
_ref2 = this.variables;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; ++_i) {
|
||||
v = _ref2[_i];
|
||||
if (v.type.assigned) _results.push("" + v.name + " = " + v.type.value);
|
||||
}
|
||||
|
|
|
@ -407,11 +407,15 @@ exports.Lexer = class Lexer
|
|||
# contents of the string. This method allows us to have strings within
|
||||
# interpolations within strings, ad infinitum.
|
||||
balancedString: (str, end) ->
|
||||
continueCount = 0
|
||||
stack = [end]
|
||||
for i in [1...str.length]
|
||||
if continueCount
|
||||
--continueCount
|
||||
continue
|
||||
switch letter = str.charAt i
|
||||
when '\\'
|
||||
i++
|
||||
++continueCount
|
||||
continue
|
||||
when end
|
||||
stack.pop()
|
||||
|
@ -422,7 +426,7 @@ exports.Lexer = class Lexer
|
|||
if end is '}' and letter in ['"', "'"]
|
||||
stack.push end = letter
|
||||
else if end is '}' and letter is '/' and match = (HEREGEX.exec(str.slice i) or REGEX.exec(str.slice i))
|
||||
i += match[0].length - 1
|
||||
continueCount += match[0].length - 1
|
||||
else if end is '}' and letter is '{'
|
||||
stack.push end = '}'
|
||||
else if end is '"' and prev is '#' and letter is '{'
|
||||
|
|
|
@ -677,9 +677,11 @@ exports.Range = class Range extends Base
|
|||
# Set up endpoints.
|
||||
known = @fromNum and @toNum
|
||||
idx = del o, 'index'
|
||||
idxName = del o, 'name'
|
||||
varPart = "#{idx} = #{@fromC}"
|
||||
varPart += ", #{@toC}" if @toC isnt @toVar
|
||||
varPart += ", #{@step}" if @step isnt @stepVar
|
||||
varPart = "#{idxName} = #{varPart}" if idxName and idxName isnt idx
|
||||
[lt, gt] = ["#{idx} <#{@equals}", "#{idx} >#{@equals}"]
|
||||
|
||||
# Generate the condition.
|
||||
|
@ -696,9 +698,10 @@ exports.Range = class Range extends Base
|
|||
stepPart = if @stepVar
|
||||
"#{idx} += #{@stepVar}"
|
||||
else if known
|
||||
if from <= to then "#{idx}++" else "#{idx}--"
|
||||
if from <= to then "++#{idx}" else "--#{idx}"
|
||||
else
|
||||
"#{cond} ? #{idx}++ : #{idx}--"
|
||||
"#{cond} ? ++#{idx} : --#{idx}"
|
||||
stepPart = "#{idxName} = #{stepPart}" if idxName and idxName isnt idx
|
||||
|
||||
# The final loop body.
|
||||
"#{varPart}; #{condPart}; #{stepPart}"
|
||||
|
@ -1606,7 +1609,9 @@ exports.For = class For extends While
|
|||
scope.find(name, immediate: yes) if name and not @pattern
|
||||
scope.find(index, immediate: yes) if index
|
||||
rvar = scope.freeVariable 'results' if @returns
|
||||
ivar = (if @range then name else index) or scope.freeVariable 'i'
|
||||
ivar = (@object and index) or scope.freeVariable 'i'
|
||||
kvar = (@range and name) or index or ivar
|
||||
kvarAssign = if kvar isnt ivar then "#{kvar} = " else ""
|
||||
# the `_by` variable is created twice in `Range`s if we don't prevent it from being declared here
|
||||
stepvar = scope.freeVariable "step" if @step and not @range
|
||||
name = ivar if @pattern
|
||||
|
@ -1615,18 +1620,19 @@ exports.For = class For extends While
|
|||
defPart = ''
|
||||
idt1 = @tab + TAB
|
||||
if @range
|
||||
forPart = source.compile merge(o, {index: ivar, @step})
|
||||
forPart = source.compile merge(o, {index: ivar, name, @step})
|
||||
else
|
||||
svar = @source.compile o, LEVEL_LIST
|
||||
if (name or @own) and not IDENTIFIER.test svar
|
||||
defPart = "#{@tab}#{ref = scope.freeVariable 'ref'} = #{svar};\n"
|
||||
svar = ref
|
||||
if name and not @pattern
|
||||
namePart = "#{name} = #{svar}[#{ivar}]"
|
||||
namePart = "#{name} = #{svar}[#{kvar}]"
|
||||
unless @object
|
||||
lvar = scope.freeVariable 'len'
|
||||
forVarPart = "#{ivar} = 0, #{lvar} = #{svar}.length" + if @step then ", #{stepvar} = #{@step.compile(o, LEVEL_OP)}" else ''
|
||||
stepPart = if @step then "#{ivar} += #{stepvar}" else "#{ivar}++"
|
||||
forVarPart = "#{kvarAssign}#{ivar} = 0, #{lvar} = #{svar}.length"
|
||||
forVarPart += ", #{stepvar} = #{@step.compile o, LEVEL_OP}" if @step
|
||||
stepPart = "#{kvarAssign}#{if @step then "#{ivar} += #{stepvar}" else "++#{ivar}"}"
|
||||
forPart = "#{forVarPart}; #{ivar} < #{lvar}; #{stepPart}"
|
||||
if @returns
|
||||
resultPart = "#{@tab}#{rvar} = [];\n"
|
||||
|
@ -1638,12 +1644,12 @@ exports.For = class For extends While
|
|||
else
|
||||
body = Block.wrap [new If @guard, body] if @guard
|
||||
if @pattern
|
||||
body.expressions.unshift new Assign @name, new Literal "#{svar}[#{ivar}]"
|
||||
body.expressions.unshift new Assign @name, new Literal "#{svar}[#{kvar}]"
|
||||
defPart += @pluckDirectCall o, body
|
||||
varPart = "\n#{idt1}#{namePart};" if namePart
|
||||
if @object
|
||||
forPart = "#{ivar} in #{svar}"
|
||||
guardPart = "\n#{idt1}if (!#{utility 'hasProp'}.call(#{svar}, #{ivar})) continue;" if @own
|
||||
forPart = "#{kvar} in #{svar}"
|
||||
guardPart = "\n#{idt1}if (!#{utility 'hasProp'}.call(#{svar}, #{kvar})) continue;" if @own
|
||||
body = body.compile merge(o, indent: idt1), LEVEL_TOP
|
||||
body = '\n' + body + '\n' if body
|
||||
"""
|
||||
|
|
|
@ -25,9 +25,13 @@ exports.OptionParser = class OptionParser
|
|||
# for interpreting the options object.
|
||||
parse: (args) ->
|
||||
options = arguments: [], literals: []
|
||||
skippingArgument = no
|
||||
originalArgs = args
|
||||
args = normalizeArguments args
|
||||
for arg, i in args
|
||||
if skippingArgument
|
||||
skippingArgument = no
|
||||
continue
|
||||
if arg is '--'
|
||||
pos = originalArgs.indexOf '--'
|
||||
options.arguments = [originalArgs[1 + pos]]
|
||||
|
@ -37,7 +41,11 @@ exports.OptionParser = class OptionParser
|
|||
matchedRule = no
|
||||
for rule in @rules
|
||||
if rule.shortFlag is arg or rule.longFlag is arg
|
||||
value = if rule.hasArgument then args[i += 1] else true
|
||||
value = if rule.hasArgument
|
||||
skippingArgument = yes
|
||||
args[i + 1]
|
||||
else
|
||||
true
|
||||
options[rule.name] = if rule.isList then (options[rule.name] or []).concat value else value
|
||||
matchedRule = yes
|
||||
break
|
||||
|
|
|
@ -460,3 +460,28 @@ test "#1850: inner `for` should not be expression-ized if `return`ing", ->
|
|||
for b in [1..9]
|
||||
c = Math.sqrt a*a + b*b
|
||||
return String [a, b, c] unless c % 1
|
||||
|
||||
test "#1910: loop index should be mutable within a loop iteration and immutable between loop iterations", ->
|
||||
n = 1
|
||||
iterations = 0
|
||||
arr = [0..n]
|
||||
for v, k in arr
|
||||
++iterations
|
||||
v = k = 5
|
||||
eq 5, k
|
||||
eq 2, k
|
||||
eq 2, iterations
|
||||
|
||||
iterations = 0
|
||||
for v in [0..n]
|
||||
++iterations
|
||||
eq 2, k
|
||||
eq 2, iterations
|
||||
|
||||
arr = ([v, v + 1] for v in [0..5])
|
||||
iterations = 0
|
||||
for own [v0, v1], k in arr when v0
|
||||
k += 3
|
||||
++iterations
|
||||
eq 6, k
|
||||
eq 5, iterations
|
||||
|
|
|
@ -428,5 +428,3 @@ test "Throw should be usable as an expression.", ->
|
|||
throw new Error 'failed'
|
||||
catch e
|
||||
ok e is 'up'
|
||||
|
||||
|
|
@ -15,14 +15,14 @@ opt = new OptionParser [
|
|||
|
||||
result = opt.parse ['one', 'two', 'three', '-r', 'dir']
|
||||
|
||||
ok result.arguments.length is 5
|
||||
ok result.arguments[3] is '-r'
|
||||
eq 5, result.arguments.length
|
||||
eq '-r', result.arguments[3]
|
||||
|
||||
result = opt.parse ['--optional', '-r', 'folder', 'one', 'two']
|
||||
|
||||
ok result.optional is true
|
||||
ok result.required is 'folder'
|
||||
ok result.arguments.join(' ') is 'one two'
|
||||
ok result.optional
|
||||
eq 'folder', result.required
|
||||
eq 'one two', result.arguments.join ' '
|
||||
|
||||
result = opt.parse ['-l', 'one.txt', '-l', 'two.txt', 'three']
|
||||
|
||||
|
|
Loading…
Reference in a new issue