react / wstein / node_modules / jest-cli / node_modules / jasmine-only / node_modules / coffee-script / lib / coffee-script / nodes.js
81146 views// Generated by CoffeeScript 1.6.31(function() {2var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, CodeFragment, 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, addLocationDataFn, compact, del, ends, extend, flatten, fragmentsToText, last, locationDataToString, merge, multident, some, starts, throwSyntaxError, unfoldSoak, utility, _ref, _ref1, _ref2, _ref3,3__hasProp = {}.hasOwnProperty,4__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; },5__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; },6__slice = [].slice;78Error.stackTraceLimit = Infinity;910Scope = require('./scope').Scope;1112_ref = require('./lexer'), RESERVED = _ref.RESERVED, STRICT_PROSCRIBED = _ref.STRICT_PROSCRIBED;1314_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, some = _ref1.some, addLocationDataFn = _ref1.addLocationDataFn, locationDataToString = _ref1.locationDataToString, throwSyntaxError = _ref1.throwSyntaxError;1516exports.extend = extend;1718exports.addLocationDataFn = addLocationDataFn;1920YES = function() {21return true;22};2324NO = function() {25return false;26};2728THIS = function() {29return this;30};3132NEGATE = function() {33this.negated = !this.negated;34return this;35};3637exports.CodeFragment = CodeFragment = (function() {38function CodeFragment(parent, code) {39var _ref2;40this.code = "" + code;41this.locationData = parent != null ? parent.locationData : void 0;42this.type = (parent != null ? (_ref2 = parent.constructor) != null ? _ref2.name : void 0 : void 0) || 'unknown';43}4445CodeFragment.prototype.toString = function() {46return "" + this.code + (this.locationData ? ": " + locationDataToString(this.locationData) : '');47};4849return CodeFragment;5051})();5253fragmentsToText = function(fragments) {54var fragment;55return ((function() {56var _i, _len, _results;57_results = [];58for (_i = 0, _len = fragments.length; _i < _len; _i++) {59fragment = fragments[_i];60_results.push(fragment.code);61}62return _results;63})()).join('');64};6566exports.Base = Base = (function() {67function Base() {}6869Base.prototype.compile = function(o, lvl) {70return fragmentsToText(this.compileToFragments(o, lvl));71};7273Base.prototype.compileToFragments = function(o, lvl) {74var node;75o = extend({}, o);76if (lvl) {77o.level = lvl;78}79node = this.unfoldSoak(o) || this;80node.tab = o.indent;81if (o.level === LEVEL_TOP || !node.isStatement(o)) {82return node.compileNode(o);83} else {84return node.compileClosure(o);85}86};8788Base.prototype.compileClosure = function(o) {89var jumpNode;90if (jumpNode = this.jumps()) {91jumpNode.error('cannot use a pure statement in an expression');92}93o.sharedScope = true;94return Closure.wrap(this).compileNode(o);95};9697Base.prototype.cache = function(o, level, reused) {98var ref, sub;99if (!this.isComplex()) {100ref = level ? this.compileToFragments(o, level) : this;101return [ref, ref];102} else {103ref = new Literal(reused || o.scope.freeVariable('ref'));104sub = new Assign(ref, this);105if (level) {106return [sub.compileToFragments(o, level), [this.makeCode(ref.value)]];107} else {108return [sub, ref];109}110}111};112113Base.prototype.cacheToCodeFragments = function(cacheValues) {114return [fragmentsToText(cacheValues[0]), fragmentsToText(cacheValues[1])];115};116117Base.prototype.makeReturn = function(res) {118var me;119me = this.unwrapAll();120if (res) {121return new Call(new Literal("" + res + ".push"), [me]);122} else {123return new Return(me);124}125};126127Base.prototype.contains = function(pred) {128var node;129node = void 0;130this.traverseChildren(false, function(n) {131if (pred(n)) {132node = n;133return false;134}135});136return node;137};138139Base.prototype.lastNonComment = function(list) {140var i;141i = list.length;142while (i--) {143if (!(list[i] instanceof Comment)) {144return list[i];145}146}147return null;148};149150Base.prototype.toString = function(idt, name) {151var tree;152if (idt == null) {153idt = '';154}155if (name == null) {156name = this.constructor.name;157}158tree = '\n' + idt + name;159if (this.soak) {160tree += '?';161}162this.eachChild(function(node) {163return tree += node.toString(idt + TAB);164});165return tree;166};167168Base.prototype.eachChild = function(func) {169var attr, child, _i, _j, _len, _len1, _ref2, _ref3;170if (!this.children) {171return this;172}173_ref2 = this.children;174for (_i = 0, _len = _ref2.length; _i < _len; _i++) {175attr = _ref2[_i];176if (this[attr]) {177_ref3 = flatten([this[attr]]);178for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {179child = _ref3[_j];180if (func(child) === false) {181return this;182}183}184}185}186return this;187};188189Base.prototype.traverseChildren = function(crossScope, func) {190return this.eachChild(function(child) {191var recur;192recur = func(child);193if (recur !== false) {194return child.traverseChildren(crossScope, func);195}196});197};198199Base.prototype.invert = function() {200return new Op('!', this);201};202203Base.prototype.unwrapAll = function() {204var node;205node = this;206while (node !== (node = node.unwrap())) {207continue;208}209return node;210};211212Base.prototype.children = [];213214Base.prototype.isStatement = NO;215216Base.prototype.jumps = NO;217218Base.prototype.isComplex = YES;219220Base.prototype.isChainable = NO;221222Base.prototype.isAssignable = NO;223224Base.prototype.unwrap = THIS;225226Base.prototype.unfoldSoak = NO;227228Base.prototype.assigns = NO;229230Base.prototype.updateLocationDataIfMissing = function(locationData) {231this.locationData || (this.locationData = locationData);232return this.eachChild(function(child) {233return child.updateLocationDataIfMissing(locationData);234});235};236237Base.prototype.error = function(message) {238return throwSyntaxError(message, this.locationData);239};240241Base.prototype.makeCode = function(code) {242return new CodeFragment(this, code);243};244245Base.prototype.wrapInBraces = function(fragments) {246return [].concat(this.makeCode('('), fragments, this.makeCode(')'));247};248249Base.prototype.joinFragmentArrays = function(fragmentsList, joinStr) {250var answer, fragments, i, _i, _len;251answer = [];252for (i = _i = 0, _len = fragmentsList.length; _i < _len; i = ++_i) {253fragments = fragmentsList[i];254if (i) {255answer.push(this.makeCode(joinStr));256}257answer = answer.concat(fragments);258}259return answer;260};261262return Base;263264})();265266exports.Block = Block = (function(_super) {267__extends(Block, _super);268269function Block(nodes) {270this.expressions = compact(flatten(nodes || []));271}272273Block.prototype.children = ['expressions'];274275Block.prototype.push = function(node) {276this.expressions.push(node);277return this;278};279280Block.prototype.pop = function() {281return this.expressions.pop();282};283284Block.prototype.unshift = function(node) {285this.expressions.unshift(node);286return this;287};288289Block.prototype.unwrap = function() {290if (this.expressions.length === 1) {291return this.expressions[0];292} else {293return this;294}295};296297Block.prototype.isEmpty = function() {298return !this.expressions.length;299};300301Block.prototype.isStatement = function(o) {302var exp, _i, _len, _ref2;303_ref2 = this.expressions;304for (_i = 0, _len = _ref2.length; _i < _len; _i++) {305exp = _ref2[_i];306if (exp.isStatement(o)) {307return true;308}309}310return false;311};312313Block.prototype.jumps = function(o) {314var exp, _i, _len, _ref2;315_ref2 = this.expressions;316for (_i = 0, _len = _ref2.length; _i < _len; _i++) {317exp = _ref2[_i];318if (exp.jumps(o)) {319return exp;320}321}322};323324Block.prototype.makeReturn = function(res) {325var expr, len;326len = this.expressions.length;327while (len--) {328expr = this.expressions[len];329if (!(expr instanceof Comment)) {330this.expressions[len] = expr.makeReturn(res);331if (expr instanceof Return && !expr.expression) {332this.expressions.splice(len, 1);333}334break;335}336}337return this;338};339340Block.prototype.compileToFragments = function(o, level) {341if (o == null) {342o = {};343}344if (o.scope) {345return Block.__super__.compileToFragments.call(this, o, level);346} else {347return this.compileRoot(o);348}349};350351Block.prototype.compileNode = function(o) {352var answer, compiledNodes, fragments, index, node, top, _i, _len, _ref2;353this.tab = o.indent;354top = o.level === LEVEL_TOP;355compiledNodes = [];356_ref2 = this.expressions;357for (index = _i = 0, _len = _ref2.length; _i < _len; index = ++_i) {358node = _ref2[index];359node = node.unwrapAll();360node = node.unfoldSoak(o) || node;361if (node instanceof Block) {362compiledNodes.push(node.compileNode(o));363} else if (top) {364node.front = true;365fragments = node.compileToFragments(o);366if (!node.isStatement(o)) {367fragments.unshift(this.makeCode("" + this.tab));368fragments.push(this.makeCode(";"));369}370compiledNodes.push(fragments);371} else {372compiledNodes.push(node.compileToFragments(o, LEVEL_LIST));373}374}375if (top) {376if (this.spaced) {377return [].concat(this.joinFragmentArrays(compiledNodes, '\n\n'), this.makeCode("\n"));378} else {379return this.joinFragmentArrays(compiledNodes, '\n');380}381}382if (compiledNodes.length) {383answer = this.joinFragmentArrays(compiledNodes, ', ');384} else {385answer = [this.makeCode("void 0")];386}387if (compiledNodes.length > 1 && o.level >= LEVEL_LIST) {388return this.wrapInBraces(answer);389} else {390return answer;391}392};393394Block.prototype.compileRoot = function(o) {395var exp, fragments, i, name, prelude, preludeExps, rest, _i, _len, _ref2;396o.indent = o.bare ? '' : TAB;397o.level = LEVEL_TOP;398this.spaced = true;399o.scope = new Scope(null, this, null);400_ref2 = o.locals || [];401for (_i = 0, _len = _ref2.length; _i < _len; _i++) {402name = _ref2[_i];403o.scope.parameter(name);404}405prelude = [];406if (!o.bare) {407preludeExps = (function() {408var _j, _len1, _ref3, _results;409_ref3 = this.expressions;410_results = [];411for (i = _j = 0, _len1 = _ref3.length; _j < _len1; i = ++_j) {412exp = _ref3[i];413if (!(exp.unwrap() instanceof Comment)) {414break;415}416_results.push(exp);417}418return _results;419}).call(this);420rest = this.expressions.slice(preludeExps.length);421this.expressions = preludeExps;422if (preludeExps.length) {423prelude = this.compileNode(merge(o, {424indent: ''425}));426prelude.push(this.makeCode("\n"));427}428this.expressions = rest;429}430fragments = this.compileWithDeclarations(o);431if (o.bare) {432return fragments;433}434return [].concat(prelude, this.makeCode("(function() {\n"), fragments, this.makeCode("\n}).call(this);\n"));435};436437Block.prototype.compileWithDeclarations = function(o) {438var assigns, declars, exp, fragments, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;439fragments = [];440post = [];441_ref2 = this.expressions;442for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {443exp = _ref2[i];444exp = exp.unwrap();445if (!(exp instanceof Comment || exp instanceof Literal)) {446break;447}448}449o = merge(o, {450level: LEVEL_TOP451});452if (i) {453rest = this.expressions.splice(i, 9e9);454_ref3 = [this.spaced, false], spaced = _ref3[0], this.spaced = _ref3[1];455_ref4 = [this.compileNode(o), spaced], fragments = _ref4[0], this.spaced = _ref4[1];456this.expressions = rest;457}458post = this.compileNode(o);459scope = o.scope;460if (scope.expressions === this) {461declars = o.scope.hasDeclarations();462assigns = scope.hasAssignments;463if (declars || assigns) {464if (i) {465fragments.push(this.makeCode('\n'));466}467fragments.push(this.makeCode("" + this.tab + "var "));468if (declars) {469fragments.push(this.makeCode(scope.declaredVariables().join(', ')));470}471if (assigns) {472if (declars) {473fragments.push(this.makeCode(",\n" + (this.tab + TAB)));474}475fragments.push(this.makeCode(scope.assignedVariables().join(",\n" + (this.tab + TAB))));476}477fragments.push(this.makeCode(";\n" + (this.spaced ? '\n' : '')));478} else if (fragments.length && post.length) {479fragments.push(this.makeCode("\n"));480}481}482return fragments.concat(post);483};484485Block.wrap = function(nodes) {486if (nodes.length === 1 && nodes[0] instanceof Block) {487return nodes[0];488}489return new Block(nodes);490};491492return Block;493494})(Base);495496exports.Literal = Literal = (function(_super) {497__extends(Literal, _super);498499function Literal(value) {500this.value = value;501}502503Literal.prototype.makeReturn = function() {504if (this.isStatement()) {505return this;506} else {507return Literal.__super__.makeReturn.apply(this, arguments);508}509};510511Literal.prototype.isAssignable = function() {512return IDENTIFIER.test(this.value);513};514515Literal.prototype.isStatement = function() {516var _ref2;517return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';518};519520Literal.prototype.isComplex = NO;521522Literal.prototype.assigns = function(name) {523return name === this.value;524};525526Literal.prototype.jumps = function(o) {527if (this.value === 'break' && !((o != null ? o.loop : void 0) || (o != null ? o.block : void 0))) {528return this;529}530if (this.value === 'continue' && !(o != null ? o.loop : void 0)) {531return this;532}533};534535Literal.prototype.compileNode = function(o) {536var answer, code, _ref2;537code = 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;538answer = this.isStatement() ? "" + this.tab + code + ";" : code;539return [this.makeCode(answer)];540};541542Literal.prototype.toString = function() {543return ' "' + this.value + '"';544};545546return Literal;547548})(Base);549550exports.Undefined = (function(_super) {551__extends(Undefined, _super);552553function Undefined() {554_ref2 = Undefined.__super__.constructor.apply(this, arguments);555return _ref2;556}557558Undefined.prototype.isAssignable = NO;559560Undefined.prototype.isComplex = NO;561562Undefined.prototype.compileNode = function(o) {563return [this.makeCode(o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0')];564};565566return Undefined;567568})(Base);569570exports.Null = (function(_super) {571__extends(Null, _super);572573function Null() {574_ref3 = Null.__super__.constructor.apply(this, arguments);575return _ref3;576}577578Null.prototype.isAssignable = NO;579580Null.prototype.isComplex = NO;581582Null.prototype.compileNode = function() {583return [this.makeCode("null")];584};585586return Null;587588})(Base);589590exports.Bool = (function(_super) {591__extends(Bool, _super);592593Bool.prototype.isAssignable = NO;594595Bool.prototype.isComplex = NO;596597Bool.prototype.compileNode = function() {598return [this.makeCode(this.val)];599};600601function Bool(val) {602this.val = val;603}604605return Bool;606607})(Base);608609exports.Return = Return = (function(_super) {610__extends(Return, _super);611612function Return(expr) {613if (expr && !expr.unwrap().isUndefined) {614this.expression = expr;615}616}617618Return.prototype.children = ['expression'];619620Return.prototype.isStatement = YES;621622Return.prototype.makeReturn = THIS;623624Return.prototype.jumps = THIS;625626Return.prototype.compileToFragments = function(o, level) {627var expr, _ref4;628expr = (_ref4 = this.expression) != null ? _ref4.makeReturn() : void 0;629if (expr && !(expr instanceof Return)) {630return expr.compileToFragments(o, level);631} else {632return Return.__super__.compileToFragments.call(this, o, level);633}634};635636Return.prototype.compileNode = function(o) {637var answer;638answer = [];639answer.push(this.makeCode(this.tab + ("return" + (this.expression ? " " : ""))));640if (this.expression) {641answer = answer.concat(this.expression.compileToFragments(o, LEVEL_PAREN));642}643answer.push(this.makeCode(";"));644return answer;645};646647return Return;648649})(Base);650651exports.Value = Value = (function(_super) {652__extends(Value, _super);653654function Value(base, props, tag) {655if (!props && base instanceof Value) {656return base;657}658this.base = base;659this.properties = props || [];660if (tag) {661this[tag] = true;662}663return this;664}665666Value.prototype.children = ['base', 'properties'];667668Value.prototype.add = function(props) {669this.properties = this.properties.concat(props);670return this;671};672673Value.prototype.hasProperties = function() {674return !!this.properties.length;675};676677Value.prototype.isArray = function() {678return !this.properties.length && this.base instanceof Arr;679};680681Value.prototype.isComplex = function() {682return this.hasProperties() || this.base.isComplex();683};684685Value.prototype.isAssignable = function() {686return this.hasProperties() || this.base.isAssignable();687};688689Value.prototype.isSimpleNumber = function() {690return this.base instanceof Literal && SIMPLENUM.test(this.base.value);691};692693Value.prototype.isString = function() {694return this.base instanceof Literal && IS_STRING.test(this.base.value);695};696697Value.prototype.isAtomic = function() {698var node, _i, _len, _ref4;699_ref4 = this.properties.concat(this.base);700for (_i = 0, _len = _ref4.length; _i < _len; _i++) {701node = _ref4[_i];702if (node.soak || node instanceof Call) {703return false;704}705}706return true;707};708709Value.prototype.isStatement = function(o) {710return !this.properties.length && this.base.isStatement(o);711};712713Value.prototype.assigns = function(name) {714return !this.properties.length && this.base.assigns(name);715};716717Value.prototype.jumps = function(o) {718return !this.properties.length && this.base.jumps(o);719};720721Value.prototype.isObject = function(onlyGenerated) {722if (this.properties.length) {723return false;724}725return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated);726};727728Value.prototype.isSplice = function() {729return last(this.properties) instanceof Slice;730};731732Value.prototype.unwrap = function() {733if (this.properties.length) {734return this;735} else {736return this.base;737}738};739740Value.prototype.cacheReference = function(o) {741var base, bref, name, nref;742name = last(this.properties);743if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {744return [this, this];745}746base = new Value(this.base, this.properties.slice(0, -1));747if (base.isComplex()) {748bref = new Literal(o.scope.freeVariable('base'));749base = new Value(new Parens(new Assign(bref, base)));750}751if (!name) {752return [base, bref];753}754if (name.isComplex()) {755nref = new Literal(o.scope.freeVariable('name'));756name = new Index(new Assign(nref, name.index));757nref = new Index(nref);758}759return [base.add(name), new Value(bref || base.base, [nref || name])];760};761762Value.prototype.compileNode = function(o) {763var fragments, prop, props, _i, _len;764this.base.front = this.front;765props = this.properties;766fragments = this.base.compileToFragments(o, (props.length ? LEVEL_ACCESS : null));767if ((this.base instanceof Parens || props.length) && SIMPLENUM.test(fragmentsToText(fragments))) {768fragments.push(this.makeCode('.'));769}770for (_i = 0, _len = props.length; _i < _len; _i++) {771prop = props[_i];772fragments.push.apply(fragments, prop.compileToFragments(o));773}774return fragments;775};776777Value.prototype.unfoldSoak = function(o) {778var _this = this;779return this.unfoldedSoak != null ? this.unfoldedSoak : this.unfoldedSoak = (function() {780var fst, i, ifn, prop, ref, snd, _i, _len, _ref4, _ref5;781if (ifn = _this.base.unfoldSoak(o)) {782(_ref4 = ifn.body.properties).push.apply(_ref4, _this.properties);783return ifn;784}785_ref5 = _this.properties;786for (i = _i = 0, _len = _ref5.length; _i < _len; i = ++_i) {787prop = _ref5[i];788if (!prop.soak) {789continue;790}791prop.soak = false;792fst = new Value(_this.base, _this.properties.slice(0, i));793snd = new Value(_this.base, _this.properties.slice(i));794if (fst.isComplex()) {795ref = new Literal(o.scope.freeVariable('ref'));796fst = new Parens(new Assign(ref, fst));797snd.base = ref;798}799return new If(new Existence(fst), snd, {800soak: true801});802}803return false;804})();805};806807return Value;808809})(Base);810811exports.Comment = Comment = (function(_super) {812__extends(Comment, _super);813814function Comment(comment) {815this.comment = comment;816}817818Comment.prototype.isStatement = YES;819820Comment.prototype.makeReturn = THIS;821822Comment.prototype.compileNode = function(o, level) {823var code;824code = "/*" + (multident(this.comment, this.tab)) + (__indexOf.call(this.comment, '\n') >= 0 ? "\n" + this.tab : '') + "*/\n";825if ((level || o.level) === LEVEL_TOP) {826code = o.indent + code;827}828return [this.makeCode(code)];829};830831return Comment;832833})(Base);834835exports.Call = Call = (function(_super) {836__extends(Call, _super);837838function Call(variable, args, soak) {839this.args = args != null ? args : [];840this.soak = soak;841this.isNew = false;842this.isSuper = variable === 'super';843this.variable = this.isSuper ? null : variable;844}845846Call.prototype.children = ['variable', 'args'];847848Call.prototype.newInstance = function() {849var base, _ref4;850base = ((_ref4 = this.variable) != null ? _ref4.base : void 0) || this.variable;851if (base instanceof Call && !base.isNew) {852base.newInstance();853} else {854this.isNew = true;855}856return this;857};858859Call.prototype.superReference = function(o) {860var accesses, method;861method = o.scope.namedMethod();862if (method != null ? method.klass : void 0) {863accesses = [new Access(new Literal('__super__'))];864if (method["static"]) {865accesses.push(new Access(new Literal('constructor')));866}867accesses.push(new Access(new Literal(method.name)));868return (new Value(new Literal(method.klass), accesses)).compile(o);869} else if (method != null ? method.ctor : void 0) {870return "" + method.name + ".__super__.constructor";871} else {872return this.error('cannot call super outside of an instance method.');873}874};875876Call.prototype.superThis = function(o) {877var method;878method = o.scope.method;879return (method && !method.klass && method.context) || "this";880};881882Call.prototype.unfoldSoak = function(o) {883var call, ifn, left, list, rite, _i, _len, _ref4, _ref5;884if (this.soak) {885if (this.variable) {886if (ifn = unfoldSoak(o, this, 'variable')) {887return ifn;888}889_ref4 = new Value(this.variable).cacheReference(o), left = _ref4[0], rite = _ref4[1];890} else {891left = new Literal(this.superReference(o));892rite = new Value(left);893}894rite = new Call(rite, this.args);895rite.isNew = this.isNew;896left = new Literal("typeof " + (left.compile(o)) + " === \"function\"");897return new If(left, new Value(rite), {898soak: true899});900}901call = this;902list = [];903while (true) {904if (call.variable instanceof Call) {905list.push(call);906call = call.variable;907continue;908}909if (!(call.variable instanceof Value)) {910break;911}912list.push(call);913if (!((call = call.variable.base) instanceof Call)) {914break;915}916}917_ref5 = list.reverse();918for (_i = 0, _len = _ref5.length; _i < _len; _i++) {919call = _ref5[_i];920if (ifn) {921if (call.variable instanceof Call) {922call.variable = ifn;923} else {924call.variable.base = ifn;925}926}927ifn = unfoldSoak(o, call, 'variable');928}929return ifn;930};931932Call.prototype.compileNode = function(o) {933var arg, argIndex, compiledArgs, compiledArray, fragments, preface, _i, _len, _ref4, _ref5;934if ((_ref4 = this.variable) != null) {935_ref4.front = this.front;936}937compiledArray = Splat.compileSplattedArray(o, this.args, true);938if (compiledArray.length) {939return this.compileSplat(o, compiledArray);940}941compiledArgs = [];942_ref5 = this.args;943for (argIndex = _i = 0, _len = _ref5.length; _i < _len; argIndex = ++_i) {944arg = _ref5[argIndex];945if (argIndex) {946compiledArgs.push(this.makeCode(", "));947}948compiledArgs.push.apply(compiledArgs, arg.compileToFragments(o, LEVEL_LIST));949}950fragments = [];951if (this.isSuper) {952preface = this.superReference(o) + (".call(" + (this.superThis(o)));953if (compiledArgs.length) {954preface += ", ";955}956fragments.push(this.makeCode(preface));957} else {958if (this.isNew) {959fragments.push(this.makeCode('new '));960}961fragments.push.apply(fragments, this.variable.compileToFragments(o, LEVEL_ACCESS));962fragments.push(this.makeCode("("));963}964fragments.push.apply(fragments, compiledArgs);965fragments.push(this.makeCode(")"));966return fragments;967};968969Call.prototype.compileSplat = function(o, splatArgs) {970var answer, base, fun, idt, name, ref;971if (this.isSuper) {972return [].concat(this.makeCode("" + (this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", "), splatArgs, this.makeCode(")"));973}974if (this.isNew) {975idt = this.tab + TAB;976return [].concat(this.makeCode("(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return Object(result) === result ? result : child;\n" + this.tab + "})("), this.variable.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), splatArgs, this.makeCode(", function(){})"));977}978answer = [];979base = new Value(this.variable);980if ((name = base.properties.pop()) && base.isComplex()) {981ref = o.scope.freeVariable('ref');982answer = answer.concat(this.makeCode("(" + ref + " = "), base.compileToFragments(o, LEVEL_LIST), this.makeCode(")"), name.compileToFragments(o));983} else {984fun = base.compileToFragments(o, LEVEL_ACCESS);985if (SIMPLENUM.test(fragmentsToText(fun))) {986fun = this.wrapInBraces(fun);987}988if (name) {989ref = fragmentsToText(fun);990fun.push.apply(fun, name.compileToFragments(o));991} else {992ref = 'null';993}994answer = answer.concat(fun);995}996return answer = answer.concat(this.makeCode(".apply(" + ref + ", "), splatArgs, this.makeCode(")"));997};998999return Call;10001001})(Base);10021003exports.Extends = Extends = (function(_super) {1004__extends(Extends, _super);10051006function Extends(child, parent) {1007this.child = child;1008this.parent = parent;1009}10101011Extends.prototype.children = ['child', 'parent'];10121013Extends.prototype.compileToFragments = function(o) {1014return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compileToFragments(o);1015};10161017return Extends;10181019})(Base);10201021exports.Access = Access = (function(_super) {1022__extends(Access, _super);10231024function Access(name, tag) {1025this.name = name;1026this.name.asKey = true;1027this.soak = tag === 'soak';1028}10291030Access.prototype.children = ['name'];10311032Access.prototype.compileToFragments = function(o) {1033var name;1034name = this.name.compileToFragments(o);1035if (IDENTIFIER.test(fragmentsToText(name))) {1036name.unshift(this.makeCode("."));1037} else {1038name.unshift(this.makeCode("["));1039name.push(this.makeCode("]"));1040}1041return name;1042};10431044Access.prototype.isComplex = NO;10451046return Access;10471048})(Base);10491050exports.Index = Index = (function(_super) {1051__extends(Index, _super);10521053function Index(index) {1054this.index = index;1055}10561057Index.prototype.children = ['index'];10581059Index.prototype.compileToFragments = function(o) {1060return [].concat(this.makeCode("["), this.index.compileToFragments(o, LEVEL_PAREN), this.makeCode("]"));1061};10621063Index.prototype.isComplex = function() {1064return this.index.isComplex();1065};10661067return Index;10681069})(Base);10701071exports.Range = Range = (function(_super) {1072__extends(Range, _super);10731074Range.prototype.children = ['from', 'to'];10751076function Range(from, to, tag) {1077this.from = from;1078this.to = to;1079this.exclusive = tag === 'exclusive';1080this.equals = this.exclusive ? '' : '=';1081}10821083Range.prototype.compileVariables = function(o) {1084var step, _ref4, _ref5, _ref6, _ref7;1085o = merge(o, {1086top: true1087});1088_ref4 = this.cacheToCodeFragments(this.from.cache(o, LEVEL_LIST)), this.fromC = _ref4[0], this.fromVar = _ref4[1];1089_ref5 = this.cacheToCodeFragments(this.to.cache(o, LEVEL_LIST)), this.toC = _ref5[0], this.toVar = _ref5[1];1090if (step = del(o, 'step')) {1091_ref6 = this.cacheToCodeFragments(step.cache(o, LEVEL_LIST)), this.step = _ref6[0], this.stepVar = _ref6[1];1092}1093_ref7 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref7[0], this.toNum = _ref7[1];1094if (this.stepVar) {1095return this.stepNum = this.stepVar.match(SIMPLENUM);1096}1097};10981099Range.prototype.compileNode = function(o) {1100var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref4, _ref5;1101if (!this.fromVar) {1102this.compileVariables(o);1103}1104if (!o.index) {1105return this.compileArray(o);1106}1107known = this.fromNum && this.toNum;1108idx = del(o, 'index');1109idxName = del(o, 'name');1110namedIndex = idxName && idxName !== idx;1111varPart = "" + idx + " = " + this.fromC;1112if (this.toC !== this.toVar) {1113varPart += ", " + this.toC;1114}1115if (this.step !== this.stepVar) {1116varPart += ", " + this.step;1117}1118_ref4 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref4[0], gt = _ref4[1];1119condPart = this.stepNum ? +this.stepNum > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref5 = [+this.fromNum, +this.toNum], from = _ref5[0], to = _ref5[1], _ref5), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = this.stepVar ? "" + this.stepVar + " > 0" : "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);1120stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? "" + idx + "++" : "" + idx + "--" : namedIndex ? "" + cond + " ? ++" + idx + " : --" + idx : "" + cond + " ? " + idx + "++ : " + idx + "--";1121if (namedIndex) {1122varPart = "" + idxName + " = " + varPart;1123}1124if (namedIndex) {1125stepPart = "" + idxName + " = " + stepPart;1126}1127return [this.makeCode("" + varPart + "; " + condPart + "; " + stepPart)];1128};11291130Range.prototype.compileArray = function(o) {1131var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref4, _ref5, _results;1132if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {1133range = (function() {1134_results = [];1135for (var _i = _ref4 = +this.fromNum, _ref5 = +this.toNum; _ref4 <= _ref5 ? _i <= _ref5 : _i >= _ref5; _ref4 <= _ref5 ? _i++ : _i--){ _results.push(_i); }1136return _results;1137}).apply(this);1138if (this.exclusive) {1139range.pop();1140}1141return [this.makeCode("[" + (range.join(', ')) + "]")];1142}1143idt = this.tab + TAB;1144i = o.scope.freeVariable('i');1145result = o.scope.freeVariable('results');1146pre = "\n" + idt + result + " = [];";1147if (this.fromNum && this.toNum) {1148o.index = i;1149body = fragmentsToText(this.compileNode(o));1150} else {1151vars = ("" + i + " = " + this.fromC) + (this.toC !== this.toVar ? ", " + this.toC : '');1152cond = "" + this.fromVar + " <= " + this.toVar;1153body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--";1154}1155post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;1156hasArgs = function(node) {1157return node != null ? node.contains(function(n) {1158return n instanceof Literal && n.value === 'arguments' && !n.asKey;1159}) : void 0;1160};1161if (hasArgs(this.from) || hasArgs(this.to)) {1162args = ', arguments';1163}1164return [this.makeCode("(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this" + (args != null ? args : '') + ")")];1165};11661167return Range;11681169})(Base);11701171exports.Slice = Slice = (function(_super) {1172__extends(Slice, _super);11731174Slice.prototype.children = ['range'];11751176function Slice(range) {1177this.range = range;1178Slice.__super__.constructor.call(this);1179}11801181Slice.prototype.compileNode = function(o) {1182var compiled, compiledText, from, fromCompiled, to, toStr, _ref4;1183_ref4 = this.range, to = _ref4.to, from = _ref4.from;1184fromCompiled = from && from.compileToFragments(o, LEVEL_PAREN) || [this.makeCode('0')];1185if (to) {1186compiled = to.compileToFragments(o, LEVEL_PAREN);1187compiledText = fragmentsToText(compiled);1188if (!(!this.range.exclusive && +compiledText === -1)) {1189toStr = ', ' + (this.range.exclusive ? compiledText : SIMPLENUM.test(compiledText) ? "" + (+compiledText + 1) : (compiled = to.compileToFragments(o, LEVEL_ACCESS), "+" + (fragmentsToText(compiled)) + " + 1 || 9e9"));1190}1191}1192return [this.makeCode(".slice(" + (fragmentsToText(fromCompiled)) + (toStr || '') + ")")];1193};11941195return Slice;11961197})(Base);11981199exports.Obj = Obj = (function(_super) {1200__extends(Obj, _super);12011202function Obj(props, generated) {1203this.generated = generated != null ? generated : false;1204this.objects = this.properties = props || [];1205}12061207Obj.prototype.children = ['properties'];12081209Obj.prototype.compileNode = function(o) {1210var answer, i, idt, indent, join, lastNoncom, node, prop, props, _i, _j, _len, _len1;1211props = this.properties;1212if (!props.length) {1213return [this.makeCode(this.front ? '({})' : '{}')];1214}1215if (this.generated) {1216for (_i = 0, _len = props.length; _i < _len; _i++) {1217node = props[_i];1218if (node instanceof Value) {1219node.error('cannot have an implicit value in an implicit object');1220}1221}1222}1223idt = o.indent += TAB;1224lastNoncom = this.lastNonComment(this.properties);1225answer = [];1226for (i = _j = 0, _len1 = props.length; _j < _len1; i = ++_j) {1227prop = props[i];1228join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';1229indent = prop instanceof Comment ? '' : idt;1230if (prop instanceof Assign && prop.variable instanceof Value && prop.variable.hasProperties()) {1231prop.variable.error('Invalid object key');1232}1233if (prop instanceof Value && prop["this"]) {1234prop = new Assign(prop.properties[0].name, prop, 'object');1235}1236if (!(prop instanceof Comment)) {1237if (!(prop instanceof Assign)) {1238prop = new Assign(prop, prop, 'object');1239}1240(prop.variable.base || prop.variable).asKey = true;1241}1242if (indent) {1243answer.push(this.makeCode(indent));1244}1245answer.push.apply(answer, prop.compileToFragments(o, LEVEL_TOP));1246if (join) {1247answer.push(this.makeCode(join));1248}1249}1250answer.unshift(this.makeCode("{" + (props.length && '\n')));1251answer.push(this.makeCode("" + (props.length && '\n' + this.tab) + "}"));1252if (this.front) {1253return this.wrapInBraces(answer);1254} else {1255return answer;1256}1257};12581259Obj.prototype.assigns = function(name) {1260var prop, _i, _len, _ref4;1261_ref4 = this.properties;1262for (_i = 0, _len = _ref4.length; _i < _len; _i++) {1263prop = _ref4[_i];1264if (prop.assigns(name)) {1265return true;1266}1267}1268return false;1269};12701271return Obj;12721273})(Base);12741275exports.Arr = Arr = (function(_super) {1276__extends(Arr, _super);12771278function Arr(objs) {1279this.objects = objs || [];1280}12811282Arr.prototype.children = ['objects'];12831284Arr.prototype.compileNode = function(o) {1285var answer, compiledObjs, fragments, index, obj, _i, _len;1286if (!this.objects.length) {1287return [this.makeCode('[]')];1288}1289o.indent += TAB;1290answer = Splat.compileSplattedArray(o, this.objects);1291if (answer.length) {1292return answer;1293}1294answer = [];1295compiledObjs = (function() {1296var _i, _len, _ref4, _results;1297_ref4 = this.objects;1298_results = [];1299for (_i = 0, _len = _ref4.length; _i < _len; _i++) {1300obj = _ref4[_i];1301_results.push(obj.compileToFragments(o, LEVEL_LIST));1302}1303return _results;1304}).call(this);1305for (index = _i = 0, _len = compiledObjs.length; _i < _len; index = ++_i) {1306fragments = compiledObjs[index];1307if (index) {1308answer.push(this.makeCode(", "));1309}1310answer.push.apply(answer, fragments);1311}1312if (fragmentsToText(answer).indexOf('\n') >= 0) {1313answer.unshift(this.makeCode("[\n" + o.indent));1314answer.push(this.makeCode("\n" + this.tab + "]"));1315} else {1316answer.unshift(this.makeCode("["));1317answer.push(this.makeCode("]"));1318}1319return answer;1320};13211322Arr.prototype.assigns = function(name) {1323var obj, _i, _len, _ref4;1324_ref4 = this.objects;1325for (_i = 0, _len = _ref4.length; _i < _len; _i++) {1326obj = _ref4[_i];1327if (obj.assigns(name)) {1328return true;1329}1330}1331return false;1332};13331334return Arr;13351336})(Base);13371338exports.Class = Class = (function(_super) {1339__extends(Class, _super);13401341function Class(variable, parent, body) {1342this.variable = variable;1343this.parent = parent;1344this.body = body != null ? body : new Block;1345this.boundFuncs = [];1346this.body.classBody = true;1347}13481349Class.prototype.children = ['variable', 'parent', 'body'];13501351Class.prototype.determineName = function() {1352var decl, tail;1353if (!this.variable) {1354return null;1355}1356decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;1357if (__indexOf.call(STRICT_PROSCRIBED, decl) >= 0) {1358this.variable.error("class variable name may not be " + decl);1359}1360return decl && (decl = IDENTIFIER.test(decl) && decl);1361};13621363Class.prototype.setContext = function(name) {1364return this.body.traverseChildren(false, function(node) {1365if (node.classBody) {1366return false;1367}1368if (node instanceof Literal && node.value === 'this') {1369return node.value = name;1370} else if (node instanceof Code) {1371node.klass = name;1372if (node.bound) {1373return node.context = name;1374}1375}1376});1377};13781379Class.prototype.addBoundFunctions = function(o) {1380var bvar, lhs, _i, _len, _ref4;1381_ref4 = this.boundFuncs;1382for (_i = 0, _len = _ref4.length; _i < _len; _i++) {1383bvar = _ref4[_i];1384lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o);1385this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)"));1386}1387};13881389Class.prototype.addProperties = function(node, name, o) {1390var assign, base, exprs, func, props;1391props = node.base.properties.slice(0);1392exprs = (function() {1393var _results;1394_results = [];1395while (assign = props.shift()) {1396if (assign instanceof Assign) {1397base = assign.variable.base;1398delete assign.context;1399func = assign.value;1400if (base.value === 'constructor') {1401if (this.ctor) {1402assign.error('cannot define more than one constructor in a class');1403}1404if (func.bound) {1405assign.error('cannot define a constructor as a bound function');1406}1407if (func instanceof Code) {1408assign = this.ctor = func;1409} else {1410this.externalCtor = o.scope.freeVariable('class');1411assign = new Assign(new Literal(this.externalCtor), func);1412}1413} else {1414if (assign.variable["this"]) {1415func["static"] = true;1416if (func.bound) {1417func.context = name;1418}1419} else {1420assign.variable = new Value(new Literal(name), [new Access(new Literal('prototype')), new Access(base)]);1421if (func instanceof Code && func.bound) {1422this.boundFuncs.push(base);1423func.bound = false;1424}1425}1426}1427}1428_results.push(assign);1429}1430return _results;1431}).call(this);1432return compact(exprs);1433};14341435Class.prototype.walkBody = function(name, o) {1436var _this = this;1437return this.traverseChildren(false, function(child) {1438var cont, exps, i, node, _i, _len, _ref4;1439cont = true;1440if (child instanceof Class) {1441return false;1442}1443if (child instanceof Block) {1444_ref4 = exps = child.expressions;1445for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {1446node = _ref4[i];1447if (node instanceof Value && node.isObject(true)) {1448cont = false;1449exps[i] = _this.addProperties(node, name, o);1450}1451}1452child.expressions = exps = flatten(exps);1453}1454return cont && !(child instanceof Class);1455});1456};14571458Class.prototype.hoistDirectivePrologue = function() {1459var expressions, index, node;1460index = 0;1461expressions = this.body.expressions;1462while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {1463++index;1464}1465return this.directives = expressions.splice(0, index);1466};14671468Class.prototype.ensureConstructor = function(name, o) {1469var missing, ref, superCall;1470missing = !this.ctor;1471this.ctor || (this.ctor = new Code);1472this.ctor.ctor = this.ctor.name = name;1473this.ctor.klass = null;1474this.ctor.noReturn = true;1475if (missing) {1476if (this.parent) {1477superCall = new Literal("" + name + ".__super__.constructor.apply(this, arguments)");1478}1479if (this.externalCtor) {1480superCall = new Literal("" + this.externalCtor + ".apply(this, arguments)");1481}1482if (superCall) {1483ref = new Literal(o.scope.freeVariable('ref'));1484this.ctor.body.unshift(new Assign(ref, superCall));1485}1486this.addBoundFunctions(o);1487if (superCall) {1488this.ctor.body.push(ref);1489this.ctor.body.makeReturn();1490}1491return this.body.expressions.unshift(this.ctor);1492} else {1493return this.addBoundFunctions(o);1494}1495};14961497Class.prototype.compileNode = function(o) {1498var call, decl, klass, lname, name, params, _ref4;1499decl = this.determineName();1500name = decl || '_Class';1501if (name.reserved) {1502name = "_" + name;1503}1504lname = new Literal(name);1505this.hoistDirectivePrologue();1506this.setContext(name);1507this.walkBody(name, o);1508this.ensureConstructor(name, o);1509this.body.spaced = true;1510if (!(this.ctor instanceof Code)) {1511this.body.expressions.unshift(this.ctor);1512}1513this.body.expressions.push(lname);1514(_ref4 = this.body.expressions).unshift.apply(_ref4, this.directives);1515call = Closure.wrap(this.body);1516if (this.parent) {1517this.superClass = new Literal(o.scope.freeVariable('super', false));1518this.body.expressions.unshift(new Extends(lname, this.superClass));1519call.args.push(this.parent);1520params = call.variable.params || call.variable.base.params;1521params.push(new Param(this.superClass));1522}1523klass = new Parens(call, true);1524if (this.variable) {1525klass = new Assign(this.variable, klass);1526}1527return klass.compileToFragments(o);1528};15291530return Class;15311532})(Base);15331534exports.Assign = Assign = (function(_super) {1535__extends(Assign, _super);15361537function Assign(variable, value, context, options) {1538var forbidden, name, _ref4;1539this.variable = variable;1540this.value = value;1541this.context = context;1542this.param = options && options.param;1543this.subpattern = options && options.subpattern;1544forbidden = (_ref4 = (name = this.variable.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref4) >= 0);1545if (forbidden && this.context !== 'object') {1546this.variable.error("variable name may not be \"" + name + "\"");1547}1548}15491550Assign.prototype.children = ['variable', 'value'];15511552Assign.prototype.isStatement = function(o) {1553return (o != null ? o.level : void 0) === LEVEL_TOP && (this.context != null) && __indexOf.call(this.context, "?") >= 0;1554};15551556Assign.prototype.assigns = function(name) {1557return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);1558};15591560Assign.prototype.unfoldSoak = function(o) {1561return unfoldSoak(o, this, 'variable');1562};15631564Assign.prototype.compileNode = function(o) {1565var answer, compiledName, isValue, match, name, val, varBase, _ref4, _ref5, _ref6, _ref7;1566if (isValue = this.variable instanceof Value) {1567if (this.variable.isArray() || this.variable.isObject()) {1568return this.compilePatternMatch(o);1569}1570if (this.variable.isSplice()) {1571return this.compileSplice(o);1572}1573if ((_ref4 = this.context) === '||=' || _ref4 === '&&=' || _ref4 === '?=') {1574return this.compileConditional(o);1575}1576}1577compiledName = this.variable.compileToFragments(o, LEVEL_LIST);1578name = fragmentsToText(compiledName);1579if (!this.context) {1580varBase = this.variable.unwrapAll();1581if (!varBase.isAssignable()) {1582this.variable.error("\"" + (this.variable.compile(o)) + "\" cannot be assigned");1583}1584if (!(typeof varBase.hasProperties === "function" ? varBase.hasProperties() : void 0)) {1585if (this.param) {1586o.scope.add(name, 'var');1587} else {1588o.scope.find(name);1589}1590}1591}1592if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) {1593if (match[1]) {1594this.value.klass = match[1];1595}1596this.value.name = (_ref5 = (_ref6 = (_ref7 = match[2]) != null ? _ref7 : match[3]) != null ? _ref6 : match[4]) != null ? _ref5 : match[5];1597}1598val = this.value.compileToFragments(o, LEVEL_LIST);1599if (this.context === 'object') {1600return compiledName.concat(this.makeCode(": "), val);1601}1602answer = compiledName.concat(this.makeCode(" " + (this.context || '=') + " "), val);1603if (o.level <= LEVEL_LIST) {1604return answer;1605} else {1606return this.wrapInBraces(answer);1607}1608};16091610Assign.prototype.compilePatternMatch = function(o) {1611var acc, assigns, code, fragments, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, vvarText, _i, _len, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;1612top = o.level === LEVEL_TOP;1613value = this.value;1614objects = this.variable.base.objects;1615if (!(olen = objects.length)) {1616code = value.compileToFragments(o);1617if (o.level >= LEVEL_OP) {1618return this.wrapInBraces(code);1619} else {1620return code;1621}1622}1623isObject = this.variable.isObject();1624if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {1625if (obj instanceof Assign) {1626_ref4 = obj, (_ref5 = _ref4.variable, idx = _ref5.base), obj = _ref4.value;1627} else {1628idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);1629}1630acc = IDENTIFIER.test(idx.unwrap().value || 0);1631value = new Value(value);1632value.properties.push(new (acc ? Access : Index)(idx));1633if (_ref6 = obj.unwrap().value, __indexOf.call(RESERVED, _ref6) >= 0) {1634obj.error("assignment to a reserved word: " + (obj.compile(o)));1635}1636return new Assign(obj, value, null, {1637param: this.param1638}).compileToFragments(o, LEVEL_TOP);1639}1640vvar = value.compileToFragments(o, LEVEL_LIST);1641vvarText = fragmentsToText(vvar);1642assigns = [];1643splat = false;1644if (!IDENTIFIER.test(vvarText) || this.variable.assigns(vvarText)) {1645assigns.push([this.makeCode("" + (ref = o.scope.freeVariable('ref')) + " = ")].concat(__slice.call(vvar)));1646vvar = [this.makeCode(ref)];1647vvarText = ref;1648}1649for (i = _i = 0, _len = objects.length; _i < _len; i = ++_i) {1650obj = objects[i];1651idx = i;1652if (isObject) {1653if (obj instanceof Assign) {1654_ref7 = obj, (_ref8 = _ref7.variable, idx = _ref8.base), obj = _ref7.value;1655} else {1656if (obj.base instanceof Parens) {1657_ref9 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref9[0], idx = _ref9[1];1658} else {1659idx = obj["this"] ? obj.properties[0].name : obj;1660}1661}1662}1663if (!splat && obj instanceof Splat) {1664name = obj.name.unwrap().value;1665obj = obj.unwrap();1666val = "" + olen + " <= " + vvarText + ".length ? " + (utility('slice')) + ".call(" + vvarText + ", " + i;1667if (rest = olen - i - 1) {1668ivar = o.scope.freeVariable('i');1669val += ", " + ivar + " = " + vvarText + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])";1670} else {1671val += ") : []";1672}1673val = new Literal(val);1674splat = "" + ivar + "++";1675} else {1676name = obj.unwrap().value;1677if (obj instanceof Splat) {1678obj.error("multiple splats are disallowed in an assignment");1679}1680if (typeof idx === 'number') {1681idx = new Literal(splat || idx);1682acc = false;1683} else {1684acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);1685}1686val = new Value(new Literal(vvarText), [new (acc ? Access : Index)(idx)]);1687}1688if ((name != null) && __indexOf.call(RESERVED, name) >= 0) {1689obj.error("assignment to a reserved word: " + (obj.compile(o)));1690}1691assigns.push(new Assign(obj, val, null, {1692param: this.param,1693subpattern: true1694}).compileToFragments(o, LEVEL_LIST));1695}1696if (!(top || this.subpattern)) {1697assigns.push(vvar);1698}1699fragments = this.joinFragmentArrays(assigns, ', ');1700if (o.level < LEVEL_LIST) {1701return fragments;1702} else {1703return this.wrapInBraces(fragments);1704}1705};17061707Assign.prototype.compileConditional = function(o) {1708var left, right, _ref4;1709_ref4 = this.variable.cacheReference(o), left = _ref4[0], right = _ref4[1];1710if (!left.properties.length && left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) {1711this.variable.error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been declared before");1712}1713if (__indexOf.call(this.context, "?") >= 0) {1714o.isExistentialEquals = true;1715}1716return new Op(this.context.slice(0, -1), left, new Assign(right, this.value, '=')).compileToFragments(o);1717};17181719Assign.prototype.compileSplice = function(o) {1720var answer, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref4, _ref5, _ref6;1721_ref4 = this.variable.properties.pop().range, from = _ref4.from, to = _ref4.to, exclusive = _ref4.exclusive;1722name = this.variable.compile(o);1723if (from) {1724_ref5 = this.cacheToCodeFragments(from.cache(o, LEVEL_OP)), fromDecl = _ref5[0], fromRef = _ref5[1];1725} else {1726fromDecl = fromRef = '0';1727}1728if (to) {1729if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) {1730to = +to.compile(o) - +fromRef;1731if (!exclusive) {1732to += 1;1733}1734} else {1735to = to.compile(o, LEVEL_ACCESS) + ' - ' + fromRef;1736if (!exclusive) {1737to += ' + 1';1738}1739}1740} else {1741to = "9e9";1742}1743_ref6 = this.value.cache(o, LEVEL_LIST), valDef = _ref6[0], valRef = _ref6[1];1744answer = [].concat(this.makeCode("[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat("), valDef, this.makeCode(")), "), valRef);1745if (o.level > LEVEL_TOP) {1746return this.wrapInBraces(answer);1747} else {1748return answer;1749}1750};17511752return Assign;17531754})(Base);17551756exports.Code = Code = (function(_super) {1757__extends(Code, _super);17581759function Code(params, body, tag) {1760this.params = params || [];1761this.body = body || new Block;1762this.bound = tag === 'boundfunc';1763if (this.bound) {1764this.context = '_this';1765}1766}17671768Code.prototype.children = ['params', 'body'];17691770Code.prototype.isStatement = function() {1771return !!this.ctor;1772};17731774Code.prototype.jumps = NO;17751776Code.prototype.compileNode = function(o) {1777var answer, code, exprs, i, idt, lit, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref4, _ref5, _ref6, _ref7, _ref8;1778o.scope = new Scope(o.scope, this.body, this);1779o.scope.shared = del(o, 'sharedScope');1780o.indent += TAB;1781delete o.bare;1782delete o.isExistentialEquals;1783params = [];1784exprs = [];1785this.eachParamName(function(name) {1786if (!o.scope.check(name)) {1787return o.scope.parameter(name);1788}1789});1790_ref4 = this.params;1791for (_i = 0, _len = _ref4.length; _i < _len; _i++) {1792param = _ref4[_i];1793if (!param.splat) {1794continue;1795}1796_ref5 = this.params;1797for (_j = 0, _len1 = _ref5.length; _j < _len1; _j++) {1798p = _ref5[_j].name;1799if (p["this"]) {1800p = p.properties[0].name;1801}1802if (p.value) {1803o.scope.add(p.value, 'var', true);1804}1805}1806splats = new Assign(new Value(new Arr((function() {1807var _k, _len2, _ref6, _results;1808_ref6 = this.params;1809_results = [];1810for (_k = 0, _len2 = _ref6.length; _k < _len2; _k++) {1811p = _ref6[_k];1812_results.push(p.asReference(o));1813}1814return _results;1815}).call(this))), new Value(new Literal('arguments')));1816break;1817}1818_ref6 = this.params;1819for (_k = 0, _len2 = _ref6.length; _k < _len2; _k++) {1820param = _ref6[_k];1821if (param.isComplex()) {1822val = ref = param.asReference(o);1823if (param.value) {1824val = new Op('?', ref, param.value);1825}1826exprs.push(new Assign(new Value(param.name), val, '=', {1827param: true1828}));1829} else {1830ref = param;1831if (param.value) {1832lit = new Literal(ref.name.value + ' == null');1833val = new Assign(new Value(param.name), param.value, '=');1834exprs.push(new If(lit, val));1835}1836}1837if (!splats) {1838params.push(ref);1839}1840}1841wasEmpty = this.body.isEmpty();1842if (splats) {1843exprs.unshift(splats);1844}1845if (exprs.length) {1846(_ref7 = this.body.expressions).unshift.apply(_ref7, exprs);1847}1848for (i = _l = 0, _len3 = params.length; _l < _len3; i = ++_l) {1849p = params[i];1850params[i] = p.compileToFragments(o);1851o.scope.parameter(fragmentsToText(params[i]));1852}1853uniqs = [];1854this.eachParamName(function(name, node) {1855if (__indexOf.call(uniqs, name) >= 0) {1856node.error("multiple parameters named '" + name + "'");1857}1858return uniqs.push(name);1859});1860if (!(wasEmpty || this.noReturn)) {1861this.body.makeReturn();1862}1863if (this.bound) {1864if ((_ref8 = o.scope.parent.method) != null ? _ref8.bound : void 0) {1865this.bound = this.context = o.scope.parent.method.context;1866} else if (!this["static"]) {1867o.scope.parent.assign('_this', 'this');1868}1869}1870idt = o.indent;1871code = 'function';1872if (this.ctor) {1873code += ' ' + this.name;1874}1875code += '(';1876answer = [this.makeCode(code)];1877for (i = _m = 0, _len4 = params.length; _m < _len4; i = ++_m) {1878p = params[i];1879if (i) {1880answer.push(this.makeCode(", "));1881}1882answer.push.apply(answer, p);1883}1884answer.push(this.makeCode(') {'));1885if (!this.body.isEmpty()) {1886answer = answer.concat(this.makeCode("\n"), this.body.compileWithDeclarations(o), this.makeCode("\n" + this.tab));1887}1888answer.push(this.makeCode('}'));1889if (this.ctor) {1890return [this.makeCode(this.tab)].concat(__slice.call(answer));1891}1892if (this.front || (o.level >= LEVEL_ACCESS)) {1893return this.wrapInBraces(answer);1894} else {1895return answer;1896}1897};18981899Code.prototype.eachParamName = function(iterator) {1900var param, _i, _len, _ref4, _results;1901_ref4 = this.params;1902_results = [];1903for (_i = 0, _len = _ref4.length; _i < _len; _i++) {1904param = _ref4[_i];1905_results.push(param.eachName(iterator));1906}1907return _results;1908};19091910Code.prototype.traverseChildren = function(crossScope, func) {1911if (crossScope) {1912return Code.__super__.traverseChildren.call(this, crossScope, func);1913}1914};19151916return Code;19171918})(Base);19191920exports.Param = Param = (function(_super) {1921__extends(Param, _super);19221923function Param(name, value, splat) {1924var _ref4;1925this.name = name;1926this.value = value;1927this.splat = splat;1928if (_ref4 = (name = this.name.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref4) >= 0) {1929this.name.error("parameter name \"" + name + "\" is not allowed");1930}1931}19321933Param.prototype.children = ['name', 'value'];19341935Param.prototype.compileToFragments = function(o) {1936return this.name.compileToFragments(o, LEVEL_LIST);1937};19381939Param.prototype.asReference = function(o) {1940var node;1941if (this.reference) {1942return this.reference;1943}1944node = this.name;1945if (node["this"]) {1946node = node.properties[0].name;1947if (node.value.reserved) {1948node = new Literal(o.scope.freeVariable(node.value));1949}1950} else if (node.isComplex()) {1951node = new Literal(o.scope.freeVariable('arg'));1952}1953node = new Value(node);1954if (this.splat) {1955node = new Splat(node);1956}1957return this.reference = node;1958};19591960Param.prototype.isComplex = function() {1961return this.name.isComplex();1962};19631964Param.prototype.eachName = function(iterator, name) {1965var atParam, node, obj, _i, _len, _ref4;1966if (name == null) {1967name = this.name;1968}1969atParam = function(obj) {1970var node;1971node = obj.properties[0].name;1972if (!node.value.reserved) {1973return iterator(node.value, node);1974}1975};1976if (name instanceof Literal) {1977return iterator(name.value, name);1978}1979if (name instanceof Value) {1980return atParam(name);1981}1982_ref4 = name.objects;1983for (_i = 0, _len = _ref4.length; _i < _len; _i++) {1984obj = _ref4[_i];1985if (obj instanceof Assign) {1986this.eachName(iterator, obj.value.unwrap());1987} else if (obj instanceof Splat) {1988node = obj.name.unwrap();1989iterator(node.value, node);1990} else if (obj instanceof Value) {1991if (obj.isArray() || obj.isObject()) {1992this.eachName(iterator, obj.base);1993} else if (obj["this"]) {1994atParam(obj);1995} else {1996iterator(obj.base.value, obj.base);1997}1998} else {1999obj.error("illegal parameter " + (obj.compile()));2000}2001}2002};20032004return Param;20052006})(Base);20072008exports.Splat = Splat = (function(_super) {2009__extends(Splat, _super);20102011Splat.prototype.children = ['name'];20122013Splat.prototype.isAssignable = YES;20142015function Splat(name) {2016this.name = name.compile ? name : new Literal(name);2017}20182019Splat.prototype.assigns = function(name) {2020return this.name.assigns(name);2021};20222023Splat.prototype.compileToFragments = function(o) {2024return this.name.compileToFragments(o);2025};20262027Splat.prototype.unwrap = function() {2028return this.name;2029};20302031Splat.compileSplattedArray = function(o, list, apply) {2032var args, base, compiledNode, concatPart, fragments, i, index, node, _i, _len;2033index = -1;2034while ((node = list[++index]) && !(node instanceof Splat)) {2035continue;2036}2037if (index >= list.length) {2038return [];2039}2040if (list.length === 1) {2041node = list[0];2042fragments = node.compileToFragments(o, LEVEL_LIST);2043if (apply) {2044return fragments;2045}2046return [].concat(node.makeCode("" + (utility('slice')) + ".call("), fragments, node.makeCode(")"));2047}2048args = list.slice(index);2049for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {2050node = args[i];2051compiledNode = node.compileToFragments(o, LEVEL_LIST);2052args[i] = node instanceof Splat ? [].concat(node.makeCode("" + (utility('slice')) + ".call("), compiledNode, node.makeCode(")")) : [].concat(node.makeCode("["), compiledNode, node.makeCode("]"));2053}2054if (index === 0) {2055node = list[0];2056concatPart = node.joinFragmentArrays(args.slice(1), ', ');2057return args[0].concat(node.makeCode(".concat("), concatPart, node.makeCode(")"));2058}2059base = (function() {2060var _j, _len1, _ref4, _results;2061_ref4 = list.slice(0, index);2062_results = [];2063for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {2064node = _ref4[_j];2065_results.push(node.compileToFragments(o, LEVEL_LIST));2066}2067return _results;2068})();2069base = list[0].joinFragmentArrays(base, ', ');2070concatPart = list[index].joinFragmentArrays(args, ', ');2071return [].concat(list[0].makeCode("["), base, list[index].makeCode("].concat("), concatPart, (last(list)).makeCode(")"));2072};20732074return Splat;20752076})(Base);20772078exports.While = While = (function(_super) {2079__extends(While, _super);20802081function While(condition, options) {2082this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;2083this.guard = options != null ? options.guard : void 0;2084}20852086While.prototype.children = ['condition', 'guard', 'body'];20872088While.prototype.isStatement = YES;20892090While.prototype.makeReturn = function(res) {2091if (res) {2092return While.__super__.makeReturn.apply(this, arguments);2093} else {2094this.returns = !this.jumps({2095loop: true2096});2097return this;2098}2099};21002101While.prototype.addBody = function(body) {2102this.body = body;2103return this;2104};21052106While.prototype.jumps = function() {2107var expressions, node, _i, _len;2108expressions = this.body.expressions;2109if (!expressions.length) {2110return false;2111}2112for (_i = 0, _len = expressions.length; _i < _len; _i++) {2113node = expressions[_i];2114if (node.jumps({2115loop: true2116})) {2117return node;2118}2119}2120return false;2121};21222123While.prototype.compileNode = function(o) {2124var answer, body, rvar, set;2125o.indent += TAB;2126set = '';2127body = this.body;2128if (body.isEmpty()) {2129body = this.makeCode('');2130} else {2131if (this.returns) {2132body.makeReturn(rvar = o.scope.freeVariable('results'));2133set = "" + this.tab + rvar + " = [];\n";2134}2135if (this.guard) {2136if (body.expressions.length > 1) {2137body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));2138} else {2139if (this.guard) {2140body = Block.wrap([new If(this.guard, body)]);2141}2142}2143}2144body = [].concat(this.makeCode("\n"), body.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab));2145}2146answer = [].concat(this.makeCode(set + this.tab + "while ("), this.condition.compileToFragments(o, LEVEL_PAREN), this.makeCode(") {"), body, this.makeCode("}"));2147if (this.returns) {2148answer.push(this.makeCode("\n" + this.tab + "return " + rvar + ";"));2149}2150return answer;2151};21522153return While;21542155})(Base);21562157exports.Op = Op = (function(_super) {2158var CONVERSIONS, INVERSIONS;21592160__extends(Op, _super);21612162function Op(op, first, second, flip) {2163if (op === 'in') {2164return new In(first, second);2165}2166if (op === 'do') {2167return this.generateDo(first);2168}2169if (op === 'new') {2170if (first instanceof Call && !first["do"] && !first.isNew) {2171return first.newInstance();2172}2173if (first instanceof Code && first.bound || first["do"]) {2174first = new Parens(first);2175}2176}2177this.operator = CONVERSIONS[op] || op;2178this.first = first;2179this.second = second;2180this.flip = !!flip;2181return this;2182}21832184CONVERSIONS = {2185'==': '===',2186'!=': '!==',2187'of': 'in'2188};21892190INVERSIONS = {2191'!==': '===',2192'===': '!=='2193};21942195Op.prototype.children = ['first', 'second'];21962197Op.prototype.isSimpleNumber = NO;21982199Op.prototype.isUnary = function() {2200return !this.second;2201};22022203Op.prototype.isComplex = function() {2204var _ref4;2205return !(this.isUnary() && ((_ref4 = this.operator) === '+' || _ref4 === '-')) || this.first.isComplex();2206};22072208Op.prototype.isChainable = function() {2209var _ref4;2210return (_ref4 = this.operator) === '<' || _ref4 === '>' || _ref4 === '>=' || _ref4 === '<=' || _ref4 === '===' || _ref4 === '!==';2211};22122213Op.prototype.invert = function() {2214var allInvertable, curr, fst, op, _ref4;2215if (this.isChainable() && this.first.isChainable()) {2216allInvertable = true;2217curr = this;2218while (curr && curr.operator) {2219allInvertable && (allInvertable = curr.operator in INVERSIONS);2220curr = curr.first;2221}2222if (!allInvertable) {2223return new Parens(this).invert();2224}2225curr = this;2226while (curr && curr.operator) {2227curr.invert = !curr.invert;2228curr.operator = INVERSIONS[curr.operator];2229curr = curr.first;2230}2231return this;2232} else if (op = INVERSIONS[this.operator]) {2233this.operator = op;2234if (this.first.unwrap() instanceof Op) {2235this.first.invert();2236}2237return this;2238} else if (this.second) {2239return new Parens(this).invert();2240} else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref4 = fst.operator) === '!' || _ref4 === 'in' || _ref4 === 'instanceof')) {2241return fst;2242} else {2243return new Op('!', this);2244}2245};22462247Op.prototype.unfoldSoak = function(o) {2248var _ref4;2249return ((_ref4 = this.operator) === '++' || _ref4 === '--' || _ref4 === 'delete') && unfoldSoak(o, this, 'first');2250};22512252Op.prototype.generateDo = function(exp) {2253var call, func, param, passedParams, ref, _i, _len, _ref4;2254passedParams = [];2255func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;2256_ref4 = func.params || [];2257for (_i = 0, _len = _ref4.length; _i < _len; _i++) {2258param = _ref4[_i];2259if (param.value) {2260passedParams.push(param.value);2261delete param.value;2262} else {2263passedParams.push(param);2264}2265}2266call = new Call(exp, passedParams);2267call["do"] = true;2268return call;2269};22702271Op.prototype.compileNode = function(o) {2272var answer, isChain, _ref4, _ref5;2273isChain = this.isChainable() && this.first.isChainable();2274if (!isChain) {2275this.first.front = this.front;2276}2277if (this.operator === 'delete' && o.scope.check(this.first.unwrapAll().value)) {2278this.error('delete operand may not be argument or var');2279}2280if (((_ref4 = this.operator) === '--' || _ref4 === '++') && (_ref5 = this.first.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref5) >= 0)) {2281this.error("cannot increment/decrement \"" + (this.first.unwrapAll().value) + "\"");2282}2283if (this.isUnary()) {2284return this.compileUnary(o);2285}2286if (isChain) {2287return this.compileChain(o);2288}2289if (this.operator === '?') {2290return this.compileExistence(o);2291}2292answer = [].concat(this.first.compileToFragments(o, LEVEL_OP), this.makeCode(' ' + this.operator + ' '), this.second.compileToFragments(o, LEVEL_OP));2293if (o.level <= LEVEL_OP) {2294return answer;2295} else {2296return this.wrapInBraces(answer);2297}2298};22992300Op.prototype.compileChain = function(o) {2301var fragments, fst, shared, _ref4;2302_ref4 = this.first.second.cache(o), this.first.second = _ref4[0], shared = _ref4[1];2303fst = this.first.compileToFragments(o, LEVEL_OP);2304fragments = fst.concat(this.makeCode(" " + (this.invert ? '&&' : '||') + " "), shared.compileToFragments(o), this.makeCode(" " + this.operator + " "), this.second.compileToFragments(o, LEVEL_OP));2305return this.wrapInBraces(fragments);2306};23072308Op.prototype.compileExistence = function(o) {2309var fst, ref;2310if (!o.isExistentialEquals && this.first.isComplex()) {2311ref = new Literal(o.scope.freeVariable('ref'));2312fst = new Parens(new Assign(ref, this.first));2313} else {2314fst = this.first;2315ref = fst;2316}2317return new If(new Existence(fst), ref, {2318type: 'if'2319}).addElse(this.second).compileToFragments(o);2320};23212322Op.prototype.compileUnary = function(o) {2323var op, parts, plusMinus;2324parts = [];2325op = this.operator;2326parts.push([this.makeCode(op)]);2327if (op === '!' && this.first instanceof Existence) {2328this.first.negated = !this.first.negated;2329return this.first.compileToFragments(o);2330}2331if (o.level >= LEVEL_ACCESS) {2332return (new Parens(this)).compileToFragments(o);2333}2334plusMinus = op === '+' || op === '-';2335if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {2336parts.push([this.makeCode(' ')]);2337}2338if ((plusMinus && this.first instanceof Op) || (op === 'new' && this.first.isStatement(o))) {2339this.first = new Parens(this.first);2340}2341parts.push(this.first.compileToFragments(o, LEVEL_OP));2342if (this.flip) {2343parts.reverse();2344}2345return this.joinFragmentArrays(parts, '');2346};23472348Op.prototype.toString = function(idt) {2349return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);2350};23512352return Op;23532354})(Base);23552356exports.In = In = (function(_super) {2357__extends(In, _super);23582359function In(object, array) {2360this.object = object;2361this.array = array;2362}23632364In.prototype.children = ['object', 'array'];23652366In.prototype.invert = NEGATE;23672368In.prototype.compileNode = function(o) {2369var hasSplat, obj, _i, _len, _ref4;2370if (this.array instanceof Value && this.array.isArray()) {2371_ref4 = this.array.base.objects;2372for (_i = 0, _len = _ref4.length; _i < _len; _i++) {2373obj = _ref4[_i];2374if (!(obj instanceof Splat)) {2375continue;2376}2377hasSplat = true;2378break;2379}2380if (!hasSplat) {2381return this.compileOrTest(o);2382}2383}2384return this.compileLoopTest(o);2385};23862387In.prototype.compileOrTest = function(o) {2388var cmp, cnj, i, item, ref, sub, tests, _i, _len, _ref4, _ref5, _ref6;2389if (this.array.base.objects.length === 0) {2390return [this.makeCode("" + (!!this.negated))];2391}2392_ref4 = this.object.cache(o, LEVEL_OP), sub = _ref4[0], ref = _ref4[1];2393_ref5 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref5[0], cnj = _ref5[1];2394tests = [];2395_ref6 = this.array.base.objects;2396for (i = _i = 0, _len = _ref6.length; _i < _len; i = ++_i) {2397item = _ref6[i];2398if (i) {2399tests.push(this.makeCode(cnj));2400}2401tests = tests.concat((i ? ref : sub), this.makeCode(cmp), item.compileToFragments(o, LEVEL_ACCESS));2402}2403if (o.level < LEVEL_OP) {2404return tests;2405} else {2406return this.wrapInBraces(tests);2407}2408};24092410In.prototype.compileLoopTest = function(o) {2411var fragments, ref, sub, _ref4;2412_ref4 = this.object.cache(o, LEVEL_LIST), sub = _ref4[0], ref = _ref4[1];2413fragments = [].concat(this.makeCode(utility('indexOf') + ".call("), this.array.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), ref, this.makeCode(") " + (this.negated ? '< 0' : '>= 0')));2414if (fragmentsToText(sub) === fragmentsToText(ref)) {2415return fragments;2416}2417fragments = sub.concat(this.makeCode(', '), fragments);2418if (o.level < LEVEL_LIST) {2419return fragments;2420} else {2421return this.wrapInBraces(fragments);2422}2423};24242425In.prototype.toString = function(idt) {2426return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));2427};24282429return In;24302431})(Base);24322433exports.Try = Try = (function(_super) {2434__extends(Try, _super);24352436function Try(attempt, errorVariable, recovery, ensure) {2437this.attempt = attempt;2438this.errorVariable = errorVariable;2439this.recovery = recovery;2440this.ensure = ensure;2441}24422443Try.prototype.children = ['attempt', 'recovery', 'ensure'];24442445Try.prototype.isStatement = YES;24462447Try.prototype.jumps = function(o) {2448var _ref4;2449return this.attempt.jumps(o) || ((_ref4 = this.recovery) != null ? _ref4.jumps(o) : void 0);2450};24512452Try.prototype.makeReturn = function(res) {2453if (this.attempt) {2454this.attempt = this.attempt.makeReturn(res);2455}2456if (this.recovery) {2457this.recovery = this.recovery.makeReturn(res);2458}2459return this;2460};24612462Try.prototype.compileNode = function(o) {2463var catchPart, ensurePart, placeholder, tryPart;2464o.indent += TAB;2465tryPart = this.attempt.compileToFragments(o, LEVEL_TOP);2466catchPart = this.recovery ? (placeholder = new Literal('_error'), this.errorVariable ? this.recovery.unshift(new Assign(this.errorVariable, placeholder)) : void 0, [].concat(this.makeCode(" catch ("), placeholder.compileToFragments(o), this.makeCode(") {\n"), this.recovery.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}"))) : !(this.ensure || this.recovery) ? [this.makeCode(' catch (_error) {}')] : [];2467ensurePart = this.ensure ? [].concat(this.makeCode(" finally {\n"), this.ensure.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}")) : [];2468return [].concat(this.makeCode("" + this.tab + "try {\n"), tryPart, this.makeCode("\n" + this.tab + "}"), catchPart, ensurePart);2469};24702471return Try;24722473})(Base);24742475exports.Throw = Throw = (function(_super) {2476__extends(Throw, _super);24772478function Throw(expression) {2479this.expression = expression;2480}24812482Throw.prototype.children = ['expression'];24832484Throw.prototype.isStatement = YES;24852486Throw.prototype.jumps = NO;24872488Throw.prototype.makeReturn = THIS;24892490Throw.prototype.compileNode = function(o) {2491return [].concat(this.makeCode(this.tab + "throw "), this.expression.compileToFragments(o), this.makeCode(";"));2492};24932494return Throw;24952496})(Base);24972498exports.Existence = Existence = (function(_super) {2499__extends(Existence, _super);25002501function Existence(expression) {2502this.expression = expression;2503}25042505Existence.prototype.children = ['expression'];25062507Existence.prototype.invert = NEGATE;25082509Existence.prototype.compileNode = function(o) {2510var cmp, cnj, code, _ref4;2511this.expression.front = this.front;2512code = this.expression.compile(o, LEVEL_OP);2513if (IDENTIFIER.test(code) && !o.scope.check(code)) {2514_ref4 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref4[0], cnj = _ref4[1];2515code = "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null";2516} else {2517code = "" + code + " " + (this.negated ? '==' : '!=') + " null";2518}2519return [this.makeCode(o.level <= LEVEL_COND ? code : "(" + code + ")")];2520};25212522return Existence;25232524})(Base);25252526exports.Parens = Parens = (function(_super) {2527__extends(Parens, _super);25282529function Parens(body) {2530this.body = body;2531}25322533Parens.prototype.children = ['body'];25342535Parens.prototype.unwrap = function() {2536return this.body;2537};25382539Parens.prototype.isComplex = function() {2540return this.body.isComplex();2541};25422543Parens.prototype.compileNode = function(o) {2544var bare, expr, fragments;2545expr = this.body.unwrap();2546if (expr instanceof Value && expr.isAtomic()) {2547expr.front = this.front;2548return expr.compileToFragments(o);2549}2550fragments = expr.compileToFragments(o, LEVEL_PAREN);2551bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns));2552if (bare) {2553return fragments;2554} else {2555return this.wrapInBraces(fragments);2556}2557};25582559return Parens;25602561})(Base);25622563exports.For = For = (function(_super) {2564__extends(For, _super);25652566function For(body, source) {2567var _ref4;2568this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;2569this.body = Block.wrap([body]);2570this.own = !!source.own;2571this.object = !!source.object;2572if (this.object) {2573_ref4 = [this.index, this.name], this.name = _ref4[0], this.index = _ref4[1];2574}2575if (this.index instanceof Value) {2576this.index.error('index cannot be a pattern matching expression');2577}2578this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;2579this.pattern = this.name instanceof Value;2580if (this.range && this.index) {2581this.index.error('indexes do not apply to range loops');2582}2583if (this.range && this.pattern) {2584this.name.error('cannot pattern match over range loops');2585}2586if (this.own && !this.object) {2587this.index.error('cannot use own with for-in');2588}2589this.returns = false;2590}25912592For.prototype.children = ['body', 'source', 'guard', 'step'];25932594For.prototype.compileNode = function(o) {2595var body, bodyFragments, compare, compareDown, declare, declareDown, defPart, defPartFragments, down, forPartFragments, guardPart, idt1, increment, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, step, stepNum, stepVar, svar, varPart, _ref4, _ref5;2596body = Block.wrap([this.body]);2597lastJumps = (_ref4 = last(body.expressions)) != null ? _ref4.jumps() : void 0;2598if (lastJumps && lastJumps instanceof Return) {2599this.returns = false;2600}2601source = this.range ? this.source.base : this.source;2602scope = o.scope;2603name = this.name && (this.name.compile(o, LEVEL_LIST));2604index = this.index && (this.index.compile(o, LEVEL_LIST));2605if (name && !this.pattern) {2606scope.find(name);2607}2608if (index) {2609scope.find(index);2610}2611if (this.returns) {2612rvar = scope.freeVariable('results');2613}2614ivar = (this.object && index) || scope.freeVariable('i');2615kvar = (this.range && name) || index || ivar;2616kvarAssign = kvar !== ivar ? "" + kvar + " = " : "";2617if (this.step && !this.range) {2618_ref5 = this.cacheToCodeFragments(this.step.cache(o, LEVEL_LIST)), step = _ref5[0], stepVar = _ref5[1];2619stepNum = stepVar.match(SIMPLENUM);2620}2621if (this.pattern) {2622name = ivar;2623}2624varPart = '';2625guardPart = '';2626defPart = '';2627idt1 = this.tab + TAB;2628if (this.range) {2629forPartFragments = source.compileToFragments(merge(o, {2630index: ivar,2631name: name,2632step: this.step2633}));2634} else {2635svar = this.source.compile(o, LEVEL_LIST);2636if ((name || this.own) && !IDENTIFIER.test(svar)) {2637defPart += "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";2638svar = ref;2639}2640if (name && !this.pattern) {2641namePart = "" + name + " = " + svar + "[" + kvar + "]";2642}2643if (!this.object) {2644if (step !== stepVar) {2645defPart += "" + this.tab + step + ";\n";2646}2647if (!(this.step && stepNum && (down = +stepNum < 0))) {2648lvar = scope.freeVariable('len');2649}2650declare = "" + kvarAssign + ivar + " = 0, " + lvar + " = " + svar + ".length";2651declareDown = "" + kvarAssign + ivar + " = " + svar + ".length - 1";2652compare = "" + ivar + " < " + lvar;2653compareDown = "" + ivar + " >= 0";2654if (this.step) {2655if (stepNum) {2656if (down) {2657compare = compareDown;2658declare = declareDown;2659}2660} else {2661compare = "" + stepVar + " > 0 ? " + compare + " : " + compareDown;2662declare = "(" + stepVar + " > 0 ? (" + declare + ") : " + declareDown + ")";2663}2664increment = "" + ivar + " += " + stepVar;2665} else {2666increment = "" + (kvar !== ivar ? "++" + ivar : "" + ivar + "++");2667}2668forPartFragments = [this.makeCode("" + declare + "; " + compare + "; " + kvarAssign + increment)];2669}2670}2671if (this.returns) {2672resultPart = "" + this.tab + rvar + " = [];\n";2673returnResult = "\n" + this.tab + "return " + rvar + ";";2674body.makeReturn(rvar);2675}2676if (this.guard) {2677if (body.expressions.length > 1) {2678body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));2679} else {2680if (this.guard) {2681body = Block.wrap([new If(this.guard, body)]);2682}2683}2684}2685if (this.pattern) {2686body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + kvar + "]")));2687}2688defPartFragments = [].concat(this.makeCode(defPart), this.pluckDirectCall(o, body));2689if (namePart) {2690varPart = "\n" + idt1 + namePart + ";";2691}2692if (this.object) {2693forPartFragments = [this.makeCode("" + kvar + " in " + svar)];2694if (this.own) {2695guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + kvar + ")) continue;";2696}2697}2698bodyFragments = body.compileToFragments(merge(o, {2699indent: idt12700}), LEVEL_TOP);2701if (bodyFragments && (bodyFragments.length > 0)) {2702bodyFragments = [].concat(this.makeCode("\n"), bodyFragments, this.makeCode("\n"));2703}2704return [].concat(defPartFragments, this.makeCode("" + (resultPart || '') + this.tab + "for ("), forPartFragments, this.makeCode(") {" + guardPart + varPart), bodyFragments, this.makeCode("" + this.tab + "}" + (returnResult || '')));2705};27062707For.prototype.pluckDirectCall = function(o, body) {2708var base, defs, expr, fn, idx, ref, val, _i, _len, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9;2709defs = [];2710_ref4 = body.expressions;2711for (idx = _i = 0, _len = _ref4.length; _i < _len; idx = ++_i) {2712expr = _ref4[idx];2713expr = expr.unwrapAll();2714if (!(expr instanceof Call)) {2715continue;2716}2717val = expr.variable.unwrapAll();2718if (!((val instanceof Code) || (val instanceof Value && ((_ref5 = val.base) != null ? _ref5.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref6 = (_ref7 = val.properties[0].name) != null ? _ref7.value : void 0) === 'call' || _ref6 === 'apply')))) {2719continue;2720}2721fn = ((_ref8 = val.base) != null ? _ref8.unwrapAll() : void 0) || val;2722ref = new Literal(o.scope.freeVariable('fn'));2723base = new Value(ref);2724if (val.base) {2725_ref9 = [base, val], val.base = _ref9[0], base = _ref9[1];2726}2727body.expressions[idx] = new Call(base, expr.args);2728defs = defs.concat(this.makeCode(this.tab), new Assign(ref, fn).compileToFragments(o, LEVEL_TOP), this.makeCode(';\n'));2729}2730return defs;2731};27322733return For;27342735})(While);27362737exports.Switch = Switch = (function(_super) {2738__extends(Switch, _super);27392740function Switch(subject, cases, otherwise) {2741this.subject = subject;2742this.cases = cases;2743this.otherwise = otherwise;2744}27452746Switch.prototype.children = ['subject', 'cases', 'otherwise'];27472748Switch.prototype.isStatement = YES;27492750Switch.prototype.jumps = function(o) {2751var block, conds, _i, _len, _ref4, _ref5, _ref6;2752if (o == null) {2753o = {2754block: true2755};2756}2757_ref4 = this.cases;2758for (_i = 0, _len = _ref4.length; _i < _len; _i++) {2759_ref5 = _ref4[_i], conds = _ref5[0], block = _ref5[1];2760if (block.jumps(o)) {2761return block;2762}2763}2764return (_ref6 = this.otherwise) != null ? _ref6.jumps(o) : void 0;2765};27662767Switch.prototype.makeReturn = function(res) {2768var pair, _i, _len, _ref4, _ref5;2769_ref4 = this.cases;2770for (_i = 0, _len = _ref4.length; _i < _len; _i++) {2771pair = _ref4[_i];2772pair[1].makeReturn(res);2773}2774if (res) {2775this.otherwise || (this.otherwise = new Block([new Literal('void 0')]));2776}2777if ((_ref5 = this.otherwise) != null) {2778_ref5.makeReturn(res);2779}2780return this;2781};27822783Switch.prototype.compileNode = function(o) {2784var block, body, cond, conditions, expr, fragments, i, idt1, idt2, _i, _j, _len, _len1, _ref4, _ref5, _ref6;2785idt1 = o.indent + TAB;2786idt2 = o.indent = idt1 + TAB;2787fragments = [].concat(this.makeCode(this.tab + "switch ("), (this.subject ? this.subject.compileToFragments(o, LEVEL_PAREN) : this.makeCode("false")), this.makeCode(") {\n"));2788_ref4 = this.cases;2789for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {2790_ref5 = _ref4[i], conditions = _ref5[0], block = _ref5[1];2791_ref6 = flatten([conditions]);2792for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {2793cond = _ref6[_j];2794if (!this.subject) {2795cond = cond.invert();2796}2797fragments = fragments.concat(this.makeCode(idt1 + "case "), cond.compileToFragments(o, LEVEL_PAREN), this.makeCode(":\n"));2798}2799if ((body = block.compileToFragments(o, LEVEL_TOP)).length > 0) {2800fragments = fragments.concat(body, this.makeCode('\n'));2801}2802if (i === this.cases.length - 1 && !this.otherwise) {2803break;2804}2805expr = this.lastNonComment(block.expressions);2806if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) {2807continue;2808}2809fragments.push(cond.makeCode(idt2 + 'break;\n'));2810}2811if (this.otherwise && this.otherwise.expressions.length) {2812fragments.push.apply(fragments, [this.makeCode(idt1 + "default:\n")].concat(__slice.call(this.otherwise.compileToFragments(o, LEVEL_TOP)), [this.makeCode("\n")]));2813}2814fragments.push(this.makeCode(this.tab + '}'));2815return fragments;2816};28172818return Switch;28192820})(Base);28212822exports.If = If = (function(_super) {2823__extends(If, _super);28242825function If(condition, body, options) {2826this.body = body;2827if (options == null) {2828options = {};2829}2830this.condition = options.type === 'unless' ? condition.invert() : condition;2831this.elseBody = null;2832this.isChain = false;2833this.soak = options.soak;2834}28352836If.prototype.children = ['condition', 'body', 'elseBody'];28372838If.prototype.bodyNode = function() {2839var _ref4;2840return (_ref4 = this.body) != null ? _ref4.unwrap() : void 0;2841};28422843If.prototype.elseBodyNode = function() {2844var _ref4;2845return (_ref4 = this.elseBody) != null ? _ref4.unwrap() : void 0;2846};28472848If.prototype.addElse = function(elseBody) {2849if (this.isChain) {2850this.elseBodyNode().addElse(elseBody);2851} else {2852this.isChain = elseBody instanceof If;2853this.elseBody = this.ensureBlock(elseBody);2854}2855return this;2856};28572858If.prototype.isStatement = function(o) {2859var _ref4;2860return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref4 = this.elseBodyNode()) != null ? _ref4.isStatement(o) : void 0);2861};28622863If.prototype.jumps = function(o) {2864var _ref4;2865return this.body.jumps(o) || ((_ref4 = this.elseBody) != null ? _ref4.jumps(o) : void 0);2866};28672868If.prototype.compileNode = function(o) {2869if (this.isStatement(o)) {2870return this.compileStatement(o);2871} else {2872return this.compileExpression(o);2873}2874};28752876If.prototype.makeReturn = function(res) {2877if (res) {2878this.elseBody || (this.elseBody = new Block([new Literal('void 0')]));2879}2880this.body && (this.body = new Block([this.body.makeReturn(res)]));2881this.elseBody && (this.elseBody = new Block([this.elseBody.makeReturn(res)]));2882return this;2883};28842885If.prototype.ensureBlock = function(node) {2886if (node instanceof Block) {2887return node;2888} else {2889return new Block([node]);2890}2891};28922893If.prototype.compileStatement = function(o) {2894var answer, body, child, cond, exeq, ifPart, indent;2895child = del(o, 'chainChild');2896exeq = del(o, 'isExistentialEquals');2897if (exeq) {2898return new If(this.condition.invert(), this.elseBodyNode(), {2899type: 'if'2900}).compileToFragments(o);2901}2902indent = o.indent + TAB;2903cond = this.condition.compileToFragments(o, LEVEL_PAREN);2904body = this.ensureBlock(this.body).compileToFragments(merge(o, {2905indent: indent2906}));2907ifPart = [].concat(this.makeCode("if ("), cond, this.makeCode(") {\n"), body, this.makeCode("\n" + this.tab + "}"));2908if (!child) {2909ifPart.unshift(this.makeCode(this.tab));2910}2911if (!this.elseBody) {2912return ifPart;2913}2914answer = ifPart.concat(this.makeCode(' else '));2915if (this.isChain) {2916o.chainChild = true;2917answer = answer.concat(this.elseBody.unwrap().compileToFragments(o, LEVEL_TOP));2918} else {2919answer = answer.concat(this.makeCode("{\n"), this.elseBody.compileToFragments(merge(o, {2920indent: indent2921}), LEVEL_TOP), this.makeCode("\n" + this.tab + "}"));2922}2923return answer;2924};29252926If.prototype.compileExpression = function(o) {2927var alt, body, cond, fragments;2928cond = this.condition.compileToFragments(o, LEVEL_COND);2929body = this.bodyNode().compileToFragments(o, LEVEL_LIST);2930alt = this.elseBodyNode() ? this.elseBodyNode().compileToFragments(o, LEVEL_LIST) : [this.makeCode('void 0')];2931fragments = cond.concat(this.makeCode(" ? "), body, this.makeCode(" : "), alt);2932if (o.level >= LEVEL_COND) {2933return this.wrapInBraces(fragments);2934} else {2935return fragments;2936}2937};29382939If.prototype.unfoldSoak = function() {2940return this.soak && this;2941};29422943return If;29442945})(Base);29462947Closure = {2948wrap: function(expressions, statement, noReturn) {2949var args, argumentsNode, call, func, meth;2950if (expressions.jumps()) {2951return expressions;2952}2953func = new Code([], Block.wrap([expressions]));2954args = [];2955argumentsNode = expressions.contains(this.isLiteralArguments);2956if (argumentsNode && expressions.classBody) {2957argumentsNode.error("Class bodies shouldn't reference arguments");2958}2959if (argumentsNode || expressions.contains(this.isLiteralThis)) {2960meth = new Literal(argumentsNode ? 'apply' : 'call');2961args = [new Literal('this')];2962if (argumentsNode) {2963args.push(new Literal('arguments'));2964}2965func = new Value(func, [new Access(meth)]);2966}2967func.noReturn = noReturn;2968call = new Call(func, args);2969if (statement) {2970return Block.wrap([call]);2971} else {2972return call;2973}2974},2975isLiteralArguments: function(node) {2976return node instanceof Literal && node.value === 'arguments' && !node.asKey;2977},2978isLiteralThis: function(node) {2979return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound) || (node instanceof Call && node.isSuper);2980}2981};29822983unfoldSoak = function(o, parent, name) {2984var ifn;2985if (!(ifn = parent[name].unfoldSoak(o))) {2986return;2987}2988parent[name] = ifn.body;2989ifn.body = new Value(parent);2990return ifn;2991};29922993UTILITIES = {2994"extends": function() {2995return "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; }";2996},2997bind: function() {2998return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';2999},3000indexOf: function() {3001return "[].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";3002},3003hasProp: function() {3004return '{}.hasOwnProperty';3005},3006slice: function() {3007return '[].slice';3008}3009};30103011LEVEL_TOP = 1;30123013LEVEL_PAREN = 2;30143015LEVEL_LIST = 3;30163017LEVEL_COND = 4;30183019LEVEL_OP = 5;30203021LEVEL_ACCESS = 6;30223023TAB = ' ';30243025IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";30263027IDENTIFIER = RegExp("^" + IDENTIFIER_STR + "$");30283029SIMPLENUM = /^[+-]?\d+$/;30303031METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\]))|(" + IDENTIFIER_STR + ")$");30323033IS_STRING = /^['"]/;30343035utility = function(name) {3036var ref;3037ref = "__" + name;3038Scope.root.assign(ref, UTILITIES[name]());3039return ref;3040};30413042multident = function(code, tab) {3043code = code.replace(/\n/g, '$&' + tab);3044return code.replace(/\s+$/, '');3045};30463047}).call(this);304830493050