react / wstein / node_modules / jest-cli / node_modules / coffee-script / lib / coffee-script / nodes.js
80677 views// Generated by CoffeeScript 1.9.31(function() {2var Access, Arr, Assign, Base, Block, Call, Class, Code, CodeFragment, Comment, Existence, Expansion, Extends, For, HEXNUM, IDENTIFIER, IS_REGEX, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, NEGATE, NO, NUMBER, 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, isComplexOrAssignable, isLiteralArguments, isLiteralThis, locationDataToString, merge, multident, parseNum, ref1, ref2, some, starts, throwSyntaxError, unfoldSoak, utility,3extend1 = 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; },4hasProp = {}.hasOwnProperty,5indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },6slice = [].slice;78Error.stackTraceLimit = Infinity;910Scope = require('./scope').Scope;1112ref1 = require('./lexer'), RESERVED = ref1.RESERVED, STRICT_PROSCRIBED = ref1.STRICT_PROSCRIBED;1314ref2 = require('./helpers'), compact = ref2.compact, flatten = ref2.flatten, extend = ref2.extend, merge = ref2.merge, del = ref2.del, starts = ref2.starts, ends = ref2.ends, some = ref2.some, addLocationDataFn = ref2.addLocationDataFn, locationDataToString = ref2.locationDataToString, throwSyntaxError = ref2.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 ref3;40this.code = "" + code;41this.locationData = parent != null ? parent.locationData : void 0;42this.type = (parent != null ? (ref3 = parent.constructor) != null ? ref3.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 j, len1, results;57results = [];58for (j = 0, len1 = fragments.length; j < len1; j++) {59fragment = fragments[j];60results.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 args, argumentsNode, func, jumpNode, meth, parts, ref3;90if (jumpNode = this.jumps()) {91jumpNode.error('cannot use a pure statement in an expression');92}93o.sharedScope = true;94func = new Code([], Block.wrap([this]));95args = [];96if ((argumentsNode = this.contains(isLiteralArguments)) || this.contains(isLiteralThis)) {97args = [new Literal('this')];98if (argumentsNode) {99meth = 'apply';100args.push(new Literal('arguments'));101} else {102meth = 'call';103}104func = new Value(func, [new Access(new Literal(meth))]);105}106parts = (new Call(func, args)).compileNode(o);107if (func.isGenerator || ((ref3 = func.base) != null ? ref3.isGenerator : void 0)) {108parts.unshift(this.makeCode("(yield* "));109parts.push(this.makeCode(")"));110}111return parts;112};113114Base.prototype.cache = function(o, level, isComplex) {115var complex, ref, sub;116complex = isComplex != null ? isComplex(this) : this.isComplex();117if (complex) {118ref = new Literal(o.scope.freeVariable('ref'));119sub = new Assign(ref, this);120if (level) {121return [sub.compileToFragments(o, level), [this.makeCode(ref.value)]];122} else {123return [sub, ref];124}125} else {126ref = level ? this.compileToFragments(o, level) : this;127return [ref, ref];128}129};130131Base.prototype.cacheToCodeFragments = function(cacheValues) {132return [fragmentsToText(cacheValues[0]), fragmentsToText(cacheValues[1])];133};134135Base.prototype.makeReturn = function(res) {136var me;137me = this.unwrapAll();138if (res) {139return new Call(new Literal(res + ".push"), [me]);140} else {141return new Return(me);142}143};144145Base.prototype.contains = function(pred) {146var node;147node = void 0;148this.traverseChildren(false, function(n) {149if (pred(n)) {150node = n;151return false;152}153});154return node;155};156157Base.prototype.lastNonComment = function(list) {158var i;159i = list.length;160while (i--) {161if (!(list[i] instanceof Comment)) {162return list[i];163}164}165return null;166};167168Base.prototype.toString = function(idt, name) {169var tree;170if (idt == null) {171idt = '';172}173if (name == null) {174name = this.constructor.name;175}176tree = '\n' + idt + name;177if (this.soak) {178tree += '?';179}180this.eachChild(function(node) {181return tree += node.toString(idt + TAB);182});183return tree;184};185186Base.prototype.eachChild = function(func) {187var attr, child, j, k, len1, len2, ref3, ref4;188if (!this.children) {189return this;190}191ref3 = this.children;192for (j = 0, len1 = ref3.length; j < len1; j++) {193attr = ref3[j];194if (this[attr]) {195ref4 = flatten([this[attr]]);196for (k = 0, len2 = ref4.length; k < len2; k++) {197child = ref4[k];198if (func(child) === false) {199return this;200}201}202}203}204return this;205};206207Base.prototype.traverseChildren = function(crossScope, func) {208return this.eachChild(function(child) {209var recur;210recur = func(child);211if (recur !== false) {212return child.traverseChildren(crossScope, func);213}214});215};216217Base.prototype.invert = function() {218return new Op('!', this);219};220221Base.prototype.unwrapAll = function() {222var node;223node = this;224while (node !== (node = node.unwrap())) {225continue;226}227return node;228};229230Base.prototype.children = [];231232Base.prototype.isStatement = NO;233234Base.prototype.jumps = NO;235236Base.prototype.isComplex = YES;237238Base.prototype.isChainable = NO;239240Base.prototype.isAssignable = NO;241242Base.prototype.unwrap = THIS;243244Base.prototype.unfoldSoak = NO;245246Base.prototype.assigns = NO;247248Base.prototype.updateLocationDataIfMissing = function(locationData) {249if (this.locationData) {250return this;251}252this.locationData = locationData;253return this.eachChild(function(child) {254return child.updateLocationDataIfMissing(locationData);255});256};257258Base.prototype.error = function(message) {259return throwSyntaxError(message, this.locationData);260};261262Base.prototype.makeCode = function(code) {263return new CodeFragment(this, code);264};265266Base.prototype.wrapInBraces = function(fragments) {267return [].concat(this.makeCode('('), fragments, this.makeCode(')'));268};269270Base.prototype.joinFragmentArrays = function(fragmentsList, joinStr) {271var answer, fragments, i, j, len1;272answer = [];273for (i = j = 0, len1 = fragmentsList.length; j < len1; i = ++j) {274fragments = fragmentsList[i];275if (i) {276answer.push(this.makeCode(joinStr));277}278answer = answer.concat(fragments);279}280return answer;281};282283return Base;284285})();286287exports.Block = Block = (function(superClass1) {288extend1(Block, superClass1);289290function Block(nodes) {291this.expressions = compact(flatten(nodes || []));292}293294Block.prototype.children = ['expressions'];295296Block.prototype.push = function(node) {297this.expressions.push(node);298return this;299};300301Block.prototype.pop = function() {302return this.expressions.pop();303};304305Block.prototype.unshift = function(node) {306this.expressions.unshift(node);307return this;308};309310Block.prototype.unwrap = function() {311if (this.expressions.length === 1) {312return this.expressions[0];313} else {314return this;315}316};317318Block.prototype.isEmpty = function() {319return !this.expressions.length;320};321322Block.prototype.isStatement = function(o) {323var exp, j, len1, ref3;324ref3 = this.expressions;325for (j = 0, len1 = ref3.length; j < len1; j++) {326exp = ref3[j];327if (exp.isStatement(o)) {328return true;329}330}331return false;332};333334Block.prototype.jumps = function(o) {335var exp, j, jumpNode, len1, ref3;336ref3 = this.expressions;337for (j = 0, len1 = ref3.length; j < len1; j++) {338exp = ref3[j];339if (jumpNode = exp.jumps(o)) {340return jumpNode;341}342}343};344345Block.prototype.makeReturn = function(res) {346var expr, len;347len = this.expressions.length;348while (len--) {349expr = this.expressions[len];350if (!(expr instanceof Comment)) {351this.expressions[len] = expr.makeReturn(res);352if (expr instanceof Return && !expr.expression) {353this.expressions.splice(len, 1);354}355break;356}357}358return this;359};360361Block.prototype.compileToFragments = function(o, level) {362if (o == null) {363o = {};364}365if (o.scope) {366return Block.__super__.compileToFragments.call(this, o, level);367} else {368return this.compileRoot(o);369}370};371372Block.prototype.compileNode = function(o) {373var answer, compiledNodes, fragments, index, j, len1, node, ref3, top;374this.tab = o.indent;375top = o.level === LEVEL_TOP;376compiledNodes = [];377ref3 = this.expressions;378for (index = j = 0, len1 = ref3.length; j < len1; index = ++j) {379node = ref3[index];380node = node.unwrapAll();381node = node.unfoldSoak(o) || node;382if (node instanceof Block) {383compiledNodes.push(node.compileNode(o));384} else if (top) {385node.front = true;386fragments = node.compileToFragments(o);387if (!node.isStatement(o)) {388fragments.unshift(this.makeCode("" + this.tab));389fragments.push(this.makeCode(";"));390}391compiledNodes.push(fragments);392} else {393compiledNodes.push(node.compileToFragments(o, LEVEL_LIST));394}395}396if (top) {397if (this.spaced) {398return [].concat(this.joinFragmentArrays(compiledNodes, '\n\n'), this.makeCode("\n"));399} else {400return this.joinFragmentArrays(compiledNodes, '\n');401}402}403if (compiledNodes.length) {404answer = this.joinFragmentArrays(compiledNodes, ', ');405} else {406answer = [this.makeCode("void 0")];407}408if (compiledNodes.length > 1 && o.level >= LEVEL_LIST) {409return this.wrapInBraces(answer);410} else {411return answer;412}413};414415Block.prototype.compileRoot = function(o) {416var exp, fragments, i, j, len1, name, prelude, preludeExps, ref3, ref4, rest;417o.indent = o.bare ? '' : TAB;418o.level = LEVEL_TOP;419this.spaced = true;420o.scope = new Scope(null, this, null, (ref3 = o.referencedVars) != null ? ref3 : []);421ref4 = o.locals || [];422for (j = 0, len1 = ref4.length; j < len1; j++) {423name = ref4[j];424o.scope.parameter(name);425}426prelude = [];427if (!o.bare) {428preludeExps = (function() {429var k, len2, ref5, results;430ref5 = this.expressions;431results = [];432for (i = k = 0, len2 = ref5.length; k < len2; i = ++k) {433exp = ref5[i];434if (!(exp.unwrap() instanceof Comment)) {435break;436}437results.push(exp);438}439return results;440}).call(this);441rest = this.expressions.slice(preludeExps.length);442this.expressions = preludeExps;443if (preludeExps.length) {444prelude = this.compileNode(merge(o, {445indent: ''446}));447prelude.push(this.makeCode("\n"));448}449this.expressions = rest;450}451fragments = this.compileWithDeclarations(o);452if (o.bare) {453return fragments;454}455return [].concat(prelude, this.makeCode("(function() {\n"), fragments, this.makeCode("\n}).call(this);\n"));456};457458Block.prototype.compileWithDeclarations = function(o) {459var assigns, declars, exp, fragments, i, j, len1, post, ref3, ref4, ref5, rest, scope, spaced;460fragments = [];461post = [];462ref3 = this.expressions;463for (i = j = 0, len1 = ref3.length; j < len1; i = ++j) {464exp = ref3[i];465exp = exp.unwrap();466if (!(exp instanceof Comment || exp instanceof Literal)) {467break;468}469}470o = merge(o, {471level: LEVEL_TOP472});473if (i) {474rest = this.expressions.splice(i, 9e9);475ref4 = [this.spaced, false], spaced = ref4[0], this.spaced = ref4[1];476ref5 = [this.compileNode(o), spaced], fragments = ref5[0], this.spaced = ref5[1];477this.expressions = rest;478}479post = this.compileNode(o);480scope = o.scope;481if (scope.expressions === this) {482declars = o.scope.hasDeclarations();483assigns = scope.hasAssignments;484if (declars || assigns) {485if (i) {486fragments.push(this.makeCode('\n'));487}488fragments.push(this.makeCode(this.tab + "var "));489if (declars) {490fragments.push(this.makeCode(scope.declaredVariables().join(', ')));491}492if (assigns) {493if (declars) {494fragments.push(this.makeCode(",\n" + (this.tab + TAB)));495}496fragments.push(this.makeCode(scope.assignedVariables().join(",\n" + (this.tab + TAB))));497}498fragments.push(this.makeCode(";\n" + (this.spaced ? '\n' : '')));499} else if (fragments.length && post.length) {500fragments.push(this.makeCode("\n"));501}502}503return fragments.concat(post);504};505506Block.wrap = function(nodes) {507if (nodes.length === 1 && nodes[0] instanceof Block) {508return nodes[0];509}510return new Block(nodes);511};512513return Block;514515})(Base);516517exports.Literal = Literal = (function(superClass1) {518extend1(Literal, superClass1);519520function Literal(value1) {521this.value = value1;522}523524Literal.prototype.makeReturn = function() {525if (this.isStatement()) {526return this;527} else {528return Literal.__super__.makeReturn.apply(this, arguments);529}530};531532Literal.prototype.isAssignable = function() {533return IDENTIFIER.test(this.value);534};535536Literal.prototype.isStatement = function() {537var ref3;538return (ref3 = this.value) === 'break' || ref3 === 'continue' || ref3 === 'debugger';539};540541Literal.prototype.isComplex = NO;542543Literal.prototype.assigns = function(name) {544return name === this.value;545};546547Literal.prototype.jumps = function(o) {548if (this.value === 'break' && !((o != null ? o.loop : void 0) || (o != null ? o.block : void 0))) {549return this;550}551if (this.value === 'continue' && !(o != null ? o.loop : void 0)) {552return this;553}554};555556Literal.prototype.compileNode = function(o) {557var answer, code, ref3;558code = this.value === 'this' ? ((ref3 = o.scope.method) != null ? ref3.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved ? "\"" + this.value + "\"" : this.value;559answer = this.isStatement() ? "" + this.tab + code + ";" : code;560return [this.makeCode(answer)];561};562563Literal.prototype.toString = function() {564return ' "' + this.value + '"';565};566567return Literal;568569})(Base);570571exports.Undefined = (function(superClass1) {572extend1(Undefined, superClass1);573574function Undefined() {575return Undefined.__super__.constructor.apply(this, arguments);576}577578Undefined.prototype.isAssignable = NO;579580Undefined.prototype.isComplex = NO;581582Undefined.prototype.compileNode = function(o) {583return [this.makeCode(o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0')];584};585586return Undefined;587588})(Base);589590exports.Null = (function(superClass1) {591extend1(Null, superClass1);592593function Null() {594return Null.__super__.constructor.apply(this, arguments);595}596597Null.prototype.isAssignable = NO;598599Null.prototype.isComplex = NO;600601Null.prototype.compileNode = function() {602return [this.makeCode("null")];603};604605return Null;606607})(Base);608609exports.Bool = (function(superClass1) {610extend1(Bool, superClass1);611612Bool.prototype.isAssignable = NO;613614Bool.prototype.isComplex = NO;615616Bool.prototype.compileNode = function() {617return [this.makeCode(this.val)];618};619620function Bool(val1) {621this.val = val1;622}623624return Bool;625626})(Base);627628exports.Return = Return = (function(superClass1) {629extend1(Return, superClass1);630631function Return(expression) {632this.expression = expression;633}634635Return.prototype.children = ['expression'];636637Return.prototype.isStatement = YES;638639Return.prototype.makeReturn = THIS;640641Return.prototype.jumps = THIS;642643Return.prototype.compileToFragments = function(o, level) {644var expr, ref3;645expr = (ref3 = this.expression) != null ? ref3.makeReturn() : void 0;646if (expr && !(expr instanceof Return)) {647return expr.compileToFragments(o, level);648} else {649return Return.__super__.compileToFragments.call(this, o, level);650}651};652653Return.prototype.compileNode = function(o) {654var answer, exprIsYieldReturn, ref3;655answer = [];656exprIsYieldReturn = (ref3 = this.expression) != null ? typeof ref3.isYieldReturn === "function" ? ref3.isYieldReturn() : void 0 : void 0;657if (!exprIsYieldReturn) {658answer.push(this.makeCode(this.tab + ("return" + (this.expression ? " " : ""))));659}660if (this.expression) {661answer = answer.concat(this.expression.compileToFragments(o, LEVEL_PAREN));662}663if (!exprIsYieldReturn) {664answer.push(this.makeCode(";"));665}666return answer;667};668669return Return;670671})(Base);672673exports.Value = Value = (function(superClass1) {674extend1(Value, superClass1);675676function Value(base, props, tag) {677if (!props && base instanceof Value) {678return base;679}680this.base = base;681this.properties = props || [];682if (tag) {683this[tag] = true;684}685return this;686}687688Value.prototype.children = ['base', 'properties'];689690Value.prototype.add = function(props) {691this.properties = this.properties.concat(props);692return this;693};694695Value.prototype.hasProperties = function() {696return !!this.properties.length;697};698699Value.prototype.bareLiteral = function(type) {700return !this.properties.length && this.base instanceof type;701};702703Value.prototype.isArray = function() {704return this.bareLiteral(Arr);705};706707Value.prototype.isRange = function() {708return this.bareLiteral(Range);709};710711Value.prototype.isComplex = function() {712return this.hasProperties() || this.base.isComplex();713};714715Value.prototype.isAssignable = function() {716return this.hasProperties() || this.base.isAssignable();717};718719Value.prototype.isSimpleNumber = function() {720return this.bareLiteral(Literal) && SIMPLENUM.test(this.base.value);721};722723Value.prototype.isString = function() {724return this.bareLiteral(Literal) && IS_STRING.test(this.base.value);725};726727Value.prototype.isRegex = function() {728return this.bareLiteral(Literal) && IS_REGEX.test(this.base.value);729};730731Value.prototype.isAtomic = function() {732var j, len1, node, ref3;733ref3 = this.properties.concat(this.base);734for (j = 0, len1 = ref3.length; j < len1; j++) {735node = ref3[j];736if (node.soak || node instanceof Call) {737return false;738}739}740return true;741};742743Value.prototype.isNotCallable = function() {744return this.isSimpleNumber() || this.isString() || this.isRegex() || this.isArray() || this.isRange() || this.isSplice() || this.isObject();745};746747Value.prototype.isStatement = function(o) {748return !this.properties.length && this.base.isStatement(o);749};750751Value.prototype.assigns = function(name) {752return !this.properties.length && this.base.assigns(name);753};754755Value.prototype.jumps = function(o) {756return !this.properties.length && this.base.jumps(o);757};758759Value.prototype.isObject = function(onlyGenerated) {760if (this.properties.length) {761return false;762}763return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated);764};765766Value.prototype.isSplice = function() {767var lastProp, ref3;768ref3 = this.properties, lastProp = ref3[ref3.length - 1];769return lastProp instanceof Slice;770};771772Value.prototype.looksStatic = function(className) {773var ref3;774return this.base.value === className && this.properties.length === 1 && ((ref3 = this.properties[0].name) != null ? ref3.value : void 0) !== 'prototype';775};776777Value.prototype.unwrap = function() {778if (this.properties.length) {779return this;780} else {781return this.base;782}783};784785Value.prototype.cacheReference = function(o) {786var base, bref, name, nref, ref3;787ref3 = this.properties, name = ref3[ref3.length - 1];788if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {789return [this, this];790}791base = new Value(this.base, this.properties.slice(0, -1));792if (base.isComplex()) {793bref = new Literal(o.scope.freeVariable('base'));794base = new Value(new Parens(new Assign(bref, base)));795}796if (!name) {797return [base, bref];798}799if (name.isComplex()) {800nref = new Literal(o.scope.freeVariable('name'));801name = new Index(new Assign(nref, name.index));802nref = new Index(nref);803}804return [base.add(name), new Value(bref || base.base, [nref || name])];805};806807Value.prototype.compileNode = function(o) {808var fragments, j, len1, prop, props;809this.base.front = this.front;810props = this.properties;811fragments = this.base.compileToFragments(o, (props.length ? LEVEL_ACCESS : null));812if ((this.base instanceof Parens || props.length) && SIMPLENUM.test(fragmentsToText(fragments))) {813fragments.push(this.makeCode('.'));814}815for (j = 0, len1 = props.length; j < len1; j++) {816prop = props[j];817fragments.push.apply(fragments, prop.compileToFragments(o));818}819return fragments;820};821822Value.prototype.unfoldSoak = function(o) {823return this.unfoldedSoak != null ? this.unfoldedSoak : this.unfoldedSoak = (function(_this) {824return function() {825var fst, i, ifn, j, len1, prop, ref, ref3, ref4, snd;826if (ifn = _this.base.unfoldSoak(o)) {827(ref3 = ifn.body.properties).push.apply(ref3, _this.properties);828return ifn;829}830ref4 = _this.properties;831for (i = j = 0, len1 = ref4.length; j < len1; i = ++j) {832prop = ref4[i];833if (!prop.soak) {834continue;835}836prop.soak = false;837fst = new Value(_this.base, _this.properties.slice(0, i));838snd = new Value(_this.base, _this.properties.slice(i));839if (fst.isComplex()) {840ref = new Literal(o.scope.freeVariable('ref'));841fst = new Parens(new Assign(ref, fst));842snd.base = ref;843}844return new If(new Existence(fst), snd, {845soak: true846});847}848return false;849};850})(this)();851};852853return Value;854855})(Base);856857exports.Comment = Comment = (function(superClass1) {858extend1(Comment, superClass1);859860function Comment(comment1) {861this.comment = comment1;862}863864Comment.prototype.isStatement = YES;865866Comment.prototype.makeReturn = THIS;867868Comment.prototype.compileNode = function(o, level) {869var code, comment;870comment = this.comment.replace(/^(\s*)#(?=\s)/gm, "$1 *");871code = "/*" + (multident(comment, this.tab)) + (indexOf.call(comment, '\n') >= 0 ? "\n" + this.tab : '') + " */";872if ((level || o.level) === LEVEL_TOP) {873code = o.indent + code;874}875return [this.makeCode("\n"), this.makeCode(code)];876};877878return Comment;879880})(Base);881882exports.Call = Call = (function(superClass1) {883extend1(Call, superClass1);884885function Call(variable, args1, soak) {886this.args = args1 != null ? args1 : [];887this.soak = soak;888this.isNew = false;889this.isSuper = variable === 'super';890this.variable = this.isSuper ? null : variable;891if (variable instanceof Value && variable.isNotCallable()) {892variable.error("literal is not a function");893}894}895896Call.prototype.children = ['variable', 'args'];897898Call.prototype.newInstance = function() {899var base, ref3;900base = ((ref3 = this.variable) != null ? ref3.base : void 0) || this.variable;901if (base instanceof Call && !base.isNew) {902base.newInstance();903} else {904this.isNew = true;905}906return this;907};908909Call.prototype.superReference = function(o) {910var accesses, base, bref, klass, method, name, nref, variable;911method = o.scope.namedMethod();912if (method != null ? method.klass : void 0) {913klass = method.klass, name = method.name, variable = method.variable;914if (klass.isComplex()) {915bref = new Literal(o.scope.parent.freeVariable('base'));916base = new Value(new Parens(new Assign(bref, klass)));917variable.base = base;918variable.properties.splice(0, klass.properties.length);919}920if (name.isComplex() || (name instanceof Index && name.index.isAssignable())) {921nref = new Literal(o.scope.parent.freeVariable('name'));922name = new Index(new Assign(nref, name.index));923variable.properties.pop();924variable.properties.push(name);925}926accesses = [new Access(new Literal('__super__'))];927if (method["static"]) {928accesses.push(new Access(new Literal('constructor')));929}930accesses.push(nref != null ? new Index(nref) : name);931return (new Value(bref != null ? bref : klass, accesses)).compile(o);932} else if (method != null ? method.ctor : void 0) {933return method.name + ".__super__.constructor";934} else {935return this.error('cannot call super outside of an instance method.');936}937};938939Call.prototype.superThis = function(o) {940var method;941method = o.scope.method;942return (method && !method.klass && method.context) || "this";943};944945Call.prototype.unfoldSoak = function(o) {946var call, ifn, j, left, len1, list, ref3, ref4, rite;947if (this.soak) {948if (this.variable) {949if (ifn = unfoldSoak(o, this, 'variable')) {950return ifn;951}952ref3 = new Value(this.variable).cacheReference(o), left = ref3[0], rite = ref3[1];953} else {954left = new Literal(this.superReference(o));955rite = new Value(left);956}957rite = new Call(rite, this.args);958rite.isNew = this.isNew;959left = new Literal("typeof " + (left.compile(o)) + " === \"function\"");960return new If(left, new Value(rite), {961soak: true962});963}964call = this;965list = [];966while (true) {967if (call.variable instanceof Call) {968list.push(call);969call = call.variable;970continue;971}972if (!(call.variable instanceof Value)) {973break;974}975list.push(call);976if (!((call = call.variable.base) instanceof Call)) {977break;978}979}980ref4 = list.reverse();981for (j = 0, len1 = ref4.length; j < len1; j++) {982call = ref4[j];983if (ifn) {984if (call.variable instanceof Call) {985call.variable = ifn;986} else {987call.variable.base = ifn;988}989}990ifn = unfoldSoak(o, call, 'variable');991}992return ifn;993};994995Call.prototype.compileNode = function(o) {996var arg, argIndex, compiledArgs, compiledArray, fragments, j, len1, preface, ref3, ref4;997if ((ref3 = this.variable) != null) {998ref3.front = this.front;999}1000compiledArray = Splat.compileSplattedArray(o, this.args, true);1001if (compiledArray.length) {1002return this.compileSplat(o, compiledArray);1003}1004compiledArgs = [];1005ref4 = this.args;1006for (argIndex = j = 0, len1 = ref4.length; j < len1; argIndex = ++j) {1007arg = ref4[argIndex];1008if (argIndex) {1009compiledArgs.push(this.makeCode(", "));1010}1011compiledArgs.push.apply(compiledArgs, arg.compileToFragments(o, LEVEL_LIST));1012}1013fragments = [];1014if (this.isSuper) {1015preface = this.superReference(o) + (".call(" + (this.superThis(o)));1016if (compiledArgs.length) {1017preface += ", ";1018}1019fragments.push(this.makeCode(preface));1020} else {1021if (this.isNew) {1022fragments.push(this.makeCode('new '));1023}1024fragments.push.apply(fragments, this.variable.compileToFragments(o, LEVEL_ACCESS));1025fragments.push(this.makeCode("("));1026}1027fragments.push.apply(fragments, compiledArgs);1028fragments.push(this.makeCode(")"));1029return fragments;1030};10311032Call.prototype.compileSplat = function(o, splatArgs) {1033var answer, base, fun, idt, name, ref;1034if (this.isSuper) {1035return [].concat(this.makeCode((this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", "), splatArgs, this.makeCode(")"));1036}1037if (this.isNew) {1038idt = this.tab + TAB;1039return [].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(){})"));1040}1041answer = [];1042base = new Value(this.variable);1043if ((name = base.properties.pop()) && base.isComplex()) {1044ref = o.scope.freeVariable('ref');1045answer = answer.concat(this.makeCode("(" + ref + " = "), base.compileToFragments(o, LEVEL_LIST), this.makeCode(")"), name.compileToFragments(o));1046} else {1047fun = base.compileToFragments(o, LEVEL_ACCESS);1048if (SIMPLENUM.test(fragmentsToText(fun))) {1049fun = this.wrapInBraces(fun);1050}1051if (name) {1052ref = fragmentsToText(fun);1053fun.push.apply(fun, name.compileToFragments(o));1054} else {1055ref = 'null';1056}1057answer = answer.concat(fun);1058}1059return answer = answer.concat(this.makeCode(".apply(" + ref + ", "), splatArgs, this.makeCode(")"));1060};10611062return Call;10631064})(Base);10651066exports.Extends = Extends = (function(superClass1) {1067extend1(Extends, superClass1);10681069function Extends(child1, parent1) {1070this.child = child1;1071this.parent = parent1;1072}10731074Extends.prototype.children = ['child', 'parent'];10751076Extends.prototype.compileToFragments = function(o) {1077return new Call(new Value(new Literal(utility('extend', o))), [this.child, this.parent]).compileToFragments(o);1078};10791080return Extends;10811082})(Base);10831084exports.Access = Access = (function(superClass1) {1085extend1(Access, superClass1);10861087function Access(name1, tag) {1088this.name = name1;1089this.name.asKey = true;1090this.soak = tag === 'soak';1091}10921093Access.prototype.children = ['name'];10941095Access.prototype.compileToFragments = function(o) {1096var name;1097name = this.name.compileToFragments(o);1098if (IDENTIFIER.test(fragmentsToText(name))) {1099name.unshift(this.makeCode("."));1100} else {1101name.unshift(this.makeCode("["));1102name.push(this.makeCode("]"));1103}1104return name;1105};11061107Access.prototype.isComplex = NO;11081109return Access;11101111})(Base);11121113exports.Index = Index = (function(superClass1) {1114extend1(Index, superClass1);11151116function Index(index1) {1117this.index = index1;1118}11191120Index.prototype.children = ['index'];11211122Index.prototype.compileToFragments = function(o) {1123return [].concat(this.makeCode("["), this.index.compileToFragments(o, LEVEL_PAREN), this.makeCode("]"));1124};11251126Index.prototype.isComplex = function() {1127return this.index.isComplex();1128};11291130return Index;11311132})(Base);11331134exports.Range = Range = (function(superClass1) {1135extend1(Range, superClass1);11361137Range.prototype.children = ['from', 'to'];11381139function Range(from1, to1, tag) {1140this.from = from1;1141this.to = to1;1142this.exclusive = tag === 'exclusive';1143this.equals = this.exclusive ? '' : '=';1144}11451146Range.prototype.compileVariables = function(o) {1147var isComplex, ref3, ref4, ref5, ref6, step;1148o = merge(o, {1149top: true1150});1151isComplex = del(o, 'isComplex');1152ref3 = this.cacheToCodeFragments(this.from.cache(o, LEVEL_LIST, isComplex)), this.fromC = ref3[0], this.fromVar = ref3[1];1153ref4 = this.cacheToCodeFragments(this.to.cache(o, LEVEL_LIST, isComplex)), this.toC = ref4[0], this.toVar = ref4[1];1154if (step = del(o, 'step')) {1155ref5 = this.cacheToCodeFragments(step.cache(o, LEVEL_LIST, isComplex)), this.step = ref5[0], this.stepVar = ref5[1];1156}1157ref6 = [this.fromVar.match(NUMBER), this.toVar.match(NUMBER)], this.fromNum = ref6[0], this.toNum = ref6[1];1158if (this.stepVar) {1159return this.stepNum = this.stepVar.match(NUMBER);1160}1161};11621163Range.prototype.compileNode = function(o) {1164var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, ref3, ref4, stepPart, to, varPart;1165if (!this.fromVar) {1166this.compileVariables(o);1167}1168if (!o.index) {1169return this.compileArray(o);1170}1171known = this.fromNum && this.toNum;1172idx = del(o, 'index');1173idxName = del(o, 'name');1174namedIndex = idxName && idxName !== idx;1175varPart = idx + " = " + this.fromC;1176if (this.toC !== this.toVar) {1177varPart += ", " + this.toC;1178}1179if (this.step !== this.stepVar) {1180varPart += ", " + this.step;1181}1182ref3 = [idx + " <" + this.equals, idx + " >" + this.equals], lt = ref3[0], gt = ref3[1];1183condPart = this.stepNum ? parseNum(this.stepNum[0]) > 0 ? lt + " " + this.toVar : gt + " " + this.toVar : known ? ((ref4 = [parseNum(this.fromNum[0]), parseNum(this.toNum[0])], from = ref4[0], to = ref4[1], ref4), from <= to ? lt + " " + to : gt + " " + to) : (cond = this.stepVar ? this.stepVar + " > 0" : this.fromVar + " <= " + this.toVar, cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);1184stepPart = this.stepVar ? idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? idx + "++" : idx + "--" : namedIndex ? cond + " ? ++" + idx + " : --" + idx : cond + " ? " + idx + "++ : " + idx + "--";1185if (namedIndex) {1186varPart = idxName + " = " + varPart;1187}1188if (namedIndex) {1189stepPart = idxName + " = " + stepPart;1190}1191return [this.makeCode(varPart + "; " + condPart + "; " + stepPart)];1192};11931194Range.prototype.compileArray = function(o) {1195var args, body, cond, hasArgs, i, idt, j, post, pre, range, ref3, ref4, result, results, vars;1196if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {1197range = (function() {1198results = [];1199for (var j = ref3 = +this.fromNum, ref4 = +this.toNum; ref3 <= ref4 ? j <= ref4 : j >= ref4; ref3 <= ref4 ? j++ : j--){ results.push(j); }1200return results;1201}).apply(this);1202if (this.exclusive) {1203range.pop();1204}1205return [this.makeCode("[" + (range.join(', ')) + "]")];1206}1207idt = this.tab + TAB;1208i = o.scope.freeVariable('i', {1209single: true1210});1211result = o.scope.freeVariable('results');1212pre = "\n" + idt + result + " = [];";1213if (this.fromNum && this.toNum) {1214o.index = i;1215body = fragmentsToText(this.compileNode(o));1216} else {1217vars = (i + " = " + this.fromC) + (this.toC !== this.toVar ? ", " + this.toC : '');1218cond = this.fromVar + " <= " + this.toVar;1219body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--";1220}1221post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;1222hasArgs = function(node) {1223return node != null ? node.contains(isLiteralArguments) : void 0;1224};1225if (hasArgs(this.from) || hasArgs(this.to)) {1226args = ', arguments';1227}1228return [this.makeCode("(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this" + (args != null ? args : '') + ")")];1229};12301231return Range;12321233})(Base);12341235exports.Slice = Slice = (function(superClass1) {1236extend1(Slice, superClass1);12371238Slice.prototype.children = ['range'];12391240function Slice(range1) {1241this.range = range1;1242Slice.__super__.constructor.call(this);1243}12441245Slice.prototype.compileNode = function(o) {1246var compiled, compiledText, from, fromCompiled, ref3, to, toStr;1247ref3 = this.range, to = ref3.to, from = ref3.from;1248fromCompiled = from && from.compileToFragments(o, LEVEL_PAREN) || [this.makeCode('0')];1249if (to) {1250compiled = to.compileToFragments(o, LEVEL_PAREN);1251compiledText = fragmentsToText(compiled);1252if (!(!this.range.exclusive && +compiledText === -1)) {1253toStr = ', ' + (this.range.exclusive ? compiledText : SIMPLENUM.test(compiledText) ? "" + (+compiledText + 1) : (compiled = to.compileToFragments(o, LEVEL_ACCESS), "+" + (fragmentsToText(compiled)) + " + 1 || 9e9"));1254}1255}1256return [this.makeCode(".slice(" + (fragmentsToText(fromCompiled)) + (toStr || '') + ")")];1257};12581259return Slice;12601261})(Base);12621263exports.Obj = Obj = (function(superClass1) {1264extend1(Obj, superClass1);12651266function Obj(props, generated) {1267this.generated = generated != null ? generated : false;1268this.objects = this.properties = props || [];1269}12701271Obj.prototype.children = ['properties'];12721273Obj.prototype.compileNode = function(o) {1274var answer, dynamicIndex, hasDynamic, i, idt, indent, j, join, k, key, l, lastNoncom, len1, len2, len3, node, oref, prop, props, ref3, value;1275props = this.properties;1276if (this.generated) {1277for (j = 0, len1 = props.length; j < len1; j++) {1278node = props[j];1279if (node instanceof Value) {1280node.error('cannot have an implicit value in an implicit object');1281}1282}1283}1284for (dynamicIndex = k = 0, len2 = props.length; k < len2; dynamicIndex = ++k) {1285prop = props[dynamicIndex];1286if ((prop.variable || prop).base instanceof Parens) {1287break;1288}1289}1290hasDynamic = dynamicIndex < props.length;1291idt = o.indent += TAB;1292lastNoncom = this.lastNonComment(this.properties);1293answer = [];1294if (hasDynamic) {1295oref = o.scope.freeVariable('obj');1296answer.push(this.makeCode("(\n" + idt + oref + " = "));1297}1298answer.push(this.makeCode("{" + (props.length === 0 || dynamicIndex === 0 ? '}' : '\n')));1299for (i = l = 0, len3 = props.length; l < len3; i = ++l) {1300prop = props[i];1301if (i === dynamicIndex) {1302if (i !== 0) {1303answer.push(this.makeCode("\n" + idt + "}"));1304}1305answer.push(this.makeCode(',\n'));1306}1307join = i === props.length - 1 || i === dynamicIndex - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';1308indent = prop instanceof Comment ? '' : idt;1309if (hasDynamic && i < dynamicIndex) {1310indent += TAB;1311}1312if (prop instanceof Assign && prop.variable instanceof Value && prop.variable.hasProperties()) {1313prop.variable.error('invalid object key');1314}1315if (prop instanceof Value && prop["this"]) {1316prop = new Assign(prop.properties[0].name, prop, 'object');1317}1318if (!(prop instanceof Comment)) {1319if (i < dynamicIndex) {1320if (!(prop instanceof Assign)) {1321prop = new Assign(prop, prop, 'object');1322}1323(prop.variable.base || prop.variable).asKey = true;1324} else {1325if (prop instanceof Assign) {1326key = prop.variable;1327value = prop.value;1328} else {1329ref3 = prop.base.cache(o), key = ref3[0], value = ref3[1];1330}1331prop = new Assign(new Value(new Literal(oref), [new Access(key)]), value);1332}1333}1334if (indent) {1335answer.push(this.makeCode(indent));1336}1337answer.push.apply(answer, prop.compileToFragments(o, LEVEL_TOP));1338if (join) {1339answer.push(this.makeCode(join));1340}1341}1342if (hasDynamic) {1343answer.push(this.makeCode(",\n" + idt + oref + "\n" + this.tab + ")"));1344} else {1345if (props.length !== 0) {1346answer.push(this.makeCode("\n" + this.tab + "}"));1347}1348}1349if (this.front && !hasDynamic) {1350return this.wrapInBraces(answer);1351} else {1352return answer;1353}1354};13551356Obj.prototype.assigns = function(name) {1357var j, len1, prop, ref3;1358ref3 = this.properties;1359for (j = 0, len1 = ref3.length; j < len1; j++) {1360prop = ref3[j];1361if (prop.assigns(name)) {1362return true;1363}1364}1365return false;1366};13671368return Obj;13691370})(Base);13711372exports.Arr = Arr = (function(superClass1) {1373extend1(Arr, superClass1);13741375function Arr(objs) {1376this.objects = objs || [];1377}13781379Arr.prototype.children = ['objects'];13801381Arr.prototype.compileNode = function(o) {1382var answer, compiledObjs, fragments, index, j, len1, obj;1383if (!this.objects.length) {1384return [this.makeCode('[]')];1385}1386o.indent += TAB;1387answer = Splat.compileSplattedArray(o, this.objects);1388if (answer.length) {1389return answer;1390}1391answer = [];1392compiledObjs = (function() {1393var j, len1, ref3, results;1394ref3 = this.objects;1395results = [];1396for (j = 0, len1 = ref3.length; j < len1; j++) {1397obj = ref3[j];1398results.push(obj.compileToFragments(o, LEVEL_LIST));1399}1400return results;1401}).call(this);1402for (index = j = 0, len1 = compiledObjs.length; j < len1; index = ++j) {1403fragments = compiledObjs[index];1404if (index) {1405answer.push(this.makeCode(", "));1406}1407answer.push.apply(answer, fragments);1408}1409if (fragmentsToText(answer).indexOf('\n') >= 0) {1410answer.unshift(this.makeCode("[\n" + o.indent));1411answer.push(this.makeCode("\n" + this.tab + "]"));1412} else {1413answer.unshift(this.makeCode("["));1414answer.push(this.makeCode("]"));1415}1416return answer;1417};14181419Arr.prototype.assigns = function(name) {1420var j, len1, obj, ref3;1421ref3 = this.objects;1422for (j = 0, len1 = ref3.length; j < len1; j++) {1423obj = ref3[j];1424if (obj.assigns(name)) {1425return true;1426}1427}1428return false;1429};14301431return Arr;14321433})(Base);14341435exports.Class = Class = (function(superClass1) {1436extend1(Class, superClass1);14371438function Class(variable1, parent1, body1) {1439this.variable = variable1;1440this.parent = parent1;1441this.body = body1 != null ? body1 : new Block;1442this.boundFuncs = [];1443this.body.classBody = true;1444}14451446Class.prototype.children = ['variable', 'parent', 'body'];14471448Class.prototype.determineName = function() {1449var decl, ref3, tail;1450if (!this.variable) {1451return null;1452}1453ref3 = this.variable.properties, tail = ref3[ref3.length - 1];1454decl = tail ? tail instanceof Access && tail.name.value : this.variable.base.value;1455if (indexOf.call(STRICT_PROSCRIBED, decl) >= 0) {1456this.variable.error("class variable name may not be " + decl);1457}1458return decl && (decl = IDENTIFIER.test(decl) && decl);1459};14601461Class.prototype.setContext = function(name) {1462return this.body.traverseChildren(false, function(node) {1463if (node.classBody) {1464return false;1465}1466if (node instanceof Literal && node.value === 'this') {1467return node.value = name;1468} else if (node instanceof Code) {1469if (node.bound) {1470return node.context = name;1471}1472}1473});1474};14751476Class.prototype.addBoundFunctions = function(o) {1477var bvar, j, len1, lhs, ref3;1478ref3 = this.boundFuncs;1479for (j = 0, len1 = ref3.length; j < len1; j++) {1480bvar = ref3[j];1481lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o);1482this.ctor.body.unshift(new Literal(lhs + " = " + (utility('bind', o)) + "(" + lhs + ", this)"));1483}1484};14851486Class.prototype.addProperties = function(node, name, o) {1487var acc, assign, base, exprs, func, props;1488props = node.base.properties.slice(0);1489exprs = (function() {1490var results;1491results = [];1492while (assign = props.shift()) {1493if (assign instanceof Assign) {1494base = assign.variable.base;1495delete assign.context;1496func = assign.value;1497if (base.value === 'constructor') {1498if (this.ctor) {1499assign.error('cannot define more than one constructor in a class');1500}1501if (func.bound) {1502assign.error('cannot define a constructor as a bound function');1503}1504if (func instanceof Code) {1505assign = this.ctor = func;1506} else {1507this.externalCtor = o.classScope.freeVariable('class');1508assign = new Assign(new Literal(this.externalCtor), func);1509}1510} else {1511if (assign.variable["this"]) {1512func["static"] = true;1513} else {1514acc = base.isComplex() ? new Index(base) : new Access(base);1515assign.variable = new Value(new Literal(name), [new Access(new Literal('prototype')), acc]);1516if (func instanceof Code && func.bound) {1517this.boundFuncs.push(base);1518func.bound = false;1519}1520}1521}1522}1523results.push(assign);1524}1525return results;1526}).call(this);1527return compact(exprs);1528};15291530Class.prototype.walkBody = function(name, o) {1531return this.traverseChildren(false, (function(_this) {1532return function(child) {1533var cont, exps, i, j, len1, node, ref3;1534cont = true;1535if (child instanceof Class) {1536return false;1537}1538if (child instanceof Block) {1539ref3 = exps = child.expressions;1540for (i = j = 0, len1 = ref3.length; j < len1; i = ++j) {1541node = ref3[i];1542if (node instanceof Assign && node.variable.looksStatic(name)) {1543node.value["static"] = true;1544} else if (node instanceof Value && node.isObject(true)) {1545cont = false;1546exps[i] = _this.addProperties(node, name, o);1547}1548}1549child.expressions = exps = flatten(exps);1550}1551return cont && !(child instanceof Class);1552};1553})(this));1554};15551556Class.prototype.hoistDirectivePrologue = function() {1557var expressions, index, node;1558index = 0;1559expressions = this.body.expressions;1560while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {1561++index;1562}1563return this.directives = expressions.splice(0, index);1564};15651566Class.prototype.ensureConstructor = function(name) {1567if (!this.ctor) {1568this.ctor = new Code;1569if (this.externalCtor) {1570this.ctor.body.push(new Literal(this.externalCtor + ".apply(this, arguments)"));1571} else if (this.parent) {1572this.ctor.body.push(new Literal(name + ".__super__.constructor.apply(this, arguments)"));1573}1574this.ctor.body.makeReturn();1575this.body.expressions.unshift(this.ctor);1576}1577this.ctor.ctor = this.ctor.name = name;1578this.ctor.klass = null;1579return this.ctor.noReturn = true;1580};15811582Class.prototype.compileNode = function(o) {1583var args, argumentsNode, func, jumpNode, klass, lname, name, ref3, superClass;1584if (jumpNode = this.body.jumps()) {1585jumpNode.error('Class bodies cannot contain pure statements');1586}1587if (argumentsNode = this.body.contains(isLiteralArguments)) {1588argumentsNode.error("Class bodies shouldn't reference arguments");1589}1590name = this.determineName() || '_Class';1591if (name.reserved) {1592name = "_" + name;1593}1594lname = new Literal(name);1595func = new Code([], Block.wrap([this.body]));1596args = [];1597o.classScope = func.makeScope(o.scope);1598this.hoistDirectivePrologue();1599this.setContext(name);1600this.walkBody(name, o);1601this.ensureConstructor(name);1602this.addBoundFunctions(o);1603this.body.spaced = true;1604this.body.expressions.push(lname);1605if (this.parent) {1606superClass = new Literal(o.classScope.freeVariable('superClass', {1607reserve: false1608}));1609this.body.expressions.unshift(new Extends(lname, superClass));1610func.params.push(new Param(superClass));1611args.push(this.parent);1612}1613(ref3 = this.body.expressions).unshift.apply(ref3, this.directives);1614klass = new Parens(new Call(func, args));1615if (this.variable) {1616klass = new Assign(this.variable, klass);1617}1618return klass.compileToFragments(o);1619};16201621return Class;16221623})(Base);16241625exports.Assign = Assign = (function(superClass1) {1626extend1(Assign, superClass1);16271628function Assign(variable1, value1, context, options) {1629var forbidden, name, ref3;1630this.variable = variable1;1631this.value = value1;1632this.context = context;1633this.param = options && options.param;1634this.subpattern = options && options.subpattern;1635forbidden = (ref3 = (name = this.variable.unwrapAll().value), indexOf.call(STRICT_PROSCRIBED, ref3) >= 0);1636if (forbidden && this.context !== 'object') {1637this.variable.error("variable name may not be \"" + name + "\"");1638}1639}16401641Assign.prototype.children = ['variable', 'value'];16421643Assign.prototype.isStatement = function(o) {1644return (o != null ? o.level : void 0) === LEVEL_TOP && (this.context != null) && indexOf.call(this.context, "?") >= 0;1645};16461647Assign.prototype.assigns = function(name) {1648return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);1649};16501651Assign.prototype.unfoldSoak = function(o) {1652return unfoldSoak(o, this, 'variable');1653};16541655Assign.prototype.compileNode = function(o) {1656var answer, compiledName, isValue, j, name, properties, prototype, ref3, ref4, ref5, ref6, ref7, val, varBase;1657if (isValue = this.variable instanceof Value) {1658if (this.variable.isArray() || this.variable.isObject()) {1659return this.compilePatternMatch(o);1660}1661if (this.variable.isSplice()) {1662return this.compileSplice(o);1663}1664if ((ref3 = this.context) === '||=' || ref3 === '&&=' || ref3 === '?=') {1665return this.compileConditional(o);1666}1667if ((ref4 = this.context) === '**=' || ref4 === '//=' || ref4 === '%%=') {1668return this.compileSpecialMath(o);1669}1670}1671if (this.value instanceof Code) {1672if (this.value["static"]) {1673this.value.klass = this.variable.base;1674this.value.name = this.variable.properties[0];1675this.value.variable = this.variable;1676} else if (((ref5 = this.variable.properties) != null ? ref5.length : void 0) >= 2) {1677ref6 = this.variable.properties, properties = 3 <= ref6.length ? slice.call(ref6, 0, j = ref6.length - 2) : (j = 0, []), prototype = ref6[j++], name = ref6[j++];1678if (((ref7 = prototype.name) != null ? ref7.value : void 0) === 'prototype') {1679this.value.klass = new Value(this.variable.base, properties);1680this.value.name = name;1681this.value.variable = this.variable;1682}1683}1684}1685if (!this.context) {1686varBase = this.variable.unwrapAll();1687if (!varBase.isAssignable()) {1688this.variable.error("\"" + (this.variable.compile(o)) + "\" cannot be assigned");1689}1690if (!(typeof varBase.hasProperties === "function" ? varBase.hasProperties() : void 0)) {1691if (this.param) {1692o.scope.add(varBase.value, 'var');1693} else {1694o.scope.find(varBase.value);1695}1696}1697}1698val = this.value.compileToFragments(o, LEVEL_LIST);1699compiledName = this.variable.compileToFragments(o, LEVEL_LIST);1700if (this.context === 'object') {1701return compiledName.concat(this.makeCode(": "), val);1702}1703answer = compiledName.concat(this.makeCode(" " + (this.context || '=') + " "), val);1704if (o.level <= LEVEL_LIST) {1705return answer;1706} else {1707return this.wrapInBraces(answer);1708}1709};17101711Assign.prototype.compilePatternMatch = function(o) {1712var acc, assigns, code, expandedIdx, fragments, i, idx, isObject, ivar, j, len1, name, obj, objects, olen, ref, ref3, ref4, ref5, ref6, ref7, ref8, rest, top, val, value, vvar, vvarText;1713top = o.level === LEVEL_TOP;1714value = this.value;1715objects = this.variable.base.objects;1716if (!(olen = objects.length)) {1717code = value.compileToFragments(o);1718if (o.level >= LEVEL_OP) {1719return this.wrapInBraces(code);1720} else {1721return code;1722}1723}1724isObject = this.variable.isObject();1725if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {1726if (obj instanceof Assign) {1727ref3 = obj, (ref4 = ref3.variable, idx = ref4.base), obj = ref3.value;1728} else {1729idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);1730}1731acc = IDENTIFIER.test(idx.unwrap().value || 0);1732value = new Value(value);1733value.properties.push(new (acc ? Access : Index)(idx));1734if (ref5 = obj.unwrap().value, indexOf.call(RESERVED, ref5) >= 0) {1735obj.error("assignment to a reserved word: " + (obj.compile(o)));1736}1737return new Assign(obj, value, null, {1738param: this.param1739}).compileToFragments(o, LEVEL_TOP);1740}1741vvar = value.compileToFragments(o, LEVEL_LIST);1742vvarText = fragmentsToText(vvar);1743assigns = [];1744expandedIdx = false;1745if (!IDENTIFIER.test(vvarText) || this.variable.assigns(vvarText)) {1746assigns.push([this.makeCode((ref = o.scope.freeVariable('ref')) + " = ")].concat(slice.call(vvar)));1747vvar = [this.makeCode(ref)];1748vvarText = ref;1749}1750for (i = j = 0, len1 = objects.length; j < len1; i = ++j) {1751obj = objects[i];1752idx = i;1753if (isObject) {1754if (obj instanceof Assign) {1755ref6 = obj, (ref7 = ref6.variable, idx = ref7.base), obj = ref6.value;1756} else {1757if (obj.base instanceof Parens) {1758ref8 = new Value(obj.unwrapAll()).cacheReference(o), obj = ref8[0], idx = ref8[1];1759} else {1760idx = obj["this"] ? obj.properties[0].name : obj;1761}1762}1763}1764if (!expandedIdx && obj instanceof Splat) {1765name = obj.name.unwrap().value;1766obj = obj.unwrap();1767val = olen + " <= " + vvarText + ".length ? " + (utility('slice', o)) + ".call(" + vvarText + ", " + i;1768if (rest = olen - i - 1) {1769ivar = o.scope.freeVariable('i', {1770single: true1771});1772val += ", " + ivar + " = " + vvarText + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])";1773} else {1774val += ") : []";1775}1776val = new Literal(val);1777expandedIdx = ivar + "++";1778} else if (!expandedIdx && obj instanceof Expansion) {1779if (rest = olen - i - 1) {1780if (rest === 1) {1781expandedIdx = vvarText + ".length - 1";1782} else {1783ivar = o.scope.freeVariable('i', {1784single: true1785});1786val = new Literal(ivar + " = " + vvarText + ".length - " + rest);1787expandedIdx = ivar + "++";1788assigns.push(val.compileToFragments(o, LEVEL_LIST));1789}1790}1791continue;1792} else {1793name = obj.unwrap().value;1794if (obj instanceof Splat || obj instanceof Expansion) {1795obj.error("multiple splats/expansions are disallowed in an assignment");1796}1797if (typeof idx === 'number') {1798idx = new Literal(expandedIdx || idx);1799acc = false;1800} else {1801acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);1802}1803val = new Value(new Literal(vvarText), [new (acc ? Access : Index)(idx)]);1804}1805if ((name != null) && indexOf.call(RESERVED, name) >= 0) {1806obj.error("assignment to a reserved word: " + (obj.compile(o)));1807}1808assigns.push(new Assign(obj, val, null, {1809param: this.param,1810subpattern: true1811}).compileToFragments(o, LEVEL_LIST));1812}1813if (!(top || this.subpattern)) {1814assigns.push(vvar);1815}1816fragments = this.joinFragmentArrays(assigns, ', ');1817if (o.level < LEVEL_LIST) {1818return fragments;1819} else {1820return this.wrapInBraces(fragments);1821}1822};18231824Assign.prototype.compileConditional = function(o) {1825var fragments, left, ref3, right;1826ref3 = this.variable.cacheReference(o), left = ref3[0], right = ref3[1];1827if (!left.properties.length && left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) {1828this.variable.error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been declared before");1829}1830if (indexOf.call(this.context, "?") >= 0) {1831o.isExistentialEquals = true;1832return new If(new Existence(left), right, {1833type: 'if'1834}).addElse(new Assign(right, this.value, '=')).compileToFragments(o);1835} else {1836fragments = new Op(this.context.slice(0, -1), left, new Assign(right, this.value, '=')).compileToFragments(o);1837if (o.level <= LEVEL_LIST) {1838return fragments;1839} else {1840return this.wrapInBraces(fragments);1841}1842}1843};18441845Assign.prototype.compileSpecialMath = function(o) {1846var left, ref3, right;1847ref3 = this.variable.cacheReference(o), left = ref3[0], right = ref3[1];1848return new Assign(left, new Op(this.context.slice(0, -1), right, this.value)).compileToFragments(o);1849};18501851Assign.prototype.compileSplice = function(o) {1852var answer, exclusive, from, fromDecl, fromRef, name, ref3, ref4, ref5, to, valDef, valRef;1853ref3 = this.variable.properties.pop().range, from = ref3.from, to = ref3.to, exclusive = ref3.exclusive;1854name = this.variable.compile(o);1855if (from) {1856ref4 = this.cacheToCodeFragments(from.cache(o, LEVEL_OP)), fromDecl = ref4[0], fromRef = ref4[1];1857} else {1858fromDecl = fromRef = '0';1859}1860if (to) {1861if (from instanceof Value && from.isSimpleNumber() && to instanceof Value && to.isSimpleNumber()) {1862to = to.compile(o) - fromRef;1863if (!exclusive) {1864to += 1;1865}1866} else {1867to = to.compile(o, LEVEL_ACCESS) + ' - ' + fromRef;1868if (!exclusive) {1869to += ' + 1';1870}1871}1872} else {1873to = "9e9";1874}1875ref5 = this.value.cache(o, LEVEL_LIST), valDef = ref5[0], valRef = ref5[1];1876answer = [].concat(this.makeCode("[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat("), valDef, this.makeCode(")), "), valRef);1877if (o.level > LEVEL_TOP) {1878return this.wrapInBraces(answer);1879} else {1880return answer;1881}1882};18831884return Assign;18851886})(Base);18871888exports.Code = Code = (function(superClass1) {1889extend1(Code, superClass1);18901891function Code(params, body, tag) {1892this.params = params || [];1893this.body = body || new Block;1894this.bound = tag === 'boundfunc';1895this.isGenerator = !!this.body.contains(function(node) {1896var ref3;1897return node instanceof Op && ((ref3 = node.operator) === 'yield' || ref3 === 'yield*');1898});1899}19001901Code.prototype.children = ['params', 'body'];19021903Code.prototype.isStatement = function() {1904return !!this.ctor;1905};19061907Code.prototype.jumps = NO;19081909Code.prototype.makeScope = function(parentScope) {1910return new Scope(parentScope, this.body, this);1911};19121913Code.prototype.compileNode = function(o) {1914var answer, boundfunc, code, exprs, i, j, k, l, len1, len2, len3, len4, len5, len6, lit, m, p, param, params, q, r, ref, ref3, ref4, ref5, ref6, ref7, ref8, splats, uniqs, val, wasEmpty, wrapper;1915if (this.bound && ((ref3 = o.scope.method) != null ? ref3.bound : void 0)) {1916this.context = o.scope.method.context;1917}1918if (this.bound && !this.context) {1919this.context = '_this';1920wrapper = new Code([new Param(new Literal(this.context))], new Block([this]));1921boundfunc = new Call(wrapper, [new Literal('this')]);1922boundfunc.updateLocationDataIfMissing(this.locationData);1923return boundfunc.compileNode(o);1924}1925o.scope = del(o, 'classScope') || this.makeScope(o.scope);1926o.scope.shared = del(o, 'sharedScope');1927o.indent += TAB;1928delete o.bare;1929delete o.isExistentialEquals;1930params = [];1931exprs = [];1932ref4 = this.params;1933for (j = 0, len1 = ref4.length; j < len1; j++) {1934param = ref4[j];1935if (!(param instanceof Expansion)) {1936o.scope.parameter(param.asReference(o));1937}1938}1939ref5 = this.params;1940for (k = 0, len2 = ref5.length; k < len2; k++) {1941param = ref5[k];1942if (!(param.splat || param instanceof Expansion)) {1943continue;1944}1945ref6 = this.params;1946for (l = 0, len3 = ref6.length; l < len3; l++) {1947p = ref6[l];1948if (!(p instanceof Expansion) && p.name.value) {1949o.scope.add(p.name.value, 'var', true);1950}1951}1952splats = new Assign(new Value(new Arr((function() {1953var len4, m, ref7, results;1954ref7 = this.params;1955results = [];1956for (m = 0, len4 = ref7.length; m < len4; m++) {1957p = ref7[m];1958results.push(p.asReference(o));1959}1960return results;1961}).call(this))), new Value(new Literal('arguments')));1962break;1963}1964ref7 = this.params;1965for (m = 0, len4 = ref7.length; m < len4; m++) {1966param = ref7[m];1967if (param.isComplex()) {1968val = ref = param.asReference(o);1969if (param.value) {1970val = new Op('?', ref, param.value);1971}1972exprs.push(new Assign(new Value(param.name), val, '=', {1973param: true1974}));1975} else {1976ref = param;1977if (param.value) {1978lit = new Literal(ref.name.value + ' == null');1979val = new Assign(new Value(param.name), param.value, '=');1980exprs.push(new If(lit, val));1981}1982}1983if (!splats) {1984params.push(ref);1985}1986}1987wasEmpty = this.body.isEmpty();1988if (splats) {1989exprs.unshift(splats);1990}1991if (exprs.length) {1992(ref8 = this.body.expressions).unshift.apply(ref8, exprs);1993}1994for (i = q = 0, len5 = params.length; q < len5; i = ++q) {1995p = params[i];1996params[i] = p.compileToFragments(o);1997o.scope.parameter(fragmentsToText(params[i]));1998}1999uniqs = [];2000this.eachParamName(function(name, node) {2001if (indexOf.call(uniqs, name) >= 0) {2002node.error("multiple parameters named " + name);2003}2004return uniqs.push(name);2005});2006if (!(wasEmpty || this.noReturn)) {2007this.body.makeReturn();2008}2009code = 'function';2010if (this.isGenerator) {2011code += '*';2012}2013if (this.ctor) {2014code += ' ' + this.name;2015}2016code += '(';2017answer = [this.makeCode(code)];2018for (i = r = 0, len6 = params.length; r < len6; i = ++r) {2019p = params[i];2020if (i) {2021answer.push(this.makeCode(", "));2022}2023answer.push.apply(answer, p);2024}2025answer.push(this.makeCode(') {'));2026if (!this.body.isEmpty()) {2027answer = answer.concat(this.makeCode("\n"), this.body.compileWithDeclarations(o), this.makeCode("\n" + this.tab));2028}2029answer.push(this.makeCode('}'));2030if (this.ctor) {2031return [this.makeCode(this.tab)].concat(slice.call(answer));2032}2033if (this.front || (o.level >= LEVEL_ACCESS)) {2034return this.wrapInBraces(answer);2035} else {2036return answer;2037}2038};20392040Code.prototype.eachParamName = function(iterator) {2041var j, len1, param, ref3, results;2042ref3 = this.params;2043results = [];2044for (j = 0, len1 = ref3.length; j < len1; j++) {2045param = ref3[j];2046results.push(param.eachName(iterator));2047}2048return results;2049};20502051Code.prototype.traverseChildren = function(crossScope, func) {2052if (crossScope) {2053return Code.__super__.traverseChildren.call(this, crossScope, func);2054}2055};20562057return Code;20582059})(Base);20602061exports.Param = Param = (function(superClass1) {2062extend1(Param, superClass1);20632064function Param(name1, value1, splat) {2065var name, ref3;2066this.name = name1;2067this.value = value1;2068this.splat = splat;2069if (ref3 = (name = this.name.unwrapAll().value), indexOf.call(STRICT_PROSCRIBED, ref3) >= 0) {2070this.name.error("parameter name \"" + name + "\" is not allowed");2071}2072}20732074Param.prototype.children = ['name', 'value'];20752076Param.prototype.compileToFragments = function(o) {2077return this.name.compileToFragments(o, LEVEL_LIST);2078};20792080Param.prototype.asReference = function(o) {2081var name, node;2082if (this.reference) {2083return this.reference;2084}2085node = this.name;2086if (node["this"]) {2087name = node.properties[0].name.value;2088if (name.reserved) {2089name = "_" + name;2090}2091node = new Literal(o.scope.freeVariable(name));2092} else if (node.isComplex()) {2093node = new Literal(o.scope.freeVariable('arg'));2094}2095node = new Value(node);2096if (this.splat) {2097node = new Splat(node);2098}2099node.updateLocationDataIfMissing(this.locationData);2100return this.reference = node;2101};21022103Param.prototype.isComplex = function() {2104return this.name.isComplex();2105};21062107Param.prototype.eachName = function(iterator, name) {2108var atParam, j, len1, node, obj, ref3;2109if (name == null) {2110name = this.name;2111}2112atParam = function(obj) {2113return iterator("@" + obj.properties[0].name.value, obj);2114};2115if (name instanceof Literal) {2116return iterator(name.value, name);2117}2118if (name instanceof Value) {2119return atParam(name);2120}2121ref3 = name.objects;2122for (j = 0, len1 = ref3.length; j < len1; j++) {2123obj = ref3[j];2124if (obj instanceof Assign) {2125this.eachName(iterator, obj.value.unwrap());2126} else if (obj instanceof Splat) {2127node = obj.name.unwrap();2128iterator(node.value, node);2129} else if (obj instanceof Value) {2130if (obj.isArray() || obj.isObject()) {2131this.eachName(iterator, obj.base);2132} else if (obj["this"]) {2133atParam(obj);2134} else {2135iterator(obj.base.value, obj.base);2136}2137} else if (!(obj instanceof Expansion)) {2138obj.error("illegal parameter " + (obj.compile()));2139}2140}2141};21422143return Param;21442145})(Base);21462147exports.Splat = Splat = (function(superClass1) {2148extend1(Splat, superClass1);21492150Splat.prototype.children = ['name'];21512152Splat.prototype.isAssignable = YES;21532154function Splat(name) {2155this.name = name.compile ? name : new Literal(name);2156}21572158Splat.prototype.assigns = function(name) {2159return this.name.assigns(name);2160};21612162Splat.prototype.compileToFragments = function(o) {2163return this.name.compileToFragments(o);2164};21652166Splat.prototype.unwrap = function() {2167return this.name;2168};21692170Splat.compileSplattedArray = function(o, list, apply) {2171var args, base, compiledNode, concatPart, fragments, i, index, j, last, len1, node;2172index = -1;2173while ((node = list[++index]) && !(node instanceof Splat)) {2174continue;2175}2176if (index >= list.length) {2177return [];2178}2179if (list.length === 1) {2180node = list[0];2181fragments = node.compileToFragments(o, LEVEL_LIST);2182if (apply) {2183return fragments;2184}2185return [].concat(node.makeCode((utility('slice', o)) + ".call("), fragments, node.makeCode(")"));2186}2187args = list.slice(index);2188for (i = j = 0, len1 = args.length; j < len1; i = ++j) {2189node = args[i];2190compiledNode = node.compileToFragments(o, LEVEL_LIST);2191args[i] = node instanceof Splat ? [].concat(node.makeCode((utility('slice', o)) + ".call("), compiledNode, node.makeCode(")")) : [].concat(node.makeCode("["), compiledNode, node.makeCode("]"));2192}2193if (index === 0) {2194node = list[0];2195concatPart = node.joinFragmentArrays(args.slice(1), ', ');2196return args[0].concat(node.makeCode(".concat("), concatPart, node.makeCode(")"));2197}2198base = (function() {2199var k, len2, ref3, results;2200ref3 = list.slice(0, index);2201results = [];2202for (k = 0, len2 = ref3.length; k < len2; k++) {2203node = ref3[k];2204results.push(node.compileToFragments(o, LEVEL_LIST));2205}2206return results;2207})();2208base = list[0].joinFragmentArrays(base, ', ');2209concatPart = list[index].joinFragmentArrays(args, ', ');2210last = list[list.length - 1];2211return [].concat(list[0].makeCode("["), base, list[index].makeCode("].concat("), concatPart, last.makeCode(")"));2212};22132214return Splat;22152216})(Base);22172218exports.Expansion = Expansion = (function(superClass1) {2219extend1(Expansion, superClass1);22202221function Expansion() {2222return Expansion.__super__.constructor.apply(this, arguments);2223}22242225Expansion.prototype.isComplex = NO;22262227Expansion.prototype.compileNode = function(o) {2228return this.error('Expansion must be used inside a destructuring assignment or parameter list');2229};22302231Expansion.prototype.asReference = function(o) {2232return this;2233};22342235Expansion.prototype.eachName = function(iterator) {};22362237return Expansion;22382239})(Base);22402241exports.While = While = (function(superClass1) {2242extend1(While, superClass1);22432244function While(condition, options) {2245this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;2246this.guard = options != null ? options.guard : void 0;2247}22482249While.prototype.children = ['condition', 'guard', 'body'];22502251While.prototype.isStatement = YES;22522253While.prototype.makeReturn = function(res) {2254if (res) {2255return While.__super__.makeReturn.apply(this, arguments);2256} else {2257this.returns = !this.jumps({2258loop: true2259});2260return this;2261}2262};22632264While.prototype.addBody = function(body1) {2265this.body = body1;2266return this;2267};22682269While.prototype.jumps = function() {2270var expressions, j, jumpNode, len1, node;2271expressions = this.body.expressions;2272if (!expressions.length) {2273return false;2274}2275for (j = 0, len1 = expressions.length; j < len1; j++) {2276node = expressions[j];2277if (jumpNode = node.jumps({2278loop: true2279})) {2280return jumpNode;2281}2282}2283return false;2284};22852286While.prototype.compileNode = function(o) {2287var answer, body, rvar, set;2288o.indent += TAB;2289set = '';2290body = this.body;2291if (body.isEmpty()) {2292body = this.makeCode('');2293} else {2294if (this.returns) {2295body.makeReturn(rvar = o.scope.freeVariable('results'));2296set = "" + this.tab + rvar + " = [];\n";2297}2298if (this.guard) {2299if (body.expressions.length > 1) {2300body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));2301} else {2302if (this.guard) {2303body = Block.wrap([new If(this.guard, body)]);2304}2305}2306}2307body = [].concat(this.makeCode("\n"), body.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab));2308}2309answer = [].concat(this.makeCode(set + this.tab + "while ("), this.condition.compileToFragments(o, LEVEL_PAREN), this.makeCode(") {"), body, this.makeCode("}"));2310if (this.returns) {2311answer.push(this.makeCode("\n" + this.tab + "return " + rvar + ";"));2312}2313return answer;2314};23152316return While;23172318})(Base);23192320exports.Op = Op = (function(superClass1) {2321var CONVERSIONS, INVERSIONS;23222323extend1(Op, superClass1);23242325function Op(op, first, second, flip) {2326if (op === 'in') {2327return new In(first, second);2328}2329if (op === 'do') {2330return this.generateDo(first);2331}2332if (op === 'new') {2333if (first instanceof Call && !first["do"] && !first.isNew) {2334return first.newInstance();2335}2336if (first instanceof Code && first.bound || first["do"]) {2337first = new Parens(first);2338}2339}2340this.operator = CONVERSIONS[op] || op;2341this.first = first;2342this.second = second;2343this.flip = !!flip;2344return this;2345}23462347CONVERSIONS = {2348'==': '===',2349'!=': '!==',2350'of': 'in',2351'yieldfrom': 'yield*'2352};23532354INVERSIONS = {2355'!==': '===',2356'===': '!=='2357};23582359Op.prototype.children = ['first', 'second'];23602361Op.prototype.isSimpleNumber = NO;23622363Op.prototype.isYield = function() {2364var ref3;2365return (ref3 = this.operator) === 'yield' || ref3 === 'yield*';2366};23672368Op.prototype.isYieldReturn = function() {2369return this.isYield() && this.first instanceof Return;2370};23712372Op.prototype.isUnary = function() {2373return !this.second;2374};23752376Op.prototype.isComplex = function() {2377var ref3;2378return !(this.isUnary() && ((ref3 = this.operator) === '+' || ref3 === '-') && this.first instanceof Value && this.first.isSimpleNumber());2379};23802381Op.prototype.isChainable = function() {2382var ref3;2383return (ref3 = this.operator) === '<' || ref3 === '>' || ref3 === '>=' || ref3 === '<=' || ref3 === '===' || ref3 === '!==';2384};23852386Op.prototype.invert = function() {2387var allInvertable, curr, fst, op, ref3;2388if (this.isChainable() && this.first.isChainable()) {2389allInvertable = true;2390curr = this;2391while (curr && curr.operator) {2392allInvertable && (allInvertable = curr.operator in INVERSIONS);2393curr = curr.first;2394}2395if (!allInvertable) {2396return new Parens(this).invert();2397}2398curr = this;2399while (curr && curr.operator) {2400curr.invert = !curr.invert;2401curr.operator = INVERSIONS[curr.operator];2402curr = curr.first;2403}2404return this;2405} else if (op = INVERSIONS[this.operator]) {2406this.operator = op;2407if (this.first.unwrap() instanceof Op) {2408this.first.invert();2409}2410return this;2411} else if (this.second) {2412return new Parens(this).invert();2413} else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((ref3 = fst.operator) === '!' || ref3 === 'in' || ref3 === 'instanceof')) {2414return fst;2415} else {2416return new Op('!', this);2417}2418};24192420Op.prototype.unfoldSoak = function(o) {2421var ref3;2422return ((ref3 = this.operator) === '++' || ref3 === '--' || ref3 === 'delete') && unfoldSoak(o, this, 'first');2423};24242425Op.prototype.generateDo = function(exp) {2426var call, func, j, len1, param, passedParams, ref, ref3;2427passedParams = [];2428func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;2429ref3 = func.params || [];2430for (j = 0, len1 = ref3.length; j < len1; j++) {2431param = ref3[j];2432if (param.value) {2433passedParams.push(param.value);2434delete param.value;2435} else {2436passedParams.push(param);2437}2438}2439call = new Call(exp, passedParams);2440call["do"] = true;2441return call;2442};24432444Op.prototype.compileNode = function(o) {2445var answer, isChain, lhs, ref3, ref4, rhs;2446isChain = this.isChainable() && this.first.isChainable();2447if (!isChain) {2448this.first.front = this.front;2449}2450if (this.operator === 'delete' && o.scope.check(this.first.unwrapAll().value)) {2451this.error('delete operand may not be argument or var');2452}2453if (((ref3 = this.operator) === '--' || ref3 === '++') && (ref4 = this.first.unwrapAll().value, indexOf.call(STRICT_PROSCRIBED, ref4) >= 0)) {2454this.error("cannot increment/decrement \"" + (this.first.unwrapAll().value) + "\"");2455}2456if (this.isYield()) {2457return this.compileYield(o);2458}2459if (this.isUnary()) {2460return this.compileUnary(o);2461}2462if (isChain) {2463return this.compileChain(o);2464}2465switch (this.operator) {2466case '?':2467return this.compileExistence(o);2468case '**':2469return this.compilePower(o);2470case '//':2471return this.compileFloorDivision(o);2472case '%%':2473return this.compileModulo(o);2474default:2475lhs = this.first.compileToFragments(o, LEVEL_OP);2476rhs = this.second.compileToFragments(o, LEVEL_OP);2477answer = [].concat(lhs, this.makeCode(" " + this.operator + " "), rhs);2478if (o.level <= LEVEL_OP) {2479return answer;2480} else {2481return this.wrapInBraces(answer);2482}2483}2484};24852486Op.prototype.compileChain = function(o) {2487var fragments, fst, ref3, shared;2488ref3 = this.first.second.cache(o), this.first.second = ref3[0], shared = ref3[1];2489fst = this.first.compileToFragments(o, LEVEL_OP);2490fragments = fst.concat(this.makeCode(" " + (this.invert ? '&&' : '||') + " "), shared.compileToFragments(o), this.makeCode(" " + this.operator + " "), this.second.compileToFragments(o, LEVEL_OP));2491return this.wrapInBraces(fragments);2492};24932494Op.prototype.compileExistence = function(o) {2495var fst, ref;2496if (this.first.isComplex()) {2497ref = new Literal(o.scope.freeVariable('ref'));2498fst = new Parens(new Assign(ref, this.first));2499} else {2500fst = this.first;2501ref = fst;2502}2503return new If(new Existence(fst), ref, {2504type: 'if'2505}).addElse(this.second).compileToFragments(o);2506};25072508Op.prototype.compileUnary = function(o) {2509var op, parts, plusMinus;2510parts = [];2511op = this.operator;2512parts.push([this.makeCode(op)]);2513if (op === '!' && this.first instanceof Existence) {2514this.first.negated = !this.first.negated;2515return this.first.compileToFragments(o);2516}2517if (o.level >= LEVEL_ACCESS) {2518return (new Parens(this)).compileToFragments(o);2519}2520plusMinus = op === '+' || op === '-';2521if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {2522parts.push([this.makeCode(' ')]);2523}2524if ((plusMinus && this.first instanceof Op) || (op === 'new' && this.first.isStatement(o))) {2525this.first = new Parens(this.first);2526}2527parts.push(this.first.compileToFragments(o, LEVEL_OP));2528if (this.flip) {2529parts.reverse();2530}2531return this.joinFragmentArrays(parts, '');2532};25332534Op.prototype.compileYield = function(o) {2535var op, parts;2536parts = [];2537op = this.operator;2538if (o.scope.parent == null) {2539this.error('yield statements must occur within a function generator.');2540}2541if (indexOf.call(Object.keys(this.first), 'expression') >= 0 && !(this.first instanceof Throw)) {2542if (this.isYieldReturn()) {2543parts.push(this.first.compileToFragments(o, LEVEL_TOP));2544} else if (this.first.expression != null) {2545parts.push(this.first.expression.compileToFragments(o, LEVEL_OP));2546}2547} else {2548parts.push([this.makeCode("(" + op + " ")]);2549parts.push(this.first.compileToFragments(o, LEVEL_OP));2550parts.push([this.makeCode(")")]);2551}2552return this.joinFragmentArrays(parts, '');2553};25542555Op.prototype.compilePower = function(o) {2556var pow;2557pow = new Value(new Literal('Math'), [new Access(new Literal('pow'))]);2558return new Call(pow, [this.first, this.second]).compileToFragments(o);2559};25602561Op.prototype.compileFloorDivision = function(o) {2562var div, floor;2563floor = new Value(new Literal('Math'), [new Access(new Literal('floor'))]);2564div = new Op('/', this.first, this.second);2565return new Call(floor, [div]).compileToFragments(o);2566};25672568Op.prototype.compileModulo = function(o) {2569var mod;2570mod = new Value(new Literal(utility('modulo', o)));2571return new Call(mod, [this.first, this.second]).compileToFragments(o);2572};25732574Op.prototype.toString = function(idt) {2575return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);2576};25772578return Op;25792580})(Base);25812582exports.In = In = (function(superClass1) {2583extend1(In, superClass1);25842585function In(object, array) {2586this.object = object;2587this.array = array;2588}25892590In.prototype.children = ['object', 'array'];25912592In.prototype.invert = NEGATE;25932594In.prototype.compileNode = function(o) {2595var hasSplat, j, len1, obj, ref3;2596if (this.array instanceof Value && this.array.isArray() && this.array.base.objects.length) {2597ref3 = this.array.base.objects;2598for (j = 0, len1 = ref3.length; j < len1; j++) {2599obj = ref3[j];2600if (!(obj instanceof Splat)) {2601continue;2602}2603hasSplat = true;2604break;2605}2606if (!hasSplat) {2607return this.compileOrTest(o);2608}2609}2610return this.compileLoopTest(o);2611};26122613In.prototype.compileOrTest = function(o) {2614var cmp, cnj, i, item, j, len1, ref, ref3, ref4, ref5, sub, tests;2615ref3 = this.object.cache(o, LEVEL_OP), sub = ref3[0], ref = ref3[1];2616ref4 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = ref4[0], cnj = ref4[1];2617tests = [];2618ref5 = this.array.base.objects;2619for (i = j = 0, len1 = ref5.length; j < len1; i = ++j) {2620item = ref5[i];2621if (i) {2622tests.push(this.makeCode(cnj));2623}2624tests = tests.concat((i ? ref : sub), this.makeCode(cmp), item.compileToFragments(o, LEVEL_ACCESS));2625}2626if (o.level < LEVEL_OP) {2627return tests;2628} else {2629return this.wrapInBraces(tests);2630}2631};26322633In.prototype.compileLoopTest = function(o) {2634var fragments, ref, ref3, sub;2635ref3 = this.object.cache(o, LEVEL_LIST), sub = ref3[0], ref = ref3[1];2636fragments = [].concat(this.makeCode(utility('indexOf', o) + ".call("), this.array.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), ref, this.makeCode(") " + (this.negated ? '< 0' : '>= 0')));2637if (fragmentsToText(sub) === fragmentsToText(ref)) {2638return fragments;2639}2640fragments = sub.concat(this.makeCode(', '), fragments);2641if (o.level < LEVEL_LIST) {2642return fragments;2643} else {2644return this.wrapInBraces(fragments);2645}2646};26472648In.prototype.toString = function(idt) {2649return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));2650};26512652return In;26532654})(Base);26552656exports.Try = Try = (function(superClass1) {2657extend1(Try, superClass1);26582659function Try(attempt, errorVariable, recovery, ensure) {2660this.attempt = attempt;2661this.errorVariable = errorVariable;2662this.recovery = recovery;2663this.ensure = ensure;2664}26652666Try.prototype.children = ['attempt', 'recovery', 'ensure'];26672668Try.prototype.isStatement = YES;26692670Try.prototype.jumps = function(o) {2671var ref3;2672return this.attempt.jumps(o) || ((ref3 = this.recovery) != null ? ref3.jumps(o) : void 0);2673};26742675Try.prototype.makeReturn = function(res) {2676if (this.attempt) {2677this.attempt = this.attempt.makeReturn(res);2678}2679if (this.recovery) {2680this.recovery = this.recovery.makeReturn(res);2681}2682return this;2683};26842685Try.prototype.compileNode = function(o) {2686var catchPart, ensurePart, placeholder, tryPart;2687o.indent += TAB;2688tryPart = this.attempt.compileToFragments(o, LEVEL_TOP);2689catchPart = 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) {}')] : [];2690ensurePart = this.ensure ? [].concat(this.makeCode(" finally {\n"), this.ensure.compileToFragments(o, LEVEL_TOP), this.makeCode("\n" + this.tab + "}")) : [];2691return [].concat(this.makeCode(this.tab + "try {\n"), tryPart, this.makeCode("\n" + this.tab + "}"), catchPart, ensurePart);2692};26932694return Try;26952696})(Base);26972698exports.Throw = Throw = (function(superClass1) {2699extend1(Throw, superClass1);27002701function Throw(expression) {2702this.expression = expression;2703}27042705Throw.prototype.children = ['expression'];27062707Throw.prototype.isStatement = YES;27082709Throw.prototype.jumps = NO;27102711Throw.prototype.makeReturn = THIS;27122713Throw.prototype.compileNode = function(o) {2714return [].concat(this.makeCode(this.tab + "throw "), this.expression.compileToFragments(o), this.makeCode(";"));2715};27162717return Throw;27182719})(Base);27202721exports.Existence = Existence = (function(superClass1) {2722extend1(Existence, superClass1);27232724function Existence(expression) {2725this.expression = expression;2726}27272728Existence.prototype.children = ['expression'];27292730Existence.prototype.invert = NEGATE;27312732Existence.prototype.compileNode = function(o) {2733var cmp, cnj, code, ref3;2734this.expression.front = this.front;2735code = this.expression.compile(o, LEVEL_OP);2736if (IDENTIFIER.test(code) && !o.scope.check(code)) {2737ref3 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = ref3[0], cnj = ref3[1];2738code = "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null";2739} else {2740code = code + " " + (this.negated ? '==' : '!=') + " null";2741}2742return [this.makeCode(o.level <= LEVEL_COND ? code : "(" + code + ")")];2743};27442745return Existence;27462747})(Base);27482749exports.Parens = Parens = (function(superClass1) {2750extend1(Parens, superClass1);27512752function Parens(body1) {2753this.body = body1;2754}27552756Parens.prototype.children = ['body'];27572758Parens.prototype.unwrap = function() {2759return this.body;2760};27612762Parens.prototype.isComplex = function() {2763return this.body.isComplex();2764};27652766Parens.prototype.compileNode = function(o) {2767var bare, expr, fragments;2768expr = this.body.unwrap();2769if (expr instanceof Value && expr.isAtomic()) {2770expr.front = this.front;2771return expr.compileToFragments(o);2772}2773fragments = expr.compileToFragments(o, LEVEL_PAREN);2774bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns));2775if (bare) {2776return fragments;2777} else {2778return this.wrapInBraces(fragments);2779}2780};27812782return Parens;27832784})(Base);27852786exports.For = For = (function(superClass1) {2787extend1(For, superClass1);27882789function For(body, source) {2790var ref3;2791this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;2792this.body = Block.wrap([body]);2793this.own = !!source.own;2794this.object = !!source.object;2795if (this.object) {2796ref3 = [this.index, this.name], this.name = ref3[0], this.index = ref3[1];2797}2798if (this.index instanceof Value) {2799this.index.error('index cannot be a pattern matching expression');2800}2801this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;2802this.pattern = this.name instanceof Value;2803if (this.range && this.index) {2804this.index.error('indexes do not apply to range loops');2805}2806if (this.range && this.pattern) {2807this.name.error('cannot pattern match over range loops');2808}2809if (this.own && !this.object) {2810this.name.error('cannot use own with for-in');2811}2812this.returns = false;2813}28142815For.prototype.children = ['body', 'source', 'guard', 'step'];28162817For.prototype.compileNode = function(o) {2818var body, bodyFragments, compare, compareDown, declare, declareDown, defPart, defPartFragments, down, forPartFragments, guardPart, idt1, increment, index, ivar, kvar, kvarAssign, last, lvar, name, namePart, ref, ref3, ref4, resultPart, returnResult, rvar, scope, source, step, stepNum, stepVar, svar, varPart;2819body = Block.wrap([this.body]);2820ref3 = body.expressions, last = ref3[ref3.length - 1];2821if ((last != null ? last.jumps() : void 0) instanceof Return) {2822this.returns = false;2823}2824source = this.range ? this.source.base : this.source;2825scope = o.scope;2826if (!this.pattern) {2827name = this.name && (this.name.compile(o, LEVEL_LIST));2828}2829index = this.index && (this.index.compile(o, LEVEL_LIST));2830if (name && !this.pattern) {2831scope.find(name);2832}2833if (index) {2834scope.find(index);2835}2836if (this.returns) {2837rvar = scope.freeVariable('results');2838}2839ivar = (this.object && index) || scope.freeVariable('i', {2840single: true2841});2842kvar = (this.range && name) || index || ivar;2843kvarAssign = kvar !== ivar ? kvar + " = " : "";2844if (this.step && !this.range) {2845ref4 = this.cacheToCodeFragments(this.step.cache(o, LEVEL_LIST, isComplexOrAssignable)), step = ref4[0], stepVar = ref4[1];2846stepNum = stepVar.match(NUMBER);2847}2848if (this.pattern) {2849name = ivar;2850}2851varPart = '';2852guardPart = '';2853defPart = '';2854idt1 = this.tab + TAB;2855if (this.range) {2856forPartFragments = source.compileToFragments(merge(o, {2857index: ivar,2858name: name,2859step: this.step,2860isComplex: isComplexOrAssignable2861}));2862} else {2863svar = this.source.compile(o, LEVEL_LIST);2864if ((name || this.own) && !IDENTIFIER.test(svar)) {2865defPart += "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";2866svar = ref;2867}2868if (name && !this.pattern) {2869namePart = name + " = " + svar + "[" + kvar + "]";2870}2871if (!this.object) {2872if (step !== stepVar) {2873defPart += "" + this.tab + step + ";\n";2874}2875if (!(this.step && stepNum && (down = parseNum(stepNum[0]) < 0))) {2876lvar = scope.freeVariable('len');2877}2878declare = "" + kvarAssign + ivar + " = 0, " + lvar + " = " + svar + ".length";2879declareDown = "" + kvarAssign + ivar + " = " + svar + ".length - 1";2880compare = ivar + " < " + lvar;2881compareDown = ivar + " >= 0";2882if (this.step) {2883if (stepNum) {2884if (down) {2885compare = compareDown;2886declare = declareDown;2887}2888} else {2889compare = stepVar + " > 0 ? " + compare + " : " + compareDown;2890declare = "(" + stepVar + " > 0 ? (" + declare + ") : " + declareDown + ")";2891}2892increment = ivar + " += " + stepVar;2893} else {2894increment = "" + (kvar !== ivar ? "++" + ivar : ivar + "++");2895}2896forPartFragments = [this.makeCode(declare + "; " + compare + "; " + kvarAssign + increment)];2897}2898}2899if (this.returns) {2900resultPart = "" + this.tab + rvar + " = [];\n";2901returnResult = "\n" + this.tab + "return " + rvar + ";";2902body.makeReturn(rvar);2903}2904if (this.guard) {2905if (body.expressions.length > 1) {2906body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));2907} else {2908if (this.guard) {2909body = Block.wrap([new If(this.guard, body)]);2910}2911}2912}2913if (this.pattern) {2914body.expressions.unshift(new Assign(this.name, new Literal(svar + "[" + kvar + "]")));2915}2916defPartFragments = [].concat(this.makeCode(defPart), this.pluckDirectCall(o, body));2917if (namePart) {2918varPart = "\n" + idt1 + namePart + ";";2919}2920if (this.object) {2921forPartFragments = [this.makeCode(kvar + " in " + svar)];2922if (this.own) {2923guardPart = "\n" + idt1 + "if (!" + (utility('hasProp', o)) + ".call(" + svar + ", " + kvar + ")) continue;";2924}2925}2926bodyFragments = body.compileToFragments(merge(o, {2927indent: idt12928}), LEVEL_TOP);2929if (bodyFragments && (bodyFragments.length > 0)) {2930bodyFragments = [].concat(this.makeCode("\n"), bodyFragments, this.makeCode("\n"));2931}2932return [].concat(defPartFragments, this.makeCode("" + (resultPart || '') + this.tab + "for ("), forPartFragments, this.makeCode(") {" + guardPart + varPart), bodyFragments, this.makeCode(this.tab + "}" + (returnResult || '')));2933};29342935For.prototype.pluckDirectCall = function(o, body) {2936var base, defs, expr, fn, idx, j, len1, ref, ref3, ref4, ref5, ref6, ref7, ref8, ref9, val;2937defs = [];2938ref3 = body.expressions;2939for (idx = j = 0, len1 = ref3.length; j < len1; idx = ++j) {2940expr = ref3[idx];2941expr = expr.unwrapAll();2942if (!(expr instanceof Call)) {2943continue;2944}2945val = (ref4 = expr.variable) != null ? ref4.unwrapAll() : void 0;2946if (!((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')))) {2947continue;2948}2949fn = ((ref8 = val.base) != null ? ref8.unwrapAll() : void 0) || val;2950ref = new Literal(o.scope.freeVariable('fn'));2951base = new Value(ref);2952if (val.base) {2953ref9 = [base, val], val.base = ref9[0], base = ref9[1];2954}2955body.expressions[idx] = new Call(base, expr.args);2956defs = defs.concat(this.makeCode(this.tab), new Assign(ref, fn).compileToFragments(o, LEVEL_TOP), this.makeCode(';\n'));2957}2958return defs;2959};29602961return For;29622963})(While);29642965exports.Switch = Switch = (function(superClass1) {2966extend1(Switch, superClass1);29672968function Switch(subject, cases, otherwise) {2969this.subject = subject;2970this.cases = cases;2971this.otherwise = otherwise;2972}29732974Switch.prototype.children = ['subject', 'cases', 'otherwise'];29752976Switch.prototype.isStatement = YES;29772978Switch.prototype.jumps = function(o) {2979var block, conds, j, jumpNode, len1, ref3, ref4, ref5;2980if (o == null) {2981o = {2982block: true2983};2984}2985ref3 = this.cases;2986for (j = 0, len1 = ref3.length; j < len1; j++) {2987ref4 = ref3[j], conds = ref4[0], block = ref4[1];2988if (jumpNode = block.jumps(o)) {2989return jumpNode;2990}2991}2992return (ref5 = this.otherwise) != null ? ref5.jumps(o) : void 0;2993};29942995Switch.prototype.makeReturn = function(res) {2996var j, len1, pair, ref3, ref4;2997ref3 = this.cases;2998for (j = 0, len1 = ref3.length; j < len1; j++) {2999pair = ref3[j];3000pair[1].makeReturn(res);3001}3002if (res) {3003this.otherwise || (this.otherwise = new Block([new Literal('void 0')]));3004}3005if ((ref4 = this.otherwise) != null) {3006ref4.makeReturn(res);3007}3008return this;3009};30103011Switch.prototype.compileNode = function(o) {3012var block, body, cond, conditions, expr, fragments, i, idt1, idt2, j, k, len1, len2, ref3, ref4, ref5;3013idt1 = o.indent + TAB;3014idt2 = o.indent = idt1 + TAB;3015fragments = [].concat(this.makeCode(this.tab + "switch ("), (this.subject ? this.subject.compileToFragments(o, LEVEL_PAREN) : this.makeCode("false")), this.makeCode(") {\n"));3016ref3 = this.cases;3017for (i = j = 0, len1 = ref3.length; j < len1; i = ++j) {3018ref4 = ref3[i], conditions = ref4[0], block = ref4[1];3019ref5 = flatten([conditions]);3020for (k = 0, len2 = ref5.length; k < len2; k++) {3021cond = ref5[k];3022if (!this.subject) {3023cond = cond.invert();3024}3025fragments = fragments.concat(this.makeCode(idt1 + "case "), cond.compileToFragments(o, LEVEL_PAREN), this.makeCode(":\n"));3026}3027if ((body = block.compileToFragments(o, LEVEL_TOP)).length > 0) {3028fragments = fragments.concat(body, this.makeCode('\n'));3029}3030if (i === this.cases.length - 1 && !this.otherwise) {3031break;3032}3033expr = this.lastNonComment(block.expressions);3034if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) {3035continue;3036}3037fragments.push(cond.makeCode(idt2 + 'break;\n'));3038}3039if (this.otherwise && this.otherwise.expressions.length) {3040fragments.push.apply(fragments, [this.makeCode(idt1 + "default:\n")].concat(slice.call(this.otherwise.compileToFragments(o, LEVEL_TOP)), [this.makeCode("\n")]));3041}3042fragments.push(this.makeCode(this.tab + '}'));3043return fragments;3044};30453046return Switch;30473048})(Base);30493050exports.If = If = (function(superClass1) {3051extend1(If, superClass1);30523053function If(condition, body1, options) {3054this.body = body1;3055if (options == null) {3056options = {};3057}3058this.condition = options.type === 'unless' ? condition.invert() : condition;3059this.elseBody = null;3060this.isChain = false;3061this.soak = options.soak;3062}30633064If.prototype.children = ['condition', 'body', 'elseBody'];30653066If.prototype.bodyNode = function() {3067var ref3;3068return (ref3 = this.body) != null ? ref3.unwrap() : void 0;3069};30703071If.prototype.elseBodyNode = function() {3072var ref3;3073return (ref3 = this.elseBody) != null ? ref3.unwrap() : void 0;3074};30753076If.prototype.addElse = function(elseBody) {3077if (this.isChain) {3078this.elseBodyNode().addElse(elseBody);3079} else {3080this.isChain = elseBody instanceof If;3081this.elseBody = this.ensureBlock(elseBody);3082this.elseBody.updateLocationDataIfMissing(elseBody.locationData);3083}3084return this;3085};30863087If.prototype.isStatement = function(o) {3088var ref3;3089return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((ref3 = this.elseBodyNode()) != null ? ref3.isStatement(o) : void 0);3090};30913092If.prototype.jumps = function(o) {3093var ref3;3094return this.body.jumps(o) || ((ref3 = this.elseBody) != null ? ref3.jumps(o) : void 0);3095};30963097If.prototype.compileNode = function(o) {3098if (this.isStatement(o)) {3099return this.compileStatement(o);3100} else {3101return this.compileExpression(o);3102}3103};31043105If.prototype.makeReturn = function(res) {3106if (res) {3107this.elseBody || (this.elseBody = new Block([new Literal('void 0')]));3108}3109this.body && (this.body = new Block([this.body.makeReturn(res)]));3110this.elseBody && (this.elseBody = new Block([this.elseBody.makeReturn(res)]));3111return this;3112};31133114If.prototype.ensureBlock = function(node) {3115if (node instanceof Block) {3116return node;3117} else {3118return new Block([node]);3119}3120};31213122If.prototype.compileStatement = function(o) {3123var answer, body, child, cond, exeq, ifPart, indent;3124child = del(o, 'chainChild');3125exeq = del(o, 'isExistentialEquals');3126if (exeq) {3127return new If(this.condition.invert(), this.elseBodyNode(), {3128type: 'if'3129}).compileToFragments(o);3130}3131indent = o.indent + TAB;3132cond = this.condition.compileToFragments(o, LEVEL_PAREN);3133body = this.ensureBlock(this.body).compileToFragments(merge(o, {3134indent: indent3135}));3136ifPart = [].concat(this.makeCode("if ("), cond, this.makeCode(") {\n"), body, this.makeCode("\n" + this.tab + "}"));3137if (!child) {3138ifPart.unshift(this.makeCode(this.tab));3139}3140if (!this.elseBody) {3141return ifPart;3142}3143answer = ifPart.concat(this.makeCode(' else '));3144if (this.isChain) {3145o.chainChild = true;3146answer = answer.concat(this.elseBody.unwrap().compileToFragments(o, LEVEL_TOP));3147} else {3148answer = answer.concat(this.makeCode("{\n"), this.elseBody.compileToFragments(merge(o, {3149indent: indent3150}), LEVEL_TOP), this.makeCode("\n" + this.tab + "}"));3151}3152return answer;3153};31543155If.prototype.compileExpression = function(o) {3156var alt, body, cond, fragments;3157cond = this.condition.compileToFragments(o, LEVEL_COND);3158body = this.bodyNode().compileToFragments(o, LEVEL_LIST);3159alt = this.elseBodyNode() ? this.elseBodyNode().compileToFragments(o, LEVEL_LIST) : [this.makeCode('void 0')];3160fragments = cond.concat(this.makeCode(" ? "), body, this.makeCode(" : "), alt);3161if (o.level >= LEVEL_COND) {3162return this.wrapInBraces(fragments);3163} else {3164return fragments;3165}3166};31673168If.prototype.unfoldSoak = function() {3169return this.soak && this;3170};31713172return If;31733174})(Base);31753176UTILITIES = {3177extend: function(o) {3178return "function(child, parent) { for (var key in parent) { if (" + (utility('hasProp', o)) + ".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; }";3179},3180bind: function() {3181return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';3182},3183indexOf: function() {3184return "[].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";3185},3186modulo: function() {3187return "function(a, b) { return (+a % (b = +b) + b) % b; }";3188},3189hasProp: function() {3190return '{}.hasOwnProperty';3191},3192slice: function() {3193return '[].slice';3194}3195};31963197LEVEL_TOP = 1;31983199LEVEL_PAREN = 2;32003201LEVEL_LIST = 3;32023203LEVEL_COND = 4;32043205LEVEL_OP = 5;32063207LEVEL_ACCESS = 6;32083209TAB = ' ';32103211IDENTIFIER = /^(?!\d)[$\w\x7f-\uffff]+$/;32123213SIMPLENUM = /^[+-]?\d+$/;32143215HEXNUM = /^[+-]?0x[\da-f]+/i;32163217NUMBER = /^[+-]?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)$/i;32183219IS_STRING = /^['"]/;32203221IS_REGEX = /^\//;32223223utility = function(name, o) {3224var ref, root;3225root = o.scope.root;3226if (name in root.utilities) {3227return root.utilities[name];3228} else {3229ref = root.freeVariable(name);3230root.assign(ref, UTILITIES[name](o));3231return root.utilities[name] = ref;3232}3233};32343235multident = function(code, tab) {3236code = code.replace(/\n/g, '$&' + tab);3237return code.replace(/\s+$/, '');3238};32393240parseNum = function(x) {3241if (x == null) {3242return 0;3243} else if (x.match(HEXNUM)) {3244return parseInt(x, 16);3245} else {3246return parseFloat(x);3247}3248};32493250isLiteralArguments = function(node) {3251return node instanceof Literal && node.value === 'arguments' && !node.asKey;3252};32533254isLiteralThis = function(node) {3255return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound) || (node instanceof Call && node.isSuper);3256};32573258isComplexOrAssignable = function(node) {3259return node.isComplex() || (typeof node.isAssignable === "function" ? node.isAssignable() : void 0);3260};32613262unfoldSoak = function(o, parent, name) {3263var ifn;3264if (!(ifn = parent[name].unfoldSoak(o))) {3265return;3266}3267parent[name] = ifn.body;3268ifn.body = new Value(parent);3269return ifn;3270};32713272}).call(this);327332743275