Skip to content

Instantly share code, notes, and snippets.

@yukulele yukulele/esdown.js
Created Jun 29, 2015

Embed
What would you like to do?
esdown
/*=esdown=*/(function(fn, deps, name) { function obj() { return {} } if (typeof exports !== 'undefined') fn(require, exports, module); else if (typeof define === 'function' && define.amd) define(['require', 'exports', 'module'].concat(deps), fn); else if (typeof window !== 'undefined' && name) fn(obj, window[name] = {}, {}); else if (typeof self !== 'undefined' && name) fn(obj, self[name] = {}, {}); else fn(obj, {}, {}); })(function(require, exports, module) { 'use strict'; function __load(p, l) { module.__es6 = !l; var e = require(p); if (e && e.constructor !== Object) e.default = e; return e; }
(function() {
var VERSION = "0.9.9";
var Global = (function() {
try { return global.global } catch (x) {}
try { return self.self } catch (x) {}
return null;
})();
function toObject(val) {
if (val == null)
throw new TypeError(val + " is not an object");
return Object(val);
}
// Iterates over the descriptors for each own property of an object
function forEachDesc(obj, fn) {
var names = Object.getOwnPropertyNames(obj);
for (var i$0 = 0; i$0 < names.length; ++i$0)
fn(names[i$0], Object.getOwnPropertyDescriptor(obj, names[i$0]));
names = Object.getOwnPropertySymbols(obj);
for (var i$1 = 0; i$1 < names.length; ++i$1)
fn(names[i$1], Object.getOwnPropertyDescriptor(obj, names[i$1]));
return obj;
}
// Installs a property into an object, merging "get" and "set" functions
function mergeProperty(target, name, desc, enumerable) {
if (desc.get || desc.set) {
var d$0 = { configurable: true };
if (desc.get) d$0.get = desc.get;
if (desc.set) d$0.set = desc.set;
desc = d$0;
}
desc.enumerable = enumerable;
Object.defineProperty(target, name, desc);
}
// Installs properties on an object, merging "get" and "set" functions
function mergeProperties(target, source, enumerable) {
forEachDesc(source, function(name, desc) { return mergeProperty(target, name, desc, enumerable); });
}
// Builds a class
function buildClass(base, def) {
var parent;
if (def === void 0) {
// If no base class is specified, then Object.prototype
// is the parent prototype
def = base;
base = null;
parent = Object.prototype;
} else if (base === null) {
// If the base is null, then then then the parent prototype is null
parent = null;
} else if (typeof base === "function") {
parent = base.prototype;
// Prototype must be null or an object
if (parent !== null && Object(parent) !== parent)
parent = void 0;
}
if (parent === void 0)
throw new TypeError;
// Create the prototype object
var proto = Object.create(parent),
statics = {};
function __(target, obj) {
if (!obj) mergeProperties(proto, target, false);
else mergeProperties(target, obj, false);
}
__.static = function(obj) { return mergeProperties(statics, obj, false); };
__.super = parent;
__.csuper = base || Function.prototype;
// Generate method collections, closing over super bindings
def(__);
var ctor = proto.constructor;
// Set constructor's prototype
ctor.prototype = proto;
// Set class "static" methods
forEachDesc(statics, function(name, desc) { return Object.defineProperty(ctor, name, desc); });
// Inherit from base constructor
if (base && ctor.__proto__)
Object.setPrototypeOf(ctor, base);
return ctor;
}
Global._esdown = {
version: VERSION,
global: Global,
class: buildClass,
// Support for iterator protocol
iter: function(obj) {
if (obj[Symbol.iterator] !== void 0)
return obj[Symbol.iterator]();
if (Array.isArray(obj))
return obj.values();
return obj;
},
asyncIter: function(obj) {
if (obj[Symbol.asyncIterator] !== void 0)
return obj[Symbol.asyncIterator]();
var iter = _esdown.computed({ }, Symbol.asyncIterator, { _: function() { return this } }),
inner = _esdown.iter(obj);
["next", "throw", "return"].forEach(function(name) {
if (name in inner)
iter[name] = function(value) { return Promise.resolve(inner[name](value)); };
});
return iter;
},
// Support for computed property names
computed: function(target) {
for (var i$2 = 1; i$2 < arguments.length; i$2 += 3) {
var desc$0 = Object.getOwnPropertyDescriptor(arguments[i$2 + 1], "_");
mergeProperty(target, arguments[i$2], desc$0, true);
if (i$2 + 2 < arguments.length)
mergeProperties(target, arguments[i$2 + 2], true);
}
return target;
},
// Support for tagged templates
callSite: function(values, raw) {
values.raw = raw || values;
return values;
},
// Support for async functions
async: function(iter) {
return new Promise(function(resolve, reject) {
resume("next", void 0);
function resume(type, value) {
try {
var result$0 = iter[type](value);
if (result$0.done) {
resolve(result$0.value);
} else {
Promise.resolve(result$0.value).then(
function(x) { return resume("next", x); },
function(x) { return resume("throw", x); });
}
} catch (x) { reject(x) }
}
});
},
// Support for async generators
asyncGen: function(iter) {
var front = null, back = null;
return _esdown.computed({
next: function(val) { return send("next", val) },
throw: function(val) { return send("throw", val) },
return: function(val) { return send("return", val) },
}, Symbol.asyncIterator, { _: function() { return this },
});
function send(type, value) {
return new Promise(function(resolve, reject) {
var x = { type: type, value: value, resolve: resolve, reject: reject, next: null };
if (back) {
back = back.next = x;
} else {
front = back = x;
resume(type, value);
}
});
}
function resume(type, value) {
if (type === "return" && !(type in iter)) {
// HACK: If the generator does not support the "return" method, then
// emulate it (poorly) using throw. (V8 circa 2015-02-13 does not support
// generator.return.)
type = "throw";
value = { value: value, __return: true };
}
try {
var result$1 = iter[type](value);
value = result$1.value;
if (typeof value === "object" && "_esdown_await" in value) {
if (result$1.done)
throw new Error("Invalid async generator return");
Promise.resolve(value._esdown_await).then(
function(x) { return resume("next", x); },
function(x) { return resume("throw", x); });
return;
}
front.resolve(result$1);
} catch (x) {
if (x && x.__return === true) {
// HACK: Return-as-throw
front.resolve({ value: x.value, done: true });
} else {
front.reject(x);
}
}
front = front.next;
if (front) resume(front.type, front.value);
else back = null;
}
},
// Support for spread operations
spread: function() {
return {
a: [],
// Add items
s: function() {
for (var i$3 = 0; i$3 < arguments.length; ++i$3)
this.a.push(arguments[i$3]);
return this;
},
// Add the contents of iterables
i: function(list) {
if (Array.isArray(list)) {
this.a.push.apply(this.a, list);
} else {
for (var __$0 = _esdown.iter(list), __$1; __$1 = __$0.next(), !__$1.done;)
{ var item$0 = __$1.value; this.a.push(item$0); }
}
return this;
}
};
},
// Support for object destructuring
objd: function(obj) {
return toObject(obj);
},
// Support for array destructuring
arrayd: function(obj) {
if (Array.isArray(obj)) {
return {
at: function(skip, pos) { return obj[pos] },
rest: function(skip, pos) { return obj.slice(pos) }
};
}
var iter = _esdown.iter(toObject(obj));
return {
at: function(skip) {
var r;
while (skip--)
r = iter.next();
return r.value;
},
rest: function(skip) {
var a = [], r;
while (--skip)
r = iter.next();
while (r = iter.next(), !r.done)
a.push(r.value);
return a;
}
};
},
// Support for private fields
getPrivate: function(obj, map, name) {
var entry = map.get(Object(obj));
if (!entry)
throw new TypeError;
return entry[name];
},
setPrivate: function(obj, map, name, value) {
var entry = map.get(Object(obj));
if (!entry)
throw new TypeError;
return entry[name] = value;
}
};
}).call(this);
(function() {
// === Polyfill Utilities ===
function eachKey(obj, fn) {
var keys = Object.getOwnPropertyNames(obj);
for (var i$4 = 0; i$4 < keys.length; ++i$4)
fn(keys[i$4]);
if (!Object.getOwnPropertySymbols)
return;
keys = Object.getOwnPropertySymbols(obj);
for (var i$5 = 0; i$5 < keys.length; ++i$5)
fn(keys[i$5]);
}
function polyfill(obj, methods) {
eachKey(methods, function(key) {
if (key in obj)
return;
Object.defineProperty(obj, key, {
value: methods[key],
configurable: true,
enumerable: false,
writable: true
});
});
}
// === Spec Helpers ===
var sign = Math.sign || function(val) {
var n = +val;
if (n === 0 || Number.isNaN(n))
return n;
return n < 0 ? -1 : 1;
};
function toInteger(val) {
var n = +val;
return n !== n /* n is NaN */ ? 0 :
(n === 0 || !isFinite(n)) ? n :
sign(n) * Math.floor(Math.abs(n));
}
function toLength(val) {
var n = toInteger(val);
return n < 0 ? 0 : Math.min(n, Number.MAX_SAFE_INTEGER);
}
function sameValue(left, right) {
if (left === right)
return left !== 0 || 1 / left === 1 / right;
return left !== left && right !== right;
}
function isRegExp(val) {
return Object.prototype.toString.call(val) == "[object RegExp]";
}
function toObject(val) {
if (val == null)
throw new TypeError(val + " is not an object");
return Object(val);
}
function iteratorMethod(obj) {
// TODO: What about typeof === "string"?
if (!obj || typeof obj !== "object")
return null;
var m = obj[Symbol.iterator];
// Generator iterators in Node 0.11.13 do not have a [Symbol.iterator] method
if (!m && typeof obj.next === "function" && typeof obj.throw === "function")
return function() { return this };
return m;
}
function assertThis(val, name) {
if (val == null)
throw new TypeError(name + " called on null or undefined");
}
// === Symbols ===
var symbolCounter = 0,
global = _esdown.global;
function fakeSymbol() {
return "__$" + Math.floor(Math.random() * 1e9) + "$" + (++symbolCounter) + "$__";
}
if (!global.Symbol)
global.Symbol = fakeSymbol;
polyfill(Symbol, {
iterator: Symbol("iterator"),
species: Symbol("species"),
// Experimental async iterator support
asyncIterator: Symbol("asyncIterator"),
});
// === Object ===
polyfill(Object, {
is: sameValue,
assign: function(target, source) {
target = toObject(target);
for (var i$6 = 1; i$6 < arguments.length; ++i$6) {
source = arguments[i$6];
if (source != null) // null or undefined
Object.keys(source).forEach(function(key) { return target[key] = source[key]; });
}
return target;
},
setPrototypeOf: function(object, proto) {
// Least effort attempt
object.__proto__ = proto;
},
getOwnPropertySymbols: function() {
// If getOwnPropertySymbols is not supported, then just return an
// empty array so that we can avoid feature testing
}
});
// === Number ===
function isInteger(val) {
return typeof val === "number" && isFinite(val) && toInteger(val) === val;
}
function epsilon() {
// Calculate the difference between 1 and the smallest value greater than 1 that
// is representable as a Number value
var result;
for (var next$0 = 1; 1 + next$0 !== 1; next$0 = next$0 / 2)
result = next$0;
return result;
}
polyfill(Number, {
EPSILON: epsilon(),
MAX_SAFE_INTEGER: 9007199254740991,
MIN_SAFE_INTEGER: -9007199254740991,
parseInt: parseInt,
parseFloat: parseFloat,
isInteger: isInteger,
isFinite: function(val) { return typeof val === "number" && isFinite(val) },
isNaN: function(val) { return val !== val },
isSafeInteger: function(val) { return isInteger(val) && Math.abs(val) <= Number.MAX_SAFE_INTEGER }
});
// === String ===
polyfill(String, {
raw: function(callsite) { for (var args = [], __$0 = 1; __$0 < arguments.length; ++__$0) args.push(arguments[__$0]);
var raw = callsite.raw,
len = toLength(raw.length);
if (len === 0)
return "";
var s = "", i = 0;
while (true) {
s += raw[i];
if (i + 1 === len || i >= args.length) break;
s += args[i++];
}
return s;
},
fromCodePoint: function() { for (var points = [], __$0 = 0; __$0 < arguments.length; ++__$0) points.push(arguments[__$0]);
var out = [];
points.forEach(function(next) {
next = Number(next);
if (!sameValue(next, toInteger(next)) || next < 0 || next > 0x10ffff)
throw new RangeError("Invalid code point " + next);
if (next < 0x10000) {
out.push(String.fromCharCode(next));
} else {
next -= 0x10000;
out.push(String.fromCharCode((next >> 10) + 0xD800));
out.push(String.fromCharCode((next % 0x400) + 0xDC00));
}
});
return out.join("");
}
});
// Repeat a string by "squaring"
function repeat(s, n) {
if (n < 1) return "";
if (n % 2) return repeat(s, n - 1) + s;
var half = repeat(s, n / 2);
return half + half;
}
var StringIterator = _esdown.class(function(__) { var StringIterator;
__({ constructor: StringIterator = function(string) {
this.string = string;
this.current = 0;
},
next: function() {
var s = this.string,
i = this.current,
len = s.length;
if (i >= len) {
this.current = Infinity;
return { value: void 0, done: true };
}
var c = s.charCodeAt(i),
chars = 1;
if (c >= 0xD800 && c <= 0xDBFF && i + 1 < s.length) {
c = s.charCodeAt(i + 1);
chars = (c < 0xDC00 || c > 0xDFFF) ? 1 : 2;
}
this.current += chars;
return { value: s.slice(i, this.current), done: false };
}});
__(_esdown.computed({}, Symbol.iterator, { _: function() { return this } }));
});
polyfill(String.prototype, _esdown.computed({
repeat: function(count) {
assertThis(this, "String.prototype.repeat");
var string = String(this);
count = toInteger(count);
if (count < 0 || count === Infinity)
throw new RangeError("Invalid count value");
return repeat(string, count);
},
startsWith: function(search) {
assertThis(this, "String.prototype.startsWith");
if (isRegExp(search))
throw new TypeError("First argument to String.prototype.startsWith must not be a regular expression");
var string = String(this);
search = String(search);
var pos = arguments.length > 1 ? arguments[1] : undefined,
start = Math.max(toInteger(pos), 0);
return string.slice(start, start + search.length) === search;
},
endsWith: function(search) {
assertThis(this, "String.prototype.endsWith");
if (isRegExp(search))
throw new TypeError("First argument to String.prototype.endsWith must not be a regular expression");
var string = String(this);
search = String(search);
var len = string.length,
arg = arguments.length > 1 ? arguments[1] : undefined,
pos = arg === undefined ? len : toInteger(arg),
end = Math.min(Math.max(pos, 0), len);
return string.slice(end - search.length, end) === search;
},
contains: function(search) {
assertThis(this, "String.prototype.contains");
var string = String(this),
pos = arguments.length > 1 ? arguments[1] : undefined;
// Somehow this trick makes method 100% compat with the spec
return string.indexOf(search, pos) !== -1;
},
codePointAt: function(pos) {
assertThis(this, "String.prototype.codePointAt");
var string = String(this),
len = string.length;
pos = toInteger(pos);
if (pos < 0 || pos >= len)
return undefined;
var a = string.charCodeAt(pos);
if (a < 0xD800 || a > 0xDBFF || pos + 1 === len)
return a;
var b = string.charCodeAt(pos + 1);
if (b < 0xDC00 || b > 0xDFFF)
return a;
return ((a - 0xD800) * 1024) + (b - 0xDC00) + 0x10000;
},
}, Symbol.iterator, { _: function() {
assertThis(this, "String.prototype[Symbol.iterator]");
return new StringIterator(this);
}
}));
// === Array ===
var ArrayIterator = _esdown.class(function(__) { var ArrayIterator;
__({ constructor: ArrayIterator = function(array, kind) {
this.array = array;
this.current = 0;
this.kind = kind;
},
next: function() {
var length = toLength(this.array.length),
index = this.current;
if (index >= length) {
this.current = Infinity;
return { value: void 0, done: true };
}
this.current += 1;
switch (this.kind) {
case "values":
return { value: this.array[index], done: false };
case "entries":
return { value: [ index, this.array[index] ], done: false };
default:
return { value: index, done: false };
}
}});
__(_esdown.computed({}, Symbol.iterator, { _: function() { return this } }));
});
polyfill(Array, {
from: function(list) {
list = toObject(list);
var ctor = typeof this === "function" ? this : Array, // TODO: Always use "this"?
map = arguments[1],
thisArg = arguments[2],
i = 0,
out;
if (map !== void 0 && typeof map !== "function")
throw new TypeError(map + " is not a function");
var getIter = iteratorMethod(list);
if (getIter) {
var iter$0 = getIter.call(list),
result$2;
out = new ctor;
while (result$2 = iter$0.next(), !result$2.done) {
out[i++] = map ? map.call(thisArg, result$2.value, i) : result$2.value;
out.length = i;
}
} else {
var len$0 = toLength(list.length);
out = new ctor(len$0);
for (; i < len$0; ++i)
out[i] = map ? map.call(thisArg, list[i], i) : list[i];
out.length = len$0;
}
return out;
},
of: function() { for (var items = [], __$0 = 0; __$0 < arguments.length; ++__$0) items.push(arguments[__$0]);
var ctor = typeof this === "function" ? this : Array;
if (ctor === Array)
return items;
var len = items.length,
out = new ctor(len);
for (var i$7 = 0; i$7 < len; ++i$7)
out[i$7] = items[i$7];
out.length = len;
return out;
}
});
function arrayFind(obj, pred, thisArg, type) {
var len = toLength(obj.length),
val;
if (typeof pred !== "function")
throw new TypeError(pred + " is not a function");
for (var i$8 = 0; i$8 < len; ++i$8) {
val = obj[i$8];
if (pred.call(thisArg, val, i$8, obj))
return type === "value" ? val : i$8;
}
return type === "value" ? void 0 : -1;
}
polyfill(Array.prototype, _esdown.computed({
copyWithin: function(target, start) {
var obj = toObject(this),
len = toLength(obj.length),
end = arguments[2];
target = toInteger(target);
start = toInteger(start);
var to = target < 0 ? Math.max(len + target, 0) : Math.min(target, len),
from = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
end = end !== void 0 ? toInteger(end) : len;
end = end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
var count = Math.min(end - from, len - to),
dir = 1;
if (from < to && to < from + count) {
dir = -1;
from += count - 1;
to += count - 1;
}
for (; count > 0; --count) {
if (from in obj) obj[to] = obj[from];
else delete obj[to];
from += dir;
to += dir;
}
return obj;
},
fill: function(value) {
var obj = toObject(this),
len = toLength(obj.length),
start = toInteger(arguments[1]),
pos = start < 0 ? Math.max(len + start, 0) : Math.min(start, len),
end = arguments.length > 2 ? toInteger(arguments[2]) : len;
end = end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
for (; pos < end; ++pos)
obj[pos] = value;
return obj;
},
find: function(pred) {
return arrayFind(toObject(this), pred, arguments[1], "value");
},
findIndex: function(pred) {
return arrayFind(toObject(this), pred, arguments[1], "index");
},
values: function() { return new ArrayIterator(this, "values") },
entries: function() { return new ArrayIterator(this, "entries") },
keys: function() { return new ArrayIterator(this, "keys") },
}, Symbol.iterator, { _: function() { return this.values() }
}));
}).call(this);
(function() {
var global = _esdown.global,
ORIGIN = {},
REMOVED = {};
var MapNode = _esdown.class(function(__) { var MapNode;
__({ constructor: MapNode = function(key, val) {
this.key = key;
this.value = val;
this.prev = this;
this.next = this;
},
insert: function(next) {
this.next = next;
this.prev = next.prev;
this.prev.next = this;
this.next.prev = this;
},
remove: function() {
this.prev.next = this.next;
this.next.prev = this.prev;
this.key = REMOVED;
}});
});
var MapIterator = _esdown.class(function(__) { var MapIterator;
__({ constructor: MapIterator = function(node, kind) {
this.current = node;
this.kind = kind;
},
next: function() {
var node = this.current;
while (node.key === REMOVED)
node = this.current = this.current.next;
if (node.key === ORIGIN)
return { value: void 0, done: true };
this.current = this.current.next;
switch (this.kind) {
case "values":
return { value: node.value, done: false };
case "entries":
return { value: [ node.key, node.value ], done: false };
default:
return { value: node.key, done: false };
}
}});
__(_esdown.computed({}, Symbol.iterator, { _: function() { return this } }));
});
function hashKey(key) {
switch (typeof key) {
case "string": return "$" + key;
case "number": return String(key);
}
throw new TypeError("Map and Set keys must be strings or numbers in esdown");
}
var Map = _esdown.class(function(__) { var Map;
__({ constructor: Map = function() {
if (arguments.length > 0)
throw new Error("Arguments to Map constructor are not supported in esdown");
this._index = {};
this._origin = new MapNode(ORIGIN);
},
clear: function() {
for (var node$0 = this._origin.next; node$0 !== this._origin; node$0 = node$0.next)
node$0.key = REMOVED;
this._index = {};
this._origin = new MapNode(ORIGIN);
},
delete: function(key) {
var h = hashKey(key),
node = this._index[h];
if (node) {
node.remove();
delete this._index[h];
return true;
}
return false;
},
forEach: function(fn) {
var thisArg = arguments[1];
if (typeof fn !== "function")
throw new TypeError(fn + " is not a function");
for (var node$1 = this._origin.next; node$1.key !== ORIGIN; node$1 = node$1.next)
if (node$1.key !== REMOVED)
fn.call(thisArg, node$1.value, node$1.key, this);
},
get: function(key) {
var h = hashKey(key),
node = this._index[h];
return node ? node.value : void 0;
},
has: function(key) {
return hashKey(key) in this._index;
},
set: function(key, val) {
var h = hashKey(key),
node = this._index[h];
if (node) {
node.value = val;
return;
}
node = new MapNode(key, val);
this._index[h] = node;
node.insert(this._origin);
},
get size() {
return Object.keys(this._index).length;
},
keys: function() { return new MapIterator(this._origin.next, "keys") },
values: function() { return new MapIterator(this._origin.next, "values") },
entries: function() { return new MapIterator(this._origin.next, "entries") }});
__(_esdown.computed({}, Symbol.iterator, { _: function() { return new MapIterator(this._origin.next, "entries") } }));
});
var mapSet = Map.prototype.set;
var Set = _esdown.class(function(__) { var Set;
__({ constructor: Set = function() {
if (arguments.length > 0)
throw new Error("Arguments to Set constructor are not supported in esdown");
this._index = {};
this._origin = new MapNode(ORIGIN);
},
add: function(key) { return mapSet.call(this, key, key) }});
__(_esdown.computed({}, Symbol.iterator, { _: function() { return new MapIterator(this._origin.next, "entries") } }));
});
// Copy shared prototype members to Set
["clear", "delete", "forEach", "has", "size", "keys", "values", "entries"].forEach(function(k) {
var d = Object.getOwnPropertyDescriptor(Map.prototype, k);
Object.defineProperty(Set.prototype, k, d);
});
if (!global.Map || !global.Map.prototype.entries) {
global.Map = Map;
global.Set = Set;
}
}).call(this);
(function() {
(function() { "use strict";
// Find global variable and exit if Promise is defined on it
var Global = (function() {
if (typeof window !== "undefined" && window && window.window === window)
return window;
if (typeof global !== "undefined" && global && global.global === global)
return global;
if (typeof self !== "undefined" && self && self.self === self)
return self;
throw new Error("Unable to determine global object");
})();
if (typeof Global.Promise === "function")
return;
// Create an efficient microtask queueing mechanism
var runLater = (function() {
// Node
if (Global.process && typeof process.version === "string") {
return Global.setImmediate ?
function(fn) { setImmediate(fn); } :
function(fn) { process.nextTick(fn); };
}
// Newish Browsers
var Observer = Global.MutationObserver || Global.WebKitMutationObserver;
if (Observer) {
var div = document.createElement("div"),
queuedFn = void 0;
var observer = new Observer(function() {
var fn = queuedFn;
queuedFn = void 0;
fn();
});
observer.observe(div, { attributes: true });
return function(fn) {
if (queuedFn !== void 0)
throw new Error("Only one function can be queued at a time");
queuedFn = fn;
div.classList.toggle("x");
};
}
// Fallback
return function(fn) { setTimeout(fn, 0); };
})();
var EnqueueMicrotask = (function() {
var queue = null;
function flush() {
var q = queue;
queue = null;
for (var i = 0; i < q.length; ++i)
q[i]();
}
return function PromiseEnqueueMicrotask(fn) {
// fn must not throw
if (!queue) {
queue = [];
runLater(flush);
}
queue.push(fn);
};
})();
// Mock V8 internal functions and vars
function SET_PRIVATE(obj, prop, val) { obj[prop] = val; }
function GET_PRIVATE(obj, prop) { return obj[prop]; }
function IS_SPEC_FUNCTION(obj) { return typeof obj === "function"; }
function IS_SPEC_OBJECT(obj) { return obj === Object(obj); }
function HAS_DEFINED_PRIVATE(obj, prop) { return prop in obj; }
function IS_UNDEFINED(x) { return x === void 0; }
function MakeTypeError(msg) { return new TypeError(msg); }
// In IE8 Object.defineProperty only works on DOM nodes, and defineProperties does not exist
var _defineProperty = Object.defineProperties && Object.defineProperty;
function AddNamedProperty(target, name, value) {
if (!_defineProperty) {
target[name] = value;
return;
}
_defineProperty(target, name, {
configurable: true,
writable: true,
enumerable: false,
value: value
});
}
function InstallFunctions(target, attr, list) {
for (var i = 0; i < list.length; i += 2)
AddNamedProperty(target, list[i], list[i + 1]);
}
var IsArray = Array.isArray || (function(obj) {
var str = Object.prototype.toString;
return function(obj) { return str.call(obj) === "[object Array]" };
})();
var UNDEFINED, DONT_ENUM, InternalArray = Array;
// V8 Implementation
var IsPromise;
var PromiseCreate;
var PromiseResolve;
var PromiseReject;
var PromiseChain;
var PromiseCatch;
var PromiseThen;
// Status values: 0 = pending, +1 = resolved, -1 = rejected
var promiseStatus = "Promise#status";
var promiseValue = "Promise#value";
var promiseOnResolve = "Promise#onResolve";
var promiseOnReject = "Promise#onReject";
var promiseRaw = {};
var promiseHasHandler = "Promise#hasHandler";
var lastMicrotaskId = 0;
var $Promise = function Promise(resolver) {
if (resolver === promiseRaw) return;
if (!IS_SPEC_FUNCTION(resolver))
throw MakeTypeError('resolver_not_a_function', [resolver]);
var promise = PromiseInit(this);
try {
resolver(function(x) { PromiseResolve(promise, x) },
function(r) { PromiseReject(promise, r) });
} catch (e) {
PromiseReject(promise, e);
}
}
// Core functionality.
function PromiseSet(promise, status, value, onResolve, onReject) {
SET_PRIVATE(promise, promiseStatus, status);
SET_PRIVATE(promise, promiseValue, value);
SET_PRIVATE(promise, promiseOnResolve, onResolve);
SET_PRIVATE(promise, promiseOnReject, onReject);
return promise;
}
function PromiseInit(promise) {
return PromiseSet(promise, 0, UNDEFINED, new InternalArray, new InternalArray);
}
function PromiseDone(promise, status, value, promiseQueue) {
if (GET_PRIVATE(promise, promiseStatus) === 0) {
PromiseEnqueue(value, GET_PRIVATE(promise, promiseQueue), status);
PromiseSet(promise, status, value);
}
}
function PromiseCoerce(constructor, x) {
if (!IsPromise(x) && IS_SPEC_OBJECT(x)) {
var then;
try {
then = x.then;
} catch(r) {
return PromiseRejected.call(constructor, r);
}
if (IS_SPEC_FUNCTION(then)) {
var deferred = PromiseDeferred.call(constructor);
try {
then.call(x, deferred.resolve, deferred.reject);
} catch(r) {
deferred.reject(r);
}
return deferred.promise;
}
}
return x;
}
function PromiseHandle(value, handler, deferred) {
try {
var result = handler(value);
if (result === deferred.promise)
throw MakeTypeError('promise_cyclic', [result]);
else if (IsPromise(result))
PromiseChain.call(result, deferred.resolve, deferred.reject);
else
deferred.resolve(result);
} catch (exception) {
try { deferred.reject(exception) } catch (e) { }
}
}
function PromiseEnqueue(value, tasks, status) {
EnqueueMicrotask(function() {
for (var i = 0; i < tasks.length; i += 2)
PromiseHandle(value, tasks[i], tasks[i + 1]);
});
}
function PromiseIdResolveHandler(x) { return x }
function PromiseIdRejectHandler(r) { throw r }
function PromiseNopResolver() {}
// -------------------------------------------------------------------
// Define exported functions.
// For bootstrapper.
IsPromise = function IsPromise(x) {
return IS_SPEC_OBJECT(x) && HAS_DEFINED_PRIVATE(x, promiseStatus);
};
PromiseCreate = function PromiseCreate() {
return new $Promise(PromiseNopResolver);
};
PromiseResolve = function PromiseResolve(promise, x) {
PromiseDone(promise, +1, x, promiseOnResolve);
};
PromiseReject = function PromiseReject(promise, r) {
PromiseDone(promise, -1, r, promiseOnReject);
};
// Convenience.
function PromiseDeferred() {
if (this === $Promise) {
// Optimized case, avoid extra closure.
var promise = PromiseInit(new $Promise(promiseRaw));
return {
promise: promise,
resolve: function(x) { PromiseResolve(promise, x) },
reject: function(r) { PromiseReject(promise, r) }
};
} else {
var result = {};
result.promise = new this(function(resolve, reject) {
result.resolve = resolve;
result.reject = reject;
});
return result;
}
}
function PromiseResolved(x) {
if (this === $Promise) {
// Optimized case, avoid extra closure.
return PromiseSet(new $Promise(promiseRaw), +1, x);
} else {
return new this(function(resolve, reject) { resolve(x) });
}
}
function PromiseRejected(r) {
var promise;
if (this === $Promise) {
// Optimized case, avoid extra closure.
promise = PromiseSet(new $Promise(promiseRaw), -1, r);
} else {
promise = new this(function(resolve, reject) { reject(r) });
}
return promise;
}
// Simple chaining.
PromiseChain = function PromiseChain(onResolve, onReject) {
onResolve = IS_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve;
onReject = IS_UNDEFINED(onReject) ? PromiseIdRejectHandler : onReject;
var deferred = PromiseDeferred.call(this.constructor);
switch (GET_PRIVATE(this, promiseStatus)) {
case UNDEFINED:
throw MakeTypeError('not_a_promise', [this]);
case 0: // Pending
GET_PRIVATE(this, promiseOnResolve).push(onResolve, deferred);
GET_PRIVATE(this, promiseOnReject).push(onReject, deferred);
break;
case +1: // Resolved
PromiseEnqueue(GET_PRIVATE(this, promiseValue), [onResolve, deferred], +1);
break;
case -1: // Rejected
PromiseEnqueue(GET_PRIVATE(this, promiseValue), [onReject, deferred], -1);
break;
}
// Mark this promise as having handler.
SET_PRIVATE(this, promiseHasHandler, true);
return deferred.promise;
}
PromiseCatch = function PromiseCatch(onReject) {
return this.then(UNDEFINED, onReject);
}
// Multi-unwrapped chaining with thenable coercion.
PromiseThen = function PromiseThen(onResolve, onReject) {
onResolve = IS_SPEC_FUNCTION(onResolve) ? onResolve : PromiseIdResolveHandler;
onReject = IS_SPEC_FUNCTION(onReject) ? onReject : PromiseIdRejectHandler;
var that = this;
var constructor = this.constructor;
return PromiseChain.call(
this,
function(x) {
x = PromiseCoerce(constructor, x);
return x === that ? onReject(MakeTypeError('promise_cyclic', [x])) :
IsPromise(x) ? x.then(onResolve, onReject) :
onResolve(x);
},
onReject);
}
// Combinators.
function PromiseCast(x) {
return IsPromise(x) ? x : new this(function(resolve) { resolve(x) });
}
function PromiseAll(values) {
var deferred = PromiseDeferred.call(this);
var resolutions = [];
if (!IsArray(values)) {
deferred.reject(MakeTypeError('invalid_argument'));
return deferred.promise;
}
try {
var count = values.length;
if (count === 0) {
deferred.resolve(resolutions);
} else {
for (var i = 0; i < values.length; ++i) {
this.resolve(values[i]).then(
(function() {
// Nested scope to get closure over current i (and avoid .bind).
var i_captured = i;
return function(x) {
resolutions[i_captured] = x;
if (--count === 0) deferred.resolve(resolutions);
};
})(),
function(r) { deferred.reject(r) });
}
}
} catch (e) {
deferred.reject(e);
}
return deferred.promise;
}
function PromiseOne(values) {
var deferred = PromiseDeferred.call(this);
if (!IsArray(values)) {
deferred.reject(MakeTypeError('invalid_argument'));
return deferred.promise;
}
try {
for (var i = 0; i < values.length; ++i) {
this.resolve(values[i]).then(
function(x) { deferred.resolve(x) },
function(r) { deferred.reject(r) });
}
} catch (e) {
deferred.reject(e);
}
return deferred.promise;
}
// -------------------------------------------------------------------
// Install exported functions.
AddNamedProperty(Global, 'Promise', $Promise, DONT_ENUM);
InstallFunctions($Promise, DONT_ENUM, [
"defer", PromiseDeferred,
"accept", PromiseResolved,
"reject", PromiseRejected,
"all", PromiseAll,
"race", PromiseOne,
"resolve", PromiseCast
]);
InstallFunctions($Promise.prototype, DONT_ENUM, [
"chain", PromiseChain,
"then", PromiseThen,
"catch", PromiseCatch
]);
})();
}).call(this);
(function() {
// === Job Queueing ===
var enqueueJob = (function() {
// Node
if (typeof self === "undefined" && typeof global !== "undefined") {
return global.setImmediate ?
function(fn) { global.setImmediate(fn) } :
function(fn) { process.nextTick(fn) };
}
// Newish Browsers
var Observer = self.MutationObserver || self.WebKitMutationObserver;
if (Observer) {
var div$0 = document.createElement("div"),
twiddle$0 = function(_) { return div$0.classList.toggle("x"); },
queue$0 = [];
var observer$0 = new Observer(function(_) {
if (queue$0.length > 1)
twiddle$0();
while (queue$0.length > 0)
queue$0.shift()();
});
observer$0.observe(div$0, { attributes: true });
return function(fn) {
queue$0.push(fn);
if (queue$0.length === 1)
twiddle$0();
};
}
// Fallback
return function(fn) { setTimeout(fn, 0) };
})();
// === Symbol Polyfills ===
function polyfillSymbol(name) {
if (!Symbol[name])
Object.defineProperty(Symbol, name, { value: Symbol(name) });
}
polyfillSymbol("observable");
// === Abstract Operations ===
function cancelSubscription(observer) {
var subscription = observer._subscription;
if (!subscription)
return;
// Drop the reference to the subscription so that we don't unsubscribe
// more than once
observer._subscription = undefined;
try {
// Call the unsubscribe function
subscription.unsubscribe();
} finally {
// Drop the reference to the inner observer so that no more notifications
// will be sent
observer._observer = undefined;
}
}
function closeSubscription(observer) {
observer._observer = undefined;
cancelSubscription(observer);
}
function hasUnsubscribe(x) {
return Object(x) === x && typeof x.unsubscribe === "function";
}
var SubscriptionObserver = _esdown.class(function(__) { var SubscriptionObserver;
__({ constructor: SubscriptionObserver = function(observer) {
this._observer = observer;
this._subscription = undefined;
},
next: function(value) {
var observer = this._observer;
// If the stream if closed, then return a "done" result
if (!observer)
return { value: undefined, done: true };
var result;
try {
// Send the next value to the sink
result = observer.next(value);
} catch (e) {
// If the observer throws, then close the stream and rethrow the error
closeSubscription(this);
throw e;
}
// Cleanup if sink is closed
if (result && result.done)
closeSubscription(this);
return result;
},
throw: function(value) {
var observer = this._observer;
// If the stream is closed, throw the error to the caller
if (!observer)
throw value;
this._observer = undefined;
try {
// If the sink does not support "throw", then throw the error to the caller
if (!("throw" in observer))
throw value;
return observer.throw(value);
} finally {
cancelSubscription(this);
}
},
return: function(value) {
var observer = this._observer;
// If the stream is closed, then return a done result
if (!observer)
return { value: value, done: true };
this._observer = undefined;
try {
// If the sink does not support "return", then return a done result
if (!("return" in observer))
return { value: value, done: true };
return observer.return(value);
} finally {
cancelSubscription(this);
}
}});
});
var Observable = _esdown.class(function(__) { var Observable;
__({ constructor: Observable = function(subscriber) {
// The stream subscriber must be a function
if (typeof subscriber !== "function")
throw new TypeError("Observable initializer must be a function");
this._subscriber = subscriber;
},
subscribe: function(observer) { var __this = this;
// The sink must be an object
if (Object(observer) !== observer)
throw new TypeError("Observer must be an object");
// Wrap the observer in order to maintain observation invariants
observer = new SubscriptionObserver(observer);
var unsubscribed = false,
subscription;
enqueueJob(function(_) {
if (unsubscribed)
return;
try {
// Call the subscriber function
subscription = __this._subscriber.call(undefined, observer);
if (!hasUnsubscribe(subscription)) {
var unsubscribe$0 = typeof subscription === "function" ?
subscription :
(function(_) { observer.return() });
subscription = { unsubscribe: unsubscribe$0 };
}
} catch (e) {
// If an error occurs during startup, then attempt to send the error
// to the observer
observer.throw(e);
}
observer._subscription = subscription;
// If the stream is already finished, then perform cleanup
if (!observer._observer)
cancelSubscription(observer);
});
return {
unsubscribe: function() {
if (unsubscribed)
return;
unsubscribed = true;
if (subscription)
subscription.unsubscribe();
}
};
}});
__(_esdown.computed({}, Symbol.observable, { _: function() { return this } }));
__({ forEach: function(fn, thisArg) { var __this = this; if (thisArg === void 0) thisArg = undefined;
return new Promise(function(resolve, reject) {
if (typeof fn !== "function")
throw new TypeError(fn + " is not a function");
__this.subscribe({
next: function(value) { fn.call(thisArg, value) },
throw: function(value) { reject(value) },
return: function(value) { resolve(undefined) },
});
});
},
map: function(fn, thisArg) { var __this = this; if (thisArg === void 0) thisArg = undefined;
if (typeof fn !== "function")
throw new TypeError(fn + " is not a function");
return new this.constructor[Symbol.species](function(sink) { return __this.subscribe({
next: function(value) {
try { value = fn.call(thisArg, value) }
catch (e) { return sink.throw(e) }
return sink.next(value);
},
throw: function(value) { return sink.throw(value) },
return: function(value) { return sink.return(value) },
}); });
},
filter: function(fn, thisArg) { var __this = this; if (thisArg === void 0) thisArg = undefined;
if (typeof fn !== "function")
throw new TypeError(fn + " is not a function");
return new this.constructor[Symbol.species](function(sink) { return __this.subscribe({
next: function(value) {
try { if (!fn.call(thisArg, value)) return { done: false } }
catch (e) { return sink.throw(e) }
return sink.next(value);
},
throw: function(value) { return sink.throw(value) },
return: function(value) { return sink.return(value) },
}); });
}});
__.static({ from: function(x) {
var C = typeof this === "function" ? this : Observable;
if (x == null)
throw new TypeError(x + " is not an object");
var method = x[Symbol.observable];
if (method != null) {
if (typeof method !== "function")
throw new TypeError(method + " is not a function");
var observable$0 = method.call(x);
if (Object(observable$0) !== observable$0)
throw new TypeError(observable$0 + " is not an object");
if (observable$0.constructor === C)
return observable$0;
return new C(function(sink) { return observable$0.subscribe(sink); });
}
method = x[Symbol.iterator];
if (typeof method !== "function")
throw new TypeError(method + " is not a function");
return new C(function(sink) {
for (var __$0 = _esdown.iter(method.call(x)), __$1; __$1 = __$0.next(), !__$1.done;) { var item$1 = __$1.value;
var result$3 = sink.next(item$1);
if (result$3 && result$3.done)
return;
}
sink.return();
});
},
of: function() { for (var items = [], __$0 = 0; __$0 < arguments.length; ++__$0) items.push(arguments[__$0]);
var C = typeof this === "function" ? this : Observable;
return new C(function(sink) {
for (var __$0 = _esdown.iter(items), __$1; __$1 = __$0.next(), !__$1.done;) { var item$2 = __$1.value;
var result$4 = sink.next(item$2);
if (result$4 && result$4.done)
return;
}
sink.return();
});
}});
__.static(_esdown.computed({}, Symbol.species, { get _() { return this } }));
});
if (!_esdown.global.Observable)
_esdown.global.Observable = Observable;
}).call(this);
var _M2 = __load("fs", 1), _M3 = __load("path", 1), _M19 = {}, _M20 = {}, _M21 = {}, _M10 = {}, _M4 = {}, _M5 = {}, _M11 = __load("repl", 1), _M12 = __load("vm", 1), _M13 = __load("util", 1), _M28 = {}, _M24 = {}, _M31 = {}, _M29 = {}, _M30 = {}, _M25 = {}, _M26 = {}, _M27 = {}, _M22 = {}, _M23 = {}, _M18 = {}, _M9 = {}, _M17 = {}, _M16 = {}, _M15 = {}, _M8 = {}, _M14 = {}, _M6 = {}, _M7 = {}, _M1 = exports;
(function(exports) {
var HAS = Object.prototype.hasOwnProperty;
function raise(x) {
x.name = "CommandError";
throw x;
}
function has(obj, name) {
return HAS.call(obj, name);
}
function parse(argv, params) {
if (!params)
return argv.slice(0);
var pos = Object.keys(params),
values = {},
shorts = {},
required = [],
list = [values];
// Create short-to-long mapping
pos.forEach(function(name) {
var p = params[name];
if (p.short)
shorts[p.short] = name;
if (p.required)
required.push(name);
});
// For each command line arg...
for (var i$0 = 0; i$0 < argv.length; ++i$0) {
var a$0 = argv[i$0],
param$0 = null,
value$0 = null,
name$0 = "";
if (a$0[0] === "-") {
if (a$0.slice(0, 2) === "--") {
// Long named parameter
name$0 = a$0.slice(2);
param$0 = has(params, name$0) ? params[name$0] : null;
} else {
// Short named parameter
name$0 = a$0.slice(1);
name$0 = has(shorts, name$0) ? shorts[name$0] : "";
param$0 = has(params, name$0) ? params[name$0] : null;
}
// Verify parameter exists
if (!param$0)
raise(new Error("Invalid command line option: " + a$0));
if (param$0.flag) {
value$0 = true;
} else {
// Get parameter value
value$0 = argv[++i$0] || "";
if (typeof value$0 !== "string" || value$0[0] === "-")
raise(new Error("No value provided for option " + a$0));
}
} else {
// Positional parameter
do {
name$0 = pos.length > 0 ? pos.shift() : "";
param$0 = name$0 ? params[name$0] : null;
} while (param$0 && !param$0.positional);;
value$0 = a$0;
}
if (param$0)
values[name$0] = value$0;
else
list.push(value$0);
}
required.forEach(function(name) {
if (values[name] === void 0)
raise(new Error("Missing required option: --" + name));
});
return list;
}
var ConsoleCommand = _esdown.class(function(__) { var ConsoleCommand;
__({ constructor: ConsoleCommand = function(cmd) {
this.fallback = cmd;
this.commands = {};
},
add: function(name, cmd) {
this.commands[name] = cmd;
return this;
},
run: function(args) {
// Peel off the "node" and main module args
args || (args = process.argv.slice(2));
var name = args[0] || "",
cmd = this.fallback;
if (name && has(this.commands, name)) {
cmd = this.commands[name];
args = args.slice(1);
}
if (!cmd)
raise(new Error("Invalid command"));
return cmd.execute.apply(cmd, parse(args, cmd.params));
}});
});
exports.ConsoleCommand = ConsoleCommand;
}).call(this, _M19);
(function(exports) {
var ConsoleIO = _esdown.class(function(__) { var ConsoleIO;
__({ constructor: ConsoleIO = function() {
this._inStream = process.stdin;
this._outStream = process.stdout;
this._outEnc = "utf8";
this._inEnc = "utf8";
this.inputEncoding = "utf8";
this.outputEncoding = "utf8";
},
get inputEncoding() {
return this._inEnc;
},
set inputEncoding(enc) {
this._inStream.setEncoding(this._inEnc = enc);
},
get outputEncoding() {
return this._outEnc;
},
set outputEncoding(enc) {
this._outStream.setEncoding(this._outEnc = enc);
},
readLine: function() { var __this = this;
return new Promise(function(resolve) {
var listener;
listener = function(data) {
resolve(data);
__this._inStream.removeListener("data", listener);
__this._inStream.pause();
};
__this._inStream.resume();
__this._inStream.on("data", listener);
});
},
writeLine: function(msg) {
console.log(msg);
},
write: function(msg) {
process.stdout.write(msg);
}});
});
exports.ConsoleIO = ConsoleIO;
}).call(this, _M20);
(function(exports) {
var ConsoleStyle = {
green: function(msg) { return "\x1B[32m" + (msg) + "\x1B[39m" },
red: function(msg) { return "\x1B[31m" + (msg) + "\x1B[39m" },
gray: function(msg) { return "\x1B[90m" + (msg) + "\x1B[39m" },
bold: function(msg) { return "\x1B[1m" + (msg) + "\x1B[22m" },
};
exports.ConsoleStyle = ConsoleStyle;
}).call(this, _M21);
(function(exports) {
Object.keys(_M19).forEach(function(k) { exports[k] = _M19[k]; });
Object.keys(_M20).forEach(function(k) { exports[k] = _M20[k]; });
Object.keys(_M21).forEach(function(k) { exports[k] = _M21[k]; });
}).call(this, _M10);
(function(exports) {
Object.keys(_M10).forEach(function(k) { exports[k] = _M10[k]; });
}).call(this, _M4);
(function(exports) {
var FS = _M2;
// Wraps a standard Node async function with a promise
// generating function
function wrap(fn) {
return function() { for (var args = [], __$0 = 0; __$0 < arguments.length; ++__$0) args.push(arguments[__$0]);
return new Promise(function(resolve, reject) {
args.push(function(err, data) {
if (err) reject(err);
else resolve(data);
});
fn.apply(null, args);
});
};
}
function exists(path) {
return new Promise(function(resolve) {
FS.exists(path, function(result) { return resolve(result); });
});
}
var
readFile = wrap(FS.readFile),
close = wrap(FS.close),
open = wrap(FS.open),
read = wrap(FS.read),
write = wrap(FS.write),
rename = wrap(FS.rename),
truncate = wrap(FS.truncate),
rmdir = wrap(FS.rmdir),
fsync = wrap(FS.fsync),
mkdir = wrap(FS.mkdir),
sendfile = wrap(FS.sendfile),
readdir = wrap(FS.readdir),
fstat = wrap(FS.fstat),
lstat = wrap(FS.lstat),
stat = wrap(FS.stat),
readlink = wrap(FS.readlink),
symlink = wrap(FS.symlink),
link = wrap(FS.link),
unlink = wrap(FS.unlink),
fchmod = wrap(FS.fchmod),
lchmod = wrap(FS.lchmod),
chmod = wrap(FS.chmod),
lchown = wrap(FS.lchown),
fchown = wrap(FS.fchown),
chown = wrap(FS.chown),
utimes = wrap(FS.utimes),
futimes = wrap(FS.futimes),
writeFile = wrap(FS.writeFile),
appendFile = wrap(FS.appendFile),
realpath = wrap(FS.realpath)
;
exports.exists = exists;
exports.readFile = readFile;
exports.close = close;
exports.open = open;
exports.read = read;
exports.write = write;
exports.rename = rename;
exports.truncate = truncate;
exports.rmdir = rmdir;
exports.fsync = fsync;
exports.mkdir = mkdir;
exports.sendfile = sendfile;
exports.readdir = readdir;
exports.fstat = fstat;
exports.lstat = lstat;
exports.stat = stat;
exports.readlink = readlink;
exports.symlink = symlink;
exports.link = link;
exports.unlink = unlink;
exports.fchmod = fchmod;
exports.lchmod = lchmod;
exports.chmod = chmod;
exports.lchown = lchown;
exports.fchown = fchown;
exports.chown = chown;
exports.utimes = utimes;
exports.futimes = futimes;
exports.writeFile = writeFile;
exports.appendFile = appendFile;
exports.realpath = realpath;
}).call(this, _M5);
(function(exports) {
function Node(type, start, end) {
this.type = type;
this.start = start;
this.end = end;
}
function Identifier(value, context, start, end) {
this.type = "Identifier";
this.start = start;
this.end = end;
this.value = value;
this.context = context;
}
function AtName(value, start, end) {
this.type = "AtName";
this.start = start;
this.end = end;
this.value = value;
}
function NumberLiteral(value, start, end) {
this.type = "NumberLiteral";
this.start = start;
this.end = end;
this.value = value;
}
function StringLiteral(value, start, end) {
this.type = "StringLiteral";
this.start = start;
this.end = end;
this.value = value;
}
function TemplatePart(value, raw, isEnd, start, end) {
this.type = "TemplatePart";
this.start = start;
this.end = end;
this.value = value;
this.raw = raw;
this.templateEnd = isEnd;
}
function RegularExpression(value, flags, start, end) {
this.type = "RegularExpression";
this.start = start;
this.end = end;
this.value = value;
this.flags = flags;
}
function BooleanLiteral(value, start, end) {
this.type = "BooleanLiteral";
this.start = start;
this.end = end;
this.value = value;
}
function NullLiteral(start, end) {
this.type = "NullLiteral";
this.start = start;
this.end = end;
}
function Script(statements, start, end) {
this.type = "Script";
this.start = start;
this.end = end;
this.statements = statements;
}
function Module(statements, start, end) {
this.type = "Module";
this.start = start;
this.end = end;
this.statements = statements;
}
function ThisExpression(start, end) {
this.type = "ThisExpression";
this.start = start;
this.end = end;
}
function SuperKeyword(start, end) {
this.type = "SuperKeyword";
this.start = start;
this.end = end;
}
function SequenceExpression(list, start, end) {
this.type = "SequenceExpression";
this.start = start;
this.end = end;
this.expressions = list;
}
function AssignmentExpression(op, left, right, start, end) {
this.type = "AssignmentExpression";
this.start = start;
this.end = end;
this.operator = op;
this.left = left;
this.right = right;
}
function SpreadExpression(expr, start, end) {
this.type = "SpreadExpression";
this.start = start;
this.end = end;
this.expression = expr;
}
function YieldExpression(expr, delegate, start, end) {
this.type = "YieldExpression";
this.start = start;
this.end = end;
this.delegate = delegate;
this.expression = expr;
}
function ConditionalExpression(test, cons, alt, start, end) {
this.type = "ConditionalExpression";
this.start = start;
this.end = end;
this.test = test;
this.consequent = cons;
this.alternate = alt;
}
function BinaryExpression(op, left, right, start, end) {
this.type = "BinaryExpression";
this.start = start;
this.end = end;
this.operator = op;
this.left = left;
this.right = right;
}
function UpdateExpression(op, expr, prefix, start, end) {
this.type = "UpdateExpression";
this.start = start;
this.end = end;
this.operator = op;
this.expression = expr;
this.prefix = prefix;
}
function UnaryExpression(op, expr, start, end) {
this.type = "UnaryExpression";
this.start = start;
this.end = end;
this.operator = op;
this.expression = expr;
}
function MemberExpression(obj, prop, computed, start, end) {
this.type = "MemberExpression";
this.start = start;
this.end = end;
this.object = obj;
this.property = prop;
this.computed = computed;
}
function MetaProperty(left, right, start, end) {
this.type = "MetaProperty";
this.start = start;
this.end = end;
this.left = left;
this.right = right;
}
function BindExpression(left, right, start, end) {
this.type = "BindExpression";
this.start = start;
this.end = end;
this.left = left;
this.right = right;
}
function CallExpression(callee, args, start, end) {
this.type = "CallExpression";
this.start = start;
this.end = end;
this.callee = callee;
this.arguments = args;
}
function TaggedTemplateExpression(tag, template, start, end) {
this.type = "TaggedTemplateExpression";
this.start = start;
this.end = end;
this.tag = tag;
this.template = template;
}
function NewExpression(callee, args, start, end) {
this.type = "NewExpression";
this.start = start;
this.end = end;
this.callee = callee;
this.arguments = args;
}
function ParenExpression(expr, start, end) {
this.type = "ParenExpression";
this.start = start;
this.end = end;
this.expression = expr;
}
function ObjectLiteral(props, comma, start, end) {
this.type = "ObjectLiteral";
this.start = start;
this.end = end;
this.properties = props;
this.trailingComma = comma;
}
function ComputedPropertyName(expr, start, end) {
this.type = "ComputedPropertyName";
this.start = start;
this.end = end;
this.expression = expr;
}
function PropertyDefinition(name, expr, start, end) {
this.type = "PropertyDefinition";
this.start = start;
this.end = end;
this.name = name;
this.expression = expr;
}
function ObjectPattern(props, comma, start, end) {
this.type = "ObjectPattern";
this.start = start;
this.end = end;
this.properties = props;
this.trailingComma = comma;
}
function PatternProperty(name, pattern, initializer, start, end) {
this.type = "PatternProperty";
this.start = start;
this.end = end;
this.name = name;
this.pattern = pattern;
this.initializer = initializer;
}
function ArrayPattern(elements, comma, start, end) {
this.type = "ArrayPattern";
this.start = start;
this.end = end;
this.elements = elements;
this.trailingComma = comma;
}
function PatternElement(pattern, initializer, start, end) {
this.type = "PatternElement";
this.start = start;
this.end = end;
this.pattern = pattern;
this.initializer = initializer;
}
function PatternRestElement(pattern, start, end) {
this.type = "PatternRestElement";
this.start = start;
this.end = end;
this.pattern = pattern;
}
function MethodDefinition(isStatic, kind, name, params, body, start, end) {
this.type = "MethodDefinition";
this.start = start;
this.end = end;
this.static = isStatic;
this.kind = kind;
this.name = name;
this.params = params;
this.body = body;
}
function ArrayLiteral(elements, comma, start, end) {
this.type = "ArrayLiteral";
this.start = start;
this.end = end;
this.elements = elements;
this.trailingComma = comma;
}
function TemplateExpression(lits, subs, start, end) {
this.type = "TemplateExpression";
this.start = start;
this.end = end;
this.literals = lits;
this.substitutions = subs;
}
function Block(statements, start, end) {
this.type = "Block";
this.start = start;
this.end = end;
this.statements = statements;
}
function LabelledStatement(label, statement, start, end) {
this.type = "LabelledStatement";
this.start = start;
this.end = end;
this.label = label;
this.statement = statement;
}
function ExpressionStatement(expr, start, end) {
this.type = "ExpressionStatement";
this.start = start;
this.end = end;
this.expression = expr;
}
function Directive(value, expr, start, end) {
this.type = "Directive";
this.start = start;
this.end = end;
this.value = value;
this.expression = expr;
}
function EmptyStatement(start, end) {
this.type = "EmptyStatement";
this.start = start;
this.end = end;
}
function VariableDeclaration(kind, list, start, end) {
this.type = "VariableDeclaration";
this.start = start;
this.end = end;
this.kind = kind;
this.declarations = list;
}
function VariableDeclarator(pattern, initializer, start, end) {
this.type = "VariableDeclarator";
this.start = start;
this.end = end;
this.pattern = pattern;
this.initializer = initializer;
}
function ReturnStatement(arg, start, end) {
this.type = "ReturnStatement";
this.start = start;
this.end = end;
this.argument = arg;
}
function BreakStatement(label, start, end) {
this.type = "BreakStatement";
this.start = start;
this.end = end;
this.label = label;
}
function ContinueStatement(label, start, end) {
this.type = "ContinueStatement";
this.start = start;
this.end = end;
this.label = label;
}
function ThrowStatement(expr, start, end) {
this.type = "ThrowStatement";
this.start = start;
this.end = end;
this.expression = expr;
}
function DebuggerStatement(start, end) {
this.type = "DebuggerStatement";
this.start = start;
this.end = end;
}
function IfStatement(test, cons, alt, start, end) {
this.type = "IfStatement";
this.start = start;
this.end = end;
this.test = test;
this.consequent = cons;
this.alternate = alt;
}
function DoWhileStatement(body, test, start, end) {
this.type = "DoWhileStatement";
this.start = start;
this.end = end;
this.body = body;
this.test = test;
}
function WhileStatement(test, body, start, end) {
this.type = "WhileStatement";
this.start = start;
this.end = end;
this.test = test;
this.body = body;
}
function ForStatement(initializer, test, update, body, start, end) {
this.type = "ForStatement";
this.start = start;
this.end = end;
this.initializer = initializer;
this.test = test;
this.update = update;
this.body = body;
}
function ForInStatement(left, right, body, start, end) {
this.type = "ForInStatement";
this.start = start;
this.end = end;
this.left = left;
this.right = right;
this.body = body;
}
function ForOfStatement(async, left, right, body, start, end) {
this.type = "ForOfStatement";
this.async = async;
this.start = start;
this.end = end;
this.left = left;
this.right = right;
this.body = body;
}
function WithStatement(object, body, start, end) {
this.type = "WithStatement";
this.start = start;
this.end = end;
this.object = object;
this.body = body;
}
function SwitchStatement(desc, cases, start, end) {
this.type = "SwitchStatement";
this.start = start;
this.end = end;
this.descriminant = desc;
this.cases = cases;
}
function SwitchCase(test, cons, start, end) {
this.type = "SwitchCase";
this.start = start;
this.end = end;
this.test = test;
this.consequent = cons;
}
function TryStatement(block, handler, fin, start, end) {
this.type = "TryStatement";
this.start = start;
this.end = end;
this.block = block;
this.handler = handler;
this.finalizer = fin;
}
function CatchClause(param, body, start, end) {
this.type = "CatchClause";
this.start = start;
this.end = end;
this.param = param;
this.body = body;
}
function FunctionDeclaration(kind, identifier, params, body, start, end) {
this.type = "FunctionDeclaration";
this.start = start;
this.end = end;
this.kind = kind;
this.identifier = identifier;
this.params = params;
this.body = body;
}
function FunctionExpression(kind, identifier, params, body, start, end) {
this.type = "FunctionExpression";
this.start = start;
this.end = end;
this.kind = kind;
this.identifier = identifier;
this.params = params;
this.body = body;
}
function FormalParameter(pattern, initializer, start, end) {
this.type = "FormalParameter";
this.start = start;
this.end = end;
this.pattern = pattern;
this.initializer = initializer;
}
function RestParameter(identifier, start, end) {
this.type = "RestParameter";
this.start = start;
this.end = end;
this.identifier = identifier;
}
function FunctionBody(statements, start, end) {
this.type = "FunctionBody";
this.start = start;
this.end = end;
this.statements = statements;
}
function ArrowFunctionHead(params, start, end) {
this.type = "ArrowFunctionHead";
this.start = start;
this.end = end;
this.parameters = params;
}
function ArrowFunction(kind, params, body, start, end) {
this.type = "ArrowFunction";
this.start = start;
this.end = end;
this.kind = kind;
this.params = params;
this.body = body;
}
function ClassDeclaration(identifier, base, body, start, end) {
this.type = "ClassDeclaration";
this.start = start;
this.end = end;
this.identifier = identifier;
this.base = base;
this.body = body;
}
function ClassExpression(identifier, base, body, start, end) {
this.type = "ClassExpression";
this.start = start;
this.end = end;
this.identifier = identifier;
this.base = base;
this.body = body;
}
function ClassBody(elems, start, end) {
this.type = "ClassBody";
this.start = start;
this.end = end;
this.elements = elems;
}
function EmptyClassElement(start, end) {
this.type = "EmptyClassElement";
this.start = start;
this.end = end;
}
function PrivateDeclaration(isStatic, name, initializer, start, end) {
this.type = "PrivateDeclaration";
this.start = start;
this.end = end;
this.static = isStatic;
this.name = name;
this.initializer = initializer;
}
function ImportDeclaration(imports, from, start, end) {
this.type = "ImportDeclaration";
this.start = start;
this.end = end;
this.imports = imports;
this.from = from;
}
function NamespaceImport(identifier, start, end) {
this.type = "NamespaceImport";
this.start = start;
this.end = end;
this.identifier = identifier;
}
function NamedImports(specifiers, start, end) {
this.type = "NamedImports";
this.start = start;
this.end = end;
this.specifiers = specifiers;
}
function DefaultImport(identifier, imports, start, end) {
this.type = "DefaultImport";
this.start = start;
this.end = end;
this.identifier = identifier;
this.imports = imports;
}
function ImportSpecifier(imported, local, start, end) {
this.type = "ImportSpecifier";
this.start = start;
this.end = end;
this.imported = imported;
this.local = local;
}
function ExportDeclaration(declaration, start, end) {
this.type = "ExportDeclaration";
this.start = start;
this.end = end;
this.declaration = declaration;
}
function ExportDefault(binding, start, end) {
this.type = "ExportDefault";
this.binding = binding;
this.start = start;
this.end = end;
}
function ExportNameList(specifiers, from, start, end) {
this.type = "ExportNameList";
this.start = start;
this.end = end;
this.specifiers = specifiers;
this.from = from;
}
function ExportNamespace(identifier, from, start, end) {
this.type = "ExportNamespace";
this.start = start;
this.end = end;
this.identifier = identifier;
this.from = from;
}
function ExportDefaultFrom(identifier, from, start, end) {
this.type = "ExportDefaultFrom";
this.start = start;
this.end = end;
this.identifier = identifier;
this.from = from;
}
function ExportSpecifier(local, exported, start, end) {
this.type = "ExportSpecifier";
this.start = start;
this.end = end;
this.local = local;
this.exported = exported;
}
exports.Node = Node;
exports.Identifier = Identifier;
exports.AtName = AtName;
exports.NumberLiteral = NumberLiteral;
exports.StringLiteral = StringLiteral;
exports.TemplatePart = TemplatePart;
exports.RegularExpression = RegularExpression;
exports.BooleanLiteral = BooleanLiteral;
exports.NullLiteral = NullLiteral;
exports.Script = Script;
exports.Module = Module;
exports.ThisExpression = ThisExpression;
exports.SuperKeyword = SuperKeyword;
exports.SequenceExpression = SequenceExpression;
exports.AssignmentExpression = AssignmentExpression;
exports.SpreadExpression = SpreadExpression;
exports.YieldExpression = YieldExpression;
exports.ConditionalExpression = ConditionalExpression;
exports.BinaryExpression = BinaryExpression;
exports.UpdateExpression = UpdateExpression;
exports.UnaryExpression = UnaryExpression;
exports.MemberExpression = MemberExpression;
exports.MetaProperty = MetaProperty;
exports.BindExpression = BindExpression;
exports.CallExpression = CallExpression;
exports.TaggedTemplateExpression = TaggedTemplateExpression;
exports.NewExpression = NewExpression;
exports.ParenExpression = ParenExpression;
exports.ObjectLiteral = ObjectLiteral;
exports.ComputedPropertyName = ComputedPropertyName;
exports.PropertyDefinition = PropertyDefinition;
exports.ObjectPattern = ObjectPattern;
exports.PatternProperty = PatternProperty;
exports.ArrayPattern = ArrayPattern;
exports.PatternElement = PatternElement;
exports.PatternRestElement = PatternRestElement;
exports.MethodDefinition = MethodDefinition;
exports.ArrayLiteral = ArrayLiteral;
exports.TemplateExpression = TemplateExpression;
exports.Block = Block;
exports.LabelledStatement = LabelledStatement;
exports.ExpressionStatement = ExpressionStatement;
exports.Directive = Directive;
exports.EmptyStatement = EmptyStatement;
exports.VariableDeclaration = VariableDeclaration;
exports.VariableDeclarator = VariableDeclarator;
exports.ReturnStatement = ReturnStatement;
exports.BreakStatement = BreakStatement;
exports.ContinueStatement = ContinueStatement;
exports.ThrowStatement = ThrowStatement;
exports.DebuggerStatement = DebuggerStatement;
exports.IfStatement = IfStatement;
exports.DoWhileStatement = DoWhileStatement;
exports.WhileStatement = WhileStatement;
exports.ForStatement = ForStatement;
exports.ForInStatement = ForInStatement;
exports.ForOfStatement = ForOfStatement;
exports.WithStatement = WithStatement;
exports.SwitchStatement = SwitchStatement;
exports.SwitchCase = SwitchCase;
exports.TryStatement = TryStatement;
exports.CatchClause = CatchClause;
exports.FunctionDeclaration = FunctionDeclaration;
exports.FunctionExpression = FunctionExpression;
exports.FormalParameter = FormalParameter;
exports.RestParameter = RestParameter;
exports.FunctionBody = FunctionBody;
exports.ArrowFunctionHead = ArrowFunctionHead;
exports.ArrowFunction = ArrowFunction;
exports.ClassDeclaration = ClassDeclaration;
exports.ClassExpression = ClassExpression;
exports.ClassBody = ClassBody;
exports.EmptyClassElement = EmptyClassElement;
exports.PrivateDeclaration = PrivateDeclaration;
exports.ImportDeclaration = ImportDeclaration;
exports.NamespaceImport = NamespaceImport;
exports.NamedImports = NamedImports;
exports.DefaultImport = DefaultImport;
exports.ImportSpecifier = ImportSpecifier;
exports.ExportDeclaration = ExportDeclaration;
exports.ExportDefault = ExportDefault;
exports.ExportNameList = ExportNameList;
exports.ExportNamespace = ExportNamespace;
exports.ExportDefaultFrom = ExportDefaultFrom;
exports.ExportSpecifier = ExportSpecifier;
}).call(this, _M28);
(function(exports) {
/*
NOTE: We forego using classes and class-based inheritance because at this time
super() tends to be slow in transpiled code. Instead, we use regular constructor
functions and give them a common prototype property.
*/
var Nodes = _M28;
Object.keys(_M28).forEach(function(k) { exports[k] = _M28[k]; });
function isNode(x) {
return x !== null && typeof x === "object" && typeof x.type === "string";
}
var NodeBase = _esdown.class(function(__) { var NodeBase; __({ constructor: NodeBase = function() {} });
__({ children: function() {
var keys = Object.keys(this),
list = [];
for (var i$0 = 0; i$0 < keys.length; ++i$0) {
if (keys[i$0] === "parent")
break;
var value$0 = this[keys[i$0]];
if (Array.isArray(value$0)) {
for (var j = 0; j < value$0.length; ++j)
if (isNode(value$0[j]))
list.push(value$0[j]);
} else if (isNode(value$0)) {
list.push(value$0);
}
}
return list;
}});
});
Object.keys(Nodes).forEach(function(k) { return Nodes[k].prototype = NodeBase.prototype; });
}).call(this, _M24);
(function(exports) {
// Unicode 6.3.0 | 2013-09-25, 18:58:50 GMT [MD]
var IDENTIFIER = [
36,0,2,
48,9,3,
65,25,2,
95,0,2,
97,25,2,
170,0,2,
181,0,2,
183,0,3,
186,0,2,
192,22,2,
216,30,2,
248,457,2,
710,11,2,
736,4,2,
748,0,2,
750,0,2,
768,111,3,
880,4,2,
886,1,2,
890,3,2,
902,0,2,
903,0,3,
904,2,2,
908,0,2,
910,19,2,
931,82,2,
1015,138,2,
1155,4,3,
1162,157,2,
1329,37,2,
1369,0,2,
1377,38,2,
1425,44,3,
1471,0,3,
1473,1,3,
1476,1,3,
1479,0,3,
1488,26,2,
1520,2,2,
1552,10,3,
1568,42,2,
1611,30,3,
1646,1,2,
1648,0,3,
1649,98,2,
1749,0,2,
1750,6,3,
1759,5,3,
1765,1,2,
1767,1,3,
1770,3,3,
1774,1,2,
1776,9,3,
1786,2,2,
1791,0,2,
1808,0,2,
1809,0,3,
1810,29,2,
1840,26,3,
1869,88,2,
1958,10,3,
1969,0,2,
1984,9,3,
1994,32,2,
2027,8,3,
2036,1,2,
2042,0,2,
2048,21,2,
2070,3,3,
2074,0,2,
2075,8,3,
2084,0,2,
2085,2,3,
2088,0,2,
2089,4,3,
2112,24,2,
2137,2,3,
2208,0,2,
2210,10,2,
2276,26,3,
2304,3,3,
2308,53,2,
2362,2,3,
2365,0,2,
2366,17,3,
2384,0,2,
2385,6,3,
2392,9,2,
2402,1,3,
2406,9,3,
2417,6,2,
2425,6,2,
2433,2,3,
2437,7,2,
2447,1,2,
2451,21,2,
2474,6,2,
2482,0,2,
2486,3,2,
2492,0,3,
2493,0,2,
2494,6,3,
2503,1,3,
2507,2,3,
2510,0