UNPKG

@kpi4me/golden-layout

Version:

A multi-screen javascript Layout manager https://golden-layout.com

1,291 lines 84.6 kB
// Generated by CoffeeScript 2.0.0-beta8 var any, assignment, beingDeclared, collectIdentifiers, concat, concatMap, CS, declarationsNeeded, declarationsNeededRecursive, defaultRules, difference, divMod, dynamicMemberAccess, enabledHelpers, envEnrichments, exports, expr, fn, fn, foldl1, forceBlock, generateMutatingWalker, generateSoak, genSym, h, h, hasSoak, helperNames, helpers, inlineHelpers, intersect, isIdentifierName, JS, jsReserved, makeReturn, makeVarDeclaration, map, memberAccess, needsCaching, nub, owns, partition, span, stmt, union, usedAsExpression, variableDeclarations; cache$ = require('./functional-helpers'); any = cache$.any; concat = cache$.concat; concatMap = cache$.concatMap; difference = cache$.difference; divMod = cache$.divMod; foldl1 = cache$.foldl1; intersect = cache$.intersect; map = cache$.map; nub = cache$.nub; owns = cache$.owns; partition = cache$.partition; span = cache$.span; union = cache$.union; cache$1 = require('./helpers'); beingDeclared = cache$1.beingDeclared; usedAsExpression = cache$1.usedAsExpression; envEnrichments = cache$1.envEnrichments; CS = require('./nodes'); JS = require('./js-nodes'); exports = null != ('undefined' !== typeof module && null != module ? module.exports : void 0) ? 'undefined' !== typeof module && null != module ? module.exports : void 0 : this; jsReserved = [ 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'implements', 'import', 'in', 'instanceof', 'interface', 'let', 'native', 'new', 'null', 'package', 'private', 'protected', 'public', 'return', 'static', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while', 'with', 'yield', 'arguments', 'eval' ]; genSym = function () { var genSymCounter; genSymCounter = 0; return function (pre) { return new JS.GenSym(pre, ++genSymCounter); }; }(); stmt = function (e) { var walk; if (!(null != e)) return e; if (e.isStatement) { return e; } else if (e['instanceof'](JS.SequenceExpression)) { walk = function (seq) { return concatMap(seq.expressions, function (e) { if (e['instanceof'](JS.SequenceExpression)) { return walk(e); } else { return [stmt(e)]; } }); }; return new JS.BlockStatement(walk(e)); } else if (e['instanceof'](JS.ConditionalExpression)) { return new JS.IfStatement(expr(e.test), stmt(e.consequent), stmt(e.alternate)); } else { return new JS.ExpressionStatement(e); } }; expr = function (s) { var accum, alternate, block, consequent, iife, lastExpression, push; if (!(null != s)) return s; if (s.isExpression) { return s; } else if (s['instanceof'](JS.BlockStatement)) { switch (s.body.length) { case 0: return helpers.undef(); case 1: return expr(s.body[0]); default: return new JS.SequenceExpression(map(s.body, expr)); } } else if (s['instanceof'](JS.ExpressionStatement)) { return s.expression; } else if (s['instanceof'](JS.ThrowStatement)) { return new JS.CallExpression(new JS.FunctionExpression(null, [], forceBlock(s)), []); } else if (s['instanceof'](JS.IfStatement)) { consequent = expr(null != s.consequent ? s.consequent : helpers.undef()); alternate = expr(null != s.alternate ? s.alternate : helpers.undef()); return new JS.ConditionalExpression(s.test, consequent, alternate); } else if (s['instanceof'](JS.ForInStatement, JS.ForStatement, JS.WhileStatement)) { accum = genSym('accum'); push = function (x) { return stmt(new JS.CallExpression(memberAccess(accum, 'push'), [x])); }; s.body = forceBlock(s.body); if (s.body.body.length) { lastExpression = s.body.body.slice(-1)[0]; if (!lastExpression['instanceof'](JS.ThrowStatement)) s.body.body[s.body.body.length - 1] = push(expr(lastExpression)); } else { s.body.body.push(push(helpers.undef())); } block = new JS.BlockStatement([ s, new JS.ReturnStatement(accum) ]); iife = new JS.FunctionExpression(null, [accum], block); return new JS.CallExpression(memberAccess(iife.g(), 'call'), [ new JS.ThisExpression, new JS.ArrayExpression([]) ]); } else if (s['instanceof'](JS.SwitchStatement, JS.TryStatement)) { block = new JS.BlockStatement([makeReturn(s)]); iife = new JS.FunctionExpression(null, [], block); return new JS.CallExpression(memberAccess(iife.g(), 'call'), [new JS.ThisExpression]); } else { throw new Error('expr: Cannot use a ' + s.type + ' as a value'); } }; makeReturn = function (node) { var stmts; if (!(null != node)) return new JS.ReturnStatement; if (node['instanceof'](JS.BlockStatement)) { return new JS.BlockStatement([].slice.call(node.body.slice(0, -1)).concat([makeReturn(node.body.slice(-1)[0])])); } else if (node['instanceof'](JS.SequenceExpression)) { return new JS.SequenceExpression([].slice.call(node.expressions.slice(0, -1)).concat([makeReturn(node.expressions.slice(-1)[0])])); } else if (node['instanceof'](JS.IfStatement)) { return new JS.IfStatement(node.test, makeReturn(node.consequent), null != node.alternate ? makeReturn(node.alternate) : null); } else if (node['instanceof'](JS.SwitchStatement)) { return new JS.SwitchStatement(node.discriminant, map(node.cases, makeReturn)); } else if (node['instanceof'](JS.SwitchCase)) { if (!node.consequent.length) return node; stmts = node.consequent.slice(-1)[0]['instanceof'](JS.BreakStatement) ? node.consequent.slice(0, -1) : node.consequent; return new JS.SwitchCase(node.test, [].slice.call(stmts.slice(0, -1)).concat([makeReturn(stmts.slice(-1)[0])])); } else if (node['instanceof'](JS.TryStatement)) { return new JS.TryStatement(makeReturn(node.block), map(node.handlers, makeReturn), null != node.finalizer ? makeReturn(node.finalizer) : null); } else if (node['instanceof'](JS.CatchClause)) { return new JS.CatchClause(node.param, makeReturn(node.body)); } else if (node['instanceof'](JS.ThrowStatement, JS.ReturnStatement, JS.BreakStatement, JS.ContinueStatement, JS.DebuggerStatement)) { return node; } else if (node['instanceof'](JS.UnaryExpression) && node.operator === 'void') { return new JS.ReturnStatement; } else { return new JS.ReturnStatement(expr(node)); } }; generateMutatingWalker = function (fn) { return function (node, args) { var childName, n; args = 2 <= arguments.length ? [].slice.call(arguments, 1) : []; for (var i$ = 0, length$ = node.childNodes.length; i$ < length$; ++i$) { childName = node.childNodes[i$]; if (!(null != node[childName])) continue; node[childName] = in$(childName, node.listMembers) ? function (accum$) { for (var i$1 = 0, length$1 = node[childName].length; i$1 < length$1; ++i$1) { n = node[childName][i$1]; accum$.push(fn.apply(n, args)); } return accum$; }.call(this, []) : fn.apply(node[childName], args); } return node; }; }; declarationsNeeded = function (node) { if (!(null != node)) return []; if (node['instanceof'](JS.AssignmentExpression) && node.operator === '=' && node.left['instanceof'](JS.Identifier)) { return [node.left]; } else if (node['instanceof'](JS.ForInStatement) && node.left['instanceof'](JS.Identifier)) { return [node.left]; } else { return []; } }; declarationsNeededRecursive = function (node) { if (!(null != node)) return []; if (node['instanceof'](JS.FunctionExpression, JS.FunctionDeclaration) && !node.generated) { return []; } else { return union(declarationsNeeded(node), concatMap(node.childNodes, function (childName) { if (!(null != node[childName])) return []; if (in$(childName, node.listMembers)) { return concatMap(node[childName], declarationsNeededRecursive); } else { return declarationsNeededRecursive(node[childName]); } })); } }; variableDeclarations = function (node) { if (!(null != node)) return []; if (node['instanceof'](JS.FunctionDeclaration)) { return [node.id]; } else if (node['instanceof'](JS.FunctionExpression) && !node.generated) { return []; } else if (node['instanceof'](JS.VariableDeclarator)) { return [node.id]; } else { return concatMap(node.childNodes, function (childName) { if (!(null != node[childName])) return []; if (in$(childName, node.listMembers)) { return concatMap(node[childName], variableDeclarations); } else { return variableDeclarations(node[childName]); } }); } }; collectIdentifiers = function (node) { return nub(function () { switch (false) { case !!(null != node): return []; case !node['instanceof'](JS.Identifier): return [node.name]; case !(node['instanceof'](JS.MemberExpression) && !node.computed): return collectIdentifiers(node.object); default: return concatMap(node.childNodes, function (childName) { if (!(null != node[childName])) return []; if (in$(childName, node.listMembers)) { return concatMap(node[childName], collectIdentifiers); } else { return collectIdentifiers(node[childName]); } }); } }.call(this)); }; needsCaching = function (node) { if (!(null != node)) return false; return envEnrichments(node, []).length > 0 || node['instanceof'](CS.FunctionApplications, CS.DoOp, CS.NewOp, CS.ArrayInitialiser, CS.ObjectInitialiser, CS.RegExp, CS.HeregExp, CS.PreIncrementOp, CS.PostIncrementOp, CS.PreDecrementOp, CS.PostDecrementOp, CS.Range) || any(difference(node.childNodes, node.listMembers), function (n) { return needsCaching(node[n]); }) || any(node.listMembers, function (n) { return any(node[n], needsCaching); }); }; forceBlock = function (node) { if (!(null != node)) return new JS.BlockStatement([]); node = stmt(node); if (node['instanceof'](JS.BlockStatement)) { return node; } else { return new JS.BlockStatement([node]); } }; makeVarDeclaration = function (vars) { var decls, v; vars.sort(function (a, b) { a = a.name.toLowerCase(); b = b.name.toLowerCase(); if (a < b) { return -1; } else if (a > b) { return 1; } else { return 0; } }); decls = function (accum$) { for (var i$ = 0, length$ = vars.length; i$ < length$; ++i$) { v = vars[i$]; accum$.push(new JS.VariableDeclarator(v)); } return accum$; }.call(this, []); return new JS.VariableDeclaration('var', decls); }; isIdentifierName = function (name) { return !in$(name, jsReserved) && /^[$_a-z][$_a-z0-9]*$/i.test(name); }; memberAccess = function (e, member) { if (isIdentifierName(member)) { return new JS.MemberExpression(false, expr(e), new JS.Identifier(member)); } else { return new JS.MemberExpression(true, expr(e), new JS.Literal(member)); } }; dynamicMemberAccess = function (e, index) { if (index['instanceof'](JS.Literal) && typeof index.value === 'string') { return memberAccess(e, index.value); } else { return new JS.MemberExpression(true, expr(e), expr(index)); } }; assignment = function (assignee, expression, valueUsed) { var alternate, assignments, consequent, e, elements, i, index, m, numElements, p, propName, restName, size, test; if (null == valueUsed) valueUsed = false; assignments = []; expression = expr(expression); switch (false) { case !assignee.rest: case !assignee['instanceof'](JS.ArrayExpression): e = expression; if (valueUsed || assignee.elements.length > 1) { e = genSym('cache'); assignments.push(new JS.AssignmentExpression('=', e, expression)); } elements = assignee.elements; for (var i$ = 0, length$ = elements.length; i$ < length$; ++i$) { m = elements[i$]; i = i$; if (m.rest) break; assignments.push(assignment(m, dynamicMemberAccess(e, new JS.Literal(i)), valueUsed)); } if (elements.length > 0) { if (elements.slice(-1)[0].rest) { numElements = elements.length; restName = elements[numElements - 1] = elements[numElements - 1].expression; test = new JS.BinaryExpression('<=', new JS.Literal(numElements), memberAccess(e, 'length')); consequent = helpers.slice(e, new JS.Literal(numElements - 1)); alternate = new JS.ArrayExpression([]); assignments.push(stmt(new JS.AssignmentExpression('=', restName, new JS.ConditionalExpression(test, consequent, alternate)))); } else if (any(elements, function (p) { return p.rest; })) { restName = index = null; for (var i$1 = 0, length$1 = elements.length; i$1 < length$1; ++i$1) { p = elements[i$1]; i = i$1; if (!p.rest) continue; restName = p.expression; index = i; break; } elements.splice(index, 1); numElements = elements.length; size = genSym('size'); assignments.push(new JS.AssignmentExpression('=', size, memberAccess(e, 'length'))); test = new JS.BinaryExpression('>', size, new JS.Literal(numElements)); consequent = helpers.slice(e, new JS.Literal(index), new JS.BinaryExpression('-', size, new JS.Literal(numElements - index))); assignments.push(new JS.AssignmentExpression('=', restName, new JS.ConditionalExpression(test, consequent, new JS.ArrayExpression([])))); for (var i$2 = 0, length$2 = elements.slice(index).length; i$2 < length$2; ++i$2) { p = elements.slice(index)[i$2]; i = i$2; assignments.push(stmt(new JS.AssignmentExpression('=', p, new JS.MemberExpression(true, e, new JS.BinaryExpression('-', size, new JS.Literal(numElements - index - i)))))); } } if (any(elements, function (p) { return p.rest; })) throw new Error('Positional destructuring assignments may not have more than one rest operator'); } break; case !assignee['instanceof'](JS.ObjectExpression): e = expression; if (valueUsed || assignee.properties.length > 1) { e = genSym('cache'); assignments.push(new JS.AssignmentExpression('=', e, expression)); } for (var i$3 = 0, length$3 = assignee.properties.length; i$3 < length$3; ++i$3) { m = assignee.properties[i$3]; propName = m.key['instanceof'](JS.Identifier) ? new JS.Literal(m.key.name) : m.key; assignments.push(assignment(m.value, dynamicMemberAccess(e, propName), valueUsed)); } break; case !assignee['instanceof'](JS.Identifier, JS.GenSym, JS.MemberExpression): assignments.push(new JS.AssignmentExpression('=', assignee, expr(expression))); break; default: throw new Error('compile: assignment: unassignable assignee: ' + assignee.type); } switch (assignments.length) { case 0: if (e === expression) { return helpers.undef(); } else { return expression; } case 1: return assignments[0]; default: return new JS.SequenceExpression(valueUsed ? [].slice.call(assignments).concat([e]) : assignments); } }; hasSoak = function (node) { switch (false) { case !node['instanceof'](CS.SoakedFunctionApplication, CS.SoakedMemberAccessOp, CS.SoakedProtoMemberAccessOp, CS.SoakedDynamicMemberAccessOp, CS.SoakedDynamicProtoMemberAccessOp): return true; case !node['instanceof'](CS.FunctionApplication): return hasSoak(node['function']); case !node['instanceof'](CS.MemberAccessOps): return hasSoak(node.expression); default: return false; } }; generateSoak = function () { var fn; fn = function (node) { var cache$2, cache$3, cache$4, cache$5, cache$6, ctor, e, memberName, sym, tests, typeofTest; switch (false) { case !node['instanceof'](CS.MemberAccessOp, CS.ProtoMemberAccessOp): cache$2 = fn(node.expression); tests = cache$2[0]; e = cache$2[1]; return [ tests, new node.constructor(e, node.memberName) ]; case !node['instanceof'](CS.DynamicMemberAccessOp, CS.DynamicProtoMemberAccessOp): cache$3 = fn(node.expression); tests = cache$3[0]; e = cache$3[1]; return [ tests, new node.constructor(e, node.indexingExpr) ]; case !node['instanceof'](CS.FunctionApplication): cache$4 = fn(node['function']); tests = cache$4[0]; e = cache$4[1]; return [ tests, new CS.FunctionApplication(e, node['arguments']) ]; case !node['instanceof'](CS.SoakedFunctionApplication): cache$5 = fn(node['function']); tests = cache$5[0]; e = cache$5[1]; typeofTest = function (e) { return new CS.EQOp(new CS.String('function'), new CS.TypeofOp(e)); }; if (needsCaching(e)) { sym = new CS.GenSym('cache'); return [ [].slice.call(tests).concat([typeofTest(new CS.AssignOp(sym, e))]), new CS.FunctionApplication(sym, node['arguments']) ]; } else { return [ [].slice.call(tests).concat([typeofTest(e)]), new CS.FunctionApplication(e, node['arguments']) ]; } case !node['instanceof'](CS.SoakedMemberAccessOp, CS.SoakedProtoMemberAccessOp, CS.SoakedDynamicMemberAccessOp, CS.SoakedDynamicProtoMemberAccessOp): memberName = function () { switch (false) { case !node['instanceof'](CS.SoakedMemberAccessOp, CS.SoakedProtoMemberAccessOp): return 'memberName'; case !node['instanceof'](CS.SoakedDynamicMemberAccessOp, CS.SoakedDynamicProtoMemberAccessOp): return 'indexingExpr'; } }.call(this); ctor = function () { switch (false) { case !node['instanceof'](CS.SoakedMemberAccessOp): return CS.MemberAccessOp; case !node['instanceof'](CS.SoakedProtoMemberAccessOp): return CS.ProtoMemberAccessOp; case !node['instanceof'](CS.SoakedDynamicMemberAccessOp): return CS.DynamicMemberAccessOp; case !node['instanceof'](CS.SoakedDynamicProtoMemberAccessOp): return CS.DynamicProtoMemberAccessOp; } }.call(this); cache$6 = fn(node.expression); tests = cache$6[0]; e = cache$6[1]; if (needsCaching(e)) { sym = new CS.GenSym('cache'); return [ [].slice.call(tests).concat([new CS.UnaryExistsOp(new CS.AssignOp(sym, e))]), new ctor(sym, node[memberName]) ]; } else { return [ [].slice.call(tests).concat([new CS.UnaryExistsOp(e)]), new ctor(e, node[memberName]) ]; } default: return [ [], node ]; } }; return function (node) { var cache$2, e, tests; cache$2 = fn(node); tests = cache$2[0]; e = cache$2[1]; return new CS.Conditional(foldl1(tests, function (memo, t) { return new CS.LogicalAndOp(memo, t); }), e); }; }(); helperNames = {}; helpers = { 'extends': function () { var block, child, ctor, f, key, parent, protoAccess; protoAccess = function (e) { return memberAccess(e, 'prototype'); }; child = new JS.Identifier('child'); parent = new JS.Identifier('parent'); ctor = new JS.Identifier('ctor'); key = new JS.Identifier('key'); block = [ new JS.ForInStatement(new JS.VariableDeclaration('var', [new JS.VariableDeclarator(key, null)]), parent, new JS.IfStatement(helpers.isOwn(parent, key), f = stmt(new JS.AssignmentExpression('=', new JS.MemberExpression(true, child, key), new JS.MemberExpression(true, parent, key))))), new JS.FunctionDeclaration(ctor, [], new JS.BlockStatement([stmt(new JS.AssignmentExpression('=', memberAccess(new JS.ThisExpression, 'constructor'), child))])), new JS.AssignmentExpression('=', protoAccess(ctor), protoAccess(parent)), new JS.AssignmentExpression('=', protoAccess(child), new JS.NewExpression(ctor, [])), new JS.AssignmentExpression('=', memberAccess(child, '__super__'), protoAccess(parent)), new JS.ReturnStatement(child) ]; return new JS.FunctionDeclaration(helperNames['extends'], [ child, parent ], new JS.BlockStatement(map(block, stmt))); }, construct: function () { var args, block, child, ctor, fn, result; child = new JS.Identifier('child'); ctor = new JS.Identifier('ctor'); fn = new JS.Identifier('fn'); args = new JS.Identifier('args'); result = new JS.Identifier('result'); block = [ new JS.VariableDeclaration('var', [new JS.VariableDeclarator(fn, new JS.FunctionExpression(null, [], new JS.BlockStatement([])))]), new JS.AssignmentExpression('=', memberAccess(fn, 'prototype'), memberAccess(ctor, 'prototype')), new JS.VariableDeclaration('var', [ new JS.VariableDeclarator(child, new JS.NewExpression(fn, [])), new JS.VariableDeclarator(result, new JS.CallExpression(memberAccess(ctor, 'apply'), [ child, args ])) ]), new JS.ReturnStatement(new JS.ConditionalExpression(new JS.BinaryExpression('===', result, new JS.CallExpression(new JS.Identifier('Object'), [result])), result, child)) ]; return new JS.FunctionDeclaration(helperNames.construct, [ ctor, args ], new JS.BlockStatement(map(block, stmt))); }, isOwn: function () { var args, functionBody, hop, params; hop = memberAccess(new JS.ObjectExpression([]), 'hasOwnProperty'); params = args = [ new JS.Identifier('o'), new JS.Identifier('p') ]; functionBody = [new JS.CallExpression(memberAccess(hop, 'call'), args)]; return new JS.FunctionDeclaration(helperNames.isOwn, params, makeReturn(new JS.BlockStatement(map(functionBody, stmt)))); }, 'in': function () { var functionBody, i, length, list, loopBody, member, varDeclaration; member = new JS.Identifier('member'); list = new JS.Identifier('list'); i = new JS.Identifier('i'); length = new JS.Identifier('length'); varDeclaration = new JS.VariableDeclaration('var', [ new JS.VariableDeclarator(i, new JS.Literal(0)), new JS.VariableDeclarator(length, memberAccess(list, 'length')) ]); loopBody = new JS.IfStatement(new JS.LogicalExpression('&&', new JS.BinaryExpression('in', i, list), new JS.BinaryExpression('===', new JS.MemberExpression(true, list, i), member)), new JS.ReturnStatement(new JS.Literal(true))); functionBody = [ new JS.ForStatement(varDeclaration, new JS.BinaryExpression('<', i, length), new JS.UpdateExpression('++', true, i), loopBody), new JS.Literal(false) ]; return new JS.FunctionDeclaration(helperNames['in'], [ member, list ], makeReturn(new JS.BlockStatement(map(functionBody, stmt)))); } }; enabledHelpers = []; for (h in helpers) { if (!isOwn$(helpers, h)) continue; fn = helpers[h]; helperNames[h] = genSym(h); helpers[h] = function (h, fn) { return function () { enabledHelpers.push(fn()); return (helpers[h] = function () { return new JS.CallExpression(helperNames[h], arguments); }).apply(this, arguments); }; }(h, fn); } inlineHelpers = { exp: function () { return new JS.CallExpression(memberAccess(new JS.Identifier('Math'), 'pow'), arguments); }, undef: function () { return new JS.UnaryExpression('void', new JS.Literal(0)); }, slice: function () { return new JS.CallExpression(memberAccess(memberAccess(new JS.ArrayExpression([]), 'slice'), 'call'), arguments); } }; for (h in inlineHelpers) { if (!isOwn$(inlineHelpers, h)) continue; fn = inlineHelpers[h]; helpers[h] = fn; } exports.Compiler = function () { Compiler.compile = function (this$) { return function () { var cache$2; return (cache$2 = new this$).compile.apply(cache$2, [].slice.call(arguments)); }; }(Compiler); defaultRules = [ [ CS.Program, function (param$) { var block, body, cache$2, cache$3, decls, fnDeclHelpers, inScope, options, otherHelpers, pkg, program; { cache$2 = param$; body = cache$2.body; inScope = cache$2.inScope; options = cache$2.options; } if (!(null != body)) return new JS.Program([]); block = stmt(body); block = block['instanceof'](JS.BlockStatement) ? block.body : [block]; cache$3 = partition(enabledHelpers, function (helper) { return helper['instanceof'](JS.FunctionDeclaration); }); fnDeclHelpers = cache$3[0]; otherHelpers = cache$3[1]; [].push.apply(block, fnDeclHelpers); [].unshift.apply(block, otherHelpers); decls = nub(concatMap(block, declarationsNeededRecursive)); if (decls.length > 0) if (options.bare) { block.unshift(makeVarDeclaration(decls)); } else { block = [stmt(new JS.UnaryExpression('void', new JS.CallExpression(memberAccess(new JS.FunctionExpression(null, [], new JS.BlockStatement(block)), 'call'), [new JS.ThisExpression])))]; } pkg = require('./../package.json'); program = new JS.Program(block); program.leadingComments = [{ type: 'Line', value: ' Generated by CoffeeScript ' + pkg.version }]; return program; } ], [ CS.Block, function (param$) { var statements; statements = param$.statements; switch (statements.length) { case 0: return new JS.EmptyStatement; case 1: return new stmt(statements[0]); default: return new JS.BlockStatement(concatMap(statements, function (s) { if (s['instanceof'](JS.BlockStatement)) { return map(s.body, stmt); } else if (s['instanceof'](JS.SequenceExpression)) { return map(s.expressions, stmt); } else { return [stmt(s)]; } })); } } ], [ CS.SeqOp, function (param$) { var cache$2, left, right; { cache$2 = param$; left = cache$2.left; right = cache$2.right; } return new JS.SequenceExpression([ left, right ]); } ], [ CS.Conditional, function (param$) { var ancestry, cache$2, condition; var alternate, consequent; { cache$2 = param$; condition = cache$2.condition; consequent = cache$2.consequent; alternate = cache$2.alternate; ancestry = cache$2.ancestry; } if (null != alternate) { if (!(null != consequent)) throw new Error('Conditional with non-null alternate requires non-null consequent'); if (!alternate['instanceof'](JS.IfStatement)) alternate = forceBlock(alternate); } if (null != alternate || (null != ancestry[0] ? ancestry[0]['instanceof'](CS.Conditional) : void 0)) consequent = forceBlock(consequent); return new JS.IfStatement(expr(condition), stmt(consequent), alternate); } ], [ CS.ForIn, function (param$) { var block, body, cache$2, compile, e, filter, i, k, keyAssignee, length, op, step, target, update, valAssignee, varDeclaration; { cache$2 = param$; valAssignee = cache$2.valAssignee; keyAssignee = cache$2.keyAssignee; target = cache$2.target; step = cache$2.step; filter = cache$2.filter; body = cache$2.body; compile = cache$2.compile; } i = genSym('i'); length = genSym('length'); block = forceBlock(body); if (!block.body.length) block.body.push(stmt(helpers.undef())); if (this.target['instanceof'](CS.Range) && (this.target.left['instanceof'](CS.Int) || this.target.left['instanceof'](CS.UnaryNegateOp) && this.target.left.expression['instanceof'](CS.Int)) && (this.target.right['instanceof'](CS.Int) || this.target.right['instanceof'](CS.UnaryNegateOp) && this.target.right.expression['instanceof'](CS.Int))) { varDeclaration = new JS.AssignmentExpression('=', i, compile(this.target.left)); update = new JS.UpdateExpression('++', true, i); if (null != keyAssignee) { k = genSym('k'); varDeclaration = new JS.SequenceExpression([ new JS.AssignmentExpression('=', k, new JS.Literal(0)), varDeclaration ]); update = new JS.SequenceExpression([ new JS.UpdateExpression('++', true, k), update ]); block.body.unshift(stmt(new JS.AssignmentExpression('=', keyAssignee, k))); } if (null != valAssignee) block.body.unshift(stmt(new JS.AssignmentExpression('=', valAssignee, i))); op = this.target.isInclusive ? '<=' : '<'; return new JS.ForStatement(varDeclaration, new JS.BinaryExpression(op, i, compile(this.target.right)), update, block); } e = needsCaching(this.target) ? genSym('cache') : target; varDeclaration = new JS.VariableDeclaration('var', [ new JS.VariableDeclarator(i, new JS.Literal(0)), new JS.VariableDeclarator(length, memberAccess(e, 'length')) ]); if (!(e === target)) varDeclaration.declarations.unshift(new JS.VariableDeclarator(e, target)); if (null != this.filter) block.body.unshift(stmt(new JS.IfStatement(new JS.UnaryExpression('!', filter), new JS.ContinueStatement))); if (null != keyAssignee) block.body.unshift(stmt(assignment(keyAssignee, i))); if (null != valAssignee) block.body.unshift(stmt(assignment(valAssignee, new JS.MemberExpression(true, e, i)))); return new JS.ForStatement(varDeclaration, new JS.BinaryExpression('<', i, length), new JS.UpdateExpression('++', true, i), block); } ], [ CS.ForOf, function (param$) { var block, body, cache$2, e, filter, keyAssignee, right, target, valAssignee; { cache$2 = param$; keyAssignee = cache$2.keyAssignee; valAssignee = cache$2.valAssignee; target = cache$2.target; filter = cache$2.filter; body = cache$2.body; } block = forceBlock(body); if (!block.body.length) block.body.push(stmt(helpers.undef())); e = this.isOwn && needsCaching(this.target) ? genSym('cache') : expr(target); if (null != this.filter) block.body.unshift(stmt(new JS.IfStatement(new JS.UnaryExpression('!', filter), new JS.ContinueStatement))); if (null != valAssignee) block.body.unshift(stmt(assignment(valAssignee, new JS.MemberExpression(true, e, keyAssignee)))); if (this.isOwn) block.body.unshift(stmt(new JS.IfStatement(new JS.UnaryExpression('!', helpers.isOwn(e, keyAssignee)), new JS.ContinueStatement))); right = e === target ? e : new JS.AssignmentExpression('=', e, target); return new JS.ForInStatement(keyAssignee, right, block); } ], [ CS.While, function (param$) { var body, cache$2, condition; { cache$2 = param$; condition = cache$2.condition; body = cache$2.body; } return new JS.WhileStatement(expr(condition), forceBlock(body)); } ], [ CS.Switch, function (param$) { var alternate, c, cache$2; var cases, expression; { cache$2 = param$; expression = cache$2.expression; cases = cache$2.cases; alternate = cache$2.alternate; } cases = concat(cases); if (!(null != expression)) { expression = new JS.Literal(false); for (var i$ = 0, length$ = cases.length; i$ < length$; ++i$) { c = cases[i$]; c.test = new JS.UnaryExpression('!', c.test); } } if (null != alternate) cases.push(new JS.SwitchCase(null, [stmt(alternate)])); for (var i$1 = 0, length$1 = cases.slice(0, -1).length; i$1 < length$1; ++i$1) { c = cases.slice(0, -1)[i$1]; if (!((null != c.consequent ? c.consequent.length : void 0) > 0)) continue; c.consequent.push(new JS.BreakStatement); } return new JS.SwitchStatement(expression, cases); } ], [ CS.SwitchCase, function (param$) { var block, cache$2, cases, conditions, consequent; { cache$2 = param$; conditions = cache$2.conditions; consequent = cache$2.consequent; } cases = map(conditions, function (c) { return new JS.SwitchCase(c, []); }); block = stmt(consequent); block = null != block ? block['instanceof'](JS.BlockStatement) ? block.body : [block] : []; cases[cases.length - 1].consequent = block; return cases; } ], [ CS.Try, function (param$) { var body, cache$2, catchAssignee, catchBlock, catchBody, e, finallyBlock, finallyBody, handlers; { cache$2 = param$; body = cache$2.body; catchAssignee = cache$2.catchAssignee; catchBody = cache$2.catchBody; finallyBody = cache$2.finallyBody; } finallyBlock = null != this.finallyBody ? forceBlock(finallyBody) : null; if (null != this.catchBody || !(null != this.finallyBody)) { e = genSym('e'); catchBlock = forceBlock(catchBody); if (null != catchAssignee) catchBlock.body.unshift(stmt(assignment(catchAssignee, e))); handlers = [new JS.CatchClause(e, catchBlock)]; } else { handlers = []; } return new JS.TryStatement(forceBlock(body), handlers, finallyBlock); } ], [ CS.Throw, function (param$) { var expression; expression = param$.expression; return new JS.ThrowStatement(expression); } ], [ CS.Range, function (param$) { var accum, ancestry, body, cache$2, condition, conditionAlternate, conditionConsequent, conditionTest, i, left, left_, range, rawLeft, rawRight, right, right_, update, vars; { cache$2 = param$; left_ = cache$2.left; right_ = cache$2.right; ancestry = cache$2.ancestry; } if ((this.left['instanceof'](CS.Int) || this.left['instanceof'](CS.UnaryNegateOp) && this.left.expression['instanceof'](CS.Int)) && (this.right['instanceof'](CS.Int) || this.right['instanceof'](CS.UnaryNegateOp) && this.right.expression['instanceof'](CS.Int))) { rawLeft = this.left['instanceof'](CS.UnaryNegateOp) ? -this.left.expression.data : this.left.data; rawRight = this.right['instanceof'](CS.UnaryNegateOp) ? -this.right.expression.data : this.right.data; if (Math.abs(rawLeft - rawRight) <= 20) { range = this.isInclusive ? function () { var accum$; accum$ = []; for (var i$ = rawLeft; rawLeft <= rawRight ? i$ <= rawRight : i$ >= rawRight; rawLeft <= rawRight ? ++i$ : --i$) accum$.push(i$); return accum$; }.apply(this, arguments) : function () { var accum$; accum$ = []; for (var i$ = rawLeft; rawLeft <= rawRight ? i$ < rawRight : i$ > rawRight; rawLeft <= rawRight ? ++i$ : --i$) accum$.push(i$); return accum$; }.apply(this, arguments); return new JS.ArrayExpression(map(range, function (n) { if (n < 0) { return new JS.UnaryExpression('-', new JS.Literal(-n)); } else { return new JS.Literal(n); } })); } } accum = genSym('accum'); body = [stmt(new JS.AssignmentExpression('=', accum, new JS.ArrayExpression([])))]; if (needsCaching(left_)) { left = genSym('from'); body.push(stmt(new JS.AssignmentExpression('=', left, left_))); } else { left = left_; } if (needsCaching(right_)) { right = genSym('to'); body.push(stmt(new JS.AssignmentExpression('=', right, right_))); } else { right = right_; } i = genSym('i'); vars = new JS.VariableDeclaration('var', [new JS.VariableDeclarator(i, left)]); conditionTest = new JS.BinaryExpression('<=', left, right); conditionConsequent = new JS.BinaryExpression(this.isInclusive ? '<=' : '<', i, right); conditionAlternate = new JS.BinaryExpression(this.isInclusive ? '>=' : '>', i, right); condition = new JS.ConditionalExpression(conditionTest, conditionConsequent, conditionAlternate); update = new JS.ConditionalExpression(conditionTest, new JS.UpdateExpression('++', true, i), new JS.UpdateExpression('--', true, i)); body.push(new JS.ForStatement(vars, condition, update, stmt(new JS.CallExpression(memberAccess(accum, 'push'), [i])))); body.push(new JS.ReturnStatement(accum)); if (any(ancestry, function (ancestor) { return ancestor['instanceof'](CS.Functions); })) { return new JS.CallExpression(memberAccess(new JS.FunctionExpression(null, [], new JS.BlockStatement(body)), 'apply'), [ new JS.ThisExpression, new JS.Identifier('arguments') ]); } else { return new JS.CallExpression(memberAccess(new JS.FunctionExpression(null, [], new JS.BlockStatement(body)), 'call'), [new JS.ThisExpression]); } } ], [ CS.ArrayInitialiser, function () { var groupMembers; groupMembers = function (members) { var cache$2, cache$3, sliced, ys, zs; if (members.length === 0) { return []; } else { cache$2 = span(members, function (x) { return !x.spread; }); ys = cache$2[0]; zs = cache$2[1]; if (ys.length === 0) { sliced = helpers.slice(zs[0].expression); cache$3 = [ sliced, zs.slice(1) ]; ys = cache$3[0]; zs = cache$3[1]; cache$3; } else { ys = new JS.ArrayExpression(map(ys, expr)); } return [ys].concat(groupMembers(zs)); } }; return function (param$) { var cache$2, compile, grouped, members; { cache$2 = param$; members = cache$2.members; compile = cache$2.compile; } if (any(members, function (m) { return m.spread; })) { grouped = map(groupMembers(members), expr); if (grouped.length <= 1) { return grouped[0]; } else { return new JS.CallExpression(memberAccess(grouped[0], 'concat'), grouped.slice(1)); } } else { return new JS.ArrayExpression(map(members, expr)); } }; }() ], [ CS.Spread, function (param$) { var expression; expression = param$.expression; return { spread: true, expression: expr(expression) }; } ], [ CS.ObjectInitialiser, function (param$) { var members; members = param$.members; return new JS.ObjectExpression(members); } ], [ CS.ObjectInitialiserMember, function (param$) { var cache$2, expression, keyName; var key; { cache$2 = param$; key = cache$2.key; expression = cache$2.expression; } keyName = this.key.data; key = isIdentifierName(keyName) ? new JS.Identifier(keyName) : new JS.Literal(keyName); return new JS.Property(key, expr(expression)); } ], [ CS.DefaultParam, function (param$) { var cache$2, d, param; { cache$2 = param$; param = cache$2.param; d = cache$2['default']; } return { param: param, 'default': d }; } ], [ CS.Function, CS.BoundFunction, function () { var handleParam; handleParam = function (param, original, block, inScope) { var decls, p; switch (false) { case !original['instanceof'](CS.Rest): return param; case !original['instanceof'](CS.Identifier): return param; case !original['instanceof'](CS.MemberAccessOps, CS.ObjectInitialiser, CS.ArrayInitialiser): p = genSym('param'); decls = map(intersect(inScope, beingDeclared(original)), function (i) { return new JS.Identifier(i); }); block.body.unshift(stmt(assignment(param, p))); if (decls.length) block.body.unshift(makeVarDeclaration(decls)); return p; case !original['instanceof'](CS.DefaultParam): p = handleParam.call(this, param.param, original.param, block, inScope); block.body.unshift(new JS.IfStatement(new JS.BinaryExpression('==', new JS.Literal(null), p), stmt(assignment(p, param['default'])))); return p; default: throw new Error('Unsupported parameter type: ' + original.className); } }; return function (param$) { var alternate, ancestry, block, cache$2, consequent, i, index, inScope, last, newThis, numArgs, numParams, p, parameters_, paramName, performedRewrite, pIndex, reassignments, rewriteThis, test; var body, parameters; { cache$2 = param$; parameters = cache$2.parameters; body = cache$2.body; ancestry = cache$2.ancestry; inScope = cache$2.inScope; } if (!(null != ancestry[0] ? ancestry[0]['instanceof'](CS.Constructor) : void 0)) body = makeReturn(body); block = forceBlock(body); last = block.body.slice(-1)[0]; if ((null != last ? last['instanceof'](JS.ReturnStatement) : void 0) && !(null != last.argument)) block.body = block.body.slice(0, -1); parameters_ = parameters.length === 0 ? [] : (pIndex = parameters.length, function (accum$) { while (pIndex--) { accum$.push(handleParam.call(this, parameters[pIndex], this.parameters[pIndex], block, inScope)); } return accum$; }.call(this, [])); parameters = parameters_.reverse(); if (parameters.length > 0) { if (parameters.slice(-1)[0].rest) { numParams = parameters.length; paramName = parameters[numParams - 1] = parameters[numParams - 1].expression; test = new JS.BinaryExpression('<=', new JS.Literal(numParams), memberAccess(new JS.Identifier('arguments'), 'length')); consequent = helpers.slice(new JS.Identifier('arguments'), new JS.Literal(numParams - 1)); alternate = new JS.ArrayExpression([]); block.body.unshift(stmt(new JS.AssignmentExpression('=', paramName, new JS.ConditionalExpression(test, consequent, alternate)))); } else if (any(parameters, function (p) { return p.rest; })) { paramName = index = null; for (var i$ = 0, length$ = parameters.length; i$ < length$; ++i$) { p = parameters[i$]; i = i$; if (!p.rest) continue; paramName = p.expression; index = i; break; } parameters.splice(index, 1); numParams = parameters.length; numArgs = genSym('numArgs'); reassignments = new JS.IfStatement(new JS.BinaryExpression('>', new JS.AssignmentExpression('=', numArgs, memberAccess(new JS.Identifier('arguments'), 'length')), new JS.Literal(numParams)), new JS.BlockStatement([stmt(new JS.AssignmentExpression('=', paramName, helpers.slice(new JS.Identifier('arguments'), new JS.Literal(index), new JS.BinaryExpression('-', numArgs, new JS.Literal(numParams - index)))))]), new JS.BlockStatement([stmt(new JS.AssignmentExpression('=', paramName, new JS.ArrayExpression([])))])); for (var i$1 = 0, length$1 = parameters.slice(index).length; i$1 < length$1; ++i$1) { p = parameters.slice(index)[i$1]; i = i$1; reassignments.consequent.body.push(stmt(new JS.AssignmentExpression('=', p, new JS.MemberExpression(true, new JS.Identifier('arguments'), new JS.BinaryExpression('-', numArgs, new JS.Literal(numParams - index - i)))))); } block.body.unshift(makeVarDeclaration([paramName]), reassignments); } if (any(parameters, function (p) { return p.rest; })) throw new Error('Parameter lists may not have more than one rest operator'); } performedRewrite = false; if (this['instanceof'](CS.BoundFunction)) { newThis = genSym('this'); rewriteThis = generateMutatingWalker(function () { if (this['instanceof'](JS.ThisExpression)) { performedRewrite = true; return newThis; } else if (this['instanceof'](JS.FunctionExpression, JS.FunctionDeclaration)) { return this; } else { return rewriteThis(this); } }); rewriteThis(block); } fn = new JS.FunctionExpression(null, parameters, block); if (performedRewrite) { return new JS.CallExpression(new JS.FunctionExpression(null, [newThis], new JS.BlockStatement([new JS.ReturnStatement(fn)])), [new JS.ThisExpression]); } else { return fn; } }; }() ], [ CS.Rest, function (param$) { var expression; expression = param$.expression; return { rest: true, expression: expression, isExpression: true, isStatement: true }; } ], [ CS.Class, function (param$) { var _, args, block, body, c, cache$2, compile, ctorBody, ctorIndex, ctorRef, i, iife, instance, member, memberName, nameAssignee, params, parent, parentRef, protoAssignOp, protoMember, ps, rewriteThis; var ctor, name; { cache$2 = param$; nameAssignee = cache$2.nameAssignee; parent = cache$2.parent; name = cache$2.name; ctor = cache$2.ctor; body = cache$2.body; compile = cache$2.compile; } args = []; params = []; parentRef = genSym('super'); block = forceBlock(body); if (name['instanceof'](JS.Identifier) && in$(name.name, jsReserved)) name = genSym(name.name); if (null != ctor) { for (var i$ = 0, length$ = block.body.length; i$ < length$; ++i$) { c = block.body[i$]; i = i$; if (!c['instanceof'](JS.FunctionDeclaration)) continue; ctorIndex = i; break; } block.body.splice(ctorIndex, 1, ctor); } else { ctorBody = new JS.BlockStatement([]); if (null != parent) ctorBody.body.push(stmt(new JS.CallExpression(memberAccess(parentRef, 'apply'), [ new JS.ThisExpression, new JS.Identifier('arguments') ]))); ctor = new JS.FunctionDeclaration(name, [], ctorBody); ctorIndex = 0; block.body.unshift(ctor); } ctor.id = name; if (null != this.ctor && !this.ctor.expression['instanceof'](CS.Functions)) { ctorRef = genSym('externalCtor'); ctor.body.body.push(makeReturn(new JS.CallExpression(memberAccess(ctorRef, 'apply'), [ new JS.ThisExpression, new JS.Identifier('arguments') ]))); block.body.splice(ctorIndex, 0, stmt(new JS.AssignmentExpression('=', ctorRef, expr(compile(this.ctor.expression))))); } if (this.boundMembers.length > 0) { instance = genSym('instance'); for (var i$1 = 0, length$1 = this.boundMembers.length; i$1 < length$1; ++i$1) { protoAssignOp = this.boundMembers[i$1]; memberName = protoAssignOp.assignee.data.toString(); ps = function (accum$) { for (var i$2 = 0, length$2 = protoAssignOp.expression.parameters.length; i$2 < length$2; ++i$2) { _ = protoAssignOp.expression.parameters[i$2]; accum$.push(genSym()); } return accum$; }.call(this, []); member = memberAccess(new JS.ThisExpression, memberName); protoMember = memberAccess(memberAccess(name, 'prototype'), memberName); fn = new JS.FunctionExpression(null, ps, new JS.BlockStatement([makeReturn(new JS.CallExpr