Urara-Blog/node_modules/.pnpm-store/v3/files/b3/dd7bf13cbd48470741f1de6bb7c08e3491097f9d74442a9c5d7e7a32d0e7426f28ab295f42c97c05a25504325a17cf4dc3b993f4b34bcb076f3dd670c2cf8a
2022-08-14 01:14:53 +08:00

48761 lines
1.5 MiB
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.mdsvex = {}));
}(this, (function (exports) { 'use strict';
const defineConfig = (config) => config;
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// resolves . and .. elements in a path array with directory names there
// must be no slashes, empty elements, or device names (c:\) in the array
// (so also no leading and trailing slashes - it does not distinguish
// relative and absolute paths)
function normalizeArray(parts, allowAboveRoot) {
// if the path tries to go above the root, `up` ends up > 0
var up = 0;
for (var i = parts.length - 1; i >= 0; i--) {
var last = parts[i];
if (last === '.') {
parts.splice(i, 1);
} else if (last === '..') {
parts.splice(i, 1);
up++;
} else if (up) {
parts.splice(i, 1);
up--;
}
}
// if the path is allowed to go above the root, restore leading ..s
if (allowAboveRoot) {
for (; up--; up) {
parts.unshift('..');
}
}
return parts;
}
// Split a filename into [root, dir, basename, ext], unix version
// 'root' is just a slash, or nothing.
var splitPathRe =
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
var splitPath = function(filename) {
return splitPathRe.exec(filename).slice(1);
};
// path.resolve([from ...], to)
// posix version
function resolve() {
var resolvedPath = '',
resolvedAbsolute = false;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0) ? arguments[i] : '/';
// Skip empty and invalid entries
if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charAt(0) === '/';
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
return !!p;
}), !resolvedAbsolute).join('/');
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
}
// path.normalize(path)
// posix version
function normalize$2(path) {
var isPathAbsolute = isAbsolute(path),
trailingSlash = substr(path, -1) === '/';
// Normalize the path
path = normalizeArray(filter(path.split('/'), function(p) {
return !!p;
}), !isPathAbsolute).join('/');
if (!path && !isPathAbsolute) {
path = '.';
}
if (path && trailingSlash) {
path += '/';
}
return (isPathAbsolute ? '/' : '') + path;
}
// posix version
function isAbsolute(path) {
return path.charAt(0) === '/';
}
// posix version
function join() {
var paths = Array.prototype.slice.call(arguments, 0);
return normalize$2(filter(paths, function(p, index) {
if (typeof p !== 'string') {
throw new TypeError('Arguments to path.join must be strings');
}
return p;
}).join('/'));
}
// path.relative(from, to)
// posix version
function relative(from, to) {
from = resolve(from).substr(1);
to = resolve(to).substr(1);
function trim(arr) {
var start = 0;
for (; start < arr.length; start++) {
if (arr[start] !== '') break;
}
var end = arr.length - 1;
for (; end >= 0; end--) {
if (arr[end] !== '') break;
}
if (start > end) return [];
return arr.slice(start, end - start + 1);
}
var fromParts = trim(from.split('/'));
var toParts = trim(to.split('/'));
var length = Math.min(fromParts.length, toParts.length);
var samePartsLength = length;
for (var i = 0; i < length; i++) {
if (fromParts[i] !== toParts[i]) {
samePartsLength = i;
break;
}
}
var outputParts = [];
for (var i = samePartsLength; i < fromParts.length; i++) {
outputParts.push('..');
}
outputParts = outputParts.concat(toParts.slice(samePartsLength));
return outputParts.join('/');
}
var sep = '/';
var delimiter = ':';
function dirname(path) {
var result = splitPath(path),
root = result[0],
dir = result[1];
if (!root && !dir) {
// No dirname whatsoever
return '.';
}
if (dir) {
// It has a dirname, strip trailing slash
dir = dir.substr(0, dir.length - 1);
}
return root + dir;
}
function basename(path, ext) {
var f = splitPath(path)[2];
// TODO: make this comparison case-insensitive on windows?
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
}
function extname(path) {
return splitPath(path)[3];
}
var path = {
extname: extname,
basename: basename,
dirname: dirname,
sep: sep,
delimiter: delimiter,
relative: relative,
join: join,
isAbsolute: isAbsolute,
normalize: normalize$2,
resolve: resolve
};
function filter (xs, f) {
if (xs.filter) return xs.filter(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
if (f(xs[i], i, xs)) res.push(xs[i]);
}
return res;
}
// String.prototype.substr - negative index don't work in IE8
var substr = 'ab'.substr(-1) === 'b' ?
function (str, start, len) { return str.substr(start, len) } :
function (str, start, len) {
if (start < 0) start = str.length + start;
return str.substr(start, len);
}
;
var fs = {};
var global$1 = (typeof global !== "undefined" ? global :
typeof self !== "undefined" ? self :
typeof window !== "undefined" ? window : {});
// shim for using process in browser
// based off https://github.com/defunctzombie/node-process/blob/master/browser.js
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
var cachedSetTimeout = defaultSetTimout;
var cachedClearTimeout = defaultClearTimeout;
if (typeof global$1.setTimeout === 'function') {
cachedSetTimeout = setTimeout;
}
if (typeof global$1.clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
}
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
function nextTick(fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
}
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
var title = 'browser';
var platform = 'browser';
var browser = true;
var env = {};
var argv = [];
var version = ''; // empty string to avoid regexp issues
var versions = {};
var release = {};
var config = {};
function noop$1() {}
var on = noop$1;
var addListener = noop$1;
var once = noop$1;
var off = noop$1;
var removeListener = noop$1;
var removeAllListeners = noop$1;
var emit = noop$1;
function binding(name) {
throw new Error('process.binding is not supported');
}
function cwd () { return '/' }
function chdir (dir) {
throw new Error('process.chdir is not supported');
}function umask() { return 0; }
// from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
var performance = global$1.performance || {};
var performanceNow =
performance.now ||
performance.mozNow ||
performance.msNow ||
performance.oNow ||
performance.webkitNow ||
function(){ return (new Date()).getTime() };
// generate timestamp or delta
// see http://nodejs.org/api/process.html#process_process_hrtime
function hrtime(previousTimestamp){
var clocktime = performanceNow.call(performance)*1e-3;
var seconds = Math.floor(clocktime);
var nanoseconds = Math.floor((clocktime%1)*1e9);
if (previousTimestamp) {
seconds = seconds - previousTimestamp[0];
nanoseconds = nanoseconds - previousTimestamp[1];
if (nanoseconds<0) {
seconds--;
nanoseconds += 1e9;
}
}
return [seconds,nanoseconds]
}
var startTime = new Date();
function uptime() {
var currentTime = new Date();
var dif = currentTime - startTime;
return dif / 1000;
}
var process$1 = {
nextTick: nextTick,
title: title,
browser: browser,
env: env,
argv: argv,
version: version,
versions: versions,
on: on,
addListener: addListener,
once: once,
off: off,
removeListener: removeListener,
removeAllListeners: removeAllListeners,
emit: emit,
binding: binding,
cwd: cwd,
chdir: chdir,
umask: umask,
hrtime: hrtime,
platform: platform,
release: release,
config: config,
uptime: uptime
};
var lookup = [];
var revLookup = [];
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
var inited = false;
function init () {
inited = true;
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
for (var i = 0, len = code.length; i < len; ++i) {
lookup[i] = code[i];
revLookup[code.charCodeAt(i)] = i;
}
revLookup['-'.charCodeAt(0)] = 62;
revLookup['_'.charCodeAt(0)] = 63;
}
function toByteArray (b64) {
if (!inited) {
init();
}
var i, j, l, tmp, placeHolders, arr;
var len = b64.length;
if (len % 4 > 0) {
throw new Error('Invalid string. Length must be a multiple of 4')
}
// the number of equal signs (place holders)
// if there are two placeholders, than the two characters before it
// represent one byte
// if there is only one, then the three characters before it represent 2 bytes
// this is just a cheap hack to not do indexOf twice
placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
// base64 is 4/3 + up to two characters of the original data
arr = new Arr(len * 3 / 4 - placeHolders);
// if there are placeholders, only get up to the last complete 4 chars
l = placeHolders > 0 ? len - 4 : len;
var L = 0;
for (i = 0, j = 0; i < l; i += 4, j += 3) {
tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
arr[L++] = (tmp >> 16) & 0xFF;
arr[L++] = (tmp >> 8) & 0xFF;
arr[L++] = tmp & 0xFF;
}
if (placeHolders === 2) {
tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
arr[L++] = tmp & 0xFF;
} else if (placeHolders === 1) {
tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
arr[L++] = (tmp >> 8) & 0xFF;
arr[L++] = tmp & 0xFF;
}
return arr
}
function tripletToBase64 (num) {
return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
}
function encodeChunk (uint8, start, end) {
var tmp;
var output = [];
for (var i = start; i < end; i += 3) {
tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
output.push(tripletToBase64(tmp));
}
return output.join('')
}
function fromByteArray (uint8) {
if (!inited) {
init();
}
var tmp;
var len = uint8.length;
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
var output = '';
var parts = [];
var maxChunkLength = 16383; // must be multiple of 3
// go through the array every three bytes, we'll deal with trailing stuff later
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
}
// pad the end with zeros, but make sure to not forget the extra bytes
if (extraBytes === 1) {
tmp = uint8[len - 1];
output += lookup[tmp >> 2];
output += lookup[(tmp << 4) & 0x3F];
output += '==';
} else if (extraBytes === 2) {
tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
output += lookup[tmp >> 10];
output += lookup[(tmp >> 4) & 0x3F];
output += lookup[(tmp << 2) & 0x3F];
output += '=';
}
parts.push(output);
return parts.join('')
}
function read (buffer, offset, isLE, mLen, nBytes) {
var e, m;
var eLen = nBytes * 8 - mLen - 1;
var eMax = (1 << eLen) - 1;
var eBias = eMax >> 1;
var nBits = -7;
var i = isLE ? (nBytes - 1) : 0;
var d = isLE ? -1 : 1;
var s = buffer[offset + i];
i += d;
e = s & ((1 << (-nBits)) - 1);
s >>= (-nBits);
nBits += eLen;
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
m = e & ((1 << (-nBits)) - 1);
e >>= (-nBits);
nBits += mLen;
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
if (e === 0) {
e = 1 - eBias;
} else if (e === eMax) {
return m ? NaN : ((s ? -1 : 1) * Infinity)
} else {
m = m + Math.pow(2, mLen);
e = e - eBias;
}
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
}
function write (buffer, value, offset, isLE, mLen, nBytes) {
var e, m, c;
var eLen = nBytes * 8 - mLen - 1;
var eMax = (1 << eLen) - 1;
var eBias = eMax >> 1;
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
var i = isLE ? 0 : (nBytes - 1);
var d = isLE ? 1 : -1;
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
value = Math.abs(value);
if (isNaN(value) || value === Infinity) {
m = isNaN(value) ? 1 : 0;
e = eMax;
} else {
e = Math.floor(Math.log(value) / Math.LN2);
if (value * (c = Math.pow(2, -e)) < 1) {
e--;
c *= 2;
}
if (e + eBias >= 1) {
value += rt / c;
} else {
value += rt * Math.pow(2, 1 - eBias);
}
if (value * c >= 2) {
e++;
c /= 2;
}
if (e + eBias >= eMax) {
m = 0;
e = eMax;
} else if (e + eBias >= 1) {
m = (value * c - 1) * Math.pow(2, mLen);
e = e + eBias;
} else {
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
e = 0;
}
}
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
e = (e << mLen) | m;
eLen += mLen;
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
buffer[offset + i - d] |= s * 128;
}
var toString$1 = {}.toString;
var isArray$1 = Array.isArray || function (arr) {
return toString$1.call(arr) == '[object Array]';
};
var INSPECT_MAX_BYTES = 50;
/**
* If `Buffer.TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
* === false Use Object implementation (most compatible, even IE6)
*
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
* Opera 11.6+, iOS 4.2+.
*
* Due to various browser bugs, sometimes the Object implementation will be used even
* when the browser supports typed arrays.
*
* Note:
*
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
*
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
*
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
* incorrect length in some situations.
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
* get the Object implementation, which is slower but behaves correctly.
*/
Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
? global$1.TYPED_ARRAY_SUPPORT
: true;
function kMaxLength () {
return Buffer.TYPED_ARRAY_SUPPORT
? 0x7fffffff
: 0x3fffffff
}
function createBuffer (that, length) {
if (kMaxLength() < length) {
throw new RangeError('Invalid typed array length')
}
if (Buffer.TYPED_ARRAY_SUPPORT) {
// Return an augmented `Uint8Array` instance, for best performance
that = new Uint8Array(length);
that.__proto__ = Buffer.prototype;
} else {
// Fallback: Return an object instance of the Buffer class
if (that === null) {
that = new Buffer(length);
}
that.length = length;
}
return that
}
/**
* The Buffer constructor returns instances of `Uint8Array` that have their
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
* returns a single octet.
*
* The `Uint8Array` prototype remains unmodified.
*/
function Buffer (arg, encodingOrOffset, length) {
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
return new Buffer(arg, encodingOrOffset, length)
}
// Common case.
if (typeof arg === 'number') {
if (typeof encodingOrOffset === 'string') {
throw new Error(
'If encoding is specified then the first argument must be a string'
)
}
return allocUnsafe(this, arg)
}
return from(this, arg, encodingOrOffset, length)
}
Buffer.poolSize = 8192; // not used by this implementation
// TODO: Legacy, not needed anymore. Remove in next major version.
Buffer._augment = function (arr) {
arr.__proto__ = Buffer.prototype;
return arr
};
function from (that, value, encodingOrOffset, length) {
if (typeof value === 'number') {
throw new TypeError('"value" argument must not be a number')
}
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
return fromArrayBuffer(that, value, encodingOrOffset, length)
}
if (typeof value === 'string') {
return fromString(that, value, encodingOrOffset)
}
return fromObject(that, value)
}
/**
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
* if value is a number.
* Buffer.from(str[, encoding])
* Buffer.from(array)
* Buffer.from(buffer)
* Buffer.from(arrayBuffer[, byteOffset[, length]])
**/
Buffer.from = function (value, encodingOrOffset, length) {
return from(null, value, encodingOrOffset, length)
};
if (Buffer.TYPED_ARRAY_SUPPORT) {
Buffer.prototype.__proto__ = Uint8Array.prototype;
Buffer.__proto__ = Uint8Array;
}
function assertSize (size) {
if (typeof size !== 'number') {
throw new TypeError('"size" argument must be a number')
} else if (size < 0) {
throw new RangeError('"size" argument must not be negative')
}
}
function alloc (that, size, fill, encoding) {
assertSize(size);
if (size <= 0) {
return createBuffer(that, size)
}
if (fill !== undefined) {
// Only pay attention to encoding if it's a string. This
// prevents accidentally sending in a number that would
// be interpretted as a start offset.
return typeof encoding === 'string'
? createBuffer(that, size).fill(fill, encoding)
: createBuffer(that, size).fill(fill)
}
return createBuffer(that, size)
}
/**
* Creates a new filled Buffer instance.
* alloc(size[, fill[, encoding]])
**/
Buffer.alloc = function (size, fill, encoding) {
return alloc(null, size, fill, encoding)
};
function allocUnsafe (that, size) {
assertSize(size);
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
if (!Buffer.TYPED_ARRAY_SUPPORT) {
for (var i = 0; i < size; ++i) {
that[i] = 0;
}
}
return that
}
/**
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
* */
Buffer.allocUnsafe = function (size) {
return allocUnsafe(null, size)
};
/**
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
*/
Buffer.allocUnsafeSlow = function (size) {
return allocUnsafe(null, size)
};
function fromString (that, string, encoding) {
if (typeof encoding !== 'string' || encoding === '') {
encoding = 'utf8';
}
if (!Buffer.isEncoding(encoding)) {
throw new TypeError('"encoding" must be a valid string encoding')
}
var length = byteLength(string, encoding) | 0;
that = createBuffer(that, length);
var actual = that.write(string, encoding);
if (actual !== length) {
// Writing a hex string, for example, that contains invalid characters will
// cause everything after the first invalid character to be ignored. (e.g.
// 'abxxcd' will be treated as 'ab')
that = that.slice(0, actual);
}
return that
}
function fromArrayLike (that, array) {
var length = array.length < 0 ? 0 : checked(array.length) | 0;
that = createBuffer(that, length);
for (var i = 0; i < length; i += 1) {
that[i] = array[i] & 255;
}
return that
}
function fromArrayBuffer (that, array, byteOffset, length) {
array.byteLength; // this throws if `array` is not a valid ArrayBuffer
if (byteOffset < 0 || array.byteLength < byteOffset) {
throw new RangeError('\'offset\' is out of bounds')
}
if (array.byteLength < byteOffset + (length || 0)) {
throw new RangeError('\'length\' is out of bounds')
}
if (byteOffset === undefined && length === undefined) {
array = new Uint8Array(array);
} else if (length === undefined) {
array = new Uint8Array(array, byteOffset);
} else {
array = new Uint8Array(array, byteOffset, length);
}
if (Buffer.TYPED_ARRAY_SUPPORT) {
// Return an augmented `Uint8Array` instance, for best performance
that = array;
that.__proto__ = Buffer.prototype;
} else {
// Fallback: Return an object instance of the Buffer class
that = fromArrayLike(that, array);
}
return that
}
function fromObject (that, obj) {
if (internalIsBuffer(obj)) {
var len = checked(obj.length) | 0;
that = createBuffer(that, len);
if (that.length === 0) {
return that
}
obj.copy(that, 0, 0, len);
return that
}
if (obj) {
if ((typeof ArrayBuffer !== 'undefined' &&
obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
if (typeof obj.length !== 'number' || isnan(obj.length)) {
return createBuffer(that, 0)
}
return fromArrayLike(that, obj)
}
if (obj.type === 'Buffer' && isArray$1(obj.data)) {
return fromArrayLike(that, obj.data)
}
}
throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
}
function checked (length) {
// Note: cannot use `length < kMaxLength()` here because that fails when
// length is NaN (which is otherwise coerced to zero.)
if (length >= kMaxLength()) {
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
'size: 0x' + kMaxLength().toString(16) + ' bytes')
}
return length | 0
}
Buffer.isBuffer = isBuffer$1;
function internalIsBuffer (b) {
return !!(b != null && b._isBuffer)
}
Buffer.compare = function compare (a, b) {
if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
throw new TypeError('Arguments must be Buffers')
}
if (a === b) return 0
var x = a.length;
var y = b.length;
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
if (a[i] !== b[i]) {
x = a[i];
y = b[i];
break
}
}
if (x < y) return -1
if (y < x) return 1
return 0
};
Buffer.isEncoding = function isEncoding (encoding) {
switch (String(encoding).toLowerCase()) {
case 'hex':
case 'utf8':
case 'utf-8':
case 'ascii':
case 'latin1':
case 'binary':
case 'base64':
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return true
default:
return false
}
};
Buffer.concat = function concat (list, length) {
if (!isArray$1(list)) {
throw new TypeError('"list" argument must be an Array of Buffers')
}
if (list.length === 0) {
return Buffer.alloc(0)
}
var i;
if (length === undefined) {
length = 0;
for (i = 0; i < list.length; ++i) {
length += list[i].length;
}
}
var buffer = Buffer.allocUnsafe(length);
var pos = 0;
for (i = 0; i < list.length; ++i) {
var buf = list[i];
if (!internalIsBuffer(buf)) {
throw new TypeError('"list" argument must be an Array of Buffers')
}
buf.copy(buffer, pos);
pos += buf.length;
}
return buffer
};
function byteLength (string, encoding) {
if (internalIsBuffer(string)) {
return string.length
}
if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
return string.byteLength
}
if (typeof string !== 'string') {
string = '' + string;
}
var len = string.length;
if (len === 0) return 0
// Use a for loop to avoid recursion
var loweredCase = false;
for (;;) {
switch (encoding) {
case 'ascii':
case 'latin1':
case 'binary':
return len
case 'utf8':
case 'utf-8':
case undefined:
return utf8ToBytes(string).length
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return len * 2
case 'hex':
return len >>> 1
case 'base64':
return base64ToBytes(string).length
default:
if (loweredCase) return utf8ToBytes(string).length // assume utf8
encoding = ('' + encoding).toLowerCase();
loweredCase = true;
}
}
}
Buffer.byteLength = byteLength;
function slowToString (encoding, start, end) {
var loweredCase = false;
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
// property of a typed array.
// This behaves neither like String nor Uint8Array in that we set start/end
// to their upper/lower bounds if the value passed is out of range.
// undefined is handled specially as per ECMA-262 6th Edition,
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
if (start === undefined || start < 0) {
start = 0;
}
// Return early if start > this.length. Done here to prevent potential uint32
// coercion fail below.
if (start > this.length) {
return ''
}
if (end === undefined || end > this.length) {
end = this.length;
}
if (end <= 0) {
return ''
}
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
end >>>= 0;
start >>>= 0;
if (end <= start) {
return ''
}
if (!encoding) encoding = 'utf8';
while (true) {
switch (encoding) {
case 'hex':
return hexSlice(this, start, end)
case 'utf8':
case 'utf-8':
return utf8Slice(this, start, end)
case 'ascii':
return asciiSlice(this, start, end)
case 'latin1':
case 'binary':
return latin1Slice(this, start, end)
case 'base64':
return base64Slice(this, start, end)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return utf16leSlice(this, start, end)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = (encoding + '').toLowerCase();
loweredCase = true;
}
}
}
// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
// Buffer instances.
Buffer.prototype._isBuffer = true;
function swap (b, n, m) {
var i = b[n];
b[n] = b[m];
b[m] = i;
}
Buffer.prototype.swap16 = function swap16 () {
var len = this.length;
if (len % 2 !== 0) {
throw new RangeError('Buffer size must be a multiple of 16-bits')
}
for (var i = 0; i < len; i += 2) {
swap(this, i, i + 1);
}
return this
};
Buffer.prototype.swap32 = function swap32 () {
var len = this.length;
if (len % 4 !== 0) {
throw new RangeError('Buffer size must be a multiple of 32-bits')
}
for (var i = 0; i < len; i += 4) {
swap(this, i, i + 3);
swap(this, i + 1, i + 2);
}
return this
};
Buffer.prototype.swap64 = function swap64 () {
var len = this.length;
if (len % 8 !== 0) {
throw new RangeError('Buffer size must be a multiple of 64-bits')
}
for (var i = 0; i < len; i += 8) {
swap(this, i, i + 7);
swap(this, i + 1, i + 6);
swap(this, i + 2, i + 5);
swap(this, i + 3, i + 4);
}
return this
};
Buffer.prototype.toString = function toString () {
var length = this.length | 0;
if (length === 0) return ''
if (arguments.length === 0) return utf8Slice(this, 0, length)
return slowToString.apply(this, arguments)
};
Buffer.prototype.equals = function equals (b) {
if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
if (this === b) return true
return Buffer.compare(this, b) === 0
};
Buffer.prototype.inspect = function inspect () {
var str = '';
var max = INSPECT_MAX_BYTES;
if (this.length > 0) {
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
if (this.length > max) str += ' ... ';
}
return '<Buffer ' + str + '>'
};
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
if (!internalIsBuffer(target)) {
throw new TypeError('Argument must be a Buffer')
}
if (start === undefined) {
start = 0;
}
if (end === undefined) {
end = target ? target.length : 0;
}
if (thisStart === undefined) {
thisStart = 0;
}
if (thisEnd === undefined) {
thisEnd = this.length;
}
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
throw new RangeError('out of range index')
}
if (thisStart >= thisEnd && start >= end) {
return 0
}
if (thisStart >= thisEnd) {
return -1
}
if (start >= end) {
return 1
}
start >>>= 0;
end >>>= 0;
thisStart >>>= 0;
thisEnd >>>= 0;
if (this === target) return 0
var x = thisEnd - thisStart;
var y = end - start;
var len = Math.min(x, y);
var thisCopy = this.slice(thisStart, thisEnd);
var targetCopy = target.slice(start, end);
for (var i = 0; i < len; ++i) {
if (thisCopy[i] !== targetCopy[i]) {
x = thisCopy[i];
y = targetCopy[i];
break
}
}
if (x < y) return -1
if (y < x) return 1
return 0
};
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
//
// Arguments:
// - buffer - a Buffer to search
// - val - a string, Buffer, or number
// - byteOffset - an index into `buffer`; will be clamped to an int32
// - encoding - an optional encoding, relevant is val is a string
// - dir - true for indexOf, false for lastIndexOf
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
// Empty buffer means no match
if (buffer.length === 0) return -1
// Normalize byteOffset
if (typeof byteOffset === 'string') {
encoding = byteOffset;
byteOffset = 0;
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff;
} else if (byteOffset < -0x80000000) {
byteOffset = -0x80000000;
}
byteOffset = +byteOffset; // Coerce to Number.
if (isNaN(byteOffset)) {
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
byteOffset = dir ? 0 : (buffer.length - 1);
}
// Normalize byteOffset: negative offsets start from the end of the buffer
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
if (byteOffset >= buffer.length) {
if (dir) return -1
else byteOffset = buffer.length - 1;
} else if (byteOffset < 0) {
if (dir) byteOffset = 0;
else return -1
}
// Normalize val
if (typeof val === 'string') {
val = Buffer.from(val, encoding);
}
// Finally, search either indexOf (if dir is true) or lastIndexOf
if (internalIsBuffer(val)) {
// Special case: looking for empty string/buffer always fails
if (val.length === 0) {
return -1
}
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
} else if (typeof val === 'number') {
val = val & 0xFF; // Search for a byte value [0-255]
if (Buffer.TYPED_ARRAY_SUPPORT &&
typeof Uint8Array.prototype.indexOf === 'function') {
if (dir) {
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
} else {
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
}
}
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
}
throw new TypeError('val must be string, number or Buffer')
}
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
var indexSize = 1;
var arrLength = arr.length;
var valLength = val.length;
if (encoding !== undefined) {
encoding = String(encoding).toLowerCase();
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
encoding === 'utf16le' || encoding === 'utf-16le') {
if (arr.length < 2 || val.length < 2) {
return -1
}
indexSize = 2;
arrLength /= 2;
valLength /= 2;
byteOffset /= 2;
}
}
function read (buf, i) {
if (indexSize === 1) {
return buf[i]
} else {
return buf.readUInt16BE(i * indexSize)
}
}
var i;
if (dir) {
var foundIndex = -1;
for (i = byteOffset; i < arrLength; i++) {
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
if (foundIndex === -1) foundIndex = i;
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
} else {
if (foundIndex !== -1) i -= i - foundIndex;
foundIndex = -1;
}
}
} else {
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
for (i = byteOffset; i >= 0; i--) {
var found = true;
for (var j = 0; j < valLength; j++) {
if (read(arr, i + j) !== read(val, j)) {
found = false;
break
}
}
if (found) return i
}
}
return -1
}
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
return this.indexOf(val, byteOffset, encoding) !== -1
};
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
};
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
};
function hexWrite (buf, string, offset, length) {
offset = Number(offset) || 0;
var remaining = buf.length - offset;
if (!length) {
length = remaining;
} else {
length = Number(length);
if (length > remaining) {
length = remaining;
}
}
// must be an even number of digits
var strLen = string.length;
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
if (length > strLen / 2) {
length = strLen / 2;
}
for (var i = 0; i < length; ++i) {
var parsed = parseInt(string.substr(i * 2, 2), 16);
if (isNaN(parsed)) return i
buf[offset + i] = parsed;
}
return i
}
function utf8Write (buf, string, offset, length) {
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
}
function asciiWrite (buf, string, offset, length) {
return blitBuffer(asciiToBytes(string), buf, offset, length)
}
function latin1Write (buf, string, offset, length) {
return asciiWrite(buf, string, offset, length)
}
function base64Write (buf, string, offset, length) {
return blitBuffer(base64ToBytes(string), buf, offset, length)
}
function ucs2Write (buf, string, offset, length) {
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
}
Buffer.prototype.write = function write (string, offset, length, encoding) {
// Buffer#write(string)
if (offset === undefined) {
encoding = 'utf8';
length = this.length;
offset = 0;
// Buffer#write(string, encoding)
} else if (length === undefined && typeof offset === 'string') {
encoding = offset;
length = this.length;
offset = 0;
// Buffer#write(string, offset[, length][, encoding])
} else if (isFinite(offset)) {
offset = offset | 0;
if (isFinite(length)) {
length = length | 0;
if (encoding === undefined) encoding = 'utf8';
} else {
encoding = length;
length = undefined;
}
// legacy write(string, encoding, offset, length) - remove in v0.13
} else {
throw new Error(
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
)
}
var remaining = this.length - offset;
if (length === undefined || length > remaining) length = remaining;
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
throw new RangeError('Attempt to write outside buffer bounds')
}
if (!encoding) encoding = 'utf8';
var loweredCase = false;
for (;;) {
switch (encoding) {
case 'hex':
return hexWrite(this, string, offset, length)
case 'utf8':
case 'utf-8':
return utf8Write(this, string, offset, length)
case 'ascii':
return asciiWrite(this, string, offset, length)
case 'latin1':
case 'binary':
return latin1Write(this, string, offset, length)
case 'base64':
// Warning: maxLength not taken into account in base64Write
return base64Write(this, string, offset, length)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return ucs2Write(this, string, offset, length)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = ('' + encoding).toLowerCase();
loweredCase = true;
}
}
};
Buffer.prototype.toJSON = function toJSON () {
return {
type: 'Buffer',
data: Array.prototype.slice.call(this._arr || this, 0)
}
};
function base64Slice (buf, start, end) {
if (start === 0 && end === buf.length) {
return fromByteArray(buf)
} else {
return fromByteArray(buf.slice(start, end))
}
}
function utf8Slice (buf, start, end) {
end = Math.min(buf.length, end);
var res = [];
var i = start;
while (i < end) {
var firstByte = buf[i];
var codePoint = null;
var bytesPerSequence = (firstByte > 0xEF) ? 4
: (firstByte > 0xDF) ? 3
: (firstByte > 0xBF) ? 2
: 1;
if (i + bytesPerSequence <= end) {
var secondByte, thirdByte, fourthByte, tempCodePoint;
switch (bytesPerSequence) {
case 1:
if (firstByte < 0x80) {
codePoint = firstByte;
}
break
case 2:
secondByte = buf[i + 1];
if ((secondByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
if (tempCodePoint > 0x7F) {
codePoint = tempCodePoint;
}
}
break
case 3:
secondByte = buf[i + 1];
thirdByte = buf[i + 2];
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
codePoint = tempCodePoint;
}
}
break
case 4:
secondByte = buf[i + 1];
thirdByte = buf[i + 2];
fourthByte = buf[i + 3];
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
codePoint = tempCodePoint;
}
}
}
}
if (codePoint === null) {
// we did not generate a valid codePoint so insert a
// replacement char (U+FFFD) and advance only 1 byte
codePoint = 0xFFFD;
bytesPerSequence = 1;
} else if (codePoint > 0xFFFF) {
// encode to utf16 (surrogate pair dance)
codePoint -= 0x10000;
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
codePoint = 0xDC00 | codePoint & 0x3FF;
}
res.push(codePoint);
i += bytesPerSequence;
}
return decodeCodePointsArray(res)
}
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
// the lowest limit is Chrome, with 0x10000 args.
// We go 1 magnitude less, for safety
var MAX_ARGUMENTS_LENGTH = 0x1000;
function decodeCodePointsArray (codePoints) {
var len = codePoints.length;
if (len <= MAX_ARGUMENTS_LENGTH) {
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
}
// Decode in chunks to avoid "call stack size exceeded".
var res = '';
var i = 0;
while (i < len) {
res += String.fromCharCode.apply(
String,
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
);
}
return res
}
function asciiSlice (buf, start, end) {
var ret = '';
end = Math.min(buf.length, end);
for (var i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i] & 0x7F);
}
return ret
}
function latin1Slice (buf, start, end) {
var ret = '';
end = Math.min(buf.length, end);
for (var i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i]);
}
return ret
}
function hexSlice (buf, start, end) {
var len = buf.length;
if (!start || start < 0) start = 0;
if (!end || end < 0 || end > len) end = len;
var out = '';
for (var i = start; i < end; ++i) {
out += toHex(buf[i]);
}
return out
}
function utf16leSlice (buf, start, end) {
var bytes = buf.slice(start, end);
var res = '';
for (var i = 0; i < bytes.length; i += 2) {
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
}
return res
}
Buffer.prototype.slice = function slice (start, end) {
var len = this.length;
start = ~~start;
end = end === undefined ? len : ~~end;
if (start < 0) {
start += len;
if (start < 0) start = 0;
} else if (start > len) {
start = len;
}
if (end < 0) {
end += len;
if (end < 0) end = 0;
} else if (end > len) {
end = len;
}
if (end < start) end = start;
var newBuf;
if (Buffer.TYPED_ARRAY_SUPPORT) {
newBuf = this.subarray(start, end);
newBuf.__proto__ = Buffer.prototype;
} else {
var sliceLen = end - start;
newBuf = new Buffer(sliceLen, undefined);
for (var i = 0; i < sliceLen; ++i) {
newBuf[i] = this[i + start];
}
}
return newBuf
};
/*
* Need to make sure that buffer isn't trying to write out of bounds.
*/
function checkOffset (offset, ext, length) {
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
}
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) checkOffset(offset, byteLength, this.length);
var val = this[offset];
var mul = 1;
var i = 0;
while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul;
}
return val
};
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) {
checkOffset(offset, byteLength, this.length);
}
var val = this[offset + --byteLength];
var mul = 1;
while (byteLength > 0 && (mul *= 0x100)) {
val += this[offset + --byteLength] * mul;
}
return val
};
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
if (!noAssert) checkOffset(offset, 1, this.length);
return this[offset]
};
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length);
return this[offset] | (this[offset + 1] << 8)
};
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length);
return (this[offset] << 8) | this[offset + 1]
};
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return ((this[offset]) |
(this[offset + 1] << 8) |
(this[offset + 2] << 16)) +
(this[offset + 3] * 0x1000000)
};
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return (this[offset] * 0x1000000) +
((this[offset + 1] << 16) |
(this[offset + 2] << 8) |
this[offset + 3])
};
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) checkOffset(offset, byteLength, this.length);
var val = this[offset];
var mul = 1;
var i = 0;
while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul;
}
mul *= 0x80;
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
return val
};
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) checkOffset(offset, byteLength, this.length);
var i = byteLength;
var mul = 1;
var val = this[offset + --i];
while (i > 0 && (mul *= 0x100)) {
val += this[offset + --i] * mul;
}
mul *= 0x80;
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
return val
};
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
if (!noAssert) checkOffset(offset, 1, this.length);
if (!(this[offset] & 0x80)) return (this[offset])
return ((0xff - this[offset] + 1) * -1)
};
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length);
var val = this[offset] | (this[offset + 1] << 8);
return (val & 0x8000) ? val | 0xFFFF0000 : val
};
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length);
var val = this[offset + 1] | (this[offset] << 8);
return (val & 0x8000) ? val | 0xFFFF0000 : val
};
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return (this[offset]) |
(this[offset + 1] << 8) |
(this[offset + 2] << 16) |
(this[offset + 3] << 24)
};
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return (this[offset] << 24) |
(this[offset + 1] << 16) |
(this[offset + 2] << 8) |
(this[offset + 3])
};
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return read(this, offset, true, 23, 4)
};
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length);
return read(this, offset, false, 23, 4)
};
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 8, this.length);
return read(this, offset, true, 52, 8)
};
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 8, this.length);
return read(this, offset, false, 52, 8)
};
function checkInt (buf, value, offset, ext, max, min) {
if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
if (offset + ext > buf.length) throw new RangeError('Index out of range')
}
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
value = +value;
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) {
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
checkInt(this, value, offset, byteLength, maxBytes, 0);
}
var mul = 1;
var i = 0;
this[offset] = value & 0xFF;
while (++i < byteLength && (mul *= 0x100)) {
this[offset + i] = (value / mul) & 0xFF;
}
return offset + byteLength
};
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
value = +value;
offset = offset | 0;
byteLength = byteLength | 0;
if (!noAssert) {
var maxBytes = Math.pow(2, 8 * byteLength) - 1;
checkInt(this, value, offset, byteLength, maxBytes, 0);
}
var i = byteLength - 1;
var mul = 1;
this[offset + i] = value & 0xFF;
while (--i >= 0 && (mul *= 0x100)) {
this[offset + i] = (value / mul) & 0xFF;
}
return offset + byteLength
};
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
this[offset] = (value & 0xff);
return offset + 1
};
function objectWriteUInt16 (buf, value, offset, littleEndian) {
if (value < 0) value = 0xffff + value + 1;
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
(littleEndian ? i : 1 - i) * 8;
}
}
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
} else {
objectWriteUInt16(this, value, offset, true);
}
return offset + 2
};
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
} else {
objectWriteUInt16(this, value, offset, false);
}
return offset + 2
};
function objectWriteUInt32 (buf, value, offset, littleEndian) {
if (value < 0) value = 0xffffffff + value + 1;
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
}
}
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset + 3] = (value >>> 24);
this[offset + 2] = (value >>> 16);
this[offset + 1] = (value >>> 8);
this[offset] = (value & 0xff);
} else {
objectWriteUInt32(this, value, offset, true);
}
return offset + 4
};
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
this[offset + 1] = (value >>> 16);
this[offset + 2] = (value >>> 8);
this[offset + 3] = (value & 0xff);
} else {
objectWriteUInt32(this, value, offset, false);
}
return offset + 4
};
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) {
var limit = Math.pow(2, 8 * byteLength - 1);
checkInt(this, value, offset, byteLength, limit - 1, -limit);
}
var i = 0;
var mul = 1;
var sub = 0;
this[offset] = value & 0xFF;
while (++i < byteLength && (mul *= 0x100)) {
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
sub = 1;
}
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
}
return offset + byteLength
};
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) {
var limit = Math.pow(2, 8 * byteLength - 1);
checkInt(this, value, offset, byteLength, limit - 1, -limit);
}
var i = byteLength - 1;
var mul = 1;
var sub = 0;
this[offset + i] = value & 0xFF;
while (--i >= 0 && (mul *= 0x100)) {
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
sub = 1;
}
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
}
return offset + byteLength
};
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
if (value < 0) value = 0xff + value + 1;
this[offset] = (value & 0xff);
return offset + 1
};
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
} else {
objectWriteUInt16(this, value, offset, true);
}
return offset + 2
};
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8);
this[offset + 1] = (value & 0xff);
} else {
objectWriteUInt16(this, value, offset, false);
}
return offset + 2
};
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff);
this[offset + 1] = (value >>> 8);
this[offset + 2] = (value >>> 16);
this[offset + 3] = (value >>> 24);
} else {
objectWriteUInt32(this, value, offset, true);
}
return offset + 4
};
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value;
offset = offset | 0;
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
if (value < 0) value = 0xffffffff + value + 1;
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24);
this[offset + 1] = (value >>> 16);
this[offset + 2] = (value >>> 8);
this[offset + 3] = (value & 0xff);
} else {
objectWriteUInt32(this, value, offset, false);
}
return offset + 4
};
function checkIEEE754 (buf, value, offset, ext, max, min) {
if (offset + ext > buf.length) throw new RangeError('Index out of range')
if (offset < 0) throw new RangeError('Index out of range')
}
function writeFloat (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
checkIEEE754(buf, value, offset, 4);
}
write(buf, value, offset, littleEndian, 23, 4);
return offset + 4
}
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
return writeFloat(this, value, offset, true, noAssert)
};
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
return writeFloat(this, value, offset, false, noAssert)
};
function writeDouble (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
checkIEEE754(buf, value, offset, 8);
}
write(buf, value, offset, littleEndian, 52, 8);
return offset + 8
}
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
return writeDouble(this, value, offset, true, noAssert)
};
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
return writeDouble(this, value, offset, false, noAssert)
};
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
if (!start) start = 0;
if (!end && end !== 0) end = this.length;
if (targetStart >= target.length) targetStart = target.length;
if (!targetStart) targetStart = 0;
if (end > 0 && end < start) end = start;
// Copy 0 bytes; we're done
if (end === start) return 0
if (target.length === 0 || this.length === 0) return 0
// Fatal error conditions
if (targetStart < 0) {
throw new RangeError('targetStart out of bounds')
}
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
if (end < 0) throw new RangeError('sourceEnd out of bounds')
// Are we oob?
if (end > this.length) end = this.length;
if (target.length - targetStart < end - start) {
end = target.length - targetStart + start;
}
var len = end - start;
var i;
if (this === target && start < targetStart && targetStart < end) {
// descending copy from end
for (i = len - 1; i >= 0; --i) {
target[i + targetStart] = this[i + start];
}
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
// ascending copy from start
for (i = 0; i < len; ++i) {
target[i + targetStart] = this[i + start];
}
} else {
Uint8Array.prototype.set.call(
target,
this.subarray(start, start + len),
targetStart
);
}
return len
};
// Usage:
// buffer.fill(number[, offset[, end]])
// buffer.fill(buffer[, offset[, end]])
// buffer.fill(string[, offset[, end]][, encoding])
Buffer.prototype.fill = function fill (val, start, end, encoding) {
// Handle string cases:
if (typeof val === 'string') {
if (typeof start === 'string') {
encoding = start;
start = 0;
end = this.length;
} else if (typeof end === 'string') {
encoding = end;
end = this.length;
}
if (val.length === 1) {
var code = val.charCodeAt(0);
if (code < 256) {
val = code;
}
}
if (encoding !== undefined && typeof encoding !== 'string') {
throw new TypeError('encoding must be a string')
}
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
throw new TypeError('Unknown encoding: ' + encoding)
}
} else if (typeof val === 'number') {
val = val & 255;
}
// Invalid ranges are not set to a default, so can range check early.
if (start < 0 || this.length < start || this.length < end) {
throw new RangeError('Out of range index')
}
if (end <= start) {
return this
}
start = start >>> 0;
end = end === undefined ? this.length : end >>> 0;
if (!val) val = 0;
var i;
if (typeof val === 'number') {
for (i = start; i < end; ++i) {
this[i] = val;
}
} else {
var bytes = internalIsBuffer(val)
? val
: utf8ToBytes(new Buffer(val, encoding).toString());
var len = bytes.length;
for (i = 0; i < end - start; ++i) {
this[i + start] = bytes[i % len];
}
}
return this
};
// HELPER FUNCTIONS
// ================
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
function base64clean (str) {
// Node strips out invalid characters like \n and \t from the string, base64-js does not
str = stringtrim(str).replace(INVALID_BASE64_RE, '');
// Node converts strings with length < 2 to ''
if (str.length < 2) return ''
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
while (str.length % 4 !== 0) {
str = str + '=';
}
return str
}
function stringtrim (str) {
if (str.trim) return str.trim()
return str.replace(/^\s+|\s+$/g, '')
}
function toHex (n) {
if (n < 16) return '0' + n.toString(16)
return n.toString(16)
}
function utf8ToBytes (string, units) {
units = units || Infinity;
var codePoint;
var length = string.length;
var leadSurrogate = null;
var bytes = [];
for (var i = 0; i < length; ++i) {
codePoint = string.charCodeAt(i);
// is surrogate component
if (codePoint > 0xD7FF && codePoint < 0xE000) {
// last char was a lead
if (!leadSurrogate) {
// no lead yet
if (codePoint > 0xDBFF) {
// unexpected trail
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
continue
} else if (i + 1 === length) {
// unpaired lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
continue
}
// valid lead
leadSurrogate = codePoint;
continue
}
// 2 leads in a row
if (codePoint < 0xDC00) {
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
leadSurrogate = codePoint;
continue
}
// valid surrogate pair
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
} else if (leadSurrogate) {
// valid bmp char, but last char was a lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
}
leadSurrogate = null;
// encode utf8
if (codePoint < 0x80) {
if ((units -= 1) < 0) break
bytes.push(codePoint);
} else if (codePoint < 0x800) {
if ((units -= 2) < 0) break
bytes.push(
codePoint >> 0x6 | 0xC0,
codePoint & 0x3F | 0x80
);
} else if (codePoint < 0x10000) {
if ((units -= 3) < 0) break
bytes.push(
codePoint >> 0xC | 0xE0,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
);
} else if (codePoint < 0x110000) {
if ((units -= 4) < 0) break
bytes.push(
codePoint >> 0x12 | 0xF0,
codePoint >> 0xC & 0x3F | 0x80,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
);
} else {
throw new Error('Invalid code point')
}
}
return bytes
}
function asciiToBytes (str) {
var byteArray = [];
for (var i = 0; i < str.length; ++i) {
// Node's code seems to be doing this and not & 0x7F..
byteArray.push(str.charCodeAt(i) & 0xFF);
}
return byteArray
}
function utf16leToBytes (str, units) {
var c, hi, lo;
var byteArray = [];
for (var i = 0; i < str.length; ++i) {
if ((units -= 2) < 0) break
c = str.charCodeAt(i);
hi = c >> 8;
lo = c % 256;
byteArray.push(lo);
byteArray.push(hi);
}
return byteArray
}
function base64ToBytes (str) {
return toByteArray(base64clean(str))
}
function blitBuffer (src, dst, offset, length) {
for (var i = 0; i < length; ++i) {
if ((i + offset >= dst.length) || (i >= src.length)) break
dst[i + offset] = src[i];
}
return i
}
function isnan (val) {
return val !== val // eslint-disable-line no-self-compare
}
// the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
// The _isBuffer check is for Safari 5-7 support, because it's missing
// Object.prototype.constructor. Remove this eventually
function isBuffer$1(obj) {
return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
}
function isFastBuffer (obj) {
return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
}
// For Node v0.10 support. Remove this eventually.
function isSlowBuffer (obj) {
return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
}
function unwrapExports (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
function getCjsExportFromNamespace (n) {
return n && n['default'] || n;
}
var compiler$1 = createCommonjsModule(function (module, exports) {
(function (global, factory) {
factory(exports) ;
}(commonjsGlobal, (function (exports) {
function assign(tar, src) {
// @ts-ignore
for (const k in src)
tar[k] = src[k];
return tar;
}
const now = (typeof process$1 !== 'undefined' && process$1.hrtime)
? () => {
const t = process$1.hrtime();
return t[0] * 1e3 + t[1] / 1e6;
}
: () => self.performance.now();
function collapse_timings(timings) {
const result = {};
timings.forEach(timing => {
result[timing.label] = Object.assign({
total: timing.end - timing.start
}, timing.children && collapse_timings(timing.children));
});
return result;
}
class Stats {
constructor() {
this.start_time = now();
this.stack = [];
this.current_children = this.timings = [];
}
start(label) {
const timing = {
label,
start: now(),
end: null,
children: []
};
this.current_children.push(timing);
this.stack.push(timing);
this.current_timing = timing;
this.current_children = timing.children;
}
stop(label) {
if (label !== this.current_timing.label) {
throw new Error(`Mismatched timing labels (expected ${this.current_timing.label}, got ${label})`);
}
this.current_timing.end = now();
this.stack.pop();
this.current_timing = this.stack[this.stack.length - 1];
this.current_children = this.current_timing ? this.current_timing.children : this.timings;
}
render() {
const timings = Object.assign({
total: now() - this.start_time
}, collapse_timings(this.timings));
return {
timings
};
}
}
// Reserved word lists for various dialects of the language
var reservedWords = {
3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
5: "class enum extends super const export import",
6: "enum",
strict: "implements interface let package private protected public static yield",
strictBind: "eval arguments"
};
// And the keywords
var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
var keywords = {
5: ecma5AndLessKeywords,
"5module": ecma5AndLessKeywords + " export import",
6: ecma5AndLessKeywords + " const class extends export import super"
};
var keywordRelationalOperator = /^in(stanceof)?$/;
// ## Character categories
// Big ugly regular expressions that match characters in the
// whitespace, identifier, and identifier-start categories. These
// are only applied when a character is found to actually have a
// code point above 128.
// Generated by `bin/generate-identifier-regex.js`.
var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08c7\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
// These are a run-length and offset encoded representation of the
// >0xffff code points that are a valid part of identifiers. The
// offset starts at 0x10000, and each pair of numbers represents an
// offset to the next range, and then a size of the range. They were
// generated by bin/generate-identifier-regex.js
// eslint-disable-next-line comma-spacing
var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,349,41,7,1,79,28,11,0,9,21,107,20,28,22,13,52,76,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,230,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,35,56,264,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,190,0,80,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,689,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,1237,43,8,8952,286,50,2,18,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,2357,44,11,6,17,0,370,43,1301,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42717,35,4148,12,221,3,5761,15,7472,3104,541,1507,4938];
// eslint-disable-next-line comma-spacing
var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,370,1,154,10,176,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,161,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,406,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,19306,9,135,4,60,6,26,9,1014,0,2,54,8,3,82,0,12,1,19628,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,262,6,10,9,419,13,1495,6,110,6,6,9,4759,9,787719,239];
// This has a complexity linear to the value of the code. The
// assumption is that looking up astral identifier characters is
// rare.
function isInAstralSet(code, set) {
var pos = 0x10000;
for (var i = 0; i < set.length; i += 2) {
pos += set[i];
if (pos > code) { return false }
pos += set[i + 1];
if (pos >= code) { return true }
}
}
// Test whether a given character code starts an identifier.
function isIdentifierStart(code, astral) {
if (code < 65) { return code === 36 }
if (code < 91) { return true }
if (code < 97) { return code === 95 }
if (code < 123) { return true }
if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
if (astral === false) { return false }
return isInAstralSet(code, astralIdentifierStartCodes)
}
// Test whether a given character is part of an identifier.
function isIdentifierChar(code, astral) {
if (code < 48) { return code === 36 }
if (code < 58) { return true }
if (code < 65) { return false }
if (code < 91) { return true }
if (code < 97) { return code === 95 }
if (code < 123) { return true }
if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
if (astral === false) { return false }
return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
}
// ## Token types
// The assignment of fine-grained, information-carrying type objects
// allows the tokenizer to store the information it has about a
// token in a way that is very cheap for the parser to look up.
// All token type variables start with an underscore, to make them
// easy to recognize.
// The `beforeExpr` property is used to disambiguate between regular
// expressions and divisions. It is set on all token types that can
// be followed by an expression (thus, a slash after them would be a
// regular expression).
//
// The `startsExpr` property is used to check if the token ends a
// `yield` expression. It is set on all token types that either can
// directly start an expression (like a quotation mark) or can
// continue an expression (like the body of a string).
//
// `isLoop` marks a keyword as starting a loop, which is important
// to know when parsing a label, in order to allow or disallow
// continue jumps to that label.
var TokenType = function TokenType(label, conf) {
if ( conf === void 0 ) conf = {};
this.label = label;
this.keyword = conf.keyword;
this.beforeExpr = !!conf.beforeExpr;
this.startsExpr = !!conf.startsExpr;
this.isLoop = !!conf.isLoop;
this.isAssign = !!conf.isAssign;
this.prefix = !!conf.prefix;
this.postfix = !!conf.postfix;
this.binop = conf.binop || null;
this.updateContext = null;
};
function binop(name, prec) {
return new TokenType(name, {beforeExpr: true, binop: prec})
}
var beforeExpr = {beforeExpr: true}, startsExpr = {startsExpr: true};
// Map keyword names to token types.
var keywords$1 = {};
// Succinct definitions of keyword token types
function kw(name, options) {
if ( options === void 0 ) options = {};
options.keyword = name;
return keywords$1[name] = new TokenType(name, options)
}
var types = {
num: new TokenType("num", startsExpr),
regexp: new TokenType("regexp", startsExpr),
string: new TokenType("string", startsExpr),
name: new TokenType("name", startsExpr),
eof: new TokenType("eof"),
// Punctuation token types.
bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
bracketR: new TokenType("]"),
braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
braceR: new TokenType("}"),
parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
parenR: new TokenType(")"),
comma: new TokenType(",", beforeExpr),
semi: new TokenType(";", beforeExpr),
colon: new TokenType(":", beforeExpr),
dot: new TokenType("."),
question: new TokenType("?", beforeExpr),
questionDot: new TokenType("?."),
arrow: new TokenType("=>", beforeExpr),
template: new TokenType("template"),
invalidTemplate: new TokenType("invalidTemplate"),
ellipsis: new TokenType("...", beforeExpr),
backQuote: new TokenType("`", startsExpr),
dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
// Operators. These carry several kinds of properties to help the
// parser use them properly (the presence of these properties is
// what categorizes them as operators).
//
// `binop`, when present, specifies that this operator is a binary
// operator, and will refer to its precedence.
//
// `prefix` and `postfix` mark the operator as a prefix or postfix
// unary operator.
//
// `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as
// binary operators with a very low precedence, that should result
// in AssignmentExpression nodes.
eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
logicalOR: binop("||", 1),
logicalAND: binop("&&", 2),
bitwiseOR: binop("|", 3),
bitwiseXOR: binop("^", 4),
bitwiseAND: binop("&", 5),
equality: binop("==/!=/===/!==", 6),
relational: binop("</>/<=/>=", 7),
bitShift: binop("<</>>/>>>", 8),
plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
modulo: binop("%", 10),
star: binop("*", 10),
slash: binop("/", 10),
starstar: new TokenType("**", {beforeExpr: true}),
coalesce: binop("??", 1),
// Keyword token types.
_break: kw("break"),
_case: kw("case", beforeExpr),
_catch: kw("catch"),
_continue: kw("continue"),
_debugger: kw("debugger"),
_default: kw("default", beforeExpr),
_do: kw("do", {isLoop: true, beforeExpr: true}),
_else: kw("else", beforeExpr),
_finally: kw("finally"),
_for: kw("for", {isLoop: true}),
_function: kw("function", startsExpr),
_if: kw("if"),
_return: kw("return", beforeExpr),
_switch: kw("switch"),
_throw: kw("throw", beforeExpr),
_try: kw("try"),
_var: kw("var"),
_const: kw("const"),
_while: kw("while", {isLoop: true}),
_with: kw("with"),
_new: kw("new", {beforeExpr: true, startsExpr: true}),
_this: kw("this", startsExpr),
_super: kw("super", startsExpr),
_class: kw("class", startsExpr),
_extends: kw("extends", beforeExpr),
_export: kw("export"),
_import: kw("import", startsExpr),
_null: kw("null", startsExpr),
_true: kw("true", startsExpr),
_false: kw("false", startsExpr),
_in: kw("in", {beforeExpr: true, binop: 7}),
_instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
_typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
_void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
_delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
};
// Matches a whole line break (where CRLF is considered a single
// line break). Used to count lines.
var lineBreak = /\r\n?|\n|\u2028|\u2029/;
var lineBreakG = new RegExp(lineBreak.source, "g");
function isNewLine(code, ecma2019String) {
return code === 10 || code === 13 || (!ecma2019String && (code === 0x2028 || code === 0x2029))
}
var nonASCIIwhitespace = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
var ref = Object.prototype;
var hasOwnProperty = ref.hasOwnProperty;
var toString = ref.toString;
// Checks if an object has a property.
function has(obj, propName) {
return hasOwnProperty.call(obj, propName)
}
var isArray = Array.isArray || (function (obj) { return (
toString.call(obj) === "[object Array]"
); });
function wordsRegexp(words) {
return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
}
// These are used when `options.locations` is on, for the
// `startLoc` and `endLoc` properties.
var Position = function Position(line, col) {
this.line = line;
this.column = col;
};
Position.prototype.offset = function offset (n) {
return new Position(this.line, this.column + n)
};
var SourceLocation = function SourceLocation(p, start, end) {
this.start = start;
this.end = end;
if (p.sourceFile !== null) { this.source = p.sourceFile; }
};
// The `getLineInfo` function is mostly useful when the
// `locations` option is off (for performance reasons) and you
// want to find the line/column position for a given character
// offset. `input` should be the code string that the offset refers
// into.
function getLineInfo(input, offset) {
for (var line = 1, cur = 0;;) {
lineBreakG.lastIndex = cur;
var match = lineBreakG.exec(input);
if (match && match.index < offset) {
++line;
cur = match.index + match[0].length;
} else {
return new Position(line, offset - cur)
}
}
}
// A second optional argument can be given to further configure
// the parser process. These options are recognized:
var defaultOptions = {
// `ecmaVersion` indicates the ECMAScript version to parse. Must be
// either 3, 5, 6 (2015), 7 (2016), 8 (2017), 9 (2018), or 10
// (2019). This influences support for strict mode, the set of
// reserved words, and support for new syntax features. The default
// is 10.
ecmaVersion: 10,
// `sourceType` indicates the mode the code should be parsed in.
// Can be either `"script"` or `"module"`. This influences global
// strict mode and parsing of `import` and `export` declarations.
sourceType: "script",
// `onInsertedSemicolon` can be a callback that will be called
// when a semicolon is automatically inserted. It will be passed
// the position of the comma as an offset, and if `locations` is
// enabled, it is given the location as a `{line, column}` object
// as second argument.
onInsertedSemicolon: null,
// `onTrailingComma` is similar to `onInsertedSemicolon`, but for
// trailing commas.
onTrailingComma: null,
// By default, reserved words are only enforced if ecmaVersion >= 5.
// Set `allowReserved` to a boolean value to explicitly turn this on
// an off. When this option has the value "never", reserved words
// and keywords can also not be used as property names.
allowReserved: null,
// When enabled, a return at the top level is not considered an
// error.
allowReturnOutsideFunction: false,
// When enabled, import/export statements are not constrained to
// appearing at the top of the program.
allowImportExportEverywhere: false,
// When enabled, await identifiers are allowed to appear at the top-level scope,
// but they are still not allowed in non-async functions.
allowAwaitOutsideFunction: false,
// When enabled, hashbang directive in the beginning of file
// is allowed and treated as a line comment.
allowHashBang: false,
// When `locations` is on, `loc` properties holding objects with
// `start` and `end` properties in `{line, column}` form (with
// line being 1-based and column 0-based) will be attached to the
// nodes.
locations: false,
// A function can be passed as `onToken` option, which will
// cause Acorn to call that function with object in the same
// format as tokens returned from `tokenizer().getToken()`. Note
// that you are not allowed to call the parser from the
// callback—that will corrupt its internal state.
onToken: null,
// A function can be passed as `onComment` option, which will
// cause Acorn to call that function with `(block, text, start,
// end)` parameters whenever a comment is skipped. `block` is a
// boolean indicating whether this is a block (`/* */`) comment,
// `text` is the content of the comment, and `start` and `end` are
// character offsets that denote the start and end of the comment.
// When the `locations` option is on, two more parameters are
// passed, the full `{line, column}` locations of the start and
// end of the comments. Note that you are not allowed to call the
// parser from the callback—that will corrupt its internal state.
onComment: null,
// Nodes have their start and end characters offsets recorded in
// `start` and `end` properties (directly on the node, rather than
// the `loc` object, which holds line/column data. To also add a
// [semi-standardized][range] `range` property holding a `[start,
// end]` array with the same numbers, set the `ranges` option to
// `true`.
//
// [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
ranges: false,
// It is possible to parse multiple files into a single AST by
// passing the tree produced by parsing the first file as
// `program` option in subsequent parses. This will add the
// toplevel forms of the parsed file to the `Program` (top) node
// of an existing parse tree.
program: null,
// When `locations` is on, you can pass this to record the source
// file in every node's `loc` object.
sourceFile: null,
// This value, if given, is stored in every node, whether
// `locations` is on or off.
directSourceFile: null,
// When enabled, parenthesized expressions are represented by
// (non-standard) ParenthesizedExpression nodes
preserveParens: false
};
// Interpret and default an options object
function getOptions(opts) {
var options = {};
for (var opt in defaultOptions)
{ options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
if (options.ecmaVersion >= 2015)
{ options.ecmaVersion -= 2009; }
if (options.allowReserved == null)
{ options.allowReserved = options.ecmaVersion < 5; }
if (isArray(options.onToken)) {
var tokens = options.onToken;
options.onToken = function (token) { return tokens.push(token); };
}
if (isArray(options.onComment))
{ options.onComment = pushComment(options, options.onComment); }
return options
}
function pushComment(options, array) {
return function(block, text, start, end, startLoc, endLoc) {
var comment = {
type: block ? "Block" : "Line",
value: text,
start: start,
end: end
};
if (options.locations)
{ comment.loc = new SourceLocation(this, startLoc, endLoc); }
if (options.ranges)
{ comment.range = [start, end]; }
array.push(comment);
}
}
// Each scope gets a bitset that may contain these flags
var
SCOPE_TOP = 1,
SCOPE_FUNCTION = 2,
SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION,
SCOPE_ASYNC = 4,
SCOPE_GENERATOR = 8,
SCOPE_ARROW = 16,
SCOPE_SIMPLE_CATCH = 32,
SCOPE_SUPER = 64,
SCOPE_DIRECT_SUPER = 128;
function functionFlags(async, generator) {
return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0)
}
// Used in checkLVal and declareName to determine the type of a binding
var
BIND_NONE = 0, // Not a binding
BIND_VAR = 1, // Var-style binding
BIND_LEXICAL = 2, // Let- or const-style binding
BIND_FUNCTION = 3, // Function declaration
BIND_SIMPLE_CATCH = 4, // Simple (identifier pattern) catch binding
BIND_OUTSIDE = 5; // Special case for function names as bound inside the function
var Parser = function Parser(options, input, startPos) {
this.options = options = getOptions(options);
this.sourceFile = options.sourceFile;
this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5]);
var reserved = "";
if (options.allowReserved !== true) {
for (var v = options.ecmaVersion;; v--)
{ if (reserved = reservedWords[v]) { break } }
if (options.sourceType === "module") { reserved += " await"; }
}
this.reservedWords = wordsRegexp(reserved);
var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
this.reservedWordsStrict = wordsRegexp(reservedStrict);
this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
this.input = String(input);
// Used to signal to callers of `readWord1` whether the word
// contained any escape sequences. This is needed because words with
// escape sequences must not be interpreted as keywords.
this.containsEsc = false;
// Set up token state
// The current position of the tokenizer in the input.
if (startPos) {
this.pos = startPos;
this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
} else {
this.pos = this.lineStart = 0;
this.curLine = 1;
}
// Properties of the current token:
// Its type
this.type = types.eof;
// For tokens that include more information than their type, the value
this.value = null;
// Its start and end offset
this.start = this.end = this.pos;
// And, if locations are used, the {line, column} object
// corresponding to those offsets
this.startLoc = this.endLoc = this.curPosition();
// Position information for the previous token
this.lastTokEndLoc = this.lastTokStartLoc = null;
this.lastTokStart = this.lastTokEnd = this.pos;
// The context stack is used to superficially track syntactic
// context to predict whether a regular expression is allowed in a
// given position.
this.context = this.initialContext();
this.exprAllowed = true;
// Figure out if it's a module code.
this.inModule = options.sourceType === "module";
this.strict = this.inModule || this.strictDirective(this.pos);
// Used to signify the start of a potential arrow function
this.potentialArrowAt = -1;
// Positions to delayed-check that yield/await does not exist in default parameters.
this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
// Labels in scope.
this.labels = [];
// Thus-far undefined exports.
this.undefinedExports = {};
// If enabled, skip leading hashbang line.
if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
{ this.skipLineComment(2); }
// Scope tracking for duplicate variable names (see scope.js)
this.scopeStack = [];
this.enterScope(SCOPE_TOP);
// For RegExp validation
this.regexpState = null;
};
var prototypeAccessors = { inFunction: { configurable: true },inGenerator: { configurable: true },inAsync: { configurable: true },allowSuper: { configurable: true },allowDirectSuper: { configurable: true },treatFunctionsAsVar: { configurable: true } };
Parser.prototype.parse = function parse () {
var node = this.options.program || this.startNode();
this.nextToken();
return this.parseTopLevel(node)
};
prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 };
prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 };
prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 };
prototypeAccessors.allowSuper.get = function () { return (this.currentThisScope().flags & SCOPE_SUPER) > 0 };
prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 };
prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) };
// Switch to a getter for 7.0.0.
Parser.prototype.inNonArrowFunction = function inNonArrowFunction () { return (this.currentThisScope().flags & SCOPE_FUNCTION) > 0 };
Parser.extend = function extend () {
var plugins = [], len = arguments.length;
while ( len-- ) plugins[ len ] = arguments[ len ];
var cls = this;
for (var i = 0; i < plugins.length; i++) { cls = plugins[i](cls); }
return cls
};
Parser.parse = function parse (input, options) {
return new this(options, input).parse()
};
Parser.parseExpressionAt = function parseExpressionAt (input, pos, options) {
var parser = new this(options, input, pos);
parser.nextToken();
return parser.parseExpression()
};
Parser.tokenizer = function tokenizer (input, options) {
return new this(options, input)
};
Object.defineProperties( Parser.prototype, prototypeAccessors );
var pp = Parser.prototype;
// ## Parser utilities
var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)")/;
pp.strictDirective = function(start) {
for (;;) {
// Try to find string literal.
skipWhiteSpace.lastIndex = start;
start += skipWhiteSpace.exec(this.input)[0].length;
var match = literal.exec(this.input.slice(start));
if (!match) { return false }
if ((match[1] || match[2]) === "use strict") {
skipWhiteSpace.lastIndex = start + match[0].length;
var spaceAfter = skipWhiteSpace.exec(this.input), end = spaceAfter.index + spaceAfter[0].length;
var next = this.input.charAt(end);
return next === ";" || next === "}" ||
(lineBreak.test(spaceAfter[0]) &&
!(/[(`.[+\-/*%<>=,?^&]/.test(next) || next === "!" && this.input.charAt(end + 1) === "="))
}
start += match[0].length;
// Skip semicolon, if any.
skipWhiteSpace.lastIndex = start;
start += skipWhiteSpace.exec(this.input)[0].length;
if (this.input[start] === ";")
{ start++; }
}
};
// Predicate that tests whether the next token is of the given
// type, and if yes, consumes it as a side effect.
pp.eat = function(type) {
if (this.type === type) {
this.next();
return true
} else {
return false
}
};
// Tests whether parsed token is a contextual keyword.
pp.isContextual = function(name) {
return this.type === types.name && this.value === name && !this.containsEsc
};
// Consumes contextual keyword if possible.
pp.eatContextual = function(name) {
if (!this.isContextual(name)) { return false }
this.next();
return true
};
// Asserts that following token is given contextual keyword.
pp.expectContextual = function(name) {
if (!this.eatContextual(name)) { this.unexpected(); }
};
// Test whether a semicolon can be inserted at the current position.
pp.canInsertSemicolon = function() {
return this.type === types.eof ||
this.type === types.braceR ||
lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
};
pp.insertSemicolon = function() {
if (this.canInsertSemicolon()) {
if (this.options.onInsertedSemicolon)
{ this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
return true
}
};
// Consume a semicolon, or, failing that, see if we are allowed to
// pretend that there is a semicolon at this position.
pp.semicolon = function() {
if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
};
pp.afterTrailingComma = function(tokType, notNext) {
if (this.type === tokType) {
if (this.options.onTrailingComma)
{ this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
if (!notNext)
{ this.next(); }
return true
}
};
// Expect a token of a given type. If found, consume it, otherwise,
// raise an unexpected token error.
pp.expect = function(type) {
this.eat(type) || this.unexpected();
};
// Raise an unexpected token error.
pp.unexpected = function(pos) {
this.raise(pos != null ? pos : this.start, "Unexpected token");
};
function DestructuringErrors() {
this.shorthandAssign =
this.trailingComma =
this.parenthesizedAssign =
this.parenthesizedBind =
this.doubleProto =
-1;
}
pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
if (!refDestructuringErrors) { return }
if (refDestructuringErrors.trailingComma > -1)
{ this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
};
pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
if (!refDestructuringErrors) { return false }
var shorthandAssign = refDestructuringErrors.shorthandAssign;
var doubleProto = refDestructuringErrors.doubleProto;
if (!andThrow) { return shorthandAssign >= 0 || doubleProto >= 0 }
if (shorthandAssign >= 0)
{ this.raise(shorthandAssign, "Shorthand property assignments are valid only in destructuring patterns"); }
if (doubleProto >= 0)
{ this.raiseRecoverable(doubleProto, "Redefinition of __proto__ property"); }
};
pp.checkYieldAwaitInDefaultParams = function() {
if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
{ this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
if (this.awaitPos)
{ this.raise(this.awaitPos, "Await expression cannot be a default value"); }
};
pp.isSimpleAssignTarget = function(expr) {
if (expr.type === "ParenthesizedExpression")
{ return this.isSimpleAssignTarget(expr.expression) }
return expr.type === "Identifier" || expr.type === "MemberExpression"
};
var pp$1 = Parser.prototype;
// ### Statement parsing
// Parse a program. Initializes the parser, reads any number of
// statements, and wraps them in a Program node. Optionally takes a
// `program` argument. If present, the statements will be appended
// to its body instead of creating a new node.
pp$1.parseTopLevel = function(node) {
var exports = {};
if (!node.body) { node.body = []; }
while (this.type !== types.eof) {
var stmt = this.parseStatement(null, true, exports);
node.body.push(stmt);
}
if (this.inModule)
{ for (var i = 0, list = Object.keys(this.undefinedExports); i < list.length; i += 1)
{
var name = list[i];
this.raiseRecoverable(this.undefinedExports[name].start, ("Export '" + name + "' is not defined"));
} }
this.adaptDirectivePrologue(node.body);
this.next();
node.sourceType = this.options.sourceType;
return this.finishNode(node, "Program")
};
var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"};
pp$1.isLet = function(context) {
if (this.options.ecmaVersion < 6 || !this.isContextual("let")) { return false }
skipWhiteSpace.lastIndex = this.pos;
var skip = skipWhiteSpace.exec(this.input);
var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
// For ambiguous cases, determine if a LexicalDeclaration (or only a
// Statement) is allowed here. If context is not empty then only a Statement
// is allowed. However, `let [` is an explicit negative lookahead for
// ExpressionStatement, so special-case it first.
if (nextCh === 91) { return true } // '['
if (context) { return false }
if (nextCh === 123) { return true } // '{'
if (isIdentifierStart(nextCh, true)) {
var pos = next + 1;
while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
var ident = this.input.slice(next, pos);
if (!keywordRelationalOperator.test(ident)) { return true }
}
return false
};
// check 'async [no LineTerminator here] function'
// - 'async /*foo*/ function' is OK.
// - 'async /*\n*/ function' is invalid.
pp$1.isAsyncFunction = function() {
if (this.options.ecmaVersion < 8 || !this.isContextual("async"))
{ return false }
skipWhiteSpace.lastIndex = this.pos;
var skip = skipWhiteSpace.exec(this.input);
var next = this.pos + skip[0].length;
return !lineBreak.test(this.input.slice(this.pos, next)) &&
this.input.slice(next, next + 8) === "function" &&
(next + 8 === this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
};
// Parse a single statement.
//
// If expecting a statement and finding a slash operator, parse a
// regular expression literal. This is to handle cases like
// `if (foo) /blah/.exec(foo)`, where looking at the previous token
// does not help.
pp$1.parseStatement = function(context, topLevel, exports) {
var starttype = this.type, node = this.startNode(), kind;
if (this.isLet(context)) {
starttype = types._var;
kind = "let";
}
// Most types of statements are recognized by the keyword they
// start with. Many are trivial to parse, some require a bit of
// complexity.
switch (starttype) {
case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
case types._debugger: return this.parseDebuggerStatement(node)
case types._do: return this.parseDoStatement(node)
case types._for: return this.parseForStatement(node)
case types._function:
// Function as sole body of either an if statement or a labeled statement
// works, but not when it is part of a labeled statement that is the sole
// body of an if statement.
if ((context && (this.strict || context !== "if" && context !== "label")) && this.options.ecmaVersion >= 6) { this.unexpected(); }
return this.parseFunctionStatement(node, false, !context)
case types._class:
if (context) { this.unexpected(); }
return this.parseClass(node, true)
case types._if: return this.parseIfStatement(node)
case types._return: return this.parseReturnStatement(node)
case types._switch: return this.parseSwitchStatement(node)
case types._throw: return this.parseThrowStatement(node)
case types._try: return this.parseTryStatement(node)
case types._const: case types._var:
kind = kind || this.value;
if (context && kind !== "var") { this.unexpected(); }
return this.parseVarStatement(node, kind)
case types._while: return this.parseWhileStatement(node)
case types._with: return this.parseWithStatement(node)
case types.braceL: return this.parseBlock(true, node)
case types.semi: return this.parseEmptyStatement(node)
case types._export:
case types._import:
if (this.options.ecmaVersion > 10 && starttype === types._import) {
skipWhiteSpace.lastIndex = this.pos;
var skip = skipWhiteSpace.exec(this.input);
var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
if (nextCh === 40 || nextCh === 46) // '(' or '.'
{ return this.parseExpressionStatement(node, this.parseExpression()) }
}
if (!this.options.allowImportExportEverywhere) {
if (!topLevel)
{ this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
if (!this.inModule)
{ this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
}
return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
// If the statement does not start with a statement keyword or a
// brace, it's an ExpressionStatement or LabeledStatement. We
// simply start parsing an expression, and afterwards, if the
// next token is a colon and the expression was a simple
// Identifier node, we switch to interpreting it as a label.
default:
if (this.isAsyncFunction()) {
if (context) { this.unexpected(); }
this.next();
return this.parseFunctionStatement(node, true, !context)
}
var maybeName = this.value, expr = this.parseExpression();
if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
{ return this.parseLabeledStatement(node, maybeName, expr, context) }
else { return this.parseExpressionStatement(node, expr) }
}
};
pp$1.parseBreakContinueStatement = function(node, keyword) {
var isBreak = keyword === "break";
this.next();
if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
else if (this.type !== types.name) { this.unexpected(); }
else {
node.label = this.parseIdent();
this.semicolon();
}
// Verify that there is an actual destination to break or
// continue to.
var i = 0;
for (; i < this.labels.length; ++i) {
var lab = this.labels[i];
if (node.label == null || lab.name === node.label.name) {
if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
if (node.label && isBreak) { break }
}
}
if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
};
pp$1.parseDebuggerStatement = function(node) {
this.next();
this.semicolon();
return this.finishNode(node, "DebuggerStatement")
};
pp$1.parseDoStatement = function(node) {
this.next();
this.labels.push(loopLabel);
node.body = this.parseStatement("do");
this.labels.pop();
this.expect(types._while);
node.test = this.parseParenExpression();
if (this.options.ecmaVersion >= 6)
{ this.eat(types.semi); }
else
{ this.semicolon(); }
return this.finishNode(node, "DoWhileStatement")
};
// Disambiguating between a `for` and a `for`/`in` or `for`/`of`
// loop is non-trivial. Basically, we have to parse the init `var`
// statement or expression, disallowing the `in` operator (see
// the second parameter to `parseExpression`), and then check
// whether the next token is `in` or `of`. When there is no init
// part (semicolon immediately after the opening parenthesis), it
// is a regular `for` loop.
pp$1.parseForStatement = function(node) {
this.next();
var awaitAt = (this.options.ecmaVersion >= 9 && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction)) && this.eatContextual("await")) ? this.lastTokStart : -1;
this.labels.push(loopLabel);
this.enterScope(0);
this.expect(types.parenL);
if (this.type === types.semi) {
if (awaitAt > -1) { this.unexpected(awaitAt); }
return this.parseFor(node, null)
}
var isLet = this.isLet();
if (this.type === types._var || this.type === types._const || isLet) {
var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
this.next();
this.parseVar(init$1, true, kind);
this.finishNode(init$1, "VariableDeclaration");
if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1) {
if (this.options.ecmaVersion >= 9) {
if (this.type === types._in) {
if (awaitAt > -1) { this.unexpected(awaitAt); }
} else { node.await = awaitAt > -1; }
}
return this.parseForIn(node, init$1)
}
if (awaitAt > -1) { this.unexpected(awaitAt); }
return this.parseFor(node, init$1)
}
var refDestructuringErrors = new DestructuringErrors;
var init = this.parseExpression(true, refDestructuringErrors);
if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
if (this.options.ecmaVersion >= 9) {
if (this.type === types._in) {
if (awaitAt > -1) { this.unexpected(awaitAt); }
} else { node.await = awaitAt > -1; }
}
this.toAssignable(init, false, refDestructuringErrors);
this.checkLVal(init);
return this.parseForIn(node, init)
} else {
this.checkExpressionErrors(refDestructuringErrors, true);
}
if (awaitAt > -1) { this.unexpected(awaitAt); }
return this.parseFor(node, init)
};
pp$1.parseFunctionStatement = function(node, isAsync, declarationPosition) {
this.next();
return this.parseFunction(node, FUNC_STATEMENT | (declarationPosition ? 0 : FUNC_HANGING_STATEMENT), false, isAsync)
};
pp$1.parseIfStatement = function(node) {
this.next();
node.test = this.parseParenExpression();
// allow function declarations in branches, but only in non-strict mode
node.consequent = this.parseStatement("if");
node.alternate = this.eat(types._else) ? this.parseStatement("if") : null;
return this.finishNode(node, "IfStatement")
};
pp$1.parseReturnStatement = function(node) {
if (!this.inFunction && !this.options.allowReturnOutsideFunction)
{ this.raise(this.start, "'return' outside of function"); }
this.next();
// In `return` (and `break`/`continue`), the keywords with
// optional arguments, we eagerly look for a semicolon or the
// possibility to insert one.
if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
else { node.argument = this.parseExpression(); this.semicolon(); }
return this.finishNode(node, "ReturnStatement")
};
pp$1.parseSwitchStatement = function(node) {
this.next();
node.discriminant = this.parseParenExpression();
node.cases = [];
this.expect(types.braceL);
this.labels.push(switchLabel);
this.enterScope(0);
// Statements under must be grouped (by label) in SwitchCase
// nodes. `cur` is used to keep the node that we are currently
// adding statements to.
var cur;
for (var sawDefault = false; this.type !== types.braceR;) {
if (this.type === types._case || this.type === types._default) {
var isCase = this.type === types._case;
if (cur) { this.finishNode(cur, "SwitchCase"); }
node.cases.push(cur = this.startNode());
cur.consequent = [];
this.next();
if (isCase) {
cur.test = this.parseExpression();
} else {
if (sawDefault) { this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"); }
sawDefault = true;
cur.test = null;
}
this.expect(types.colon);
} else {
if (!cur) { this.unexpected(); }
cur.consequent.push(this.parseStatement(null));
}
}
this.exitScope();
if (cur) { this.finishNode(cur, "SwitchCase"); }
this.next(); // Closing brace
this.labels.pop();
return this.finishNode(node, "SwitchStatement")
};
pp$1.parseThrowStatement = function(node) {
this.next();
if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
{ this.raise(this.lastTokEnd, "Illegal newline after throw"); }
node.argument = this.parseExpression();
this.semicolon();
return this.finishNode(node, "ThrowStatement")
};
// Reused empty array added for node fields that are always empty.
var empty = [];
pp$1.parseTryStatement = function(node) {
this.next();
node.block = this.parseBlock();
node.handler = null;
if (this.type === types._catch) {
var clause = this.startNode();
this.next();
if (this.eat(types.parenL)) {
clause.param = this.parseBindingAtom();
var simple = clause.param.type === "Identifier";
this.enterScope(simple ? SCOPE_SIMPLE_CATCH : 0);
this.checkLVal(clause.param, simple ? BIND_SIMPLE_CATCH : BIND_LEXICAL);
this.expect(types.parenR);
} else {
if (this.options.ecmaVersion < 10) { this.unexpected(); }
clause.param = null;
this.enterScope(0);
}
clause.body = this.parseBlock(false);
this.exitScope();
node.handler = this.finishNode(clause, "CatchClause");
}
node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
if (!node.handler && !node.finalizer)
{ this.raise(node.start, "Missing catch or finally clause"); }
return this.finishNode(node, "TryStatement")
};
pp$1.parseVarStatement = function(node, kind) {
this.next();
this.parseVar(node, false, kind);
this.semicolon();
return this.finishNode(node, "VariableDeclaration")
};
pp$1.parseWhileStatement = function(node) {
this.next();
node.test = this.parseParenExpression();
this.labels.push(loopLabel);
node.body = this.parseStatement("while");
this.labels.pop();
return this.finishNode(node, "WhileStatement")
};
pp$1.parseWithStatement = function(node) {
if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
this.next();
node.object = this.parseParenExpression();
node.body = this.parseStatement("with");
return this.finishNode(node, "WithStatement")
};
pp$1.parseEmptyStatement = function(node) {
this.next();
return this.finishNode(node, "EmptyStatement")
};
pp$1.parseLabeledStatement = function(node, maybeName, expr, context) {
for (var i$1 = 0, list = this.labels; i$1 < list.length; i$1 += 1)
{
var label = list[i$1];
if (label.name === maybeName)
{ this.raise(expr.start, "Label '" + maybeName + "' is already declared");
} }
var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
for (var i = this.labels.length - 1; i >= 0; i--) {
var label$1 = this.labels[i];
if (label$1.statementStart === node.start) {
// Update information about previous labels on this node
label$1.statementStart = this.start;
label$1.kind = kind;
} else { break }
}
this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
node.body = this.parseStatement(context ? context.indexOf("label") === -1 ? context + "label" : context : "label");
this.labels.pop();
node.label = expr;
return this.finishNode(node, "LabeledStatement")
};
pp$1.parseExpressionStatement = function(node, expr) {
node.expression = expr;
this.semicolon();
return this.finishNode(node, "ExpressionStatement")
};
// Parse a semicolon-enclosed block of statements, handling `"use
// strict"` declarations when `allowStrict` is true (used for
// function bodies).
pp$1.parseBlock = function(createNewLexicalScope, node, exitStrict) {
if ( createNewLexicalScope === void 0 ) createNewLexicalScope = true;
if ( node === void 0 ) node = this.startNode();
node.body = [];
this.expect(types.braceL);
if (createNewLexicalScope) { this.enterScope(0); }
while (this.type !== types.braceR) {
var stmt = this.parseStatement(null);
node.body.push(stmt);
}
if (exitStrict) { this.strict = false; }
this.next();
if (createNewLexicalScope) { this.exitScope(); }
return this.finishNode(node, "BlockStatement")
};
// Parse a regular `for` loop. The disambiguation code in
// `parseStatement` will already have parsed the init statement or
// expression.
pp$1.parseFor = function(node, init) {
node.init = init;
this.expect(types.semi);
node.test = this.type === types.semi ? null : this.parseExpression();
this.expect(types.semi);
node.update = this.type === types.parenR ? null : this.parseExpression();
this.expect(types.parenR);
node.body = this.parseStatement("for");
this.exitScope();
this.labels.pop();
return this.finishNode(node, "ForStatement")
};
// Parse a `for`/`in` and `for`/`of` loop, which are almost
// same from parser's perspective.
pp$1.parseForIn = function(node, init) {
var isForIn = this.type === types._in;
this.next();
if (
init.type === "VariableDeclaration" &&
init.declarations[0].init != null &&
(
!isForIn ||
this.options.ecmaVersion < 8 ||
this.strict ||
init.kind !== "var" ||
init.declarations[0].id.type !== "Identifier"
)
) {
this.raise(
init.start,
((isForIn ? "for-in" : "for-of") + " loop variable declaration may not have an initializer")
);
} else if (init.type === "AssignmentPattern") {
this.raise(init.start, "Invalid left-hand side in for-loop");
}
node.left = init;
node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
this.expect(types.parenR);
node.body = this.parseStatement("for");
this.exitScope();
this.labels.pop();
return this.finishNode(node, isForIn ? "ForInStatement" : "ForOfStatement")
};
// Parse a list of variable declarations.
pp$1.parseVar = function(node, isFor, kind) {
node.declarations = [];
node.kind = kind;
for (;;) {
var decl = this.startNode();
this.parseVarId(decl, kind);
if (this.eat(types.eq)) {
decl.init = this.parseMaybeAssign(isFor);
} else if (kind === "const" && !(this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of")))) {
this.unexpected();
} else if (decl.id.type !== "Identifier" && !(isFor && (this.type === types._in || this.isContextual("of")))) {
this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value");
} else {
decl.init = null;
}
node.declarations.push(this.finishNode(decl, "VariableDeclarator"));
if (!this.eat(types.comma)) { break }
}
return node
};
pp$1.parseVarId = function(decl, kind) {
decl.id = this.parseBindingAtom();
this.checkLVal(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
};
var FUNC_STATEMENT = 1, FUNC_HANGING_STATEMENT = 2, FUNC_NULLABLE_ID = 4;
// Parse a function declaration or literal (depending on the
// `statement & FUNC_STATEMENT`).
// Remove `allowExpressionBody` for 7.0.0, as it is only called with false
pp$1.parseFunction = function(node, statement, allowExpressionBody, isAsync) {
this.initFunction(node);
if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
if (this.type === types.star && (statement & FUNC_HANGING_STATEMENT))
{ this.unexpected(); }
node.generator = this.eat(types.star);
}
if (this.options.ecmaVersion >= 8)
{ node.async = !!isAsync; }
if (statement & FUNC_STATEMENT) {
node.id = (statement & FUNC_NULLABLE_ID) && this.type !== types.name ? null : this.parseIdent();
if (node.id && !(statement & FUNC_HANGING_STATEMENT))
// If it is a regular function declaration in sloppy mode, then it is
// subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding
// mode depends on properties of the current scope (see
// treatFunctionsAsVar).
{ this.checkLVal(node.id, (this.strict || node.generator || node.async) ? this.treatFunctionsAsVar ? BIND_VAR : BIND_LEXICAL : BIND_FUNCTION); }
}
var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
this.yieldPos = 0;
this.awaitPos = 0;
this.awaitIdentPos = 0;
this.enterScope(functionFlags(node.async, node.generator));
if (!(statement & FUNC_STATEMENT))
{ node.id = this.type === types.name ? this.parseIdent() : null; }
this.parseFunctionParams(node);
this.parseFunctionBody(node, allowExpressionBody, false);
this.yieldPos = oldYieldPos;
this.awaitPos = oldAwaitPos;
this.awaitIdentPos = oldAwaitIdentPos;
return this.finishNode(node, (statement & FUNC_STATEMENT) ? "FunctionDeclaration" : "FunctionExpression")
};
pp$1.parseFunctionParams = function(node) {
this.expect(types.parenL);
node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
this.checkYieldAwaitInDefaultParams();
};
// Parse a class declaration or literal (depending on the
// `isStatement` parameter).
pp$1.parseClass = function(node, isStatement) {
this.next();
// ecma-262 14.6 Class Definitions
// A class definition is always strict mode code.
var oldStrict = this.strict;
this.strict = true;
this.parseClassId(node, isStatement);
this.parseClassSuper(node);
var classBody = this.startNode();
var hadConstructor = false;
classBody.body = [];
this.expect(types.braceL);
while (this.type !== types.braceR) {
var element = this.parseClassElement(node.superClass !== null);
if (element) {
classBody.body.push(element);
if (element.type === "MethodDefinition" && element.kind === "constructor") {
if (hadConstructor) { this.raise(element.start, "Duplicate constructor in the same class"); }
hadConstructor = true;
}
}
}
this.strict = oldStrict;
this.next();
node.body = this.finishNode(classBody, "ClassBody");
return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
};
pp$1.parseClassElement = function(constructorAllowsSuper) {
var this$1 = this;
if (this.eat(types.semi)) { return null }
var method = this.startNode();
var tryContextual = function (k, noLineBreak) {
if ( noLineBreak === void 0 ) noLineBreak = false;
var start = this$1.start, startLoc = this$1.startLoc;
if (!this$1.eatContextual(k)) { return false }
if (this$1.type !== types.parenL && (!noLineBreak || !this$1.canInsertSemicolon())) { return true }
if (method.key) { this$1.unexpected(); }
method.computed = false;
method.key = this$1.startNodeAt(start, startLoc);
method.key.name = k;
this$1.finishNode(method.key, "Identifier");
return false
};
method.kind = "method";
method.static = tryContextual("static");
var isGenerator = this.eat(types.star);
var isAsync = false;
if (!isGenerator) {
if (this.options.ecmaVersion >= 8 && tryContextual("async", true)) {
isAsync = true;
isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
} else if (tryContextual("get")) {
method.kind = "get";
} else if (tryContextual("set")) {
method.kind = "set";
}
}
if (!method.key) { this.parsePropertyName(method); }
var key = method.key;
var allowsDirectSuper = false;
if (!method.computed && !method.static && (key.type === "Identifier" && key.name === "constructor" ||
key.type === "Literal" && key.value === "constructor")) {
if (method.kind !== "method") { this.raise(key.start, "Constructor can't have get/set modifier"); }
if (isGenerator) { this.raise(key.start, "Constructor can't be a generator"); }
if (isAsync) { this.raise(key.start, "Constructor can't be an async method"); }
method.kind = "constructor";
allowsDirectSuper = constructorAllowsSuper;
} else if (method.static && key.type === "Identifier" && key.name === "prototype") {
this.raise(key.start, "Classes may not have a static property named prototype");
}
this.parseClassMethod(method, isGenerator, isAsync, allowsDirectSuper);
if (method.kind === "get" && method.value.params.length !== 0)
{ this.raiseRecoverable(method.value.start, "getter should have no params"); }
if (method.kind === "set" && method.value.params.length !== 1)
{ this.raiseRecoverable(method.value.start, "setter should have exactly one param"); }
if (method.kind === "set" && method.value.params[0].type === "RestElement")
{ this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
return method
};
pp$1.parseClassMethod = function(method, isGenerator, isAsync, allowsDirectSuper) {
method.value = this.parseMethod(isGenerator, isAsync, allowsDirectSuper);
return this.finishNode(method, "MethodDefinition")
};
pp$1.parseClassId = function(node, isStatement) {
if (this.type === types.name) {
node.id = this.parseIdent();
if (isStatement)
{ this.checkLVal(node.id, BIND_LEXICAL, false); }
} else {
if (isStatement === true)
{ this.unexpected(); }
node.id = null;
}
};
pp$1.parseClassSuper = function(node) {
node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
};
// Parses module export declaration.
pp$1.parseExport = function(node, exports) {
this.next();
// export * from '...'
if (this.eat(types.star)) {
if (this.options.ecmaVersion >= 11) {
if (this.eatContextual("as")) {
node.exported = this.parseIdent(true);
this.checkExport(exports, node.exported.name, this.lastTokStart);
} else {
node.exported = null;
}
}
this.expectContextual("from");
if (this.type !== types.string) { this.unexpected(); }
node.source = this.parseExprAtom();
this.semicolon();
return this.finishNode(node, "ExportAllDeclaration")
}
if (this.eat(types._default)) { // export default ...
this.checkExport(exports, "default", this.lastTokStart);
var isAsync;
if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
var fNode = this.startNode();
this.next();
if (isAsync) { this.next(); }
node.declaration = this.parseFunction(fNode, FUNC_STATEMENT | FUNC_NULLABLE_ID, false, isAsync);
} else if (this.type === types._class) {
var cNode = this.startNode();
node.declaration = this.parseClass(cNode, "nullableID");
} else {
node.declaration = this.parseMaybeAssign();
this.semicolon();
}
return this.finishNode(node, "ExportDefaultDeclaration")
}
// export var|const|let|function|class ...
if (this.shouldParseExportStatement()) {
node.declaration = this.parseStatement(null);
if (node.declaration.type === "VariableDeclaration")
{ this.checkVariableExport(exports, node.declaration.declarations); }
else
{ this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
node.specifiers = [];
node.source = null;
} else { // export { x, y as z } [from '...']
node.declaration = null;
node.specifiers = this.parseExportSpecifiers(exports);
if (this.eatContextual("from")) {
if (this.type !== types.string) { this.unexpected(); }
node.source = this.parseExprAtom();
} else {
for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
// check for keywords used as local names
var spec = list[i];
this.checkUnreserved(spec.local);
// check if export is defined
this.checkLocalExport(spec.local);
}
node.source = null;
}
this.semicolon();
}
return this.finishNode(node, "ExportNamedDeclaration")
};
pp$1.checkExport = function(exports, name, pos) {
if (!exports) { return }
if (has(exports, name))
{ this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
exports[name] = true;
};
pp$1.checkPatternExport = function(exports, pat) {
var type = pat.type;
if (type === "Identifier")
{ this.checkExport(exports, pat.name, pat.start); }
else if (type === "ObjectPattern")
{ for (var i = 0, list = pat.properties; i < list.length; i += 1)
{
var prop = list[i];
this.checkPatternExport(exports, prop);
} }
else if (type === "ArrayPattern")
{ for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
var elt = list$1[i$1];
if (elt) { this.checkPatternExport(exports, elt); }
} }
else if (type === "Property")
{ this.checkPatternExport(exports, pat.value); }
else if (type === "AssignmentPattern")
{ this.checkPatternExport(exports, pat.left); }
else if (type === "RestElement")
{ this.checkPatternExport(exports, pat.argument); }
else if (type === "ParenthesizedExpression")
{ this.checkPatternExport(exports, pat.expression); }
};
pp$1.checkVariableExport = function(exports, decls) {
if (!exports) { return }
for (var i = 0, list = decls; i < list.length; i += 1)
{
var decl = list[i];
this.checkPatternExport(exports, decl.id);
}
};
pp$1.shouldParseExportStatement = function() {
return this.type.keyword === "var" ||
this.type.keyword === "const" ||
this.type.keyword === "class" ||
this.type.keyword === "function" ||
this.isLet() ||
this.isAsyncFunction()
};
// Parses a comma-separated list of module exports.
pp$1.parseExportSpecifiers = function(exports) {
var nodes = [], first = true;
// export { x, y as z } [from '...']
this.expect(types.braceL);
while (!this.eat(types.braceR)) {
if (!first) {
this.expect(types.comma);
if (this.afterTrailingComma(types.braceR)) { break }
} else { first = false; }
var node = this.startNode();
node.local = this.parseIdent(true);
node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local;
this.checkExport(exports, node.exported.name, node.exported.start);
nodes.push(this.finishNode(node, "ExportSpecifier"));
}
return nodes
};
// Parses import declaration.
pp$1.parseImport = function(node) {
this.next();
// import '...'
if (this.type === types.string) {
node.specifiers = empty;
node.source = this.parseExprAtom();
} else {
node.specifiers = this.parseImportSpecifiers();
this.expectContextual("from");
node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
}
this.semicolon();
return this.finishNode(node, "ImportDeclaration")
};
// Parses a comma-separated list of module imports.
pp$1.parseImportSpecifiers = function() {
var nodes = [], first = true;
if (this.type === types.name) {
// import defaultObj, { x, y as z } from '...'
var node = this.startNode();
node.local = this.parseIdent();
this.checkLVal(node.local, BIND_LEXICAL);
nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
if (!this.eat(types.comma)) { return nodes }
}
if (this.type === types.star) {
var node$1 = this.startNode();
this.next();
this.expectContextual("as");
node$1.local = this.parseIdent();
this.checkLVal(node$1.local, BIND_LEXICAL);
nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
return nodes
}
this.expect(types.braceL);
while (!this.eat(types.braceR)) {
if (!first) {
this.expect(types.comma);
if (this.afterTrailingComma(types.braceR)) { break }
} else { first = false; }
var node$2 = this.startNode();
node$2.imported = this.parseIdent(true);
if (this.eatContextual("as")) {
node$2.local = this.parseIdent();
} else {
this.checkUnreserved(node$2.imported);
node$2.local = node$2.imported;
}
this.checkLVal(node$2.local, BIND_LEXICAL);
nodes.push(this.finishNode(node$2, "ImportSpecifier"));
}
return nodes
};
// Set `ExpressionStatement#directive` property for directive prologues.
pp$1.adaptDirectivePrologue = function(statements) {
for (var i = 0; i < statements.length && this.isDirectiveCandidate(statements[i]); ++i) {
statements[i].directive = statements[i].expression.raw.slice(1, -1);
}
};
pp$1.isDirectiveCandidate = function(statement) {
return (
statement.type === "ExpressionStatement" &&
statement.expression.type === "Literal" &&
typeof statement.expression.value === "string" &&
// Reject parenthesized strings.
(this.input[statement.start] === "\"" || this.input[statement.start] === "'")
)
};
var pp$2 = Parser.prototype;
// Convert existing expression atom to assignable pattern
// if possible.
pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
if (this.options.ecmaVersion >= 6 && node) {
switch (node.type) {
case "Identifier":
if (this.inAsync && node.name === "await")
{ this.raise(node.start, "Cannot use 'await' as identifier inside an async function"); }
break
case "ObjectPattern":
case "ArrayPattern":
case "RestElement":
break
case "ObjectExpression":
node.type = "ObjectPattern";
if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
for (var i = 0, list = node.properties; i < list.length; i += 1) {
var prop = list[i];
this.toAssignable(prop, isBinding);
// Early error:
// AssignmentRestProperty[Yield, Await] :
// `...` DestructuringAssignmentTarget[Yield, Await]
//
// It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.
if (
prop.type === "RestElement" &&
(prop.argument.type === "ArrayPattern" || prop.argument.type === "ObjectPattern")
) {
this.raise(prop.argument.start, "Unexpected token");
}
}
break
case "Property":
// AssignmentProperty has type === "Property"
if (node.kind !== "init") { this.raise(node.key.start, "Object pattern can't contain getter or setter"); }
this.toAssignable(node.value, isBinding);
break
case "ArrayExpression":
node.type = "ArrayPattern";
if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
this.toAssignableList(node.elements, isBinding);
break
case "SpreadElement":
node.type = "RestElement";
this.toAssignable(node.argument, isBinding);
if (node.argument.type === "AssignmentPattern")
{ this.raise(node.argument.start, "Rest elements cannot have a default value"); }
break
case "AssignmentExpression":
if (node.operator !== "=") { this.raise(node.left.end, "Only '=' operator can be used for specifying default value."); }
node.type = "AssignmentPattern";
delete node.operator;
this.toAssignable(node.left, isBinding);
// falls through to AssignmentPattern
case "AssignmentPattern":
break
case "ParenthesizedExpression":
this.toAssignable(node.expression, isBinding, refDestructuringErrors);
break
case "ChainExpression":
this.raiseRecoverable(node.start, "Optional chaining cannot appear in left-hand side");
break
case "MemberExpression":
if (!isBinding) { break }
default:
this.raise(node.start, "Assigning to rvalue");
}
} else if (refDestructuringErrors) { this.checkPatternErrors(refDestructuringErrors, true); }
return node
};
// Convert list of expression atoms to binding list.
pp$2.toAssignableList = function(exprList, isBinding) {
var end = exprList.length;
for (var i = 0; i < end; i++) {
var elt = exprList[i];
if (elt) { this.toAssignable(elt, isBinding); }
}
if (end) {
var last = exprList[end - 1];
if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
{ this.unexpected(last.argument.start); }
}
return exprList
};
// Parses spread element.
pp$2.parseSpread = function(refDestructuringErrors) {
var node = this.startNode();
this.next();
node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
return this.finishNode(node, "SpreadElement")
};
pp$2.parseRestBinding = function() {
var node = this.startNode();
this.next();
// RestElement inside of a function parameter must be an identifier
if (this.options.ecmaVersion === 6 && this.type !== types.name)
{ this.unexpected(); }
node.argument = this.parseBindingAtom();
return this.finishNode(node, "RestElement")
};
// Parses lvalue (assignable) atom.
pp$2.parseBindingAtom = function() {
if (this.options.ecmaVersion >= 6) {
switch (this.type) {
case types.bracketL:
var node = this.startNode();
this.next();
node.elements = this.parseBindingList(types.bracketR, true, true);
return this.finishNode(node, "ArrayPattern")
case types.braceL:
return this.parseObj(true)
}
}
return this.parseIdent()
};
pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
var elts = [], first = true;
while (!this.eat(close)) {
if (first) { first = false; }
else { this.expect(types.comma); }
if (allowEmpty && this.type === types.comma) {
elts.push(null);
} else if (allowTrailingComma && this.afterTrailingComma(close)) {
break
} else if (this.type === types.ellipsis) {
var rest = this.parseRestBinding();
this.parseBindingListItem(rest);
elts.push(rest);
if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
this.expect(close);
break
} else {
var elem = this.parseMaybeDefault(this.start, this.startLoc);
this.parseBindingListItem(elem);
elts.push(elem);
}
}
return elts
};
pp$2.parseBindingListItem = function(param) {
return param
};
// Parses assignment pattern around given atom if possible.
pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
left = left || this.parseBindingAtom();
if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
var node = this.startNodeAt(startPos, startLoc);
node.left = left;
node.right = this.parseMaybeAssign();
return this.finishNode(node, "AssignmentPattern")
};
// Verify that a node is an lval — something that can be assigned
// to.
// bindingType can be either:
// 'var' indicating that the lval creates a 'var' binding
// 'let' indicating that the lval creates a lexical ('let' or 'const') binding
// 'none' indicating that the binding should be checked for illegal identifiers, but not for duplicate references
pp$2.checkLVal = function(expr, bindingType, checkClashes) {
if ( bindingType === void 0 ) bindingType = BIND_NONE;
switch (expr.type) {
case "Identifier":
if (bindingType === BIND_LEXICAL && expr.name === "let")
{ this.raiseRecoverable(expr.start, "let is disallowed as a lexically bound name"); }
if (this.strict && this.reservedWordsStrictBind.test(expr.name))
{ this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
if (checkClashes) {
if (has(checkClashes, expr.name))
{ this.raiseRecoverable(expr.start, "Argument name clash"); }
checkClashes[expr.name] = true;
}
if (bindingType !== BIND_NONE && bindingType !== BIND_OUTSIDE) { this.declareName(expr.name, bindingType, expr.start); }
break
case "ChainExpression":
this.raiseRecoverable(expr.start, "Optional chaining cannot appear in left-hand side");
break
case "MemberExpression":
if (bindingType) { this.raiseRecoverable(expr.start, "Binding member expression"); }
break
case "ObjectPattern":
for (var i = 0, list = expr.properties; i < list.length; i += 1)
{
var prop = list[i];
this.checkLVal(prop, bindingType, checkClashes);
}
break
case "Property":
// AssignmentProperty has type === "Property"
this.checkLVal(expr.value, bindingType, checkClashes);
break
case "ArrayPattern":
for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
var elem = list$1[i$1];
if (elem) { this.checkLVal(elem, bindingType, checkClashes); }
}
break
case "AssignmentPattern":
this.checkLVal(expr.left, bindingType, checkClashes);
break
case "RestElement":
this.checkLVal(expr.argument, bindingType, checkClashes);
break
case "ParenthesizedExpression":
this.checkLVal(expr.expression, bindingType, checkClashes);
break
default:
this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
}
};
// A recursive descent parser operates by defining functions for all
var pp$3 = Parser.prototype;
// Check if property name clashes with already added.
// Object/class getters and setters are not allowed to clash —
// either with each other or with an init property — and in
// strict mode, init properties are also not allowed to be repeated.
pp$3.checkPropClash = function(prop, propHash, refDestructuringErrors) {
if (this.options.ecmaVersion >= 9 && prop.type === "SpreadElement")
{ return }
if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
{ return }
var key = prop.key;
var name;
switch (key.type) {
case "Identifier": name = key.name; break
case "Literal": name = String(key.value); break
default: return
}
var kind = prop.kind;
if (this.options.ecmaVersion >= 6) {
if (name === "__proto__" && kind === "init") {
if (propHash.proto) {
if (refDestructuringErrors) {
if (refDestructuringErrors.doubleProto < 0)
{ refDestructuringErrors.doubleProto = key.start; }
// Backwards-compat kludge. Can be removed in version 6.0
} else { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
}
propHash.proto = true;
}
return
}
name = "$" + name;
var other = propHash[name];
if (other) {
var redefinition;
if (kind === "init") {
redefinition = this.strict && other.init || other.get || other.set;
} else {
redefinition = other.init || other[kind];
}
if (redefinition)
{ this.raiseRecoverable(key.start, "Redefinition of property"); }
} else {
other = propHash[name] = {
init: false,
get: false,
set: false
};
}
other[kind] = true;
};
// ### Expression parsing
// These nest, from the most general expression type at the top to
// 'atomic', nondivisible expression types at the bottom. Most of
// the functions will simply let the function(s) below them parse,
// and, *if* the syntactic construct they handle is present, wrap
// the AST node that the inner parser gave them in another node.
// Parse a full expression. The optional arguments are used to
// forbid the `in` operator (in for loops initalization expressions)
// and provide reference for storing '=' operator inside shorthand
// property assignment in contexts where both object expression
// and object pattern might appear (so it's possible to raise
// delayed syntax error at correct position).
pp$3.parseExpression = function(noIn, refDestructuringErrors) {
var startPos = this.start, startLoc = this.startLoc;
var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
if (this.type === types.comma) {
var node = this.startNodeAt(startPos, startLoc);
node.expressions = [expr];
while (this.eat(types.comma)) { node.expressions.push(this.parseMaybeAssign(noIn, refDestructuringErrors)); }
return this.finishNode(node, "SequenceExpression")
}
return expr
};
// Parse an assignment expression. This includes applications of
// operators like `+=`.
pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
if (this.isContextual("yield")) {
if (this.inGenerator) { return this.parseYield(noIn) }
// The tokenizer will assume an expression is allowed after
// `yield`, but this isn't that kind of yield
else { this.exprAllowed = false; }
}
var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
if (refDestructuringErrors) {
oldParenAssign = refDestructuringErrors.parenthesizedAssign;
oldTrailingComma = refDestructuringErrors.trailingComma;
refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
} else {
refDestructuringErrors = new DestructuringErrors;
ownDestructuringErrors = true;
}
var startPos = this.start, startLoc = this.startLoc;
if (this.type === types.parenL || this.type === types.name)
{ this.potentialArrowAt = this.start; }
var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
if (this.type.isAssign) {
var node = this.startNodeAt(startPos, startLoc);
node.operator = this.value;
node.left = this.type === types.eq ? this.toAssignable(left, false, refDestructuringErrors) : left;
if (!ownDestructuringErrors) {
refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = refDestructuringErrors.doubleProto = -1;
}
if (refDestructuringErrors.shorthandAssign >= node.left.start)
{ refDestructuringErrors.shorthandAssign = -1; } // reset because shorthand default was used correctly
this.checkLVal(left);
this.next();
node.right = this.parseMaybeAssign(noIn);
return this.finishNode(node, "AssignmentExpression")
} else {
if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
}
if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
return left
};
// Parse a ternary conditional (`?:`) operator.
pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
var startPos = this.start, startLoc = this.startLoc;
var expr = this.parseExprOps(noIn, refDestructuringErrors);
if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
if (this.eat(types.question)) {
var node = this.startNodeAt(startPos, startLoc);
node.test = expr;
node.consequent = this.parseMaybeAssign();
this.expect(types.colon);
node.alternate = this.parseMaybeAssign(noIn);
return this.finishNode(node, "ConditionalExpression")
}
return expr
};
// Start the precedence parser.
pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
var startPos = this.start, startLoc = this.startLoc;
var expr = this.parseMaybeUnary(refDestructuringErrors, false);
if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
return expr.start === startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
};
// Parse binary operators with the operator precedence parsing
// algorithm. `left` is the left-hand side of the operator.
// `minPrec` provides context that allows the function to stop and
// defer further parser to one of its callers when it encounters an
// operator that has a lower precedence than the set it is parsing.
pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
var prec = this.type.binop;
if (prec != null && (!noIn || this.type !== types._in)) {
if (prec > minPrec) {
var logical = this.type === types.logicalOR || this.type === types.logicalAND;
var coalesce = this.type === types.coalesce;
if (coalesce) {
// Handle the precedence of `tt.coalesce` as equal to the range of logical expressions.
// In other words, `node.right` shouldn't contain logical expressions in order to check the mixed error.
prec = types.logicalAND.binop;
}
var op = this.value;
this.next();
var startPos = this.start, startLoc = this.startLoc;
var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical || coalesce);
if ((logical && this.type === types.coalesce) || (coalesce && (this.type === types.logicalOR || this.type === types.logicalAND))) {
this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses");
}
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
}
}
return left
};
pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
var node = this.startNodeAt(startPos, startLoc);
node.left = left;
node.operator = op;
node.right = right;
return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
};
// Parse unary operators, both prefix and postfix.
pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
var startPos = this.start, startLoc = this.startLoc, expr;
if (this.isContextual("await") && (this.inAsync || (!this.inFunction && this.options.allowAwaitOutsideFunction))) {
expr = this.parseAwait();
sawUnary = true;
} else if (this.type.prefix) {
var node = this.startNode(), update = this.type === types.incDec;
node.operator = this.value;
node.prefix = true;
this.next();
node.argument = this.parseMaybeUnary(null, true);
this.checkExpressionErrors(refDestructuringErrors, true);
if (update) { this.checkLVal(node.argument); }
else if (this.strict && node.operator === "delete" &&
node.argument.type === "Identifier")
{ this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
else { sawUnary = true; }
expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
} else {
expr = this.parseExprSubscripts(refDestructuringErrors);
if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
while (this.type.postfix && !this.canInsertSemicolon()) {
var node$1 = this.startNodeAt(startPos, startLoc);
node$1.operator = this.value;
node$1.prefix = false;
node$1.argument = expr;
this.checkLVal(expr);
this.next();
expr = this.finishNode(node$1, "UpdateExpression");
}
}
if (!sawUnary && this.eat(types.starstar))
{ return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
else
{ return expr }
};
// Parse call, dot, and `[]`-subscript expressions.
pp$3.parseExprSubscripts = function(refDestructuringErrors) {
var startPos = this.start, startLoc = this.startLoc;
var expr = this.parseExprAtom(refDestructuringErrors);
if (expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")")
{ return expr }
var result = this.parseSubscripts(expr, startPos, startLoc);
if (refDestructuringErrors && result.type === "MemberExpression") {
if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
}
return result
};
pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
this.lastTokEnd === base.end && !this.canInsertSemicolon() && base.end - base.start === 5 &&
this.potentialArrowAt === base.start;
var optionalChained = false;
while (true) {
var element = this.parseSubscript(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained);
if (element.optional) { optionalChained = true; }
if (element === base || element.type === "ArrowFunctionExpression") {
if (optionalChained) {
var chainNode = this.startNodeAt(startPos, startLoc);
chainNode.expression = element;
element = this.finishNode(chainNode, "ChainExpression");
}
return element
}
base = element;
}
};
pp$3.parseSubscript = function(base, startPos, startLoc, noCalls, maybeAsyncArrow, optionalChained) {
var optionalSupported = this.options.ecmaVersion >= 11;
var optional = optionalSupported && this.eat(types.questionDot);
if (noCalls && optional) { this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); }
var computed = this.eat(types.bracketL);
if (computed || (optional && this.type !== types.parenL && this.type !== types.backQuote) || this.eat(types.dot)) {
var node = this.startNodeAt(startPos, startLoc);
node.object = base;
node.property = computed ? this.parseExpression() : this.parseIdent(this.options.allowReserved !== "never");
node.computed = !!computed;
if (computed) { this.expect(types.bracketR); }
if (optionalSupported) {
node.optional = optional;
}
base = this.finishNode(node, "MemberExpression");
} else if (!noCalls && this.eat(types.parenL)) {
var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
this.yieldPos = 0;
this.awaitPos = 0;
this.awaitIdentPos = 0;
var exprList = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors);
if (maybeAsyncArrow && !optional && !this.canInsertSemicolon() && this.eat(types.arrow)) {
this.checkPatternErrors(refDestructuringErrors, false);
this.checkYieldAwaitInDefaultParams();
if (this.awaitIdentPos > 0)
{ this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"); }
this.yieldPos = oldYieldPos;
this.awaitPos = oldAwaitPos;
this.awaitIdentPos = oldAwaitIdentPos;
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true)
}
this.checkExpressionErrors(refDestructuringErrors, true);
this.yieldPos = oldYieldPos || this.yieldPos;
this.awaitPos = oldAwaitPos || this.awaitPos;
this.awaitIdentPos = oldAwaitIdentPos || this.awaitIdentPos;
var node$1 = this.startNodeAt(startPos, startLoc);
node$1.callee = base;
node$1.arguments = exprList;
if (optionalSupported) {
node$1.optional = optional;
}
base = this.finishNode(node$1, "CallExpression");
} else if (this.type === types.backQuote) {
if (optional || optionalChained) {
this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions");
}
var node$2 = this.startNodeAt(startPos, startLoc);
node$2.tag = base;
node$2.quasi = this.parseTemplate({isTagged: true});
base = this.finishNode(node$2, "TaggedTemplateExpression");
}
return base
};
// Parse an atomic expression — either a single token that is an
// expression, an expression started by a keyword like `function` or
// `new`, or an expression wrapped in punctuation like `()`, `[]`,
// or `{}`.
pp$3.parseExprAtom = function(refDestructuringErrors) {
// If a division operator appears in an expression position, the
// tokenizer got confused, and we force it to read a regexp instead.
if (this.type === types.slash) { this.readRegexp(); }
var node, canBeArrow = this.potentialArrowAt === this.start;
switch (this.type) {
case types._super:
if (!this.allowSuper)
{ this.raise(this.start, "'super' keyword outside a method"); }
node = this.startNode();
this.next();
if (this.type === types.parenL && !this.allowDirectSuper)
{ this.raise(node.start, "super() call outside constructor of a subclass"); }
// The `super` keyword can appear at below:
// SuperProperty:
// super [ Expression ]
// super . IdentifierName
// SuperCall:
// super ( Arguments )
if (this.type !== types.dot && this.type !== types.bracketL && this.type !== types.parenL)
{ this.unexpected(); }
return this.finishNode(node, "Super")
case types._this:
node = this.startNode();
this.next();
return this.finishNode(node, "ThisExpression")
case types.name:
var startPos = this.start, startLoc = this.startLoc, containsEsc = this.containsEsc;
var id = this.parseIdent(false);
if (this.options.ecmaVersion >= 8 && !containsEsc && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
{ return this.parseFunction(this.startNodeAt(startPos, startLoc), 0, false, true) }
if (canBeArrow && !this.canInsertSemicolon()) {
if (this.eat(types.arrow))
{ return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name && !containsEsc) {
id = this.parseIdent(false);
if (this.canInsertSemicolon() || !this.eat(types.arrow))
{ this.unexpected(); }
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
}
}
return id
case types.regexp:
var value = this.value;
node = this.parseLiteral(value.value);
node.regex = {pattern: value.pattern, flags: value.flags};
return node
case types.num: case types.string:
return this.parseLiteral(this.value)
case types._null: case types._true: case types._false:
node = this.startNode();
node.value = this.type === types._null ? null : this.type === types._true;
node.raw = this.type.keyword;
this.next();
return this.finishNode(node, "Literal")
case types.parenL:
var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
if (refDestructuringErrors) {
if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
{ refDestructuringErrors.parenthesizedAssign = start; }
if (refDestructuringErrors.parenthesizedBind < 0)
{ refDestructuringErrors.parenthesizedBind = start; }
}
return expr
case types.bracketL:
node = this.startNode();
this.next();
node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
return this.finishNode(node, "ArrayExpression")
case types.braceL:
return this.parseObj(false, refDestructuringErrors)
case types._function:
node = this.startNode();
this.next();
return this.parseFunction(node, 0)
case types._class:
return this.parseClass(this.startNode(), false)
case types._new:
return this.parseNew()
case types.backQuote:
return this.parseTemplate()
case types._import:
if (this.options.ecmaVersion >= 11) {
return this.parseExprImport()
} else {
return this.unexpected()
}
default:
this.unexpected();
}
};
pp$3.parseExprImport = function() {
var node = this.startNode();
// Consume `import` as an identifier for `import.meta`.
// Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`.
if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword import"); }
var meta = this.parseIdent(true);
switch (this.type) {
case types.parenL:
return this.parseDynamicImport(node)
case types.dot:
node.meta = meta;
return this.parseImportMeta(node)
default:
this.unexpected();
}
};
pp$3.parseDynamicImport = function(node) {
this.next(); // skip `(`
// Parse node.source.
node.source = this.parseMaybeAssign();
// Verify ending.
if (!this.eat(types.parenR)) {
var errorPos = this.start;
if (this.eat(types.comma) && this.eat(types.parenR)) {
this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
} else {
this.unexpected(errorPos);
}
}
return this.finishNode(node, "ImportExpression")
};
pp$3.parseImportMeta = function(node) {
this.next(); // skip `.`
var containsEsc = this.containsEsc;
node.property = this.parseIdent(true);
if (node.property.name !== "meta")
{ this.raiseRecoverable(node.property.start, "The only valid meta property for import is 'import.meta'"); }
if (containsEsc)
{ this.raiseRecoverable(node.start, "'import.meta' must not contain escaped characters"); }
if (this.options.sourceType !== "module")
{ this.raiseRecoverable(node.start, "Cannot use 'import.meta' outside a module"); }
return this.finishNode(node, "MetaProperty")
};
pp$3.parseLiteral = function(value) {
var node = this.startNode();
node.value = value;
node.raw = this.input.slice(this.start, this.end);
if (node.raw.charCodeAt(node.raw.length - 1) === 110) { node.bigint = node.raw.slice(0, -1); }
this.next();
return this.finishNode(node, "Literal")
};
pp$3.parseParenExpression = function() {
this.expect(types.parenL);
var val = this.parseExpression();
this.expect(types.parenR);
return val
};
pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
if (this.options.ecmaVersion >= 6) {
this.next();
var innerStartPos = this.start, innerStartLoc = this.startLoc;
var exprList = [], first = true, lastIsComma = false;
var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart;
this.yieldPos = 0;
this.awaitPos = 0;
// Do not save awaitIdentPos to allow checking awaits nested in parameters
while (this.type !== types.parenR) {
first ? first = false : this.expect(types.comma);
if (allowTrailingComma && this.afterTrailingComma(types.parenR, true)) {
lastIsComma = true;
break
} else if (this.type === types.ellipsis) {
spreadStart = this.start;
exprList.push(this.parseParenItem(this.parseRestBinding()));
if (this.type === types.comma) { this.raise(this.start, "Comma is not permitted after the rest element"); }
break
} else {
exprList.push(this.parseMaybeAssign(false, refDestructuringErrors, this.parseParenItem));
}
}
var innerEndPos = this.start, innerEndLoc = this.startLoc;
this.expect(types.parenR);
if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
this.checkPatternErrors(refDestructuringErrors, false);
this.checkYieldAwaitInDefaultParams();
this.yieldPos = oldYieldPos;
this.awaitPos = oldAwaitPos;
return this.parseParenArrowList(startPos, startLoc, exprList)
}
if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
if (spreadStart) { this.unexpected(spreadStart); }
this.checkExpressionErrors(refDestructuringErrors, true);
this.yieldPos = oldYieldPos || this.yieldPos;
this.awaitPos = oldAwaitPos || this.awaitPos;
if (exprList.length > 1) {
val = this.startNodeAt(innerStartPos, innerStartLoc);
val.expressions = exprList;
this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
} else {
val = exprList[0];
}
} else {
val = this.parseParenExpression();
}
if (this.options.preserveParens) {
var par = this.startNodeAt(startPos, startLoc);
par.expression = val;
return this.finishNode(par, "ParenthesizedExpression")
} else {
return val
}
};
pp$3.parseParenItem = function(item) {
return item
};
pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
};
// New's precedence is slightly tricky. It must allow its argument to
// be a `[]` or dot subscript expression, but not a call — at least,
// not without wrapping it in parentheses. Thus, it uses the noCalls
// argument to parseSubscripts to prevent it from consuming the
// argument list.
var empty$1 = [];
pp$3.parseNew = function() {
if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword new"); }
var node = this.startNode();
var meta = this.parseIdent(true);
if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
node.meta = meta;
var containsEsc = this.containsEsc;
node.property = this.parseIdent(true);
if (node.property.name !== "target")
{ this.raiseRecoverable(node.property.start, "The only valid meta property for new is 'new.target'"); }
if (containsEsc)
{ this.raiseRecoverable(node.start, "'new.target' must not contain escaped characters"); }
if (!this.inNonArrowFunction())
{ this.raiseRecoverable(node.start, "'new.target' can only be used in functions"); }
return this.finishNode(node, "MetaProperty")
}
var startPos = this.start, startLoc = this.startLoc, isImport = this.type === types._import;
node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
if (isImport && node.callee.type === "ImportExpression") {
this.raise(startPos, "Cannot use new with import()");
}
if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
else { node.arguments = empty$1; }
return this.finishNode(node, "NewExpression")
};
// Parse template expression.
pp$3.parseTemplateElement = function(ref) {
var isTagged = ref.isTagged;
var elem = this.startNode();
if (this.type === types.invalidTemplate) {
if (!isTagged) {
this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
}
elem.value = {
raw: this.value,
cooked: null
};
} else {
elem.value = {
raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
cooked: this.value
};
}
this.next();
elem.tail = this.type === types.backQuote;
return this.finishNode(elem, "TemplateElement")
};
pp$3.parseTemplate = function(ref) {
if ( ref === void 0 ) ref = {};
var isTagged = ref.isTagged; if ( isTagged === void 0 ) isTagged = false;
var node = this.startNode();
this.next();
node.expressions = [];
var curElt = this.parseTemplateElement({isTagged: isTagged});
node.quasis = [curElt];
while (!curElt.tail) {
if (this.type === types.eof) { this.raise(this.pos, "Unterminated template literal"); }
this.expect(types.dollarBraceL);
node.expressions.push(this.parseExpression());
this.expect(types.braceR);
node.quasis.push(curElt = this.parseTemplateElement({isTagged: isTagged}));
}
this.next();
return this.finishNode(node, "TemplateLiteral")
};
pp$3.isAsyncProp = function(prop) {
return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
(this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword || (this.options.ecmaVersion >= 9 && this.type === types.star)) &&
!lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
};
// Parse an object literal or binding pattern.
pp$3.parseObj = function(isPattern, refDestructuringErrors) {
var node = this.startNode(), first = true, propHash = {};
node.properties = [];
this.next();
while (!this.eat(types.braceR)) {
if (!first) {
this.expect(types.comma);
if (this.options.ecmaVersion >= 5 && this.afterTrailingComma(types.braceR)) { break }
} else { first = false; }
var prop = this.parseProperty(isPattern, refDestructuringErrors);
if (!isPattern) { this.checkPropClash(prop, propHash, refDestructuringErrors); }
node.properties.push(prop);
}
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
};
pp$3.parseProperty = function(isPattern, refDestructuringErrors) {
var prop = this.startNode(), isGenerator, isAsync, startPos, startLoc;
if (this.options.ecmaVersion >= 9 && this.eat(types.ellipsis)) {
if (isPattern) {
prop.argument = this.parseIdent(false);
if (this.type === types.comma) {
this.raise(this.start, "Comma is not permitted after the rest element");
}
return this.finishNode(prop, "RestElement")
}
// To disallow parenthesized identifier via `this.toAssignable()`.
if (this.type === types.parenL && refDestructuringErrors) {
if (refDestructuringErrors.parenthesizedAssign < 0) {
refDestructuringErrors.parenthesizedAssign = this.start;
}
if (refDestructuringErrors.parenthesizedBind < 0) {
refDestructuringErrors.parenthesizedBind = this.start;
}
}
// Parse argument.
prop.argument = this.parseMaybeAssign(false, refDestructuringErrors);
// To disallow trailing comma via `this.toAssignable()`.
if (this.type === types.comma && refDestructuringErrors && refDestructuringErrors.trailingComma < 0) {
refDestructuringErrors.trailingComma = this.start;
}
// Finish
return this.finishNode(prop, "SpreadElement")
}
if (this.options.ecmaVersion >= 6) {
prop.method = false;
prop.shorthand = false;
if (isPattern || refDestructuringErrors) {
startPos = this.start;
startLoc = this.startLoc;
}
if (!isPattern)
{ isGenerator = this.eat(types.star); }
}
var containsEsc = this.containsEsc;
this.parsePropertyName(prop);
if (!isPattern && !containsEsc && this.options.ecmaVersion >= 8 && !isGenerator && this.isAsyncProp(prop)) {
isAsync = true;
isGenerator = this.options.ecmaVersion >= 9 && this.eat(types.star);
this.parsePropertyName(prop, refDestructuringErrors);
} else {
isAsync = false;
}
this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc);
return this.finishNode(prop, "Property")
};
pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors, containsEsc) {
if ((isGenerator || isAsync) && this.type === types.colon)
{ this.unexpected(); }
if (this.eat(types.colon)) {
prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
prop.kind = "init";
} else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
if (isPattern) { this.unexpected(); }
prop.kind = "init";
prop.method = true;
prop.value = this.parseMethod(isGenerator, isAsync);
} else if (!isPattern && !containsEsc &&
this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
(prop.key.name === "get" || prop.key.name === "set") &&
(this.type !== types.comma && this.type !== types.braceR && this.type !== types.eq)) {
if (isGenerator || isAsync) { this.unexpected(); }
prop.kind = prop.key.name;
this.parsePropertyName(prop);
prop.value = this.parseMethod(false);
var paramCount = prop.kind === "get" ? 0 : 1;
if (prop.value.params.length !== paramCount) {
var start = prop.value.start;
if (prop.kind === "get")
{ this.raiseRecoverable(start, "getter should have no params"); }
else
{ this.raiseRecoverable(start, "setter should have exactly one param"); }
} else {
if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
{ this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
}
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
if (isGenerator || isAsync) { this.unexpected(); }
this.checkUnreserved(prop.key);
if (prop.key.name === "await" && !this.awaitIdentPos)
{ this.awaitIdentPos = startPos; }
prop.kind = "init";
if (isPattern) {
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
} else if (this.type === types.eq && refDestructuringErrors) {
if (refDestructuringErrors.shorthandAssign < 0)
{ refDestructuringErrors.shorthandAssign = this.start; }
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
} else {
prop.value = prop.key;
}
prop.shorthand = true;
} else { this.unexpected(); }
};
pp$3.parsePropertyName = function(prop) {
if (this.options.ecmaVersion >= 6) {
if (this.eat(types.bracketL)) {
prop.computed = true;
prop.key = this.parseMaybeAssign();
this.expect(types.bracketR);
return prop.key
} else {
prop.computed = false;
}
}
return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never")
};
// Initialize empty function node.
pp$3.initFunction = function(node) {
node.id = null;
if (this.options.ecmaVersion >= 6) { node.generator = node.expression = false; }
if (this.options.ecmaVersion >= 8) { node.async = false; }
};
// Parse object or class method.
pp$3.parseMethod = function(isGenerator, isAsync, allowDirectSuper) {
var node = this.startNode(), oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
this.initFunction(node);
if (this.options.ecmaVersion >= 6)
{ node.generator = isGenerator; }
if (this.options.ecmaVersion >= 8)
{ node.async = !!isAsync; }
this.yieldPos = 0;
this.awaitPos = 0;
this.awaitIdentPos = 0;
this.enterScope(functionFlags(isAsync, node.generator) | SCOPE_SUPER | (allowDirectSuper ? SCOPE_DIRECT_SUPER : 0));
this.expect(types.parenL);
node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
this.checkYieldAwaitInDefaultParams();
this.parseFunctionBody(node, false, true);
this.yieldPos = oldYieldPos;
this.awaitPos = oldAwaitPos;
this.awaitIdentPos = oldAwaitIdentPos;
return this.finishNode(node, "FunctionExpression")
};
// Parse arrow function expression with given parameters.
pp$3.parseArrowExpression = function(node, params, isAsync) {
var oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldAwaitIdentPos = this.awaitIdentPos;
this.enterScope(functionFlags(isAsync, false) | SCOPE_ARROW);
this.initFunction(node);
if (this.options.ecmaVersion >= 8) { node.async = !!isAsync; }
this.yieldPos = 0;
this.awaitPos = 0;
this.awaitIdentPos = 0;
node.params = this.toAssignableList(params, true);
this.parseFunctionBody(node, true, false);
this.yieldPos = oldYieldPos;
this.awaitPos = oldAwaitPos;
this.awaitIdentPos = oldAwaitIdentPos;
return this.finishNode(node, "ArrowFunctionExpression")
};
// Parse function body and check parameters.
pp$3.parseFunctionBody = function(node, isArrowFunction, isMethod) {
var isExpression = isArrowFunction && this.type !== types.braceL;
var oldStrict = this.strict, useStrict = false;
if (isExpression) {
node.body = this.parseMaybeAssign();
node.expression = true;
this.checkParams(node, false);
} else {
var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
if (!oldStrict || nonSimple) {
useStrict = this.strictDirective(this.end);
// If this is a strict mode function, verify that argument names
// are not repeated, and it does not try to bind the words `eval`
// or `arguments`.
if (useStrict && nonSimple)
{ this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
}
// Start a new scope with regard to labels and the `inFunction`
// flag (restore them to their old value afterwards).
var oldLabels = this.labels;
this.labels = [];
if (useStrict) { this.strict = true; }
// Add the params to varDeclaredNames to ensure that an error is thrown
// if a let/const declaration in the function clashes with one of the params.
this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && !isMethod && this.isSimpleParamList(node.params));
// Ensure the function name isn't a forbidden identifier in strict mode, e.g. 'eval'
if (this.strict && node.id) { this.checkLVal(node.id, BIND_OUTSIDE); }
node.body = this.parseBlock(false, undefined, useStrict && !oldStrict);
node.expression = false;
this.adaptDirectivePrologue(node.body.body);
this.labels = oldLabels;
}
this.exitScope();
};
pp$3.isSimpleParamList = function(params) {
for (var i = 0, list = params; i < list.length; i += 1)
{
var param = list[i];
if (param.type !== "Identifier") { return false
} }
return true
};
// Checks function params for various disallowed patterns such as using "eval"
// or "arguments" and duplicate parameters.
pp$3.checkParams = function(node, allowDuplicates) {
var nameHash = {};
for (var i = 0, list = node.params; i < list.length; i += 1)
{
var param = list[i];
this.checkLVal(param, BIND_VAR, allowDuplicates ? null : nameHash);
}
};
// Parses a comma-separated list of expressions, and returns them as
// an array. `close` is the token type that ends the list, and
// `allowEmpty` can be turned on to allow subsequent commas with
// nothing in between them to be parsed as `null` (which is needed
// for array literals).
pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
var elts = [], first = true;
while (!this.eat(close)) {
if (!first) {
this.expect(types.comma);
if (allowTrailingComma && this.afterTrailingComma(close)) { break }
} else { first = false; }
var elt = (void 0);
if (allowEmpty && this.type === types.comma)
{ elt = null; }
else if (this.type === types.ellipsis) {
elt = this.parseSpread(refDestructuringErrors);
if (refDestructuringErrors && this.type === types.comma && refDestructuringErrors.trailingComma < 0)
{ refDestructuringErrors.trailingComma = this.start; }
} else {
elt = this.parseMaybeAssign(false, refDestructuringErrors);
}
elts.push(elt);
}
return elts
};
pp$3.checkUnreserved = function(ref) {
var start = ref.start;
var end = ref.end;
var name = ref.name;
if (this.inGenerator && name === "yield")
{ this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); }
if (this.inAsync && name === "await")
{ this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); }
if (this.keywords.test(name))
{ this.raise(start, ("Unexpected keyword '" + name + "'")); }
if (this.options.ecmaVersion < 6 &&
this.input.slice(start, end).indexOf("\\") !== -1) { return }
var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
if (re.test(name)) {
if (!this.inAsync && name === "await")
{ this.raiseRecoverable(start, "Cannot use keyword 'await' outside an async function"); }
this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved"));
}
};
// Parse the next token as an identifier. If `liberal` is true (used
// when parsing properties), it will also convert keywords into
// identifiers.
pp$3.parseIdent = function(liberal, isBinding) {
var node = this.startNode();
if (this.type === types.name) {
node.name = this.value;
} else if (this.type.keyword) {
node.name = this.type.keyword;
// To fix https://github.com/acornjs/acorn/issues/575
// `class` and `function` keywords push new context into this.context.
// But there is no chance to pop the context if the keyword is consumed as an identifier such as a property name.
// If the previous token is a dot, this does not apply because the context-managing code already ignored the keyword
if ((node.name === "class" || node.name === "function") &&
(this.lastTokEnd !== this.lastTokStart + 1 || this.input.charCodeAt(this.lastTokStart) !== 46)) {
this.context.pop();
}
} else {
this.unexpected();
}
this.next(!!liberal);
this.finishNode(node, "Identifier");
if (!liberal) {
this.checkUnreserved(node);
if (node.name === "await" && !this.awaitIdentPos)
{ this.awaitIdentPos = node.start; }
}
return node
};
// Parses yield expression inside generator.
pp$3.parseYield = function(noIn) {
if (!this.yieldPos) { this.yieldPos = this.start; }
var node = this.startNode();
this.next();
if (this.type === types.semi || this.canInsertSemicolon() || (this.type !== types.star && !this.type.startsExpr)) {
node.delegate = false;
node.argument = null;
} else {
node.delegate = this.eat(types.star);
node.argument = this.parseMaybeAssign(noIn);
}
return this.finishNode(node, "YieldExpression")
};
pp$3.parseAwait = function() {
if (!this.awaitPos) { this.awaitPos = this.start; }
var node = this.startNode();
this.next();
node.argument = this.parseMaybeUnary(null, false);
return this.finishNode(node, "AwaitExpression")
};
var pp$4 = Parser.prototype;
// This function is used to raise exceptions on parse errors. It
// takes an offset integer (into the current `input`) to indicate
// the location of the error, attaches the position to the end
// of the error message, and then raises a `SyntaxError` with that
// message.
pp$4.raise = function(pos, message) {
var loc = getLineInfo(this.input, pos);
message += " (" + loc.line + ":" + loc.column + ")";
var err = new SyntaxError(message);
err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
throw err
};
pp$4.raiseRecoverable = pp$4.raise;
pp$4.curPosition = function() {
if (this.options.locations) {
return new Position(this.curLine, this.pos - this.lineStart)
}
};
var pp$5 = Parser.prototype;
var Scope = function Scope(flags) {
this.flags = flags;
// A list of var-declared names in the current lexical scope
this.var = [];
// A list of lexically-declared names in the current lexical scope
this.lexical = [];
// A list of lexically-declared FunctionDeclaration names in the current lexical scope
this.functions = [];
};
// The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names.
pp$5.enterScope = function(flags) {
this.scopeStack.push(new Scope(flags));
};
pp$5.exitScope = function() {
this.scopeStack.pop();
};
// The spec says:
// > At the top level of a function, or script, function declarations are
// > treated like var declarations rather than like lexical declarations.
pp$5.treatFunctionsAsVarInScope = function(scope) {
return (scope.flags & SCOPE_FUNCTION) || !this.inModule && (scope.flags & SCOPE_TOP)
};
pp$5.declareName = function(name, bindingType, pos) {
var redeclared = false;
if (bindingType === BIND_LEXICAL) {
var scope = this.currentScope();
redeclared = scope.lexical.indexOf(name) > -1 || scope.functions.indexOf(name) > -1 || scope.var.indexOf(name) > -1;
scope.lexical.push(name);
if (this.inModule && (scope.flags & SCOPE_TOP))
{ delete this.undefinedExports[name]; }
} else if (bindingType === BIND_SIMPLE_CATCH) {
var scope$1 = this.currentScope();
scope$1.lexical.push(name);
} else if (bindingType === BIND_FUNCTION) {
var scope$2 = this.currentScope();
if (this.treatFunctionsAsVar)
{ redeclared = scope$2.lexical.indexOf(name) > -1; }
else
{ redeclared = scope$2.lexical.indexOf(name) > -1 || scope$2.var.indexOf(name) > -1; }
scope$2.functions.push(name);
} else {
for (var i = this.scopeStack.length - 1; i >= 0; --i) {
var scope$3 = this.scopeStack[i];
if (scope$3.lexical.indexOf(name) > -1 && !((scope$3.flags & SCOPE_SIMPLE_CATCH) && scope$3.lexical[0] === name) ||
!this.treatFunctionsAsVarInScope(scope$3) && scope$3.functions.indexOf(name) > -1) {
redeclared = true;
break
}
scope$3.var.push(name);
if (this.inModule && (scope$3.flags & SCOPE_TOP))
{ delete this.undefinedExports[name]; }
if (scope$3.flags & SCOPE_VAR) { break }
}
}
if (redeclared) { this.raiseRecoverable(pos, ("Identifier '" + name + "' has already been declared")); }
};
pp$5.checkLocalExport = function(id) {
// scope.functions must be empty as Module code is always strict.
if (this.scopeStack[0].lexical.indexOf(id.name) === -1 &&
this.scopeStack[0].var.indexOf(id.name) === -1) {
this.undefinedExports[id.name] = id;
}
};
pp$5.currentScope = function() {
return this.scopeStack[this.scopeStack.length - 1]
};
pp$5.currentVarScope = function() {
for (var i = this.scopeStack.length - 1;; i--) {
var scope = this.scopeStack[i];
if (scope.flags & SCOPE_VAR) { return scope }
}
};
// Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`.
pp$5.currentThisScope = function() {
for (var i = this.scopeStack.length - 1;; i--) {
var scope = this.scopeStack[i];
if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope }
}
};
var Node = function Node(parser, pos, loc) {
this.type = "";
this.start = pos;
this.end = 0;
if (parser.options.locations)
{ this.loc = new SourceLocation(parser, loc); }
if (parser.options.directSourceFile)
{ this.sourceFile = parser.options.directSourceFile; }
if (parser.options.ranges)
{ this.range = [pos, 0]; }
};
// Start an AST node, attaching a start offset.
var pp$6 = Parser.prototype;
pp$6.startNode = function() {
return new Node(this, this.start, this.startLoc)
};
pp$6.startNodeAt = function(pos, loc) {
return new Node(this, pos, loc)
};
// Finish an AST node, adding `type` and `end` properties.
function finishNodeAt(node, type, pos, loc) {
node.type = type;
node.end = pos;
if (this.options.locations)
{ node.loc.end = loc; }
if (this.options.ranges)
{ node.range[1] = pos; }
return node
}
pp$6.finishNode = function(node, type) {
return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
};
// Finish node at given position
pp$6.finishNodeAt = function(node, type, pos, loc) {
return finishNodeAt.call(this, node, type, pos, loc)
};
// The algorithm used to determine whether a regexp can appear at a
var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
this.token = token;
this.isExpr = !!isExpr;
this.preserveSpace = !!preserveSpace;
this.override = override;
this.generator = !!generator;
};
var types$1 = {
b_stat: new TokContext("{", false),
b_expr: new TokContext("{", true),
b_tmpl: new TokContext("${", false),
p_stat: new TokContext("(", false),
p_expr: new TokContext("(", true),
q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
f_stat: new TokContext("function", false),
f_expr: new TokContext("function", true),
f_expr_gen: new TokContext("function", true, false, null, true),
f_gen: new TokContext("function", false, false, null, true)
};
var pp$7 = Parser.prototype;
pp$7.initialContext = function() {
return [types$1.b_stat]
};
pp$7.braceIsBlock = function(prevType) {
var parent = this.curContext();
if (parent === types$1.f_expr || parent === types$1.f_stat)
{ return true }
if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
{ return !parent.isExpr }
// The check for `tt.name && exprAllowed` detects whether we are
// after a `yield` or `of` construct. See the `updateContext` for
// `tt.name`.
if (prevType === types._return || prevType === types.name && this.exprAllowed)
{ return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType === types.arrow)
{ return true }
if (prevType === types.braceL)
{ return parent === types$1.b_stat }
if (prevType === types._var || prevType === types._const || prevType === types.name)
{ return false }
return !this.exprAllowed
};
pp$7.inGeneratorContext = function() {
for (var i = this.context.length - 1; i >= 1; i--) {
var context = this.context[i];
if (context.token === "function")
{ return context.generator }
}
return false
};
pp$7.updateContext = function(prevType) {
var update, type = this.type;
if (type.keyword && prevType === types.dot)
{ this.exprAllowed = false; }
else if (update = type.updateContext)
{ update.call(this, prevType); }
else
{ this.exprAllowed = type.beforeExpr; }
};
// Token-specific context update code
types.parenR.updateContext = types.braceR.updateContext = function() {
if (this.context.length === 1) {
this.exprAllowed = true;
return
}
var out = this.context.pop();
if (out === types$1.b_stat && this.curContext().token === "function") {
out = this.context.pop();
}
this.exprAllowed = !out.isExpr;
};
types.braceL.updateContext = function(prevType) {
this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
this.exprAllowed = true;
};
types.dollarBraceL.updateContext = function() {
this.context.push(types$1.b_tmpl);
this.exprAllowed = true;
};
types.parenL.updateContext = function(prevType) {
var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
this.exprAllowed = true;
};
types.incDec.updateContext = function() {
// tokExprAllowed stays unchanged
};
types._function.updateContext = types._class.updateContext = function(prevType) {
if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
!(prevType === types._return && lineBreak.test(this.input.slice(this.lastTokEnd, this.start))) &&
!((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
{ this.context.push(types$1.f_expr); }
else
{ this.context.push(types$1.f_stat); }
this.exprAllowed = false;
};
types.backQuote.updateContext = function() {
if (this.curContext() === types$1.q_tmpl)
{ this.context.pop(); }
else
{ this.context.push(types$1.q_tmpl); }
this.exprAllowed = false;
};
types.star.updateContext = function(prevType) {
if (prevType === types._function) {
var index = this.context.length - 1;
if (this.context[index] === types$1.f_expr)
{ this.context[index] = types$1.f_expr_gen; }
else
{ this.context[index] = types$1.f_gen; }
}
this.exprAllowed = true;
};
types.name.updateContext = function(prevType) {
var allowed = false;
if (this.options.ecmaVersion >= 6 && prevType !== types.dot) {
if (this.value === "of" && !this.exprAllowed ||
this.value === "yield" && this.inGeneratorContext())
{ allowed = true; }
}
this.exprAllowed = allowed;
};
// This file contains Unicode properties extracted from the ECMAScript
// specification. The lists are extracted like so:
// $$('#table-binary-unicode-properties > figure > table > tbody > tr > td:nth-child(1) code').map(el => el.innerText)
// #table-binary-unicode-properties
var ecma9BinaryProperties = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS";
var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
var ecma11BinaryProperties = ecma10BinaryProperties;
var unicodeBinaryProperties = {
9: ecma9BinaryProperties,
10: ecma10BinaryProperties,
11: ecma11BinaryProperties
};
// #table-unicode-general-category-values
var unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu";
// #table-unicode-script-values
var ecma9ScriptValues = "Adlam Adlm Ahom Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb";
var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd";
var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
var unicodeScriptValues = {
9: ecma9ScriptValues,
10: ecma10ScriptValues,
11: ecma11ScriptValues
};
var data = {};
function buildUnicodeData(ecmaVersion) {
var d = data[ecmaVersion] = {
binary: wordsRegexp(unicodeBinaryProperties[ecmaVersion] + " " + unicodeGeneralCategoryValues),
nonBinary: {
General_Category: wordsRegexp(unicodeGeneralCategoryValues),
Script: wordsRegexp(unicodeScriptValues[ecmaVersion])
}
};
d.nonBinary.Script_Extensions = d.nonBinary.Script;
d.nonBinary.gc = d.nonBinary.General_Category;
d.nonBinary.sc = d.nonBinary.Script;
d.nonBinary.scx = d.nonBinary.Script_Extensions;
}
buildUnicodeData(9);
buildUnicodeData(10);
buildUnicodeData(11);
var pp$8 = Parser.prototype;
var RegExpValidationState = function RegExpValidationState(parser) {
this.parser = parser;
this.validFlags = "gim" + (parser.options.ecmaVersion >= 6 ? "uy" : "") + (parser.options.ecmaVersion >= 9 ? "s" : "");
this.unicodeProperties = data[parser.options.ecmaVersion >= 11 ? 11 : parser.options.ecmaVersion];
this.source = "";
this.flags = "";
this.start = 0;
this.switchU = false;
this.switchN = false;
this.pos = 0;
this.lastIntValue = 0;
this.lastStringValue = "";
this.lastAssertionIsQuantifiable = false;
this.numCapturingParens = 0;
this.maxBackReference = 0;
this.groupNames = [];
this.backReferenceNames = [];
};
RegExpValidationState.prototype.reset = function reset (start, pattern, flags) {
var unicode = flags.indexOf("u") !== -1;
this.start = start | 0;
this.source = pattern + "";
this.flags = flags;
this.switchU = unicode && this.parser.options.ecmaVersion >= 6;
this.switchN = unicode && this.parser.options.ecmaVersion >= 9;
};
RegExpValidationState.prototype.raise = function raise (message) {
this.parser.raiseRecoverable(this.start, ("Invalid regular expression: /" + (this.source) + "/: " + message));
};
// If u flag is given, this returns the code point at the index (it combines a surrogate pair).
// Otherwise, this returns the code unit of the index (can be a part of a surrogate pair).
RegExpValidationState.prototype.at = function at (i, forceU) {
if ( forceU === void 0 ) forceU = false;
var s = this.source;
var l = s.length;
if (i >= l) {
return -1
}
var c = s.charCodeAt(i);
if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l) {
return c
}
var next = s.charCodeAt(i + 1);
return next >= 0xDC00 && next <= 0xDFFF ? (c << 10) + next - 0x35FDC00 : c
};
RegExpValidationState.prototype.nextIndex = function nextIndex (i, forceU) {
if ( forceU === void 0 ) forceU = false;
var s = this.source;
var l = s.length;
if (i >= l) {
return l
}
var c = s.charCodeAt(i), next;
if (!(forceU || this.switchU) || c <= 0xD7FF || c >= 0xE000 || i + 1 >= l ||
(next = s.charCodeAt(i + 1)) < 0xDC00 || next > 0xDFFF) {
return i + 1
}
return i + 2
};
RegExpValidationState.prototype.current = function current (forceU) {
if ( forceU === void 0 ) forceU = false;
return this.at(this.pos, forceU)
};
RegExpValidationState.prototype.lookahead = function lookahead (forceU) {
if ( forceU === void 0 ) forceU = false;
return this.at(this.nextIndex(this.pos, forceU), forceU)
};
RegExpValidationState.prototype.advance = function advance (forceU) {
if ( forceU === void 0 ) forceU = false;
this.pos = this.nextIndex(this.pos, forceU);
};
RegExpValidationState.prototype.eat = function eat (ch, forceU) {
if ( forceU === void 0 ) forceU = false;
if (this.current(forceU) === ch) {
this.advance(forceU);
return true
}
return false
};
function codePointToString(ch) {
if (ch <= 0xFFFF) { return String.fromCharCode(ch) }
ch -= 0x10000;
return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00)
}
/**
* Validate the flags part of a given RegExpLiteral.
*
* @param {RegExpValidationState} state The state to validate RegExp.
* @returns {void}
*/
pp$8.validateRegExpFlags = function(state) {
var validFlags = state.validFlags;
var flags = state.flags;
for (var i = 0; i < flags.length; i++) {
var flag = flags.charAt(i);
if (validFlags.indexOf(flag) === -1) {
this.raise(state.start, "Invalid regular expression flag");
}
if (flags.indexOf(flag, i + 1) > -1) {
this.raise(state.start, "Duplicate regular expression flag");
}
}
};
/**
* Validate the pattern part of a given RegExpLiteral.
*
* @param {RegExpValidationState} state The state to validate RegExp.
* @returns {void}
*/
pp$8.validateRegExpPattern = function(state) {
this.regexp_pattern(state);
// The goal symbol for the parse is |Pattern[~U, ~N]|. If the result of
// parsing contains a |GroupName|, reparse with the goal symbol
// |Pattern[~U, +N]| and use this result instead. Throw a *SyntaxError*
// exception if _P_ did not conform to the grammar, if any elements of _P_
// were not matched by the parse, or if any Early Error conditions exist.
if (!state.switchN && this.options.ecmaVersion >= 9 && state.groupNames.length > 0) {
state.switchN = true;
this.regexp_pattern(state);
}
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern
pp$8.regexp_pattern = function(state) {
state.pos = 0;
state.lastIntValue = 0;
state.lastStringValue = "";
state.lastAssertionIsQuantifiable = false;
state.numCapturingParens = 0;
state.maxBackReference = 0;
state.groupNames.length = 0;
state.backReferenceNames.length = 0;
this.regexp_disjunction(state);
if (state.pos !== state.source.length) {
// Make the same messages as V8.
if (state.eat(0x29 /* ) */)) {
state.raise("Unmatched ')'");
}
if (state.eat(0x5D /* ] */) || state.eat(0x7D /* } */)) {
state.raise("Lone quantifier brackets");
}
}
if (state.maxBackReference > state.numCapturingParens) {
state.raise("Invalid escape");
}
for (var i = 0, list = state.backReferenceNames; i < list.length; i += 1) {
var name = list[i];
if (state.groupNames.indexOf(name) === -1) {
state.raise("Invalid named capture referenced");
}
}
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-Disjunction
pp$8.regexp_disjunction = function(state) {
this.regexp_alternative(state);
while (state.eat(0x7C /* | */)) {
this.regexp_alternative(state);
}
// Make the same message as V8.
if (this.regexp_eatQuantifier(state, true)) {
state.raise("Nothing to repeat");
}
if (state.eat(0x7B /* { */)) {
state.raise("Lone quantifier brackets");
}
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-Alternative
pp$8.regexp_alternative = function(state) {
while (state.pos < state.source.length && this.regexp_eatTerm(state))
{ }
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Term
pp$8.regexp_eatTerm = function(state) {
if (this.regexp_eatAssertion(state)) {
// Handle `QuantifiableAssertion Quantifier` alternative.
// `state.lastAssertionIsQuantifiable` is true if the last eaten Assertion
// is a QuantifiableAssertion.
if (state.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(state)) {
// Make the same message as V8.
if (state.switchU) {
state.raise("Invalid quantifier");
}
}
return true
}
if (state.switchU ? this.regexp_eatAtom(state) : this.regexp_eatExtendedAtom(state)) {
this.regexp_eatQuantifier(state);
return true
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-Assertion
pp$8.regexp_eatAssertion = function(state) {
var start = state.pos;
state.lastAssertionIsQuantifiable = false;
// ^, $
if (state.eat(0x5E /* ^ */) || state.eat(0x24 /* $ */)) {
return true
}
// \b \B
if (state.eat(0x5C /* \ */)) {
if (state.eat(0x42 /* B */) || state.eat(0x62 /* b */)) {
return true
}
state.pos = start;
}
// Lookahead / Lookbehind
if (state.eat(0x28 /* ( */) && state.eat(0x3F /* ? */)) {
var lookbehind = false;
if (this.options.ecmaVersion >= 9) {
lookbehind = state.eat(0x3C /* < */);
}
if (state.eat(0x3D /* = */) || state.eat(0x21 /* ! */)) {
this.regexp_disjunction(state);
if (!state.eat(0x29 /* ) */)) {
state.raise("Unterminated group");
}
state.lastAssertionIsQuantifiable = !lookbehind;
return true
}
}
state.pos = start;
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-Quantifier
pp$8.regexp_eatQuantifier = function(state, noError) {
if ( noError === void 0 ) noError = false;
if (this.regexp_eatQuantifierPrefix(state, noError)) {
state.eat(0x3F /* ? */);
return true
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-QuantifierPrefix
pp$8.regexp_eatQuantifierPrefix = function(state, noError) {
return (
state.eat(0x2A /* * */) ||
state.eat(0x2B /* + */) ||
state.eat(0x3F /* ? */) ||
this.regexp_eatBracedQuantifier(state, noError)
)
};
pp$8.regexp_eatBracedQuantifier = function(state, noError) {
var start = state.pos;
if (state.eat(0x7B /* { */)) {
var min = 0, max = -1;
if (this.regexp_eatDecimalDigits(state)) {
min = state.lastIntValue;
if (state.eat(0x2C /* , */) && this.regexp_eatDecimalDigits(state)) {
max = state.lastIntValue;
}
if (state.eat(0x7D /* } */)) {
// SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-term
if (max !== -1 && max < min && !noError) {
state.raise("numbers out of order in {} quantifier");
}
return true
}
}
if (state.switchU && !noError) {
state.raise("Incomplete quantifier");
}
state.pos = start;
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-Atom
pp$8.regexp_eatAtom = function(state) {
return (
this.regexp_eatPatternCharacters(state) ||
state.eat(0x2E /* . */) ||
this.regexp_eatReverseSolidusAtomEscape(state) ||
this.regexp_eatCharacterClass(state) ||
this.regexp_eatUncapturingGroup(state) ||
this.regexp_eatCapturingGroup(state)
)
};
pp$8.regexp_eatReverseSolidusAtomEscape = function(state) {
var start = state.pos;
if (state.eat(0x5C /* \ */)) {
if (this.regexp_eatAtomEscape(state)) {
return true
}
state.pos = start;
}
return false
};
pp$8.regexp_eatUncapturingGroup = function(state) {
var start = state.pos;
if (state.eat(0x28 /* ( */)) {
if (state.eat(0x3F /* ? */) && state.eat(0x3A /* : */)) {
this.regexp_disjunction(state);
if (state.eat(0x29 /* ) */)) {
return true
}
state.raise("Unterminated group");
}
state.pos = start;
}
return false
};
pp$8.regexp_eatCapturingGroup = function(state) {
if (state.eat(0x28 /* ( */)) {
if (this.options.ecmaVersion >= 9) {
this.regexp_groupSpecifier(state);
} else if (state.current() === 0x3F /* ? */) {
state.raise("Invalid group");
}
this.regexp_disjunction(state);
if (state.eat(0x29 /* ) */)) {
state.numCapturingParens += 1;
return true
}
state.raise("Unterminated group");
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedAtom
pp$8.regexp_eatExtendedAtom = function(state) {
return (
state.eat(0x2E /* . */) ||
this.regexp_eatReverseSolidusAtomEscape(state) ||
this.regexp_eatCharacterClass(state) ||
this.regexp_eatUncapturingGroup(state) ||
this.regexp_eatCapturingGroup(state) ||
this.regexp_eatInvalidBracedQuantifier(state) ||
this.regexp_eatExtendedPatternCharacter(state)
)
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-InvalidBracedQuantifier
pp$8.regexp_eatInvalidBracedQuantifier = function(state) {
if (this.regexp_eatBracedQuantifier(state, true)) {
state.raise("Nothing to repeat");
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-SyntaxCharacter
pp$8.regexp_eatSyntaxCharacter = function(state) {
var ch = state.current();
if (isSyntaxCharacter(ch)) {
state.lastIntValue = ch;
state.advance();
return true
}
return false
};
function isSyntaxCharacter(ch) {
return (
ch === 0x24 /* $ */ ||
ch >= 0x28 /* ( */ && ch <= 0x2B /* + */ ||
ch === 0x2E /* . */ ||
ch === 0x3F /* ? */ ||
ch >= 0x5B /* [ */ && ch <= 0x5E /* ^ */ ||
ch >= 0x7B /* { */ && ch <= 0x7D /* } */
)
}
// https://www.ecma-international.org/ecma-262/8.0/#prod-PatternCharacter
// But eat eager.
pp$8.regexp_eatPatternCharacters = function(state) {
var start = state.pos;
var ch = 0;
while ((ch = state.current()) !== -1 && !isSyntaxCharacter(ch)) {
state.advance();
}
return state.pos !== start
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ExtendedPatternCharacter
pp$8.regexp_eatExtendedPatternCharacter = function(state) {
var ch = state.current();
if (
ch !== -1 &&
ch !== 0x24 /* $ */ &&
!(ch >= 0x28 /* ( */ && ch <= 0x2B /* + */) &&
ch !== 0x2E /* . */ &&
ch !== 0x3F /* ? */ &&
ch !== 0x5B /* [ */ &&
ch !== 0x5E /* ^ */ &&
ch !== 0x7C /* | */
) {
state.advance();
return true
}
return false
};
// GroupSpecifier ::
// [empty]
// `?` GroupName
pp$8.regexp_groupSpecifier = function(state) {
if (state.eat(0x3F /* ? */)) {
if (this.regexp_eatGroupName(state)) {
if (state.groupNames.indexOf(state.lastStringValue) !== -1) {
state.raise("Duplicate capture group name");
}
state.groupNames.push(state.lastStringValue);
return
}
state.raise("Invalid group");
}
};
// GroupName ::
// `<` RegExpIdentifierName `>`
// Note: this updates `state.lastStringValue` property with the eaten name.
pp$8.regexp_eatGroupName = function(state) {
state.lastStringValue = "";
if (state.eat(0x3C /* < */)) {
if (this.regexp_eatRegExpIdentifierName(state) && state.eat(0x3E /* > */)) {
return true
}
state.raise("Invalid capture group name");
}
return false
};
// RegExpIdentifierName ::
// RegExpIdentifierStart
// RegExpIdentifierName RegExpIdentifierPart
// Note: this updates `state.lastStringValue` property with the eaten name.
pp$8.regexp_eatRegExpIdentifierName = function(state) {
state.lastStringValue = "";
if (this.regexp_eatRegExpIdentifierStart(state)) {
state.lastStringValue += codePointToString(state.lastIntValue);
while (this.regexp_eatRegExpIdentifierPart(state)) {
state.lastStringValue += codePointToString(state.lastIntValue);
}
return true
}
return false
};
// RegExpIdentifierStart ::
// UnicodeIDStart
// `$`
// `_`
// `\` RegExpUnicodeEscapeSequence[+U]
pp$8.regexp_eatRegExpIdentifierStart = function(state) {
var start = state.pos;
var forceU = this.options.ecmaVersion >= 11;
var ch = state.current(forceU);
state.advance(forceU);
if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
ch = state.lastIntValue;
}
if (isRegExpIdentifierStart(ch)) {
state.lastIntValue = ch;
return true
}
state.pos = start;
return false
};
function isRegExpIdentifierStart(ch) {
return isIdentifierStart(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */
}
// RegExpIdentifierPart ::
// UnicodeIDContinue
// `$`
// `_`
// `\` RegExpUnicodeEscapeSequence[+U]
// <ZWNJ>
// <ZWJ>
pp$8.regexp_eatRegExpIdentifierPart = function(state) {
var start = state.pos;
var forceU = this.options.ecmaVersion >= 11;
var ch = state.current(forceU);
state.advance(forceU);
if (ch === 0x5C /* \ */ && this.regexp_eatRegExpUnicodeEscapeSequence(state, forceU)) {
ch = state.lastIntValue;
}
if (isRegExpIdentifierPart(ch)) {
state.lastIntValue = ch;
return true
}
state.pos = start;
return false
};
function isRegExpIdentifierPart(ch) {
return isIdentifierChar(ch, true) || ch === 0x24 /* $ */ || ch === 0x5F /* _ */ || ch === 0x200C /* <ZWNJ> */ || ch === 0x200D /* <ZWJ> */
}
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-AtomEscape
pp$8.regexp_eatAtomEscape = function(state) {
if (
this.regexp_eatBackReference(state) ||
this.regexp_eatCharacterClassEscape(state) ||
this.regexp_eatCharacterEscape(state) ||
(state.switchN && this.regexp_eatKGroupName(state))
) {
return true
}
if (state.switchU) {
// Make the same message as V8.
if (state.current() === 0x63 /* c */) {
state.raise("Invalid unicode escape");
}
state.raise("Invalid escape");
}
return false
};
pp$8.regexp_eatBackReference = function(state) {
var start = state.pos;
if (this.regexp_eatDecimalEscape(state)) {
var n = state.lastIntValue;
if (state.switchU) {
// For SyntaxError in https://www.ecma-international.org/ecma-262/8.0/#sec-atomescape
if (n > state.maxBackReference) {
state.maxBackReference = n;
}
return true
}
if (n <= state.numCapturingParens) {
return true
}
state.pos = start;
}
return false
};
pp$8.regexp_eatKGroupName = function(state) {
if (state.eat(0x6B /* k */)) {
if (this.regexp_eatGroupName(state)) {
state.backReferenceNames.push(state.lastStringValue);
return true
}
state.raise("Invalid named reference");
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-CharacterEscape
pp$8.regexp_eatCharacterEscape = function(state) {
return (
this.regexp_eatControlEscape(state) ||
this.regexp_eatCControlLetter(state) ||
this.regexp_eatZero(state) ||
this.regexp_eatHexEscapeSequence(state) ||
this.regexp_eatRegExpUnicodeEscapeSequence(state, false) ||
(!state.switchU && this.regexp_eatLegacyOctalEscapeSequence(state)) ||
this.regexp_eatIdentityEscape(state)
)
};
pp$8.regexp_eatCControlLetter = function(state) {
var start = state.pos;
if (state.eat(0x63 /* c */)) {
if (this.regexp_eatControlLetter(state)) {
return true
}
state.pos = start;
}
return false
};
pp$8.regexp_eatZero = function(state) {
if (state.current() === 0x30 /* 0 */ && !isDecimalDigit(state.lookahead())) {
state.lastIntValue = 0;
state.advance();
return true
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlEscape
pp$8.regexp_eatControlEscape = function(state) {
var ch = state.current();
if (ch === 0x74 /* t */) {
state.lastIntValue = 0x09; /* \t */
state.advance();
return true
}
if (ch === 0x6E /* n */) {
state.lastIntValue = 0x0A; /* \n */
state.advance();
return true
}
if (ch === 0x76 /* v */) {
state.lastIntValue = 0x0B; /* \v */
state.advance();
return true
}
if (ch === 0x66 /* f */) {
state.lastIntValue = 0x0C; /* \f */
state.advance();
return true
}
if (ch === 0x72 /* r */) {
state.lastIntValue = 0x0D; /* \r */
state.advance();
return true
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-ControlLetter
pp$8.regexp_eatControlLetter = function(state) {
var ch = state.current();
if (isControlLetter(ch)) {
state.lastIntValue = ch % 0x20;
state.advance();
return true
}
return false
};
function isControlLetter(ch) {
return (
(ch >= 0x41 /* A */ && ch <= 0x5A /* Z */) ||
(ch >= 0x61 /* a */ && ch <= 0x7A /* z */)
)
}
// https://www.ecma-international.org/ecma-262/8.0/#prod-RegExpUnicodeEscapeSequence
pp$8.regexp_eatRegExpUnicodeEscapeSequence = function(state, forceU) {
if ( forceU === void 0 ) forceU = false;
var start = state.pos;
var switchU = forceU || state.switchU;
if (state.eat(0x75 /* u */)) {
if (this.regexp_eatFixedHexDigits(state, 4)) {
var lead = state.lastIntValue;
if (switchU && lead >= 0xD800 && lead <= 0xDBFF) {
var leadSurrogateEnd = state.pos;
if (state.eat(0x5C /* \ */) && state.eat(0x75 /* u */) && this.regexp_eatFixedHexDigits(state, 4)) {
var trail = state.lastIntValue;
if (trail >= 0xDC00 && trail <= 0xDFFF) {
state.lastIntValue = (lead - 0xD800) * 0x400 + (trail - 0xDC00) + 0x10000;
return true
}
}
state.pos = leadSurrogateEnd;
state.lastIntValue = lead;
}
return true
}
if (
switchU &&
state.eat(0x7B /* { */) &&
this.regexp_eatHexDigits(state) &&
state.eat(0x7D /* } */) &&
isValidUnicode(state.lastIntValue)
) {
return true
}
if (switchU) {
state.raise("Invalid unicode escape");
}
state.pos = start;
}
return false
};
function isValidUnicode(ch) {
return ch >= 0 && ch <= 0x10FFFF
}
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-IdentityEscape
pp$8.regexp_eatIdentityEscape = function(state) {
if (state.switchU) {
if (this.regexp_eatSyntaxCharacter(state)) {
return true
}
if (state.eat(0x2F /* / */)) {
state.lastIntValue = 0x2F; /* / */
return true
}
return false
}
var ch = state.current();
if (ch !== 0x63 /* c */ && (!state.switchN || ch !== 0x6B /* k */)) {
state.lastIntValue = ch;
state.advance();
return true
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalEscape
pp$8.regexp_eatDecimalEscape = function(state) {
state.lastIntValue = 0;
var ch = state.current();
if (ch >= 0x31 /* 1 */ && ch <= 0x39 /* 9 */) {
do {
state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
state.advance();
} while ((ch = state.current()) >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */)
return true
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClassEscape
pp$8.regexp_eatCharacterClassEscape = function(state) {
var ch = state.current();
if (isCharacterClassEscape(ch)) {
state.lastIntValue = -1;
state.advance();
return true
}
if (
state.switchU &&
this.options.ecmaVersion >= 9 &&
(ch === 0x50 /* P */ || ch === 0x70 /* p */)
) {
state.lastIntValue = -1;
state.advance();
if (
state.eat(0x7B /* { */) &&
this.regexp_eatUnicodePropertyValueExpression(state) &&
state.eat(0x7D /* } */)
) {
return true
}
state.raise("Invalid property name");
}
return false
};
function isCharacterClassEscape(ch) {
return (
ch === 0x64 /* d */ ||
ch === 0x44 /* D */ ||
ch === 0x73 /* s */ ||
ch === 0x53 /* S */ ||
ch === 0x77 /* w */ ||
ch === 0x57 /* W */
)
}
// UnicodePropertyValueExpression ::
// UnicodePropertyName `=` UnicodePropertyValue
// LoneUnicodePropertyNameOrValue
pp$8.regexp_eatUnicodePropertyValueExpression = function(state) {
var start = state.pos;
// UnicodePropertyName `=` UnicodePropertyValue
if (this.regexp_eatUnicodePropertyName(state) && state.eat(0x3D /* = */)) {
var name = state.lastStringValue;
if (this.regexp_eatUnicodePropertyValue(state)) {
var value = state.lastStringValue;
this.regexp_validateUnicodePropertyNameAndValue(state, name, value);
return true
}
}
state.pos = start;
// LoneUnicodePropertyNameOrValue
if (this.regexp_eatLoneUnicodePropertyNameOrValue(state)) {
var nameOrValue = state.lastStringValue;
this.regexp_validateUnicodePropertyNameOrValue(state, nameOrValue);
return true
}
return false
};
pp$8.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
if (!has(state.unicodeProperties.nonBinary, name))
{ state.raise("Invalid property name"); }
if (!state.unicodeProperties.nonBinary[name].test(value))
{ state.raise("Invalid property value"); }
};
pp$8.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
if (!state.unicodeProperties.binary.test(nameOrValue))
{ state.raise("Invalid property name"); }
};
// UnicodePropertyName ::
// UnicodePropertyNameCharacters
pp$8.regexp_eatUnicodePropertyName = function(state) {
var ch = 0;
state.lastStringValue = "";
while (isUnicodePropertyNameCharacter(ch = state.current())) {
state.lastStringValue += codePointToString(ch);
state.advance();
}
return state.lastStringValue !== ""
};
function isUnicodePropertyNameCharacter(ch) {
return isControlLetter(ch) || ch === 0x5F /* _ */
}
// UnicodePropertyValue ::
// UnicodePropertyValueCharacters
pp$8.regexp_eatUnicodePropertyValue = function(state) {
var ch = 0;
state.lastStringValue = "";
while (isUnicodePropertyValueCharacter(ch = state.current())) {
state.lastStringValue += codePointToString(ch);
state.advance();
}
return state.lastStringValue !== ""
};
function isUnicodePropertyValueCharacter(ch) {
return isUnicodePropertyNameCharacter(ch) || isDecimalDigit(ch)
}
// LoneUnicodePropertyNameOrValue ::
// UnicodePropertyValueCharacters
pp$8.regexp_eatLoneUnicodePropertyNameOrValue = function(state) {
return this.regexp_eatUnicodePropertyValue(state)
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-CharacterClass
pp$8.regexp_eatCharacterClass = function(state) {
if (state.eat(0x5B /* [ */)) {
state.eat(0x5E /* ^ */);
this.regexp_classRanges(state);
if (state.eat(0x5D /* ] */)) {
return true
}
// Unreachable since it threw "unterminated regular expression" error before.
state.raise("Unterminated character class");
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassRanges
// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRanges
// https://www.ecma-international.org/ecma-262/8.0/#prod-NonemptyClassRangesNoDash
pp$8.regexp_classRanges = function(state) {
while (this.regexp_eatClassAtom(state)) {
var left = state.lastIntValue;
if (state.eat(0x2D /* - */) && this.regexp_eatClassAtom(state)) {
var right = state.lastIntValue;
if (state.switchU && (left === -1 || right === -1)) {
state.raise("Invalid character class");
}
if (left !== -1 && right !== -1 && left > right) {
state.raise("Range out of order in character class");
}
}
}
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtom
// https://www.ecma-international.org/ecma-262/8.0/#prod-ClassAtomNoDash
pp$8.regexp_eatClassAtom = function(state) {
var start = state.pos;
if (state.eat(0x5C /* \ */)) {
if (this.regexp_eatClassEscape(state)) {
return true
}
if (state.switchU) {
// Make the same message as V8.
var ch$1 = state.current();
if (ch$1 === 0x63 /* c */ || isOctalDigit(ch$1)) {
state.raise("Invalid class escape");
}
state.raise("Invalid escape");
}
state.pos = start;
}
var ch = state.current();
if (ch !== 0x5D /* ] */) {
state.lastIntValue = ch;
state.advance();
return true
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassEscape
pp$8.regexp_eatClassEscape = function(state) {
var start = state.pos;
if (state.eat(0x62 /* b */)) {
state.lastIntValue = 0x08; /* <BS> */
return true
}
if (state.switchU && state.eat(0x2D /* - */)) {
state.lastIntValue = 0x2D; /* - */
return true
}
if (!state.switchU && state.eat(0x63 /* c */)) {
if (this.regexp_eatClassControlLetter(state)) {
return true
}
state.pos = start;
}
return (
this.regexp_eatCharacterClassEscape(state) ||
this.regexp_eatCharacterEscape(state)
)
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-ClassControlLetter
pp$8.regexp_eatClassControlLetter = function(state) {
var ch = state.current();
if (isDecimalDigit(ch) || ch === 0x5F /* _ */) {
state.lastIntValue = ch % 0x20;
state.advance();
return true
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
pp$8.regexp_eatHexEscapeSequence = function(state) {
var start = state.pos;
if (state.eat(0x78 /* x */)) {
if (this.regexp_eatFixedHexDigits(state, 2)) {
return true
}
if (state.switchU) {
state.raise("Invalid escape");
}
state.pos = start;
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-DecimalDigits
pp$8.regexp_eatDecimalDigits = function(state) {
var start = state.pos;
var ch = 0;
state.lastIntValue = 0;
while (isDecimalDigit(ch = state.current())) {
state.lastIntValue = 10 * state.lastIntValue + (ch - 0x30 /* 0 */);
state.advance();
}
return state.pos !== start
};
function isDecimalDigit(ch) {
return ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */
}
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigits
pp$8.regexp_eatHexDigits = function(state) {
var start = state.pos;
var ch = 0;
state.lastIntValue = 0;
while (isHexDigit(ch = state.current())) {
state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
state.advance();
}
return state.pos !== start
};
function isHexDigit(ch) {
return (
(ch >= 0x30 /* 0 */ && ch <= 0x39 /* 9 */) ||
(ch >= 0x41 /* A */ && ch <= 0x46 /* F */) ||
(ch >= 0x61 /* a */ && ch <= 0x66 /* f */)
)
}
function hexToInt(ch) {
if (ch >= 0x41 /* A */ && ch <= 0x46 /* F */) {
return 10 + (ch - 0x41 /* A */)
}
if (ch >= 0x61 /* a */ && ch <= 0x66 /* f */) {
return 10 + (ch - 0x61 /* a */)
}
return ch - 0x30 /* 0 */
}
// https://www.ecma-international.org/ecma-262/8.0/#prod-annexB-LegacyOctalEscapeSequence
// Allows only 0-377(octal) i.e. 0-255(decimal).
pp$8.regexp_eatLegacyOctalEscapeSequence = function(state) {
if (this.regexp_eatOctalDigit(state)) {
var n1 = state.lastIntValue;
if (this.regexp_eatOctalDigit(state)) {
var n2 = state.lastIntValue;
if (n1 <= 3 && this.regexp_eatOctalDigit(state)) {
state.lastIntValue = n1 * 64 + n2 * 8 + state.lastIntValue;
} else {
state.lastIntValue = n1 * 8 + n2;
}
} else {
state.lastIntValue = n1;
}
return true
}
return false
};
// https://www.ecma-international.org/ecma-262/8.0/#prod-OctalDigit
pp$8.regexp_eatOctalDigit = function(state) {
var ch = state.current();
if (isOctalDigit(ch)) {
state.lastIntValue = ch - 0x30; /* 0 */
state.advance();
return true
}
state.lastIntValue = 0;
return false
};
function isOctalDigit(ch) {
return ch >= 0x30 /* 0 */ && ch <= 0x37 /* 7 */
}
// https://www.ecma-international.org/ecma-262/8.0/#prod-Hex4Digits
// https://www.ecma-international.org/ecma-262/8.0/#prod-HexDigit
// And HexDigit HexDigit in https://www.ecma-international.org/ecma-262/8.0/#prod-HexEscapeSequence
pp$8.regexp_eatFixedHexDigits = function(state, length) {
var start = state.pos;
state.lastIntValue = 0;
for (var i = 0; i < length; ++i) {
var ch = state.current();
if (!isHexDigit(ch)) {
state.pos = start;
return false
}
state.lastIntValue = 16 * state.lastIntValue + hexToInt(ch);
state.advance();
}
return true
};
// Object type used to represent tokens. Note that normally, tokens
// simply exist as properties on the parser object. This is only
// used for the onToken callback and the external tokenizer.
var Token = function Token(p) {
this.type = p.type;
this.value = p.value;
this.start = p.start;
this.end = p.end;
if (p.options.locations)
{ this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
if (p.options.ranges)
{ this.range = [p.start, p.end]; }
};
// ## Tokenizer
var pp$9 = Parser.prototype;
// Move to the next token
pp$9.next = function(ignoreEscapeSequenceInKeyword) {
if (!ignoreEscapeSequenceInKeyword && this.type.keyword && this.containsEsc)
{ this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword); }
if (this.options.onToken)
{ this.options.onToken(new Token(this)); }
this.lastTokEnd = this.end;
this.lastTokStart = this.start;
this.lastTokEndLoc = this.endLoc;
this.lastTokStartLoc = this.startLoc;
this.nextToken();
};
pp$9.getToken = function() {
this.next();
return new Token(this)
};
// If we're in an ES6 environment, make parsers iterable
if (typeof Symbol !== "undefined")
{ pp$9[Symbol.iterator] = function() {
var this$1 = this;
return {
next: function () {
var token = this$1.getToken();
return {
done: token.type === types.eof,
value: token
}
}
}
}; }
// Toggle strict mode. Re-reads the next number or string to please
// pedantic tests (`"use strict"; 010;` should fail).
pp$9.curContext = function() {
return this.context[this.context.length - 1]
};
// Read a single token, updating the parser object's token-related
// properties.
pp$9.nextToken = function() {
var curContext = this.curContext();
if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
this.start = this.pos;
if (this.options.locations) { this.startLoc = this.curPosition(); }
if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
if (curContext.override) { return curContext.override(this) }
else { this.readToken(this.fullCharCodeAtPos()); }
};
pp$9.readToken = function(code) {
// Identifier or keyword. '\uXXXX' sequences are allowed in
// identifiers, so '\' also dispatches to that.
if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 /* '\' */)
{ return this.readWord() }
return this.getTokenFromCode(code)
};
pp$9.fullCharCodeAtPos = function() {
var code = this.input.charCodeAt(this.pos);
if (code <= 0xd7ff || code >= 0xe000) { return code }
var next = this.input.charCodeAt(this.pos + 1);
return (code << 10) + next - 0x35fdc00
};
pp$9.skipBlockComment = function() {
var startLoc = this.options.onComment && this.curPosition();
var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
this.pos = end + 2;
if (this.options.locations) {
lineBreakG.lastIndex = start;
var match;
while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
++this.curLine;
this.lineStart = match.index + match[0].length;
}
}
if (this.options.onComment)
{ this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
startLoc, this.curPosition()); }
};
pp$9.skipLineComment = function(startSkip) {
var start = this.pos;
var startLoc = this.options.onComment && this.curPosition();
var ch = this.input.charCodeAt(this.pos += startSkip);
while (this.pos < this.input.length && !isNewLine(ch)) {
ch = this.input.charCodeAt(++this.pos);
}
if (this.options.onComment)
{ this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
startLoc, this.curPosition()); }
};
// Called at the start of the parse and after every token. Skips
// whitespace and comments, and.
pp$9.skipSpace = function() {
loop: while (this.pos < this.input.length) {
var ch = this.input.charCodeAt(this.pos);
switch (ch) {
case 32: case 160: // ' '
++this.pos;
break
case 13:
if (this.input.charCodeAt(this.pos + 1) === 10) {
++this.pos;
}
case 10: case 8232: case 8233:
++this.pos;
if (this.options.locations) {
++this.curLine;
this.lineStart = this.pos;
}
break
case 47: // '/'
switch (this.input.charCodeAt(this.pos + 1)) {
case 42: // '*'
this.skipBlockComment();
break
case 47:
this.skipLineComment(2);
break
default:
break loop
}
break
default:
if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
++this.pos;
} else {
break loop
}
}
}
};
// Called at the end of every token. Sets `end`, `val`, and
// maintains `context` and `exprAllowed`, and skips the space after
// the token, so that the next one's `start` will point at the
// right position.
pp$9.finishToken = function(type, val) {
this.end = this.pos;
if (this.options.locations) { this.endLoc = this.curPosition(); }
var prevType = this.type;
this.type = type;
this.value = val;
this.updateContext(prevType);
};
// ### Token reading
// This is the function that is called to fetch the next token. It
// is somewhat obscure, because it works in character codes rather
// than characters, and because operator parsing has been inlined
// into it.
//
// All in the name of speed.
//
pp$9.readToken_dot = function() {
var next = this.input.charCodeAt(this.pos + 1);
if (next >= 48 && next <= 57) { return this.readNumber(true) }
var next2 = this.input.charCodeAt(this.pos + 2);
if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) { // 46 = dot '.'
this.pos += 3;
return this.finishToken(types.ellipsis)
} else {
++this.pos;
return this.finishToken(types.dot)
}
};
pp$9.readToken_slash = function() { // '/'
var next = this.input.charCodeAt(this.pos + 1);
if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
if (next === 61) { return this.finishOp(types.assign, 2) }
return this.finishOp(types.slash, 1)
};
pp$9.readToken_mult_modulo_exp = function(code) { // '%*'
var next = this.input.charCodeAt(this.pos + 1);
var size = 1;
var tokentype = code === 42 ? types.star : types.modulo;
// exponentiation operator ** and **=
if (this.options.ecmaVersion >= 7 && code === 42 && next === 42) {
++size;
tokentype = types.starstar;
next = this.input.charCodeAt(this.pos + 2);
}
if (next === 61) { return this.finishOp(types.assign, size + 1) }
return this.finishOp(tokentype, size)
};
pp$9.readToken_pipe_amp = function(code) { // '|&'
var next = this.input.charCodeAt(this.pos + 1);
if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
if (next === 61) { return this.finishOp(types.assign, 2) }
return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
};
pp$9.readToken_caret = function() { // '^'
var next = this.input.charCodeAt(this.pos + 1);
if (next === 61) { return this.finishOp(types.assign, 2) }
return this.finishOp(types.bitwiseXOR, 1)
};
pp$9.readToken_plus_min = function(code) { // '+-'
var next = this.input.charCodeAt(this.pos + 1);
if (next === code) {
if (next === 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 62 &&
(this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
// A `-->` line comment
this.skipLineComment(3);
this.skipSpace();
return this.nextToken()
}
return this.finishOp(types.incDec, 2)
}
if (next === 61) { return this.finishOp(types.assign, 2) }
return this.finishOp(types.plusMin, 1)
};
pp$9.readToken_lt_gt = function(code) { // '<>'
var next = this.input.charCodeAt(this.pos + 1);
var size = 1;
if (next === code) {
size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
return this.finishOp(types.bitShift, size)
}
if (next === 33 && code === 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) === 45 &&
this.input.charCodeAt(this.pos + 3) === 45) {
// `<!--`, an XML-style comment that should be interpreted as a line comment
this.skipLineComment(4);
this.skipSpace();
return this.nextToken()
}
if (next === 61) { size = 2; }
return this.finishOp(types.relational, size)
};
pp$9.readToken_eq_excl = function(code) { // '=!'
var next = this.input.charCodeAt(this.pos + 1);
if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) { // '=>'
this.pos += 2;
return this.finishToken(types.arrow)
}
return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
};
pp$9.readToken_question = function() { // '?'
if (this.options.ecmaVersion >= 11) {
var next = this.input.charCodeAt(this.pos + 1);
if (next === 46) {
var next2 = this.input.charCodeAt(this.pos + 2);
if (next2 < 48 || next2 > 57) { return this.finishOp(types.questionDot, 2) }
}
if (next === 63) { return this.finishOp(types.coalesce, 2) }
}
return this.finishOp(types.question, 1)
};
pp$9.getTokenFromCode = function(code) {
switch (code) {
// The interpretation of a dot depends on whether it is followed
// by a digit or another two dots.
case 46: // '.'
return this.readToken_dot()
// Punctuation tokens.
case 40: ++this.pos; return this.finishToken(types.parenL)
case 41: ++this.pos; return this.finishToken(types.parenR)
case 59: ++this.pos; return this.finishToken(types.semi)
case 44: ++this.pos; return this.finishToken(types.comma)
case 91: ++this.pos; return this.finishToken(types.bracketL)
case 93: ++this.pos; return this.finishToken(types.bracketR)
case 123: ++this.pos; return this.finishToken(types.braceL)
case 125: ++this.pos; return this.finishToken(types.braceR)
case 58: ++this.pos; return this.finishToken(types.colon)
case 96: // '`'
if (this.options.ecmaVersion < 6) { break }
++this.pos;
return this.finishToken(types.backQuote)
case 48: // '0'
var next = this.input.charCodeAt(this.pos + 1);
if (next === 120 || next === 88) { return this.readRadixNumber(16) } // '0x', '0X' - hex number
if (this.options.ecmaVersion >= 6) {
if (next === 111 || next === 79) { return this.readRadixNumber(8) } // '0o', '0O' - octal number
if (next === 98 || next === 66) { return this.readRadixNumber(2) } // '0b', '0B' - binary number
}
// Anything else beginning with a digit is an integer, octal
// number, or float.
case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9
return this.readNumber(false)
// Quotes produce strings.
case 34: case 39: // '"', "'"
return this.readString(code)
// Operators are parsed inline in tiny state machines. '=' (61) is
// often referred to. `finishOp` simply skips the amount of
// characters it is given as second argument, and returns a token
// of the type given by its first argument.
case 47: // '/'
return this.readToken_slash()
case 37: case 42: // '%*'
return this.readToken_mult_modulo_exp(code)
case 124: case 38: // '|&'
return this.readToken_pipe_amp(code)
case 94: // '^'
return this.readToken_caret()
case 43: case 45: // '+-'
return this.readToken_plus_min(code)
case 60: case 62: // '<>'
return this.readToken_lt_gt(code)
case 61: case 33: // '=!'
return this.readToken_eq_excl(code)
case 63: // '?'
return this.readToken_question()
case 126: // '~'
return this.finishOp(types.prefix, 1)
}
this.raise(this.pos, "Unexpected character '" + codePointToString$1(code) + "'");
};
pp$9.finishOp = function(type, size) {
var str = this.input.slice(this.pos, this.pos + size);
this.pos += size;
return this.finishToken(type, str)
};
pp$9.readRegexp = function() {
var escaped, inClass, start = this.pos;
for (;;) {
if (this.pos >= this.input.length) { this.raise(start, "Unterminated regular expression"); }
var ch = this.input.charAt(this.pos);
if (lineBreak.test(ch)) { this.raise(start, "Unterminated regular expression"); }
if (!escaped) {
if (ch === "[") { inClass = true; }
else if (ch === "]" && inClass) { inClass = false; }
else if (ch === "/" && !inClass) { break }
escaped = ch === "\\";
} else { escaped = false; }
++this.pos;
}
var pattern = this.input.slice(start, this.pos);
++this.pos;
var flagsStart = this.pos;
var flags = this.readWord1();
if (this.containsEsc) { this.unexpected(flagsStart); }
// Validate pattern
var state = this.regexpState || (this.regexpState = new RegExpValidationState(this));
state.reset(start, pattern, flags);
this.validateRegExpFlags(state);
this.validateRegExpPattern(state);
// Create Literal#value property value.
var value = null;
try {
value = new RegExp(pattern, flags);
} catch (e) {
// ESTree requires null if it failed to instantiate RegExp object.
// https://github.com/estree/estree/blob/a27003adf4fd7bfad44de9cef372a2eacd527b1c/es5.md#regexpliteral
}
return this.finishToken(types.regexp, {pattern: pattern, flags: flags, value: value})
};
// Read an integer in the given radix. Return null if zero digits
// were read, the integer value otherwise. When `len` is given, this
// will return `null` unless the integer has exactly `len` digits.
pp$9.readInt = function(radix, len) {
var start = this.pos, total = 0;
for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
var code = this.input.charCodeAt(this.pos), val = (void 0);
if (code >= 97) { val = code - 97 + 10; } // a
else if (code >= 65) { val = code - 65 + 10; } // A
else if (code >= 48 && code <= 57) { val = code - 48; } // 0-9
else { val = Infinity; }
if (val >= radix) { break }
++this.pos;
total = total * radix + val;
}
if (this.pos === start || len != null && this.pos - start !== len) { return null }
return total
};
pp$9.readRadixNumber = function(radix) {
var start = this.pos;
this.pos += 2; // 0x
var val = this.readInt(radix);
if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
if (this.options.ecmaVersion >= 11 && this.input.charCodeAt(this.pos) === 110) {
val = typeof BigInt !== "undefined" ? BigInt(this.input.slice(start, this.pos)) : null;
++this.pos;
} else if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
return this.finishToken(types.num, val)
};
// Read an integer, octal integer, or floating-point number.
pp$9.readNumber = function(startsWithDot) {
var start = this.pos;
if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
var octal = this.pos - start >= 2 && this.input.charCodeAt(start) === 48;
if (octal && this.strict) { this.raise(start, "Invalid number"); }
var next = this.input.charCodeAt(this.pos);
if (!octal && !startsWithDot && this.options.ecmaVersion >= 11 && next === 110) {
var str$1 = this.input.slice(start, this.pos);
var val$1 = typeof BigInt !== "undefined" ? BigInt(str$1) : null;
++this.pos;
if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
return this.finishToken(types.num, val$1)
}
if (octal && /[89]/.test(this.input.slice(start, this.pos))) { octal = false; }
if (next === 46 && !octal) { // '.'
++this.pos;
this.readInt(10);
next = this.input.charCodeAt(this.pos);
}
if ((next === 69 || next === 101) && !octal) { // 'eE'
next = this.input.charCodeAt(++this.pos);
if (next === 43 || next === 45) { ++this.pos; } // '+-'
if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
}
if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
var str = this.input.slice(start, this.pos);
var val = octal ? parseInt(str, 8) : parseFloat(str);
return this.finishToken(types.num, val)
};
// Read a string value, interpreting backslash-escapes.
pp$9.readCodePoint = function() {
var ch = this.input.charCodeAt(this.pos), code;
if (ch === 123) { // '{'
if (this.options.ecmaVersion < 6) { this.unexpected(); }
var codePos = ++this.pos;
code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
++this.pos;
if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
} else {
code = this.readHexChar(4);
}
return code
};
function codePointToString$1(code) {
// UTF-16 Decoding
if (code <= 0xFFFF) { return String.fromCharCode(code) }
code -= 0x10000;
return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
}
pp$9.readString = function(quote) {
var out = "", chunkStart = ++this.pos;
for (;;) {
if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated string constant"); }
var ch = this.input.charCodeAt(this.pos);
if (ch === quote) { break }
if (ch === 92) { // '\'
out += this.input.slice(chunkStart, this.pos);
out += this.readEscapedChar(false);
chunkStart = this.pos;
} else {
if (isNewLine(ch, this.options.ecmaVersion >= 10)) { this.raise(this.start, "Unterminated string constant"); }
++this.pos;
}
}
out += this.input.slice(chunkStart, this.pos++);
return this.finishToken(types.string, out)
};
// Reads template string tokens.
var INVALID_TEMPLATE_ESCAPE_ERROR = {};
pp$9.tryReadTemplateToken = function() {
this.inTemplateElement = true;
try {
this.readTmplToken();
} catch (err) {
if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
this.readInvalidTemplateToken();
} else {
throw err
}
}
this.inTemplateElement = false;
};
pp$9.invalidStringToken = function(position, message) {
if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
throw INVALID_TEMPLATE_ESCAPE_ERROR
} else {
this.raise(position, message);
}
};
pp$9.readTmplToken = function() {
var out = "", chunkStart = this.pos;
for (;;) {
if (this.pos >= this.input.length) { this.raise(this.start, "Unterminated template"); }
var ch = this.input.charCodeAt(this.pos);
if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) { // '`', '${'
if (this.pos === this.start && (this.type === types.template || this.type === types.invalidTemplate)) {
if (ch === 36) {
this.pos += 2;
return this.finishToken(types.dollarBraceL)
} else {
++this.pos;
return this.finishToken(types.backQuote)
}
}
out += this.input.slice(chunkStart, this.pos);
return this.finishToken(types.template, out)
}
if (ch === 92) { // '\'
out += this.input.slice(chunkStart, this.pos);
out += this.readEscapedChar(true);
chunkStart = this.pos;
} else if (isNewLine(ch)) {
out += this.input.slice(chunkStart, this.pos);
++this.pos;
switch (ch) {
case 13:
if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
case 10:
out += "\n";
break
default:
out += String.fromCharCode(ch);
break
}
if (this.options.locations) {
++this.curLine;
this.lineStart = this.pos;
}
chunkStart = this.pos;
} else {
++this.pos;
}
}
};
// Reads a template token to search for the end, without validating any escape sequences
pp$9.readInvalidTemplateToken = function() {
for (; this.pos < this.input.length; this.pos++) {
switch (this.input[this.pos]) {
case "\\":
++this.pos;
break
case "$":
if (this.input[this.pos + 1] !== "{") {
break
}
// falls through
case "`":
return this.finishToken(types.invalidTemplate, this.input.slice(this.start, this.pos))
// no default
}
}
this.raise(this.start, "Unterminated template");
};
// Used to read escaped characters
pp$9.readEscapedChar = function(inTemplate) {
var ch = this.input.charCodeAt(++this.pos);
++this.pos;
switch (ch) {
case 110: return "\n" // 'n' -> '\n'
case 114: return "\r" // 'r' -> '\r'
case 120: return String.fromCharCode(this.readHexChar(2)) // 'x'
case 117: return codePointToString$1(this.readCodePoint()) // 'u'
case 116: return "\t" // 't' -> '\t'
case 98: return "\b" // 'b' -> '\b'
case 118: return "\u000b" // 'v' -> '\u000b'
case 102: return "\f" // 'f' -> '\f'
case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; } // '\r\n'
case 10: // ' \n'
if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
return ""
case 56:
case 57:
if (inTemplate) {
var codePos = this.pos - 1;
this.invalidStringToken(
codePos,
"Invalid escape sequence in template string"
);
return null
}
default:
if (ch >= 48 && ch <= 55) {
var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
var octal = parseInt(octalStr, 8);
if (octal > 255) {
octalStr = octalStr.slice(0, -1);
octal = parseInt(octalStr, 8);
}
this.pos += octalStr.length - 1;
ch = this.input.charCodeAt(this.pos);
if ((octalStr !== "0" || ch === 56 || ch === 57) && (this.strict || inTemplate)) {
this.invalidStringToken(
this.pos - 1 - octalStr.length,
inTemplate
? "Octal literal in template string"
: "Octal literal in strict mode"
);
}
return String.fromCharCode(octal)
}
if (isNewLine(ch)) {
// Unicode new line characters after \ get removed from output in both
// template literals and strings
return ""
}
return String.fromCharCode(ch)
}
};
// Used to read character escape sequences ('\x', '\u', '\U').
pp$9.readHexChar = function(len) {
var codePos = this.pos;
var n = this.readInt(16, len);
if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
return n
};
// Read an identifier, and return it as a string. Sets `this.containsEsc`
// to whether the word contained a '\u' escape.
//
// Incrementally adds only escaped chars, adding other chunks as-is
// as a micro-optimization.
pp$9.readWord1 = function() {
this.containsEsc = false;
var word = "", first = true, chunkStart = this.pos;
var astral = this.options.ecmaVersion >= 6;
while (this.pos < this.input.length) {
var ch = this.fullCharCodeAtPos();
if (isIdentifierChar(ch, astral)) {
this.pos += ch <= 0xffff ? 1 : 2;
} else if (ch === 92) { // "\"
this.containsEsc = true;
word += this.input.slice(chunkStart, this.pos);
var escStart = this.pos;
if (this.input.charCodeAt(++this.pos) !== 117) // "u"
{ this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"); }
++this.pos;
var esc = this.readCodePoint();
if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
{ this.invalidStringToken(escStart, "Invalid Unicode escape"); }
word += codePointToString$1(esc);
chunkStart = this.pos;
} else {
break
}
first = false;
}
return word + this.input.slice(chunkStart, this.pos)
};
// Read an identifier or keyword token. Will check for reserved
// words when necessary.
pp$9.readWord = function() {
var word = this.readWord1();
var type = types.name;
if (this.keywords.test(word)) {
type = keywords$1[word];
}
return this.finishToken(type, word)
};
// Acorn is a tiny, fast JavaScript parser written in JavaScript.
var version = "7.3.1";
Parser.acorn = {
Parser: Parser,
version: version,
defaultOptions: defaultOptions,
Position: Position,
SourceLocation: SourceLocation,
getLineInfo: getLineInfo,
Node: Node,
TokenType: TokenType,
tokTypes: types,
keywordTypes: keywords$1,
TokContext: TokContext,
tokContexts: types$1,
isIdentifierChar: isIdentifierChar,
isIdentifierStart: isIdentifierStart,
Token: Token,
isNewLine: isNewLine,
lineBreak: lineBreak,
lineBreakG: lineBreakG,
nonASCIIwhitespace: nonASCIIwhitespace
};
// The main exported interface (under `self.acorn` when in the
// browser) is a `parse` function that takes a code string and
// returns an abstract syntax tree as specified by [Mozilla parser
// API][api].
//
// [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
function parse(input, options) {
return Parser.parse(input, options)
}
// This function tries to parse a single expression at a given
// offset in a string. Useful for parsing mixed-language formats
// that embed JavaScript expressions.
function parseExpressionAt(input, pos, options) {
return Parser.parseExpressionAt(input, pos, options)
}
function walk(ast, { enter, leave }) {
return visit(ast, null, enter, leave);
}
let should_skip = false;
let should_remove = false;
let replacement = null;
const context = {
skip: () => should_skip = true,
remove: () => should_remove = true,
replace: (node) => replacement = node
};
function replace(parent, prop, index, node) {
if (parent) {
if (index !== null) {
parent[prop][index] = node;
} else {
parent[prop] = node;
}
}
}
function remove(parent, prop, index) {
if (parent) {
if (index !== null) {
parent[prop].splice(index, 1);
} else {
delete parent[prop];
}
}
}
function visit(
node,
parent,
enter,
leave,
prop,
index
) {
if (node) {
if (enter) {
const _should_skip = should_skip;
const _should_remove = should_remove;
const _replacement = replacement;
should_skip = false;
should_remove = false;
replacement = null;
enter.call(context, node, parent, prop, index);
if (replacement) {
node = replacement;
replace(parent, prop, index, node);
}
if (should_remove) {
remove(parent, prop, index);
}
const skipped = should_skip;
const removed = should_remove;
should_skip = _should_skip;
should_remove = _should_remove;
replacement = _replacement;
if (skipped) return node;
if (removed) return null;
}
for (const key in node) {
const value = (node )[key];
if (typeof value !== 'object') {
continue;
}
else if (Array.isArray(value)) {
for (let j = 0, k = 0; j < value.length; j += 1, k += 1) {
if (value[j] !== null && typeof value[j].type === 'string') {
if (!visit(value[j], node, enter, leave, key, k)) {
// removed
j--;
}
}
}
}
else if (value !== null && typeof value.type === 'string') {
visit(value, node, enter, leave, key, null);
}
}
if (leave) {
const _replacement = replacement;
const _should_remove = should_remove;
replacement = null;
should_remove = false;
leave.call(context, node, parent, prop, index);
if (replacement) {
node = replacement;
replace(parent, prop, index, node);
}
if (should_remove) {
remove(parent, prop, index);
}
const removed = should_remove;
replacement = _replacement;
should_remove = _should_remove;
if (removed) return null;
}
}
return node;
}
function isReference(node, parent) {
if (node.type === 'MemberExpression') {
return !node.computed && isReference(node.object, node);
}
if (node.type === 'Identifier') {
if (!parent)
return true;
switch (parent.type) {
// disregard `bar` in `foo.bar`
case 'MemberExpression': return parent.computed || node === parent.object;
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
case 'MethodDefinition': return parent.computed;
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
case 'FieldDefinition': return parent.computed || node === parent.value;
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
case 'Property': return parent.computed || node === parent.value;
// disregard the `bar` in `export { foo as bar }` or
// the foo in `import { foo as bar }`
case 'ExportSpecifier':
case 'ImportSpecifier': return node === parent.local;
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
case 'LabeledStatement':
case 'BreakStatement':
case 'ContinueStatement': return false;
default: return true;
}
}
return false;
}
function analyze(expression) {
const map = new WeakMap();
let scope = new Scope$1(null, false);
walk(expression, {
enter(node, parent) {
if (node.type === 'ImportDeclaration') {
node.specifiers.forEach((specifier) => {
scope.declarations.set(specifier.local.name, specifier);
});
} else if (/(Function(Declaration|Expression)|ArrowFunctionExpression)/.test(node.type)) {
if (node.type === 'FunctionDeclaration') {
scope.declarations.set(node.id.name, node);
map.set(node, scope = new Scope$1(scope, false));
} else {
map.set(node, scope = new Scope$1(scope, false));
if (node.type === 'FunctionExpression' && node.id) scope.declarations.set(node.id.name, node);
}
node.params.forEach((param) => {
extract_names(param).forEach(name => {
scope.declarations.set(name, node);
});
});
} else if (/For(?:In|Of)?Statement/.test(node.type)) {
map.set(node, scope = new Scope$1(scope, true));
} else if (node.type === 'BlockStatement') {
map.set(node, scope = new Scope$1(scope, true));
} else if (/(Class|Variable)Declaration/.test(node.type)) {
scope.add_declaration(node);
} else if (node.type === 'CatchClause') {
map.set(node, scope = new Scope$1(scope, true));
if (node.param) {
extract_names(node.param).forEach(name => {
scope.declarations.set(name, node.param);
});
}
}
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
}
});
const globals = new Map();
walk(expression, {
enter(node, parent) {
if (map.has(node)) scope = map.get(node);
if (node.type === 'Identifier' && isReference(node, parent)) {
const owner = scope.find_owner(node.name);
if (!owner) globals.set(node.name, node);
add_reference(scope, node.name);
}
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
}
});
return { map, scope, globals };
}
function add_reference(scope, name) {
scope.references.add(name);
if (scope.parent) add_reference(scope.parent, name);
}
class Scope$1 {
__init() {this.declarations = new Map();}
__init2() {this.initialised_declarations = new Set();}
__init3() {this.references = new Set();}
constructor(parent, block) {Scope$1.prototype.__init.call(this);Scope$1.prototype.__init2.call(this);Scope$1.prototype.__init3.call(this);
this.parent = parent;
this.block = block;
}
add_declaration(node) {
if (node.type === 'VariableDeclaration') {
if (node.kind === 'var' && this.block && this.parent) {
this.parent.add_declaration(node);
} else if (node.type === 'VariableDeclaration') {
node.declarations.forEach((declarator) => {
extract_names(declarator.id).forEach(name => {
this.declarations.set(name, node);
if (declarator.init) this.initialised_declarations.add(name);
});
});
}
} else {
this.declarations.set(node.id.name, node);
}
}
find_owner(name) {
if (this.declarations.has(name)) return this;
return this.parent && this.parent.find_owner(name);
}
has(name) {
return (
this.declarations.has(name) || (this.parent && this.parent.has(name))
);
}
}
function extract_names(param) {
return extract_identifiers(param).map(node => node.name);
}
function extract_identifiers(param) {
const nodes = [];
extractors[param.type] && extractors[param.type](nodes, param);
return nodes;
}
const extractors = {
Identifier(nodes, param) {
nodes.push(param);
},
MemberExpression(nodes, param) {
let object = param;
while (object.type === 'MemberExpression') object = object.object;
nodes.push(object);
},
ObjectPattern(nodes, param) {
param.properties.forEach((prop) => {
if (prop.type === 'RestElement') {
nodes.push(prop.argument);
} else {
extractors[prop.value.type](nodes, prop.value);
}
});
},
ArrayPattern(nodes, param) {
param.elements.forEach((element) => {
if (element) extractors[element.type](nodes, element);
});
},
RestElement(nodes, param) {
extractors[param.argument.type](nodes, param.argument);
},
AssignmentPattern(nodes, param) {
extractors[param.left.type](nodes, param.left);
}
};
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
function encode(decoded) {
var sourceFileIndex = 0; // second field
var sourceCodeLine = 0; // third field
var sourceCodeColumn = 0; // fourth field
var nameIndex = 0; // fifth field
var mappings = '';
for (var i = 0; i < decoded.length; i++) {
var line = decoded[i];
if (i > 0)
mappings += ';';
if (line.length === 0)
continue;
var generatedCodeColumn = 0; // first field
var lineMappings = [];
for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
var segment = line_1[_i];
var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
generatedCodeColumn = segment[0];
if (segment.length > 1) {
segmentMappings +=
encodeInteger(segment[1] - sourceFileIndex) +
encodeInteger(segment[2] - sourceCodeLine) +
encodeInteger(segment[3] - sourceCodeColumn);
sourceFileIndex = segment[1];
sourceCodeLine = segment[2];
sourceCodeColumn = segment[3];
}
if (segment.length === 5) {
segmentMappings += encodeInteger(segment[4] - nameIndex);
nameIndex = segment[4];
}
lineMappings.push(segmentMappings);
}
mappings += lineMappings.join(',');
}
return mappings;
}
function encodeInteger(num) {
var result = '';
num = num < 0 ? (-num << 1) | 1 : num << 1;
do {
var clamped = num & 31;
num >>>= 5;
if (num > 0) {
clamped |= 32;
}
result += chars[clamped];
} while (num > 0);
return result;
}
// generate an ID that is, to all intents and purposes, unique
const id = (Math.round(Math.random() * 1e20)).toString(36);
const re = new RegExp(`_${id}_(?:(\\d+)|(AT)|(HASH))_(\\w+)?`, 'g');
const get_comment_handlers = (comments, raw) => ({
// pass to acorn options
onComment: (block, value, start, end) => {
if (block && /\n/.test(value)) {
let a = start;
while (a > 0 && raw[a - 1] !== '\n') a -= 1;
let b = a;
while (/[ \t]/.test(raw[b])) b += 1;
const indentation = raw.slice(a, b);
value = value.replace(new RegExp(`^${indentation}`, 'gm'), '');
}
comments.push({ type: block ? 'Block' : 'Line', value, start, end });
},
// pass to estree-walker options
enter(node) {
let comment;
while (comments[0] && comments[0].start < (node ).start) {
comment = comments.shift();
comment.value = comment.value.replace(re, (match, id, at, hash, value) => {
if (hash) return `#${value}`;
if (at) return `@${value}`;
return match;
});
const next = comments[0] || node;
(comment ).has_trailing_newline = (
comment.type === 'Line' ||
/\n/.test(raw.slice(comment.end, (next ).start))
);
(node.leadingComments || (node.leadingComments = [])).push(comment);
}
},
leave(node) {
if (comments[0]) {
const slice = raw.slice((node ).end, comments[0].start);
if (/^[,) \t]*$/.test(slice)) {
node.trailingComments = [comments.shift()];
}
}
}
});
function handle(node, state) {
const handler = handlers[node.type];
if (!handler) {
throw new Error(`Not implemented ${node.type}`);
}
const result = handler(node, state);
if (node.leadingComments) {
result.unshift(c(node.leadingComments.map(comment => comment.type === 'Block'
? `/*${comment.value}*/${(comment ).has_trailing_newline ? `\n${state.indent}` : ` `}`
: `//${comment.value}${(comment ).has_trailing_newline ? `\n${state.indent}` : ` `}`).join(``)));
}
if (node.trailingComments) {
state.comments.push(node.trailingComments[0]); // there is only ever one
}
return result;
}
function c(content, node) {
return {
content,
loc: node && node.loc,
has_newline: /\n/.test(content)
};
}
const OPERATOR_PRECEDENCE = {
'||': 2,
'&&': 3,
'??': 4,
'|': 5,
'^': 6,
'&': 7,
'==': 8,
'!=': 8,
'===': 8,
'!==': 8,
'<': 9,
'>': 9,
'<=': 9,
'>=': 9,
in: 9,
instanceof: 9,
'<<': 10,
'>>': 10,
'>>>': 10,
'+': 11,
'-': 11,
'*': 12,
'%': 12,
'/': 12,
'**': 13,
};
const EXPRESSIONS_PRECEDENCE = {
ArrayExpression: 20,
TaggedTemplateExpression: 20,
ThisExpression: 20,
Identifier: 20,
Literal: 18,
TemplateLiteral: 20,
Super: 20,
SequenceExpression: 20,
MemberExpression: 19,
CallExpression: 19,
NewExpression: 19,
AwaitExpression: 17,
ClassExpression: 17,
FunctionExpression: 17,
ObjectExpression: 17,
UpdateExpression: 16,
UnaryExpression: 15,
BinaryExpression: 14,
LogicalExpression: 13,
ConditionalExpression: 4,
ArrowFunctionExpression: 3,
AssignmentExpression: 3,
YieldExpression: 2,
RestElement: 1
};
function needs_parens(node, parent, is_right) {
const precedence = EXPRESSIONS_PRECEDENCE[node.type];
const parent_precedence = EXPRESSIONS_PRECEDENCE[parent.type];
if (precedence !== parent_precedence) {
// Different node types
return (
(!is_right &&
precedence === 15 &&
parent_precedence === 14 &&
parent.operator === '**') ||
precedence < parent_precedence
);
}
if (precedence !== 13 && precedence !== 14) {
// Not a `LogicalExpression` or `BinaryExpression`
return false;
}
if ((node ).operator === '**' && parent.operator === '**') {
// Exponentiation operator has right-to-left associativity
return !is_right;
}
if (is_right) {
// Parenthesis are used if both operators have the same precedence
return (
OPERATOR_PRECEDENCE[(node ).operator] <=
OPERATOR_PRECEDENCE[parent.operator]
);
}
return (
OPERATOR_PRECEDENCE[(node ).operator] <
OPERATOR_PRECEDENCE[parent.operator]
);
}
function has_call_expression(node) {
while (node) {
if (node.type[0] === 'CallExpression') {
return true;
} else if (node.type === 'MemberExpression') {
node = node.object;
} else {
return false;
}
}
}
const has_newline = (chunks) => {
for (let i = 0; i < chunks.length; i += 1) {
if (chunks[i].has_newline) return true;
}
return false;
};
const get_length = (chunks) => {
let total = 0;
for (let i = 0; i < chunks.length; i += 1) {
total += chunks[i].content.length;
}
return total;
};
const sum = (a, b) => a + b;
const join = (nodes, separator) => {
if (nodes.length === 0) return [];
const joined = [...nodes[0]];
for (let i = 1; i < nodes.length; i += 1) {
joined.push(separator, ...nodes[i] );
}
return joined;
};
const scoped = (fn) => {
return (node, state) => {
return fn(node, {
...state,
scope: state.scope_map.get(node)
});
};
};
const deconflict = (name, names) => {
const original = name;
let i = 1;
while (names.has(name)) {
name = `${original}$${i++}`;
}
return name;
};
const handle_body = (nodes, state) => {
const chunks = [];
const body = nodes.map(statement => {
const chunks = handle(statement, {
...state,
indent: state.indent
});
let add_newline = false;
while (state.comments.length) {
const comment = state.comments.shift();
const prefix = add_newline ? `\n${state.indent}` : ` `;
chunks.push(c(comment.type === 'Block'
? `${prefix}/*${comment.value}*/`
: `${prefix}//${comment.value}`));
add_newline = (comment.type === 'Line');
}
return chunks;
});
let needed_padding = false;
for (let i = 0; i < body.length; i += 1) {
const needs_padding = has_newline(body[i]);
if (i > 0) {
chunks.push(
c(needs_padding || needed_padding ? `\n\n${state.indent}` : `\n${state.indent}`)
);
}
chunks.push(
...body[i]
);
needed_padding = needs_padding;
}
return chunks;
};
const handle_var_declaration = (node, state) => {
const chunks = [c(`${node.kind} `)];
const declarators = node.declarations.map(d => handle(d, {
...state,
indent: state.indent + (node.declarations.length === 1 ? '' : '\t')
}));
const multiple_lines = (
declarators.some(has_newline) ||
(declarators.map(get_length).reduce(sum, 0) + (state.indent.length + declarators.length - 1) * 2) > 80
);
const separator = c(multiple_lines ? `,\n${state.indent}\t` : ', ');
if (multiple_lines) {
chunks.push(...join(declarators, separator));
} else {
chunks.push(
...join(declarators, separator)
);
}
return chunks;
};
const handlers = {
Program(node, state) {
return handle_body(node.body, state);
},
BlockStatement: scoped((node, state) => {
return [
c(`{\n${state.indent}\t`),
...handle_body(node.body, { ...state, indent: state.indent + '\t' }),
c(`\n${state.indent}}`)
];
}),
EmptyStatement(node, state) {
return [];
},
ParenthesizedExpression(node, state) {
return handle(node.expression, state);
},
ExpressionStatement(node, state) {
if (
node.expression.type === 'AssignmentExpression' &&
node.expression.left.type === 'ObjectPattern'
) {
// is an AssignmentExpression to an ObjectPattern
return [
c('('),
...handle(node.expression, state),
c(');')
];
}
return [
...handle(node.expression, state),
c(';')
];
},
IfStatement(node, state) {
const chunks = [
c('if ('),
...handle(node.test, state),
c(') '),
...handle(node.consequent, state)
];
if (node.alternate) {
chunks.push(
c(' else '),
...handle(node.alternate, state)
);
}
return chunks;
},
LabeledStatement(node, state) {
return [
...handle(node.label, state),
c(': '),
...handle(node.body, state)
];
},
BreakStatement(node, state) {
return node.label
? [c('break '), ...handle(node.label, state), c(';')]
: [c('break;')];
},
ContinueStatement(node, state) {
return node.label
? [c('continue '), ...handle(node.label, state), c(';')]
: [c('continue;')];
},
WithStatement(node, state) {
return [
c('with ('),
...handle(node.object, state),
c(') '),
...handle(node.body, state)
];
},
SwitchStatement(node, state) {
const chunks = [
c('switch ('),
...handle(node.discriminant, state),
c(') {')
];
node.cases.forEach(block => {
if (block.test) {
chunks.push(
c(`\n${state.indent}\tcase `),
...handle(block.test, { ...state, indent: `${state.indent}\t` }),
c(':')
);
} else {
chunks.push(c(`\n${state.indent}\tdefault:`));
}
block.consequent.forEach(statement => {
chunks.push(
c(`\n${state.indent}\t\t`),
...handle(statement, { ...state, indent: `${state.indent}\t\t` })
);
});
});
chunks.push(c(`\n${state.indent}}`));
return chunks;
},
ReturnStatement(node, state) {
if (node.argument) {
return [
c('return '),
...handle(node.argument, state),
c(';')
];
} else {
return [c('return;')];
}
},
ThrowStatement(node, state) {
return [
c('throw '),
...handle(node.argument, state),
c(';')
];
},
TryStatement(node, state) {
const chunks = [
c('try '),
...handle(node.block, state)
];
if (node.handler) {
if (node.handler.param) {
chunks.push(
c(' catch('),
...handle(node.handler.param, state),
c(') ')
);
} else {
chunks.push(c(' catch '));
}
chunks.push(...handle(node.handler.body, state));
}
if (node.finalizer) {
chunks.push(c(' finally '), ...handle(node.finalizer, state));
}
return chunks;
},
WhileStatement(node, state) {
return [
c('while ('),
...handle(node.test, state),
c(') '),
...handle(node.body, state)
];
},
DoWhileStatement(node, state) {
return [
c('do '),
...handle(node.body, state),
c(' while ('),
...handle(node.test, state),
c(');')
];
},
ForStatement: scoped((node, state) => {
const chunks = [c('for (')];
if (node.init) {
if ((node.init ).type === 'VariableDeclaration') {
chunks.push(...handle_var_declaration(node.init , state));
} else {
chunks.push(...handle(node.init, state));
}
}
chunks.push(c('; '));
if (node.test) chunks.push(...handle(node.test, state));
chunks.push(c('; '));
if (node.update) chunks.push(...handle(node.update, state));
chunks.push(
c(') '),
...handle(node.body, state)
);
return chunks;
}),
ForInStatement: scoped((node, state) => {
const chunks = [
c(`for ${(node ).await ? 'await ' : ''}(`)
];
if ((node.left ).type === 'VariableDeclaration') {
chunks.push(...handle_var_declaration(node.left , state));
} else {
chunks.push(...handle(node.left, state));
}
chunks.push(
c(node.type === 'ForInStatement' ? ` in ` : ` of `),
...handle(node.right, state),
c(') '),
...handle(node.body, state)
);
return chunks;
}),
DebuggerStatement(node, state) {
return [c('debugger', node), c(';')];
},
FunctionDeclaration: scoped((node, state) => {
const chunks = [];
if (node.async) chunks.push(c('async '));
chunks.push(c(node.generator ? 'function* ' : 'function '));
if (node.id) chunks.push(...handle(node.id, state));
chunks.push(c('('));
const params = node.params.map(p => handle(p, {
...state,
indent: state.indent + '\t'
}));
const multiple_lines = (
params.some(has_newline) ||
(params.map(get_length).reduce(sum, 0) + (state.indent.length + params.length - 1) * 2) > 80
);
const separator = c(multiple_lines ? `,\n${state.indent}` : ', ');
if (multiple_lines) {
chunks.push(
c(`\n${state.indent}\t`),
...join(params, separator),
c(`\n${state.indent}`)
);
} else {
chunks.push(
...join(params, separator)
);
}
chunks.push(
c(') '),
...handle(node.body, state)
);
return chunks;
}),
VariableDeclaration(node, state) {
return handle_var_declaration(node, state).concat(c(';'));
},
VariableDeclarator(node, state) {
if (node.init) {
return [
...handle(node.id, state),
c(' = '),
...handle(node.init, state)
];
} else {
return handle(node.id, state);
}
},
ClassDeclaration(node, state) {
const chunks = [c('class ')];
if (node.id) chunks.push(...handle(node.id, state), c(' '));
if (node.superClass) {
chunks.push(
c('extends '),
...handle(node.superClass, state),
c(' ')
);
}
chunks.push(...handle(node.body, state));
return chunks;
},
ImportDeclaration(node, state) {
const chunks = [c('import ')];
const { length } = node.specifiers;
const source = handle(node.source, state);
if (length > 0) {
let i = 0;
while (i < length) {
if (i > 0) {
chunks.push(c(', '));
}
const specifier = node.specifiers[i];
if (specifier.type === 'ImportDefaultSpecifier') {
chunks.push(c(specifier.local.name, specifier));
i += 1;
} else if (specifier.type === 'ImportNamespaceSpecifier') {
chunks.push(c('* as ' + specifier.local.name, specifier));
i += 1;
} else {
break;
}
}
if (i < length) {
// we have named specifiers
const specifiers = node.specifiers.slice(i).map((specifier) => {
const name = handle(specifier.imported, state)[0];
const as = handle(specifier.local, state)[0];
if (name.content === as.content) {
return [as];
}
return [name, c(' as '), as];
});
const width = get_length(chunks) + specifiers.map(get_length).reduce(sum, 0) + (2 * specifiers.length) + 6 + get_length(source);
if (width > 80) {
chunks.push(
c(`{\n\t`),
...join(specifiers, c(',\n\t')),
c('\n}')
);
} else {
chunks.push(
c(`{ `),
...join(specifiers, c(', ')),
c(' }')
);
}
}
chunks.push(c(' from '));
}
chunks.push(
...source,
c(';')
);
return chunks;
},
ImportExpression(node, state) {
return [c('import('), ...handle(node.source, state), c(')')];
},
ExportDefaultDeclaration(node, state) {
const chunks = [
c(`export default `),
...handle(node.declaration, state)
];
if (node.declaration.type !== 'FunctionDeclaration') {
chunks.push(c(';'));
}
return chunks;
},
ExportNamedDeclaration(node, state) {
const chunks = [c('export ')];
if (node.declaration) {
chunks.push(...handle(node.declaration, state));
} else {
const specifiers = node.specifiers.map(specifier => {
const name = handle(specifier.local, state)[0];
const as = handle(specifier.exported, state)[0];
if (name.content === as.content) {
return [name];
}
return [name, c(' as '), as];
});
const width = 7 + specifiers.map(get_length).reduce(sum, 0) + 2 * specifiers.length;
if (width > 80) {
chunks.push(
c('{\n\t'),
...join(specifiers, c(',\n\t')),
c('\n}')
);
} else {
chunks.push(
c('{ '),
...join(specifiers, c(', ')),
c(' }')
);
}
if (node.source) {
chunks.push(
c(' from '),
...handle(node.source, state)
);
}
}
chunks.push(c(';'));
return chunks;
},
ExportAllDeclaration(node, state) {
return [
c(`export * from `),
...handle(node.source, state),
c(`;`)
];
},
MethodDefinition(node, state) {
const chunks = [];
if (node.static) {
chunks.push(c('static '));
}
if (node.kind === 'get' || node.kind === 'set') {
// Getter or setter
chunks.push(c(node.kind + ' '));
}
if (node.value.async) {
chunks.push(c('async '));
}
if (node.value.generator) {
chunks.push(c('*'));
}
if (node.computed) {
chunks.push(
c('['),
...handle(node.key, state),
c(']')
);
} else {
chunks.push(...handle(node.key, state));
}
chunks.push(c('('));
const { params } = node.value;
for (let i = 0; i < params.length; i += 1) {
chunks.push(...handle(params[i], state));
if (i < params.length - 1) chunks.push(c(', '));
}
chunks.push(
c(') '),
...handle(node.value.body, state)
);
return chunks;
},
ArrowFunctionExpression: scoped((node, state) => {
const chunks = [];
if (node.async) chunks.push(c('async '));
if (node.params.length === 1 && node.params[0].type === 'Identifier') {
chunks.push(...handle(node.params[0], state));
} else {
const params = node.params.map(param => handle(param, {
...state,
indent: state.indent + '\t'
}));
chunks.push(
c('('),
...join(params, c(', ')),
c(')')
);
}
chunks.push(c(' => '));
if (node.body.type === 'ObjectExpression') {
chunks.push(
c('('),
...handle(node.body, state),
c(')')
);
} else {
chunks.push(...handle(node.body, state));
}
return chunks;
}),
ThisExpression(node, state) {
return [c('this', node)];
},
Super(node, state) {
return [c('super', node)];
},
RestElement(node, state) {
return [c('...'), ...handle(node.argument, state)];
},
YieldExpression(node, state) {
if (node.argument) {
return [c(node.delegate ? `yield* ` : `yield `), ...handle(node.argument, state)];
}
return [c(node.delegate ? `yield*` : `yield`)];
},
AwaitExpression(node, state) {
if (node.argument) {
const precedence = EXPRESSIONS_PRECEDENCE[node.argument.type];
if (precedence && (precedence < EXPRESSIONS_PRECEDENCE.AwaitExpression)) {
return [c('await ('), ...handle(node.argument, state), c(')')];
} else {
return [c('await '), ...handle(node.argument, state)];
}
}
return [c('await')];
},
TemplateLiteral(node, state) {
const chunks = [c('`')];
const { quasis, expressions } = node;
for (let i = 0; i < expressions.length; i++) {
chunks.push(
c(quasis[i].value.raw),
c('${'),
...handle(expressions[i], state),
c('}')
);
}
chunks.push(
c(quasis[quasis.length - 1].value.raw),
c('`')
);
return chunks;
},
TaggedTemplateExpression(node, state) {
return handle(node.tag, state).concat(handle(node.quasi, state));
},
ArrayExpression(node, state) {
const chunks = [c('[')];
const elements = [];
let sparse_commas = [];
for (let i = 0; i < node.elements.length; i += 1) {
// can't use map/forEach because of sparse arrays
const element = node.elements[i];
if (element) {
elements.push([...sparse_commas, ...handle(element, {
...state,
indent: state.indent + '\t'
})]);
sparse_commas = [];
} else {
sparse_commas.push(c(','));
}
}
const multiple_lines = (
elements.some(has_newline) ||
(elements.map(get_length).reduce(sum, 0) + (state.indent.length + elements.length - 1) * 2) > 80
);
if (multiple_lines) {
chunks.push(
c(`\n${state.indent}\t`),
...join(elements, c(`,\n${state.indent}\t`)),
c(`\n${state.indent}`),
...sparse_commas
);
} else {
chunks.push(...join(elements, c(', ')), ...sparse_commas);
}
chunks.push(c(']'));
return chunks;
},
ObjectExpression(node, state) {
if (node.properties.length === 0) {
return [c('{}')];
}
let has_inline_comment = false;
const chunks = [];
const separator = c(', ');
node.properties.forEach((p, i) => {
chunks.push(...handle(p, {
...state,
indent: state.indent + '\t'
}));
if (state.comments.length) {
// TODO generalise this, so it works with ArrayExpressions and other things.
// At present, stuff will just get appended to the closest statement/declaration
chunks.push(c(', '));
while (state.comments.length) {
const comment = state.comments.shift();
chunks.push(c(comment.type === 'Block'
? `/*${comment.value}*/\n${state.indent}\t`
: `//${comment.value}\n${state.indent}\t`));
if (comment.type === 'Line') {
has_inline_comment = true;
}
}
} else {
if (i < node.properties.length - 1) {
chunks.push(separator);
}
}
});
const multiple_lines = (
has_inline_comment ||
has_newline(chunks) ||
get_length(chunks) > 40
);
if (multiple_lines) {
separator.content = `,\n${state.indent}\t`;
}
return [
c(multiple_lines ? `{\n${state.indent}\t` : `{ `),
...chunks,
c(multiple_lines ? `\n${state.indent}}` : ` }`)
];
},
Property(node, state) {
const value = handle(node.value, state);
if (node.key === node.value) {
return value;
}
// special case
if (
!node.computed &&
node.value.type === 'AssignmentPattern' &&
node.value.left.type === 'Identifier' &&
node.value.left.name === (node.key ).name
) {
return value;
}
if (node.value.type === 'Identifier' && (
(node.key.type === 'Identifier' && node.key.name === value[0].content) ||
(node.key.type === 'Literal' && node.key.value === value[0].content)
)) {
return value;
}
const key = handle(node.key, state);
if (node.value.type === 'FunctionExpression' && !node.value.id) {
state = {
...state,
scope: state.scope_map.get(node.value)
};
const chunks = node.kind !== 'init'
? [c(`${node.kind} `)]
: [];
if (node.value.async) {
chunks.push(c('async '));
}
if (node.value.generator) {
chunks.push(c('*'));
}
chunks.push(
...(node.computed ? [c('['), ...key, c(']')] : key),
c('('),
...join((node.value ).params.map(param => handle(param, state)), c(', ')),
c(') '),
...handle((node.value ).body, state)
);
return chunks;
}
if (node.computed) {
return [
c('['),
...key,
c(']: '),
...value
];
}
return [
...key,
c(': '),
...value
];
},
ObjectPattern(node, state) {
const chunks = [c('{ ')];
for (let i = 0; i < node.properties.length; i += 1) {
chunks.push(...handle(node.properties[i], state));
if (i < node.properties.length - 1) chunks.push(c(', '));
}
chunks.push(c(' }'));
return chunks;
},
SequenceExpression(node, state) {
const expressions = node.expressions.map(e => handle(e, state));
return [
c('('),
...join(expressions, c(', ')),
c(')')
];
},
UnaryExpression(node, state) {
const chunks = [c(node.operator)];
if (node.operator.length > 1) {
chunks.push(c(' '));
}
if (
EXPRESSIONS_PRECEDENCE[node.argument.type] <
EXPRESSIONS_PRECEDENCE.UnaryExpression
) {
chunks.push(
c('('),
...handle(node.argument, state),
c(')')
);
} else {
chunks.push(...handle(node.argument, state));
}
return chunks;
},
UpdateExpression(node, state) {
return node.prefix
? [c(node.operator), ...handle(node.argument, state)]
: [...handle(node.argument, state), c(node.operator)];
},
AssignmentExpression(node, state) {
return [
...handle(node.left, state),
c(` ${node.operator || '='} `),
...handle(node.right, state)
];
},
BinaryExpression(node, state) {
const chunks = [];
// TODO
// const is_in = node.operator === 'in';
// if (is_in) {
// // Avoids confusion in `for` loops initializers
// chunks.push(c('('));
// }
if (needs_parens(node.left, node, false)) {
chunks.push(
c('('),
...handle(node.left, state),
c(')')
);
} else {
chunks.push(...handle(node.left, state));
}
chunks.push(c(` ${node.operator} `));
if (needs_parens(node.right, node, true)) {
chunks.push(
c('('),
...handle(node.right, state),
c(')')
);
} else {
chunks.push(...handle(node.right, state));
}
return chunks;
},
ConditionalExpression(node, state) {
const chunks = [];
if (
EXPRESSIONS_PRECEDENCE[node.test.type] >
EXPRESSIONS_PRECEDENCE.ConditionalExpression
) {
chunks.push(...handle(node.test, state));
} else {
chunks.push(
c('('),
...handle(node.test, state),
c(')')
);
}
const child_state = { ...state, indent: state.indent + '\t' };
const consequent = handle(node.consequent, child_state);
const alternate = handle(node.alternate, child_state);
const multiple_lines = (
has_newline(consequent) || has_newline(alternate) ||
get_length(chunks) + get_length(consequent) + get_length(alternate) > 50
);
if (multiple_lines) {
chunks.push(
c(`\n${state.indent}? `),
...consequent,
c(`\n${state.indent}: `),
...alternate
);
} else {
chunks.push(
c(` ? `),
...consequent,
c(` : `),
...alternate
);
}
return chunks;
},
NewExpression(node, state) {
const chunks = [c('new ')];
if (
EXPRESSIONS_PRECEDENCE[node.callee.type] <
EXPRESSIONS_PRECEDENCE.CallExpression || has_call_expression(node.callee)
) {
chunks.push(
c('('),
...handle(node.callee, state),
c(')')
);
} else {
chunks.push(...handle(node.callee, state));
}
// TODO this is copied from CallExpression — DRY it out
const args = node.arguments.map(arg => handle(arg, {
...state,
indent: state.indent + '\t'
}));
const separator = args.some(has_newline) // TODO or length exceeds 80
? c(',\n' + state.indent)
: c(', ');
chunks.push(
c('('),
...join(args, separator) ,
c(')')
);
return chunks;
},
ChainExpression(node, state) {
return handle(node.expression, state);
},
CallExpression(node, state) {
const chunks = [];
if (
EXPRESSIONS_PRECEDENCE[node.callee.type] <
EXPRESSIONS_PRECEDENCE.CallExpression
) {
chunks.push(
c('('),
...handle(node.callee, state),
c(')')
);
} else {
chunks.push(...handle(node.callee, state));
}
if ((node ).optional) {
chunks.push(c('?.'));
}
const args = node.arguments.map(arg => handle(arg, state));
const multiple_lines = args.slice(0, -1).some(has_newline); // TODO or length exceeds 80
if (multiple_lines) {
// need to handle args again. TODO find alternative approach?
const args = node.arguments.map(arg => handle(arg, {
...state,
indent: `${state.indent}\t`
}));
chunks.push(
c(`(\n${state.indent}\t`),
...join(args, c(`,\n${state.indent}\t`)),
c(`\n${state.indent})`)
);
} else {
chunks.push(
c('('),
...join(args, c(', ')),
c(')')
);
}
return chunks;
},
MemberExpression(node, state) {
const chunks = [];
if (EXPRESSIONS_PRECEDENCE[node.object.type] < EXPRESSIONS_PRECEDENCE.MemberExpression) {
chunks.push(
c('('),
...handle(node.object, state),
c(')')
);
} else {
chunks.push(...handle(node.object, state));
}
if (node.computed) {
if (node.optional) {
chunks.push(c('?.'));
}
chunks.push(
c('['),
...handle(node.property, state),
c(']')
);
} else {
chunks.push(
c(node.optional ? '?.' : '.'),
...handle(node.property, state)
);
}
return chunks;
},
MetaProperty(node, state) {
return [...handle(node.meta, state), c('.'), ...handle(node.property, state)];
},
Identifier(node, state) {
let name = node.name;
if (name[0] === '@') {
name = state.getName(name.slice(1));
} else if (node.name[0] === '#') {
const owner = state.scope.find_owner(node.name);
if (!owner) {
throw new Error(`Could not find owner for node`);
}
if (!state.deconflicted.has(owner)) {
state.deconflicted.set(owner, new Map());
}
const deconflict_map = state.deconflicted.get(owner);
if (!deconflict_map.has(node.name)) {
deconflict_map.set(node.name, deconflict(node.name.slice(1), owner.references));
}
name = deconflict_map.get(node.name);
}
return [c(name, node)];
},
Literal(node, state) {
if (typeof node.value === 'string') {
return [
// TODO do we need to handle weird unicode characters somehow?
// str.replace(/\\u(\d{4})/g, (m, n) => String.fromCharCode(+n))
c(JSON.stringify(node.value).replace(re, (_m, _i, at, hash, name) => {
if (at) return '@' + name;
if (hash) return '#' + name;
throw new Error(`this shouldn't happen`);
}), node)
];
}
const { regex } = node ; // TODO is this right?
if (regex) {
return [c(`/${regex.pattern}/${regex.flags}`, node)];
}
return [c(String(node.value), node)];
}
};
handlers.ForOfStatement = handlers.ForInStatement;
handlers.FunctionExpression = handlers.FunctionDeclaration;
handlers.ClassExpression = handlers.ClassDeclaration;
handlers.ClassBody = handlers.BlockStatement;
handlers.SpreadElement = handlers.RestElement;
handlers.ArrayPattern = handlers.ArrayExpression;
handlers.LogicalExpression = handlers.BinaryExpression;
handlers.AssignmentPattern = handlers.AssignmentExpression;
let btoa = () => {
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
};
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
} else if (typeof Buffer === 'function') {
btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
}
function print(node, opts = {}) {
if (Array.isArray(node)) {
return print({
type: 'Program',
body: node
} , opts);
}
const {
getName = (x) => {
throw new Error(`Unhandled sigil @${x}`);
}
} = opts;
let { map: scope_map, scope } = analyze(node);
const deconflicted = new WeakMap();
const chunks = handle(node, {
indent: '',
getName,
scope,
scope_map,
deconflicted,
comments: []
});
let code = '';
let mappings = [];
let current_line = [];
let current_column = 0;
for (let i = 0; i < chunks.length; i += 1) {
const chunk = chunks[i];
code += chunk.content;
if (chunk.loc) {
current_line.push([
current_column,
0, // source index is always zero
chunk.loc.start.line - 1,
chunk.loc.start.column,
]);
}
for (let i = 0; i < chunk.content.length; i += 1) {
if (chunk.content[i] === '\n') {
mappings.push(current_line);
current_line = [];
current_column = 0;
} else {
current_column += 1;
}
}
if (chunk.loc) {
current_line.push([
current_column,
0, // source index is always zero
chunk.loc.end.line - 1,
chunk.loc.end.column,
]);
}
}
mappings.push(current_line);
const map = {
version: 3,
names: [] ,
sources: [opts.sourceMapSource || null],
sourcesContent: [opts.sourceMapContent || null],
mappings: encode(mappings)
};
Object.defineProperties(map, {
toString: {
enumerable: false,
value: function toString() {
return JSON.stringify(this);
}
},
toUrl: {
enumerable: false,
value: function toUrl() {
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
}
}
});
return {
code,
map
};
}
const sigils = {
'@': 'AT',
'#': 'HASH'
};
const join$1 = (strings) => {
let str = strings[0];
for (let i = 1; i < strings.length; i += 1) {
str += `_${id}_${i - 1}_${strings[i]}`;
}
return str.replace(/([@#])(\w+)/g, (_m, sigil, name) => `_${id}_${sigils[sigil]}_${name}`);
};
const flatten_body = (array, target) => {
for (let i = 0; i < array.length; i += 1) {
const statement = array[i];
if (Array.isArray(statement)) {
flatten_body(statement, target);
continue;
}
if (statement.type === 'ExpressionStatement') {
if (statement.expression === EMPTY) continue;
if (Array.isArray(statement.expression)) {
// TODO this is hacktacular
let node = statement.expression[0];
while (Array.isArray(node)) node = node[0];
if (node) node.leadingComments = statement.leadingComments;
flatten_body(statement.expression, target);
continue;
}
if (/(Expression|Literal)$/.test(statement.expression.type)) {
target.push(statement);
continue;
}
if (statement.leadingComments) statement.expression.leadingComments = statement.leadingComments;
if (statement.trailingComments) statement.expression.trailingComments = statement.trailingComments;
target.push(statement.expression);
continue;
}
target.push(statement);
}
return target;
};
const flatten_properties = (array, target) => {
for (let i = 0; i < array.length; i += 1) {
const property = array[i];
if (property.value === EMPTY) continue;
if (property.key === property.value && Array.isArray(property.key)) {
flatten_properties(property.key, target);
continue;
}
target.push(property);
}
return target;
};
const flatten = (nodes, target) => {
for (let i = 0; i < nodes.length; i += 1) {
const node = nodes[i];
if (node === EMPTY) continue;
if (Array.isArray(node)) {
flatten(node, target);
continue;
}
target.push(node);
}
return target;
};
const EMPTY = { type: 'Empty' };
const acorn_opts = (comments, raw) => {
const { onComment } = get_comment_handlers(comments, raw);
return {
ecmaVersion: 2020,
sourceType: 'module',
allowAwaitOutsideFunction: true,
allowImportExportEverywhere: true,
allowReturnOutsideFunction: true,
onComment
} ;
};
const inject = (raw, node, values, comments) => {
comments.forEach(comment => {
comment.value = comment.value.replace(re, (m, i) => +i in values ? values[+i] : m);
});
const { enter, leave } = get_comment_handlers(comments, raw);
walk(node, {
enter,
leave(node, parent, key, index) {
if (node.type === 'Identifier') {
re.lastIndex = 0;
const match = re.exec(node.name);
if (match) {
if (match[1]) {
if (+match[1] in values) {
let value = values[+match[1]];
if (typeof value === 'string') {
value = { type: 'Identifier', name: value, leadingComments: node.leadingComments, trailingComments: node.trailingComments };
} else if (typeof value === 'number') {
value = { type: 'Literal', value, leadingComments: node.leadingComments, trailingComments: node.trailingComments };
}
this.replace(value || EMPTY);
}
} else {
node.name = `${match[2] ? `@` : `#`}${match[4]}`;
}
}
}
if (node.type === 'Literal') {
if (typeof node.value === 'string') {
re.lastIndex = 0;
node.value = node.value.replace(re, (m, i) => +i in values ? values[+i] : m);
}
}
if (node.type === 'TemplateElement') {
re.lastIndex = 0;
node.value.raw = (node.value.raw ).replace(re, (m, i) => +i in values ? values[+i] : m);
}
if (node.type === 'Program' || node.type === 'BlockStatement') {
node.body = flatten_body(node.body, []);
}
if (node.type === 'ObjectExpression' || node.type === 'ObjectPattern') {
node.properties = flatten_properties(node.properties, []);
}
if (node.type === 'ArrayExpression' || node.type === 'ArrayPattern') {
node.elements = flatten(node.elements, []);
}
if (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ArrowFunctionExpression') {
node.params = flatten(node.params, []);
}
if (node.type === 'CallExpression' || node.type === 'NewExpression') {
node.arguments = flatten(node.arguments, []);
}
if (node.type === 'ImportDeclaration' || node.type === 'ExportNamedDeclaration') {
node.specifiers = flatten(node.specifiers, []);
}
if (node.type === 'ForStatement') {
node.init = node.init === EMPTY ? null : node.init;
node.test = node.test === EMPTY ? null : node.test;
node.update = node.update === EMPTY ? null : node.update;
}
leave(node);
}
});
};
function b(strings, ...values) {
const str = join$1(strings);
const comments = [];
try {
const ast = parse(str, acorn_opts(comments, str));
inject(str, ast, values, comments);
return ast.body;
} catch (err) {
handle_error(str, err);
}
}
function x(strings, ...values) {
const str = join$1(strings);
const comments = [];
try {
const expression = parseExpressionAt(str, 0, acorn_opts(comments, str)) ;
const match = /\S+/.exec(str.slice((expression ).end));
if (match) {
throw new Error(`Unexpected token '${match[0]}'`);
}
inject(str, expression, values, comments);
return expression;
} catch (err) {
handle_error(str, err);
}
}
function p(strings, ...values) {
const str = `{${join$1(strings)}}`;
const comments = [];
try {
const expression = parseExpressionAt(str, 0, acorn_opts(comments, str)) ;
inject(str, expression, values, comments);
return expression.properties[0];
} catch (err) {
handle_error(str, err);
}
}
function handle_error(str, err) {
// TODO location/code frame
re.lastIndex = 0;
str = str.replace(re, (m, i, at, hash, name) => {
if (at) return `@${name}`;
if (hash) return `#${name}`;
return '${...}';
});
console.log(`failed to parse:\n${str}`);
throw err;
}
const parse$1 = (source, opts) => {
const comments = [];
const { onComment, enter, leave } = get_comment_handlers(comments, source);
const ast = parse(source, { onComment, ...opts });
walk(ast , { enter, leave });
return ast;
};
const parseExpressionAt$1 = (source, index, opts) => {
const comments = [];
const { onComment, enter, leave } = get_comment_handlers(comments, source);
const ast = parseExpressionAt(source, index, { onComment, ...opts });
walk(ast , { enter, leave });
return ast;
};
const parse$2 = (source) => parse$1(source, {
sourceType: 'module',
ecmaVersion: 11,
locations: true
});
const parse_expression_at = (source, index) => parseExpressionAt$1(source, index, {
ecmaVersion: 11,
locations: true
});
const whitespace = /[ \t\r\n]/;
const dimensions = /^(?:offset|client)(?:Width|Height)$/;
function read_expression(parser) {
try {
const node = parse_expression_at(parser.template, parser.index);
let num_parens = 0;
for (let i = parser.index; i < node.start; i += 1) {
if (parser.template[i] === '(')
num_parens += 1;
}
let index = node.end;
while (num_parens > 0) {
const char = parser.template[index];
if (char === ')') {
num_parens -= 1;
}
else if (!whitespace.test(char)) {
parser.error({
code: 'unexpected-token',
message: 'Expected )'
}, index);
}
index += 1;
}
parser.index = index;
return node;
}
catch (err) {
parser.acorn_error(err);
}
}
const script_closing_tag = '</script>';
function get_context(parser, attributes, start) {
const context = attributes.find(attribute => attribute.name === 'context');
if (!context)
return 'default';
if (context.value.length !== 1 || context.value[0].type !== 'Text') {
parser.error({
code: 'invalid-script',
message: `context attribute must be static`
}, start);
}
const value = context.value[0].data;
if (value !== 'module') {
parser.error({
code: `invalid-script`,
message: `If the context attribute is supplied, its value must be "module"`
}, context.start);
}
return value;
}
function read_script(parser, start, attributes) {
const script_start = parser.index;
const script_end = parser.template.indexOf(script_closing_tag, script_start);
if (script_end === -1)
parser.error({
code: `unclosed-script`,
message: `<script> must have a closing tag`
});
const source = parser.template.slice(0, script_start).replace(/[^\n]/g, ' ') +
parser.template.slice(script_start, script_end);
parser.index = script_end + script_closing_tag.length;
let ast;
try {
ast = parse$2(source);
}
catch (err) {
parser.acorn_error(err);
}
// TODO is this necessary?
ast.start = script_start;
return {
type: 'Script',
start,
end: parser.index,
context: get_context(parser, attributes, start),
content: ast,
};
}
var MAX_LINE_LENGTH = 100;
var OFFSET_CORRECTION = 60;
var TAB_REPLACEMENT = ' ';
function sourceFragment(error, extraLines) {
function processLines(start, end) {
return lines.slice(start, end).map(function(line, idx) {
var num = String(start + idx + 1);
while (num.length < maxNumLength) {
num = ' ' + num;
}
return num + ' |' + line;
}).join('\n');
}
var lines = error.source.split(/\n|\r\n?|\f/);
var line = error.line;
var column = error.column;
var startLine = Math.max(1, line - extraLines) - 1;
var endLine = Math.min(line + extraLines, lines.length + 1);
var maxNumLength = Math.max(4, String(endLine).length) + 1;
var cutLeft = 0;
// correct column according to replaced tab before column
column += (TAB_REPLACEMENT.length - 1) * (lines[line - 1].substr(0, column - 1).match(/\t/g) || []).length;
if (column > MAX_LINE_LENGTH) {
cutLeft = column - OFFSET_CORRECTION + 3;
column = OFFSET_CORRECTION - 2;
}
for (var i = startLine; i <= endLine; i++) {
if (i >= 0 && i < lines.length) {
lines[i] = lines[i].replace(/\t/g, TAB_REPLACEMENT);
lines[i] =
(cutLeft > 0 && lines[i].length > cutLeft ? '\u2026' : '') +
lines[i].substr(cutLeft, MAX_LINE_LENGTH - 2) +
(lines[i].length > cutLeft + MAX_LINE_LENGTH - 1 ? '\u2026' : '');
}
}
return [
processLines(startLine, line),
new Array(column + maxNumLength + 2).join('-') + '^',
processLines(line, endLine)
].join('\n');
}
var CssSyntaxError = function(message, source, offset, line, column) {
// some VMs prevent setting line/column otherwise (iOS Safari 10 even throw an exception)
var error = Object.create(SyntaxError.prototype);
error.name = 'CssSyntaxError';
error.message = message;
error.stack = (new Error().stack || '').replace(/^.+\n/, error.name + ': ' + error.message + '\n');
error.source = source;
error.offset = offset;
error.line = line;
error.column = column;
error.sourceFragment = function(extraLines) {
return sourceFragment(error, isNaN(extraLines) ? 0 : extraLines);
};
Object.defineProperty(error, 'formattedMessage', {
get: function() {
return (
'Parse error: ' + error.message + '\n' +
sourceFragment(error, 2)
);
}
});
// for backward capability
error.parseError = {
offset: offset,
line: line,
column: column
};
return error;
};
var error = CssSyntaxError;
// token types (note: value shouldn't intersect with used char codes)
var WHITESPACE = 1;
var IDENTIFIER = 2;
var NUMBER = 3;
var STRING = 4;
var COMMENT = 5;
var PUNCTUATOR = 6;
var CDO = 7;
var CDC = 8;
var ATRULE = 14;
var FUNCTION = 15;
var URL = 16;
var RAW = 17;
var TAB = 9;
var N = 10;
var F = 12;
var R = 13;
var SPACE = 32;
var TYPE = {
WhiteSpace: WHITESPACE,
Identifier: IDENTIFIER,
Number: NUMBER,
String: STRING,
Comment: COMMENT,
Punctuator: PUNCTUATOR,
CDO: CDO,
CDC: CDC,
Atrule: ATRULE,
Function: FUNCTION,
Url: URL,
Raw: RAW,
ExclamationMark: 33, // !
QuotationMark: 34, // "
NumberSign: 35, // #
DollarSign: 36, // $
PercentSign: 37, // %
Ampersand: 38, // &
Apostrophe: 39, // '
LeftParenthesis: 40, // (
RightParenthesis: 41, // )
Asterisk: 42, // *
PlusSign: 43, // +
Comma: 44, // ,
HyphenMinus: 45, // -
FullStop: 46, // .
Solidus: 47, // /
Colon: 58, // :
Semicolon: 59, // ;
LessThanSign: 60, // <
EqualsSign: 61, // =
GreaterThanSign: 62, // >
QuestionMark: 63, // ?
CommercialAt: 64, // @
LeftSquareBracket: 91, // [
Backslash: 92, // \
RightSquareBracket: 93, // ]
CircumflexAccent: 94, // ^
LowLine: 95, // _
GraveAccent: 96, // `
LeftCurlyBracket: 123, // {
VerticalLine: 124, // |
RightCurlyBracket: 125, // }
Tilde: 126 // ~
};
var NAME = Object.keys(TYPE).reduce(function(result, key) {
result[TYPE[key]] = key;
return result;
}, {});
// https://drafts.csswg.org/css-syntax/#tokenizer-definitions
// > non-ASCII code point
// > A code point with a value equal to or greater than U+0080 <control>
// > name-start code point
// > A letter, a non-ASCII code point, or U+005F LOW LINE (_).
// > name code point
// > A name-start code point, a digit, or U+002D HYPHEN-MINUS (-)
// That means only ASCII code points has a special meaning and we a maps for 0..127 codes only
var SafeUint32Array = typeof Uint32Array !== 'undefined' ? Uint32Array : Array; // fallback on Array when TypedArray is not supported
var SYMBOL_TYPE = new SafeUint32Array(0x80);
var PUNCTUATION = new SafeUint32Array(0x80);
var STOP_URL_RAW = new SafeUint32Array(0x80);
for (var i = 0; i < SYMBOL_TYPE.length; i++) {
SYMBOL_TYPE[i] = IDENTIFIER;
}
// fill categories
[
TYPE.ExclamationMark, // !
TYPE.QuotationMark, // "
TYPE.NumberSign, // #
TYPE.DollarSign, // $
TYPE.PercentSign, // %
TYPE.Ampersand, // &
TYPE.Apostrophe, // '
TYPE.LeftParenthesis, // (
TYPE.RightParenthesis, // )
TYPE.Asterisk, // *
TYPE.PlusSign, // +
TYPE.Comma, // ,
TYPE.HyphenMinus, // -
TYPE.FullStop, // .
TYPE.Solidus, // /
TYPE.Colon, // :
TYPE.Semicolon, // ;
TYPE.LessThanSign, // <
TYPE.EqualsSign, // =
TYPE.GreaterThanSign, // >
TYPE.QuestionMark, // ?
TYPE.CommercialAt, // @
TYPE.LeftSquareBracket, // [
// TYPE.Backslash, // \
TYPE.RightSquareBracket, // ]
TYPE.CircumflexAccent, // ^
// TYPE.LowLine, // _
TYPE.GraveAccent, // `
TYPE.LeftCurlyBracket, // {
TYPE.VerticalLine, // |
TYPE.RightCurlyBracket, // }
TYPE.Tilde // ~
].forEach(function(key) {
SYMBOL_TYPE[Number(key)] = PUNCTUATOR;
PUNCTUATION[Number(key)] = PUNCTUATOR;
});
for (var i = 48; i <= 57; i++) {
SYMBOL_TYPE[i] = NUMBER;
}
SYMBOL_TYPE[SPACE] = WHITESPACE;
SYMBOL_TYPE[TAB] = WHITESPACE;
SYMBOL_TYPE[N] = WHITESPACE;
SYMBOL_TYPE[R] = WHITESPACE;
SYMBOL_TYPE[F] = WHITESPACE;
SYMBOL_TYPE[TYPE.Apostrophe] = STRING;
SYMBOL_TYPE[TYPE.QuotationMark] = STRING;
STOP_URL_RAW[SPACE] = 1;
STOP_URL_RAW[TAB] = 1;
STOP_URL_RAW[N] = 1;
STOP_URL_RAW[R] = 1;
STOP_URL_RAW[F] = 1;
STOP_URL_RAW[TYPE.Apostrophe] = 1;
STOP_URL_RAW[TYPE.QuotationMark] = 1;
STOP_URL_RAW[TYPE.LeftParenthesis] = 1;
STOP_URL_RAW[TYPE.RightParenthesis] = 1;
// whitespace is punctuation ...
PUNCTUATION[SPACE] = PUNCTUATOR;
PUNCTUATION[TAB] = PUNCTUATOR;
PUNCTUATION[N] = PUNCTUATOR;
PUNCTUATION[R] = PUNCTUATOR;
PUNCTUATION[F] = PUNCTUATOR;
// ... hyper minus is not
PUNCTUATION[TYPE.HyphenMinus] = 0;
var _const = {
TYPE: TYPE,
NAME: NAME,
SYMBOL_TYPE: SYMBOL_TYPE,
PUNCTUATION: PUNCTUATION,
STOP_URL_RAW: STOP_URL_RAW
};
var PUNCTUATION$1 = _const.PUNCTUATION;
var STOP_URL_RAW$1 = _const.STOP_URL_RAW;
var TYPE$1 = _const.TYPE;
var FULLSTOP = TYPE$1.FullStop;
var PLUSSIGN = TYPE$1.PlusSign;
var HYPHENMINUS = TYPE$1.HyphenMinus;
var PUNCTUATOR$1 = TYPE$1.Punctuator;
var TAB$1 = 9;
var N$1 = 10;
var F$1 = 12;
var R$1 = 13;
var SPACE$1 = 32;
var BACK_SLASH = 92;
var E = 101; // 'e'.charCodeAt(0)
function firstCharOffset(source) {
// detect BOM (https://en.wikipedia.org/wiki/Byte_order_mark)
if (source.charCodeAt(0) === 0xFEFF || // UTF-16BE
source.charCodeAt(0) === 0xFFFE) { // UTF-16LE
return 1;
}
return 0;
}
function isHex(code) {
return (code >= 48 && code <= 57) || // 0 .. 9
(code >= 65 && code <= 70) || // A .. F
(code >= 97 && code <= 102); // a .. f
}
function isNumber(code) {
return code >= 48 && code <= 57;
}
function isNewline(source, offset, code) {
if (code === N$1 || code === F$1 || code === R$1) {
if (code === R$1 && offset + 1 < source.length && source.charCodeAt(offset + 1) === N$1) {
return 2;
}
return 1;
}
return 0;
}
function cmpChar(testStr, offset, referenceCode) {
var code = testStr.charCodeAt(offset);
// code.toLowerCase()
if (code >= 65 && code <= 90) {
code = code | 32;
}
return code === referenceCode;
}
function cmpStr(testStr, start, end, referenceStr) {
if (end - start !== referenceStr.length) {
return false;
}
if (start < 0 || end > testStr.length) {
return false;
}
for (var i = start; i < end; i++) {
var testCode = testStr.charCodeAt(i);
var refCode = referenceStr.charCodeAt(i - start);
// testStr[i].toLowerCase()
if (testCode >= 65 && testCode <= 90) {
testCode = testCode | 32;
}
if (testCode !== refCode) {
return false;
}
}
return true;
}
function endsWith(testStr, referenceStr) {
return cmpStr(testStr, testStr.length - referenceStr.length, testStr.length, referenceStr);
}
function findLastNonSpaceLocation(scanner) {
for (var i = scanner.source.length - 1; i >= 0; i--) {
var code = scanner.source.charCodeAt(i);
if (code !== SPACE$1 && code !== TAB$1 && code !== R$1 && code !== N$1 && code !== F$1) {
break;
}
}
return scanner.getLocation(i + 1);
}
function findWhiteSpaceEnd(source, offset) {
for (; offset < source.length; offset++) {
var code = source.charCodeAt(offset);
if (code !== SPACE$1 && code !== TAB$1 && code !== R$1 && code !== N$1 && code !== F$1) {
break;
}
}
return offset;
}
function findCommentEnd(source, offset) {
var commentEnd = source.indexOf('*/', offset);
if (commentEnd === -1) {
return source.length;
}
return commentEnd + 2;
}
function findStringEnd(source, offset, quote) {
for (; offset < source.length; offset++) {
var code = source.charCodeAt(offset);
// TODO: bad string
if (code === BACK_SLASH) {
offset++;
} else if (code === quote) {
offset++;
break;
}
}
return offset;
}
function findDecimalNumberEnd(source, offset) {
for (; offset < source.length; offset++) {
var code = source.charCodeAt(offset);
if (code < 48 || code > 57) { // not a 0 .. 9
break;
}
}
return offset;
}
function findNumberEnd(source, offset, allowFraction) {
var code;
offset = findDecimalNumberEnd(source, offset);
// fraction: .\d+
if (allowFraction && offset + 1 < source.length && source.charCodeAt(offset) === FULLSTOP) {
code = source.charCodeAt(offset + 1);
if (isNumber(code)) {
offset = findDecimalNumberEnd(source, offset + 1);
}
}
// exponent: e[+-]\d+
if (offset + 1 < source.length) {
if ((source.charCodeAt(offset) | 32) === E) { // case insensitive check for `e`
code = source.charCodeAt(offset + 1);
if (code === PLUSSIGN || code === HYPHENMINUS) {
if (offset + 2 < source.length) {
code = source.charCodeAt(offset + 2);
}
}
if (isNumber(code)) {
offset = findDecimalNumberEnd(source, offset + 2);
}
}
}
return offset;
}
// skip escaped unicode sequence that can ends with space
// [0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?
function findEscaseEnd(source, offset) {
for (var i = 0; i < 7 && offset + i < source.length; i++) {
var code = source.charCodeAt(offset + i);
if (i !== 6 && isHex(code)) {
continue;
}
if (i > 0) {
offset += i - 1 + isNewline(source, offset + i, code);
if (code === SPACE$1 || code === TAB$1) {
offset++;
}
}
break;
}
return offset;
}
function findIdentifierEnd(source, offset) {
for (; offset < source.length; offset++) {
var code = source.charCodeAt(offset);
if (code === BACK_SLASH) {
offset = findEscaseEnd(source, offset + 1);
} else if (code < 0x80 && PUNCTUATION$1[code] === PUNCTUATOR$1) {
break;
}
}
return offset;
}
function findUrlRawEnd(source, offset) {
for (; offset < source.length; offset++) {
var code = source.charCodeAt(offset);
if (code === BACK_SLASH) {
offset = findEscaseEnd(source, offset + 1);
} else if (code < 0x80 && STOP_URL_RAW$1[code] === 1) {
break;
}
}
return offset;
}
var utils = {
firstCharOffset: firstCharOffset,
isHex: isHex,
isNumber: isNumber,
isNewline: isNewline,
cmpChar: cmpChar,
cmpStr: cmpStr,
endsWith: endsWith,
findLastNonSpaceLocation: findLastNonSpaceLocation,
findWhiteSpaceEnd: findWhiteSpaceEnd,
findCommentEnd: findCommentEnd,
findStringEnd: findStringEnd,
findDecimalNumberEnd: findDecimalNumberEnd,
findNumberEnd: findNumberEnd,
findEscaseEnd: findEscaseEnd,
findIdentifierEnd: findIdentifierEnd,
findUrlRawEnd: findUrlRawEnd
};
var TYPE$2 = _const.TYPE;
var NAME$1 = _const.NAME;
var SYMBOL_TYPE$1 = _const.SYMBOL_TYPE;
var firstCharOffset$1 = utils.firstCharOffset;
var cmpStr$1 = utils.cmpStr;
var isNumber$1 = utils.isNumber;
var findLastNonSpaceLocation$1 = utils.findLastNonSpaceLocation;
var findWhiteSpaceEnd$1 = utils.findWhiteSpaceEnd;
var findCommentEnd$1 = utils.findCommentEnd;
var findStringEnd$1 = utils.findStringEnd;
var findNumberEnd$1 = utils.findNumberEnd;
var findIdentifierEnd$1 = utils.findIdentifierEnd;
var findUrlRawEnd$1 = utils.findUrlRawEnd;
var NULL = 0;
var WHITESPACE$1 = TYPE$2.WhiteSpace;
var IDENTIFIER$1 = TYPE$2.Identifier;
var NUMBER$1 = TYPE$2.Number;
var STRING$1 = TYPE$2.String;
var COMMENT$1 = TYPE$2.Comment;
var PUNCTUATOR$2 = TYPE$2.Punctuator;
var CDO$1 = TYPE$2.CDO;
var CDC$1 = TYPE$2.CDC;
var ATRULE$1 = TYPE$2.Atrule;
var FUNCTION$1 = TYPE$2.Function;
var URL$1 = TYPE$2.Url;
var RAW$1 = TYPE$2.Raw;
var N$2 = 10;
var F$2 = 12;
var R$2 = 13;
var STAR = TYPE$2.Asterisk;
var SLASH = TYPE$2.Solidus;
var FULLSTOP$1 = TYPE$2.FullStop;
var PLUSSIGN$1 = TYPE$2.PlusSign;
var HYPHENMINUS$1 = TYPE$2.HyphenMinus;
var GREATERTHANSIGN = TYPE$2.GreaterThanSign;
var LESSTHANSIGN = TYPE$2.LessThanSign;
var EXCLAMATIONMARK = TYPE$2.ExclamationMark;
var COMMERCIALAT = TYPE$2.CommercialAt;
var QUOTATIONMARK = TYPE$2.QuotationMark;
var APOSTROPHE = TYPE$2.Apostrophe;
var LEFTPARENTHESIS = TYPE$2.LeftParenthesis;
var RIGHTPARENTHESIS = TYPE$2.RightParenthesis;
var LEFTCURLYBRACKET = TYPE$2.LeftCurlyBracket;
var RIGHTCURLYBRACKET = TYPE$2.RightCurlyBracket;
var LEFTSQUAREBRACKET = TYPE$2.LeftSquareBracket;
var RIGHTSQUAREBRACKET = TYPE$2.RightSquareBracket;
var MIN_BUFFER_SIZE = 16 * 1024;
var OFFSET_MASK = 0x00FFFFFF;
var TYPE_SHIFT = 24;
var SafeUint32Array$1 = typeof Uint32Array !== 'undefined' ? Uint32Array : Array; // fallback on Array when TypedArray is not supported
function computeLinesAndColumns(tokenizer, source) {
var sourceLength = source.length;
var start = firstCharOffset$1(source);
var lines = tokenizer.lines;
var line = tokenizer.startLine;
var columns = tokenizer.columns;
var column = tokenizer.startColumn;
if (lines === null || lines.length < sourceLength + 1) {
lines = new SafeUint32Array$1(Math.max(sourceLength + 1024, MIN_BUFFER_SIZE));
columns = new SafeUint32Array$1(lines.length);
}
for (var i = start; i < sourceLength; i++) {
var code = source.charCodeAt(i);
lines[i] = line;
columns[i] = column++;
if (code === N$2 || code === R$2 || code === F$2) {
if (code === R$2 && i + 1 < sourceLength && source.charCodeAt(i + 1) === N$2) {
i++;
lines[i] = line;
columns[i] = column;
}
line++;
column = 1;
}
}
lines[i] = line;
columns[i] = column;
tokenizer.linesAnsColumnsComputed = true;
tokenizer.lines = lines;
tokenizer.columns = columns;
}
function tokenLayout(tokenizer, source, startPos) {
var sourceLength = source.length;
var offsetAndType = tokenizer.offsetAndType;
var balance = tokenizer.balance;
var tokenCount = 0;
var prevType = 0;
var offset = startPos;
var anchor = 0;
var balanceCloseCode = 0;
var balanceStart = 0;
var balancePrev = 0;
if (offsetAndType === null || offsetAndType.length < sourceLength + 1) {
offsetAndType = new SafeUint32Array$1(sourceLength + 1024);
balance = new SafeUint32Array$1(sourceLength + 1024);
}
while (offset < sourceLength) {
var code = source.charCodeAt(offset);
var type = code < 0x80 ? SYMBOL_TYPE$1[code] : IDENTIFIER$1;
balance[tokenCount] = sourceLength;
switch (type) {
case WHITESPACE$1:
offset = findWhiteSpaceEnd$1(source, offset + 1);
break;
case PUNCTUATOR$2:
switch (code) {
case balanceCloseCode:
balancePrev = balanceStart & OFFSET_MASK;
balanceStart = balance[balancePrev];
balanceCloseCode = balanceStart >> TYPE_SHIFT;
balance[tokenCount] = balancePrev;
balance[balancePrev++] = tokenCount;
for (; balancePrev < tokenCount; balancePrev++) {
if (balance[balancePrev] === sourceLength) {
balance[balancePrev] = tokenCount;
}
}
break;
case LEFTSQUAREBRACKET:
balance[tokenCount] = balanceStart;
balanceCloseCode = RIGHTSQUAREBRACKET;
balanceStart = (balanceCloseCode << TYPE_SHIFT) | tokenCount;
break;
case LEFTCURLYBRACKET:
balance[tokenCount] = balanceStart;
balanceCloseCode = RIGHTCURLYBRACKET;
balanceStart = (balanceCloseCode << TYPE_SHIFT) | tokenCount;
break;
case LEFTPARENTHESIS:
balance[tokenCount] = balanceStart;
balanceCloseCode = RIGHTPARENTHESIS;
balanceStart = (balanceCloseCode << TYPE_SHIFT) | tokenCount;
break;
}
// /*
if (code === STAR && prevType === SLASH) {
type = COMMENT$1;
offset = findCommentEnd$1(source, offset + 1);
tokenCount--; // rewrite prev token
break;
}
// edge case for -.123 and +.123
if (code === FULLSTOP$1 && (prevType === PLUSSIGN$1 || prevType === HYPHENMINUS$1)) {
if (offset + 1 < sourceLength && isNumber$1(source.charCodeAt(offset + 1))) {
type = NUMBER$1;
offset = findNumberEnd$1(source, offset + 2, false);
tokenCount--; // rewrite prev token
break;
}
}
// <!--
if (code === EXCLAMATIONMARK && prevType === LESSTHANSIGN) {
if (offset + 2 < sourceLength &&
source.charCodeAt(offset + 1) === HYPHENMINUS$1 &&
source.charCodeAt(offset + 2) === HYPHENMINUS$1) {
type = CDO$1;
offset = offset + 3;
tokenCount--; // rewrite prev token
break;
}
}
// -->
if (code === HYPHENMINUS$1 && prevType === HYPHENMINUS$1) {
if (offset + 1 < sourceLength && source.charCodeAt(offset + 1) === GREATERTHANSIGN) {
type = CDC$1;
offset = offset + 2;
tokenCount--; // rewrite prev token
break;
}
}
// ident(
if (code === LEFTPARENTHESIS && prevType === IDENTIFIER$1) {
offset = offset + 1;
tokenCount--; // rewrite prev token
balance[tokenCount] = balance[tokenCount + 1];
balanceStart--;
// 4 char length identifier and equal to `url(` (case insensitive)
if (offset - anchor === 4 && cmpStr$1(source, anchor, offset, 'url(')) {
// special case for url() because it can contain any symbols sequence with few exceptions
anchor = findWhiteSpaceEnd$1(source, offset);
code = source.charCodeAt(anchor);
if (code !== LEFTPARENTHESIS &&
code !== RIGHTPARENTHESIS &&
code !== QUOTATIONMARK &&
code !== APOSTROPHE) {
// url(
offsetAndType[tokenCount++] = (URL$1 << TYPE_SHIFT) | offset;
balance[tokenCount] = sourceLength;
// ws*
if (anchor !== offset) {
offsetAndType[tokenCount++] = (WHITESPACE$1 << TYPE_SHIFT) | anchor;
balance[tokenCount] = sourceLength;
}
// raw
type = RAW$1;
offset = findUrlRawEnd$1(source, anchor);
} else {
type = URL$1;
}
} else {
type = FUNCTION$1;
}
break;
}
type = code;
offset = offset + 1;
break;
case NUMBER$1:
offset = findNumberEnd$1(source, offset + 1, prevType !== FULLSTOP$1);
// merge number with a preceding dot, dash or plus
if (prevType === FULLSTOP$1 ||
prevType === HYPHENMINUS$1 ||
prevType === PLUSSIGN$1) {
tokenCount--; // rewrite prev token
}
break;
case STRING$1:
offset = findStringEnd$1(source, offset + 1, code);
break;
default:
anchor = offset;
offset = findIdentifierEnd$1(source, offset);
// merge identifier with a preceding dash
if (prevType === HYPHENMINUS$1) {
// rewrite prev token
tokenCount--;
// restore prev prev token type
// for case @-prefix-ident
prevType = tokenCount === 0 ? 0 : offsetAndType[tokenCount - 1] >> TYPE_SHIFT;
}
if (prevType === COMMERCIALAT) {
// rewrite prev token and change type to <at-keyword-token>
tokenCount--;
type = ATRULE$1;
}
}
offsetAndType[tokenCount++] = (type << TYPE_SHIFT) | offset;
prevType = type;
}
// finalize arrays
offsetAndType[tokenCount] = offset;
balance[tokenCount] = sourceLength;
while (balanceStart !== 0) {
balancePrev = balanceStart & OFFSET_MASK;
balanceStart = balance[balancePrev];
balance[balancePrev] = sourceLength;
}
tokenizer.offsetAndType = offsetAndType;
tokenizer.tokenCount = tokenCount;
tokenizer.balance = balance;
}
//
// tokenizer
//
var Tokenizer = function(source, startOffset, startLine, startColumn) {
this.offsetAndType = null;
this.balance = null;
this.lines = null;
this.columns = null;
this.setSource(source, startOffset, startLine, startColumn);
};
Tokenizer.prototype = {
setSource: function(source, startOffset, startLine, startColumn) {
var safeSource = String(source || '');
var start = firstCharOffset$1(safeSource);
this.source = safeSource;
this.firstCharOffset = start;
this.startOffset = typeof startOffset === 'undefined' ? 0 : startOffset;
this.startLine = typeof startLine === 'undefined' ? 1 : startLine;
this.startColumn = typeof startColumn === 'undefined' ? 1 : startColumn;
this.linesAnsColumnsComputed = false;
this.eof = false;
this.currentToken = -1;
this.tokenType = 0;
this.tokenStart = start;
this.tokenEnd = start;
tokenLayout(this, safeSource, start);
this.next();
},
lookupType: function(offset) {
offset += this.currentToken;
if (offset < this.tokenCount) {
return this.offsetAndType[offset] >> TYPE_SHIFT;
}
return NULL;
},
lookupNonWSType: function(offset) {
offset += this.currentToken;
for (var type; offset < this.tokenCount; offset++) {
type = this.offsetAndType[offset] >> TYPE_SHIFT;
if (type !== WHITESPACE$1) {
return type;
}
}
return NULL;
},
lookupValue: function(offset, referenceStr) {
offset += this.currentToken;
if (offset < this.tokenCount) {
return cmpStr$1(
this.source,
this.offsetAndType[offset - 1] & OFFSET_MASK,
this.offsetAndType[offset] & OFFSET_MASK,
referenceStr
);
}
return false;
},
getTokenStart: function(tokenNum) {
if (tokenNum === this.currentToken) {
return this.tokenStart;
}
if (tokenNum > 0) {
return tokenNum < this.tokenCount
? this.offsetAndType[tokenNum - 1] & OFFSET_MASK
: this.offsetAndType[this.tokenCount] & OFFSET_MASK;
}
return this.firstCharOffset;
},
getOffsetExcludeWS: function() {
if (this.currentToken > 0) {
if ((this.offsetAndType[this.currentToken - 1] >> TYPE_SHIFT) === WHITESPACE$1) {
return this.currentToken > 1
? this.offsetAndType[this.currentToken - 2] & OFFSET_MASK
: this.firstCharOffset;
}
}
return this.tokenStart;
},
getRawLength: function(startToken, endTokenType1, endTokenType2, includeTokenType2) {
var cursor = startToken;
var balanceEnd;
loop:
for (; cursor < this.tokenCount; cursor++) {
balanceEnd = this.balance[cursor];
// belance end points to offset before start
if (balanceEnd < startToken) {
break loop;
}
// check token is stop type
switch (this.offsetAndType[cursor] >> TYPE_SHIFT) {
case endTokenType1:
break loop;
case endTokenType2:
if (includeTokenType2) {
cursor++;
}
break loop;
default:
// fast forward to the end of balanced block
if (this.balance[balanceEnd] === cursor) {
cursor = balanceEnd;
}
}
}
return cursor - this.currentToken;
},
getTokenValue: function() {
return this.source.substring(this.tokenStart, this.tokenEnd);
},
substrToCursor: function(start) {
return this.source.substring(start, this.tokenStart);
},
skipWS: function() {
for (var i = this.currentToken, skipTokenCount = 0; i < this.tokenCount; i++, skipTokenCount++) {
if ((this.offsetAndType[i] >> TYPE_SHIFT) !== WHITESPACE$1) {
break;
}
}
if (skipTokenCount > 0) {
this.skip(skipTokenCount);
}
},
skipSC: function() {
while (this.tokenType === WHITESPACE$1 || this.tokenType === COMMENT$1) {
this.next();
}
},
skip: function(tokenCount) {
var next = this.currentToken + tokenCount;
if (next < this.tokenCount) {
this.currentToken = next;
this.tokenStart = this.offsetAndType[next - 1] & OFFSET_MASK;
next = this.offsetAndType[next];
this.tokenType = next >> TYPE_SHIFT;
this.tokenEnd = next & OFFSET_MASK;
} else {
this.currentToken = this.tokenCount;
this.next();
}
},
next: function() {
var next = this.currentToken + 1;
if (next < this.tokenCount) {
this.currentToken = next;
this.tokenStart = this.tokenEnd;
next = this.offsetAndType[next];
this.tokenType = next >> TYPE_SHIFT;
this.tokenEnd = next & OFFSET_MASK;
} else {
this.currentToken = this.tokenCount;
this.eof = true;
this.tokenType = NULL;
this.tokenStart = this.tokenEnd = this.source.length;
}
},
eat: function(tokenType) {
if (this.tokenType !== tokenType) {
var offset = this.tokenStart;
var message = NAME$1[tokenType] + ' is expected';
// tweak message and offset
if (tokenType === IDENTIFIER$1) {
// when identifier is expected but there is a function or url
if (this.tokenType === FUNCTION$1 || this.tokenType === URL$1) {
offset = this.tokenEnd - 1;
message += ' but function found';
}
} else {
// when test type is part of another token show error for current position + 1
// e.g. eat(HYPHENMINUS) will fail on "-foo", but pointing on "-" is odd
if (this.source.charCodeAt(this.tokenStart) === tokenType) {
offset = offset + 1;
}
}
this.error(message, offset);
}
this.next();
},
eatNonWS: function(tokenType) {
this.skipWS();
this.eat(tokenType);
},
consume: function(tokenType) {
var value = this.getTokenValue();
this.eat(tokenType);
return value;
},
consumeFunctionName: function() {
var name = this.source.substring(this.tokenStart, this.tokenEnd - 1);
this.eat(FUNCTION$1);
return name;
},
consumeNonWS: function(tokenType) {
this.skipWS();
return this.consume(tokenType);
},
expectIdentifier: function(name) {
if (this.tokenType !== IDENTIFIER$1 || cmpStr$1(this.source, this.tokenStart, this.tokenEnd, name) === false) {
this.error('Identifier `' + name + '` is expected');
}
this.next();
},
getLocation: function(offset, filename) {
if (!this.linesAnsColumnsComputed) {
computeLinesAndColumns(this, this.source);
}
return {
source: filename,
offset: this.startOffset + offset,
line: this.lines[offset],
column: this.columns[offset]
};
},
getLocationRange: function(start, end, filename) {
if (!this.linesAnsColumnsComputed) {
computeLinesAndColumns(this, this.source);
}
return {
source: filename,
start: {
offset: this.startOffset + start,
line: this.lines[start],
column: this.columns[start]
},
end: {
offset: this.startOffset + end,
line: this.lines[end],
column: this.columns[end]
}
};
},
error: function(message, offset) {
var location = typeof offset !== 'undefined' && offset < this.source.length
? this.getLocation(offset)
: this.eof
? findLastNonSpaceLocation$1(this)
: this.getLocation(this.tokenStart);
throw new error(
message || 'Unexpected input',
this.source,
location.offset,
location.line,
location.column
);
},
dump: function() {
var offset = 0;
return Array.prototype.slice.call(this.offsetAndType, 0, this.tokenCount).map(function(item, idx) {
var start = offset;
var end = item & OFFSET_MASK;
offset = end;
return {
idx: idx,
type: NAME$1[item >> TYPE_SHIFT],
chunk: this.source.substring(start, end),
balance: this.balance[idx]
};
}, this);
}
};
// extend with error class
Tokenizer.CssSyntaxError = error;
// extend tokenizer with constants
Object.keys(_const).forEach(function(key) {
Tokenizer[key] = _const[key];
});
// extend tokenizer with static methods from utils
Object.keys(utils).forEach(function(key) {
Tokenizer[key] = utils[key];
});
// warm up tokenizer to elimitate code branches that never execute
// fix soft deoptimizations (insufficient type feedback)
new Tokenizer('\n\r\r\n\f<!---->//""\'\'/*\r\n\f*/1a;.\\31\t\+2{url(a);func();+1.2e3 -.4e-5 .6e+7}').getLocation();
var Tokenizer_1 = Tokenizer;
var tokenizer = Tokenizer_1;
//
// item item item item
// /------\ /------\ /------\ /------\
// | data | | data | | data | | data |
// null <--+-prev |<---+-prev |<---+-prev |<---+-prev |
// | next-+--->| next-+--->| next-+--->| next-+--> null
// \------/ \------/ \------/ \------/
// ^ ^
// | list |
// | /------\ |
// \--------------+-head | |
// | tail-+--------------/
// \------/
//
function createItem(data) {
return {
prev: null,
next: null,
data: data
};
}
var cursors = null;
var List = function() {
this.cursor = null;
this.head = null;
this.tail = null;
};
List.createItem = createItem;
List.prototype.createItem = createItem;
List.prototype.getSize = function() {
var size = 0;
var cursor = this.head;
while (cursor) {
size++;
cursor = cursor.next;
}
return size;
};
List.prototype.fromArray = function(array) {
var cursor = null;
this.head = null;
for (var i = 0; i < array.length; i++) {
var item = createItem(array[i]);
if (cursor !== null) {
cursor.next = item;
} else {
this.head = item;
}
item.prev = cursor;
cursor = item;
}
this.tail = cursor;
return this;
};
List.prototype.toArray = function() {
var cursor = this.head;
var result = [];
while (cursor) {
result.push(cursor.data);
cursor = cursor.next;
}
return result;
};
List.prototype.toJSON = List.prototype.toArray;
List.prototype.isEmpty = function() {
return this.head === null;
};
List.prototype.first = function() {
return this.head && this.head.data;
};
List.prototype.last = function() {
return this.tail && this.tail.data;
};
function allocateCursor(node, prev, next) {
var cursor;
if (cursors !== null) {
cursor = cursors;
cursors = cursors.cursor;
cursor.prev = prev;
cursor.next = next;
cursor.cursor = node.cursor;
} else {
cursor = {
prev: prev,
next: next,
cursor: node.cursor
};
}
node.cursor = cursor;
return cursor;
}
function releaseCursor(node) {
var cursor = node.cursor;
node.cursor = cursor.cursor;
cursor.prev = null;
cursor.next = null;
cursor.cursor = cursors;
cursors = cursor;
}
List.prototype.each = function(fn, context) {
var item;
if (context === undefined) {
context = this;
}
// push cursor
var cursor = allocateCursor(this, null, this.head);
while (cursor.next !== null) {
item = cursor.next;
cursor.next = item.next;
fn.call(context, item.data, item, this);
}
// pop cursor
releaseCursor(this);
};
List.prototype.eachRight = function(fn, context) {
var item;
if (context === undefined) {
context = this;
}
// push cursor
var cursor = allocateCursor(this, this.tail, null);
while (cursor.prev !== null) {
item = cursor.prev;
cursor.prev = item.prev;
fn.call(context, item.data, item, this);
}
// pop cursor
releaseCursor(this);
};
List.prototype.nextUntil = function(start, fn, context) {
if (start === null) {
return;
}
var item;
if (context === undefined) {
context = this;
}
// push cursor
var cursor = allocateCursor(this, null, start);
while (cursor.next !== null) {
item = cursor.next;
cursor.next = item.next;
if (fn.call(context, item.data, item, this)) {
break;
}
}
// pop cursor
releaseCursor(this);
};
List.prototype.prevUntil = function(start, fn, context) {
if (start === null) {
return;
}
var item;
if (context === undefined) {
context = this;
}
// push cursor
var cursor = allocateCursor(this, start, null);
while (cursor.prev !== null) {
item = cursor.prev;
cursor.prev = item.prev;
if (fn.call(context, item.data, item, this)) {
break;
}
}
// pop cursor
releaseCursor(this);
};
List.prototype.some = function(fn, context) {
var cursor = this.head;
if (context === undefined) {
context = this;
}
while (cursor !== null) {
if (fn.call(context, cursor.data, cursor, this)) {
return true;
}
cursor = cursor.next;
}
return false;
};
List.prototype.map = function(fn, context) {
var result = [];
var cursor = this.head;
if (context === undefined) {
context = this;
}
while (cursor !== null) {
result.push(fn.call(context, cursor.data, cursor, this));
cursor = cursor.next;
}
return result;
};
List.prototype.clear = function() {
this.head = null;
this.tail = null;
};
List.prototype.copy = function() {
var result = new List();
var cursor = this.head;
while (cursor !== null) {
result.insert(createItem(cursor.data));
cursor = cursor.next;
}
return result;
};
List.prototype.updateCursors = function(prevOld, prevNew, nextOld, nextNew) {
var cursor = this.cursor;
while (cursor !== null) {
if (cursor.prev === prevOld) {
cursor.prev = prevNew;
}
if (cursor.next === nextOld) {
cursor.next = nextNew;
}
cursor = cursor.cursor;
}
};
List.prototype.prepend = function(item) {
// head
// ^
// item
this.updateCursors(null, item, this.head, item);
// insert to the beginning of the list
if (this.head !== null) {
// new item <- first item
this.head.prev = item;
// new item -> first item
item.next = this.head;
} else {
// if list has no head, then it also has no tail
// in this case tail points to the new item
this.tail = item;
}
// head always points to new item
this.head = item;
return this;
};
List.prototype.prependData = function(data) {
return this.prepend(createItem(data));
};
List.prototype.append = function(item) {
// tail
// ^
// item
this.updateCursors(this.tail, item, null, item);
// insert to the ending of the list
if (this.tail !== null) {
// last item -> new item
this.tail.next = item;
// last item <- new item
item.prev = this.tail;
} else {
// if list has no tail, then it also has no head
// in this case head points to new item
this.head = item;
}
// tail always points to new item
this.tail = item;
return this;
};
List.prototype.appendData = function(data) {
return this.append(createItem(data));
};
List.prototype.insert = function(item, before) {
if (before !== undefined && before !== null) {
// prev before
// ^
// item
this.updateCursors(before.prev, item, before, item);
if (before.prev === null) {
// insert to the beginning of list
if (this.head !== before) {
throw new Error('before doesn\'t belong to list');
}
// since head points to before therefore list doesn't empty
// no need to check tail
this.head = item;
before.prev = item;
item.next = before;
this.updateCursors(null, item);
} else {
// insert between two items
before.prev.next = item;
item.prev = before.prev;
before.prev = item;
item.next = before;
}
} else {
this.append(item);
}
};
List.prototype.insertData = function(data, before) {
this.insert(createItem(data), before);
};
List.prototype.remove = function(item) {
// item
// ^
// prev next
this.updateCursors(item, item.prev, item, item.next);
if (item.prev !== null) {
item.prev.next = item.next;
} else {
if (this.head !== item) {
throw new Error('item doesn\'t belong to list');
}
this.head = item.next;
}
if (item.next !== null) {
item.next.prev = item.prev;
} else {
if (this.tail !== item) {
throw new Error('item doesn\'t belong to list');
}
this.tail = item.prev;
}
item.prev = null;
item.next = null;
return item;
};
List.prototype.appendList = function(list) {
// ignore empty lists
if (list.head === null) {
return;
}
this.updateCursors(this.tail, list.tail, null, list.head);
// insert to end of the list
if (this.tail !== null) {
// if destination list has a tail, then it also has a head,
// but head doesn't change
// dest tail -> source head
this.tail.next = list.head;
// dest tail <- source head
list.head.prev = this.tail;
} else {
// if list has no a tail, then it also has no a head
// in this case points head to new item
this.head = list.head;
}
// tail always start point to new item
this.tail = list.tail;
list.head = null;
list.tail = null;
};
List.prototype.insertList = function(list, before) {
if (before !== undefined && before !== null) {
// ignore empty lists
if (list.head === null) {
return;
}
this.updateCursors(before.prev, list.tail, before, list.head);
// insert in the middle of dist list
if (before.prev !== null) {
// before.prev <-> list.head
before.prev.next = list.head;
list.head.prev = before.prev;
} else {
this.head = list.head;
}
before.prev = list.tail;
list.tail.next = before;
list.head = null;
list.tail = null;
} else {
this.appendList(list);
}
};
List.prototype.replace = function(oldItem, newItemOrList) {
if ('head' in newItemOrList) {
this.insertList(newItemOrList, oldItem);
} else {
this.insert(newItemOrList, oldItem);
}
this.remove(oldItem);
};
var list = List;
var TYPE$3 = tokenizer.TYPE;
var WHITESPACE$2 = TYPE$3.WhiteSpace;
var COMMENT$2 = TYPE$3.Comment;
var sequence = function readSequence(recognizer) {
var children = new list();
var child = null;
var context = {
recognizer: recognizer,
space: null,
ignoreWS: false,
ignoreWSAfter: false
};
this.scanner.skipSC();
while (!this.scanner.eof) {
switch (this.scanner.tokenType) {
case COMMENT$2:
this.scanner.next();
continue;
case WHITESPACE$2:
if (context.ignoreWS) {
this.scanner.next();
} else {
context.space = this.WhiteSpace();
}
continue;
}
child = recognizer.getNode.call(this, context);
if (child === undefined) {
break;
}
if (context.space !== null) {
children.appendData(context.space);
context.space = null;
}
children.appendData(child);
if (context.ignoreWSAfter) {
context.ignoreWSAfter = false;
context.ignoreWS = true;
} else {
context.ignoreWS = false;
}
}
return children;
};
var noop = function() {};
function createParseContext(name) {
return function() {
return this[name]();
};
}
function processConfig(config) {
var parserConfig = {
context: {},
scope: {},
atrule: {},
pseudo: {}
};
if (config.parseContext) {
for (var name in config.parseContext) {
switch (typeof config.parseContext[name]) {
case 'function':
parserConfig.context[name] = config.parseContext[name];
break;
case 'string':
parserConfig.context[name] = createParseContext(config.parseContext[name]);
break;
}
}
}
if (config.scope) {
for (var name in config.scope) {
parserConfig.scope[name] = config.scope[name];
}
}
if (config.atrule) {
for (var name in config.atrule) {
var atrule = config.atrule[name];
if (atrule.parse) {
parserConfig.atrule[name] = atrule.parse;
}
}
}
if (config.pseudo) {
for (var name in config.pseudo) {
var pseudo = config.pseudo[name];
if (pseudo.parse) {
parserConfig.pseudo[name] = pseudo.parse;
}
}
}
if (config.node) {
for (var name in config.node) {
parserConfig[name] = config.node[name].parse;
}
}
return parserConfig;
}
var create = function createParser(config) {
var parser = {
scanner: new tokenizer(),
filename: '<unknown>',
needPositions: false,
tolerant: false,
onParseError: noop,
parseAtruleExpression: true,
parseSelector: true,
parseValue: true,
parseCustomProperty: false,
readSequence: sequence,
tolerantParse: function(consumer, fallback) {
if (this.tolerant) {
var start = this.scanner.currentToken;
try {
return consumer.call(this);
} catch (e) {
this.onParseError(e);
return fallback.call(this, start);
}
} else {
return consumer.call(this);
}
},
getLocation: function(start, end) {
if (this.needPositions) {
return this.scanner.getLocationRange(
start,
end,
this.filename
);
}
return null;
},
getLocationFromList: function(list) {
if (this.needPositions) {
return this.scanner.getLocationRange(
list.head !== null ? list.first().loc.start.offset - this.scanner.startOffset : this.scanner.tokenStart,
list.head !== null ? list.last().loc.end.offset - this.scanner.startOffset : this.scanner.tokenStart,
this.filename
);
}
return null;
}
};
config = processConfig(config || {});
for (var key in config) {
parser[key] = config[key];
}
return function(source, options) {
options = options || {};
var context = options.context || 'default';
var ast;
parser.scanner.setSource(source, options.offset, options.line, options.column);
parser.filename = options.filename || '<unknown>';
parser.needPositions = Boolean(options.positions);
parser.tolerant = Boolean(options.tolerant);
parser.onParseError = typeof options.onParseError === 'function' ? options.onParseError : noop;
parser.parseAtruleExpression = 'parseAtruleExpression' in options ? Boolean(options.parseAtruleExpression) : true;
parser.parseSelector = 'parseSelector' in options ? Boolean(options.parseSelector) : true;
parser.parseValue = 'parseValue' in options ? Boolean(options.parseValue) : true;
parser.parseCustomProperty = 'parseCustomProperty' in options ? Boolean(options.parseCustomProperty) : false;
if (!parser.context.hasOwnProperty(context)) {
throw new Error('Unknown context `' + context + '`');
}
ast = parser.context[context].call(parser, options);
if (!parser.scanner.eof) {
parser.scanner.error();
}
// console.log(JSON.stringify(ast, null, 4));
return ast;
};
};
var cmpChar$1 = tokenizer.cmpChar;
var TYPE$4 = tokenizer.TYPE;
var IDENTIFIER$2 = TYPE$4.Identifier;
var STRING$2 = TYPE$4.String;
var NUMBER$2 = TYPE$4.Number;
var FUNCTION$2 = TYPE$4.Function;
var URL$2 = TYPE$4.Url;
var NUMBERSIGN = TYPE$4.NumberSign;
var LEFTPARENTHESIS$1 = TYPE$4.LeftParenthesis;
var LEFTSQUAREBRACKET$1 = TYPE$4.LeftSquareBracket;
var PLUSSIGN$2 = TYPE$4.PlusSign;
var HYPHENMINUS$2 = TYPE$4.HyphenMinus;
var COMMA = TYPE$4.Comma;
var SOLIDUS = TYPE$4.Solidus;
var ASTERISK = TYPE$4.Asterisk;
var PERCENTSIGN = TYPE$4.PercentSign;
var BACKSLASH = TYPE$4.Backslash;
var U = 117; // 'u'.charCodeAt(0)
var _default = function defaultRecognizer(context) {
switch (this.scanner.tokenType) {
case NUMBERSIGN:
return this.HexColor();
case COMMA:
context.space = null;
context.ignoreWSAfter = true;
return this.Operator();
case SOLIDUS:
case ASTERISK:
case PLUSSIGN$2:
case HYPHENMINUS$2:
return this.Operator();
case LEFTPARENTHESIS$1:
return this.Parentheses(this.readSequence, context.recognizer);
case LEFTSQUAREBRACKET$1:
return this.Brackets(this.readSequence, context.recognizer);
case STRING$2:
return this.String();
case NUMBER$2:
switch (this.scanner.lookupType(1)) {
case PERCENTSIGN:
return this.Percentage();
case IDENTIFIER$2:
// edge case: number with folowing \0 and \9 hack shouldn't to be a Dimension
if (cmpChar$1(this.scanner.source, this.scanner.tokenEnd, BACKSLASH)) {
return this.Number();
} else {
return this.Dimension();
}
default:
return this.Number();
}
case FUNCTION$2:
return this.Function(this.readSequence, context.recognizer);
case URL$2:
return this.Url();
case IDENTIFIER$2:
// check for unicode range, it should start with u+ or U+
if (cmpChar$1(this.scanner.source, this.scanner.tokenStart, U) &&
cmpChar$1(this.scanner.source, this.scanner.tokenStart + 1, PLUSSIGN$2)) {
return this.UnicodeRange();
} else {
return this.Identifier();
}
}
};
var atruleExpression = {
getNode: _default
};
var TYPE$5 = tokenizer.TYPE;
var IDENTIFIER$3 = TYPE$5.Identifier;
var NUMBER$3 = TYPE$5.Number;
var NUMBERSIGN$1 = TYPE$5.NumberSign;
var LEFTSQUAREBRACKET$2 = TYPE$5.LeftSquareBracket;
var PLUSSIGN$3 = TYPE$5.PlusSign;
var SOLIDUS$1 = TYPE$5.Solidus;
var ASTERISK$1 = TYPE$5.Asterisk;
var FULLSTOP$2 = TYPE$5.FullStop;
var COLON = TYPE$5.Colon;
var GREATERTHANSIGN$1 = TYPE$5.GreaterThanSign;
var VERTICALLINE = TYPE$5.VerticalLine;
var TILDE = TYPE$5.Tilde;
function getNode(context) {
switch (this.scanner.tokenType) {
case PLUSSIGN$3:
case GREATERTHANSIGN$1:
case TILDE:
context.space = null;
context.ignoreWSAfter = true;
return this.Combinator();
case SOLIDUS$1: // /deep/
return this.Combinator();
case FULLSTOP$2:
return this.ClassSelector();
case LEFTSQUAREBRACKET$2:
return this.AttributeSelector();
case NUMBERSIGN$1:
return this.IdSelector();
case COLON:
if (this.scanner.lookupType(1) === COLON) {
return this.PseudoElementSelector();
} else {
return this.PseudoClassSelector();
}
case IDENTIFIER$3:
case ASTERISK$1:
case VERTICALLINE:
return this.TypeSelector();
case NUMBER$3:
return this.Percentage();
}
}
var selector = {
getNode: getNode
};
// https://drafts.csswg.org/css-images-4/#element-notation
// https://developer.mozilla.org/en-US/docs/Web/CSS/element
var element = function() {
this.scanner.skipSC();
var id = this.IdSelector();
this.scanner.skipSC();
return new list().appendData(
id
);
};
// legacy IE function
// expression '(' raw ')'
var expression = function() {
return new list().appendData(
this.Raw(this.scanner.currentToken, 0, 0, false, false)
);
};
var TYPE$6 = tokenizer.TYPE;
var IDENTIFIER$4 = TYPE$6.Identifier;
var COMMA$1 = TYPE$6.Comma;
var SEMICOLON = TYPE$6.Semicolon;
var HYPHENMINUS$3 = TYPE$6.HyphenMinus;
var EXCLAMATIONMARK$1 = TYPE$6.ExclamationMark;
// var '(' ident (',' <value>? )? ')'
var _var = function() {
var children = new list();
this.scanner.skipSC();
var identStart = this.scanner.tokenStart;
this.scanner.eat(HYPHENMINUS$3);
if (this.scanner.source.charCodeAt(this.scanner.tokenStart) !== HYPHENMINUS$3) {
this.scanner.error('HyphenMinus is expected');
}
this.scanner.eat(IDENTIFIER$4);
children.appendData({
type: 'Identifier',
loc: this.getLocation(identStart, this.scanner.tokenStart),
name: this.scanner.substrToCursor(identStart)
});
this.scanner.skipSC();
if (this.scanner.tokenType === COMMA$1) {
children.appendData(this.Operator());
children.appendData(this.parseCustomProperty
? this.Value(null)
: this.Raw(this.scanner.currentToken, EXCLAMATIONMARK$1, SEMICOLON, false, false)
);
}
return children;
};
var value = {
getNode: _default,
'-moz-element': element,
'element': element,
'expression': expression,
'var': _var
};
var scope = {
AtruleExpression: atruleExpression,
Selector: selector,
Value: value
};
var fontFace = {
parse: {
expression: null,
block: function() {
return this.Block(this.Declaration);
}
}
};
var TYPE$7 = tokenizer.TYPE;
var STRING$3 = TYPE$7.String;
var IDENTIFIER$5 = TYPE$7.Identifier;
var URL$3 = TYPE$7.Url;
var LEFTPARENTHESIS$2 = TYPE$7.LeftParenthesis;
var _import = {
parse: {
expression: function() {
var children = new list();
this.scanner.skipSC();
switch (this.scanner.tokenType) {
case STRING$3:
children.appendData(this.String());
break;
case URL$3:
children.appendData(this.Url());
break;
default:
this.scanner.error('String or url() is expected');
}
if (this.scanner.lookupNonWSType(0) === IDENTIFIER$5 ||
this.scanner.lookupNonWSType(0) === LEFTPARENTHESIS$2) {
children.appendData(this.WhiteSpace());
children.appendData(this.MediaQueryList());
}
return children;
},
block: null
}
};
var media = {
parse: {
expression: function() {
return new list().appendData(
this.MediaQueryList()
);
},
block: function() {
return this.Block(this.Rule);
}
}
};
var TYPE$8 = tokenizer.TYPE;
var LEFTCURLYBRACKET$1 = TYPE$8.LeftCurlyBracket;
var page = {
parse: {
expression: function() {
if (this.scanner.lookupNonWSType(0) === LEFTCURLYBRACKET$1) {
return null;
}
return new list().appendData(
this.SelectorList()
);
},
block: function() {
return this.Block(this.Declaration);
}
}
};
var TYPE$9 = tokenizer.TYPE;
var WHITESPACE$3 = TYPE$9.WhiteSpace;
var COMMENT$3 = TYPE$9.Comment;
var IDENTIFIER$6 = TYPE$9.Identifier;
var FUNCTION$3 = TYPE$9.Function;
var LEFTPARENTHESIS$3 = TYPE$9.LeftParenthesis;
var HYPHENMINUS$4 = TYPE$9.HyphenMinus;
var COLON$1 = TYPE$9.Colon;
function consumeRaw() {
return new list().appendData(
this.Raw(this.scanner.currentToken, 0, 0, false, false)
);
}
function parentheses() {
var index = 0;
this.scanner.skipSC();
// TODO: make it simplier
if (this.scanner.tokenType === IDENTIFIER$6) {
index = 1;
} else if (this.scanner.tokenType === HYPHENMINUS$4 &&
this.scanner.lookupType(1) === IDENTIFIER$6) {
index = 2;
}
if (index !== 0 && this.scanner.lookupNonWSType(index) === COLON$1) {
return new list().appendData(
this.Declaration()
);
}
return readSequence.call(this);
}
function readSequence() {
var children = new list();
var space = null;
var child;
this.scanner.skipSC();
scan:
while (!this.scanner.eof) {
switch (this.scanner.tokenType) {
case WHITESPACE$3:
space = this.WhiteSpace();
continue;
case COMMENT$3:
this.scanner.next();
continue;
case FUNCTION$3:
child = this.Function(consumeRaw, this.scope.AtruleExpression);
break;
case IDENTIFIER$6:
child = this.Identifier();
break;
case LEFTPARENTHESIS$3:
child = this.Parentheses(parentheses, this.scope.AtruleExpression);
break;
default:
break scan;
}
if (space !== null) {
children.appendData(space);
space = null;
}
children.appendData(child);
}
return children;
}
var supports = {
parse: {
expression: function() {
var children = readSequence.call(this);
if (children.isEmpty()) {
this.scanner.error('Condition is expected');
}
return children;
},
block: function() {
return this.Block(this.Rule);
}
}
};
var atrule = {
'font-face': fontFace,
'import': _import,
'media': media,
'page': page,
'supports': supports
};
var dir = {
parse: function() {
return new list().appendData(
this.Identifier()
);
}
};
var has$1 = {
parse: function() {
return new list().appendData(
this.SelectorList()
);
}
};
var lang = {
parse: function() {
return new list().appendData(
this.Identifier()
);
}
};
var selectorList = {
parse: function selectorList() {
return new list().appendData(
this.SelectorList()
);
}
};
var matches = selectorList;
var not = selectorList;
var ALLOW_OF_CLAUSE = true;
var nthWithOfClause = {
parse: function() {
return new list().appendData(
this.Nth(ALLOW_OF_CLAUSE)
);
}
};
var nthChild = nthWithOfClause;
var nthLastChild = nthWithOfClause;
var DISALLOW_OF_CLAUSE = false;
var nth = {
parse: function nth() {
return new list().appendData(
this.Nth(DISALLOW_OF_CLAUSE)
);
}
};
var nthLastOfType = nth;
var nthOfType = nth;
var slotted = {
parse: function compoundSelector() {
return new list().appendData(
this.Selector()
);
}
};
var pseudo = {
'dir': dir,
'has': has$1,
'lang': lang,
'matches': matches,
'not': not,
'nth-child': nthChild,
'nth-last-child': nthLastChild,
'nth-last-of-type': nthLastOfType,
'nth-of-type': nthOfType,
'slotted': slotted
};
var cmpChar$2 = tokenizer.cmpChar;
var isNumber$2 = tokenizer.isNumber;
var TYPE$a = tokenizer.TYPE;
var IDENTIFIER$7 = TYPE$a.Identifier;
var NUMBER$4 = TYPE$a.Number;
var PLUSSIGN$4 = TYPE$a.PlusSign;
var HYPHENMINUS$5 = TYPE$a.HyphenMinus;
var N$3 = 110; // 'n'.charCodeAt(0)
var DISALLOW_SIGN = true;
var ALLOW_SIGN = false;
function checkTokenIsInteger(scanner, disallowSign) {
var pos = scanner.tokenStart;
if (scanner.source.charCodeAt(pos) === PLUSSIGN$4 ||
scanner.source.charCodeAt(pos) === HYPHENMINUS$5) {
if (disallowSign) {
scanner.error();
}
pos++;
}
for (; pos < scanner.tokenEnd; pos++) {
if (!isNumber$2(scanner.source.charCodeAt(pos))) {
scanner.error('Unexpected input', pos);
}
}
}
// An+B microsyntax https://www.w3.org/TR/css-syntax-3/#anb
var AnPlusB = {
name: 'AnPlusB',
structure: {
a: [String, null],
b: [String, null]
},
parse: function() {
var start = this.scanner.tokenStart;
var end = start;
var prefix = '';
var a = null;
var b = null;
if (this.scanner.tokenType === NUMBER$4 ||
this.scanner.tokenType === PLUSSIGN$4) {
checkTokenIsInteger(this.scanner, ALLOW_SIGN);
prefix = this.scanner.getTokenValue();
this.scanner.next();
end = this.scanner.tokenStart;
}
if (this.scanner.tokenType === IDENTIFIER$7) {
var bStart = this.scanner.tokenStart;
if (cmpChar$2(this.scanner.source, bStart, HYPHENMINUS$5)) {
if (prefix === '') {
prefix = '-';
bStart++;
} else {
this.scanner.error('Unexpected hyphen minus');
}
}
if (!cmpChar$2(this.scanner.source, bStart, N$3)) {
this.scanner.error();
}
a = prefix === '' ? '1' :
prefix === '+' ? '+1' :
prefix === '-' ? '-1' :
prefix;
var len = this.scanner.tokenEnd - bStart;
if (len > 1) {
// ..n-..
if (this.scanner.source.charCodeAt(bStart + 1) !== HYPHENMINUS$5) {
this.scanner.error('Unexpected input', bStart + 1);
}
if (len > 2) {
// ..n-{number}..
this.scanner.tokenStart = bStart + 2;
} else {
// ..n- {number}
this.scanner.next();
this.scanner.skipSC();
}
checkTokenIsInteger(this.scanner, DISALLOW_SIGN);
b = '-' + this.scanner.getTokenValue();
this.scanner.next();
end = this.scanner.tokenStart;
} else {
prefix = '';
this.scanner.next();
end = this.scanner.tokenStart;
this.scanner.skipSC();
if (this.scanner.tokenType === HYPHENMINUS$5 ||
this.scanner.tokenType === PLUSSIGN$4) {
prefix = this.scanner.getTokenValue();
this.scanner.next();
this.scanner.skipSC();
}
if (this.scanner.tokenType === NUMBER$4) {
checkTokenIsInteger(this.scanner, prefix !== '');
if (!isNumber$2(this.scanner.source.charCodeAt(this.scanner.tokenStart))) {
prefix = this.scanner.source.charAt(this.scanner.tokenStart);
this.scanner.tokenStart++;
}
if (prefix === '') {
// should be an operator before number
this.scanner.error();
} else if (prefix === '+') {
// plus is using by default
prefix = '';
}
b = prefix + this.scanner.getTokenValue();
this.scanner.next();
end = this.scanner.tokenStart;
} else {
if (prefix) {
this.scanner.eat(NUMBER$4);
}
}
}
} else {
if (prefix === '' || prefix === '+') { // no number
this.scanner.error(
'Number or identifier is expected',
this.scanner.tokenStart + (
this.scanner.tokenType === PLUSSIGN$4 ||
this.scanner.tokenType === HYPHENMINUS$5
)
);
}
b = prefix;
}
return {
type: 'AnPlusB',
loc: this.getLocation(start, end),
a: a,
b: b
};
},
generate: function(processChunk, node) {
var a = node.a !== null && node.a !== undefined;
var b = node.b !== null && node.b !== undefined;
if (a) {
processChunk(
node.a === '+1' ? '+n' :
node.a === '1' ? 'n' :
node.a === '-1' ? '-n' :
node.a + 'n'
);
if (b) {
b = String(node.b);
if (b.charAt(0) === '-' || b.charAt(0) === '+') {
processChunk(b.charAt(0));
processChunk(b.substr(1));
} else {
processChunk('+');
processChunk(b);
}
}
} else {
processChunk(String(node.b));
}
}
};
var TYPE$b = tokenizer.TYPE;
var ATRULE$2 = TYPE$b.Atrule;
var SEMICOLON$1 = TYPE$b.Semicolon;
var LEFTCURLYBRACKET$2 = TYPE$b.LeftCurlyBracket;
var RIGHTCURLYBRACKET$1 = TYPE$b.RightCurlyBracket;
function isBlockAtrule() {
for (var offset = 1, type; type = this.scanner.lookupType(offset); offset++) {
if (type === RIGHTCURLYBRACKET$1) {
return true;
}
if (type === LEFTCURLYBRACKET$2 ||
type === ATRULE$2) {
return false;
}
}
this.scanner.skip(offset);
this.scanner.eat(RIGHTCURLYBRACKET$1);
}
var Atrule = {
name: 'Atrule',
structure: {
name: String,
expression: ['AtruleExpression', null],
block: ['Block', null]
},
parse: function() {
var start = this.scanner.tokenStart;
var name;
var nameLowerCase;
var expression = null;
var block = null;
this.scanner.eat(ATRULE$2);
name = this.scanner.substrToCursor(start + 1);
nameLowerCase = name.toLowerCase();
this.scanner.skipSC();
expression = this.AtruleExpression(name);
// turn empty AtruleExpression into null
if (expression.children.head === null) {
expression = null;
}
this.scanner.skipSC();
if (this.atrule.hasOwnProperty(nameLowerCase)) {
if (typeof this.atrule[nameLowerCase].block === 'function') {
if (this.scanner.tokenType !== LEFTCURLYBRACKET$2) {
// FIXME: make tolerant
this.scanner.error('Curly bracket is expected');
}
block = this.atrule[nameLowerCase].block.call(this);
} else {
if (!this.tolerant || !this.scanner.eof) {
this.scanner.eat(SEMICOLON$1);
}
}
} else {
switch (this.scanner.tokenType) {
case SEMICOLON$1:
this.scanner.next();
break;
case LEFTCURLYBRACKET$2:
// TODO: should consume block content as Raw?
block = this.Block(isBlockAtrule.call(this) ? this.Declaration : this.Rule);
break;
default:
if (!this.tolerant) {
this.scanner.error('Semicolon or block is expected');
}
}
}
return {
type: 'Atrule',
loc: this.getLocation(start, this.scanner.tokenStart),
name: name,
expression: expression,
block: block
};
},
generate: function(processChunk, node) {
processChunk('@');
processChunk(node.name);
if (node.expression !== null) {
processChunk(' ');
this.generate(processChunk, node.expression);
}
if (node.block) {
this.generate(processChunk, node.block);
} else {
processChunk(';');
}
},
walkContext: 'atrule'
};
var TYPE$c = tokenizer.TYPE;
var SEMICOLON$2 = TYPE$c.Semicolon;
var LEFTCURLYBRACKET$3 = TYPE$c.LeftCurlyBracket;
function consumeRaw$1(startToken) {
return new list().appendData(
this.Raw(startToken, SEMICOLON$2, LEFTCURLYBRACKET$3, false, true)
);
}
function consumeDefaultSequence() {
return this.readSequence(this.scope.AtruleExpression);
}
var AtruleExpression = {
name: 'AtruleExpression',
structure: {
children: [[]]
},
parse: function(name) {
var children = null;
var startToken = this.scanner.currentToken;
if (name !== null) {
name = name.toLowerCase();
}
if (this.parseAtruleExpression) {
// custom consumer
if (this.atrule.hasOwnProperty(name)) {
if (typeof this.atrule[name].expression === 'function') {
children = this.tolerantParse(this.atrule[name].expression, consumeRaw$1);
}
} else {
// default consumer
this.scanner.skipSC();
children = this.tolerantParse(consumeDefaultSequence, consumeRaw$1);
}
if (this.tolerant) {
if (this.scanner.eof || (this.scanner.tokenType !== SEMICOLON$2 && this.scanner.tokenType !== LEFTCURLYBRACKET$3)) {
children = consumeRaw$1.call(this, startToken);
}
}
} else {
children = consumeRaw$1.call(this, startToken);
}
if (children === null) {
children = new list();
}
return {
type: 'AtruleExpression',
loc: this.getLocationFromList(children),
children: children
};
},
generate: function(processChunk, node) {
this.each(processChunk, node);
},
walkContext: 'atruleExpression'
};
var TYPE$d = tokenizer.TYPE;
var IDENTIFIER$8 = TYPE$d.Identifier;
var STRING$4 = TYPE$d.String;
var DOLLARSIGN = TYPE$d.DollarSign;
var ASTERISK$2 = TYPE$d.Asterisk;
var COLON$2 = TYPE$d.Colon;
var EQUALSSIGN = TYPE$d.EqualsSign;
var LEFTSQUAREBRACKET$3 = TYPE$d.LeftSquareBracket;
var RIGHTSQUAREBRACKET$1 = TYPE$d.RightSquareBracket;
var CIRCUMFLEXACCENT = TYPE$d.CircumflexAccent;
var VERTICALLINE$1 = TYPE$d.VerticalLine;
var TILDE$1 = TYPE$d.Tilde;
function getAttributeName() {
if (this.scanner.eof) {
this.scanner.error('Unexpected end of input');
}
var start = this.scanner.tokenStart;
var expectIdentifier = false;
var checkColon = true;
if (this.scanner.tokenType === ASTERISK$2) {
expectIdentifier = true;
checkColon = false;
this.scanner.next();
} else if (this.scanner.tokenType !== VERTICALLINE$1) {
this.scanner.eat(IDENTIFIER$8);
}
if (this.scanner.tokenType === VERTICALLINE$1) {
if (this.scanner.lookupType(1) !== EQUALSSIGN) {
this.scanner.next();
this.scanner.eat(IDENTIFIER$8);
} else if (expectIdentifier) {
this.scanner.error('Identifier is expected', this.scanner.tokenEnd);
}
} else if (expectIdentifier) {
this.scanner.error('Vertical line is expected');
}
if (checkColon && this.scanner.tokenType === COLON$2) {
this.scanner.next();
this.scanner.eat(IDENTIFIER$8);
}
return {
type: 'Identifier',
loc: this.getLocation(start, this.scanner.tokenStart),
name: this.scanner.substrToCursor(start)
};
}
function getOperator() {
var start = this.scanner.tokenStart;
var tokenType = this.scanner.tokenType;
if (tokenType !== EQUALSSIGN && // =
tokenType !== TILDE$1 && // ~=
tokenType !== CIRCUMFLEXACCENT && // ^=
tokenType !== DOLLARSIGN && // $=
tokenType !== ASTERISK$2 && // *=
tokenType !== VERTICALLINE$1 // |=
) {
this.scanner.error('Attribute selector (=, ~=, ^=, $=, *=, |=) is expected');
}
if (tokenType === EQUALSSIGN) {
this.scanner.next();
} else {
this.scanner.next();
this.scanner.eat(EQUALSSIGN);
}
return this.scanner.substrToCursor(start);
}
// '[' S* attrib_name ']'
// '[' S* attrib_name S* attrib_matcher S* [ IDENT | STRING ] S* attrib_flags? S* ']'
var AttributeSelector = {
name: 'AttributeSelector',
structure: {
name: 'Identifier',
matcher: [String, null],
value: ['String', 'Identifier', null],
flags: [String, null]
},
parse: function() {
var start = this.scanner.tokenStart;
var name;
var matcher = null;
var value = null;
var flags = null;
this.scanner.eat(LEFTSQUAREBRACKET$3);
this.scanner.skipSC();
name = getAttributeName.call(this);
this.scanner.skipSC();
if (this.scanner.tokenType !== RIGHTSQUAREBRACKET$1) {
// avoid case `[name i]`
if (this.scanner.tokenType !== IDENTIFIER$8) {
matcher = getOperator.call(this);
this.scanner.skipSC();
value = this.scanner.tokenType === STRING$4
? this.String()
: this.Identifier();
this.scanner.skipSC();
}
// attribute flags
if (this.scanner.tokenType === IDENTIFIER$8) {
flags = this.scanner.getTokenValue();
this.scanner.next();
this.scanner.skipSC();
}
}
this.scanner.eat(RIGHTSQUAREBRACKET$1);
return {
type: 'AttributeSelector',
loc: this.getLocation(start, this.scanner.tokenStart),
name: name,
matcher: matcher,
value: value,
flags: flags
};
},
generate: function(processChunk, node) {
var flagsPrefix = ' ';
processChunk('[');
this.generate(processChunk, node.name);
if (node.matcher !== null) {
processChunk(node.matcher);
if (node.value !== null) {
this.generate(processChunk, node.value);
// space between string and flags is not required
if (node.value.type === 'String') {
flagsPrefix = '';
}
}
}
if (node.flags !== null) {
processChunk(flagsPrefix);
processChunk(node.flags);
}
processChunk(']');
}
};
var TYPE$e = tokenizer.TYPE;
var WHITESPACE$4 = TYPE$e.WhiteSpace;
var COMMENT$4 = TYPE$e.Comment;
var SEMICOLON$3 = TYPE$e.Semicolon;
var ATRULE$3 = TYPE$e.Atrule;
var LEFTCURLYBRACKET$4 = TYPE$e.LeftCurlyBracket;
var RIGHTCURLYBRACKET$2 = TYPE$e.RightCurlyBracket;
function consumeRaw$2(startToken) {
return this.Raw(startToken, 0, SEMICOLON$3, true, true);
}
var Block = {
name: 'Block',
structure: {
children: [['Atrule', 'Rule', 'Declaration']]
},
parse: function(defaultConsumer) {
if (!defaultConsumer) {
defaultConsumer = this.Declaration;
}
var start = this.scanner.tokenStart;
var children = new list();
this.scanner.eat(LEFTCURLYBRACKET$4);
scan:
while (!this.scanner.eof) {
switch (this.scanner.tokenType) {
case RIGHTCURLYBRACKET$2:
break scan;
case WHITESPACE$4:
case COMMENT$4:
case SEMICOLON$3:
this.scanner.next();
break;
case ATRULE$3:
children.appendData(this.tolerantParse(this.Atrule, consumeRaw$2));
break;
default:
children.appendData(this.tolerantParse(defaultConsumer, consumeRaw$2));
}
}
if (!this.tolerant || !this.scanner.eof) {
this.scanner.eat(RIGHTCURLYBRACKET$2);
}
return {
type: 'Block',
loc: this.getLocation(start, this.scanner.tokenStart),
children: children
};
},
generate: function(processChunk, node) {
processChunk('{');
this.each(processChunk, node);
processChunk('}');
},
walkContext: 'block'
};
var TYPE$f = tokenizer.TYPE;
var LEFTSQUAREBRACKET$4 = TYPE$f.LeftSquareBracket;
var RIGHTSQUAREBRACKET$2 = TYPE$f.RightSquareBracket;
// currently only Grid Layout uses square brackets, but left it universal
// https://drafts.csswg.org/css-grid/#track-sizing
// [ ident* ]
var Brackets = {
name: 'Brackets',
structure: {
children: [[]]
},
parse: function(readSequence, recognizer) {
var start = this.scanner.tokenStart;
var children = null;
this.scanner.eat(LEFTSQUAREBRACKET$4);
children = readSequence.call(this, recognizer);
this.scanner.eat(RIGHTSQUAREBRACKET$2);
return {
type: 'Brackets',
loc: this.getLocation(start, this.scanner.tokenStart),
children: children
};
},
generate: function(processChunk, node) {
processChunk('[');
this.each(processChunk, node);
processChunk(']');
}
};
var CDC$2 = tokenizer.TYPE.CDC;
var CDC_1 = {
name: 'CDC',
structure: [],
parse: function() {
var start = this.scanner.tokenStart;
this.scanner.eat(CDC$2); // -->
return {
type: 'CDC',
loc: this.getLocation(start, this.scanner.tokenStart)
};
},
generate: function(processChunk) {
processChunk('-->');
}
};
var CDO$2 = tokenizer.TYPE.CDO;
var CDO_1 = {
name: 'CDO',
structure: [],
parse: function() {
var start = this.scanner.tokenStart;
this.scanner.eat(CDO$2); // <!--
return {
type: 'CDO',
loc: this.getLocation(start, this.scanner.tokenStart)
};
},
generate: function(processChunk) {
processChunk('<!--');
}
};
var TYPE$g = tokenizer.TYPE;
var IDENTIFIER$9 = TYPE$g.Identifier;
var FULLSTOP$3 = TYPE$g.FullStop;
// '.' ident
var ClassSelector = {
name: 'ClassSelector',
structure: {
name: String
},
parse: function() {
this.scanner.eat(FULLSTOP$3);
return {
type: 'ClassSelector',
loc: this.getLocation(this.scanner.tokenStart - 1, this.scanner.tokenEnd),
name: this.scanner.consume(IDENTIFIER$9)
};
},
generate: function(processChunk, node) {
processChunk('.');
processChunk(node.name);
}
};
var TYPE$h = tokenizer.TYPE;
var PLUSSIGN$5 = TYPE$h.PlusSign;
var SOLIDUS$2 = TYPE$h.Solidus;
var GREATERTHANSIGN$2 = TYPE$h.GreaterThanSign;
var TILDE$2 = TYPE$h.Tilde;
// + | > | ~ | /deep/
var Combinator = {
name: 'Combinator',
structure: {
name: String
},
parse: function() {
var start = this.scanner.tokenStart;
switch (this.scanner.tokenType) {
case GREATERTHANSIGN$2:
case PLUSSIGN$5:
case TILDE$2:
this.scanner.next();
break;
case SOLIDUS$2:
this.scanner.next();
this.scanner.expectIdentifier('deep');
this.scanner.eat(SOLIDUS$2);
break;
default:
this.scanner.error('Combinator is expected');
}
return {
type: 'Combinator',
loc: this.getLocation(start, this.scanner.tokenStart),
name: this.scanner.substrToCursor(start)
};
},
generate: function(processChunk, node) {
processChunk(node.name);
}
};
var TYPE$i = tokenizer.TYPE;
var ASTERISK$3 = TYPE$i.Asterisk;
var SOLIDUS$3 = TYPE$i.Solidus;
// '/*' .* '*/'
var Comment = {
name: 'Comment',
structure: {
value: String
},
parse: function() {
var start = this.scanner.tokenStart;
var end = this.scanner.tokenEnd;
if ((end - start + 2) >= 2 &&
this.scanner.source.charCodeAt(end - 2) === ASTERISK$3 &&
this.scanner.source.charCodeAt(end - 1) === SOLIDUS$3) {
end -= 2;
}
this.scanner.next();
return {
type: 'Comment',
loc: this.getLocation(start, this.scanner.tokenStart),
value: this.scanner.source.substring(start + 2, end)
};
},
generate: function(processChunk, node) {
processChunk('/*');
processChunk(node.value);
processChunk('*/');
}
};
var TYPE$j = tokenizer.TYPE;
var IDENTIFIER$a = TYPE$j.Identifier;
var COLON$3 = TYPE$j.Colon;
var EXCLAMATIONMARK$2 = TYPE$j.ExclamationMark;
var SOLIDUS$4 = TYPE$j.Solidus;
var ASTERISK$4 = TYPE$j.Asterisk;
var DOLLARSIGN$1 = TYPE$j.DollarSign;
var HYPHENMINUS$6 = TYPE$j.HyphenMinus;
var SEMICOLON$4 = TYPE$j.Semicolon;
var RIGHTCURLYBRACKET$3 = TYPE$j.RightCurlyBracket;
var RIGHTPARENTHESIS$1 = TYPE$j.RightParenthesis;
var PLUSSIGN$6 = TYPE$j.PlusSign;
var NUMBERSIGN$2 = TYPE$j.NumberSign;
var Declaration = {
name: 'Declaration',
structure: {
important: [Boolean, String],
property: String,
value: ['Value', 'Raw']
},
parse: function() {
var start = this.scanner.tokenStart;
var property = readProperty.call(this);
var important = false;
var value;
this.scanner.skipSC();
this.scanner.eat(COLON$3);
if (isCustomProperty(property) ? this.parseCustomProperty : this.parseValue) {
value = this.Value(property);
} else {
value = this.Raw(this.scanner.currentToken, EXCLAMATIONMARK$2, SEMICOLON$4, false, false);
}
if (this.scanner.tokenType === EXCLAMATIONMARK$2) {
important = getImportant(this.scanner);
this.scanner.skipSC();
}
// TODO: include or not to include semicolon to range?
// if (this.scanner.tokenType === SEMICOLON) {
// this.scanner.next();
// }
if (!this.scanner.eof &&
this.scanner.tokenType !== SEMICOLON$4 &&
this.scanner.tokenType !== RIGHTPARENTHESIS$1 &&
this.scanner.tokenType !== RIGHTCURLYBRACKET$3) {
this.scanner.error();
}
return {
type: 'Declaration',
loc: this.getLocation(start, this.scanner.tokenStart),
important: important,
property: property,
value: value
};
},
generate: function(processChunk, node, item) {
processChunk(node.property);
processChunk(':');
this.generate(processChunk, node.value);
if (node.important) {
processChunk(node.important === true ? '!important' : '!' + node.important);
}
if (item && item.next) {
processChunk(';');
}
},
walkContext: 'declaration'
};
function isCustomProperty(name) {
return name.length >= 2 &&
name.charCodeAt(0) === HYPHENMINUS$6 &&
name.charCodeAt(1) === HYPHENMINUS$6;
}
function readProperty() {
var start = this.scanner.tokenStart;
var prefix = 0;
// hacks
switch (this.scanner.tokenType) {
case ASTERISK$4:
case DOLLARSIGN$1:
case PLUSSIGN$6:
case NUMBERSIGN$2:
prefix = 1;
break;
// TODO: not sure we should support this hack
case SOLIDUS$4:
prefix = this.scanner.lookupType(1) === SOLIDUS$4 ? 2 : 1;
break;
}
if (this.scanner.lookupType(prefix) === HYPHENMINUS$6) {
prefix++;
}
if (prefix) {
this.scanner.skip(prefix);
}
this.scanner.eat(IDENTIFIER$a);
return this.scanner.substrToCursor(start);
}
// ! ws* important
function getImportant(scanner) {
scanner.eat(EXCLAMATIONMARK$2);
scanner.skipSC();
var important = scanner.consume(IDENTIFIER$a);
// store original value in case it differ from `important`
// for better original source restoring and hacks like `!ie` support
return important === 'important' ? true : important;
}
var TYPE$k = tokenizer.TYPE;
var WHITESPACE$5 = TYPE$k.WhiteSpace;
var COMMENT$5 = TYPE$k.Comment;
var SEMICOLON$5 = TYPE$k.Semicolon;
function consumeRaw$3(startToken) {
return this.Raw(startToken, 0, SEMICOLON$5, true, true);
}
var DeclarationList = {
name: 'DeclarationList',
structure: {
children: [['Declaration']]
},
parse: function() {
var children = new list();
while (!this.scanner.eof) {
switch (this.scanner.tokenType) {
case WHITESPACE$5:
case COMMENT$5:
case SEMICOLON$5:
this.scanner.next();
break;
default:
children.appendData(this.tolerantParse(this.Declaration, consumeRaw$3));
}
}
return {
type: 'DeclarationList',
loc: this.getLocationFromList(children),
children: children
};
},
generate: function(processChunk, node) {
this.each(processChunk, node);
}
};
var NUMBER$5 = tokenizer.TYPE.Number;
// special reader for units to avoid adjoined IE hacks (i.e. '1px\9')
function readUnit(scanner) {
var unit = scanner.getTokenValue();
var backSlashPos = unit.indexOf('\\');
if (backSlashPos > 0) {
// patch token offset
scanner.tokenStart += backSlashPos;
// return part before backslash
return unit.substring(0, backSlashPos);
}
// no backslash in unit name
scanner.next();
return unit;
}
// number ident
var Dimension = {
name: 'Dimension',
structure: {
value: String,
unit: String
},
parse: function() {
var start = this.scanner.tokenStart;
var value = this.scanner.consume(NUMBER$5);
var unit = readUnit(this.scanner);
return {
type: 'Dimension',
loc: this.getLocation(start, this.scanner.tokenStart),
value: value,
unit: unit
};
},
generate: function(processChunk, node) {
processChunk(node.value);
processChunk(node.unit);
}
};
var TYPE$l = tokenizer.TYPE;
var RIGHTPARENTHESIS$2 = TYPE$l.RightParenthesis;
// <function-token> <sequence> ')'
var _Function = {
name: 'Function',
structure: {
name: String,
children: [[]]
},
parse: function(readSequence, recognizer) {
var start = this.scanner.tokenStart;
var name = this.scanner.consumeFunctionName();
var nameLowerCase = name.toLowerCase();
var children;
children = recognizer.hasOwnProperty(nameLowerCase)
? recognizer[nameLowerCase].call(this, recognizer)
: readSequence.call(this, recognizer);
this.scanner.eat(RIGHTPARENTHESIS$2);
return {
type: 'Function',
loc: this.getLocation(start, this.scanner.tokenStart),
name: name,
children: children
};
},
generate: function(processChunk, node) {
processChunk(node.name);
processChunk('(');
this.each(processChunk, node);
processChunk(')');
},
walkContext: 'function'
};
var isHex$1 = tokenizer.isHex;
var TYPE$m = tokenizer.TYPE;
var IDENTIFIER$b = TYPE$m.Identifier;
var NUMBER$6 = TYPE$m.Number;
var NUMBERSIGN$3 = TYPE$m.NumberSign;
function consumeHexSequence(scanner, required) {
if (!isHex$1(scanner.source.charCodeAt(scanner.tokenStart))) {
if (required) {
scanner.error('Unexpected input', scanner.tokenStart);
} else {
return;
}
}
for (var pos = scanner.tokenStart + 1; pos < scanner.tokenEnd; pos++) {
var code = scanner.source.charCodeAt(pos);
// break on non-hex char
if (!isHex$1(code)) {
// break token, exclude symbol
scanner.tokenStart = pos;
return;
}
}
// token is full hex sequence, go to next token
scanner.next();
}
// # ident
var HexColor = {
name: 'HexColor',
structure: {
value: String
},
parse: function() {
var start = this.scanner.tokenStart;
this.scanner.eat(NUMBERSIGN$3);
switch (this.scanner.tokenType) {
case NUMBER$6:
consumeHexSequence(this.scanner, true);
// if token is identifier then number consists of hex only,
// try to add identifier to result
if (this.scanner.tokenType === IDENTIFIER$b) {
consumeHexSequence(this.scanner, false);
}
break;
case IDENTIFIER$b:
consumeHexSequence(this.scanner, true);
break;
default:
this.scanner.error('Number or identifier is expected');
}
return {
type: 'HexColor',
loc: this.getLocation(start, this.scanner.tokenStart),
value: this.scanner.substrToCursor(start + 1) // skip #
};
},
generate: function(processChunk, node) {
processChunk('#');
processChunk(node.value);
}
};
var TYPE$n = tokenizer.TYPE;
var IDENTIFIER$c = TYPE$n.Identifier;
var Identifier = {
name: 'Identifier',
structure: {
name: String
},
parse: function() {
return {
type: 'Identifier',
loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
name: this.scanner.consume(IDENTIFIER$c)
};
},
generate: function(processChunk, node) {
processChunk(node.name);
}
};
var TYPE$o = tokenizer.TYPE;
var IDENTIFIER$d = TYPE$o.Identifier;
var NUMBERSIGN$4 = TYPE$o.NumberSign;
// '#' ident
var IdSelector = {
name: 'IdSelector',
structure: {
name: String
},
parse: function() {
this.scanner.eat(NUMBERSIGN$4);
return {
type: 'IdSelector',
loc: this.getLocation(this.scanner.tokenStart - 1, this.scanner.tokenEnd),
name: this.scanner.consume(IDENTIFIER$d)
};
},
generate: function(processChunk, node) {
processChunk('#');
processChunk(node.name);
}
};
var TYPE$p = tokenizer.TYPE;
var IDENTIFIER$e = TYPE$p.Identifier;
var NUMBER$7 = TYPE$p.Number;
var LEFTPARENTHESIS$4 = TYPE$p.LeftParenthesis;
var RIGHTPARENTHESIS$3 = TYPE$p.RightParenthesis;
var COLON$4 = TYPE$p.Colon;
var SOLIDUS$5 = TYPE$p.Solidus;
var MediaFeature = {
name: 'MediaFeature',
structure: {
name: String,
value: ['Identifier', 'Number', 'Dimension', 'Ratio', null]
},
parse: function() {
var start = this.scanner.tokenStart;
var name;
var value = null;
this.scanner.eat(LEFTPARENTHESIS$4);
this.scanner.skipSC();
name = this.scanner.consume(IDENTIFIER$e);
this.scanner.skipSC();
if (this.scanner.tokenType !== RIGHTPARENTHESIS$3) {
this.scanner.eat(COLON$4);
this.scanner.skipSC();
switch (this.scanner.tokenType) {
case NUMBER$7:
if (this.scanner.lookupType(1) === IDENTIFIER$e) {
value = this.Dimension();
} else if (this.scanner.lookupNonWSType(1) === SOLIDUS$5) {
value = this.Ratio();
} else {
value = this.Number();
}
break;
case IDENTIFIER$e:
value = this.Identifier();
break;
default:
this.scanner.error('Number, dimension, ratio or identifier is expected');
}
this.scanner.skipSC();
}
this.scanner.eat(RIGHTPARENTHESIS$3);
return {
type: 'MediaFeature',
loc: this.getLocation(start, this.scanner.tokenStart),
name: name,
value: value
};
},
generate: function(processChunk, node) {
processChunk('(');
processChunk(node.name);
if (node.value !== null) {
processChunk(':');
this.generate(processChunk, node.value);
}
processChunk(')');
}
};
var TYPE$q = tokenizer.TYPE;
var WHITESPACE$6 = TYPE$q.WhiteSpace;
var COMMENT$6 = TYPE$q.Comment;
var IDENTIFIER$f = TYPE$q.Identifier;
var LEFTPARENTHESIS$5 = TYPE$q.LeftParenthesis;
var MediaQuery = {
name: 'MediaQuery',
structure: {
children: [['Identifier', 'MediaFeature', 'WhiteSpace']]
},
parse: function() {
this.scanner.skipSC();
var children = new list();
var child = null;
var space = null;
scan:
while (!this.scanner.eof) {
switch (this.scanner.tokenType) {
case COMMENT$6:
this.scanner.next();
continue;
case WHITESPACE$6:
space = this.WhiteSpace();
continue;
case IDENTIFIER$f:
child = this.Identifier();
break;
case LEFTPARENTHESIS$5:
child = this.MediaFeature();
break;
default:
break scan;
}
if (space !== null) {
children.appendData(space);
space = null;
}
children.appendData(child);
}
if (child === null) {
this.scanner.error('Identifier or parenthesis is expected');
}
return {
type: 'MediaQuery',
loc: this.getLocationFromList(children),
children: children
};
},
generate: function(processChunk, node) {
this.each(processChunk, node);
}
};
var COMMA$2 = tokenizer.TYPE.Comma;
var MediaQueryList = {
name: 'MediaQueryList',
structure: {
children: [['MediaQuery']]
},
parse: function(relative) {
var children = new list();
this.scanner.skipSC();
while (!this.scanner.eof) {
children.appendData(this.MediaQuery(relative));
if (this.scanner.tokenType !== COMMA$2) {
break;
}
this.scanner.next();
}
return {
type: 'MediaQueryList',
loc: this.getLocationFromList(children),
children: children
};
},
generate: function(processChunk, node) {
this.eachComma(processChunk, node);
}
};
// https://drafts.csswg.org/css-syntax-3/#the-anb-type
var Nth = {
name: 'Nth',
structure: {
nth: ['AnPlusB', 'Identifier'],
selector: ['SelectorList', null]
},
parse: function(allowOfClause) {
this.scanner.skipSC();
var start = this.scanner.tokenStart;
var end = start;
var selector = null;
var query;
if (this.scanner.lookupValue(0, 'odd') || this.scanner.lookupValue(0, 'even')) {
query = this.Identifier();
} else {
query = this.AnPlusB();
}
this.scanner.skipSC();
if (allowOfClause && this.scanner.lookupValue(0, 'of')) {
this.scanner.next();
selector = this.SelectorList();
if (this.needPositions) {
end = selector.children.last().loc.end.offset;
}
} else {
if (this.needPositions) {
end = query.loc.end.offset;
}
}
return {
type: 'Nth',
loc: this.getLocation(start, end),
nth: query,
selector: selector
};
},
generate: function(processChunk, node) {
this.generate(processChunk, node.nth);
if (node.selector !== null) {
processChunk(' of ');
this.generate(processChunk, node.selector);
}
}
};
var NUMBER$8 = tokenizer.TYPE.Number;
var _Number = {
name: 'Number',
structure: {
value: String
},
parse: function() {
return {
type: 'Number',
loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
value: this.scanner.consume(NUMBER$8)
};
},
generate: function(processChunk, node) {
processChunk(node.value);
}
};
// '/' | '*' | ',' | ':' | '+' | '-'
var Operator = {
name: 'Operator',
structure: {
value: String
},
parse: function() {
var start = this.scanner.tokenStart;
this.scanner.next();
return {
type: 'Operator',
loc: this.getLocation(start, this.scanner.tokenStart),
value: this.scanner.substrToCursor(start)
};
},
generate: function(processChunk, node) {
processChunk(node.value);
}
};
var TYPE$r = tokenizer.TYPE;
var LEFTPARENTHESIS$6 = TYPE$r.LeftParenthesis;
var RIGHTPARENTHESIS$4 = TYPE$r.RightParenthesis;
var Parentheses = {
name: 'Parentheses',
structure: {
children: [[]]
},
parse: function(readSequence, recognizer) {
var start = this.scanner.tokenStart;
var children = null;
this.scanner.eat(LEFTPARENTHESIS$6);
children = readSequence.call(this, recognizer);
this.scanner.eat(RIGHTPARENTHESIS$4);
return {
type: 'Parentheses',
loc: this.getLocation(start, this.scanner.tokenStart),
children: children
};
},
generate: function(processChunk, node) {
processChunk('(');
this.each(processChunk, node);
processChunk(')');
}
};
var TYPE$s = tokenizer.TYPE;
var NUMBER$9 = TYPE$s.Number;
var PERCENTSIGN$1 = TYPE$s.PercentSign;
var Percentage = {
name: 'Percentage',
structure: {
value: String
},
parse: function() {
var start = this.scanner.tokenStart;
var number = this.scanner.consume(NUMBER$9);
this.scanner.eat(PERCENTSIGN$1);
return {
type: 'Percentage',
loc: this.getLocation(start, this.scanner.tokenStart),
value: number
};
},
generate: function(processChunk, node) {
processChunk(node.value);
processChunk('%');
}
};
var TYPE$t = tokenizer.TYPE;
var IDENTIFIER$g = TYPE$t.Identifier;
var FUNCTION$4 = TYPE$t.Function;
var COLON$5 = TYPE$t.Colon;
var RIGHTPARENTHESIS$5 = TYPE$t.RightParenthesis;
// : ident [ '(' .. ')' ]?
var PseudoClassSelector = {
name: 'PseudoClassSelector',
structure: {
name: String,
children: [['Raw'], null]
},
parse: function() {
var start = this.scanner.tokenStart;
var children = null;
var name;
var nameLowerCase;
this.scanner.eat(COLON$5);
if (this.scanner.tokenType === FUNCTION$4) {
name = this.scanner.consumeFunctionName();
nameLowerCase = name.toLowerCase();
if (this.pseudo.hasOwnProperty(nameLowerCase)) {
this.scanner.skipSC();
children = this.pseudo[nameLowerCase].call(this);
this.scanner.skipSC();
} else {
children = new list().appendData(
this.Raw(this.scanner.currentToken, 0, 0, false, false)
);
}
this.scanner.eat(RIGHTPARENTHESIS$5);
} else {
name = this.scanner.consume(IDENTIFIER$g);
}
return {
type: 'PseudoClassSelector',
loc: this.getLocation(start, this.scanner.tokenStart),
name: name,
children: children
};
},
generate: function(processChunk, node) {
processChunk(':');
processChunk(node.name);
if (node.children !== null) {
processChunk('(');
this.each(processChunk, node);
processChunk(')');
}
},
walkContext: 'function'
};
var TYPE$u = tokenizer.TYPE;
var IDENTIFIER$h = TYPE$u.Identifier;
var FUNCTION$5 = TYPE$u.Function;
var COLON$6 = TYPE$u.Colon;
var RIGHTPARENTHESIS$6 = TYPE$u.RightParenthesis;
// :: ident [ '(' .. ')' ]?
var PseudoElementSelector = {
name: 'PseudoElementSelector',
structure: {
name: String,
children: [['Raw'], null]
},
parse: function() {
var start = this.scanner.tokenStart;
var children = null;
var name;
var nameLowerCase;
this.scanner.eat(COLON$6);
this.scanner.eat(COLON$6);
if (this.scanner.tokenType === FUNCTION$5) {
name = this.scanner.consumeFunctionName();
nameLowerCase = name.toLowerCase();
if (this.pseudo.hasOwnProperty(nameLowerCase)) {
this.scanner.skipSC();
children = this.pseudo[nameLowerCase].call(this);
this.scanner.skipSC();
} else {
children = new list().appendData(
this.Raw(this.scanner.currentToken, 0, 0, false, false)
);
}
this.scanner.eat(RIGHTPARENTHESIS$6);
} else {
name = this.scanner.consume(IDENTIFIER$h);
}
return {
type: 'PseudoElementSelector',
loc: this.getLocation(start, this.scanner.tokenStart),
name: name,
children: children
};
},
generate: function(processChunk, node) {
processChunk('::');
processChunk(node.name);
if (node.children !== null) {
processChunk('(');
this.each(processChunk, node);
processChunk(')');
}
},
walkContext: 'function'
};
var isNumber$3 = tokenizer.isNumber;
var TYPE$v = tokenizer.TYPE;
var NUMBER$a = TYPE$v.Number;
var SOLIDUS$6 = TYPE$v.Solidus;
var FULLSTOP$4 = TYPE$v.FullStop;
// Terms of <ratio> should to be a positive number (not zero or negative)
// (see https://drafts.csswg.org/mediaqueries-3/#values)
// However, -o-min-device-pixel-ratio takes fractional values as a ratio's term
// and this is using by various sites. Therefore we relax checking on parse
// to test a term is unsigned number without exponent part.
// Additional checks may to be applied on lexer validation.
function consumeNumber(scanner) {
var value = scanner.consumeNonWS(NUMBER$a);
for (var i = 0; i < value.length; i++) {
var code = value.charCodeAt(i);
if (!isNumber$3(code) && code !== FULLSTOP$4) {
scanner.error('Unsigned number is expected', scanner.tokenStart - value.length + i);
}
}
if (Number(value) === 0) {
scanner.error('Zero number is not allowed', scanner.tokenStart - value.length);
}
return value;
}
// <positive-integer> S* '/' S* <positive-integer>
var Ratio = {
name: 'Ratio',
structure: {
left: String,
right: String
},
parse: function() {
var start = this.scanner.tokenStart;
var left = consumeNumber(this.scanner);
var right;
this.scanner.eatNonWS(SOLIDUS$6);
right = consumeNumber(this.scanner);
return {
type: 'Ratio',
loc: this.getLocation(start, this.scanner.tokenStart),
left: left,
right: right
};
},
generate: function(processChunk, node) {
processChunk(node.left);
processChunk('/');
processChunk(node.right);
}
};
var Raw = {
name: 'Raw',
structure: {
value: String
},
parse: function(startToken, endTokenType1, endTokenType2, includeTokenType2, excludeWhiteSpace) {
var startOffset = this.scanner.getTokenStart(startToken);
var endOffset;
this.scanner.skip(
this.scanner.getRawLength(
startToken,
endTokenType1,
endTokenType2,
includeTokenType2
)
);
if (excludeWhiteSpace && this.scanner.tokenStart > startOffset) {
endOffset = this.scanner.getOffsetExcludeWS();
} else {
endOffset = this.scanner.tokenStart;
}
return {
type: 'Raw',
loc: this.getLocation(startOffset, endOffset),
value: this.scanner.source.substring(startOffset, endOffset)
};
},
generate: function(processChunk, node) {
processChunk(node.value);
}
};
var TYPE$w = tokenizer.TYPE;
var LEFTCURLYBRACKET$5 = TYPE$w.LeftCurlyBracket;
function consumeRaw$4(startToken) {
return this.Raw(startToken, LEFTCURLYBRACKET$5, 0, false, true);
}
var Rule = {
name: 'Rule',
structure: {
selector: ['SelectorList', 'Raw'],
block: ['Block']
},
parse: function() {
var startToken = this.scanner.currentToken;
var startOffset = this.scanner.tokenStart;
var selector = this.parseSelector
? this.tolerantParse(this.SelectorList, consumeRaw$4)
: consumeRaw$4.call(this, startToken);
var block = this.Block(this.Declaration);
return {
type: 'Rule',
loc: this.getLocation(startOffset, this.scanner.tokenStart),
selector: selector,
block: block
};
},
generate: function(processChunk, node) {
this.generate(processChunk, node.selector);
this.generate(processChunk, node.block);
},
walkContext: 'rule'
};
var Selector = {
name: 'Selector',
structure: {
children: [[
'TypeSelector',
'IdSelector',
'ClassSelector',
'AttributeSelector',
'PseudoClassSelector',
'PseudoElementSelector',
'Combinator',
'WhiteSpace'
]]
},
parse: function() {
var children = this.readSequence(this.scope.Selector);
// nothing were consumed
if (children.isEmpty()) {
this.scanner.error('Selector is expected');
}
return {
type: 'Selector',
loc: this.getLocationFromList(children),
children: children
};
},
generate: function(processChunk, node) {
this.each(processChunk, node);
}
};
var TYPE$x = tokenizer.TYPE;
var COMMA$3 = TYPE$x.Comma;
var LEFTCURLYBRACKET$6 = TYPE$x.LeftCurlyBracket;
var SelectorList = {
name: 'SelectorList',
structure: {
children: [['Selector', 'Raw']]
},
parse: function() {
var children = new list();
while (!this.scanner.eof) {
children.appendData(this.parseSelector
? this.Selector()
: this.Raw(this.scanner.currentToken, COMMA$3, LEFTCURLYBRACKET$6, false, false)
);
if (this.scanner.tokenType === COMMA$3) {
this.scanner.next();
continue;
}
break;
}
return {
type: 'SelectorList',
loc: this.getLocationFromList(children),
children: children
};
},
generate: function(processChunk, node) {
this.eachComma(processChunk, node);
},
walkContext: 'selector'
};
var STRING$5 = tokenizer.TYPE.String;
var _String = {
name: 'String',
structure: {
value: String
},
parse: function() {
return {
type: 'String',
loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
value: this.scanner.consume(STRING$5)
};
},
generate: function(processChunk, node) {
processChunk(node.value);
}
};
var TYPE$y = tokenizer.TYPE;
var WHITESPACE$7 = TYPE$y.WhiteSpace;
var COMMENT$7 = TYPE$y.Comment;
var EXCLAMATIONMARK$3 = TYPE$y.ExclamationMark;
var ATRULE$4 = TYPE$y.Atrule;
var CDO$3 = TYPE$y.CDO;
var CDC$3 = TYPE$y.CDC;
function consumeRaw$5(startToken) {
return this.Raw(startToken, 0, 0, false, false);
}
var StyleSheet = {
name: 'StyleSheet',
structure: {
children: [['Comment', 'Atrule', 'Rule', 'Raw']]
},
parse: function() {
var start = this.scanner.tokenStart;
var children = new list();
var child;
while (!this.scanner.eof) {
switch (this.scanner.tokenType) {
case WHITESPACE$7:
this.scanner.next();
continue;
case COMMENT$7:
// ignore comments except exclamation comments (i.e. /*! .. */) on top level
if (this.scanner.source.charCodeAt(this.scanner.tokenStart + 2) !== EXCLAMATIONMARK$3) {
this.scanner.next();
continue;
}
child = this.Comment();
break;
case CDO$3: // <!--
child = this.CDO();
break;
case CDC$3: // -->
child = this.CDC();
break;
// CSS Syntax Module Level 3
// §2.2 Error handling
// At the "top level" of a stylesheet, an <at-keyword-token> starts an at-rule.
case ATRULE$4:
child = this.Atrule();
break;
// Anything else starts a qualified rule ...
default:
child = this.tolerantParse(this.Rule, consumeRaw$5);
}
children.appendData(child);
}
return {
type: 'StyleSheet',
loc: this.getLocation(start, this.scanner.tokenStart),
children: children
};
},
generate: function(processChunk, node) {
this.each(processChunk, node);
},
walkContext: 'stylesheet'
};
var TYPE$z = tokenizer.TYPE;
var IDENTIFIER$i = TYPE$z.Identifier;
var ASTERISK$5 = TYPE$z.Asterisk;
var VERTICALLINE$2 = TYPE$z.VerticalLine;
function eatIdentifierOrAsterisk() {
if (this.scanner.tokenType !== IDENTIFIER$i &&
this.scanner.tokenType !== ASTERISK$5) {
this.scanner.error('Identifier or asterisk is expected');
}
this.scanner.next();
}
// ident
// ident|ident
// ident|*
// *
// *|ident
// *|*
// |ident
// |*
var TypeSelector = {
name: 'TypeSelector',
structure: {
name: String
},
parse: function() {
var start = this.scanner.tokenStart;
if (this.scanner.tokenType === VERTICALLINE$2) {
this.scanner.next();
eatIdentifierOrAsterisk.call(this);
} else {
eatIdentifierOrAsterisk.call(this);
if (this.scanner.tokenType === VERTICALLINE$2) {
this.scanner.next();
eatIdentifierOrAsterisk.call(this);
}
}
return {
type: 'TypeSelector',
loc: this.getLocation(start, this.scanner.tokenStart),
name: this.scanner.substrToCursor(start)
};
},
generate: function(processChunk, node) {
processChunk(node.name);
}
};
var isHex$2 = tokenizer.isHex;
var TYPE$A = tokenizer.TYPE;
var IDENTIFIER$j = TYPE$A.Identifier;
var NUMBER$b = TYPE$A.Number;
var PLUSSIGN$7 = TYPE$A.PlusSign;
var HYPHENMINUS$7 = TYPE$A.HyphenMinus;
var FULLSTOP$5 = TYPE$A.FullStop;
var QUESTIONMARK = TYPE$A.QuestionMark;
function scanUnicodeNumber(scanner) {
for (var pos = scanner.tokenStart + 1; pos < scanner.tokenEnd; pos++) {
var code = scanner.source.charCodeAt(pos);
// break on fullstop or hyperminus/plussign after exponent
if (code === FULLSTOP$5 || code === PLUSSIGN$7) {
// break token, exclude symbol
scanner.tokenStart = pos;
return false;
}
}
return true;
}
// https://drafts.csswg.org/css-syntax-3/#urange
function scanUnicodeRange(scanner) {
var hexStart = scanner.tokenStart + 1; // skip +
var hexLength = 0;
scan: {
if (scanner.tokenType === NUMBER$b) {
if (scanner.source.charCodeAt(scanner.tokenStart) !== FULLSTOP$5 && scanUnicodeNumber(scanner)) {
scanner.next();
} else if (scanner.source.charCodeAt(scanner.tokenStart) !== HYPHENMINUS$7) {
break scan;
}
} else {
scanner.next(); // PLUSSIGN
}
if (scanner.tokenType === HYPHENMINUS$7) {
scanner.next();
}
if (scanner.tokenType === NUMBER$b) {
scanner.next();
}
if (scanner.tokenType === IDENTIFIER$j) {
scanner.next();
}
if (scanner.tokenStart === hexStart) {
scanner.error('Unexpected input', hexStart);
}
}
// validate for U+x{1,6} or U+x{1,6}-x{1,6}
// where x is [0-9a-fA-F]
for (var i = hexStart, wasHyphenMinus = false; i < scanner.tokenStart; i++) {
var code = scanner.source.charCodeAt(i);
if (isHex$2(code) === false && (code !== HYPHENMINUS$7 || wasHyphenMinus)) {
scanner.error('Unexpected input', i);
}
if (code === HYPHENMINUS$7) {
// hex sequence shouldn't be an empty
if (hexLength === 0) {
scanner.error('Unexpected input', i);
}
wasHyphenMinus = true;
hexLength = 0;
} else {
hexLength++;
// too long hex sequence
if (hexLength > 6) {
scanner.error('Too long hex sequence', i);
}
}
}
// check we have a non-zero sequence
if (hexLength === 0) {
scanner.error('Unexpected input', i - 1);
}
// U+abc???
if (!wasHyphenMinus) {
// consume as many U+003F QUESTION MARK (?) code points as possible
for (; hexLength < 6 && !scanner.eof; scanner.next()) {
if (scanner.tokenType !== QUESTIONMARK) {
break;
}
hexLength++;
}
}
}
var UnicodeRange = {
name: 'UnicodeRange',
structure: {
value: String
},
parse: function() {
var start = this.scanner.tokenStart;
this.scanner.next(); // U or u
scanUnicodeRange(this.scanner);
return {
type: 'UnicodeRange',
loc: this.getLocation(start, this.scanner.tokenStart),
value: this.scanner.substrToCursor(start)
};
},
generate: function(processChunk, node) {
processChunk(node.value);
}
};
var TYPE$B = tokenizer.TYPE;
var STRING$6 = TYPE$B.String;
var URL$4 = TYPE$B.Url;
var RAW$2 = TYPE$B.Raw;
var RIGHTPARENTHESIS$7 = TYPE$B.RightParenthesis;
// url '(' S* (string | raw) S* ')'
var Url = {
name: 'Url',
structure: {
value: ['String', 'Raw']
},
parse: function() {
var start = this.scanner.tokenStart;
var value;
this.scanner.eat(URL$4);
this.scanner.skipSC();
switch (this.scanner.tokenType) {
case STRING$6:
value = this.String();
break;
case RAW$2:
value = this.Raw(this.scanner.currentToken, 0, RAW$2, true, false);
break;
default:
this.scanner.error('String or Raw is expected');
}
this.scanner.skipSC();
this.scanner.eat(RIGHTPARENTHESIS$7);
return {
type: 'Url',
loc: this.getLocation(start, this.scanner.tokenStart),
value: value
};
},
generate: function(processChunk, node) {
processChunk('url');
processChunk('(');
this.generate(processChunk, node.value);
processChunk(')');
}
};
var endsWith$1 = tokenizer.endsWith;
var TYPE$C = tokenizer.TYPE;
var WHITESPACE$8 = TYPE$C.WhiteSpace;
var COMMENT$8 = TYPE$C.Comment;
var FUNCTION$6 = TYPE$C.Function;
var COLON$7 = TYPE$C.Colon;
var SEMICOLON$6 = TYPE$C.Semicolon;
var EXCLAMATIONMARK$4 = TYPE$C.ExclamationMark;
// 'progid:' ws* 'DXImageTransform.Microsoft.' ident ws* '(' .* ')'
function checkProgid(scanner) {
var offset = 0;
for (var type; type = scanner.lookupType(offset); offset++) {
if (type !== WHITESPACE$8 && type !== COMMENT$8) {
break;
}
}
if (scanner.lookupValue(offset, 'alpha(') ||
scanner.lookupValue(offset, 'chroma(') ||
scanner.lookupValue(offset, 'dropshadow(')) {
if (scanner.lookupType(offset) !== FUNCTION$6) {
return false;
}
} else {
if (scanner.lookupValue(offset, 'progid') === false ||
scanner.lookupType(offset + 1) !== COLON$7) {
return false;
}
}
return true;
}
var Value = {
name: 'Value',
structure: {
children: [[]]
},
parse: function(property) {
// special parser for filter property since it can contains non-standart syntax for old IE
if (property !== null && endsWith$1(property, 'filter') && checkProgid(this.scanner)) {
this.scanner.skipSC();
return this.Raw(this.scanner.currentToken, EXCLAMATIONMARK$4, SEMICOLON$6, false, false);
}
var start = this.scanner.tokenStart;
var children = this.readSequence(this.scope.Value);
return {
type: 'Value',
loc: this.getLocation(start, this.scanner.tokenStart),
children: children
};
},
generate: function(processChunk, node) {
this.each(processChunk, node);
}
};
var WHITESPACE$9 = tokenizer.TYPE.WhiteSpace;
var SPACE$2 = Object.freeze({
type: 'WhiteSpace',
loc: null,
value: ' '
});
var WhiteSpace = {
name: 'WhiteSpace',
structure: {
value: String
},
parse: function() {
this.scanner.eat(WHITESPACE$9);
return SPACE$2;
// return {
// type: 'WhiteSpace',
// loc: this.getLocation(this.scanner.tokenStart, this.scanner.tokenEnd),
// value: this.scanner.consume(WHITESPACE)
// };
},
generate: function(processChunk, node) {
processChunk(node.value);
}
};
var node = {
AnPlusB: AnPlusB,
Atrule: Atrule,
AtruleExpression: AtruleExpression,
AttributeSelector: AttributeSelector,
Block: Block,
Brackets: Brackets,
CDC: CDC_1,
CDO: CDO_1,
ClassSelector: ClassSelector,
Combinator: Combinator,
Comment: Comment,
Declaration: Declaration,
DeclarationList: DeclarationList,
Dimension: Dimension,
Function: _Function,
HexColor: HexColor,
Identifier: Identifier,
IdSelector: IdSelector,
MediaFeature: MediaFeature,
MediaQuery: MediaQuery,
MediaQueryList: MediaQueryList,
Nth: Nth,
Number: _Number,
Operator: Operator,
Parentheses: Parentheses,
Percentage: Percentage,
PseudoClassSelector: PseudoClassSelector,
PseudoElementSelector: PseudoElementSelector,
Ratio: Ratio,
Raw: Raw,
Rule: Rule,
Selector: Selector,
SelectorList: SelectorList,
String: _String,
StyleSheet: StyleSheet,
TypeSelector: TypeSelector,
UnicodeRange: UnicodeRange,
Url: Url,
Value: Value,
WhiteSpace: WhiteSpace
};
var parser = {
parseContext: {
default: 'StyleSheet',
stylesheet: 'StyleSheet',
atrule: 'Atrule',
atruleExpression: function(options) {
return this.AtruleExpression(options.atrule ? String(options.atrule) : null);
},
mediaQueryList: 'MediaQueryList',
mediaQuery: 'MediaQuery',
rule: 'Rule',
selectorList: 'SelectorList',
selector: 'Selector',
block: function() {
return this.Block(this.Declaration);
},
declarationList: 'DeclarationList',
declaration: 'Declaration',
value: function(options) {
return this.Value(options.property ? String(options.property) : null);
}
},
scope: scope,
atrule: atrule,
pseudo: pseudo,
node: node
};
var parser$1 = create(parser);
function read_style(parser, start, attributes) {
const content_start = parser.index;
const styles = parser.read_until(/<\/style>/);
const content_end = parser.index;
let ast;
try {
ast = parser$1(styles, {
positions: true,
offset: content_start,
});
}
catch (err) {
if (err.name === 'CssSyntaxError') {
parser.error({
code: `css-syntax-error`,
message: err.message
}, err.offset);
}
else {
throw err;
}
}
ast = JSON.parse(JSON.stringify(ast));
// tidy up AST
walk(ast, {
enter: (node) => {
// replace `ref:a` nodes
if (node.type === 'Selector') {
for (let i = 0; i < node.children.length; i += 1) {
const a = node.children[i];
const b = node.children[i + 1];
if (is_ref_selector(a, b)) {
parser.error({
code: `invalid-ref-selector`,
message: 'ref selectors are no longer supported'
}, a.loc.start.offset);
}
}
}
if (node.type === 'Declaration' && node.value.type === 'Value' && node.value.children.length === 0) {
parser.error({
code: `invalid-declaration`,
message: `Declaration cannot be empty`
}, node.start);
}
if (node.type === 'PseudoClassSelector' && node.name === 'global' && node.children === null) {
parser.error({
code: `css-syntax-error`,
message: `:global() must contain a selector`
}, node.loc.start.offset);
}
if (node.loc) {
node.start = node.loc.start.offset;
node.end = node.loc.end.offset;
delete node.loc;
}
}
});
parser.eat('</style>', true);
const end = parser.index;
return {
type: 'Style',
start,
end,
attributes,
children: ast.children,
content: {
start: content_start,
end: content_end,
styles
}
};
}
function is_ref_selector(a, b) {
if (!b)
return false;
return (a.type === 'TypeSelector' &&
a.name === 'ref' &&
b.type === 'PseudoClassSelector');
}
// https://dev.w3.org/html5/html-author/charref
var entities = {
CounterClockwiseContourIntegral: 8755,
ClockwiseContourIntegral: 8754,
DoubleLongLeftRightArrow: 10234,
DiacriticalDoubleAcute: 733,
NotSquareSupersetEqual: 8931,
CloseCurlyDoubleQuote: 8221,
DoubleContourIntegral: 8751,
FilledVerySmallSquare: 9642,
NegativeVeryThinSpace: 8203,
NotPrecedesSlantEqual: 8928,
NotRightTriangleEqual: 8941,
NotSucceedsSlantEqual: 8929,
CapitalDifferentialD: 8517,
DoubleLeftRightArrow: 8660,
DoubleLongRightArrow: 10233,
EmptyVerySmallSquare: 9643,
NestedGreaterGreater: 8811,
NotDoubleVerticalBar: 8742,
NotLeftTriangleEqual: 8940,
NotSquareSubsetEqual: 8930,
OpenCurlyDoubleQuote: 8220,
ReverseUpEquilibrium: 10607,
DoubleLongLeftArrow: 10232,
DownLeftRightVector: 10576,
LeftArrowRightArrow: 8646,
NegativeMediumSpace: 8203,
RightArrowLeftArrow: 8644,
SquareSupersetEqual: 8850,
leftrightsquigarrow: 8621,
DownRightTeeVector: 10591,
DownRightVectorBar: 10583,
LongLeftRightArrow: 10231,
Longleftrightarrow: 10234,
NegativeThickSpace: 8203,
PrecedesSlantEqual: 8828,
ReverseEquilibrium: 8651,
RightDoubleBracket: 10215,
RightDownTeeVector: 10589,
RightDownVectorBar: 10581,
RightTriangleEqual: 8885,
SquareIntersection: 8851,
SucceedsSlantEqual: 8829,
blacktriangleright: 9656,
longleftrightarrow: 10231,
DoubleUpDownArrow: 8661,
DoubleVerticalBar: 8741,
DownLeftTeeVector: 10590,
DownLeftVectorBar: 10582,
FilledSmallSquare: 9724,
GreaterSlantEqual: 10878,
LeftDoubleBracket: 10214,
LeftDownTeeVector: 10593,
LeftDownVectorBar: 10585,
LeftTriangleEqual: 8884,
NegativeThinSpace: 8203,
NotReverseElement: 8716,
NotTildeFullEqual: 8775,
RightAngleBracket: 10217,
RightUpDownVector: 10575,
SquareSubsetEqual: 8849,
VerticalSeparator: 10072,
blacktriangledown: 9662,
blacktriangleleft: 9666,
leftrightharpoons: 8651,
rightleftharpoons: 8652,
twoheadrightarrow: 8608,
DiacriticalAcute: 180,
DiacriticalGrave: 96,
DiacriticalTilde: 732,
DoubleRightArrow: 8658,
DownArrowUpArrow: 8693,
EmptySmallSquare: 9723,
GreaterEqualLess: 8923,
GreaterFullEqual: 8807,
LeftAngleBracket: 10216,
LeftUpDownVector: 10577,
LessEqualGreater: 8922,
NonBreakingSpace: 160,
NotRightTriangle: 8939,
NotSupersetEqual: 8841,
RightTriangleBar: 10704,
RightUpTeeVector: 10588,
RightUpVectorBar: 10580,
UnderParenthesis: 9181,
UpArrowDownArrow: 8645,
circlearrowright: 8635,
downharpoonright: 8642,
ntrianglerighteq: 8941,
rightharpoondown: 8641,
rightrightarrows: 8649,
twoheadleftarrow: 8606,
vartriangleright: 8883,
CloseCurlyQuote: 8217,
ContourIntegral: 8750,
DoubleDownArrow: 8659,
DoubleLeftArrow: 8656,
DownRightVector: 8641,
LeftRightVector: 10574,
LeftTriangleBar: 10703,
LeftUpTeeVector: 10592,
LeftUpVectorBar: 10584,
LowerRightArrow: 8600,
NotGreaterEqual: 8817,
NotGreaterTilde: 8821,
NotLeftTriangle: 8938,
OverParenthesis: 9180,
RightDownVector: 8642,
ShortRightArrow: 8594,
UpperRightArrow: 8599,
bigtriangledown: 9661,
circlearrowleft: 8634,
curvearrowright: 8631,
downharpoonleft: 8643,
leftharpoondown: 8637,
leftrightarrows: 8646,
nLeftrightarrow: 8654,
nleftrightarrow: 8622,
ntrianglelefteq: 8940,
rightleftarrows: 8644,
rightsquigarrow: 8605,
rightthreetimes: 8908,
straightepsilon: 1013,
trianglerighteq: 8885,
vartriangleleft: 8882,
DiacriticalDot: 729,
DoubleRightTee: 8872,
DownLeftVector: 8637,
GreaterGreater: 10914,
HorizontalLine: 9472,
InvisibleComma: 8291,
InvisibleTimes: 8290,
LeftDownVector: 8643,
LeftRightArrow: 8596,
Leftrightarrow: 8660,
LessSlantEqual: 10877,
LongRightArrow: 10230,
Longrightarrow: 10233,
LowerLeftArrow: 8601,
NestedLessLess: 8810,
NotGreaterLess: 8825,
NotLessGreater: 8824,
NotSubsetEqual: 8840,
NotVerticalBar: 8740,
OpenCurlyQuote: 8216,
ReverseElement: 8715,
RightTeeVector: 10587,
RightVectorBar: 10579,
ShortDownArrow: 8595,
ShortLeftArrow: 8592,
SquareSuperset: 8848,
TildeFullEqual: 8773,
UpperLeftArrow: 8598,
ZeroWidthSpace: 8203,
curvearrowleft: 8630,
doublebarwedge: 8966,
downdownarrows: 8650,
hookrightarrow: 8618,
leftleftarrows: 8647,
leftrightarrow: 8596,
leftthreetimes: 8907,
longrightarrow: 10230,
looparrowright: 8620,
nshortparallel: 8742,
ntriangleright: 8939,
rightarrowtail: 8611,
rightharpoonup: 8640,
trianglelefteq: 8884,
upharpoonright: 8638,
ApplyFunction: 8289,
DifferentialD: 8518,
DoubleLeftTee: 10980,
DoubleUpArrow: 8657,
LeftTeeVector: 10586,
LeftVectorBar: 10578,
LessFullEqual: 8806,
LongLeftArrow: 10229,
Longleftarrow: 10232,
NotTildeEqual: 8772,
NotTildeTilde: 8777,
Poincareplane: 8460,
PrecedesEqual: 10927,
PrecedesTilde: 8830,
RightArrowBar: 8677,
RightTeeArrow: 8614,
RightTriangle: 8883,
RightUpVector: 8638,
SucceedsEqual: 10928,
SucceedsTilde: 8831,
SupersetEqual: 8839,
UpEquilibrium: 10606,
VerticalTilde: 8768,
VeryThinSpace: 8202,
bigtriangleup: 9651,
blacktriangle: 9652,
divideontimes: 8903,
fallingdotseq: 8786,
hookleftarrow: 8617,
leftarrowtail: 8610,
leftharpoonup: 8636,
longleftarrow: 10229,
looparrowleft: 8619,
measuredangle: 8737,
ntriangleleft: 8938,
shortparallel: 8741,
smallsetminus: 8726,
triangleright: 9657,
upharpoonleft: 8639,
DownArrowBar: 10515,
DownTeeArrow: 8615,
ExponentialE: 8519,
GreaterEqual: 8805,
GreaterTilde: 8819,
HilbertSpace: 8459,
HumpDownHump: 8782,
Intersection: 8898,
LeftArrowBar: 8676,
LeftTeeArrow: 8612,
LeftTriangle: 8882,
LeftUpVector: 8639,
NotCongruent: 8802,
NotLessEqual: 8816,
NotLessTilde: 8820,
Proportional: 8733,
RightCeiling: 8969,
RoundImplies: 10608,
ShortUpArrow: 8593,
SquareSubset: 8847,
UnderBracket: 9141,
VerticalLine: 124,
blacklozenge: 10731,
exponentiale: 8519,
risingdotseq: 8787,
triangledown: 9663,
triangleleft: 9667,
CircleMinus: 8854,
CircleTimes: 8855,
Equilibrium: 8652,
GreaterLess: 8823,
LeftCeiling: 8968,
LessGreater: 8822,
MediumSpace: 8287,
NotPrecedes: 8832,
NotSucceeds: 8833,
OverBracket: 9140,
RightVector: 8640,
Rrightarrow: 8667,
RuleDelayed: 10740,
SmallCircle: 8728,
SquareUnion: 8852,
SubsetEqual: 8838,
UpDownArrow: 8597,
Updownarrow: 8661,
VerticalBar: 8739,
backepsilon: 1014,
blacksquare: 9642,
circledcirc: 8858,
circleddash: 8861,
curlyeqprec: 8926,
curlyeqsucc: 8927,
diamondsuit: 9830,
eqslantless: 10901,
expectation: 8496,
nRightarrow: 8655,
nrightarrow: 8603,
preccurlyeq: 8828,
precnapprox: 10937,
quaternions: 8461,
straightphi: 981,
succcurlyeq: 8829,
succnapprox: 10938,
thickapprox: 8776,
updownarrow: 8597,
Bernoullis: 8492,
CirclePlus: 8853,
EqualTilde: 8770,
Fouriertrf: 8497,
ImaginaryI: 8520,
Laplacetrf: 8466,
LeftVector: 8636,
Lleftarrow: 8666,
NotElement: 8713,
NotGreater: 8815,
Proportion: 8759,
RightArrow: 8594,
RightFloor: 8971,
Rightarrow: 8658,
TildeEqual: 8771,
TildeTilde: 8776,
UnderBrace: 9183,
UpArrowBar: 10514,
UpTeeArrow: 8613,
circledast: 8859,
complement: 8705,
curlywedge: 8911,
eqslantgtr: 10902,
gtreqqless: 10892,
lessapprox: 10885,
lesseqqgtr: 10891,
lmoustache: 9136,
longmapsto: 10236,
mapstodown: 8615,
mapstoleft: 8612,
nLeftarrow: 8653,
nleftarrow: 8602,
precapprox: 10935,
rightarrow: 8594,
rmoustache: 9137,
sqsubseteq: 8849,
sqsupseteq: 8850,
subsetneqq: 10955,
succapprox: 10936,
supsetneqq: 10956,
upuparrows: 8648,
varepsilon: 949,
varnothing: 8709,
Backslash: 8726,
CenterDot: 183,
CircleDot: 8857,
Congruent: 8801,
Coproduct: 8720,
DoubleDot: 168,
DownArrow: 8595,
DownBreve: 785,
Downarrow: 8659,
HumpEqual: 8783,
LeftArrow: 8592,
LeftFloor: 8970,
Leftarrow: 8656,
LessTilde: 8818,
Mellintrf: 8499,
MinusPlus: 8723,
NotCupCap: 8813,
NotExists: 8708,
OverBrace: 9182,
PlusMinus: 177,
Therefore: 8756,
ThinSpace: 8201,
TripleDot: 8411,
UnionPlus: 8846,
backprime: 8245,
backsimeq: 8909,
bigotimes: 10754,
centerdot: 183,
checkmark: 10003,
complexes: 8450,
dotsquare: 8865,
downarrow: 8595,
gtrapprox: 10886,
gtreqless: 8923,
heartsuit: 9829,
leftarrow: 8592,
lesseqgtr: 8922,
nparallel: 8742,
nshortmid: 8740,
nsubseteq: 8840,
nsupseteq: 8841,
pitchfork: 8916,
rationals: 8474,
spadesuit: 9824,
subseteqq: 10949,
subsetneq: 8842,
supseteqq: 10950,
supsetneq: 8843,
therefore: 8756,
triangleq: 8796,
varpropto: 8733,
DDotrahd: 10513,
DotEqual: 8784,
Integral: 8747,
LessLess: 10913,
NotEqual: 8800,
NotTilde: 8769,
PartialD: 8706,
Precedes: 8826,
RightTee: 8866,
Succeeds: 8827,
SuchThat: 8715,
Superset: 8835,
Uarrocir: 10569,
UnderBar: 818,
andslope: 10840,
angmsdaa: 10664,
angmsdab: 10665,
angmsdac: 10666,
angmsdad: 10667,
angmsdae: 10668,
angmsdaf: 10669,
angmsdag: 10670,
angmsdah: 10671,
angrtvbd: 10653,
approxeq: 8778,
awconint: 8755,
backcong: 8780,
barwedge: 8965,
bbrktbrk: 9142,
bigoplus: 10753,
bigsqcup: 10758,
biguplus: 10756,
bigwedge: 8896,
boxminus: 8863,
boxtimes: 8864,
capbrcup: 10825,
circledR: 174,
circledS: 9416,
cirfnint: 10768,
clubsuit: 9827,
cupbrcap: 10824,
curlyvee: 8910,
cwconint: 8754,
doteqdot: 8785,
dotminus: 8760,
drbkarow: 10512,
dzigrarr: 10239,
elinters: 9191,
emptyset: 8709,
eqvparsl: 10725,
fpartint: 10765,
geqslant: 10878,
gesdotol: 10884,
gnapprox: 10890,
hksearow: 10533,
hkswarow: 10534,
imagline: 8464,
imagpart: 8465,
infintie: 10717,
integers: 8484,
intercal: 8890,
intlarhk: 10775,
laemptyv: 10676,
ldrushar: 10571,
leqslant: 10877,
lesdotor: 10883,
llcorner: 8990,
lnapprox: 10889,
lrcorner: 8991,
lurdshar: 10570,
mapstoup: 8613,
multimap: 8888,
naturals: 8469,
otimesas: 10806,
parallel: 8741,
plusacir: 10787,
pointint: 10773,
precneqq: 10933,
precnsim: 8936,
profalar: 9006,
profline: 8978,
profsurf: 8979,
raemptyv: 10675,
realpart: 8476,
rppolint: 10770,
rtriltri: 10702,
scpolint: 10771,
setminus: 8726,
shortmid: 8739,
smeparsl: 10724,
sqsubset: 8847,
sqsupset: 8848,
subseteq: 8838,
succneqq: 10934,
succnsim: 8937,
supseteq: 8839,
thetasym: 977,
thicksim: 8764,
timesbar: 10801,
triangle: 9653,
triminus: 10810,
trpezium: 9186,
ulcorner: 8988,
urcorner: 8989,
varkappa: 1008,
varsigma: 962,
vartheta: 977,
Because: 8757,
Cayleys: 8493,
Cconint: 8752,
Cedilla: 184,
Diamond: 8900,
DownTee: 8868,
Element: 8712,
Epsilon: 917,
Implies: 8658,
LeftTee: 8867,
NewLine: 10,
NoBreak: 8288,
NotLess: 8814,
Omicron: 927,
OverBar: 175,
Product: 8719,
UpArrow: 8593,
Uparrow: 8657,
Upsilon: 933,
alefsym: 8501,
angrtvb: 8894,
angzarr: 9084,
asympeq: 8781,
backsim: 8765,
because: 8757,
bemptyv: 10672,
between: 8812,
bigcirc: 9711,
bigodot: 10752,
bigstar: 9733,
boxplus: 8862,
ccupssm: 10832,
cemptyv: 10674,
cirscir: 10690,
coloneq: 8788,
congdot: 10861,
cudarrl: 10552,
cudarrr: 10549,
cularrp: 10557,
curarrm: 10556,
dbkarow: 10511,
ddagger: 8225,
ddotseq: 10871,
demptyv: 10673,
diamond: 8900,
digamma: 989,
dotplus: 8724,
dwangle: 10662,
epsilon: 949,
eqcolon: 8789,
equivDD: 10872,
gesdoto: 10882,
gtquest: 10876,
gtrless: 8823,
harrcir: 10568,
intprod: 10812,
isindot: 8949,
larrbfs: 10527,
larrsim: 10611,
lbrksld: 10639,
lbrkslu: 10637,
ldrdhar: 10599,
lesdoto: 10881,
lessdot: 8918,
lessgtr: 8822,
lesssim: 8818,
lotimes: 10804,
lozenge: 9674,
ltquest: 10875,
luruhar: 10598,
maltese: 10016,
minusdu: 10794,
napprox: 8777,
natural: 9838,
nearrow: 8599,
nexists: 8708,
notinva: 8713,
notinvb: 8951,
notinvc: 8950,
notniva: 8716,
notnivb: 8958,
notnivc: 8957,
npolint: 10772,
nsqsube: 8930,
nsqsupe: 8931,
nvinfin: 10718,
nwarrow: 8598,
olcross: 10683,
omicron: 959,
orderof: 8500,
orslope: 10839,
pertenk: 8241,
planckh: 8462,
pluscir: 10786,
plussim: 10790,
plustwo: 10791,
precsim: 8830,
quatint: 10774,
questeq: 8799,
rarrbfs: 10528,
rarrsim: 10612,
rbrksld: 10638,
rbrkslu: 10640,
rdldhar: 10601,
realine: 8475,
rotimes: 10805,
ruluhar: 10600,
searrow: 8600,
simplus: 10788,
simrarr: 10610,
subedot: 10947,
submult: 10945,
subplus: 10943,
subrarr: 10617,
succsim: 8831,
supdsub: 10968,
supedot: 10948,
suphsub: 10967,
suplarr: 10619,
supmult: 10946,
supplus: 10944,
swarrow: 8601,
topfork: 10970,
triplus: 10809,
tritime: 10811,
uparrow: 8593,
upsilon: 965,
uwangle: 10663,
vzigzag: 10650,
zigrarr: 8669,
Aacute: 193,
Abreve: 258,
Agrave: 192,
Assign: 8788,
Atilde: 195,
Barwed: 8966,
Bumpeq: 8782,
Cacute: 262,
Ccaron: 268,
Ccedil: 199,
Colone: 10868,
Conint: 8751,
CupCap: 8781,
Dagger: 8225,
Dcaron: 270,
DotDot: 8412,
Dstrok: 272,
Eacute: 201,
Ecaron: 282,
Egrave: 200,
Exists: 8707,
ForAll: 8704,
Gammad: 988,
Gbreve: 286,
Gcedil: 290,
HARDcy: 1066,
Hstrok: 294,
Iacute: 205,
Igrave: 204,
Itilde: 296,
Jsercy: 1032,
Kcedil: 310,
Lacute: 313,
Lambda: 923,
Lcaron: 317,
Lcedil: 315,
Lmidot: 319,
Lstrok: 321,
Nacute: 323,
Ncaron: 327,
Ncedil: 325,
Ntilde: 209,
Oacute: 211,
Odblac: 336,
Ograve: 210,
Oslash: 216,
Otilde: 213,
Otimes: 10807,
Racute: 340,
Rarrtl: 10518,
Rcaron: 344,
Rcedil: 342,
SHCHcy: 1065,
SOFTcy: 1068,
Sacute: 346,
Scaron: 352,
Scedil: 350,
Square: 9633,
Subset: 8912,
Supset: 8913,
Tcaron: 356,
Tcedil: 354,
Tstrok: 358,
Uacute: 218,
Ubreve: 364,
Udblac: 368,
Ugrave: 217,
Utilde: 360,
Vdashl: 10982,
Verbar: 8214,
Vvdash: 8874,
Yacute: 221,
Zacute: 377,
Zcaron: 381,
aacute: 225,
abreve: 259,
agrave: 224,
andand: 10837,
angmsd: 8737,
angsph: 8738,
apacir: 10863,
approx: 8776,
atilde: 227,
barvee: 8893,
barwed: 8965,
becaus: 8757,
bernou: 8492,
bigcap: 8898,
bigcup: 8899,
bigvee: 8897,
bkarow: 10509,
bottom: 8869,
bowtie: 8904,
boxbox: 10697,
bprime: 8245,
brvbar: 166,
bullet: 8226,
bumpeq: 8783,
cacute: 263,
capand: 10820,
capcap: 10827,
capcup: 10823,
capdot: 10816,
ccaron: 269,
ccedil: 231,
circeq: 8791,
cirmid: 10991,
colone: 8788,
commat: 64,
compfn: 8728,
conint: 8750,
coprod: 8720,
copysr: 8471,
cularr: 8630,
cupcap: 10822,
cupcup: 10826,
cupdot: 8845,
curarr: 8631,
curren: 164,
cylcty: 9005,
dagger: 8224,
daleth: 8504,
dcaron: 271,
dfisht: 10623,
divide: 247,
divonx: 8903,
dlcorn: 8990,
dlcrop: 8973,
dollar: 36,
drcorn: 8991,
drcrop: 8972,
dstrok: 273,
eacute: 233,
easter: 10862,
ecaron: 283,
ecolon: 8789,
egrave: 232,
egsdot: 10904,
elsdot: 10903,
emptyv: 8709,
emsp13: 8196,
emsp14: 8197,
eparsl: 10723,
eqcirc: 8790,
equals: 61,
equest: 8799,
female: 9792,
ffilig: 64259,
ffllig: 64260,
forall: 8704,
frac12: 189,
frac13: 8531,
frac14: 188,
frac15: 8533,
frac16: 8537,
frac18: 8539,
frac23: 8532,
frac25: 8534,
frac34: 190,
frac35: 8535,
frac38: 8540,
frac45: 8536,
frac56: 8538,
frac58: 8541,
frac78: 8542,
gacute: 501,
gammad: 989,
gbreve: 287,
gesdot: 10880,
gesles: 10900,
gtlPar: 10645,
gtrarr: 10616,
gtrdot: 8919,
gtrsim: 8819,
hairsp: 8202,
hamilt: 8459,
hardcy: 1098,
hearts: 9829,
hellip: 8230,
hercon: 8889,
homtht: 8763,
horbar: 8213,
hslash: 8463,
hstrok: 295,
hybull: 8259,
hyphen: 8208,
iacute: 237,
igrave: 236,
iiiint: 10764,
iinfin: 10716,
incare: 8453,
inodot: 305,
intcal: 8890,
iquest: 191,
isinsv: 8947,
itilde: 297,
jsercy: 1112,
kappav: 1008,
kcedil: 311,
kgreen: 312,
lAtail: 10523,
lacute: 314,
lagran: 8466,
lambda: 955,
langle: 10216,
larrfs: 10525,
larrhk: 8617,
larrlp: 8619,
larrpl: 10553,
larrtl: 8610,
latail: 10521,
lbrace: 123,
lbrack: 91,
lcaron: 318,
lcedil: 316,
ldquor: 8222,
lesdot: 10879,
lesges: 10899,
lfisht: 10620,
lfloor: 8970,
lharul: 10602,
llhard: 10603,
lmidot: 320,
lmoust: 9136,
loplus: 10797,
lowast: 8727,
lowbar: 95,
lparlt: 10643,
lrhard: 10605,
lsaquo: 8249,
lsquor: 8218,
lstrok: 322,
lthree: 8907,
ltimes: 8905,
ltlarr: 10614,
ltrPar: 10646,
mapsto: 8614,
marker: 9646,
mcomma: 10793,
midast: 42,
midcir: 10992,
middot: 183,
minusb: 8863,
minusd: 8760,
mnplus: 8723,
models: 8871,
mstpos: 8766,
nVDash: 8879,
nVdash: 8878,
nacute: 324,
ncaron: 328,
ncedil: 326,
nearhk: 10532,
nequiv: 8802,
nesear: 10536,
nexist: 8708,
nltrie: 8940,
nprcue: 8928,
nrtrie: 8941,
nsccue: 8929,
nsimeq: 8772,
ntilde: 241,
numero: 8470,
nvDash: 8877,
nvHarr: 10500,
nvdash: 8876,
nvlArr: 10498,
nvrArr: 10499,
nwarhk: 10531,
nwnear: 10535,
oacute: 243,
odblac: 337,
odsold: 10684,
ograve: 242,
ominus: 8854,
origof: 8886,
oslash: 248,
otilde: 245,
otimes: 8855,
parsim: 10995,
percnt: 37,
period: 46,
permil: 8240,
phmmat: 8499,
planck: 8463,
plankv: 8463,
plusdo: 8724,
plusdu: 10789,
plusmn: 177,
preceq: 10927,
primes: 8473,
prnsim: 8936,
propto: 8733,
prurel: 8880,
puncsp: 8200,
qprime: 8279,
rAtail: 10524,
racute: 341,
rangle: 10217,
rarrap: 10613,
rarrfs: 10526,
rarrhk: 8618,
rarrlp: 8620,
rarrpl: 10565,
rarrtl: 8611,
ratail: 10522,
rbrace: 125,
rbrack: 93,
rcaron: 345,
rcedil: 343,
rdquor: 8221,
rfisht: 10621,
rfloor: 8971,
rharul: 10604,
rmoust: 9137,
roplus: 10798,
rpargt: 10644,
rsaquo: 8250,
rsquor: 8217,
rthree: 8908,
rtimes: 8906,
sacute: 347,
scaron: 353,
scedil: 351,
scnsim: 8937,
searhk: 10533,
seswar: 10537,
sfrown: 8994,
shchcy: 1097,
sigmaf: 962,
sigmav: 962,
simdot: 10858,
smashp: 10803,
softcy: 1100,
solbar: 9023,
spades: 9824,
sqsube: 8849,
sqsupe: 8850,
square: 9633,
squarf: 9642,
ssetmn: 8726,
ssmile: 8995,
sstarf: 8902,
subdot: 10941,
subset: 8834,
subsim: 10951,
subsub: 10965,
subsup: 10963,
succeq: 10928,
supdot: 10942,
supset: 8835,
supsim: 10952,
supsub: 10964,
supsup: 10966,
swarhk: 10534,
swnwar: 10538,
target: 8982,
tcaron: 357,
tcedil: 355,
telrec: 8981,
there4: 8756,
thetav: 977,
thinsp: 8201,
thksim: 8764,
timesb: 8864,
timesd: 10800,
topbot: 9014,
topcir: 10993,
tprime: 8244,
tridot: 9708,
tstrok: 359,
uacute: 250,
ubreve: 365,
udblac: 369,
ufisht: 10622,
ugrave: 249,
ulcorn: 8988,
ulcrop: 8975,
urcorn: 8989,
urcrop: 8974,
utilde: 361,
vangrt: 10652,
varphi: 966,
varrho: 1009,
veebar: 8891,
vellip: 8942,
verbar: 124,
wedbar: 10847,
wedgeq: 8793,
weierp: 8472,
wreath: 8768,
xoplus: 10753,
xotime: 10754,
xsqcup: 10758,
xuplus: 10756,
xwedge: 8896,
yacute: 253,
zacute: 378,
zcaron: 382,
zeetrf: 8488,
AElig: 198,
Acirc: 194,
Alpha: 913,
Amacr: 256,
Aogon: 260,
Aring: 197,
Breve: 728,
Ccirc: 264,
Colon: 8759,
Cross: 10799,
Dashv: 10980,
Delta: 916,
Ecirc: 202,
Emacr: 274,
Eogon: 280,
Equal: 10869,
Gamma: 915,
Gcirc: 284,
Hacek: 711,
Hcirc: 292,
IJlig: 306,
Icirc: 206,
Imacr: 298,
Iogon: 302,
Iukcy: 1030,
Jcirc: 308,
Jukcy: 1028,
Kappa: 922,
OElig: 338,
Ocirc: 212,
Omacr: 332,
Omega: 937,
Prime: 8243,
RBarr: 10512,
Scirc: 348,
Sigma: 931,
THORN: 222,
TRADE: 8482,
TSHcy: 1035,
Theta: 920,
Tilde: 8764,
Ubrcy: 1038,
Ucirc: 219,
Umacr: 362,
Union: 8899,
Uogon: 370,
UpTee: 8869,
Uring: 366,
VDash: 8875,
Vdash: 8873,
Wcirc: 372,
Wedge: 8896,
Ycirc: 374,
acirc: 226,
acute: 180,
aelig: 230,
aleph: 8501,
alpha: 945,
amacr: 257,
amalg: 10815,
angle: 8736,
angrt: 8735,
angst: 8491,
aogon: 261,
aring: 229,
asymp: 8776,
awint: 10769,
bcong: 8780,
bdquo: 8222,
bepsi: 1014,
blank: 9251,
blk12: 9618,
blk14: 9617,
blk34: 9619,
block: 9608,
boxDL: 9559,
boxDR: 9556,
boxDl: 9558,
boxDr: 9555,
boxHD: 9574,
boxHU: 9577,
boxHd: 9572,
boxHu: 9575,
boxUL: 9565,
boxUR: 9562,
boxUl: 9564,
boxUr: 9561,
boxVH: 9580,
boxVL: 9571,
boxVR: 9568,
boxVh: 9579,
boxVl: 9570,
boxVr: 9567,
boxdL: 9557,
boxdR: 9554,
boxdl: 9488,
boxdr: 9484,
boxhD: 9573,
boxhU: 9576,
boxhd: 9516,
boxhu: 9524,
boxuL: 9563,
boxuR: 9560,
boxul: 9496,
boxur: 9492,
boxvH: 9578,
boxvL: 9569,
boxvR: 9566,
boxvh: 9532,
boxvl: 9508,
boxvr: 9500,
breve: 728,
bsemi: 8271,
bsime: 8909,
bsolb: 10693,
bumpE: 10926,
bumpe: 8783,
caret: 8257,
caron: 711,
ccaps: 10829,
ccirc: 265,
ccups: 10828,
cedil: 184,
check: 10003,
clubs: 9827,
colon: 58,
comma: 44,
crarr: 8629,
cross: 10007,
csube: 10961,
csupe: 10962,
ctdot: 8943,
cuepr: 8926,
cuesc: 8927,
cupor: 10821,
cuvee: 8910,
cuwed: 8911,
cwint: 8753,
dashv: 8867,
dblac: 733,
ddarr: 8650,
delta: 948,
dharl: 8643,
dharr: 8642,
diams: 9830,
disin: 8946,
doteq: 8784,
dtdot: 8945,
dtrif: 9662,
duarr: 8693,
duhar: 10607,
eDDot: 10871,
ecirc: 234,
efDot: 8786,
emacr: 275,
empty: 8709,
eogon: 281,
eplus: 10865,
epsiv: 949,
eqsim: 8770,
equiv: 8801,
erDot: 8787,
erarr: 10609,
esdot: 8784,
exist: 8707,
fflig: 64256,
filig: 64257,
fllig: 64258,
fltns: 9649,
forkv: 10969,
frasl: 8260,
frown: 8994,
gamma: 947,
gcirc: 285,
gescc: 10921,
gimel: 8503,
gneqq: 8809,
gnsim: 8935,
grave: 96,
gsime: 10894,
gsiml: 10896,
gtcir: 10874,
gtdot: 8919,
harrw: 8621,
hcirc: 293,
hoarr: 8703,
icirc: 238,
iexcl: 161,
iiint: 8749,
iiota: 8489,
ijlig: 307,
imacr: 299,
image: 8465,
imath: 305,
imped: 437,
infin: 8734,
iogon: 303,
iprod: 10812,
isinE: 8953,
isins: 8948,
isinv: 8712,
iukcy: 1110,
jcirc: 309,
jmath: 567,
jukcy: 1108,
kappa: 954,
lAarr: 8666,
lBarr: 10510,
langd: 10641,
laquo: 171,
larrb: 8676,
lbarr: 10508,
lbbrk: 10098,
lbrke: 10635,
lceil: 8968,
ldquo: 8220,
lescc: 10920,
lhard: 8637,
lharu: 8636,
lhblk: 9604,
llarr: 8647,
lltri: 9722,
lneqq: 8808,
lnsim: 8934,
loang: 10220,
loarr: 8701,
lobrk: 10214,
lopar: 10629,
lrarr: 8646,
lrhar: 8651,
lrtri: 8895,
lsime: 10893,
lsimg: 10895,
lsquo: 8216,
ltcir: 10873,
ltdot: 8918,
ltrie: 8884,
ltrif: 9666,
mDDot: 8762,
mdash: 8212,
micro: 181,
minus: 8722,
mumap: 8888,
nabla: 8711,
napos: 329,
natur: 9838,
ncong: 8775,
ndash: 8211,
neArr: 8663,
nearr: 8599,
ngsim: 8821,
nhArr: 8654,
nharr: 8622,
nhpar: 10994,
nlArr: 8653,
nlarr: 8602,
nless: 8814,
nlsim: 8820,
nltri: 8938,
notin: 8713,
notni: 8716,
nprec: 8832,
nrArr: 8655,
nrarr: 8603,
nrtri: 8939,
nsime: 8772,
nsmid: 8740,
nspar: 8742,
nsube: 8840,
nsucc: 8833,
nsupe: 8841,
numsp: 8199,
nwArr: 8662,
nwarr: 8598,
ocirc: 244,
odash: 8861,
oelig: 339,
ofcir: 10687,
ohbar: 10677,
olarr: 8634,
olcir: 10686,
oline: 8254,
omacr: 333,
omega: 969,
operp: 10681,
oplus: 8853,
orarr: 8635,
order: 8500,
ovbar: 9021,
parsl: 11005,
phone: 9742,
plusb: 8862,
pluse: 10866,
pound: 163,
prcue: 8828,
prime: 8242,
prnap: 10937,
prsim: 8830,
quest: 63,
rAarr: 8667,
rBarr: 10511,
radic: 8730,
rangd: 10642,
range: 10661,
raquo: 187,
rarrb: 8677,
rarrc: 10547,
rarrw: 8605,
ratio: 8758,
rbarr: 10509,
rbbrk: 10099,
rbrke: 10636,
rceil: 8969,
rdquo: 8221,
reals: 8477,
rhard: 8641,
rharu: 8640,
rlarr: 8644,
rlhar: 8652,
rnmid: 10990,
roang: 10221,
roarr: 8702,
robrk: 10215,
ropar: 10630,
rrarr: 8649,
rsquo: 8217,
rtrie: 8885,
rtrif: 9656,
sbquo: 8218,
sccue: 8829,
scirc: 349,
scnap: 10938,
scsim: 8831,
sdotb: 8865,
sdote: 10854,
seArr: 8664,
searr: 8600,
setmn: 8726,
sharp: 9839,
sigma: 963,
simeq: 8771,
simgE: 10912,
simlE: 10911,
simne: 8774,
slarr: 8592,
smile: 8995,
sqcap: 8851,
sqcup: 8852,
sqsub: 8847,
sqsup: 8848,
srarr: 8594,
starf: 9733,
strns: 175,
subnE: 10955,
subne: 8842,
supnE: 10956,
supne: 8843,
swArr: 8665,
swarr: 8601,
szlig: 223,
theta: 952,
thkap: 8776,
thorn: 254,
tilde: 732,
times: 215,
trade: 8482,
trisb: 10701,
tshcy: 1115,
twixt: 8812,
ubrcy: 1118,
ucirc: 251,
udarr: 8645,
udhar: 10606,
uharl: 8639,
uharr: 8638,
uhblk: 9600,
ultri: 9720,
umacr: 363,
uogon: 371,
uplus: 8846,
upsih: 978,
uring: 367,
urtri: 9721,
utdot: 8944,
utrif: 9652,
uuarr: 8648,
vBarv: 10985,
vDash: 8872,
varpi: 982,
vdash: 8866,
veeeq: 8794,
vltri: 8882,
vprop: 8733,
vrtri: 8883,
wcirc: 373,
wedge: 8743,
xcirc: 9711,
xdtri: 9661,
xhArr: 10234,
xharr: 10231,
xlArr: 10232,
xlarr: 10229,
xodot: 10752,
xrArr: 10233,
xrarr: 10230,
xutri: 9651,
ycirc: 375,
Aopf: 120120,
Ascr: 119964,
Auml: 196,
Barv: 10983,
Beta: 914,
Bopf: 120121,
Bscr: 8492,
CHcy: 1063,
COPY: 169,
Cdot: 266,
Copf: 8450,
Cscr: 119966,
DJcy: 1026,
DScy: 1029,
DZcy: 1039,
Darr: 8609,
Dopf: 120123,
Dscr: 119967,
Edot: 278,
Eopf: 120124,
Escr: 8496,
Esim: 10867,
Euml: 203,
Fopf: 120125,
Fscr: 8497,
GJcy: 1027,
Gdot: 288,
Gopf: 120126,
Gscr: 119970,
Hopf: 8461,
Hscr: 8459,
IEcy: 1045,
IOcy: 1025,
Idot: 304,
Iopf: 120128,
Iota: 921,
Iscr: 8464,
Iuml: 207,
Jopf: 120129,
Jscr: 119973,
KHcy: 1061,
KJcy: 1036,
Kopf: 120130,
Kscr: 119974,
LJcy: 1033,
Lang: 10218,
Larr: 8606,
Lopf: 120131,
Lscr: 8466,
Mopf: 120132,
Mscr: 8499,
NJcy: 1034,
Nopf: 8469,
Nscr: 119977,
Oopf: 120134,
Oscr: 119978,
Ouml: 214,
Popf: 8473,
Pscr: 119979,
QUOT: 34,
Qopf: 8474,
Qscr: 119980,
Rang: 10219,
Rarr: 8608,
Ropf: 8477,
Rscr: 8475,
SHcy: 1064,
Sopf: 120138,
Sqrt: 8730,
Sscr: 119982,
Star: 8902,
TScy: 1062,
Topf: 120139,
Tscr: 119983,
Uarr: 8607,
Uopf: 120140,
Upsi: 978,
Uscr: 119984,
Uuml: 220,
Vbar: 10987,
Vert: 8214,
Vopf: 120141,
Vscr: 119985,
Wopf: 120142,
Wscr: 119986,
Xopf: 120143,
Xscr: 119987,
YAcy: 1071,
YIcy: 1031,
YUcy: 1070,
Yopf: 120144,
Yscr: 119988,
Yuml: 376,
ZHcy: 1046,
Zdot: 379,
Zeta: 918,
Zopf: 8484,
Zscr: 119989,
andd: 10844,
andv: 10842,
ange: 10660,
aopf: 120146,
apid: 8779,
apos: 39,
ascr: 119990,
auml: 228,
bNot: 10989,
bbrk: 9141,
beta: 946,
beth: 8502,
bnot: 8976,
bopf: 120147,
boxH: 9552,
boxV: 9553,
boxh: 9472,
boxv: 9474,
bscr: 119991,
bsim: 8765,
bsol: 92,
bull: 8226,
bump: 8782,
cdot: 267,
cent: 162,
chcy: 1095,
cirE: 10691,
circ: 710,
cire: 8791,
comp: 8705,
cong: 8773,
copf: 120148,
copy: 169,
cscr: 119992,
csub: 10959,
csup: 10960,
dArr: 8659,
dHar: 10597,
darr: 8595,
dash: 8208,
diam: 8900,
djcy: 1106,
dopf: 120149,
dscr: 119993,
dscy: 1109,
dsol: 10742,
dtri: 9663,
dzcy: 1119,
eDot: 8785,
ecir: 8790,
edot: 279,
emsp: 8195,
ensp: 8194,
eopf: 120150,
epar: 8917,
epsi: 1013,
escr: 8495,
esim: 8770,
euml: 235,
euro: 8364,
excl: 33,
flat: 9837,
fnof: 402,
fopf: 120151,
fork: 8916,
fscr: 119995,
gdot: 289,
geqq: 8807,
gjcy: 1107,
gnap: 10890,
gneq: 10888,
gopf: 120152,
gscr: 8458,
gsim: 8819,
gtcc: 10919,
hArr: 8660,
half: 189,
harr: 8596,
hbar: 8463,
hopf: 120153,
hscr: 119997,
iecy: 1077,
imof: 8887,
iocy: 1105,
iopf: 120154,
iota: 953,
iscr: 119998,
isin: 8712,
iuml: 239,
jopf: 120155,
jscr: 119999,
khcy: 1093,
kjcy: 1116,
kopf: 120156,
kscr: 120000,
lArr: 8656,
lHar: 10594,
lang: 10216,
larr: 8592,
late: 10925,
lcub: 123,
ldca: 10550,
ldsh: 8626,
leqq: 8806,
ljcy: 1113,
lnap: 10889,
lneq: 10887,
lopf: 120157,
lozf: 10731,
lpar: 40,
lscr: 120001,
lsim: 8818,
lsqb: 91,
ltcc: 10918,
ltri: 9667,
macr: 175,
male: 9794,
malt: 10016,
mlcp: 10971,
mldr: 8230,
mopf: 120158,
mscr: 120002,
nbsp: 160,
ncap: 10819,
ncup: 10818,
ngeq: 8817,
ngtr: 8815,
nisd: 8954,
njcy: 1114,
nldr: 8229,
nleq: 8816,
nmid: 8740,
nopf: 120159,
npar: 8742,
nscr: 120003,
nsim: 8769,
nsub: 8836,
nsup: 8837,
ntgl: 8825,
ntlg: 8824,
oast: 8859,
ocir: 8858,
odiv: 10808,
odot: 8857,
ogon: 731,
oint: 8750,
omid: 10678,
oopf: 120160,
opar: 10679,
ordf: 170,
ordm: 186,
oror: 10838,
oscr: 8500,
osol: 8856,
ouml: 246,
para: 182,
part: 8706,
perp: 8869,
phiv: 966,
plus: 43,
popf: 120161,
prap: 10935,
prec: 8826,
prnE: 10933,
prod: 8719,
prop: 8733,
pscr: 120005,
qint: 10764,
qopf: 120162,
qscr: 120006,
quot: 34,
rArr: 8658,
rHar: 10596,
race: 10714,
rang: 10217,
rarr: 8594,
rcub: 125,
rdca: 10551,
rdsh: 8627,
real: 8476,
rect: 9645,
rhov: 1009,
ring: 730,
ropf: 120163,
rpar: 41,
rscr: 120007,
rsqb: 93,
rtri: 9657,
scap: 10936,
scnE: 10934,
sdot: 8901,
sect: 167,
semi: 59,
sext: 10038,
shcy: 1096,
sime: 8771,
simg: 10910,
siml: 10909,
smid: 8739,
smte: 10924,
solb: 10692,
sopf: 120164,
spar: 8741,
squf: 9642,
sscr: 120008,
star: 9734,
subE: 10949,
sube: 8838,
succ: 8827,
sung: 9834,
sup1: 185,
sup2: 178,
sup3: 179,
supE: 10950,
supe: 8839,
tbrk: 9140,
tdot: 8411,
tint: 8749,
toea: 10536,
topf: 120165,
tosa: 10537,
trie: 8796,
tscr: 120009,
tscy: 1094,
uArr: 8657,
uHar: 10595,
uarr: 8593,
uopf: 120166,
upsi: 965,
uscr: 120010,
utri: 9653,
uuml: 252,
vArr: 8661,
vBar: 10984,
varr: 8597,
vert: 124,
vopf: 120167,
vscr: 120011,
wopf: 120168,
wscr: 120012,
xcap: 8898,
xcup: 8899,
xmap: 10236,
xnis: 8955,
xopf: 120169,
xscr: 120013,
xvee: 8897,
yacy: 1103,
yicy: 1111,
yopf: 120170,
yscr: 120014,
yucy: 1102,
yuml: 255,
zdot: 380,
zeta: 950,
zhcy: 1078,
zopf: 120171,
zscr: 120015,
zwnj: 8204,
AMP: 38,
Acy: 1040,
Afr: 120068,
And: 10835,
Bcy: 1041,
Bfr: 120069,
Cap: 8914,
Cfr: 8493,
Chi: 935,
Cup: 8915,
Dcy: 1044,
Del: 8711,
Dfr: 120071,
Dot: 168,
ENG: 330,
ETH: 208,
Ecy: 1069,
Efr: 120072,
Eta: 919,
Fcy: 1060,
Ffr: 120073,
Gcy: 1043,
Gfr: 120074,
Hat: 94,
Hfr: 8460,
Icy: 1048,
Ifr: 8465,
Int: 8748,
Jcy: 1049,
Jfr: 120077,
Kcy: 1050,
Kfr: 120078,
Lcy: 1051,
Lfr: 120079,
Lsh: 8624,
Map: 10501,
Mcy: 1052,
Mfr: 120080,
Ncy: 1053,
Nfr: 120081,
Not: 10988,
Ocy: 1054,
Ofr: 120082,
Pcy: 1055,
Pfr: 120083,
Phi: 934,
Psi: 936,
Qfr: 120084,
REG: 174,
Rcy: 1056,
Rfr: 8476,
Rho: 929,
Rsh: 8625,
Scy: 1057,
Sfr: 120086,
Sub: 8912,
Sum: 8721,
Sup: 8913,
Tab: 9,
Tau: 932,
Tcy: 1058,
Tfr: 120087,
Ucy: 1059,
Ufr: 120088,
Vcy: 1042,
Vee: 8897,
Vfr: 120089,
Wfr: 120090,
Xfr: 120091,
Ycy: 1067,
Yfr: 120092,
Zcy: 1047,
Zfr: 8488,
acd: 8767,
acy: 1072,
afr: 120094,
amp: 38,
and: 8743,
ang: 8736,
apE: 10864,
ape: 8778,
ast: 42,
bcy: 1073,
bfr: 120095,
bot: 8869,
cap: 8745,
cfr: 120096,
chi: 967,
cir: 9675,
cup: 8746,
dcy: 1076,
deg: 176,
dfr: 120097,
die: 168,
div: 247,
dot: 729,
ecy: 1101,
efr: 120098,
egs: 10902,
ell: 8467,
els: 10901,
eng: 331,
eta: 951,
eth: 240,
fcy: 1092,
ffr: 120099,
gEl: 10892,
gap: 10886,
gcy: 1075,
gel: 8923,
geq: 8805,
ges: 10878,
gfr: 120100,
ggg: 8921,
glE: 10898,
gla: 10917,
glj: 10916,
gnE: 8809,
gne: 10888,
hfr: 120101,
icy: 1080,
iff: 8660,
ifr: 120102,
int: 8747,
jcy: 1081,
jfr: 120103,
kcy: 1082,
kfr: 120104,
lEg: 10891,
lap: 10885,
lat: 10923,
lcy: 1083,
leg: 8922,
leq: 8804,
les: 10877,
lfr: 120105,
lgE: 10897,
lnE: 8808,
lne: 10887,
loz: 9674,
lrm: 8206,
lsh: 8624,
map: 8614,
mcy: 1084,
mfr: 120106,
mho: 8487,
mid: 8739,
nap: 8777,
ncy: 1085,
nfr: 120107,
nge: 8817,
ngt: 8815,
nis: 8956,
niv: 8715,
nle: 8816,
nlt: 8814,
not: 172,
npr: 8832,
nsc: 8833,
num: 35,
ocy: 1086,
ofr: 120108,
ogt: 10689,
ohm: 8486,
olt: 10688,
ord: 10845,
orv: 10843,
par: 8741,
pcy: 1087,
pfr: 120109,
phi: 966,
piv: 982,
prE: 10931,
pre: 10927,
psi: 968,
qfr: 120110,
rcy: 1088,
reg: 174,
rfr: 120111,
rho: 961,
rlm: 8207,
rsh: 8625,
scE: 10932,
sce: 10928,
scy: 1089,
sfr: 120112,
shy: 173,
sim: 8764,
smt: 10922,
sol: 47,
squ: 9633,
sub: 8834,
sum: 8721,
sup: 8835,
tau: 964,
tcy: 1090,
tfr: 120113,
top: 8868,
ucy: 1091,
ufr: 120114,
uml: 168,
vcy: 1074,
vee: 8744,
vfr: 120115,
wfr: 120116,
xfr: 120117,
ycy: 1099,
yen: 165,
yfr: 120118,
zcy: 1079,
zfr: 120119,
zwj: 8205,
DD: 8517,
GT: 62,
Gg: 8921,
Gt: 8811,
Im: 8465,
LT: 60,
Ll: 8920,
Lt: 8810,
Mu: 924,
Nu: 925,
Or: 10836,
Pi: 928,
Pr: 10939,
Re: 8476,
Sc: 10940,
Xi: 926,
ac: 8766,
af: 8289,
ap: 8776,
dd: 8518,
ee: 8519,
eg: 10906,
el: 10905,
gE: 8807,
ge: 8805,
gg: 8811,
gl: 8823,
gt: 62,
ic: 8291,
ii: 8520,
in: 8712,
it: 8290,
lE: 8806,
le: 8804,
lg: 8822,
ll: 8810,
lt: 60,
mp: 8723,
mu: 956,
ne: 8800,
ni: 8715,
nu: 957,
oS: 9416,
or: 8744,
pi: 960,
pm: 177,
pr: 8826,
rx: 8478,
sc: 8827,
wp: 8472,
wr: 8768,
xi: 958,
};
const windows_1252 = [
8364,
129,
8218,
402,
8222,
8230,
8224,
8225,
710,
8240,
352,
8249,
338,
141,
381,
143,
144,
8216,
8217,
8220,
8221,
8226,
8211,
8212,
732,
8482,
353,
8250,
339,
157,
382,
376,
];
const entity_pattern = new RegExp(`&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(entities).join('|')}))(?:;|\\b)`, 'g');
function decode_character_references(html) {
return html.replace(entity_pattern, (match, entity) => {
let code;
// Handle named entities
if (entity[0] !== '#') {
code = entities[entity];
}
else if (entity[1] === 'x') {
code = parseInt(entity.substring(2), 16);
}
else {
code = parseInt(entity.substring(1), 10);
}
if (!code) {
return match;
}
return String.fromCodePoint(validate_code(code));
});
}
const NUL = 0;
// some code points are verboten. If we were inserting HTML, the browser would replace the illegal
// code points with alternatives in some cases - since we're bypassing that mechanism, we need
// to replace them ourselves
//
// Source: http://en.wikipedia.org/wiki/Character_encodings_in_HTML#Illegal_characters
function validate_code(code) {
// line feed becomes generic whitespace
if (code === 10) {
return 32;
}
// ASCII range. (Why someone would use HTML entities for ASCII characters I don't know, but...)
if (code < 128) {
return code;
}
// code points 128-159 are dealt with leniently by browsers, but they're incorrect. We need
// to correct the mistake or we'll end up with missing € signs and so on
if (code <= 159) {
return windows_1252[code - 128];
}
// basic multilingual plane
if (code < 55296) {
return code;
}
// UTF-16 surrogate halves
if (code <= 57343) {
return NUL;
}
// rest of the basic multilingual plane
if (code <= 65535) {
return code;
}
// supplementary multilingual plane 0x10000 - 0x1ffff
if (code >= 65536 && code <= 131071) {
return code;
}
// supplementary ideographic plane 0x20000 - 0x2ffff
if (code >= 131072 && code <= 196607) {
return code;
}
return NUL;
}
// based on http://developers.whatwg.org/syntax.html#syntax-tag-omission
const disallowed_contents = new Map([
['li', new Set(['li'])],
['dt', new Set(['dt', 'dd'])],
['dd', new Set(['dt', 'dd'])],
[
'p',
new Set('address article aside blockquote div dl fieldset footer form h1 h2 h3 h4 h5 h6 header hgroup hr main menu nav ol p pre section table ul'.split(' ')),
],
['rt', new Set(['rt', 'rp'])],
['rp', new Set(['rt', 'rp'])],
['optgroup', new Set(['optgroup'])],
['option', new Set(['option', 'optgroup'])],
['thead', new Set(['tbody', 'tfoot'])],
['tbody', new Set(['tbody', 'tfoot'])],
['tfoot', new Set(['tbody'])],
['tr', new Set(['tr', 'tbody'])],
['td', new Set(['td', 'th', 'tr'])],
['th', new Set(['td', 'th', 'tr'])],
]);
// can this be a child of the parent element, or does it implicitly
// close it, like `<li>one<li>two`?
function closing_tag_omitted(current, next) {
if (disallowed_contents.has(current)) {
if (!next || disallowed_contents.get(current).has(next)) {
return true;
}
}
return false;
}
// Adapted from https://github.com/acornjs/acorn/blob/6584815dca7440e00de841d1dad152302fdd7ca5/src/tokenize.js
// Reproduced under MIT License https://github.com/acornjs/acorn/blob/master/LICENSE
function full_char_code_at(str, i) {
const code = str.charCodeAt(i);
if (code <= 0xd7ff || code >= 0xe000)
return code;
const next = str.charCodeAt(i + 1);
return (code << 10) + next - 0x35fdc00;
}
const globals = new Set([
'alert',
'Array',
'Boolean',
'clearInterval',
'clearTimeout',
'confirm',
'console',
'Date',
'decodeURI',
'decodeURIComponent',
'document',
'encodeURI',
'encodeURIComponent',
'Error',
'EvalError',
'Event',
'fetch',
'global',
'globalThis',
'history',
'Infinity',
'InternalError',
'Intl',
'isFinite',
'isNaN',
'JSON',
'localStorage',
'location',
'Map',
'Math',
'NaN',
'navigator',
'Number',
'Object',
'parseFloat',
'parseInt',
'process',
'Promise',
'prompt',
'RangeError',
'ReferenceError',
'RegExp',
'sessionStorage',
'Set',
'setInterval',
'setTimeout',
'String',
'SyntaxError',
'TypeError',
'undefined',
'URIError',
'URL',
'window'
]);
const reserved = new Set([
'arguments',
'await',
'break',
'case',
'catch',
'class',
'const',
'continue',
'debugger',
'default',
'delete',
'do',
'else',
'enum',
'eval',
'export',
'extends',
'false',
'finally',
'for',
'function',
'if',
'implements',
'import',
'in',
'instanceof',
'interface',
'let',
'new',
'null',
'package',
'private',
'protected',
'public',
'return',
'static',
'super',
'switch',
'this',
'throw',
'true',
'try',
'typeof',
'var',
'void',
'while',
'with',
'yield',
]);
const void_element_names = /^(?:area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/;
function is_void(name) {
return void_element_names.test(name) || name.toLowerCase() === '!doctype';
}
function is_valid(str) {
let i = 0;
while (i < str.length) {
const code = full_char_code_at(str, i);
if (!(i === 0 ? isIdentifierStart : isIdentifierChar)(code, true))
return false;
i += code <= 0xffff ? 1 : 2;
}
return true;
}
function sanitize(name) {
return name
.replace(/[^a-zA-Z0-9_]+/g, '_')
.replace(/^_/, '')
.replace(/_$/, '')
.replace(/^[0-9]/, '_$&');
}
function fuzzymatch(name, names) {
const set = new FuzzySet(names);
const matches = set.get(name);
return matches && matches[0] && matches[0][0] > 0.7 ? matches[0][1] : null;
}
// adapted from https://github.com/Glench/fuzzyset.js/blob/master/lib/fuzzyset.js
// BSD Licensed
const GRAM_SIZE_LOWER = 2;
const GRAM_SIZE_UPPER = 3;
// return an edit distance from 0 to 1
function _distance(str1, str2) {
if (str1 === null && str2 === null)
throw 'Trying to compare two null values';
if (str1 === null || str2 === null)
return 0;
str1 = String(str1);
str2 = String(str2);
const distance = levenshtein(str1, str2);
if (str1.length > str2.length) {
return 1 - distance / str1.length;
}
else {
return 1 - distance / str2.length;
}
}
// helper functions
function levenshtein(str1, str2) {
const current = [];
let prev;
let value;
for (let i = 0; i <= str2.length; i++) {
for (let j = 0; j <= str1.length; j++) {
if (i && j) {
if (str1.charAt(j - 1) === str2.charAt(i - 1)) {
value = prev;
}
else {
value = Math.min(current[j], current[j - 1], prev) + 1;
}
}
else {
value = i + j;
}
prev = current[j];
current[j] = value;
}
}
return current.pop();
}
const non_word_regex = /[^\w, ]+/;
function iterate_grams(value, gram_size = 2) {
const simplified = '-' + value.toLowerCase().replace(non_word_regex, '') + '-';
const len_diff = gram_size - simplified.length;
const results = [];
if (len_diff > 0) {
for (let i = 0; i < len_diff; ++i) {
value += '-';
}
}
for (let i = 0; i < simplified.length - gram_size + 1; ++i) {
results.push(simplified.slice(i, i + gram_size));
}
return results;
}
function gram_counter(value, gram_size = 2) {
// return an object where key=gram, value=number of occurrences
const result = {};
const grams = iterate_grams(value, gram_size);
let i = 0;
for (i; i < grams.length; ++i) {
if (grams[i] in result) {
result[grams[i]] += 1;
}
else {
result[grams[i]] = 1;
}
}
return result;
}
function sort_descending(a, b) {
return b[0] - a[0];
}
class FuzzySet {
constructor(arr) {
this.exact_set = {};
this.match_dict = {};
this.items = {};
// initialization
for (let i = GRAM_SIZE_LOWER; i < GRAM_SIZE_UPPER + 1; ++i) {
this.items[i] = [];
}
// add all the items to the set
for (let i = 0; i < arr.length; ++i) {
this.add(arr[i]);
}
}
add(value) {
const normalized_value = value.toLowerCase();
if (normalized_value in this.exact_set) {
return false;
}
let i = GRAM_SIZE_LOWER;
for (i; i < GRAM_SIZE_UPPER + 1; ++i) {
this._add(value, i);
}
}
_add(value, gram_size) {
const normalized_value = value.toLowerCase();
const items = this.items[gram_size] || [];
const index = items.length;
items.push(0);
const gram_counts = gram_counter(normalized_value, gram_size);
let sum_of_square_gram_counts = 0;
let gram;
let gram_count;
for (gram in gram_counts) {
gram_count = gram_counts[gram];
sum_of_square_gram_counts += Math.pow(gram_count, 2);
if (gram in this.match_dict) {
this.match_dict[gram].push([index, gram_count]);
}
else {
this.match_dict[gram] = [[index, gram_count]];
}
}
const vector_normal = Math.sqrt(sum_of_square_gram_counts);
items[index] = [vector_normal, normalized_value];
this.items[gram_size] = items;
this.exact_set[normalized_value] = value;
}
get(value) {
const normalized_value = value.toLowerCase();
const result = this.exact_set[normalized_value];
if (result) {
return [[1, result]];
}
let results = [];
// start with high gram size and if there are no results, go to lower gram sizes
for (let gram_size = GRAM_SIZE_UPPER; gram_size >= GRAM_SIZE_LOWER; --gram_size) {
results = this.__get(value, gram_size);
if (results) {
return results;
}
}
return null;
}
__get(value, gram_size) {
const normalized_value = value.toLowerCase();
const matches = {};
const gram_counts = gram_counter(normalized_value, gram_size);
const items = this.items[gram_size];
let sum_of_square_gram_counts = 0;
let gram;
let gram_count;
let i;
let index;
let other_gram_count;
for (gram in gram_counts) {
gram_count = gram_counts[gram];
sum_of_square_gram_counts += Math.pow(gram_count, 2);
if (gram in this.match_dict) {
for (i = 0; i < this.match_dict[gram].length; ++i) {
index = this.match_dict[gram][i][0];
other_gram_count = this.match_dict[gram][i][1];
if (index in matches) {
matches[index] += gram_count * other_gram_count;
}
else {
matches[index] = gram_count * other_gram_count;
}
}
}
}
const vector_normal = Math.sqrt(sum_of_square_gram_counts);
let results = [];
let match_score;
// build a results list of [score, str]
for (const match_index in matches) {
match_score = matches[match_index];
results.push([
match_score / (vector_normal * items[match_index][0]),
items[match_index][1],
]);
}
results.sort(sort_descending);
let new_results = [];
const end_index = Math.min(50, results.length);
// truncate somewhat arbitrarily to 50
for (let i = 0; i < end_index; ++i) {
new_results.push([
_distance(results[i][1], normalized_value),
results[i][1],
]);
}
results = new_results;
results.sort(sort_descending);
new_results = [];
for (let i = 0; i < results.length; ++i) {
if (results[i][0] == results[0][0]) {
new_results.push([results[i][0], this.exact_set[results[i][1]]]);
}
}
return new_results;
}
}
function list$1(items, conjunction = 'or') {
if (items.length === 1)
return items[0];
return `${items.slice(0, -1).join(', ')} ${conjunction} ${items[items.length - 1]}`;
}
// eslint-disable-next-line no-useless-escape
const valid_tag_name = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/;
const meta_tags = new Map([
['svelte:head', 'Head'],
['svelte:options', 'Options'],
['svelte:window', 'Window'],
['svelte:body', 'Body']
]);
const valid_meta_tags = Array.from(meta_tags.keys()).concat('svelte:self', 'svelte:component');
const specials = new Map([
[
'script',
{
read: read_script,
property: 'js',
},
],
[
'style',
{
read: read_style,
property: 'css',
},
],
]);
const SELF = /^svelte:self(?=[\s/>])/;
const COMPONENT = /^svelte:component(?=[\s/>])/;
function parent_is_head(stack) {
let i = stack.length;
while (i--) {
const { type } = stack[i];
if (type === 'Head')
return true;
if (type === 'Element' || type === 'InlineComponent')
return false;
}
return false;
}
function tag(parser) {
const start = parser.index++;
let parent = parser.current();
if (parser.eat('!--')) {
const data = parser.read_until(/-->/);
parser.eat('-->', true, 'comment was left open, expected -->');
parser.current().children.push({
start,
end: parser.index,
type: 'Comment',
data,
});
return;
}
const is_closing_tag = parser.eat('/');
const name = read_tag_name(parser);
if (meta_tags.has(name)) {
const slug = meta_tags.get(name).toLowerCase();
if (is_closing_tag) {
if ((name === 'svelte:window' || name === 'svelte:body') &&
parser.current().children.length) {
parser.error({
code: `invalid-${slug}-content`,
message: `<${name}> cannot have children`
}, parser.current().children[0].start);
}
}
else {
if (name in parser.meta_tags) {
parser.error({
code: `duplicate-${slug}`,
message: `A component can only have one <${name}> tag`
}, start);
}
if (parser.stack.length > 1) {
parser.error({
code: `invalid-${slug}-placement`,
message: `<${name}> tags cannot be inside elements or blocks`
}, start);
}
parser.meta_tags[name] = true;
}
}
const type = meta_tags.has(name)
? meta_tags.get(name)
: (/[A-Z]/.test(name[0]) || name === 'svelte:self' || name === 'svelte:component') ? 'InlineComponent'
: name === 'title' && parent_is_head(parser.stack) ? 'Title'
: name === 'slot' && !parser.customElement ? 'Slot' : 'Element';
const element = {
start,
end: null,
type,
name,
attributes: [],
children: [],
};
parser.allow_whitespace();
if (is_closing_tag) {
if (is_void(name)) {
parser.error({
code: `invalid-void-content`,
message: `<${name}> is a void element and cannot have children, or a closing tag`
}, start);
}
parser.eat('>', true);
// close any elements that don't have their own closing tags, e.g. <div><p></div>
while (parent.name !== name) {
if (parent.type !== 'Element') {
const message = parser.last_auto_closed_tag && parser.last_auto_closed_tag.tag === name
? `</${name}> attempted to close <${name}> that was already automatically closed by <${parser.last_auto_closed_tag.reason}>`
: `</${name}> attempted to close an element that was not open`;
parser.error({
code: `invalid-closing-tag`,
message
}, start);
}
parent.end = start;
parser.stack.pop();
parent = parser.current();
}
parent.end = parser.index;
parser.stack.pop();
if (parser.last_auto_closed_tag && parser.stack.length < parser.last_auto_closed_tag.depth) {
parser.last_auto_closed_tag = null;
}
return;
}
else if (closing_tag_omitted(parent.name, name)) {
parent.end = start;
parser.stack.pop();
parser.last_auto_closed_tag = {
tag: parent.name,
reason: name,
depth: parser.stack.length,
};
}
const unique_names = new Set();
let attribute;
while ((attribute = read_attribute(parser, unique_names))) {
element.attributes.push(attribute);
parser.allow_whitespace();
}
if (name === 'svelte:component') {
const index = element.attributes.findIndex(attr => attr.type === 'Attribute' && attr.name === 'this');
if (!~index) {
parser.error({
code: `missing-component-definition`,
message: `<svelte:component> must have a 'this' attribute`
}, start);
}
const definition = element.attributes.splice(index, 1)[0];
if (definition.value === true || definition.value.length !== 1 || definition.value[0].type === 'Text') {
parser.error({
code: `invalid-component-definition`,
message: `invalid component definition`
}, definition.start);
}
element.expression = definition.value[0].expression;
}
// special cases top-level <script> and <style>
if (specials.has(name) && parser.stack.length === 1) {
const special = specials.get(name);
parser.eat('>', true);
const content = special.read(parser, start, element.attributes);
if (content)
parser[special.property].push(content);
return;
}
parser.current().children.push(element);
const self_closing = parser.eat('/') || is_void(name);
parser.eat('>', true);
if (self_closing) {
// don't push self-closing elements onto the stack
element.end = parser.index;
}
else if (name === 'textarea') {
// special case
element.children = read_sequence(parser, () => parser.template.slice(parser.index, parser.index + 11) === '</textarea>');
parser.read(/<\/textarea>/);
element.end = parser.index;
}
else if (name === 'script') {
// special case
const start = parser.index;
const data = parser.read_until(/<\/script>/);
const end = parser.index;
element.children.push({ start, end, type: 'Text', data });
parser.eat('</script>', true);
element.end = parser.index;
}
else if (name === 'style') {
// special case
const start = parser.index;
const data = parser.read_until(/<\/style>/);
const end = parser.index;
element.children.push({ start, end, type: 'Text', data });
parser.eat('</style>', true);
}
else {
parser.stack.push(element);
}
}
function read_tag_name(parser) {
const start = parser.index;
if (parser.read(SELF)) {
// check we're inside a block, otherwise this
// will cause infinite recursion
let i = parser.stack.length;
let legal = false;
while (i--) {
const fragment = parser.stack[i];
if (fragment.type === 'IfBlock' || fragment.type === 'EachBlock' || fragment.type === 'InlineComponent') {
legal = true;
break;
}
}
if (!legal) {
parser.error({
code: `invalid-self-placement`,
message: `<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components`
}, start);
}
return 'svelte:self';
}
if (parser.read(COMPONENT))
return 'svelte:component';
const name = parser.read_until(/(\s|\/|>)/);
if (meta_tags.has(name))
return name;
if (name.startsWith('svelte:')) {
const match = fuzzymatch(name.slice(7), valid_meta_tags);
let message = `Valid <svelte:...> tag names are ${list$1(valid_meta_tags)}`;
if (match)
message += ` (did you mean '${match}'?)`;
parser.error({
code: 'invalid-tag-name',
message
}, start);
}
if (!valid_tag_name.test(name)) {
parser.error({
code: `invalid-tag-name`,
message: `Expected valid tag name`
}, start);
}
return name;
}
function read_attribute(parser, unique_names) {
const start = parser.index;
function check_unique(name) {
if (unique_names.has(name)) {
parser.error({
code: `duplicate-attribute`,
message: 'Attributes need to be unique'
}, start);
}
unique_names.add(name);
}
if (parser.eat('{')) {
parser.allow_whitespace();
if (parser.eat('...')) {
const expression = read_expression(parser);
parser.allow_whitespace();
parser.eat('}', true);
return {
start,
end: parser.index,
type: 'Spread',
expression
};
}
else {
const value_start = parser.index;
const name = parser.read_identifier();
parser.allow_whitespace();
parser.eat('}', true);
check_unique(name);
return {
start,
end: parser.index,
type: 'Attribute',
name,
value: [{
start: value_start,
end: value_start + name.length,
type: 'AttributeShorthand',
expression: {
start: value_start,
end: value_start + name.length,
type: 'Identifier',
name
}
}]
};
}
}
// eslint-disable-next-line no-useless-escape
const name = parser.read_until(/[\s=\/>"']/);
if (!name)
return null;
let end = parser.index;
parser.allow_whitespace();
const colon_index = name.indexOf(':');
const type = colon_index !== -1 && get_directive_type(name.slice(0, colon_index));
let value = true;
if (parser.eat('=')) {
parser.allow_whitespace();
value = read_attribute_value(parser);
end = parser.index;
}
else if (parser.match_regex(/["']/)) {
parser.error({
code: `unexpected-token`,
message: `Expected =`
}, parser.index);
}
if (type) {
const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|');
if (type === 'Binding' && directive_name !== 'this') {
check_unique(directive_name);
}
else if (type !== 'EventHandler') {
check_unique(name);
}
if (type === 'Ref') {
parser.error({
code: `invalid-ref-directive`,
message: `The ref directive is no longer supported — use \`bind:this={${directive_name}}\` instead`
}, start);
}
if (value[0]) {
if (value.length > 1 || value[0].type === 'Text') {
parser.error({
code: `invalid-directive-value`,
message: `Directive value must be a JavaScript expression enclosed in curly braces`
}, value[0].start);
}
}
const directive = {
start,
end,
type,
name: directive_name,
modifiers,
expression: (value[0] && value[0].expression) || null
};
if (type === 'Transition') {
const direction = name.slice(0, colon_index);
directive.intro = direction === 'in' || direction === 'transition';
directive.outro = direction === 'out' || direction === 'transition';
}
if (!directive.expression && (type === 'Binding' || type === 'Class')) {
directive.expression = {
start: directive.start + colon_index + 1,
end: directive.end,
type: 'Identifier',
name: directive.name
};
}
return directive;
}
check_unique(name);
return {
start,
end,
type: 'Attribute',
name,
value,
};
}
function get_directive_type(name) {
if (name === 'use')
return 'Action';
if (name === 'animate')
return 'Animation';
if (name === 'bind')
return 'Binding';
if (name === 'class')
return 'Class';
if (name === 'on')
return 'EventHandler';
if (name === 'let')
return 'Let';
if (name === 'ref')
return 'Ref';
if (name === 'in' || name === 'out' || name === 'transition')
return 'Transition';
}
function read_attribute_value(parser) {
const quote_mark = parser.eat(`'`) ? `'` : parser.eat(`"`) ? `"` : null;
const regex = (quote_mark === `'` ? /'/ :
quote_mark === `"` ? /"/ :
/(\/>|[\s"'=<>`])/);
const value = read_sequence(parser, () => !!parser.match_regex(regex));
if (quote_mark)
parser.index += 1;
return value;
}
function read_sequence(parser, done) {
let current_chunk = {
start: parser.index,
end: null,
type: 'Text',
raw: '',
data: null
};
function flush() {
if (current_chunk.raw) {
current_chunk.data = decode_character_references(current_chunk.raw);
current_chunk.end = parser.index;
chunks.push(current_chunk);
}
}
const chunks = [];
while (parser.index < parser.template.length) {
const index = parser.index;
if (done()) {
flush();
return chunks;
}
else if (parser.eat('{')) {
flush();
parser.allow_whitespace();
const expression = read_expression(parser);
parser.allow_whitespace();
parser.eat('}', true);
chunks.push({
start: index,
end: parser.index,
type: 'MustacheTag',
expression,
});
current_chunk = {
start: parser.index,
end: null,
type: 'Text',
raw: '',
data: null
};
}
else {
current_chunk.raw += parser.template[parser.index++];
}
}
parser.error({
code: `unexpected-eof`,
message: `Unexpected end of input`
});
}
const SQUARE_BRACKET_OPEN = "[".charCodeAt(0);
const SQUARE_BRACKET_CLOSE = "]".charCodeAt(0);
const CURLY_BRACKET_OPEN = "{".charCodeAt(0);
const CURLY_BRACKET_CLOSE = "}".charCodeAt(0);
function is_bracket_open(code) {
return code === SQUARE_BRACKET_OPEN || code === CURLY_BRACKET_OPEN;
}
function is_bracket_close(code) {
return code === SQUARE_BRACKET_CLOSE || code === CURLY_BRACKET_CLOSE;
}
function is_bracket_pair(open, close) {
return ((open === SQUARE_BRACKET_OPEN && close === SQUARE_BRACKET_CLOSE) ||
(open === CURLY_BRACKET_OPEN && close === CURLY_BRACKET_CLOSE));
}
function get_bracket_close(open) {
if (open === SQUARE_BRACKET_OPEN) {
return SQUARE_BRACKET_CLOSE;
}
if (open === CURLY_BRACKET_OPEN) {
return CURLY_BRACKET_CLOSE;
}
}
function read_context(parser) {
const start = parser.index;
let i = parser.index;
const code = full_char_code_at(parser.template, i);
if (isIdentifierStart(code, true)) {
return {
type: "Identifier",
name: parser.read_identifier(),
start,
end: parser.index
};
}
if (!is_bracket_open(code)) {
parser.error({
code: "unexpected-token",
message: "Expected identifier or destructure pattern"
});
}
const bracket_stack = [code];
i += code <= 0xffff ? 1 : 2;
while (i < parser.template.length) {
const code = full_char_code_at(parser.template, i);
if (is_bracket_open(code)) {
bracket_stack.push(code);
}
else if (is_bracket_close(code)) {
if (!is_bracket_pair(bracket_stack[bracket_stack.length - 1], code)) {
parser.error({
code: "unexpected-token",
message: `Expected ${String.fromCharCode(get_bracket_close(bracket_stack[bracket_stack.length - 1]))}`
});
}
bracket_stack.pop();
if (bracket_stack.length === 0) {
i += code <= 0xffff ? 1 : 2;
break;
}
}
i += code <= 0xffff ? 1 : 2;
}
parser.index = i;
const pattern_string = parser.template.slice(start, i);
try {
// the length of the `space_with_newline` has to be start - 1
// because we added a `(` in front of the pattern_string,
// which shifted the entire string to right by 1
// so we offset it by removing 1 character in the `space_with_newline`
// to achieve that, we remove the 1st space encountered,
// so it will not affect the `column` of the node
let space_with_newline = parser.template.slice(0, start).replace(/[^\n]/g, ' ');
const first_space = space_with_newline.indexOf(' ');
space_with_newline = space_with_newline.slice(0, first_space) + space_with_newline.slice(first_space + 1);
return parse_expression_at(`${space_with_newline}(${pattern_string} = 1)`, start - 1).left;
}
catch (error) {
parser.acorn_error(error);
}
}
function trim_start(str) {
let i = 0;
while (whitespace.test(str[i]))
i += 1;
return str.slice(i);
}
function trim_end(str) {
let i = str.length;
while (whitespace.test(str[i - 1]))
i -= 1;
return str.slice(0, i);
}
function to_string(node) {
switch (node.type) {
case 'IfBlock':
return '{#if} block';
case 'ThenBlock':
return '{:then} block';
case 'ElseBlock':
return '{:else} block';
case 'PendingBlock':
case 'AwaitBlock':
return '{#await} block';
case 'CatchBlock':
return '{:catch} block';
case 'EachBlock':
return '{#each} block';
case 'RawMustacheTag':
return '{@html} block';
case 'DebugTag':
return '{@debug} block';
case 'Element':
case 'InlineComponent':
case 'Slot':
case 'Title':
return `<${node.name}> tag`;
default:
return node.type;
}
}
function trim_whitespace(block, trim_before, trim_after) {
if (!block.children || block.children.length === 0)
return; // AwaitBlock
const first_child = block.children[0];
const last_child = block.children[block.children.length - 1];
if (first_child.type === 'Text' && trim_before) {
first_child.data = trim_start(first_child.data);
if (!first_child.data)
block.children.shift();
}
if (last_child.type === 'Text' && trim_after) {
last_child.data = trim_end(last_child.data);
if (!last_child.data)
block.children.pop();
}
if (block.else) {
trim_whitespace(block.else, trim_before, trim_after);
}
if (first_child.elseif) {
trim_whitespace(first_child, trim_before, trim_after);
}
}
function mustache(parser) {
const start = parser.index;
parser.index += 1;
parser.allow_whitespace();
// {/if}, {/each} or {/await}
if (parser.eat('/')) {
let block = parser.current();
let expected;
if (closing_tag_omitted(block.name)) {
block.end = start;
parser.stack.pop();
block = parser.current();
}
if (block.type === 'ElseBlock' || block.type === 'PendingBlock' || block.type === 'ThenBlock' || block.type === 'CatchBlock') {
block.end = start;
parser.stack.pop();
block = parser.current();
expected = 'await';
}
if (block.type === 'IfBlock') {
expected = 'if';
}
else if (block.type === 'EachBlock') {
expected = 'each';
}
else if (block.type === 'AwaitBlock') {
expected = 'await';
}
else {
parser.error({
code: `unexpected-block-close`,
message: `Unexpected block closing tag`
});
}
parser.eat(expected, true);
parser.allow_whitespace();
parser.eat('}', true);
while (block.elseif) {
block.end = parser.index;
parser.stack.pop();
block = parser.current();
if (block.else) {
block.else.end = start;
}
}
// strip leading/trailing whitespace as necessary
const char_before = parser.template[block.start - 1];
const char_after = parser.template[parser.index];
const trim_before = !char_before || whitespace.test(char_before);
const trim_after = !char_after || whitespace.test(char_after);
trim_whitespace(block, trim_before, trim_after);
block.end = parser.index;
parser.stack.pop();
}
else if (parser.eat(':else')) {
if (parser.eat('if')) {
parser.error({
code: 'invalid-elseif',
message: `'elseif' should be 'else if'`
});
}
parser.allow_whitespace();
// :else if
if (parser.eat('if')) {
const block = parser.current();
if (block.type !== 'IfBlock') {
parser.error({
code: `invalid-elseif-placement`,
message: parser.stack.some(block => block.type === 'IfBlock')
? `Expected to close ${to_string(block)} before seeing {:else if ...} block`
: `Cannot have an {:else if ...} block outside an {#if ...} block`
});
}
parser.require_whitespace();
const expression = read_expression(parser);
parser.allow_whitespace();
parser.eat('}', true);
block.else = {
start: parser.index,
end: null,
type: 'ElseBlock',
children: [
{
start: parser.index,
end: null,
type: 'IfBlock',
elseif: true,
expression,
children: [],
},
],
};
parser.stack.push(block.else.children[0]);
}
// :else
else {
const block = parser.current();
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
parser.error({
code: `invalid-else-placement`,
message: parser.stack.some(block => block.type === 'IfBlock' || block.type === 'EachBlock')
? `Expected to close ${to_string(block)} before seeing {:else} block`
: `Cannot have an {:else} block outside an {#if ...} or {#each ...} block`
});
}
parser.allow_whitespace();
parser.eat('}', true);
block.else = {
start: parser.index,
end: null,
type: 'ElseBlock',
children: [],
};
parser.stack.push(block.else);
}
}
else if (parser.match(':then') || parser.match(':catch')) {
const block = parser.current();
const is_then = parser.eat(':then') || !parser.eat(':catch');
if (is_then) {
if (block.type !== 'PendingBlock') {
parser.error({
code: `invalid-then-placement`,
message: parser.stack.some(block => block.type === 'PendingBlock')
? `Expected to close ${to_string(block)} before seeing {:then} block`
: `Cannot have an {:then} block outside an {#await ...} block`
});
}
}
else {
if (block.type !== 'ThenBlock' && block.type !== 'PendingBlock') {
parser.error({
code: `invalid-catch-placement`,
message: parser.stack.some(block => block.type === 'ThenBlock' || block.type === 'PendingBlock')
? `Expected to close ${to_string(block)} before seeing {:catch} block`
: `Cannot have an {:catch} block outside an {#await ...} block`
});
}
}
block.end = start;
parser.stack.pop();
const await_block = parser.current();
if (!parser.eat('}')) {
parser.require_whitespace();
await_block[is_then ? 'value' : 'error'] = read_context(parser);
parser.allow_whitespace();
parser.eat('}', true);
}
const new_block = {
start,
end: null,
type: is_then ? 'ThenBlock' : 'CatchBlock',
children: [],
skip: false
};
await_block[is_then ? 'then' : 'catch'] = new_block;
parser.stack.push(new_block);
}
else if (parser.eat('#')) {
// {#if foo}, {#each foo} or {#await foo}
let type;
if (parser.eat('if')) {
type = 'IfBlock';
}
else if (parser.eat('each')) {
type = 'EachBlock';
}
else if (parser.eat('await')) {
type = 'AwaitBlock';
}
else {
parser.error({
code: `expected-block-type`,
message: `Expected if, each or await`
});
}
parser.require_whitespace();
const expression = read_expression(parser);
const block = type === 'AwaitBlock' ?
{
start,
end: null,
type,
expression,
value: null,
error: null,
pending: {
start: null,
end: null,
type: 'PendingBlock',
children: [],
skip: true
},
then: {
start: null,
end: null,
type: 'ThenBlock',
children: [],
skip: true
},
catch: {
start: null,
end: null,
type: 'CatchBlock',
children: [],
skip: true
},
} :
{
start,
end: null,
type,
expression,
children: [],
};
parser.allow_whitespace();
// {#each} blocks must declare a context {#each list as item}
if (type === 'EachBlock') {
parser.eat('as', true);
parser.require_whitespace();
block.context = read_context(parser);
parser.allow_whitespace();
if (parser.eat(',')) {
parser.allow_whitespace();
block.index = parser.read_identifier();
if (!block.index)
parser.error({
code: `expected-name`,
message: `Expected name`
});
parser.allow_whitespace();
}
if (parser.eat('(')) {
parser.allow_whitespace();
block.key = read_expression(parser);
parser.allow_whitespace();
parser.eat(')', true);
parser.allow_whitespace();
}
}
const await_block_shorthand = type === 'AwaitBlock' && parser.eat('then');
if (await_block_shorthand) {
parser.require_whitespace();
block.value = read_context(parser);
parser.allow_whitespace();
}
const await_block_catch_shorthand = !await_block_shorthand && type === 'AwaitBlock' && parser.eat('catch');
if (await_block_catch_shorthand) {
parser.require_whitespace();
block.error = read_context(parser);
parser.allow_whitespace();
}
parser.eat('}', true);
parser.current().children.push(block);
parser.stack.push(block);
if (type === 'AwaitBlock') {
let child_block;
if (await_block_shorthand) {
block.then.skip = false;
child_block = block.then;
}
else if (await_block_catch_shorthand) {
block.catch.skip = false;
child_block = block.catch;
}
else {
block.pending.skip = false;
child_block = block.pending;
}
child_block.start = parser.index;
parser.stack.push(child_block);
}
}
else if (parser.eat('@html')) {
// {@html content} tag
parser.require_whitespace();
const expression = read_expression(parser);
parser.allow_whitespace();
parser.eat('}', true);
parser.current().children.push({
start,
end: parser.index,
type: 'RawMustacheTag',
expression,
});
}
else if (parser.eat('@debug')) {
let identifiers;
// Implies {@debug} which indicates "debug all"
if (parser.read(/\s*}/)) {
identifiers = [];
}
else {
const expression = read_expression(parser);
identifiers = expression.type === 'SequenceExpression'
? expression.expressions
: [expression];
identifiers.forEach(node => {
if (node.type !== 'Identifier') {
parser.error({
code: 'invalid-debug-args',
message: '{@debug ...} arguments must be identifiers, not arbitrary expressions'
}, node.start);
}
});
parser.allow_whitespace();
parser.eat('}', true);
}
parser.current().children.push({
start,
end: parser.index,
type: 'DebugTag',
identifiers
});
}
else {
const expression = read_expression(parser);
parser.allow_whitespace();
parser.eat('}', true);
parser.current().children.push({
start,
end: parser.index,
type: 'MustacheTag',
expression,
});
}
}
function text(parser) {
const start = parser.index;
let data = '';
while (parser.index < parser.template.length &&
!parser.match('<') &&
!parser.match('{')) {
data += parser.template[parser.index++];
}
const node = {
start,
end: parser.index,
type: 'Text',
raw: data,
data: decode_character_references(data),
};
parser.current().children.push(node);
}
function fragment(parser) {
if (parser.match('<')) {
return tag;
}
if (parser.match('{')) {
return mustache;
}
return text;
}
function getLocator(source, options) {
if (options === void 0) { options = {}; }
var offsetLine = options.offsetLine || 0;
var offsetColumn = options.offsetColumn || 0;
var originalLines = source.split('\n');
var start = 0;
var lineRanges = originalLines.map(function (line, i) {
var end = start + line.length + 1;
var range = { start: start, end: end, line: i };
start = end;
return range;
});
var i = 0;
function rangeContains(range, index) {
return range.start <= index && index < range.end;
}
function getLocation(range, index) {
return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };
}
function locate(search, startIndex) {
if (typeof search === 'string') {
search = source.indexOf(search, startIndex || 0);
}
var range = lineRanges[i];
var d = search >= range.end ? 1 : -1;
while (range) {
if (rangeContains(range, search))
return getLocation(range, search);
i += d;
range = lineRanges[i];
}
}
return locate;
}
function locate(source, search, options) {
if (typeof options === 'number') {
throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument');
}
return getLocator(source, options)(search, options && options.startIndex);
}
function tabs_to_spaces(str) {
return str.replace(/^\t+/, match => match.split('\t').join(' '));
}
function get_code_frame(source, line, column) {
const lines = source.split('\n');
const frame_start = Math.max(0, line - 2);
const frame_end = Math.min(line + 3, lines.length);
const digits = String(frame_end + 1).length;
return lines
.slice(frame_start, frame_end)
.map((str, i) => {
const isErrorLine = frame_start + i === line;
const line_num = String(i + frame_start + 1).padStart(digits, ' ');
if (isErrorLine) {
const indicator = ' '.repeat(digits + 2 + tabs_to_spaces(str.slice(0, column)).length) + '^';
return `${line_num}: ${tabs_to_spaces(str)}\n${indicator}`;
}
return `${line_num}: ${tabs_to_spaces(str)}`;
})
.join('\n');
}
class CompileError extends Error {
toString() {
return `${this.message} (${this.start.line}:${this.start.column})\n${this.frame}`;
}
}
function error$1(message, props) {
const error = new CompileError(message);
error.name = props.name;
const start = locate(props.source, props.start, { offsetLine: 1 });
const end = locate(props.source, props.end || props.start, { offsetLine: 1 });
error.code = props.code;
error.start = start;
error.end = end;
error.pos = props.start;
error.filename = props.filename;
error.frame = get_code_frame(props.source, start.line - 1, start.column);
throw error;
}
class Parser$1 {
constructor(template, options) {
this.index = 0;
this.stack = [];
this.css = [];
this.js = [];
this.meta_tags = {};
if (typeof template !== 'string') {
throw new TypeError('Template must be a string');
}
this.template = template.replace(/\s+$/, '');
this.filename = options.filename;
this.customElement = options.customElement;
this.html = {
start: null,
end: null,
type: 'Fragment',
children: [],
};
this.stack.push(this.html);
let state = fragment;
while (this.index < this.template.length) {
state = state(this) || fragment;
}
if (this.stack.length > 1) {
const current = this.current();
const type = current.type === 'Element' ? `<${current.name}>` : 'Block';
const slug = current.type === 'Element' ? 'element' : 'block';
this.error({
code: `unclosed-${slug}`,
message: `${type} was left open`
}, current.start);
}
if (state !== fragment) {
this.error({
code: `unexpected-eof`,
message: 'Unexpected end of input'
});
}
if (this.html.children.length) {
let start = this.html.children[0].start;
while (whitespace.test(template[start]))
start += 1;
let end = this.html.children[this.html.children.length - 1].end;
while (whitespace.test(template[end - 1]))
end -= 1;
this.html.start = start;
this.html.end = end;
}
else {
this.html.start = this.html.end = null;
}
}
current() {
return this.stack[this.stack.length - 1];
}
acorn_error(err) {
this.error({
code: `parse-error`,
message: err.message.replace(/ \(\d+:\d+\)$/, '')
}, err.pos);
}
error({ code, message }, index = this.index) {
error$1(message, {
name: 'ParseError',
code,
source: this.template,
start: index,
filename: this.filename
});
}
eat(str, required, message) {
if (this.match(str)) {
this.index += str.length;
return true;
}
if (required) {
this.error({
code: `unexpected-${this.index === this.template.length ? 'eof' : 'token'}`,
message: message || `Expected ${str}`
});
}
return false;
}
match(str) {
return this.template.slice(this.index, this.index + str.length) === str;
}
match_regex(pattern) {
const match = pattern.exec(this.template.slice(this.index));
if (!match || match.index !== 0)
return null;
return match[0];
}
allow_whitespace() {
while (this.index < this.template.length &&
whitespace.test(this.template[this.index])) {
this.index++;
}
}
read(pattern) {
const result = this.match_regex(pattern);
if (result)
this.index += result.length;
return result;
}
read_identifier(allow_reserved = false) {
const start = this.index;
let i = this.index;
const code = full_char_code_at(this.template, i);
if (!isIdentifierStart(code, true))
return null;
i += code <= 0xffff ? 1 : 2;
while (i < this.template.length) {
const code = full_char_code_at(this.template, i);
if (!isIdentifierChar(code, true))
break;
i += code <= 0xffff ? 1 : 2;
}
const identifier = this.template.slice(this.index, this.index = i);
if (!allow_reserved && reserved.has(identifier)) {
this.error({
code: `unexpected-reserved-word`,
message: `'${identifier}' is a reserved word in JavaScript and cannot be used here`
}, start);
}
return identifier;
}
read_until(pattern) {
if (this.index >= this.template.length)
this.error({
code: `unexpected-eof`,
message: 'Unexpected end of input'
});
const start = this.index;
const match = pattern.exec(this.template.slice(start));
if (match) {
this.index = start + match.index;
return this.template.slice(start, this.index);
}
this.index = this.template.length;
return this.template.slice(start);
}
require_whitespace() {
if (!whitespace.test(this.template[this.index])) {
this.error({
code: `missing-whitespace`,
message: `Expected whitespace`
});
}
this.allow_whitespace();
}
}
function parse$3(template, options = {}) {
const parser = new Parser$1(template, options);
// TODO we may want to allow multiple <style> tags —
// one scoped, one global. for now, only allow one
if (parser.css.length > 1) {
parser.error({
code: 'duplicate-style',
message: 'You can only have one top-level <style> tag per component'
}, parser.css[1].start);
}
const instance_scripts = parser.js.filter(script => script.context === 'default');
const module_scripts = parser.js.filter(script => script.context === 'module');
if (instance_scripts.length > 1) {
parser.error({
code: `invalid-script`,
message: `A component can only have one instance-level <script> element`
}, instance_scripts[1].start);
}
if (module_scripts.length > 1) {
parser.error({
code: `invalid-script`,
message: `A component can only have one <script context="module"> element`
}, module_scripts[1].start);
}
return {
html: parser.html,
css: parser.css[0],
instance: instance_scripts[0],
module: module_scripts[0]
};
}
function is_head(node) {
return node && node.type === 'MemberExpression' && node.object.name === '@_document' && node.property.name === 'head';
}
class Block$1 {
constructor(options) {
this.dependencies = new Set();
this.event_listeners = [];
this.variables = new Map();
this.has_update_method = false;
this.parent = options.parent;
this.renderer = options.renderer;
this.name = options.name;
this.type = options.type;
this.comment = options.comment;
this.wrappers = [];
// for keyed each blocks
this.key = options.key;
this.first = null;
this.bindings = options.bindings;
this.chunks = {
declarations: [],
init: [],
create: [],
claim: [],
hydrate: [],
mount: [],
measure: [],
fix: [],
animate: [],
intro: [],
update: [],
outro: [],
destroy: [],
};
this.has_animation = false;
this.has_intro_method = false; // a block could have an intro method but not intro transitions, e.g. if a sibling block has intros
this.has_outro_method = false;
this.outros = 0;
this.get_unique_name = this.renderer.component.get_unique_name_maker();
this.aliases = new Map();
if (this.key)
this.aliases.set('key', this.get_unique_name('key'));
}
assign_variable_names() {
const seen = new Set();
const dupes = new Set();
let i = this.wrappers.length;
while (i--) {
const wrapper = this.wrappers[i];
if (!wrapper.var)
continue;
if (seen.has(wrapper.var.name)) {
dupes.add(wrapper.var.name);
}
seen.add(wrapper.var.name);
}
const counts = new Map();
i = this.wrappers.length;
while (i--) {
const wrapper = this.wrappers[i];
if (!wrapper.var)
continue;
let suffix = '';
if (dupes.has(wrapper.var.name)) {
const i = counts.get(wrapper.var.name) || 0;
counts.set(wrapper.var.name, i + 1);
suffix = i;
}
wrapper.var.name = this.get_unique_name(wrapper.var.name + suffix).name;
}
}
add_dependencies(dependencies) {
dependencies.forEach(dependency => {
this.dependencies.add(dependency);
});
this.has_update_method = true;
if (this.parent) {
this.parent.add_dependencies(dependencies);
}
}
add_element(id, render_statement, claim_statement, parent_node, no_detach) {
this.add_variable(id);
this.chunks.create.push(b `${id} = ${render_statement};`);
if (this.renderer.options.hydratable) {
this.chunks.claim.push(b `${id} = ${claim_statement || render_statement};`);
}
if (parent_node) {
this.chunks.mount.push(b `@append(${parent_node}, ${id});`);
if (is_head(parent_node) && !no_detach)
this.chunks.destroy.push(b `@detach(${id});`);
}
else {
this.chunks.mount.push(b `@insert(#target, ${id}, #anchor);`);
if (!no_detach)
this.chunks.destroy.push(b `if (detaching) @detach(${id});`);
}
}
add_intro(local) {
this.has_intros = this.has_intro_method = true;
if (!local && this.parent)
this.parent.add_intro();
}
add_outro(local) {
this.has_outros = this.has_outro_method = true;
this.outros += 1;
if (!local && this.parent)
this.parent.add_outro();
}
add_animation() {
this.has_animation = true;
}
add_variable(id, init) {
if (this.variables.has(id.name)) {
throw new Error(`Variable '${id.name}' already initialised with a different value`);
}
this.variables.set(id.name, { id, init });
}
alias(name) {
if (!this.aliases.has(name)) {
this.aliases.set(name, this.get_unique_name(name));
}
return this.aliases.get(name);
}
child(options) {
return new Block$1(Object.assign({}, this, { key: null }, options, { parent: this }));
}
get_contents(key) {
const { dev } = this.renderer.options;
if (this.has_outros) {
this.add_variable({ type: 'Identifier', name: '#current' });
if (this.chunks.intro.length > 0) {
this.chunks.intro.push(b `#current = true;`);
this.chunks.mount.push(b `#current = true;`);
}
if (this.chunks.outro.length > 0) {
this.chunks.outro.push(b `#current = false;`);
}
}
if (this.autofocus) {
this.chunks.mount.push(b `${this.autofocus}.focus();`);
}
this.render_listeners();
const properties = {};
const noop = x `@noop`;
properties.key = key;
if (this.first) {
properties.first = x `null`;
this.chunks.hydrate.push(b `this.first = ${this.first};`);
}
if (this.chunks.create.length === 0 && this.chunks.hydrate.length === 0) {
properties.create = noop;
}
else {
const hydrate = this.chunks.hydrate.length > 0 && (this.renderer.options.hydratable
? b `this.h();`
: this.chunks.hydrate);
properties.create = x `function #create() {
${this.chunks.create}
${hydrate}
}`;
}
if (this.renderer.options.hydratable || this.chunks.claim.length > 0) {
if (this.chunks.claim.length === 0 && this.chunks.hydrate.length === 0) {
properties.claim = noop;
}
else {
properties.claim = x `function #claim(#nodes) {
${this.chunks.claim}
${this.renderer.options.hydratable && this.chunks.hydrate.length > 0 && b `this.h();`}
}`;
}
}
if (this.renderer.options.hydratable && this.chunks.hydrate.length > 0) {
properties.hydrate = x `function #hydrate() {
${this.chunks.hydrate}
}`;
}
if (this.chunks.mount.length === 0) {
properties.mount = noop;
}
else if (this.event_listeners.length === 0) {
properties.mount = x `function #mount(#target, #anchor) {
${this.chunks.mount}
}`;
}
else {
properties.mount = x `function #mount(#target, #anchor) {
${this.chunks.mount}
}`;
}
if (this.has_update_method || this.maintain_context) {
if (this.chunks.update.length === 0 && !this.maintain_context) {
properties.update = noop;
}
else {
const ctx = this.maintain_context ? x `#new_ctx` : x `#ctx`;
let dirty = { type: 'Identifier', name: '#dirty' };
if (!this.renderer.context_overflow && !this.parent) {
dirty = { type: 'ArrayPattern', elements: [dirty] };
}
properties.update = x `function #update(${ctx}, ${dirty}) {
${this.maintain_context && b `#ctx = ${ctx};`}
${this.chunks.update}
}`;
}
}
if (this.has_animation) {
properties.measure = x `function #measure() {
${this.chunks.measure}
}`;
properties.fix = x `function #fix() {
${this.chunks.fix}
}`;
properties.animate = x `function #animate() {
${this.chunks.animate}
}`;
}
if (this.has_intro_method || this.has_outro_method) {
if (this.chunks.intro.length === 0) {
properties.intro = noop;
}
else {
properties.intro = x `function #intro(#local) {
${this.has_outros && b `if (#current) return;`}
${this.chunks.intro}
}`;
}
if (this.chunks.outro.length === 0) {
properties.outro = noop;
}
else {
properties.outro = x `function #outro(#local) {
${this.chunks.outro}
}`;
}
}
if (this.chunks.destroy.length === 0) {
properties.destroy = noop;
}
else {
properties.destroy = x `function #destroy(detaching) {
${this.chunks.destroy}
}`;
}
if (!this.renderer.component.compile_options.dev) {
// allow shorthand names
for (const name in properties) {
const property = properties[name];
if (property)
property.id = null;
}
}
const return_value = x `{
key: ${properties.key},
first: ${properties.first},
c: ${properties.create},
l: ${properties.claim},
h: ${properties.hydrate},
m: ${properties.mount},
p: ${properties.update},
r: ${properties.measure},
f: ${properties.fix},
a: ${properties.animate},
i: ${properties.intro},
o: ${properties.outro},
d: ${properties.destroy}
}`;
const block = dev && this.get_unique_name('block');
const body = b `
${this.chunks.declarations}
${Array.from(this.variables.values()).map(({ id, init }) => {
return init
? b `let ${id} = ${init}`
: b `let ${id}`;
})}
${this.chunks.init}
${dev
? b `
const ${block} = ${return_value};
@dispatch_dev("SvelteRegisterBlock", {
block: ${block},
id: ${this.name || 'create_fragment'}.name,
type: "${this.type}",
source: "${this.comment ? this.comment.replace(/"/g, '\\"') : ''}",
ctx: #ctx
});
return ${block};`
: b `
return ${return_value};`}
`;
return body;
}
has_content() {
return !!this.first ||
this.event_listeners.length > 0 ||
this.chunks.intro.length > 0 ||
this.chunks.outro.length > 0 ||
this.chunks.create.length > 0 ||
this.chunks.hydrate.length > 0 ||
this.chunks.claim.length > 0 ||
this.chunks.mount.length > 0 ||
this.chunks.update.length > 0 ||
this.chunks.destroy.length > 0 ||
this.has_animation;
}
render() {
const key = this.key && this.get_unique_name('key');
const args = [x `#ctx`];
if (key)
args.unshift(key);
const fn = b `function ${this.name}(${args}) {
${this.get_contents(key)}
}`;
return this.comment
? b `
// ${this.comment}
${fn}`
: fn;
}
render_listeners(chunk = '') {
if (this.event_listeners.length > 0) {
this.add_variable({ type: 'Identifier', name: '#mounted' });
this.chunks.destroy.push(b `#mounted = false`);
const dispose = {
type: 'Identifier',
name: `#dispose${chunk}`
};
this.add_variable(dispose);
if (this.event_listeners.length === 1) {
this.chunks.mount.push(b `
if (!#mounted) {
${dispose} = ${this.event_listeners[0]};
#mounted = true;
}
`);
this.chunks.destroy.push(b `${dispose}();`);
}
else {
this.chunks.mount.push(b `
if (!#mounted) {
${dispose} = [
${this.event_listeners}
];
#mounted = true;
}
`);
this.chunks.destroy.push(b `@run_all(${dispose});`);
}
}
}
}
class Wrapper {
constructor(renderer, block, parent, node) {
this.node = node;
// make these non-enumerable so that they can be logged sensibly
// (TODO in dev only?)
Object.defineProperties(this, {
renderer: {
value: renderer
},
parent: {
value: parent
}
});
this.can_use_innerhtml = !renderer.options.hydratable;
this.is_static_content = !renderer.options.hydratable;
block.wrappers.push(this);
}
cannot_use_innerhtml() {
this.can_use_innerhtml = false;
if (this.parent)
this.parent.cannot_use_innerhtml();
}
not_static_content() {
this.is_static_content = false;
if (this.parent)
this.parent.not_static_content();
}
get_or_create_anchor(block, parent_node, parent_nodes) {
// TODO use this in EachBlock and IfBlock — tricky because
// children need to be created first
const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node();
const anchor = needs_anchor
? block.get_unique_name(`${this.var.name}_anchor`)
: (this.next && this.next.var) || { type: 'Identifier', name: 'null' };
if (needs_anchor) {
block.add_element(anchor, x `@empty()`, parent_nodes && x `@empty()`, parent_node);
}
return anchor;
}
get_update_mount_node(anchor) {
return ((this.parent && this.parent.is_dom_node())
? this.parent.var
: x `${anchor}.parentNode`);
}
is_dom_node() {
return (this.node.type === 'Element' ||
this.node.type === 'Text' ||
this.node.type === 'MustacheTag');
}
render(_block, _parent_node, _parent_nodes) {
throw Error('Wrapper class is not renderable');
}
}
function create_debugging_comment(node, component) {
const { locate, source } = component;
let c = node.start;
if (node.type === 'ElseBlock') {
while (source[c - 1] !== '{')
c -= 1;
while (source[c - 1] === '{')
c -= 1;
}
let d;
if (node.type === 'InlineComponent' || node.type === 'Element') {
if (node.children.length) {
d = node.children[0].start;
while (source[d - 1] !== '>')
d -= 1;
}
else {
d = node.start;
while (source[d] !== '>')
d += 1;
d += 1;
}
}
else if (node.type === 'Text' || node.type === 'Comment') {
d = node.end;
}
else {
// @ts-ignore
d = node.expression ? node.expression.node.end : c;
while (source[d] !== '}')
d += 1;
while (source[d] === '}')
d += 1;
}
const start = locate(c);
const loc = `(${start.line}:${start.column})`;
return `${loc} ${source.slice(c, d)}`.replace(/\s/g, ' ');
}
class AwaitBlockBranch extends Wrapper {
constructor(status, renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.var = null;
this.status = status;
this.block = block.child({
comment: create_debugging_comment(node, this.renderer.component),
name: this.renderer.component.get_unique_name(`create_${status}_block`),
type: status
});
this.add_context(parent.node[status + '_node'], parent.node[status + '_contexts']);
this.fragment = new FragmentWrapper(renderer, this.block, this.node.children, parent, strip_whitespace, next_sibling);
this.is_dynamic = this.block.dependencies.size > 0;
}
add_context(node, contexts) {
if (!node)
return;
if (node.type === 'Identifier') {
this.value = node.name;
this.renderer.add_to_context(this.value, true);
}
else {
contexts.forEach(context => {
this.renderer.add_to_context(context.key.name, true);
});
this.value = this.block.parent.get_unique_name('value').name;
this.value_contexts = contexts;
this.renderer.add_to_context(this.value, true);
this.is_destructured = true;
}
this.value_index = this.renderer.context_lookup.get(this.value).index;
}
render(block, parent_node, parent_nodes) {
this.fragment.render(block, parent_node, parent_nodes);
if (this.is_destructured) {
this.render_destructure();
}
}
render_destructure() {
const props = this.value_contexts.map(prop => b `#ctx[${this.block.renderer.context_lookup.get(prop.key.name).index}] = ${prop.modifier(x `#ctx[${this.value_index}]`)};`);
const get_context = this.block.renderer.component.get_unique_name(`get_${this.status}_context`);
this.block.renderer.blocks.push(b `
function ${get_context}(#ctx) {
${props}
}
`);
this.block.chunks.declarations.push(b `${get_context}(#ctx)`);
if (this.block.has_update_method) {
this.block.chunks.update.push(b `${get_context}(#ctx)`);
}
}
}
class AwaitBlockWrapper extends Wrapper {
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.var = { type: 'Identifier', name: 'await_block' };
this.cannot_use_innerhtml();
this.not_static_content();
block.add_dependencies(this.node.expression.dependencies);
let is_dynamic = false;
let has_intros = false;
let has_outros = false;
['pending', 'then', 'catch'].forEach((status) => {
const child = this.node[status];
const branch = new AwaitBlockBranch(status, renderer, block, this, child, strip_whitespace, next_sibling);
renderer.blocks.push(branch.block);
if (branch.is_dynamic) {
is_dynamic = true;
// TODO should blocks update their own parents?
block.add_dependencies(branch.block.dependencies);
}
if (branch.block.has_intros)
has_intros = true;
if (branch.block.has_outros)
has_outros = true;
this[status] = branch;
});
['pending', 'then', 'catch'].forEach(status => {
this[status].block.has_update_method = is_dynamic;
this[status].block.has_intro_method = has_intros;
this[status].block.has_outro_method = has_outros;
});
if (has_outros) {
block.add_outro();
}
}
render(block, parent_node, parent_nodes) {
const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes);
const update_mount_node = this.get_update_mount_node(anchor);
const snippet = this.node.expression.manipulate(block);
const info = block.get_unique_name(`info`);
const promise = block.get_unique_name(`promise`);
block.add_variable(promise);
block.maintain_context = true;
const info_props = x `{
ctx: #ctx,
current: null,
token: null,
pending: ${this.pending.block.name},
then: ${this.then.block.name},
catch: ${this.catch.block.name},
value: ${this.then.value_index},
error: ${this.catch.value_index},
blocks: ${this.pending.block.has_outro_method && x `[,,,]`}
}`;
block.chunks.init.push(b `
let ${info} = ${info_props};
`);
block.chunks.init.push(b `
@handle_promise(${promise} = ${snippet}, ${info});
`);
block.chunks.create.push(b `
${info}.block.c();
`);
if (parent_nodes && this.renderer.options.hydratable) {
block.chunks.claim.push(b `
${info}.block.l(${parent_nodes});
`);
}
const initial_mount_node = parent_node || '#target';
const anchor_node = parent_node ? 'null' : '#anchor';
const has_transitions = this.pending.block.has_intro_method || this.pending.block.has_outro_method;
block.chunks.mount.push(b `
${info}.block.m(${initial_mount_node}, ${info}.anchor = ${anchor_node});
${info}.mount = () => ${update_mount_node};
${info}.anchor = ${anchor};
`);
if (has_transitions) {
block.chunks.intro.push(b `@transition_in(${info}.block);`);
}
const dependencies = this.node.expression.dynamic_dependencies();
if (dependencies.length > 0) {
const condition = x `
${block.renderer.dirty(dependencies)} &&
${promise} !== (${promise} = ${snippet}) &&
@handle_promise(${promise}, ${info})`;
block.chunks.update.push(b `${info}.ctx = #ctx;`);
if (this.pending.block.has_update_method) {
block.chunks.update.push(b `
if (${condition}) {
} else {
const #child_ctx = #ctx.slice();
${this.then.value && b `#child_ctx[${this.then.value_index}] = ${info}.resolved;`}
${info}.block.p(#child_ctx, #dirty);
}
`);
}
else {
block.chunks.update.push(b `
${condition}
`);
}
}
else {
if (this.pending.block.has_update_method) {
block.chunks.update.push(b `
{
const #child_ctx = #ctx.slice();
${this.then.value && b `#child_ctx[${this.then.value_index}] = ${info}.resolved;`}
${info}.block.p(#child_ctx, #dirty);
}
`);
}
}
if (this.pending.block.has_outro_method) {
block.chunks.outro.push(b `
for (let #i = 0; #i < 3; #i += 1) {
const block = ${info}.blocks[#i];
@transition_out(block);
}
`);
}
block.chunks.destroy.push(b `
${info}.block.d(${parent_node ? null : 'detaching'});
${info}.token = null;
${info} = null;
`);
[this.pending, this.then, this.catch].forEach(branch => {
branch.render(branch.block, null, x `#nodes`);
});
}
}
const TRUE = x `true`;
const FALSE = x `false`;
class EventHandlerWrapper {
constructor(node, parent) {
this.node = node;
this.parent = parent;
if (!node.expression) {
this.parent.renderer.add_to_context(node.handler_name.name);
this.parent.renderer.component.partly_hoisted.push(b `
function ${node.handler_name.name}(event) {
@bubble($$self, event);
}
`);
}
}
get_snippet(block) {
const snippet = this.node.expression ? this.node.expression.manipulate(block) : block.renderer.reference(this.node.handler_name);
if (this.node.reassigned) {
block.maintain_context = true;
return x `function () { if (@is_function(${snippet})) ${snippet}.apply(this, arguments); }`;
}
return snippet;
}
render(block, target) {
let snippet = this.get_snippet(block);
if (this.node.modifiers.has('preventDefault'))
snippet = x `@prevent_default(${snippet})`;
if (this.node.modifiers.has('stopPropagation'))
snippet = x `@stop_propagation(${snippet})`;
if (this.node.modifiers.has('self'))
snippet = x `@self(${snippet})`;
const args = [];
const opts = ['passive', 'once', 'capture'].filter(mod => this.node.modifiers.has(mod));
if (opts.length) {
args.push((opts.length === 1 && opts[0] === 'capture')
? TRUE
: x `{ ${opts.map(opt => p `${opt}: true`)} }`);
}
else if (block.renderer.options.dev) {
args.push(FALSE);
}
if (block.renderer.options.dev) {
args.push(this.node.modifiers.has('preventDefault') ? TRUE : FALSE);
args.push(this.node.modifiers.has('stopPropagation') ? TRUE : FALSE);
}
block.event_listeners.push(x `@listen(${target}, "${this.node.name}", ${snippet}, ${args})`);
}
}
function add_event_handlers(block, target, handlers) {
handlers.forEach(handler => add_event_handler(block, target, handler));
}
function add_event_handler(block, target, handler) {
handler.render(block, target);
}
class BodyWrapper extends Wrapper {
constructor(renderer, block, parent, node) {
super(renderer, block, parent, node);
this.handlers = this.node.handlers.map(handler => new EventHandlerWrapper(handler, this));
}
render(block, _parent_node, _parent_nodes) {
add_event_handlers(block, x `@_document.body`, this.handlers);
}
}
function add_to_set(a, b) {
// @ts-ignore
b.forEach(item => {
a.add(item);
});
}
class DebugTagWrapper extends Wrapper {
constructor(renderer, block, parent, node, _strip_whitespace, _next_sibling) {
super(renderer, block, parent, node);
}
render(block, _parent_node, _parent_nodes) {
const { renderer } = this;
const { component } = renderer;
if (!renderer.options.dev)
return;
const { var_lookup } = component;
const start = component.locate(this.node.start + 1);
const end = { line: start.line, column: start.column + 6 };
const loc = { start, end };
const debug = {
type: 'DebuggerStatement',
loc
};
if (this.node.expressions.length === 0) {
// Debug all
block.chunks.create.push(debug);
block.chunks.update.push(debug);
}
else {
const log = {
type: 'Identifier',
name: 'log',
loc
};
const dependencies = new Set();
this.node.expressions.forEach(expression => {
add_to_set(dependencies, expression.dependencies);
});
const contextual_identifiers = this.node.expressions
.filter(e => {
const variable = var_lookup.get(e.node.name);
return !(variable && variable.hoistable);
})
.map(e => e.node.name);
const logged_identifiers = this.node.expressions.map(e => p `${e.node.name}`);
const debug_statements = b `
${contextual_identifiers.map(name => b `const ${name} = ${renderer.reference(name)};`)}
@_console.${log}({ ${logged_identifiers} });
debugger;`;
if (dependencies.size) {
const condition = renderer.dirty(Array.from(dependencies));
block.chunks.update.push(b `
if (${condition}) {
${debug_statements}
}
`);
}
block.chunks.create.push(b `{
${debug_statements}
}`);
}
}
}
class ElseBlockWrapper extends Wrapper {
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.var = null;
this.block = block.child({
comment: create_debugging_comment(node, this.renderer.component),
name: this.renderer.component.get_unique_name(`create_else_block`),
type: 'else'
});
this.fragment = new FragmentWrapper(renderer, this.block, this.node.children, parent, strip_whitespace, next_sibling);
this.is_dynamic = this.block.dependencies.size > 0;
}
}
class EachBlockWrapper extends Wrapper {
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.updates = [];
this.var = { type: 'Identifier', name: 'each' };
this.cannot_use_innerhtml();
this.not_static_content();
const { dependencies } = node.expression;
block.add_dependencies(dependencies);
this.node.contexts.forEach(context => {
renderer.add_to_context(context.key.name, true);
});
this.block = block.child({
comment: create_debugging_comment(this.node, this.renderer.component),
name: renderer.component.get_unique_name('create_each_block'),
type: 'each',
// @ts-ignore todo: probably error
key: node.key,
bindings: new Map(block.bindings)
});
// TODO this seems messy
this.block.has_animation = this.node.has_animation;
this.index_name = this.node.index
? { type: 'Identifier', name: this.node.index }
: renderer.component.get_unique_name(`${this.node.context}_index`);
const fixed_length = node.expression.node.type === 'ArrayExpression' &&
node.expression.node.elements.every(element => element.type !== 'SpreadElement')
? node.expression.node.elements.length
: null;
// hack the sourcemap, so that if data is missing the bug
// is easy to find
let c = this.node.start + 2;
while (renderer.component.source[c] !== 'e')
c += 1;
const start = renderer.component.locate(c);
const end = { line: start.line, column: start.column + 4 };
const length = {
type: 'Identifier',
name: 'length',
loc: { start, end }
};
const each_block_value = renderer.component.get_unique_name(`${this.var.name}_value`);
const iterations = block.get_unique_name(`${this.var.name}_blocks`);
renderer.add_to_context(each_block_value.name, true);
renderer.add_to_context(this.index_name.name, true);
this.vars = {
create_each_block: this.block.name,
each_block_value,
get_each_context: renderer.component.get_unique_name(`get_${this.var.name}_context`),
iterations,
// optimisation for array literal
fixed_length,
data_length: fixed_length === null ? x `${each_block_value}.${length}` : fixed_length,
view_length: fixed_length === null ? x `${iterations}.length` : fixed_length
};
const store = node.expression.node.type === 'Identifier' &&
node.expression.node.name[0] === '$'
? node.expression.node.name.slice(1)
: null;
node.contexts.forEach(prop => {
this.block.bindings.set(prop.key.name, {
object: this.vars.each_block_value,
property: this.index_name,
modifier: prop.modifier,
snippet: prop.modifier(x `${this.vars.each_block_value}[${this.index_name}]`),
store,
tail: prop.modifier(x `[${this.index_name}]`)
});
});
if (this.node.index) {
this.block.get_unique_name(this.node.index); // this prevents name collisions (#1254)
}
renderer.blocks.push(this.block);
this.fragment = new FragmentWrapper(renderer, this.block, node.children, this, strip_whitespace, next_sibling);
if (this.node.else) {
this.else = new ElseBlockWrapper(renderer, block, this, this.node.else, strip_whitespace, next_sibling);
renderer.blocks.push(this.else.block);
if (this.else.is_dynamic) {
this.block.add_dependencies(this.else.block.dependencies);
}
}
block.add_dependencies(this.block.dependencies);
if (this.block.has_outros || (this.else && this.else.block.has_outros)) {
block.add_outro();
}
}
render(block, parent_node, parent_nodes) {
if (this.fragment.nodes.length === 0)
return;
const { renderer } = this;
const { component } = renderer;
const needs_anchor = this.next
? !this.next.is_dom_node() :
!parent_node || !this.parent.is_dom_node();
this.context_props = this.node.contexts.map(prop => b `child_ctx[${renderer.context_lookup.get(prop.key.name).index}] = ${prop.modifier(x `list[i]`)};`);
if (this.node.has_binding)
this.context_props.push(b `child_ctx[${renderer.context_lookup.get(this.vars.each_block_value.name).index}] = list;`);
if (this.node.has_binding || this.node.has_index_binding || this.node.index)
this.context_props.push(b `child_ctx[${renderer.context_lookup.get(this.index_name.name).index}] = i;`);
const snippet = this.node.expression.manipulate(block);
block.chunks.init.push(b `let ${this.vars.each_block_value} = ${snippet};`);
if (this.renderer.options.dev) {
block.chunks.init.push(b `@validate_each_argument(${this.vars.each_block_value});`);
}
// TODO which is better — Object.create(array) or array.slice()?
renderer.blocks.push(b `
function ${this.vars.get_each_context}(#ctx, list, i) {
const child_ctx = #ctx.slice();
${this.context_props}
return child_ctx;
}
`);
const initial_anchor_node = { type: 'Identifier', name: parent_node ? 'null' : '#anchor' };
const initial_mount_node = parent_node || { type: 'Identifier', name: '#target' };
const update_anchor_node = needs_anchor
? block.get_unique_name(`${this.var.name}_anchor`)
: (this.next && this.next.var) || { type: 'Identifier', name: 'null' };
const update_mount_node = this.get_update_mount_node(update_anchor_node);
const args = {
block,
parent_node,
parent_nodes,
snippet,
initial_anchor_node,
initial_mount_node,
update_anchor_node,
update_mount_node
};
const all_dependencies = new Set(this.block.dependencies); // TODO should be dynamic deps only
this.node.expression.dynamic_dependencies().forEach((dependency) => {
all_dependencies.add(dependency);
});
this.dependencies = all_dependencies;
if (this.node.key) {
this.render_keyed(args);
}
else {
this.render_unkeyed(args);
}
if (this.block.has_intro_method || this.block.has_outro_method) {
block.chunks.intro.push(b `
for (let #i = 0; #i < ${this.vars.data_length}; #i += 1) {
@transition_in(${this.vars.iterations}[#i]);
}
`);
}
if (needs_anchor) {
block.add_element(update_anchor_node, x `@empty()`, parent_nodes && x `@empty()`, parent_node);
}
if (this.else) {
const each_block_else = component.get_unique_name(`${this.var.name}_else`);
block.chunks.init.push(b `let ${each_block_else} = null;`);
// TODO neaten this up... will end up with an empty line in the block
block.chunks.init.push(b `
if (!${this.vars.data_length}) {
${each_block_else} = ${this.else.block.name}(#ctx);
}
`);
block.chunks.create.push(b `
if (${each_block_else}) {
${each_block_else}.c();
}
`);
if (this.renderer.options.hydratable) {
block.chunks.claim.push(b `
if (${each_block_else}) {
${each_block_else}.l(${parent_nodes});
}
`);
}
block.chunks.mount.push(b `
if (${each_block_else}) {
${each_block_else}.m(${initial_mount_node}, ${initial_anchor_node});
}
`);
const has_transitions = !!(this.else.block.has_intro_method || this.else.block.has_outro_method);
const destroy_block_else = this.else.block.has_outro_method
? b `
@group_outros();
@transition_out(${each_block_else}, 1, 1, () => {
${each_block_else} = null;
});
@check_outros();`
: b `
${each_block_else}.d(1);
${each_block_else} = null;`;
if (this.else.block.has_update_method) {
this.updates.push(b `
if (!${this.vars.data_length} && ${each_block_else}) {
${each_block_else}.p(#ctx, #dirty);
} else if (!${this.vars.data_length}) {
${each_block_else} = ${this.else.block.name}(#ctx);
${each_block_else}.c();
${has_transitions && b `@transition_in(${each_block_else}, 1);`}
${each_block_else}.m(${update_mount_node}, ${update_anchor_node});
} else if (${each_block_else}) {
${destroy_block_else};
}
`);
}
else {
this.updates.push(b `
if (${this.vars.data_length}) {
if (${each_block_else}) {
${destroy_block_else};
}
} else if (!${each_block_else}) {
${each_block_else} = ${this.else.block.name}(#ctx);
${each_block_else}.c();
${has_transitions && b `@transition_in(${each_block_else}, 1);`}
${each_block_else}.m(${update_mount_node}, ${update_anchor_node});
}
`);
}
block.chunks.destroy.push(b `
if (${each_block_else}) ${each_block_else}.d(${parent_node ? '' : 'detaching'});
`);
}
if (this.updates.length) {
block.chunks.update.push(b `
if (${block.renderer.dirty(Array.from(all_dependencies))}) {
${this.updates}
}
`);
}
this.fragment.render(this.block, null, x `#nodes`);
if (this.else) {
this.else.fragment.render(this.else.block, null, x `#nodes`);
}
}
render_keyed({ block, parent_node, parent_nodes, snippet, initial_anchor_node, initial_mount_node, update_anchor_node, update_mount_node }) {
const { create_each_block, iterations, data_length, view_length } = this.vars;
const get_key = block.get_unique_name('get_key');
const lookup = block.get_unique_name(`${this.var.name}_lookup`);
block.add_variable(iterations, x `[]`);
block.add_variable(lookup, x `new @_Map()`);
if (this.fragment.nodes[0].is_dom_node()) {
this.block.first = this.fragment.nodes[0].var;
}
else {
this.block.first = this.block.get_unique_name('first');
this.block.add_element(this.block.first, x `@empty()`, parent_nodes && x `@empty()`, null);
}
block.chunks.init.push(b `
const ${get_key} = #ctx => ${this.node.key.manipulate(block)};
${this.renderer.options.dev && b `@validate_each_keys(#ctx, ${this.vars.each_block_value}, ${this.vars.get_each_context}, ${get_key});`}
for (let #i = 0; #i < ${data_length}; #i += 1) {
let child_ctx = ${this.vars.get_each_context}(#ctx, ${this.vars.each_block_value}, #i);
let key = ${get_key}(child_ctx);
${lookup}.set(key, ${iterations}[#i] = ${create_each_block}(key, child_ctx));
}
`);
block.chunks.create.push(b `
for (let #i = 0; #i < ${view_length}; #i += 1) {
${iterations}[#i].c();
}
`);
if (parent_nodes && this.renderer.options.hydratable) {
block.chunks.claim.push(b `
for (let #i = 0; #i < ${view_length}; #i += 1) {
${iterations}[#i].l(${parent_nodes});
}
`);
}
block.chunks.mount.push(b `
for (let #i = 0; #i < ${view_length}; #i += 1) {
${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node});
}
`);
const dynamic = this.block.has_update_method;
const destroy = this.node.has_animation
? (this.block.has_outros
? `@fix_and_outro_and_destroy_block`
: `@fix_and_destroy_block`)
: this.block.has_outros
? `@outro_and_destroy_block`
: `@destroy_block`;
if (this.dependencies.size) {
this.updates.push(b `
const ${this.vars.each_block_value} = ${snippet};
${this.renderer.options.dev && b `@validate_each_argument(${this.vars.each_block_value});`}
${this.block.has_outros && b `@group_outros();`}
${this.node.has_animation && b `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].r();`}
${this.renderer.options.dev && b `@validate_each_keys(#ctx, ${this.vars.each_block_value}, ${this.vars.get_each_context}, ${get_key});`}
${iterations} = @update_keyed_each(${iterations}, #dirty, ${get_key}, ${dynamic ? 1 : 0}, #ctx, ${this.vars.each_block_value}, ${lookup}, ${update_mount_node}, ${destroy}, ${create_each_block}, ${update_anchor_node}, ${this.vars.get_each_context});
${this.node.has_animation && b `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].a();`}
${this.block.has_outros && b `@check_outros();`}
`);
}
if (this.block.has_outros) {
block.chunks.outro.push(b `
for (let #i = 0; #i < ${view_length}; #i += 1) {
@transition_out(${iterations}[#i]);
}
`);
}
block.chunks.destroy.push(b `
for (let #i = 0; #i < ${view_length}; #i += 1) {
${iterations}[#i].d(${parent_node ? null : 'detaching'});
}
`);
}
render_unkeyed({ block, parent_nodes, snippet, initial_anchor_node, initial_mount_node, update_anchor_node, update_mount_node }) {
const { create_each_block, iterations, fixed_length, data_length, view_length } = this.vars;
block.chunks.init.push(b `
let ${iterations} = [];
for (let #i = 0; #i < ${data_length}; #i += 1) {
${iterations}[#i] = ${create_each_block}(${this.vars.get_each_context}(#ctx, ${this.vars.each_block_value}, #i));
}
`);
block.chunks.create.push(b `
for (let #i = 0; #i < ${view_length}; #i += 1) {
${iterations}[#i].c();
}
`);
if (parent_nodes && this.renderer.options.hydratable) {
block.chunks.claim.push(b `
for (let #i = 0; #i < ${view_length}; #i += 1) {
${iterations}[#i].l(${parent_nodes});
}
`);
}
block.chunks.mount.push(b `
for (let #i = 0; #i < ${view_length}; #i += 1) {
${iterations}[#i].m(${initial_mount_node}, ${initial_anchor_node});
}
`);
if (this.dependencies.size) {
const has_transitions = !!(this.block.has_intro_method || this.block.has_outro_method);
const for_loop_body = this.block.has_update_method
? b `
if (${iterations}[#i]) {
${iterations}[#i].p(child_ctx, #dirty);
${has_transitions && b `@transition_in(${this.vars.iterations}[#i], 1);`}
} else {
${iterations}[#i] = ${create_each_block}(child_ctx);
${iterations}[#i].c();
${has_transitions && b `@transition_in(${this.vars.iterations}[#i], 1);`}
${iterations}[#i].m(${update_mount_node}, ${update_anchor_node});
}
`
: has_transitions
? b `
if (${iterations}[#i]) {
@transition_in(${this.vars.iterations}[#i], 1);
} else {
${iterations}[#i] = ${create_each_block}(child_ctx);
${iterations}[#i].c();
@transition_in(${this.vars.iterations}[#i], 1);
${iterations}[#i].m(${update_mount_node}, ${update_anchor_node});
}
`
: b `
if (!${iterations}[#i]) {
${iterations}[#i] = ${create_each_block}(child_ctx);
${iterations}[#i].c();
${iterations}[#i].m(${update_mount_node}, ${update_anchor_node});
}
`;
const start = this.block.has_update_method ? 0 : `#old_length`;
let remove_old_blocks;
if (this.block.has_outros) {
const out = block.get_unique_name('out');
block.chunks.init.push(b `
const ${out} = i => @transition_out(${iterations}[i], 1, 1, () => {
${iterations}[i] = null;
});
`);
remove_old_blocks = b `
@group_outros();
for (#i = ${data_length}; #i < ${view_length}; #i += 1) {
${out}(#i);
}
@check_outros();
`;
}
else {
remove_old_blocks = b `
for (${this.block.has_update_method ? null : x `#i = ${data_length}`}; #i < ${this.block.has_update_method ? view_length : '#old_length'}; #i += 1) {
${iterations}[#i].d(1);
}
${!fixed_length && b `${view_length} = ${data_length};`}
`;
}
// We declare `i` as block scoped here, as the `remove_old_blocks` code
// may rely on continuing where this iteration stopped.
const update = b `
${!this.block.has_update_method && b `const #old_length = ${this.vars.each_block_value}.length;`}
${this.vars.each_block_value} = ${snippet};
${this.renderer.options.dev && b `@validate_each_argument(${this.vars.each_block_value});`}
let #i;
for (#i = ${start}; #i < ${data_length}; #i += 1) {
const child_ctx = ${this.vars.get_each_context}(#ctx, ${this.vars.each_block_value}, #i);
${for_loop_body}
}
${remove_old_blocks}
`;
this.updates.push(update);
}
if (this.block.has_outros) {
block.chunks.outro.push(b `
${iterations} = ${iterations}.filter(@_Boolean);
for (let #i = 0; #i < ${view_length}; #i += 1) {
@transition_out(${iterations}[#i]);
}
`);
}
block.chunks.destroy.push(b `@destroy_each(${iterations}, detaching);`);
}
}
function string_literal(data) {
return {
type: 'Literal',
value: data
};
}
const escaped = {
'"': '&quot;',
"'": '&#39;',
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
};
function escape_html(html) {
return String(html).replace(/["'&<>]/g, match => escaped[match]);
}
function escape_template(str) {
return str.replace(/(\${|`|\\)/g, '\\$1');
}
class TextWrapper extends Wrapper {
constructor(renderer, block, parent, node, data) {
super(renderer, block, parent, node);
this.skip = this.node.should_skip();
this.data = data;
this.var = (this.skip ? null : x `t`);
}
use_space() {
if (this.renderer.component.component_options.preserveWhitespace)
return false;
if (/[\S\u00A0]/.test(this.data))
return false;
let node = this.parent && this.parent.node;
while (node) {
if (node.type === 'Element' && node.name === 'pre') {
return false;
}
node = node.parent;
}
return true;
}
render(block, parent_node, parent_nodes) {
if (this.skip)
return;
const use_space = this.use_space();
block.add_element(this.var, use_space ? x `@space()` : x `@text("${this.data}")`, parent_nodes && (use_space ? x `@claim_space(${parent_nodes})` : x `@claim_text(${parent_nodes}, "${this.data}")`), parent_node);
}
}
const svg_attributes = 'accent-height accumulate additive alignment-baseline allowReorder alphabetic amplitude arabic-form ascent attributeName attributeType autoReverse azimuth baseFrequency baseline-shift baseProfile bbox begin bias by calcMode cap-height class clip clipPathUnits clip-path clip-rule color color-interpolation color-interpolation-filters color-profile color-rendering contentScriptType contentStyleType cursor cx cy d decelerate descent diffuseConstant direction display divisor dominant-baseline dur dx dy edgeMode elevation enable-background end exponent externalResourcesRequired fill fill-opacity fill-rule filter filterRes filterUnits flood-color flood-opacity font-family font-size font-size-adjust font-stretch font-style font-variant font-weight format from fr fx fy g1 g2 glyph-name glyph-orientation-horizontal glyph-orientation-vertical glyphRef gradientTransform gradientUnits hanging height href horiz-adv-x horiz-origin-x id ideographic image-rendering in in2 intercept k k1 k2 k3 k4 kernelMatrix kernelUnitLength kerning keyPoints keySplines keyTimes lang lengthAdjust letter-spacing lighting-color limitingConeAngle local marker-end marker-mid marker-start markerHeight markerUnits markerWidth mask maskContentUnits maskUnits mathematical max media method min mode name numOctaves offset onabort onactivate onbegin onclick onend onerror onfocusin onfocusout onload onmousedown onmousemove onmouseout onmouseover onmouseup onrepeat onresize onscroll onunload opacity operator order orient orientation origin overflow overline-position overline-thickness panose-1 paint-order pathLength patternContentUnits patternTransform patternUnits pointer-events points pointsAtX pointsAtY pointsAtZ preserveAlpha preserveAspectRatio primitiveUnits r radius refX refY rendering-intent repeatCount repeatDur requiredExtensions requiredFeatures restart result rotate rx ry scale seed shape-rendering slope spacing specularConstant specularExponent speed spreadMethod startOffset stdDeviation stemh stemv stitchTiles stop-color stop-opacity strikethrough-position strikethrough-thickness string stroke stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity stroke-width style surfaceScale systemLanguage tabindex tableValues target targetX targetY text-anchor text-decoration text-rendering textLength to transform type u1 u2 underline-position underline-thickness unicode unicode-bidi unicode-range units-per-em v-alphabetic v-hanging v-ideographic v-mathematical values version vert-adv-y vert-origin-x vert-origin-y viewBox viewTarget visibility width widths word-spacing writing-mode x x-height x1 x2 xChannelSelector xlink:actuate xlink:arcrole xlink:href xlink:role xlink:show xlink:title xlink:type xml:base xml:lang xml:space y y1 y2 yChannelSelector z zoomAndPan'.split(' ');
const svg_attribute_lookup = new Map();
svg_attributes.forEach(name => {
svg_attribute_lookup.set(name.toLowerCase(), name);
});
function fix_attribute_casing(name) {
name = name.toLowerCase();
return svg_attribute_lookup.get(name) || name;
}
const html = 'http://www.w3.org/1999/xhtml';
const mathml = 'http://www.w3.org/1998/Math/MathML';
const svg = 'http://www.w3.org/2000/svg';
const xlink = 'http://www.w3.org/1999/xlink';
const xml = 'http://www.w3.org/XML/1998/namespace';
const xmlns = 'http://www.w3.org/2000/xmlns';
const valid_namespaces = [
'html',
'mathml',
'svg',
'xlink',
'xml',
'xmlns',
html,
mathml,
svg,
xlink,
xml,
xmlns,
];
const namespaces = { html, mathml, svg, xlink, xml, xmlns };
function handle_select_value_binding(attr, dependencies) {
const { parent } = attr;
if (parent.node.name === "select") {
parent.select_binding_dependencies = dependencies;
dependencies.forEach((prop) => {
parent.renderer.component.indirect_dependencies.set(prop, new Set());
});
}
}
class BaseAttributeWrapper {
constructor(parent, block, node) {
this.node = node;
this.parent = parent;
if (node.dependencies.size > 0) {
parent.cannot_use_innerhtml();
parent.not_static_content();
block.add_dependencies(node.dependencies);
}
}
render(_block) { }
}
class AttributeWrapper extends BaseAttributeWrapper {
constructor(parent, block, node) {
super(parent, block, node);
if (node.dependencies.size > 0) {
// special case — <option value={foo}> — see below
if (this.parent.node.name === 'option' && node.name === 'value') {
let select = this.parent;
while (select && (select.node.type !== 'Element' || select.node.name !== 'select'))
// @ts-ignore todo: doublecheck this, but looks to be correct
select = select.parent;
if (select && select.select_binding_dependencies) {
select.select_binding_dependencies.forEach(prop => {
this.node.dependencies.forEach((dependency) => {
this.parent.renderer.component.indirect_dependencies.get(prop).add(dependency);
});
});
}
}
if (node.name === 'value') {
handle_select_value_binding(this, node.dependencies);
}
}
this.name = fix_attribute_casing(this.node.name);
this.metadata = this.get_metadata();
this.is_indirectly_bound_value = is_indirectly_bound_value(this);
this.property_name = this.is_indirectly_bound_value
? '__value'
: this.metadata && this.metadata.property_name;
this.is_src = this.name === 'src'; // TODO retire this exception in favour of https://github.com/sveltejs/svelte/issues/3750
this.is_select_value_attribute = this.name === 'value' && this.parent.node.name === 'select';
this.is_input_value = this.name === 'value' && this.parent.node.name === 'input';
this.should_cache = should_cache(this);
}
render(block) {
const element = this.parent;
const { name, property_name, should_cache, is_indirectly_bound_value } = this;
// xlink is a special case... we could maybe extend this to generic
// namespaced attributes but I'm not sure that's applicable in
// HTML5?
const method = /-/.test(element.node.name)
? '@set_custom_element_data'
: name.slice(0, 6) === 'xlink:'
? '@xlink_attr'
: '@attr';
const is_legacy_input_type = element.renderer.component.compile_options.legacy && name === 'type' && this.parent.node.name === 'input';
const dependencies = this.get_dependencies();
const value = this.get_value(block);
let updater;
const init = this.get_init(block, value);
if (is_legacy_input_type) {
block.chunks.hydrate.push(b `@set_input_type(${element.var}, ${init});`);
updater = b `@set_input_type(${element.var}, ${should_cache ? this.last : value});`;
}
else if (this.is_select_value_attribute) {
// annoying special case
const is_multiple_select = element.node.get_static_attribute_value('multiple');
if (is_multiple_select) {
updater = b `@select_options(${element.var}, ${value});`;
}
else {
updater = b `@select_option(${element.var}, ${value});`;
}
block.chunks.mount.push(b `
${updater}
`);
}
else if (this.is_src) {
block.chunks.hydrate.push(b `if (${element.var}.src !== ${init}) ${method}(${element.var}, "${name}", ${this.last});`);
updater = b `${method}(${element.var}, "${name}", ${should_cache ? this.last : value});`;
}
else if (property_name) {
block.chunks.hydrate.push(b `${element.var}.${property_name} = ${init};`);
updater = block.renderer.options.dev
? b `@prop_dev(${element.var}, "${property_name}", ${should_cache ? this.last : value});`
: b `${element.var}.${property_name} = ${should_cache ? this.last : value};`;
}
else {
block.chunks.hydrate.push(b `${method}(${element.var}, "${name}", ${init});`);
updater = b `${method}(${element.var}, "${name}", ${should_cache ? this.last : value});`;
}
if (is_indirectly_bound_value) {
const update_value = b `${element.var}.value = ${element.var}.__value;`;
block.chunks.hydrate.push(update_value);
updater = b `
${updater}
${update_value};
`;
}
if (dependencies.length > 0) {
const condition = this.get_dom_update_conditions(block, block.renderer.dirty(dependencies));
block.chunks.update.push(b `
if (${condition}) {
${updater}
}`);
}
// special case autofocus. has to be handled in a bit of a weird way
if (this.node.is_true && name === 'autofocus') {
block.autofocus = element.var;
}
}
get_init(block, value) {
this.last = this.should_cache && block.get_unique_name(`${this.parent.var.name}_${this.name.replace(/[^a-zA-Z_$]/g, '_')}_value`);
if (this.should_cache)
block.add_variable(this.last);
return this.should_cache ? x `${this.last} = ${value}` : value;
}
get_dom_update_conditions(block, dependency_condition) {
const { property_name, should_cache, last } = this;
const element = this.parent;
const value = this.get_value(block);
let condition = dependency_condition;
if (should_cache) {
condition = this.is_src
? x `${condition} && (${element.var}.src !== (${last} = ${value}))`
: x `${condition} && (${last} !== (${last} = ${value}))`;
}
if (this.is_input_value) {
const type = element.node.get_static_attribute_value('type');
if (type === null || type === "" || type === "text" || type === "email" || type === "password") {
condition = x `${condition} && ${element.var}.${property_name} !== ${should_cache ? last : value}`;
}
}
if (block.has_outros) {
condition = x `!#current || ${condition}`;
}
return condition;
}
get_dependencies() {
const node_dependencies = this.node.get_dependencies();
const dependencies = new Set(node_dependencies);
node_dependencies.forEach((prop) => {
const indirect_dependencies = this.parent.renderer.component.indirect_dependencies.get(prop);
if (indirect_dependencies) {
indirect_dependencies.forEach(indirect_dependency => {
dependencies.add(indirect_dependency);
});
}
});
return Array.from(dependencies);
}
get_metadata() {
if (this.parent.node.namespace)
return null;
const metadata = attribute_lookup[this.name];
if (metadata && metadata.applies_to && !metadata.applies_to.includes(this.parent.node.name))
return null;
return metadata;
}
get_value(block) {
if (this.node.is_true) {
if (this.metadata && boolean_attribute.has(this.metadata.property_name.toLowerCase())) {
return x `true`;
}
return x `""`;
}
if (this.node.chunks.length === 0)
return x `""`;
// TODO some of this code is repeated in Tag.ts — would be good to
// DRY it out if that's possible without introducing crazy indirection
if (this.node.chunks.length === 1) {
return this.node.chunks[0].type === 'Text'
? string_literal(this.node.chunks[0].data)
: this.node.chunks[0].manipulate(block);
}
let value = this.node.name === 'class'
? this.get_class_name_text(block)
: this.render_chunks(block).reduce((lhs, rhs) => x `${lhs} + ${rhs}`);
// '{foo} {bar}' — treat as string concatenation
if (this.node.chunks[0].type !== 'Text') {
value = x `"" + ${value}`;
}
return value;
}
get_class_name_text(block) {
const scoped_css = this.node.chunks.some((chunk) => chunk.synthetic);
const rendered = this.render_chunks(block);
if (scoped_css && rendered.length === 2) {
// we have a situation like class={possiblyUndefined}
rendered[0] = x `@null_to_empty(${rendered[0]})`;
}
return rendered.reduce((lhs, rhs) => x `${lhs} + ${rhs}`);
}
render_chunks(block) {
return this.node.chunks.map((chunk) => {
if (chunk.type === 'Text') {
return string_literal(chunk.data);
}
return chunk.manipulate(block);
});
}
stringify() {
if (this.node.is_true)
return '';
const value = this.node.chunks;
if (value.length === 0)
return `=""`;
return `="${value.map(chunk => {
return chunk.type === 'Text'
? chunk.data.replace(/"/g, '\\"')
: `\${${chunk.manipulate()}}`;
}).join('')}"`;
}
}
// source: https://html.spec.whatwg.org/multipage/indices.html
const attribute_lookup = {
allowfullscreen: { property_name: 'allowFullscreen', applies_to: ['iframe'] },
allowpaymentrequest: { property_name: 'allowPaymentRequest', applies_to: ['iframe'] },
async: { applies_to: ['script'] },
autofocus: { applies_to: ['button', 'input', 'keygen', 'select', 'textarea'] },
autoplay: { applies_to: ['audio', 'video'] },
checked: { applies_to: ['input'] },
controls: { applies_to: ['audio', 'video'] },
default: { applies_to: ['track'] },
defer: { applies_to: ['script'] },
disabled: {
applies_to: [
'button',
'fieldset',
'input',
'keygen',
'optgroup',
'option',
'select',
'textarea',
],
},
formnovalidate: { property_name: 'formNoValidate', applies_to: ['button', 'input'] },
hidden: {},
indeterminate: { applies_to: ['input'] },
ismap: { property_name: 'isMap', applies_to: ['img'] },
loop: { applies_to: ['audio', 'bgsound', 'video'] },
multiple: { applies_to: ['input', 'select'] },
muted: { applies_to: ['audio', 'video'] },
nomodule: { property_name: 'noModule', applies_to: ['script'] },
novalidate: { property_name: 'noValidate', applies_to: ['form'] },
open: { applies_to: ['details', 'dialog'] },
playsinline: { property_name: 'playsInline', applies_to: ['video'] },
readonly: { property_name: 'readOnly', applies_to: ['input', 'textarea'] },
required: { applies_to: ['input', 'select', 'textarea'] },
reversed: { applies_to: ['ol'] },
selected: { applies_to: ['option'] },
value: {
applies_to: [
'button',
'option',
'input',
'li',
'meter',
'progress',
'param',
'select',
'textarea',
],
},
};
Object.keys(attribute_lookup).forEach(name => {
const metadata = attribute_lookup[name];
if (!metadata.property_name)
metadata.property_name = name;
});
// source: https://html.spec.whatwg.org/multipage/indices.html
const boolean_attribute = new Set([
'allowfullscreen',
'allowpaymentrequest',
'async',
'autofocus',
'autoplay',
'checked',
'controls',
'default',
'defer',
'disabled',
'formnovalidate',
'hidden',
'ismap',
'itemscope',
'loop',
'multiple',
'muted',
'nomodule',
'novalidate',
'open',
'playsinline',
'readonly',
'required',
'reversed',
'selected'
]);
function should_cache(attribute) {
return attribute.is_src || attribute.node.should_cache();
}
function is_indirectly_bound_value(attribute) {
const element = attribute.parent;
return attribute.name === 'value' &&
(element.node.name === 'option' || // TODO check it's actually bound
(element.node.name === 'input' &&
element.node.bindings.some((binding) => /checked|group/.test(binding.name))));
}
class StyleAttributeWrapper extends AttributeWrapper {
render(block) {
const style_props = optimize_style(this.node.chunks);
if (!style_props)
return super.render(block);
style_props.forEach((prop) => {
let value;
if (is_dynamic(prop.value)) {
const prop_dependencies = new Set();
value = prop.value
.map(chunk => {
if (chunk.type === 'Text') {
return string_literal(chunk.data);
}
else {
add_to_set(prop_dependencies, chunk.dynamic_dependencies());
return chunk.manipulate(block);
}
})
.reduce((lhs, rhs) => x `${lhs} + ${rhs}`);
// TODO is this necessary? style.setProperty always treats value as string, no?
// if (prop.value.length === 1 || prop.value[0].type !== 'Text') {
// value = x`"" + ${value}`;
// }
if (prop_dependencies.size) {
let condition = block.renderer.dirty(Array.from(prop_dependencies));
if (block.has_outros) {
condition = x `!#current || ${condition}`;
}
const update = b `
if (${condition}) {
@set_style(${this.parent.var}, "${prop.key}", ${value}, ${prop.important ? 1 : null});
}`;
block.chunks.update.push(update);
}
}
else {
value = string_literal(prop.value[0].data);
}
block.chunks.hydrate.push(b `@set_style(${this.parent.var}, "${prop.key}", ${value}, ${prop.important ? 1 : null});`);
});
}
}
function optimize_style(value) {
const props = [];
let chunks = value.slice();
while (chunks.length) {
const chunk = chunks[0];
if (chunk.type !== 'Text')
return null;
const key_match = /^\s*([\w-]+):\s*/.exec(chunk.data);
if (!key_match)
return null;
const key = key_match[1];
const offset = key_match.index + key_match[0].length;
const remaining_data = chunk.data.slice(offset);
if (remaining_data) {
chunks[0] = {
start: chunk.start + offset,
end: chunk.end,
type: 'Text',
data: remaining_data
};
}
else {
chunks.shift();
}
const result = get_style_value(chunks);
props.push({ key, value: result.value, important: result.important });
chunks = result.chunks;
}
return props;
}
function get_style_value(chunks) {
const value = [];
let in_url = false;
let quote_mark = null;
let escaped = false;
let closed = false;
while (chunks.length && !closed) {
const chunk = chunks.shift();
if (chunk.type === 'Text') {
let c = 0;
while (c < chunk.data.length) {
const char = chunk.data[c];
if (escaped) {
escaped = false;
}
else if (char === '\\') {
escaped = true;
}
else if (char === quote_mark) {
quote_mark = null;
}
else if (char === '"' || char === "'") {
quote_mark = char;
}
else if (char === ')' && in_url) {
in_url = false;
}
else if (char === 'u' && chunk.data.slice(c, c + 4) === 'url(') {
in_url = true;
}
else if (char === ';' && !in_url && !quote_mark) {
closed = true;
break;
}
c += 1;
}
if (c > 0) {
value.push({
type: 'Text',
start: chunk.start,
end: chunk.start + c,
data: chunk.data.slice(0, c)
});
}
while (/[;\s]/.test(chunk.data[c]))
c += 1;
const remaining_data = chunk.data.slice(c);
if (remaining_data) {
chunks.unshift({
start: chunk.start + c,
end: chunk.end,
type: 'Text',
data: remaining_data
});
break;
}
}
else {
value.push(chunk);
}
}
let important = false;
const last_chunk = value[value.length - 1];
if (last_chunk && last_chunk.type === 'Text' && /\s*!important\s*$/.test(last_chunk.data)) {
important = true;
last_chunk.data = last_chunk.data.replace(/\s*!important\s*$/, '');
if (!last_chunk.data)
value.pop();
}
return {
chunks,
value,
important
};
}
function is_dynamic(value) {
return value.length > 1 || value[0].type !== 'Text';
}
class SpreadAttributeWrapper extends BaseAttributeWrapper {
}
function get_object(node) {
while (node.type === 'MemberExpression')
node = node.object;
return node;
}
function replace_object(node, replacement) {
if (node.type === 'Identifier')
return replacement;
const ancestor = node;
let parent;
while (node.type === 'MemberExpression') {
parent = node;
node = node.object;
}
parent.object = replacement;
return ancestor;
}
function flatten_reference(node) {
const nodes = [];
const parts = [];
while (node.type === 'MemberExpression') {
nodes.unshift(node.property);
if (!node.computed) {
parts.unshift(node.property.name);
}
else {
const computed_property = to_string$1(node.property);
if (computed_property) {
parts.unshift(`[${computed_property}]`);
}
}
node = node.object;
}
const name = node.type === 'Identifier'
? node.name
: node.type === 'ThisExpression' ? 'this' : null;
nodes.unshift(node);
parts.unshift(name);
return { name, nodes, parts };
}
function to_string$1(node) {
switch (node.type) {
case 'Literal':
return String(node.value);
case 'Identifier':
return node.name;
}
}
function mark_each_block_bindings(parent, binding) {
// we need to ensure that the each block creates a context including
// the list and the index, if they're not otherwise referenced
binding.expression.references.forEach(name => {
const each_block = parent.node.scope.get_owner(name);
if (each_block) {
each_block.has_binding = true;
}
});
if (binding.name === "group") {
// for `<input bind:group={} >`, we make sure that all the each blocks creates context with `index`
for (const name of binding.expression.contextual_dependencies) {
const each_block = parent.node.scope.get_owner(name);
each_block.has_index_binding = true;
}
}
}
class BindingWrapper {
constructor(block, node, parent) {
this.node = node;
this.parent = parent;
const { dependencies } = this.node.expression;
block.add_dependencies(dependencies);
// TODO does this also apply to e.g. `<input type='checkbox' bind:group='foo'>`?
handle_select_value_binding(this, dependencies);
if (node.is_contextual) {
mark_each_block_bindings(this.parent, this.node);
}
this.object = get_object(this.node.expression.node).name;
// view to model
this.handler = get_event_handler(this, parent.renderer, block, this.object, this.node.raw_expression);
this.snippet = this.node.expression.manipulate(block);
this.is_readonly = this.node.is_readonly;
this.needs_lock = this.node.name === 'currentTime'; // TODO others?
}
get_dependencies() {
const dependencies = new Set(this.node.expression.dependencies);
this.node.expression.dependencies.forEach((prop) => {
const indirect_dependencies = this.parent.renderer.component.indirect_dependencies.get(prop);
if (indirect_dependencies) {
indirect_dependencies.forEach(indirect_dependency => {
dependencies.add(indirect_dependency);
});
}
});
return dependencies;
}
is_readonly_media_attribute() {
return this.node.is_readonly_media_attribute();
}
render(block, lock) {
if (this.is_readonly)
return;
const { parent } = this;
const update_conditions = this.needs_lock ? [x `!${lock}`] : [];
const mount_conditions = [];
const dependency_array = Array.from(this.get_dependencies());
if (dependency_array.length > 0) {
update_conditions.push(block.renderer.dirty(dependency_array));
}
if (parent.node.name === "input") {
const type = parent.node.get_static_attribute_value("type");
if (type === null ||
type === "" ||
type === "text" ||
type === "email" ||
type === "password") {
update_conditions.push(x `${parent.var}.${this.node.name} !== ${this.snippet}`);
}
else if (type === "number") {
update_conditions.push(x `@to_number(${parent.var}.${this.node.name}) !== ${this.snippet}`);
}
}
// model to view
let update_dom = get_dom_updater(parent, this);
let mount_dom = update_dom;
// special cases
switch (this.node.name) {
case 'group':
{
const { binding_group, is_context, contexts, index } = get_binding_group(parent.renderer, this.node, block);
block.renderer.add_to_context(`$$binding_groups`);
if (is_context) {
if (contexts.length > 1) {
let binding_group = x `${block.renderer.reference('$$binding_groups')}[${index}]`;
for (const name of contexts.slice(0, -1)) {
binding_group = x `${binding_group}[${block.renderer.reference(name)}]`;
block.chunks.init.push(b `${binding_group} = ${binding_group} || [];`);
}
}
block.chunks.init.push(b `${binding_group(true)} = [];`);
}
block.chunks.hydrate.push(b `${binding_group(true)}.push(${parent.var});`);
block.chunks.destroy.push(b `${binding_group(true)}.splice(${binding_group(true)}.indexOf(${parent.var}), 1);`);
break;
}
case 'textContent':
update_conditions.push(x `${this.snippet} !== ${parent.var}.textContent`);
mount_conditions.push(x `${this.snippet} !== void 0`);
break;
case 'innerHTML':
update_conditions.push(x `${this.snippet} !== ${parent.var}.innerHTML`);
mount_conditions.push(x `${this.snippet} !== void 0`);
break;
case 'currentTime':
update_conditions.push(x `!@_isNaN(${this.snippet})`);
mount_dom = null;
break;
case 'playbackRate':
case 'volume':
update_conditions.push(x `!@_isNaN(${this.snippet})`);
mount_conditions.push(x `!@_isNaN(${this.snippet})`);
break;
case 'paused':
{
// this is necessary to prevent audio restarting by itself
const last = block.get_unique_name(`${parent.var.name}_is_paused`);
block.add_variable(last, x `true`);
update_conditions.push(x `${last} !== (${last} = ${this.snippet})`);
update_dom = b `${parent.var}[${last} ? "pause" : "play"]();`;
mount_dom = null;
break;
}
case 'value':
if (parent.node.get_static_attribute_value('type') === 'file') {
update_dom = null;
mount_dom = null;
}
}
if (update_dom) {
if (update_conditions.length > 0) {
const condition = update_conditions.reduce((lhs, rhs) => x `${lhs} && ${rhs}`);
block.chunks.update.push(b `
if (${condition}) {
${update_dom}
}
`);
}
else {
block.chunks.update.push(update_dom);
}
}
if (mount_dom) {
if (mount_conditions.length > 0) {
const condition = mount_conditions.reduce((lhs, rhs) => x `${lhs} && ${rhs}`);
block.chunks.mount.push(b `
if (${condition}) {
${mount_dom}
}
`);
}
else {
block.chunks.mount.push(mount_dom);
}
}
}
}
function get_dom_updater(element, binding) {
const { node } = element;
if (binding.is_readonly_media_attribute()) {
return null;
}
if (binding.node.name === 'this') {
return null;
}
if (node.name === 'select') {
return node.get_static_attribute_value('multiple') === true ?
b `@select_options(${element.var}, ${binding.snippet})` :
b `@select_option(${element.var}, ${binding.snippet})`;
}
if (binding.node.name === 'group') {
const type = node.get_static_attribute_value('type');
const condition = type === 'checkbox'
? x `~${binding.snippet}.indexOf(${element.var}.__value)`
: x `${element.var}.__value === ${binding.snippet}`;
return b `${element.var}.checked = ${condition};`;
}
if (binding.node.name === 'value') {
return b `@set_input_value(${element.var}, ${binding.snippet});`;
}
return b `${element.var}.${binding.node.name} = ${binding.snippet};`;
}
function get_binding_group(renderer, value, block) {
const { parts } = flatten_reference(value.raw_expression);
let keypath = parts.join('.');
const contexts = [];
for (const dep of value.expression.contextual_dependencies) {
const context = block.bindings.get(dep);
let key;
let name;
if (context) {
key = context.object.name;
name = context.property.name;
}
else {
key = dep;
name = dep;
}
keypath = `${key}@${keypath}`;
contexts.push(name);
}
if (!renderer.binding_groups.has(keypath)) {
const index = renderer.binding_groups.size;
contexts.forEach(context => {
renderer.add_to_context(context, true);
});
renderer.binding_groups.set(keypath, {
binding_group: (to_reference = false) => {
let binding_group = '$$binding_groups';
let _secondary_indexes = contexts;
if (to_reference) {
binding_group = block.renderer.reference(binding_group);
_secondary_indexes = _secondary_indexes.map(name => block.renderer.reference(name));
}
if (_secondary_indexes.length > 0) {
let obj = x `${binding_group}[${index}]`;
_secondary_indexes.forEach(secondary_index => {
obj = x `${obj}[${secondary_index}]`;
});
return obj;
}
else {
return x `${binding_group}[${index}]`;
}
},
is_context: contexts.length > 0,
contexts,
index,
});
}
return renderer.binding_groups.get(keypath);
}
function get_event_handler(binding, renderer, block, name, lhs) {
const contextual_dependencies = new Set(binding.node.expression.contextual_dependencies);
const context = block.bindings.get(name);
let set_store;
if (context) {
const { object, property, store, snippet } = context;
lhs = replace_object(lhs, snippet);
contextual_dependencies.add(object.name);
contextual_dependencies.add(property.name);
contextual_dependencies.delete(name);
if (store) {
set_store = b `${store}.set(${`$${store}`});`;
}
}
else {
const object = get_object(lhs);
if (object.name[0] === '$') {
const store = object.name.slice(1);
set_store = b `${store}.set(${object.name});`;
}
}
const value = get_value_from_dom(renderer, binding.parent, binding, block, contextual_dependencies);
const mutation = b `
${lhs} = ${value};
${set_store}
`;
return {
uses_context: binding.node.is_contextual || binding.node.expression.uses_context,
mutation,
contextual_dependencies,
lhs,
};
}
function get_value_from_dom(renderer, element, binding, block, contextual_dependencies) {
const { node } = element;
const { name } = binding.node;
if (name === 'this') {
return x `$$value`;
}
// <select bind:value='selected>
if (node.name === 'select') {
return node.get_static_attribute_value('multiple') === true ?
x `@select_multiple_value(this)` :
x `@select_value(this)`;
}
const type = node.get_static_attribute_value('type');
// <input type='checkbox' bind:group='foo'>
if (name === 'group') {
if (type === 'checkbox') {
const { binding_group, contexts } = get_binding_group(renderer, binding.node, block);
add_to_set(contextual_dependencies, contexts);
return x `@get_binding_group_value(${binding_group()}, this.__value, this.checked)`;
}
return x `this.__value`;
}
// <input type='range|number' bind:value>
if (type === 'range' || type === 'number') {
return x `@to_number(this.${name})`;
}
if ((name === 'buffered' || name === 'seekable' || name === 'played')) {
return x `@time_ranges_to_array(this.${name})`;
}
// everything else
return x `this.${name}`;
}
function add_actions(block, target, actions) {
actions.forEach(action => add_action(block, target, action));
}
function add_action(block, target, action) {
const { expression } = action;
let snippet;
let dependencies;
if (expression) {
snippet = expression.manipulate(block);
dependencies = expression.dynamic_dependencies();
}
const id = block.get_unique_name(`${action.name.replace(/[^a-zA-Z0-9_$]/g, '_')}_action`);
block.add_variable(id);
const fn = block.renderer.reference(action.name);
block.event_listeners.push(x `@action_destroyer(${id} = ${fn}.call(null, ${target}, ${snippet}))`);
if (dependencies && dependencies.length > 0) {
let condition = x `${id} && @is_function(${id}.update)`;
if (dependencies.length > 0) {
condition = x `${condition} && ${block.renderer.dirty(dependencies)}`;
}
block.chunks.update.push(b `if (${condition}) ${id}.update.call(null, ${snippet});`);
}
}
function get_slot_definition(block, scope, lets) {
if (lets.length === 0)
return { block, scope };
const context_input = {
type: 'ObjectPattern',
properties: lets.map(l => ({
type: 'Property',
kind: 'init',
key: l.name,
value: l.value || l.name
}))
};
const properties = [];
const value_map = new Map();
lets.forEach(l => {
let value;
if (l.names.length > 1) {
// more than one, probably destructuring
const unique_name = block.get_unique_name(l.names.join('_')).name;
value_map.set(l.value, unique_name);
value = { type: 'Identifier', name: unique_name };
}
else {
value = l.value || l.name;
}
properties.push({
type: 'Property',
kind: 'init',
key: l.name,
value,
});
});
const changes_input = {
type: 'ObjectPattern',
properties,
};
const names = new Set();
const names_lookup = new Map();
lets.forEach(l => {
l.names.forEach(name => {
names.add(name);
if (value_map.has(l.value)) {
names_lookup.set(name, value_map.get(l.value));
}
});
});
const context = {
type: 'ObjectExpression',
properties: Array.from(names).map(name => p `${block.renderer.context_lookup.get(name).index}: ${name}`)
};
const { context_lookup } = block.renderer;
// i am well aware that this code is gross
// TODO: context-overflow make it less gross
const changes = {
type: 'ParenthesizedExpression',
get expression() {
if (block.renderer.context_overflow) {
const grouped = [];
Array.from(names).forEach(name => {
const i = context_lookup.get(name).index.value;
const g = Math.floor(i / 31);
const lookup_name = names_lookup.has(name) ? names_lookup.get(name) : name;
if (!grouped[g])
grouped[g] = [];
grouped[g].push({ name: lookup_name, n: i % 31 });
});
const elements = [];
for (let g = 0; g < grouped.length; g += 1) {
elements[g] = grouped[g]
? grouped[g]
.map(({ name, n }) => x `${name} ? ${1 << n} : 0`)
.reduce((lhs, rhs) => x `${lhs} | ${rhs}`)
: x `0`;
}
return {
type: 'ArrayExpression',
elements
};
}
return Array.from(names)
.map(name => {
const lookup_name = names_lookup.has(name) ? names_lookup.get(name) : name;
const i = context_lookup.get(name).index.value;
return x `${lookup_name} ? ${1 << i} : 0`;
})
.reduce((lhs, rhs) => x `${lhs} | ${rhs}`);
}
};
return {
block,
scope,
get_context: x `${context_input} => ${context}`,
get_changes: x `${changes_input} => ${changes}`
};
}
function compare_node(a, b) {
if (a === b)
return true;
if (!a || !b)
return false;
if (a.type !== b.type)
return false;
switch (a.type) {
case "Identifier":
return a.name === b.name;
case "MemberExpression":
return (compare_node(a.object, b.object) &&
compare_node(a.property, b.property) &&
a.computed === b.computed);
case 'Literal':
return a.value === b.value;
}
}
function bind_this(component, block, binding, variable) {
const fn = component.get_unique_name(`${variable.name}_binding`);
block.renderer.add_to_context(fn.name);
const callee = block.renderer.reference(fn.name);
const { contextual_dependencies, mutation } = binding.handler;
const dependencies = binding.get_dependencies();
const body = b `
${mutation}
${Array.from(dependencies)
.filter(dep => dep[0] !== '$')
.filter(dep => !contextual_dependencies.has(dep))
.map(dep => b `${block.renderer.invalidate(dep)};`)}
`;
if (contextual_dependencies.size) {
const params = Array.from(contextual_dependencies).map(name => ({
type: 'Identifier',
name
}));
component.partly_hoisted.push(b `
function ${fn}($$value, ${params}) {
@binding_callbacks[$$value ? 'unshift' : 'push'](() => {
${body}
});
}
`);
const alias_map = new Map();
const args = [];
for (let id of params) {
const value = block.renderer.reference(id.name);
let found = false;
if (block.variables.has(id.name)) {
let alias = id.name;
for (let i = 1; block.variables.has(alias) && !compare_node(block.variables.get(alias).init, value); alias = `${id.name}_${i++}`)
;
alias_map.set(alias, id.name);
id = { type: 'Identifier', name: alias };
found = block.variables.has(alias);
}
args.push(id);
if (!found) {
block.add_variable(id, value);
}
}
const assign = block.get_unique_name(`assign_${variable.name}`);
const unassign = block.get_unique_name(`unassign_${variable.name}`);
block.chunks.init.push(b `
const ${assign} = () => ${callee}(${variable}, ${args});
const ${unassign} = () => ${callee}(null, ${args});
`);
const condition = Array.from(args)
.map(name => x `${name} !== ${block.renderer.reference(alias_map.get(name.name) || name.name)}`)
.reduce((lhs, rhs) => x `${lhs} || ${rhs}`);
// we push unassign and unshift assign so that references are
// nulled out before they're created, to avoid glitches
// with shifting indices
block.chunks.update.push(b `
if (${condition}) {
${unassign}();
${args.map(a => b `${a} = ${block.renderer.reference(alias_map.get(a.name) || a.name)}`)};
${assign}();
}`);
block.chunks.destroy.push(b `${unassign}();`);
return b `${assign}();`;
}
component.partly_hoisted.push(b `
function ${fn}($$value) {
@binding_callbacks[$$value ? 'unshift' : 'push'](() => {
${body}
});
}
`);
block.chunks.destroy.push(b `${callee}(null);`);
return b `${callee}(${variable});`;
}
class Node$1 {
constructor(component, parent, _scope, info) {
this.start = info.start;
this.end = info.end;
this.type = info.type;
// this makes properties non-enumerable, which makes logging
// bearable. might have a performance cost. TODO remove in prod?
Object.defineProperties(this, {
component: {
value: component
},
parent: {
value: parent
}
});
}
cannot_use_innerhtml() {
if (this.can_use_innerhtml !== false) {
this.can_use_innerhtml = false;
if (this.parent)
this.parent.cannot_use_innerhtml();
}
}
find_nearest(selector) {
if (selector.test(this.type))
return this;
if (this.parent)
return this.parent.find_nearest(selector);
}
get_static_attribute_value(name) {
const attribute = this.attributes && this.attributes.find((attr) => attr.type === 'Attribute' && attr.name.toLowerCase() === name);
if (!attribute)
return null;
if (attribute.is_true)
return true;
if (attribute.chunks.length === 0)
return '';
if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') {
return attribute.chunks[0].data;
}
return null;
}
has_ancestor(type) {
return this.parent ?
this.parent.type === type || this.parent.has_ancestor(type) :
false;
}
}
function create_scopes(expression) {
return analyze(expression);
}
function is_dynamic$1(variable) {
if (variable) {
if (variable.mutated || variable.reassigned)
return true; // dynamic internal state
if (!variable.module && variable.writable && variable.export_name)
return true; // writable props
}
return false;
}
function nodes_match(a, b) {
if (!!a !== !!b)
return false;
if (Array.isArray(a) !== Array.isArray(b))
return false;
if (a && typeof a === 'object') {
if (Array.isArray(a)) {
if (a.length !== b.length)
return false;
return a.every((child, i) => nodes_match(child, b[i]));
}
const a_keys = Object.keys(a).sort();
const b_keys = Object.keys(b).sort();
if (a_keys.length !== b_keys.length)
return false;
let i = a_keys.length;
while (i--) {
const key = a_keys[i];
if (b_keys[i] !== key)
return false;
if (key === 'start' || key === 'end')
continue;
if (!nodes_match(a[key], b[key])) {
return false;
}
}
return true;
}
return a === b;
}
function invalidate(renderer, scope, node, names, main_execution_context = false) {
const { component } = renderer;
const [head, ...tail] = Array.from(names)
.filter(name => {
const owner = scope.find_owner(name);
return !owner || owner === component.instance_scope;
})
.map(name => component.var_lookup.get(name))
.filter(variable => {
return variable && (!variable.hoistable &&
!variable.global &&
!variable.module &&
(variable.referenced ||
variable.subscribable ||
variable.is_reactive_dependency ||
variable.export_name ||
variable.name[0] === '$'));
});
function get_invalidated(variable, node) {
if (main_execution_context && !variable.subscribable && variable.name[0] !== '$') {
return node || x `${variable.name}`;
}
return renderer.invalidate(variable.name);
}
if (head) {
component.has_reactive_assignments = true;
if (node.type === 'AssignmentExpression' && node.operator === '=' && nodes_match(node.left, node.right) && tail.length === 0) {
return get_invalidated(head, node);
}
else {
const is_store_value = head.name[0] === '$' && head.name[1] !== '$';
const extra_args = tail.map(variable => get_invalidated(variable));
const pass_value = (extra_args.length > 0 ||
(node.type === 'AssignmentExpression' && node.left.type !== 'Identifier') ||
(node.type === 'UpdateExpression' && (!node.prefix || node.argument.type !== 'Identifier')));
if (pass_value) {
extra_args.unshift({
type: 'Identifier',
name: head.name
});
}
let invalidate = is_store_value
? x `@set_store_value(${head.name.slice(1)}, ${node}, ${extra_args})`
: !main_execution_context
? x `$$invalidate(${renderer.context_lookup.get(head.name).index}, ${node}, ${extra_args})`
: node;
if (head.subscribable && head.reassigned) {
const subscribe = `$$subscribe_${head.name}`;
invalidate = x `${subscribe}(${invalidate})`;
}
return invalidate;
}
}
return node;
}
const reserved_keywords = new Set(["$$props", "$$restProps"]);
function is_reserved_keyword(name) {
return reserved_keywords.has(name);
}
class Expression {
// todo: owner type
constructor(component, owner, template_scope, info, lazy) {
this.type = 'Expression';
this.references = new Set();
this.dependencies = new Set();
this.contextual_dependencies = new Set();
this.declarations = [];
this.uses_context = false;
// TODO revert to direct property access in prod?
Object.defineProperties(this, {
component: {
value: component
}
});
this.node = info;
this.template_scope = template_scope;
this.owner = owner;
const { dependencies, contextual_dependencies, references } = this;
let { map, scope } = create_scopes(info);
this.scope = scope;
this.scope_map = map;
const expression = this;
let function_expression;
// discover dependencies, but don't change the code yet
walk(info, {
enter(node, parent, key) {
// don't manipulate shorthand props twice
if (key === 'value' && parent.shorthand)
return;
if (map.has(node)) {
scope = map.get(node);
}
if (!function_expression && /FunctionExpression/.test(node.type)) {
function_expression = node;
}
if (isReference(node, parent)) {
const { name, nodes } = flatten_reference(node);
references.add(name);
if (scope.has(name))
return;
if (name[0] === '$') {
const store_name = name.slice(1);
if (template_scope.names.has(store_name) || scope.has(store_name)) {
component.error(node, {
code: `contextual-store`,
message: `Stores must be declared at the top level of the component (this may change in a future version of Svelte)`
});
}
}
if (template_scope.is_let(name)) {
if (!function_expression) { // TODO should this be `!lazy` ?
contextual_dependencies.add(name);
dependencies.add(name);
}
}
else if (template_scope.names.has(name)) {
expression.uses_context = true;
contextual_dependencies.add(name);
const owner = template_scope.get_owner(name);
const is_index = owner.type === 'EachBlock' && owner.key && name === owner.index;
if (!lazy || is_index) {
template_scope.dependencies_for_name.get(name).forEach(name => dependencies.add(name));
}
}
else {
if (!lazy) {
dependencies.add(name);
}
component.add_reference(name);
component.warn_if_undefined(name, nodes[0], template_scope);
}
this.skip();
}
// track any assignments from template expressions as mutable
let names;
let deep = false;
if (function_expression) {
if (node.type === 'AssignmentExpression') {
deep = node.left.type === 'MemberExpression';
names = extract_names(deep ? get_object(node.left) : node.left);
}
else if (node.type === 'UpdateExpression') {
names = extract_names(get_object(node.argument));
}
}
if (names) {
names.forEach(name => {
if (template_scope.names.has(name)) {
template_scope.dependencies_for_name.get(name).forEach(name => {
const variable = component.var_lookup.get(name);
if (variable)
variable[deep ? 'mutated' : 'reassigned'] = true;
});
const each_block = template_scope.get_owner(name);
each_block.has_binding = true;
}
else {
component.add_reference(name);
const variable = component.var_lookup.get(name);
if (variable)
variable[deep ? 'mutated' : 'reassigned'] = true;
}
});
}
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
if (node === function_expression) {
function_expression = null;
}
}
});
}
dynamic_dependencies() {
return Array.from(this.dependencies).filter(name => {
if (this.template_scope.is_let(name))
return true;
if (is_reserved_keyword(name))
return true;
const variable = this.component.var_lookup.get(name);
return is_dynamic$1(variable);
});
}
// TODO move this into a render-dom wrapper?
manipulate(block) {
// TODO ideally we wouldn't end up calling this method
// multiple times
if (this.manipulated)
return this.manipulated;
const { component, declarations, scope_map: map, template_scope, owner } = this;
let scope = this.scope;
let function_expression;
let dependencies;
let contextual_dependencies;
const node = walk(this.node, {
enter(node, parent) {
if (node.type === 'Property' && node.shorthand) {
node.value = JSON.parse(JSON.stringify(node.value));
node.shorthand = false;
}
if (map.has(node)) {
scope = map.get(node);
}
if (node.type === 'Identifier' && isReference(node, parent)) {
const { name } = flatten_reference(node);
if (scope.has(name))
return;
if (function_expression) {
if (template_scope.names.has(name)) {
contextual_dependencies.add(name);
template_scope.dependencies_for_name.get(name).forEach(dependency => {
dependencies.add(dependency);
});
}
else {
dependencies.add(name);
component.add_reference(name); // TODO is this redundant/misplaced?
}
}
else if (is_contextual(component, template_scope, name)) {
const reference = block.renderer.reference(node);
this.replace(reference);
}
this.skip();
}
if (!function_expression) {
if (node.type === 'AssignmentExpression') ;
if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
function_expression = node;
dependencies = new Set();
contextual_dependencies = new Set();
}
}
},
leave(node, parent) {
if (map.has(node))
scope = scope.parent;
if (node === function_expression) {
const id = component.get_unique_name(sanitize(get_function_name(node, owner)));
const declaration = b `const ${id} = ${node}`;
if (dependencies.size === 0 && contextual_dependencies.size === 0) {
// we can hoist this out of the component completely
component.fully_hoisted.push(declaration);
this.replace(id);
component.add_var({
name: id.name,
internal: true,
hoistable: true,
referenced: true
});
}
else if (contextual_dependencies.size === 0) {
// function can be hoisted inside the component init
component.partly_hoisted.push(declaration);
block.renderer.add_to_context(id.name);
this.replace(block.renderer.reference(id));
}
else {
// we need a combo block/init recipe
const deps = Array.from(contextual_dependencies);
node.params = [
...deps.map(name => ({ type: 'Identifier', name })),
...node.params
];
const context_args = deps.map(name => block.renderer.reference(name));
component.partly_hoisted.push(declaration);
block.renderer.add_to_context(id.name);
const callee = block.renderer.reference(id);
this.replace(id);
if (node.params.length > 0) {
declarations.push(b `
function ${id}(...args) {
return ${callee}(${context_args}, ...args);
}
`);
}
else {
declarations.push(b `
function ${id}() {
return ${callee}(${context_args});
}
`);
}
}
function_expression = null;
dependencies = null;
contextual_dependencies = null;
if (parent && parent.type === 'Property') {
parent.method = false;
}
}
if (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') {
const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument;
const object_name = get_object(assignee).name;
if (scope.has(object_name))
return;
// normally (`a = 1`, `b.c = 2`), there'll be a single name
// (a or b). In destructuring cases (`[d, e] = [e, d]`) there
// may be more, in which case we need to tack the extra ones
// onto the initial function call
const names = new Set(extract_names(assignee));
const traced = new Set();
names.forEach(name => {
const dependencies = template_scope.dependencies_for_name.get(name);
if (dependencies) {
dependencies.forEach(name => traced.add(name));
}
else {
traced.add(name);
}
});
const context = block.bindings.get(object_name);
if (context) {
// for `{#each array as item}`
// replace `item = 1` to `each_array[each_index] = 1`, this allow us to mutate the array
// rather than mutating the local `item` variable
const { snippet, object, property } = context;
const replaced = replace_object(assignee, snippet);
if (node.type === 'AssignmentExpression') {
node.left = replaced;
}
else {
node.argument = replaced;
}
contextual_dependencies.add(object.name);
contextual_dependencies.add(property.name);
}
this.replace(invalidate(block.renderer, scope, node, traced));
}
}
});
if (declarations.length > 0) {
block.maintain_context = true;
declarations.forEach(declaration => {
block.chunks.init.push(declaration);
});
}
return (this.manipulated = node);
}
}
function get_function_name(_node, parent) {
if (parent.type === 'EventHandler') {
return `${parent.name}_handler`;
}
if (parent.type === 'Action') {
return `${parent.name}_function`;
}
return 'func';
}
function is_contextual(component, scope, name) {
if (is_reserved_keyword(name))
return true;
// if it's a name below root scope, it's contextual
if (!scope.is_top_level(name))
return true;
const variable = component.var_lookup.get(name);
// hoistables, module declarations, and imports are non-contextual
if (!variable || variable.hoistable)
return false;
// assume contextual
return true;
}
class Action extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
component.warn_if_undefined(info.name, info, scope);
this.name = info.name;
component.add_reference(info.name.split('.')[0]);
this.expression = info.expression
? new Expression(component, this, scope, info.expression)
: null;
this.uses_context = this.expression && this.expression.uses_context;
}
}
class Tag extends Wrapper {
constructor(renderer, block, parent, node) {
super(renderer, block, parent, node);
this.cannot_use_innerhtml();
if (!this.is_dependencies_static()) {
this.not_static_content();
}
block.add_dependencies(node.expression.dependencies);
}
is_dependencies_static() {
return this.node.expression.contextual_dependencies.size === 0 && this.node.expression.dynamic_dependencies().length === 0;
}
rename_this_method(block, update) {
const dependencies = this.node.expression.dynamic_dependencies();
let snippet = this.node.expression.manipulate(block);
const value = this.node.should_cache && block.get_unique_name(`${this.var.name}_value`);
const content = this.node.should_cache ? value : snippet;
snippet = x `${snippet} + ""`;
if (this.node.should_cache)
block.add_variable(value, snippet); // TODO may need to coerce snippet to string
if (dependencies.length > 0) {
let condition = block.renderer.dirty(dependencies);
if (block.has_outros) {
condition = x `!#current || ${condition}`;
}
const update_cached_value = x `${value} !== (${value} = ${snippet})`;
if (this.node.should_cache) {
condition = x `${condition} && ${update_cached_value}`;
}
block.chunks.update.push(b `if (${condition}) ${update(content)}`);
}
return { init: content };
}
}
class MustacheTagWrapper extends Tag {
constructor(renderer, block, parent, node) {
super(renderer, block, parent, node);
this.var = { type: 'Identifier', name: 't' };
}
render(block, parent_node, parent_nodes) {
const { init } = this.rename_this_method(block, value => x `@set_data(${this.var}, ${value})`);
block.add_element(this.var, x `@text(${init})`, parent_nodes && x `@claim_text(${parent_nodes}, ${init})`, parent_node);
}
}
class RawMustacheTagWrapper extends Tag {
constructor(renderer, block, parent, node) {
super(renderer, block, parent, node);
this.var = { type: 'Identifier', name: 'raw' };
this.cannot_use_innerhtml();
this.not_static_content();
}
render(block, parent_node, _parent_nodes) {
const in_head = is_head(parent_node);
const can_use_innerhtml = !in_head && parent_node && !this.prev && !this.next;
if (can_use_innerhtml) {
const insert = content => b `${parent_node}.innerHTML = ${content};`[0];
const { init } = this.rename_this_method(block, content => insert(content));
block.chunks.mount.push(insert(init));
}
else {
const needs_anchor = in_head || (this.next ? !this.next.is_dom_node() : (!this.parent || !this.parent.is_dom_node()));
const html_tag = block.get_unique_name('html_tag');
const html_anchor = needs_anchor && block.get_unique_name('html_anchor');
block.add_variable(html_tag);
const { init } = this.rename_this_method(block, content => x `${html_tag}.p(${content})`);
const update_anchor = needs_anchor ? html_anchor : this.next ? this.next.var : 'null';
block.chunks.hydrate.push(b `${html_tag} = new @HtmlTag(${update_anchor});`);
block.chunks.mount.push(b `${html_tag}.m(${init}, ${parent_node || '#target'}, ${parent_node ? null : '#anchor'});`);
if (needs_anchor) {
block.add_element(html_anchor, x `@empty()`, x `@empty()`, parent_node);
}
if (!parent_node || in_head) {
block.chunks.destroy.push(b `if (detaching) ${html_tag}.d();`);
}
}
}
}
const events = [
{
event_names: ['input'],
filter: (node, _name) => node.name === 'textarea' ||
node.name === 'input' && !/radio|checkbox|range|file/.test(node.get_static_attribute_value('type'))
},
{
event_names: ['input'],
filter: (node, name) => (name === 'textContent' || name === 'innerHTML') &&
node.attributes.some(attribute => attribute.name === 'contenteditable')
},
{
event_names: ['change'],
filter: (node, _name) => node.name === 'select' ||
node.name === 'input' && /radio|checkbox|file/.test(node.get_static_attribute_value('type'))
},
{
event_names: ['change', 'input'],
filter: (node, _name) => node.name === 'input' && node.get_static_attribute_value('type') === 'range'
},
{
event_names: ['elementresize'],
filter: (_node, name) => dimensions.test(name)
},
// media events
{
event_names: ['timeupdate'],
filter: (node, name) => node.is_media_node() &&
(name === 'currentTime' || name === 'played' || name === 'ended')
},
{
event_names: ['durationchange'],
filter: (node, name) => node.is_media_node() &&
name === 'duration'
},
{
event_names: ['play', 'pause'],
filter: (node, name) => node.is_media_node() &&
name === 'paused'
},
{
event_names: ['progress'],
filter: (node, name) => node.is_media_node() &&
name === 'buffered'
},
{
event_names: ['loadedmetadata'],
filter: (node, name) => node.is_media_node() &&
(name === 'buffered' || name === 'seekable')
},
{
event_names: ['volumechange'],
filter: (node, name) => node.is_media_node() &&
(name === 'volume' || name === 'muted')
},
{
event_names: ['ratechange'],
filter: (node, name) => node.is_media_node() &&
name === 'playbackRate'
},
{
event_names: ['seeking', 'seeked'],
filter: (node, name) => node.is_media_node() &&
(name === 'seeking')
},
{
event_names: ['ended'],
filter: (node, name) => node.is_media_node() &&
name === 'ended'
},
{
event_names: ['resize'],
filter: (node, name) => node.is_media_node() &&
(name === 'videoHeight' || name === 'videoWidth')
},
// details event
{
event_names: ['toggle'],
filter: (node, _name) => node.name === 'details'
},
];
class ElementWrapper extends Wrapper {
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.var = {
type: 'Identifier',
name: node.name.replace(/[^a-zA-Z0-9_$]/g, '_')
};
this.void = is_void(node.name);
this.class_dependencies = [];
if (this.node.children.length) {
this.node.lets.forEach(l => {
extract_names(l.value || l.name).forEach(name => {
renderer.add_to_context(name, true);
});
});
}
this.attributes = this.node.attributes.map(attribute => {
if (attribute.name === 'slot') {
// TODO make separate subclass for this?
let owner = this.parent;
while (owner) {
if (owner.node.type === 'InlineComponent') {
break;
}
if (owner.node.type === 'Element' && /-/.test(owner.node.name)) {
break;
}
owner = owner.parent;
}
if (owner && owner.node.type === 'InlineComponent') {
const name = attribute.get_static_value();
if (!owner.slots.has(name)) {
const child_block = block.child({
comment: create_debugging_comment(node, this.renderer.component),
name: this.renderer.component.get_unique_name(`create_${sanitize(name)}_slot`),
type: 'slot'
});
const { scope, lets } = this.node;
const seen = new Set(lets.map(l => l.name.name));
owner.node.lets.forEach(l => {
if (!seen.has(l.name.name))
lets.push(l);
});
owner.slots.set(name, get_slot_definition(child_block, scope, lets));
this.renderer.blocks.push(child_block);
}
this.slot_block = owner.slots.get(name).block;
block = this.slot_block;
}
}
if (attribute.name === 'style') {
return new StyleAttributeWrapper(this, block, attribute);
}
if (attribute.type === 'Spread') {
return new SpreadAttributeWrapper(this, block, attribute);
}
return new AttributeWrapper(this, block, attribute);
});
// ordinarily, there'll only be one... but we need to handle
// the rare case where an element can have multiple bindings,
// e.g. <audio bind:paused bind:currentTime>
this.bindings = this.node.bindings.map(binding => new BindingWrapper(block, binding, this));
this.event_handlers = this.node.handlers.map(event_handler => new EventHandlerWrapper(event_handler, this));
if (node.intro || node.outro) {
if (node.intro)
block.add_intro(node.intro.is_local);
if (node.outro)
block.add_outro(node.outro.is_local);
}
if (node.animation) {
block.add_animation();
}
// add directive and handler dependencies
[node.animation, node.outro, ...node.actions, ...node.classes].forEach(directive => {
if (directive && directive.expression) {
block.add_dependencies(directive.expression.dependencies);
}
});
node.handlers.forEach(handler => {
if (handler.expression) {
block.add_dependencies(handler.expression.dependencies);
}
});
if (this.parent) {
if (node.actions.length > 0 ||
node.animation ||
node.bindings.length > 0 ||
node.classes.length > 0 ||
node.intro || node.outro ||
node.handlers.length > 0 ||
this.node.name === 'option' ||
renderer.options.dev) {
this.parent.cannot_use_innerhtml(); // need to use add_location
this.parent.not_static_content();
}
}
this.fragment = new FragmentWrapper(renderer, block, node.children, this, strip_whitespace, next_sibling);
if (this.slot_block) {
block.parent.add_dependencies(block.dependencies);
// appalling hack
const index = block.parent.wrappers.indexOf(this);
block.parent.wrappers.splice(index, 1);
block.wrappers.push(this);
}
}
render(block, parent_node, parent_nodes) {
const { renderer } = this;
if (this.node.name === 'noscript')
return;
if (this.slot_block) {
block = this.slot_block;
}
const node = this.var;
const nodes = parent_nodes && block.get_unique_name(`${this.var.name}_nodes`); // if we're in unclaimable territory, i.e. <head>, parent_nodes is null
const children = x `@children(${this.node.name === 'template' ? x `${node}.content` : node})`;
block.add_variable(node);
const render_statement = this.get_render_statement(block);
block.chunks.create.push(b `${node} = ${render_statement};`);
if (renderer.options.hydratable) {
if (parent_nodes) {
block.chunks.claim.push(b `
${node} = ${this.get_claim_statement(parent_nodes)};
`);
if (!this.void && this.node.children.length > 0) {
block.chunks.claim.push(b `
var ${nodes} = ${children};
`);
}
}
else {
block.chunks.claim.push(b `${node} = ${render_statement};`);
}
}
if (parent_node) {
block.chunks.mount.push(b `@append(${parent_node}, ${node});`);
if (is_head(parent_node)) {
block.chunks.destroy.push(b `@detach(${node});`);
}
}
else {
block.chunks.mount.push(b `@insert(#target, ${node}, #anchor);`);
// TODO we eventually need to consider what happens to elements
// that belong to the same outgroup as an outroing element...
block.chunks.destroy.push(b `if (detaching) @detach(${node});`);
}
// insert static children with textContent or innerHTML
const can_use_textcontent = this.can_use_textcontent();
if (!this.node.namespace && (this.can_use_innerhtml || can_use_textcontent) && this.fragment.nodes.length > 0) {
if (this.fragment.nodes.length === 1 && this.fragment.nodes[0].node.type === 'Text') {
block.chunks.create.push(b `${node}.textContent = ${string_literal(this.fragment.nodes[0].data)};`);
}
else {
const state = {
quasi: {
type: 'TemplateElement',
value: { raw: '' }
}
};
const literal = {
type: 'TemplateLiteral',
expressions: [],
quasis: []
};
const can_use_raw_text = !this.can_use_innerhtml && can_use_textcontent;
to_html(this.fragment.nodes, block, literal, state, can_use_raw_text);
literal.quasis.push(state.quasi);
block.chunks.create.push(b `${node}.${this.can_use_innerhtml ? 'innerHTML' : 'textContent'} = ${literal};`);
}
}
else {
this.fragment.nodes.forEach((child) => {
child.render(block, this.node.name === 'template' ? x `${node}.content` : node, nodes);
});
}
const event_handler_or_binding_uses_context = (this.bindings.some(binding => binding.handler.uses_context) ||
this.node.handlers.some(handler => handler.uses_context) ||
this.node.actions.some(action => action.uses_context));
if (event_handler_or_binding_uses_context) {
block.maintain_context = true;
}
this.add_attributes(block);
this.add_directives_in_order(block);
this.add_transitions(block);
this.add_animation(block);
this.add_classes(block);
this.add_manual_style_scoping(block);
if (nodes && this.renderer.options.hydratable && !this.void) {
block.chunks.claim.push(b `${this.node.children.length > 0 ? nodes : children}.forEach(@detach);`);
}
if (renderer.options.dev) {
const loc = renderer.locate(this.node.start);
block.chunks.hydrate.push(b `@add_location(${this.var}, ${renderer.file_var}, ${loc.line - 1}, ${loc.column}, ${this.node.start});`);
}
}
can_use_textcontent() {
return this.is_static_content && this.fragment.nodes.every(node => node.node.type === 'Text' || node.node.type === 'MustacheTag');
}
get_render_statement(block) {
const { name, namespace } = this.node;
if (namespace === namespaces.svg) {
return x `@svg_element("${name}")`;
}
if (namespace) {
return x `@_document.createElementNS("${namespace}", "${name}")`;
}
const is = this.attributes.find(attr => attr.node.name === 'is');
if (is) {
return x `@element_is("${name}", ${is.render_chunks(block).reduce((lhs, rhs) => x `${lhs} + ${rhs}`)})`;
}
return x `@element("${name}")`;
}
get_claim_statement(nodes) {
const attributes = this.node.attributes
.filter((attr) => attr.type === 'Attribute')
.map((attr) => p `${attr.name}: true`);
const name = this.node.namespace
? this.node.name
: this.node.name.toUpperCase();
const svg = this.node.namespace === namespaces.svg ? 1 : null;
return x `@claim_element(${nodes}, "${name}", { ${attributes} }, ${svg})`;
}
add_directives_in_order(block) {
const binding_groups = events
.map(event => ({
events: event.event_names,
bindings: this.bindings
.filter(binding => binding.node.name !== 'this')
.filter(binding => event.filter(this.node, binding.node.name))
}))
.filter(group => group.bindings.length);
const this_binding = this.bindings.find(b => b.node.name === 'this');
function getOrder(item) {
if (item instanceof EventHandlerWrapper) {
return item.node.start;
}
else if (item instanceof BindingWrapper) {
return item.node.start;
}
else if (item instanceof Action) {
return item.start;
}
else {
return item.bindings[0].node.start;
}
}
[
...binding_groups,
...this.event_handlers,
this_binding,
...this.node.actions
]
.filter(Boolean)
.sort((a, b) => getOrder(a) - getOrder(b))
.forEach(item => {
if (item instanceof EventHandlerWrapper) {
add_event_handler(block, this.var, item);
}
else if (item instanceof BindingWrapper) {
this.add_this_binding(block, item);
}
else if (item instanceof Action) {
add_action(block, this.var, item);
}
else {
this.add_bindings(block, item);
}
});
}
add_bindings(block, binding_group) {
const { renderer } = this;
if (binding_group.bindings.length === 0)
return;
renderer.component.has_reactive_assignments = true;
const lock = binding_group.bindings.some(binding => binding.needs_lock) ?
block.get_unique_name(`${this.var.name}_updating`) :
null;
if (lock)
block.add_variable(lock, x `false`);
const handler = renderer.component.get_unique_name(`${this.var.name}_${binding_group.events.join('_')}_handler`);
renderer.add_to_context(handler.name);
// TODO figure out how to handle locks
const needs_lock = binding_group.bindings.some(binding => binding.needs_lock);
const dependencies = new Set();
const contextual_dependencies = new Set();
binding_group.bindings.forEach(binding => {
// TODO this is a mess
add_to_set(dependencies, binding.get_dependencies());
add_to_set(contextual_dependencies, binding.handler.contextual_dependencies);
binding.render(block, lock);
});
// media bindings — awkward special case. The native timeupdate events
// fire too infrequently, so we need to take matters into our
// own hands
let animation_frame;
if (binding_group.events[0] === 'timeupdate') {
animation_frame = block.get_unique_name(`${this.var.name}_animationframe`);
block.add_variable(animation_frame);
}
const has_local_function = contextual_dependencies.size > 0 || needs_lock || animation_frame;
let callee = renderer.reference(handler);
// TODO dry this out — similar code for event handlers and component bindings
if (has_local_function) {
const args = Array.from(contextual_dependencies).map(name => renderer.reference(name));
// need to create a block-local function that calls an instance-level function
if (animation_frame) {
block.chunks.init.push(b `
function ${handler}() {
@_cancelAnimationFrame(${animation_frame});
if (!${this.var}.paused) {
${animation_frame} = @raf(${handler});
${needs_lock && b `${lock} = true;`}
}
${callee}.call(${this.var}, ${args});
}
`);
}
else {
block.chunks.init.push(b `
function ${handler}() {
${needs_lock && b `${lock} = true;`}
${callee}.call(${this.var}, ${args});
}
`);
}
callee = handler;
}
const params = Array.from(contextual_dependencies).map(name => ({
type: 'Identifier',
name
}));
this.renderer.component.partly_hoisted.push(b `
function ${handler}(${params}) {
${binding_group.bindings.map(b => b.handler.mutation)}
${Array.from(dependencies)
.filter(dep => dep[0] !== '$')
.filter(dep => !contextual_dependencies.has(dep))
.map(dep => b `${this.renderer.invalidate(dep)};`)}
}
`);
binding_group.events.forEach(name => {
if (name === 'elementresize') {
// special case
const resize_listener = block.get_unique_name(`${this.var.name}_resize_listener`);
block.add_variable(resize_listener);
block.chunks.mount.push(b `${resize_listener} = @add_resize_listener(${this.var}, ${callee}.bind(${this.var}));`);
block.chunks.destroy.push(b `${resize_listener}();`);
}
else {
block.event_listeners.push(x `@listen(${this.var}, "${name}", ${callee})`);
}
});
const some_initial_state_is_undefined = binding_group.bindings
.map(binding => x `${binding.snippet} === void 0`)
.reduce((lhs, rhs) => x `${lhs} || ${rhs}`);
const should_initialise = (this.node.name === 'select' ||
binding_group.bindings.find(binding => {
return (binding.node.name === 'indeterminate' ||
binding.node.name === 'textContent' ||
binding.node.name === 'innerHTML' ||
binding.is_readonly_media_attribute());
}));
if (should_initialise) {
const callback = has_local_function ? handler : x `() => ${callee}.call(${this.var})`;
block.chunks.hydrate.push(b `if (${some_initial_state_is_undefined}) @add_render_callback(${callback});`);
}
if (binding_group.events[0] === 'elementresize') {
block.chunks.hydrate.push(b `@add_render_callback(() => ${callee}.call(${this.var}));`);
}
if (lock) {
block.chunks.update.push(b `${lock} = false;`);
}
}
add_this_binding(block, this_binding) {
const { renderer } = this;
renderer.component.has_reactive_assignments = true;
const binding_callback = bind_this(renderer.component, block, this_binding, this.var);
block.chunks.mount.push(binding_callback);
}
add_attributes(block) {
// Get all the class dependencies first
this.attributes.forEach((attribute) => {
if (attribute.node.name === 'class') {
const dependencies = attribute.node.get_dependencies();
this.class_dependencies.push(...dependencies);
}
});
if (this.node.attributes.some(attr => attr.is_spread)) {
this.add_spread_attributes(block);
return;
}
this.attributes.forEach((attribute) => {
attribute.render(block);
});
}
add_spread_attributes(block) {
const levels = block.get_unique_name(`${this.var.name}_levels`);
const data = block.get_unique_name(`${this.var.name}_data`);
const initial_props = [];
const updates = [];
this.attributes
.forEach(attr => {
const dependencies = attr.node.get_dependencies();
const condition = dependencies.length > 0
? block.renderer.dirty(dependencies)
: null;
if (attr instanceof SpreadAttributeWrapper) {
const snippet = attr.node.expression.manipulate(block);
initial_props.push(snippet);
updates.push(condition ? x `${condition} && ${snippet}` : snippet);
}
else {
const name = attr.property_name || attr.name;
initial_props.push(x `{ ${name}: ${attr.get_init(block, attr.get_value(block))} }`);
const snippet = x `{ ${name}: ${attr.should_cache ? attr.last : attr.get_value(block)} }`;
updates.push(condition ? x `${attr.get_dom_update_conditions(block, condition)} && ${snippet}` : snippet);
}
});
block.chunks.init.push(b `
let ${levels} = [${initial_props}];
let ${data} = {};
for (let #i = 0; #i < ${levels}.length; #i += 1) {
${data} = @assign(${data}, ${levels}[#i]);
}
`);
const fn = this.node.namespace === namespaces.svg ? x `@set_svg_attributes` : x `@set_attributes`;
block.chunks.hydrate.push(b `${fn}(${this.var}, ${data});`);
block.chunks.update.push(b `
${fn}(${this.var}, ${data} = @get_spread_update(${levels}, [
${updates}
]));
`);
// handle edge cases for elements
if (this.node.name === 'select') {
const dependencies = new Set();
for (const attr of this.attributes) {
for (const dep of attr.node.dependencies) {
dependencies.add(dep);
}
}
block.chunks.mount.push(b `
if (${data}.multiple) @select_options(${this.var}, ${data}.value);
`);
block.chunks.update.push(b `
if (${block.renderer.dirty(Array.from(dependencies))} && ${data}.multiple) @select_options(${this.var}, ${data}.value);
`);
}
}
add_transitions(block) {
const { intro, outro } = this.node;
if (!intro && !outro)
return;
if (intro === outro) {
// bidirectional transition
const name = block.get_unique_name(`${this.var.name}_transition`);
const snippet = intro.expression
? intro.expression.manipulate(block)
: x `{}`;
block.add_variable(name);
const fn = this.renderer.reference(intro.name);
const intro_block = b `
@add_render_callback(() => {
if (!${name}) ${name} = @create_bidirectional_transition(${this.var}, ${fn}, ${snippet}, true);
${name}.run(1);
});
`;
const outro_block = b `
if (!${name}) ${name} = @create_bidirectional_transition(${this.var}, ${fn}, ${snippet}, false);
${name}.run(0);
`;
if (intro.is_local) {
block.chunks.intro.push(b `
if (#local) {
${intro_block}
}
`);
block.chunks.outro.push(b `
if (#local) {
${outro_block}
}
`);
}
else {
block.chunks.intro.push(intro_block);
block.chunks.outro.push(outro_block);
}
block.chunks.destroy.push(b `if (detaching && ${name}) ${name}.end();`);
}
else {
const intro_name = intro && block.get_unique_name(`${this.var.name}_intro`);
const outro_name = outro && block.get_unique_name(`${this.var.name}_outro`);
if (intro) {
block.add_variable(intro_name);
const snippet = intro.expression
? intro.expression.manipulate(block)
: x `{}`;
const fn = this.renderer.reference(intro.name);
let intro_block;
if (outro) {
intro_block = b `
@add_render_callback(() => {
if (${outro_name}) ${outro_name}.end(1);
if (!${intro_name}) ${intro_name} = @create_in_transition(${this.var}, ${fn}, ${snippet});
${intro_name}.start();
});
`;
block.chunks.outro.push(b `if (${intro_name}) ${intro_name}.invalidate();`);
}
else {
intro_block = b `
if (!${intro_name}) {
@add_render_callback(() => {
${intro_name} = @create_in_transition(${this.var}, ${fn}, ${snippet});
${intro_name}.start();
});
}
`;
}
if (intro.is_local) {
intro_block = b `
if (#local) {
${intro_block}
}
`;
}
block.chunks.intro.push(intro_block);
}
if (outro) {
block.add_variable(outro_name);
const snippet = outro.expression
? outro.expression.manipulate(block)
: x `{}`;
const fn = this.renderer.reference(outro.name);
if (!intro) {
block.chunks.intro.push(b `
if (${outro_name}) ${outro_name}.end(1);
`);
}
// TODO hide elements that have outro'd (unless they belong to a still-outroing
// group) prior to their removal from the DOM
let outro_block = b `
${outro_name} = @create_out_transition(${this.var}, ${fn}, ${snippet});
`;
if (outro.is_local) {
outro_block = b `
if (#local) {
${outro_block}
}
`;
}
block.chunks.outro.push(outro_block);
block.chunks.destroy.push(b `if (detaching && ${outro_name}) ${outro_name}.end();`);
}
}
}
add_animation(block) {
if (!this.node.animation)
return;
const { outro } = this.node;
const rect = block.get_unique_name('rect');
const stop_animation = block.get_unique_name('stop_animation');
block.add_variable(rect);
block.add_variable(stop_animation, x `@noop`);
block.chunks.measure.push(b `
${rect} = ${this.var}.getBoundingClientRect();
`);
block.chunks.fix.push(b `
@fix_position(${this.var});
${stop_animation}();
${outro && b `@add_transform(${this.var}, ${rect});`}
`);
const params = this.node.animation.expression ? this.node.animation.expression.manipulate(block) : x `{}`;
const name = this.renderer.reference(this.node.animation.name);
block.chunks.animate.push(b `
${stop_animation}();
${stop_animation} = @create_animation(${this.var}, ${rect}, ${name}, ${params});
`);
}
add_classes(block) {
const has_spread = this.node.attributes.some(attr => attr.is_spread);
this.node.classes.forEach(class_directive => {
const { expression, name } = class_directive;
let snippet;
let dependencies;
if (expression) {
snippet = expression.manipulate(block);
dependencies = expression.dependencies;
}
else {
snippet = name;
dependencies = new Set([name]);
}
const updater = b `@toggle_class(${this.var}, "${name}", ${snippet});`;
block.chunks.hydrate.push(updater);
if (has_spread) {
block.chunks.update.push(updater);
}
else if ((dependencies && dependencies.size > 0) || this.class_dependencies.length) {
const all_dependencies = this.class_dependencies.concat(...dependencies);
const condition = block.renderer.dirty(all_dependencies);
block.chunks.update.push(b `
if (${condition}) {
${updater}
}`);
}
});
}
add_manual_style_scoping(block) {
if (this.node.needs_manual_style_scoping) {
const updater = b `@toggle_class(${this.var}, "${this.node.component.stylesheet.id}", true);`;
block.chunks.hydrate.push(updater);
block.chunks.update.push(updater);
}
}
}
function to_html(wrappers, block, literal, state, can_use_raw_text) {
wrappers.forEach(wrapper => {
if (wrapper instanceof TextWrapper) {
if (wrapper.use_space())
state.quasi.value.raw += ' ';
const parent = wrapper.node.parent;
const raw = parent && (parent.name === 'script' ||
parent.name === 'style' ||
can_use_raw_text);
state.quasi.value.raw += (raw ? wrapper.data : escape_html(wrapper.data))
.replace(/\\/g, '\\\\')
.replace(/`/g, '\\`')
.replace(/\$/g, '\\$');
}
else if (wrapper instanceof MustacheTagWrapper || wrapper instanceof RawMustacheTagWrapper) {
literal.quasis.push(state.quasi);
literal.expressions.push(wrapper.node.expression.manipulate(block));
state.quasi = {
type: 'TemplateElement',
value: { raw: '' }
};
}
else if (wrapper.node.name === 'noscript') ;
else {
// element
state.quasi.value.raw += `<${wrapper.node.name}`;
wrapper.attributes.forEach((attr) => {
state.quasi.value.raw += ` ${fix_attribute_casing(attr.node.name)}="`;
attr.node.chunks.forEach(chunk => {
if (chunk.type === 'Text') {
state.quasi.value.raw += escape_html(chunk.data);
}
else {
literal.quasis.push(state.quasi);
literal.expressions.push(chunk.manipulate(block));
state.quasi = {
type: 'TemplateElement',
value: { raw: '' }
};
}
});
state.quasi.value.raw += `"`;
});
state.quasi.value.raw += '>';
if (!wrapper.void) {
to_html(wrapper.fragment.nodes, block, literal, state);
state.quasi.value.raw += `</${wrapper.node.name}>`;
}
}
});
}
class HeadWrapper extends Wrapper {
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.can_use_innerhtml = false;
this.fragment = new FragmentWrapper(renderer, block, node.children, this, strip_whitespace, next_sibling);
}
render(block, _parent_node, _parent_nodes) {
let nodes;
if (this.renderer.options.hydratable && this.fragment.nodes.length) {
nodes = block.get_unique_name('head_nodes');
block.chunks.claim.push(b `const ${nodes} = @query_selector_all('[data-svelte="${this.node.id}"]', @_document.head);`);
}
this.fragment.render(block, x `@_document.head`, nodes);
if (nodes && this.renderer.options.hydratable) {
block.chunks.claim.push(b `${nodes}.forEach(@detach);`);
}
}
}
function is_else_if(node) {
return (node && node.children.length === 1 && node.children[0].type === 'IfBlock');
}
class IfBlockBranch extends Wrapper {
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.var = null;
const { expression } = node;
const is_else = !expression;
if (expression) {
this.dependencies = expression.dynamic_dependencies();
// TODO is this the right rule? or should any non-reference count?
// const should_cache = !is_reference(expression.node, null) && dependencies.length > 0;
let should_cache = false;
walk(expression.node, {
enter(node) {
if (node.type === 'CallExpression' || node.type === 'NewExpression') {
should_cache = true;
}
}
});
if (should_cache) {
this.condition = block.get_unique_name(`show_if`);
this.snippet = expression.manipulate(block);
}
else {
this.condition = expression.manipulate(block);
}
}
this.block = block.child({
comment: create_debugging_comment(node, parent.renderer.component),
name: parent.renderer.component.get_unique_name(is_else ? `create_else_block` : `create_if_block`),
type: node.expression ? 'if' : 'else'
});
this.fragment = new FragmentWrapper(renderer, this.block, node.children, parent, strip_whitespace, next_sibling);
this.is_dynamic = this.block.dependencies.size > 0;
}
}
class IfBlockWrapper extends Wrapper {
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.needs_update = false;
this.var = { type: 'Identifier', name: 'if_block' };
this.cannot_use_innerhtml();
this.not_static_content();
this.branches = [];
const blocks = [];
let is_dynamic = false;
let has_intros = false;
let has_outros = false;
const create_branches = (node) => {
const branch = new IfBlockBranch(renderer, block, this, node, strip_whitespace, next_sibling);
this.branches.push(branch);
blocks.push(branch.block);
block.add_dependencies(node.expression.dependencies);
if (branch.block.dependencies.size > 0) {
// the condition, or its contents, is dynamic
is_dynamic = true;
block.add_dependencies(branch.block.dependencies);
}
if (branch.dependencies && branch.dependencies.length > 0) {
// the condition itself is dynamic
this.needs_update = true;
}
if (branch.block.has_intros)
has_intros = true;
if (branch.block.has_outros)
has_outros = true;
if (is_else_if(node.else)) {
create_branches(node.else.children[0]);
}
else if (node.else) {
const branch = new IfBlockBranch(renderer, block, this, node.else, strip_whitespace, next_sibling);
this.branches.push(branch);
blocks.push(branch.block);
if (branch.block.dependencies.size > 0) {
is_dynamic = true;
block.add_dependencies(branch.block.dependencies);
}
if (branch.block.has_intros)
has_intros = true;
if (branch.block.has_outros)
has_outros = true;
}
};
create_branches(this.node);
blocks.forEach(block => {
block.has_update_method = is_dynamic;
block.has_intro_method = has_intros;
block.has_outro_method = has_outros;
});
renderer.blocks.push(...blocks);
}
render(block, parent_node, parent_nodes) {
const name = this.var;
const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node();
const anchor = needs_anchor
? block.get_unique_name(`${this.var.name}_anchor`)
: (this.next && this.next.var) || 'null';
const has_else = !(this.branches[this.branches.length - 1].condition);
const if_exists_condition = has_else ? null : name;
const dynamic = this.branches[0].block.has_update_method; // can use [0] as proxy for all, since they necessarily have the same value
const has_intros = this.branches[0].block.has_intro_method;
const has_outros = this.branches[0].block.has_outro_method;
const has_transitions = has_intros || has_outros;
const vars = { name, anchor, if_exists_condition, has_else, has_transitions };
const detaching = parent_node && !is_head(parent_node) ? null : 'detaching';
if (this.node.else) {
this.branches.forEach(branch => {
if (branch.snippet)
block.add_variable(branch.condition);
});
if (has_outros) {
this.render_compound_with_outros(block, parent_node, parent_nodes, dynamic, vars, detaching);
block.chunks.outro.push(b `@transition_out(${name});`);
}
else {
this.render_compound(block, parent_node, parent_nodes, dynamic, vars, detaching);
}
}
else {
this.render_simple(block, parent_node, parent_nodes, dynamic, vars, detaching);
if (has_outros) {
block.chunks.outro.push(b `@transition_out(${name});`);
}
}
if (if_exists_condition) {
block.chunks.create.push(b `if (${if_exists_condition}) ${name}.c();`);
}
else {
block.chunks.create.push(b `${name}.c();`);
}
if (parent_nodes && this.renderer.options.hydratable) {
if (if_exists_condition) {
block.chunks.claim.push(b `if (${if_exists_condition}) ${name}.l(${parent_nodes});`);
}
else {
block.chunks.claim.push(b `${name}.l(${parent_nodes});`);
}
}
if (has_intros || has_outros) {
block.chunks.intro.push(b `@transition_in(${name});`);
}
if (needs_anchor) {
block.add_element(anchor, x `@empty()`, parent_nodes && x `@empty()`, parent_node);
}
this.branches.forEach(branch => {
branch.fragment.render(branch.block, null, x `#nodes`);
});
}
render_compound(block, parent_node, _parent_nodes, dynamic, { name, anchor, has_else, if_exists_condition, has_transitions }, detaching) {
const select_block_type = this.renderer.component.get_unique_name(`select_block_type`);
const current_block_type = block.get_unique_name(`current_block_type`);
const get_block = has_else
? x `${current_block_type}(#ctx)`
: x `${current_block_type} && ${current_block_type}(#ctx)`;
if (this.needs_update) {
block.chunks.init.push(b `
function ${select_block_type}(#ctx, #dirty) {
${this.branches.map(({ dependencies, condition, snippet, block }) => condition
? b `
${snippet && (dependencies.length > 0
? b `if (${condition} == null || ${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}`
: b `if (${condition} == null) ${condition} = !!${snippet}`)}
if (${condition}) return ${block.name};`
: b `return ${block.name};`)}
}
`);
}
else {
block.chunks.init.push(b `
function ${select_block_type}(#ctx, #dirty) {
${this.branches.map(({ condition, snippet, block }) => condition
? b `if (${snippet || condition}) return ${block.name};`
: b `return ${block.name};`)}
}
`);
}
block.chunks.init.push(b `
let ${current_block_type} = ${select_block_type}(#ctx, ${this.get_initial_dirty_bit()});
let ${name} = ${get_block};
`);
const initial_mount_node = parent_node || '#target';
const anchor_node = parent_node ? 'null' : '#anchor';
if (if_exists_condition) {
block.chunks.mount.push(b `if (${if_exists_condition}) ${name}.m(${initial_mount_node}, ${anchor_node});`);
}
else {
block.chunks.mount.push(b `${name}.m(${initial_mount_node}, ${anchor_node});`);
}
if (this.needs_update) {
const update_mount_node = this.get_update_mount_node(anchor);
const change_block = b `
${if_exists_condition ? b `if (${if_exists_condition}) ${name}.d(1)` : b `${name}.d(1)`};
${name} = ${get_block};
if (${name}) {
${name}.c();
${has_transitions && b `@transition_in(${name}, 1);`}
${name}.m(${update_mount_node}, ${anchor});
}
`;
if (dynamic) {
block.chunks.update.push(b `
if (${current_block_type} === (${current_block_type} = ${select_block_type}(#ctx, #dirty)) && ${name}) {
${name}.p(#ctx, #dirty);
} else {
${change_block}
}
`);
}
else {
block.chunks.update.push(b `
if (${current_block_type} !== (${current_block_type} = ${select_block_type}(#ctx, #dirty))) {
${change_block}
}
`);
}
}
else if (dynamic) {
if (if_exists_condition) {
block.chunks.update.push(b `if (${if_exists_condition}) ${name}.p(#ctx, #dirty);`);
}
else {
block.chunks.update.push(b `${name}.p(#ctx, #dirty);`);
}
}
if (if_exists_condition) {
block.chunks.destroy.push(b `
if (${if_exists_condition}) {
${name}.d(${detaching});
}
`);
}
else {
block.chunks.destroy.push(b `
${name}.d(${detaching});
`);
}
}
// if any of the siblings have outros, we need to keep references to the blocks
// (TODO does this only apply to bidi transitions?)
render_compound_with_outros(block, parent_node, _parent_nodes, dynamic, { name, anchor, has_else, has_transitions, if_exists_condition }, detaching) {
const select_block_type = this.renderer.component.get_unique_name(`select_block_type`);
const current_block_type_index = block.get_unique_name(`current_block_type_index`);
const previous_block_index = block.get_unique_name(`previous_block_index`);
const if_block_creators = block.get_unique_name(`if_block_creators`);
const if_blocks = block.get_unique_name(`if_blocks`);
const if_current_block_type_index = has_else
? nodes => nodes
: nodes => b `if (~${current_block_type_index}) { ${nodes} }`;
block.add_variable(current_block_type_index);
block.add_variable(name);
block.chunks.init.push(b `
const ${if_block_creators} = [
${this.branches.map(branch => branch.block.name)}
];
const ${if_blocks} = [];
${this.needs_update
? b `
function ${select_block_type}(#ctx, #dirty) {
${this.branches.map(({ dependencies, condition, snippet }, i) => condition
? b `
${snippet && (dependencies.length > 0
? b `if (${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}`
: b `if (${condition} == null) ${condition} = !!${snippet}`)}
if (${condition}) return ${i};`
: b `return ${i};`)}
${!has_else && b `return -1;`}
}
`
: b `
function ${select_block_type}(#ctx, #dirty) {
${this.branches.map(({ condition, snippet }, i) => condition
? b `if (${snippet || condition}) return ${i};`
: b `return ${i};`)}
${!has_else && b `return -1;`}
}
`}
`);
if (has_else) {
block.chunks.init.push(b `
${current_block_type_index} = ${select_block_type}(#ctx, ${this.get_initial_dirty_bit()});
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#ctx);
`);
}
else {
block.chunks.init.push(b `
if (~(${current_block_type_index} = ${select_block_type}(#ctx, ${this.get_initial_dirty_bit()}))) {
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#ctx);
}
`);
}
const initial_mount_node = parent_node || '#target';
const anchor_node = parent_node ? 'null' : '#anchor';
block.chunks.mount.push(if_current_block_type_index(b `${if_blocks}[${current_block_type_index}].m(${initial_mount_node}, ${anchor_node});`));
if (this.needs_update) {
const update_mount_node = this.get_update_mount_node(anchor);
const destroy_old_block = b `
@group_outros();
@transition_out(${if_blocks}[${previous_block_index}], 1, 1, () => {
${if_blocks}[${previous_block_index}] = null;
});
@check_outros();
`;
const create_new_block = b `
${name} = ${if_blocks}[${current_block_type_index}];
if (!${name}) {
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#ctx);
${name}.c();
}
${has_transitions && b `@transition_in(${name}, 1);`}
${name}.m(${update_mount_node}, ${anchor});
`;
const change_block = has_else
? b `
${destroy_old_block}
${create_new_block}
`
: b `
if (${name}) {
${destroy_old_block}
}
if (~${current_block_type_index}) {
${create_new_block}
} else {
${name} = null;
}
`;
if (dynamic) {
block.chunks.update.push(b `
let ${previous_block_index} = ${current_block_type_index};
${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
if (${current_block_type_index} === ${previous_block_index}) {
${if_current_block_type_index(b `${if_blocks}[${current_block_type_index}].p(#ctx, #dirty);`)}
} else {
${change_block}
}
`);
}
else {
block.chunks.update.push(b `
let ${previous_block_index} = ${current_block_type_index};
${current_block_type_index} = ${select_block_type}(#ctx, #dirty);
if (${current_block_type_index} !== ${previous_block_index}) {
${change_block}
}
`);
}
}
else if (dynamic) {
if (if_exists_condition) {
block.chunks.update.push(b `if (${if_exists_condition}) ${name}.p(#ctx, #dirty);`);
}
else {
block.chunks.update.push(b `${name}.p(#ctx, #dirty);`);
}
}
block.chunks.destroy.push(if_current_block_type_index(b `${if_blocks}[${current_block_type_index}].d(${detaching});`));
}
render_simple(block, parent_node, _parent_nodes, dynamic, { name, anchor, if_exists_condition, has_transitions }, detaching) {
const branch = this.branches[0];
if (branch.snippet)
block.add_variable(branch.condition, branch.snippet);
block.chunks.init.push(b `
let ${name} = ${branch.condition} && ${branch.block.name}(#ctx);
`);
const initial_mount_node = parent_node || '#target';
const anchor_node = parent_node ? 'null' : '#anchor';
block.chunks.mount.push(b `if (${name}) ${name}.m(${initial_mount_node}, ${anchor_node});`);
if (branch.dependencies.length > 0) {
const update_mount_node = this.get_update_mount_node(anchor);
const enter = b `
if (${name}) {
${dynamic && b `${name}.p(#ctx, #dirty);`}
${has_transitions &&
b `if (${block.renderer.dirty(branch.dependencies)}) {
@transition_in(${name}, 1);
}`}
} else {
${name} = ${branch.block.name}(#ctx);
${name}.c();
${has_transitions && b `@transition_in(${name}, 1);`}
${name}.m(${update_mount_node}, ${anchor});
}
`;
if (branch.snippet) {
block.chunks.update.push(b `if (${block.renderer.dirty(branch.dependencies)}) ${branch.condition} = ${branch.snippet}`);
}
// no `p()` here — we don't want to update outroing nodes,
// as that will typically result in glitching
if (branch.block.has_outro_method) {
block.chunks.update.push(b `
if (${branch.condition}) {
${enter}
} else if (${name}) {
@group_outros();
@transition_out(${name}, 1, 1, () => {
${name} = null;
});
@check_outros();
}
`);
}
else {
block.chunks.update.push(b `
if (${branch.condition}) {
${enter}
} else if (${name}) {
${name}.d(1);
${name} = null;
}
`);
}
}
else if (dynamic) {
block.chunks.update.push(b `
if (${branch.condition}) ${name}.p(#ctx, #dirty);
`);
}
if (if_exists_condition) {
block.chunks.destroy.push(b `
if (${if_exists_condition}) ${name}.d(${detaching});
`);
}
else {
block.chunks.destroy.push(b `
${name}.d(${detaching});
`);
}
}
get_initial_dirty_bit() {
const _this = this;
// TODO: context-overflow make it less gross
const val = x `-1`;
return {
get type() {
return _this.renderer.context_overflow ? 'ArrayExpression' : 'UnaryExpression';
},
// as [-1]
elements: [val],
// as -1
operator: val.operator,
prefix: val.prefix,
argument: val.argument,
};
}
}
class InlineComponentWrapper extends Wrapper {
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.slots = new Map();
this.cannot_use_innerhtml();
this.not_static_content();
if (this.node.expression) {
block.add_dependencies(this.node.expression.dependencies);
}
this.node.attributes.forEach(attr => {
block.add_dependencies(attr.dependencies);
});
this.node.bindings.forEach(binding => {
if (binding.is_contextual) {
mark_each_block_bindings(this, binding);
}
block.add_dependencies(binding.expression.dependencies);
});
this.node.handlers.forEach(handler => {
if (handler.expression) {
block.add_dependencies(handler.expression.dependencies);
}
});
this.var = {
type: 'Identifier',
name: (this.node.name === 'svelte:self' ? renderer.component.name.name :
this.node.name === 'svelte:component' ? 'switch_instance' :
sanitize(this.node.name)).toLowerCase()
};
if (this.node.children.length) {
this.node.lets.forEach(l => {
extract_names(l.value || l.name).forEach(name => {
renderer.add_to_context(name, true);
});
});
const default_slot = block.child({
comment: create_debugging_comment(node, renderer.component),
name: renderer.component.get_unique_name(`create_default_slot`),
type: 'slot'
});
this.renderer.blocks.push(default_slot);
this.slots.set('default', get_slot_definition(default_slot, this.node.scope, this.node.lets));
this.fragment = new FragmentWrapper(renderer, default_slot, node.children, this, strip_whitespace, next_sibling);
const dependencies = new Set();
// TODO is this filtering necessary? (I *think* so)
default_slot.dependencies.forEach(name => {
if (!this.node.scope.is_let(name)) {
dependencies.add(name);
}
});
block.add_dependencies(dependencies);
}
block.add_outro();
}
warn_if_reactive() {
const { name } = this.node;
const variable = this.renderer.component.var_lookup.get(name);
if (!variable) {
return;
}
if (variable.reassigned || variable.export_name || variable.is_reactive_dependency) {
this.renderer.component.warn(this.node, {
code: 'reactive-component',
message: `<${name}/> will not be reactive if ${name} changes. Use <svelte:component this={${name}}/> if you want this reactivity.`,
});
}
}
render(block, parent_node, parent_nodes) {
this.warn_if_reactive();
const { renderer } = this;
const { component } = renderer;
const name = this.var;
block.add_variable(name);
const component_opts = x `{}`;
const statements = [];
const updates = [];
if (this.fragment) {
this.renderer.add_to_context('$$scope', true);
const default_slot = this.slots.get('default');
this.fragment.nodes.forEach((child) => {
child.render(default_slot.block, null, x `#nodes`);
});
}
let props;
const name_changes = block.get_unique_name(`${name.name}_changes`);
const uses_spread = !!this.node.attributes.find(a => a.is_spread);
// removing empty slot
for (const slot of this.slots.keys()) {
if (!this.slots.get(slot).block.has_content()) {
this.renderer.remove_block(this.slots.get(slot).block);
this.slots.delete(slot);
}
}
const initial_props = this.slots.size > 0
? [
p `$$slots: {
${Array.from(this.slots).map(([name, slot]) => {
return p `${name}: [${slot.block.name}, ${slot.get_context || null}, ${slot.get_changes || null}]`;
})}
}`,
p `$$scope: {
ctx: #ctx
}`
]
: [];
const attribute_object = uses_spread
? x `{ ${initial_props} }`
: x `{
${this.node.attributes.map(attr => p `${attr.name}: ${attr.get_value(block)}`)},
${initial_props}
}`;
if (this.node.attributes.length || this.node.bindings.length || initial_props.length) {
if (!uses_spread && this.node.bindings.length === 0) {
component_opts.properties.push(p `props: ${attribute_object}`);
}
else {
props = block.get_unique_name(`${name.name}_props`);
component_opts.properties.push(p `props: ${props}`);
}
}
if (component.compile_options.dev) {
// TODO this is a terrible hack, but without it the component
// will complain that options.target is missing. This would
// work better if components had separate public and private
// APIs
component_opts.properties.push(p `$$inline: true`);
}
const fragment_dependencies = new Set(this.fragment ? ['$$scope'] : []);
this.slots.forEach(slot => {
slot.block.dependencies.forEach(name => {
const is_let = slot.scope.is_let(name);
const variable = renderer.component.var_lookup.get(name);
if (is_let || is_dynamic$1(variable))
fragment_dependencies.add(name);
});
});
const dynamic_attributes = this.node.attributes.filter(a => a.get_dependencies().length > 0);
if (!uses_spread && (dynamic_attributes.length > 0 || this.node.bindings.length > 0 || fragment_dependencies.size > 0)) {
updates.push(b `const ${name_changes} = {};`);
}
if (this.node.attributes.length) {
if (uses_spread) {
const levels = block.get_unique_name(`${this.var.name}_spread_levels`);
const initial_props = [];
const changes = [];
const all_dependencies = new Set();
this.node.attributes.forEach(attr => {
add_to_set(all_dependencies, attr.dependencies);
});
this.node.attributes.forEach((attr, i) => {
const { name, dependencies } = attr;
const condition = dependencies.size > 0 && (dependencies.size !== all_dependencies.size)
? renderer.dirty(Array.from(dependencies))
: null;
const unchanged = dependencies.size === 0;
let change_object;
if (attr.is_spread) {
const value = attr.expression.manipulate(block);
initial_props.push(value);
let value_object = value;
if (attr.expression.node.type !== 'ObjectExpression') {
value_object = x `@get_spread_object(${value})`;
}
change_object = value_object;
}
else {
const obj = x `{ ${name}: ${attr.get_value(block)} }`;
initial_props.push(obj);
change_object = obj;
}
changes.push(unchanged
? x `${levels}[${i}]`
: condition
? x `${condition} && ${change_object}`
: change_object);
});
block.chunks.init.push(b `
const ${levels} = [
${initial_props}
];
`);
statements.push(b `
for (let #i = 0; #i < ${levels}.length; #i += 1) {
${props} = @assign(${props}, ${levels}[#i]);
}
`);
if (all_dependencies.size) {
const condition = renderer.dirty(Array.from(all_dependencies));
updates.push(b `
const ${name_changes} = ${condition} ? @get_spread_update(${levels}, [
${changes}
]) : {}
`);
}
else {
updates.push(b `
const ${name_changes} = {};
`);
}
}
else {
dynamic_attributes.forEach((attribute) => {
const dependencies = attribute.get_dependencies();
if (dependencies.length > 0) {
const condition = renderer.dirty(dependencies);
updates.push(b `
if (${condition}) ${name_changes}.${attribute.name} = ${attribute.get_value(block)};
`);
}
});
}
}
if (fragment_dependencies.size > 0) {
updates.push(b `
if (${renderer.dirty(Array.from(fragment_dependencies))}) {
${name_changes}.$$scope = { dirty: #dirty, ctx: #ctx };
}`);
}
const munged_bindings = this.node.bindings.map(binding => {
component.has_reactive_assignments = true;
if (binding.name === 'this') {
return bind_this(component, block, new BindingWrapper(block, binding, this), this.var);
}
const id = component.get_unique_name(`${this.var.name}_${binding.name}_binding`);
renderer.add_to_context(id.name);
const callee = renderer.reference(id);
const updating = block.get_unique_name(`updating_${binding.name}`);
block.add_variable(updating);
const snippet = binding.expression.manipulate(block);
statements.push(b `
if (${snippet} !== void 0) {
${props}.${binding.name} = ${snippet};
}`);
updates.push(b `
if (!${updating} && ${renderer.dirty(Array.from(binding.expression.dependencies))}) {
${updating} = true;
${name_changes}.${binding.name} = ${snippet};
@add_flush_callback(() => ${updating} = false);
}
`);
const contextual_dependencies = Array.from(binding.expression.contextual_dependencies);
const dependencies = Array.from(binding.expression.dependencies);
let lhs = binding.raw_expression;
if (binding.is_contextual && binding.expression.node.type === 'Identifier') {
// bind:x={y} — we can't just do `y = x`, we need to
// to `array[index] = x;
const { name } = binding.expression.node;
const { object, property, snippet } = block.bindings.get(name);
lhs = snippet;
contextual_dependencies.push(object.name, property.name);
}
const params = [x `#value`];
if (contextual_dependencies.length > 0) {
const args = [];
contextual_dependencies.forEach(name => {
params.push({
type: 'Identifier',
name
});
renderer.add_to_context(name, true);
args.push(renderer.reference(name));
});
block.chunks.init.push(b `
function ${id}(#value) {
${callee}.call(null, #value, ${args});
}
`);
block.maintain_context = true; // TODO put this somewhere more logical
}
else {
block.chunks.init.push(b `
function ${id}(#value) {
${callee}.call(null, #value);
}
`);
}
const body = b `
function ${id}(${params}) {
${lhs} = #value;
${renderer.invalidate(dependencies[0])};
}
`;
component.partly_hoisted.push(body);
return b `@binding_callbacks.push(() => @bind(${this.var}, '${binding.name}', ${id}));`;
});
const munged_handlers = this.node.handlers.map(handler => {
const event_handler = new EventHandlerWrapper(handler, this);
let snippet = event_handler.get_snippet(block);
if (handler.modifiers.has('once'))
snippet = x `@once(${snippet})`;
return b `${name}.$on("${handler.name}", ${snippet});`;
});
if (this.node.name === 'svelte:component') {
const switch_value = block.get_unique_name('switch_value');
const switch_props = block.get_unique_name('switch_props');
const snippet = this.node.expression.manipulate(block);
block.chunks.init.push(b `
var ${switch_value} = ${snippet};
function ${switch_props}(#ctx) {
${(this.node.attributes.length > 0 || this.node.bindings.length > 0) && b `
${props && b `let ${props} = ${attribute_object};`}`}
${statements}
return ${component_opts};
}
if (${switch_value}) {
${name} = new ${switch_value}(${switch_props}(#ctx));
${munged_bindings}
${munged_handlers}
}
`);
block.chunks.create.push(b `if (${name}) @create_component(${name}.$$.fragment);`);
if (parent_nodes && this.renderer.options.hydratable) {
block.chunks.claim.push(b `if (${name}) @claim_component(${name}.$$.fragment, ${parent_nodes});`);
}
block.chunks.mount.push(b `
if (${name}) {
@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});
}
`);
const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes);
const update_mount_node = this.get_update_mount_node(anchor);
if (updates.length) {
block.chunks.update.push(b `
${updates}
`);
}
block.chunks.update.push(b `
if (${switch_value} !== (${switch_value} = ${snippet})) {
if (${name}) {
@group_outros();
const old_component = ${name};
@transition_out(old_component.$$.fragment, 1, 0, () => {
@destroy_component(old_component, 1);
});
@check_outros();
}
if (${switch_value}) {
${name} = new ${switch_value}(${switch_props}(#ctx));
${munged_bindings}
${munged_handlers}
@create_component(${name}.$$.fragment);
@transition_in(${name}.$$.fragment, 1);
@mount_component(${name}, ${update_mount_node}, ${anchor});
} else {
${name} = null;
}
} else if (${switch_value}) {
${updates.length > 0 && b `${name}.$set(${name_changes});`}
}
`);
block.chunks.intro.push(b `
if (${name}) @transition_in(${name}.$$.fragment, #local);
`);
block.chunks.outro.push(b `if (${name}) @transition_out(${name}.$$.fragment, #local);`);
block.chunks.destroy.push(b `if (${name}) @destroy_component(${name}, ${parent_node ? null : 'detaching'});`);
}
else {
const expression = this.node.name === 'svelte:self'
? component.name
: this.renderer.reference(this.node.name);
block.chunks.init.push(b `
${(this.node.attributes.length > 0 || this.node.bindings.length > 0) && b `
${props && b `let ${props} = ${attribute_object};`}`}
${statements}
${name} = new ${expression}(${component_opts});
${munged_bindings}
${munged_handlers}
`);
block.chunks.create.push(b `@create_component(${name}.$$.fragment);`);
if (parent_nodes && this.renderer.options.hydratable) {
block.chunks.claim.push(b `@claim_component(${name}.$$.fragment, ${parent_nodes});`);
}
block.chunks.mount.push(b `@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});`);
block.chunks.intro.push(b `
@transition_in(${name}.$$.fragment, #local);
`);
if (updates.length) {
block.chunks.update.push(b `
${updates}
${name}.$set(${name_changes});
`);
}
block.chunks.destroy.push(b `
@destroy_component(${name}, ${parent_node ? null : 'detaching'});
`);
block.chunks.outro.push(b `@transition_out(${name}.$$.fragment, #local);`);
}
}
}
function get_slot_data(values, block = null) {
return {
type: 'ObjectExpression',
properties: Array.from(values.values())
.filter(attribute => attribute.name !== 'name')
.map(attribute => {
const value = get_value(block, attribute);
return p `${attribute.name}: ${value}`;
})
};
}
function get_value(block, attribute) {
if (attribute.is_true)
return x `true`;
if (attribute.chunks.length === 0)
return x `""`;
let value = attribute.chunks
.map(chunk => chunk.type === 'Text' ? string_literal(chunk.data) : (block ? chunk.manipulate(block) : chunk.node))
.reduce((lhs, rhs) => x `${lhs} + ${rhs}`);
if (attribute.chunks.length > 1 && attribute.chunks[0].type !== 'Text') {
value = x `"" + ${value}`;
}
return value;
}
class SlotWrapper extends Wrapper {
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
super(renderer, block, parent, node);
this.fallback = null;
this.var = { type: 'Identifier', name: 'slot' };
this.dependencies = new Set(['$$scope']);
this.cannot_use_innerhtml();
this.not_static_content();
if (this.node.children.length) {
this.fallback = block.child({
comment: create_debugging_comment(this.node.children[0], this.renderer.component),
name: this.renderer.component.get_unique_name(`fallback_block`),
type: 'fallback'
});
renderer.blocks.push(this.fallback);
}
this.fragment = new FragmentWrapper(renderer, this.fallback, node.children, this, strip_whitespace, next_sibling);
this.node.values.forEach(attribute => {
add_to_set(this.dependencies, attribute.dependencies);
});
block.add_dependencies(this.dependencies);
// we have to do this, just in case
block.add_intro();
block.add_outro();
}
render(block, parent_node, parent_nodes) {
const { renderer } = this;
const { slot_name } = this.node;
let get_slot_changes_fn;
let get_slot_context_fn;
if (this.node.values.size > 0) {
get_slot_changes_fn = renderer.component.get_unique_name(`get_${sanitize(slot_name)}_slot_changes`);
get_slot_context_fn = renderer.component.get_unique_name(`get_${sanitize(slot_name)}_slot_context`);
const changes = x `{}`;
const dependencies = new Set();
this.node.values.forEach(attribute => {
attribute.chunks.forEach(chunk => {
if (chunk.dependencies) {
add_to_set(dependencies, chunk.contextual_dependencies);
// add_to_set(dependencies, (chunk as Expression).dependencies);
chunk.dependencies.forEach(name => {
const variable = renderer.component.var_lookup.get(name);
if (variable && !variable.hoistable)
dependencies.add(name);
});
}
});
const dynamic_dependencies = Array.from(attribute.dependencies).filter((name) => this.is_dependency_dynamic(name));
if (dynamic_dependencies.length > 0) {
changes.properties.push(p `${attribute.name}: ${renderer.dirty(dynamic_dependencies)}`);
}
});
renderer.blocks.push(b `
const ${get_slot_changes_fn} = #dirty => ${changes};
const ${get_slot_context_fn} = #ctx => ${get_slot_data(this.node.values, block)};
`);
}
else {
get_slot_changes_fn = 'null';
get_slot_context_fn = 'null';
}
let has_fallback = !!this.fallback;
if (this.fallback) {
this.fragment.render(this.fallback, null, x `#nodes`);
has_fallback = this.fallback.has_content();
if (!has_fallback) {
renderer.remove_block(this.fallback);
}
}
const slot = block.get_unique_name(`${sanitize(slot_name)}_slot`);
const slot_definition = block.get_unique_name(`${sanitize(slot_name)}_slot_template`);
const slot_or_fallback = has_fallback ? block.get_unique_name(`${sanitize(slot_name)}_slot_or_fallback`) : slot;
block.chunks.init.push(b `
const ${slot_definition} = ${renderer.reference('$$slots')}.${slot_name};
const ${slot} = @create_slot(${slot_definition}, #ctx, ${renderer.reference('$$scope')}, ${get_slot_context_fn});
${has_fallback ? b `const ${slot_or_fallback} = ${slot} || ${this.fallback.name}(#ctx);` : null}
`);
block.chunks.create.push(b `if (${slot_or_fallback}) ${slot_or_fallback}.c();`);
if (renderer.options.hydratable) {
block.chunks.claim.push(b `if (${slot_or_fallback}) ${slot_or_fallback}.l(${parent_nodes});`);
}
block.chunks.mount.push(b `
if (${slot_or_fallback}) {
${slot_or_fallback}.m(${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});
}
`);
block.chunks.intro.push(b `@transition_in(${slot_or_fallback}, #local);`);
block.chunks.outro.push(b `@transition_out(${slot_or_fallback}, #local);`);
const dynamic_dependencies = Array.from(this.dependencies).filter((name) => this.is_dependency_dynamic(name));
const fallback_dynamic_dependencies = has_fallback
? Array.from(this.fallback.dependencies).filter((name) => this.is_dependency_dynamic(name))
: [];
const slot_update = b `
if (${slot}.p && ${renderer.dirty(dynamic_dependencies)}) {
@update_slot(${slot}, ${slot_definition}, #ctx, ${renderer.reference('$$scope')}, #dirty, ${get_slot_changes_fn}, ${get_slot_context_fn});
}
`;
const fallback_update = has_fallback && fallback_dynamic_dependencies.length > 0 && b `
if (${slot_or_fallback} && ${slot_or_fallback}.p && ${renderer.dirty(fallback_dynamic_dependencies)}) {
${slot_or_fallback}.p(#ctx, #dirty);
}
`;
if (fallback_update) {
block.chunks.update.push(b `
if (${slot}) {
${slot_update}
} else {
${fallback_update}
}
`);
}
else {
block.chunks.update.push(b `
if (${slot}) {
${slot_update}
}
`);
}
block.chunks.destroy.push(b `if (${slot_or_fallback}) ${slot_or_fallback}.d(detaching);`);
}
is_dependency_dynamic(name) {
if (name === '$$scope')
return true;
if (this.node.scope.is_let(name))
return true;
if (is_reserved_keyword(name))
return true;
const variable = this.renderer.component.var_lookup.get(name);
return is_dynamic$1(variable);
}
}
class TitleWrapper extends Wrapper {
constructor(renderer, block, parent, node, _strip_whitespace, _next_sibling) {
super(renderer, block, parent, node);
}
render(block, _parent_node, _parent_nodes) {
const is_dynamic = !!this.node.children.find(node => node.type !== 'Text');
if (is_dynamic) {
let value;
const all_dependencies = new Set();
// TODO some of this code is repeated in Tag.ts — would be good to
// DRY it out if that's possible without introducing crazy indirection
if (this.node.children.length === 1) {
// single {tag} — may be a non-string
// @ts-ignore todo: check this
const { expression } = this.node.children[0];
value = expression.manipulate(block);
add_to_set(all_dependencies, expression.dependencies);
}
else {
// '{foo} {bar}' — treat as string concatenation
value = this.node.children
.map(chunk => {
if (chunk.type === 'Text')
return string_literal(chunk.data);
chunk.expression.dependencies.forEach(d => {
all_dependencies.add(d);
});
return chunk.expression.manipulate(block);
})
.reduce((lhs, rhs) => x `${lhs} + ${rhs}`);
if (this.node.children[0].type !== 'Text') {
value = x `"" + ${value}`;
}
}
const last = this.node.should_cache && block.get_unique_name(`title_value`);
if (this.node.should_cache)
block.add_variable(last);
const init = this.node.should_cache ? x `${last} = ${value}` : value;
block.chunks.init.push(b `@_document.title = ${init};`);
const updater = b `@_document.title = ${this.node.should_cache ? last : value};`;
if (all_dependencies.size) {
const dependencies = Array.from(all_dependencies);
let condition = block.renderer.dirty(dependencies);
if (block.has_outros) {
condition = x `!#current || ${condition}`;
}
if (this.node.should_cache) {
condition = x `${condition} && (${last} !== (${last} = ${value}))`;
}
block.chunks.update.push(b `
if (${condition}) {
${updater}
}`);
}
}
else {
const value = this.node.children.length > 0
? string_literal(this.node.children[0].data)
: x `""`;
block.chunks.hydrate.push(b `@_document.title = ${value};`);
}
}
}
const associated_events = {
innerWidth: 'resize',
innerHeight: 'resize',
outerWidth: 'resize',
outerHeight: 'resize',
scrollX: 'scroll',
scrollY: 'scroll',
};
const properties = {
scrollX: 'pageXOffset',
scrollY: 'pageYOffset'
};
const readonly = new Set([
'innerWidth',
'innerHeight',
'outerWidth',
'outerHeight',
'online',
]);
class WindowWrapper extends Wrapper {
constructor(renderer, block, parent, node) {
super(renderer, block, parent, node);
this.handlers = this.node.handlers.map(handler => new EventHandlerWrapper(handler, this));
}
render(block, _parent_node, _parent_nodes) {
const { renderer } = this;
const { component } = renderer;
const events = {};
const bindings = {};
add_actions(block, '@_window', this.node.actions);
add_event_handlers(block, '@_window', this.handlers);
this.node.bindings.forEach(binding => {
// in dev mode, throw if read-only values are written to
if (readonly.has(binding.name)) {
renderer.readonly.add(binding.expression.node.name);
}
bindings[binding.name] = binding.expression.node.name;
// bind:online is a special case, we need to listen for two separate events
if (binding.name === 'online')
return;
const associated_event = associated_events[binding.name];
const property = properties[binding.name] || binding.name;
if (!events[associated_event])
events[associated_event] = [];
events[associated_event].push({
name: binding.expression.node.name,
value: property
});
});
const scrolling = block.get_unique_name(`scrolling`);
const clear_scrolling = block.get_unique_name(`clear_scrolling`);
const scrolling_timeout = block.get_unique_name(`scrolling_timeout`);
Object.keys(events).forEach(event => {
const id = block.get_unique_name(`onwindow${event}`);
const props = events[event];
renderer.add_to_context(id.name);
const fn = renderer.reference(id.name);
if (event === 'scroll') {
// TODO other bidirectional bindings...
block.add_variable(scrolling, x `false`);
block.add_variable(clear_scrolling, x `() => { ${scrolling} = false }`);
block.add_variable(scrolling_timeout);
const condition = bindings.scrollX && bindings.scrollY
? x `"${bindings.scrollX}" in this._state || "${bindings.scrollY}" in this._state`
: x `"${bindings.scrollX || bindings.scrollY}" in this._state`;
const scrollX = bindings.scrollX && x `this._state.${bindings.scrollX}`;
const scrollY = bindings.scrollY && x `this._state.${bindings.scrollY}`;
renderer.meta_bindings.push(b `
if (${condition}) {
@_scrollTo(${scrollX || '@_window.pageXOffset'}, ${scrollY || '@_window.pageYOffset'});
}
${scrollX && `${scrollX} = @_window.pageXOffset;`}
${scrollY && `${scrollY} = @_window.pageYOffset;`}
`);
block.event_listeners.push(x `
@listen(@_window, "${event}", () => {
${scrolling} = true;
@_clearTimeout(${scrolling_timeout});
${scrolling_timeout} = @_setTimeout(${clear_scrolling}, 100);
${fn}();
})
`);
}
else {
props.forEach(prop => {
renderer.meta_bindings.push(b `this._state.${prop.name} = @_window.${prop.value};`);
});
block.event_listeners.push(x `
@listen(@_window, "${event}", ${fn})
`);
}
component.partly_hoisted.push(b `
function ${id}() {
${props.map(prop => renderer.invalidate(prop.name, x `${prop.name} = @_window.${prop.value}`))}
}
`);
block.chunks.init.push(b `
@add_render_callback(${fn});
`);
component.has_reactive_assignments = true;
});
// special case... might need to abstract this out if we add more special cases
if (bindings.scrollX || bindings.scrollY) {
const condition = renderer.dirty([bindings.scrollX, bindings.scrollY].filter(Boolean));
const scrollX = bindings.scrollX ? renderer.reference(bindings.scrollX) : x `@_window.pageXOffset`;
const scrollY = bindings.scrollY ? renderer.reference(bindings.scrollY) : x `@_window.pageYOffset`;
block.chunks.update.push(b `
if (${condition} && !${scrolling}) {
${scrolling} = true;
@_clearTimeout(${scrolling_timeout});
@_scrollTo(${scrollX}, ${scrollY});
${scrolling_timeout} = @_setTimeout(${clear_scrolling}, 100);
}
`);
}
// another special case. (I'm starting to think these are all special cases.)
if (bindings.online) {
const id = block.get_unique_name(`onlinestatuschanged`);
const name = bindings.online;
renderer.add_to_context(id.name);
const reference = renderer.reference(id.name);
component.partly_hoisted.push(b `
function ${id}() {
${renderer.invalidate(name, x `${name} = @_navigator.onLine`)}
}
`);
block.chunks.init.push(b `
@add_render_callback(${reference});
`);
block.event_listeners.push(x `@listen(@_window, "online", ${reference})`, x `@listen(@_window, "offline", ${reference})`);
component.has_reactive_assignments = true;
}
}
}
function link(next, prev) {
prev.next = next;
if (next)
next.prev = prev;
}
const wrappers = {
AwaitBlock: AwaitBlockWrapper,
Body: BodyWrapper,
Comment: null,
DebugTag: DebugTagWrapper,
EachBlock: EachBlockWrapper,
Element: ElementWrapper,
Head: HeadWrapper,
IfBlock: IfBlockWrapper,
InlineComponent: InlineComponentWrapper,
MustacheTag: MustacheTagWrapper,
Options: null,
RawMustacheTag: RawMustacheTagWrapper,
Slot: SlotWrapper,
Text: TextWrapper,
Title: TitleWrapper,
Window: WindowWrapper
};
function trimmable_at(child, next_sibling) {
// Whitespace is trimmable if one of the following is true:
// The child and its sibling share a common nearest each block (not at an each block boundary)
// The next sibling's previous node is an each block
return (next_sibling.node.find_nearest(/EachBlock/) === child.find_nearest(/EachBlock/)) || next_sibling.node.prev.type === 'EachBlock';
}
class FragmentWrapper {
constructor(renderer, block, nodes, parent, strip_whitespace, next_sibling) {
this.nodes = [];
let last_child;
let window_wrapper;
let i = nodes.length;
while (i--) {
const child = nodes[i];
if (!child.type) {
throw new Error(`missing type`);
}
if (!(child.type in wrappers)) {
throw new Error(`TODO implement ${child.type}`);
}
// special case — this is an easy way to remove whitespace surrounding
// <svelte:window/>. lil hacky but it works
if (child.type === 'Window') {
window_wrapper = new WindowWrapper(renderer, block, parent, child);
continue;
}
if (child.type === 'Text') {
let { data } = child;
// We want to remove trailing whitespace inside an element/component/block,
// *unless* there is no whitespace between this node and its next sibling
if (this.nodes.length === 0) {
const should_trim = (next_sibling ? (next_sibling.node.type === 'Text' && /^\s/.test(next_sibling.node.data) && trimmable_at(child, next_sibling)) : !child.has_ancestor('EachBlock'));
if (should_trim) {
data = trim_end(data);
if (!data)
continue;
}
}
// glue text nodes (which could e.g. be separated by comments) together
if (last_child && last_child.node.type === 'Text') {
last_child.data = data + last_child.data;
continue;
}
const wrapper = new TextWrapper(renderer, block, parent, child, data);
if (wrapper.skip)
continue;
this.nodes.unshift(wrapper);
link(last_child, last_child = wrapper);
}
else {
const Wrapper = wrappers[child.type];
if (!Wrapper)
continue;
const wrapper = new Wrapper(renderer, block, parent, child, strip_whitespace, last_child || next_sibling);
this.nodes.unshift(wrapper);
link(last_child, last_child = wrapper);
}
}
if (strip_whitespace) {
const first = this.nodes[0];
if (first && first.node.type === 'Text') {
first.data = trim_start(first.data);
if (!first.data) {
first.var = null;
this.nodes.shift();
if (this.nodes[0]) {
this.nodes[0].prev = null;
}
}
}
}
if (window_wrapper) {
this.nodes.unshift(window_wrapper);
link(last_child, window_wrapper);
}
}
render(block, parent_node, parent_nodes) {
for (let i = 0; i < this.nodes.length; i += 1) {
this.nodes[i].render(block, parent_node, parent_nodes);
}
}
}
class Renderer {
constructor(component, options) {
this.context = [];
this.initial_context = [];
this.context_lookup = new Map();
this.blocks = [];
this.readonly = new Set();
this.meta_bindings = []; // initial values for e.g. window.innerWidth, if there's a <svelte:window> meta tag
this.binding_groups = new Map();
this.component = component;
this.options = options;
this.locate = component.locate; // TODO messy
this.file_var = options.dev && this.component.get_unique_name('file');
component.vars.filter(v => !v.hoistable || (v.export_name && !v.module)).forEach(v => this.add_to_context(v.name));
// ensure store values are included in context
component.vars.filter(v => v.subscribable).forEach(v => this.add_to_context(`$${v.name}`));
reserved_keywords.forEach(keyword => {
if (component.var_lookup.has(keyword)) {
this.add_to_context(keyword);
}
});
if (component.slots.size > 0) {
this.add_to_context('$$scope');
this.add_to_context('$$slots');
}
if (this.binding_groups.size > 0) {
this.add_to_context('$$binding_groups');
}
// main block
this.block = new Block$1({
renderer: this,
name: null,
type: 'component',
key: null,
bindings: new Map(),
dependencies: new Set(),
});
this.block.has_update_method = true;
this.fragment = new FragmentWrapper(this, this.block, component.fragment.children, null, true, null);
// TODO messy
this.blocks.forEach(block => {
if (block instanceof Block$1) {
block.assign_variable_names();
}
});
this.block.assign_variable_names();
this.fragment.render(this.block, null, x `#nodes`);
this.context_overflow = this.context.length > 31;
this.context.forEach(member => {
const { variable } = member;
if (variable) {
member.priority += 2;
if (variable.mutated || variable.reassigned)
member.priority += 4;
// these determine whether variable is included in initial context
// array, so must have the highest priority
if (variable.export_name)
member.priority += 16;
if (variable.referenced)
member.priority += 32;
}
else if (member.is_non_contextual) {
// determine whether variable is included in initial context
// array, so must have the highest priority
member.priority += 8;
}
if (!member.is_contextual) {
member.priority += 1;
}
});
this.context.sort((a, b) => (b.priority - a.priority) || (a.index.value - b.index.value));
this.context.forEach((member, i) => member.index.value = i);
let i = this.context.length;
while (i--) {
const member = this.context[i];
if (member.variable) {
if (member.variable.referenced || member.variable.export_name)
break;
}
else if (member.is_non_contextual) {
break;
}
}
this.initial_context = this.context.slice(0, i + 1);
}
add_to_context(name, contextual = false) {
if (!this.context_lookup.has(name)) {
const member = {
name,
index: { type: 'Literal', value: this.context.length },
is_contextual: false,
is_non_contextual: false,
variable: null,
priority: 0
};
this.context_lookup.set(name, member);
this.context.push(member);
}
const member = this.context_lookup.get(name);
if (contextual) {
member.is_contextual = true;
}
else {
member.is_non_contextual = true;
const variable = this.component.var_lookup.get(name);
member.variable = variable;
}
return member;
}
invalidate(name, value) {
const variable = this.component.var_lookup.get(name);
const member = this.context_lookup.get(name);
if (variable && (variable.subscribable && (variable.reassigned || variable.export_name))) {
return x `${`$$subscribe_${name}`}($$invalidate(${member.index}, ${value || name}))`;
}
if (name[0] === '$' && name[1] !== '$') {
return x `${name.slice(1)}.set(${value || name})`;
}
if (variable && (variable.module || (!variable.referenced &&
!variable.is_reactive_dependency &&
!variable.export_name &&
!name.startsWith('$$')))) {
return value || name;
}
if (value) {
return x `$$invalidate(${member.index}, ${value})`;
}
// if this is a reactive declaration, invalidate dependencies recursively
const deps = new Set([name]);
deps.forEach(name => {
const reactive_declarations = this.component.reactive_declarations.filter(x => x.assignees.has(name));
reactive_declarations.forEach(declaration => {
declaration.dependencies.forEach(name => {
deps.add(name);
});
});
});
// TODO ideally globals etc wouldn't be here in the first place
const filtered = Array.from(deps).filter(n => this.context_lookup.has(n));
if (!filtered.length)
return null;
return filtered
.map(n => x `$$invalidate(${this.context_lookup.get(n).index}, ${n})`)
.reduce((lhs, rhs) => x `${lhs}, ${rhs}`);
}
dirty(names, is_reactive_declaration = false) {
const renderer = this;
const dirty = (is_reactive_declaration
? x `$$self.$$.dirty`
: x `#dirty`);
const get_bitmask = () => {
const bitmask = [];
names.forEach((name) => {
const member = renderer.context_lookup.get(name);
if (!member)
return;
if (member.index.value === -1) {
throw new Error(`unset index`);
}
const value = member.index.value;
const i = (value / 31) | 0;
const n = 1 << (value % 31);
if (!bitmask[i])
bitmask[i] = { n: 0, names: [] };
bitmask[i].n |= n;
bitmask[i].names.push(name);
});
return bitmask;
};
// TODO: context-overflow make it less gross
return {
// Using a ParenthesizedExpression allows us to create
// the expression lazily. TODO would be better if
// context was determined before rendering, so that
// this indirection was unnecessary
type: 'ParenthesizedExpression',
get expression() {
const bitmask = get_bitmask();
if (!bitmask.length) {
return x `${dirty} & /*${names.join(', ')}*/ 0`;
}
if (renderer.context_overflow) {
return bitmask
.map((b, i) => ({ b, i }))
.filter(({ b }) => b)
.map(({ b, i }) => x `${dirty}[${i}] & /*${b.names.join(', ')}*/ ${b.n}`)
.reduce((lhs, rhs) => x `${lhs} | ${rhs}`);
}
return x `${dirty} & /*${names.join(', ')}*/ ${bitmask[0].n}`;
}
};
}
reference(node) {
if (typeof node === 'string') {
node = { type: 'Identifier', name: node };
}
const { name, nodes } = flatten_reference(node);
const member = this.context_lookup.get(name);
// TODO is this correct?
if (this.component.var_lookup.get(name)) {
this.component.add_reference(name);
}
if (member !== undefined) {
const replacement = x `/*${member.name}*/ #ctx[${member.index}]`;
if (nodes[0].loc)
replacement.object.loc = nodes[0].loc;
nodes[0] = replacement;
return nodes.reduce((lhs, rhs) => x `${lhs}.${rhs}`);
}
return node;
}
remove_block(block) {
this.blocks.splice(this.blocks.indexOf(block), 1);
}
}
function dom(component, options) {
const { name } = component;
const renderer = new Renderer(component, options);
const { block } = renderer;
block.has_outro_method = true;
// prevent fragment being created twice (#1063)
if (options.customElement)
block.chunks.create.push(b `this.c = @noop;`);
const body = [];
if (renderer.file_var) {
const file = component.file ? x `"${component.file}"` : x `undefined`;
body.push(b `const ${renderer.file_var} = ${file};`);
}
const css = component.stylesheet.render(options.filename, !options.customElement);
const styles = component.stylesheet.has_styles && options.dev
? `${css.code}\n/*# sourceMappingURL=${css.map.toUrl()} */`
: css.code;
const add_css = component.get_unique_name('add_css');
const should_add_css = (!options.customElement &&
!!styles &&
options.css !== false);
if (should_add_css) {
body.push(b `
function ${add_css}() {
var style = @element("style");
style.id = "${component.stylesheet.id}-style";
style.textContent = "${styles}";
@append(@_document.head, style);
}
`);
}
// fix order
// TODO the deconflicted names of blocks are reversed... should set them here
const blocks = renderer.blocks.slice().reverse();
body.push(...blocks.map(block => {
// TODO this is a horrible mess — renderer.blocks
// contains a mixture of Blocks and Nodes
if (block.render)
return block.render();
return block;
}));
if (options.dev && !options.hydratable) {
block.chunks.claim.push(b `throw new @_Error("options.hydrate only works if the component was compiled with the \`hydratable: true\` option");`);
}
const uses_props = component.var_lookup.has('$$props');
const uses_rest = component.var_lookup.has('$$restProps');
const $$props = uses_props || uses_rest ? `$$new_props` : `$$props`;
const props = component.vars.filter(variable => !variable.module && variable.export_name);
const writable_props = props.filter(variable => variable.writable);
const omit_props_names = component.get_unique_name('omit_props_names');
const compute_rest = x `@compute_rest_props($$props, ${omit_props_names.name})`;
const rest = uses_rest ? b `
const ${omit_props_names.name} = [${props.map(prop => `"${prop.export_name}"`).join(',')}];
let $$restProps = ${compute_rest};
` : null;
const set = (uses_props || uses_rest || writable_props.length > 0 || component.slots.size > 0)
? x `
${$$props} => {
${uses_props && renderer.invalidate('$$props', x `$$props = @assign(@assign({}, $$props), @exclude_internal_props($$new_props))`)}
${uses_rest && !uses_props && x `$$props = @assign(@assign({}, $$props), @exclude_internal_props($$new_props))`}
${uses_rest && renderer.invalidate('$$restProps', x `$$restProps = ${compute_rest}`)}
${writable_props.map(prop => b `if ('${prop.export_name}' in ${$$props}) ${renderer.invalidate(prop.name, x `${prop.name} = ${$$props}.${prop.export_name}`)};`)}
${component.slots.size > 0 &&
b `if ('$$scope' in ${$$props}) ${renderer.invalidate('$$scope', x `$$scope = ${$$props}.$$scope`)};`}
}
`
: null;
const accessors = [];
const not_equal = component.component_options.immutable ? x `@not_equal` : x `@safe_not_equal`;
let dev_props_check;
let inject_state;
let capture_state;
let props_inject;
props.forEach(prop => {
const variable = component.var_lookup.get(prop.name);
if (!variable.writable || component.component_options.accessors) {
accessors.push({
type: 'MethodDefinition',
kind: 'get',
key: { type: 'Identifier', name: prop.export_name },
value: x `function() {
return ${prop.hoistable ? prop.name : x `this.$$.ctx[${renderer.context_lookup.get(prop.name).index}]`}
}`
});
}
else if (component.compile_options.dev) {
accessors.push({
type: 'MethodDefinition',
kind: 'get',
key: { type: 'Identifier', name: prop.export_name },
value: x `function() {
throw new @_Error("<${component.tag}>: Props cannot be read directly from the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'");
}`
});
}
if (component.component_options.accessors) {
if (variable.writable && !renderer.readonly.has(prop.name)) {
accessors.push({
type: 'MethodDefinition',
kind: 'set',
key: { type: 'Identifier', name: prop.export_name },
value: x `function(${prop.name}) {
this.$set({ ${prop.export_name}: ${prop.name} });
@flush();
}`
});
}
else if (component.compile_options.dev) {
accessors.push({
type: 'MethodDefinition',
kind: 'set',
key: { type: 'Identifier', name: prop.export_name },
value: x `function(value) {
throw new @_Error("<${component.tag}>: Cannot set read-only property '${prop.export_name}'");
}`
});
}
}
else if (component.compile_options.dev) {
accessors.push({
type: 'MethodDefinition',
kind: 'set',
key: { type: 'Identifier', name: prop.export_name },
value: x `function(value) {
throw new @_Error("<${component.tag}>: Props cannot be set directly on the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'");
}`
});
}
});
if (component.compile_options.dev) {
// checking that expected ones were passed
const expected = props.filter(prop => prop.writable && !prop.initialised);
if (expected.length) {
dev_props_check = b `
const { ctx: #ctx } = this.$$;
const props = ${options.customElement ? x `this.attributes` : x `options.props || {}`};
${expected.map(prop => b `
if (${renderer.reference(prop.name)} === undefined && !('${prop.export_name}' in props)) {
@_console.warn("<${component.tag}> was created without expected prop '${prop.export_name}'");
}`)}
`;
}
const capturable_vars = component.vars.filter(v => !v.internal && !v.global && !v.name.startsWith('$$'));
if (capturable_vars.length > 0) {
capture_state = x `() => ({ ${capturable_vars.map(prop => p `${prop.name}`)} })`;
}
const injectable_vars = capturable_vars.filter(v => !v.module && v.writable && v.name[0] !== '$');
if (uses_props || injectable_vars.length > 0) {
inject_state = x `
${$$props} => {
${uses_props && renderer.invalidate('$$props', x `$$props = @assign(@assign({}, $$props), $$new_props)`)}
${injectable_vars.map(v => b `if ('${v.name}' in $$props) ${renderer.invalidate(v.name, x `${v.name} = ${$$props}.${v.name}`)};`)}
}
`;
props_inject = b `
if ($$props && "$$inject" in $$props) {
$$self.$inject_state($$props.$$inject);
}
`;
}
}
// instrument assignments
if (component.ast.instance) {
let scope = component.instance_scope;
const map = component.instance_scope_map;
let execution_context = null;
walk(component.ast.instance.content, {
enter(node) {
if (map.has(node)) {
scope = map.get(node);
if (!execution_context && !scope.block) {
execution_context = node;
}
}
else if (!execution_context && node.type === 'LabeledStatement' && node.label.name === '$') {
execution_context = node;
}
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
if (execution_context === node) {
execution_context = null;
}
if (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') {
const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument;
// normally (`a = 1`, `b.c = 2`), there'll be a single name
// (a or b). In destructuring cases (`[d, e] = [e, d]`) there
// may be more, in which case we need to tack the extra ones
// onto the initial function call
const names = new Set(extract_names(assignee));
this.replace(invalidate(renderer, scope, node, names, execution_context === null));
}
}
});
component.rewrite_props(({ name, reassigned, export_name }) => {
const value = `$${name}`;
const i = renderer.context_lookup.get(`$${name}`).index;
const insert = (reassigned || export_name)
? b `${`$$subscribe_${name}`}()`
: b `@component_subscribe($$self, ${name}, #value => $$invalidate(${i}, ${value} = #value))`;
if (component.compile_options.dev) {
return b `@validate_store(${name}, '${name}'); ${insert}`;
}
return insert;
});
}
const args = [x `$$self`];
const has_invalidate = props.length > 0 ||
component.has_reactive_assignments ||
component.slots.size > 0 ||
capture_state ||
inject_state;
if (has_invalidate) {
args.push(x `$$props`, x `$$invalidate`);
}
else if (component.compile_options.dev) {
// $$props arg is still needed for unknown prop check
args.push(x `$$props`);
}
const has_create_fragment = component.compile_options.dev || block.has_content();
if (has_create_fragment) {
body.push(b `
function create_fragment(#ctx) {
${block.get_contents()}
}
`);
}
body.push(b `
${component.extract_javascript(component.ast.module)}
${component.fully_hoisted}
`);
const filtered_props = props.filter(prop => {
const variable = component.var_lookup.get(prop.name);
if (variable.hoistable)
return false;
if (prop.name[0] === '$')
return false;
return true;
});
const reactive_stores = component.vars.filter(variable => variable.name[0] === '$' && variable.name[1] !== '$');
const instance_javascript = component.extract_javascript(component.ast.instance);
const has_definition = (component.compile_options.dev ||
(instance_javascript && instance_javascript.length > 0) ||
filtered_props.length > 0 ||
uses_props ||
component.partly_hoisted.length > 0 ||
renderer.initial_context.length > 0 ||
component.reactive_declarations.length > 0 ||
capture_state ||
inject_state);
const definition = has_definition
? component.alias('instance')
: { type: 'Literal', value: null };
const reactive_store_subscriptions = reactive_stores
.filter(store => {
const variable = component.var_lookup.get(store.name.slice(1));
return !variable || variable.hoistable;
})
.map(({ name }) => b `
${component.compile_options.dev && b `@validate_store(${name.slice(1)}, '${name.slice(1)}');`}
@component_subscribe($$self, ${name.slice(1)}, $$value => $$invalidate(${renderer.context_lookup.get(name).index}, ${name} = $$value));
`);
const resubscribable_reactive_store_unsubscribers = reactive_stores
.filter(store => {
const variable = component.var_lookup.get(store.name.slice(1));
return variable && (variable.reassigned || variable.export_name);
})
.map(({ name }) => b `$$self.$$.on_destroy.push(() => ${`$$unsubscribe_${name.slice(1)}`}());`);
if (has_definition) {
const reactive_declarations = [];
const fixed_reactive_declarations = []; // not really 'reactive' but whatever
component.reactive_declarations.forEach(d => {
const dependencies = Array.from(d.dependencies);
const uses_rest_or_props = !!dependencies.find(n => n === '$$props' || n === '$$restProps');
const writable = dependencies.filter(n => {
const variable = component.var_lookup.get(n);
return variable && (variable.export_name || variable.mutated || variable.reassigned);
});
const condition = !uses_rest_or_props && writable.length > 0 && renderer.dirty(writable, true);
let statement = d.node; // TODO remove label (use d.node.body) if it's not referenced
if (condition)
statement = b `if (${condition}) { ${statement} }`[0];
if (condition || uses_rest_or_props) {
reactive_declarations.push(statement);
}
else {
fixed_reactive_declarations.push(statement);
}
});
const injected = Array.from(component.injected_reactive_declaration_vars).filter(name => {
const variable = component.var_lookup.get(name);
return variable.injected && variable.name[0] !== '$';
});
const reactive_store_declarations = reactive_stores.map(variable => {
const $name = variable.name;
const name = $name.slice(1);
const store = component.var_lookup.get(name);
if (store && (store.reassigned || store.export_name)) {
const unsubscribe = `$$unsubscribe_${name}`;
const subscribe = `$$subscribe_${name}`;
const i = renderer.context_lookup.get($name).index;
return b `let ${$name}, ${unsubscribe} = @noop, ${subscribe} = () => (${unsubscribe}(), ${unsubscribe} = @subscribe(${name}, $$value => $$invalidate(${i}, ${$name} = $$value)), ${name})`;
}
return b `let ${$name};`;
});
let unknown_props_check;
if (component.compile_options.dev && !(uses_props || uses_rest)) {
unknown_props_check = b `
const writable_props = [${writable_props.map(prop => x `'${prop.export_name}'`)}];
@_Object.keys($$props).forEach(key => {
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$') @_console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`);
});
`;
}
const return_value = {
type: 'ArrayExpression',
elements: renderer.initial_context.map(member => ({
type: 'Identifier',
name: member.name
}))
};
body.push(b `
function ${definition}(${args}) {
${rest}
${reactive_store_declarations}
${reactive_store_subscriptions}
${resubscribable_reactive_store_unsubscribers}
${instance_javascript}
${unknown_props_check}
${component.slots.size || component.compile_options.dev ? b `let { $$slots = {}, $$scope } = $$props;` : null}
${component.compile_options.dev && b `@validate_slots('${component.tag}', $$slots, [${[...component.slots.keys()].map(key => `'${key}'`).join(',')}]);`}
${renderer.binding_groups.size > 0 && b `const $$binding_groups = [${[...renderer.binding_groups.keys()].map(_ => x `[]`)}];`}
${component.partly_hoisted}
${set && b `$$self.$$set = ${set};`}
${capture_state && b `$$self.$capture_state = ${capture_state};`}
${inject_state && b `$$self.$inject_state = ${inject_state};`}
${injected.map(name => b `let ${name};`)}
${ /* before reactive declarations */props_inject}
${reactive_declarations.length > 0 && b `
$$self.$$.update = () => {
${reactive_declarations}
};
`}
${fixed_reactive_declarations}
${uses_props && b `$$props = @exclude_internal_props($$props);`}
return ${return_value};
}
`);
}
const prop_indexes = x `{
${props.filter(v => v.export_name && !v.module).map(v => p `${v.export_name}: ${renderer.context_lookup.get(v.name).index}`)}
}`;
let dirty;
if (renderer.context_overflow) {
dirty = x `[]`;
for (let i = 0; i < renderer.context.length; i += 31) {
dirty.elements.push(x `-1`);
}
}
if (options.customElement) {
const declaration = b `
class ${name} extends @SvelteElement {
constructor(options) {
super();
${css.code && b `this.shadowRoot.innerHTML = \`<style>${css.code.replace(/\\/g, '\\\\')}${options.dev ? `\n/*# sourceMappingURL=${css.map.toUrl()} */` : ''}</style>\`;`}
@init(this, { target: this.shadowRoot }, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, ${dirty});
${dev_props_check}
if (options) {
if (options.target) {
@insert(options.target, this, options.anchor);
}
${(props.length > 0 || uses_props || uses_rest) && b `
if (options.props) {
this.$set(options.props);
@flush();
}`}
}
}
}
`[0];
if (props.length > 0) {
declaration.body.body.push({
type: 'MethodDefinition',
kind: 'get',
static: true,
computed: false,
key: { type: 'Identifier', name: 'observedAttributes' },
value: x `function() {
return [${props.map(prop => x `"${prop.export_name}"`)}];
}`
});
}
declaration.body.body.push(...accessors);
body.push(declaration);
if (component.tag != null) {
body.push(b `
@_customElements.define("${component.tag}", ${name});
`);
}
}
else {
const superclass = {
type: 'Identifier',
name: options.dev ? '@SvelteComponentDev' : '@SvelteComponent'
};
const declaration = b `
class ${name} extends ${superclass} {
constructor(options) {
super(${options.dev && `options`});
${should_add_css && b `if (!@_document.getElementById("${component.stylesheet.id}-style")) ${add_css}();`}
@init(this, options, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, ${dirty});
${options.dev && b `@dispatch_dev("SvelteRegisterComponent", { component: this, tagName: "${name.name}", options, id: create_fragment.name });`}
${dev_props_check}
}
}
`[0];
declaration.body.body.push(...accessors);
body.push(declaration);
}
return { js: flatten$1(body, []), css };
}
function flatten$1(nodes, target) {
for (let i = 0; i < nodes.length; i += 1) {
const node = nodes[i];
if (Array.isArray(node)) {
flatten$1(node, target);
}
else {
target.push(node);
}
}
return target;
}
function AwaitBlock (node, renderer, options) {
renderer.push();
renderer.render(node.pending.children, options);
const pending = renderer.pop();
renderer.push();
renderer.render(node.then.children, options);
const then = renderer.pop();
renderer.add_expression(x `
function(__value) {
if (@is_promise(__value)) return ${pending};
return (function(${node.then_node ? node.then_node : ''}) { return ${then}; }(__value));
}(${node.expression.node})
`);
}
function Comment$1 (_node, _renderer, _options) {
// TODO preserve comments
// if (options.preserveComments) {
// renderer.append(`<!--${node.data}-->`);
// }
}
function DebugTag (node, renderer, options) {
if (!options.dev)
return;
const filename = options.filename || null;
const { line, column } = options.locate(node.start + 1);
const obj = x `{
${node.expressions.map(e => p `${e.node.name}`)}
}`;
renderer.add_expression(x `@debug(${filename ? x `"${filename}"` : x `null`}, ${line - 1}, ${column}, ${obj})`);
}
function EachBlock (node, renderer, options) {
const args = [node.context_node];
if (node.index)
args.push({ type: 'Identifier', name: node.index });
renderer.push();
renderer.render(node.children, options);
const result = renderer.pop();
const consequent = x `@each(${node.expression.node}, (${args}) => ${result})`;
if (node.else) {
renderer.push();
renderer.render(node.else.children, options);
const alternate = renderer.pop();
renderer.add_expression(x `${node.expression.node}.length ? ${consequent} : ${alternate}`);
}
else {
renderer.add_expression(consequent);
}
}
function get_class_attribute_value(attribute) {
// handle special case — `class={possiblyUndefined}` with scoped CSS
if (attribute.chunks.length === 2 && attribute.chunks[1].synthetic) {
const value = attribute.chunks[0].node;
return x `@escape(@null_to_empty(${value})) + "${attribute.chunks[1].data}"`;
}
return get_attribute_value(attribute);
}
function get_attribute_value(attribute) {
if (attribute.chunks.length === 0)
return x `""`;
return attribute.chunks
.map((chunk) => {
return chunk.type === 'Text'
? string_literal(chunk.data.replace(/"/g, '&quot;'))
: x `@escape(${chunk.node})`;
})
.reduce((lhs, rhs) => x `${lhs} + ${rhs}`);
}
function get_slot_scope(lets) {
if (lets.length === 0)
return null;
return {
type: 'ObjectPattern',
properties: lets.map(l => {
return {
type: 'Property',
kind: 'init',
method: false,
shorthand: false,
computed: false,
key: l.name,
value: l.value || l.name
};
})
};
}
// source: https://html.spec.whatwg.org/multipage/indices.html
const boolean_attributes = new Set([
'allowfullscreen',
'allowpaymentrequest',
'async',
'autofocus',
'autoplay',
'checked',
'controls',
'default',
'defer',
'disabled',
'formnovalidate',
'hidden',
'ismap',
'loop',
'multiple',
'muted',
'nomodule',
'novalidate',
'open',
'playsinline',
'readonly',
'required',
'reversed',
'selected'
]);
// similar logic from `compile/render_dom/wrappers/Fragment`
// We want to remove trailing whitespace inside an element/component/block,
// *unless* there is no whitespace between this node and its next sibling
function remove_whitespace_children(children, next) {
const nodes = [];
let last_child;
let i = children.length;
while (i--) {
const child = children[i];
if (child.type === 'Text') {
if (child.should_skip()) {
continue;
}
let { data } = child;
if (nodes.length === 0) {
const should_trim = next
? next.type === 'Text' &&
/^\s/.test(next.data) &&
trimmable_at$1(child, next)
: !child.has_ancestor('EachBlock');
if (should_trim) {
data = trim_end(data);
if (!data)
continue;
}
}
// glue text nodes (which could e.g. be separated by comments) together
if (last_child && last_child.type === 'Text') {
last_child.data = data + last_child.data;
continue;
}
nodes.unshift(child);
link(last_child, last_child = child);
}
else {
nodes.unshift(child);
link(last_child, last_child = child);
}
}
const first = nodes[0];
if (first && first.type === 'Text') {
first.data = trim_start(first.data);
if (!first.data) {
first.var = null;
nodes.shift();
if (nodes[0]) {
nodes[0].prev = null;
}
}
}
return nodes;
}
function trimmable_at$1(child, next_sibling) {
// Whitespace is trimmable if one of the following is true:
// The child and its sibling share a common nearest each block (not at an each block boundary)
// The next sibling's previous node is an each block
return (next_sibling.find_nearest(/EachBlock/) ===
child.find_nearest(/EachBlock/) || next_sibling.prev.type === 'EachBlock');
}
function Element (node, renderer, options) {
const children = remove_whitespace_children(node.children, node.next);
// awkward special case
let node_contents;
const contenteditable = (node.name !== 'textarea' &&
node.name !== 'input' &&
node.attributes.some((attribute) => attribute.name === 'contenteditable'));
const slot = node.get_static_attribute_value('slot');
const nearest_inline_component = node.find_nearest(/InlineComponent/);
if (slot && nearest_inline_component) {
renderer.push();
}
renderer.add_string(`<${node.name}`);
const class_expression_list = node.classes.map(class_directive => {
const { expression, name } = class_directive;
const snippet = expression ? expression.node : x `#ctx.${name}`; // TODO is this right?
return x `${snippet} ? "${name}" : ""`;
});
if (node.needs_manual_style_scoping) {
class_expression_list.push(x `"${node.component.stylesheet.id}"`);
}
const class_expression = class_expression_list.length > 0 &&
class_expression_list.reduce((lhs, rhs) => x `${lhs} + ' ' + ${rhs}`);
if (node.attributes.some(attr => attr.is_spread)) {
// TODO dry this out
const args = [];
node.attributes.forEach(attribute => {
if (attribute.is_spread) {
args.push(attribute.expression.node);
}
else {
const name = attribute.name.toLowerCase();
if (name === 'value' && node.name.toLowerCase() === 'textarea') {
node_contents = get_attribute_value(attribute);
}
else if (attribute.is_true) {
args.push(x `{ ${attribute.name}: true }`);
}
else if (boolean_attributes.has(name) &&
attribute.chunks.length === 1 &&
attribute.chunks[0].type !== 'Text') {
// a boolean attribute with one non-Text chunk
args.push(x `{ ${attribute.name}: ${attribute.chunks[0].node} || null }`);
}
else {
args.push(x `{ ${attribute.name}: ${get_attribute_value(attribute)} }`);
}
}
});
renderer.add_expression(x `@spread([${args}], ${class_expression})`);
}
else {
let add_class_attribute = !!class_expression;
node.attributes.forEach(attribute => {
const name = attribute.name.toLowerCase();
if (name === 'value' && node.name.toLowerCase() === 'textarea') {
node_contents = get_attribute_value(attribute);
}
else if (attribute.is_true) {
renderer.add_string(` ${attribute.name}`);
}
else if (boolean_attributes.has(name) &&
attribute.chunks.length === 1 &&
attribute.chunks[0].type !== 'Text') {
// a boolean attribute with one non-Text chunk
renderer.add_string(` `);
renderer.add_expression(x `${attribute.chunks[0].node} ? "${attribute.name}" : ""`);
}
else if (name === 'class' && class_expression) {
add_class_attribute = false;
renderer.add_string(` ${attribute.name}="`);
renderer.add_expression(x `[${get_class_attribute_value(attribute)}, ${class_expression}].join(' ').trim()`);
renderer.add_string(`"`);
}
else if (attribute.chunks.length === 1 && attribute.chunks[0].type !== 'Text') {
const snippet = attribute.chunks[0].node;
renderer.add_expression(x `@add_attribute("${attribute.name}", ${snippet}, ${boolean_attributes.has(name) ? 1 : 0})`);
}
else {
renderer.add_string(` ${attribute.name}="`);
renderer.add_expression((name === 'class' ? get_class_attribute_value : get_attribute_value)(attribute));
renderer.add_string(`"`);
}
});
if (add_class_attribute) {
renderer.add_expression(x `@add_classes([${class_expression}].join(' ').trim())`);
}
}
node.bindings.forEach(binding => {
const { name, expression } = binding;
if (binding.is_readonly) {
return;
}
if (name === 'group') ;
else if (contenteditable && (name === 'textContent' || name === 'innerHTML')) {
node_contents = expression.node;
// TODO where was this used?
// value = name === 'textContent' ? x`@escape($$value)` : x`$$value`;
}
else if (binding.name === 'value' && node.name === 'textarea') {
const snippet = expression.node;
node_contents = x `${snippet} || ""`;
}
else {
const snippet = expression.node;
renderer.add_expression(x `@add_attribute("${name}", ${snippet}, 1)`);
}
});
if (options.hydratable && options.head_id) {
renderer.add_string(` data-svelte="${options.head_id}"`);
}
renderer.add_string('>');
if (node_contents !== undefined) {
if (contenteditable) {
renderer.push();
renderer.render(children, options);
const result = renderer.pop();
renderer.add_expression(x `($$value => $$value === void 0 ? ${result} : $$value)(${node_contents})`);
}
else {
renderer.add_expression(node_contents);
}
if (!is_void(node.name)) {
renderer.add_string(`</${node.name}>`);
}
}
else if (slot && nearest_inline_component) {
renderer.render(children, options);
if (!is_void(node.name)) {
renderer.add_string(`</${node.name}>`);
}
const lets = node.lets;
const seen = new Set(lets.map(l => l.name.name));
nearest_inline_component.lets.forEach(l => {
if (!seen.has(l.name.name))
lets.push(l);
});
options.slot_scopes.set(slot, {
input: get_slot_scope(node.lets),
output: renderer.pop()
});
}
else {
renderer.render(children, options);
if (!is_void(node.name)) {
renderer.add_string(`</${node.name}>`);
}
}
}
function Head (node, renderer, options) {
const head_options = Object.assign({}, options, { head_id: node.id });
renderer.push();
renderer.render(node.children, head_options);
const result = renderer.pop();
renderer.add_expression(x `$$result.head += ${result}, ""`);
}
function HtmlTag (node, renderer, _options) {
renderer.add_expression(node.expression.node);
}
function IfBlock (node, renderer, options) {
const condition = node.expression.node;
renderer.push();
renderer.render(node.children, options);
const consequent = renderer.pop();
renderer.push();
if (node.else)
renderer.render(node.else.children, options);
const alternate = renderer.pop();
renderer.add_expression(x `${condition} ? ${consequent} : ${alternate}`);
}
function get_prop_value(attribute) {
if (attribute.is_true)
return x `true`;
if (attribute.chunks.length === 0)
return x `''`;
return attribute.chunks
.map(chunk => {
if (chunk.type === 'Text')
return string_literal(chunk.data);
return chunk.node;
})
.reduce((lhs, rhs) => x `${lhs} + ${rhs}`);
}
function InlineComponent (node, renderer, options) {
const binding_props = [];
const binding_fns = [];
node.bindings.forEach(binding => {
renderer.has_bindings = true;
// TODO this probably won't work for contextual bindings
const snippet = binding.expression.node;
binding_props.push(p `${binding.name}: ${snippet}`);
binding_fns.push(p `${binding.name}: $$value => { ${snippet} = $$value; $$settled = false }`);
});
const uses_spread = node.attributes.find(attr => attr.is_spread);
let props;
if (uses_spread) {
props = x `@_Object.assign(${node.attributes
.map(attribute => {
if (attribute.is_spread) {
return attribute.expression.node;
}
else {
return x `{ ${attribute.name}: ${get_prop_value(attribute)} }`;
}
})
.concat(binding_props.map(p => x `{ ${p} }`))})`;
}
else {
props = x `{
${node.attributes.map(attribute => p `${attribute.name}: ${get_prop_value(attribute)}`)},
${binding_props}
}`;
}
const bindings = x `{
${binding_fns}
}`;
const expression = (node.name === 'svelte:self'
? renderer.name
: node.name === 'svelte:component'
? x `(${node.expression.node}) || @missing_component`
: node.name.split('.').reduce(((lhs, rhs) => x `${lhs}.${rhs}`)));
const slot_fns = [];
const children = remove_whitespace_children(node.children, node.next);
if (children.length) {
const slot_scopes = new Map();
renderer.push();
renderer.render(children, Object.assign({}, options, {
slot_scopes
}));
slot_scopes.set('default', {
input: get_slot_scope(node.lets),
output: renderer.pop()
});
slot_scopes.forEach(({ input, output }, name) => {
if (!is_empty_template_literal(output)) {
slot_fns.push(p `${name}: (${input}) => ${output}`);
}
});
}
const slots = x `{
${slot_fns}
}`;
renderer.add_expression(x `@validate_component(${expression}, "${node.name}").$$render($$result, ${props}, ${bindings}, ${slots})`);
}
function is_empty_template_literal(template_literal) {
return (template_literal.expressions.length === 0 &&
template_literal.quasis.length === 1 &&
template_literal.quasis[0].value.raw === "");
}
function Slot (node, renderer, options) {
const slot_data = get_slot_data(node.values);
renderer.push();
renderer.render(node.children, options);
const result = renderer.pop();
renderer.add_expression(x `
$$slots.${node.slot_name}
? $$slots.${node.slot_name}(${slot_data})
: ${result}
`);
}
function Tag$1 (node, renderer, _options) {
const snippet = node.expression.node;
renderer.add_expression(node.parent &&
node.parent.type === 'Element' &&
node.parent.name === 'style'
? snippet
: x `@escape(${snippet})`);
}
function Text (node, renderer, _options) {
let text = node.data;
if (!node.parent ||
node.parent.type !== 'Element' ||
(node.parent.name !== 'script' && node.parent.name !== 'style')) {
// unless this Text node is inside a <script> or <style> element, escape &,<,>
text = escape_html(text);
}
renderer.add_string(text);
}
function Title (node, renderer, options) {
renderer.push();
renderer.add_string(`<title>`);
renderer.render(node.children, options);
renderer.add_string(`</title>`);
const result = renderer.pop();
renderer.add_expression(x `$$result.title = ${result}, ""`);
}
function noop$1() { }
const handlers$1 = {
AwaitBlock,
Body: noop$1,
Comment: Comment$1,
DebugTag,
EachBlock,
Element,
Head,
IfBlock,
InlineComponent,
MustacheTag: Tag$1,
Options: noop$1,
RawMustacheTag: HtmlTag,
Slot,
Text,
Title,
Window: noop$1
};
class Renderer$1 {
constructor({ name }) {
this.has_bindings = false;
this.stack = [];
this.targets = [];
this.name = name;
this.push();
}
add_string(str) {
this.current.value += escape_template(str);
}
add_expression(node) {
this.literal.quasis.push({
type: 'TemplateElement',
value: { raw: this.current.value, cooked: null },
tail: false
});
this.literal.expressions.push(node);
this.current.value = '';
}
push() {
const current = this.current = { value: '' };
const literal = this.literal = {
type: 'TemplateLiteral',
expressions: [],
quasis: []
};
this.stack.push({ current, literal });
}
pop() {
this.literal.quasis.push({
type: 'TemplateElement',
value: { raw: this.current.value, cooked: null },
tail: true
});
const popped = this.stack.pop();
const last = this.stack[this.stack.length - 1];
if (last) {
this.literal = last.literal;
this.current = last.current;
}
return popped.literal;
}
render(nodes, options) {
nodes.forEach(node => {
const handler = handlers$1[node.type];
if (!handler) {
throw new Error(`No handler for '${node.type}' nodes`);
}
handler(node, this, options);
});
}
}
function ssr(component, options) {
const renderer = new Renderer$1({
name: component.name
});
const { name } = component;
// create $$render function
renderer.render(trim(component.fragment.children), Object.assign({
locate: component.locate
}, options));
// TODO put this inside the Renderer class
const literal = renderer.pop();
// TODO concatenate CSS maps
const css = options.customElement ?
{ code: null, map: null } :
component.stylesheet.render(options.filename, true);
const uses_rest = component.var_lookup.has('$$restProps');
const props = component.vars.filter(variable => !variable.module && variable.export_name);
const rest = uses_rest ? b `let $$restProps = @compute_rest_props($$props, [${props.map(prop => `"${prop.export_name}"`).join(',')}]);` : null;
const reactive_stores = component.vars.filter(variable => variable.name[0] === '$' && variable.name[1] !== '$');
const reactive_store_values = reactive_stores
.map(({ name }) => {
const store_name = name.slice(1);
const store = component.var_lookup.get(store_name);
if (store && store.hoistable)
return null;
const assignment = b `${name} = @get_store_value(${store_name});`;
return component.compile_options.dev
? b `@validate_store(${store_name}, '${store_name}'); ${assignment}`
: assignment;
})
.filter(Boolean);
component.rewrite_props(({ name }) => {
const value = `$${name}`;
let insert = b `${value} = @get_store_value(${name})`;
if (component.compile_options.dev) {
insert = b `@validate_store(${name}, '${name}'); ${insert}`;
}
return insert;
});
const instance_javascript = component.extract_javascript(component.ast.instance);
// TODO only do this for props with a default value
const parent_bindings = instance_javascript
? component.vars
.filter(variable => !variable.module && variable.export_name)
.map(prop => {
return b `if ($$props.${prop.export_name} === void 0 && $$bindings.${prop.export_name} && ${prop.name} !== void 0) $$bindings.${prop.export_name}(${prop.name});`;
})
: [];
const reactive_declarations = component.reactive_declarations.map(d => {
const body = d.node.body;
let statement = b `${body}`;
if (d.declaration) {
const declared = extract_names(d.declaration);
const injected = declared.filter(name => {
return name[0] !== '$' && component.var_lookup.get(name).injected;
});
const self_dependencies = injected.filter(name => d.dependencies.has(name));
if (injected.length) {
// in some cases we need to do `let foo; [expression]`, in
// others we can do `let [expression]`
const separate = (self_dependencies.length > 0 ||
declared.length > injected.length);
const { left, right } = body.expression;
statement = separate
? b `
${injected.map(name => b `let ${name};`)}
${statement}`
: b `
let ${left} = ${right}`;
}
}
else { // TODO do not add label if it's not referenced
statement = b `$: { ${statement} }`;
}
return statement;
});
const main = renderer.has_bindings
? b `
let $$settled;
let $$rendered;
do {
$$settled = true;
${reactive_store_values}
${reactive_declarations}
$$rendered = ${literal};
} while (!$$settled);
return $$rendered;
`
: b `
${reactive_store_values}
${reactive_declarations}
return ${literal};`;
const blocks = [
rest,
...reactive_stores.map(({ name }) => {
const store_name = name.slice(1);
const store = component.var_lookup.get(store_name);
if (store && store.hoistable) {
return b `let ${name} = @get_store_value(${store_name});`;
}
return b `let ${name};`;
}),
instance_javascript,
...parent_bindings,
css.code && b `$$result.css.add(#css);`,
main
].filter(Boolean);
const js = b `
${css.code ? b `
const #css = {
code: "${css.code}",
map: ${css.map ? string_literal(css.map.toString()) : 'null'}
};` : null}
${component.extract_javascript(component.ast.module)}
${component.fully_hoisted}
const ${name} = @create_ssr_component(($$result, $$props, $$bindings, $$slots) => {
${blocks}
});
`;
return { js, css };
}
function trim(nodes) {
let start = 0;
for (; start < nodes.length; start += 1) {
const node = nodes[start];
if (node.type !== 'Text')
break;
node.data = node.data.replace(/^\s+/, '');
if (node.data)
break;
}
let end = nodes.length;
for (; end > start; end -= 1) {
const node = nodes[end - 1];
if (node.type !== 'Text')
break;
node.data = node.data.replace(/\s+$/, '');
if (node.data)
break;
}
return nodes.slice(start, end);
}
const wrappers$1 = { esm, cjs };
function create_module(program, format, name, banner, sveltePath = 'svelte', helpers, globals, imports, module_exports) {
const internal_path = `${sveltePath}/internal`;
helpers.sort((a, b) => (a.name < b.name) ? -1 : 1);
globals.sort((a, b) => (a.name < b.name) ? -1 : 1);
if (format === 'esm') {
return esm(program, name, banner, sveltePath, internal_path, helpers, globals, imports, module_exports);
}
if (format === 'cjs')
return cjs(program, name, banner, sveltePath, internal_path, helpers, globals, imports, module_exports);
throw new Error(`options.format is invalid (must be ${list$1(Object.keys(wrappers$1))})`);
}
function edit_source(source, sveltePath) {
return source === 'svelte' || source.startsWith('svelte/')
? source.replace('svelte', sveltePath)
: source;
}
function get_internal_globals(globals, helpers) {
return globals.length > 0 && {
type: 'VariableDeclaration',
kind: 'const',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'ObjectPattern',
properties: globals.map(g => ({
type: 'Property',
method: false,
shorthand: false,
computed: false,
key: { type: 'Identifier', name: g.name },
value: g.alias,
kind: 'init'
}))
},
init: helpers.find(({ name }) => name === 'globals').alias
}]
};
}
function esm(program, name, banner, sveltePath, internal_path, helpers, globals, imports, module_exports) {
const import_declaration = {
type: 'ImportDeclaration',
specifiers: helpers.map(h => ({
type: 'ImportSpecifier',
local: h.alias,
imported: { type: 'Identifier', name: h.name }
})),
source: { type: 'Literal', value: internal_path }
};
const internal_globals = get_internal_globals(globals, helpers);
// edit user imports
imports.forEach(node => {
node.source.value = edit_source(node.source.value, sveltePath);
});
const exports = module_exports.length > 0 && {
type: 'ExportNamedDeclaration',
specifiers: module_exports.map(x => ({
type: 'Specifier',
local: { type: 'Identifier', name: x.name },
exported: { type: 'Identifier', name: x.as }
}))
};
program.body = b `
/* ${banner} */
${import_declaration}
${internal_globals}
${imports}
${program.body}
export default ${name};
${exports}
`;
}
function cjs(program, name, banner, sveltePath, internal_path, helpers, globals, imports, module_exports) {
const internal_requires = {
type: 'VariableDeclaration',
kind: 'const',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'ObjectPattern',
properties: helpers.map(h => ({
type: 'Property',
method: false,
shorthand: false,
computed: false,
key: { type: 'Identifier', name: h.name },
value: h.alias,
kind: 'init'
}))
},
init: x `require("${internal_path}")`
}]
};
const internal_globals = get_internal_globals(globals, helpers);
const user_requires = imports.map(node => {
const init = x `require("${edit_source(node.source.value, sveltePath)}")`;
if (node.specifiers.length === 0) {
return b `${init};`;
}
return {
type: 'VariableDeclaration',
kind: 'const',
declarations: [{
type: 'VariableDeclarator',
id: node.specifiers[0].type === 'ImportNamespaceSpecifier'
? { type: 'Identifier', name: node.specifiers[0].local.name }
: {
type: 'ObjectPattern',
properties: node.specifiers.map(s => ({
type: 'Property',
method: false,
shorthand: false,
computed: false,
key: s.type === 'ImportSpecifier' ? s.imported : { type: 'Identifier', name: 'default' },
value: s.local,
kind: 'init'
}))
},
init
}]
};
});
const exports = module_exports.map(x => b `exports.${{ type: 'Identifier', name: x.as }} = ${{ type: 'Identifier', name: x.name }};`);
program.body = b `
/* ${banner} */
"use strict";
${internal_requires}
${internal_globals}
${user_requires}
${program.body}
exports.default = ${name};
${exports}
`;
}
var Chunk = function Chunk(start, end, content) {
this.start = start;
this.end = end;
this.original = content;
this.intro = '';
this.outro = '';
this.content = content;
this.storeName = false;
this.edited = false;
// we make these non-enumerable, for sanity while debugging
Object.defineProperties(this, {
previous: { writable: true, value: null },
next: { writable: true, value: null }
});
};
Chunk.prototype.appendLeft = function appendLeft (content) {
this.outro += content;
};
Chunk.prototype.appendRight = function appendRight (content) {
this.intro = this.intro + content;
};
Chunk.prototype.clone = function clone () {
var chunk = new Chunk(this.start, this.end, this.original);
chunk.intro = this.intro;
chunk.outro = this.outro;
chunk.content = this.content;
chunk.storeName = this.storeName;
chunk.edited = this.edited;
return chunk;
};
Chunk.prototype.contains = function contains (index) {
return this.start < index && index < this.end;
};
Chunk.prototype.eachNext = function eachNext (fn) {
var chunk = this;
while (chunk) {
fn(chunk);
chunk = chunk.next;
}
};
Chunk.prototype.eachPrevious = function eachPrevious (fn) {
var chunk = this;
while (chunk) {
fn(chunk);
chunk = chunk.previous;
}
};
Chunk.prototype.edit = function edit (content, storeName, contentOnly) {
this.content = content;
if (!contentOnly) {
this.intro = '';
this.outro = '';
}
this.storeName = storeName;
this.edited = true;
return this;
};
Chunk.prototype.prependLeft = function prependLeft (content) {
this.outro = content + this.outro;
};
Chunk.prototype.prependRight = function prependRight (content) {
this.intro = content + this.intro;
};
Chunk.prototype.split = function split (index) {
var sliceIndex = index - this.start;
var originalBefore = this.original.slice(0, sliceIndex);
var originalAfter = this.original.slice(sliceIndex);
this.original = originalBefore;
var newChunk = new Chunk(index, this.end, originalAfter);
newChunk.outro = this.outro;
this.outro = '';
this.end = index;
if (this.edited) {
// TODO is this block necessary?...
newChunk.edit('', false);
this.content = '';
} else {
this.content = originalBefore;
}
newChunk.next = this.next;
if (newChunk.next) { newChunk.next.previous = newChunk; }
newChunk.previous = this;
this.next = newChunk;
return newChunk;
};
Chunk.prototype.toString = function toString () {
return this.intro + this.content + this.outro;
};
Chunk.prototype.trimEnd = function trimEnd (rx) {
this.outro = this.outro.replace(rx, '');
if (this.outro.length) { return true; }
var trimmed = this.content.replace(rx, '');
if (trimmed.length) {
if (trimmed !== this.content) {
this.split(this.start + trimmed.length).edit('', undefined, true);
}
return true;
} else {
this.edit('', undefined, true);
this.intro = this.intro.replace(rx, '');
if (this.intro.length) { return true; }
}
};
Chunk.prototype.trimStart = function trimStart (rx) {
this.intro = this.intro.replace(rx, '');
if (this.intro.length) { return true; }
var trimmed = this.content.replace(rx, '');
if (trimmed.length) {
if (trimmed !== this.content) {
this.split(this.end - trimmed.length);
this.edit('', undefined, true);
}
return true;
} else {
this.edit('', undefined, true);
this.outro = this.outro.replace(rx, '');
if (this.outro.length) { return true; }
}
};
var btoa$1 = function () {
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
};
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
btoa$1 = function (str) { return window.btoa(unescape(encodeURIComponent(str))); };
} else if (typeof Buffer === 'function') {
btoa$1 = function (str) { return Buffer.from(str, 'utf-8').toString('base64'); };
}
var SourceMap = function SourceMap(properties) {
this.version = 3;
this.file = properties.file;
this.sources = properties.sources;
this.sourcesContent = properties.sourcesContent;
this.names = properties.names;
this.mappings = encode(properties.mappings);
};
SourceMap.prototype.toString = function toString () {
return JSON.stringify(this);
};
SourceMap.prototype.toUrl = function toUrl () {
return 'data:application/json;charset=utf-8;base64,' + btoa$1(this.toString());
};
function guessIndent(code) {
var lines = code.split('\n');
var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
if (tabbed.length === 0 && spaced.length === 0) {
return null;
}
// More lines tabbed than spaced? Assume tabs, and
// default to tabs in the case of a tie (or nothing
// to go on)
if (tabbed.length >= spaced.length) {
return '\t';
}
// Otherwise, we need to guess the multiple
var min = spaced.reduce(function (previous, current) {
var numSpaces = /^ +/.exec(current)[0].length;
return Math.min(numSpaces, previous);
}, Infinity);
return new Array(min + 1).join(' ');
}
function getRelativePath(from, to) {
var fromParts = from.split(/[/\\]/);
var toParts = to.split(/[/\\]/);
fromParts.pop(); // get dirname
while (fromParts[0] === toParts[0]) {
fromParts.shift();
toParts.shift();
}
if (fromParts.length) {
var i = fromParts.length;
while (i--) { fromParts[i] = '..'; }
}
return fromParts.concat(toParts).join('/');
}
var toString$1 = Object.prototype.toString;
function isObject(thing) {
return toString$1.call(thing) === '[object Object]';
}
function getLocator$1(source) {
var originalLines = source.split('\n');
var lineOffsets = [];
for (var i = 0, pos = 0; i < originalLines.length; i++) {
lineOffsets.push(pos);
pos += originalLines[i].length + 1;
}
return function locate(index) {
var i = 0;
var j = lineOffsets.length;
while (i < j) {
var m = (i + j) >> 1;
if (index < lineOffsets[m]) {
j = m;
} else {
i = m + 1;
}
}
var line = i - 1;
var column = index - lineOffsets[line];
return { line: line, column: column };
};
}
var Mappings = function Mappings(hires) {
this.hires = hires;
this.generatedCodeLine = 0;
this.generatedCodeColumn = 0;
this.raw = [];
this.rawSegments = this.raw[this.generatedCodeLine] = [];
this.pending = null;
};
Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {
if (content.length) {
var segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
if (nameIndex >= 0) {
segment.push(nameIndex);
}
this.rawSegments.push(segment);
} else if (this.pending) {
this.rawSegments.push(this.pending);
}
this.advance(content);
this.pending = null;
};
Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
var originalCharIndex = chunk.start;
var first = true;
while (originalCharIndex < chunk.end) {
if (this.hires || first || sourcemapLocations[originalCharIndex]) {
this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
}
if (original[originalCharIndex] === '\n') {
loc.line += 1;
loc.column = 0;
this.generatedCodeLine += 1;
this.raw[this.generatedCodeLine] = this.rawSegments = [];
this.generatedCodeColumn = 0;
} else {
loc.column += 1;
this.generatedCodeColumn += 1;
}
originalCharIndex += 1;
first = false;
}
this.pending = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
};
Mappings.prototype.advance = function advance (str) {
if (!str) { return; }
var lines = str.split('\n');
if (lines.length > 1) {
for (var i = 0; i < lines.length - 1; i++) {
this.generatedCodeLine++;
this.raw[this.generatedCodeLine] = this.rawSegments = [];
}
this.generatedCodeColumn = 0;
}
this.generatedCodeColumn += lines[lines.length - 1].length;
};
var n = '\n';
var warned = {
insertLeft: false,
insertRight: false,
storeName: false
};
var MagicString = function MagicString(string, options) {
if ( options === void 0 ) options = {};
var chunk = new Chunk(0, string.length, string);
Object.defineProperties(this, {
original: { writable: true, value: string },
outro: { writable: true, value: '' },
intro: { writable: true, value: '' },
firstChunk: { writable: true, value: chunk },
lastChunk: { writable: true, value: chunk },
lastSearchedChunk: { writable: true, value: chunk },
byStart: { writable: true, value: {} },
byEnd: { writable: true, value: {} },
filename: { writable: true, value: options.filename },
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
sourcemapLocations: { writable: true, value: {} },
storedNames: { writable: true, value: {} },
indentStr: { writable: true, value: guessIndent(string) }
});
this.byStart[0] = chunk;
this.byEnd[string.length] = chunk;
};
MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
this.sourcemapLocations[char] = true;
};
MagicString.prototype.append = function append (content) {
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
this.outro += content;
return this;
};
MagicString.prototype.appendLeft = function appendLeft (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byEnd[index];
if (chunk) {
chunk.appendLeft(content);
} else {
this.intro += content;
}
return this;
};
MagicString.prototype.appendRight = function appendRight (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byStart[index];
if (chunk) {
chunk.appendRight(content);
} else {
this.outro += content;
}
return this;
};
MagicString.prototype.clone = function clone () {
var cloned = new MagicString(this.original, { filename: this.filename });
var originalChunk = this.firstChunk;
var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
while (originalChunk) {
cloned.byStart[clonedChunk.start] = clonedChunk;
cloned.byEnd[clonedChunk.end] = clonedChunk;
var nextOriginalChunk = originalChunk.next;
var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
if (nextClonedChunk) {
clonedChunk.next = nextClonedChunk;
nextClonedChunk.previous = clonedChunk;
clonedChunk = nextClonedChunk;
}
originalChunk = nextOriginalChunk;
}
cloned.lastChunk = clonedChunk;
if (this.indentExclusionRanges) {
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
}
Object.keys(this.sourcemapLocations).forEach(function (loc) {
cloned.sourcemapLocations[loc] = true;
});
return cloned;
};
MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
var this$1 = this;
options = options || {};
var sourceIndex = 0;
var names = Object.keys(this.storedNames);
var mappings = new Mappings(options.hires);
var locate = getLocator$1(this.original);
if (this.intro) {
mappings.advance(this.intro);
}
this.firstChunk.eachNext(function (chunk) {
var loc = locate(chunk.start);
if (chunk.intro.length) { mappings.advance(chunk.intro); }
if (chunk.edited) {
mappings.addEdit(
sourceIndex,
chunk.content,
loc,
chunk.storeName ? names.indexOf(chunk.original) : -1
);
} else {
mappings.addUneditedChunk(sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations);
}
if (chunk.outro.length) { mappings.advance(chunk.outro); }
});
return {
file: options.file ? options.file.split(/[/\\]/).pop() : null,
sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
sourcesContent: options.includeContent ? [this.original] : [null],
names: names,
mappings: mappings.raw
};
};
MagicString.prototype.generateMap = function generateMap (options) {
return new SourceMap(this.generateDecodedMap(options));
};
MagicString.prototype.getIndentString = function getIndentString () {
return this.indentStr === null ? '\t' : this.indentStr;
};
MagicString.prototype.indent = function indent (indentStr, options) {
var pattern = /^[^\r\n]/gm;
if (isObject(indentStr)) {
options = indentStr;
indentStr = undefined;
}
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
if (indentStr === '') { return this; } // noop
options = options || {};
// Process exclusion ranges
var isExcluded = {};
if (options.exclude) {
var exclusions =
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
exclusions.forEach(function (exclusion) {
for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
isExcluded[i] = true;
}
});
}
var shouldIndentNextCharacter = options.indentStart !== false;
var replacer = function (match) {
if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
shouldIndentNextCharacter = true;
return match;
};
this.intro = this.intro.replace(pattern, replacer);
var charIndex = 0;
var chunk = this.firstChunk;
while (chunk) {
var end = chunk.end;
if (chunk.edited) {
if (!isExcluded[charIndex]) {
chunk.content = chunk.content.replace(pattern, replacer);
if (chunk.content.length) {
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
}
}
} else {
charIndex = chunk.start;
while (charIndex < end) {
if (!isExcluded[charIndex]) {
var char = this.original[charIndex];
if (char === '\n') {
shouldIndentNextCharacter = true;
} else if (char !== '\r' && shouldIndentNextCharacter) {
shouldIndentNextCharacter = false;
if (charIndex === chunk.start) {
chunk.prependRight(indentStr);
} else {
this._splitChunk(chunk, charIndex);
chunk = chunk.next;
chunk.prependRight(indentStr);
}
}
}
charIndex += 1;
}
}
charIndex = chunk.end;
chunk = chunk.next;
}
this.outro = this.outro.replace(pattern, replacer);
return this;
};
MagicString.prototype.insert = function insert () {
throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
};
MagicString.prototype.insertLeft = function insertLeft (index, content) {
if (!warned.insertLeft) {
console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
warned.insertLeft = true;
}
return this.appendLeft(index, content);
};
MagicString.prototype.insertRight = function insertRight (index, content) {
if (!warned.insertRight) {
console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
warned.insertRight = true;
}
return this.prependRight(index, content);
};
MagicString.prototype.move = function move (start, end, index) {
if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
this._split(start);
this._split(end);
this._split(index);
var first = this.byStart[start];
var last = this.byEnd[end];
var oldLeft = first.previous;
var oldRight = last.next;
var newRight = this.byStart[index];
if (!newRight && last === this.lastChunk) { return this; }
var newLeft = newRight ? newRight.previous : this.lastChunk;
if (oldLeft) { oldLeft.next = oldRight; }
if (oldRight) { oldRight.previous = oldLeft; }
if (newLeft) { newLeft.next = first; }
if (newRight) { newRight.previous = last; }
if (!first.previous) { this.firstChunk = last.next; }
if (!last.next) {
this.lastChunk = first.previous;
this.lastChunk.next = null;
}
first.previous = newLeft;
last.next = newRight || null;
if (!newLeft) { this.firstChunk = first; }
if (!newRight) { this.lastChunk = last; }
return this;
};
MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
while (start < 0) { start += this.original.length; }
while (end < 0) { end += this.original.length; }
if (end > this.original.length) { throw new Error('end is out of bounds'); }
if (start === end)
{ throw new Error('Cannot overwrite a zero-length range use appendLeft or prependRight instead'); }
this._split(start);
this._split(end);
if (options === true) {
if (!warned.storeName) {
console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console
warned.storeName = true;
}
options = { storeName: true };
}
var storeName = options !== undefined ? options.storeName : false;
var contentOnly = options !== undefined ? options.contentOnly : false;
if (storeName) {
var original = this.original.slice(start, end);
this.storedNames[original] = true;
}
var first = this.byStart[start];
var last = this.byEnd[end];
if (first) {
if (end > first.end && first.next !== this.byStart[first.end]) {
throw new Error('Cannot overwrite across a split point');
}
first.edit(content, storeName, contentOnly);
if (first !== last) {
var chunk = first.next;
while (chunk !== last) {
chunk.edit('', false);
chunk = chunk.next;
}
chunk.edit('', false);
}
} else {
// must be inserting at the end
var newChunk = new Chunk(start, end, '').edit(content, storeName);
// TODO last chunk in the array may not be the last chunk, if it's moved...
last.next = newChunk;
newChunk.previous = last;
}
return this;
};
MagicString.prototype.prepend = function prepend (content) {
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
this.intro = content + this.intro;
return this;
};
MagicString.prototype.prependLeft = function prependLeft (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byEnd[index];
if (chunk) {
chunk.prependLeft(content);
} else {
this.intro = content + this.intro;
}
return this;
};
MagicString.prototype.prependRight = function prependRight (index, content) {
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
this._split(index);
var chunk = this.byStart[index];
if (chunk) {
chunk.prependRight(content);
} else {
this.outro = content + this.outro;
}
return this;
};
MagicString.prototype.remove = function remove (start, end) {
while (start < 0) { start += this.original.length; }
while (end < 0) { end += this.original.length; }
if (start === end) { return this; }
if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
if (start > end) { throw new Error('end must be greater than start'); }
this._split(start);
this._split(end);
var chunk = this.byStart[start];
while (chunk) {
chunk.intro = '';
chunk.outro = '';
chunk.edit('');
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
}
return this;
};
MagicString.prototype.lastChar = function lastChar () {
if (this.outro.length)
{ return this.outro[this.outro.length - 1]; }
var chunk = this.lastChunk;
do {
if (chunk.outro.length)
{ return chunk.outro[chunk.outro.length - 1]; }
if (chunk.content.length)
{ return chunk.content[chunk.content.length - 1]; }
if (chunk.intro.length)
{ return chunk.intro[chunk.intro.length - 1]; }
} while (chunk = chunk.previous);
if (this.intro.length)
{ return this.intro[this.intro.length - 1]; }
return '';
};
MagicString.prototype.lastLine = function lastLine () {
var lineIndex = this.outro.lastIndexOf(n);
if (lineIndex !== -1)
{ return this.outro.substr(lineIndex + 1); }
var lineStr = this.outro;
var chunk = this.lastChunk;
do {
if (chunk.outro.length > 0) {
lineIndex = chunk.outro.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.outro.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.outro + lineStr;
}
if (chunk.content.length > 0) {
lineIndex = chunk.content.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.content.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.content + lineStr;
}
if (chunk.intro.length > 0) {
lineIndex = chunk.intro.lastIndexOf(n);
if (lineIndex !== -1)
{ return chunk.intro.substr(lineIndex + 1) + lineStr; }
lineStr = chunk.intro + lineStr;
}
} while (chunk = chunk.previous);
lineIndex = this.intro.lastIndexOf(n);
if (lineIndex !== -1)
{ return this.intro.substr(lineIndex + 1) + lineStr; }
return this.intro + lineStr;
};
MagicString.prototype.slice = function slice (start, end) {
if ( start === void 0 ) start = 0;
if ( end === void 0 ) end = this.original.length;
while (start < 0) { start += this.original.length; }
while (end < 0) { end += this.original.length; }
var result = '';
// find start chunk
var chunk = this.firstChunk;
while (chunk && (chunk.start > start || chunk.end <= start)) {
// found end chunk before start
if (chunk.start < end && chunk.end >= end) {
return result;
}
chunk = chunk.next;
}
if (chunk && chunk.edited && chunk.start !== start)
{ throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
var startChunk = chunk;
while (chunk) {
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
result += chunk.intro;
}
var containsEnd = chunk.start < end && chunk.end >= end;
if (containsEnd && chunk.edited && chunk.end !== end)
{ throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
var sliceStart = startChunk === chunk ? start - chunk.start : 0;
var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
result += chunk.content.slice(sliceStart, sliceEnd);
if (chunk.outro && (!containsEnd || chunk.end === end)) {
result += chunk.outro;
}
if (containsEnd) {
break;
}
chunk = chunk.next;
}
return result;
};
// TODO deprecate this? not really very useful
MagicString.prototype.snip = function snip (start, end) {
var clone = this.clone();
clone.remove(0, start);
clone.remove(end, clone.original.length);
return clone;
};
MagicString.prototype._split = function _split (index) {
if (this.byStart[index] || this.byEnd[index]) { return; }
var chunk = this.lastSearchedChunk;
var searchForward = index > chunk.end;
while (chunk) {
if (chunk.contains(index)) { return this._splitChunk(chunk, index); }
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
}
};
MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
if (chunk.edited && chunk.content.length) {
// zero-length edited chunks are a special case (overlapping replacements)
var loc = getLocator$1(this.original)(index);
throw new Error(
("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " \"" + (chunk.original) + "\")")
);
}
var newChunk = chunk.split(index);
this.byEnd[index] = chunk;
this.byStart[index] = newChunk;
this.byEnd[newChunk.end] = newChunk;
if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
this.lastSearchedChunk = chunk;
return true;
};
MagicString.prototype.toString = function toString () {
var str = this.intro;
var chunk = this.firstChunk;
while (chunk) {
str += chunk.toString();
chunk = chunk.next;
}
return str + this.outro;
};
MagicString.prototype.isEmpty = function isEmpty () {
var chunk = this.firstChunk;
do {
if (chunk.intro.length && chunk.intro.trim() ||
chunk.content.length && chunk.content.trim() ||
chunk.outro.length && chunk.outro.trim())
{ return false; }
} while (chunk = chunk.next);
return true;
};
MagicString.prototype.length = function length () {
var chunk = this.firstChunk;
var length = 0;
do {
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
} while (chunk = chunk.next);
return length;
};
MagicString.prototype.trimLines = function trimLines () {
return this.trim('[\\r\\n]');
};
MagicString.prototype.trim = function trim (charType) {
return this.trimStart(charType).trimEnd(charType);
};
MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
var rx = new RegExp((charType || '\\s') + '+$');
this.outro = this.outro.replace(rx, '');
if (this.outro.length) { return true; }
var chunk = this.lastChunk;
do {
var end = chunk.end;
var aborted = chunk.trimEnd(rx);
// if chunk was trimmed, we have a new lastChunk
if (chunk.end !== end) {
if (this.lastChunk === chunk) {
this.lastChunk = chunk.next;
}
this.byEnd[chunk.end] = chunk;
this.byStart[chunk.next.start] = chunk.next;
this.byEnd[chunk.next.end] = chunk.next;
}
if (aborted) { return true; }
chunk = chunk.previous;
} while (chunk);
return false;
};
MagicString.prototype.trimEnd = function trimEnd (charType) {
this.trimEndAborted(charType);
return this;
};
MagicString.prototype.trimStartAborted = function trimStartAborted (charType) {
var rx = new RegExp('^' + (charType || '\\s') + '+');
this.intro = this.intro.replace(rx, '');
if (this.intro.length) { return true; }
var chunk = this.firstChunk;
do {
var end = chunk.end;
var aborted = chunk.trimStart(rx);
if (chunk.end !== end) {
// special case...
if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
this.byEnd[chunk.end] = chunk;
this.byStart[chunk.next.start] = chunk.next;
this.byEnd[chunk.next.end] = chunk.next;
}
if (aborted) { return true; }
chunk = chunk.next;
} while (chunk);
return false;
};
MagicString.prototype.trimStart = function trimStart (charType) {
this.trimStartAborted(charType);
return this;
};
const UNKNOWN = {};
function gather_possible_values(node, set) {
if (node.type === 'Literal') {
set.add(node.value);
}
else if (node.type === 'ConditionalExpression') {
gather_possible_values(node.consequent, set);
gather_possible_values(node.alternate, set);
}
else {
set.add(UNKNOWN);
}
}
var BlockAppliesToNode;
(function (BlockAppliesToNode) {
BlockAppliesToNode[BlockAppliesToNode["NotPossible"] = 0] = "NotPossible";
BlockAppliesToNode[BlockAppliesToNode["Possible"] = 1] = "Possible";
BlockAppliesToNode[BlockAppliesToNode["UnknownSelectorType"] = 2] = "UnknownSelectorType";
})(BlockAppliesToNode || (BlockAppliesToNode = {}));
class Selector$1 {
constructor(node, stylesheet) {
this.node = node;
this.stylesheet = stylesheet;
this.blocks = group_selectors(node);
// take trailing :global(...) selectors out of consideration
let i = this.blocks.length;
while (i > 0) {
if (!this.blocks[i - 1].global)
break;
i -= 1;
}
this.local_blocks = this.blocks.slice(0, i);
this.used = this.local_blocks.length === 0;
}
apply(node, stack) {
const to_encapsulate = [];
apply_selector(this.local_blocks.slice(), node, stack.slice(), to_encapsulate);
if (to_encapsulate.length > 0) {
to_encapsulate.forEach(({ node, block }) => {
this.stylesheet.nodes_with_css_class.add(node);
block.should_encapsulate = true;
});
this.used = true;
}
}
minify(code) {
let c = null;
this.blocks.forEach((block, i) => {
if (i > 0) {
if (block.start - c > 1) {
code.overwrite(c, block.start, block.combinator.name || ' ');
}
}
c = block.end;
});
}
transform(code, attr, max_amount_class_specificity_increased) {
const amount_class_specificity_to_increase = max_amount_class_specificity_increased - this.blocks.filter(block => block.should_encapsulate).length;
attr = attr.repeat(amount_class_specificity_to_increase + 1);
function encapsulate_block(block) {
let i = block.selectors.length;
while (i--) {
const selector = block.selectors[i];
if (selector.type === 'PseudoElementSelector' || selector.type === 'PseudoClassSelector') {
if (selector.name !== 'root') {
if (i === 0)
code.prependRight(selector.start, attr);
}
continue;
}
if (selector.type === 'TypeSelector' && selector.name === '*') {
code.overwrite(selector.start, selector.end, attr);
}
else {
code.appendLeft(selector.end, attr);
}
break;
}
}
this.blocks.forEach((block) => {
if (block.global) {
const selector = block.selectors[0];
const first = selector.children[0];
const last = selector.children[selector.children.length - 1];
code.remove(selector.start, first.start).remove(last.end, selector.end);
}
if (block.should_encapsulate)
encapsulate_block(block);
});
}
validate(component) {
this.blocks.forEach((block) => {
let i = block.selectors.length;
while (i-- > 1) {
const selector = block.selectors[i];
if (selector.type === 'PseudoClassSelector' && selector.name === 'global') {
component.error(selector, {
code: `css-invalid-global`,
message: `:global(...) must be the first element in a compound selector`
});
}
}
});
let start = 0;
let end = this.blocks.length;
for (; start < end; start += 1) {
if (!this.blocks[start].global)
break;
}
for (; end > start; end -= 1) {
if (!this.blocks[end - 1].global)
break;
}
for (let i = start; i < end; i += 1) {
if (this.blocks[i].global) {
component.error(this.blocks[i].selectors[0], {
code: `css-invalid-global`,
message: `:global(...) can be at the start or end of a selector sequence, but not in the middle`
});
}
}
}
get_amount_class_specificity_increased() {
let count = 0;
for (const block of this.blocks) {
if (block.should_encapsulate) {
count++;
}
}
return count;
}
}
function apply_selector(blocks, node, stack, to_encapsulate) {
const block = blocks.pop();
if (!block)
return false;
if (!node) {
return blocks.every(block => block.global);
}
switch (block_might_apply_to_node(block, node)) {
case BlockAppliesToNode.NotPossible:
return false;
case BlockAppliesToNode.UnknownSelectorType:
// bail. TODO figure out what these could be
to_encapsulate.push({ node, block });
return true;
}
if (block.combinator) {
if (block.combinator.type === 'WhiteSpace') {
for (const ancestor_block of blocks) {
if (ancestor_block.global) {
continue;
}
for (const stack_node of stack) {
if (block_might_apply_to_node(ancestor_block, stack_node) !== BlockAppliesToNode.NotPossible) {
to_encapsulate.push({ node: stack_node, block: ancestor_block });
}
}
if (to_encapsulate.length) {
to_encapsulate.push({ node, block });
return true;
}
}
if (blocks.every(block => block.global)) {
to_encapsulate.push({ node, block });
return true;
}
return false;
}
else if (block.combinator.name === '>') {
if (apply_selector(blocks, stack.pop(), stack, to_encapsulate)) {
to_encapsulate.push({ node, block });
return true;
}
return false;
}
// TODO other combinators
to_encapsulate.push({ node, block });
return true;
}
to_encapsulate.push({ node, block });
return true;
}
function block_might_apply_to_node(block, node) {
let i = block.selectors.length;
while (i--) {
const selector = block.selectors[i];
const name = typeof selector.name === 'string' && selector.name.replace(/\\(.)/g, '$1');
if (selector.type === 'PseudoClassSelector' || selector.type === 'PseudoElementSelector') {
continue;
}
if (selector.type === 'PseudoClassSelector' && name === 'global') {
// TODO shouldn't see this here... maybe we should enforce that :global(...)
// cannot be sandwiched between non-global selectors?
return BlockAppliesToNode.NotPossible;
}
if (selector.type === 'ClassSelector') {
if (!attribute_matches(node, 'class', name, '~=', false) && !node.classes.some(c => c.name === name))
return BlockAppliesToNode.NotPossible;
}
else if (selector.type === 'IdSelector') {
if (!attribute_matches(node, 'id', name, '=', false))
return BlockAppliesToNode.NotPossible;
}
else if (selector.type === 'AttributeSelector') {
if (!attribute_matches(node, selector.name.name, selector.value && unquote(selector.value), selector.matcher, selector.flags))
return BlockAppliesToNode.NotPossible;
}
else if (selector.type === 'TypeSelector') {
if (node.name.toLowerCase() !== name.toLowerCase() && name !== '*')
return BlockAppliesToNode.NotPossible;
}
else {
return BlockAppliesToNode.UnknownSelectorType;
}
}
return BlockAppliesToNode.Possible;
}
function test_attribute(operator, expected_value, case_insensitive, value) {
if (case_insensitive) {
expected_value = expected_value.toLowerCase();
value = value.toLowerCase();
}
switch (operator) {
case '=': return value === expected_value;
case '~=': return value.split(/\s/).includes(expected_value);
case '|=': return `${value}-`.startsWith(`${expected_value}-`);
case '^=': return value.startsWith(expected_value);
case '$=': return value.endsWith(expected_value);
case '*=': return value.includes(expected_value);
default: throw new Error(`this shouldn't happen`);
}
}
function attribute_matches(node, name, expected_value, operator, case_insensitive) {
const spread = node.attributes.find(attr => attr.type === 'Spread');
if (spread)
return true;
if (node.bindings.some((binding) => binding.name === name))
return true;
const attr = node.attributes.find((attr) => attr.name === name);
if (!attr)
return false;
if (attr.is_true)
return operator === null;
if (!expected_value)
return true;
if (attr.chunks.length === 1) {
const value = attr.chunks[0];
if (!value)
return false;
if (value.type === 'Text')
return test_attribute(operator, expected_value, case_insensitive, value.data);
}
const possible_values = new Set();
let prev_values = [];
for (const chunk of attr.chunks) {
const current_possible_values = new Set();
if (chunk.type === 'Text') {
current_possible_values.add(chunk.data);
}
else {
gather_possible_values(chunk.node, current_possible_values);
}
// impossible to find out all combinations
if (current_possible_values.has(UNKNOWN))
return true;
if (prev_values.length > 0) {
const start_with_space = [];
const remaining = [];
current_possible_values.forEach((current_possible_value) => {
if (/^\s/.test(current_possible_value)) {
start_with_space.push(current_possible_value);
}
else {
remaining.push(current_possible_value);
}
});
if (remaining.length > 0) {
if (start_with_space.length > 0) {
prev_values.forEach(prev_value => possible_values.add(prev_value));
}
const combined = [];
prev_values.forEach((prev_value) => {
remaining.forEach((value) => {
combined.push(prev_value + value);
});
});
prev_values = combined;
start_with_space.forEach((value) => {
if (/\s$/.test(value)) {
possible_values.add(value);
}
else {
prev_values.push(value);
}
});
continue;
}
else {
prev_values.forEach(prev_value => possible_values.add(prev_value));
prev_values = [];
}
}
current_possible_values.forEach((current_possible_value) => {
if (/\s$/.test(current_possible_value)) {
possible_values.add(current_possible_value);
}
else {
prev_values.push(current_possible_value);
}
});
if (prev_values.length < current_possible_values.size) {
prev_values.push(' ');
}
if (prev_values.length > 20) {
// might grow exponentially, bail out
return true;
}
}
prev_values.forEach(prev_value => possible_values.add(prev_value));
if (possible_values.has(UNKNOWN))
return true;
for (const value of possible_values) {
if (test_attribute(operator, expected_value, case_insensitive, value))
return true;
}
return false;
}
function unquote(value) {
if (value.type === 'Identifier')
return value.name;
const str = value.value;
if (str[0] === str[str.length - 1] && str[0] === "'" || str[0] === '"') {
return str.slice(1, str.length - 1);
}
return str;
}
class Block$2 {
constructor(combinator) {
this.combinator = combinator;
this.global = false;
this.selectors = [];
this.start = null;
this.end = null;
this.should_encapsulate = false;
}
add(selector) {
if (this.selectors.length === 0) {
this.start = selector.start;
this.global = selector.type === 'PseudoClassSelector' && selector.name === 'global';
}
this.selectors.push(selector);
this.end = selector.end;
}
}
function group_selectors(selector) {
let block = new Block$2(null);
const blocks = [block];
selector.children.forEach((child) => {
if (child.type === 'WhiteSpace' || child.type === 'Combinator') {
block = new Block$2(child);
blocks.push(block);
}
else {
block.add(child);
}
});
return blocks;
}
// https://github.com/darkskyapp/string-hash/blob/master/index.js
function hash(str) {
str = str.replace(/\r/g, "");
let hash = 5381;
let i = str.length;
while (i--)
hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
return (hash >>> 0).toString(36);
}
function remove_css_prefix(name) {
return name.replace(/^-((webkit)|(moz)|(o)|(ms))-/, '');
}
const is_keyframes_node = (node) => remove_css_prefix(node.name) === 'keyframes';
const at_rule_has_declaration = ({ block }) => block &&
block.children &&
block.children.find((node) => node.type === 'Declaration');
function minify_declarations(code, start, declarations) {
let c = start;
declarations.forEach((declaration, i) => {
const separator = i > 0 ? ';' : '';
if ((declaration.node.start - c) > separator.length) {
code.overwrite(c, declaration.node.start, separator);
}
declaration.minify(code);
c = declaration.node.end;
});
return c;
}
class Rule$1 {
constructor(node, stylesheet, parent) {
this.node = node;
this.parent = parent;
this.selectors = node.selector.children.map((node) => new Selector$1(node, stylesheet));
this.declarations = node.block.children.map((node) => new Declaration$1(node));
}
apply(node, stack) {
this.selectors.forEach(selector => selector.apply(node, stack)); // TODO move the logic in here?
}
is_used(dev) {
if (this.parent && this.parent.node.type === 'Atrule' && is_keyframes_node(this.parent.node))
return true;
if (this.declarations.length === 0)
return dev;
return this.selectors.some(s => s.used);
}
minify(code, _dev) {
let c = this.node.start;
let started = false;
this.selectors.forEach((selector) => {
if (selector.used) {
const separator = started ? ',' : '';
if ((selector.node.start - c) > separator.length) {
code.overwrite(c, selector.node.start, separator);
}
selector.minify(code);
c = selector.node.end;
started = true;
}
});
code.remove(c, this.node.block.start);
c = this.node.block.start + 1;
c = minify_declarations(code, c, this.declarations);
code.remove(c, this.node.block.end - 1);
}
transform(code, id, keyframes, max_amount_class_specificity_increased) {
if (this.parent && this.parent.node.type === 'Atrule' && is_keyframes_node(this.parent.node))
return true;
const attr = `.${id}`;
this.selectors.forEach(selector => selector.transform(code, attr, max_amount_class_specificity_increased));
this.declarations.forEach(declaration => declaration.transform(code, keyframes));
}
validate(component) {
this.selectors.forEach(selector => {
selector.validate(component);
});
}
warn_on_unused_selector(handler) {
this.selectors.forEach(selector => {
if (!selector.used)
handler(selector);
});
}
get_max_amount_class_specificity_increased() {
return Math.max(...this.selectors.map(selector => selector.get_amount_class_specificity_increased()));
}
}
class Declaration$1 {
constructor(node) {
this.node = node;
}
transform(code, keyframes) {
const property = this.node.property && remove_css_prefix(this.node.property.toLowerCase());
if (property === 'animation' || property === 'animation-name') {
this.node.value.children.forEach((block) => {
if (block.type === 'Identifier') {
const name = block.name;
if (keyframes.has(name)) {
code.overwrite(block.start, block.end, keyframes.get(name));
}
}
});
}
}
minify(code) {
if (!this.node.property)
return; // @apply, and possibly other weird cases?
const c = this.node.start + this.node.property.length;
const first = this.node.value.children
? this.node.value.children[0]
: this.node.value;
let start = first.start;
while (/\s/.test(code.original[start]))
start += 1;
if (start - c > 1) {
code.overwrite(c, start, ':');
}
}
}
class Atrule$1 {
constructor(node) {
this.node = node;
this.children = [];
this.declarations = [];
}
apply(node, stack) {
if (this.node.name === 'media' || this.node.name === 'supports') {
this.children.forEach(child => {
child.apply(node, stack);
});
}
else if (is_keyframes_node(this.node)) {
this.children.forEach((rule) => {
rule.selectors.forEach(selector => {
selector.used = true;
});
});
}
}
is_used(_dev) {
return true; // TODO
}
minify(code, dev) {
if (this.node.name === 'media') {
const expression_char = code.original[this.node.expression.start];
let c = this.node.start + (expression_char === '(' ? 6 : 7);
if (this.node.expression.start > c)
code.remove(c, this.node.expression.start);
this.node.expression.children.forEach((query) => {
// TODO minify queries
c = query.end;
});
code.remove(c, this.node.block.start);
}
else if (this.node.name === 'supports') {
let c = this.node.start + 9;
if (this.node.expression.start - c > 1)
code.overwrite(c, this.node.expression.start, ' ');
this.node.expression.children.forEach((query) => {
// TODO minify queries
c = query.end;
});
code.remove(c, this.node.block.start);
}
else {
let c = this.node.start + this.node.name.length + 1;
if (this.node.expression) {
if (this.node.expression.start - c > 1)
code.overwrite(c, this.node.expression.start, ' ');
c = this.node.expression.end;
}
if (this.node.block && this.node.block.start - c > 0) {
code.remove(c, this.node.block.start);
}
}
// TODO other atrules
if (this.node.block) {
let c = this.node.block.start + 1;
if (this.declarations.length) {
c = minify_declarations(code, c, this.declarations);
// if the atrule has children, leave the last declaration semicolon alone
if (this.children.length)
c++;
}
this.children.forEach(child => {
if (child.is_used(dev)) {
code.remove(c, child.node.start);
child.minify(code, dev);
c = child.node.end;
}
});
code.remove(c, this.node.block.end - 1);
}
}
transform(code, id, keyframes, max_amount_class_specificity_increased) {
if (is_keyframes_node(this.node)) {
this.node.expression.children.forEach(({ type, name, start, end }) => {
if (type === 'Identifier') {
if (name.startsWith('-global-')) {
code.remove(start, start + 8);
this.children.forEach((rule) => {
rule.selectors.forEach(selector => {
selector.used = true;
});
});
}
else {
code.overwrite(start, end, keyframes.get(name));
}
}
});
}
this.children.forEach(child => {
child.transform(code, id, keyframes, max_amount_class_specificity_increased);
});
}
validate(component) {
this.children.forEach(child => {
child.validate(component);
});
}
warn_on_unused_selector(handler) {
if (this.node.name !== 'media')
return;
this.children.forEach(child => {
child.warn_on_unused_selector(handler);
});
}
get_max_amount_class_specificity_increased() {
return Math.max(...this.children.map(rule => rule.get_max_amount_class_specificity_increased()));
}
}
class Stylesheet {
constructor(source, ast, filename, dev) {
this.children = [];
this.keyframes = new Map();
this.nodes_with_css_class = new Set();
this.source = source;
this.ast = ast;
this.filename = filename;
this.dev = dev;
if (ast.css && ast.css.children.length) {
this.id = `svelte-${hash(ast.css.content.styles)}`;
this.has_styles = true;
const stack = [];
let depth = 0;
let current_atrule = null;
walk(ast.css, {
enter: (node) => {
if (node.type === 'Atrule') {
const atrule = new Atrule$1(node);
stack.push(atrule);
if (current_atrule) {
current_atrule.children.push(atrule);
}
else if (depth <= 1) {
this.children.push(atrule);
}
if (is_keyframes_node(node)) {
node.expression.children.forEach((expression) => {
if (expression.type === 'Identifier' && !expression.name.startsWith('-global-')) {
this.keyframes.set(expression.name, `${this.id}-${expression.name}`);
}
});
}
else if (at_rule_has_declaration(node)) {
const at_rule_declarations = node.block.children
.filter(node => node.type === 'Declaration')
.map(node => new Declaration$1(node));
atrule.declarations.push(...at_rule_declarations);
}
current_atrule = atrule;
}
if (node.type === 'Rule') {
const rule = new Rule$1(node, this, current_atrule);
if (current_atrule) {
current_atrule.children.push(rule);
}
else if (depth <= 1) {
this.children.push(rule);
}
}
depth += 1;
},
leave: (node) => {
if (node.type === 'Atrule') {
stack.pop();
current_atrule = stack[stack.length - 1];
}
depth -= 1;
}
});
}
else {
this.has_styles = false;
}
}
apply(node) {
if (!this.has_styles)
return;
const stack = [];
let parent = node;
while (parent = parent.parent) {
if (parent.type === 'Element')
stack.unshift(parent);
}
for (let i = 0; i < this.children.length; i += 1) {
const child = this.children[i];
child.apply(node, stack);
}
}
reify() {
this.nodes_with_css_class.forEach((node) => {
node.add_css_class();
});
}
render(file, should_transform_selectors) {
if (!this.has_styles) {
return { code: null, map: null };
}
const code = new MagicString(this.source);
walk(this.ast.css, {
enter: (node) => {
code.addSourcemapLocation(node.start);
code.addSourcemapLocation(node.end);
}
});
if (should_transform_selectors) {
const max = Math.max(...this.children.map(rule => rule.get_max_amount_class_specificity_increased()));
this.children.forEach((child) => {
child.transform(code, this.id, this.keyframes, max);
});
}
let c = 0;
this.children.forEach(child => {
if (child.is_used(this.dev)) {
code.remove(c, child.node.start);
child.minify(code, this.dev);
c = child.node.end;
}
});
code.remove(c, this.source.length);
return {
code: code.toString(),
map: code.generateMap({
includeContent: true,
source: this.filename,
file
})
};
}
validate(component) {
this.children.forEach(child => {
child.validate(component);
});
}
warn_on_unused_selectors(component) {
this.children.forEach(child => {
child.warn_on_unused_selector((selector) => {
component.warn(selector.node, {
code: `css-unused-selector`,
message: `Unused CSS selector`
});
});
});
}
}
const test = typeof process$1 !== 'undefined' && process$1.env.TEST;
class AbstractBlock extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
}
warn_if_empty_block() {
if (!this.children || this.children.length > 1)
return;
const child = this.children[0];
if (!child || (child.type === 'Text' && !/[^ \r\n\f\v\t]/.test(child.data))) {
this.component.warn(this, {
code: 'empty-block',
message: 'Empty block'
});
}
}
}
class PendingBlock extends AbstractBlock {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.children = map_children(component, parent, scope, info.children);
if (!info.skip) {
this.warn_if_empty_block();
}
}
}
class ThenBlock extends AbstractBlock {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.scope = scope.child();
if (parent.then_node) {
parent.then_contexts.forEach(context => {
this.scope.add(context.key.name, parent.expression.dependencies, this);
});
}
this.children = map_children(component, parent, this.scope, info.children);
if (!info.skip) {
this.warn_if_empty_block();
}
}
}
class CatchBlock extends AbstractBlock {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.scope = scope.child();
if (parent.catch_node) {
parent.catch_contexts.forEach(context => {
this.scope.add(context.key.name, parent.expression.dependencies, this);
});
}
this.children = map_children(component, parent, this.scope, info.children);
if (!info.skip) {
this.warn_if_empty_block();
}
}
}
function unpack_destructuring(contexts, node, modifier) {
if (!node)
return;
if (node.type === 'Identifier') {
contexts.push({
key: node,
modifier
});
}
else if (node.type === 'RestElement') {
contexts.push({
key: node.argument,
modifier
});
}
else if (node.type === 'ArrayPattern') {
node.elements.forEach((element, i) => {
if (element && element.type === 'RestElement') {
unpack_destructuring(contexts, element, node => x `${modifier(node)}.slice(${i})`);
}
else if (element && element.type === 'AssignmentPattern') {
unpack_destructuring(contexts, element.left, node => x `${modifier(node)}[${i}] !== undefined ? ${modifier(node)}[${i}] : ${element.right}`);
}
else {
unpack_destructuring(contexts, element, node => x `${modifier(node)}[${i}]`);
}
});
}
else if (node.type === 'ObjectPattern') {
const used_properties = [];
node.properties.forEach((property) => {
if (property.type === 'RestElement') {
unpack_destructuring(contexts, property.argument, node => x `@object_without_properties(${modifier(node)}, [${used_properties}])`);
}
else {
const key = property.key;
const value = property.value;
used_properties.push(x `"${key.name}"`);
if (value.type === 'AssignmentPattern') {
unpack_destructuring(contexts, value.left, node => x `${modifier(node)}.${key.name} !== undefined ? ${modifier(node)}.${key.name} : ${value.right}`);
}
else {
unpack_destructuring(contexts, value, node => x `${modifier(node)}.${key.name}`);
}
}
});
}
}
class AwaitBlock$1 extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.expression = new Expression(component, this, scope, info.expression);
this.then_node = info.value;
this.catch_node = info.error;
if (this.then_node) {
this.then_contexts = [];
unpack_destructuring(this.then_contexts, info.value, node => node);
}
if (this.catch_node) {
this.catch_contexts = [];
unpack_destructuring(this.catch_contexts, info.error, node => node);
}
this.pending = new PendingBlock(component, this, scope, info.pending);
this.then = new ThenBlock(component, this, scope, info.then);
this.catch = new CatchBlock(component, this, scope, info.catch);
}
}
class EventHandler extends Node$1 {
constructor(component, parent, template_scope, info) {
super(component, parent, template_scope, info);
this.uses_context = false;
this.can_make_passive = false;
this.name = info.name;
this.modifiers = new Set(info.modifiers);
if (info.expression) {
this.expression = new Expression(component, this, template_scope, info.expression);
this.uses_context = this.expression.uses_context;
if (/FunctionExpression/.test(info.expression.type) && info.expression.params.length === 0) {
// TODO make this detection more accurate — if `event.preventDefault` isn't called, and
// `event` is passed to another function, we can make it passive
this.can_make_passive = true;
}
else if (info.expression.type === 'Identifier') {
let node = component.node_for_declaration.get(info.expression.name);
if (node) {
if (node.type === 'VariableDeclaration') {
// for `const handleClick = () => {...}`, we want the [arrow] function expression node
const declarator = node.declarations.find(d => d.id.name === info.expression.name);
node = declarator && declarator.init;
}
if (node && (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ArrowFunctionExpression') && node.params.length === 0) {
this.can_make_passive = true;
}
}
}
}
else {
this.handler_name = component.get_unique_name(`${sanitize(this.name)}_handler`);
}
}
get reassigned() {
if (!this.expression) {
return false;
}
const node = this.expression.node;
if (/FunctionExpression/.test(node.type)) {
return false;
}
return this.expression.dynamic_dependencies().length > 0;
}
}
class Body extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.handlers = [];
info.attributes.forEach(node => {
if (node.type === 'EventHandler') {
this.handlers.push(new EventHandler(component, this, scope, node));
}
});
}
}
const pattern = /^\s*svelte-ignore\s+([\s\S]+)\s*$/m;
class Comment$2 extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.data = info.data;
const match = pattern.exec(this.data);
this.ignores = match ? match[1].split(/[^\S]/).map(x => x.trim()).filter(Boolean) : [];
}
}
class ElseBlock extends AbstractBlock {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.children = map_children(component, this, scope, info.children);
this.warn_if_empty_block();
}
}
class EachBlock$1 extends AbstractBlock {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.has_binding = false;
this.has_index_binding = false;
this.expression = new Expression(component, this, scope, info.expression);
this.context = info.context.name || 'each'; // TODO this is used to facilitate binding; currently fails with destructuring
this.context_node = info.context;
this.index = info.index;
this.scope = scope.child();
this.contexts = [];
unpack_destructuring(this.contexts, info.context, node => node);
this.contexts.forEach(context => {
this.scope.add(context.key.name, this.expression.dependencies, this);
});
if (this.index) {
// index can only change if this is a keyed each block
const dependencies = info.key ? this.expression.dependencies : new Set([]);
this.scope.add(this.index, dependencies, this);
}
this.key = info.key
? new Expression(component, this, this.scope, info.key)
: null;
this.has_animation = false;
this.children = map_children(component, this, this.scope, info.children);
if (this.has_animation) {
if (this.children.length !== 1) {
const child = this.children.find(child => !!child.animation);
component.error(child.animation, {
code: `invalid-animation`,
message: `An element that use the animate directive must be the sole child of a keyed each block`
});
}
}
this.warn_if_empty_block();
this.else = info.else
? new ElseBlock(component, this, this.scope, info.else)
: null;
}
}
class Attribute extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.scope = scope;
if (info.type === 'Spread') {
this.name = null;
this.is_spread = true;
this.is_true = false;
this.expression = new Expression(component, this, scope, info.expression);
this.dependencies = this.expression.dependencies;
this.chunks = null;
this.is_static = false;
}
else {
this.name = info.name;
this.is_true = info.value === true;
this.is_static = true;
this.dependencies = new Set();
this.chunks = this.is_true
? []
: info.value.map(node => {
if (node.type === 'Text')
return node;
this.is_static = false;
const expression = new Expression(component, this, scope, node.expression);
add_to_set(this.dependencies, expression.dependencies);
return expression;
});
}
}
get_dependencies() {
if (this.is_spread)
return this.expression.dynamic_dependencies();
const dependencies = new Set();
this.chunks.forEach(chunk => {
if (chunk.type === 'Expression') {
add_to_set(dependencies, chunk.dynamic_dependencies());
}
});
return Array.from(dependencies);
}
get_value(block) {
if (this.is_true)
return x `true`;
if (this.chunks.length === 0)
return x `""`;
if (this.chunks.length === 1) {
return this.chunks[0].type === 'Text'
? string_literal(this.chunks[0].data)
: this.chunks[0].manipulate(block);
}
let expression = this.chunks
.map(chunk => chunk.type === 'Text' ? string_literal(chunk.data) : chunk.manipulate(block))
.reduce((lhs, rhs) => x `${lhs} + ${rhs}`);
if (this.chunks[0].type !== 'Text') {
expression = x `"" + ${expression}`;
}
return expression;
}
get_static_value() {
if (this.is_spread || this.dependencies.size > 0)
return null;
return this.is_true
? true
: this.chunks[0]
// method should be called only when `is_static = true`
? this.chunks[0].data
: '';
}
should_cache() {
return this.is_static
? false
: this.chunks.length === 1
// @ts-ignore todo: probably error
? this.chunks[0].node.type !== 'Identifier' || this.scope.names.has(this.chunks[0].node.name)
: true;
}
}
// TODO this should live in a specific binding
const read_only_media_attributes = new Set([
'duration',
'buffered',
'seekable',
'played',
'seeking',
'ended',
'videoHeight',
'videoWidth'
]);
class Binding extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
if (info.expression.type !== 'Identifier' && info.expression.type !== 'MemberExpression') {
component.error(info, {
code: 'invalid-directive-value',
message: 'Can only bind to an identifier (e.g. `foo`) or a member expression (e.g. `foo.bar` or `foo[baz]`)'
});
}
this.name = info.name;
this.expression = new Expression(component, this, scope, info.expression);
this.raw_expression = JSON.parse(JSON.stringify(info.expression));
const { name } = get_object(this.expression.node);
this.is_contextual = Array.from(this.expression.references).some(name => scope.names.has(name));
// make sure we track this as a mutable ref
if (scope.is_let(name)) {
component.error(this, {
code: 'invalid-binding',
message: 'Cannot bind to a variable declared with the let: directive'
});
}
else if (scope.names.has(name)) {
if (scope.is_await(name)) {
component.error(this, {
code: 'invalid-binding',
message: 'Cannot bind to a variable declared with {#await ... then} or {:catch} blocks'
});
}
scope.dependencies_for_name.get(name).forEach(name => {
const variable = component.var_lookup.get(name);
if (variable) {
variable.mutated = true;
}
});
}
else {
const variable = component.var_lookup.get(name);
if (!variable || variable.global)
component.error(this.expression.node, {
code: 'binding-undeclared',
message: `${name} is not declared`
});
variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true;
if (info.expression.type === 'Identifier' && !variable.writable)
component.error(this.expression.node, {
code: 'invalid-binding',
message: 'Cannot bind to a variable which is not writable',
});
}
const type = parent.get_static_attribute_value('type');
this.is_readonly = (dimensions.test(this.name) ||
(parent.is_media_node && parent.is_media_node() && read_only_media_attributes.has(this.name)) ||
(parent.name === 'input' && type === 'file') // TODO others?
);
}
is_readonly_media_attribute() {
return read_only_media_attributes.has(this.name);
}
}
class Transition extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
component.warn_if_undefined(info.name, info, scope);
this.name = info.name;
component.add_reference(info.name.split('.')[0]);
this.directive = info.intro && info.outro ? 'transition' : info.intro ? 'in' : 'out';
this.is_local = info.modifiers.includes('local');
if ((info.intro && parent.intro) || (info.outro && parent.outro)) {
const parent_transition = (parent.intro || parent.outro);
const message = this.directive === parent_transition.directive
? `An element can only have one '${this.directive}' directive`
: `An element cannot have both ${describe(parent_transition)} directive and ${describe(this)} directive`;
component.error(info, {
code: `duplicate-transition`,
message
});
}
this.expression = info.expression
? new Expression(component, this, scope, info.expression, true)
: null;
}
}
function describe(transition) {
return transition.directive === 'transition'
? `a 'transition'`
: `an '${transition.directive}'`;
}
class Animation extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
component.warn_if_undefined(info.name, info, scope);
this.name = info.name;
component.add_reference(info.name.split('.')[0]);
if (parent.animation) {
component.error(this, {
code: `duplicate-animation`,
message: `An element can only have one 'animate' directive`
});
}
const block = parent.parent;
if (!block || block.type !== 'EachBlock' || !block.key) {
// TODO can we relax the 'immediate child' rule?
component.error(this, {
code: `invalid-animation`,
message: `An element that use the animate directive must be the immediate child of a keyed each block`
});
}
block.has_animation = true;
this.expression = info.expression
? new Expression(component, this, scope, info.expression, true)
: null;
}
}
class Class extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.name = info.name;
this.expression = info.expression
? new Expression(component, this, scope, info.expression)
: null;
}
}
// Whitespace inside one of these elements will not result in
// a whitespace node being created in any circumstances. (This
// list is almost certainly very incomplete)
const elements_without_text = new Set([
'audio',
'datalist',
'dl',
'optgroup',
'select',
'video',
]);
class Text$1 extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.data = info.data;
this.synthetic = info.synthetic || false;
}
should_skip() {
if (/\S/.test(this.data))
return false;
const parent_element = this.find_nearest(/(?:Element|InlineComponent|Head)/);
if (!parent_element)
return false;
if (parent_element.type === 'Head')
return true;
if (parent_element.type === 'InlineComponent')
return parent_element.children.length === 1 && this === parent_element.children[0];
// svg namespace exclusions
if (/svg$/.test(parent_element.namespace)) {
if (this.prev && this.prev.type === "Element" && this.prev.name === "tspan")
return false;
}
return parent_element.namespace || elements_without_text.has(parent_element.name);
}
}
const applicable = new Set(['Identifier', 'ObjectExpression', 'ArrayExpression', 'Property']);
class Let extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.names = [];
this.name = { type: 'Identifier', name: info.name };
const { names } = this;
if (info.expression) {
this.value = info.expression;
walk(info.expression, {
enter(node) {
if (!applicable.has(node.type)) {
component.error(node, {
code: 'invalid-let',
message: `let directive value must be an identifier or an object/array pattern`
});
}
if (node.type === 'Identifier') {
names.push(node.name);
}
// slightly unfortunate hack
if (node.type === 'ArrayExpression') {
node.type = 'ArrayPattern';
}
if (node.type === 'ObjectExpression') {
node.type = 'ObjectPattern';
}
}
});
}
else {
names.push(this.name.name);
}
}
}
const svg$1 = /^(?:altGlyph|altGlyphDef|altGlyphItem|animate|animateColor|animateMotion|animateTransform|circle|clipPath|color-profile|cursor|defs|desc|discard|ellipse|feBlend|feColorMatrix|feComponentTransfer|feComposite|feConvolveMatrix|feDiffuseLighting|feDisplacementMap|feDistantLight|feDropShadow|feFlood|feFuncA|feFuncB|feFuncG|feFuncR|feGaussianBlur|feImage|feMerge|feMergeNode|feMorphology|feOffset|fePointLight|feSpecularLighting|feSpotLight|feTile|feTurbulence|filter|font|font-face|font-face-format|font-face-name|font-face-src|font-face-uri|foreignObject|g|glyph|glyphRef|hatch|hatchpath|hkern|image|line|linearGradient|marker|mask|mesh|meshgradient|meshpatch|meshrow|metadata|missing-glyph|mpath|path|pattern|polygon|polyline|radialGradient|rect|set|solidcolor|stop|svg|switch|symbol|text|textPath|tref|tspan|unknown|use|view|vkern)$/;
const aria_attributes = 'activedescendant atomic autocomplete busy checked colcount colindex colspan controls current describedby details disabled dropeffect errormessage expanded flowto grabbed haspopup hidden invalid keyshortcuts label labelledby level live modal multiline multiselectable orientation owns placeholder posinset pressed readonly relevant required roledescription rowcount rowindex rowspan selected setsize sort valuemax valuemin valuenow valuetext'.split(' ');
const aria_attribute_set = new Set(aria_attributes);
const aria_roles = 'alert alertdialog application article banner blockquote button caption cell checkbox code columnheader combobox complementary contentinfo definition deletion dialog directory document emphasis feed figure form generic grid gridcell group heading img link list listbox listitem log main marquee math meter menu menubar menuitem menuitemcheckbox menuitemradio navigation none note option paragraph presentation progressbar radio radiogroup region row rowgroup rowheader scrollbar search searchbox separator slider spinbutton status strong subscript superscript switch tab table tablist tabpanel term textbox time timer toolbar tooltip tree treegrid treeitem'.split(' ');
const aria_role_set = new Set(aria_roles);
const a11y_required_attributes = {
a: ['href'],
area: ['alt', 'aria-label', 'aria-labelledby'],
// html-has-lang
html: ['lang'],
// iframe-has-title
iframe: ['title'],
img: ['alt'],
object: ['title', 'aria-label', 'aria-labelledby']
};
const a11y_distracting_elements = new Set([
'blink',
'marquee'
]);
const a11y_required_content = new Set([
// anchor-has-content
'a',
// heading-has-content
'h1',
'h2',
'h3',
'h4',
'h5',
'h6'
]);
const a11y_no_onchange = new Set([
'select',
'option'
]);
const a11y_labelable = new Set([
"button",
"input",
"keygen",
"meter",
"output",
"progress",
"select",
"textarea"
]);
const invisible_elements = new Set(['meta', 'html', 'script', 'style']);
const valid_modifiers = new Set([
'preventDefault',
'stopPropagation',
'capture',
'once',
'passive',
'self'
]);
const passive_events = new Set([
'wheel',
'touchstart',
'touchmove',
'touchend',
'touchcancel'
]);
function get_namespace(parent, element, explicit_namespace) {
const parent_element = parent.find_nearest(/^Element/);
if (!parent_element) {
return explicit_namespace || (svg$1.test(element.name)
? namespaces.svg
: null);
}
if (svg$1.test(element.name.toLowerCase()))
return namespaces.svg;
if (parent_element.name.toLowerCase() === 'foreignobject')
return null;
return parent_element.namespace;
}
class Element$1 extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.attributes = [];
this.actions = [];
this.bindings = [];
this.classes = [];
this.handlers = [];
this.lets = [];
this.intro = null;
this.outro = null;
this.animation = null;
this.name = info.name;
this.namespace = get_namespace(parent, this, component.namespace);
if (this.name === 'textarea') {
if (info.children.length > 0) {
const value_attribute = info.attributes.find(node => node.name === 'value');
if (value_attribute) {
component.error(value_attribute, {
code: `textarea-duplicate-value`,
message: `A <textarea> can have either a value attribute or (equivalently) child content, but not both`
});
}
// this is an egregious hack, but it's the easiest way to get <textarea>
// children treated the same way as a value attribute
info.attributes.push({
type: 'Attribute',
name: 'value',
value: info.children
});
info.children = [];
}
}
if (this.name === 'option') {
// Special case — treat these the same way:
// <option>{foo}</option>
// <option value={foo}>{foo}</option>
const value_attribute = info.attributes.find(attribute => attribute.name === 'value');
if (!value_attribute) {
info.attributes.push({
type: 'Attribute',
name: 'value',
value: info.children,
synthetic: true
});
}
}
const has_let = info.attributes.some(node => node.type === 'Let');
if (has_let) {
scope = scope.child();
}
// Binding relies on Attribute, defer its evaluation
const order = ['Binding']; // everything else is -1
info.attributes.sort((a, b) => order.indexOf(a.type) - order.indexOf(b.type));
info.attributes.forEach(node => {
switch (node.type) {
case 'Action':
this.actions.push(new Action(component, this, scope, node));
break;
case 'Attribute':
case 'Spread':
// special case
if (node.name === 'xmlns')
this.namespace = node.value[0].data;
this.attributes.push(new Attribute(component, this, scope, node));
break;
case 'Binding':
this.bindings.push(new Binding(component, this, scope, node));
break;
case 'Class':
this.classes.push(new Class(component, this, scope, node));
break;
case 'EventHandler':
this.handlers.push(new EventHandler(component, this, scope, node));
break;
case 'Let': {
const l = new Let(component, this, scope, node);
this.lets.push(l);
const dependencies = new Set([l.name.name]);
l.names.forEach(name => {
scope.add(name, dependencies, this);
});
break;
}
case 'Transition':
{
const transition = new Transition(component, this, scope, node);
if (node.intro)
this.intro = transition;
if (node.outro)
this.outro = transition;
break;
}
case 'Animation':
this.animation = new Animation(component, this, scope, node);
break;
default:
throw new Error(`Not implemented: ${node.type}`);
}
});
this.scope = scope;
this.children = map_children(component, this, this.scope, info.children);
this.validate();
component.stylesheet.apply(this);
}
validate() {
if (a11y_distracting_elements.has(this.name)) {
// no-distracting-elements
this.component.warn(this, {
code: `a11y-distracting-elements`,
message: `A11y: Avoid <${this.name}> elements`
});
}
if (this.name === 'figcaption') {
let { parent } = this;
let is_figure_parent = false;
while (parent) {
if (parent.name === 'figure') {
is_figure_parent = true;
break;
}
if (parent.type === 'Element') {
break;
}
parent = parent.parent;
}
if (!is_figure_parent) {
this.component.warn(this, {
code: `a11y-structure`,
message: `A11y: <figcaption> must be an immediate child of <figure>`
});
}
}
if (this.name === 'figure') {
const children = this.children.filter(node => {
if (node.type === 'Comment')
return false;
if (node.type === 'Text')
return /\S/.test(node.data);
return true;
});
const index = children.findIndex(child => child.name === 'figcaption');
if (index !== -1 && (index !== 0 && index !== children.length - 1)) {
this.component.warn(children[index], {
code: `a11y-structure`,
message: `A11y: <figcaption> must be first or last child of <figure>`
});
}
}
this.validate_attributes();
this.validate_special_cases();
this.validate_bindings();
this.validate_content();
this.validate_event_handlers();
}
validate_attributes() {
const { component, parent } = this;
const attribute_map = new Map();
this.attributes.forEach(attribute => {
if (attribute.is_spread)
return;
const name = attribute.name.toLowerCase();
// aria-props
if (name.startsWith('aria-')) {
if (invisible_elements.has(this.name)) {
// aria-unsupported-elements
component.warn(attribute, {
code: `a11y-aria-attributes`,
message: `A11y: <${this.name}> should not have aria-* attributes`
});
}
const type = name.slice(5);
if (!aria_attribute_set.has(type)) {
const match = fuzzymatch(type, aria_attributes);
let message = `A11y: Unknown aria attribute 'aria-${type}'`;
if (match)
message += ` (did you mean '${match}'?)`;
component.warn(attribute, {
code: `a11y-unknown-aria-attribute`,
message
});
}
if (name === 'aria-hidden' && /^h[1-6]$/.test(this.name)) {
component.warn(attribute, {
code: `a11y-hidden`,
message: `A11y: <${this.name}> element should not be hidden`
});
}
}
// aria-role
if (name === 'role') {
if (invisible_elements.has(this.name)) {
// aria-unsupported-elements
component.warn(attribute, {
code: `a11y-misplaced-role`,
message: `A11y: <${this.name}> should not have role attribute`
});
}
const value = attribute.get_static_value();
// @ts-ignore
if (value && !aria_role_set.has(value)) {
// @ts-ignore
const match = fuzzymatch(value, aria_roles);
let message = `A11y: Unknown role '${value}'`;
if (match)
message += ` (did you mean '${match}'?)`;
component.warn(attribute, {
code: `a11y-unknown-role`,
message
});
}
}
// no-access-key
if (name === 'accesskey') {
component.warn(attribute, {
code: `a11y-accesskey`,
message: `A11y: Avoid using accesskey`
});
}
// no-autofocus
if (name === 'autofocus') {
component.warn(attribute, {
code: `a11y-autofocus`,
message: `A11y: Avoid using autofocus`
});
}
// scope
if (name === 'scope' && this.name !== 'th') {
component.warn(attribute, {
code: `a11y-misplaced-scope`,
message: `A11y: The scope attribute should only be used with <th> elements`
});
}
// tabindex-no-positive
if (name === 'tabindex') {
const value = attribute.get_static_value();
// @ts-ignore todo is tabindex=true correct case?
if (!isNaN(value) && +value > 0) {
component.warn(attribute, {
code: `a11y-positive-tabindex`,
message: `A11y: avoid tabindex values above zero`
});
}
}
if (/(^[0-9-.])|[\^$@%&#?!|()[\]{}^*+~;]/.test(name)) {
component.error(attribute, {
code: `illegal-attribute`,
message: `'${name}' is not a valid attribute name`,
});
}
if (name === 'slot') {
if (!attribute.is_static) {
component.error(attribute, {
code: `invalid-slot-attribute`,
message: `slot attribute cannot have a dynamic value`
});
}
if (component.slot_outlets.has(name)) {
component.error(attribute, {
code: `duplicate-slot-attribute`,
message: `Duplicate '${name}' slot`
});
component.slot_outlets.add(name);
}
if (!(parent.type === 'InlineComponent' || within_custom_element(parent))) {
component.error(attribute, {
code: `invalid-slotted-content`,
message: `Element with a slot='...' attribute must be a child of a component or a descendant of a custom element`,
});
}
}
if (name === 'is') {
component.warn(attribute, {
code: 'avoid-is',
message: `The 'is' attribute is not supported cross-browser and should be avoided`
});
}
attribute_map.set(attribute.name, attribute);
});
}
validate_special_cases() {
const { component, attributes, handlers } = this;
const attribute_map = new Map();
const handlers_map = new Map();
attributes.forEach(attribute => (attribute_map.set(attribute.name, attribute)));
handlers.forEach(handler => (handlers_map.set(handler.name, handler)));
if (this.name === 'a') {
const href_attribute = attribute_map.get('href') || attribute_map.get('xlink:href');
const id_attribute = attribute_map.get('id');
const name_attribute = attribute_map.get('name');
if (href_attribute) {
const href_value = href_attribute.get_static_value();
if (href_value === '' || href_value === '#' || /^\W*javascript:/i.test(href_value)) {
component.warn(href_attribute, {
code: `a11y-invalid-attribute`,
message: `A11y: '${href_value}' is not a valid ${href_attribute.name} attribute`
});
}
}
else {
const id_attribute_valid = id_attribute && id_attribute.get_static_value() !== '';
const name_attribute_valid = name_attribute && name_attribute.get_static_value() !== '';
if (!id_attribute_valid && !name_attribute_valid) {
component.warn(this, {
code: `a11y-missing-attribute`,
message: `A11y: <a> element should have an href attribute`
});
}
}
}
else {
const required_attributes = a11y_required_attributes[this.name];
if (required_attributes) {
const has_attribute = required_attributes.some(name => attribute_map.has(name));
if (!has_attribute) {
should_have_attribute(this, required_attributes);
}
}
}
if (this.name === 'input') {
const type = attribute_map.get('type');
if (type && type.get_static_value() === 'image') {
const required_attributes = ['alt', 'aria-label', 'aria-labelledby'];
const has_attribute = required_attributes.some(name => attribute_map.has(name));
if (!has_attribute) {
should_have_attribute(this, required_attributes, 'input type="image"');
}
}
}
if (this.name === 'img') {
const alt_attribute = attribute_map.get('alt');
const aria_hidden_attribute = attribute_map.get('aria-hidden');
const aria_hidden_exist = aria_hidden_attribute && aria_hidden_attribute.get_static_value();
if (alt_attribute && !aria_hidden_exist) {
const alt_value = alt_attribute.get_static_value();
if (/\b(image|picture|photo)\b/i.test(alt_value)) {
component.warn(this, {
code: `a11y-img-redundant-alt`,
message: `A11y: Screenreaders already announce <img> elements as an image.`
});
}
}
}
if (this.name === 'label') {
const has_input_child = this.children.some(i => (i instanceof Element$1 && a11y_labelable.has(i.name)));
if (!attribute_map.has('for') && !has_input_child) {
component.warn(this, {
code: `a11y-label-has-associated-control`,
message: `A11y: A form label must be associated with a control.`
});
}
}
if (this.is_media_node()) {
if (attribute_map.has('muted')) {
return;
}
let has_caption;
const track = this.children.find((i) => i.name === 'track');
if (track) {
has_caption = track.attributes.find(a => a.name === 'kind' && a.get_static_value() === 'captions');
}
if (!has_caption) {
component.warn(this, {
code: `a11y-media-has-caption`,
message: `A11y: Media elements must have a <track kind="captions">`
});
}
}
if (a11y_no_onchange.has(this.name)) {
if (handlers_map.has('change') && !handlers_map.has('blur')) {
component.warn(this, {
code: `a11y-no-onchange`,
message: `A11y: on:blur must be used instead of on:change, unless absolutely necessary and it causes no negative consequences for keyboard only or screen reader users.`
});
}
}
}
validate_bindings() {
const { component } = this;
const check_type_attribute = () => {
const attribute = this.attributes.find((attribute) => attribute.name === 'type');
if (!attribute)
return null;
if (!attribute.is_static) {
component.error(attribute, {
code: `invalid-type`,
message: `'type' attribute cannot be dynamic if input uses two-way binding`
});
}
const value = attribute.get_static_value();
if (value === true) {
component.error(attribute, {
code: `missing-type`,
message: `'type' attribute must be specified`
});
}
return value;
};
this.bindings.forEach(binding => {
const { name } = binding;
if (name === 'value') {
if (this.name !== 'input' &&
this.name !== 'textarea' &&
this.name !== 'select') {
component.error(binding, {
code: `invalid-binding`,
message: `'value' is not a valid binding on <${this.name}> elements`
});
}
if (this.name === 'select') {
const attribute = this.attributes.find((attribute) => attribute.name === 'multiple');
if (attribute && !attribute.is_static) {
component.error(attribute, {
code: `dynamic-multiple-attribute`,
message: `'multiple' attribute cannot be dynamic if select uses two-way binding`
});
}
}
else {
check_type_attribute();
}
}
else if (name === 'checked' || name === 'indeterminate') {
if (this.name !== 'input') {
component.error(binding, {
code: `invalid-binding`,
message: `'${name}' is not a valid binding on <${this.name}> elements`
});
}
const type = check_type_attribute();
if (type !== 'checkbox') {
let message = `'${name}' binding can only be used with <input type="checkbox">`;
if (type === 'radio')
message += ` — for <input type="radio">, use 'group' binding`;
component.error(binding, { code: `invalid-binding`, message });
}
}
else if (name === 'group') {
if (this.name !== 'input') {
component.error(binding, {
code: `invalid-binding`,
message: `'group' is not a valid binding on <${this.name}> elements`
});
}
const type = check_type_attribute();
if (type !== 'checkbox' && type !== 'radio') {
component.error(binding, {
code: `invalid-binding`,
message: `'group' binding can only be used with <input type="checkbox"> or <input type="radio">`
});
}
}
else if (name === 'files') {
if (this.name !== 'input') {
component.error(binding, {
code: `invalid-binding`,
message: `'files' is not a valid binding on <${this.name}> elements`
});
}
const type = check_type_attribute();
if (type !== 'file') {
component.error(binding, {
code: `invalid-binding`,
message: `'files' binding can only be used with <input type="file">`
});
}
}
else if (name === 'open') {
if (this.name !== 'details') {
component.error(binding, {
code: `invalid-binding`,
message: `'${name}' binding can only be used with <details>`
});
}
}
else if (name === 'currentTime' ||
name === 'duration' ||
name === 'paused' ||
name === 'buffered' ||
name === 'seekable' ||
name === 'played' ||
name === 'volume' ||
name === 'muted' ||
name === 'playbackRate' ||
name === 'seeking' ||
name === 'ended') {
if (this.name !== 'audio' && this.name !== 'video') {
component.error(binding, {
code: `invalid-binding`,
message: `'${name}' binding can only be used with <audio> or <video>`
});
}
}
else if (name === 'videoHeight' ||
name === 'videoWidth') {
if (this.name !== 'video') {
component.error(binding, {
code: `invalid-binding`,
message: `'${name}' binding can only be used with <video>`
});
}
}
else if (dimensions.test(name)) {
if (this.name === 'svg' && (name === 'offsetWidth' || name === 'offsetHeight')) {
component.error(binding, {
code: 'invalid-binding',
message: `'${binding.name}' is not a valid binding on <svg>. Use '${name.replace('offset', 'client')}' instead`
});
}
else if (svg$1.test(this.name)) {
component.error(binding, {
code: 'invalid-binding',
message: `'${binding.name}' is not a valid binding on SVG elements`
});
}
else if (is_void(this.name)) {
component.error(binding, {
code: 'invalid-binding',
message: `'${binding.name}' is not a valid binding on void elements like <${this.name}>. Use a wrapper element instead`
});
}
}
else if (name === 'textContent' ||
name === 'innerHTML') {
const contenteditable = this.attributes.find((attribute) => attribute.name === 'contenteditable');
if (!contenteditable) {
component.error(binding, {
code: `missing-contenteditable-attribute`,
message: `'contenteditable' attribute is required for textContent and innerHTML two-way bindings`
});
}
else if (contenteditable && !contenteditable.is_static) {
component.error(contenteditable, {
code: `dynamic-contenteditable-attribute`,
message: `'contenteditable' attribute cannot be dynamic if element uses two-way binding`
});
}
}
else if (name !== 'this') {
component.error(binding, {
code: `invalid-binding`,
message: `'${binding.name}' is not a valid binding`
});
}
});
}
validate_content() {
if (!a11y_required_content.has(this.name))
return;
if (this.bindings
.some((binding) => ['textContent', 'innerHTML'].includes(binding.name)))
return;
if (this.children.length === 0) {
this.component.warn(this, {
code: `a11y-missing-content`,
message: `A11y: <${this.name}> element should have child content`
});
}
}
validate_event_handlers() {
const { component } = this;
this.handlers.forEach(handler => {
if (handler.modifiers.has('passive') && handler.modifiers.has('preventDefault')) {
component.error(handler, {
code: 'invalid-event-modifier',
message: `The 'passive' and 'preventDefault' modifiers cannot be used together`
});
}
handler.modifiers.forEach(modifier => {
if (!valid_modifiers.has(modifier)) {
component.error(handler, {
code: 'invalid-event-modifier',
message: `Valid event modifiers are ${list$1(Array.from(valid_modifiers))}`
});
}
if (modifier === 'passive') {
if (passive_events.has(handler.name)) {
if (handler.can_make_passive) {
component.warn(handler, {
code: 'redundant-event-modifier',
message: `Touch event handlers that don't use the 'event' object are passive by default`
});
}
}
else {
component.warn(handler, {
code: 'redundant-event-modifier',
message: `The passive modifier only works with wheel and touch events`
});
}
}
if (component.compile_options.legacy && (modifier === 'once' || modifier === 'passive')) {
// TODO this could be supported, but it would need a few changes to
// how event listeners work
component.error(handler, {
code: 'invalid-event-modifier',
message: `The '${modifier}' modifier cannot be used in legacy mode`
});
}
});
if (passive_events.has(handler.name) && handler.can_make_passive && !handler.modifiers.has('preventDefault')) {
// touch/wheel events should be passive by default
handler.modifiers.add('passive');
}
});
}
is_media_node() {
return this.name === 'audio' || this.name === 'video';
}
add_css_class() {
if (this.attributes.some(attr => attr.is_spread)) {
this.needs_manual_style_scoping = true;
return;
}
const { id } = this.component.stylesheet;
const class_attribute = this.attributes.find(a => a.name === 'class');
if (class_attribute && !class_attribute.is_true) {
if (class_attribute.chunks.length === 1 && class_attribute.chunks[0].type === 'Text') {
class_attribute.chunks[0].data += ` ${id}`;
}
else {
class_attribute.chunks.push(new Text$1(this.component, this, this.scope, {
type: 'Text',
data: ` ${id}`,
synthetic: true
}));
}
}
else {
this.attributes.push(new Attribute(this.component, this, this.scope, {
type: 'Attribute',
name: 'class',
value: [{ type: 'Text', data: id, synthetic: true }]
}));
}
}
}
function should_have_attribute(node, attributes, name = node.name) {
const article = /^[aeiou]/.test(attributes[0]) ? 'an' : 'a';
const sequence = attributes.length > 1 ?
attributes.slice(0, -1).join(', ') + ` or ${attributes[attributes.length - 1]}` :
attributes[0];
node.component.warn(node, {
code: `a11y-missing-attribute`,
message: `A11y: <${name}> element should have ${article} ${sequence} attribute`
});
}
function within_custom_element(parent) {
while (parent) {
if (parent.type === 'InlineComponent')
return false;
if (parent.type === 'Element' && /-/.test(parent.name))
return true;
parent = parent.parent;
}
return false;
}
class Head$1 extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
if (info.attributes.length) {
component.error(info.attributes[0], {
code: `invalid-attribute`,
message: `<svelte:head> should not have any attributes or directives`
});
}
this.children = map_children(component, parent, scope, info.children.filter(child => {
return (child.type !== 'Text' || /\S/.test(child.data));
}));
if (this.children.length > 0) {
this.id = `svelte-${hash(this.component.source.slice(this.start, this.end))}`;
}
}
}
class IfBlock$1 extends AbstractBlock {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.expression = new Expression(component, this, scope, info.expression);
this.children = map_children(component, this, scope, info.children);
this.else = info.else
? new ElseBlock(component, this, scope, info.else)
: null;
this.warn_if_empty_block();
}
}
class InlineComponent$1 extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.attributes = [];
this.bindings = [];
this.handlers = [];
this.lets = [];
if (info.name !== 'svelte:component' && info.name !== 'svelte:self') {
const name = info.name.split('.')[0]; // accommodate namespaces
component.warn_if_undefined(name, info, scope);
component.add_reference(name);
}
this.name = info.name;
this.expression = this.name === 'svelte:component'
? new Expression(component, this, scope, info.expression)
: null;
info.attributes.forEach(node => {
/* eslint-disable no-fallthrough */
switch (node.type) {
case 'Action':
component.error(node, {
code: `invalid-action`,
message: `Actions can only be applied to DOM elements, not components`
});
case 'Attribute':
if (node.name === 'slot') {
component.error(node, {
code: `invalid-prop`,
message: `'slot' is reserved for future use in named slots`
});
}
// fallthrough
case 'Spread':
this.attributes.push(new Attribute(component, this, scope, node));
break;
case 'Binding':
this.bindings.push(new Binding(component, this, scope, node));
break;
case 'Class':
component.error(node, {
code: `invalid-class`,
message: `Classes can only be applied to DOM elements, not components`
});
case 'EventHandler':
this.handlers.push(new EventHandler(component, this, scope, node));
break;
case 'Let':
this.lets.push(new Let(component, this, scope, node));
break;
case 'Transition':
component.error(node, {
code: `invalid-transition`,
message: `Transitions can only be applied to DOM elements, not components`
});
default:
throw new Error(`Not implemented: ${node.type}`);
}
/* eslint-enable no-fallthrough */
});
if (this.lets.length > 0) {
this.scope = scope.child();
this.lets.forEach(l => {
const dependencies = new Set([l.name.name]);
l.names.forEach(name => {
this.scope.add(name, dependencies, this);
});
});
}
else {
this.scope = scope;
}
this.handlers.forEach(handler => {
handler.modifiers.forEach(modifier => {
if (modifier !== 'once') {
component.error(handler, {
code: 'invalid-event-modifier',
message: `Event modifiers other than 'once' can only be used on DOM elements`
});
}
});
});
this.children = map_children(component, this, this.scope, info.children);
}
}
class Tag$2 extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.expression = new Expression(component, this, scope, info.expression);
this.should_cache = (info.expression.type !== 'Identifier' ||
(this.expression.dependencies.size && scope.names.has(info.expression.name)));
}
}
class MustacheTag extends Tag$2 {
}
class Options extends Node$1 {
}
class RawMustacheTag extends Tag$2 {
}
class DebugTag$1 extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.expressions = info.identifiers.map(node => {
return new Expression(component, parent, scope, node);
});
}
}
class Slot$1 extends Element$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.values = new Map();
info.attributes.forEach(attr => {
if (attr.type !== 'Attribute') {
component.error(attr, {
code: `invalid-slot-directive`,
message: `<slot> cannot have directives`
});
}
if (attr.name === 'name') {
if (attr.value.length !== 1 || attr.value[0].type !== 'Text') {
component.error(attr, {
code: `dynamic-slot-name`,
message: `<slot> name cannot be dynamic`
});
}
this.slot_name = attr.value[0].data;
if (this.slot_name === 'default') {
component.error(attr, {
code: `invalid-slot-name`,
message: `default is a reserved word — it cannot be used as a slot name`
});
}
}
this.values.set(attr.name, new Attribute(component, this, scope, attr));
});
if (!this.slot_name)
this.slot_name = 'default';
if (this.slot_name === 'default') {
// if this is the default slot, add our dependencies to any
// other slots (which inherit our slot values) that were
// previously encountered
component.slots.forEach((slot) => {
this.values.forEach((attribute, name) => {
if (!slot.values.has(name)) {
slot.values.set(name, attribute);
}
});
});
}
else if (component.slots.has('default')) {
// otherwise, go the other way — inherit values from
// a previously encountered default slot
const default_slot = component.slots.get('default');
default_slot.values.forEach((attribute, name) => {
if (!this.values.has(name)) {
this.values.set(name, attribute);
}
});
}
component.slots.set(this.slot_name, this);
}
}
class Title$1 extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.children = map_children(component, parent, scope, info.children);
if (info.attributes.length > 0) {
component.error(info.attributes[0], {
code: `illegal-attribute`,
message: `<title> cannot have attributes`
});
}
info.children.forEach(child => {
if (child.type !== 'Text' && child.type !== 'MustacheTag') {
component.error(child, {
code: 'illegal-structure',
message: `<title> can only contain text and {tags}`
});
}
});
this.should_cache = info.children.length === 1
? (info.children[0].type !== 'Identifier' ||
scope.names.has(info.children[0].name))
: true;
}
}
const valid_bindings = [
'innerWidth',
'innerHeight',
'outerWidth',
'outerHeight',
'scrollX',
'scrollY',
'online'
];
class Window extends Node$1 {
constructor(component, parent, scope, info) {
super(component, parent, scope, info);
this.handlers = [];
this.bindings = [];
this.actions = [];
info.attributes.forEach(node => {
if (node.type === 'EventHandler') {
this.handlers.push(new EventHandler(component, this, scope, node));
}
else if (node.type === 'Binding') {
if (node.expression.type !== 'Identifier') {
const { parts } = flatten_reference(node.expression);
// TODO is this constraint necessary?
component.error(node.expression, {
code: `invalid-binding`,
message: `Bindings on <svelte:window> must be to top-level properties, e.g. '${parts[parts.length - 1]}' rather than '${parts.join('.')}'`
});
}
if (!~valid_bindings.indexOf(node.name)) {
const match = (node.name === 'width' ? 'innerWidth' :
node.name === 'height' ? 'innerHeight' :
fuzzymatch(node.name, valid_bindings));
const message = `'${node.name}' is not a valid binding on <svelte:window>`;
if (match) {
component.error(node, {
code: `invalid-binding`,
message: `${message} (did you mean '${match}'?)`
});
}
else {
component.error(node, {
code: `invalid-binding`,
message: `${message} — valid bindings are ${list$1(valid_bindings)}`
});
}
}
this.bindings.push(new Binding(component, this, scope, node));
}
else if (node.type === 'Action') {
this.actions.push(new Action(component, this, scope, node));
}
});
}
}
function get_constructor(type) {
switch (type) {
case 'AwaitBlock': return AwaitBlock$1;
case 'Body': return Body;
case 'Comment': return Comment$2;
case 'EachBlock': return EachBlock$1;
case 'Element': return Element$1;
case 'Head': return Head$1;
case 'IfBlock': return IfBlock$1;
case 'InlineComponent': return InlineComponent$1;
case 'MustacheTag': return MustacheTag;
case 'Options': return Options;
case 'RawMustacheTag': return RawMustacheTag;
case 'DebugTag': return DebugTag$1;
case 'Slot': return Slot$1;
case 'Text': return Text$1;
case 'Title': return Title$1;
case 'Window': return Window;
default: throw new Error(`Not implemented: ${type}`);
}
}
function map_children(component, parent, scope, children) {
let last = null;
let ignores = [];
return children.map(child => {
const constructor = get_constructor(child.type);
const use_ignores = child.type !== 'Text' && child.type !== 'Comment' && ignores.length;
if (use_ignores)
component.push_ignores(ignores);
const node = new constructor(component, parent, scope, child);
if (use_ignores)
component.pop_ignores(), ignores = [];
if (node.type === 'Comment' && node.ignores.length) {
ignores.push(...node.ignores);
}
if (last)
last.next = node;
node.prev = last;
last = node;
return node;
});
}
class TemplateScope {
constructor(parent) {
this.owners = new Map();
this.parent = parent;
this.names = new Set(parent ? parent.names : []);
this.dependencies_for_name = new Map(parent ? parent.dependencies_for_name : []);
}
add(name, dependencies, owner) {
this.names.add(name);
this.dependencies_for_name.set(name, dependencies);
this.owners.set(name, owner);
return this;
}
child() {
const child = new TemplateScope(this);
return child;
}
is_top_level(name) {
return !this.parent || !this.names.has(name) && this.parent.is_top_level(name);
}
get_owner(name) {
return this.owners.get(name) || (this.parent && this.parent.get_owner(name));
}
is_let(name) {
const owner = this.get_owner(name);
return owner && (owner.type === 'Element' || owner.type === 'InlineComponent');
}
is_await(name) {
const owner = this.get_owner(name);
return owner && (owner.type === 'ThenBlock' || owner.type === 'CatchBlock');
}
}
class Fragment extends Node$1 {
constructor(component, info) {
const scope = new TemplateScope();
super(component, null, scope, info);
this.scope = scope;
this.children = map_children(component, this, scope, info.children);
}
}
// This file is automatically generated
var internal_exports = new Set(["HtmlTag", "SvelteComponent", "SvelteComponentDev", "SvelteElement", "action_destroyer", "add_attribute", "add_classes", "add_flush_callback", "add_location", "add_render_callback", "add_resize_listener", "add_transform", "afterUpdate", "append", "append_dev", "assign", "attr", "attr_dev", "beforeUpdate", "bind", "binding_callbacks", "blank_object", "bubble", "check_outros", "children", "claim_component", "claim_element", "claim_space", "claim_text", "clear_loops", "component_subscribe", "compute_rest_props", "createEventDispatcher", "create_animation", "create_bidirectional_transition", "create_component", "create_in_transition", "create_out_transition", "create_slot", "create_ssr_component", "current_component", "custom_event", "dataset_dev", "debug", "destroy_block", "destroy_component", "destroy_each", "detach", "detach_after_dev", "detach_before_dev", "detach_between_dev", "detach_dev", "dirty_components", "dispatch_dev", "each", "element", "element_is", "empty", "escape", "escaped", "exclude_internal_props", "fix_and_destroy_block", "fix_and_outro_and_destroy_block", "fix_position", "flush", "getContext", "get_binding_group_value", "get_current_component", "get_slot_changes", "get_slot_context", "get_spread_object", "get_spread_update", "get_store_value", "globals", "group_outros", "handle_promise", "has_prop", "identity", "init", "insert", "insert_dev", "intros", "invalid_attribute_name_character", "is_client", "is_crossorigin", "is_empty", "is_function", "is_promise", "listen", "listen_dev", "loop", "loop_guard", "missing_component", "mount_component", "noop", "not_equal", "now", "null_to_empty", "object_without_properties", "onDestroy", "onMount", "once", "outro_and_destroy_block", "prevent_default", "prop_dev", "query_selector_all", "raf", "run", "run_all", "safe_not_equal", "schedule_update", "select_multiple_value", "select_option", "select_options", "select_value", "self", "setContext", "set_attributes", "set_current_component", "set_custom_element_data", "set_data", "set_data_dev", "set_input_type", "set_input_value", "set_now", "set_raf", "set_store_value", "set_style", "set_svg_attributes", "space", "spread", "stop_propagation", "subscribe", "svg_element", "text", "tick", "time_ranges_to_array", "to_number", "toggle_class", "transition_in", "transition_out", "update_keyed_each", "update_slot", "validate_component", "validate_each_argument", "validate_each_keys", "validate_slots", "validate_store", "xlink_attr"]);
function is_used_as_reference(node, parent) {
if (!isReference(node, parent)) {
return false;
}
if (!parent) {
return true;
}
/* eslint-disable no-fallthrough */
switch (parent.type) {
// disregard the `foo` in `const foo = bar`
case 'VariableDeclarator':
return node !== parent.id;
// disregard the `foo`, `bar` in `function foo(bar){}`
case 'FunctionDeclaration':
// disregard the `foo` in `import { foo } from 'foo'`
case 'ImportSpecifier':
// disregard the `foo` in `import foo from 'foo'`
case 'ImportDefaultSpecifier':
// disregard the `foo` in `import * as foo from 'foo'`
case 'ImportNamespaceSpecifier':
// disregard the `foo` in `export { foo }`
case 'ExportSpecifier':
return false;
default:
return true;
}
}
function check_graph_for_cycles(edges) {
const graph = edges.reduce((g, edge) => {
const [u, v] = edge;
if (!g.has(u))
g.set(u, []);
if (!g.has(v))
g.set(v, []);
g.get(u).push(v);
return g;
}, new Map());
const visited = new Set();
const on_stack = new Set();
const cycles = [];
function visit(v) {
visited.add(v);
on_stack.add(v);
graph.get(v).forEach(w => {
if (!visited.has(w)) {
visit(w);
}
else if (on_stack.has(w)) {
cycles.push([...on_stack, w]);
}
});
on_stack.delete(v);
}
graph.forEach((_, v) => {
if (!visited.has(v)) {
visit(v);
}
});
return cycles[0];
}
class Component {
constructor(ast, source, name, compile_options, stats, warnings) {
this.ignore_stack = [];
this.vars = [];
this.var_lookup = new Map();
this.imports = [];
this.hoistable_nodes = new Set();
this.node_for_declaration = new Map();
this.partly_hoisted = [];
this.fully_hoisted = [];
this.reactive_declarations = [];
this.reactive_declaration_nodes = new Set();
this.has_reactive_assignments = false;
this.injected_reactive_declaration_vars = new Set();
this.helpers = new Map();
this.globals = new Map();
this.indirect_dependencies = new Map();
this.aliases = new Map();
this.used_names = new Set();
this.globally_used_names = new Set();
this.slots = new Map();
this.slot_outlets = new Set();
this.name = { type: 'Identifier', name };
this.stats = stats;
this.warnings = warnings;
this.ast = ast;
this.source = source;
this.compile_options = compile_options;
// the instance JS gets mutated, so we park
// a copy here for later. TODO this feels gross
this.original_ast = {
html: ast.html,
css: ast.css,
instance: ast.instance && JSON.parse(JSON.stringify(ast.instance)),
module: ast.module
};
this.file =
compile_options.filename &&
(typeof process$1 !== 'undefined'
? compile_options.filename
.replace(process$1.cwd(), '')
.replace(/^[/\\]/, '')
: compile_options.filename);
this.locate = getLocator(this.source, { offsetLine: 1 });
// styles
this.stylesheet = new Stylesheet(source, ast, compile_options.filename, compile_options.dev);
this.stylesheet.validate(this);
this.component_options = process_component_options(this, this.ast.html.children);
this.namespace =
namespaces[this.component_options.namespace] ||
this.component_options.namespace;
if (compile_options.customElement) {
if (this.component_options.tag === undefined &&
compile_options.tag === undefined) {
const svelteOptions = ast.html.children.find(child => child.name === 'svelte:options') || { start: 0, end: 0 };
this.warn(svelteOptions, {
code: 'custom-element-no-tag',
message: `No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag="my-thing"/>. To hide this warning, use <svelte:options tag={null}/>`,
});
}
this.tag = this.component_options.tag || compile_options.tag;
}
else {
this.tag = this.name.name;
}
this.walk_module_js();
this.walk_instance_js_pre_template();
this.fragment = new Fragment(this, ast.html);
this.name = this.get_unique_name(name);
this.walk_instance_js_post_template();
if (!compile_options.customElement)
this.stylesheet.reify();
this.stylesheet.warn_on_unused_selectors(this);
}
add_var(variable) {
this.vars.push(variable);
this.var_lookup.set(variable.name, variable);
}
add_reference(name) {
const variable = this.var_lookup.get(name);
if (variable) {
variable.referenced = true;
}
else if (is_reserved_keyword(name)) {
this.add_var({
name,
injected: true,
referenced: true,
});
}
else if (name[0] === '$') {
this.add_var({
name,
injected: true,
referenced: true,
mutated: true,
writable: true,
});
const subscribable_name = name.slice(1);
const variable = this.var_lookup.get(subscribable_name);
if (variable) {
variable.referenced = true;
variable.subscribable = true;
}
}
else {
this.used_names.add(name);
}
}
alias(name) {
if (!this.aliases.has(name)) {
this.aliases.set(name, this.get_unique_name(name));
}
return this.aliases.get(name);
}
global(name) {
const alias = this.alias(name);
this.globals.set(name, alias);
return alias;
}
generate(result) {
let js = null;
let css = null;
if (result) {
const { compile_options, name } = this;
const { format = 'esm' } = compile_options;
const banner = `${this.file ? `${this.file} ` : ``}generated by Svelte v${'3.24.1'}`;
const program = { type: 'Program', body: result.js };
walk(program, {
enter: (node, parent, key) => {
if (node.type === 'Identifier') {
if (node.name[0] === '@') {
if (node.name[1] === '_') {
const alias = this.global(node.name.slice(2));
node.name = alias.name;
}
else {
let name = node.name.slice(1);
if (compile_options.dev) {
if (internal_exports.has(`${name}_dev`)) {
name += '_dev';
}
else if (internal_exports.has(`${name}Dev`)) {
name += 'Dev';
}
}
const alias = this.alias(name);
this.helpers.set(name, alias);
node.name = alias.name;
}
}
else if (node.name[0] !== '#' && !is_valid(node.name)) {
// this hack allows x`foo.${bar}` where bar could be invalid
const literal = { type: 'Literal', value: node.name };
if (parent.type === 'Property' && key === 'key') {
parent.key = literal;
}
else if (parent.type === 'MemberExpression' && key === 'property') {
parent.property = literal;
parent.computed = true;
}
}
}
}
});
const referenced_globals = Array.from(this.globals, ([name, alias]) => name !== alias.name && { name, alias }).filter(Boolean);
if (referenced_globals.length) {
this.helpers.set('globals', this.alias('globals'));
}
const imported_helpers = Array.from(this.helpers, ([name, alias]) => ({
name,
alias,
}));
create_module(program, format, name, banner, compile_options.sveltePath, imported_helpers, referenced_globals, this.imports, this.vars
.filter(variable => variable.module && variable.export_name)
.map(variable => ({
name: variable.name,
as: variable.export_name,
})));
css = compile_options.customElement
? { code: null, map: null }
: result.css;
js = print(program, {
sourceMapSource: compile_options.filename
});
js.map.sources = [
compile_options.filename ? get_relative_path(compile_options.outputFilename || '', compile_options.filename) : null
];
js.map.sourcesContent = [
this.source
];
}
return {
js,
css,
ast: this.original_ast,
warnings: this.warnings,
vars: this.vars
.filter(v => !v.global && !v.internal)
.map(v => ({
name: v.name,
export_name: v.export_name || null,
injected: v.injected || false,
module: v.module || false,
mutated: v.mutated || false,
reassigned: v.reassigned || false,
referenced: v.referenced || false,
writable: v.writable || false,
referenced_from_script: v.referenced_from_script || false,
})),
stats: this.stats.render(),
};
}
get_unique_name(name, scope) {
if (test)
name = `${name}$`;
let alias = name;
for (let i = 1; reserved.has(alias) ||
this.var_lookup.has(alias) ||
this.used_names.has(alias) ||
this.globally_used_names.has(alias) ||
(scope && scope.has(alias)); alias = `${name}_${i++}`)
;
this.used_names.add(alias);
return { type: 'Identifier', name: alias };
}
get_unique_name_maker() {
const local_used_names = new Set();
function add(name) {
local_used_names.add(name);
}
reserved.forEach(add);
internal_exports.forEach(add);
this.var_lookup.forEach((_value, key) => add(key));
return (name) => {
if (test)
name = `${name}$`;
let alias = name;
for (let i = 1; this.used_names.has(alias) || local_used_names.has(alias); alias = `${name}_${i++}`)
;
local_used_names.add(alias);
this.globally_used_names.add(alias);
return {
type: 'Identifier',
name: alias
};
};
}
error(pos, e) {
error$1(e.message, {
name: 'ValidationError',
code: e.code,
source: this.source,
start: pos.start,
end: pos.end,
filename: this.compile_options.filename,
});
}
warn(pos, warning) {
if (this.ignores && this.ignores.has(warning.code)) {
return;
}
const start = this.locate(pos.start);
const end = this.locate(pos.end);
const frame = get_code_frame(this.source, start.line - 1, start.column);
this.warnings.push({
code: warning.code,
message: warning.message,
frame,
start,
end,
pos: pos.start,
filename: this.compile_options.filename,
toString: () => `${warning.message} (${start.line}:${start.column})\n${frame}`,
});
}
extract_imports(node) {
this.imports.push(node);
}
extract_exports(node) {
if (node.type === 'ExportDefaultDeclaration') {
this.error(node, {
code: `default-export`,
message: `A component cannot have a default export`,
});
}
if (node.type === 'ExportNamedDeclaration') {
if (node.source) {
this.error(node, {
code: `not-implemented`,
message: `A component currently cannot have an export ... from`,
});
}
if (node.declaration) {
if (node.declaration.type === 'VariableDeclaration') {
node.declaration.declarations.forEach(declarator => {
extract_names(declarator.id).forEach(name => {
const variable = this.var_lookup.get(name);
variable.export_name = name;
if (variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) {
this.warn(declarator, {
code: `unused-export-let`,
message: `${this.name.name} has unused export property '${name}'. If it is for external reference only, please consider using \`export const ${name}\``
});
}
});
});
}
else {
const { name } = node.declaration.id;
const variable = this.var_lookup.get(name);
variable.export_name = name;
}
return node.declaration;
}
else {
node.specifiers.forEach(specifier => {
const variable = this.var_lookup.get(specifier.local.name);
if (variable) {
variable.export_name = specifier.exported.name;
if (variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) {
this.warn(specifier, {
code: `unused-export-let`,
message: `${this.name.name} has unused export property '${specifier.exported.name}'. If it is for external reference only, please consider using \`export const ${specifier.exported.name}\``
});
}
}
});
return null;
}
}
}
extract_javascript(script) {
if (!script)
return null;
return script.content.body.filter(node => {
if (!node)
return false;
if (this.hoistable_nodes.has(node))
return false;
if (this.reactive_declaration_nodes.has(node))
return false;
if (node.type === 'ImportDeclaration')
return false;
if (node.type === 'ExportDeclaration' && node.specifiers.length > 0)
return false;
return true;
});
}
walk_module_js() {
const component = this;
const script = this.ast.module;
if (!script)
return;
walk(script.content, {
enter(node) {
if (node.type === 'LabeledStatement' && node.label.name === '$') {
component.warn(node, {
code: 'module-script-reactive-declaration',
message: '$: has no effect in a module script',
});
}
},
});
const { scope, globals } = create_scopes(script.content);
this.module_scope = scope;
scope.declarations.forEach((node, name) => {
if (name[0] === '$') {
this.error(node, {
code: 'illegal-declaration',
message: `The $ prefix is reserved, and cannot be used for variable and import names`,
});
}
const writable = node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');
this.add_var({
name,
module: true,
hoistable: true,
writable
});
});
globals.forEach((node, name) => {
if (name[0] === '$') {
this.error(node, {
code: 'illegal-subscription',
message: `Cannot reference store value inside <script context="module">`,
});
}
else {
this.add_var({
name,
global: true,
hoistable: true
});
}
});
const { body } = script.content;
let i = body.length;
while (--i >= 0) {
const node = body[i];
if (node.type === 'ImportDeclaration') {
this.extract_imports(node);
body.splice(i, 1);
}
if (/^Export/.test(node.type)) {
const replacement = this.extract_exports(node);
if (replacement) {
body[i] = replacement;
}
else {
body.splice(i, 1);
}
}
}
}
walk_instance_js_pre_template() {
const script = this.ast.instance;
if (!script)
return;
// inject vars for reactive declarations
script.content.body.forEach(node => {
if (node.type !== 'LabeledStatement')
return;
if (node.body.type !== 'ExpressionStatement')
return;
const { expression } = node.body;
if (expression.type !== 'AssignmentExpression')
return;
if (expression.left.type === 'MemberExpression')
return;
extract_names(expression.left).forEach(name => {
if (!this.var_lookup.has(name) && name[0] !== '$') {
this.injected_reactive_declaration_vars.add(name);
}
});
});
const { scope: instance_scope, map, globals } = create_scopes(script.content);
this.instance_scope = instance_scope;
this.instance_scope_map = map;
instance_scope.declarations.forEach((node, name) => {
if (name[0] === '$') {
this.error(node, {
code: 'illegal-declaration',
message: `The $ prefix is reserved, and cannot be used for variable and import names`,
});
}
const writable = node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');
this.add_var({
name,
initialised: instance_scope.initialised_declarations.has(name),
writable
});
this.node_for_declaration.set(name, node);
});
globals.forEach((node, name) => {
if (this.var_lookup.has(name))
return;
if (this.injected_reactive_declaration_vars.has(name)) {
this.add_var({
name,
injected: true,
writable: true,
reassigned: true,
initialised: true,
});
}
else if (is_reserved_keyword(name)) {
this.add_var({
name,
injected: true,
});
}
else if (name[0] === '$') {
if (name === '$' || name[1] === '$') {
this.error(node, {
code: 'illegal-global',
message: `${name} is an illegal variable name`
});
}
this.add_var({
name,
injected: true,
mutated: true,
writable: true,
});
this.add_reference(name.slice(1));
const variable = this.var_lookup.get(name.slice(1));
if (variable) {
variable.subscribable = true;
variable.referenced_from_script = true;
}
}
else {
this.add_var({
name,
global: true,
hoistable: true
});
}
});
this.track_references_and_mutations();
}
walk_instance_js_post_template() {
const script = this.ast.instance;
if (!script)
return;
this.post_template_walk();
this.hoist_instance_declarations();
this.extract_reactive_declarations();
}
post_template_walk() {
const script = this.ast.instance;
if (!script)
return;
const component = this;
const { content } = script;
const { instance_scope, instance_scope_map: map } = this;
let scope = instance_scope;
const to_remove = [];
const remove = (parent, prop, index) => {
to_remove.unshift([parent, prop, index]);
};
let scope_updated = false;
let generator_count = 0;
walk(content, {
enter(node, parent, prop, index) {
if ((node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') && node.generator === true) {
generator_count++;
}
if (map.has(node)) {
scope = map.get(node);
}
if (node.type === 'ImportDeclaration') {
component.extract_imports(node);
// TODO: to use actual remove
remove(parent, prop, index);
return this.skip();
}
if (/^Export/.test(node.type)) {
const replacement = component.extract_exports(node);
if (replacement) {
this.replace(replacement);
}
else {
// TODO: to use actual remove
remove(parent, prop, index);
}
return this.skip();
}
component.warn_on_undefined_store_value_references(node, parent, scope);
},
leave(node) {
if ((node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') && node.generator === true) {
generator_count--;
}
// do it on leave, to prevent infinite loop
if (component.compile_options.dev && component.compile_options.loopGuardTimeout > 0 && generator_count <= 0) {
const to_replace_for_loop_protect = component.loop_protect(node, scope, component.compile_options.loopGuardTimeout);
if (to_replace_for_loop_protect) {
this.replace(to_replace_for_loop_protect);
scope_updated = true;
}
}
if (map.has(node)) {
scope = scope.parent;
}
},
});
for (const [parent, prop, index] of to_remove) {
if (parent) {
if (index !== null) {
parent[prop].splice(index, 1);
}
else {
delete parent[prop];
}
}
}
if (scope_updated) {
const { scope, map } = create_scopes(script.content);
this.instance_scope = scope;
this.instance_scope_map = map;
}
}
track_references_and_mutations() {
const script = this.ast.instance;
if (!script)
return;
const component = this;
const { content } = script;
const { instance_scope, module_scope, instance_scope_map: map } = this;
let scope = instance_scope;
walk(content, {
enter(node, parent) {
if (map.has(node)) {
scope = map.get(node);
}
if (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') {
const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument;
const names = extract_names(assignee);
const deep = assignee.type === 'MemberExpression';
names.forEach(name => {
const scope_owner = scope.find_owner(name);
if (scope_owner !== null
? scope_owner === instance_scope
: module_scope && module_scope.has(name)) {
const variable = component.var_lookup.get(name);
variable[deep ? 'mutated' : 'reassigned'] = true;
}
});
}
if (is_used_as_reference(node, parent)) {
const object = get_object(node);
if (scope.find_owner(object.name) === instance_scope) {
const variable = component.var_lookup.get(object.name);
variable.referenced_from_script = true;
}
}
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
},
});
}
warn_on_undefined_store_value_references(node, parent, scope) {
if (node.type === 'LabeledStatement' &&
node.label.name === '$' &&
parent.type !== 'Program') {
this.warn(node, {
code: 'non-top-level-reactive-declaration',
message: '$: has no effect outside of the top-level',
});
}
if (isReference(node, parent)) {
const object = get_object(node);
const { name } = object;
if (name[0] === '$') {
if (!scope.has(name)) {
this.warn_if_undefined(name, object, null);
}
if (name[1] !== '$' && scope.has(name.slice(1)) && scope.find_owner(name.slice(1)) !== this.instance_scope) {
this.error(node, {
code: `contextual-store`,
message: `Stores must be declared at the top level of the component (this may change in a future version of Svelte)`
});
}
}
}
}
loop_protect(node, scope, timeout) {
if (node.type === 'WhileStatement' ||
node.type === 'ForStatement' ||
node.type === 'DoWhileStatement') {
const guard = this.get_unique_name('guard', scope);
this.used_names.add(guard.name);
const before = b `const ${guard} = @loop_guard(${timeout})`;
const inside = b `${guard}();`;
// wrap expression statement with BlockStatement
if (node.body.type !== 'BlockStatement') {
node.body = {
type: 'BlockStatement',
body: [node.body],
};
}
node.body.body.push(inside[0]);
return {
type: 'BlockStatement',
body: [
before[0],
node,
],
};
}
return null;
}
rewrite_props(get_insert) {
if (!this.ast.instance)
return;
const component = this;
const { instance_scope, instance_scope_map: map } = this;
let scope = instance_scope;
walk(this.ast.instance.content, {
enter(node, parent, key, index) {
if (/Function/.test(node.type)) {
return this.skip();
}
if (map.has(node)) {
scope = map.get(node);
}
if (node.type === 'VariableDeclaration') {
if (node.kind === 'var' || scope === instance_scope) {
node.declarations.forEach(declarator => {
if (declarator.id.type !== 'Identifier') {
const inserts = [];
extract_names(declarator.id).forEach(name => {
const variable = component.var_lookup.get(name);
if (variable.export_name) {
// TODO is this still true post-#3539?
component.error(declarator, {
code: 'destructured-prop',
message: `Cannot declare props in destructured declaration`,
});
}
if (variable.subscribable) {
inserts.push(get_insert(variable));
}
});
if (inserts.length) {
parent[key].splice(index + 1, 0, ...inserts);
}
return;
}
const { name } = declarator.id;
const variable = component.var_lookup.get(name);
if (variable.export_name && variable.writable) {
const insert = variable.subscribable
? get_insert(variable)
: null;
parent[key].splice(index + 1, 0, insert);
declarator.id = {
type: 'ObjectPattern',
properties: [{
type: 'Property',
method: false,
shorthand: false,
computed: false,
kind: 'init',
key: { type: 'Identifier', name: variable.export_name },
value: declarator.init
? {
type: 'AssignmentPattern',
left: declarator.id,
right: declarator.init
}
: declarator.id
}]
};
declarator.init = x `$$props`;
}
else if (variable.subscribable) {
const insert = get_insert(variable);
parent[key].splice(index + 1, 0, ...insert);
}
});
}
}
},
leave(node, parent, _key, index) {
if (map.has(node)) {
scope = scope.parent;
}
if (node.type === 'ExportNamedDeclaration' && node.declaration) {
parent.body[index] = node.declaration;
}
},
});
}
hoist_instance_declarations() {
// we can safely hoist variable declarations that are
// initialised to literals, and functions that don't
// reference instance variables other than other
// hoistable functions. TODO others?
const { hoistable_nodes, var_lookup, injected_reactive_declaration_vars, imports, } = this;
const top_level_function_declarations = new Map();
const { body } = this.ast.instance.content;
for (let i = 0; i < body.length; i += 1) {
const node = body[i];
if (node.type === 'VariableDeclaration') {
const all_hoistable = node.declarations.every(d => {
if (!d.init)
return false;
if (d.init.type !== 'Literal')
return false;
// everything except const values can be changed by e.g. svelte devtools
// which means we can't hoist it
if (node.kind !== 'const' && this.compile_options.dev)
return false;
const { name } = d.id;
const v = this.var_lookup.get(name);
if (v.reassigned)
return false;
if (v.export_name)
return false;
if (this.var_lookup.get(name).reassigned)
return false;
if (this.vars.find(variable => variable.name === name && variable.module))
return false;
return true;
});
if (all_hoistable) {
node.declarations.forEach(d => {
const variable = this.var_lookup.get(d.id.name);
variable.hoistable = true;
});
hoistable_nodes.add(node);
body.splice(i--, 1);
this.fully_hoisted.push(node);
}
}
if (node.type === 'ExportNamedDeclaration' &&
node.declaration &&
node.declaration.type === 'FunctionDeclaration') {
top_level_function_declarations.set(node.declaration.id.name, node);
}
if (node.type === 'FunctionDeclaration') {
top_level_function_declarations.set(node.id.name, node);
}
}
const checked = new Set();
const walking = new Set();
const is_hoistable = fn_declaration => {
if (fn_declaration.type === 'ExportNamedDeclaration') {
fn_declaration = fn_declaration.declaration;
}
const instance_scope = this.instance_scope;
let scope = this.instance_scope;
const map = this.instance_scope_map;
let hoistable = true;
// handle cycles
walking.add(fn_declaration);
walk(fn_declaration, {
enter(node, parent) {
if (!hoistable)
return this.skip();
if (map.has(node)) {
scope = map.get(node);
}
if (isReference(node, parent)) {
const { name } = flatten_reference(node);
const owner = scope.find_owner(name);
if (injected_reactive_declaration_vars.has(name)) {
hoistable = false;
}
else if (name[0] === '$' && !owner) {
hoistable = false;
}
else if (owner === instance_scope) {
const variable = var_lookup.get(name);
if (variable.reassigned || variable.mutated)
hoistable = false;
if (name === fn_declaration.id.name)
return;
if (variable.hoistable)
return;
if (top_level_function_declarations.has(name)) {
const other_declaration = top_level_function_declarations.get(name);
if (walking.has(other_declaration)) {
hoistable = false;
}
else if (other_declaration.type === 'ExportNamedDeclaration' &&
walking.has(other_declaration.declaration)) {
hoistable = false;
}
else if (!is_hoistable(other_declaration)) {
hoistable = false;
}
}
else {
hoistable = false;
}
}
this.skip();
}
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
},
});
checked.add(fn_declaration);
walking.delete(fn_declaration);
return hoistable;
};
for (const [name, node] of top_level_function_declarations) {
if (is_hoistable(node)) {
const variable = this.var_lookup.get(name);
variable.hoistable = true;
hoistable_nodes.add(node);
const i = body.indexOf(node);
body.splice(i, 1);
this.fully_hoisted.push(node);
}
}
for (const { specifiers } of imports) {
for (const specifier of specifiers) {
const variable = var_lookup.get(specifier.local.name);
if (!variable.mutated || variable.subscribable) {
variable.hoistable = true;
}
}
}
}
extract_reactive_declarations() {
const component = this;
const unsorted_reactive_declarations = [];
this.ast.instance.content.body.forEach(node => {
if (node.type === 'LabeledStatement' && node.label.name === '$') {
this.reactive_declaration_nodes.add(node);
const assignees = new Set();
const assignee_nodes = new Set();
const dependencies = new Set();
let scope = this.instance_scope;
const map = this.instance_scope_map;
walk(node.body, {
enter(node, parent) {
if (map.has(node)) {
scope = map.get(node);
}
if (node.type === 'AssignmentExpression') {
const left = get_object(node.left);
extract_identifiers(left).forEach(node => {
assignee_nodes.add(node);
assignees.add(node.name);
});
if (node.operator !== '=') {
dependencies.add(left.name);
}
}
else if (node.type === 'UpdateExpression') {
const identifier = get_object(node.argument);
assignees.add(identifier.name);
}
else if (isReference(node, parent)) {
const identifier = get_object(node);
if (!assignee_nodes.has(identifier)) {
const { name } = identifier;
const owner = scope.find_owner(name);
const variable = component.var_lookup.get(name);
if (variable)
variable.is_reactive_dependency = true;
const is_writable_or_mutated = variable && (variable.writable || variable.mutated);
if ((!owner || owner === component.instance_scope) &&
(name[0] === '$' || is_writable_or_mutated)) {
dependencies.add(name);
}
}
this.skip();
}
},
leave(node) {
if (map.has(node)) {
scope = scope.parent;
}
},
});
const { expression } = node.body;
const declaration = expression && expression.left;
unsorted_reactive_declarations.push({
assignees,
dependencies,
node,
declaration,
});
}
});
const lookup = new Map();
unsorted_reactive_declarations.forEach(declaration => {
declaration.assignees.forEach(name => {
if (!lookup.has(name)) {
lookup.set(name, []);
}
// TODO warn or error if a name is assigned to in
// multiple reactive declarations?
lookup.get(name).push(declaration);
});
});
const cycle = check_graph_for_cycles(unsorted_reactive_declarations.reduce((acc, declaration) => {
declaration.assignees.forEach(v => {
declaration.dependencies.forEach(w => {
if (!declaration.assignees.has(w)) {
acc.push([v, w]);
}
});
});
return acc;
}, []));
if (cycle && cycle.length) {
const declarationList = lookup.get(cycle[0]);
const declaration = declarationList[0];
this.error(declaration.node, {
code: 'cyclical-reactive-declaration',
message: `Cyclical dependency detected: ${cycle.join(' → ')}`
});
}
const add_declaration = declaration => {
if (this.reactive_declarations.includes(declaration))
return;
declaration.dependencies.forEach(name => {
if (declaration.assignees.has(name))
return;
const earlier_declarations = lookup.get(name);
if (earlier_declarations)
earlier_declarations.forEach(add_declaration);
});
this.reactive_declarations.push(declaration);
};
unsorted_reactive_declarations.forEach(add_declaration);
}
warn_if_undefined(name, node, template_scope) {
if (name[0] === '$') {
if (name === '$' || name[1] === '$' && !is_reserved_keyword(name)) {
this.error(node, {
code: 'illegal-global',
message: `${name} is an illegal variable name`
});
}
this.has_reactive_assignments = true; // TODO does this belong here?
if (is_reserved_keyword(name))
return;
name = name.slice(1);
}
if (this.var_lookup.has(name) && !this.var_lookup.get(name).global)
return;
if (template_scope && template_scope.names.has(name))
return;
if (globals.has(name) && node.type !== 'InlineComponent')
return;
let message = `'${name}' is not defined`;
if (!this.ast.instance)
message += `. Consider adding a <script> block with 'export let ${name}' to declare a prop`;
this.warn(node, {
code: 'missing-declaration',
message,
});
}
push_ignores(ignores) {
this.ignores = new Set(this.ignores || []);
add_to_set(this.ignores, ignores);
this.ignore_stack.push(this.ignores);
}
pop_ignores() {
this.ignore_stack.pop();
this.ignores = this.ignore_stack[this.ignore_stack.length - 1];
}
}
function process_component_options(component, nodes) {
const component_options = {
immutable: component.compile_options.immutable || false,
accessors: 'accessors' in component.compile_options
? component.compile_options.accessors
: !!component.compile_options.customElement,
preserveWhitespace: !!component.compile_options.preserveWhitespace,
};
const node = nodes.find(node => node.name === 'svelte:options');
function get_value(attribute, code, message) {
const { value } = attribute;
const chunk = value[0];
if (!chunk)
return true;
if (value.length > 1) {
component.error(attribute, { code, message });
}
if (chunk.type === 'Text')
return chunk.data;
if (chunk.expression.type !== 'Literal') {
component.error(attribute, { code, message });
}
return chunk.expression.value;
}
if (node) {
node.attributes.forEach(attribute => {
if (attribute.type === 'Attribute') {
const { name } = attribute;
switch (name) {
case 'tag': {
const code = 'invalid-tag-attribute';
const message = `'tag' must be a string literal`;
const tag = get_value(attribute, code, message);
if (typeof tag !== 'string' && tag !== null)
component.error(attribute, { code, message });
if (tag && !/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) {
component.error(attribute, {
code: `invalid-tag-property`,
message: `tag name must be two or more words joined by the '-' character`,
});
}
if (tag && !component.compile_options.customElement) {
component.warn(attribute, {
code: 'missing-custom-element-compile-options',
message: `The 'tag' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?`
});
}
component_options.tag = tag;
break;
}
case 'namespace': {
const code = 'invalid-namespace-attribute';
const message = `The 'namespace' attribute must be a string literal representing a valid namespace`;
const ns = get_value(attribute, code, message);
if (typeof ns !== 'string')
component.error(attribute, { code, message });
if (valid_namespaces.indexOf(ns) === -1) {
const match = fuzzymatch(ns, valid_namespaces);
if (match) {
component.error(attribute, {
code: `invalid-namespace-property`,
message: `Invalid namespace '${ns}' (did you mean '${match}'?)`,
});
}
else {
component.error(attribute, {
code: `invalid-namespace-property`,
message: `Invalid namespace '${ns}'`,
});
}
}
component_options.namespace = ns;
break;
}
case 'accessors':
case 'immutable':
case 'preserveWhitespace': {
const code = `invalid-${name}-value`;
const message = `${name} attribute must be true or false`;
const value = get_value(attribute, code, message);
if (typeof value !== 'boolean')
component.error(attribute, { code, message });
component_options[name] = value;
break;
}
default:
component.error(attribute, {
code: `invalid-options-attribute`,
message: `<svelte:options> unknown attribute`,
});
}
}
else {
component.error(attribute, {
code: `invalid-options-attribute`,
message: `<svelte:options> can only have static 'tag', 'namespace', 'accessors', 'immutable' and 'preserveWhitespace' attributes`,
});
}
});
}
return component_options;
}
function get_relative_path(from, to) {
const from_parts = from.split(/[/\\]/);
const to_parts = to.split(/[/\\]/);
from_parts.pop(); // get dirname
while (from_parts[0] === to_parts[0]) {
from_parts.shift();
to_parts.shift();
}
if (from_parts.length) {
let i = from_parts.length;
while (i--)
from_parts[i] = '..';
}
return from_parts.concat(to_parts).join('/');
}
function get_name_from_filename(filename) {
if (!filename)
return null;
const parts = filename.split(/[/\\]/).map(encodeURI);
if (parts.length > 1) {
const index_match = parts[parts.length - 1].match(/^index(\.\w+)/);
if (index_match) {
parts.pop();
parts[parts.length - 1] += index_match[1];
}
}
const base = parts.pop()
.replace(/%/g, 'u')
.replace(/\.[^.]+$/, "")
.replace(/[^a-zA-Z_$0-9]+/g, '_')
.replace(/^_/, '')
.replace(/_$/, '')
.replace(/^(\d)/, '_$1');
if (!base) {
throw new Error(`Could not derive component name from file ${filename}`);
}
return base[0].toUpperCase() + base.slice(1);
}
const valid_options = [
'format',
'name',
'filename',
'generate',
'outputFilename',
'cssOutputFilename',
'sveltePath',
'dev',
'accessors',
'immutable',
'hydratable',
'legacy',
'customElement',
'tag',
'css',
'loopGuardTimeout',
'preserveComments',
'preserveWhitespace'
];
function validate_options(options, warnings) {
const { name, filename, loopGuardTimeout, dev } = options;
Object.keys(options).forEach(key => {
if (!valid_options.includes(key)) {
const match = fuzzymatch(key, valid_options);
let message = `Unrecognized option '${key}'`;
if (match)
message += ` (did you mean '${match}'?)`;
throw new Error(message);
}
});
if (name && !/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(name)) {
throw new Error(`options.name must be a valid identifier (got '${name}')`);
}
if (name && /^[a-z]/.test(name)) {
const message = `options.name should be capitalised`;
warnings.push({
code: `options-lowercase-name`,
message,
filename,
toString: () => message,
});
}
if (loopGuardTimeout && !dev) {
const message = 'options.loopGuardTimeout is for options.dev = true only';
warnings.push({
code: `options-loop-guard-timeout`,
message,
filename,
toString: () => message,
});
}
}
function compile(source, options = {}) {
options = assign({ generate: 'dom', dev: false }, options);
const stats = new Stats();
const warnings = [];
validate_options(options, warnings);
stats.start('parse');
const ast = parse$3(source, options);
stats.stop('parse');
stats.start('create component');
const component = new Component(ast, source, options.name || get_name_from_filename(options.filename) || 'Component', options, stats, warnings);
stats.stop('create component');
const result = options.generate === false
? null
: options.generate === 'ssr'
? ssr(component, options)
: dom(component, options);
return component.generate(result);
}
function parse_attributes(str) {
const attrs = {};
str.split(/\s+/).filter(Boolean).forEach(attr => {
const p = attr.indexOf('=');
if (p === -1) {
attrs[attr] = true;
}
else {
attrs[attr.slice(0, p)] = `'"`.includes(attr[p + 1]) ?
attr.slice(p + 2, -1) :
attr.slice(p + 1);
}
});
return attrs;
}
async function replace_async(str, re, func) {
const replacements = [];
str.replace(re, (...args) => {
replacements.push(func(...args).then(res => ({
offset: args[args.length - 2],
length: args[0].length,
replacement: res,
})));
return '';
});
let out = '';
let last_end = 0;
for (const { offset, length, replacement } of await Promise.all(replacements)) {
out += str.slice(last_end, offset) + replacement;
last_end = offset + length;
}
out += str.slice(last_end);
return out;
}
async function preprocess(source, preprocessor, options) {
// @ts-ignore todo: doublecheck
const filename = (options && options.filename) || preprocessor.filename; // legacy
const dependencies = [];
const preprocessors = Array.isArray(preprocessor) ? preprocessor : [preprocessor];
const markup = preprocessors.map(p => p.markup).filter(Boolean);
const script = preprocessors.map(p => p.script).filter(Boolean);
const style = preprocessors.map(p => p.style).filter(Boolean);
for (const fn of markup) {
const processed = await fn({
content: source,
filename
});
if (processed && processed.dependencies)
dependencies.push(...processed.dependencies);
source = processed ? processed.code : source;
}
for (const fn of script) {
source = await replace_async(source, /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi, async (match, attributes = '', content = '') => {
if (!attributes && !content) {
return match;
}
attributes = attributes || '';
const processed = await fn({
content,
attributes: parse_attributes(attributes),
filename
});
if (processed && processed.dependencies)
dependencies.push(...processed.dependencies);
return processed ? `<script${attributes}>${processed.code}</script>` : match;
});
}
for (const fn of style) {
source = await replace_async(source, /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi, async (match, attributes = '', content = '') => {
if (!attributes && !content) {
return match;
}
const processed = await fn({
content,
attributes: parse_attributes(attributes),
filename
});
if (processed && processed.dependencies)
dependencies.push(...processed.dependencies);
return processed ? `<style${attributes}>${processed.code}</style>` : match;
});
}
return {
// TODO return separated output, in future version where svelte.compile supports it:
// style: { code: styleCode, map: styleMap },
// script { code: scriptCode, map: scriptMap },
// markup { code: markupCode, map: markupMap },
code: source,
dependencies: [...new Set(dependencies)],
toString() {
return source;
}
};
}
const VERSION = '3.24.1';
exports.VERSION = VERSION;
exports.compile = compile;
exports.parse = parse$3;
exports.preprocess = preprocess;
exports.walk = walk;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=compiler.js.map
});
unwrapExports(compiler$1);
var compiler_1 = compiler$1.parse;
var bail_1 = bail;
function bail(err) {
if (err) {
throw err
}
}
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
var isBuffer = function isBuffer (obj) {
return obj != null && obj.constructor != null &&
typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
};
var hasOwn = Object.prototype.hasOwnProperty;
var toStr = Object.prototype.toString;
var defineProperty = Object.defineProperty;
var gOPD = Object.getOwnPropertyDescriptor;
var isArray = function isArray(arr) {
if (typeof Array.isArray === 'function') {
return Array.isArray(arr);
}
return toStr.call(arr) === '[object Array]';
};
var isPlainObject = function isPlainObject(obj) {
if (!obj || toStr.call(obj) !== '[object Object]') {
return false;
}
var hasOwnConstructor = hasOwn.call(obj, 'constructor');
var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
// Not own constructor property must be Object
if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
return false;
}
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
var key;
for (key in obj) { /**/ }
return typeof key === 'undefined' || hasOwn.call(obj, key);
};
// If name is '__proto__', and Object.defineProperty is available, define __proto__ as an own property on target
var setProperty = function setProperty(target, options) {
if (defineProperty && options.name === '__proto__') {
defineProperty(target, options.name, {
enumerable: true,
configurable: true,
value: options.newValue,
writable: true
});
} else {
target[options.name] = options.newValue;
}
};
// Return undefined instead of __proto__ if '__proto__' is not an own property
var getProperty = function getProperty(obj, name) {
if (name === '__proto__') {
if (!hasOwn.call(obj, name)) {
return void 0;
} else if (gOPD) {
// In early versions of node, obj['__proto__'] is buggy when obj has
// __proto__ as an own property. Object.getOwnPropertyDescriptor() works.
return gOPD(obj, name).value;
}
}
return obj[name];
};
var extend$2 = function extend() {
var options, name, src, copy, copyIsArray, clone;
var target = arguments[0];
var i = 1;
var length = arguments.length;
var deep = false;
// Handle a deep copy situation
if (typeof target === 'boolean') {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
if (target == null || (typeof target !== 'object' && typeof target !== 'function')) {
target = {};
}
for (; i < length; ++i) {
options = arguments[i];
// Only deal with non-null/undefined values
if (options != null) {
// Extend the base object
for (name in options) {
src = getProperty(target, name);
copy = getProperty(options, name);
// Prevent never-ending loop
if (target !== copy) {
// Recurse if we're merging plain objects or arrays
if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
if (copyIsArray) {
copyIsArray = false;
clone = src && isArray(src) ? src : [];
} else {
clone = src && isPlainObject(src) ? src : {};
}
// Never move original objects, clone them
setProperty(target, { name: name, newValue: extend(deep, clone, copy) });
// Don't bring in undefined values
} else if (typeof copy !== 'undefined') {
setProperty(target, { name: name, newValue: copy });
}
}
}
}
}
// Return the modified object
return target;
};
var isPlainObj = value => {
if (Object.prototype.toString.call(value) !== '[object Object]') {
return false;
}
const prototype = Object.getPrototypeOf(value);
return prototype === null || prototype === Object.prototype;
};
var slice$3 = [].slice;
var wrap_1$1 = wrap$2;
// Wrap `fn`.
// Can be sync or async; return a promise, receive a completion handler, return
// new values and errors.
function wrap$2(fn, callback) {
var invoked;
return wrapped
function wrapped() {
var params = slice$3.call(arguments, 0);
var callback = fn.length > params.length;
var result;
if (callback) {
params.push(done);
}
try {
result = fn.apply(null, params);
} catch (error) {
// Well, this is quite the pickle.
// `fn` received a callback and invoked it (thus continuing the pipeline),
// but later also threw an error.
// Were not about to restart the pipeline again, so the only thing left
// to do is to throw the thing instead.
if (callback && invoked) {
throw error
}
return done(error)
}
if (!callback) {
if (result && typeof result.then === 'function') {
result.then(then, done);
} else if (result instanceof Error) {
done(result);
} else {
then(result);
}
}
}
// Invoke `next`, only once.
function done() {
if (!invoked) {
invoked = true;
callback.apply(null, arguments);
}
}
// Invoke `done` with one value.
// Tracks if an error is passed, too.
function then(value) {
done(null, value);
}
}
var trough_1 = trough;
trough.wrap = wrap_1$1;
var slice$2 = [].slice;
// Create new middleware.
function trough() {
var fns = [];
var middleware = {};
middleware.run = run;
middleware.use = use;
return middleware
// Run `fns`. Last argument must be a completion handler.
function run() {
var index = -1;
var input = slice$2.call(arguments, 0, -1);
var done = arguments[arguments.length - 1];
if (typeof done !== 'function') {
throw new Error('Expected function as last argument, not ' + done)
}
next.apply(null, [null].concat(input));
// Run the next `fn`, if any.
function next(err) {
var fn = fns[++index];
var params = slice$2.call(arguments, 0);
var values = params.slice(1);
var length = input.length;
var pos = -1;
if (err) {
done(err);
return
}
// Copy non-nully input into values.
while (++pos < length) {
if (values[pos] === null || values[pos] === undefined) {
values[pos] = input[pos];
}
}
input = values;
// Next or done.
if (fn) {
wrap_1$1(fn, next).apply(null, input);
} else {
done.apply(null, [null].concat(input));
}
}
}
// Add `fn` to the list.
function use(fn) {
if (typeof fn !== 'function') {
throw new Error('Expected `fn` to be a function, not ' + fn)
}
fns.push(fn);
return middleware
}
}
var own$e = {}.hasOwnProperty;
var unistUtilStringifyPosition = stringify$4;
function stringify$4(value) {
// Nothing.
if (!value || typeof value !== 'object') {
return ''
}
// Node.
if (own$e.call(value, 'position') || own$e.call(value, 'type')) {
return position$1(value.position)
}
// Position.
if (own$e.call(value, 'start') || own$e.call(value, 'end')) {
return position$1(value)
}
// Point.
if (own$e.call(value, 'line') || own$e.call(value, 'column')) {
return point(value)
}
// ?
return ''
}
function point(point) {
if (!point || typeof point !== 'object') {
point = {};
}
return index$5(point.line) + ':' + index$5(point.column)
}
function position$1(pos) {
if (!pos || typeof pos !== 'object') {
pos = {};
}
return point(pos.start) + '-' + point(pos.end)
}
function index$5(value) {
return value && typeof value === 'number' ? value : 1
}
var vfileMessage = VMessage;
// Inherit from `Error#`.
function VMessagePrototype() {}
VMessagePrototype.prototype = Error.prototype;
VMessage.prototype = new VMessagePrototype();
// Message properties.
var proto$6 = VMessage.prototype;
proto$6.file = '';
proto$6.name = '';
proto$6.reason = '';
proto$6.message = '';
proto$6.stack = '';
proto$6.fatal = null;
proto$6.column = null;
proto$6.line = null;
// Construct a new VMessage.
//
// Note: We cannot invoke `Error` on the created context, as that adds readonly
// `line` and `column` attributes on Safari 9, thus throwing and failing the
// data.
function VMessage(reason, position, origin) {
var parts;
var range;
var location;
if (typeof position === 'string') {
origin = position;
position = null;
}
parts = parseOrigin(origin);
range = unistUtilStringifyPosition(position) || '1:1';
location = {
start: {line: null, column: null},
end: {line: null, column: null}
};
// Node.
if (position && position.position) {
position = position.position;
}
if (position) {
// Position.
if (position.start) {
location = position;
position = position.start;
} else {
// Point.
location.start = position;
}
}
if (reason.stack) {
this.stack = reason.stack;
reason = reason.message;
}
this.message = reason;
this.name = range;
this.reason = reason;
this.line = position ? position.line : null;
this.column = position ? position.column : null;
this.location = location;
this.source = parts[0];
this.ruleId = parts[1];
}
function parseOrigin(origin) {
var result = [null, null];
var index;
if (typeof origin === 'string') {
index = origin.indexOf(':');
if (index === -1) {
result[1] = origin;
} else {
result[0] = origin.slice(0, index);
result[1] = origin.slice(index + 1);
}
}
return result
}
function replaceExt(npath, ext) {
if (typeof npath !== 'string') {
return npath;
}
if (npath.length === 0) {
return npath;
}
var nFileName = path.basename(npath, path.extname(npath)) + ext;
return path.join(path.dirname(npath), nFileName);
}
var replaceExt_1 = replaceExt;
var core$1 = VFile;
var own$d = {}.hasOwnProperty;
var proto$5 = VFile.prototype;
// Order of setting (least specific to most), we need this because otherwise
// `{stem: 'a', path: '~/b.js'}` would throw, as a path is needed before a
// stem can be set.
var order = ['history', 'path', 'basename', 'stem', 'extname', 'dirname'];
proto$5.toString = toString;
// Access full path (`~/index.min.js`).
Object.defineProperty(proto$5, 'path', {get: getPath, set: setPath});
// Access parent path (`~`).
Object.defineProperty(proto$5, 'dirname', {get: getDirname, set: setDirname});
// Access basename (`index.min.js`).
Object.defineProperty(proto$5, 'basename', {get: getBasename, set: setBasename});
// Access extname (`.js`).
Object.defineProperty(proto$5, 'extname', {get: getExtname, set: setExtname});
// Access stem (`index.min`).
Object.defineProperty(proto$5, 'stem', {get: getStem, set: setStem});
// Construct a new file.
function VFile(options) {
var prop;
var index;
var length;
if (!options) {
options = {};
} else if (typeof options === 'string' || isBuffer(options)) {
options = {contents: options};
} else if ('message' in options && 'messages' in options) {
return options
}
if (!(this instanceof VFile)) {
return new VFile(options)
}
this.data = {};
this.messages = [];
this.history = [];
this.cwd = process$1.cwd();
// Set path related properties in the correct order.
index = -1;
length = order.length;
while (++index < length) {
prop = order[index];
if (own$d.call(options, prop)) {
this[prop] = options[prop];
}
}
// Set non-path related properties.
for (prop in options) {
if (order.indexOf(prop) === -1) {
this[prop] = options[prop];
}
}
}
function getPath() {
return this.history[this.history.length - 1]
}
function setPath(path) {
assertNonEmpty(path, 'path');
if (path !== this.path) {
this.history.push(path);
}
}
function getDirname() {
return typeof this.path === 'string' ? path.dirname(this.path) : undefined
}
function setDirname(dirname) {
assertPath(this.path, 'dirname');
this.path = path.join(dirname || '', this.basename);
}
function getBasename() {
return typeof this.path === 'string' ? path.basename(this.path) : undefined
}
function setBasename(basename) {
assertNonEmpty(basename, 'basename');
assertPart(basename, 'basename');
this.path = path.join(this.dirname || '', basename);
}
function getExtname() {
return typeof this.path === 'string' ? path.extname(this.path) : undefined
}
function setExtname(extname) {
var ext = extname || '';
assertPart(ext, 'extname');
assertPath(this.path, 'extname');
if (ext) {
if (ext.charAt(0) !== '.') {
throw new Error('`extname` must start with `.`')
}
if (ext.indexOf('.', 1) !== -1) {
throw new Error('`extname` cannot contain multiple dots')
}
}
this.path = replaceExt_1(this.path, ext);
}
function getStem() {
return typeof this.path === 'string'
? path.basename(this.path, this.extname)
: undefined
}
function setStem(stem) {
assertNonEmpty(stem, 'stem');
assertPart(stem, 'stem');
this.path = path.join(this.dirname || '', stem + (this.extname || ''));
}
// Get the value of the file.
function toString(encoding) {
var value = this.contents || '';
return isBuffer(value) ? value.toString(encoding) : String(value)
}
// Assert that `part` is not a path (i.e., does not contain `path.sep`).
function assertPart(part, name) {
if (part.indexOf(path.sep) !== -1) {
throw new Error(
'`' + name + '` cannot be a path: did not expect `' + path.sep + '`'
)
}
}
// Assert that `part` is not empty.
function assertNonEmpty(part, name) {
if (!part) {
throw new Error('`' + name + '` cannot be empty')
}
}
// Assert `path` exists.
function assertPath(path, name) {
if (!path) {
throw new Error('Setting `' + name + '` requires `path` to be set too')
}
}
var vfile = core$1;
var proto$4 = core$1.prototype;
proto$4.message = message;
proto$4.info = info$1;
proto$4.fail = fail;
// Create a message with `reason` at `position`.
// When an error is passed in as `reason`, copies the stack.
function message(reason, position, origin) {
var filePath = this.path;
var message = new vfileMessage(reason, position, origin);
if (filePath) {
message.name = filePath + ':' + message.name;
message.file = filePath;
}
message.fatal = false;
this.messages.push(message);
return message
}
// Fail: creates a vmessage, associates it with the file, and throws it.
function fail() {
var message = this.message.apply(this, arguments);
message.fatal = true;
throw message
}
// Info: creates a vmessage, associates it with the file, and marks the fatality
// as null.
function info$1() {
var message = this.message.apply(this, arguments);
message.fatal = null;
return message
}
// Expose a frozen processor.
var unified_1$1 = unified$1().freeze();
var slice$1 = [].slice;
var own$c = {}.hasOwnProperty;
// Process pipeline.
var pipeline$1 = trough_1()
.use(pipelineParse$1)
.use(pipelineRun$1)
.use(pipelineStringify$1);
function pipelineParse$1(p, ctx) {
ctx.tree = p.parse(ctx.file);
}
function pipelineRun$1(p, ctx, next) {
p.run(ctx.tree, ctx.file, done);
function done(err, tree, file) {
if (err) {
next(err);
} else {
ctx.tree = tree;
ctx.file = file;
next();
}
}
}
function pipelineStringify$1(p, ctx) {
var result = p.stringify(ctx.tree, ctx.file);
var file = ctx.file;
if (result === undefined || result === null) ; else if (typeof result === 'string' || isBuffer(result)) {
file.contents = result;
} else {
file.result = result;
}
}
// Function to create the first processor.
function unified$1() {
var attachers = [];
var transformers = trough_1();
var namespace = {};
var frozen = false;
var freezeIndex = -1;
// Data management.
processor.data = data;
// Lock.
processor.freeze = freeze;
// Plugins.
processor.attachers = attachers;
processor.use = use;
// API.
processor.parse = parse;
processor.stringify = stringify;
processor.run = run;
processor.runSync = runSync;
processor.process = process;
processor.processSync = processSync;
// Expose.
return processor
// Create a new processor based on the processor in the current scope.
function processor() {
var destination = unified$1();
var length = attachers.length;
var index = -1;
while (++index < length) {
destination.use.apply(null, attachers[index]);
}
destination.data(extend$2(true, {}, namespace));
return destination
}
// Freeze: used to signal a processor that has finished configuration.
//
// For example, take unified itself: its frozen.
// Plugins should not be added to it.
// Rather, it should be extended, by invoking it, before modifying it.
//
// In essence, always invoke this when exporting a processor.
function freeze() {
var values;
var plugin;
var options;
var transformer;
if (frozen) {
return processor
}
while (++freezeIndex < attachers.length) {
values = attachers[freezeIndex];
plugin = values[0];
options = values[1];
transformer = null;
if (options === false) {
continue
}
if (options === true) {
values[1] = undefined;
}
transformer = plugin.apply(processor, values.slice(1));
if (typeof transformer === 'function') {
transformers.use(transformer);
}
}
frozen = true;
freezeIndex = Infinity;
return processor
}
// Data management.
// Getter / setter for processor-specific informtion.
function data(key, value) {
if (typeof key === 'string') {
// Set `key`.
if (arguments.length === 2) {
assertUnfrozen$1('data', frozen);
namespace[key] = value;
return processor
}
// Get `key`.
return (own$c.call(namespace, key) && namespace[key]) || null
}
// Set space.
if (key) {
assertUnfrozen$1('data', frozen);
namespace = key;
return processor
}
// Get space.
return namespace
}
// Plugin management.
//
// Pass it:
// * an attacher and options,
// * a preset,
// * a list of presets, attachers, and arguments (list of attachers and
// options).
function use(value) {
var settings;
assertUnfrozen$1('use', frozen);
if (value === null || value === undefined) ; else if (typeof value === 'function') {
addPlugin.apply(null, arguments);
} else if (typeof value === 'object') {
if ('length' in value) {
addList(value);
} else {
addPreset(value);
}
} else {
throw new Error('Expected usable value, not `' + value + '`')
}
if (settings) {
namespace.settings = extend$2(namespace.settings || {}, settings);
}
return processor
function addPreset(result) {
addList(result.plugins);
if (result.settings) {
settings = extend$2(settings || {}, result.settings);
}
}
function add(value) {
if (typeof value === 'function') {
addPlugin(value);
} else if (typeof value === 'object') {
if ('length' in value) {
addPlugin.apply(null, value);
} else {
addPreset(value);
}
} else {
throw new Error('Expected usable value, not `' + value + '`')
}
}
function addList(plugins) {
var length;
var index;
if (plugins === null || plugins === undefined) ; else if (typeof plugins === 'object' && 'length' in plugins) {
length = plugins.length;
index = -1;
while (++index < length) {
add(plugins[index]);
}
} else {
throw new Error('Expected a list of plugins, not `' + plugins + '`')
}
}
function addPlugin(plugin, value) {
var entry = find(plugin);
if (entry) {
if (isPlainObj(entry[1]) && isPlainObj(value)) {
value = extend$2(entry[1], value);
}
entry[1] = value;
} else {
attachers.push(slice$1.call(arguments));
}
}
}
function find(plugin) {
var length = attachers.length;
var index = -1;
var entry;
while (++index < length) {
entry = attachers[index];
if (entry[0] === plugin) {
return entry
}
}
}
// Parse a file (in string or vfile representation) into a unist node using
// the `Parser` on the processor.
function parse(doc) {
var file = vfile(doc);
var Parser;
freeze();
Parser = processor.Parser;
assertParser$1('parse', Parser);
if (newable$1(Parser, 'parse')) {
return new Parser(String(file), file).parse()
}
return Parser(String(file), file) // eslint-disable-line new-cap
}
// Run transforms on a unist node representation of a file (in string or
// vfile representation), async.
function run(node, file, cb) {
assertNode$1(node);
freeze();
if (!cb && typeof file === 'function') {
cb = file;
file = null;
}
if (!cb) {
return new Promise(executor)
}
executor(null, cb);
function executor(resolve, reject) {
transformers.run(node, vfile(file), done);
function done(err, tree, file) {
tree = tree || node;
if (err) {
reject(err);
} else if (resolve) {
resolve(tree);
} else {
cb(null, tree, file);
}
}
}
}
// Run transforms on a unist node representation of a file (in string or
// vfile representation), sync.
function runSync(node, file) {
var complete = false;
var result;
run(node, file, done);
assertDone$1('runSync', 'run', complete);
return result
function done(err, tree) {
complete = true;
bail_1(err);
result = tree;
}
}
// Stringify a unist node representation of a file (in string or vfile
// representation) into a string using the `Compiler` on the processor.
function stringify(node, doc) {
var file = vfile(doc);
var Compiler;
freeze();
Compiler = processor.Compiler;
assertCompiler$1('stringify', Compiler);
assertNode$1(node);
if (newable$1(Compiler, 'compile')) {
return new Compiler(node, file).compile()
}
return Compiler(node, file) // eslint-disable-line new-cap
}
// Parse a file (in string or vfile representation) into a unist node using
// the `Parser` on the processor, then run transforms on that node, and
// compile the resulting node using the `Compiler` on the processor, and
// store that result on the vfile.
function process(doc, cb) {
freeze();
assertParser$1('process', processor.Parser);
assertCompiler$1('process', processor.Compiler);
if (!cb) {
return new Promise(executor)
}
executor(null, cb);
function executor(resolve, reject) {
var file = vfile(doc);
pipeline$1.run(processor, {file: file}, done);
function done(err) {
if (err) {
reject(err);
} else if (resolve) {
resolve(file);
} else {
cb(null, file);
}
}
}
}
// Process the given document (in string or vfile representation), sync.
function processSync(doc) {
var complete = false;
var file;
freeze();
assertParser$1('processSync', processor.Parser);
assertCompiler$1('processSync', processor.Compiler);
file = vfile(doc);
process(file, done);
assertDone$1('processSync', 'process', complete);
return file
function done(err) {
complete = true;
bail_1(err);
}
}
}
// Check if `value` is a constructor.
function newable$1(value, name) {
return (
typeof value === 'function' &&
value.prototype &&
// A function with keys in its prototype is probably a constructor.
// Classes prototype methods are not enumerable, so we check if some value
// exists in the prototype.
(keys$2(value.prototype) || name in value.prototype)
)
}
// Check if `value` is an object with keys.
function keys$2(value) {
var key;
for (key in value) {
return true
}
return false
}
// Assert a parser is available.
function assertParser$1(name, Parser) {
if (typeof Parser !== 'function') {
throw new Error('Cannot `' + name + '` without `Parser`')
}
}
// Assert a compiler is available.
function assertCompiler$1(name, Compiler) {
if (typeof Compiler !== 'function') {
throw new Error('Cannot `' + name + '` without `Compiler`')
}
}
// Assert the processor is not frozen.
function assertUnfrozen$1(name, frozen) {
if (frozen) {
throw new Error(
'Cannot invoke `' +
name +
'` on a frozen processor.\nCreate a new processor first, by invoking it: use `processor()` instead of `processor`.'
)
}
}
// Assert `node` is a unist node.
function assertNode$1(node) {
if (!node || typeof node.type !== 'string') {
throw new Error('Expected node, got `' + node + '`')
}
}
// Assert that `complete` is `true`.
function assertDone$1(name, asyncName, complete) {
if (!complete) {
throw new Error(
'`' + name + '` finished async. Use `' + asyncName + '` instead'
)
}
}
var immutable = extend$1;
var hasOwnProperty = Object.prototype.hasOwnProperty;
function extend$1() {
var target = {};
for (var i = 0; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target
}
var inherits_browser = createCommonjsModule(function (module) {
if (typeof Object.create === 'function') {
// implementation from standard node.js 'util' module
module.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
}
};
} else {
// old school shim for old browsers
module.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor;
var TempCtor = function () {};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
}
};
}
});
var unherit_1 = unherit;
// Create a custom constructor which can be modified without affecting the
// original class.
function unherit(Super) {
var result;
var key;
var value;
inherits_browser(Of, Super);
inherits_browser(From, Of);
// Clone values.
result = Of.prototype;
for (key in result) {
value = result[key];
if (value && typeof value === 'object') {
result[key] = 'concat' in value ? value.concat() : immutable(value);
}
}
return Of
// Constructor accepting a single argument, which itself is an `arguments`
// object.
function From(parameters) {
return Super.apply(this, parameters)
}
// Constructor accepting variadic arguments.
function Of() {
if (!(this instanceof Of)) {
return new From(arguments)
}
return Super.apply(this, arguments)
}
}
var stateToggle = factory$6;
// Construct a state `toggler`: a function which inverses `property` in context
// based on its current value.
// The by `toggler` returned function restores that value.
function factory$6(key, state, ctx) {
return enter
function enter() {
var context = ctx || this;
var current = context[key];
context[key] = !state;
return exit
function exit() {
context[key] = current;
}
}
}
var vfileLocation = factory$5;
function factory$5(file) {
var contents = indices(String(file));
return {
toPosition: offsetToPositionFactory(contents),
toOffset: positionToOffsetFactory(contents)
}
}
// Factory to get the line and column-based `position` for `offset` in the bound
// indices.
function offsetToPositionFactory(indices) {
return offsetToPosition
// Get the line and column-based `position` for `offset` in the bound indices.
function offsetToPosition(offset) {
var index = -1;
var length = indices.length;
if (offset < 0) {
return {}
}
while (++index < length) {
if (indices[index] > offset) {
return {
line: index + 1,
column: offset - (indices[index - 1] || 0) + 1,
offset: offset
}
}
}
return {}
}
}
// Factory to get the `offset` for a line and column-based `position` in the
// bound indices.
function positionToOffsetFactory(indices) {
return positionToOffset
// Get the `offset` for a line and column-based `position` in the bound
// indices.
function positionToOffset(position) {
var line = position && position.line;
var column = position && position.column;
if (!isNaN(line) && !isNaN(column) && line - 1 in indices) {
return (indices[line - 2] || 0) + column - 1 || 0
}
return -1
}
}
// Get indices of line-breaks in `value`.
function indices(value) {
var result = [];
var index = value.indexOf('\n');
while (index !== -1) {
result.push(index + 1);
index = value.indexOf('\n', index + 1);
}
result.push(value.length + 1);
return result
}
var _unescape = factory$4;
var backslash$7 = '\\';
// Factory to de-escape a value, based on a list at `key` in `ctx`.
function factory$4(ctx, key) {
return unescape
// De-escape a string using the expression at `key` in `ctx`.
function unescape(value) {
var previous = 0;
var index = value.indexOf(backslash$7);
var escape = ctx[key];
var queue = [];
var character;
while (index !== -1) {
queue.push(value.slice(previous, index));
previous = index + 1;
character = value.charAt(previous);
// If the following character is not a valid escape, add the slash.
if (!character || escape.indexOf(character) === -1) {
queue.push(backslash$7);
}
index = value.indexOf(backslash$7, previous + 1);
}
queue.push(value.slice(previous));
return queue.join('')
}
}
var AElig$1 = "Æ";
var AMP$1 = "&";
var Aacute$1 = "Á";
var Acirc$1 = "Â";
var Agrave$1 = "À";
var Aring$1 = "Å";
var Atilde$1 = "Ã";
var Auml$1 = "Ä";
var COPY = "©";
var Ccedil$1 = "Ç";
var ETH$1 = "Ð";
var Eacute$1 = "É";
var Ecirc$1 = "Ê";
var Egrave$1 = "È";
var Euml$1 = "Ë";
var GT$1 = ">";
var Iacute$1 = "Í";
var Icirc$1 = "Î";
var Igrave$1 = "Ì";
var Iuml$1 = "Ï";
var LT$1 = "<";
var Ntilde$1 = "Ñ";
var Oacute$1 = "Ó";
var Ocirc$1 = "Ô";
var Ograve$1 = "Ò";
var Oslash$1 = "Ø";
var Otilde$1 = "Õ";
var Ouml$1 = "Ö";
var QUOT = "\"";
var REG = "®";
var THORN$1 = "Þ";
var Uacute$1 = "Ú";
var Ucirc$1 = "Û";
var Ugrave$1 = "Ù";
var Uuml$1 = "Ü";
var Yacute$1 = "Ý";
var aacute$1 = "á";
var acirc$1 = "â";
var acute$1 = "´";
var aelig$1 = "æ";
var agrave$1 = "à";
var amp$1 = "&";
var aring$1 = "å";
var atilde$1 = "ã";
var auml$1 = "ä";
var brvbar$1 = "¦";
var ccedil$1 = "ç";
var cedil$1 = "¸";
var cent$1 = "¢";
var copy$1 = "©";
var curren$1 = "¤";
var deg$1 = "°";
var divide$1 = "÷";
var eacute$1 = "é";
var ecirc$1 = "ê";
var egrave$1 = "è";
var eth$1 = "ð";
var euml$1 = "ë";
var frac12$1 = "½";
var frac14$1 = "¼";
var frac34$1 = "¾";
var gt$1 = ">";
var iacute$1 = "í";
var icirc$1 = "î";
var iexcl$1 = "¡";
var igrave$1 = "ì";
var iquest$1 = "¿";
var iuml$1 = "ï";
var laquo$1 = "«";
var lt$1 = "<";
var macr$1 = "¯";
var micro$1 = "µ";
var middot$1 = "·";
var nbsp$1 = " ";
var not$1 = "¬";
var ntilde$1 = "ñ";
var oacute$1 = "ó";
var ocirc$1 = "ô";
var ograve$1 = "ò";
var ordf$1 = "ª";
var ordm$1 = "º";
var oslash$1 = "ø";
var otilde$1 = "õ";
var ouml$1 = "ö";
var para$1 = "¶";
var plusmn$1 = "±";
var pound$1 = "£";
var quot$1 = "\"";
var raquo$1 = "»";
var reg$1 = "®";
var sect$1 = "§";
var shy$1 = "­";
var sup1$1 = "¹";
var sup2$1 = "²";
var sup3$1 = "³";
var szlig$1 = "ß";
var thorn$1 = "þ";
var times$1 = "×";
var uacute$1 = "ú";
var ucirc$1 = "û";
var ugrave$1 = "ù";
var uml$1 = "¨";
var uuml$1 = "ü";
var yacute$1 = "ý";
var yen$1 = "¥";
var yuml$1 = "ÿ";
var index$4 = {
AElig: AElig$1,
AMP: AMP$1,
Aacute: Aacute$1,
Acirc: Acirc$1,
Agrave: Agrave$1,
Aring: Aring$1,
Atilde: Atilde$1,
Auml: Auml$1,
COPY: COPY,
Ccedil: Ccedil$1,
ETH: ETH$1,
Eacute: Eacute$1,
Ecirc: Ecirc$1,
Egrave: Egrave$1,
Euml: Euml$1,
GT: GT$1,
Iacute: Iacute$1,
Icirc: Icirc$1,
Igrave: Igrave$1,
Iuml: Iuml$1,
LT: LT$1,
Ntilde: Ntilde$1,
Oacute: Oacute$1,
Ocirc: Ocirc$1,
Ograve: Ograve$1,
Oslash: Oslash$1,
Otilde: Otilde$1,
Ouml: Ouml$1,
QUOT: QUOT,
REG: REG,
THORN: THORN$1,
Uacute: Uacute$1,
Ucirc: Ucirc$1,
Ugrave: Ugrave$1,
Uuml: Uuml$1,
Yacute: Yacute$1,
aacute: aacute$1,
acirc: acirc$1,
acute: acute$1,
aelig: aelig$1,
agrave: agrave$1,
amp: amp$1,
aring: aring$1,
atilde: atilde$1,
auml: auml$1,
brvbar: brvbar$1,
ccedil: ccedil$1,
cedil: cedil$1,
cent: cent$1,
copy: copy$1,
curren: curren$1,
deg: deg$1,
divide: divide$1,
eacute: eacute$1,
ecirc: ecirc$1,
egrave: egrave$1,
eth: eth$1,
euml: euml$1,
frac12: frac12$1,
frac14: frac14$1,
frac34: frac34$1,
gt: gt$1,
iacute: iacute$1,
icirc: icirc$1,
iexcl: iexcl$1,
igrave: igrave$1,
iquest: iquest$1,
iuml: iuml$1,
laquo: laquo$1,
lt: lt$1,
macr: macr$1,
micro: micro$1,
middot: middot$1,
nbsp: nbsp$1,
not: not$1,
ntilde: ntilde$1,
oacute: oacute$1,
ocirc: ocirc$1,
ograve: ograve$1,
ordf: ordf$1,
ordm: ordm$1,
oslash: oslash$1,
otilde: otilde$1,
ouml: ouml$1,
para: para$1,
plusmn: plusmn$1,
pound: pound$1,
quot: quot$1,
raquo: raquo$1,
reg: reg$1,
sect: sect$1,
shy: shy$1,
sup1: sup1$1,
sup2: sup2$1,
sup3: sup3$1,
szlig: szlig$1,
thorn: thorn$1,
times: times$1,
uacute: uacute$1,
ucirc: ucirc$1,
ugrave: ugrave$1,
uml: uml$1,
uuml: uuml$1,
yacute: yacute$1,
yen: yen$1,
yuml: yuml$1
};
var characterEntitiesLegacy = /*#__PURE__*/Object.freeze({
__proto__: null,
AElig: AElig$1,
AMP: AMP$1,
Aacute: Aacute$1,
Acirc: Acirc$1,
Agrave: Agrave$1,
Aring: Aring$1,
Atilde: Atilde$1,
Auml: Auml$1,
COPY: COPY,
Ccedil: Ccedil$1,
ETH: ETH$1,
Eacute: Eacute$1,
Ecirc: Ecirc$1,
Egrave: Egrave$1,
Euml: Euml$1,
GT: GT$1,
Iacute: Iacute$1,
Icirc: Icirc$1,
Igrave: Igrave$1,
Iuml: Iuml$1,
LT: LT$1,
Ntilde: Ntilde$1,
Oacute: Oacute$1,
Ocirc: Ocirc$1,
Ograve: Ograve$1,
Oslash: Oslash$1,
Otilde: Otilde$1,
Ouml: Ouml$1,
QUOT: QUOT,
REG: REG,
THORN: THORN$1,
Uacute: Uacute$1,
Ucirc: Ucirc$1,
Ugrave: Ugrave$1,
Uuml: Uuml$1,
Yacute: Yacute$1,
aacute: aacute$1,
acirc: acirc$1,
acute: acute$1,
aelig: aelig$1,
agrave: agrave$1,
amp: amp$1,
aring: aring$1,
atilde: atilde$1,
auml: auml$1,
brvbar: brvbar$1,
ccedil: ccedil$1,
cedil: cedil$1,
cent: cent$1,
copy: copy$1,
curren: curren$1,
deg: deg$1,
divide: divide$1,
eacute: eacute$1,
ecirc: ecirc$1,
egrave: egrave$1,
eth: eth$1,
euml: euml$1,
frac12: frac12$1,
frac14: frac14$1,
frac34: frac34$1,
gt: gt$1,
iacute: iacute$1,
icirc: icirc$1,
iexcl: iexcl$1,
igrave: igrave$1,
iquest: iquest$1,
iuml: iuml$1,
laquo: laquo$1,
lt: lt$1,
macr: macr$1,
micro: micro$1,
middot: middot$1,
nbsp: nbsp$1,
not: not$1,
ntilde: ntilde$1,
oacute: oacute$1,
ocirc: ocirc$1,
ograve: ograve$1,
ordf: ordf$1,
ordm: ordm$1,
oslash: oslash$1,
otilde: otilde$1,
ouml: ouml$1,
para: para$1,
plusmn: plusmn$1,
pound: pound$1,
quot: quot$1,
raquo: raquo$1,
reg: reg$1,
sect: sect$1,
shy: shy$1,
sup1: sup1$1,
sup2: sup2$1,
sup3: sup3$1,
szlig: szlig$1,
thorn: thorn$1,
times: times$1,
uacute: uacute$1,
ucirc: ucirc$1,
ugrave: ugrave$1,
uml: uml$1,
uuml: uuml$1,
yacute: yacute$1,
yen: yen$1,
yuml: yuml$1,
'default': index$4
});
var index$3 = {
"0": "<22>",
"128": "€",
"130": "",
"131": "ƒ",
"132": "„",
"133": "…",
"134": "†",
"135": "‡",
"136": "ˆ",
"137": "‰",
"138": "Š",
"139": "",
"140": "Œ",
"142": "Ž",
"145": "",
"146": "",
"147": "“",
"148": "”",
"149": "•",
"150": "",
"151": "—",
"152": "˜",
"153": "™",
"154": "š",
"155": "",
"156": "œ",
"158": "ž",
"159": "Ÿ"
};
var characterReferenceInvalid = /*#__PURE__*/Object.freeze({
__proto__: null,
'default': index$3
});
var isDecimal = decimal$1;
// Check if the given character code, or the character code at the first
// character, is decimal.
function decimal$1(character) {
var code = typeof character === 'string' ? character.charCodeAt(0) : character;
return code >= 48 && code <= 57 /* 0-9 */
}
var isHexadecimal = hexadecimal;
// Check if the given character code, or the character code at the first
// character, is hexadecimal.
function hexadecimal(character) {
var code = typeof character === 'string' ? character.charCodeAt(0) : character;
return (
(code >= 97 /* a */ && code <= 102) /* z */ ||
(code >= 65 /* A */ && code <= 70) /* Z */ ||
(code >= 48 /* A */ && code <= 57) /* Z */
)
}
var isAlphabetical = alphabetical;
// Check if the given character code, or the character code at the first
// character, is alphabetical.
function alphabetical(character) {
var code = typeof character === 'string' ? character.charCodeAt(0) : character;
return (
(code >= 97 && code <= 122) /* a-z */ ||
(code >= 65 && code <= 90) /* A-Z */
)
}
var isAlphanumerical = alphanumerical;
// Check if the given character code, or the character code at the first
// character, is alphanumerical.
function alphanumerical(character) {
return isAlphabetical(character) || isDecimal(character)
}
/* eslint-env browser */
var el;
var semicolon$2 = 59; // ';'
var decodeEntity_browser = decodeEntity;
function decodeEntity(characters) {
var entity = '&' + characters + ';';
var char;
el = el || document.createElement('i');
el.innerHTML = entity;
char = el.textContent;
// Some entities do not require the closing semicolon (`&not` - for instance),
// which leads to situations where parsing the assumed entity of &notit; will
// result in the string `¬it;`. When we encounter a trailing semicolon after
// parsing and the entity to decode was not a semicolon (`&semi;`), we can
// assume that the matching was incomplete
if (char.charCodeAt(char.length - 1) === semicolon$2 && characters !== 'semi') {
return false
}
// If the decoded string is equal to the input, the entity was not valid
return char === entity ? false : char
}
var legacy = getCjsExportFromNamespace(characterEntitiesLegacy);
var invalid = getCjsExportFromNamespace(characterReferenceInvalid);
var parseEntities_1 = parseEntities;
var own$b = {}.hasOwnProperty;
var fromCharCode = String.fromCharCode;
var noop = Function.prototype;
// Default settings.
var defaults$3 = {
warning: null,
reference: null,
text: null,
warningContext: null,
referenceContext: null,
textContext: null,
position: {},
additional: null,
attribute: false,
nonTerminated: true
};
// Characters.
var tab$e = 9; // '\t'
var lineFeed$j = 10; // '\n'
var formFeed = 12; // '\f'
var space$j = 32; // ' '
var ampersand$1 = 38; // '&'
var semicolon$1 = 59; // ';'
var lessThan$8 = 60; // '<'
var equalsTo$2 = 61; // '='
var numberSign$1 = 35; // '#'
var uppercaseX = 88; // 'X'
var lowercaseX$1 = 120; // 'x'
var replacementCharacter = 65533; // '<27>'
// Reference types.
var name$1 = 'named';
var hexa = 'hexadecimal';
var deci = 'decimal';
// Map of bases.
var bases = {};
bases[hexa] = 16;
bases[deci] = 10;
// Map of types to tests.
// Each type of character reference accepts different characters.
// This test is used to detect whether a reference has ended (as the semicolon
// is not strictly needed).
var tests = {};
tests[name$1] = isAlphanumerical;
tests[deci] = isDecimal;
tests[hexa] = isHexadecimal;
// Warning types.
var namedNotTerminated = 1;
var numericNotTerminated = 2;
var namedEmpty = 3;
var numericEmpty = 4;
var namedUnknown = 5;
var numericDisallowed = 6;
var numericProhibited = 7;
// Warning messages.
var messages = {};
messages[namedNotTerminated] =
'Named character references must be terminated by a semicolon';
messages[numericNotTerminated] =
'Numeric character references must be terminated by a semicolon';
messages[namedEmpty] = 'Named character references cannot be empty';
messages[numericEmpty] = 'Numeric character references cannot be empty';
messages[namedUnknown] = 'Named character references must be known';
messages[numericDisallowed] =
'Numeric character references cannot be disallowed';
messages[numericProhibited] =
'Numeric character references cannot be outside the permissible Unicode range';
// Wrap to ensure clean parameters are given to `parse`.
function parseEntities(value, options) {
var settings = {};
var option;
var key;
if (!options) {
options = {};
}
for (key in defaults$3) {
option = options[key];
settings[key] =
option === null || option === undefined ? defaults$3[key] : option;
}
if (settings.position.indent || settings.position.start) {
settings.indent = settings.position.indent || [];
settings.position = settings.position.start;
}
return parse$7(value, settings)
}
// Parse entities.
// eslint-disable-next-line complexity
function parse$7(value, settings) {
var additional = settings.additional;
var nonTerminated = settings.nonTerminated;
var handleText = settings.text;
var handleReference = settings.reference;
var handleWarning = settings.warning;
var textContext = settings.textContext;
var referenceContext = settings.referenceContext;
var warningContext = settings.warningContext;
var pos = settings.position;
var indent = settings.indent || [];
var length = value.length;
var index = 0;
var lines = -1;
var column = pos.column || 1;
var line = pos.line || 1;
var queue = '';
var result = [];
var entityCharacters;
var namedEntity;
var terminated;
var characters;
var character;
var reference;
var following;
var warning;
var reason;
var output;
var entity;
var begin;
var start;
var type;
var test;
var prev;
var next;
var diff;
var end;
if (typeof additional === 'string') {
additional = additional.charCodeAt(0);
}
// Cache the current point.
prev = now();
// Wrap `handleWarning`.
warning = handleWarning ? parseError : noop;
// Ensure the algorithm walks over the first character and the end
// (inclusive).
index--;
length++;
while (++index < length) {
// If the previous character was a newline.
if (character === lineFeed$j) {
column = indent[lines] || 1;
}
character = value.charCodeAt(index);
if (character === ampersand$1) {
following = value.charCodeAt(index + 1);
// The behaviour depends on the identity of the next character.
if (
following === tab$e ||
following === lineFeed$j ||
following === formFeed ||
following === space$j ||
following === ampersand$1 ||
following === lessThan$8 ||
following !== following ||
(additional && following === additional)
) {
// Not a character reference.
// No characters are consumed, and nothing is returned.
// This is not an error, either.
queue += fromCharCode(character);
column++;
continue
}
start = index + 1;
begin = start;
end = start;
if (following === numberSign$1) {
// Numerical entity.
end = ++begin;
// The behaviour further depends on the next character.
following = value.charCodeAt(end);
if (following === uppercaseX || following === lowercaseX$1) {
// ASCII hex digits.
type = hexa;
end = ++begin;
} else {
// ASCII digits.
type = deci;
}
} else {
// Named entity.
type = name$1;
}
entityCharacters = '';
entity = '';
characters = '';
test = tests[type];
end--;
while (++end < length) {
following = value.charCodeAt(end);
if (!test(following)) {
break
}
characters += fromCharCode(following);
// Check if we can match a legacy named reference.
// If so, we cache that as the last viable named reference.
// This ensures we do not need to walk backwards later.
if (type === name$1 && own$b.call(legacy, characters)) {
entityCharacters = characters;
entity = legacy[characters];
}
}
terminated = value.charCodeAt(end) === semicolon$1;
if (terminated) {
end++;
namedEntity = type === name$1 ? decodeEntity_browser(characters) : false;
if (namedEntity) {
entityCharacters = characters;
entity = namedEntity;
}
}
diff = 1 + end - start;
if (!terminated && !nonTerminated) ; else if (!characters) {
// An empty (possible) entity is valid, unless its numeric (thus an
// ampersand followed by an octothorp).
if (type !== name$1) {
warning(numericEmpty, diff);
}
} else if (type === name$1) {
// An ampersand followed by anything unknown, and not terminated, is
// invalid.
if (terminated && !entity) {
warning(namedUnknown, 1);
} else {
// If theres something after an entity name which is not known, cap
// the reference.
if (entityCharacters !== characters) {
end = begin + entityCharacters.length;
diff = 1 + end - begin;
terminated = false;
}
// If the reference is not terminated, warn.
if (!terminated) {
reason = entityCharacters ? namedNotTerminated : namedEmpty;
if (settings.attribute) {
following = value.charCodeAt(end);
if (following === equalsTo$2) {
warning(reason, diff);
entity = null;
} else if (isAlphanumerical(following)) {
entity = null;
} else {
warning(reason, diff);
}
} else {
warning(reason, diff);
}
}
}
reference = entity;
} else {
if (!terminated) {
// All non-terminated numeric entities are not rendered, and trigger a
// warning.
warning(numericNotTerminated, diff);
}
// When terminated and number, parse as either hexadecimal or decimal.
reference = parseInt(characters, bases[type]);
// Trigger a warning when the parsed number is prohibited, and replace
// with replacement character.
if (prohibited(reference)) {
warning(numericProhibited, diff);
reference = fromCharCode(replacementCharacter);
} else if (reference in invalid) {
// Trigger a warning when the parsed number is disallowed, and replace
// by an alternative.
warning(numericDisallowed, diff);
reference = invalid[reference];
} else {
// Parse the number.
output = '';
// Trigger a warning when the parsed number should not be used.
if (disallowed(reference)) {
warning(numericDisallowed, diff);
}
// Stringify the number.
if (reference > 0xffff) {
reference -= 0x10000;
output += fromCharCode((reference >>> (10 & 0x3ff)) | 0xd800);
reference = 0xdc00 | (reference & 0x3ff);
}
reference = output + fromCharCode(reference);
}
}
// Found it!
// First eat the queued characters as normal text, then eat an entity.
if (reference) {
flush();
prev = now();
index = end - 1;
column += end - start + 1;
result.push(reference);
next = now();
next.offset++;
if (handleReference) {
handleReference.call(
referenceContext,
reference,
{start: prev, end: next},
value.slice(start - 1, end)
);
}
prev = next;
} else {
// If we could not find a reference, queue the checked characters (as
// normal characters), and move the pointer to their end.
// This is possible because we can be certain neither newlines nor
// ampersands are included.
characters = value.slice(start - 1, end);
queue += characters;
column += characters.length;
index = end - 1;
}
} else {
// Handle anything other than an ampersand, including newlines and EOF.
if (
character === 10 // Line feed
) {
line++;
lines++;
column = 0;
}
if (character === character) {
queue += fromCharCode(character);
column++;
} else {
flush();
}
}
}
// Return the reduced nodes.
return result.join('')
// Get current position.
function now() {
return {
line: line,
column: column,
offset: index + (pos.offset || 0)
}
}
// “Throw” a parse-error: a warning.
function parseError(code, offset) {
var position = now();
position.column += offset;
position.offset += offset;
handleWarning.call(warningContext, messages[code], position, code);
}
// Flush `queue` (normal text).
// Macro invoked before each entity and at the end of `value`.
// Does nothing when `queue` is empty.
function flush() {
if (queue) {
result.push(queue);
if (handleText) {
handleText.call(textContext, queue, {start: prev, end: now()});
}
queue = '';
}
}
}
// Check if `character` is outside the permissible unicode range.
function prohibited(code) {
return (code >= 0xd800 && code <= 0xdfff) || code > 0x10ffff
}
// Check if `character` is disallowed.
function disallowed(code) {
return (
(code >= 0x0001 && code <= 0x0008) ||
code === 0x000b ||
(code >= 0x000d && code <= 0x001f) ||
(code >= 0x007f && code <= 0x009f) ||
(code >= 0xfdd0 && code <= 0xfdef) ||
(code & 0xffff) === 0xffff ||
(code & 0xffff) === 0xfffe
)
}
var decode = factory$3;
// Factory to create an entity decoder.
function factory$3(ctx) {
decoder.raw = decodeRaw;
return decoder
// Normalize `position` to add an `indent`.
function normalize(position) {
var offsets = ctx.offset;
var line = position.line;
var result = [];
while (++line) {
if (!(line in offsets)) {
break
}
result.push((offsets[line] || 0) + 1);
}
return {start: position, indent: result}
}
// Decode `value` (at `position`) into text-nodes.
function decoder(value, position, handler) {
parseEntities_1(value, {
position: normalize(position),
warning: handleWarning,
text: handler,
reference: handler,
textContext: ctx,
referenceContext: ctx
});
}
// Decode `value` (at `position`) into a string.
function decodeRaw(value, position, options) {
return parseEntities_1(
value,
immutable(options, {position: normalize(position), warning: handleWarning})
)
}
// Handle a warning.
// See <https://github.com/wooorm/parse-entities> for the warnings.
function handleWarning(reason, position, code) {
if (code !== 3) {
ctx.file.message(reason, position);
}
}
}
var tokenizer$1 = factory$2;
// Construct a tokenizer. This creates both `tokenizeInline` and `tokenizeBlock`.
function factory$2(type) {
return tokenize
// Tokenizer for a bound `type`.
function tokenize(value, location) {
var self = this;
var offset = self.offset;
var tokens = [];
var methods = self[type + 'Methods'];
var tokenizers = self[type + 'Tokenizers'];
var line = location.line;
var column = location.column;
var index;
var length;
var method;
var name;
var matched;
var valueLength;
// Trim white space only lines.
if (!value) {
return tokens
}
// Expose on `eat`.
eat.now = now;
eat.file = self.file;
// Sync initial offset.
updatePosition('');
// Iterate over `value`, and iterate over all tokenizers. When one eats
// something, re-iterate with the remaining value. If no tokenizer eats,
// something failed (should not happen) and an exception is thrown.
while (value) {
index = -1;
length = methods.length;
matched = false;
while (++index < length) {
name = methods[index];
method = tokenizers[name];
// Previously, we had constructs such as footnotes and YAML that used
// these properties.
// Those are now external (plus there are userland extensions), that may
// still use them.
if (
method &&
/* istanbul ignore next */ (!method.onlyAtStart || self.atStart) &&
/* istanbul ignore next */ (!method.notInList || !self.inList) &&
/* istanbul ignore next */ (!method.notInBlock || !self.inBlock) &&
(!method.notInLink || !self.inLink)
) {
valueLength = value.length;
method.apply(self, [eat, value]);
matched = valueLength !== value.length;
if (matched) {
break
}
}
}
/* istanbul ignore if */
if (!matched) {
self.file.fail(new Error('Infinite loop'), eat.now());
}
}
self.eof = now();
return tokens
// Update line, column, and offset based on `value`.
function updatePosition(subvalue) {
var lastIndex = -1;
var index = subvalue.indexOf('\n');
while (index !== -1) {
line++;
lastIndex = index;
index = subvalue.indexOf('\n', index + 1);
}
if (lastIndex === -1) {
column += subvalue.length;
} else {
column = subvalue.length - lastIndex;
}
if (line in offset) {
if (lastIndex !== -1) {
column += offset[line];
} else if (column <= offset[line]) {
column = offset[line] + 1;
}
}
}
// Get offset. Called before the first character is eaten to retrieve the
// ranges offsets.
function getOffset() {
var indentation = [];
var pos = line + 1;
// Done. Called when the last character is eaten to retrieve the ranges
// offsets.
return function () {
var last = line + 1;
while (pos < last) {
indentation.push((offset[pos] || 0) + 1);
pos++;
}
return indentation
}
}
// Get the current position.
function now() {
var pos = {line: line, column: column};
pos.offset = self.toOffset(pos);
return pos
}
// Store position information for a node.
function Position(start) {
this.start = start;
this.end = now();
}
// Throw when a value is incorrectly eaten. This shouldnt happen but will
// throw on new, incorrect rules.
function validateEat(subvalue) {
/* istanbul ignore if */
if (value.slice(0, subvalue.length) !== subvalue) {
// Capture stack-trace.
self.file.fail(
new Error(
'Incorrectly eaten value: please report this warning on https://git.io/vg5Ft'
),
now()
);
}
}
// Mark position and patch `node.position`.
function position() {
var before = now();
return update
// Add the position to a node.
function update(node, indent) {
var previous = node.position;
var start = previous ? previous.start : before;
var combined = [];
var n = previous && previous.end.line;
var l = before.line;
node.position = new Position(start);
// If there was already a `position`, this node was merged. Fixing
// `start` wasnt hard, but the indent is different. Especially
// because some information, the indent between `n` and `l` wasnt
// tracked. Luckily, that space is (should be?) empty, so we can
// safely check for it now.
if (previous && indent && previous.indent) {
combined = previous.indent;
if (n < l) {
while (++n < l) {
combined.push((offset[n] || 0) + 1);
}
combined.push(before.column);
}
indent = combined.concat(indent);
}
node.position.indent = indent || [];
return node
}
}
// Add `node` to `parent`s children or to `tokens`. Performs merges where
// possible.
function add(node, parent) {
var children = parent ? parent.children : tokens;
var previous = children[children.length - 1];
var fn;
if (
previous &&
node.type === previous.type &&
(node.type === 'text' || node.type === 'blockquote') &&
mergeable(previous) &&
mergeable(node)
) {
fn = node.type === 'text' ? mergeText : mergeBlockquote;
node = fn.call(self, previous, node);
}
if (node !== previous) {
children.push(node);
}
if (self.atStart && tokens.length !== 0) {
self.exitStart();
}
return node
}
// Remove `subvalue` from `value`. `subvalue` must be at the start of
// `value`.
function eat(subvalue) {
var indent = getOffset();
var pos = position();
var current = now();
validateEat(subvalue);
apply.reset = reset;
reset.test = test;
apply.test = test;
value = value.slice(subvalue.length);
updatePosition(subvalue);
indent = indent();
return apply
// Add the given arguments, add `position` to the returned node, and
// return the node.
function apply(node, parent) {
return pos(add(pos(node), parent), indent)
}
// Functions just like apply, but resets the content: the line and
// column are reversed, and the eaten value is re-added. This is
// useful for nodes with a single type of content, such as lists and
// tables. See `apply` above for what parameters are expected.
function reset() {
var node = apply.apply(null, arguments);
line = current.line;
column = current.column;
value = subvalue + value;
return node
}
// Test the position, after eating, and reverse to a not-eaten state.
function test() {
var result = pos({});
line = current.line;
column = current.column;
value = subvalue + value;
return result.position
}
}
}
}
// Check whether a node is mergeable with adjacent nodes.
function mergeable(node) {
var start;
var end;
if (node.type !== 'text' || !node.position) {
return true
}
start = node.position.start;
end = node.position.end;
// Only merge nodes which occupy the same size as their `value`.
return (
start.line !== end.line || end.column - start.column === node.value.length
)
}
// Merge two text nodes: `node` into `prev`.
function mergeText(previous, node) {
previous.value += node.value;
return previous
}
// Merge two blockquotes: `node` into `prev`, unless in CommonMark or gfm modes.
function mergeBlockquote(previous, node) {
if (this.options.commonmark || this.options.gfm) {
return node
}
previous.children = previous.children.concat(node.children);
return previous
}
var markdownEscapes = escapes$1;
var defaults$2 = [
'\\',
'`',
'*',
'{',
'}',
'[',
']',
'(',
')',
'#',
'+',
'-',
'.',
'!',
'_',
'>'
];
var gfm = defaults$2.concat(['~', '|']);
var commonmark = gfm.concat([
'\n',
'"',
'$',
'%',
'&',
"'",
',',
'/',
':',
';',
'<',
'=',
'?',
'@',
'^'
]);
escapes$1.default = defaults$2;
escapes$1.gfm = gfm;
escapes$1.commonmark = commonmark;
// Get markdown escapes.
function escapes$1(options) {
var settings = options || {};
if (settings.commonmark) {
return commonmark
}
return settings.gfm ? gfm : defaults$2
}
var blockElements = [
'address',
'article',
'aside',
'base',
'basefont',
'blockquote',
'body',
'caption',
'center',
'col',
'colgroup',
'dd',
'details',
'dialog',
'dir',
'div',
'dl',
'dt',
'fieldset',
'figcaption',
'figure',
'footer',
'form',
'frame',
'frameset',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'head',
'header',
'hgroup',
'hr',
'html',
'iframe',
'legend',
'li',
'link',
'main',
'menu',
'menuitem',
'meta',
'nav',
'noframes',
'ol',
'optgroup',
'option',
'p',
'param',
'pre',
'section',
'source',
'title',
'summary',
'table',
'tbody',
'td',
'tfoot',
'th',
'thead',
'title',
'tr',
'track',
'ul'
];
var defaults$1 = {
position: true,
gfm: true,
commonmark: false,
pedantic: false,
blocks: blockElements
};
var setOptions_1 = setOptions;
function setOptions(options) {
var self = this;
var current = self.options;
var key;
var value;
if (options == null) {
options = {};
} else if (typeof options === 'object') {
options = immutable(options);
} else {
throw new Error('Invalid value `' + options + '` for setting `options`')
}
for (key in defaults$1) {
value = options[key];
if (value == null) {
value = current[key];
}
if (
(key !== 'blocks' && typeof value !== 'boolean') ||
(key === 'blocks' && typeof value !== 'object')
) {
throw new Error(
'Invalid value `' + value + '` for setting `options.' + key + '`'
)
}
options[key] = value;
}
self.options = options;
self.escape = markdownEscapes(options);
return self
}
var convert_1 = convert$1;
function convert$1(test) {
if (test == null) {
return ok$1
}
if (typeof test === 'string') {
return typeFactory$1(test)
}
if (typeof test === 'object') {
return 'length' in test ? anyFactory$1(test) : allFactory(test)
}
if (typeof test === 'function') {
return test
}
throw new Error('Expected function, string, or object as test')
}
// Utility assert each property in `test` is represented in `node`, and each
// values are strictly equal.
function allFactory(test) {
return all
function all(node) {
var key;
for (key in test) {
if (node[key] !== test[key]) return false
}
return true
}
}
function anyFactory$1(tests) {
var checks = [];
var index = -1;
while (++index < tests.length) {
checks[index] = convert$1(tests[index]);
}
return any
function any() {
var index = -1;
while (++index < checks.length) {
if (checks[index].apply(this, arguments)) {
return true
}
}
return false
}
}
// Utility to convert a string into a function which checks a given nodes type
// for said string.
function typeFactory$1(test) {
return type
function type(node) {
return Boolean(node && node.type === test)
}
}
// Utility to return true.
function ok$1() {
return true
}
var color_browser = identity;
function identity(d) {
return d
}
var unistUtilVisitParents = visitParents;
var CONTINUE$1 = true;
var SKIP$1 = 'skip';
var EXIT$1 = false;
visitParents.CONTINUE = CONTINUE$1;
visitParents.SKIP = SKIP$1;
visitParents.EXIT = EXIT$1;
function visitParents(tree, test, visitor, reverse) {
var step;
var is;
if (typeof test === 'function' && typeof visitor !== 'function') {
reverse = visitor;
visitor = test;
test = null;
}
is = convert_1(test);
step = reverse ? -1 : 1;
factory(tree, null, [])();
function factory(node, index, parents) {
var value = typeof node === 'object' && node !== null ? node : {};
var name;
if (typeof value.type === 'string') {
name =
typeof value.tagName === 'string'
? value.tagName
: typeof value.name === 'string'
? value.name
: undefined;
visit.displayName =
'node (' + color_browser(value.type + (name ? '<' + name + '>' : '')) + ')';
}
return visit
function visit() {
var grandparents = parents.concat(node);
var result = [];
var subresult;
var offset;
if (!test || is(node, index, parents[parents.length - 1] || null)) {
result = toResult(visitor(node, parents));
if (result[0] === EXIT$1) {
return result
}
}
if (node.children && result[0] !== SKIP$1) {
offset = (reverse ? node.children.length : -1) + step;
while (offset > -1 && offset < node.children.length) {
subresult = factory(node.children[offset], offset, grandparents)();
if (subresult[0] === EXIT$1) {
return subresult
}
offset =
typeof subresult[1] === 'number' ? subresult[1] : offset + step;
}
}
return result
}
}
}
function toResult(value) {
if (value !== null && typeof value === 'object' && 'length' in value) {
return value
}
if (typeof value === 'number') {
return [CONTINUE$1, value]
}
return [value]
}
var unistUtilVisit = visit;
var CONTINUE = unistUtilVisitParents.CONTINUE;
var SKIP = unistUtilVisitParents.SKIP;
var EXIT = unistUtilVisitParents.EXIT;
visit.CONTINUE = CONTINUE;
visit.SKIP = SKIP;
visit.EXIT = EXIT;
function visit(tree, test, visitor, reverse) {
if (typeof test === 'function' && typeof visitor !== 'function') {
reverse = visitor;
visitor = test;
test = null;
}
unistUtilVisitParents(tree, test, overload, reverse);
function overload(node, parents) {
var parent = parents[parents.length - 1];
var index = parent ? parent.children.indexOf(node) : null;
return visitor(node, index, parent)
}
}
var unistUtilRemovePosition = removePosition;
function removePosition(node, force) {
unistUtilVisit(node, force ? hard : soft);
return node
}
function hard(node) {
delete node.position;
}
function soft(node) {
node.position = undefined;
}
var parse_1$2 = parse$6;
var lineFeed$i = '\n';
var lineBreaksExpression = /\r\n|\r/g;
// Parse the bound file.
function parse$6() {
var self = this;
var value = String(self.file);
var start = {line: 1, column: 1, offset: 0};
var content = immutable(start);
var node;
// Clean non-unix newlines: `\r\n` and `\r` are all changed to `\n`.
// This should not affect positional information.
value = value.replace(lineBreaksExpression, lineFeed$i);
// BOM.
if (value.charCodeAt(0) === 0xfeff) {
value = value.slice(1);
content.column++;
content.offset++;
}
node = {
type: 'root',
children: self.tokenizeBlock(value, content),
position: {start: start, end: self.eof || immutable(start)}
};
if (!self.options.position) {
unistUtilRemovePosition(node, true);
}
return node
}
// A line containing no characters, or a line containing only spaces (U+0020) or
// tabs (U+0009), is called a blank line.
// See <https://spec.commonmark.org/0.29/#blank-line>.
var reBlankLine = /^[ \t]*(\n|$)/;
// Note that though blank lines play a special role in lists to determine
// whether the list is tight or loose
// (<https://spec.commonmark.org/0.29/#blank-lines>), its done by the list
// tokenizer and this blank line tokenizer does not have to be responsible for
// that.
// Therefore, configs such as `blankLine.notInList` do not have to be set here.
var blankLine_1 = blankLine;
function blankLine(eat, value, silent) {
var match;
var subvalue = '';
var index = 0;
var length = value.length;
while (index < length) {
match = reBlankLine.exec(value.slice(index));
if (match == null) {
break
}
index += match[0].length;
subvalue += match[0];
}
if (subvalue === '') {
return
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
eat(subvalue);
}
/*!
* repeat-string <https://github.com/jonschlinkert/repeat-string>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
/**
* Results cache
*/
var res = '';
var cache;
/**
* Expose `repeat`
*/
var repeatString = repeat$1;
/**
* Repeat the given `string` the specified `number`
* of times.
*
* **Example:**
*
* ```js
* var repeat = require('repeat-string');
* repeat('A', 5);
* //=> AAAAA
* ```
*
* @param {String} `string` The string to repeat
* @param {Number} `number` The number of times to repeat the string
* @return {String} Repeated string
* @api public
*/
function repeat$1(str, num) {
if (typeof str !== 'string') {
throw new TypeError('expected a string');
}
// cover common, quick use cases
if (num === 1) return str;
if (num === 2) return str + str;
var max = str.length * num;
if (cache !== str || typeof cache === 'undefined') {
cache = str;
res = '';
} else if (res.length >= max) {
return res.substr(0, max);
}
while (max > res.length && num > 1) {
if (num & 1) {
res += str;
}
num >>= 1;
str += str;
}
res += str;
res = res.substr(0, max);
return res;
}
var trimTrailingLines_1 = trimTrailingLines;
var line = '\n';
// Remove final newline characters from `value`.
function trimTrailingLines(value) {
var val = String(value);
var index = val.length;
while (val.charAt(--index) === line) {
// Empty
}
return val.slice(0, index + 1)
}
var codeIndented = indentedCode$1;
var lineFeed$h = '\n';
var tab$d = '\t';
var space$i = ' ';
var tabSize$4 = 4;
var codeIndent = repeatString(space$i, tabSize$4);
function indentedCode$1(eat, value, silent) {
var index = -1;
var length = value.length;
var subvalue = '';
var content = '';
var subvalueQueue = '';
var contentQueue = '';
var character;
var blankQueue;
var indent;
while (++index < length) {
character = value.charAt(index);
if (indent) {
indent = false;
subvalue += subvalueQueue;
content += contentQueue;
subvalueQueue = '';
contentQueue = '';
if (character === lineFeed$h) {
subvalueQueue = character;
contentQueue = character;
} else {
subvalue += character;
content += character;
while (++index < length) {
character = value.charAt(index);
if (!character || character === lineFeed$h) {
contentQueue = character;
subvalueQueue = character;
break
}
subvalue += character;
content += character;
}
}
} else if (
character === space$i &&
value.charAt(index + 1) === character &&
value.charAt(index + 2) === character &&
value.charAt(index + 3) === character
) {
subvalueQueue += codeIndent;
index += 3;
indent = true;
} else if (character === tab$d) {
subvalueQueue += character;
indent = true;
} else {
blankQueue = '';
while (character === tab$d || character === space$i) {
blankQueue += character;
character = value.charAt(++index);
}
if (character !== lineFeed$h) {
break
}
subvalueQueue += blankQueue + character;
contentQueue += character;
}
}
if (content) {
if (silent) {
return true
}
return eat(subvalue)({
type: 'code',
lang: null,
meta: null,
value: trimTrailingLines_1(content)
})
}
}
var codeFenced = fencedCode;
var lineFeed$g = '\n';
var tab$c = '\t';
var space$h = ' ';
var tilde$3 = '~';
var graveAccent$2 = '`';
var minFenceCount = 3;
var tabSize$3 = 4;
function fencedCode(eat, value, silent) {
var self = this;
var gfm = self.options.gfm;
var length = value.length + 1;
var index = 0;
var subvalue = '';
var fenceCount;
var marker;
var character;
var flag;
var lang;
var meta;
var queue;
var content;
var exdentedContent;
var closing;
var exdentedClosing;
var indent;
var now;
if (!gfm) {
return
}
// Eat initial spacing.
while (index < length) {
character = value.charAt(index);
if (character !== space$h && character !== tab$c) {
break
}
subvalue += character;
index++;
}
indent = index;
// Eat the fence.
character = value.charAt(index);
if (character !== tilde$3 && character !== graveAccent$2) {
return
}
index++;
marker = character;
fenceCount = 1;
subvalue += character;
while (index < length) {
character = value.charAt(index);
if (character !== marker) {
break
}
subvalue += character;
fenceCount++;
index++;
}
if (fenceCount < minFenceCount) {
return
}
// Eat spacing before flag.
while (index < length) {
character = value.charAt(index);
if (character !== space$h && character !== tab$c) {
break
}
subvalue += character;
index++;
}
// Eat flag.
flag = '';
queue = '';
while (index < length) {
character = value.charAt(index);
if (
character === lineFeed$g ||
(marker === graveAccent$2 && character === marker)
) {
break
}
if (character === space$h || character === tab$c) {
queue += character;
} else {
flag += queue + character;
queue = '';
}
index++;
}
character = value.charAt(index);
if (character && character !== lineFeed$g) {
return
}
if (silent) {
return true
}
now = eat.now();
now.column += subvalue.length;
now.offset += subvalue.length;
subvalue += flag;
flag = self.decode.raw(self.unescape(flag), now);
if (queue) {
subvalue += queue;
}
queue = '';
closing = '';
exdentedClosing = '';
content = '';
exdentedContent = '';
var skip = true;
// Eat content.
while (index < length) {
character = value.charAt(index);
content += closing;
exdentedContent += exdentedClosing;
closing = '';
exdentedClosing = '';
if (character !== lineFeed$g) {
content += character;
exdentedClosing += character;
index++;
continue
}
// The first line feed is ignored. Others arent.
if (skip) {
subvalue += character;
skip = false;
} else {
closing += character;
exdentedClosing += character;
}
queue = '';
index++;
while (index < length) {
character = value.charAt(index);
if (character !== space$h) {
break
}
queue += character;
index++;
}
closing += queue;
exdentedClosing += queue.slice(indent);
if (queue.length >= tabSize$3) {
continue
}
queue = '';
while (index < length) {
character = value.charAt(index);
if (character !== marker) {
break
}
queue += character;
index++;
}
closing += queue;
exdentedClosing += queue;
if (queue.length < fenceCount) {
continue
}
queue = '';
while (index < length) {
character = value.charAt(index);
if (character !== space$h && character !== tab$c) {
break
}
closing += character;
exdentedClosing += character;
index++;
}
if (!character || character === lineFeed$g) {
break
}
}
subvalue += content + closing;
// Get lang and meta from the flag.
index = -1;
length = flag.length;
while (++index < length) {
character = flag.charAt(index);
if (character === space$h || character === tab$c) {
if (!lang) {
lang = flag.slice(0, index);
}
} else if (lang) {
meta = flag.slice(index);
break
}
}
return eat(subvalue)({
type: 'code',
lang: lang || flag || null,
meta: meta || null,
value: exdentedContent
})
}
var trim_1 = createCommonjsModule(function (module, exports) {
exports = module.exports = trim;
function trim(str){
return str.replace(/^\s*|\s*$/g, '');
}
exports.left = function(str){
return str.replace(/^\s*/, '');
};
exports.right = function(str){
return str.replace(/\s*$/, '');
};
});
trim_1.left;
trim_1.right;
var interrupt_1 = interrupt;
function interrupt(interruptors, tokenizers, ctx, parameters) {
var length = interruptors.length;
var index = -1;
var interruptor;
var config;
while (++index < length) {
interruptor = interruptors[index];
config = interruptor[1] || {};
if (
config.pedantic !== undefined &&
config.pedantic !== ctx.options.pedantic
) {
continue
}
if (
config.commonmark !== undefined &&
config.commonmark !== ctx.options.commonmark
) {
continue
}
if (tokenizers[interruptor[0]].apply(ctx, parameters)) {
return true
}
}
return false
}
var blockquote_1$1 = blockquote$1;
var lineFeed$f = '\n';
var tab$b = '\t';
var space$g = ' ';
var greaterThan$4 = '>';
function blockquote$1(eat, value, silent) {
var self = this;
var offsets = self.offset;
var tokenizers = self.blockTokenizers;
var interruptors = self.interruptBlockquote;
var now = eat.now();
var currentLine = now.line;
var length = value.length;
var values = [];
var contents = [];
var indents = [];
var add;
var index = 0;
var character;
var rest;
var nextIndex;
var content;
var line;
var startIndex;
var prefixed;
var exit;
while (index < length) {
character = value.charAt(index);
if (character !== space$g && character !== tab$b) {
break
}
index++;
}
if (value.charAt(index) !== greaterThan$4) {
return
}
if (silent) {
return true
}
index = 0;
while (index < length) {
nextIndex = value.indexOf(lineFeed$f, index);
startIndex = index;
prefixed = false;
if (nextIndex === -1) {
nextIndex = length;
}
while (index < length) {
character = value.charAt(index);
if (character !== space$g && character !== tab$b) {
break
}
index++;
}
if (value.charAt(index) === greaterThan$4) {
index++;
prefixed = true;
if (value.charAt(index) === space$g) {
index++;
}
} else {
index = startIndex;
}
content = value.slice(index, nextIndex);
if (!prefixed && !trim_1(content)) {
index = startIndex;
break
}
if (!prefixed) {
rest = value.slice(index);
// Check if the following code contains a possible block.
if (interrupt_1(interruptors, tokenizers, self, [eat, rest, true])) {
break
}
}
line = startIndex === index ? content : value.slice(startIndex, nextIndex);
indents.push(index - startIndex);
values.push(line);
contents.push(content);
index = nextIndex + 1;
}
index = -1;
length = indents.length;
add = eat(values.join(lineFeed$f));
while (++index < length) {
offsets[currentLine] = (offsets[currentLine] || 0) + indents[index];
currentLine++;
}
exit = self.enterBlock();
contents = self.tokenizeBlock(contents.join(lineFeed$f), now);
exit();
return add({type: 'blockquote', children: contents})
}
var headingAtx = atxHeading;
var lineFeed$e = '\n';
var tab$a = '\t';
var space$f = ' ';
var numberSign = '#';
var maxFenceCount = 6;
function atxHeading(eat, value, silent) {
var self = this;
var pedantic = self.options.pedantic;
var length = value.length + 1;
var index = -1;
var now = eat.now();
var subvalue = '';
var content = '';
var character;
var queue;
var depth;
// Eat initial spacing.
while (++index < length) {
character = value.charAt(index);
if (character !== space$f && character !== tab$a) {
index--;
break
}
subvalue += character;
}
// Eat hashes.
depth = 0;
while (++index <= length) {
character = value.charAt(index);
if (character !== numberSign) {
index--;
break
}
subvalue += character;
depth++;
}
if (depth > maxFenceCount) {
return
}
if (!depth || (!pedantic && value.charAt(index + 1) === numberSign)) {
return
}
length = value.length + 1;
// Eat intermediate white-space.
queue = '';
while (++index < length) {
character = value.charAt(index);
if (character !== space$f && character !== tab$a) {
index--;
break
}
queue += character;
}
// Exit when not in pedantic mode without spacing.
if (!pedantic && queue.length === 0 && character && character !== lineFeed$e) {
return
}
if (silent) {
return true
}
// Eat content.
subvalue += queue;
queue = '';
content = '';
while (++index < length) {
character = value.charAt(index);
if (!character || character === lineFeed$e) {
break
}
if (character !== space$f && character !== tab$a && character !== numberSign) {
content += queue + character;
queue = '';
continue
}
while (character === space$f || character === tab$a) {
queue += character;
character = value.charAt(++index);
}
// `#` without a queue is part of the content.
if (!pedantic && content && !queue && character === numberSign) {
content += character;
continue
}
while (character === numberSign) {
queue += character;
character = value.charAt(++index);
}
while (character === space$f || character === tab$a) {
queue += character;
character = value.charAt(++index);
}
index--;
}
now.column += subvalue.length;
now.offset += subvalue.length;
subvalue += content + queue;
return eat(subvalue)({
type: 'heading',
depth: depth,
children: self.tokenizeInline(content, now)
})
}
var thematicBreak_1$1 = thematicBreak$1;
var tab$9 = '\t';
var lineFeed$d = '\n';
var space$e = ' ';
var asterisk$4 = '*';
var dash$7 = '-';
var underscore$6 = '_';
var maxCount = 3;
function thematicBreak$1(eat, value, silent) {
var index = -1;
var length = value.length + 1;
var subvalue = '';
var character;
var marker;
var markerCount;
var queue;
while (++index < length) {
character = value.charAt(index);
if (character !== tab$9 && character !== space$e) {
break
}
subvalue += character;
}
if (
character !== asterisk$4 &&
character !== dash$7 &&
character !== underscore$6
) {
return
}
marker = character;
subvalue += character;
markerCount = 1;
queue = '';
while (++index < length) {
character = value.charAt(index);
if (character === marker) {
markerCount++;
subvalue += queue + marker;
queue = '';
} else if (character === space$e) {
queue += character;
} else if (
markerCount >= maxCount &&
(!character || character === lineFeed$d)
) {
subvalue += queue;
if (silent) {
return true
}
return eat(subvalue)({type: 'thematicBreak'})
} else {
return
}
}
}
var getIndentation = indentation$1;
var tab$8 = '\t';
var space$d = ' ';
var spaceSize = 1;
var tabSize$2 = 4;
// Gets indentation information for a line.
function indentation$1(value) {
var index = 0;
var indent = 0;
var character = value.charAt(index);
var stops = {};
var size;
var lastIndent = 0;
while (character === tab$8 || character === space$d) {
size = character === tab$8 ? tabSize$2 : spaceSize;
indent += size;
if (size > 1) {
indent = Math.floor(indent / size) * size;
}
while (lastIndent < indent) {
stops[++lastIndent] = index;
}
character = value.charAt(++index);
}
return {indent: indent, stops: stops}
}
var removeIndentation = indentation;
var lineFeed$c = '\n';
var space$c = ' ';
var exclamationMark$4 = '!';
// Remove the minimum indent from every line in `value`. Supports both tab,
// spaced, and mixed indentation (as well as possible).
function indentation(value, maximum) {
var values = value.split(lineFeed$c);
var position = values.length + 1;
var minIndent = Infinity;
var matrix = [];
var index;
var indentation;
var stops;
values.unshift(repeatString(space$c, maximum) + exclamationMark$4);
while (position--) {
indentation = getIndentation(values[position]);
matrix[position] = indentation.stops;
if (trim_1(values[position]).length === 0) {
continue
}
if (indentation.indent) {
if (indentation.indent > 0 && indentation.indent < minIndent) {
minIndent = indentation.indent;
}
} else {
minIndent = Infinity;
break
}
}
if (minIndent !== Infinity) {
position = values.length;
while (position--) {
stops = matrix[position];
index = minIndent;
while (index && !(index in stops)) {
index--;
}
values[position] = values[position].slice(stops[index] + 1);
}
}
values.shift();
return values.join(lineFeed$c)
}
var list_1$1 = list$1;
var asterisk$3 = '*';
var underscore$5 = '_';
var plusSign$2 = '+';
var dash$6 = '-';
var dot$3 = '.';
var space$b = ' ';
var lineFeed$b = '\n';
var tab$7 = '\t';
var rightParenthesis$3 = ')';
var lowercaseX = 'x';
var tabSize$1 = 4;
var looseListItemExpression = /\n\n(?!\s*$)/;
var taskItemExpression = /^\[([ X\tx])][ \t]/;
var bulletExpression = /^([ \t]*)([*+-]|\d+[.)])( {1,4}(?! )| |\t|$|(?=\n))([^\n]*)/;
var pedanticBulletExpression = /^([ \t]*)([*+-]|\d+[.)])([ \t]+)/;
var initialIndentExpression = /^( {1,4}|\t)?/gm;
function list$1(eat, value, silent) {
var self = this;
var commonmark = self.options.commonmark;
var pedantic = self.options.pedantic;
var tokenizers = self.blockTokenizers;
var interuptors = self.interruptList;
var index = 0;
var length = value.length;
var start = null;
var size;
var queue;
var ordered;
var character;
var marker;
var nextIndex;
var startIndex;
var prefixed;
var currentMarker;
var content;
var line;
var previousEmpty;
var empty;
var items;
var allLines;
var emptyLines;
var item;
var enterTop;
var exitBlockquote;
var spread = false;
var node;
var now;
var end;
var indented;
while (index < length) {
character = value.charAt(index);
if (character !== tab$7 && character !== space$b) {
break
}
index++;
}
character = value.charAt(index);
if (character === asterisk$3 || character === plusSign$2 || character === dash$6) {
marker = character;
ordered = false;
} else {
ordered = true;
queue = '';
while (index < length) {
character = value.charAt(index);
if (!isDecimal(character)) {
break
}
queue += character;
index++;
}
character = value.charAt(index);
if (
!queue ||
!(character === dot$3 || (commonmark && character === rightParenthesis$3))
) {
return
}
/* Slightly abusing `silent` mode, whose goal is to make interrupting
* paragraphs work.
* Well, thats exactly what we want to do here: dont interrupt:
* 2. here, because the “list” doesnt start with `1`. */
if (silent && queue !== '1') {
return
}
start = parseInt(queue, 10);
marker = character;
}
character = value.charAt(++index);
if (
character !== space$b &&
character !== tab$7 &&
(pedantic || (character !== lineFeed$b && character !== ''))
) {
return
}
if (silent) {
return true
}
index = 0;
items = [];
allLines = [];
emptyLines = [];
while (index < length) {
nextIndex = value.indexOf(lineFeed$b, index);
startIndex = index;
prefixed = false;
indented = false;
if (nextIndex === -1) {
nextIndex = length;
}
size = 0;
while (index < length) {
character = value.charAt(index);
if (character === tab$7) {
size += tabSize$1 - (size % tabSize$1);
} else if (character === space$b) {
size++;
} else {
break
}
index++;
}
if (item && size >= item.indent) {
indented = true;
}
character = value.charAt(index);
currentMarker = null;
if (!indented) {
if (
character === asterisk$3 ||
character === plusSign$2 ||
character === dash$6
) {
currentMarker = character;
index++;
size++;
} else {
queue = '';
while (index < length) {
character = value.charAt(index);
if (!isDecimal(character)) {
break
}
queue += character;
index++;
}
character = value.charAt(index);
index++;
if (
queue &&
(character === dot$3 || (commonmark && character === rightParenthesis$3))
) {
currentMarker = character;
size += queue.length + 1;
}
}
if (currentMarker) {
character = value.charAt(index);
if (character === tab$7) {
size += tabSize$1 - (size % tabSize$1);
index++;
} else if (character === space$b) {
end = index + tabSize$1;
while (index < end) {
if (value.charAt(index) !== space$b) {
break
}
index++;
size++;
}
if (index === end && value.charAt(index) === space$b) {
index -= tabSize$1 - 1;
size -= tabSize$1 - 1;
}
} else if (character !== lineFeed$b && character !== '') {
currentMarker = null;
}
}
}
if (currentMarker) {
if (!pedantic && marker !== currentMarker) {
break
}
prefixed = true;
} else {
if (!commonmark && !indented && value.charAt(startIndex) === space$b) {
indented = true;
} else if (commonmark && item) {
indented = size >= item.indent || size > tabSize$1;
}
prefixed = false;
index = startIndex;
}
line = value.slice(startIndex, nextIndex);
content = startIndex === index ? line : value.slice(index, nextIndex);
if (
currentMarker === asterisk$3 ||
currentMarker === underscore$5 ||
currentMarker === dash$6
) {
if (tokenizers.thematicBreak.call(self, eat, line, true)) {
break
}
}
previousEmpty = empty;
empty = !prefixed && !trim_1(content).length;
if (indented && item) {
item.value = item.value.concat(emptyLines, line);
allLines = allLines.concat(emptyLines, line);
emptyLines = [];
} else if (prefixed) {
if (emptyLines.length !== 0) {
spread = true;
item.value.push('');
item.trail = emptyLines.concat();
}
item = {
value: [line],
indent: size,
trail: []
};
items.push(item);
allLines = allLines.concat(emptyLines, line);
emptyLines = [];
} else if (empty) {
if (previousEmpty && !commonmark) {
break
}
emptyLines.push(line);
} else {
if (previousEmpty) {
break
}
if (interrupt_1(interuptors, tokenizers, self, [eat, line, true])) {
break
}
item.value = item.value.concat(emptyLines, line);
allLines = allLines.concat(emptyLines, line);
emptyLines = [];
}
index = nextIndex + 1;
}
node = eat(allLines.join(lineFeed$b)).reset({
type: 'list',
ordered: ordered,
start: start,
spread: spread,
children: []
});
enterTop = self.enterList();
exitBlockquote = self.enterBlock();
index = -1;
length = items.length;
while (++index < length) {
item = items[index].value.join(lineFeed$b);
now = eat.now();
eat(item)(listItem$2(self, item, now), node);
item = items[index].trail.join(lineFeed$b);
if (index !== length - 1) {
item += lineFeed$b;
}
eat(item);
}
enterTop();
exitBlockquote();
return node
}
function listItem$2(ctx, value, position) {
var offsets = ctx.offset;
var fn = ctx.options.pedantic ? pedanticListItem : normalListItem;
var checked = null;
var task;
var indent;
value = fn.apply(null, arguments);
if (ctx.options.gfm) {
task = value.match(taskItemExpression);
if (task) {
indent = task[0].length;
checked = task[1].toLowerCase() === lowercaseX;
offsets[position.line] += indent;
value = value.slice(indent);
}
}
return {
type: 'listItem',
spread: looseListItemExpression.test(value),
checked: checked,
children: ctx.tokenizeBlock(value, position)
}
}
// Create a list-item using overly simple mechanics.
function pedanticListItem(ctx, value, position) {
var offsets = ctx.offset;
var line = position.line;
// Remove the list-items bullet.
value = value.replace(pedanticBulletExpression, replacer);
// The initial line was also matched by the below, so we reset the `line`.
line = position.line;
return value.replace(initialIndentExpression, replacer)
// A simple replacer which removed all matches, and adds their length to
// `offset`.
function replacer($0) {
offsets[line] = (offsets[line] || 0) + $0.length;
line++;
return ''
}
}
// Create a list-item using sane mechanics.
function normalListItem(ctx, value, position) {
var offsets = ctx.offset;
var line = position.line;
var max;
var bullet;
var rest;
var lines;
var trimmedLines;
var index;
var length;
// Remove the list-items bullet.
value = value.replace(bulletExpression, replacer);
lines = value.split(lineFeed$b);
trimmedLines = removeIndentation(value, getIndentation(max).indent).split(lineFeed$b);
// We replaced the initial bullet with something else above, which was used
// to trick `removeIndentation` into removing some more characters when
// possible. However, that could result in the initial line to be stripped
// more than it should be.
trimmedLines[0] = rest;
offsets[line] = (offsets[line] || 0) + bullet.length;
line++;
index = 0;
length = lines.length;
while (++index < length) {
offsets[line] =
(offsets[line] || 0) + lines[index].length - trimmedLines[index].length;
line++;
}
return trimmedLines.join(lineFeed$b)
/* eslint-disable-next-line max-params */
function replacer($0, $1, $2, $3, $4) {
bullet = $1 + $2 + $3;
rest = $4;
// Make sure that the first nine numbered list items can indent with an
// extra space. That is, when the bullet did not receive an extra final
// space.
if (Number($2) < 10 && bullet.length % 2 === 1) {
$2 = space$b + $2;
}
max = $1 + repeatString(space$b, $2.length) + $3;
return max + rest
}
}
var headingSetext = setextHeading;
var lineFeed$a = '\n';
var tab$6 = '\t';
var space$a = ' ';
var equalsTo$1 = '=';
var dash$5 = '-';
var maxIndent = 3;
var equalsToDepth = 1;
var dashDepth = 2;
function setextHeading(eat, value, silent) {
var self = this;
var now = eat.now();
var length = value.length;
var index = -1;
var subvalue = '';
var content;
var queue;
var character;
var marker;
var depth;
// Eat initial indentation.
while (++index < length) {
character = value.charAt(index);
if (character !== space$a || index >= maxIndent) {
index--;
break
}
subvalue += character;
}
// Eat content.
content = '';
queue = '';
while (++index < length) {
character = value.charAt(index);
if (character === lineFeed$a) {
index--;
break
}
if (character === space$a || character === tab$6) {
queue += character;
} else {
content += queue + character;
queue = '';
}
}
now.column += subvalue.length;
now.offset += subvalue.length;
subvalue += content + queue;
// Ensure the content is followed by a newline and a valid marker.
character = value.charAt(++index);
marker = value.charAt(++index);
if (character !== lineFeed$a || (marker !== equalsTo$1 && marker !== dash$5)) {
return
}
subvalue += character;
// Eat Setext-line.
queue = marker;
depth = marker === equalsTo$1 ? equalsToDepth : dashDepth;
while (++index < length) {
character = value.charAt(index);
if (character !== marker) {
if (character !== lineFeed$a) {
return
}
index--;
break
}
queue += character;
}
if (silent) {
return true
}
return eat(subvalue + queue)({
type: 'heading',
depth: depth,
children: self.tokenizeInline(content, now)
})
}
var attributeName$2 = '[a-zA-Z_:][a-zA-Z0-9:._-]*';
var unquoted$2 = '[^"\'=<>`\\u0000-\\u0020]+';
var singleQuoted$2 = "'[^']*'";
var doubleQuoted$2 = '"[^"]*"';
var attributeValue$2 =
'(?:' + unquoted$2 + '|' + singleQuoted$2 + '|' + doubleQuoted$2 + ')';
var attribute$2 =
'(?:\\s+' + attributeName$2 + '(?:\\s*=\\s*' + attributeValue$2 + ')?)';
var openTag$1 = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute$2 + '*\\s*\\/?>';
var closeTag$1 = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>';
var comment$1 = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->';
var processing = '<[?].*?[?]>';
var declaration = '<![A-Za-z]+\\s+[^>]*>';
var cdata = '<!\\[CDATA\\[[\\s\\S]*?\\]\\]>';
var openCloseTag$2 = new RegExp('^(?:' + openTag$1 + '|' + closeTag$1 + ')');
var tag$2 = new RegExp(
'^(?:' +
openTag$1 +
'|' +
closeTag$1 +
'|' +
comment$1 +
'|' +
processing +
'|' +
declaration +
'|' +
cdata +
')'
);
var html$4 = {
openCloseTag: openCloseTag$2,
tag: tag$2
};
var openCloseTag$1 = html$4.openCloseTag;
var htmlBlock = blockHtml$1;
var tab$5 = '\t';
var space$9 = ' ';
var lineFeed$9 = '\n';
var lessThan$7 = '<';
var rawOpenExpression$1 = /^<(script|pre|style)(?=(\s|>|$))/i;
var rawCloseExpression$1 = /<\/(script|pre|style)>/i;
var commentOpenExpression$1 = /^<!--/;
var commentCloseExpression$1 = /-->/;
var instructionOpenExpression$1 = /^<\?/;
var instructionCloseExpression$1 = /\?>/;
var directiveOpenExpression$1 = /^<![A-Za-z]/;
var directiveCloseExpression$1 = />/;
var cdataOpenExpression$1 = /^<!\[CDATA\[/;
var cdataCloseExpression$1 = /]]>/;
var elementCloseExpression$1 = /^$/;
var otherElementOpenExpression$1 = new RegExp(openCloseTag$1.source + '\\s*$');
function blockHtml$1(eat, value, silent) {
var self = this;
var blocks = self.options.blocks.join('|');
var elementOpenExpression = new RegExp(
'^</?(' + blocks + ')(?=(\\s|/?>|$))',
'i'
);
var length = value.length;
var index = 0;
var next;
var line;
var offset;
var character;
var count;
var sequence;
var subvalue;
var sequences = [
[rawOpenExpression$1, rawCloseExpression$1, true],
[commentOpenExpression$1, commentCloseExpression$1, true],
[instructionOpenExpression$1, instructionCloseExpression$1, true],
[directiveOpenExpression$1, directiveCloseExpression$1, true],
[cdataOpenExpression$1, cdataCloseExpression$1, true],
[elementOpenExpression, elementCloseExpression$1, true],
[otherElementOpenExpression$1, elementCloseExpression$1, false]
];
// Eat initial spacing.
while (index < length) {
character = value.charAt(index);
if (character !== tab$5 && character !== space$9) {
break
}
index++;
}
if (value.charAt(index) !== lessThan$7) {
return
}
next = value.indexOf(lineFeed$9, index + 1);
next = next === -1 ? length : next;
line = value.slice(index, next);
offset = -1;
count = sequences.length;
while (++offset < count) {
if (sequences[offset][0].test(line)) {
sequence = sequences[offset];
break
}
}
if (!sequence) {
return
}
if (silent) {
return sequence[2]
}
index = next;
if (!sequence[1].test(line)) {
while (index < length) {
next = value.indexOf(lineFeed$9, index + 1);
next = next === -1 ? length : next;
line = value.slice(index + 1, next);
if (sequence[1].test(line)) {
if (line) {
index = next;
}
break
}
index = next;
}
}
subvalue = value.slice(0, index);
return eat(subvalue)({type: 'html', value: subvalue})
}
var isWhitespaceCharacter = whitespace$1;
var fromCode$1 = String.fromCharCode;
var re$2 = /\s/;
// Check if the given character code, or the character code at the first
// character, is a whitespace character.
function whitespace$1(character) {
return re$2.test(
typeof character === 'number' ? fromCode$1(character) : character.charAt(0)
)
}
var collapseWhiteSpace = collapse;
// `collapse(' \t\nbar \nbaz\t') // ' bar baz '`
function collapse(value) {
return String(value).replace(/\s+/g, ' ')
}
var normalize_1$1 = normalize$1;
// Normalize an identifier. Collapses multiple white space characters into a
// single space, and removes casing.
function normalize$1(value) {
return collapseWhiteSpace(value).toLowerCase()
}
var definition_1 = definition;
var quotationMark$2 = '"';
var apostrophe$3 = "'";
var backslash$6 = '\\';
var lineFeed$8 = '\n';
var tab$4 = '\t';
var space$8 = ' ';
var leftSquareBracket$2 = '[';
var rightSquareBracket$2 = ']';
var leftParenthesis$1 = '(';
var rightParenthesis$2 = ')';
var colon$2 = ':';
var lessThan$6 = '<';
var greaterThan$3 = '>';
function definition(eat, value, silent) {
var self = this;
var commonmark = self.options.commonmark;
var index = 0;
var length = value.length;
var subvalue = '';
var beforeURL;
var beforeTitle;
var queue;
var character;
var test;
var identifier;
var url;
var title;
while (index < length) {
character = value.charAt(index);
if (character !== space$8 && character !== tab$4) {
break
}
subvalue += character;
index++;
}
character = value.charAt(index);
if (character !== leftSquareBracket$2) {
return
}
index++;
subvalue += character;
queue = '';
while (index < length) {
character = value.charAt(index);
if (character === rightSquareBracket$2) {
break
} else if (character === backslash$6) {
queue += character;
index++;
character = value.charAt(index);
}
queue += character;
index++;
}
if (
!queue ||
value.charAt(index) !== rightSquareBracket$2 ||
value.charAt(index + 1) !== colon$2
) {
return
}
identifier = queue;
subvalue += queue + rightSquareBracket$2 + colon$2;
index = subvalue.length;
queue = '';
while (index < length) {
character = value.charAt(index);
if (character !== tab$4 && character !== space$8 && character !== lineFeed$8) {
break
}
subvalue += character;
index++;
}
character = value.charAt(index);
queue = '';
beforeURL = subvalue;
if (character === lessThan$6) {
index++;
while (index < length) {
character = value.charAt(index);
if (!isEnclosedURLCharacter(character)) {
break
}
queue += character;
index++;
}
character = value.charAt(index);
if (character === isEnclosedURLCharacter.delimiter) {
subvalue += lessThan$6 + queue + character;
index++;
} else {
if (commonmark) {
return
}
index -= queue.length + 1;
queue = '';
}
}
if (!queue) {
while (index < length) {
character = value.charAt(index);
if (!isUnclosedURLCharacter(character)) {
break
}
queue += character;
index++;
}
subvalue += queue;
}
if (!queue) {
return
}
url = queue;
queue = '';
while (index < length) {
character = value.charAt(index);
if (character !== tab$4 && character !== space$8 && character !== lineFeed$8) {
break
}
queue += character;
index++;
}
character = value.charAt(index);
test = null;
if (character === quotationMark$2) {
test = quotationMark$2;
} else if (character === apostrophe$3) {
test = apostrophe$3;
} else if (character === leftParenthesis$1) {
test = rightParenthesis$2;
}
if (!test) {
queue = '';
index = subvalue.length;
} else if (queue) {
subvalue += queue + character;
index = subvalue.length;
queue = '';
while (index < length) {
character = value.charAt(index);
if (character === test) {
break
}
if (character === lineFeed$8) {
index++;
character = value.charAt(index);
if (character === lineFeed$8 || character === test) {
return
}
queue += lineFeed$8;
}
queue += character;
index++;
}
character = value.charAt(index);
if (character !== test) {
return
}
beforeTitle = subvalue;
subvalue += queue + character;
index++;
title = queue;
queue = '';
} else {
return
}
while (index < length) {
character = value.charAt(index);
if (character !== tab$4 && character !== space$8) {
break
}
subvalue += character;
index++;
}
character = value.charAt(index);
if (!character || character === lineFeed$8) {
if (silent) {
return true
}
beforeURL = eat(beforeURL).test().end;
url = self.decode.raw(self.unescape(url), beforeURL, {nonTerminated: false});
if (title) {
beforeTitle = eat(beforeTitle).test().end;
title = self.decode.raw(self.unescape(title), beforeTitle);
}
return eat(subvalue)({
type: 'definition',
identifier: normalize_1$1(identifier),
label: identifier,
title: title || null,
url: url
})
}
}
// Check if `character` can be inside an enclosed URI.
function isEnclosedURLCharacter(character) {
return (
character !== greaterThan$3 &&
character !== leftSquareBracket$2 &&
character !== rightSquareBracket$2
)
}
isEnclosedURLCharacter.delimiter = greaterThan$3;
// Check if `character` can be inside an unclosed URI.
function isUnclosedURLCharacter(character) {
return (
character !== leftSquareBracket$2 &&
character !== rightSquareBracket$2 &&
!isWhitespaceCharacter(character)
)
}
var table_1$1 = table$1;
var tab$3 = '\t';
var lineFeed$7 = '\n';
var space$7 = ' ';
var dash$4 = '-';
var colon$1 = ':';
var backslash$5 = '\\';
var verticalBar = '|';
var minColumns = 1;
var minRows = 2;
var left = 'left';
var center = 'center';
var right = 'right';
function table$1(eat, value, silent) {
var self = this;
var index;
var alignments;
var alignment;
var subvalue;
var row;
var length;
var lines;
var queue;
var character;
var hasDash;
var align;
var cell;
var preamble;
var now;
var position;
var lineCount;
var line;
var rows;
var table;
var lineIndex;
var pipeIndex;
var first;
// Exit when not in gfm-mode.
if (!self.options.gfm) {
return
}
// Get the rows.
// Detecting tables soon is hard, so there are some checks for performance
// here, such as the minimum number of rows, and allowed characters in the
// alignment row.
index = 0;
lineCount = 0;
length = value.length + 1;
lines = [];
while (index < length) {
lineIndex = value.indexOf(lineFeed$7, index);
pipeIndex = value.indexOf(verticalBar, index + 1);
if (lineIndex === -1) {
lineIndex = value.length;
}
if (pipeIndex === -1 || pipeIndex > lineIndex) {
if (lineCount < minRows) {
return
}
break
}
lines.push(value.slice(index, lineIndex));
lineCount++;
index = lineIndex + 1;
}
// Parse the alignment row.
subvalue = lines.join(lineFeed$7);
alignments = lines.splice(1, 1)[0] || [];
index = 0;
length = alignments.length;
lineCount--;
alignment = false;
align = [];
while (index < length) {
character = alignments.charAt(index);
if (character === verticalBar) {
hasDash = null;
if (alignment === false) {
if (first === false) {
return
}
} else {
align.push(alignment);
alignment = false;
}
first = false;
} else if (character === dash$4) {
hasDash = true;
alignment = alignment || null;
} else if (character === colon$1) {
if (alignment === left) {
alignment = center;
} else if (hasDash && alignment === null) {
alignment = right;
} else {
alignment = left;
}
} else if (!isWhitespaceCharacter(character)) {
return
}
index++;
}
if (alignment !== false) {
align.push(alignment);
}
// Exit when without enough columns.
if (align.length < minColumns) {
return
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
// Parse the rows.
position = -1;
rows = [];
table = eat(subvalue).reset({type: 'table', align: align, children: rows});
while (++position < lineCount) {
line = lines[position];
row = {type: 'tableRow', children: []};
// Eat a newline character when this is not the first row.
if (position) {
eat(lineFeed$7);
}
// Eat the row.
eat(line).reset(row, table);
length = line.length + 1;
index = 0;
queue = '';
cell = '';
preamble = true;
while (index < length) {
character = line.charAt(index);
if (character === tab$3 || character === space$7) {
if (cell) {
queue += character;
} else {
eat(character);
}
index++;
continue
}
if (character === '' || character === verticalBar) {
if (preamble) {
eat(character);
} else {
if ((cell || character) && !preamble) {
subvalue = cell;
if (queue.length > 1) {
if (character) {
subvalue += queue.slice(0, -1);
queue = queue.charAt(queue.length - 1);
} else {
subvalue += queue;
queue = '';
}
}
now = eat.now();
eat(subvalue)(
{type: 'tableCell', children: self.tokenizeInline(cell, now)},
row
);
}
eat(queue + character);
queue = '';
cell = '';
}
} else {
if (queue) {
cell += queue;
queue = '';
}
cell += character;
if (character === backslash$5 && index !== length - 2) {
cell += line.charAt(index + 1);
index++;
}
}
preamble = false;
index++;
}
// Eat the alignment row.
if (!position) {
eat(lineFeed$7 + alignments);
}
}
return table
}
var paragraph_1$1 = paragraph$1;
var tab$2 = '\t';
var lineFeed$6 = '\n';
var space$6 = ' ';
var tabSize = 4;
// Tokenise paragraph.
function paragraph$1(eat, value, silent) {
var self = this;
var settings = self.options;
var commonmark = settings.commonmark;
var tokenizers = self.blockTokenizers;
var interruptors = self.interruptParagraph;
var index = value.indexOf(lineFeed$6);
var length = value.length;
var position;
var subvalue;
var character;
var size;
var now;
while (index < length) {
// Eat everything if theres no following newline.
if (index === -1) {
index = length;
break
}
// Stop if the next character is NEWLINE.
if (value.charAt(index + 1) === lineFeed$6) {
break
}
// In commonmark-mode, following indented lines are part of the paragraph.
if (commonmark) {
size = 0;
position = index + 1;
while (position < length) {
character = value.charAt(position);
if (character === tab$2) {
size = tabSize;
break
} else if (character === space$6) {
size++;
} else {
break
}
position++;
}
if (size >= tabSize && character !== lineFeed$6) {
index = value.indexOf(lineFeed$6, index + 1);
continue
}
}
subvalue = value.slice(index + 1);
// Check if the following code contains a possible block.
if (interrupt_1(interruptors, tokenizers, self, [eat, subvalue, true])) {
break
}
position = index;
index = value.indexOf(lineFeed$6, index + 1);
if (index !== -1 && trim_1(value.slice(position, index)) === '') {
index = position;
break
}
}
subvalue = value.slice(0, index);
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
now = eat.now();
subvalue = trimTrailingLines_1(subvalue);
return eat(subvalue)({
type: 'paragraph',
children: self.tokenizeInline(subvalue, now)
})
}
var _escape$1 = locate$9;
function locate$9(value, fromIndex) {
return value.indexOf('\\', fromIndex)
}
var _escape = escape$1;
escape$1.locator = _escape$1;
var lineFeed$5 = '\n';
var backslash$4 = '\\';
function escape$1(eat, value, silent) {
var self = this;
var character;
var node;
if (value.charAt(0) === backslash$4) {
character = value.charAt(1);
if (self.escape.indexOf(character) !== -1) {
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
if (character === lineFeed$5) {
node = {type: 'break'};
} else {
node = {type: 'text', value: character};
}
return eat(backslash$4 + character)(node)
}
}
}
var tag$1 = locate$8;
function locate$8(value, fromIndex) {
return value.indexOf('<', fromIndex)
}
var autoLink_1 = autoLink;
autoLink.locator = tag$1;
autoLink.notInLink = true;
var lessThan$5 = '<';
var greaterThan$2 = '>';
var atSign$1 = '@';
var slash$3 = '/';
var mailto = 'mailto:';
var mailtoLength = mailto.length;
function autoLink(eat, value, silent) {
var self = this;
var subvalue = '';
var length = value.length;
var index = 0;
var queue = '';
var hasAtCharacter = false;
var link = '';
var character;
var now;
var content;
var tokenizers;
var exit;
if (value.charAt(0) !== lessThan$5) {
return
}
index++;
subvalue = lessThan$5;
while (index < length) {
character = value.charAt(index);
if (
isWhitespaceCharacter(character) ||
character === greaterThan$2 ||
character === atSign$1 ||
(character === ':' && value.charAt(index + 1) === slash$3)
) {
break
}
queue += character;
index++;
}
if (!queue) {
return
}
link += queue;
queue = '';
character = value.charAt(index);
link += character;
index++;
if (character === atSign$1) {
hasAtCharacter = true;
} else {
if (character !== ':' || value.charAt(index + 1) !== slash$3) {
return
}
link += slash$3;
index++;
}
while (index < length) {
character = value.charAt(index);
if (isWhitespaceCharacter(character) || character === greaterThan$2) {
break
}
queue += character;
index++;
}
character = value.charAt(index);
if (!queue || character !== greaterThan$2) {
return
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
link += queue;
content = link;
subvalue += link + character;
now = eat.now();
now.column++;
now.offset++;
if (hasAtCharacter) {
if (link.slice(0, mailtoLength).toLowerCase() === mailto) {
content = content.slice(mailtoLength);
now.column += mailtoLength;
now.offset += mailtoLength;
} else {
link = mailto + link;
}
}
// Temporarily remove all tokenizers except text in autolinks.
tokenizers = self.inlineTokenizers;
self.inlineTokenizers = {text: tokenizers.text};
exit = self.enterLink();
content = self.tokenizeInline(content, now);
self.inlineTokenizers = tokenizers;
exit();
return eat(subvalue)({
type: 'link',
title: null,
url: parseEntities_1(link, {nonTerminated: false}),
children: content
})
}
var ccount_1 = ccount;
function ccount(value, character) {
var val = String(value);
var count = 0;
var index;
if (typeof character !== 'string' || character.length !== 1) {
throw new Error('Expected character')
}
index = val.indexOf(character);
while (index !== -1) {
count++;
index = val.indexOf(character, index + 1);
}
return count
}
var url$1 = locate$7;
var values = ['www.', 'http://', 'https://'];
function locate$7(value, fromIndex) {
var min = -1;
var index;
var length;
var position;
if (!this.options.gfm) {
return min
}
length = values.length;
index = -1;
while (++index < length) {
position = value.indexOf(values[index], fromIndex);
if (position !== -1 && (min === -1 || position < min)) {
min = position;
}
}
return min
}
var url_1 = url;
url.locator = url$1;
url.notInLink = true;
var exclamationMark$3 = 33; // '!'
var ampersand = 38; // '&'
var rightParenthesis$1 = 41; // ')'
var asterisk$2 = 42; // '*'
var comma$1 = 44; // ','
var dash$3 = 45; // '-'
var dot$2 = 46; // '.'
var colon = 58; // ':'
var semicolon = 59; // ';'
var questionMark$1 = 63; // '?'
var lessThan$4 = 60; // '<'
var underscore$4 = 95; // '_'
var tilde$2 = 126; // '~'
var leftParenthesisCharacter = '(';
var rightParenthesisCharacter = ')';
function url(eat, value, silent) {
var self = this;
var gfm = self.options.gfm;
var tokenizers = self.inlineTokenizers;
var length = value.length;
var previousDot = -1;
var protocolless = false;
var dots;
var lastTwoPartsStart;
var start;
var index;
var pathStart;
var path;
var code;
var end;
var leftCount;
var rightCount;
var content;
var children;
var url;
var exit;
if (!gfm) {
return
}
// `WWW.` doesnt work.
if (value.slice(0, 4) === 'www.') {
protocolless = true;
index = 4;
} else if (value.slice(0, 7).toLowerCase() === 'http://') {
index = 7;
} else if (value.slice(0, 8).toLowerCase() === 'https://') {
index = 8;
} else {
return
}
// Act as if the starting boundary is a dot.
previousDot = index - 1;
// Parse a valid domain.
start = index;
dots = [];
while (index < length) {
code = value.charCodeAt(index);
if (code === dot$2) {
// Dots may not appear after each other.
if (previousDot === index - 1) {
break
}
dots.push(index);
previousDot = index;
index++;
continue
}
if (
isDecimal(code) ||
isAlphabetical(code) ||
code === dash$3 ||
code === underscore$4
) {
index++;
continue
}
break
}
// Ignore a final dot:
if (code === dot$2) {
dots.pop();
index--;
}
// If there are not dots, exit.
if (dots[0] === undefined) {
return
}
// If there is an underscore in the last two domain parts, exit:
// `www.example.c_m` and `www.ex_ample.com` are not OK, but
// `www.sub_domain.example.com` is.
lastTwoPartsStart = dots.length < 2 ? start : dots[dots.length - 2] + 1;
if (value.slice(lastTwoPartsStart, index).indexOf('_') !== -1) {
return
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
end = index;
pathStart = index;
// Parse a path.
while (index < length) {
code = value.charCodeAt(index);
if (isWhitespaceCharacter(code) || code === lessThan$4) {
break
}
index++;
if (
code === exclamationMark$3 ||
code === asterisk$2 ||
code === comma$1 ||
code === dot$2 ||
code === colon ||
code === questionMark$1 ||
code === underscore$4 ||
code === tilde$2
) ; else {
end = index;
}
}
index = end;
// If the path ends in a closing paren, and the count of closing parens is
// higher than the opening count, then remove the supefluous closing parens.
if (value.charCodeAt(index - 1) === rightParenthesis$1) {
path = value.slice(pathStart, index);
leftCount = ccount_1(path, leftParenthesisCharacter);
rightCount = ccount_1(path, rightParenthesisCharacter);
while (rightCount > leftCount) {
index = pathStart + path.lastIndexOf(rightParenthesisCharacter);
path = value.slice(pathStart, index);
rightCount--;
}
}
if (value.charCodeAt(index - 1) === semicolon) {
// GitHub doesnt document this, but final semicolons arent paret of the
// URL either.
index--;
// // If the path ends in what looks like an entity, its not part of the path.
if (isAlphabetical(value.charCodeAt(index - 1))) {
end = index - 2;
while (isAlphabetical(value.charCodeAt(end))) {
end--;
}
if (value.charCodeAt(end) === ampersand) {
index = end;
}
}
}
content = value.slice(0, index);
url = parseEntities_1(content, {nonTerminated: false});
if (protocolless) {
url = 'http://' + url;
}
exit = self.enterLink();
// Temporarily remove all tokenizers except text in url.
self.inlineTokenizers = {text: tokenizers.text};
children = self.tokenizeInline(content, eat.now());
self.inlineTokenizers = tokenizers;
exit();
return eat(content)({type: 'link', title: null, url: url, children: children})
}
var plusSign$1 = 43; // '+'
var dash$2 = 45; // '-'
var dot$1 = 46; // '.'
var underscore$3 = 95; // '_'
var email$1 = locate$6;
// See: <https://github.github.com/gfm/#extended-email-autolink>
function locate$6(value, fromIndex) {
var self = this;
var at;
var position;
if (!this.options.gfm) {
return -1
}
at = value.indexOf('@', fromIndex);
if (at === -1) {
return -1
}
position = at;
if (position === fromIndex || !isGfmAtext(value.charCodeAt(position - 1))) {
return locate$6.call(self, value, at + 1)
}
while (position > fromIndex && isGfmAtext(value.charCodeAt(position - 1))) {
position--;
}
return position
}
function isGfmAtext(code) {
return (
isDecimal(code) ||
isAlphabetical(code) ||
code === plusSign$1 ||
code === dash$2 ||
code === dot$1 ||
code === underscore$3
)
}
var email_1 = email;
email.locator = email$1;
email.notInLink = true;
var plusSign = 43; // '+'
var dash$1 = 45; // '-'
var dot = 46; // '.'
var atSign = 64; // '@'
var underscore$2 = 95; // '_'
function email(eat, value, silent) {
var self = this;
var gfm = self.options.gfm;
var tokenizers = self.inlineTokenizers;
var index = 0;
var length = value.length;
var firstDot = -1;
var code;
var content;
var children;
var exit;
if (!gfm) {
return
}
code = value.charCodeAt(index);
while (
isDecimal(code) ||
isAlphabetical(code) ||
code === plusSign ||
code === dash$1 ||
code === dot ||
code === underscore$2
) {
code = value.charCodeAt(++index);
}
if (index === 0) {
return
}
if (code !== atSign) {
return
}
index++;
while (index < length) {
code = value.charCodeAt(index);
if (
isDecimal(code) ||
isAlphabetical(code) ||
code === dash$1 ||
code === dot ||
code === underscore$2
) {
index++;
if (firstDot === -1 && code === dot) {
firstDot = index;
}
continue
}
break
}
if (
firstDot === -1 ||
firstDot === index ||
code === dash$1 ||
code === underscore$2
) {
return
}
if (code === dot) {
index--;
}
content = value.slice(0, index);
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
exit = self.enterLink();
// Temporarily remove all tokenizers except text in url.
self.inlineTokenizers = {text: tokenizers.text};
children = self.tokenizeInline(content, eat.now());
self.inlineTokenizers = tokenizers;
exit();
return eat(content)({
type: 'link',
title: null,
url: 'mailto:' + parseEntities_1(content, {nonTerminated: false}),
children: children
})
}
var tag = html$4.tag;
var htmlInline = inlineHTML;
inlineHTML.locator = tag$1;
var lessThan$3 = '<';
var questionMark = '?';
var exclamationMark$2 = '!';
var slash$2 = '/';
var htmlLinkOpenExpression = /^<a /i;
var htmlLinkCloseExpression = /^<\/a>/i;
function inlineHTML(eat, value, silent) {
var self = this;
var length = value.length;
var character;
var subvalue;
if (value.charAt(0) !== lessThan$3 || length < 3) {
return
}
character = value.charAt(1);
if (
!isAlphabetical(character) &&
character !== questionMark &&
character !== exclamationMark$2 &&
character !== slash$2
) {
return
}
subvalue = value.match(tag);
if (!subvalue) {
return
}
/* istanbul ignore if - not used yet. */
if (silent) {
return true
}
subvalue = subvalue[0];
if (!self.inLink && htmlLinkOpenExpression.test(subvalue)) {
self.inLink = true;
} else if (self.inLink && htmlLinkCloseExpression.test(subvalue)) {
self.inLink = false;
}
return eat(subvalue)({type: 'html', value: subvalue})
}
var link$3 = locate$5;
function locate$5(value, fromIndex) {
var link = value.indexOf('[', fromIndex);
var image = value.indexOf('![', fromIndex);
if (image === -1) {
return link
}
// Link can never be `-1` if an image is found, so we dont need to check
// for that :)
return link < image ? link : image
}
var link_1$1 = link$2;
link$2.locator = link$3;
var lineFeed$4 = '\n';
var exclamationMark$1 = '!';
var quotationMark$1 = '"';
var apostrophe$2 = "'";
var leftParenthesis = '(';
var rightParenthesis = ')';
var lessThan$2 = '<';
var greaterThan$1 = '>';
var leftSquareBracket$1 = '[';
var backslash$3 = '\\';
var rightSquareBracket$1 = ']';
var graveAccent$1 = '`';
function link$2(eat, value, silent) {
var self = this;
var subvalue = '';
var index = 0;
var character = value.charAt(0);
var pedantic = self.options.pedantic;
var commonmark = self.options.commonmark;
var gfm = self.options.gfm;
var closed;
var count;
var opening;
var beforeURL;
var beforeTitle;
var subqueue;
var hasMarker;
var isImage;
var content;
var marker;
var length;
var title;
var depth;
var queue;
var url;
var now;
var exit;
var node;
// Detect whether this is an image.
if (character === exclamationMark$1) {
isImage = true;
subvalue = character;
character = value.charAt(++index);
}
// Eat the opening.
if (character !== leftSquareBracket$1) {
return
}
// Exit when this is a link and were already inside a link.
if (!isImage && self.inLink) {
return
}
subvalue += character;
queue = '';
index++;
// Eat the content.
length = value.length;
now = eat.now();
depth = 0;
now.column += index;
now.offset += index;
while (index < length) {
character = value.charAt(index);
subqueue = character;
if (character === graveAccent$1) {
// Inline-code in link content.
count = 1;
while (value.charAt(index + 1) === graveAccent$1) {
subqueue += character;
index++;
count++;
}
if (!opening) {
opening = count;
} else if (count >= opening) {
opening = 0;
}
} else if (character === backslash$3) {
// Allow brackets to be escaped.
index++;
subqueue += value.charAt(index);
} else if ((!opening || gfm) && character === leftSquareBracket$1) {
// In GFM mode, brackets in code still count. In all other modes,
// they dont.
depth++;
} else if ((!opening || gfm) && character === rightSquareBracket$1) {
if (depth) {
depth--;
} else {
if (value.charAt(index + 1) !== leftParenthesis) {
return
}
subqueue += leftParenthesis;
closed = true;
index++;
break
}
}
queue += subqueue;
subqueue = '';
index++;
}
// Eat the content closing.
if (!closed) {
return
}
content = queue;
subvalue += queue + subqueue;
index++;
// Eat white-space.
while (index < length) {
character = value.charAt(index);
if (!isWhitespaceCharacter(character)) {
break
}
subvalue += character;
index++;
}
// Eat the URL.
character = value.charAt(index);
queue = '';
beforeURL = subvalue;
if (character === lessThan$2) {
index++;
beforeURL += lessThan$2;
while (index < length) {
character = value.charAt(index);
if (character === greaterThan$1) {
break
}
if (commonmark && character === lineFeed$4) {
return
}
queue += character;
index++;
}
if (value.charAt(index) !== greaterThan$1) {
return
}
subvalue += lessThan$2 + queue + greaterThan$1;
url = queue;
index++;
} else {
character = null;
subqueue = '';
while (index < length) {
character = value.charAt(index);
if (
subqueue &&
(character === quotationMark$1 ||
character === apostrophe$2 ||
(commonmark && character === leftParenthesis))
) {
break
}
if (isWhitespaceCharacter(character)) {
if (!pedantic) {
break
}
subqueue += character;
} else {
if (character === leftParenthesis) {
depth++;
} else if (character === rightParenthesis) {
if (depth === 0) {
break
}
depth--;
}
queue += subqueue;
subqueue = '';
if (character === backslash$3) {
queue += backslash$3;
character = value.charAt(++index);
}
queue += character;
}
index++;
}
subvalue += queue;
url = queue;
index = subvalue.length;
}
// Eat white-space.
queue = '';
while (index < length) {
character = value.charAt(index);
if (!isWhitespaceCharacter(character)) {
break
}
queue += character;
index++;
}
character = value.charAt(index);
subvalue += queue;
// Eat the title.
if (
queue &&
(character === quotationMark$1 ||
character === apostrophe$2 ||
(commonmark && character === leftParenthesis))
) {
index++;
subvalue += character;
queue = '';
marker = character === leftParenthesis ? rightParenthesis : character;
beforeTitle = subvalue;
// In commonmark-mode, things are pretty easy: the marker cannot occur
// inside the title. Non-commonmark does, however, support nested
// delimiters.
if (commonmark) {
while (index < length) {
character = value.charAt(index);
if (character === marker) {
break
}
if (character === backslash$3) {
queue += backslash$3;
character = value.charAt(++index);
}
index++;
queue += character;
}
character = value.charAt(index);
if (character !== marker) {
return
}
title = queue;
subvalue += queue + character;
index++;
while (index < length) {
character = value.charAt(index);
if (!isWhitespaceCharacter(character)) {
break
}
subvalue += character;
index++;
}
} else {
subqueue = '';
while (index < length) {
character = value.charAt(index);
if (character === marker) {
if (hasMarker) {
queue += marker + subqueue;
subqueue = '';
}
hasMarker = true;
} else if (!hasMarker) {
queue += character;
} else if (character === rightParenthesis) {
subvalue += queue + marker + subqueue;
title = queue;
break
} else if (isWhitespaceCharacter(character)) {
subqueue += character;
} else {
queue += marker + subqueue + character;
subqueue = '';
hasMarker = false;
}
index++;
}
}
}
if (value.charAt(index) !== rightParenthesis) {
return
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
subvalue += rightParenthesis;
url = self.decode.raw(self.unescape(url), eat(beforeURL).test().end, {
nonTerminated: false
});
if (title) {
beforeTitle = eat(beforeTitle).test().end;
title = self.decode.raw(self.unescape(title), beforeTitle);
}
node = {
type: isImage ? 'image' : 'link',
title: title || null,
url: url
};
if (isImage) {
node.alt = self.decode.raw(self.unescape(content), now) || null;
} else {
exit = self.enterLink();
node.children = self.tokenizeInline(content, now);
exit();
}
return eat(subvalue)(node)
}
var reference_1 = reference;
reference.locator = link$3;
var link$1 = 'link';
var image$2 = 'image';
var shortcut = 'shortcut';
var collapsed = 'collapsed';
var full = 'full';
var exclamationMark = '!';
var leftSquareBracket = '[';
var backslash$2 = '\\';
var rightSquareBracket = ']';
function reference(eat, value, silent) {
var self = this;
var commonmark = self.options.commonmark;
var character = value.charAt(0);
var index = 0;
var length = value.length;
var subvalue = '';
var intro = '';
var type = link$1;
var referenceType = shortcut;
var content;
var identifier;
var now;
var node;
var exit;
var queue;
var bracketed;
var depth;
// Check whether were eating an image.
if (character === exclamationMark) {
type = image$2;
intro = character;
character = value.charAt(++index);
}
if (character !== leftSquareBracket) {
return
}
index++;
intro += character;
queue = '';
// Eat the text.
depth = 0;
while (index < length) {
character = value.charAt(index);
if (character === leftSquareBracket) {
bracketed = true;
depth++;
} else if (character === rightSquareBracket) {
if (!depth) {
break
}
depth--;
}
if (character === backslash$2) {
queue += backslash$2;
character = value.charAt(++index);
}
queue += character;
index++;
}
subvalue = queue;
content = queue;
character = value.charAt(index);
if (character !== rightSquareBracket) {
return
}
index++;
subvalue += character;
queue = '';
if (!commonmark) {
// The original markdown syntax definition explicitly allows for whitespace
// between the link text and link label; commonmark departs from this, in
// part to improve support for shortcut reference links
while (index < length) {
character = value.charAt(index);
if (!isWhitespaceCharacter(character)) {
break
}
queue += character;
index++;
}
}
character = value.charAt(index);
if (character === leftSquareBracket) {
identifier = '';
queue += character;
index++;
while (index < length) {
character = value.charAt(index);
if (character === leftSquareBracket || character === rightSquareBracket) {
break
}
if (character === backslash$2) {
identifier += backslash$2;
character = value.charAt(++index);
}
identifier += character;
index++;
}
character = value.charAt(index);
if (character === rightSquareBracket) {
referenceType = identifier ? full : collapsed;
queue += identifier + character;
index++;
} else {
identifier = '';
}
subvalue += queue;
queue = '';
} else {
if (!content) {
return
}
identifier = content;
}
// Brackets cannot be inside the identifier.
if (referenceType !== full && bracketed) {
return
}
subvalue = intro + subvalue;
if (type === link$1 && self.inLink) {
return null
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
now = eat.now();
now.column += intro.length;
now.offset += intro.length;
identifier = referenceType === full ? identifier : content;
node = {
type: type + 'Reference',
identifier: normalize_1$1(identifier),
label: identifier,
referenceType: referenceType
};
if (type === link$1) {
exit = self.enterLink();
node.children = self.tokenizeInline(content, now);
exit();
} else {
node.alt = self.decode.raw(self.unescape(content), now) || null;
}
return eat(subvalue)(node)
}
var strong$2 = locate$4;
function locate$4(value, fromIndex) {
var asterisk = value.indexOf('**', fromIndex);
var underscore = value.indexOf('__', fromIndex);
if (underscore === -1) {
return asterisk
}
if (asterisk === -1) {
return underscore
}
return underscore < asterisk ? underscore : asterisk
}
var strong_1$1 = strong$1;
strong$1.locator = strong$2;
var backslash$1 = '\\';
var asterisk$1 = '*';
var underscore$1 = '_';
function strong$1(eat, value, silent) {
var self = this;
var index = 0;
var character = value.charAt(index);
var now;
var pedantic;
var marker;
var queue;
var subvalue;
var length;
var previous;
if (
(character !== asterisk$1 && character !== underscore$1) ||
value.charAt(++index) !== character
) {
return
}
pedantic = self.options.pedantic;
marker = character;
subvalue = marker + marker;
length = value.length;
index++;
queue = '';
character = '';
if (pedantic && isWhitespaceCharacter(value.charAt(index))) {
return
}
while (index < length) {
previous = character;
character = value.charAt(index);
if (
character === marker &&
value.charAt(index + 1) === marker &&
(!pedantic || !isWhitespaceCharacter(previous))
) {
character = value.charAt(index + 2);
if (character !== marker) {
if (!trim_1(queue)) {
return
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
now = eat.now();
now.column += 2;
now.offset += 2;
return eat(subvalue + queue + subvalue)({
type: 'strong',
children: self.tokenizeInline(queue, now)
})
}
}
if (!pedantic && character === backslash$1) {
queue += character;
character = value.charAt(++index);
}
queue += character;
index++;
}
}
var isWordCharacter = wordCharacter;
var fromCode = String.fromCharCode;
var re$1 = /\w/;
// Check if the given character code, or the character code at the first
// character, is a word character.
function wordCharacter(character) {
return re$1.test(
typeof character === 'number' ? fromCode(character) : character.charAt(0)
)
}
var emphasis$2 = locate$3;
function locate$3(value, fromIndex) {
var asterisk = value.indexOf('*', fromIndex);
var underscore = value.indexOf('_', fromIndex);
if (underscore === -1) {
return asterisk
}
if (asterisk === -1) {
return underscore
}
return underscore < asterisk ? underscore : asterisk
}
var emphasis_1$1 = emphasis$1;
emphasis$1.locator = emphasis$2;
var asterisk = '*';
var underscore = '_';
var backslash = '\\';
function emphasis$1(eat, value, silent) {
var self = this;
var index = 0;
var character = value.charAt(index);
var now;
var pedantic;
var marker;
var queue;
var subvalue;
var length;
var previous;
if (character !== asterisk && character !== underscore) {
return
}
pedantic = self.options.pedantic;
subvalue = character;
marker = character;
length = value.length;
index++;
queue = '';
character = '';
if (pedantic && isWhitespaceCharacter(value.charAt(index))) {
return
}
while (index < length) {
previous = character;
character = value.charAt(index);
if (character === marker && (!pedantic || !isWhitespaceCharacter(previous))) {
character = value.charAt(++index);
if (character !== marker) {
if (!trim_1(queue) || previous === marker) {
return
}
if (!pedantic && marker === underscore && isWordCharacter(character)) {
queue += marker;
continue
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
now = eat.now();
now.column++;
now.offset++;
return eat(subvalue + queue + marker)({
type: 'emphasis',
children: self.tokenizeInline(queue, now)
})
}
queue += marker;
}
if (!pedantic && character === backslash) {
queue += character;
character = value.charAt(++index);
}
queue += character;
index++;
}
}
var _delete$2 = locate$2;
function locate$2(value, fromIndex) {
return value.indexOf('~~', fromIndex)
}
var _delete$1 = strikethrough$1;
strikethrough$1.locator = _delete$2;
var tilde$1 = '~';
var fence$1 = '~~';
function strikethrough$1(eat, value, silent) {
var self = this;
var character = '';
var previous = '';
var preceding = '';
var subvalue = '';
var index;
var length;
var now;
if (
!self.options.gfm ||
value.charAt(0) !== tilde$1 ||
value.charAt(1) !== tilde$1 ||
isWhitespaceCharacter(value.charAt(2))
) {
return
}
index = 1;
length = value.length;
now = eat.now();
now.column += 2;
now.offset += 2;
while (++index < length) {
character = value.charAt(index);
if (
character === tilde$1 &&
previous === tilde$1 &&
(!preceding || !isWhitespaceCharacter(preceding))
) {
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
return eat(fence$1 + subvalue + fence$1)({
type: 'delete',
children: self.tokenizeInline(subvalue, now)
})
}
subvalue += previous;
preceding = previous;
previous = character;
}
}
var codeInline$1 = locate$1;
function locate$1(value, fromIndex) {
return value.indexOf('`', fromIndex)
}
var codeInline = inlineCode$1;
inlineCode$1.locator = codeInline$1;
var lineFeed$3 = 10; // '\n'
var space$5 = 32; // ' '
var graveAccent = 96; // '`'
function inlineCode$1(eat, value, silent) {
var length = value.length;
var index = 0;
var openingFenceEnd;
var closingFenceStart;
var closingFenceEnd;
var code;
var next;
var found;
while (index < length) {
if (value.charCodeAt(index) !== graveAccent) {
break
}
index++;
}
if (index === 0 || index === length) {
return
}
openingFenceEnd = index;
next = value.charCodeAt(index);
while (index < length) {
code = next;
next = value.charCodeAt(index + 1);
if (code === graveAccent) {
if (closingFenceStart === undefined) {
closingFenceStart = index;
}
closingFenceEnd = index + 1;
if (
next !== graveAccent &&
closingFenceEnd - closingFenceStart === openingFenceEnd
) {
found = true;
break
}
} else if (closingFenceStart !== undefined) {
closingFenceStart = undefined;
closingFenceEnd = undefined;
}
index++;
}
if (!found) {
return
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
// Remove the initial and final space (or line feed), iff they exist and there
// are non-space characters in the content.
index = openingFenceEnd;
length = closingFenceStart;
code = value.charCodeAt(index);
next = value.charCodeAt(length - 1);
found = false;
if (
length - index > 2 &&
(code === space$5 || code === lineFeed$3) &&
(next === space$5 || next === lineFeed$3)
) {
index++;
length--;
while (index < length) {
code = value.charCodeAt(index);
if (code !== space$5 && code !== lineFeed$3) {
found = true;
break
}
index++;
}
if (found === true) {
openingFenceEnd++;
closingFenceStart--;
}
}
return eat(value.slice(0, closingFenceEnd))({
type: 'inlineCode',
value: value.slice(openingFenceEnd, closingFenceStart)
})
}
var _break$2 = locate;
function locate(value, fromIndex) {
var index = value.indexOf('\n', fromIndex);
while (index > fromIndex) {
if (value.charAt(index - 1) !== ' ') {
break
}
index--;
}
return index
}
var _break$1 = hardBreak$1;
hardBreak$1.locator = _break$2;
var space$4 = ' ';
var lineFeed$2 = '\n';
var minBreakLength = 2;
function hardBreak$1(eat, value, silent) {
var length = value.length;
var index = -1;
var queue = '';
var character;
while (++index < length) {
character = value.charAt(index);
if (character === lineFeed$2) {
if (index < minBreakLength) {
return
}
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
queue += character;
return eat(queue)({type: 'break'})
}
if (character !== space$4) {
return
}
queue += character;
}
}
var text_1$2 = text$3;
function text$3(eat, value, silent) {
var self = this;
var methods;
var tokenizers;
var index;
var length;
var subvalue;
var position;
var tokenizer;
var name;
var min;
var now;
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
methods = self.inlineMethods;
length = methods.length;
tokenizers = self.inlineTokenizers;
index = -1;
min = value.length;
while (++index < length) {
name = methods[index];
if (name === 'text' || !tokenizers[name]) {
continue
}
tokenizer = tokenizers[name].locator;
if (!tokenizer) {
eat.file.fail('Missing locator: `' + name + '`');
}
position = tokenizer.call(self, value, 1);
if (position !== -1 && position < min) {
min = position;
}
}
subvalue = value.slice(0, min);
now = eat.now();
self.decode(subvalue, now, handler);
function handler(content, position, source) {
eat(source || content)({type: 'text', value: content});
}
}
var parser$1 = Parser;
function Parser(doc, file) {
this.file = file;
this.offset = {};
this.options = immutable(this.options);
this.setOptions({});
this.inList = false;
this.inBlock = false;
this.inLink = false;
this.atStart = true;
this.toOffset = vfileLocation(file).toOffset;
this.unescape = _unescape(this, 'escape');
this.decode = decode(this);
}
var proto$3 = Parser.prototype;
// Expose core.
proto$3.setOptions = setOptions_1;
proto$3.parse = parse_1$2;
// Expose `defaults`.
proto$3.options = defaults$1;
// Enter and exit helpers.
proto$3.exitStart = stateToggle('atStart', true);
proto$3.enterList = stateToggle('inList', false);
proto$3.enterLink = stateToggle('inLink', false);
proto$3.enterBlock = stateToggle('inBlock', false);
// Nodes that can interupt a paragraph:
//
// ```markdown
// A paragraph, followed by a thematic break.
// ___
// ```
//
// In the above example, the thematic break “interupts” the paragraph.
proto$3.interruptParagraph = [
['thematicBreak'],
['list'],
['atxHeading'],
['fencedCode'],
['blockquote'],
['html'],
['setextHeading', {commonmark: false}],
['definition', {commonmark: false}]
];
// Nodes that can interupt a list:
//
// ```markdown
// - One
// ___
// ```
//
// In the above example, the thematic break “interupts” the list.
proto$3.interruptList = [
['atxHeading', {pedantic: false}],
['fencedCode', {pedantic: false}],
['thematicBreak', {pedantic: false}],
['definition', {commonmark: false}]
];
// Nodes that can interupt a blockquote:
//
// ```markdown
// > A paragraph.
// ___
// ```
//
// In the above example, the thematic break “interupts” the blockquote.
proto$3.interruptBlockquote = [
['indentedCode', {commonmark: true}],
['fencedCode', {commonmark: true}],
['atxHeading', {commonmark: true}],
['setextHeading', {commonmark: true}],
['thematicBreak', {commonmark: true}],
['html', {commonmark: true}],
['list', {commonmark: true}],
['definition', {commonmark: false}]
];
// Handlers.
proto$3.blockTokenizers = {
blankLine: blankLine_1,
indentedCode: codeIndented,
fencedCode: codeFenced,
blockquote: blockquote_1$1,
atxHeading: headingAtx,
thematicBreak: thematicBreak_1$1,
list: list_1$1,
setextHeading: headingSetext,
html: htmlBlock,
definition: definition_1,
table: table_1$1,
paragraph: paragraph_1$1
};
proto$3.inlineTokenizers = {
escape: _escape,
autoLink: autoLink_1,
url: url_1,
email: email_1,
html: htmlInline,
link: link_1$1,
reference: reference_1,
strong: strong_1$1,
emphasis: emphasis_1$1,
deletion: _delete$1,
code: codeInline,
break: _break$1,
text: text_1$2
};
// Expose precedence.
proto$3.blockMethods = keys$1(proto$3.blockTokenizers);
proto$3.inlineMethods = keys$1(proto$3.inlineTokenizers);
// Tokenizers.
proto$3.tokenizeBlock = tokenizer$1('block');
proto$3.tokenizeInline = tokenizer$1('inline');
proto$3.tokenizeFactory = tokenizer$1;
// Get all keys in `value`.
function keys$1(value) {
var result = [];
var key;
for (key in value) {
result.push(key);
}
return result
}
var remarkParse = parse$5;
parse$5.Parser = parser$1;
function parse$5(options) {
var settings = this.data('settings');
var Local = unherit_1(parser$1);
Local.prototype.options = immutable(Local.prototype.options, settings, options);
this.Parser = Local;
}
var mdastUtilDefinitions$1 = getDefinitionFactory$1;
var own$a = {}.hasOwnProperty;
// Get a definition in `node` by `identifier`.
function getDefinitionFactory$1(node, options) {
return getterFactory$1(gather$1(node, options))
}
// Gather all definitions in `node`
function gather$1(node, options) {
var cache = {};
if (!node || !node.type) {
throw new Error('mdast-util-definitions expected node')
}
unistUtilVisit(node, 'definition', options && options.commonmark ? commonmark : normal);
return cache
function commonmark(definition) {
var id = normalise$1(definition.identifier);
if (!own$a.call(cache, id)) {
cache[id] = definition;
}
}
function normal(definition) {
cache[normalise$1(definition.identifier)] = definition;
}
}
// Factory to get a node from the given definition-cache.
function getterFactory$1(cache) {
return getter
// Get a node from the bound definition-cache.
function getter(identifier) {
var id = identifier && normalise$1(identifier);
return id && own$a.call(cache, id) ? cache[id] : null
}
}
function normalise$1(identifier) {
return identifier.toUpperCase()
}
var parse_1$1 = parse$4;
var stringify_1$1 = stringify$3;
var empty$2 = '';
var space$3 = ' ';
var whiteSpace$1 = /[ \t\n\r\f]+/g;
function parse$4(value) {
var input = String(value || empty$2).trim();
return input === empty$2 ? [] : input.split(whiteSpace$1)
}
function stringify$3(values) {
return values.join(space$3).trim()
}
var spaceSeparatedTokens = {
parse: parse_1$1,
stringify: stringify_1$1
};
var isAbsoluteUrl = url => {
if (typeof url !== 'string') {
throw new TypeError(`Expected a \`string\`, got \`${typeof url}\``);
}
// Don't match Windows paths `c:\`
if (/^[a-zA-Z]:\\/.test(url)) {
return false;
}
// Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url);
};
var spaceSeparated$4 = spaceSeparatedTokens.parse;
var remarkExternalLinks = externalLinks;
var defaultTarget = '_blank';
var defaultRel = ['nofollow', 'noopener', 'noreferrer'];
var defaultProtocols = ['http', 'https'];
function externalLinks(options) {
var settings = options || {};
var target = settings.target;
var rel = settings.rel;
var protocols = settings.protocols || defaultProtocols;
var content = settings.content;
var contentProperties = settings.contentProperties || {};
if (typeof rel === 'string') {
rel = spaceSeparated$4(rel);
}
if (content && typeof content === 'object' && !('length' in content)) {
content = [content];
}
return transform
function transform(tree) {
var definition = mdastUtilDefinitions$1(tree);
unistUtilVisit(tree, ['link', 'linkReference'], visitor);
function visitor(node) {
var ctx = node.type === 'link' ? node : definition(node.identifier);
var protocol;
var data;
var props;
if (!ctx) return
protocol = ctx.url.slice(0, ctx.url.indexOf(':'));
if (isAbsoluteUrl(ctx.url) && protocols.indexOf(protocol) !== -1) {
data = node.data || (node.data = {});
props = data.hProperties || (data.hProperties = {});
if (target !== false) {
props.target = target || defaultTarget;
}
if (rel !== false) {
props.rel = (rel || defaultRel).concat();
}
if (content) {
// `fragment` is not a known mdast node, but unknown nodes with
// children are handled as elements by `mdast-util-to-hast`:
// See: <https://github.com/syntax-tree/mdast-util-to-hast#notes>.
node.children.push({
type: 'fragment',
children: [],
data: {
hName: 'span',
hProperties: extend$2(true, contentProperties),
hChildren: extend$2(true, content)
}
});
}
}
}
}
}
var format = createCommonjsModule(function (module) {
(function() {
//// Export the API
var namespace;
// CommonJS / Node module
{
namespace = module.exports = format;
}
namespace.format = format;
namespace.vsprintf = vsprintf;
if (typeof console !== 'undefined' && typeof console.log === 'function') {
namespace.printf = printf;
}
function printf(/* ... */) {
console.log(format.apply(null, arguments));
}
function vsprintf(fmt, replacements) {
return format.apply(null, [fmt].concat(replacements));
}
function format(fmt) {
var argIndex = 1 // skip initial format argument
, args = [].slice.call(arguments)
, i = 0
, n = fmt.length
, result = ''
, c
, escaped = false
, arg
, tmp
, leadingZero = false
, precision
, nextArg = function() { return args[argIndex++]; }
, slurpNumber = function() {
var digits = '';
while (/\d/.test(fmt[i])) {
digits += fmt[i++];
c = fmt[i];
}
return digits.length > 0 ? parseInt(digits) : null;
}
;
for (; i < n; ++i) {
c = fmt[i];
if (escaped) {
escaped = false;
if (c == '.') {
leadingZero = false;
c = fmt[++i];
}
else if (c == '0' && fmt[i + 1] == '.') {
leadingZero = true;
i += 2;
c = fmt[i];
}
else {
leadingZero = true;
}
precision = slurpNumber();
switch (c) {
case 'b': // number in binary
result += parseInt(nextArg(), 10).toString(2);
break;
case 'c': // character
arg = nextArg();
if (typeof arg === 'string' || arg instanceof String)
result += arg;
else
result += String.fromCharCode(parseInt(arg, 10));
break;
case 'd': // number in decimal
result += parseInt(nextArg(), 10);
break;
case 'f': // floating point number
tmp = String(parseFloat(nextArg()).toFixed(precision || 6));
result += leadingZero ? tmp : tmp.replace(/^0/, '');
break;
case 'j': // JSON
result += JSON.stringify(nextArg());
break;
case 'o': // number in octal
result += '0' + parseInt(nextArg(), 10).toString(8);
break;
case 's': // string
result += nextArg();
break;
case 'x': // lowercase hexadecimal
result += '0x' + parseInt(nextArg(), 10).toString(16);
break;
case 'X': // uppercase hexadecimal
result += '0x' + parseInt(nextArg(), 10).toString(16).toUpperCase();
break;
default:
result += c;
break;
}
} else if (c === '%') {
escaped = true;
} else {
result += c;
}
}
return result;
}
}());
});
var fault = create$3(Error);
var fault_1 = fault;
fault.eval = create$3(EvalError);
fault.range = create$3(RangeError);
fault.reference = create$3(ReferenceError);
fault.syntax = create$3(SyntaxError);
fault.type = create$3(TypeError);
fault.uri = create$3(URIError);
fault.create = create$3;
// Create a new `EConstructor`, with the formatted `format` as a first argument.
function create$3(EConstructor) {
FormattedError.displayName = EConstructor.displayName || EConstructor.name;
return FormattedError
function FormattedError(format$1) {
if (format$1) {
format$1 = format.apply(null, arguments);
}
return new EConstructor(format$1)
}
}
var matters_1 = matters;
var own$9 = {}.hasOwnProperty;
var markers = {
yaml: '-',
toml: '+'
};
function matters(options) {
var results = [];
var index = -1;
var length;
// One preset or matter.
if (typeof options === 'string' || !('length' in options)) {
options = [options];
}
length = options.length;
while (++index < length) {
results[index] = matter(options[index]);
}
return results
}
function matter(option) {
var result = option;
if (typeof result === 'string') {
if (!own$9.call(markers, result)) {
throw fault_1('Missing matter definition for `%s`', result)
}
result = {type: result, marker: markers[result]};
} else if (typeof result !== 'object') {
throw fault_1('Expected matter to be an object, not `%j`', result)
}
if (!own$9.call(result, 'type')) {
throw fault_1('Missing `type` in matter `%j`', result)
}
if (!own$9.call(result, 'fence') && !own$9.call(result, 'marker')) {
throw fault_1('Missing `marker` or `fence` in matter `%j`', result)
}
return result
}
var fence_1 = fence;
function fence(matter, prop) {
var marker;
if (matter.marker) {
marker = pick(matter.marker, prop);
return marker + marker + marker
}
return pick(matter.fence, prop)
}
function pick(schema, prop) {
return typeof schema === 'string' ? schema : schema[prop]
}
var parse$3 = create$2;
function create$2(matter) {
var name = matter.type + 'FrontMatter';
var open = fence_1(matter, 'open');
var close = fence_1(matter, 'close');
var newline = '\n';
var anywhere = matter.anywhere;
frontmatter.displayName = name;
frontmatter.onlyAtStart = typeof anywhere === 'boolean' ? !anywhere : true;
return [name, frontmatter]
function frontmatter(eat, value, silent) {
var index = open.length;
var offset;
if (value.slice(0, index) !== open || value.charAt(index) !== newline) {
return
}
offset = value.indexOf(close, index);
while (offset !== -1 && value.charAt(offset - 1) !== newline) {
index = offset + close.length;
offset = value.indexOf(close, index);
}
if (offset !== -1) {
/* istanbul ignore if - never used (yet) */
if (silent) {
return true
}
return eat(value.slice(0, offset + close.length))({
type: matter.type,
value: value.slice(open.length + 1, offset - 1)
})
}
}
}
var compile = create$1;
function create$1(matter) {
var type = matter.type;
var open = fence_1(matter, 'open');
var close = fence_1(matter, 'close');
frontmatter.displayName = type + 'FrontMatter';
return [type, frontmatter]
function frontmatter(node) {
return open + (node.value ? '\n' + node.value : '') + '\n' + close
}
}
var remarkFrontmatter = frontmatter;
function frontmatter(options) {
var parser = this.Parser;
var compiler = this.Compiler;
var config = matters_1(options || ['yaml']);
if (isRemarkParser(parser)) {
attachParser(parser, config);
}
if (isRemarkCompiler(compiler)) {
attachCompiler(compiler, config);
}
}
function attachParser(parser, matters) {
var proto = parser.prototype;
var tokenizers = wrap$1(parse$3, matters);
var names = [];
var key;
for (key in tokenizers) {
names.push(key);
}
proto.blockMethods = names.concat(proto.blockMethods);
proto.blockTokenizers = Object.assign({}, tokenizers, proto.blockTokenizers);
}
function attachCompiler(compiler, matters) {
var proto = compiler.prototype;
proto.visitors = Object.assign({}, wrap$1(compile, matters), proto.visitors);
}
function wrap$1(func, matters) {
var result = {};
var length = matters.length;
var index = -1;
var tuple;
while (++index < length) {
tuple = func(matters[index]);
result[tuple[0]] = tuple[1];
}
return result
}
function isRemarkParser(parser) {
return Boolean(parser && parser.prototype && parser.prototype.blockTokenizers)
}
function isRemarkCompiler(compiler) {
return Boolean(compiler && compiler.prototype && compiler.prototype.visitors)
}
var unistBuilder = u;
function u(type, props, value) {
var node;
if (
(value === null || value === undefined) &&
(typeof props !== 'object' || Array.isArray(props))
) {
value = props;
props = {};
}
node = Object.assign({type: String(type)}, props);
if (Array.isArray(value)) {
node.children = value;
} else if (value !== null && value !== undefined) {
node.value = String(value);
}
return node
}
var start = factory$1('start');
var end = factory$1('end');
var unistUtilPosition = position;
position.start = start;
position.end = end;
function position(node) {
return {start: start(node), end: end(node)}
}
function factory$1(type) {
point.displayName = type;
return point
function point(node) {
var point = (node && node.position && node.position[type]) || {};
return {
line: point.line || null,
column: point.column || null,
offset: isNaN(point.offset) ? null : point.offset
}
}
}
var unistUtilGenerated = generated;
function generated(node) {
var position = optional(optional(node).position);
var start = optional(position.start);
var end = optional(position.end);
return !start.line || !start.column || !end.line || !end.column
}
function optional(value) {
return value && typeof value === 'object' ? value : {}
}
var mdastUtilDefinitions = getDefinitionFactory;
var own$8 = {}.hasOwnProperty;
// Get a definition in `node` by `identifier`.
function getDefinitionFactory(node, options) {
return getterFactory(gather(node, options))
}
// Gather all definitions in `node`
function gather(node, options) {
var cache = {};
if (!node || !node.type) {
throw new Error('mdast-util-definitions expected node')
}
unistUtilVisit(node, 'definition', options && options.commonmark ? commonmark : normal);
return cache
function commonmark(definition) {
var id = normalise(definition.identifier);
if (!own$8.call(cache, id)) {
cache[id] = definition;
}
}
function normal(definition) {
cache[normalise(definition.identifier)] = definition;
}
}
// Factory to get a node from the given definition-cache.
function getterFactory(cache) {
return getter
// Get a node from the bound definition-cache.
function getter(identifier) {
var id = identifier && normalise(identifier);
return id && own$8.call(cache, id) ? cache[id] : null
}
}
function normalise(identifier) {
return identifier.toUpperCase()
}
var all_1$1 = all$2;
function all$2(h, parent) {
var nodes = parent.children || [];
var length = nodes.length;
var values = [];
var index = -1;
var result;
var head;
while (++index < length) {
result = one_1$1(h, nodes[index], parent);
if (result) {
if (index && nodes[index - 1].type === 'break') {
if (result.value) {
result.value = result.value.replace(/^\s+/, '');
}
head = result.children && result.children[0];
if (head && head.value) {
head.value = head.value.replace(/^\s+/, '');
}
}
values = values.concat(result);
}
}
return values
}
var one_1$1 = one$2;
var own$7 = {}.hasOwnProperty;
// Transform an unknown node.
function unknown(h, node) {
if (text$2(node)) {
return h.augment(node, unistBuilder('text', node.value))
}
return h(node, 'div', all_1$1(h, node))
}
// Visit a node.
function one$2(h, node, parent) {
var type = node && node.type;
var fn = own$7.call(h.handlers, type) ? h.handlers[type] : h.unknownHandler;
// Fail on non-nodes.
if (!type) {
throw new Error('Expected node, got `' + node + '`')
}
return (typeof fn === 'function' ? fn : unknown)(h, node, parent)
}
// Check if the node should be renderered as a text node.
function text$2(node) {
var data = node.data || {};
if (
own$7.call(data, 'hName') ||
own$7.call(data, 'hProperties') ||
own$7.call(data, 'hChildren')
) {
return false
}
return 'value' in node
}
var thematicBreak_1 = thematicBreak;
function thematicBreak(h, node) {
return h(node, 'hr')
}
var wrap_1 = wrap;
// Wrap `nodes` with line feeds between each entry.
// Optionally adds line feeds at the start and end.
function wrap(nodes, loose) {
var result = [];
var index = -1;
var length = nodes.length;
if (loose) {
result.push(unistBuilder('text', '\n'));
}
while (++index < length) {
if (index) {
result.push(unistBuilder('text', '\n'));
}
result.push(nodes[index]);
}
if (loose && nodes.length !== 0) {
result.push(unistBuilder('text', '\n'));
}
return result
}
var list_1 = list;
function list(h, node) {
var props = {};
var name = node.ordered ? 'ol' : 'ul';
var items;
var index = -1;
var length;
if (typeof node.start === 'number' && node.start !== 1) {
props.start = node.start;
}
items = all_1$1(h, node);
length = items.length;
// Like GitHub, add a class for custom styling.
while (++index < length) {
if (
items[index].properties.className &&
items[index].properties.className.indexOf('task-list-item') !== -1
) {
props.className = ['contains-task-list'];
break
}
}
return h(node, name, props, wrap_1(items, true))
}
var footer = generateFootnotes;
function generateFootnotes(h) {
var footnoteById = h.footnoteById;
var footnoteOrder = h.footnoteOrder;
var length = footnoteOrder.length;
var index = -1;
var listItems = [];
var def;
var backReference;
var content;
var tail;
while (++index < length) {
def = footnoteById[footnoteOrder[index].toUpperCase()];
if (!def) {
continue
}
content = def.children.concat();
tail = content[content.length - 1];
backReference = {
type: 'link',
url: '#fnref-' + def.identifier,
data: {hProperties: {className: ['footnote-backref']}},
children: [{type: 'text', value: '↩'}]
};
if (!tail || tail.type !== 'paragraph') {
tail = {type: 'paragraph', children: []};
content.push(tail);
}
tail.children.push(backReference);
listItems.push({
type: 'listItem',
data: {hProperties: {id: 'fn-' + def.identifier}},
children: content,
position: def.position
});
}
if (listItems.length === 0) {
return null
}
return h(
null,
'div',
{className: ['footnotes']},
wrap_1(
[
thematicBreak_1(h),
list_1(h, {type: 'list', ordered: true, children: listItems})
],
true
)
)
}
var blockquote_1 = blockquote;
function blockquote(h, node) {
return h(node, 'blockquote', wrap_1(all_1$1(h, node), true))
}
var _break = hardBreak;
function hardBreak(h, node) {
return [h(node, 'br'), unistBuilder('text', '\n')]
}
var detab_1 = detab;
var tab$1 = 0x09;
var lineFeed$1 = 0x0a;
var carriageReturn = 0x0d;
// Replace tabs with spaces, being smart about which column the tab is at and
// which size should be used.
function detab(value, size) {
var string = typeof value === 'string';
var length = string && value.length;
var start = 0;
var index = -1;
var column = -1;
var tabSize = size || 4;
var results = [];
var code;
var add;
if (!string) {
throw new Error('detab expected string')
}
while (++index < length) {
code = value.charCodeAt(index);
if (code === tab$1) {
add = tabSize - ((column + 1) % tabSize);
column += add;
results.push(value.slice(start, index) + repeatString(' ', add));
start = index + 1;
} else if (code === lineFeed$1 || code === carriageReturn) {
column = -1;
} else {
column++;
}
}
results.push(value.slice(start));
return results.join('')
}
var code_1 = code;
function code(h, node) {
var value = node.value ? detab_1(node.value + '\n') : '';
var lang = node.lang && node.lang.match(/^[^ \t]+(?=[ \t]|$)/);
var props = {};
if (lang) {
props.className = ['language-' + lang];
}
return h(node.position, 'pre', [h(node, 'code', props, [unistBuilder('text', value)])])
}
var _delete = strikethrough;
function strikethrough(h, node) {
return h(node, 'del', all_1$1(h, node))
}
var emphasis_1 = emphasis;
function emphasis(h, node) {
return h(node, 'em', all_1$1(h, node))
}
var footnoteReference_1 = footnoteReference;
function footnoteReference(h, node) {
var footnoteOrder = h.footnoteOrder;
var identifier = String(node.identifier);
if (footnoteOrder.indexOf(identifier) === -1) {
footnoteOrder.push(identifier);
}
return h(node.position, 'sup', {id: 'fnref-' + identifier}, [
h(node, 'a', {href: '#fn-' + identifier, className: ['footnote-ref']}, [
unistBuilder('text', node.label || identifier)
])
])
}
var footnote_1 = footnote;
function footnote(h, node) {
var footnoteById = h.footnoteById;
var footnoteOrder = h.footnoteOrder;
var identifier = 1;
while (identifier in footnoteById) {
identifier++;
}
identifier = String(identifier);
// No need to check if `identifier` exists in `footnoteOrder`, its guaranteed
// to not exist because we just generated it.
footnoteOrder.push(identifier);
footnoteById[identifier] = {
type: 'footnoteDefinition',
identifier: identifier,
children: [{type: 'paragraph', children: node.children}],
position: node.position
};
return footnoteReference_1(h, {
type: 'footnoteReference',
identifier: identifier,
position: node.position
})
}
var heading_1 = heading;
function heading(h, node) {
return h(node, 'h' + node.depth, all_1$1(h, node))
}
var html_1$1 = html$3;
// Return either a `raw` node in dangerous mode, otherwise nothing.
function html$3(h, node) {
return h.dangerous ? h.augment(node, unistBuilder('raw', node.value)) : null
}
var encodeCache = {};
// Create a lookup array where anything but characters in `chars` string
// and alphanumeric chars is percent-encoded.
//
function getEncodeCache(exclude) {
var i, ch, cache = encodeCache[exclude];
if (cache) { return cache; }
cache = encodeCache[exclude] = [];
for (i = 0; i < 128; i++) {
ch = String.fromCharCode(i);
if (/^[0-9a-z]$/i.test(ch)) {
// always allow unencoded alphanumeric characters
cache.push(ch);
} else {
cache.push('%' + ('0' + i.toString(16).toUpperCase()).slice(-2));
}
}
for (i = 0; i < exclude.length; i++) {
cache[exclude.charCodeAt(i)] = exclude[i];
}
return cache;
}
// Encode unsafe characters with percent-encoding, skipping already
// encoded sequences.
//
// - string - string to encode
// - exclude - list of characters to ignore (in addition to a-zA-Z0-9)
// - keepEscaped - don't encode '%' in a correct escape sequence (default: true)
//
function encode$1(string, exclude, keepEscaped) {
var i, l, code, nextCode, cache,
result = '';
if (typeof exclude !== 'string') {
// encode(string, keepEscaped)
keepEscaped = exclude;
exclude = encode$1.defaultChars;
}
if (typeof keepEscaped === 'undefined') {
keepEscaped = true;
}
cache = getEncodeCache(exclude);
for (i = 0, l = string.length; i < l; i++) {
code = string.charCodeAt(i);
if (keepEscaped && code === 0x25 /* % */ && i + 2 < l) {
if (/^[0-9a-f]{2}$/i.test(string.slice(i + 1, i + 3))) {
result += string.slice(i, i + 3);
i += 2;
continue;
}
}
if (code < 128) {
result += cache[code];
continue;
}
if (code >= 0xD800 && code <= 0xDFFF) {
if (code >= 0xD800 && code <= 0xDBFF && i + 1 < l) {
nextCode = string.charCodeAt(i + 1);
if (nextCode >= 0xDC00 && nextCode <= 0xDFFF) {
result += encodeURIComponent(string[i] + string[i + 1]);
i++;
continue;
}
}
result += '%EF%BF%BD';
continue;
}
result += encodeURIComponent(string[i]);
}
return result;
}
encode$1.defaultChars = ";/?:@&=+$,-_.!~*'()#";
encode$1.componentChars = "-_.!~*'()";
var encode_1 = encode$1;
var revert_1 = revert;
// Return the content of a reference without definition as Markdown.
function revert(h, node) {
var subtype = node.referenceType;
var suffix = ']';
var contents;
var head;
var tail;
if (subtype === 'collapsed') {
suffix += '[]';
} else if (subtype === 'full') {
suffix += '[' + (node.label || node.identifier) + ']';
}
if (node.type === 'imageReference') {
return unistBuilder('text', '![' + node.alt + suffix)
}
contents = all_1$1(h, node);
head = contents[0];
if (head && head.type === 'text') {
head.value = '[' + head.value;
} else {
contents.unshift(unistBuilder('text', '['));
}
tail = contents[contents.length - 1];
if (tail && tail.type === 'text') {
tail.value += suffix;
} else {
contents.push(unistBuilder('text', suffix));
}
return contents
}
var imageReference_1 = imageReference;
function imageReference(h, node) {
var def = h.definition(node.identifier);
var props;
if (!def) {
return revert_1(h, node)
}
props = {src: encode_1(def.url || ''), alt: node.alt};
if (def.title !== null && def.title !== undefined) {
props.title = def.title;
}
return h(node, 'img', props)
}
var image_1 = image$1;
function image$1(h, node) {
var props = {src: encode_1(node.url), alt: node.alt};
if (node.title !== null && node.title !== undefined) {
props.title = node.title;
}
return h(node, 'img', props)
}
var inlineCode_1 = inlineCode;
function inlineCode(h, node) {
return h(node, 'code', [unistBuilder('text', collapseWhiteSpace(node.value))])
}
var linkReference_1 = linkReference;
function linkReference(h, node) {
var def = h.definition(node.identifier);
var props;
if (!def) {
return revert_1(h, node)
}
props = {href: encode_1(def.url || '')};
if (def.title !== null && def.title !== undefined) {
props.title = def.title;
}
return h(node, 'a', props, all_1$1(h, node))
}
var link_1 = link;
function link(h, node) {
var props = {href: encode_1(node.url)};
if (node.title !== null && node.title !== undefined) {
props.title = node.title;
}
return h(node, 'a', props, all_1$1(h, node))
}
var listItem_1 = listItem$1;
function listItem$1(h, node, parent) {
var children = node.children;
var head = children[0];
var raw = all_1$1(h, node);
var loose = parent ? listLoose(parent) : listItemLoose(node);
var props = {};
var result;
var container;
var index;
var length;
var child;
// Tight lists should not render `paragraph` nodes as `p` elements.
if (loose) {
result = raw;
} else {
result = [];
length = raw.length;
index = -1;
while (++index < length) {
child = raw[index];
if (child.tagName === 'p') {
result = result.concat(child.children);
} else {
result.push(child);
}
}
}
if (typeof node.checked === 'boolean') {
if (loose && (!head || head.type !== 'paragraph')) {
result.unshift(h(null, 'p', []));
}
container = loose ? result[0].children : result;
if (container.length !== 0) {
container.unshift(unistBuilder('text', ' '));
}
container.unshift(
h(null, 'input', {
type: 'checkbox',
checked: node.checked,
disabled: true
})
);
// According to github-markdown-css, this class hides bullet.
// See: <https://github.com/sindresorhus/github-markdown-css>.
props.className = ['task-list-item'];
}
if (loose && result.length !== 0) {
result = wrap_1(result, true);
}
return h(node, 'li', props, result)
}
function listLoose(node) {
var loose = node.spread;
var children = node.children;
var length = children.length;
var index = -1;
while (!loose && ++index < length) {
loose = listItemLoose(children[index]);
}
return loose
}
function listItemLoose(node) {
var spread = node.spread;
return spread === undefined || spread === null
? node.children.length > 1
: spread
}
var paragraph_1 = paragraph;
function paragraph(h, node) {
return h(node, 'p', all_1$1(h, node))
}
var root_1 = root;
function root(h, node) {
return h.augment(node, unistBuilder('root', wrap_1(all_1$1(h, node))))
}
var strong_1 = strong;
function strong(h, node) {
return h(node, 'strong', all_1$1(h, node))
}
var table_1 = table;
function table(h, node) {
var rows = node.children;
var index = rows.length;
var align = node.align;
var alignLength = align.length;
var result = [];
var pos;
var row;
var out;
var name;
var cell;
while (index--) {
row = rows[index].children;
name = index === 0 ? 'th' : 'td';
pos = alignLength;
out = [];
while (pos--) {
cell = row[pos];
out[pos] = h(cell, name, {align: align[pos]}, cell ? all_1$1(h, cell) : []);
}
result[index] = h(rows[index], 'tr', wrap_1(out, true));
}
return h(
node,
'table',
wrap_1(
[
h(result[0].position, 'thead', wrap_1([result[0]], true)),
h(
{
start: unistUtilPosition.start(result[1]),
end: unistUtilPosition.end(result[result.length - 1])
},
'tbody',
wrap_1(result.slice(1), true)
)
],
true
)
)
}
var trimLines_1 = trimLines;
var ws = /[ \t]*\n+[ \t]*/g;
var newline$1 = '\n';
function trimLines(value) {
return String(value).replace(ws, newline$1)
}
var text_1$1 = text$1;
function text$1(h, node) {
return h.augment(node, unistBuilder('text', trimLines_1(node.value)))
}
var handlers$1 = {
blockquote: blockquote_1,
break: _break,
code: code_1,
delete: _delete,
emphasis: emphasis_1,
footnoteReference: footnoteReference_1,
footnote: footnote_1,
heading: heading_1,
html: html_1$1,
imageReference: imageReference_1,
image: image_1,
inlineCode: inlineCode_1,
linkReference: linkReference_1,
link: link_1,
listItem: listItem_1,
list: list_1,
paragraph: paragraph_1,
root: root_1,
strong: strong_1,
table: table_1,
text: text_1$1,
thematicBreak: thematicBreak_1,
toml: ignore,
yaml: ignore,
definition: ignore,
footnoteDefinition: ignore
};
// Return nothing for nodes that are ignored.
function ignore() {
return null
}
var lib$2 = toHast;
var own$6 = {}.hasOwnProperty;
var deprecationWarningIssued = false;
// Factory to transform.
function factory(tree, options) {
var settings = options || {};
// Issue a warning if the deprecated tag 'allowDangerousHTML' is used
if (settings.allowDangerousHTML !== undefined && !deprecationWarningIssued) {
deprecationWarningIssued = true;
console.warn(
'mdast-util-to-hast: deprecation: `allowDangerousHTML` is nonstandard, use `allowDangerousHtml` instead'
);
}
var dangerous = settings.allowDangerousHtml || settings.allowDangerousHTML;
var footnoteById = {};
h.dangerous = dangerous;
h.definition = mdastUtilDefinitions(tree, settings);
h.footnoteById = footnoteById;
h.footnoteOrder = [];
h.augment = augment;
h.handlers = Object.assign({}, handlers$1, settings.handlers);
h.unknownHandler = settings.unknownHandler;
unistUtilVisit(tree, 'footnoteDefinition', onfootnotedefinition);
return h
// Finalise the created `right`, a hast node, from `left`, an mdast node.
function augment(left, right) {
var data;
var ctx;
// Handle `data.hName`, `data.hProperties, `data.hChildren`.
if (left && 'data' in left) {
data = left.data;
if (right.type === 'element' && data.hName) {
right.tagName = data.hName;
}
if (right.type === 'element' && data.hProperties) {
right.properties = Object.assign({}, right.properties, data.hProperties);
}
if (right.children && data.hChildren) {
right.children = data.hChildren;
}
}
ctx = left && left.position ? left : {position: left};
if (!unistUtilGenerated(ctx)) {
right.position = {
start: unistUtilPosition.start(ctx),
end: unistUtilPosition.end(ctx)
};
}
return right
}
// Create an element for `node`.
function h(node, tagName, props, children) {
if (
(children === undefined || children === null) &&
typeof props === 'object' &&
'length' in props
) {
children = props;
props = {};
}
return augment(node, {
type: 'element',
tagName: tagName,
properties: props || {},
children: children || []
})
}
function onfootnotedefinition(definition) {
var id = String(definition.identifier).toUpperCase();
// Mimick CM behavior of link definitions.
// See: <https://github.com/syntax-tree/mdast-util-definitions/blob/8d48e57/index.js#L26>.
if (!own$6.call(footnoteById, id)) {
footnoteById[id] = definition;
}
}
}
// Transform `tree`, which is an mdast node, to a hast node.
function toHast(tree, options) {
var h = factory(tree, options);
var node = one_1$1(h, tree);
var foot = footer(h);
if (foot) {
node.children = node.children.concat(unistBuilder('text', '\n'), foot);
}
return node
}
var mdastUtilToHast = lib$2;
var remarkRehype = remark2rehype;
// Attacher.
// If a destination is given, runs the destination with the new hast tree
// (bridge mode).
// Without destination, returns the tree: further plugins run on that tree
// (mutate mode).
function remark2rehype(destination, options) {
if (destination && !destination.process) {
options = destination;
destination = null;
}
return destination ? bridge(destination, options) : mutate(options)
}
// Bridge mode.
// Runs the destination with the new hast tree.
function bridge(destination, options) {
return transformer
function transformer(node, file, next) {
destination.run(mdastUtilToHast(node, options), file, done);
function done(err) {
next(err);
}
}
}
// Mutate-mode.
// Further transformers run on the hast tree.
function mutate(options) {
return transformer
function transformer(node) {
return mdastUtilToHast(node, options)
}
}
var schema$1 = Schema$2;
var proto$2 = Schema$2.prototype;
proto$2.space = null;
proto$2.normal = {};
proto$2.property = {};
function Schema$2(property, normal, space) {
this.property = property;
this.normal = normal;
if (space) {
this.space = space;
}
}
var merge_1 = merge$1;
function merge$1(definitions) {
var length = definitions.length;
var property = [];
var normal = [];
var index = -1;
var info;
var space;
while (++index < length) {
info = definitions[index];
property.push(info.property);
normal.push(info.normal);
space = info.space;
}
return new schema$1(
immutable.apply(null, property),
immutable.apply(null, normal),
space
)
}
var normalize_1 = normalize;
function normalize(value) {
return value.toLowerCase()
}
var info = Info;
var proto$1 = Info.prototype;
proto$1.space = null;
proto$1.attribute = null;
proto$1.property = null;
proto$1.boolean = false;
proto$1.booleanish = false;
proto$1.overloadedBoolean = false;
proto$1.number = false;
proto$1.commaSeparated = false;
proto$1.spaceSeparated = false;
proto$1.commaOrSpaceSeparated = false;
proto$1.mustUseProperty = false;
proto$1.defined = false;
function Info(property, attribute) {
this.property = property;
this.attribute = attribute;
}
var powers = 0;
var boolean_1 = increment();
var booleanish$2 = increment();
var overloadedBoolean$1 = increment();
var number$3 = increment();
var spaceSeparated$3 = increment();
var commaSeparated$2 = increment();
var commaOrSpaceSeparated$1 = increment();
function increment() {
return Math.pow(2, ++powers)
}
var types = {
boolean: boolean_1,
booleanish: booleanish$2,
overloadedBoolean: overloadedBoolean$1,
number: number$3,
spaceSeparated: spaceSeparated$3,
commaSeparated: commaSeparated$2,
commaOrSpaceSeparated: commaOrSpaceSeparated$1
};
var definedInfo = DefinedInfo;
DefinedInfo.prototype = new info();
DefinedInfo.prototype.defined = true;
var checks = [
'boolean',
'booleanish',
'overloadedBoolean',
'number',
'commaSeparated',
'spaceSeparated',
'commaOrSpaceSeparated'
];
var checksLength = checks.length;
function DefinedInfo(property, attribute, mask, space) {
var index = -1;
var check;
mark$1(this, 'space', space);
info.call(this, property, attribute);
while (++index < checksLength) {
check = checks[index];
mark$1(this, check, (mask & types[check]) === types[check]);
}
}
function mark$1(values, key, value) {
if (value) {
values[key] = value;
}
}
var create_1 = create;
function create(definition) {
var space = definition.space;
var mustUseProperty = definition.mustUseProperty || [];
var attributes = definition.attributes || {};
var props = definition.properties;
var transform = definition.transform;
var property = {};
var normal = {};
var prop;
var info;
for (prop in props) {
info = new definedInfo(
prop,
transform(attributes, prop),
props[prop],
space
);
if (mustUseProperty.indexOf(prop) !== -1) {
info.mustUseProperty = true;
}
property[prop] = info;
normal[normalize_1(prop)] = prop;
normal[normalize_1(info.attribute)] = prop;
}
return new schema$1(property, normal, space)
}
var xlink = create_1({
space: 'xlink',
transform: xlinkTransform,
properties: {
xLinkActuate: null,
xLinkArcRole: null,
xLinkHref: null,
xLinkRole: null,
xLinkShow: null,
xLinkTitle: null,
xLinkType: null
}
});
function xlinkTransform(_, prop) {
return 'xlink:' + prop.slice(5).toLowerCase()
}
var xml = create_1({
space: 'xml',
transform: xmlTransform,
properties: {
xmlLang: null,
xmlBase: null,
xmlSpace: null
}
});
function xmlTransform(_, prop) {
return 'xml:' + prop.slice(3).toLowerCase()
}
var caseSensitiveTransform_1 = caseSensitiveTransform;
function caseSensitiveTransform(attributes, attribute) {
return attribute in attributes ? attributes[attribute] : attribute
}
var caseInsensitiveTransform_1 = caseInsensitiveTransform;
function caseInsensitiveTransform(attributes, property) {
return caseSensitiveTransform_1(attributes, property.toLowerCase())
}
var xmlns = create_1({
space: 'xmlns',
attributes: {
xmlnsxlink: 'xmlns:xlink'
},
transform: caseInsensitiveTransform_1,
properties: {
xmlns: null,
xmlnsXLink: null
}
});
var booleanish$1 = types.booleanish;
var number$2 = types.number;
var spaceSeparated$2 = types.spaceSeparated;
var aria = create_1({
transform: ariaTransform,
properties: {
ariaActiveDescendant: null,
ariaAtomic: booleanish$1,
ariaAutoComplete: null,
ariaBusy: booleanish$1,
ariaChecked: booleanish$1,
ariaColCount: number$2,
ariaColIndex: number$2,
ariaColSpan: number$2,
ariaControls: spaceSeparated$2,
ariaCurrent: null,
ariaDescribedBy: spaceSeparated$2,
ariaDetails: null,
ariaDisabled: booleanish$1,
ariaDropEffect: spaceSeparated$2,
ariaErrorMessage: null,
ariaExpanded: booleanish$1,
ariaFlowTo: spaceSeparated$2,
ariaGrabbed: booleanish$1,
ariaHasPopup: null,
ariaHidden: booleanish$1,
ariaInvalid: null,
ariaKeyShortcuts: null,
ariaLabel: null,
ariaLabelledBy: spaceSeparated$2,
ariaLevel: number$2,
ariaLive: null,
ariaModal: booleanish$1,
ariaMultiLine: booleanish$1,
ariaMultiSelectable: booleanish$1,
ariaOrientation: null,
ariaOwns: spaceSeparated$2,
ariaPlaceholder: null,
ariaPosInSet: number$2,
ariaPressed: booleanish$1,
ariaReadOnly: booleanish$1,
ariaRelevant: null,
ariaRequired: booleanish$1,
ariaRoleDescription: spaceSeparated$2,
ariaRowCount: number$2,
ariaRowIndex: number$2,
ariaRowSpan: number$2,
ariaSelected: booleanish$1,
ariaSetSize: number$2,
ariaSort: null,
ariaValueMax: number$2,
ariaValueMin: number$2,
ariaValueNow: number$2,
ariaValueText: null,
role: null
}
});
function ariaTransform(_, prop) {
return prop === 'role' ? prop : 'aria-' + prop.slice(4).toLowerCase()
}
var boolean$1 = types.boolean;
var overloadedBoolean = types.overloadedBoolean;
var booleanish = types.booleanish;
var number$1 = types.number;
var spaceSeparated$1 = types.spaceSeparated;
var commaSeparated$1 = types.commaSeparated;
var html$2 = create_1({
space: 'html',
attributes: {
acceptcharset: 'accept-charset',
classname: 'class',
htmlfor: 'for',
httpequiv: 'http-equiv'
},
transform: caseInsensitiveTransform_1,
mustUseProperty: ['checked', 'multiple', 'muted', 'selected'],
properties: {
// Standard Properties.
abbr: null,
accept: commaSeparated$1,
acceptCharset: spaceSeparated$1,
accessKey: spaceSeparated$1,
action: null,
allow: null,
allowFullScreen: boolean$1,
allowPaymentRequest: boolean$1,
allowUserMedia: boolean$1,
alt: null,
as: null,
async: boolean$1,
autoCapitalize: null,
autoComplete: spaceSeparated$1,
autoFocus: boolean$1,
autoPlay: boolean$1,
capture: boolean$1,
charSet: null,
checked: boolean$1,
cite: null,
className: spaceSeparated$1,
cols: number$1,
colSpan: null,
content: null,
contentEditable: booleanish,
controls: boolean$1,
controlsList: spaceSeparated$1,
coords: number$1 | commaSeparated$1,
crossOrigin: null,
data: null,
dateTime: null,
decoding: null,
default: boolean$1,
defer: boolean$1,
dir: null,
dirName: null,
disabled: boolean$1,
download: overloadedBoolean,
draggable: booleanish,
encType: null,
enterKeyHint: null,
form: null,
formAction: null,
formEncType: null,
formMethod: null,
formNoValidate: boolean$1,
formTarget: null,
headers: spaceSeparated$1,
height: number$1,
hidden: boolean$1,
high: number$1,
href: null,
hrefLang: null,
htmlFor: spaceSeparated$1,
httpEquiv: spaceSeparated$1,
id: null,
imageSizes: null,
imageSrcSet: commaSeparated$1,
inputMode: null,
integrity: null,
is: null,
isMap: boolean$1,
itemId: null,
itemProp: spaceSeparated$1,
itemRef: spaceSeparated$1,
itemScope: boolean$1,
itemType: spaceSeparated$1,
kind: null,
label: null,
lang: null,
language: null,
list: null,
loop: boolean$1,
low: number$1,
manifest: null,
max: null,
maxLength: number$1,
media: null,
method: null,
min: null,
minLength: number$1,
multiple: boolean$1,
muted: boolean$1,
name: null,
nonce: null,
noModule: boolean$1,
noValidate: boolean$1,
onAbort: null,
onAfterPrint: null,
onAuxClick: null,
onBeforePrint: null,
onBeforeUnload: null,
onBlur: null,
onCancel: null,
onCanPlay: null,
onCanPlayThrough: null,
onChange: null,
onClick: null,
onClose: null,
onContextMenu: null,
onCopy: null,
onCueChange: null,
onCut: null,
onDblClick: null,
onDrag: null,
onDragEnd: null,
onDragEnter: null,
onDragExit: null,
onDragLeave: null,
onDragOver: null,
onDragStart: null,
onDrop: null,
onDurationChange: null,
onEmptied: null,
onEnded: null,
onError: null,
onFocus: null,
onFormData: null,
onHashChange: null,
onInput: null,
onInvalid: null,
onKeyDown: null,
onKeyPress: null,
onKeyUp: null,
onLanguageChange: null,
onLoad: null,
onLoadedData: null,
onLoadedMetadata: null,
onLoadEnd: null,
onLoadStart: null,
onMessage: null,
onMessageError: null,
onMouseDown: null,
onMouseEnter: null,
onMouseLeave: null,
onMouseMove: null,
onMouseOut: null,
onMouseOver: null,
onMouseUp: null,
onOffline: null,
onOnline: null,
onPageHide: null,
onPageShow: null,
onPaste: null,
onPause: null,
onPlay: null,
onPlaying: null,
onPopState: null,
onProgress: null,
onRateChange: null,
onRejectionHandled: null,
onReset: null,
onResize: null,
onScroll: null,
onSecurityPolicyViolation: null,
onSeeked: null,
onSeeking: null,
onSelect: null,
onSlotChange: null,
onStalled: null,
onStorage: null,
onSubmit: null,
onSuspend: null,
onTimeUpdate: null,
onToggle: null,
onUnhandledRejection: null,
onUnload: null,
onVolumeChange: null,
onWaiting: null,
onWheel: null,
open: boolean$1,
optimum: number$1,
pattern: null,
ping: spaceSeparated$1,
placeholder: null,
playsInline: boolean$1,
poster: null,
preload: null,
readOnly: boolean$1,
referrerPolicy: null,
rel: spaceSeparated$1,
required: boolean$1,
reversed: boolean$1,
rows: number$1,
rowSpan: number$1,
sandbox: spaceSeparated$1,
scope: null,
scoped: boolean$1,
seamless: boolean$1,
selected: boolean$1,
shape: null,
size: number$1,
sizes: null,
slot: null,
span: number$1,
spellCheck: booleanish,
src: null,
srcDoc: null,
srcLang: null,
srcSet: commaSeparated$1,
start: number$1,
step: null,
style: null,
tabIndex: number$1,
target: null,
title: null,
translate: null,
type: null,
typeMustMatch: boolean$1,
useMap: null,
value: booleanish,
width: number$1,
wrap: null,
// Legacy.
// See: https://html.spec.whatwg.org/#other-elements,-attributes-and-apis
align: null, // Several. Use CSS `text-align` instead,
aLink: null, // `<body>`. Use CSS `a:active {color}` instead
archive: spaceSeparated$1, // `<object>`. List of URIs to archives
axis: null, // `<td>` and `<th>`. Use `scope` on `<th>`
background: null, // `<body>`. Use CSS `background-image` instead
bgColor: null, // `<body>` and table elements. Use CSS `background-color` instead
border: number$1, // `<table>`. Use CSS `border-width` instead,
borderColor: null, // `<table>`. Use CSS `border-color` instead,
bottomMargin: number$1, // `<body>`
cellPadding: null, // `<table>`
cellSpacing: null, // `<table>`
char: null, // Several table elements. When `align=char`, sets the character to align on
charOff: null, // Several table elements. When `char`, offsets the alignment
classId: null, // `<object>`
clear: null, // `<br>`. Use CSS `clear` instead
code: null, // `<object>`
codeBase: null, // `<object>`
codeType: null, // `<object>`
color: null, // `<font>` and `<hr>`. Use CSS instead
compact: boolean$1, // Lists. Use CSS to reduce space between items instead
declare: boolean$1, // `<object>`
event: null, // `<script>`
face: null, // `<font>`. Use CSS instead
frame: null, // `<table>`
frameBorder: null, // `<iframe>`. Use CSS `border` instead
hSpace: number$1, // `<img>` and `<object>`
leftMargin: number$1, // `<body>`
link: null, // `<body>`. Use CSS `a:link {color: *}` instead
longDesc: null, // `<frame>`, `<iframe>`, and `<img>`. Use an `<a>`
lowSrc: null, // `<img>`. Use a `<picture>`
marginHeight: number$1, // `<body>`
marginWidth: number$1, // `<body>`
noResize: boolean$1, // `<frame>`
noHref: boolean$1, // `<area>`. Use no href instead of an explicit `nohref`
noShade: boolean$1, // `<hr>`. Use background-color and height instead of borders
noWrap: boolean$1, // `<td>` and `<th>`
object: null, // `<applet>`
profile: null, // `<head>`
prompt: null, // `<isindex>`
rev: null, // `<link>`
rightMargin: number$1, // `<body>`
rules: null, // `<table>`
scheme: null, // `<meta>`
scrolling: booleanish, // `<frame>`. Use overflow in the child context
standby: null, // `<object>`
summary: null, // `<table>`
text: null, // `<body>`. Use CSS `color` instead
topMargin: number$1, // `<body>`
valueType: null, // `<param>`
version: null, // `<html>`. Use a doctype.
vAlign: null, // Several. Use CSS `vertical-align` instead
vLink: null, // `<body>`. Use CSS `a:visited {color}` instead
vSpace: number$1, // `<img>` and `<object>`
// Non-standard Properties.
allowTransparency: null,
autoCorrect: null,
autoSave: null,
disablePictureInPicture: boolean$1,
disableRemotePlayback: boolean$1,
prefix: null,
property: null,
results: number$1,
security: null,
unselectable: null
}
});
var html_1 = merge_1([xml, xlink, xmlns, aria, html$2]);
var boolean = types.boolean;
var number = types.number;
var spaceSeparated = types.spaceSeparated;
var commaSeparated = types.commaSeparated;
var commaOrSpaceSeparated = types.commaOrSpaceSeparated;
var svg = create_1({
space: 'svg',
attributes: {
accentHeight: 'accent-height',
alignmentBaseline: 'alignment-baseline',
arabicForm: 'arabic-form',
baselineShift: 'baseline-shift',
capHeight: 'cap-height',
className: 'class',
clipPath: 'clip-path',
clipRule: 'clip-rule',
colorInterpolation: 'color-interpolation',
colorInterpolationFilters: 'color-interpolation-filters',
colorProfile: 'color-profile',
colorRendering: 'color-rendering',
crossOrigin: 'crossorigin',
dataType: 'datatype',
dominantBaseline: 'dominant-baseline',
enableBackground: 'enable-background',
fillOpacity: 'fill-opacity',
fillRule: 'fill-rule',
floodColor: 'flood-color',
floodOpacity: 'flood-opacity',
fontFamily: 'font-family',
fontSize: 'font-size',
fontSizeAdjust: 'font-size-adjust',
fontStretch: 'font-stretch',
fontStyle: 'font-style',
fontVariant: 'font-variant',
fontWeight: 'font-weight',
glyphName: 'glyph-name',
glyphOrientationHorizontal: 'glyph-orientation-horizontal',
glyphOrientationVertical: 'glyph-orientation-vertical',
hrefLang: 'hreflang',
horizAdvX: 'horiz-adv-x',
horizOriginX: 'horiz-origin-x',
horizOriginY: 'horiz-origin-y',
imageRendering: 'image-rendering',
letterSpacing: 'letter-spacing',
lightingColor: 'lighting-color',
markerEnd: 'marker-end',
markerMid: 'marker-mid',
markerStart: 'marker-start',
navDown: 'nav-down',
navDownLeft: 'nav-down-left',
navDownRight: 'nav-down-right',
navLeft: 'nav-left',
navNext: 'nav-next',
navPrev: 'nav-prev',
navRight: 'nav-right',
navUp: 'nav-up',
navUpLeft: 'nav-up-left',
navUpRight: 'nav-up-right',
onAbort: 'onabort',
onActivate: 'onactivate',
onAfterPrint: 'onafterprint',
onBeforePrint: 'onbeforeprint',
onBegin: 'onbegin',
onCancel: 'oncancel',
onCanPlay: 'oncanplay',
onCanPlayThrough: 'oncanplaythrough',
onChange: 'onchange',
onClick: 'onclick',
onClose: 'onclose',
onCopy: 'oncopy',
onCueChange: 'oncuechange',
onCut: 'oncut',
onDblClick: 'ondblclick',
onDrag: 'ondrag',
onDragEnd: 'ondragend',
onDragEnter: 'ondragenter',
onDragExit: 'ondragexit',
onDragLeave: 'ondragleave',
onDragOver: 'ondragover',
onDragStart: 'ondragstart',
onDrop: 'ondrop',
onDurationChange: 'ondurationchange',
onEmptied: 'onemptied',
onEnd: 'onend',
onEnded: 'onended',
onError: 'onerror',
onFocus: 'onfocus',
onFocusIn: 'onfocusin',
onFocusOut: 'onfocusout',
onHashChange: 'onhashchange',
onInput: 'oninput',
onInvalid: 'oninvalid',
onKeyDown: 'onkeydown',
onKeyPress: 'onkeypress',
onKeyUp: 'onkeyup',
onLoad: 'onload',
onLoadedData: 'onloadeddata',
onLoadedMetadata: 'onloadedmetadata',
onLoadStart: 'onloadstart',
onMessage: 'onmessage',
onMouseDown: 'onmousedown',
onMouseEnter: 'onmouseenter',
onMouseLeave: 'onmouseleave',
onMouseMove: 'onmousemove',
onMouseOut: 'onmouseout',
onMouseOver: 'onmouseover',
onMouseUp: 'onmouseup',
onMouseWheel: 'onmousewheel',
onOffline: 'onoffline',
onOnline: 'ononline',
onPageHide: 'onpagehide',
onPageShow: 'onpageshow',
onPaste: 'onpaste',
onPause: 'onpause',
onPlay: 'onplay',
onPlaying: 'onplaying',
onPopState: 'onpopstate',
onProgress: 'onprogress',
onRateChange: 'onratechange',
onRepeat: 'onrepeat',
onReset: 'onreset',
onResize: 'onresize',
onScroll: 'onscroll',
onSeeked: 'onseeked',
onSeeking: 'onseeking',
onSelect: 'onselect',
onShow: 'onshow',
onStalled: 'onstalled',
onStorage: 'onstorage',
onSubmit: 'onsubmit',
onSuspend: 'onsuspend',
onTimeUpdate: 'ontimeupdate',
onToggle: 'ontoggle',
onUnload: 'onunload',
onVolumeChange: 'onvolumechange',
onWaiting: 'onwaiting',
onZoom: 'onzoom',
overlinePosition: 'overline-position',
overlineThickness: 'overline-thickness',
paintOrder: 'paint-order',
panose1: 'panose-1',
pointerEvents: 'pointer-events',
referrerPolicy: 'referrerpolicy',
renderingIntent: 'rendering-intent',
shapeRendering: 'shape-rendering',
stopColor: 'stop-color',
stopOpacity: 'stop-opacity',
strikethroughPosition: 'strikethrough-position',
strikethroughThickness: 'strikethrough-thickness',
strokeDashArray: 'stroke-dasharray',
strokeDashOffset: 'stroke-dashoffset',
strokeLineCap: 'stroke-linecap',
strokeLineJoin: 'stroke-linejoin',
strokeMiterLimit: 'stroke-miterlimit',
strokeOpacity: 'stroke-opacity',
strokeWidth: 'stroke-width',
tabIndex: 'tabindex',
textAnchor: 'text-anchor',
textDecoration: 'text-decoration',
textRendering: 'text-rendering',
typeOf: 'typeof',
underlinePosition: 'underline-position',
underlineThickness: 'underline-thickness',
unicodeBidi: 'unicode-bidi',
unicodeRange: 'unicode-range',
unitsPerEm: 'units-per-em',
vAlphabetic: 'v-alphabetic',
vHanging: 'v-hanging',
vIdeographic: 'v-ideographic',
vMathematical: 'v-mathematical',
vectorEffect: 'vector-effect',
vertAdvY: 'vert-adv-y',
vertOriginX: 'vert-origin-x',
vertOriginY: 'vert-origin-y',
wordSpacing: 'word-spacing',
writingMode: 'writing-mode',
xHeight: 'x-height',
// These were camelcased in Tiny. Now lowercased in SVG 2
playbackOrder: 'playbackorder',
timelineBegin: 'timelinebegin'
},
transform: caseSensitiveTransform_1,
properties: {
about: commaOrSpaceSeparated,
accentHeight: number,
accumulate: null,
additive: null,
alignmentBaseline: null,
alphabetic: number,
amplitude: number,
arabicForm: null,
ascent: number,
attributeName: null,
attributeType: null,
azimuth: number,
bandwidth: null,
baselineShift: null,
baseFrequency: null,
baseProfile: null,
bbox: null,
begin: null,
bias: number,
by: null,
calcMode: null,
capHeight: number,
className: spaceSeparated,
clip: null,
clipPath: null,
clipPathUnits: null,
clipRule: null,
color: null,
colorInterpolation: null,
colorInterpolationFilters: null,
colorProfile: null,
colorRendering: null,
content: null,
contentScriptType: null,
contentStyleType: null,
crossOrigin: null,
cursor: null,
cx: null,
cy: null,
d: null,
dataType: null,
defaultAction: null,
descent: number,
diffuseConstant: number,
direction: null,
display: null,
dur: null,
divisor: number,
dominantBaseline: null,
download: boolean,
dx: null,
dy: null,
edgeMode: null,
editable: null,
elevation: number,
enableBackground: null,
end: null,
event: null,
exponent: number,
externalResourcesRequired: null,
fill: null,
fillOpacity: number,
fillRule: null,
filter: null,
filterRes: null,
filterUnits: null,
floodColor: null,
floodOpacity: null,
focusable: null,
focusHighlight: null,
fontFamily: null,
fontSize: null,
fontSizeAdjust: null,
fontStretch: null,
fontStyle: null,
fontVariant: null,
fontWeight: null,
format: null,
fr: null,
from: null,
fx: null,
fy: null,
g1: commaSeparated,
g2: commaSeparated,
glyphName: commaSeparated,
glyphOrientationHorizontal: null,
glyphOrientationVertical: null,
glyphRef: null,
gradientTransform: null,
gradientUnits: null,
handler: null,
hanging: number,
hatchContentUnits: null,
hatchUnits: null,
height: null,
href: null,
hrefLang: null,
horizAdvX: number,
horizOriginX: number,
horizOriginY: number,
id: null,
ideographic: number,
imageRendering: null,
initialVisibility: null,
in: null,
in2: null,
intercept: number,
k: number,
k1: number,
k2: number,
k3: number,
k4: number,
kernelMatrix: commaOrSpaceSeparated,
kernelUnitLength: null,
keyPoints: null, // SEMI_COLON_SEPARATED
keySplines: null, // SEMI_COLON_SEPARATED
keyTimes: null, // SEMI_COLON_SEPARATED
kerning: null,
lang: null,
lengthAdjust: null,
letterSpacing: null,
lightingColor: null,
limitingConeAngle: number,
local: null,
markerEnd: null,
markerMid: null,
markerStart: null,
markerHeight: null,
markerUnits: null,
markerWidth: null,
mask: null,
maskContentUnits: null,
maskUnits: null,
mathematical: null,
max: null,
media: null,
mediaCharacterEncoding: null,
mediaContentEncodings: null,
mediaSize: number,
mediaTime: null,
method: null,
min: null,
mode: null,
name: null,
navDown: null,
navDownLeft: null,
navDownRight: null,
navLeft: null,
navNext: null,
navPrev: null,
navRight: null,
navUp: null,
navUpLeft: null,
navUpRight: null,
numOctaves: null,
observer: null,
offset: null,
onAbort: null,
onActivate: null,
onAfterPrint: null,
onBeforePrint: null,
onBegin: null,
onCancel: null,
onCanPlay: null,
onCanPlayThrough: null,
onChange: null,
onClick: null,
onClose: null,
onCopy: null,
onCueChange: null,
onCut: null,
onDblClick: null,
onDrag: null,
onDragEnd: null,
onDragEnter: null,
onDragExit: null,
onDragLeave: null,
onDragOver: null,
onDragStart: null,
onDrop: null,
onDurationChange: null,
onEmptied: null,
onEnd: null,
onEnded: null,
onError: null,
onFocus: null,
onFocusIn: null,
onFocusOut: null,
onHashChange: null,
onInput: null,
onInvalid: null,
onKeyDown: null,
onKeyPress: null,
onKeyUp: null,
onLoad: null,
onLoadedData: null,
onLoadedMetadata: null,
onLoadStart: null,
onMessage: null,
onMouseDown: null,
onMouseEnter: null,
onMouseLeave: null,
onMouseMove: null,
onMouseOut: null,
onMouseOver: null,
onMouseUp: null,
onMouseWheel: null,
onOffline: null,
onOnline: null,
onPageHide: null,
onPageShow: null,
onPaste: null,
onPause: null,
onPlay: null,
onPlaying: null,
onPopState: null,
onProgress: null,
onRateChange: null,
onRepeat: null,
onReset: null,
onResize: null,
onScroll: null,
onSeeked: null,
onSeeking: null,
onSelect: null,
onShow: null,
onStalled: null,
onStorage: null,
onSubmit: null,
onSuspend: null,
onTimeUpdate: null,
onToggle: null,
onUnload: null,
onVolumeChange: null,
onWaiting: null,
onZoom: null,
opacity: null,
operator: null,
order: null,
orient: null,
orientation: null,
origin: null,
overflow: null,
overlay: null,
overlinePosition: number,
overlineThickness: number,
paintOrder: null,
panose1: null,
path: null,
pathLength: number,
patternContentUnits: null,
patternTransform: null,
patternUnits: null,
phase: null,
ping: spaceSeparated,
pitch: null,
playbackOrder: null,
pointerEvents: null,
points: null,
pointsAtX: number,
pointsAtY: number,
pointsAtZ: number,
preserveAlpha: null,
preserveAspectRatio: null,
primitiveUnits: null,
propagate: null,
property: commaOrSpaceSeparated,
r: null,
radius: null,
referrerPolicy: null,
refX: null,
refY: null,
rel: commaOrSpaceSeparated,
rev: commaOrSpaceSeparated,
renderingIntent: null,
repeatCount: null,
repeatDur: null,
requiredExtensions: commaOrSpaceSeparated,
requiredFeatures: commaOrSpaceSeparated,
requiredFonts: commaOrSpaceSeparated,
requiredFormats: commaOrSpaceSeparated,
resource: null,
restart: null,
result: null,
rotate: null,
rx: null,
ry: null,
scale: null,
seed: null,
shapeRendering: null,
side: null,
slope: null,
snapshotTime: null,
specularConstant: number,
specularExponent: number,
spreadMethod: null,
spacing: null,
startOffset: null,
stdDeviation: null,
stemh: null,
stemv: null,
stitchTiles: null,
stopColor: null,
stopOpacity: null,
strikethroughPosition: number,
strikethroughThickness: number,
string: null,
stroke: null,
strokeDashArray: commaOrSpaceSeparated,
strokeDashOffset: null,
strokeLineCap: null,
strokeLineJoin: null,
strokeMiterLimit: number,
strokeOpacity: number,
strokeWidth: null,
style: null,
surfaceScale: number,
syncBehavior: null,
syncBehaviorDefault: null,
syncMaster: null,
syncTolerance: null,
syncToleranceDefault: null,
systemLanguage: commaOrSpaceSeparated,
tabIndex: number,
tableValues: null,
target: null,
targetX: number,
targetY: number,
textAnchor: null,
textDecoration: null,
textRendering: null,
textLength: null,
timelineBegin: null,
title: null,
transformBehavior: null,
type: null,
typeOf: commaOrSpaceSeparated,
to: null,
transform: null,
u1: null,
u2: null,
underlinePosition: number,
underlineThickness: number,
unicode: null,
unicodeBidi: null,
unicodeRange: null,
unitsPerEm: number,
values: null,
vAlphabetic: number,
vMathematical: number,
vectorEffect: null,
vHanging: number,
vIdeographic: number,
version: null,
vertAdvY: number,
vertOriginX: number,
vertOriginY: number,
viewBox: null,
viewTarget: null,
visibility: null,
width: null,
widths: null,
wordSpacing: null,
writingMode: null,
x: null,
x1: null,
x2: null,
xChannelSelector: null,
xHeight: number,
y: null,
y1: null,
y2: null,
yChannelSelector: null,
z: null,
zoomAndPan: null
}
});
var svg_1 = merge_1([xml, xlink, xmlns, aria, svg]);
var index$2 = [
"area",
"base",
"basefont",
"bgsound",
"br",
"col",
"command",
"embed",
"frame",
"hr",
"image",
"img",
"input",
"isindex",
"keygen",
"link",
"menuitem",
"meta",
"nextid",
"param",
"source",
"track",
"wbr"
];
var htmlVoidElements = /*#__PURE__*/Object.freeze({
__proto__: null,
'default': index$2
});
var unistUtilIs = is;
// Assert if `test` passes for `node`. When a `parent` node is known the
// `index` of node.
// eslint-disable-next-line max-params
function is(test, node, index, parent, context) {
var hasParent = parent !== null && parent !== undefined;
var hasIndex = index !== null && index !== undefined;
var check = convert(test);
if (
hasIndex &&
(typeof index !== 'number' || index < 0 || index === Infinity)
) {
throw new Error('Expected positive finite index or child node')
}
if (hasParent && (!is(null, parent) || !parent.children)) {
throw new Error('Expected parent node')
}
if (!node || !node.type || typeof node.type !== 'string') {
return false
}
if (hasParent !== hasIndex) {
throw new Error('Expected both parent and index')
}
return Boolean(check.call(context, node, index, parent))
}
function convert(test) {
if (typeof test === 'string') {
return typeFactory(test)
}
if (test === null || test === undefined) {
return ok
}
if (typeof test === 'object') {
return ('length' in test ? anyFactory : matchesFactory)(test)
}
if (typeof test === 'function') {
return test
}
throw new Error('Expected function, string, or object as test')
}
function convertAll(tests) {
var results = [];
var length = tests.length;
var index = -1;
while (++index < length) {
results[index] = convert(tests[index]);
}
return results
}
// Utility assert each property in `test` is represented in `node`, and each
// values are strictly equal.
function matchesFactory(test) {
return matches
function matches(node) {
var key;
for (key in test) {
if (node[key] !== test[key]) {
return false
}
}
return true
}
}
function anyFactory(tests) {
var checks = convertAll(tests);
var length = checks.length;
return matches
function matches() {
var index = -1;
while (++index < length) {
if (checks[index].apply(this, arguments)) {
return true
}
}
return false
}
}
// Utility to convert a string into a function which checks a given nodes type
// for said string.
function typeFactory(test) {
return type
function type(node) {
return Boolean(node && node.type === test)
}
}
// Utility to return true.
function ok() {
return true
}
var hastUtilIsElement = isElement;
// Check if if `node` is an `element` and, if `tagNames` is given, `node`
// matches them `tagNames`.
function isElement(node, tagNames) {
var name;
if (
!(
tagNames === null ||
tagNames === undefined ||
typeof tagNames === 'string' ||
(typeof tagNames === 'object' && tagNames.length !== 0)
)
) {
throw new Error(
'Expected `string` or `Array.<string>` for `tagNames`, not `' +
tagNames +
'`'
)
}
if (
!node ||
typeof node !== 'object' ||
node.type !== 'element' ||
typeof node.tagName !== 'string'
) {
return false
}
if (tagNames === null || tagNames === undefined) {
return true
}
name = node.tagName;
if (typeof tagNames === 'string') {
return name === tagNames
}
return tagNames.indexOf(name) !== -1
}
var hastUtilWhitespace = interElementWhiteSpace;
// HTML white-space expression.
// See <https://html.spec.whatwg.org/#space-character>.
var re = /[ \t\n\f\r]/g;
function interElementWhiteSpace(node) {
var value;
if (node && typeof node === 'object' && node.type === 'text') {
value = node.value || '';
} else if (typeof node === 'string') {
value = node;
} else {
return false
}
return value.replace(re, '') === ''
}
var before$1 = siblings(-1);
var after$2 = siblings(1);
/* Factory to check siblings in a direction. */
function siblings(increment) {
return sibling
/* Find applicable siblings in a direction. */
function sibling(parent, index, includeWhiteSpace) {
var siblings = parent && parent.children;
var next;
index += increment;
next = siblings && siblings[index];
if (!includeWhiteSpace) {
while (next && hastUtilWhitespace(next)) {
index += increment;
next = siblings[index];
}
}
return next
}
}
var siblings_1 = {
before: before$1,
after: after$2
};
var after$1 = siblings_1.after;
var first_1 = first;
/* Get the first child in `parent`. */
function first(parent, includeWhiteSpace) {
return after$1(parent, -1, includeWhiteSpace)
}
var place_1 = place;
/* Get the position of `node` in `parent`. */
function place(parent, child) {
return parent && parent.children && parent.children.indexOf(child)
}
var whiteSpaceLeft_1 = whiteSpaceLeft;
/* Check if `node` starts with white-space. */
function whiteSpaceLeft(node) {
return unistUtilIs('text', node) && hastUtilWhitespace(node.value.charAt(0))
}
var omission_1 = omission$1;
var own$5 = {}.hasOwnProperty;
/* Factory to check if a given node can have a tag omitted. */
function omission$1(handlers) {
return omit
/* Check if a given node can have a tag omitted. */
function omit(node, index, parent) {
var name = node.tagName;
var fn = own$5.call(handlers, name) ? handlers[name] : false;
return fn ? fn(node, index, parent) : false
}
}
var after = siblings_1.after;
var optionGroup = 'optgroup';
var options = ['option'].concat(optionGroup);
var dataListItem = ['dt', 'dd'];
var listItem = 'li';
var menuContent = ['menuitem', 'hr', 'menu'];
var ruby = ['rp', 'rt'];
var tableContainer = ['tbody', 'tfoot'];
var tableRow$1 = 'tr';
var tableCell = ['td', 'th'];
var confusingParagraphParent = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];
var clearParagraphSibling = [
'address',
'article',
'aside',
'blockquote',
'details',
'div',
'dl',
'fieldset',
'figcaption',
'figure',
'footer',
'form',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'header',
'hgroup',
'hr',
'main',
'menu',
'nav',
'ol',
'p',
'pre',
'section',
'table',
'ul'
];
var closing$1 = omission_1({
html: html$1,
head: headOrColgroupOrCaption,
body: body$1,
p: p,
li: li,
dt: dt,
dd: dd,
rt: rubyElement,
rp: rubyElement,
optgroup: optgroup,
option: option,
menuitem: menuitem,
colgroup: headOrColgroupOrCaption,
caption: headOrColgroupOrCaption,
thead: thead,
tbody: tbody$1,
tfoot: tfoot,
tr: tr,
td: cells,
th: cells
});
/* Macro for `</head>`, `</colgroup>`, and `</caption>`. */
function headOrColgroupOrCaption(node, index, parent) {
var next = after(parent, index, true);
return !next || (!unistUtilIs('comment', next) && !whiteSpaceLeft_1(next))
}
/* Whether to omit `</html>`. */
function html$1(node, index, parent) {
var next = after(parent, index);
return !next || !unistUtilIs('comment', next)
}
/* Whether to omit `</body>`. */
function body$1(node, index, parent) {
var next = after(parent, index);
return !next || !unistUtilIs('comment', next)
}
/* Whether to omit `</p>`. */
function p(node, index, parent) {
var next = after(parent, index);
return next ? hastUtilIsElement(next, clearParagraphSibling) : !parent || !hastUtilIsElement(parent, confusingParagraphParent)
}
/* Whether to omit `</li>`. */
function li(node, index, parent) {
var next = after(parent, index);
return !next || hastUtilIsElement(next, listItem)
}
/* Whether to omit `</dt>`. */
function dt(node, index, parent) {
var next = after(parent, index);
return next && hastUtilIsElement(next, dataListItem)
}
/* Whether to omit `</dd>`. */
function dd(node, index, parent) {
var next = after(parent, index);
return !next || hastUtilIsElement(next, dataListItem)
}
/* Whether to omit `</rt>` or `</rp>`. */
function rubyElement(node, index, parent) {
var next = after(parent, index);
return !next || hastUtilIsElement(next, ruby)
}
/* Whether to omit `</optgroup>`. */
function optgroup(node, index, parent) {
var next = after(parent, index);
return !next || hastUtilIsElement(next, optionGroup)
}
/* Whether to omit `</option>`. */
function option(node, index, parent) {
var next = after(parent, index);
return !next || hastUtilIsElement(next, options)
}
/* Whether to omit `</menuitem>`. */
function menuitem(node, index, parent) {
var next = after(parent, index);
return !next || hastUtilIsElement(next, menuContent)
}
/* Whether to omit `</thead>`. */
function thead(node, index, parent) {
var next = after(parent, index);
return next && hastUtilIsElement(next, tableContainer)
}
/* Whether to omit `</tbody>`. */
function tbody$1(node, index, parent) {
var next = after(parent, index);
return !next || hastUtilIsElement(next, tableContainer)
}
/* Whether to omit `</tfoot>`. */
function tfoot(node, index, parent) {
return !after(parent, index)
}
/* Whether to omit `</tr>`. */
function tr(node, index, parent) {
var next = after(parent, index);
return !next || hastUtilIsElement(next, tableRow$1)
}
/* Whether to omit `</td>` or `</th>`. */
function cells(node, index, parent) {
var next = after(parent, index);
return !next || hastUtilIsElement(next, tableCell)
}
var before = siblings_1.before;
var own$4 = {}.hasOwnProperty;
var uniqueHeadMetadata = ['title', 'base'];
var meta = ['meta', 'link', 'script', 'style', 'template'];
var tableContainers = ['thead', 'tbody'];
var tableRow = 'tr';
var opening$1 = omission_1({
html: html,
head: head,
body: body,
colgroup: colgroup,
tbody: tbody
});
/* Whether to omit `<html>`. */
function html(node) {
var head = first_1(node);
return !head || !unistUtilIs('comment', head)
}
/* Whether to omit `<head>`. */
function head(node) {
var children = node.children;
var length = children.length;
var map = {};
var index = -1;
var child;
var name;
while (++index < length) {
child = children[index];
name = child.tagName;
if (hastUtilIsElement(child, uniqueHeadMetadata)) {
if (own$4.call(map, name)) {
return false
}
map[name] = true;
}
}
return Boolean(length)
}
/* Whether to omit `<body>`. */
function body(node) {
var head = first_1(node, true);
return !head || (!unistUtilIs('comment', head) && !whiteSpaceLeft_1(head) && !hastUtilIsElement(head, meta))
}
/* Whether to omit `<colgroup>`.
* The spec describes some logic for the opening tag,
* but its easier to implement in the closing tag, to
* the same effect, so we handle it there instead. */
function colgroup(node, index, parent) {
var prev = before(parent, index);
var head = first_1(node, true);
/* Previous colgroup was already omitted. */
if (hastUtilIsElement(prev, 'colgroup') && closing$1(prev, place_1(parent, prev), parent)) {
return false
}
return head && hastUtilIsElement(head, 'col')
}
/* Whether to omit `<tbody>`. */
function tbody(node, index, parent) {
var prev = before(parent, index);
var head = first_1(node);
/* Previous table section was already omitted. */
if (hastUtilIsElement(prev, tableContainers) && closing$1(prev, place_1(parent, prev), parent)) {
return false
}
return head && hastUtilIsElement(head, tableRow)
}
var opening = opening$1;
var closing = closing$1;
var omission = {
opening: opening,
closing: closing
};
var index$1 = [
"script",
"style",
"pre",
"textarea"
];
var htmlWhitespaceSensitiveTagNames = /*#__PURE__*/Object.freeze({
__proto__: null,
'default': index$1
});
var sensitive = getCjsExportFromNamespace(htmlWhitespaceSensitiveTagNames);
var all_1 = all$1;
/* Stringify all children of `parent`. */
function all$1(ctx, parent) {
var children = parent && parent.children;
var length = children && children.length;
var index = -1;
var results = [];
let printWidthOffset = 0;
let innerTextLength = 0;
while (++index < length) {
innerTextLength = getInnerTextLength(children[index]);
results[index] = one_1(ctx, children[index], index, parent, printWidthOffset, innerTextLength);
printWidthOffset = results[index].replace(/\n+/g, '').length;
}
return results.join('')
}
/**
* Returns the text lenght of the first line of the first child.
* Whitespace sensitive elements are ignored.
* @param {*} node
*/
function getInnerTextLength(node) {
// ignore style, script, pre, textarea elements
if (sensitive.indexOf(node.tagName) !== -1) {
return 0
}
if (!node.children || !node.children.length) {
return 0
}
var child = node.children[0];
if (child.type === 'text' || child.type === 'comment') {
return child.value.split('\n')[0].length
}
return 0
}
var text_1 = text;
/* Stringify `text`. */
function text(ctx, node, index, parent) {
var value = node.value;
return value
}
var data = 'data';
var find_1 = find;
var valid = /^data[-\w.:]+$/i;
var dash = /-[a-z]/g;
var cap$1 = /[A-Z]/g;
function find(schema, value) {
var normal = normalize_1(value);
var prop = value;
var Type = info;
if (normal in schema.normal) {
return schema.property[schema.normal[normal]]
}
if (normal.length > 4 && normal.slice(0, 4) === data && valid.test(value)) {
// Attribute or property.
if (value.charAt(4) === '-') {
prop = datasetToProperty(value);
} else {
value = datasetToAttribute(value);
}
Type = definedInfo;
}
return new Type(prop, value)
}
function datasetToProperty(attribute) {
var value = attribute.slice(5).replace(dash, camelcase);
return data + value.charAt(0).toUpperCase() + value.slice(1)
}
function datasetToAttribute(property) {
var value = property.slice(4);
if (dash.test(value)) {
return property
}
value = value.replace(cap$1, kebab);
if (value.charAt(0) !== '-') {
value = '-' + value;
}
return data + value
}
function kebab($0) {
return '-' + $0.toLowerCase()
}
function camelcase($0) {
return $0.charAt(1).toUpperCase()
}
var parse_1 = parse$2;
var stringify_1 = stringify$2;
var comma = ',';
var space$2 = ' ';
var empty$1 = '';
// Parse comma-separated tokens to an array.
function parse$2(value) {
var values = [];
var input = String(value || empty$1);
var index = input.indexOf(comma);
var lastIndex = 0;
var end = false;
var val;
while (!end) {
if (index === -1) {
index = input.length;
end = true;
}
val = input.slice(lastIndex, index).trim();
if (val || !end) {
values.push(val);
}
lastIndex = index + 1;
index = input.indexOf(comma, lastIndex);
}
return values
}
// Compile an array to comma-separated tokens.
// `options.padLeft` (default: `true`) pads a space left of each token, and
// `options.padRight` (default: `false`) pads a space to the right of each token.
function stringify$2(values, options) {
var settings = options || {};
var left = settings.padLeft === false ? empty$1 : space$2;
var right = settings.padRight ? space$2 : empty$1;
// Ensure the last empty entry is seen.
if (values[values.length - 1] === empty$1) {
values = values.concat(empty$1);
}
return values.join(right + comma + left).trim()
}
var commaSeparatedTokens = {
parse: parse_1,
stringify: stringify_1
};
var nbsp = " ";
var iexcl = "¡";
var cent = "¢";
var pound = "£";
var curren = "¤";
var yen = "¥";
var brvbar = "¦";
var sect = "§";
var uml = "¨";
var copy = "©";
var ordf = "ª";
var laquo = "«";
var not = "¬";
var shy = "­";
var reg = "®";
var macr = "¯";
var deg = "°";
var plusmn = "±";
var sup2 = "²";
var sup3 = "³";
var acute = "´";
var micro = "µ";
var para = "¶";
var middot = "·";
var cedil = "¸";
var sup1 = "¹";
var ordm = "º";
var raquo = "»";
var frac14 = "¼";
var frac12 = "½";
var frac34 = "¾";
var iquest = "¿";
var Agrave = "À";
var Aacute = "Á";
var Acirc = "Â";
var Atilde = "Ã";
var Auml = "Ä";
var Aring = "Å";
var AElig = "Æ";
var Ccedil = "Ç";
var Egrave = "È";
var Eacute = "É";
var Ecirc = "Ê";
var Euml = "Ë";
var Igrave = "Ì";
var Iacute = "Í";
var Icirc = "Î";
var Iuml = "Ï";
var ETH = "Ð";
var Ntilde = "Ñ";
var Ograve = "Ò";
var Oacute = "Ó";
var Ocirc = "Ô";
var Otilde = "Õ";
var Ouml = "Ö";
var times = "×";
var Oslash = "Ø";
var Ugrave = "Ù";
var Uacute = "Ú";
var Ucirc = "Û";
var Uuml = "Ü";
var Yacute = "Ý";
var THORN = "Þ";
var szlig = "ß";
var agrave = "à";
var aacute = "á";
var acirc = "â";
var atilde = "ã";
var auml = "ä";
var aring = "å";
var aelig = "æ";
var ccedil = "ç";
var egrave = "è";
var eacute = "é";
var ecirc = "ê";
var euml = "ë";
var igrave = "ì";
var iacute = "í";
var icirc = "î";
var iuml = "ï";
var eth = "ð";
var ntilde = "ñ";
var ograve = "ò";
var oacute = "ó";
var ocirc = "ô";
var otilde = "õ";
var ouml = "ö";
var divide = "÷";
var oslash = "ø";
var ugrave = "ù";
var uacute = "ú";
var ucirc = "û";
var uuml = "ü";
var yacute = "ý";
var thorn = "þ";
var yuml = "ÿ";
var fnof = "ƒ";
var Alpha = "Α";
var Beta = "Β";
var Gamma = "Γ";
var Delta = "Δ";
var Epsilon = "Ε";
var Zeta = "Ζ";
var Eta = "Η";
var Theta = "Θ";
var Iota = "Ι";
var Kappa = "Κ";
var Lambda = "Λ";
var Mu = "Μ";
var Nu = "Ν";
var Xi = "Ξ";
var Omicron = "Ο";
var Pi = "Π";
var Rho = "Ρ";
var Sigma = "Σ";
var Tau = "Τ";
var Upsilon = "Υ";
var Phi = "Φ";
var Chi = "Χ";
var Psi = "Ψ";
var Omega = "Ω";
var alpha = "α";
var beta = "β";
var gamma = "γ";
var delta = "δ";
var epsilon = "ε";
var zeta = "ζ";
var eta = "η";
var theta = "θ";
var iota = "ι";
var kappa = "κ";
var lambda = "λ";
var mu = "μ";
var nu = "ν";
var xi = "ξ";
var omicron = "ο";
var pi = "π";
var rho = "ρ";
var sigmaf = "ς";
var sigma = "σ";
var tau = "τ";
var upsilon = "υ";
var phi = "φ";
var chi = "χ";
var psi = "ψ";
var omega = "ω";
var thetasym = "ϑ";
var upsih = "ϒ";
var piv = "ϖ";
var bull = "•";
var hellip = "…";
var prime = "";
var Prime = "″";
var oline = "‾";
var frasl = "";
var weierp = "℘";
var image = "";
var real = "";
var trade = "™";
var alefsym = "ℵ";
var larr = "←";
var uarr = "↑";
var rarr = "→";
var darr = "↓";
var harr = "↔";
var crarr = "↵";
var lArr = "⇐";
var uArr = "⇑";
var rArr = "⇒";
var dArr = "⇓";
var hArr = "⇔";
var forall = "∀";
var part = "∂";
var exist = "∃";
var empty = "∅";
var nabla = "∇";
var isin = "∈";
var notin = "∉";
var ni = "∋";
var prod = "∏";
var sum = "∑";
var minus = "";
var lowast = "";
var radic = "√";
var prop = "∝";
var infin = "∞";
var ang = "∠";
var and = "∧";
var or = "";
var cap = "∩";
var cup = "";
var int = "∫";
var there4 = "∴";
var sim = "";
var cong = "≅";
var asymp = "≈";
var ne = "≠";
var equiv = "≡";
var le = "≤";
var ge = "≥";
var sub = "⊂";
var sup = "⊃";
var nsub = "⊄";
var sube = "⊆";
var supe = "⊇";
var oplus = "⊕";
var otimes = "⊗";
var perp = "⊥";
var sdot = "⋅";
var lceil = "⌈";
var rceil = "⌉";
var lfloor = "⌊";
var rfloor = "⌋";
var lang = "〈";
var rang = "〉";
var loz = "◊";
var spades = "♠";
var clubs = "♣";
var hearts = "♥";
var diams = "♦";
var quot = "\"";
var amp = "&";
var lt = "<";
var gt = ">";
var OElig = "Œ";
var oelig = "œ";
var Scaron = "Š";
var scaron = "š";
var Yuml = "Ÿ";
var circ = "ˆ";
var tilde = "˜";
var ensp = "";
var emsp = "";
var thinsp = "";
var zwnj = "";
var zwj = "";
var lrm = "";
var rlm = "";
var ndash = "";
var mdash = "—";
var lsquo = "";
var rsquo = "";
var sbquo = "";
var ldquo = "“";
var rdquo = "”";
var bdquo = "„";
var dagger = "†";
var Dagger = "‡";
var permil = "‰";
var lsaquo = "";
var rsaquo = "";
var euro = "€";
var index = {
nbsp: nbsp,
iexcl: iexcl,
cent: cent,
pound: pound,
curren: curren,
yen: yen,
brvbar: brvbar,
sect: sect,
uml: uml,
copy: copy,
ordf: ordf,
laquo: laquo,
not: not,
shy: shy,
reg: reg,
macr: macr,
deg: deg,
plusmn: plusmn,
sup2: sup2,
sup3: sup3,
acute: acute,
micro: micro,
para: para,
middot: middot,
cedil: cedil,
sup1: sup1,
ordm: ordm,
raquo: raquo,
frac14: frac14,
frac12: frac12,
frac34: frac34,
iquest: iquest,
Agrave: Agrave,
Aacute: Aacute,
Acirc: Acirc,
Atilde: Atilde,
Auml: Auml,
Aring: Aring,
AElig: AElig,
Ccedil: Ccedil,
Egrave: Egrave,
Eacute: Eacute,
Ecirc: Ecirc,
Euml: Euml,
Igrave: Igrave,
Iacute: Iacute,
Icirc: Icirc,
Iuml: Iuml,
ETH: ETH,
Ntilde: Ntilde,
Ograve: Ograve,
Oacute: Oacute,
Ocirc: Ocirc,
Otilde: Otilde,
Ouml: Ouml,
times: times,
Oslash: Oslash,
Ugrave: Ugrave,
Uacute: Uacute,
Ucirc: Ucirc,
Uuml: Uuml,
Yacute: Yacute,
THORN: THORN,
szlig: szlig,
agrave: agrave,
aacute: aacute,
acirc: acirc,
atilde: atilde,
auml: auml,
aring: aring,
aelig: aelig,
ccedil: ccedil,
egrave: egrave,
eacute: eacute,
ecirc: ecirc,
euml: euml,
igrave: igrave,
iacute: iacute,
icirc: icirc,
iuml: iuml,
eth: eth,
ntilde: ntilde,
ograve: ograve,
oacute: oacute,
ocirc: ocirc,
otilde: otilde,
ouml: ouml,
divide: divide,
oslash: oslash,
ugrave: ugrave,
uacute: uacute,
ucirc: ucirc,
uuml: uuml,
yacute: yacute,
thorn: thorn,
yuml: yuml,
fnof: fnof,
Alpha: Alpha,
Beta: Beta,
Gamma: Gamma,
Delta: Delta,
Epsilon: Epsilon,
Zeta: Zeta,
Eta: Eta,
Theta: Theta,
Iota: Iota,
Kappa: Kappa,
Lambda: Lambda,
Mu: Mu,
Nu: Nu,
Xi: Xi,
Omicron: Omicron,
Pi: Pi,
Rho: Rho,
Sigma: Sigma,
Tau: Tau,
Upsilon: Upsilon,
Phi: Phi,
Chi: Chi,
Psi: Psi,
Omega: Omega,
alpha: alpha,
beta: beta,
gamma: gamma,
delta: delta,
epsilon: epsilon,
zeta: zeta,
eta: eta,
theta: theta,
iota: iota,
kappa: kappa,
lambda: lambda,
mu: mu,
nu: nu,
xi: xi,
omicron: omicron,
pi: pi,
rho: rho,
sigmaf: sigmaf,
sigma: sigma,
tau: tau,
upsilon: upsilon,
phi: phi,
chi: chi,
psi: psi,
omega: omega,
thetasym: thetasym,
upsih: upsih,
piv: piv,
bull: bull,
hellip: hellip,
prime: prime,
Prime: Prime,
oline: oline,
frasl: frasl,
weierp: weierp,
image: image,
real: real,
trade: trade,
alefsym: alefsym,
larr: larr,
uarr: uarr,
rarr: rarr,
darr: darr,
harr: harr,
crarr: crarr,
lArr: lArr,
uArr: uArr,
rArr: rArr,
dArr: dArr,
hArr: hArr,
forall: forall,
part: part,
exist: exist,
empty: empty,
nabla: nabla,
isin: isin,
notin: notin,
ni: ni,
prod: prod,
sum: sum,
minus: minus,
lowast: lowast,
radic: radic,
prop: prop,
infin: infin,
ang: ang,
and: and,
or: or,
cap: cap,
cup: cup,
int: int,
there4: there4,
sim: sim,
cong: cong,
asymp: asymp,
ne: ne,
equiv: equiv,
le: le,
ge: ge,
sub: sub,
sup: sup,
nsub: nsub,
sube: sube,
supe: supe,
oplus: oplus,
otimes: otimes,
perp: perp,
sdot: sdot,
lceil: lceil,
rceil: rceil,
lfloor: lfloor,
rfloor: rfloor,
lang: lang,
rang: rang,
loz: loz,
spades: spades,
clubs: clubs,
hearts: hearts,
diams: diams,
quot: quot,
amp: amp,
lt: lt,
gt: gt,
OElig: OElig,
oelig: oelig,
Scaron: Scaron,
scaron: scaron,
Yuml: Yuml,
circ: circ,
tilde: tilde,
ensp: ensp,
emsp: emsp,
thinsp: thinsp,
zwnj: zwnj,
zwj: zwj,
lrm: lrm,
rlm: rlm,
ndash: ndash,
mdash: mdash,
lsquo: lsquo,
rsquo: rsquo,
sbquo: sbquo,
ldquo: ldquo,
rdquo: rdquo,
bdquo: bdquo,
dagger: dagger,
Dagger: Dagger,
permil: permil,
lsaquo: lsaquo,
rsaquo: rsaquo,
euro: euro
};
var characterEntitiesHtml4 = /*#__PURE__*/Object.freeze({
__proto__: null,
nbsp: nbsp,
iexcl: iexcl,
cent: cent,
pound: pound,
curren: curren,
yen: yen,
brvbar: brvbar,
sect: sect,
uml: uml,
copy: copy,
ordf: ordf,
laquo: laquo,
not: not,
shy: shy,
reg: reg,
macr: macr,
deg: deg,
plusmn: plusmn,
sup2: sup2,
sup3: sup3,
acute: acute,
micro: micro,
para: para,
middot: middot,
cedil: cedil,
sup1: sup1,
ordm: ordm,
raquo: raquo,
frac14: frac14,
frac12: frac12,
frac34: frac34,
iquest: iquest,
Agrave: Agrave,
Aacute: Aacute,
Acirc: Acirc,
Atilde: Atilde,
Auml: Auml,
Aring: Aring,
AElig: AElig,
Ccedil: Ccedil,
Egrave: Egrave,
Eacute: Eacute,
Ecirc: Ecirc,
Euml: Euml,
Igrave: Igrave,
Iacute: Iacute,
Icirc: Icirc,
Iuml: Iuml,
ETH: ETH,
Ntilde: Ntilde,
Ograve: Ograve,
Oacute: Oacute,
Ocirc: Ocirc,
Otilde: Otilde,
Ouml: Ouml,
times: times,
Oslash: Oslash,
Ugrave: Ugrave,
Uacute: Uacute,
Ucirc: Ucirc,
Uuml: Uuml,
Yacute: Yacute,
THORN: THORN,
szlig: szlig,
agrave: agrave,
aacute: aacute,
acirc: acirc,
atilde: atilde,
auml: auml,
aring: aring,
aelig: aelig,
ccedil: ccedil,
egrave: egrave,
eacute: eacute,
ecirc: ecirc,
euml: euml,
igrave: igrave,
iacute: iacute,
icirc: icirc,
iuml: iuml,
eth: eth,
ntilde: ntilde,
ograve: ograve,
oacute: oacute,
ocirc: ocirc,
otilde: otilde,
ouml: ouml,
divide: divide,
oslash: oslash,
ugrave: ugrave,
uacute: uacute,
ucirc: ucirc,
uuml: uuml,
yacute: yacute,
thorn: thorn,
yuml: yuml,
fnof: fnof,
Alpha: Alpha,
Beta: Beta,
Gamma: Gamma,
Delta: Delta,
Epsilon: Epsilon,
Zeta: Zeta,
Eta: Eta,
Theta: Theta,
Iota: Iota,
Kappa: Kappa,
Lambda: Lambda,
Mu: Mu,
Nu: Nu,
Xi: Xi,
Omicron: Omicron,
Pi: Pi,
Rho: Rho,
Sigma: Sigma,
Tau: Tau,
Upsilon: Upsilon,
Phi: Phi,
Chi: Chi,
Psi: Psi,
Omega: Omega,
alpha: alpha,
beta: beta,
gamma: gamma,
delta: delta,
epsilon: epsilon,
zeta: zeta,
eta: eta,
theta: theta,
iota: iota,
kappa: kappa,
lambda: lambda,
mu: mu,
nu: nu,
xi: xi,
omicron: omicron,
pi: pi,
rho: rho,
sigmaf: sigmaf,
sigma: sigma,
tau: tau,
upsilon: upsilon,
phi: phi,
chi: chi,
psi: psi,
omega: omega,
thetasym: thetasym,
upsih: upsih,
piv: piv,
bull: bull,
hellip: hellip,
prime: prime,
Prime: Prime,
oline: oline,
frasl: frasl,
weierp: weierp,
image: image,
real: real,
trade: trade,
alefsym: alefsym,
larr: larr,
uarr: uarr,
rarr: rarr,
darr: darr,
harr: harr,
crarr: crarr,
lArr: lArr,
uArr: uArr,
rArr: rArr,
dArr: dArr,
hArr: hArr,
forall: forall,
part: part,
exist: exist,
empty: empty,
nabla: nabla,
isin: isin,
notin: notin,
ni: ni,
prod: prod,
sum: sum,
minus: minus,
lowast: lowast,
radic: radic,
prop: prop,
infin: infin,
ang: ang,
and: and,
or: or,
cap: cap,
cup: cup,
int: int,
there4: there4,
sim: sim,
cong: cong,
asymp: asymp,
ne: ne,
equiv: equiv,
le: le,
ge: ge,
sub: sub,
sup: sup,
nsub: nsub,
sube: sube,
supe: supe,
oplus: oplus,
otimes: otimes,
perp: perp,
sdot: sdot,
lceil: lceil,
rceil: rceil,
lfloor: lfloor,
rfloor: rfloor,
lang: lang,
rang: rang,
loz: loz,
spades: spades,
clubs: clubs,
hearts: hearts,
diams: diams,
quot: quot,
amp: amp,
lt: lt,
gt: gt,
OElig: OElig,
oelig: oelig,
Scaron: Scaron,
scaron: scaron,
Yuml: Yuml,
circ: circ,
tilde: tilde,
ensp: ensp,
emsp: emsp,
thinsp: thinsp,
zwnj: zwnj,
zwj: zwj,
lrm: lrm,
rlm: rlm,
ndash: ndash,
mdash: mdash,
lsquo: lsquo,
rsquo: rsquo,
sbquo: sbquo,
ldquo: ldquo,
rdquo: rdquo,
bdquo: bdquo,
dagger: dagger,
Dagger: Dagger,
permil: permil,
lsaquo: lsaquo,
rsaquo: rsaquo,
euro: euro,
'default': index
});
var dangerous$1 = [
"cent",
"copy",
"divide",
"gt",
"lt",
"not",
"para",
"times"
];
var dangerous$2 = /*#__PURE__*/Object.freeze({
__proto__: null,
'default': dangerous$1
});
var entities = getCjsExportFromNamespace(characterEntitiesHtml4);
var dangerous = getCjsExportFromNamespace(dangerous$2);
var decimal = isDecimal;
var stringifyEntities = encode;
encode.escape = escape;
var own$3 = {}.hasOwnProperty;
// List of enforced escapes.
var escapes = ['"', "'", '<', '>', '&', '`'];
// Map of characters to names.
var characters = construct();
// Default escapes.
var defaultEscapes = toExpression(escapes);
// Surrogate pairs.
var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
// Non-ASCII characters.
// eslint-disable-next-line no-control-regex, unicorn/no-hex-escape
var bmp = /[\x01-\t\x0B\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g;
// Encode special characters in `value`.
function encode(value, options) {
var settings = options || {};
var subset = settings.subset;
var set = subset ? toExpression(subset) : defaultEscapes;
var escapeOnly = settings.escapeOnly;
var omit = settings.omitOptionalSemicolons;
value = value.replace(set, replace);
if (subset || escapeOnly) {
return value
}
return value
.replace(surrogatePair, replaceSurrogatePair)
.replace(bmp, replace)
function replaceSurrogatePair(pair, pos, val) {
return toHexReference(
(pair.charCodeAt(0) - 0xd800) * 0x400 +
pair.charCodeAt(1) -
0xdc00 +
0x10000,
val.charAt(pos + 2),
omit
)
}
function replace(char, pos, val) {
return one$1(char, val.charAt(pos + 1), settings)
}
}
// Shortcut to escape special characters in HTML.
function escape(value) {
return encode(value, {escapeOnly: true, useNamedReferences: true})
}
// Encode `char` according to `options`.
function one$1(char, next, options) {
var shortest = options.useShortestReferences;
var omit = options.omitOptionalSemicolons;
var named;
var code;
var numeric;
var decimal;
if ((shortest || options.useNamedReferences) && own$3.call(characters, char)) {
named = toNamed(characters[char], next, omit, options.attribute);
}
if (shortest || !named) {
code = char.charCodeAt(0);
numeric = toHexReference(code, next, omit);
// Use the shortest numeric reference when requested.
// A simple algorithm would use decimal for all code points under 100, as
// those are shorter than hexadecimal:
//
// * `&#99;` vs `&#x63;` (decimal shorter)
// * `&#100;` vs `&#x64;` (equal)
//
// However, because we take `next` into consideration when `omit` is used,
// And it would be possible that decimals are shorter on bigger values as
// well if `next` is hexadecimal but not decimal, we instead compare both.
if (shortest) {
decimal = toDecimalReference(code, next, omit);
if (decimal.length < numeric.length) {
numeric = decimal;
}
}
}
if (named && (!shortest || named.length < numeric.length)) {
return named
}
return numeric
}
// Transform `code` into an entity.
function toNamed(name, next, omit, attribute) {
var value = '&' + name;
if (
omit &&
own$3.call(legacy, name) &&
dangerous.indexOf(name) === -1 &&
(!attribute || (next && next !== '=' && !isAlphanumerical(next)))
) {
return value
}
return value + ';'
}
// Transform `code` into a hexadecimal character reference.
function toHexReference(code, next, omit) {
var value = '&#x' + code.toString(16).toUpperCase();
return omit && next && !isHexadecimal(next) ? value : value + ';'
}
// Transform `code` into a decimal character reference.
function toDecimalReference(code, next, omit) {
var value = '&#' + String(code);
return omit && next && !decimal(next) ? value : value + ';'
}
// Create an expression for `characters`.
function toExpression(characters) {
return new RegExp('[' + characters.join('') + ']', 'g')
}
// Construct the map.
function construct() {
var chars = {};
var name;
for (name in entities) {
chars[entities[name]] = name;
}
return chars
}
// Characters.
var NULL = '\0';
var AMP = '&';
var SP = ' ';
var TB = '\t';
var GR = '`';
var DQ$1 = '"';
var SQ$1 = "'";
var EQ = '=';
var LT = '<';
var GT = '>';
var SO = '/';
var LF = '\n';
var CR = '\r';
var FF = '\f';
var whitespace = [SP, TB, LF, CR, FF];
// https://html.spec.whatwg.org/#attribute-name-state
var name = whitespace.concat(AMP, SO, GT, EQ);
// https://html.spec.whatwg.org/#attribute-value-(unquoted)-state
var unquoted$1 = whitespace.concat(AMP, GT);
var unquotedSafe = unquoted$1.concat(NULL, DQ$1, SQ$1, LT, EQ, GR);
// https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state
var singleQuoted$1 = [AMP, SQ$1];
// https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state
var doubleQuoted$1 = [AMP, DQ$1];
// Maps of subsets. Each value is a matrix of tuples.
// The first value causes parse errors, the second is valid.
// Of both values, the first value is unsafe, and the second is safe.
var constants = {
name: [[name, name.concat(DQ$1, SQ$1, GR)], [name.concat(NULL, DQ$1, SQ$1, LT), name.concat(NULL, DQ$1, SQ$1, LT, GR)]],
unquoted: [[unquoted$1, unquotedSafe], [unquotedSafe, unquotedSafe]],
single: [
[singleQuoted$1, singleQuoted$1.concat(DQ$1, GR)],
[singleQuoted$1.concat(NULL), singleQuoted$1.concat(NULL, DQ$1, GR)]
],
double: [
[doubleQuoted$1, doubleQuoted$1.concat(SQ$1, GR)],
[doubleQuoted$1.concat(NULL), doubleQuoted$1.concat(NULL, SQ$1, GR)]
]
};
var spaces = spaceSeparatedTokens.stringify;
var commas = commaSeparatedTokens.stringify;
var element_1 = element;
/* Constants. */
var emptyString = '';
/* Characters. */
var space$1 = ' ';
var quotationMark = '"';
var apostrophe$1 = "'";
var equalsTo = '=';
var lessThan$1 = '<';
var greaterThan = '>';
var slash$1 = '/';
var newLine = '\n';
/* Stringify an element `node`. */
function element(ctx, node, index, parent, printWidthOffset, innerTextLength) {
var parentSchema = ctx.schema;
var name = node.tagName;
var value = '';
var selfClosing;
var close;
var omit;
var root = node;
var content;
var attrs;
var indentLevel = getNodeData(node, 'indentLevel', 0);
var printContext = {
offset: printWidthOffset,
wrapAttributes: false,
indentLevel
};
var isVoid = ctx.voids.indexOf(name) !== -1;
var ignoreAttrCollapsing =
getNodeData(node, 'ignore', false) || getNodeData(node, 'preserveAttrWrapping', false);
if (parentSchema.space === 'html' && name === 'svg') {
ctx.schema = svg_1;
}
if (ctx.schema.space === 'svg') {
omit = false;
close = true;
selfClosing = ctx.closeEmpty;
} else {
omit = ctx.omit;
close = ctx.close;
selfClosing = isVoid;
}
// check for 'selfClosing' property set by hast-util-from-webparser package
// in order to support custom self-closing elements
if (selfClosing === false) {
selfClosing = getNodeData(node, 'selfClosing', false);
}
// <
printContext.offset += lessThan$1.length;
// tagName length
printContext.offset += node.tagName.length;
// / closing tag
if (selfClosing && !isVoid) {
printContext.offset += slash$1.length;
}
// >
printContext.offset += greaterThan.length;
const propertyCount = Object.keys(node.properties).length;
// force to wrap attributes on multiple lines when the node contains
// more than one attribute
if (propertyCount > 1 && ctx.wrapAttributes) {
printContext.wrapAttributes = true;
}
// one space before each attribute
if (propertyCount) {
printContext.offset += propertyCount * space$1.length;
}
// represent the length of the inner text of the node
printContext.offset += innerTextLength;
attrs = attributes(ctx, node.properties, printContext, ignoreAttrCollapsing);
const shouldCollapse = ignoreAttrCollapsing === false && printContext.wrapAttributes;
content = all_1(ctx, root);
/* If the node is categorised as void, but it has
* children, remove the categorisation. This
* enables for example `menuitem`s, which are
* void in W3C HTML but not void in WHATWG HTML, to
* be stringified properly. */
selfClosing = content ? false : selfClosing;
if (attrs || !omit || !omit.opening(node, index, parent)) {
value = lessThan$1 + name;
if (attrs) {
// add no space after tagName when element is collapsed
if (shouldCollapse) {
value += attrs;
} else {
value += space$1 + attrs;
}
}
let selfClosed = false;
// check if the should close self-closing elements
if (selfClosing && close) {
if ((!ctx.tightClose || attrs.charAt(attrs.length - 1) === slash$1) && !shouldCollapse) {
value += space$1;
}
if (shouldCollapse) {
value += newLine + repeatString(ctx.tabWidth, printContext.indentLevel);
}
selfClosed = true;
value += slash$1;
}
// allow any element to self close itself except known HTML void elements
else if (selfClosing && !isVoid) {
if (shouldCollapse) {
value += newLine + repeatString(ctx.tabWidth, printContext.indentLevel);
}
selfClosed = true;
value += slash$1;
}
// add newline when element should be wrappend on multiple lines and when
// it's no self-closing element because in that case the newline was already added before the slash (/)
if (shouldCollapse && !selfClosed) {
value += newLine + repeatString(ctx.tabWidth, printContext.indentLevel);
}
value += greaterThan;
}
value += content;
if (!selfClosing && (!omit || !omit.closing(node, index, parent))) {
value += lessThan$1 + slash$1 + name + greaterThan;
}
ctx.schema = parentSchema;
return value
}
/* Stringify all attributes. */
function attributes(ctx, props, printContext, ignoreIndent) {
var values = [];
var key;
var value;
var result;
var length;
var index;
var last;
for (key in props) {
value = props[key];
if (value == null) {
continue
}
result = attribute$1(ctx, key, value);
printContext.offset += result.length;
if (ignoreIndent === false && printContext.offset > ctx.printWidth) {
printContext.wrapAttributes = true;
}
if (result) {
values.push(result);
}
}
length = values.length;
index = -1;
while (++index < length) {
result = values[index];
last = null;
/* In tight mode, dont add a space after quoted attributes. */
if (last !== quotationMark && last !== apostrophe$1) {
if (printContext.wrapAttributes) {
values[index] = newLine + repeatString(ctx.tabWidth, printContext.indentLevel + 1) + result;
} else if (index !== length - 1) {
values[index] = result + space$1;
} else {
values[index] = result;
}
}
}
return values.join(emptyString)
}
/* Stringify one attribute. */
function attribute$1(ctx, key, value) {
var schema = ctx.schema;
var info = find_1(schema, key);
var name = info.attribute;
if (value == null || (typeof value === 'number' && isNaN(value)) || (value === false && info.boolean)) {
return emptyString
}
name = attributeName$1(ctx, name);
if ((value === true && info.boolean) || (value === true && info.overloadedBoolean)) {
return name
}
return name + attributeValue$1(ctx, key, value, info)
}
/* Stringify the attribute name. */
function attributeName$1(ctx, name) {
// Always encode without parse errors in non-HTML.
var valid = ctx.schema.space === 'html' ? ctx.valid : 1;
var subset = constants.name[valid][ctx.safe];
return stringifyEntities(name, immutable(ctx.entities, { subset: subset }))
}
/* Stringify the attribute value. */
function attributeValue$1(ctx, key, value, info) {
var quote = ctx.quote;
if (typeof value === 'object' && 'length' in value) {
/* `spaces` doesnt accept a second argument, but its
* given here just to keep the code cleaner. */
value = (info.commaSeparated ? commas : spaces)(value, {
padLeft: !ctx.tightLists
});
}
value = String(value);
// When attr has no value we avoid quoting
if (value === '') {
return value
} else {
value = equalsTo + quote + value + quote;
}
return value
}
function getNodeData(node, key, defaultValue) {
let data = node.data || {};
return data[key] || defaultValue
}
var doctype_1 = doctype;
/* Stringify a doctype `node`. */
function doctype(ctx, node) {
var sep = ctx.tightDoctype ? '' : ' ';
var name = node.name;
var pub = node.public;
var sys = node.system;
var val = ['<!doctype'];
if (name) {
val.push(sep, name);
if (pub != null) {
val.push(' public', sep, smart(pub));
} else if (sys != null) {
val.push(' system');
}
if (sys != null) {
val.push(sep, smart(sys));
}
}
return val.join('') + '>'
}
function smart(value) {
var quote = value.indexOf('"') === -1 ? '"' : "'";
return quote + value + quote
}
var comment_1 = comment;
/* Stringify a comment `node`. */
function comment(ctx, node) {
return '<!--' + node.value + '-->'
}
var raw_1 = raw;
/* Stringify `raw`. */
function raw(ctx, node) {
return node.value
}
var one_1 = one;
var own$2 = {}.hasOwnProperty;
var handlers = {};
handlers.root = all_1;
handlers.text = text_1;
handlers.element = element_1;
handlers.doctype = doctype_1;
handlers.comment = comment_1;
handlers.raw = raw_1;
/* Stringify `node`. */
function one(ctx, node, index, parent, printWidthOffset, innerTextLength) {
var type = node && node.type;
if (!type) {
throw new Error('Expected node, not `' + node + '`')
}
if (!own$2.call(handlers, type)) {
throw new Error('Cannot compile unknown node `' + type + '`')
}
return handlers[type](ctx, node, index, parent, printWidthOffset, innerTextLength)
}
var voids = getCjsExportFromNamespace(htmlVoidElements);
var lib$1 = toHTML;
/* Characters. */
var DQ = '"';
var SQ = "'";
/* Stringify the given HAST node. */
function toHTML(node, options) {
var settings = options || {};
var quote = settings.singleQuote ? SQ : DQ;
var printWidth = settings.printWidth === undefined ? 80 : settings.printWidth;
var useTabs = settings.useTabs;
var tabWidth = settings.tabWidth || 2;
var wrapAttributes = settings.wrapAttributes;
if (useTabs) {
tabWidth = '\t';
} else if (typeof tabWidth === 'number') {
tabWidth = repeatString(' ', tabWidth);
}
return one_1(
{
valid: settings.allowParseErrors ? 0 : 1,
safe: settings.allowDangerousCharacters ? 0 : 1,
schema: settings.space === 'svg' ? svg_1 : html_1,
omit: settings.omitOptionalTags && omission,
quote: quote,
printWidth: printWidth,
tabWidth: tabWidth,
wrapAttributes: wrapAttributes,
tightDoctype: Boolean(settings.tightDoctype),
tightLists: settings.tightCommaSeparatedLists,
voids: settings.voids || voids.concat(),
entities: settings.entities || {},
close: settings.closeSelfClosing,
tightClose: settings.tightSelfClosing,
closeEmpty: settings.closeEmptyElements
},
node
)
}
var prettyhtmlHastToHtml = lib$1;
const void_els = [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'link',
'meta',
'param',
'source',
'track',
'wbr',
];
// these regex don't check if it is a valid svelte tag name
// i want to defer to svelte's compiler errors so i don't end up reimplementing the svelte parser
const RE_SVELTE_TAG = /^<svelte:([a-z]*)[\s\S]*(?:(?:svelte:[a-z]*)|(?:\/))>$/;
const RE_SVELTE_TAG_START = /(^\s*)<([\\/\s])*svelte:/;
function parse_svelte_tag(
eat,
value,
silent
) {
const is_svelte_tag = RE_SVELTE_TAG_START.exec(value);
if (is_svelte_tag) {
if (silent) return true;
const trimmed_value = value.trim();
let cbPos = 0;
let pos = 1;
let current_tag = '';
let in_tag_name = false;
while (cbPos > -1) {
if (!trimmed_value[pos]) {
break;
}
if (trimmed_value[pos].match(/</)) {
cbPos++;
current_tag = '';
in_tag_name = true;
}
if (in_tag_name && trimmed_value[pos].match(/\s/)) {
in_tag_name = false;
}
if (in_tag_name && !trimmed_value[pos].match(/</)) {
current_tag += trimmed_value[pos];
}
const is_void = void_els.includes(current_tag);
if (
(is_void && trimmed_value[pos].match(/>/)) ||
(trimmed_value[pos - 1] + trimmed_value[pos]).match(/\/>/)
) {
cbPos--;
}
if ((trimmed_value[pos - 1] + trimmed_value[pos]).match(/<\//)) {
let inner_indent = 0;
while (inner_indent > -1) {
if (trimmed_value[pos].match(/>/)) {
pos++;
inner_indent -= 1;
cbPos -= 2;
} else {
pos++;
}
}
}
pos++;
}
const match = RE_SVELTE_TAG.exec(trimmed_value.substring(0, pos).trim());
if (!match) return;
return eat(is_svelte_tag[1] + match[0])({
type: 'svelteTag',
value: match[0],
name: match[1],
});
}
}
// these regex don't check if it is a valid block name
// i want to defer to svelte's compiler errors so i don't end up reimplementing the svelte parser
// 'else if' is a special case due to the annoying whitespace
const RE_SVELTE_BLOCK_START = /(^\s*){[#:/@]/;
const RE_SVELTE_BLOCK = /^{[#:/@](else if|[a-z]+).*}$/;
function parse_svelte_block(
eat,
value,
silent
) {
const is_svelte_block = RE_SVELTE_BLOCK_START.exec(value);
if (is_svelte_block) {
if (silent) return true;
const trimmed_value = value.trim();
let cbPos = 0;
let pos = 1;
while (cbPos > -1) {
if (trimmed_value[pos].match(/{/)) cbPos++;
if (trimmed_value[pos].match(/}/)) cbPos--;
pos++;
}
const match = RE_SVELTE_BLOCK.exec(trimmed_value.substring(0, pos));
if (!match) return;
return eat(is_svelte_block[1] + match[0])({
type: 'svelteBlock',
value: `${is_svelte_block[1]}${match[0]}`,
name: match[1],
});
}
}
const dotAllPolyfill = '[\0-\uFFFF]';
const attributeName = '[a-zA-Z_:][a-zA-Z0-9:._-]*';
const unquoted = '[^"\'=<>`\\u0000-\\u0020]+';
const singleQuoted = "'[^']*'";
const doubleQuoted = '"[^"]*"';
const jsProps = '{.*}'.replace('.', dotAllPolyfill);
const attributeValue =
'(?:' +
unquoted +
'|' +
singleQuoted +
'|' +
doubleQuoted +
'|' +
jsProps +
')';
const attribute =
'(?:\\s+' + attributeName + '(?:\\s*=\\s*' + attributeValue + ')?)';
const openTag = '<[A-Za-z]*[A-Za-z0-9\\.\\-]*' + attribute + '*\\s*\\/?>';
const closeTag = '<\\/[A-Za-z][A-Za-z0-9\\.\\-]*\\s*>';
'<[?].*?[?]>'.replace('.', dotAllPolyfill);
const openCloseTag = new RegExp('^(?:' + openTag + '|' + closeTag + ')');
const tab = '\t';
const space = ' ';
const lineFeed = '\n';
const lessThan = '<';
const rawOpenExpression = /^<(script|pre|style)(?=(\s|>|$))/i;
const rawCloseExpression = /<\/(script|pre|style)>/i;
const commentOpenExpression = /^<!--/;
const commentCloseExpression = /-->/;
const instructionOpenExpression = /^<\?/;
const instructionCloseExpression = /\?>/;
const directiveOpenExpression = /^<![A-Za-z]/;
const directiveCloseExpression = />/;
const cdataOpenExpression = /^<!\[CDATA\[/;
const cdataCloseExpression = /\]\]>/;
const elementCloseExpression = /^$/;
const otherElementOpenExpression = new RegExp(openCloseTag.source + '\\s*$');
const fragmentOpenExpression = /^<>/;
//@ts-ignore
function blockHtml(
eat,
value,
silent
) {
const blocks = '[a-z\\.]*(\\.){0,1}[a-z][a-z0-9\\.]*';
const elementOpenExpression = new RegExp(
'^</?(' + blocks + ')(?=(\\s|/?>|$))',
'i'
);
const length = value.length;
let index = 0;
let next;
let line;
let offset;
let character;
let sequence;
const sequences = [
[rawOpenExpression, rawCloseExpression, true],
[commentOpenExpression, commentCloseExpression, true],
[instructionOpenExpression, instructionCloseExpression, true],
[directiveOpenExpression, directiveCloseExpression, true],
[cdataOpenExpression, cdataCloseExpression, true],
[elementOpenExpression, elementCloseExpression, true],
[fragmentOpenExpression, elementCloseExpression, true],
[otherElementOpenExpression, elementCloseExpression, false],
];
// Eat initial spacing.
while (index < length) {
character = value.charAt(index);
if (character !== tab && character !== space) {
break;
}
index++;
}
if (value.charAt(index) !== lessThan) {
return;
}
next = value.indexOf(lineFeed, index + 1);
next = next === -1 ? length : next;
line = value.slice(index, next);
offset = -1;
const count = sequences.length;
while (++offset < count) {
if (sequences[offset][0].test(line)) {
sequence = sequences[offset];
break;
}
}
if (!sequence) {
return;
}
if (silent) {
return sequence[2];
}
index = next;
if (!sequence[1].test(line)) {
while (index < length) {
next = value.indexOf(lineFeed, index + 1);
next = next === -1 ? length : next;
line = value.slice(index + 1, next);
if (sequence[1].test(line)) {
if (line) {
index = next;
}
break;
}
index = next;
}
}
const subvalue = value.slice(0, index);
return eat(subvalue)({ type: 'html', value: subvalue });
}
function mdsvex_parser() {
const Parser = this.Parser;
const block_tokenizers = Parser.prototype.blockTokenizers;
const methods = Parser.prototype.blockMethods;
block_tokenizers.svelteBlock = parse_svelte_block;
block_tokenizers.svelteTag = parse_svelte_tag;
block_tokenizers.html = blockHtml;
block_tokenizers.indentedCode = indentedCode;
methods.splice(methods.indexOf('html'), 0, 'svelteBlock');
methods.splice(methods.indexOf('html'), 0, 'svelteTag');
}
function indentedCode() {
return true;
}
// Expose a frozen processor.
var unified_1 = unified().freeze();
var slice = [].slice;
var own$1 = {}.hasOwnProperty;
// Process pipeline.
var pipeline = trough_1()
.use(pipelineParse)
.use(pipelineRun)
.use(pipelineStringify);
function pipelineParse(p, ctx) {
ctx.tree = p.parse(ctx.file);
}
function pipelineRun(p, ctx, next) {
p.run(ctx.tree, ctx.file, done);
function done(err, tree, file) {
if (err) {
next(err);
} else {
ctx.tree = tree;
ctx.file = file;
next();
}
}
}
function pipelineStringify(p, ctx) {
ctx.file.contents = p.stringify(ctx.tree, ctx.file);
}
// Function to create the first processor.
function unified() {
var attachers = [];
var transformers = trough_1();
var namespace = {};
var frozen = false;
var freezeIndex = -1;
// Data management.
processor.data = data;
// Lock.
processor.freeze = freeze;
// Plugins.
processor.attachers = attachers;
processor.use = use;
// API.
processor.parse = parse;
processor.stringify = stringify;
processor.run = run;
processor.runSync = runSync;
processor.process = process;
processor.processSync = processSync;
// Expose.
return processor
// Create a new processor based on the processor in the current scope.
function processor() {
var destination = unified();
var length = attachers.length;
var index = -1;
while (++index < length) {
destination.use.apply(null, attachers[index]);
}
destination.data(extend$2(true, {}, namespace));
return destination
}
// Freeze: used to signal a processor that has finished configuration.
//
// For example, take unified itself: its frozen.
// Plugins should not be added to it.
// Rather, it should be extended, by invoking it, before modifying it.
//
// In essence, always invoke this when exporting a processor.
function freeze() {
var values;
var plugin;
var options;
var transformer;
if (frozen) {
return processor
}
while (++freezeIndex < attachers.length) {
values = attachers[freezeIndex];
plugin = values[0];
options = values[1];
transformer = null;
if (options === false) {
continue
}
if (options === true) {
values[1] = undefined;
}
transformer = plugin.apply(processor, values.slice(1));
if (typeof transformer === 'function') {
transformers.use(transformer);
}
}
frozen = true;
freezeIndex = Infinity;
return processor
}
// Data management.
// Getter / setter for processor-specific informtion.
function data(key, value) {
if (typeof key === 'string') {
// Set `key`.
if (arguments.length === 2) {
assertUnfrozen('data', frozen);
namespace[key] = value;
return processor
}
// Get `key`.
return (own$1.call(namespace, key) && namespace[key]) || null
}
// Set space.
if (key) {
assertUnfrozen('data', frozen);
namespace = key;
return processor
}
// Get space.
return namespace
}
// Plugin management.
//
// Pass it:
// * an attacher and options,
// * a preset,
// * a list of presets, attachers, and arguments (list of attachers and
// options).
function use(value) {
var settings;
assertUnfrozen('use', frozen);
if (value === null || value === undefined) ; else if (typeof value === 'function') {
addPlugin.apply(null, arguments);
} else if (typeof value === 'object') {
if ('length' in value) {
addList(value);
} else {
addPreset(value);
}
} else {
throw new Error('Expected usable value, not `' + value + '`')
}
if (settings) {
namespace.settings = extend$2(namespace.settings || {}, settings);
}
return processor
function addPreset(result) {
addList(result.plugins);
if (result.settings) {
settings = extend$2(settings || {}, result.settings);
}
}
function add(value) {
if (typeof value === 'function') {
addPlugin(value);
} else if (typeof value === 'object') {
if ('length' in value) {
addPlugin.apply(null, value);
} else {
addPreset(value);
}
} else {
throw new Error('Expected usable value, not `' + value + '`')
}
}
function addList(plugins) {
var length;
var index;
if (plugins === null || plugins === undefined) ; else if (typeof plugins === 'object' && 'length' in plugins) {
length = plugins.length;
index = -1;
while (++index < length) {
add(plugins[index]);
}
} else {
throw new Error('Expected a list of plugins, not `' + plugins + '`')
}
}
function addPlugin(plugin, value) {
var entry = find(plugin);
if (entry) {
if (isPlainObj(entry[1]) && isPlainObj(value)) {
value = extend$2(entry[1], value);
}
entry[1] = value;
} else {
attachers.push(slice.call(arguments));
}
}
}
function find(plugin) {
var length = attachers.length;
var index = -1;
var entry;
while (++index < length) {
entry = attachers[index];
if (entry[0] === plugin) {
return entry
}
}
}
// Parse a file (in string or vfile representation) into a unist node using
// the `Parser` on the processor.
function parse(doc) {
var file = vfile(doc);
var Parser;
freeze();
Parser = processor.Parser;
assertParser('parse', Parser);
if (newable(Parser, 'parse')) {
return new Parser(String(file), file).parse()
}
return Parser(String(file), file) // eslint-disable-line new-cap
}
// Run transforms on a unist node representation of a file (in string or
// vfile representation), async.
function run(node, file, cb) {
assertNode(node);
freeze();
if (!cb && typeof file === 'function') {
cb = file;
file = null;
}
if (!cb) {
return new Promise(executor)
}
executor(null, cb);
function executor(resolve, reject) {
transformers.run(node, vfile(file), done);
function done(err, tree, file) {
tree = tree || node;
if (err) {
reject(err);
} else if (resolve) {
resolve(tree);
} else {
cb(null, tree, file);
}
}
}
}
// Run transforms on a unist node representation of a file (in string or
// vfile representation), sync.
function runSync(node, file) {
var complete = false;
var result;
run(node, file, done);
assertDone('runSync', 'run', complete);
return result
function done(err, tree) {
complete = true;
bail_1(err);
result = tree;
}
}
// Stringify a unist node representation of a file (in string or vfile
// representation) into a string using the `Compiler` on the processor.
function stringify(node, doc) {
var file = vfile(doc);
var Compiler;
freeze();
Compiler = processor.Compiler;
assertCompiler('stringify', Compiler);
assertNode(node);
if (newable(Compiler, 'compile')) {
return new Compiler(node, file).compile()
}
return Compiler(node, file) // eslint-disable-line new-cap
}
// Parse a file (in string or vfile representation) into a unist node using
// the `Parser` on the processor, then run transforms on that node, and
// compile the resulting node using the `Compiler` on the processor, and
// store that result on the vfile.
function process(doc, cb) {
freeze();
assertParser('process', processor.Parser);
assertCompiler('process', processor.Compiler);
if (!cb) {
return new Promise(executor)
}
executor(null, cb);
function executor(resolve, reject) {
var file = vfile(doc);
pipeline.run(processor, {file: file}, done);
function done(err) {
if (err) {
reject(err);
} else if (resolve) {
resolve(file);
} else {
cb(null, file);
}
}
}
}
// Process the given document (in string or vfile representation), sync.
function processSync(doc) {
var complete = false;
var file;
freeze();
assertParser('processSync', processor.Parser);
assertCompiler('processSync', processor.Compiler);
file = vfile(doc);
process(file, done);
assertDone('processSync', 'process', complete);
return file
function done(err) {
complete = true;
bail_1(err);
}
}
}
// Check if `value` is a constructor.
function newable(value, name) {
return (
typeof value === 'function' &&
value.prototype &&
// A function with keys in its prototype is probably a constructor.
// Classes prototype methods are not enumerable, so we check if some value
// exists in the prototype.
(keys(value.prototype) || name in value.prototype)
)
}
// Check if `value` is an object with keys.
function keys(value) {
var key;
for (key in value) {
return true
}
return false
}
// Assert a parser is available.
function assertParser(name, Parser) {
if (typeof Parser !== 'function') {
throw new Error('Cannot `' + name + '` without `Parser`')
}
}
// Assert a compiler is available.
function assertCompiler(name, Compiler) {
if (typeof Compiler !== 'function') {
throw new Error('Cannot `' + name + '` without `Compiler`')
}
}
// Assert the processor is not frozen.
function assertUnfrozen(name, frozen) {
if (frozen) {
throw new Error(
'Cannot invoke `' +
name +
'` on a frozen processor.\nCreate a new processor first, by invoking it: use `processor()` instead of `processor`.'
)
}
}
// Assert `node` is a unist node.
function assertNode(node) {
if (!node || typeof node.type !== 'string') {
throw new Error('Expected node, got `' + node + '`')
}
}
// Assert that `complete` is `true`.
function assertDone(name, asyncName, complete) {
if (!complete) {
throw new Error(
'`' + name + '` finished async. Use `' + asyncName + '` instead'
)
}
}
var nlcstToString_1 = nlcstToString;
// Stringify one nlcst node or list of nodes.
function nlcstToString(node, separator) {
var sep = separator || '';
var values;
var length;
var children;
if (!node || (!('length' in node) && !node.type)) {
throw new Error('Expected node, not `' + node + '`')
}
if (typeof node.value === 'string') {
return node.value
}
children = 'length' in node ? node : node.children;
length = children.length;
// Shortcut: This is pretty common, and a small performance win.
if (length === 1 && 'value' in children[0]) {
return children[0].value
}
values = [];
while (length--) {
values[length] = nlcstToString(children[length], sep);
}
return values.join(sep)
}
var tokenizer = tokenizerFactory;
// Factory to create a tokenizer based on a given `expression`.
function tokenizerFactory(childType, expression) {
return tokenizer
// A function that splits.
function tokenizer(node) {
var children = [];
var tokens = node.children;
var type = node.type;
var length = tokens.length;
var index = -1;
var lastIndex = length - 1;
var start = 0;
var first;
var last;
var parent;
while (++index < length) {
if (
index === lastIndex ||
(tokens[index].type === childType &&
expression.test(nlcstToString_1(tokens[index])))
) {
first = tokens[start];
last = tokens[index];
parent = {
type: type,
children: tokens.slice(start, index + 1)
};
if (first.position && last.position) {
parent.position = {
start: first.position.start,
end: last.position.end
};
}
children.push(parent);
start = index + 1;
}
}
return children
}
}
var parser = parserFactory;
// Construct a parser based on `options`.
function parserFactory(options) {
var type = options.type;
var tokenizerProperty = options.tokenizer;
var delimiter = options.delimiter;
var tokenize = delimiter && tokenizer(options.delimiterType, delimiter);
return parser
function parser(value) {
var children = this[tokenizerProperty](value);
return {
type: type,
children: tokenize ? tokenize(children) : children
}
}
}
// This module is generated by `script/build-expressions.js`.
var expressions = {
affixSymbol: /^([\)\]\}\u0F3B\u0F3D\u169C\u2046\u207E\u208E\u2309\u230B\u232A\u2769\u276B\u276D\u276F\u2771\u2773\u2775\u27C6\u27E7\u27E9\u27EB\u27ED\u27EF\u2984\u2986\u2988\u298A\u298C\u298E\u2990\u2992\u2994\u2996\u2998\u29D9\u29DB\u29FD\u2E23\u2E25\u2E27\u2E29\u3009\u300B\u300D\u300F\u3011\u3015\u3017\u3019\u301B\u301E\u301F\uFD3E\uFE18\uFE36\uFE38\uFE3A\uFE3C\uFE3E\uFE40\uFE42\uFE44\uFE48\uFE5A\uFE5C\uFE5E\uFF09\uFF3D\uFF5D\uFF60\uFF63]|["'\xBB\u2019\u201D\u203A\u2E03\u2E05\u2E0A\u2E0D\u2E1D\u2E21]|[!\.\?\u2026\u203D])\1*$/,
newLine: /^[ \t]*((\r?\n|\r)[\t ]*)+$/,
newLineMulti: /^[ \t]*((\r?\n|\r)[\t ]*){2,}$/,
terminalMarker: /^((?:[!\.\?\u2026\u203D])+)$/,
wordSymbolInner: /^((?:[&'\x2D\.:=\?@\xAD\xB7\u2010\u2011\u2019\u2027])|(?:_)+)$/,
numerical: /^(?:[0-9\xB2\xB3\xB9\xBC-\xBE\u0660-\u0669\u06F0-\u06F9\u07C0-\u07C9\u0966-\u096F\u09E6-\u09EF\u09F4-\u09F9\u0A66-\u0A6F\u0AE6-\u0AEF\u0B66-\u0B6F\u0B72-\u0B77\u0BE6-\u0BF2\u0C66-\u0C6F\u0C78-\u0C7E\u0CE6-\u0CEF\u0D58-\u0D5E\u0D66-\u0D78\u0DE6-\u0DEF\u0E50-\u0E59\u0ED0-\u0ED9\u0F20-\u0F33\u1040-\u1049\u1090-\u1099\u1369-\u137C\u16EE-\u16F0\u17E0-\u17E9\u17F0-\u17F9\u1810-\u1819\u1946-\u194F\u19D0-\u19DA\u1A80-\u1A89\u1A90-\u1A99\u1B50-\u1B59\u1BB0-\u1BB9\u1C40-\u1C49\u1C50-\u1C59\u2070\u2074-\u2079\u2080-\u2089\u2150-\u2182\u2185-\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2CFD\u3007\u3021-\u3029\u3038-\u303A\u3192-\u3195\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\uA620-\uA629\uA6E6-\uA6EF\uA830-\uA835\uA8D0-\uA8D9\uA900-\uA909\uA9D0-\uA9D9\uA9F0-\uA9F9\uAA50-\uAA59\uABF0-\uABF9\uFF10-\uFF19]|\uD800[\uDD07-\uDD33\uDD40-\uDD78\uDD8A\uDD8B\uDEE1-\uDEFB\uDF20-\uDF23\uDF41\uDF4A\uDFD1-\uDFD5]|\uD801[\uDCA0-\uDCA9]|\uD802[\uDC58-\uDC5F\uDC79-\uDC7F\uDCA7-\uDCAF\uDCFB-\uDCFF\uDD16-\uDD1B\uDDBC\uDDBD\uDDC0-\uDDCF\uDDD2-\uDDFF\uDE40-\uDE48\uDE7D\uDE7E\uDE9D-\uDE9F\uDEEB-\uDEEF\uDF58-\uDF5F\uDF78-\uDF7F\uDFA9-\uDFAF]|\uD803[\uDCFA-\uDCFF\uDD30-\uDD39\uDE60-\uDE7E\uDF1D-\uDF26\uDF51-\uDF54]|\uD804[\uDC52-\uDC6F\uDCF0-\uDCF9\uDD36-\uDD3F\uDDD0-\uDDD9\uDDE1-\uDDF4\uDEF0-\uDEF9]|\uD805[\uDC50-\uDC59\uDCD0-\uDCD9\uDE50-\uDE59\uDEC0-\uDEC9\uDF30-\uDF3B]|\uD806[\uDCE0-\uDCF2]|\uD807[\uDC50-\uDC6C\uDD50-\uDD59\uDDA0-\uDDA9\uDFC0-\uDFD4]|\uD809[\uDC00-\uDC6E]|\uD81A[\uDE60-\uDE69\uDF50-\uDF59\uDF5B-\uDF61]|\uD81B[\uDE80-\uDE96]|\uD834[\uDEE0-\uDEF3\uDF60-\uDF78]|\uD835[\uDFCE-\uDFFF]|\uD838[\uDD40-\uDD49\uDEF0-\uDEF9]|\uD83A[\uDCC7-\uDCCF\uDD50-\uDD59]|\uD83B[\uDC71-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDCB4\uDD01-\uDD2D\uDD2F-\uDD3D]|\uD83C[\uDD00-\uDD0C])+$/,
digitStart: /^\d/,
lowerInitial: /^(?:[a-z\xB5\xDF-\xF6\xF8-\xFF\u0101\u0103\u0105\u0107\u0109\u010B\u010D\u010F\u0111\u0113\u0115\u0117\u0119\u011B\u011D\u011F\u0121\u0123\u0125\u0127\u0129\u012B\u012D\u012F\u0131\u0133\u0135\u0137\u0138\u013A\u013C\u013E\u0140\u0142\u0144\u0146\u0148\u0149\u014B\u014D\u014F\u0151\u0153\u0155\u0157\u0159\u015B\u015D\u015F\u0161\u0163\u0165\u0167\u0169\u016B\u016D\u016F\u0171\u0173\u0175\u0177\u017A\u017C\u017E-\u0180\u0183\u0185\u0188\u018C\u018D\u0192\u0195\u0199-\u019B\u019E\u01A1\u01A3\u01A5\u01A8\u01AA\u01AB\u01AD\u01B0\u01B4\u01B6\u01B9\u01BA\u01BD-\u01BF\u01C6\u01C9\u01CC\u01CE\u01D0\u01D2\u01D4\u01D6\u01D8\u01DA\u01DC\u01DD\u01DF\u01E1\u01E3\u01E5\u01E7\u01E9\u01EB\u01ED\u01EF\u01F0\u01F3\u01F5\u01F9\u01FB\u01FD\u01FF\u0201\u0203\u0205\u0207\u0209\u020B\u020D\u020F\u0211\u0213\u0215\u0217\u0219\u021B\u021D\u021F\u0221\u0223\u0225\u0227\u0229\u022B\u022D\u022F\u0231\u0233-\u0239\u023C\u023F\u0240\u0242\u0247\u0249\u024B\u024D\u024F-\u0293\u0295-\u02AF\u0371\u0373\u0377\u037B-\u037D\u0390\u03AC-\u03CE\u03D0\u03D1\u03D5-\u03D7\u03D9\u03DB\u03DD\u03DF\u03E1\u03E3\u03E5\u03E7\u03E9\u03EB\u03ED\u03EF-\u03F3\u03F5\u03F8\u03FB\u03FC\u0430-\u045F\u0461\u0463\u0465\u0467\u0469\u046B\u046D\u046F\u0471\u0473\u0475\u0477\u0479\u047B\u047D\u047F\u0481\u048B\u048D\u048F\u0491\u0493\u0495\u0497\u0499\u049B\u049D\u049F\u04A1\u04A3\u04A5\u04A7\u04A9\u04AB\u04AD\u04AF\u04B1\u04B3\u04B5\u04B7\u04B9\u04BB\u04BD\u04BF\u04C2\u04C4\u04C6\u04C8\u04CA\u04CC\u04CE\u04CF\u04D1\u04D3\u04D5\u04D7\u04D9\u04DB\u04DD\u04DF\u04E1\u04E3\u04E5\u04E7\u04E9\u04EB\u04ED\u04EF\u04F1\u04F3\u04F5\u04F7\u04F9\u04FB\u04FD\u04FF\u0501\u0503\u0505\u0507\u0509\u050B\u050D\u050F\u0511\u0513\u0515\u0517\u0519\u051B\u051D\u051F\u0521\u0523\u0525\u0527\u0529\u052B\u052D\u052F\u0560-\u0588\u10D0-\u10FA\u10FD-\u10FF\u13F8-\u13FD\u1C80-\u1C88\u1D00-\u1D2B\u1D6B-\u1D77\u1D79-\u1D9A\u1E01\u1E03\u1E05\u1E07\u1E09\u1E0B\u1E0D\u1E0F\u1E11\u1E13\u1E15\u1E17\u1E19\u1E1B\u1E1D\u1E1F\u1E21\u1E23\u1E25\u1E27\u1E29\u1E2B\u1E2D\u1E2F\u1E31\u1E33\u1E35\u1E37\u1E39\u1E3B\u1E3D\u1E3F\u1E41\u1E43\u1E45\u1E47\u1E49\u1E4B\u1E4D\u1E4F\u1E51\u1E53\u1E55\u1E57\u1E59\u1E5B\u1E5D\u1E5F\u1E61\u1E63\u1E65\u1E67\u1E69\u1E6B\u1E6D\u1E6F\u1E71\u1E73\u1E75\u1E77\u1E79\u1E7B\u1E7D\u1E7F\u1E81\u1E83\u1E85\u1E87\u1E89\u1E8B\u1E8D\u1E8F\u1E91\u1E93\u1E95-\u1E9D\u1E9F\u1EA1\u1EA3\u1EA5\u1EA7\u1EA9\u1EAB\u1EAD\u1EAF\u1EB1\u1EB3\u1EB5\u1EB7\u1EB9\u1EBB\u1EBD\u1EBF\u1EC1\u1EC3\u1EC5\u1EC7\u1EC9\u1ECB\u1ECD\u1ECF\u1ED1\u1ED3\u1ED5\u1ED7\u1ED9\u1EDB\u1EDD\u1EDF\u1EE1\u1EE3\u1EE5\u1EE7\u1EE9\u1EEB\u1EED\u1EEF\u1EF1\u1EF3\u1EF5\u1EF7\u1EF9\u1EFB\u1EFD\u1EFF-\u1F07\u1F10-\u1F15\u1F20-\u1F27\u1F30-\u1F37\u1F40-\u1F45\u1F50-\u1F57\u1F60-\u1F67\u1F70-\u1F7D\u1F80-\u1F87\u1F90-\u1F97\u1FA0-\u1FA7\u1FB0-\u1FB4\u1FB6\u1FB7\u1FBE\u1FC2-\u1FC4\u1FC6\u1FC7\u1FD0-\u1FD3\u1FD6\u1FD7\u1FE0-\u1FE7\u1FF2-\u1FF4\u1FF6\u1FF7\u210A\u210E\u210F\u2113\u212F\u2134\u2139\u213C\u213D\u2146-\u2149\u214E\u2184\u2C30-\u2C5E\u2C61\u2C65\u2C66\u2C68\u2C6A\u2C6C\u2C71\u2C73\u2C74\u2C76-\u2C7B\u2C81\u2C83\u2C85\u2C87\u2C89\u2C8B\u2C8D\u2C8F\u2C91\u2C93\u2C95\u2C97\u2C99\u2C9B\u2C9D\u2C9F\u2CA1\u2CA3\u2CA5\u2CA7\u2CA9\u2CAB\u2CAD\u2CAF\u2CB1\u2CB3\u2CB5\u2CB7\u2CB9\u2CBB\u2CBD\u2CBF\u2CC1\u2CC3\u2CC5\u2CC7\u2CC9\u2CCB\u2CCD\u2CCF\u2CD1\u2CD3\u2CD5\u2CD7\u2CD9\u2CDB\u2CDD\u2CDF\u2CE1\u2CE3\u2CE4\u2CEC\u2CEE\u2CF3\u2D00-\u2D25\u2D27\u2D2D\uA641\uA643\uA645\uA647\uA649\uA64B\uA64D\uA64F\uA651\uA653\uA655\uA657\uA659\uA65B\uA65D\uA65F\uA661\uA663\uA665\uA667\uA669\uA66B\uA66D\uA681\uA683\uA685\uA687\uA689\uA68B\uA68D\uA68F\uA691\uA693\uA695\uA697\uA699\uA69B\uA723\uA725\uA727\uA729\uA72B\uA72D\uA72F-\uA731\uA733\uA735\uA737\uA739\uA73B\uA73D\uA73F\uA741\uA743\uA745\uA747\uA749\uA74B\uA74D\uA74F\uA751\uA753\uA755\uA757\uA759\uA75B\uA75D\uA75F\uA761\uA763\uA765\uA767\uA769\uA76B\uA76D\uA76F\uA771-\uA778\uA77A\uA77C\uA77F\uA781\uA783\uA785\uA787\uA78C\uA78E\uA791\uA793-\uA795\uA797\uA799\uA79B\uA79D\uA79F\uA7A1\uA7A3\uA7A5\uA7A7\uA7A9\uA7AF\uA7B5\uA7B7\uA7B9\uA7BB\uA7BD\uA7BF\uA7C3\uA7FA\uAB30-\uAB5A\uAB60-\uAB67\uAB70-\uABBF\uFB00-\uFB06\uFB13-\uFB17\uFF41-\uFF5A]|\uD801[\uDC28-\uDC4F\uDCD8-\uDCFB]|\uD803[\uDCC0-\uDCF2]|\uD806[\uDCC0-\uDCDF]|\uD81B[\uDE60-\uDE7F]|\uD835[\uDC1A-\uDC33\uDC4E-\uDC54\uDC56-\uDC67\uDC82-\uDC9B\uDCB6-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDCCF\uDCEA-\uDD03\uDD1E-\uDD37\uDD52-\uDD6B\uDD86-\uDD9F\uDDBA-\uDDD3\uDDEE-\uDE07\uDE22-\uDE3B\uDE56-\uDE6F\uDE8A-\uDEA5\uDEC2-\uDEDA\uDEDC-\uDEE1\uDEFC-\uDF14\uDF16-\uDF1B\uDF36-\uDF4E\uDF50-\uDF55\uDF70-\uDF88\uDF8A-\uDF8F\uDFAA-\uDFC2\uDFC4-\uDFC9\uDFCB]|\uD83A[\uDD22-\uDD43])/,
surrogates: /[\uD800-\uDFFF]/,
punctuation: /[!"'-\),-\/:;\?\[-\]_\{\}\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u201F\u2022-\u2027\u2032-\u203A\u203C-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD803[\uDF55-\uDF59]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC8\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDC4B-\uDC4F\uDC5B\uDC5D\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDE60-\uDE6C\uDF3C-\uDF3E]|\uD806[\uDC3B\uDDE2\uDE3F-\uDE46\uDE9A-\uDE9C\uDE9E-\uDEA2]|\uD807[\uDC41-\uDC45\uDC70\uDC71\uDEF7\uDEF8\uDFFF]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD81B[\uDE97-\uDE9A\uDFE2]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]|\uD83A[\uDD5E\uDD5F]/,
word: /[0-9A-Za-z\xAA\xB2\xB3\xB5\xB9\xBA\xBC-\xBE\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u052F\u0531-\u0556\u0559\u0560-\u0588\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05EF-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u07FD\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D3-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09F4-\u09F9\u09FC\u09FE\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71-\u0B77\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BF2\u0C00-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C78-\u0C7E\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D63\u0D66-\u0D78\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F33\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u17F0-\u17F9\u180B-\u180D\u1810-\u1819\u1820-\u1878\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABE\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CD0-\u1CD2\u1CD4-\u1CFA\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2070\u2071\u2074-\u2079\u207F-\u2089\u2090-\u209C\u20D0-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2CFD\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3192-\u3195\u31A0-\u31BA\u31F0-\u31FF\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DB5\u4E00-\u9FEF\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7BF\uA7C2-\uA7C6\uA7F7-\uA827\uA830-\uA835\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB67\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD07-\uDD33\uDD40-\uDD78\uDD8A\uDD8B\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0-\uDEFB\uDF00-\uDF23\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC58-\uDC76\uDC79-\uDC9E\uDCA7-\uDCAF\uDCE0-\uDCF2\uDCF4\uDCF5\uDCFB-\uDD1B\uDD20-\uDD39\uDD80-\uDDB7\uDDBC-\uDDCF\uDDD2-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE38-\uDE3A\uDE3F-\uDE48\uDE60-\uDE7E\uDE80-\uDE9F\uDEC0-\uDEC7\uDEC9-\uDEE6\uDEEB-\uDEEF\uDF00-\uDF35\uDF40-\uDF55\uDF58-\uDF72\uDF78-\uDF91\uDFA9-\uDFAF]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDCFA-\uDD27\uDD30-\uDD39\uDE60-\uDE7E\uDF00-\uDF27\uDF30-\uDF54\uDFE0-\uDFF6]|\uD804[\uDC00-\uDC46\uDC52-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD44-\uDD46\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDC9-\uDDCC\uDDD0-\uDDDA\uDDDC\uDDE1-\uDDF4\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3B-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC5E\uDC5F\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF1D-\uDF2B\uDF30-\uDF3B]|\uD806[\uDC00-\uDC3A\uDCA0-\uDCF2\uDCFF\uDDA0-\uDDA7\uDDAA-\uDDD7\uDDDA-\uDDE1\uDDE3\uDDE4\uDE00-\uDE3E\uDE47\uDE50-\uDE99\uDE9D\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC6C\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD8E\uDD90\uDD91\uDD93-\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF6\uDFC0-\uDFD4]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF5B-\uDF61\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE96\uDF00-\uDF4A\uDF4F-\uDF87\uDF8F-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44\uDEE0-\uDEF3\uDF60-\uDF78]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A\uDD00-\uDD2C\uDD30-\uDD3D\uDD40-\uDD49\uDD4E\uDEC0-\uDEF9]|\uD83A[\uDC00-\uDCC4\uDCC7-\uDCD6\uDD00-\uDD4B\uDD50-\uDD59]|\uD83B[\uDC71-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDCB4\uDD01-\uDD2D\uDD2F-\uDD3D\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD83C[\uDD00-\uDD0C]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/,
whiteSpace: /[\t-\r \x85\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/
};
var arrayIterate = iterate;
var own = {}.hasOwnProperty;
function iterate(values, callback, context) {
var index = -1;
var result;
if (!values) {
throw new Error('Iterate requires that |this| not be ' + values)
}
if (!own.call(values, 'length')) {
throw new Error('Iterate requires that |this| has a `length`')
}
if (typeof callback !== 'function') {
throw new Error('`callback` must be a function')
}
// The length might change, so we do not cache it.
while (++index < values.length) {
// Skip missing values.
if (!(index in values)) {
continue
}
result = callback.call(context, values[index], index, values);
// If `callback` returns a `number`, move `index` over to `number`.
if (typeof result === 'number') {
// Make sure that negative numbers do not break the loop.
if (result < 0) {
index = 0;
}
index = result - 1;
}
}
}
var unistUtilModifyChildren = modifierFactory;
// Turn `callback` into a child-modifier accepting a parent. See
// `array-iterate` for more info.
function modifierFactory(callback) {
return iteratorFactory(wrapperFactory(callback))
}
// Turn `callback` into a `iterator' accepting a parent.
function iteratorFactory(callback) {
return iterator
function iterator(parent) {
var children = parent && parent.children;
if (!children) {
throw new Error('Missing children in `parent` for `modifier`')
}
return arrayIterate(children, callback, parent)
}
}
// Pass the context as the third argument to `callback`.
function wrapperFactory(callback) {
return wrapper
function wrapper(value, index) {
return callback(value, index, this)
}
}
var mergeInitialWordSymbol_1 = unistUtilModifyChildren(mergeInitialWordSymbol);
// Merge certain punctuation marks into their following words.
function mergeInitialWordSymbol(child, index, parent) {
var children;
var next;
if (
(child.type !== 'SymbolNode' && child.type !== 'PunctuationNode') ||
nlcstToString_1(child) !== '&'
) {
return
}
children = parent.children;
next = children[index + 1];
// If either a previous word, or no following word, exists, exit early.
if (
(index !== 0 && children[index - 1].type === 'WordNode') ||
!(next && next.type === 'WordNode')
) {
return
}
// Remove `child` from parent.
children.splice(index, 1);
// Add the punctuation mark at the start of the next node.
next.children.unshift(child);
// Update position.
if (next.position && child.position) {
next.position.start = child.position.start;
}
// Next, iterate over the node at the previous position, as it's now adjacent
// to a following word.
return index - 1
}
var mergeFinalWordSymbol_1 = unistUtilModifyChildren(mergeFinalWordSymbol$1);
// Merge certain punctuation marks into their preceding words.
function mergeFinalWordSymbol$1(child, index, parent) {
var children;
var prev;
var next;
if (
index !== 0 &&
(child.type === 'SymbolNode' || child.type === 'PunctuationNode') &&
nlcstToString_1(child) === '-'
) {
children = parent.children;
prev = children[index - 1];
next = children[index + 1];
if (
(!next || next.type !== 'WordNode') &&
prev &&
prev.type === 'WordNode'
) {
// Remove `child` from parent.
children.splice(index, 1);
// Add the punctuation mark at the end of the previous node.
prev.children.push(child);
// Update position.
if (prev.position && child.position) {
prev.position.end = child.position.end;
}
// Next, iterate over the node *now* at the current position (which was
// the next node).
return index
}
}
}
var mergeInnerWordSymbol_1 = unistUtilModifyChildren(mergeInnerWordSymbol);
// Symbols part of surrounding words.
var wordSymbolInner = expressions.wordSymbolInner;
// Merge words joined by certain punctuation marks.
function mergeInnerWordSymbol(child, index, parent) {
var siblings;
var sibling;
var prev;
var last;
var position;
var tokens;
var queue;
if (
index !== 0 &&
(child.type === 'SymbolNode' || child.type === 'PunctuationNode')
) {
siblings = parent.children;
prev = siblings[index - 1];
if (prev && prev.type === 'WordNode') {
position = index - 1;
tokens = [];
queue = [];
// - If a token which is neither word nor inner word symbol is found,
// the loop is broken
// - If an inner word symbol is found, its queued
// - If a word is found, its queued (and the queue stored and emptied)
while (siblings[++position]) {
sibling = siblings[position];
if (sibling.type === 'WordNode') {
tokens = tokens.concat(queue, sibling.children);
queue = [];
} else if (
(sibling.type === 'SymbolNode' ||
sibling.type === 'PunctuationNode') &&
wordSymbolInner.test(nlcstToString_1(sibling))
) {
queue.push(sibling);
} else {
break
}
}
if (tokens.length !== 0) {
// If there is a queue, remove its length from `position`.
if (queue.length !== 0) {
position -= queue.length;
}
// Remove every (one or more) inner-word punctuation marks and children
// of words.
siblings.splice(index, position - index);
// Add all found tokens to `prev`s children.
prev.children = prev.children.concat(tokens);
last = tokens[tokens.length - 1];
// Update position.
if (prev.position && last.position) {
prev.position.end = last.position.end;
}
// Next, iterate over the node *now* at the current position.
return index
}
}
}
}
var mergeInnerWordSlash_1 = unistUtilModifyChildren(mergeInnerWordSlash);
var slash = '/';
// Merge words joined by certain punctuation marks.
function mergeInnerWordSlash(child, index, parent) {
var siblings = parent.children;
var prev;
var next;
var prevValue;
var nextValue;
var queue;
var tail;
var count;
prev = siblings[index - 1];
next = siblings[index + 1];
if (
prev &&
prev.type === 'WordNode' &&
(child.type === 'SymbolNode' || child.type === 'PunctuationNode') &&
nlcstToString_1(child) === slash
) {
prevValue = nlcstToString_1(prev);
tail = child;
queue = [child];
count = 1;
if (next && next.type === 'WordNode') {
nextValue = nlcstToString_1(next);
tail = next;
queue = queue.concat(next.children);
count++;
}
if (prevValue.length < 3 && (!nextValue || nextValue.length < 3)) {
// Add all found tokens to `prev`s children.
prev.children = prev.children.concat(queue);
siblings.splice(index, count);
// Update position.
if (prev.position && tail.position) {
prev.position.end = tail.position.end;
}
// Next, iterate over the node *now* at the current position.
return index
}
}
}
var mergeInitialisms_1 = unistUtilModifyChildren(mergeInitialisms);
var numerical = expressions.numerical;
// Merge initialisms.
function mergeInitialisms(child, index, parent) {
var siblings;
var prev;
var children;
var length;
var position;
var otherChild;
var isAllDigits;
var value;
if (index !== 0 && nlcstToString_1(child) === '.') {
siblings = parent.children;
prev = siblings[index - 1];
children = prev.children;
length = children && children.length;
if (prev.type === 'WordNode' && length !== 1 && length % 2 !== 0) {
position = length;
isAllDigits = true;
while (children[--position]) {
otherChild = children[position];
value = nlcstToString_1(otherChild);
if (position % 2 === 0) {
// Initialisms consist of one character values.
if (value.length > 1) {
return
}
if (!numerical.test(value)) {
isAllDigits = false;
}
} else if (value !== '.') {
if (position < length - 2) {
break
} else {
return
}
}
}
if (!isAllDigits) {
// Remove `child` from parent.
siblings.splice(index, 1);
// Add child to the previous children.
children.push(child);
// Update position.
if (prev.position && child.position) {
prev.position.end = child.position.end;
}
// Next, iterate over the node *now* at the current position.
return index
}
}
}
}
var mergeWords = unistUtilModifyChildren(mergeFinalWordSymbol);
// Merge multiple words. This merges the children of adjacent words, something
// which should not occur naturally by parse-latin, but might happen when custom
// tokens were passed in.
function mergeFinalWordSymbol(child, index, parent) {
var siblings = parent.children;
var next;
if (child.type === 'WordNode') {
next = siblings[index + 1];
if (next && next.type === 'WordNode') {
// Remove `next` from parent.
siblings.splice(index + 1, 1);
// Add the punctuation mark at the end of the previous node.
child.children = child.children.concat(next.children);
// Update position.
if (next.position && child.position) {
child.position.end = next.position.end;
}
// Next, re-iterate the current node.
return index
}
}
}
var unistUtilVisitChildren = visitChildren;
function visitChildren(callback) {
return visitor
// Visit `parent`, invoking `callback` for each child.
function visitor(parent) {
var index = -1;
var children = parent && parent.children;
if (!children) {
throw new Error('Missing children in `parent` for `visitor`')
}
while (++index in children) {
callback(children[index], index, parent);
}
}
}
var patchPosition_1 = unistUtilVisitChildren(patchPosition);
// Patch the position on a parent node based on its first and last child.
function patchPosition(child, index, node) {
var siblings = node.children;
if (!child.position) {
return
}
if (
index === 0 &&
(!node.position || /* istanbul ignore next */ !node.position.start)
) {
patch(node);
node.position.start = child.position.start;
}
if (index === siblings.length - 1 && (!node.position || !node.position.end)) {
patch(node);
node.position.end = child.position.end;
}
}
// Add a `position` object when it does not yet exist on `node`.
function patch(node) {
if (!node.position) {
node.position = {};
}
}
var mergeNonWordSentences_1 = unistUtilModifyChildren(mergeNonWordSentences);
// Merge a sentence into the following sentence, when the sentence does not
// contain word tokens.
function mergeNonWordSentences(child, index, parent) {
var children = child.children;
var position = -1;
var prev;
var next;
while (children[++position]) {
if (children[position].type === 'WordNode') {
return
}
}
prev = parent.children[index - 1];
if (prev) {
prev.children = prev.children.concat(children);
// Remove the child.
parent.children.splice(index, 1);
// Patch position.
if (prev.position && child.position) {
prev.position.end = child.position.end;
}
// Next, iterate over the node *now* at the current position (which was the
// next node).
return index
}
next = parent.children[index + 1];
if (next) {
next.children = children.concat(next.children);
// Patch position.
if (next.position && child.position) {
next.position.start = child.position.start;
}
// Remove the child.
parent.children.splice(index, 1);
}
}
var mergeAffixSymbol_1 = unistUtilModifyChildren(mergeAffixSymbol);
// Closing or final punctuation, or terminal markers that should still be
// included in the previous sentence, even though they follow the sentences
// terminal marker.
var affixSymbol = expressions.affixSymbol;
// Move certain punctuation following a terminal marker (thus in the next
// sentence) to the previous sentence.
function mergeAffixSymbol(child, index, parent) {
var children = child.children;
var first;
var second;
var prev;
if (children && children.length !== 0 && index !== 0) {
first = children[0];
second = children[1];
prev = parent.children[index - 1];
if (
(first.type === 'SymbolNode' || first.type === 'PunctuationNode') &&
affixSymbol.test(nlcstToString_1(first))
) {
prev.children.push(children.shift());
// Update position.
if (first.position && prev.position) {
prev.position.end = first.position.end;
}
if (second && second.position && child.position) {
child.position.start = second.position.start;
}
// Next, iterate over the previous node again.
return index - 1
}
}
}
var mergeInitialLowerCaseLetterSentences_1 = unistUtilModifyChildren(mergeInitialLowerCaseLetterSentences);
// Initial lowercase letter.
var lowerInitial = expressions.lowerInitial;
// Merge a sentence into its previous sentence, when the sentence starts with a
// lower case letter.
function mergeInitialLowerCaseLetterSentences(child, index, parent) {
var children = child.children;
var position;
var node;
var siblings;
var prev;
if (children && children.length !== 0 && index !== 0) {
position = -1;
while (children[++position]) {
node = children[position];
if (node.type === 'WordNode') {
if (!lowerInitial.test(nlcstToString_1(node))) {
return
}
siblings = parent.children;
prev = siblings[index - 1];
prev.children = prev.children.concat(children);
siblings.splice(index, 1);
// Update position.
if (prev.position && child.position) {
prev.position.end = child.position.end;
}
// Next, iterate over the node *now* at the current position.
return index
}
if (node.type === 'SymbolNode' || node.type === 'PunctuationNode') {
return
}
}
}
}
var mergeInitialDigitSentences_1 = unistUtilModifyChildren(mergeInitialDigitSentences);
// Initial lowercase letter.
var digit = expressions.digitStart;
// Merge a sentence into its previous sentence, when the sentence starts with a
// lower case letter.
function mergeInitialDigitSentences(child, index, parent) {
var children = child.children;
var siblings = parent.children;
var prev = siblings[index - 1];
var head = children[0];
if (prev && head && head.type === 'WordNode' && digit.test(nlcstToString_1(head))) {
prev.children = prev.children.concat(children);
siblings.splice(index, 1);
// Update position.
if (prev.position && child.position) {
prev.position.end = child.position.end;
}
// Next, iterate over the node *now* at the current position.
return index
}
}
var mergePrefixExceptions_1 = unistUtilModifyChildren(mergePrefixExceptions);
// Blacklist of full stop characters that should not be treated as terminal
// sentence markers: A case-insensitive abbreviation.
var abbreviationPrefix = new RegExp(
'^(' +
'[0-9]{1,3}|' +
'[a-z]|' +
// Common Latin Abbreviations:
// Based on: <https://en.wikipedia.org/wiki/List_of_Latin_abbreviations>.
// Where only the abbreviations written without joining full stops,
// but with a final full stop, were extracted.
//
// circa, capitulus, confer, compare, centum weight, eadem, (et) alii,
// et cetera, floruit, foliis, ibidem, idem, nemine && contradicente,
// opere && citato, (per) cent, (per) procurationem, (pro) tempore,
// sic erat scriptum, (et) sequentia, statim, videlicet. */
'al|ca|cap|cca|cent|cf|cit|con|cp|cwt|ead|etc|ff|' +
'fl|ibid|id|nem|op|pro|seq|sic|stat|tem|viz' +
')$'
);
// Merge a sentence into its next sentence, when the sentence ends with a
// certain word.
function mergePrefixExceptions(child, index, parent) {
var children = child.children;
var period;
var node;
var next;
if (children && children.length > 1) {
period = children[children.length - 1];
if (period && nlcstToString_1(period) === '.') {
node = children[children.length - 2];
if (
node &&
node.type === 'WordNode' &&
abbreviationPrefix.test(nlcstToString_1(node).toLowerCase())
) {
// Merge period into abbreviation.
node.children.push(period);
children.pop();
// Update position.
if (period.position && node.position) {
node.position.end = period.position.end;
}
// Merge sentences.
next = parent.children[index + 1];
if (next) {
child.children = children.concat(next.children);
parent.children.splice(index + 1, 1);
// Update position.
if (next.position && child.position) {
child.position.end = next.position.end;
}
// Next, iterate over the current node again.
return index - 1
}
}
}
}
}
var mergeAffixExceptions_1 = unistUtilModifyChildren(mergeAffixExceptions);
// Merge a sentence into its previous sentence, when the sentence starts with a
// comma.
function mergeAffixExceptions(child, index, parent) {
var children = child.children;
var node;
var position;
var value;
var previousChild;
if (!children || children.length === 0 || index === 0) {
return
}
position = -1;
while (children[++position]) {
node = children[position];
if (node.type === 'WordNode') {
return
}
if (node.type === 'SymbolNode' || node.type === 'PunctuationNode') {
value = nlcstToString_1(node);
if (value !== ',' && value !== ';') {
return
}
previousChild = parent.children[index - 1];
previousChild.children = previousChild.children.concat(children);
// Update position.
if (previousChild.position && child.position) {
previousChild.position.end = child.position.end;
}
parent.children.splice(index, 1);
// Next, iterate over the node *now* at the current position.
return index
}
}
}
var mergeRemainingFullStops_1 = unistUtilVisitChildren(mergeRemainingFullStops);
// Blacklist of full stop characters that should not be treated as terminal
// sentence markers: A case-insensitive abbreviation.
var terminalMarker = expressions.terminalMarker;
// Merge non-terminal-marker full stops into the previous word (if available),
// or the next word (if available).
function mergeRemainingFullStops(child) {
var children = child.children;
var position = children.length;
var hasFoundDelimiter = false;
var grandchild;
var prev;
var next;
var nextNext;
while (children[--position]) {
grandchild = children[position];
if (
grandchild.type !== 'SymbolNode' &&
grandchild.type !== 'PunctuationNode'
) {
// This is a sentence without terminal marker, so we 'fool' the code to
// make it think we have found one.
if (grandchild.type === 'WordNode') {
hasFoundDelimiter = true;
}
continue
}
// Exit when this token is not a terminal marker.
if (!terminalMarker.test(nlcstToString_1(grandchild))) {
continue
}
// Ignore the first terminal marker found (starting at the end), as it
// should not be merged.
if (!hasFoundDelimiter) {
hasFoundDelimiter = true;
continue
}
// Only merge a single full stop.
if (nlcstToString_1(grandchild) !== '.') {
continue
}
prev = children[position - 1];
next = children[position + 1];
if (prev && prev.type === 'WordNode') {
nextNext = children[position + 2];
// Continue when the full stop is followed by a space and another full
// stop, such as: `{.} .`
if (
next &&
nextNext &&
next.type === 'WhiteSpaceNode' &&
nlcstToString_1(nextNext) === '.'
) {
continue
}
// Remove `child` from parent.
children.splice(position, 1);
// Add the punctuation mark at the end of the previous node.
prev.children.push(grandchild);
// Update position.
if (grandchild.position && prev.position) {
prev.position.end = grandchild.position.end;
}
position--;
} else if (next && next.type === 'WordNode') {
// Remove `child` from parent.
children.splice(position, 1);
// Add the punctuation mark at the start of the next node.
next.children.unshift(grandchild);
if (grandchild.position && next.position) {
next.position.start = grandchild.position.start;
}
}
}
}
var makeInitialWhiteSpaceSiblings_1 = unistUtilVisitChildren(makeInitialWhiteSpaceSiblings);
// Move white space starting a sentence up, so they are the siblings of
// sentences.
function makeInitialWhiteSpaceSiblings(child, index, parent) {
var children = child.children;
var next;
if (
children &&
children.length !== 0 &&
children[0].type === 'WhiteSpaceNode'
) {
parent.children.splice(index, 0, children.shift());
next = children[0];
if (next && next.position && child.position) {
child.position.start = next.position.start;
}
}
}
var makeFinalWhiteSpaceSiblings_1 = unistUtilModifyChildren(makeFinalWhiteSpaceSiblings);
// Move white space ending a paragraph up, so they are the siblings of
// paragraphs.
function makeFinalWhiteSpaceSiblings(child, index, parent) {
var children = child.children;
var prev;
if (
children &&
children.length !== 0 &&
children[children.length - 1].type === 'WhiteSpaceNode'
) {
parent.children.splice(index + 1, 0, child.children.pop());
prev = children[children.length - 1];
if (prev && prev.position && child.position) {
child.position.end = prev.position.end;
}
// Next, iterate over the current node again.
return index
}
}
var breakImplicitSentences_1 = unistUtilModifyChildren(breakImplicitSentences);
// Two or more new line characters.
var multiNewLine = expressions.newLineMulti;
// Break a sentence if a white space with more than one new-line is found.
function breakImplicitSentences(child, index, parent) {
var children;
var position;
var length;
var tail;
var head;
var end;
var insertion;
var node;
if (child.type !== 'SentenceNode') {
return
}
children = child.children;
// Ignore first and last child.
length = children.length - 1;
position = 0;
while (++position < length) {
node = children[position];
if (node.type !== 'WhiteSpaceNode' || !multiNewLine.test(nlcstToString_1(node))) {
continue
}
child.children = children.slice(0, position);
insertion = {
type: 'SentenceNode',
children: children.slice(position + 1)
};
tail = children[position - 1];
head = children[position + 1];
parent.children.splice(index + 1, 0, node, insertion);
if (child.position && tail.position && head.position) {
end = child.position.end;
child.position.end = tail.position.end;
insertion.position = {
start: head.position.start,
end: end
};
}
return index + 1
}
}
var removeEmptyNodes_1 = unistUtilModifyChildren(removeEmptyNodes);
// Remove empty children.
function removeEmptyNodes(child, index, parent) {
if ('children' in child && child.children.length === 0) {
parent.children.splice(index, 1);
// Next, iterate over the node *now* at the current position (which was the
// next node).
return index
}
}
var lib = ParseLatin;
// PARSE LATIN
// Transform Latin-script natural language into an NLCST-tree.
function ParseLatin(doc, file) {
var value = file || doc;
if (!(this instanceof ParseLatin)) {
return new ParseLatin(doc, file)
}
this.doc = value ? String(value) : null;
}
// Quick access to the prototype.
var proto = ParseLatin.prototype;
// Default position.
proto.position = true;
// Create text nodes.
proto.tokenizeSymbol = createTextFactory('Symbol');
proto.tokenizeWhiteSpace = createTextFactory('WhiteSpace');
proto.tokenizePunctuation = createTextFactory('Punctuation');
proto.tokenizeSource = createTextFactory('Source');
proto.tokenizeText = createTextFactory('Text');
// Expose `run`.
proto.run = run;
// Inject `plugins` to modifiy the result of the method at `key` on the operated
// on context.
proto.use = useFactory(function(context, key, plugins) {
context[key] = context[key].concat(plugins);
});
// Inject `plugins` to modifiy the result of the method at `key` on the operated
// on context, before any other.
proto.useFirst = useFactory(function(context, key, plugins) {
context[key] = plugins.concat(context[key]);
});
// Easy access to the document parser. This additionally supports retext-style
// invocation: where an instance is created for each file, and the file is given
// on construction.
proto.parse = function(value) {
return this.tokenizeRoot(value || this.doc)
};
// Transform a `value` into a list of `NLCSTNode`s.
proto.tokenize = function(value) {
return tokenize(this, value)
};
// PARENT NODES
//
// All these nodes are `pluggable`: they come with a `use` method which accepts
// a plugin (`function(NLCSTNode)`).
// Every time one of these methods are called, the plugin is invoked with the
// node, allowing for easy modification.
//
// In fact, the internal transformation from `tokenize` (a list of words, white
// space, punctuation, and symbols) to `tokenizeRoot` (an NLCST tree), is also
// implemented through this mechanism.
// Create a `WordNode` with its children set to a single `TextNode`, its value
// set to the given `value`.
pluggable(ParseLatin, 'tokenizeWord', function(value, eat) {
var add = (eat || noopEat)('');
var parent = {type: 'WordNode', children: []};
this.tokenizeText(value, eat, parent);
return add(parent)
});
// Create a `SentenceNode` with its children set to `Node`s, their values set
// to the tokenized given `value`.
//
// Unless plugins add new nodes, the sentence is populated by `WordNode`s,
// `SymbolNode`s, `PunctuationNode`s, and `WhiteSpaceNode`s.
pluggable(
ParseLatin,
'tokenizeSentence',
parser({
type: 'SentenceNode',
tokenizer: 'tokenize'
})
);
// Create a `ParagraphNode` with its children set to `Node`s, their values set
// to the tokenized given `value`.
//
// Unless plugins add new nodes, the paragraph is populated by `SentenceNode`s
// and `WhiteSpaceNode`s.
pluggable(
ParseLatin,
'tokenizeParagraph',
parser({
type: 'ParagraphNode',
delimiter: expressions.terminalMarker,
delimiterType: 'PunctuationNode',
tokenizer: 'tokenizeSentence'
})
);
// Create a `RootNode` with its children set to `Node`s, their values set to the
// tokenized given `value`.
pluggable(
ParseLatin,
'tokenizeRoot',
parser({
type: 'RootNode',
delimiter: expressions.newLine,
delimiterType: 'WhiteSpaceNode',
tokenizer: 'tokenizeParagraph'
})
);
// PLUGINS
proto.use('tokenizeSentence', [
mergeInitialWordSymbol_1,
mergeFinalWordSymbol_1,
mergeInnerWordSymbol_1,
mergeInnerWordSlash_1,
mergeInitialisms_1,
mergeWords,
patchPosition_1
]);
proto.use('tokenizeParagraph', [
mergeNonWordSentences_1,
mergeAffixSymbol_1,
mergeInitialLowerCaseLetterSentences_1,
mergeInitialDigitSentences_1,
mergePrefixExceptions_1,
mergeAffixExceptions_1,
mergeRemainingFullStops_1,
makeInitialWhiteSpaceSiblings_1,
makeFinalWhiteSpaceSiblings_1,
breakImplicitSentences_1,
removeEmptyNodes_1,
patchPosition_1
]);
proto.use('tokenizeRoot', [
makeInitialWhiteSpaceSiblings_1,
makeFinalWhiteSpaceSiblings_1,
removeEmptyNodes_1,
patchPosition_1
]);
// TEXT NODES
// Factory to create a `Text`.
function createTextFactory(type) {
type += 'Node';
return createText
// Construct a `Text` from a bound `type`
function createText(value, eat, parent) {
if (value === null || value === undefined) {
value = '';
}
return (eat || noopEat)(value)(
{
type: type,
value: String(value)
},
parent
)
}
}
// Run transform plug-ins for `key` on `nodes`.
function run(key, nodes) {
var wareKey = key + 'Plugins';
var plugins = this[wareKey];
var index = -1;
if (plugins) {
while (plugins[++index]) {
plugins[index](nodes);
}
}
return nodes
}
// Make a method “pluggable”.
function pluggable(Constructor, key, callback) {
// Set a pluggable version of `callback` on `Constructor`.
Constructor.prototype[key] = function() {
return this.run(key, callback.apply(this, arguments))
};
}
// Factory to inject `plugins`. Takes `callback` for the actual inserting.
function useFactory(callback) {
return use
// Validate if `plugins` can be inserted.
// Invokes the bound `callback` to do the actual inserting.
function use(key, plugins) {
var self = this;
var wareKey;
// Throw if the method is not pluggable.
if (!(key in self)) {
throw new Error(
'Illegal Invocation: Unsupported `key` for ' +
'`use(key, plugins)`. Make sure `key` is a ' +
'supported function'
)
}
// Fail silently when no plugins are given.
if (!plugins) {
return
}
wareKey = key + 'Plugins';
// Make sure `plugins` is a list.
if (typeof plugins === 'function') {
plugins = [plugins];
} else {
plugins = plugins.concat();
}
// Make sure `wareKey` exists.
if (!self[wareKey]) {
self[wareKey] = [];
}
// Invoke callback with the ware key and plugins.
callback(self, wareKey, plugins);
}
}
// CLASSIFY
// Match a word character.
var wordRe = expressions.word;
// Match a surrogate character.
var surrogatesRe = expressions.surrogates;
// Match a punctuation character.
var punctuationRe = expressions.punctuation;
// Match a white space character.
var whiteSpaceRe = expressions.whiteSpace;
// Transform a `value` into a list of `NLCSTNode`s.
function tokenize(parser, value) {
var tokens;
var offset;
var line;
var column;
var index;
var length;
var character;
var queue;
var prev;
var left;
var right;
var eater;
if (value === null || value === undefined) {
value = '';
} else if (value instanceof String) {
value = value.toString();
}
if (typeof value !== 'string') {
// Return the given nodes if this is either an empty array, or an array with
// a node as a first child.
if ('length' in value && (!value[0] || value[0].type)) {
return value
}
throw new Error(
"Illegal invocation: '" +
value +
"' is not a valid argument for 'ParseLatin'"
)
}
tokens = [];
if (!value) {
return tokens
}
index = 0;
offset = 0;
line = 1;
column = 1;
// Eat mechanism to use.
eater = parser.position ? eat : noPositionEat;
length = value.length;
prev = '';
queue = '';
while (index < length) {
character = value.charAt(index);
if (whiteSpaceRe.test(character)) {
right = 'WhiteSpace';
} else if (punctuationRe.test(character)) {
right = 'Punctuation';
} else if (wordRe.test(character)) {
right = 'Word';
} else {
right = 'Symbol';
}
tick();
prev = character;
character = '';
left = right;
right = null;
index++;
}
tick();
return tokens
// Check one character.
function tick() {
if (
left === right &&
(left === 'Word' ||
left === 'WhiteSpace' ||
character === prev ||
surrogatesRe.test(character))
) {
queue += character;
} else {
// Flush the previous queue.
if (queue) {
parser['tokenize' + left](queue, eater);
}
queue = character;
}
}
// Remove `subvalue` from `value`.
// Expects `subvalue` to be at the start from `value`, and applies no
// validation.
function eat(subvalue) {
var pos = position();
update(subvalue);
return apply
// Add the given arguments, add `position` to the returned node, and return
// the node.
function apply() {
return pos(add.apply(null, arguments))
}
}
// Remove `subvalue` from `value`.
// Does not patch positional information.
function noPositionEat() {
return apply
// Add the given arguments and return the node.
function apply() {
return add.apply(null, arguments)
}
}
// Add mechanism.
function add(node, parent) {
if (parent) {
parent.children.push(node);
} else {
tokens.push(node);
}
return node
}
// Mark position and patch `node.position`.
function position() {
var before = now();
// Add the position to a node.
function patch(node) {
node.position = new Position(before);
return node
}
return patch
}
// Update line and column based on `value`.
function update(subvalue) {
var subvalueLength = subvalue.length;
var character = -1;
var lastIndex = -1;
offset += subvalueLength;
while (++character < subvalueLength) {
if (subvalue.charAt(character) === '\n') {
lastIndex = character;
line++;
}
}
if (lastIndex === -1) {
column += subvalueLength;
} else {
column = subvalueLength - lastIndex;
}
}
// Store position information for a node.
function Position(start) {
this.start = start;
this.end = now();
}
// Get the current position.
function now() {
return {
line: line,
column: column,
offset: offset
}
}
}
// Add mechanism used when text-tokenisers are called directly outside of the
// `tokenize` function.
function noopAdd(node, parent) {
if (parent) {
parent.children.push(node);
}
return node
}
// Eat and add mechanism without adding positional information, used when
// text-tokenisers are called directly outside of the `tokenize` function.
function noopEat() {
return noopAdd
}
var parseLatin = lib;
var retextLatin = parse$1;
parse$1.Parser = parseLatin;
function parse$1() {
this.Parser = unherit_1(parseLatin);
}
var retextStringify = stringify$1;
function stringify$1() {
this.Compiler = compiler;
}
function compiler(tree) {
return nlcstToString_1(tree)
}
var retext = unified_1()
.use(retextLatin)
.use(retextStringify)
.freeze();
var retextSmartypants = smartypants;
var punctuation = 'PunctuationNode';
var symbol = 'SymbolNode';
var word = 'WordNode';
var whiteSpace = 'WhiteSpaceNode';
var decadeExpression = /^\d\ds$/;
var threeFullStopsExpression = /^\.{3,}$/;
var fullStopsExpression = /^\.+$/;
var threeDashes = '---';
var twoDashes = '--';
var emDash = '—';
var enDash = '';
var ellipsis = '…';
var twoBackticks = '``';
var backtick = '`';
var twoSingleQuotes = "''";
var singleQuote = "'";
var apostrophe = '';
var doubleQuote = '"';
var openingDoubleQuote = '“';
var closingDoubleQuote = '”';
var openingSingleQuote = '';
var closingSingleQuote = '';
var closingQuotes = {};
var openingQuotes = {};
openingQuotes[doubleQuote] = openingDoubleQuote;
closingQuotes[doubleQuote] = closingDoubleQuote;
openingQuotes[singleQuote] = openingSingleQuote;
closingQuotes[singleQuote] = closingSingleQuote;
var educators = {};
// Expose educators.
educators.dashes = {
true: dashes,
oldschool: oldschool,
inverted: inverted
};
educators.backticks = {
true: backticks,
all: all
};
educators.ellipses = {
true: ellipses
};
educators.quotes = {
true: quotes
};
// Attacher.
function smartypants(options) {
var methods = [];
var quotes;
var ellipses;
var backticks;
var dashes;
if (!options) {
options = {};
}
if ('quotes' in options) {
quotes = options.quotes;
if (quotes !== Boolean(quotes)) {
throw new TypeError(
'Illegal invocation: `' +
quotes +
'` ' +
'is not a valid value for `quotes` in ' +
'`smartypants`'
)
}
} else {
quotes = true;
}
if ('ellipses' in options) {
ellipses = options.ellipses;
if (ellipses !== Boolean(ellipses)) {
throw new TypeError(
'Illegal invocation: `' +
ellipses +
'` ' +
'is not a valid value for `ellipses` in ' +
'`smartypants`'
)
}
} else {
ellipses = true;
}
if ('backticks' in options) {
backticks = options.backticks;
if (backticks !== Boolean(backticks) && backticks !== 'all') {
throw new TypeError(
'Illegal invocation: `' +
backticks +
'` ' +
'is not a valid value for `backticks` in ' +
'`smartypants`'
)
}
if (backticks === 'all' && quotes === true) {
throw new TypeError(
'Illegal invocation: `backticks: ' +
backticks +
'` is not a valid value ' +
'when `quotes: ' +
quotes +
'` in ' +
'`smartypants`'
)
}
} else {
backticks = true;
}
if ('dashes' in options) {
dashes = options.dashes;
if (
dashes !== Boolean(dashes) &&
dashes !== 'oldschool' &&
dashes !== 'inverted'
) {
throw new TypeError(
'Illegal invocation: `' +
dashes +
'` ' +
'is not a valid value for `dahes` in ' +
'`smartypants`'
)
}
} else {
dashes = true;
}
if (quotes !== false) {
methods.push(educators.quotes[quotes]);
}
if (ellipses !== false) {
methods.push(educators.ellipses[ellipses]);
}
if (backticks !== false) {
methods.push(educators.backticks[backticks]);
}
if (dashes !== false) {
methods.push(educators.dashes[dashes]);
}
return transformFactory(methods)
}
// Create a transformer for the bound methods.
function transformFactory(methods) {
var length = methods.length;
return transformer
// Transformer.
function transformer(tree) {
unistUtilVisit(tree, visitor);
}
function visitor(node, position, parent) {
var index = -1;
if (node.type === punctuation || node.type === symbol) {
while (++index < length) {
methods[index](node, position, parent);
}
}
}
}
// Transform three dahes into an em-dash, and two into an en-dash.
function oldschool(node) {
if (node.value === threeDashes) {
node.value = emDash;
} else if (node.value === twoDashes) {
node.value = enDash;
}
}
// Transform two dahes into an em-dash.
function dashes(node) {
if (node.value === twoDashes) {
node.value = emDash;
}
}
// Transform three dahes into an en-dash, and two into an em-dash.
function inverted(node) {
if (node.value === threeDashes) {
node.value = enDash;
} else if (node.value === twoDashes) {
node.value = emDash;
}
}
// Transform double backticks and single quotes into smart quotes.
function backticks(node) {
if (node.value === twoBackticks) {
node.value = openingDoubleQuote;
} else if (node.value === twoSingleQuotes) {
node.value = closingDoubleQuote;
}
}
// Transform single and double backticks and single quotes into smart quotes.
function all(node) {
backticks(node);
if (node.value === backtick) {
node.value = openingSingleQuote;
} else if (node.value === singleQuote) {
node.value = closingSingleQuote;
}
}
// Transform multiple dots into unicode ellipses.
function ellipses(node, index, parent) {
var value = node.value;
var siblings = parent.children;
var position;
var nodes;
var sibling;
var type;
var count;
var queue;
// Simple node with three dots and without white-space.
if (threeFullStopsExpression.test(node.value)) {
node.value = ellipsis;
return
}
if (!fullStopsExpression.test(value)) {
return
}
// Search for dot-nodes with white-space between.
nodes = [];
position = index;
count = 1;
// Its possible that the node is merged with an adjacent word-node. In that
// code, we cannot transform it because theres no reference to the
// grandparent.
while (--position > 0) {
sibling = siblings[position];
if (sibling.type !== whiteSpace) {
break
}
queue = sibling;
sibling = siblings[--position];
type = sibling && sibling.type;
if (
sibling &&
(type === punctuation || type === symbol) &&
fullStopsExpression.test(sibling.value)
) {
nodes.push(queue, sibling);
count++;
continue
}
break
}
if (count < 3) {
return
}
siblings.splice(index - nodes.length, nodes.length);
node.value = ellipsis;
}
// Transform straight single- and double quotes into smart quotes.
// eslint-disable-next-line complexity
function quotes(node, index, parent) {
var siblings = parent.children;
var value = node.value;
var next;
var nextNext;
var prev;
var nextValue;
if (value !== doubleQuote && value !== singleQuote) {
return
}
prev = siblings[index - 1];
next = siblings[index + 1];
nextNext = siblings[index + 2];
nextValue = next && nlcstToString_1(next);
if (
next &&
nextNext &&
(next.type === punctuation || next.type === symbol) &&
nextNext.type !== word
) {
// Special case if the very first character is a quote followed by
// punctuation at a non-word-break. Close the quotes by brute force.
node.value = closingQuotes[value];
} else if (
nextNext &&
(nextValue === doubleQuote || nextValue === singleQuote) &&
nextNext.type === word
) {
// Special case for double sets of quotes:
// `He said, "'Quoted' words in a larger quote."`
node.value = openingQuotes[value];
next.value = openingQuotes[nextValue];
} else if (next && decadeExpression.test(nextValue)) {
// Special case for decade abbreviations: `the '80s`
node.value = closingQuotes[value];
} else if (
prev &&
next &&
(prev.type === whiteSpace ||
prev.type === punctuation ||
prev.type === symbol) &&
next.type === word
) {
// Get most opening single quotes.
node.value = openingQuotes[value];
} else if (
prev &&
prev.type !== whiteSpace &&
prev.type !== symbol &&
prev.type !== punctuation
) {
// Closing quotes.
node.value = closingQuotes[value];
} else if (
!next ||
next.type === whiteSpace ||
((value === singleQuote || value === apostrophe) && nextValue === 's')
) {
node.value = closingQuotes[value];
} else {
node.value = openingQuotes[value];
}
}
function isNothing(subject) {
return (typeof subject === 'undefined') || (subject === null);
}
function isObject(subject) {
return (typeof subject === 'object') && (subject !== null);
}
function toArray(sequence) {
if (Array.isArray(sequence)) return sequence;
else if (isNothing(sequence)) return [];
return [ sequence ];
}
function extend(target, source) {
var index, length, key, sourceKeys;
if (source) {
sourceKeys = Object.keys(source);
for (index = 0, length = sourceKeys.length; index < length; index += 1) {
key = sourceKeys[index];
target[key] = source[key];
}
}
return target;
}
function repeat(string, count) {
var result = '', cycle;
for (cycle = 0; cycle < count; cycle += 1) {
result += string;
}
return result;
}
function isNegativeZero(number) {
return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
}
var isNothing_1 = isNothing;
var isObject_1 = isObject;
var toArray_1 = toArray;
var repeat_1 = repeat;
var isNegativeZero_1 = isNegativeZero;
var extend_1 = extend;
var common = {
isNothing: isNothing_1,
isObject: isObject_1,
toArray: toArray_1,
repeat: repeat_1,
isNegativeZero: isNegativeZero_1,
extend: extend_1
};
// YAML error class. http://stackoverflow.com/questions/8458984
function YAMLException$1(reason, mark) {
// Super constructor
Error.call(this);
this.name = 'YAMLException';
this.reason = reason;
this.mark = mark;
this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
// Include stack trace in error object
if (Error.captureStackTrace) {
// Chrome and NodeJS
Error.captureStackTrace(this, this.constructor);
} else {
// FF, IE 10+ and Safari 6+. Fallback for others
this.stack = (new Error()).stack || '';
}
}
// Inherit from Error
YAMLException$1.prototype = Object.create(Error.prototype);
YAMLException$1.prototype.constructor = YAMLException$1;
YAMLException$1.prototype.toString = function toString(compact) {
var result = this.name + ': ';
result += this.reason || '(unknown reason)';
if (!compact && this.mark) {
result += ' ' + this.mark.toString();
}
return result;
};
var exception = YAMLException$1;
function Mark(name, buffer, position, line, column) {
this.name = name;
this.buffer = buffer;
this.position = position;
this.line = line;
this.column = column;
}
Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
var head, start, tail, end, snippet;
if (!this.buffer) return null;
indent = indent || 4;
maxLength = maxLength || 75;
head = '';
start = this.position;
while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
start -= 1;
if (this.position - start > (maxLength / 2 - 1)) {
head = ' ... ';
start += 5;
break;
}
}
tail = '';
end = this.position;
while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
end += 1;
if (end - this.position > (maxLength / 2 - 1)) {
tail = ' ... ';
end -= 5;
break;
}
}
snippet = this.buffer.slice(start, end);
return common.repeat(' ', indent) + head + snippet + tail + '\n' +
common.repeat(' ', indent + this.position - start + head.length) + '^';
};
Mark.prototype.toString = function toString(compact) {
var snippet, where = '';
if (this.name) {
where += 'in "' + this.name + '" ';
}
where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
if (!compact) {
snippet = this.getSnippet();
if (snippet) {
where += ':\n' + snippet;
}
}
return where;
};
var mark = Mark;
var TYPE_CONSTRUCTOR_OPTIONS = [
'kind',
'resolve',
'construct',
'instanceOf',
'predicate',
'represent',
'defaultStyle',
'styleAliases'
];
var YAML_NODE_KINDS = [
'scalar',
'sequence',
'mapping'
];
function compileStyleAliases(map) {
var result = {};
if (map !== null) {
Object.keys(map).forEach(function (style) {
map[style].forEach(function (alias) {
result[String(alias)] = style;
});
});
}
return result;
}
function Type$1(tag, options) {
options = options || {};
Object.keys(options).forEach(function (name) {
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
}
});
// TODO: Add tag format check.
this.tag = tag;
this.kind = options['kind'] || null;
this.resolve = options['resolve'] || function () { return true; };
this.construct = options['construct'] || function (data) { return data; };
this.instanceOf = options['instanceOf'] || null;
this.predicate = options['predicate'] || null;
this.represent = options['represent'] || null;
this.defaultStyle = options['defaultStyle'] || null;
this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
}
}
var type = Type$1;
/*eslint-disable max-len*/
function compileList(schema, name, result) {
var exclude = [];
schema.include.forEach(function (includedSchema) {
result = compileList(includedSchema, name, result);
});
schema[name].forEach(function (currentType) {
result.forEach(function (previousType, previousIndex) {
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
exclude.push(previousIndex);
}
});
result.push(currentType);
});
return result.filter(function (type, index) {
return exclude.indexOf(index) === -1;
});
}
function compileMap(/* lists... */) {
var result = {
scalar: {},
sequence: {},
mapping: {},
fallback: {}
}, index, length;
function collectType(type) {
result[type.kind][type.tag] = result['fallback'][type.tag] = type;
}
for (index = 0, length = arguments.length; index < length; index += 1) {
arguments[index].forEach(collectType);
}
return result;
}
function Schema$1(definition) {
this.include = definition.include || [];
this.implicit = definition.implicit || [];
this.explicit = definition.explicit || [];
this.implicit.forEach(function (type) {
if (type.loadKind && type.loadKind !== 'scalar') {
throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
}
});
this.compiledImplicit = compileList(this, 'implicit', []);
this.compiledExplicit = compileList(this, 'explicit', []);
this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
}
Schema$1.DEFAULT = null;
Schema$1.create = function createSchema() {
var schemas, types;
switch (arguments.length) {
case 1:
schemas = Schema$1.DEFAULT;
types = arguments[0];
break;
case 2:
schemas = arguments[0];
types = arguments[1];
break;
default:
throw new exception('Wrong number of arguments for Schema.create function');
}
schemas = common.toArray(schemas);
types = common.toArray(types);
if (!schemas.every(function (schema) { return schema instanceof Schema$1; })) {
throw new exception('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
}
if (!types.every(function (type$1) { return type$1 instanceof type; })) {
throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
}
return new Schema$1({
include: schemas,
explicit: types
});
};
var schema = Schema$1;
var str = new type('tag:yaml.org,2002:str', {
kind: 'scalar',
construct: function (data) { return data !== null ? data : ''; }
});
var seq = new type('tag:yaml.org,2002:seq', {
kind: 'sequence',
construct: function (data) { return data !== null ? data : []; }
});
var map = new type('tag:yaml.org,2002:map', {
kind: 'mapping',
construct: function (data) { return data !== null ? data : {}; }
});
var failsafe = new schema({
explicit: [
str,
seq,
map
]
});
function resolveYamlNull(data) {
if (data === null) return true;
var max = data.length;
return (max === 1 && data === '~') ||
(max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
}
function constructYamlNull() {
return null;
}
function isNull(object) {
return object === null;
}
var _null = new type('tag:yaml.org,2002:null', {
kind: 'scalar',
resolve: resolveYamlNull,
construct: constructYamlNull,
predicate: isNull,
represent: {
canonical: function () { return '~'; },
lowercase: function () { return 'null'; },
uppercase: function () { return 'NULL'; },
camelcase: function () { return 'Null'; }
},
defaultStyle: 'lowercase'
});
function resolveYamlBoolean(data) {
if (data === null) return false;
var max = data.length;
return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
(max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
}
function constructYamlBoolean(data) {
return data === 'true' ||
data === 'True' ||
data === 'TRUE';
}
function isBoolean(object) {
return Object.prototype.toString.call(object) === '[object Boolean]';
}
var bool = new type('tag:yaml.org,2002:bool', {
kind: 'scalar',
resolve: resolveYamlBoolean,
construct: constructYamlBoolean,
predicate: isBoolean,
represent: {
lowercase: function (object) { return object ? 'true' : 'false'; },
uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
camelcase: function (object) { return object ? 'True' : 'False'; }
},
defaultStyle: 'lowercase'
});
function isHexCode(c) {
return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
((0x61/* a */ <= c) && (c <= 0x66/* f */));
}
function isOctCode(c) {
return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
}
function isDecCode(c) {
return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
}
function resolveYamlInteger(data) {
if (data === null) return false;
var max = data.length,
index = 0,
hasDigits = false,
ch;
if (!max) return false;
ch = data[index];
// sign
if (ch === '-' || ch === '+') {
ch = data[++index];
}
if (ch === '0') {
// 0
if (index + 1 === max) return true;
ch = data[++index];
// base 2, base 8, base 16
if (ch === 'b') {
// base 2
index++;
for (; index < max; index++) {
ch = data[index];
if (ch === '_') continue;
if (ch !== '0' && ch !== '1') return false;
hasDigits = true;
}
return hasDigits && ch !== '_';
}
if (ch === 'x') {
// base 16
index++;
for (; index < max; index++) {
ch = data[index];
if (ch === '_') continue;
if (!isHexCode(data.charCodeAt(index))) return false;
hasDigits = true;
}
return hasDigits && ch !== '_';
}
// base 8
for (; index < max; index++) {
ch = data[index];
if (ch === '_') continue;
if (!isOctCode(data.charCodeAt(index))) return false;
hasDigits = true;
}
return hasDigits && ch !== '_';
}
// base 10 (except 0) or base 60
// value should not start with `_`;
if (ch === '_') return false;
for (; index < max; index++) {
ch = data[index];
if (ch === '_') continue;
if (ch === ':') break;
if (!isDecCode(data.charCodeAt(index))) {
return false;
}
hasDigits = true;
}
// Should have digits and should not end with `_`
if (!hasDigits || ch === '_') return false;
// if !base60 - done;
if (ch !== ':') return true;
// base60 almost not used, no needs to optimize
return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
}
function constructYamlInteger(data) {
var value = data, sign = 1, ch, base, digits = [];
if (value.indexOf('_') !== -1) {
value = value.replace(/_/g, '');
}
ch = value[0];
if (ch === '-' || ch === '+') {
if (ch === '-') sign = -1;
value = value.slice(1);
ch = value[0];
}
if (value === '0') return 0;
if (ch === '0') {
if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
if (value[1] === 'x') return sign * parseInt(value, 16);
return sign * parseInt(value, 8);
}
if (value.indexOf(':') !== -1) {
value.split(':').forEach(function (v) {
digits.unshift(parseInt(v, 10));
});
value = 0;
base = 1;
digits.forEach(function (d) {
value += (d * base);
base *= 60;
});
return sign * value;
}
return sign * parseInt(value, 10);
}
function isInteger(object) {
return (Object.prototype.toString.call(object)) === '[object Number]' &&
(object % 1 === 0 && !common.isNegativeZero(object));
}
var int_1 = new type('tag:yaml.org,2002:int', {
kind: 'scalar',
resolve: resolveYamlInteger,
construct: constructYamlInteger,
predicate: isInteger,
represent: {
binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1); },
octal: function (obj) { return obj >= 0 ? '0' + obj.toString(8) : '-0' + obj.toString(8).slice(1); },
decimal: function (obj) { return obj.toString(10); },
/* eslint-disable max-len */
hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1); }
},
defaultStyle: 'decimal',
styleAliases: {
binary: [ 2, 'bin' ],
octal: [ 8, 'oct' ],
decimal: [ 10, 'dec' ],
hexadecimal: [ 16, 'hex' ]
}
});
var YAML_FLOAT_PATTERN = new RegExp(
// 2.5e4, 2.5 and integers
'^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' +
// .2e4, .2
// special case, seems not from spec
'|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' +
// 20:59
'|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
// .inf
'|[-+]?\\.(?:inf|Inf|INF)' +
// .nan
'|\\.(?:nan|NaN|NAN))$');
function resolveYamlFloat(data) {
if (data === null) return false;
if (!YAML_FLOAT_PATTERN.test(data) ||
// Quick hack to not allow integers end with `_`
// Probably should update regexp & check speed
data[data.length - 1] === '_') {
return false;
}
return true;
}
function constructYamlFloat(data) {
var value, sign, base, digits;
value = data.replace(/_/g, '').toLowerCase();
sign = value[0] === '-' ? -1 : 1;
digits = [];
if ('+-'.indexOf(value[0]) >= 0) {
value = value.slice(1);
}
if (value === '.inf') {
return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
} else if (value === '.nan') {
return NaN;
} else if (value.indexOf(':') >= 0) {
value.split(':').forEach(function (v) {
digits.unshift(parseFloat(v, 10));
});
value = 0.0;
base = 1;
digits.forEach(function (d) {
value += d * base;
base *= 60;
});
return sign * value;
}
return sign * parseFloat(value, 10);
}
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
function representYamlFloat(object, style) {
var res;
if (isNaN(object)) {
switch (style) {
case 'lowercase': return '.nan';
case 'uppercase': return '.NAN';
case 'camelcase': return '.NaN';
}
} else if (Number.POSITIVE_INFINITY === object) {
switch (style) {
case 'lowercase': return '.inf';
case 'uppercase': return '.INF';
case 'camelcase': return '.Inf';
}
} else if (Number.NEGATIVE_INFINITY === object) {
switch (style) {
case 'lowercase': return '-.inf';
case 'uppercase': return '-.INF';
case 'camelcase': return '-.Inf';
}
} else if (common.isNegativeZero(object)) {
return '-0.0';
}
res = object.toString(10);
// JS stringifier can build scientific format without dots: 5e-100,
// while YAML requres dot: 5.e-100. Fix it with simple hack
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
}
function isFloat(object) {
return (Object.prototype.toString.call(object) === '[object Number]') &&
(object % 1 !== 0 || common.isNegativeZero(object));
}
var float_1 = new type('tag:yaml.org,2002:float', {
kind: 'scalar',
resolve: resolveYamlFloat,
construct: constructYamlFloat,
predicate: isFloat,
represent: representYamlFloat,
defaultStyle: 'lowercase'
});
var json = new schema({
include: [
failsafe
],
implicit: [
_null,
bool,
int_1,
float_1
]
});
var core = new schema({
include: [
json
]
});
var YAML_DATE_REGEXP = new RegExp(
'^([0-9][0-9][0-9][0-9])' + // [1] year
'-([0-9][0-9])' + // [2] month
'-([0-9][0-9])$'); // [3] day
var YAML_TIMESTAMP_REGEXP = new RegExp(
'^([0-9][0-9][0-9][0-9])' + // [1] year
'-([0-9][0-9]?)' + // [2] month
'-([0-9][0-9]?)' + // [3] day
'(?:[Tt]|[ \\t]+)' + // ...
'([0-9][0-9]?)' + // [4] hour
':([0-9][0-9])' + // [5] minute
':([0-9][0-9])' + // [6] second
'(?:\\.([0-9]*))?' + // [7] fraction
'(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
'(?::([0-9][0-9]))?))?$'); // [11] tz_minute
function resolveYamlTimestamp(data) {
if (data === null) return false;
if (YAML_DATE_REGEXP.exec(data) !== null) return true;
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
return false;
}
function constructYamlTimestamp(data) {
var match, year, month, day, hour, minute, second, fraction = 0,
delta = null, tz_hour, tz_minute, date;
match = YAML_DATE_REGEXP.exec(data);
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
if (match === null) throw new Error('Date resolve error');
// match: [1] year [2] month [3] day
year = +(match[1]);
month = +(match[2]) - 1; // JS month starts with 0
day = +(match[3]);
if (!match[4]) { // no hour
return new Date(Date.UTC(year, month, day));
}
// match: [4] hour [5] minute [6] second [7] fraction
hour = +(match[4]);
minute = +(match[5]);
second = +(match[6]);
if (match[7]) {
fraction = match[7].slice(0, 3);
while (fraction.length < 3) { // milli-seconds
fraction += '0';
}
fraction = +fraction;
}
// match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
if (match[9]) {
tz_hour = +(match[10]);
tz_minute = +(match[11] || 0);
delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
if (match[9] === '-') delta = -delta;
}
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
if (delta) date.setTime(date.getTime() - delta);
return date;
}
function representYamlTimestamp(object /*, style*/) {
return object.toISOString();
}
var timestamp = new type('tag:yaml.org,2002:timestamp', {
kind: 'scalar',
resolve: resolveYamlTimestamp,
construct: constructYamlTimestamp,
instanceOf: Date,
represent: representYamlTimestamp
});
function resolveYamlMerge(data) {
return data === '<<' || data === null;
}
var merge = new type('tag:yaml.org,2002:merge', {
kind: 'scalar',
resolve: resolveYamlMerge
});
/*eslint-disable no-bitwise*/
var NodeBuffer;
try {
// A trick for browserified version, to not include `Buffer` shim
var _require$1 = commonjsRequire;
NodeBuffer = _require$1('buffer').Buffer;
} catch (__) {}
// [ 64, 65, 66 ] -> [ padding, CR, LF ]
var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
function resolveYamlBinary(data) {
if (data === null) return false;
var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
// Convert one by one.
for (idx = 0; idx < max; idx++) {
code = map.indexOf(data.charAt(idx));
// Skip CR/LF
if (code > 64) continue;
// Fail on illegal characters
if (code < 0) return false;
bitlen += 6;
}
// If there are any bits left, source was corrupted
return (bitlen % 8) === 0;
}
function constructYamlBinary(data) {
var idx, tailbits,
input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
max = input.length,
map = BASE64_MAP,
bits = 0,
result = [];
// Collect by 6*4 bits (3 bytes)
for (idx = 0; idx < max; idx++) {
if ((idx % 4 === 0) && idx) {
result.push((bits >> 16) & 0xFF);
result.push((bits >> 8) & 0xFF);
result.push(bits & 0xFF);
}
bits = (bits << 6) | map.indexOf(input.charAt(idx));
}
// Dump tail
tailbits = (max % 4) * 6;
if (tailbits === 0) {
result.push((bits >> 16) & 0xFF);
result.push((bits >> 8) & 0xFF);
result.push(bits & 0xFF);
} else if (tailbits === 18) {
result.push((bits >> 10) & 0xFF);
result.push((bits >> 2) & 0xFF);
} else if (tailbits === 12) {
result.push((bits >> 4) & 0xFF);
}
// Wrap into Buffer for NodeJS and leave Array for browser
if (NodeBuffer) {
// Support node 6.+ Buffer API when available
return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result);
}
return result;
}
function representYamlBinary(object /*, style*/) {
var result = '', bits = 0, idx, tail,
max = object.length,
map = BASE64_MAP;
// Convert every three bytes to 4 ASCII characters.
for (idx = 0; idx < max; idx++) {
if ((idx % 3 === 0) && idx) {
result += map[(bits >> 18) & 0x3F];
result += map[(bits >> 12) & 0x3F];
result += map[(bits >> 6) & 0x3F];
result += map[bits & 0x3F];
}
bits = (bits << 8) + object[idx];
}
// Dump tail
tail = max % 3;
if (tail === 0) {
result += map[(bits >> 18) & 0x3F];
result += map[(bits >> 12) & 0x3F];
result += map[(bits >> 6) & 0x3F];
result += map[bits & 0x3F];
} else if (tail === 2) {
result += map[(bits >> 10) & 0x3F];
result += map[(bits >> 4) & 0x3F];
result += map[(bits << 2) & 0x3F];
result += map[64];
} else if (tail === 1) {
result += map[(bits >> 2) & 0x3F];
result += map[(bits << 4) & 0x3F];
result += map[64];
result += map[64];
}
return result;
}
function isBinary(object) {
return NodeBuffer && NodeBuffer.isBuffer(object);
}
var binary = new type('tag:yaml.org,2002:binary', {
kind: 'scalar',
resolve: resolveYamlBinary,
construct: constructYamlBinary,
predicate: isBinary,
represent: representYamlBinary
});
var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
var _toString$2 = Object.prototype.toString;
function resolveYamlOmap(data) {
if (data === null) return true;
var objectKeys = [], index, length, pair, pairKey, pairHasKey,
object = data;
for (index = 0, length = object.length; index < length; index += 1) {
pair = object[index];
pairHasKey = false;
if (_toString$2.call(pair) !== '[object Object]') return false;
for (pairKey in pair) {
if (_hasOwnProperty$3.call(pair, pairKey)) {
if (!pairHasKey) pairHasKey = true;
else return false;
}
}
if (!pairHasKey) return false;
if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
else return false;
}
return true;
}
function constructYamlOmap(data) {
return data !== null ? data : [];
}
var omap = new type('tag:yaml.org,2002:omap', {
kind: 'sequence',
resolve: resolveYamlOmap,
construct: constructYamlOmap
});
var _toString$1 = Object.prototype.toString;
function resolveYamlPairs(data) {
if (data === null) return true;
var index, length, pair, keys, result,
object = data;
result = new Array(object.length);
for (index = 0, length = object.length; index < length; index += 1) {
pair = object[index];
if (_toString$1.call(pair) !== '[object Object]') return false;
keys = Object.keys(pair);
if (keys.length !== 1) return false;
result[index] = [ keys[0], pair[keys[0]] ];
}
return true;
}
function constructYamlPairs(data) {
if (data === null) return [];
var index, length, pair, keys, result,
object = data;
result = new Array(object.length);
for (index = 0, length = object.length; index < length; index += 1) {
pair = object[index];
keys = Object.keys(pair);
result[index] = [ keys[0], pair[keys[0]] ];
}
return result;
}
var pairs = new type('tag:yaml.org,2002:pairs', {
kind: 'sequence',
resolve: resolveYamlPairs,
construct: constructYamlPairs
});
var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
function resolveYamlSet(data) {
if (data === null) return true;
var key, object = data;
for (key in object) {
if (_hasOwnProperty$2.call(object, key)) {
if (object[key] !== null) return false;
}
}
return true;
}
function constructYamlSet(data) {
return data !== null ? data : {};
}
var set = new type('tag:yaml.org,2002:set', {
kind: 'mapping',
resolve: resolveYamlSet,
construct: constructYamlSet
});
var default_safe = new schema({
include: [
core
],
implicit: [
timestamp,
merge
],
explicit: [
binary,
omap,
pairs,
set
]
});
function resolveJavascriptUndefined() {
return true;
}
function constructJavascriptUndefined() {
/*eslint-disable no-undefined*/
return undefined;
}
function representJavascriptUndefined() {
return '';
}
function isUndefined(object) {
return typeof object === 'undefined';
}
var _undefined = new type('tag:yaml.org,2002:js/undefined', {
kind: 'scalar',
resolve: resolveJavascriptUndefined,
construct: constructJavascriptUndefined,
predicate: isUndefined,
represent: representJavascriptUndefined
});
function resolveJavascriptRegExp(data) {
if (data === null) return false;
if (data.length === 0) return false;
var regexp = data,
tail = /\/([gim]*)$/.exec(data),
modifiers = '';
// if regexp starts with '/' it can have modifiers and must be properly closed
// `/foo/gim` - modifiers tail can be maximum 3 chars
if (regexp[0] === '/') {
if (tail) modifiers = tail[1];
if (modifiers.length > 3) return false;
// if expression starts with /, is should be properly terminated
if (regexp[regexp.length - modifiers.length - 1] !== '/') return false;
}
return true;
}
function constructJavascriptRegExp(data) {
var regexp = data,
tail = /\/([gim]*)$/.exec(data),
modifiers = '';
// `/foo/gim` - tail can be maximum 4 chars
if (regexp[0] === '/') {
if (tail) modifiers = tail[1];
regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
}
return new RegExp(regexp, modifiers);
}
function representJavascriptRegExp(object /*, style*/) {
var result = '/' + object.source + '/';
if (object.global) result += 'g';
if (object.multiline) result += 'm';
if (object.ignoreCase) result += 'i';
return result;
}
function isRegExp(object) {
return Object.prototype.toString.call(object) === '[object RegExp]';
}
var regexp = new type('tag:yaml.org,2002:js/regexp', {
kind: 'scalar',
resolve: resolveJavascriptRegExp,
construct: constructJavascriptRegExp,
predicate: isRegExp,
represent: representJavascriptRegExp
});
var esprima;
// Browserified version does not have esprima
//
// 1. For node.js just require module as deps
// 2. For browser try to require mudule via external AMD system.
// If not found - try to fallback to window.esprima. If not
// found too - then fail to parse.
//
try {
// workaround to exclude package from browserify list.
var _require = commonjsRequire;
esprima = _require('esprima');
} catch (_) {
/* eslint-disable no-redeclare */
/* global window */
if (typeof window !== 'undefined') esprima = window.esprima;
}
function resolveJavascriptFunction(data) {
if (data === null) return false;
try {
var source = '(' + data + ')',
ast = esprima.parse(source, { range: true });
if (ast.type !== 'Program' ||
ast.body.length !== 1 ||
ast.body[0].type !== 'ExpressionStatement' ||
(ast.body[0].expression.type !== 'ArrowFunctionExpression' &&
ast.body[0].expression.type !== 'FunctionExpression')) {
return false;
}
return true;
} catch (err) {
return false;
}
}
function constructJavascriptFunction(data) {
/*jslint evil:true*/
var source = '(' + data + ')',
ast = esprima.parse(source, { range: true }),
params = [],
body;
if (ast.type !== 'Program' ||
ast.body.length !== 1 ||
ast.body[0].type !== 'ExpressionStatement' ||
(ast.body[0].expression.type !== 'ArrowFunctionExpression' &&
ast.body[0].expression.type !== 'FunctionExpression')) {
throw new Error('Failed to resolve function');
}
ast.body[0].expression.params.forEach(function (param) {
params.push(param.name);
});
body = ast.body[0].expression.body.range;
// Esprima's ranges include the first '{' and the last '}' characters on
// function expressions. So cut them out.
if (ast.body[0].expression.body.type === 'BlockStatement') {
/*eslint-disable no-new-func*/
return new Function(params, source.slice(body[0] + 1, body[1] - 1));
}
// ES6 arrow functions can omit the BlockStatement. In that case, just return
// the body.
/*eslint-disable no-new-func*/
return new Function(params, 'return ' + source.slice(body[0], body[1]));
}
function representJavascriptFunction(object /*, style*/) {
return object.toString();
}
function isFunction(object) {
return Object.prototype.toString.call(object) === '[object Function]';
}
var _function = new type('tag:yaml.org,2002:js/function', {
kind: 'scalar',
resolve: resolveJavascriptFunction,
construct: constructJavascriptFunction,
predicate: isFunction,
represent: representJavascriptFunction
});
var default_full = schema.DEFAULT = new schema({
include: [
default_safe
],
explicit: [
_undefined,
regexp,
_function
]
});
/*eslint-disable max-len,no-use-before-define*/
var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
var CONTEXT_FLOW_IN = 1;
var CONTEXT_FLOW_OUT = 2;
var CONTEXT_BLOCK_IN = 3;
var CONTEXT_BLOCK_OUT = 4;
var CHOMPING_CLIP = 1;
var CHOMPING_STRIP = 2;
var CHOMPING_KEEP = 3;
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
function _class(obj) { return Object.prototype.toString.call(obj); }
function is_EOL(c) {
return (c === 0x0A/* LF */) || (c === 0x0D/* CR */);
}
function is_WHITE_SPACE(c) {
return (c === 0x09/* Tab */) || (c === 0x20/* Space */);
}
function is_WS_OR_EOL(c) {
return (c === 0x09/* Tab */) ||
(c === 0x20/* Space */) ||
(c === 0x0A/* LF */) ||
(c === 0x0D/* CR */);
}
function is_FLOW_INDICATOR(c) {
return c === 0x2C/* , */ ||
c === 0x5B/* [ */ ||
c === 0x5D/* ] */ ||
c === 0x7B/* { */ ||
c === 0x7D/* } */;
}
function fromHexCode(c) {
var lc;
if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
return c - 0x30;
}
/*eslint-disable no-bitwise*/
lc = c | 0x20;
if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) {
return lc - 0x61 + 10;
}
return -1;
}
function escapedHexLen(c) {
if (c === 0x78/* x */) { return 2; }
if (c === 0x75/* u */) { return 4; }
if (c === 0x55/* U */) { return 8; }
return 0;
}
function fromDecimalCode(c) {
if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
return c - 0x30;
}
return -1;
}
function simpleEscapeSequence(c) {
/* eslint-disable indent */
return (c === 0x30/* 0 */) ? '\x00' :
(c === 0x61/* a */) ? '\x07' :
(c === 0x62/* b */) ? '\x08' :
(c === 0x74/* t */) ? '\x09' :
(c === 0x09/* Tab */) ? '\x09' :
(c === 0x6E/* n */) ? '\x0A' :
(c === 0x76/* v */) ? '\x0B' :
(c === 0x66/* f */) ? '\x0C' :
(c === 0x72/* r */) ? '\x0D' :
(c === 0x65/* e */) ? '\x1B' :
(c === 0x20/* Space */) ? ' ' :
(c === 0x22/* " */) ? '\x22' :
(c === 0x2F/* / */) ? '/' :
(c === 0x5C/* \ */) ? '\x5C' :
(c === 0x4E/* N */) ? '\x85' :
(c === 0x5F/* _ */) ? '\xA0' :
(c === 0x4C/* L */) ? '\u2028' :
(c === 0x50/* P */) ? '\u2029' : '';
}
function charFromCodepoint(c) {
if (c <= 0xFFFF) {
return String.fromCharCode(c);
}
// Encode UTF-16 surrogate pair
// https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
return String.fromCharCode(
((c - 0x010000) >> 10) + 0xD800,
((c - 0x010000) & 0x03FF) + 0xDC00
);
}
var simpleEscapeCheck = new Array(256); // integer, for fast access
var simpleEscapeMap = new Array(256);
for (var i = 0; i < 256; i++) {
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
simpleEscapeMap[i] = simpleEscapeSequence(i);
}
function State$1(input, options) {
this.input = input;
this.filename = options['filename'] || null;
this.schema = options['schema'] || default_full;
this.onWarning = options['onWarning'] || null;
this.legacy = options['legacy'] || false;
this.json = options['json'] || false;
this.listener = options['listener'] || null;
this.implicitTypes = this.schema.compiledImplicit;
this.typeMap = this.schema.compiledTypeMap;
this.length = input.length;
this.position = 0;
this.line = 0;
this.lineStart = 0;
this.lineIndent = 0;
this.documents = [];
/*
this.version;
this.checkLineBreaks;
this.tagMap;
this.anchorMap;
this.tag;
this.anchor;
this.kind;
this.result;*/
}
function generateError(state, message) {
return new exception(
message,
new mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
}
function throwError(state, message) {
throw generateError(state, message);
}
function throwWarning(state, message) {
if (state.onWarning) {
state.onWarning.call(null, generateError(state, message));
}
}
var directiveHandlers = {
YAML: function handleYamlDirective(state, name, args) {
var match, major, minor;
if (state.version !== null) {
throwError(state, 'duplication of %YAML directive');
}
if (args.length !== 1) {
throwError(state, 'YAML directive accepts exactly one argument');
}
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
if (match === null) {
throwError(state, 'ill-formed argument of the YAML directive');
}
major = parseInt(match[1], 10);
minor = parseInt(match[2], 10);
if (major !== 1) {
throwError(state, 'unacceptable YAML version of the document');
}
state.version = args[0];
state.checkLineBreaks = (minor < 2);
if (minor !== 1 && minor !== 2) {
throwWarning(state, 'unsupported YAML version of the document');
}
},
TAG: function handleTagDirective(state, name, args) {
var handle, prefix;
if (args.length !== 2) {
throwError(state, 'TAG directive accepts exactly two arguments');
}
handle = args[0];
prefix = args[1];
if (!PATTERN_TAG_HANDLE.test(handle)) {
throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
}
if (_hasOwnProperty$1.call(state.tagMap, handle)) {
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
}
if (!PATTERN_TAG_URI.test(prefix)) {
throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
}
state.tagMap[handle] = prefix;
}
};
function captureSegment(state, start, end, checkJson) {
var _position, _length, _character, _result;
if (start < end) {
_result = state.input.slice(start, end);
if (checkJson) {
for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
_character = _result.charCodeAt(_position);
if (!(_character === 0x09 ||
(0x20 <= _character && _character <= 0x10FFFF))) {
throwError(state, 'expected valid JSON character');
}
}
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
throwError(state, 'the stream contains non-printable characters');
}
state.result += _result;
}
}
function mergeMappings(state, destination, source, overridableKeys) {
var sourceKeys, key, index, quantity;
if (!common.isObject(source)) {
throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
}
sourceKeys = Object.keys(source);
for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
key = sourceKeys[index];
if (!_hasOwnProperty$1.call(destination, key)) {
destination[key] = source[key];
overridableKeys[key] = true;
}
}
}
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
var index, quantity;
// The output is a plain object here, so keys can only be strings.
// We need to convert keyNode to a string, but doing so can hang the process
// (deeply nested arrays that explode exponentially using aliases).
if (Array.isArray(keyNode)) {
keyNode = Array.prototype.slice.call(keyNode);
for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
if (Array.isArray(keyNode[index])) {
throwError(state, 'nested arrays are not supported inside keys');
}
if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') {
keyNode[index] = '[object Object]';
}
}
}
// Avoid code execution in load() via toString property
// (still use its own toString for arrays, timestamps,
// and whatever user schema extensions happen to have @@toStringTag)
if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') {
keyNode = '[object Object]';
}
keyNode = String(keyNode);
if (_result === null) {
_result = {};
}
if (keyTag === 'tag:yaml.org,2002:merge') {
if (Array.isArray(valueNode)) {
for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
mergeMappings(state, _result, valueNode[index], overridableKeys);
}
} else {
mergeMappings(state, _result, valueNode, overridableKeys);
}
} else {
if (!state.json &&
!_hasOwnProperty$1.call(overridableKeys, keyNode) &&
_hasOwnProperty$1.call(_result, keyNode)) {
state.line = startLine || state.line;
state.position = startPos || state.position;
throwError(state, 'duplicated mapping key');
}
_result[keyNode] = valueNode;
delete overridableKeys[keyNode];
}
return _result;
}
function readLineBreak(state) {
var ch;
ch = state.input.charCodeAt(state.position);
if (ch === 0x0A/* LF */) {
state.position++;
} else if (ch === 0x0D/* CR */) {
state.position++;
if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
state.position++;
}
} else {
throwError(state, 'a line break is expected');
}
state.line += 1;
state.lineStart = state.position;
}
function skipSeparationSpace(state, allowComments, checkIndent) {
var lineBreaks = 0,
ch = state.input.charCodeAt(state.position);
while (ch !== 0) {
while (is_WHITE_SPACE(ch)) {
ch = state.input.charCodeAt(++state.position);
}
if (allowComments && ch === 0x23/* # */) {
do {
ch = state.input.charCodeAt(++state.position);
} while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
}
if (is_EOL(ch)) {
readLineBreak(state);
ch = state.input.charCodeAt(state.position);
lineBreaks++;
state.lineIndent = 0;
while (ch === 0x20/* Space */) {
state.lineIndent++;
ch = state.input.charCodeAt(++state.position);
}
} else {
break;
}
}
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
throwWarning(state, 'deficient indentation');
}
return lineBreaks;
}
function testDocumentSeparator(state) {
var _position = state.position,
ch;
ch = state.input.charCodeAt(_position);
// Condition state.position === state.lineStart is tested
// in parent on each call, for efficiency. No needs to test here again.
if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
ch === state.input.charCodeAt(_position + 1) &&
ch === state.input.charCodeAt(_position + 2)) {
_position += 3;
ch = state.input.charCodeAt(_position);
if (ch === 0 || is_WS_OR_EOL(ch)) {
return true;
}
}
return false;
}
function writeFoldedLines(state, count) {
if (count === 1) {
state.result += ' ';
} else if (count > 1) {
state.result += common.repeat('\n', count - 1);
}
}
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
var preceding,
following,
captureStart,
captureEnd,
hasPendingContent,
_line,
_lineStart,
_lineIndent,
_kind = state.kind,
_result = state.result,
ch;
ch = state.input.charCodeAt(state.position);
if (is_WS_OR_EOL(ch) ||
is_FLOW_INDICATOR(ch) ||
ch === 0x23/* # */ ||
ch === 0x26/* & */ ||
ch === 0x2A/* * */ ||
ch === 0x21/* ! */ ||
ch === 0x7C/* | */ ||
ch === 0x3E/* > */ ||
ch === 0x27/* ' */ ||
ch === 0x22/* " */ ||
ch === 0x25/* % */ ||
ch === 0x40/* @ */ ||
ch === 0x60/* ` */) {
return false;
}
if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
following = state.input.charCodeAt(state.position + 1);
if (is_WS_OR_EOL(following) ||
withinFlowCollection && is_FLOW_INDICATOR(following)) {
return false;
}
}
state.kind = 'scalar';
state.result = '';
captureStart = captureEnd = state.position;
hasPendingContent = false;
while (ch !== 0) {
if (ch === 0x3A/* : */) {
following = state.input.charCodeAt(state.position + 1);
if (is_WS_OR_EOL(following) ||
withinFlowCollection && is_FLOW_INDICATOR(following)) {
break;
}
} else if (ch === 0x23/* # */) {
preceding = state.input.charCodeAt(state.position - 1);
if (is_WS_OR_EOL(preceding)) {
break;
}
} else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
withinFlowCollection && is_FLOW_INDICATOR(ch)) {
break;
} else if (is_EOL(ch)) {
_line = state.line;
_lineStart = state.lineStart;
_lineIndent = state.lineIndent;
skipSeparationSpace(state, false, -1);
if (state.lineIndent >= nodeIndent) {
hasPendingContent = true;
ch = state.input.charCodeAt(state.position);
continue;
} else {
state.position = captureEnd;
state.line = _line;
state.lineStart = _lineStart;
state.lineIndent = _lineIndent;
break;
}
}
if (hasPendingContent) {
captureSegment(state, captureStart, captureEnd, false);
writeFoldedLines(state, state.line - _line);
captureStart = captureEnd = state.position;
hasPendingContent = false;
}
if (!is_WHITE_SPACE(ch)) {
captureEnd = state.position + 1;
}
ch = state.input.charCodeAt(++state.position);
}
captureSegment(state, captureStart, captureEnd, false);
if (state.result) {
return true;
}
state.kind = _kind;
state.result = _result;
return false;
}
function readSingleQuotedScalar(state, nodeIndent) {
var ch,
captureStart, captureEnd;
ch = state.input.charCodeAt(state.position);
if (ch !== 0x27/* ' */) {
return false;
}
state.kind = 'scalar';
state.result = '';
state.position++;
captureStart = captureEnd = state.position;
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
if (ch === 0x27/* ' */) {
captureSegment(state, captureStart, state.position, true);
ch = state.input.charCodeAt(++state.position);
if (ch === 0x27/* ' */) {
captureStart = state.position;
state.position++;
captureEnd = state.position;
} else {
return true;
}
} else if (is_EOL(ch)) {
captureSegment(state, captureStart, captureEnd, true);
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
captureStart = captureEnd = state.position;
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
throwError(state, 'unexpected end of the document within a single quoted scalar');
} else {
state.position++;
captureEnd = state.position;
}
}
throwError(state, 'unexpected end of the stream within a single quoted scalar');
}
function readDoubleQuotedScalar(state, nodeIndent) {
var captureStart,
captureEnd,
hexLength,
hexResult,
tmp,
ch;
ch = state.input.charCodeAt(state.position);
if (ch !== 0x22/* " */) {
return false;
}
state.kind = 'scalar';
state.result = '';
state.position++;
captureStart = captureEnd = state.position;
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
if (ch === 0x22/* " */) {
captureSegment(state, captureStart, state.position, true);
state.position++;
return true;
} else if (ch === 0x5C/* \ */) {
captureSegment(state, captureStart, state.position, true);
ch = state.input.charCodeAt(++state.position);
if (is_EOL(ch)) {
skipSeparationSpace(state, false, nodeIndent);
// TODO: rework to inline fn with no type cast?
} else if (ch < 256 && simpleEscapeCheck[ch]) {
state.result += simpleEscapeMap[ch];
state.position++;
} else if ((tmp = escapedHexLen(ch)) > 0) {
hexLength = tmp;
hexResult = 0;
for (; hexLength > 0; hexLength--) {
ch = state.input.charCodeAt(++state.position);
if ((tmp = fromHexCode(ch)) >= 0) {
hexResult = (hexResult << 4) + tmp;
} else {
throwError(state, 'expected hexadecimal character');
}
}
state.result += charFromCodepoint(hexResult);
state.position++;
} else {
throwError(state, 'unknown escape sequence');
}
captureStart = captureEnd = state.position;
} else if (is_EOL(ch)) {
captureSegment(state, captureStart, captureEnd, true);
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
captureStart = captureEnd = state.position;
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
throwError(state, 'unexpected end of the document within a double quoted scalar');
} else {
state.position++;
captureEnd = state.position;
}
}
throwError(state, 'unexpected end of the stream within a double quoted scalar');
}
function readFlowCollection(state, nodeIndent) {
var readNext = true,
_line,
_tag = state.tag,
_result,
_anchor = state.anchor,
following,
terminator,
isPair,
isExplicitPair,
isMapping,
overridableKeys = {},
keyNode,
keyTag,
valueNode,
ch;
ch = state.input.charCodeAt(state.position);
if (ch === 0x5B/* [ */) {
terminator = 0x5D;/* ] */
isMapping = false;
_result = [];
} else if (ch === 0x7B/* { */) {
terminator = 0x7D;/* } */
isMapping = true;
_result = {};
} else {
return false;
}
if (state.anchor !== null) {
state.anchorMap[state.anchor] = _result;
}
ch = state.input.charCodeAt(++state.position);
while (ch !== 0) {
skipSeparationSpace(state, true, nodeIndent);
ch = state.input.charCodeAt(state.position);
if (ch === terminator) {
state.position++;
state.tag = _tag;
state.anchor = _anchor;
state.kind = isMapping ? 'mapping' : 'sequence';
state.result = _result;
return true;
} else if (!readNext) {
throwError(state, 'missed comma between flow collection entries');
}
keyTag = keyNode = valueNode = null;
isPair = isExplicitPair = false;
if (ch === 0x3F/* ? */) {
following = state.input.charCodeAt(state.position + 1);
if (is_WS_OR_EOL(following)) {
isPair = isExplicitPair = true;
state.position++;
skipSeparationSpace(state, true, nodeIndent);
}
}
_line = state.line;
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
keyTag = state.tag;
keyNode = state.result;
skipSeparationSpace(state, true, nodeIndent);
ch = state.input.charCodeAt(state.position);
if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
isPair = true;
ch = state.input.charCodeAt(++state.position);
skipSeparationSpace(state, true, nodeIndent);
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
valueNode = state.result;
}
if (isMapping) {
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
} else if (isPair) {
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
} else {
_result.push(keyNode);
}
skipSeparationSpace(state, true, nodeIndent);
ch = state.input.charCodeAt(state.position);
if (ch === 0x2C/* , */) {
readNext = true;
ch = state.input.charCodeAt(++state.position);
} else {
readNext = false;
}
}
throwError(state, 'unexpected end of the stream within a flow collection');
}
function readBlockScalar(state, nodeIndent) {
var captureStart,
folding,
chomping = CHOMPING_CLIP,
didReadContent = false,
detectedIndent = false,
textIndent = nodeIndent,
emptyLines = 0,
atMoreIndented = false,
tmp,
ch;
ch = state.input.charCodeAt(state.position);
if (ch === 0x7C/* | */) {
folding = false;
} else if (ch === 0x3E/* > */) {
folding = true;
} else {
return false;
}
state.kind = 'scalar';
state.result = '';
while (ch !== 0) {
ch = state.input.charCodeAt(++state.position);
if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
if (CHOMPING_CLIP === chomping) {
chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
} else {
throwError(state, 'repeat of a chomping mode identifier');
}
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
if (tmp === 0) {
throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
} else if (!detectedIndent) {
textIndent = nodeIndent + tmp - 1;
detectedIndent = true;
} else {
throwError(state, 'repeat of an indentation width identifier');
}
} else {
break;
}
}
if (is_WHITE_SPACE(ch)) {
do { ch = state.input.charCodeAt(++state.position); }
while (is_WHITE_SPACE(ch));
if (ch === 0x23/* # */) {
do { ch = state.input.charCodeAt(++state.position); }
while (!is_EOL(ch) && (ch !== 0));
}
}
while (ch !== 0) {
readLineBreak(state);
state.lineIndent = 0;
ch = state.input.charCodeAt(state.position);
while ((!detectedIndent || state.lineIndent < textIndent) &&
(ch === 0x20/* Space */)) {
state.lineIndent++;
ch = state.input.charCodeAt(++state.position);
}
if (!detectedIndent && state.lineIndent > textIndent) {
textIndent = state.lineIndent;
}
if (is_EOL(ch)) {
emptyLines++;
continue;
}
// End of the scalar.
if (state.lineIndent < textIndent) {
// Perform the chomping.
if (chomping === CHOMPING_KEEP) {
state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
} else if (chomping === CHOMPING_CLIP) {
if (didReadContent) { // i.e. only if the scalar is not empty.
state.result += '\n';
}
}
// Break this `while` cycle and go to the funciton's epilogue.
break;
}
// Folded style: use fancy rules to handle line breaks.
if (folding) {
// Lines starting with white space characters (more-indented lines) are not folded.
if (is_WHITE_SPACE(ch)) {
atMoreIndented = true;
// except for the first content line (cf. Example 8.1)
state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
// End of more-indented block.
} else if (atMoreIndented) {
atMoreIndented = false;
state.result += common.repeat('\n', emptyLines + 1);
// Just one line break - perceive as the same line.
} else if (emptyLines === 0) {
if (didReadContent) { // i.e. only if we have already read some scalar content.
state.result += ' ';
}
// Several line breaks - perceive as different lines.
} else {
state.result += common.repeat('\n', emptyLines);
}
// Literal style: just add exact number of line breaks between content lines.
} else {
// Keep all line breaks except the header line break.
state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
}
didReadContent = true;
detectedIndent = true;
emptyLines = 0;
captureStart = state.position;
while (!is_EOL(ch) && (ch !== 0)) {
ch = state.input.charCodeAt(++state.position);
}
captureSegment(state, captureStart, state.position, false);
}
return true;
}
function readBlockSequence(state, nodeIndent) {
var _line,
_tag = state.tag,
_anchor = state.anchor,
_result = [],
following,
detected = false,
ch;
if (state.anchor !== null) {
state.anchorMap[state.anchor] = _result;
}
ch = state.input.charCodeAt(state.position);
while (ch !== 0) {
if (ch !== 0x2D/* - */) {
break;
}
following = state.input.charCodeAt(state.position + 1);
if (!is_WS_OR_EOL(following)) {
break;
}
detected = true;
state.position++;
if (skipSeparationSpace(state, true, -1)) {
if (state.lineIndent <= nodeIndent) {
_result.push(null);
ch = state.input.charCodeAt(state.position);
continue;
}
}
_line = state.line;
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
_result.push(state.result);
skipSeparationSpace(state, true, -1);
ch = state.input.charCodeAt(state.position);
if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
throwError(state, 'bad indentation of a sequence entry');
} else if (state.lineIndent < nodeIndent) {
break;
}
}
if (detected) {
state.tag = _tag;
state.anchor = _anchor;
state.kind = 'sequence';
state.result = _result;
return true;
}
return false;
}
function readBlockMapping(state, nodeIndent, flowIndent) {
var following,
allowCompact,
_line,
_pos,
_tag = state.tag,
_anchor = state.anchor,
_result = {},
overridableKeys = {},
keyTag = null,
keyNode = null,
valueNode = null,
atExplicitKey = false,
detected = false,
ch;
if (state.anchor !== null) {
state.anchorMap[state.anchor] = _result;
}
ch = state.input.charCodeAt(state.position);
while (ch !== 0) {
following = state.input.charCodeAt(state.position + 1);
_line = state.line; // Save the current line.
_pos = state.position;
//
// Explicit notation case. There are two separate blocks:
// first for the key (denoted by "?") and second for the value (denoted by ":")
//
if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
if (ch === 0x3F/* ? */) {
if (atExplicitKey) {
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
keyTag = keyNode = valueNode = null;
}
detected = true;
atExplicitKey = true;
allowCompact = true;
} else if (atExplicitKey) {
// i.e. 0x3A/* : */ === character after the explicit key.
atExplicitKey = false;
allowCompact = true;
} else {
throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
}
state.position += 1;
ch = following;
//
// Implicit notation case. Flow-style node as the key first, then ":", and the value.
//
} else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
if (state.line === _line) {
ch = state.input.charCodeAt(state.position);
while (is_WHITE_SPACE(ch)) {
ch = state.input.charCodeAt(++state.position);
}
if (ch === 0x3A/* : */) {
ch = state.input.charCodeAt(++state.position);
if (!is_WS_OR_EOL(ch)) {
throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
}
if (atExplicitKey) {
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
keyTag = keyNode = valueNode = null;
}
detected = true;
atExplicitKey = false;
allowCompact = false;
keyTag = state.tag;
keyNode = state.result;
} else if (detected) {
throwError(state, 'can not read an implicit mapping pair; a colon is missed');
} else {
state.tag = _tag;
state.anchor = _anchor;
return true; // Keep the result of `composeNode`.
}
} else if (detected) {
throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
} else {
state.tag = _tag;
state.anchor = _anchor;
return true; // Keep the result of `composeNode`.
}
} else {
break; // Reading is done. Go to the epilogue.
}
//
// Common reading code for both explicit and implicit notations.
//
if (state.line === _line || state.lineIndent > nodeIndent) {
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
if (atExplicitKey) {
keyNode = state.result;
} else {
valueNode = state.result;
}
}
if (!atExplicitKey) {
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
keyTag = keyNode = valueNode = null;
}
skipSeparationSpace(state, true, -1);
ch = state.input.charCodeAt(state.position);
}
if (state.lineIndent > nodeIndent && (ch !== 0)) {
throwError(state, 'bad indentation of a mapping entry');
} else if (state.lineIndent < nodeIndent) {
break;
}
}
//
// Epilogue.
//
// Special case: last mapping's node contains only the key in explicit notation.
if (atExplicitKey) {
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
}
// Expose the resulting mapping.
if (detected) {
state.tag = _tag;
state.anchor = _anchor;
state.kind = 'mapping';
state.result = _result;
}
return detected;
}
function readTagProperty(state) {
var _position,
isVerbatim = false,
isNamed = false,
tagHandle,
tagName,
ch;
ch = state.input.charCodeAt(state.position);
if (ch !== 0x21/* ! */) return false;
if (state.tag !== null) {
throwError(state, 'duplication of a tag property');
}
ch = state.input.charCodeAt(++state.position);
if (ch === 0x3C/* < */) {
isVerbatim = true;
ch = state.input.charCodeAt(++state.position);
} else if (ch === 0x21/* ! */) {
isNamed = true;
tagHandle = '!!';
ch = state.input.charCodeAt(++state.position);
} else {
tagHandle = '!';
}
_position = state.position;
if (isVerbatim) {
do { ch = state.input.charCodeAt(++state.position); }
while (ch !== 0 && ch !== 0x3E/* > */);
if (state.position < state.length) {
tagName = state.input.slice(_position, state.position);
ch = state.input.charCodeAt(++state.position);
} else {
throwError(state, 'unexpected end of the stream within a verbatim tag');
}
} else {
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
if (ch === 0x21/* ! */) {
if (!isNamed) {
tagHandle = state.input.slice(_position - 1, state.position + 1);
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
throwError(state, 'named tag handle cannot contain such characters');
}
isNamed = true;
_position = state.position + 1;
} else {
throwError(state, 'tag suffix cannot contain exclamation marks');
}
}
ch = state.input.charCodeAt(++state.position);
}
tagName = state.input.slice(_position, state.position);
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
throwError(state, 'tag suffix cannot contain flow indicator characters');
}
}
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
throwError(state, 'tag name cannot contain such characters: ' + tagName);
}
if (isVerbatim) {
state.tag = tagName;
} else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
state.tag = state.tagMap[tagHandle] + tagName;
} else if (tagHandle === '!') {
state.tag = '!' + tagName;
} else if (tagHandle === '!!') {
state.tag = 'tag:yaml.org,2002:' + tagName;
} else {
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
}
return true;
}
function readAnchorProperty(state) {
var _position,
ch;
ch = state.input.charCodeAt(state.position);
if (ch !== 0x26/* & */) return false;
if (state.anchor !== null) {
throwError(state, 'duplication of an anchor property');
}
ch = state.input.charCodeAt(++state.position);
_position = state.position;
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
ch = state.input.charCodeAt(++state.position);
}
if (state.position === _position) {
throwError(state, 'name of an anchor node must contain at least one character');
}
state.anchor = state.input.slice(_position, state.position);
return true;
}
function readAlias(state) {
var _position, alias,
ch;
ch = state.input.charCodeAt(state.position);
if (ch !== 0x2A/* * */) return false;
ch = state.input.charCodeAt(++state.position);
_position = state.position;
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
ch = state.input.charCodeAt(++state.position);
}
if (state.position === _position) {
throwError(state, 'name of an alias node must contain at least one character');
}
alias = state.input.slice(_position, state.position);
if (!state.anchorMap.hasOwnProperty(alias)) {
throwError(state, 'unidentified alias "' + alias + '"');
}
state.result = state.anchorMap[alias];
skipSeparationSpace(state, true, -1);
return true;
}
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
var allowBlockStyles,
allowBlockScalars,
allowBlockCollections,
indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
atNewLine = false,
hasContent = false,
typeIndex,
typeQuantity,
type,
flowIndent,
blockIndent;
if (state.listener !== null) {
state.listener('open', state);
}
state.tag = null;
state.anchor = null;
state.kind = null;
state.result = null;
allowBlockStyles = allowBlockScalars = allowBlockCollections =
CONTEXT_BLOCK_OUT === nodeContext ||
CONTEXT_BLOCK_IN === nodeContext;
if (allowToSeek) {
if (skipSeparationSpace(state, true, -1)) {
atNewLine = true;
if (state.lineIndent > parentIndent) {
indentStatus = 1;
} else if (state.lineIndent === parentIndent) {
indentStatus = 0;
} else if (state.lineIndent < parentIndent) {
indentStatus = -1;
}
}
}
if (indentStatus === 1) {
while (readTagProperty(state) || readAnchorProperty(state)) {
if (skipSeparationSpace(state, true, -1)) {
atNewLine = true;
allowBlockCollections = allowBlockStyles;
if (state.lineIndent > parentIndent) {
indentStatus = 1;
} else if (state.lineIndent === parentIndent) {
indentStatus = 0;
} else if (state.lineIndent < parentIndent) {
indentStatus = -1;
}
} else {
allowBlockCollections = false;
}
}
}
if (allowBlockCollections) {
allowBlockCollections = atNewLine || allowCompact;
}
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
flowIndent = parentIndent;
} else {
flowIndent = parentIndent + 1;
}
blockIndent = state.position - state.lineStart;
if (indentStatus === 1) {
if (allowBlockCollections &&
(readBlockSequence(state, blockIndent) ||
readBlockMapping(state, blockIndent, flowIndent)) ||
readFlowCollection(state, flowIndent)) {
hasContent = true;
} else {
if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
readSingleQuotedScalar(state, flowIndent) ||
readDoubleQuotedScalar(state, flowIndent)) {
hasContent = true;
} else if (readAlias(state)) {
hasContent = true;
if (state.tag !== null || state.anchor !== null) {
throwError(state, 'alias node should not have any properties');
}
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
hasContent = true;
if (state.tag === null) {
state.tag = '?';
}
}
if (state.anchor !== null) {
state.anchorMap[state.anchor] = state.result;
}
}
} else if (indentStatus === 0) {
// Special case: block sequences are allowed to have same indentation level as the parent.
// http://www.yaml.org/spec/1.2/spec.html#id2799784
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
}
}
if (state.tag !== null && state.tag !== '!') {
if (state.tag === '?') {
// Implicit resolving is not allowed for non-scalar types, and '?'
// non-specific tag is only automatically assigned to plain scalars.
//
// We only need to check kind conformity in case user explicitly assigns '?'
// tag, for example like this: "!<?> [0]"
//
if (state.result !== null && state.kind !== 'scalar') {
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
}
for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
type = state.implicitTypes[typeIndex];
if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
state.result = type.construct(state.result);
state.tag = type.tag;
if (state.anchor !== null) {
state.anchorMap[state.anchor] = state.result;
}
break;
}
}
} else if (_hasOwnProperty$1.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
type = state.typeMap[state.kind || 'fallback'][state.tag];
if (state.result !== null && type.kind !== state.kind) {
throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
}
if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched
throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
} else {
state.result = type.construct(state.result);
if (state.anchor !== null) {
state.anchorMap[state.anchor] = state.result;
}
}
} else {
throwError(state, 'unknown tag !<' + state.tag + '>');
}
}
if (state.listener !== null) {
state.listener('close', state);
}
return state.tag !== null || state.anchor !== null || hasContent;
}
function readDocument(state) {
var documentStart = state.position,
_position,
directiveName,
directiveArgs,
hasDirectives = false,
ch;
state.version = null;
state.checkLineBreaks = state.legacy;
state.tagMap = {};
state.anchorMap = {};
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
skipSeparationSpace(state, true, -1);
ch = state.input.charCodeAt(state.position);
if (state.lineIndent > 0 || ch !== 0x25/* % */) {
break;
}
hasDirectives = true;
ch = state.input.charCodeAt(++state.position);
_position = state.position;
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
ch = state.input.charCodeAt(++state.position);
}
directiveName = state.input.slice(_position, state.position);
directiveArgs = [];
if (directiveName.length < 1) {
throwError(state, 'directive name must not be less than one character in length');
}
while (ch !== 0) {
while (is_WHITE_SPACE(ch)) {
ch = state.input.charCodeAt(++state.position);
}
if (ch === 0x23/* # */) {
do { ch = state.input.charCodeAt(++state.position); }
while (ch !== 0 && !is_EOL(ch));
break;
}
if (is_EOL(ch)) break;
_position = state.position;
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
ch = state.input.charCodeAt(++state.position);
}
directiveArgs.push(state.input.slice(_position, state.position));
}
if (ch !== 0) readLineBreak(state);
if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
directiveHandlers[directiveName](state, directiveName, directiveArgs);
} else {
throwWarning(state, 'unknown document directive "' + directiveName + '"');
}
}
skipSeparationSpace(state, true, -1);
if (state.lineIndent === 0 &&
state.input.charCodeAt(state.position) === 0x2D/* - */ &&
state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
state.position += 3;
skipSeparationSpace(state, true, -1);
} else if (hasDirectives) {
throwError(state, 'directives end mark is expected');
}
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
skipSeparationSpace(state, true, -1);
if (state.checkLineBreaks &&
PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
throwWarning(state, 'non-ASCII line breaks are interpreted as content');
}
state.documents.push(state.result);
if (state.position === state.lineStart && testDocumentSeparator(state)) {
if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
state.position += 3;
skipSeparationSpace(state, true, -1);
}
return;
}
if (state.position < (state.length - 1)) {
throwError(state, 'end of the stream or a document separator is expected');
} else {
return;
}
}
function loadDocuments(input, options) {
input = String(input);
options = options || {};
if (input.length !== 0) {
// Add tailing `\n` if not exists
if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ &&
input.charCodeAt(input.length - 1) !== 0x0D/* CR */) {
input += '\n';
}
// Strip BOM
if (input.charCodeAt(0) === 0xFEFF) {
input = input.slice(1);
}
}
var state = new State$1(input, options);
var nullpos = input.indexOf('\0');
if (nullpos !== -1) {
state.position = nullpos;
throwError(state, 'null byte is not allowed in input');
}
// Use 0 as string terminator. That significantly simplifies bounds check.
state.input += '\0';
while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
state.lineIndent += 1;
state.position += 1;
}
while (state.position < (state.length - 1)) {
readDocument(state);
}
return state.documents;
}
function loadAll$1(input, iterator, options) {
if (iterator !== null && typeof iterator === 'object' && typeof options === 'undefined') {
options = iterator;
iterator = null;
}
var documents = loadDocuments(input, options);
if (typeof iterator !== 'function') {
return documents;
}
for (var index = 0, length = documents.length; index < length; index += 1) {
iterator(documents[index]);
}
}
function load$1(input, options) {
var documents = loadDocuments(input, options);
if (documents.length === 0) {
/*eslint-disable no-undefined*/
return undefined;
} else if (documents.length === 1) {
return documents[0];
}
throw new exception('expected a single document in the stream, but found more');
}
function safeLoadAll$1(input, iterator, options) {
if (typeof iterator === 'object' && iterator !== null && typeof options === 'undefined') {
options = iterator;
iterator = null;
}
return loadAll$1(input, iterator, common.extend({ schema: default_safe }, options));
}
function safeLoad$1(input, options) {
return load$1(input, common.extend({ schema: default_safe }, options));
}
var loadAll_1 = loadAll$1;
var load_1 = load$1;
var safeLoadAll_1 = safeLoadAll$1;
var safeLoad_1 = safeLoad$1;
var loader = {
loadAll: loadAll_1,
load: load_1,
safeLoadAll: safeLoadAll_1,
safeLoad: safeLoad_1
};
/*eslint-disable no-use-before-define*/
var _toString = Object.prototype.toString;
var _hasOwnProperty = Object.prototype.hasOwnProperty;
var CHAR_TAB = 0x09; /* Tab */
var CHAR_LINE_FEED = 0x0A; /* LF */
var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */
var CHAR_SPACE = 0x20; /* Space */
var CHAR_EXCLAMATION = 0x21; /* ! */
var CHAR_DOUBLE_QUOTE = 0x22; /* " */
var CHAR_SHARP = 0x23; /* # */
var CHAR_PERCENT = 0x25; /* % */
var CHAR_AMPERSAND = 0x26; /* & */
var CHAR_SINGLE_QUOTE = 0x27; /* ' */
var CHAR_ASTERISK = 0x2A; /* * */
var CHAR_COMMA = 0x2C; /* , */
var CHAR_MINUS = 0x2D; /* - */
var CHAR_COLON = 0x3A; /* : */
var CHAR_EQUALS = 0x3D; /* = */
var CHAR_GREATER_THAN = 0x3E; /* > */
var CHAR_QUESTION = 0x3F; /* ? */
var CHAR_COMMERCIAL_AT = 0x40; /* @ */
var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
var CHAR_GRAVE_ACCENT = 0x60; /* ` */
var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
var CHAR_VERTICAL_LINE = 0x7C; /* | */
var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
var ESCAPE_SEQUENCES = {};
ESCAPE_SEQUENCES[0x00] = '\\0';
ESCAPE_SEQUENCES[0x07] = '\\a';
ESCAPE_SEQUENCES[0x08] = '\\b';
ESCAPE_SEQUENCES[0x09] = '\\t';
ESCAPE_SEQUENCES[0x0A] = '\\n';
ESCAPE_SEQUENCES[0x0B] = '\\v';
ESCAPE_SEQUENCES[0x0C] = '\\f';
ESCAPE_SEQUENCES[0x0D] = '\\r';
ESCAPE_SEQUENCES[0x1B] = '\\e';
ESCAPE_SEQUENCES[0x22] = '\\"';
ESCAPE_SEQUENCES[0x5C] = '\\\\';
ESCAPE_SEQUENCES[0x85] = '\\N';
ESCAPE_SEQUENCES[0xA0] = '\\_';
ESCAPE_SEQUENCES[0x2028] = '\\L';
ESCAPE_SEQUENCES[0x2029] = '\\P';
var DEPRECATED_BOOLEANS_SYNTAX = [
'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
];
function compileStyleMap(schema, map) {
var result, keys, index, length, tag, style, type;
if (map === null) return {};
result = {};
keys = Object.keys(map);
for (index = 0, length = keys.length; index < length; index += 1) {
tag = keys[index];
style = String(map[tag]);
if (tag.slice(0, 2) === '!!') {
tag = 'tag:yaml.org,2002:' + tag.slice(2);
}
type = schema.compiledTypeMap['fallback'][tag];
if (type && _hasOwnProperty.call(type.styleAliases, style)) {
style = type.styleAliases[style];
}
result[tag] = style;
}
return result;
}
function encodeHex(character) {
var string, handle, length;
string = character.toString(16).toUpperCase();
if (character <= 0xFF) {
handle = 'x';
length = 2;
} else if (character <= 0xFFFF) {
handle = 'u';
length = 4;
} else if (character <= 0xFFFFFFFF) {
handle = 'U';
length = 8;
} else {
throw new exception('code point within a string may not be greater than 0xFFFFFFFF');
}
return '\\' + handle + common.repeat('0', length - string.length) + string;
}
function State(options) {
this.schema = options['schema'] || default_full;
this.indent = Math.max(1, (options['indent'] || 2));
this.noArrayIndent = options['noArrayIndent'] || false;
this.skipInvalid = options['skipInvalid'] || false;
this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
this.sortKeys = options['sortKeys'] || false;
this.lineWidth = options['lineWidth'] || 80;
this.noRefs = options['noRefs'] || false;
this.noCompatMode = options['noCompatMode'] || false;
this.condenseFlow = options['condenseFlow'] || false;
this.implicitTypes = this.schema.compiledImplicit;
this.explicitTypes = this.schema.compiledExplicit;
this.tag = null;
this.result = '';
this.duplicates = [];
this.usedDuplicates = null;
}
// Indents every line in a string. Empty lines (\n only) are not indented.
function indentString(string, spaces) {
var ind = common.repeat(' ', spaces),
position = 0,
next = -1,
result = '',
line,
length = string.length;
while (position < length) {
next = string.indexOf('\n', position);
if (next === -1) {
line = string.slice(position);
position = length;
} else {
line = string.slice(position, next + 1);
position = next + 1;
}
if (line.length && line !== '\n') result += ind;
result += line;
}
return result;
}
function generateNextLine(state, level) {
return '\n' + common.repeat(' ', state.indent * level);
}
function testImplicitResolving(state, str) {
var index, length, type;
for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
type = state.implicitTypes[index];
if (type.resolve(str)) {
return true;
}
}
return false;
}
// [33] s-white ::= s-space | s-tab
function isWhitespace(c) {
return c === CHAR_SPACE || c === CHAR_TAB;
}
// Returns true if the character can be printed without escaping.
// From YAML 1.2: "any allowed characters known to be non-printable
// should also be escaped. [However,] This isnt mandatory"
// Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
function isPrintable(c) {
return (0x00020 <= c && c <= 0x00007E)
|| ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
|| ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF /* BOM */)
|| (0x10000 <= c && c <= 0x10FFFF);
}
// [34] ns-char ::= nb-char - s-white
// [27] nb-char ::= c-printable - b-char - c-byte-order-mark
// [26] b-char ::= b-line-feed | b-carriage-return
// [24] b-line-feed ::= #xA /* LF */
// [25] b-carriage-return ::= #xD /* CR */
// [3] c-byte-order-mark ::= #xFEFF
function isNsChar(c) {
return isPrintable(c) && !isWhitespace(c)
// byte-order-mark
&& c !== 0xFEFF
// b-char
&& c !== CHAR_CARRIAGE_RETURN
&& c !== CHAR_LINE_FEED;
}
// Simplified test for values allowed after the first character in plain style.
function isPlainSafe(c, prev) {
// Uses a subset of nb-char - c-flow-indicator - ":" - "#"
// where nb-char ::= c-printable - b-char - c-byte-order-mark.
return isPrintable(c) && c !== 0xFEFF
// - c-flow-indicator
&& c !== CHAR_COMMA
&& c !== CHAR_LEFT_SQUARE_BRACKET
&& c !== CHAR_RIGHT_SQUARE_BRACKET
&& c !== CHAR_LEFT_CURLY_BRACKET
&& c !== CHAR_RIGHT_CURLY_BRACKET
// - ":" - "#"
// /* An ns-char preceding */ "#"
&& c !== CHAR_COLON
&& ((c !== CHAR_SHARP) || (prev && isNsChar(prev)));
}
// Simplified test for values allowed as the first character in plain style.
function isPlainSafeFirst(c) {
// Uses a subset of ns-char - c-indicator
// where ns-char = nb-char - s-white.
return isPrintable(c) && c !== 0xFEFF
&& !isWhitespace(c) // - s-white
// - (c-indicator ::=
// “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
&& c !== CHAR_MINUS
&& c !== CHAR_QUESTION
&& c !== CHAR_COLON
&& c !== CHAR_COMMA
&& c !== CHAR_LEFT_SQUARE_BRACKET
&& c !== CHAR_RIGHT_SQUARE_BRACKET
&& c !== CHAR_LEFT_CURLY_BRACKET
&& c !== CHAR_RIGHT_CURLY_BRACKET
// | “#” | “&” | “*” | “!” | “|” | “=” | “>” | “'” | “"”
&& c !== CHAR_SHARP
&& c !== CHAR_AMPERSAND
&& c !== CHAR_ASTERISK
&& c !== CHAR_EXCLAMATION
&& c !== CHAR_VERTICAL_LINE
&& c !== CHAR_EQUALS
&& c !== CHAR_GREATER_THAN
&& c !== CHAR_SINGLE_QUOTE
&& c !== CHAR_DOUBLE_QUOTE
// | “%” | “@” | “`”)
&& c !== CHAR_PERCENT
&& c !== CHAR_COMMERCIAL_AT
&& c !== CHAR_GRAVE_ACCENT;
}
// Determines whether block indentation indicator is required.
function needIndentIndicator(string) {
var leadingSpaceRe = /^\n* /;
return leadingSpaceRe.test(string);
}
var STYLE_PLAIN = 1,
STYLE_SINGLE = 2,
STYLE_LITERAL = 3,
STYLE_FOLDED = 4,
STYLE_DOUBLE = 5;
// Determines which scalar styles are possible and returns the preferred style.
// lineWidth = -1 => no limit.
// Pre-conditions: str.length > 0.
// Post-conditions:
// STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
// STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
// STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
var i;
var char, prev_char;
var hasLineBreak = false;
var hasFoldableLine = false; // only checked if shouldTrackWidth
var shouldTrackWidth = lineWidth !== -1;
var previousLineBreak = -1; // count the first line correctly
var plain = isPlainSafeFirst(string.charCodeAt(0))
&& !isWhitespace(string.charCodeAt(string.length - 1));
if (singleLineOnly) {
// Case: no block styles.
// Check for disallowed characters to rule out plain and single.
for (i = 0; i < string.length; i++) {
char = string.charCodeAt(i);
if (!isPrintable(char)) {
return STYLE_DOUBLE;
}
prev_char = i > 0 ? string.charCodeAt(i - 1) : null;
plain = plain && isPlainSafe(char, prev_char);
}
} else {
// Case: block styles permitted.
for (i = 0; i < string.length; i++) {
char = string.charCodeAt(i);
if (char === CHAR_LINE_FEED) {
hasLineBreak = true;
// Check if any line can be folded.
if (shouldTrackWidth) {
hasFoldableLine = hasFoldableLine ||
// Foldable line = too long, and not more-indented.
(i - previousLineBreak - 1 > lineWidth &&
string[previousLineBreak + 1] !== ' ');
previousLineBreak = i;
}
} else if (!isPrintable(char)) {
return STYLE_DOUBLE;
}
prev_char = i > 0 ? string.charCodeAt(i - 1) : null;
plain = plain && isPlainSafe(char, prev_char);
}
// in case the end is missing a \n
hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
(i - previousLineBreak - 1 > lineWidth &&
string[previousLineBreak + 1] !== ' '));
}
// Although every style can represent \n without escaping, prefer block styles
// for multiline, since they're more readable and they don't add empty lines.
// Also prefer folding a super-long line.
if (!hasLineBreak && !hasFoldableLine) {
// Strings interpretable as another type have to be quoted;
// e.g. the string 'true' vs. the boolean true.
return plain && !testAmbiguousType(string)
? STYLE_PLAIN : STYLE_SINGLE;
}
// Edge case: block indentation indicator can only have one digit.
if (indentPerLevel > 9 && needIndentIndicator(string)) {
return STYLE_DOUBLE;
}
// At this point we know block styles are valid.
// Prefer literal style unless we want to fold.
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
}
// Note: line breaking/folding is implemented for only the folded style.
// NB. We drop the last trailing newline (if any) of a returned block scalar
// since the dumper adds its own newline. This always works:
// • No ending newline => unaffected; already using strip "-" chomping.
// • Ending newline => removed then restored.
// Importantly, this keeps the "+" chomp indicator from gaining an extra line.
function writeScalar(state, string, level, iskey) {
state.dump = (function () {
if (string.length === 0) {
return "''";
}
if (!state.noCompatMode &&
DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
return "'" + string + "'";
}
var indent = state.indent * Math.max(1, level); // no 0-indent scalars
// As indentation gets deeper, let the width decrease monotonically
// to the lower bound min(state.lineWidth, 40).
// Note that this implies
// state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
// state.lineWidth > 40 + state.indent: width decreases until the lower bound.
// This behaves better than a constant minimum width which disallows narrower options,
// or an indent threshold which causes the width to suddenly increase.
var lineWidth = state.lineWidth === -1
? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
// Without knowing if keys are implicit/explicit, assume implicit for safety.
var singleLineOnly = iskey
// No block styles in flow mode.
|| (state.flowLevel > -1 && level >= state.flowLevel);
function testAmbiguity(string) {
return testImplicitResolving(state, string);
}
switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
case STYLE_PLAIN:
return string;
case STYLE_SINGLE:
return "'" + string.replace(/'/g, "''") + "'";
case STYLE_LITERAL:
return '|' + blockHeader(string, state.indent)
+ dropEndingNewline(indentString(string, indent));
case STYLE_FOLDED:
return '>' + blockHeader(string, state.indent)
+ dropEndingNewline(indentString(foldString(string, lineWidth), indent));
case STYLE_DOUBLE:
return '"' + escapeString(string) + '"';
default:
throw new exception('impossible error: invalid scalar style');
}
}());
}
// Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
function blockHeader(string, indentPerLevel) {
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : '';
// note the special case: the string '\n' counts as a "trailing" empty line.
var clip = string[string.length - 1] === '\n';
var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
var chomp = keep ? '+' : (clip ? '' : '-');
return indentIndicator + chomp + '\n';
}
// (See the note for writeScalar.)
function dropEndingNewline(string) {
return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
}
// Note: a long line without a suitable break point will exceed the width limit.
// Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
function foldString(string, width) {
// In folded style, $k$ consecutive newlines output as $k+1$ newlines—
// unless they're before or after a more-indented line, or at the very
// beginning or end, in which case $k$ maps to $k$.
// Therefore, parse each chunk as newline(s) followed by a content line.
var lineRe = /(\n+)([^\n]*)/g;
// first line (possibly an empty line)
var result = (function () {
var nextLF = string.indexOf('\n');
nextLF = nextLF !== -1 ? nextLF : string.length;
lineRe.lastIndex = nextLF;
return foldLine(string.slice(0, nextLF), width);
}());
// If we haven't reached the first content line yet, don't add an extra \n.
var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
var moreIndented;
// rest of the lines
var match;
while ((match = lineRe.exec(string))) {
var prefix = match[1], line = match[2];
moreIndented = (line[0] === ' ');
result += prefix
+ (!prevMoreIndented && !moreIndented && line !== ''
? '\n' : '')
+ foldLine(line, width);
prevMoreIndented = moreIndented;
}
return result;
}
// Greedy line breaking.
// Picks the longest line under the limit each time,
// otherwise settles for the shortest line over the limit.
// NB. More-indented lines *cannot* be folded, as that would add an extra \n.
function foldLine(line, width) {
if (line === '' || line[0] === ' ') return line;
// Since a more-indented line adds a \n, breaks can't be followed by a space.
var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
var match;
// start is an inclusive index. end, curr, and next are exclusive.
var start = 0, end, curr = 0, next = 0;
var result = '';
// Invariants: 0 <= start <= length-1.
// 0 <= curr <= next <= max(0, length-2). curr - start <= width.
// Inside the loop:
// A match implies length >= 2, so curr and next are <= length-2.
while ((match = breakRe.exec(line))) {
next = match.index;
// maintain invariant: curr - start <= width
if (next - start > width) {
end = (curr > start) ? curr : next; // derive end <= length-2
result += '\n' + line.slice(start, end);
// skip the space that was output as \n
start = end + 1; // derive start <= length-1
}
curr = next;
}
// By the invariants, start <= length-1, so there is something left over.
// It is either the whole string or a part starting from non-whitespace.
result += '\n';
// Insert a break if the remainder is too long and there is a break available.
if (line.length - start > width && curr > start) {
result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
} else {
result += line.slice(start);
}
return result.slice(1); // drop extra \n joiner
}
// Escapes a double-quoted string.
function escapeString(string) {
var result = '';
var char, nextChar;
var escapeSeq;
for (var i = 0; i < string.length; i++) {
char = string.charCodeAt(i);
// Check for surrogate pairs (reference Unicode 3.0 section "3.7 Surrogates").
if (char >= 0xD800 && char <= 0xDBFF/* high surrogate */) {
nextChar = string.charCodeAt(i + 1);
if (nextChar >= 0xDC00 && nextChar <= 0xDFFF/* low surrogate */) {
// Combine the surrogate pair and store it escaped.
result += encodeHex((char - 0xD800) * 0x400 + nextChar - 0xDC00 + 0x10000);
// Advance index one extra since we already used that char here.
i++; continue;
}
}
escapeSeq = ESCAPE_SEQUENCES[char];
result += !escapeSeq && isPrintable(char)
? string[i]
: escapeSeq || encodeHex(char);
}
return result;
}
function writeFlowSequence(state, level, object) {
var _result = '',
_tag = state.tag,
index,
length;
for (index = 0, length = object.length; index < length; index += 1) {
// Write only valid elements.
if (writeNode(state, level, object[index], false, false)) {
if (index !== 0) _result += ',' + (!state.condenseFlow ? ' ' : '');
_result += state.dump;
}
}
state.tag = _tag;
state.dump = '[' + _result + ']';
}
function writeBlockSequence(state, level, object, compact) {
var _result = '',
_tag = state.tag,
index,
length;
for (index = 0, length = object.length; index < length; index += 1) {
// Write only valid elements.
if (writeNode(state, level + 1, object[index], true, true)) {
if (!compact || index !== 0) {
_result += generateNextLine(state, level);
}
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
_result += '-';
} else {
_result += '- ';
}
_result += state.dump;
}
}
state.tag = _tag;
state.dump = _result || '[]'; // Empty sequence if no valid values.
}
function writeFlowMapping(state, level, object) {
var _result = '',
_tag = state.tag,
objectKeyList = Object.keys(object),
index,
length,
objectKey,
objectValue,
pairBuffer;
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
pairBuffer = '';
if (index !== 0) pairBuffer += ', ';
if (state.condenseFlow) pairBuffer += '"';
objectKey = objectKeyList[index];
objectValue = object[objectKey];
if (!writeNode(state, level, objectKey, false, false)) {
continue; // Skip this pair because of invalid key;
}
if (state.dump.length > 1024) pairBuffer += '? ';
pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
if (!writeNode(state, level, objectValue, false, false)) {
continue; // Skip this pair because of invalid value.
}
pairBuffer += state.dump;
// Both key and value are valid.
_result += pairBuffer;
}
state.tag = _tag;
state.dump = '{' + _result + '}';
}
function writeBlockMapping(state, level, object, compact) {
var _result = '',
_tag = state.tag,
objectKeyList = Object.keys(object),
index,
length,
objectKey,
objectValue,
explicitPair,
pairBuffer;
// Allow sorting keys so that the output file is deterministic
if (state.sortKeys === true) {
// Default sorting
objectKeyList.sort();
} else if (typeof state.sortKeys === 'function') {
// Custom sort function
objectKeyList.sort(state.sortKeys);
} else if (state.sortKeys) {
// Something is wrong
throw new exception('sortKeys must be a boolean or a function');
}
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
pairBuffer = '';
if (!compact || index !== 0) {
pairBuffer += generateNextLine(state, level);
}
objectKey = objectKeyList[index];
objectValue = object[objectKey];
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
continue; // Skip this pair because of invalid key.
}
explicitPair = (state.tag !== null && state.tag !== '?') ||
(state.dump && state.dump.length > 1024);
if (explicitPair) {
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
pairBuffer += '?';
} else {
pairBuffer += '? ';
}
}
pairBuffer += state.dump;
if (explicitPair) {
pairBuffer += generateNextLine(state, level);
}
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
continue; // Skip this pair because of invalid value.
}
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
pairBuffer += ':';
} else {
pairBuffer += ': ';
}
pairBuffer += state.dump;
// Both key and value are valid.
_result += pairBuffer;
}
state.tag = _tag;
state.dump = _result || '{}'; // Empty mapping if no valid pairs.
}
function detectType(state, object, explicit) {
var _result, typeList, index, length, type, style;
typeList = explicit ? state.explicitTypes : state.implicitTypes;
for (index = 0, length = typeList.length; index < length; index += 1) {
type = typeList[index];
if ((type.instanceOf || type.predicate) &&
(!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
(!type.predicate || type.predicate(object))) {
state.tag = explicit ? type.tag : '?';
if (type.represent) {
style = state.styleMap[type.tag] || type.defaultStyle;
if (_toString.call(type.represent) === '[object Function]') {
_result = type.represent(object, style);
} else if (_hasOwnProperty.call(type.represent, style)) {
_result = type.represent[style](object, style);
} else {
throw new exception('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
}
state.dump = _result;
}
return true;
}
}
return false;
}
// Serializes `object` and writes it to global `result`.
// Returns true on success, or false on invalid object.
//
function writeNode(state, level, object, block, compact, iskey) {
state.tag = null;
state.dump = object;
if (!detectType(state, object, false)) {
detectType(state, object, true);
}
var type = _toString.call(state.dump);
if (block) {
block = (state.flowLevel < 0 || state.flowLevel > level);
}
var objectOrArray = type === '[object Object]' || type === '[object Array]',
duplicateIndex,
duplicate;
if (objectOrArray) {
duplicateIndex = state.duplicates.indexOf(object);
duplicate = duplicateIndex !== -1;
}
if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
compact = false;
}
if (duplicate && state.usedDuplicates[duplicateIndex]) {
state.dump = '*ref_' + duplicateIndex;
} else {
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
state.usedDuplicates[duplicateIndex] = true;
}
if (type === '[object Object]') {
if (block && (Object.keys(state.dump).length !== 0)) {
writeBlockMapping(state, level, state.dump, compact);
if (duplicate) {
state.dump = '&ref_' + duplicateIndex + state.dump;
}
} else {
writeFlowMapping(state, level, state.dump);
if (duplicate) {
state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
}
}
} else if (type === '[object Array]') {
var arrayLevel = (state.noArrayIndent && (level > 0)) ? level - 1 : level;
if (block && (state.dump.length !== 0)) {
writeBlockSequence(state, arrayLevel, state.dump, compact);
if (duplicate) {
state.dump = '&ref_' + duplicateIndex + state.dump;
}
} else {
writeFlowSequence(state, arrayLevel, state.dump);
if (duplicate) {
state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
}
}
} else if (type === '[object String]') {
if (state.tag !== '?') {
writeScalar(state, state.dump, level, iskey);
}
} else {
if (state.skipInvalid) return false;
throw new exception('unacceptable kind of an object to dump ' + type);
}
if (state.tag !== null && state.tag !== '?') {
state.dump = '!<' + state.tag + '> ' + state.dump;
}
}
return true;
}
function getDuplicateReferences(object, state) {
var objects = [],
duplicatesIndexes = [],
index,
length;
inspectNode(object, objects, duplicatesIndexes);
for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
state.duplicates.push(objects[duplicatesIndexes[index]]);
}
state.usedDuplicates = new Array(length);
}
function inspectNode(object, objects, duplicatesIndexes) {
var objectKeyList,
index,
length;
if (object !== null && typeof object === 'object') {
index = objects.indexOf(object);
if (index !== -1) {
if (duplicatesIndexes.indexOf(index) === -1) {
duplicatesIndexes.push(index);
}
} else {
objects.push(object);
if (Array.isArray(object)) {
for (index = 0, length = object.length; index < length; index += 1) {
inspectNode(object[index], objects, duplicatesIndexes);
}
} else {
objectKeyList = Object.keys(object);
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
}
}
}
}
}
function dump$1(input, options) {
options = options || {};
var state = new State(options);
if (!state.noRefs) getDuplicateReferences(input, state);
if (writeNode(state, 0, input, true, true)) return state.dump + '\n';
return '';
}
function safeDump$1(input, options) {
return dump$1(input, common.extend({ schema: default_safe }, options));
}
var dump_1 = dump$1;
var safeDump_1 = safeDump$1;
var dumper = {
dump: dump_1,
safeDump: safeDump_1
};
function deprecated(name) {
return function () {
throw new Error('Function ' + name + ' is deprecated and cannot be used.');
};
}
var Type = type;
var Schema = schema;
var FAILSAFE_SCHEMA = failsafe;
var JSON_SCHEMA = json;
var CORE_SCHEMA = core;
var DEFAULT_SAFE_SCHEMA = default_safe;
var DEFAULT_FULL_SCHEMA = default_full;
var load = loader.load;
var loadAll = loader.loadAll;
var safeLoad = loader.safeLoad;
var safeLoadAll = loader.safeLoadAll;
var dump = dumper.dump;
var safeDump = dumper.safeDump;
var YAMLException = exception;
// Deprecated schema names from JS-YAML 2.0.x
var MINIMAL_SCHEMA = failsafe;
var SAFE_SCHEMA = default_safe;
var DEFAULT_SCHEMA = default_full;
// Deprecated functions from JS-YAML 1.x.x
var scan = deprecated('scan');
var parse = deprecated('parse');
var compose = deprecated('compose');
var addConstructor = deprecated('addConstructor');
var jsYaml$1 = {
Type: Type,
Schema: Schema,
FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
JSON_SCHEMA: JSON_SCHEMA,
CORE_SCHEMA: CORE_SCHEMA,
DEFAULT_SAFE_SCHEMA: DEFAULT_SAFE_SCHEMA,
DEFAULT_FULL_SCHEMA: DEFAULT_FULL_SCHEMA,
load: load,
loadAll: loadAll,
safeLoad: safeLoad,
safeLoadAll: safeLoadAll,
dump: dump,
safeDump: safeDump,
YAMLException: YAMLException,
MINIMAL_SCHEMA: MINIMAL_SCHEMA,
SAFE_SCHEMA: SAFE_SCHEMA,
DEFAULT_SCHEMA: DEFAULT_SCHEMA,
scan: scan,
parse: parse,
compose: compose,
addConstructor: addConstructor
};
var jsYaml = jsYaml$1;
/*!
* escape-html
* Copyright(c) 2012-2013 TJ Holowaychuk
* Copyright(c) 2015 Andreas Lubbe
* Copyright(c) 2015 Tiancheng "Timothy" Gu
* MIT Licensed
*/
/**
* Module variables.
* @private
*/
var matchHtmlRegExp = /["'&<>]/;
/**
* Module exports.
* @public
*/
var escapeHtml_1 = escapeHtml;
/**
* Escape special characters in the given string of html.
*
* @param {string} string The string to escape for inserting into HTML
* @return {string}
* @public
*/
function escapeHtml(string) {
var str = '' + string;
var match = matchHtmlRegExp.exec(str);
if (!match) {
return str;
}
var escape;
var html = '';
var index = 0;
var lastIndex = 0;
for (index = match.index; index < str.length; index++) {
switch (str.charCodeAt(index)) {
case 34: // "
escape = '&quot;';
break;
case 38: // &
escape = '&amp;';
break;
case 39: // '
escape = '&#39;';
break;
case 60: // <
escape = '&lt;';
break;
case 62: // >
escape = '&gt;';
break;
default:
continue;
}
if (lastIndex !== index) {
html += str.substring(lastIndex, index);
}
lastIndex = index + 1;
html += escape;
}
return lastIndex !== index
? html + str.substring(lastIndex, index)
: html;
}
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
// this needs a big old cleanup
const newline = '\n';
// extract the yaml from 'yaml' nodes and put them in the vfil for later use
function default_frontmatter(
value,
messages
) {
try {
return jsYaml.safeLoad(value) ;
} catch (e) {
messages.push(new vfileMessage('YAML failed to parse'));
}
}
function parse_frontmatter({
parse,
type,
}) {
const transformer = (tree, vFile) => {
unistUtilVisit(tree, type, (node) => {
const data = parse(node.value, vFile.messages);
if (data) {
// @ts-ignore
vFile.data.fm = data;
}
});
};
return transformer;
}
// in code nodes replace the character witrh the html entities
// maybe I'll need more of these
const entites = [
[/</g, '&lt;'],
[/>/g, '&gt;'],
[/{/g, '&#123;'],
[/}/g, '&#125;'],
];
function escape_code({ blocks }) {
return function (tree) {
if (!blocks) {
unistUtilVisit(tree, 'code', escape);
}
unistUtilVisit(tree, 'inlineCode', escape);
function escape(node) {
for (let i = 0; i < entites.length; i += 1) {
node.value = node.value.replace(entites[i][0], entites[i][1]);
}
}
};
}
// special case - process nodes with retext and smartypants
// retext plugins can't work generally due to the difficulties in converting between the two trees
function smartypants_transformer(options = {}) {
const processor = retext().use(retextSmartypants, options);
return function (tree) {
unistUtilVisit(tree, 'text', (node) => {
node.value = String(processor.processSync(node.value));
});
};
}
// regex for scripts and attributes
const attrs = `(?:\\s{0,1}[a-zA-z]+=(?:"){0,1}[a-zA-Z0-9]+(?:"){0,1})*`;
const context = `(?:\\s{0,1}context)=(?:"){0,1}module(?:"){0,1}`;
const RE_BLANK = /^\n+$|^\s+$/;
const RE_SCRIPT = new RegExp(`^(<script` + attrs + `>)`);
const RE_MODULE_SCRIPT = new RegExp(
`^(<script` + attrs + context + attrs + `>)`
);
function extract_parts(nodes) {
// since we are wrapping and replacing we need to keep track of the different component 'parts'
// many special tags cannot be wrapped nor can style or script tags
const parts = {
special: [],
html: [],
instance: [],
module: [],
css: [],
};
// iterate through all top level child nodes and assign them to the correct 'part'
// anything that is a normal HAST node gets stored as HTML untouched
// everything else gets parsed by the svelte parser
children: for (let i = 0; i < nodes.length; i += 1) {
const empty_node =
nodes[i].type === 'text' && RE_BLANK.exec(nodes[i].value );
// i no longer knwo why i did this
if (empty_node || !nodes[i].value) {
if (
!parts.html.length ||
!(
RE_BLANK.exec(nodes[i].value ) &&
RE_BLANK.exec(parts.html[parts.html.length - 1].value )
)
) {
parts.html.push(nodes[i]);
}
continue children;
}
let result
;
try {
result = compiler_1(nodes[i].value );
} catch (e) {
parts.html.push(nodes[i]);
continue children;
}
// svelte special tags that have to be top level
if (!result.html || !result.html.children) return parts;
const _parts
= result.html.children.map((v) => {
if (
v.type === 'Options' ||
v.type === 'Head' ||
v.type === 'Window' ||
v.type === 'Body'
) {
return ['special', v.start, v.end];
} else {
return ['html', v.start, v.end];
}
});
results: for (const key in result) {
if (key === 'html' || !result[key ])
continue results;
_parts.push([
key ,
result[key ].start,
result[key ].end,
]);
}
// sort them to ensure the array is in the order they appear in the source, no gaps
// this might not be necessary any more, i forget
const sorted = _parts.sort((a, b) => a[1] - b[1]);
// push the nodes into the correct 'part' since they are sorted everything should be in the correct order
sorted.forEach((next) => {
parts[next[0]].push({
type: 'raw',
value: (nodes[i].value ).substring(next[1], next[2]),
});
});
}
return parts;
}
function map_layout_to_path(
filename,
layout_map
) {
const match = Object.keys(layout_map).find((l) =>
new RegExp(`\\` + `${sep}${l}` + `\\` + `${sep}`).test(
normalize$2(filename).replace(process.cwd(), '')
)
);
if (match) {
return layout_map[match];
} else {
return layout_map['_'] ? layout_map['_'] : undefined;
}
}
function generate_layout_import(
layout
) {
if (!layout) return false;
return `import Layout_MDSVEX_DEFAULT${
layout.components.length ? `, * as Components` : ''
} from '${layout.path}';`;
}
function generate_layout({
frontmatter_layout,
layout_options,
layout_mode,
filename,
}
) {
let selected_layout;
const error = { reason: '' };
if (!layout_options || frontmatter_layout === false) {
return [false, false, false];
} else if (layout_mode === 'single') {
selected_layout = layout_options.__mdsvex_default;
if (frontmatter_layout)
error.reason = `You attempted to apply a named layout in the front-matter of "${filename}", but did not provide any named layouts as options to the preprocessor. `;
} else if (frontmatter_layout) {
selected_layout = layout_options[frontmatter_layout];
if (!selected_layout)
error.reason = `Could not find a layout with the name "${frontmatter_layout}" and no fall back layout ("_") was provided.`;
} else {
selected_layout = map_layout_to_path(filename, layout_options);
}
return [
generate_layout_import(selected_layout),
selected_layout !== undefined &&
selected_layout.components.length > 0 &&
selected_layout.components,
error.reason ? error : false,
];
}
function transform_hast({
layout,
layout_mode,
}
) {
return function transformer(tree, vFile) {
// we need to keep { and } intact for svelte, so reverse the escaping in links and images
// if anyone actually uses these characters for any other reason i'll probably just cry
unistUtilVisit(tree, 'element', (node) => {
if (
node.tagName === 'a' &&
node.properties &&
typeof node.properties.href === 'string'
) {
node.properties.href = node.properties.href
.replace(/%7B/g, '{')
.replace(/%7D/g, '}');
}
if (
node.tagName === 'img' &&
node.properties &&
typeof node.properties.src === 'string'
) {
node.properties.src = node.properties.src
.replace(/%7B/g, '{')
.replace(/%7D/g, '}');
}
});
// the rest only applies to layouts and front matter
// this breaks position data
// svelte preprocessors don't currently support sourcemaps
// i'll fix this when they do
//@ts-ignore
if (!layout && !vFile.data.fm) return tree;
unistUtilVisit(tree, 'root', (node) => {
const { special, html, instance, module: _module, css } = extract_parts(
node.children
);
const { fm: metadata } = vFile.data ;
// Workaround for script and style tags in strings
// https://github.com/sveltejs/svelte/issues/5292
const stringified =
metadata &&
JSON.stringify(metadata).replace(/<(\/?script|\/?style)/g, '<"+"$1');
const fm =
metadata &&
`export const metadata = ${stringified};${newline}` +
`\tconst { ${Object.keys(metadata).join(', ')} } = metadata;`;
const frontmatter_layout =
metadata && (metadata.layout );
const [import_script, components, error] = generate_layout({
frontmatter_layout,
layout_options: layout,
layout_mode,
//@ts-ignore
filename: vFile.filename,
});
if (error) vFile.messages.push(new vfileMessage(error.reason));
if (components) {
for (let i = 0; i < components.length; i++) {
unistUtilVisit(tree, 'element', (node) => {
if (node.tagName === components[i]) {
node.tagName = `Components.${components[i]}`;
}
});
}
}
// add the layout if we are using one, reusing the existing script if one exists
if (import_script && !instance[0]) {
instance.push({
type: 'raw',
value: `${newline}<script>${newline}\t${import_script}${newline}</script>${newline}`,
});
} else if (import_script) {
instance[0].value = (instance[0].value ).replace(
RE_SCRIPT,
`$1${newline}\t${import_script}`
);
}
// inject the frontmatter into the module script if there is any, reusing the existing module script if one exists
if (!_module[0] && fm) {
_module.push({
type: 'raw',
value: `<script context="module">${newline}\t${fm}${newline}</script>`,
});
} else if (fm) {
// @ts-ignore
_module[0].value = _module[0].value.replace(
RE_MODULE_SCRIPT,
`$1${newline}\t${fm}`
);
}
// smoosh it all together in an order that makes sense,
// if using a layout we only wrap the html and nothing else
//@ts-ignore
node.children = [
//@ts-ignore
..._module,
//@ts-ignore
{ type: 'raw', value: _module[0] ? newline : '' },
//@ts-ignore
...instance,
//@ts-ignore
{ type: 'raw', value: instance[0] ? newline : '' },
//@ts-ignore
...css,
//@ts-ignore
{ type: 'raw', value: css[0] ? newline : '' },
//@ts-ignore
...special,
//@ts-ignore
{ type: 'raw', value: special[0] ? newline : '' },
{
//@ts-ignore
type: 'raw',
value: import_script
? `<Layout_MDSVEX_DEFAULT {...$$props}${
fm ? ' {...metadata}' : ''
}>`
: '',
},
//@ts-ignore
{ type: 'raw', value: newline },
//@ts-ignore
...html,
//@ts-ignore
{ type: 'raw', value: newline },
//@ts-ignore
{ type: 'raw', value: import_script ? '</Layout_MDSVEX_DEFAULT>' : '' },
];
});
};
}
// highlighting stuff
// { [lang]: { path, deps: pointer to key } }
const langs = {};
function highlight_blocks({
highlighter: highlight_fn,
alias,
}
= {}) {
if (highlight_fn && !true) {
if (alias) {
for (const lang in alias) {
langs[lang] = langs[alias[lang]];
}
}
}
return async function (tree) {
if (highlight_fn) {
const nodes = [];
unistUtilVisit(tree, 'code', (node) => {
nodes.push(node);
});
await Promise.all(
nodes.map(async (node) => {
(node ).type = 'html';
node.value = await highlight_fn(
node.value,
(node ).lang,
(node ).meta
);
})
);
}
};
}
// escape curlies, backtick, \t, \r, \n to avoid breaking output of {@html `here`} in .svelte
const escape_svelty = (str) =>
str
.replace(
/[{}`]/g,
//@ts-ignore
(c) => ({ '{': '&#123;', '}': '&#125;', '`': '&#96;' }[c])
)
.replace(/\\([trn])/g, '&#92;$1');
const code_highlight = (code, lang) => {
const normalised_lang = _optionalChain([lang, 'optionalAccess', _ => _.toLowerCase, 'call', _2 => _2()]);
{
const highlighted = escape_svelty(escapeHtml_1(code));
return `<pre class="language-${normalised_lang}">{@html \`<code class="language-${normalised_lang}">${highlighted}</code>\`}</pre>`;
}
};
function stringify( options = {}) {
this.Compiler = compiler;
function compiler(tree) {
return prettyhtmlHastToHtml(tree, options);
}
}
const apply_plugins = (plugins, parser) => {
(plugins ).forEach((plugin) => {
if (Array.isArray(plugin)) {
if (plugin[1] && plugin[1]) parser.use(plugin[0], plugin[1]);
else parser.use(plugin[0]);
} else {
parser.use(plugin);
}
});
return parser;
};
function transform(
{
remarkPlugins = [],
rehypePlugins = [],
frontmatter,
smartypants,
layout,
layout_mode,
highlight,
} = { layout_mode: 'single' }
) {
const fm_opts = frontmatter
? frontmatter
: { parse: default_frontmatter, type: 'yaml', marker: '-' };
const toMDAST = unified_1$1()
.use(remarkParse)
.use(mdsvex_parser)
.use(remarkExternalLinks, { target: false, rel: ['nofollow'] })
.use(escape_code, { blocks: !!highlight })
.use(remarkFrontmatter, [{ type: fm_opts.type, marker: fm_opts.marker }])
.use(parse_frontmatter, { parse: fm_opts.parse, type: fm_opts.type });
if (smartypants) {
toMDAST.use(
smartypants_transformer,
typeof smartypants === 'boolean' ? {} : smartypants
);
}
apply_plugins(remarkPlugins, toMDAST).use(highlight_blocks, highlight || {});
const toHAST = toMDAST
.use(remarkRehype, {
// @ts-ignore
allowDangerousHtml: true,
allowDangerousCharacters: true,
})
.use(transform_hast, { layout, layout_mode });
apply_plugins(rehypePlugins, toHAST);
const processor = toHAST.use(stringify, {
allowDangerousHtml: true,
allowDangerousCharacters: true,
});
return processor;
}
const defaults = {
remarkPlugins: [],
rehypePlugins: [],
smartypants: true,
extension: '.svx',
highlight: { highlighter: code_highlight },
};
function to_posix(_path) {
const isExtendedLengthPath = /^\\\\\?\\/.test(_path);
const hasNonAscii = /[^\u0000-\u0080]+/.test(_path);
if (isExtendedLengthPath || hasNonAscii) {
return _path;
}
return _path.replace(/\\/g, '/');
}
function resolve_layout(layout_path) {
try {
return to_posix(require.resolve(layout_path));
} catch (e) {
try {
const _path = join(process.cwd(), layout_path);
return to_posix(require.resolve(_path));
} catch (e) {
throw new Error(
`The layout path you provided couldn't be found at either ${layout_path} or ${join(
process.cwd(),
layout_path
)}. Please double-check it and try again.`
);
}
}
}
// handle custom components
function process_layouts(layouts) {
const _layouts = layouts;
for (const key in _layouts) {
const layout = fs.readFileSync(_layouts[key].path, { encoding: 'utf8' });
let ast;
try {
ast = compiler_1(layout);
} catch (e) {
throw new Error(e.toString() + `\n at ${_layouts[key].path}`);
}
if (ast.module) {
const component_exports = ast.module.content.body.filter(
(node) => node.type === 'ExportNamedDeclaration'
) ;
if (component_exports.length) {
_layouts[key].components = [];
for (let i = 0; i < component_exports.length; i++) {
if (
component_exports[i].specifiers &&
component_exports[i].specifiers.length
) {
for (let j = 0; j < component_exports[i].specifiers.length; j++) {
_layouts[key].components.push(
component_exports[i].specifiers[j].exported.name
);
}
//@ts-ignore
} else if (component_exports[i].declaration.declarations) {
//@ts-ignore
const declarations = component_exports[i].declaration.declarations;
for (let j = 0; j < declarations.length; j++) {
_layouts[key].components.push(declarations[j].id.name);
}
} else if (component_exports[i].declaration) {
_layouts[key].components.push(
//@ts-ignore
component_exports[i].declaration.id.name
);
}
}
}
}
}
return _layouts;
}
/**
* The svelte preprocessor for use with svelte.preprocess
*
* **options** - An options object with the following properties, all are optional.
*
* - `extension` - The extension to use for mdsvex files
* - `extensions` - The extensions to use for mdsvex files
* - `layout` - Layouts to apply to mdsvex documents
* - `frontmatter` - frontmatter options for documents
* - `highlight` - syntax highlighting options
* - `smartypants` - smart typography options
* - `remarkPlugins` - remark plugins to apply to the markdown
* - `rehypePlugins` - rehype plugins to apply to the rendered html
*
*/
const mdsvex = (options = defaults) => {
const {
remarkPlugins = [],
rehypePlugins = [],
smartypants = true,
extension = '.svx',
extensions,
layout = false,
highlight = { highlighter: code_highlight },
frontmatter,
} = options;
//@ts-ignore
if (options.layouts) {
throw new Error(
`mdsvex: "layouts" is not a valid option. Did you mean "layout"?`
);
}
const unknown_opts = [];
const known_opts = [
'filename',
'remarkPlugins',
'rehypePlugins',
'smartypants',
'extension',
'extensions',
'layout',
'highlight',
'frontmatter',
];
for (const opt in options) {
if (!known_opts.includes(opt)) unknown_opts.push(opt);
}
if (unknown_opts.length) {
console.warn(
`mdsvex: Received unknown options: ${unknown_opts.join(
', '
)}. Valid options are: ${known_opts.join(', ')}.`
);
}
let _layout = {};
let layout_mode = 'single';
if (typeof layout === 'string') {
_layout.__mdsvex_default = { path: resolve_layout(layout), components: [] };
} else if (typeof layout === 'object') {
layout_mode = 'named';
for (const name in layout) {
_layout[name] = { path: resolve_layout(layout[name]), components: [] };
}
}
if (highlight && highlight.highlighter === undefined) {
highlight.highlighter = code_highlight;
}
_layout = process_layouts(_layout);
const parser = transform({
remarkPlugins,
rehypePlugins,
smartypants,
layout: _layout,
layout_mode,
highlight,
frontmatter,
});
return {
markup: async ({ content, filename }) => {
const extensionsParts = (extensions || [extension]).map((ext) =>
ext.split('.').pop()
);
if (!extensionsParts.includes(filename.split('.').pop())) return;
const parsed = await parser.process({ contents: content, filename });
return {
code: parsed.contents ,
data: parsed.data ,
map: '',
};
},
};
};
/**
* The standalone compile function.
*
* - **source** - the source code to convert.
* - **options** - An options object with the following properties, all are optional.
*
* - `filename` - The filename of the generated file
* - `extension` - The extension to use for mdsvex files
* - `extensions` - The extensions to use for mdsvex files
* - `layout` - Layouts to apply to mdsvex documents
* - `frontmatter` - frontmatter options for documents
* - `highlight` - syntax highlighting options
* - `smartypants` - smart typography options
* - `remarkPlugins` - remark plugins to apply to the markdown
* - `rehypePlugins` - rehype plugins to apply to the rendered html
*/
const _compile = (
source,
opts
) =>
mdsvex(opts).markup({
content: source,
filename:
(opts && opts.filename) ||
`file${
(opts && ((opts.extensions && opts.extensions[0]) || opts.extension)) ||
'.svx'
}`,
});
exports.compile = _compile;
exports.defineMDSveXConfig = defineConfig;
exports.escapeSvelte = escape_svelty;
exports.mdsvex = mdsvex;
Object.defineProperty(exports, '__esModule', { value: true });
})));