You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pm...@apache.org on 2012/06/29 16:42:29 UTC
[2/6] [CB-984] [weinre] weinre broken with node 0.8
http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/4d3b995f/weinre.server/node_modules/coffee-script/lib/coffee-script/nodes.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/coffee-script/lib/coffee-script/nodes.js b/weinre.server/node_modules/coffee-script/lib/coffee-script/nodes.js
index 1941298..799b68e 100644
--- a/weinre.server/node_modules/coffee-script/lib/coffee-script/nodes.js
+++ b/weinre.server/node_modules/coffee-script/lib/coffee-script/nodes.js
@@ -1,14 +1,15 @@
+// Generated by CoffeeScript 1.3.3
(function() {
- var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref,
- __hasProp = Object.prototype.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; },
- __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+ var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref, _ref1,
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Scope = require('./scope').Scope;
- RESERVED = require('./lexer').RESERVED;
+ _ref = require('./lexer'), RESERVED = _ref.RESERVED, STRICT_PROSCRIBED = _ref.STRICT_PROSCRIBED;
- _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;
+ _ref1 = require('./helpers'), compact = _ref1.compact, flatten = _ref1.flatten, extend = _ref1.extend, merge = _ref1.merge, del = _ref1.del, starts = _ref1.starts, ends = _ref1.ends, last = _ref1.last;
exports.extend = extend;
@@ -36,7 +37,9 @@
Base.prototype.compile = function(o, lvl) {
var node;
o = extend({}, o);
- if (lvl) o.level = lvl;
+ if (lvl) {
+ o.level = lvl;
+ }
node = this.unfoldSoak(o) || this;
node.tab = o.indent;
if (o.level === LEVEL_TOP || !node.isStatement(o)) {
@@ -111,17 +114,25 @@
var i;
i = list.length;
while (i--) {
- if (!(list[i] instanceof Comment)) return list[i];
+ if (!(list[i] instanceof Comment)) {
+ return list[i];
+ }
}
return null;
};
Base.prototype.toString = function(idt, name) {
var tree;
- if (idt == null) idt = '';
- if (name == null) name = this.constructor.name;
+ if (idt == null) {
+ idt = '';
+ }
+ if (name == null) {
+ name = this.constructor.name;
+ }
tree = '\n' + idt + name;
- if (this.soak) tree += '?';
+ if (this.soak) {
+ tree += '?';
+ }
this.eachChild(function(node) {
return tree += node.toString(idt + TAB);
});
@@ -129,16 +140,20 @@
};
Base.prototype.eachChild = function(func) {
- var attr, child, _i, _j, _len, _len2, _ref2, _ref3;
- if (!this.children) return this;
+ var attr, child, _i, _j, _len, _len1, _ref2, _ref3;
+ if (!this.children) {
+ return this;
+ }
_ref2 = this.children;
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, _len1 = _ref3.length; _j < _len1; _j++) {
child = _ref3[_j];
- if (func(child) === false) return this;
+ if (func(child) === false) {
+ return this;
+ }
}
}
}
@@ -147,7 +162,9 @@
Base.prototype.traverseChildren = function(crossScope, func) {
return this.eachChild(function(child) {
- if (func(child) === false) return false;
+ if (func(child) === false) {
+ return false;
+ }
return child.traverseChildren(crossScope, func);
});
};
@@ -228,7 +245,9 @@
_ref2 = this.expressions;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
exp = _ref2[_i];
- if (exp.isStatement(o)) return true;
+ if (exp.isStatement(o)) {
+ return true;
+ }
}
return false;
};
@@ -238,7 +257,9 @@
_ref2 = this.expressions;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
exp = _ref2[_i];
- if (exp.jumps(o)) return exp;
+ if (exp.jumps(o)) {
+ return exp;
+ }
}
};
@@ -259,7 +280,9 @@
};
Block.prototype.compile = function(o, level) {
- if (o == null) o = {};
+ if (o == null) {
+ o = {};
+ }
if (o.scope) {
return Block.__super__.compile.call(this, o, level);
} else {
@@ -282,7 +305,13 @@
} else if (top) {
node.front = true;
code = node.compile(o);
- codes.push(node.isStatement(o) ? code : "" + this.tab + code + ";");
+ if (!node.isStatement(o)) {
+ code = "" + this.tab + code + ";";
+ if (node instanceof Literal) {
+ code = "" + code + "\n";
+ }
+ }
+ codes.push(code);
} else {
codes.push(node.compile(o, LEVEL_LIST));
}
@@ -311,12 +340,14 @@
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;
+ if (!(exp.unwrap() instanceof Comment)) {
+ break;
+ }
_results.push(exp);
}
return _results;
@@ -331,18 +362,22 @@
this.expressions = rest;
}
code = this.compileWithDeclarations(o);
- if (o.bare) return code;
+ if (o.bare) {
+ return code;
+ }
return "" + prelude + "(function() {\n" + code + "\n}).call(this);\n";
};
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;
+ if (!(exp instanceof Comment || exp instanceof Literal)) {
+ break;
+ }
}
o = merge(o, {
level: LEVEL_TOP
@@ -359,11 +394,17 @@
declars = o.scope.hasDeclarations();
assigns = scope.hasAssignments;
if (declars || assigns) {
- if (i) code += '\n';
+ if (i) {
+ code += '\n';
+ }
code += "" + this.tab + "var ";
- if (declars) code += scope.declaredVariables().join(', ');
+ if (declars) {
+ code += scope.declaredVariables().join(', ');
+ }
if (assigns) {
- if (declars) code += ",\n" + (this.tab + TAB);
+ if (declars) {
+ code += ",\n" + (this.tab + TAB);
+ }
code += scope.assignedVariables().join(",\n" + (this.tab + TAB));
}
code += ';\n';
@@ -373,7 +414,9 @@
};
Block.wrap = function(nodes) {
- if (nodes.length === 1 && nodes[0] instanceof Block) return nodes[0];
+ if (nodes.length === 1 && nodes[0] instanceof Block) {
+ return nodes[0];
+ }
return new Block(nodes);
};
@@ -416,12 +459,14 @@
if (this.value === 'break' && !((o != null ? o.loop : void 0) || (o != null ? o.block : void 0))) {
return this;
}
- if (this.value === 'continue' && !(o != null ? o.loop : void 0)) return this;
+ if (this.value === 'continue' && !(o != null ? o.loop : void 0)) {
+ return this;
+ }
};
Literal.prototype.compileNode = function(o) {
- var code, _ref2, _ref3;
- code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved && ((_ref3 = "" + this.value) !== 'eval' && _ref3 !== 'arguments') ? "\"" + this.value + "\"" : this.value;
+ var code, _ref2;
+ code = this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved ? "\"" + this.value + "\"" : this.value;
if (this.isStatement()) {
return "" + this.tab + code + ";";
} else {
@@ -437,12 +482,78 @@
})(Base);
+ exports.Undefined = (function(_super) {
+
+ __extends(Undefined, _super);
+
+ function Undefined() {
+ return Undefined.__super__.constructor.apply(this, arguments);
+ }
+
+ Undefined.prototype.isAssignable = NO;
+
+ Undefined.prototype.isComplex = NO;
+
+ Undefined.prototype.compileNode = function(o) {
+ if (o.level >= LEVEL_ACCESS) {
+ return '(void 0)';
+ } else {
+ return 'void 0';
+ }
+ };
+
+ return Undefined;
+
+ })(Base);
+
+ exports.Null = (function(_super) {
+
+ __extends(Null, _super);
+
+ function Null() {
+ return Null.__super__.constructor.apply(this, arguments);
+ }
+
+ Null.prototype.isAssignable = NO;
+
+ Null.prototype.isComplex = NO;
+
+ Null.prototype.compileNode = function() {
+ return "null";
+ };
+
+ return Null;
+
+ })(Base);
+
+ exports.Bool = (function(_super) {
+
+ __extends(Bool, _super);
+
+ Bool.prototype.isAssignable = NO;
+
+ Bool.prototype.isComplex = NO;
+
+ Bool.prototype.compileNode = function() {
+ return this.val;
+ };
+
+ function Bool(val) {
+ this.val = val;
+ }
+
+ return Bool;
+
+ })(Base);
+
exports.Return = Return = (function(_super) {
__extends(Return, _super);
function Return(expr) {
- if (expr && !expr.unwrap().isUndefined) this.expression = expr;
+ if (expr && !expr.unwrap().isUndefined) {
+ this.expression = expr;
+ }
}
Return.prototype.children = ['expression'];
@@ -476,10 +587,14 @@
__extends(Value, _super);
function Value(base, props, tag) {
- if (!props && base instanceof Value) return base;
+ if (!props && base instanceof Value) {
+ return base;
+ }
this.base = base;
this.properties = props || [];
- if (tag) this[tag] = true;
+ if (tag) {
+ this[tag] = true;
+ }
return this;
}
@@ -510,12 +625,18 @@
return this.base instanceof Literal && SIMPLENUM.test(this.base.value);
};
+ Value.prototype.isString = function() {
+ return this.base instanceof Literal && IS_STRING.test(this.base.value);
+ };
+
Value.prototype.isAtomic = function() {
var node, _i, _len, _ref2;
_ref2 = this.properties.concat(this.base);
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
node = _ref2[_i];
- if (node.soak || node instanceof Call) return false;
+ if (node.soak || node instanceof Call) {
+ return false;
+ }
}
return true;
};
@@ -533,7 +654,9 @@
};
Value.prototype.isObject = function(onlyGenerated) {
- if (this.properties.length) return false;
+ if (this.properties.length) {
+ return false;
+ }
return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated);
};
@@ -560,7 +683,9 @@
bref = new Literal(o.scope.freeVariable('base'));
base = new Value(new Parens(new Assign(bref, base)));
}
- if (!name) return [base, bref];
+ if (!name) {
+ return [base, bref];
+ }
if (name.isComplex()) {
nref = new Literal(o.scope.freeVariable('name'));
name = new Index(new Assign(nref, name.index));
@@ -587,17 +712,21 @@
Value.prototype.unfoldSoak = function(o) {
var result,
_this = this;
- if (this.unfoldedSoak != null) return this.unfoldedSoak;
+ 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;
+ if (!prop.soak) {
+ continue;
+ }
prop.soak = false;
fst = new Value(_this.base, _this.properties.slice(0, i));
snd = new Value(_this.base, _this.properties.slice(i));
@@ -633,8 +762,10 @@
Comment.prototype.compileNode = function(o, level) {
var code;
- code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/");
- if ((level || o.level) === LEVEL_TOP) code = o.indent + code;
+ code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/\n");
+ if ((level || o.level) === LEVEL_TOP) {
+ code = o.indent + code;
+ }
return code;
};
@@ -669,15 +800,19 @@
Call.prototype.superReference = function(o) {
var accesses, method, name;
- method = o.scope.method;
- if (!method) throw SyntaxError('cannot call super outside of a function.');
+ method = o.scope.namedMethod();
+ if (!method) {
+ throw SyntaxError('cannot call super outside of a function.');
+ }
name = method.name;
if (name == null) {
throw SyntaxError('cannot call super on an anonymous function.');
}
if (method.klass) {
accesses = [new Access(new Literal('__super__'))];
- if (method.static) accesses.push(new Access(new Literal('constructor')));
+ if (method["static"]) {
+ accesses.push(new Access(new Literal('constructor')));
+ }
accesses.push(new Access(new Literal(name)));
return (new Value(new Literal(method.klass), accesses)).compile(o);
} else {
@@ -685,11 +820,19 @@
}
};
+ Call.prototype.superThis = function(o) {
+ var method;
+ method = o.scope.method;
+ return (method && !method.klass && method.context) || "this";
+ };
+
Call.prototype.unfoldSoak = function(o) {
var call, ifn, left, list, rite, _i, _len, _ref2, _ref3;
if (this.soak) {
if (this.variable) {
- if (ifn = unfoldSoak(o, this, 'variable')) return ifn;
+ if (ifn = unfoldSoak(o, this, 'variable')) {
+ return ifn;
+ }
_ref2 = new Value(this.variable).cacheReference(o), left = _ref2[0], rite = _ref2[1];
} else {
left = new Literal(this.superReference(o));
@@ -710,9 +853,13 @@
call = call.variable;
continue;
}
- if (!(call.variable instanceof Value)) break;
+ if (!(call.variable instanceof Value)) {
+ break;
+ }
list.push(call);
- if (!((call = call.variable.base) instanceof Call)) break;
+ if (!((call = call.variable.base) instanceof Call)) {
+ break;
+ }
}
_ref3 = list.reverse();
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
@@ -730,7 +877,7 @@
};
Call.prototype.filterImplicitObjects = function(list) {
- var node, nodes, obj, prop, properties, _i, _j, _len, _len2, _ref2;
+ var node, nodes, obj, prop, properties, _i, _j, _len, _len1, _ref2;
nodes = [];
for (_i = 0, _len = list.length; _i < _len; _i++) {
node = list[_i];
@@ -740,10 +887,12 @@
}
obj = null;
_ref2 = node.base.properties;
- for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
+ for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
prop = _ref2[_j];
if (prop instanceof Assign || prop instanceof Comment) {
- if (!obj) nodes.push(obj = new Obj(properties = [], true));
+ if (!obj) {
+ nodes.push(obj = new Obj(properties = [], true));
+ }
properties.push(prop);
} else {
nodes.push(prop);
@@ -756,7 +905,9 @@
Call.prototype.compileNode = function(o) {
var arg, args, code, _ref2;
- if ((_ref2 = this.variable) != null) _ref2.front = this.front;
+ if ((_ref2 = this.variable) != null) {
+ _ref2.front = this.front;
+ }
if (code = Splat.compileSplattedArray(o, this.args, true)) {
return this.compileSplat(o, code);
}
@@ -771,24 +922,24 @@
return _results;
})()).join(', ');
if (this.isSuper) {
- return this.superReference(o) + (".call(this" + (args && ', ' + args) + ")");
+ return this.superReference(o) + (".call(" + (this.superThis(o)) + (args && ', ' + args) + ")");
} else {
return (this.isNew ? 'new ' : '') + this.variable.compile(o, LEVEL_ACCESS) + ("(" + args + ")");
}
};
Call.prototype.compileSuper = function(args, o) {
- return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")";
+ return "" + (this.superReference(o)) + ".call(" + (this.superThis(o)) + (args.length ? ', ' : '') + args + ")";
};
Call.prototype.compileSplat = function(o, splatArgs) {
var base, fun, idt, name, ref;
if (this.isSuper) {
- return "" + (this.superReference(o)) + ".apply(this, " + splatArgs + ")";
+ return "" + (this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", " + splatArgs + ")";
}
if (this.isNew) {
idt = this.tab + TAB;
- return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function() {})";
+ return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args), t = typeof result;\n" + idt + "return t == \"object\" || t == \"function\" ? result || child : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function(){})";
}
base = new Value(this.variable);
if ((name = base.properties.pop()) && base.isComplex()) {
@@ -796,7 +947,9 @@
fun = "(" + ref + " = " + (base.compile(o, LEVEL_LIST)) + ")" + (name.compile(o));
} else {
fun = base.compile(o, LEVEL_ACCESS);
- if (SIMPLENUM.test(fun)) fun = "(" + fun + ")";
+ if (SIMPLENUM.test(fun)) {
+ fun = "(" + fun + ")";
+ }
if (name) {
ref = fun;
fun += name.compile(o);
@@ -904,21 +1057,39 @@
_ref4 = step.cache(o, LEVEL_LIST), this.step = _ref4[0], this.stepVar = _ref4[1];
}
_ref5 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref5[0], this.toNum = _ref5[1];
- if (this.stepVar) return this.stepNum = this.stepVar.match(SIMPLENUM);
+ if (this.stepVar) {
+ return this.stepNum = this.stepVar.match(SIMPLENUM);
+ }
};
Range.prototype.compileNode = function(o) {
- var cond, condPart, from, gt, idx, known, lt, stepPart, to, varPart, _ref2, _ref3;
- if (!this.fromVar) this.compileVariables(o);
- if (!o.index) return this.compileArray(o);
+ var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, 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');
+ namedIndex = idxName && idxName !== idx;
varPart = "" + idx + " = " + this.fromC;
- if (this.toC !== this.toVar) varPart += ", " + this.toC;
- if (this.step !== this.stepVar) varPart += ", " + this.step;
+ if (this.toC !== this.toVar) {
+ varPart += ", " + this.toC;
+ }
+ if (this.step !== this.stepVar) {
+ varPart += ", " + this.step;
+ }
_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 ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? "" + idx + "++" : "" + idx + "--" : namedIndex ? "" + cond + " ? ++" + idx + " : --" + idx : "" + cond + " ? " + idx + "++ : " + idx + "--";
+ if (namedIndex) {
+ varPart = "" + idxName + " = " + varPart;
+ }
+ if (namedIndex) {
+ stepPart = "" + idxName + " = " + stepPart;
+ }
return "" + varPart + "; " + condPart + "; " + stepPart;
};
@@ -930,7 +1101,9 @@
for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i++ : _i--){ _results.push(_i); }
return _results;
}).apply(this);
- if (this.exclusive) range.pop();
+ if (this.exclusive) {
+ range.pop();
+ }
return "[" + (range.join(', ')) + "]";
}
idt = this.tab + TAB;
@@ -951,7 +1124,9 @@
return n instanceof Literal && n.value === 'arguments' && !n.asKey;
}) : void 0;
};
- if (hasArgs(this.from) || hasArgs(this.to)) args = ', arguments';
+ if (hasArgs(this.from) || hasArgs(this.to)) {
+ args = ', arguments';
+ }
return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this" + (args != null ? args : '') + ")";
};
@@ -974,9 +1149,9 @@
var compiled, from, fromStr, to, toStr, _ref2;
_ref2 = this.range, to = _ref2.to, from = _ref2.from;
fromStr = from && from.compile(o, LEVEL_PAREN) || '0';
- compiled = to && to.compile(o, LEVEL_ACCESS);
+ compiled = to && to.compile(o, LEVEL_PAREN);
if (to && !(!this.range.exclusive && +compiled === -1)) {
- toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? (+compiled + 1).toString() : "" + compiled + " + 1 || 9e9");
+ toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? "" + (+compiled + 1) : (compiled = to.compile(o, LEVEL_ACCESS), "" + compiled + " + 1 || 9e9"));
}
return ".slice(" + fromStr + (toStr || '') + ")";
};
@@ -997,12 +1172,29 @@
Obj.prototype.children = ['properties'];
Obj.prototype.compileNode = function(o) {
- var i, idt, indent, join, lastNoncom, node, obj, prop, props, _i, _len;
+ var i, idt, indent, join, lastNoncom, node, obj, prop, propName, propNames, props, _i, _j, _len, _len1, _ref2;
props = this.properties;
- if (!props.length) return (this.front ? '({})' : '{}');
+ propNames = [];
+ _ref2 = this.properties;
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ prop = _ref2[_i];
+ if (prop.isComplex()) {
+ prop = prop.variable;
+ }
+ if (prop != null) {
+ propName = prop.unwrapAll().value.toString();
+ if (__indexOf.call(propNames, propName) >= 0) {
+ throw SyntaxError("multiple object literal properties named \"" + propName + "\"");
+ }
+ propNames.push(propName);
+ }
+ }
+ if (!props.length) {
+ return (this.front ? '({})' : '{}');
+ }
if (this.generated) {
- for (_i = 0, _len = props.length; _i < _len; _i++) {
- node = props[_i];
+ for (_j = 0, _len1 = props.length; _j < _len1; _j++) {
+ node = props[_j];
if (node instanceof Value) {
throw new Error('cannot have an implicit value in an implicit object');
}
@@ -1011,9 +1203,9 @@
idt = o.indent += TAB;
lastNoncom = this.lastNonComment(this.properties);
props = (function() {
- var _len2, _results;
+ var _k, _len2, _results;
_results = [];
- for (i = 0, _len2 = props.length; i < _len2; i++) {
+ for (i = _k = 0, _len2 = props.length; _k < _len2; i = ++_k) {
prop = props[i];
join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
indent = prop instanceof Comment ? '' : idt;
@@ -1021,7 +1213,9 @@
prop = new Assign(prop.properties[0].name, prop, 'object');
}
if (!(prop instanceof Comment)) {
- if (!(prop instanceof Assign)) prop = new Assign(prop, prop, 'object');
+ if (!(prop instanceof Assign)) {
+ prop = new Assign(prop, prop, 'object');
+ }
(prop.variable.base || prop.variable).asKey = true;
}
_results.push(indent + prop.compile(o, LEVEL_TOP) + join);
@@ -1042,7 +1236,9 @@
_ref2 = this.properties;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
prop = _ref2[_i];
- if (prop.assigns(name)) return true;
+ if (prop.assigns(name)) {
+ return true;
+ }
}
return false;
};
@@ -1065,10 +1261,14 @@
Arr.prototype.compileNode = function(o) {
var code, obj, objs;
- if (!this.objects.length) return '[]';
+ if (!this.objects.length) {
+ return '[]';
+ }
o.indent += TAB;
objs = this.filterImplicitObjects(this.objects);
- if (code = Splat.compileSplattedArray(o, objs)) return code;
+ if (code = Splat.compileSplattedArray(o, objs)) {
+ return code;
+ }
code = ((function() {
var _i, _len, _results;
_results = [];
@@ -1090,7 +1290,9 @@
_ref2 = this.objects;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
obj = _ref2[_i];
- if (obj.assigns(name)) return true;
+ if (obj.assigns(name)) {
+ return true;
+ }
}
return false;
};
@@ -1115,19 +1317,28 @@
Class.prototype.determineName = function() {
var decl, tail;
- if (!this.variable) return null;
+ if (!this.variable) {
+ return null;
+ }
decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;
+ if (__indexOf.call(STRICT_PROSCRIBED, decl) >= 0) {
+ throw SyntaxError("variable name may not be " + decl);
+ }
return decl && (decl = IDENTIFIER.test(decl) && decl);
};
Class.prototype.setContext = function(name) {
return this.body.traverseChildren(false, function(node) {
- if (node.classBody) return false;
+ if (node.classBody) {
+ return false;
+ }
if (node instanceof Literal && node.value === 'this') {
return node.value = name;
} else if (node instanceof Code) {
node.klass = name;
- if (node.bound) return node.context = name;
+ if (node.bound) {
+ return node.context = name;
+ }
}
});
};
@@ -1172,8 +1383,10 @@
}
} else {
if (assign.variable["this"]) {
- func.static = true;
- if (func.bound) func.context = name;
+ func["static"] = true;
+ if (func.bound) {
+ func.context = name;
+ }
} else {
assign.variable = new Value(new Literal(name), [new Access(new Literal('prototype')), new Access(base)]);
if (func instanceof Code && func.bound) {
@@ -1193,11 +1406,13 @@
Class.prototype.walkBody = function(name, o) {
var _this = this;
return this.traverseChildren(false, function(child) {
- var exps, i, node, _len, _ref2;
- if (child instanceof Class) return false;
+ 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);
@@ -1208,6 +1423,16 @@
});
};
+ Class.prototype.hoistDirectivePrologue = function() {
+ var expressions, index, node;
+ index = 0;
+ expressions = this.body.expressions;
+ while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {
+ ++index;
+ }
+ return this.directives = expressions.splice(0, index);
+ };
+
Class.prototype.ensureConstructor = function(name) {
if (!this.ctor) {
this.ctor = new Code;
@@ -1217,6 +1442,7 @@
if (this.externalCtor) {
this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)"));
}
+ this.ctor.body.makeReturn();
this.body.expressions.unshift(this.ctor);
}
this.ctor.ctor = this.ctor.name = name;
@@ -1225,27 +1451,36 @@
};
Class.prototype.compileNode = function(o) {
- var call, decl, klass, lname, name;
+ var call, decl, klass, lname, name, params, _ref2;
decl = this.determineName();
- name = decl || this.name || '_Class';
- if (name.reserved) name = "_" + name;
+ name = decl || '_Class';
+ if (name.reserved) {
+ name = "_" + name;
+ }
lname = new Literal(name);
+ this.hoistDirectivePrologue();
this.setContext(name);
this.walkBody(name, o);
this.ensureConstructor(name);
this.body.spaced = true;
- if (!(this.ctor instanceof Code)) this.body.expressions.unshift(this.ctor);
+ if (!(this.ctor instanceof Code)) {
+ this.body.expressions.unshift(this.ctor);
+ }
this.body.expressions.push(lname);
+ (_ref2 = this.body.expressions).unshift.apply(_ref2, this.directives);
this.addBoundFunctions(o);
call = Closure.wrap(this.body);
if (this.parent) {
this.superClass = new Literal(o.scope.freeVariable('super', false));
this.body.expressions.unshift(new Extends(lname, this.superClass));
call.args.push(this.parent);
- call.variable.params.push(new Param(this.superClass));
+ params = call.variable.params || call.variable.base.params;
+ params.push(new Param(this.superClass));
}
klass = new Parens(call, true);
- if (this.variable) klass = new Assign(this.variable, klass);
+ if (this.variable) {
+ klass = new Assign(this.variable, klass);
+ }
return klass.compile(o);
};
@@ -1258,11 +1493,16 @@
__extends(Assign, _super);
function Assign(variable, value, context, options) {
+ var forbidden, name, _ref2;
this.variable = variable;
this.value = value;
this.context = context;
this.param = options && options.param;
this.subpattern = options && options.subpattern;
+ forbidden = (_ref2 = (name = this.variable.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0);
+ if (forbidden && this.context !== 'object') {
+ throw SyntaxError("variable name may not be \"" + name + "\"");
+ }
}
Assign.prototype.children = ['variable', 'value'];
@@ -1285,7 +1525,9 @@
if (this.variable.isArray() || this.variable.isObject()) {
return this.compilePatternMatch(o);
}
- if (this.variable.isSplice()) return this.compileSplice(o);
+ if (this.variable.isSplice()) {
+ return this.compileSplice(o);
+ }
if ((_ref2 = this.context) === '||=' || _ref2 === '&&=' || _ref2 === '?=') {
return this.compileConditional(o);
}
@@ -1304,11 +1546,15 @@
}
}
if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) {
- if (match[1]) this.value.klass = match[1];
+ if (match[1]) {
+ this.value.klass = match[1];
+ }
this.value.name = (_ref3 = (_ref4 = (_ref5 = match[2]) != null ? _ref5 : match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5];
}
val = this.value.compile(o, LEVEL_LIST);
- if (this.context === 'object') return "" + name + ": " + val;
+ if (this.context === 'object') {
+ return "" + name + ": " + val;
+ }
val = name + (" " + (this.context || '=') + " ") + val;
if (o.level <= LEVEL_LIST) {
return val;
@@ -1318,7 +1564,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;
@@ -1344,7 +1590,7 @@
acc = IDENTIFIER.test(idx.unwrap().value || 0);
value = new Value(value);
value.properties.push(new (acc ? Access : Index)(idx));
- if (_ref5 = obj.unwrap().value, __indexOf.call(['arguments', 'eval'].concat(RESERVED), _ref5) >= 0) {
+ if (_ref5 = obj.unwrap().value, __indexOf.call(RESERVED, _ref5) >= 0) {
throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (value.compile(o)));
}
return new Assign(obj, value, null, {
@@ -1358,7 +1604,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) {
@@ -1398,7 +1644,7 @@
}
val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]);
}
- if ((name != null) && __indexOf.call(['arguments', 'eval'].concat(RESERVED), name) >= 0) {
+ if ((name != null) && __indexOf.call(RESERVED, name) >= 0) {
throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (val.compile(o)));
}
assigns.push(new Assign(obj, val, null, {
@@ -1406,7 +1652,9 @@
subpattern: true
}).compile(o, LEVEL_LIST));
}
- if (!(top || this.subpattern)) assigns.push(vvar);
+ if (!(top || this.subpattern)) {
+ assigns.push(vvar);
+ }
code = assigns.join(', ');
if (o.level < LEVEL_LIST) {
return code;
@@ -1416,10 +1664,15 @@
};
Assign.prototype.compileConditional = function(o) {
- var left, rite, _ref2;
- _ref2 = this.variable.cacheReference(o), left = _ref2[0], rite = _ref2[1];
- if (__indexOf.call(this.context, "?") >= 0) o.isExistentialEquals = true;
- return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value, '=')).compile(o);
+ var left, right, _ref2;
+ _ref2 = this.variable.cacheReference(o), left = _ref2[0], right = _ref2[1];
+ if (!left.properties.length && left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) {
+ throw new Error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been defined.");
+ }
+ if (__indexOf.call(this.context, "?") >= 0) {
+ o.isExistentialEquals = true;
+ }
+ return new Op(this.context.slice(0, -1), left, new Assign(right, this.value, '=')).compile(o);
};
Assign.prototype.compileSplice = function(o) {
@@ -1430,10 +1683,14 @@
if (to) {
if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) {
to = +to.compile(o) - +fromRef;
- if (!exclusive) to += 1;
+ if (!exclusive) {
+ to += 1;
+ }
} else {
to = to.compile(o, LEVEL_ACCESS) + ' - ' + fromRef;
- if (!exclusive) to += ' + 1';
+ if (!exclusive) {
+ to += ' + 1';
+ }
}
} else {
to = "9e9";
@@ -1459,7 +1716,9 @@
this.params = params || [];
this.body = body || new Block;
this.bound = tag === 'boundfunc';
- if (this.bound) this.context = '_this';
+ if (this.bound) {
+ this.context = '_this';
+ }
}
Code.prototype.children = ['params', 'body'];
@@ -1471,40 +1730,57 @@
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, name, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
o.scope = new Scope(o.scope, this.body, this);
o.scope.shared = del(o, 'sharedScope');
o.indent += TAB;
delete o.bare;
- vars = [];
+ delete o.isExistentialEquals;
+ params = [];
exprs = [];
- _ref2 = this.params;
+ _ref2 = this.paramNames();
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++) {
- p = _ref3[_j];
- if (p.name.value) o.scope.add(p.name.value, 'var', true);
+ name = _ref2[_i];
+ if (!o.scope.check(name)) {
+ o.scope.parameter(name);
+ }
+ }
+ _ref3 = this.params;
+ for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
+ param = _ref3[_j];
+ if (!param.splat) {
+ continue;
+ }
+ _ref4 = this.params;
+ for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
+ p = _ref4[_k].name;
+ if (p["this"]) {
+ p = p.properties[0].name;
+ }
+ if (p.value) {
+ o.scope.add(p.value, 'var', true);
+ }
}
splats = new Assign(new Value(new Arr((function() {
- var _k, _len3, _ref4, _results;
- _ref4 = this.params;
+ var _l, _len3, _ref5, _results;
+ _ref5 = this.params;
_results = [];
- for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) {
- p = _ref4[_k];
+ for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
+ p = _ref5[_l];
_results.push(p.asReference(o));
}
return _results;
}).call(this))), new Value(new Literal('arguments')));
break;
}
- _ref4 = this.params;
- for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) {
- param = _ref4[_k];
+ _ref5 = this.params;
+ for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
+ param = _ref5[_l];
if (param.isComplex()) {
val = ref = param.asReference(o);
- if (param.value) val = new Op('?', ref, param.value);
+ if (param.value) {
+ val = new Op('?', ref, param.value);
+ }
exprs.push(new Assign(new Value(param.name), val, '=', {
param: true
}));
@@ -1516,36 +1792,53 @@
exprs.push(new If(lit, val));
}
}
- if (!splats) vars.push(ref);
+ if (!splats) {
+ params.push(ref);
+ }
}
wasEmpty = this.body.isEmpty();
- if (splats) exprs.unshift(splats);
- if (exprs.length) {
- (_ref5 = this.body.expressions).unshift.apply(_ref5, exprs);
+ if (splats) {
+ exprs.unshift(splats);
}
- if (!splats) {
- for (i = 0, _len4 = vars.length; i < _len4; i++) {
- v = vars[i];
- o.scope.parameter(vars[i] = v.compile(o));
+ if (exprs.length) {
+ (_ref6 = this.body.expressions).unshift.apply(_ref6, exprs);
+ }
+ for (i = _m = 0, _len4 = params.length; _m < _len4; i = ++_m) {
+ p = params[i];
+ o.scope.parameter(params[i] = p.compile(o));
+ }
+ uniqs = [];
+ _ref7 = this.paramNames();
+ for (_n = 0, _len5 = _ref7.length; _n < _len5; _n++) {
+ name = _ref7[_n];
+ if (__indexOf.call(uniqs, name) >= 0) {
+ throw SyntaxError("multiple parameters named '" + name + "'");
}
+ uniqs.push(name);
+ }
+ if (!(wasEmpty || this.noReturn)) {
+ this.body.makeReturn();
}
- if (!(wasEmpty || this.noReturn)) this.body.makeReturn();
if (this.bound) {
- if ((_ref6 = o.scope.parent.method) != null ? _ref6.bound : void 0) {
+ if ((_ref8 = o.scope.parent.method) != null ? _ref8.bound : void 0) {
this.bound = this.context = o.scope.parent.method.context;
- } else if (!this.static) {
+ } else if (!this["static"]) {
o.scope.parent.assign('_this', 'this');
}
}
idt = o.indent;
code = 'function';
- if (this.ctor) code += ' ' + this.name;
- code += '(' + vars.join(', ') + ') {';
+ if (this.ctor) {
+ code += ' ' + this.name;
+ }
+ code += '(' + params.join(', ') + ') {';
if (!this.body.isEmpty()) {
code += "\n" + (this.body.compileWithDeclarations(o)) + "\n" + this.tab;
}
code += '}';
- if (this.ctor) return this.tab + code;
+ if (this.ctor) {
+ return this.tab + code;
+ }
if (this.front || (o.level >= LEVEL_ACCESS)) {
return "(" + code + ")";
} else {
@@ -1553,6 +1846,17 @@
}
};
+ Code.prototype.paramNames = function() {
+ var names, param, _i, _len, _ref2;
+ names = [];
+ _ref2 = this.params;
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ param = _ref2[_i];
+ names.push.apply(names, param.names());
+ }
+ return names;
+ };
+
Code.prototype.traverseChildren = function(crossScope, func) {
if (crossScope) {
return Code.__super__.traverseChildren.call(this, crossScope, func);
@@ -1568,9 +1872,13 @@
__extends(Param, _super);
function Param(name, value, splat) {
+ var _ref2;
this.name = name;
this.value = value;
this.splat = splat;
+ if (_ref2 = (name = this.name.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0) {
+ throw SyntaxError("parameter name \"" + name + "\" is not allowed");
+ }
}
Param.prototype.children = ['name', 'value'];
@@ -1581,16 +1889,22 @@
Param.prototype.asReference = function(o) {
var node;
- if (this.reference) return this.reference;
+ if (this.reference) {
+ return this.reference;
+ }
node = this.name;
if (node["this"]) {
node = node.properties[0].name;
- if (node.value.reserved) node = new Literal('_' + node.value);
+ if (node.value.reserved) {
+ node = new Literal(o.scope.freeVariable(node.value));
+ }
} else if (node.isComplex()) {
node = new Literal(o.scope.freeVariable('arg'));
}
node = new Value(node);
- if (this.splat) node = new Splat(node);
+ if (this.splat) {
+ node = new Splat(node);
+ }
return this.reference = node;
};
@@ -1598,6 +1912,49 @@
return this.name.isComplex();
};
+ Param.prototype.names = function(name) {
+ var atParam, names, obj, _i, _len, _ref2;
+ if (name == null) {
+ name = this.name;
+ }
+ atParam = function(obj) {
+ var value;
+ value = obj.properties[0].name.value;
+ if (value.reserved) {
+ return [];
+ } else {
+ return [value];
+ }
+ };
+ if (name instanceof Literal) {
+ return [name.value];
+ }
+ if (name instanceof Value) {
+ return atParam(name);
+ }
+ names = [];
+ _ref2 = name.objects;
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ obj = _ref2[_i];
+ if (obj instanceof Assign) {
+ names.push(obj.value.unwrap().value);
+ } else if (obj instanceof Splat) {
+ names.push(obj.name.unwrap().value);
+ } else if (obj instanceof Value) {
+ if (obj.isArray() || obj.isObject()) {
+ names.push.apply(names, this.names(obj.base));
+ } else if (obj["this"]) {
+ names.push.apply(names, atParam(obj));
+ } else {
+ names.push(obj.base.value);
+ }
+ } else {
+ throw SyntaxError("illegal parameter " + (obj.compile()));
+ }
+ }
+ return names;
+ };
+
return Param;
})(Base);
@@ -1631,19 +1988,23 @@
};
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;
}
- if (index >= list.length) return '';
+ if (index >= list.length) {
+ return '';
+ }
if (list.length === 1) {
code = list[0].compile(o, LEVEL_LIST);
- if (apply) return code;
+ if (apply) {
+ return code;
+ }
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 + "]";
@@ -1652,11 +2013,11 @@
return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")");
}
base = (function() {
- var _i, _len2, _ref2, _results;
+ var _j, _len1, _ref2, _results;
_ref2 = list.slice(0, index);
_results = [];
- for (_i = 0, _len2 = _ref2.length; _i < _len2; _i++) {
- node = _ref2[_i];
+ for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
+ node = _ref2[_j];
_results.push(node.compile(o, LEVEL_LIST));
}
return _results;
@@ -1700,12 +2061,16 @@
While.prototype.jumps = function() {
var expressions, node, _i, _len;
expressions = this.body.expressions;
- if (!expressions.length) return false;
+ if (!expressions.length) {
+ return false;
+ }
for (_i = 0, _len = expressions.length; _i < _len; _i++) {
node = expressions[_i];
if (node.jumps({
loop: true
- })) return node;
+ })) {
+ return node;
+ }
}
return false;
};
@@ -1726,13 +2091,17 @@
if (body.expressions.length > 1) {
body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
} else {
- if (this.guard) body = Block.wrap([new If(this.guard, body)]);
+ if (this.guard) {
+ body = Block.wrap([new If(this.guard, body)]);
+ }
}
}
body = "\n" + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab;
}
code = set + this.tab + ("while (" + (this.condition.compile(o, LEVEL_PAREN)) + ") {" + body + "}");
- if (this.returns) code += "\n" + this.tab + "return " + rvar + ";";
+ if (this.returns) {
+ code += "\n" + this.tab + "return " + rvar + ";";
+ }
return code;
};
@@ -1746,12 +2115,11 @@
__extends(Op, _super);
function Op(op, first, second, flip) {
- var call;
- if (op === 'in') return new In(first, second);
+ if (op === 'in') {
+ return new In(first, second);
+ }
if (op === 'do') {
- call = new Call(first, first.params || []);
- call["do"] = true;
- return call;
+ return this.generateDo(first);
}
if (op === 'new') {
if (first instanceof Call && !first["do"] && !first.isNew) {
@@ -1806,7 +2174,9 @@
allInvertable && (allInvertable = curr.operator in INVERSIONS);
curr = curr.first;
}
- if (!allInvertable) return new Parens(this).invert();
+ if (!allInvertable) {
+ return new Parens(this).invert();
+ }
curr = this;
while (curr && curr.operator) {
curr.invert = !curr.invert;
@@ -1816,7 +2186,9 @@
return this;
} else if (op = INVERSIONS[this.operator]) {
this.operator = op;
- if (this.first.unwrap() instanceof Op) this.first.invert();
+ if (this.first.unwrap() instanceof Op) {
+ this.first.invert();
+ }
return this;
} else if (this.second) {
return new Parens(this).invert();
@@ -1832,13 +2204,46 @@
return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first');
};
+ Op.prototype.generateDo = function(exp) {
+ var call, func, param, passedParams, ref, _i, _len, _ref2;
+ 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++) {
+ param = _ref2[_i];
+ if (param.value) {
+ passedParams.push(param.value);
+ delete param.value;
+ } else {
+ passedParams.push(param);
+ }
+ }
+ call = new Call(exp, passedParams);
+ call["do"] = true;
+ return call;
+ };
+
Op.prototype.compileNode = function(o) {
- var code, isChain;
+ var code, isChain, _ref2, _ref3;
isChain = this.isChainable() && this.first.isChainable();
- if (!isChain) this.first.front = this.front;
- if (this.isUnary()) return this.compileUnary(o);
- if (isChain) return this.compileChain(o);
- if (this.operator === '?') return this.compileExistence(o);
+ if (!isChain) {
+ this.first.front = this.front;
+ }
+ if (this.operator === 'delete' && o.scope.check(this.first.unwrapAll().value)) {
+ throw SyntaxError('delete operand may not be argument or var');
+ }
+ if (((_ref2 = this.operator) === '--' || _ref2 === '++') && (_ref3 = this.first.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0)) {
+ throw SyntaxError('prefix increment/decrement may not have eval or arguments operand');
+ }
+ if (this.isUnary()) {
+ return this.compileUnary(o);
+ }
+ if (isChain) {
+ return this.compileChain(o);
+ }
+ if (this.operator === '?') {
+ return this.compileExistence(o);
+ }
code = this.first.compile(o, LEVEL_OP) + ' ' + this.operator + ' ' + this.second.compile(o, LEVEL_OP);
if (o.level <= LEVEL_OP) {
return code;
@@ -1857,7 +2262,7 @@
Op.prototype.compileExistence = function(o) {
var fst, ref;
- if (this.first.isComplex() && o.level > LEVEL_TOP) {
+ if (this.first.isComplex()) {
ref = new Literal(o.scope.freeVariable('ref'));
fst = new Parens(new Assign(ref, this.first));
} else {
@@ -1871,6 +2276,9 @@
Op.prototype.compileUnary = function(o) {
var op, parts, plusMinus;
+ if (o.level >= LEVEL_ACCESS) {
+ return (new Parens(this)).compile(o);
+ }
parts = [op = this.operator];
plusMinus = op === '+' || op === '-';
if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {
@@ -1880,7 +2288,9 @@
this.first = new Parens(this.first);
}
parts.push(this.first.compile(o, LEVEL_OP));
- if (this.flip) parts.reverse();
+ if (this.flip) {
+ parts.reverse();
+ }
return parts.join('');
};
@@ -1911,25 +2321,31 @@
_ref2 = this.array.base.objects;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
obj = _ref2[_i];
- if (!(obj instanceof Splat)) continue;
+ if (!(obj instanceof Splat)) {
+ continue;
+ }
hasSplat = true;
break;
}
- if (!hasSplat) return this.compileOrTest(o);
+ if (!hasSplat) {
+ return this.compileOrTest(o);
+ }
}
return this.compileLoopTest(o);
};
In.prototype.compileOrTest = function(o) {
var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3;
- if (this.array.base.objects.length === 0) return "" + (!!this.negated);
+ if (this.array.base.objects.length === 0) {
+ return "" + (!!this.negated);
+ }
_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));
}
@@ -1947,7 +2363,9 @@
var code, ref, sub, _ref2;
_ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1];
code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0');
- if (sub === ref) return code;
+ if (sub === ref) {
+ return code;
+ }
code = sub + ', ' + code;
if (o.level < LEVEL_LIST) {
return code;
@@ -1985,8 +2403,12 @@
};
Try.prototype.makeReturn = function(res) {
- if (this.attempt) this.attempt = this.attempt.makeReturn(res);
- if (this.recovery) this.recovery = this.recovery.makeReturn(res);
+ if (this.attempt) {
+ this.attempt = this.attempt.makeReturn(res);
+ }
+ if (this.recovery) {
+ this.recovery = this.recovery.makeReturn(res);
+ }
return this;
};
@@ -1995,7 +2417,20 @@
o.indent += TAB;
errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
tryPart = this.attempt.compile(o, LEVEL_TOP);
- catchPart = this.recovery ? (!o.scope.check(this.error.value) ? o.scope.add(this.error.value, 'param') : void 0, " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}") : !(this.ensure || this.recovery) ? ' catch (_error) {}' : void 0;
+ catchPart = (function() {
+ var _ref2;
+ if (this.recovery) {
+ if (_ref2 = this.error.value, __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0) {
+ throw SyntaxError("catch variable may not be \"" + this.error.value + "\"");
+ }
+ if (!o.scope.check(this.error.value)) {
+ o.scope.add(this.error.value, 'param');
+ }
+ return " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}";
+ } else if (!(this.ensure || this.recovery)) {
+ return ' catch (_error) {}';
+ }
+ }).call(this);
ensurePart = this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : '';
return "" + this.tab + "try {\n" + tryPart + "\n" + this.tab + "}" + (catchPart || '') + ensurePart;
};
@@ -2129,28 +2564,34 @@
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;
+ if (lastJumps && lastJumps instanceof Return) {
+ this.returns = false;
+ }
source = this.range ? this.source.base : this.source;
scope = o.scope;
name = this.name && this.name.compile(o, LEVEL_LIST);
index = this.index && this.index.compile(o, LEVEL_LIST);
if (name && !this.pattern) {
- scope.find(name, {
- immediate: true
- });
+ scope.find(name);
}
if (index) {
- scope.find(index, {
- immediate: true
- });
+ scope.find(index);
+ }
+ if (this.returns) {
+ rvar = scope.freeVariable('results');
+ }
+ 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;
}
- if (this.returns) rvar = scope.freeVariable('results');
- ivar = (this.range ? name : index) || scope.freeVariable('i');
- if (this.step && !this.range) stepvar = scope.freeVariable("step");
- if (this.pattern) name = ivar;
varPart = '';
guardPart = '';
defPart = '';
@@ -2158,6 +2599,7 @@
if (this.range) {
forPart = source.compile(merge(o, {
index: ivar,
+ name: name,
step: this.step
}));
} else {
@@ -2167,12 +2609,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 : (kvar !== ivar ? "++" + ivar : "" + ivar + "++"));
forPart = "" + forVarPart + "; " + ivar + " < " + lvar + "; " + stepPart;
}
}
@@ -2185,35 +2630,43 @@
if (body.expressions.length > 1) {
body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
} else {
- if (this.guard) body = Block.wrap([new If(this.guard, body)]);
+ if (this.guard) {
+ body = Block.wrap([new If(this.guard, body)]);
+ }
}
}
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 (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, {
indent: idt1
}), LEVEL_TOP);
- if (body) body = '\n' + body + '\n';
+ if (body) {
+ body = '\n' + body + '\n';
+ }
return "" + defPart + (resultPart || '') + this.tab + "for (" + forPart + ") {" + guardPart + varPart + body + this.tab + "}" + (returnResult || '');
};
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;
+ if (!(expr instanceof Call)) {
+ continue;
+ }
val = expr.variable.unwrapAll();
if (!((val instanceof Code) || (val instanceof Value && ((_ref3 = val.base) != null ? _ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref4 = (_ref5 = val.properties[0].name) != null ? _ref5.value : void 0) === 'call' || _ref4 === 'apply')))) {
continue;
@@ -2221,7 +2674,9 @@
fn = ((_ref6 = val.base) != null ? _ref6.unwrapAll() : void 0) || val;
ref = new Literal(o.scope.freeVariable('fn'));
base = new Value(ref);
- if (val.base) _ref7 = [base, val], val.base = _ref7[0], base = _ref7[1];
+ if (val.base) {
+ _ref7 = [base, val], val.base = _ref7[0], base = _ref7[1];
+ }
body.expressions[idx] = new Call(base, expr.args);
defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n';
}
@@ -2256,7 +2711,9 @@
_ref2 = this.cases;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
_ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1];
- if (block.jumps(o)) return block;
+ if (block.jumps(o)) {
+ return block;
+ }
}
return (_ref4 = this.otherwise) != null ? _ref4.jumps(o) : void 0;
};
@@ -2271,26 +2728,34 @@
if (res) {
this.otherwise || (this.otherwise = new Block([new Literal('void 0')]));
}
- if ((_ref3 = this.otherwise) != null) _ref3.makeReturn(res);
+ if ((_ref3 = this.otherwise) != null) {
+ _ref3.makeReturn(res);
+ }
return this;
};
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, _len1, _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];
- if (!this.subject) cond = cond.invert();
+ for (_j = 0, _len1 = _ref5.length; _j < _len1; _j++) {
+ cond = _ref5[_j];
+ if (!this.subject) {
+ cond = cond.invert();
+ }
code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
}
- if (body = block.compile(o, LEVEL_TOP)) code += body + '\n';
- if (i === this.cases.length - 1 && !this.otherwise) break;
+ if (body = block.compile(o, LEVEL_TOP)) {
+ code += body + '\n';
+ }
+ if (i === this.cases.length - 1 && !this.otherwise) {
+ break;
+ }
expr = this.lastNonComment(block.expressions);
if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) {
continue;
@@ -2313,7 +2778,9 @@
function If(condition, body, options) {
this.body = body;
- if (options == null) options = {};
+ if (options == null) {
+ options = {};
+ }
this.condition = options.type === 'unless' ? condition.invert() : condition;
this.elseBody = null;
this.isChain = false;
@@ -2378,7 +2845,7 @@
};
If.prototype.compileStatement = function(o) {
- var body, bodyc, child, cond, exeq, ifPart, _ref2;
+ var body, child, cond, exeq, ifPart;
child = del(o, 'chainChild');
exeq = del(o, 'isExistentialEquals');
if (exeq) {
@@ -2389,14 +2856,13 @@
cond = this.condition.compile(o, LEVEL_PAREN);
o.indent += TAB;
body = this.ensureBlock(this.body);
- bodyc = body.compile(o);
- if (1 === ((_ref2 = body.expressions) != null ? _ref2.length : void 0) && !this.elseBody && !child && bodyc && cond && -1 === (bodyc.indexOf('\n')) && 80 > cond.length + bodyc.length) {
- return "" + this.tab + "if (" + cond + ") " + (bodyc.replace(/^\s+/, ''));
- }
- if (bodyc) bodyc = "\n" + bodyc + "\n" + this.tab;
- ifPart = "if (" + cond + ") {" + bodyc + "}";
- if (!child) ifPart = this.tab + ifPart;
- if (!this.elseBody) return ifPart;
+ ifPart = "if (" + cond + ") {\n" + (body.compile(o)) + "\n" + this.tab + "}";
+ if (!child) {
+ ifPart = this.tab + ifPart;
+ }
+ if (!this.elseBody) {
+ return ifPart;
+ }
return ifPart + ' else ' + (this.isChain ? (o.indent = this.tab, o.chainChild = true, this.elseBody.unwrap().compile(o, LEVEL_TOP)) : "{\n" + (this.elseBody.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}");
};
@@ -2424,13 +2890,17 @@
Closure = {
wrap: function(expressions, statement, noReturn) {
var args, call, func, mentionsArgs, meth;
- if (expressions.jumps()) return expressions;
+ if (expressions.jumps()) {
+ return expressions;
+ }
func = new Code([], Block.wrap([expressions]));
args = [];
if ((mentionsArgs = expressions.contains(this.literalArgs)) || expressions.contains(this.literalThis)) {
meth = new Literal(mentionsArgs ? 'apply' : 'call');
args = [new Literal('this')];
- if (mentionsArgs) args.push(new Literal('arguments'));
+ if (mentionsArgs) {
+ args.push(new Literal('arguments'));
+ }
func = new Value(func, [new Access(meth)]);
}
func.noReturn = noReturn;
@@ -2445,13 +2915,15 @@
return node instanceof Literal && node.value === 'arguments' && !node.asKey;
},
literalThis: function(node) {
- return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound);
+ return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound) || (node instanceof Call && node.isSuper);
}
};
unfoldSoak = function(o, parent, name) {
var ifn;
- if (!(ifn = parent[name].unfoldSoak(o))) return;
+ if (!(ifn = parent[name].unfoldSoak(o))) {
+ return;
+ }
parent[name] = ifn.body;
ifn.body = new Value(parent);
return ifn;
@@ -2459,19 +2931,19 @@
UTILITIES = {
"extends": function() {
- return "function(child, parent) { for (var key in parent) { if (" + (utility('hasProp')) + ".call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }";
+ return "function(child, parent) { for (var key in parent) { if (" + (utility('hasProp')) + ".call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }";
},
bind: function() {
return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';
},
indexOf: function() {
- return "Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";
+ return "[].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";
},
hasProp: function() {
- return 'Object.prototype.hasOwnProperty';
+ return '{}.hasOwnProperty';
},
slice: function() {
- return 'Array.prototype.slice';
+ return '[].slice';
}
};
http://git-wip-us.apache.org/repos/asf/incubator-cordova-weinre/blob/4d3b995f/weinre.server/node_modules/coffee-script/lib/coffee-script/optparse.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/coffee-script/lib/coffee-script/optparse.js b/weinre.server/node_modules/coffee-script/lib/coffee-script/optparse.js
index 5e0114c..d7fda40 100644
--- a/weinre.server/node_modules/coffee-script/lib/coffee-script/optparse.js
+++ b/weinre.server/node_modules/coffee-script/lib/coffee-script/optparse.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
(function() {
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments;
@@ -9,39 +10,48 @@
}
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, seenNonOptionArg, skippingArgument, value, _i, _j, _len, _len1, _ref;
options = {
- arguments: [],
- literals: []
+ "arguments": []
};
+ 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]];
- options.literals = originalArgs.slice(2 + pos);
+ options["arguments"] = options["arguments"].concat(originalArgs.slice(pos + 1));
break;
}
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];
- if (rule.shortFlag === arg || rule.longFlag === arg) {
- value = rule.hasArgument ? args[i += 1] : true;
- options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value;
- matchedRule = true;
- break;
+ seenNonOptionArg = options["arguments"].length > 0;
+ if (!seenNonOptionArg) {
+ matchedRule = false;
+ _ref = this.rules;
+ for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
+ rule = _ref[_j];
+ if (rule.shortFlag === arg || rule.longFlag === arg) {
+ value = true;
+ if (rule.hasArgument) {
+ skippingArgument = true;
+ value = args[i + 1];
+ }
+ options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value;
+ matchedRule = true;
+ break;
+ }
+ }
+ if (isOption && !matchedRule) {
+ throw new Error("unrecognized option: " + arg);
}
}
- if (isOption && !matchedRule) {
- throw new Error("unrecognized option: " + arg);
- }
- if (!isOption) {
- options.arguments = originalArgs.slice(originalArgs.indexOf(arg));
- break;
+ if (seenNonOptionArg || !isOption) {
+ options["arguments"].push(arg);
}
}
return options;
@@ -50,7 +60,9 @@
OptionParser.prototype.help = function() {
var letPart, lines, rule, spaces, _i, _len, _ref;
lines = [];
- if (this.banner) lines.unshift("" + this.banner + "\n");
+ if (this.banner) {
+ lines.unshift("" + this.banner + "\n");
+ }
_ref = this.rules;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
rule = _ref[_i];
@@ -66,9 +78,9 @@
})();
- LONG_FLAG = /^(--\w[\w\-]+)/;
+ LONG_FLAG = /^(--\w[\w\-]*)/;
- SHORT_FLAG = /^(-\w)/;
+ SHORT_FLAG = /^(-\w)$/;
MULTI_FLAG = /^-(\w{2,})/;
@@ -79,7 +91,9 @@
_results = [];
for (_i = 0, _len = rules.length; _i < _len; _i++) {
tuple = rules[_i];
- if (tuple.length < 3) tuple.unshift(null);
+ if (tuple.length < 3) {
+ tuple.unshift(null);
+ }
_results.push(buildRule.apply(null, tuple));
}
return _results;
@@ -87,7 +101,9 @@
buildRule = function(shortFlag, longFlag, description, options) {
var match;
- if (options == null) options = {};
+ if (options == null) {
+ options = {};
+ }
match = longFlag.match(OPTIONAL);
longFlag = longFlag.match(LONG_FLAG)[1];
return {
@@ -101,14 +117,14 @@
};
normalizeArguments = function(args) {
- var arg, l, match, result, _i, _j, _len, _len2, _ref;
+ var arg, l, match, result, _i, _j, _len, _len1, _ref;
args = args.slice(0);
result = [];
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, _len1 = _ref.length; _j < _len1; _j++) {
l = _ref[_j];
result.push('-' + l);
}