@glimmer/util
Advanced tools
Comparing version 0.85.5 to 0.85.6
@@ -1,646 +0,2 @@ | ||
const EMPTY_ARRAY = Object.freeze([]); | ||
function emptyArray() { | ||
return EMPTY_ARRAY; | ||
} | ||
const EMPTY_STRING_ARRAY = emptyArray(); | ||
const EMPTY_NUMBER_ARRAY = emptyArray(); | ||
/** | ||
* This function returns `true` if the input array is the special empty array sentinel, | ||
* which is sometimes used for optimizations. | ||
*/ | ||
function isEmptyArray(input) { | ||
return input === EMPTY_ARRAY; | ||
} | ||
function* reverse(input) { | ||
for (let i = input.length - 1; i >= 0; i--) { | ||
yield input[i]; | ||
} | ||
} | ||
function* enumerate(input) { | ||
let i = 0; | ||
for (const item of input) { | ||
yield [i++, item]; | ||
} | ||
} | ||
// import Logger from './logger'; | ||
// let alreadyWarned = false; | ||
function debugAssert(test, msg) { | ||
// if (!alreadyWarned) { | ||
// alreadyWarned = true; | ||
// Logger.warn("Don't leave debug assertions on in public builds"); | ||
// } | ||
if (!test) { | ||
throw new Error(msg || 'assertion failure'); | ||
} | ||
} | ||
function deprecate(desc) { | ||
LOCAL_LOGGER.warn(`DEPRECATION: ${desc}`); | ||
} | ||
function keys(obj) { | ||
return Object.keys(obj); | ||
} | ||
function unwrap(val) { | ||
if (val === null || val === undefined) throw new Error(`Expected value to be present`); | ||
return val; | ||
} | ||
function expect(val, message) { | ||
if (val === null || val === undefined) throw new Error(message); | ||
return val; | ||
} | ||
function unreachable() { | ||
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'unreachable'; | ||
return new Error(message); | ||
} | ||
function exhausted(value) { | ||
throw new Error(`Exhausted ${String(value)}`); | ||
} | ||
const tuple = function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return args; | ||
}; | ||
function isPresent(value) { | ||
return value !== null && value !== undefined; | ||
} | ||
function assertPresent(value, message) { | ||
if (!isPresent(value)) { | ||
throw new Error(`Expected present, got ${typeof value === 'string' ? value : message}`); | ||
} | ||
} | ||
function isPresentArray(list) { | ||
return list.length > 0; | ||
} | ||
function ifPresent(list, ifPresent, otherwise) { | ||
if (isPresentArray(list)) { | ||
return ifPresent(list); | ||
} else { | ||
return otherwise(); | ||
} | ||
} | ||
function arrayToOption(list) { | ||
if (isPresentArray(list)) { | ||
return list; | ||
} else { | ||
return null; | ||
} | ||
} | ||
function assertPresentArray(list) { | ||
let message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : `unexpected empty list`; | ||
if (!isPresentArray(list)) { | ||
throw new Error(message); | ||
} | ||
} | ||
function asPresentArray(list) { | ||
let message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : `unexpected empty list`; | ||
assertPresentArray(list, message); | ||
return list; | ||
} | ||
function getLast(list) { | ||
return list.length === 0 ? undefined : list[list.length - 1]; | ||
} | ||
function getFirst(list) { | ||
return list.length === 0 ? undefined : list[0]; | ||
} | ||
function mapPresentArray(list, mapper) { | ||
if (list === null) { | ||
return null; | ||
} | ||
let out = []; | ||
for (let item of list) { | ||
out.push(mapper(item)); | ||
} | ||
return out; | ||
} | ||
function dict() { | ||
return Object.create(null); | ||
} | ||
function isDict(u) { | ||
return u !== null && u !== undefined; | ||
} | ||
function isObject(u) { | ||
return typeof u === 'function' || typeof u === 'object' && u !== null; | ||
} | ||
class StackImpl { | ||
stack; | ||
current = null; | ||
constructor() { | ||
let values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
this.stack = values; | ||
} | ||
get size() { | ||
return this.stack.length; | ||
} | ||
push(item) { | ||
this.current = item; | ||
this.stack.push(item); | ||
} | ||
pop() { | ||
let item = this.stack.pop(); | ||
this.current = getLast(this.stack) ?? null; | ||
return item === undefined ? null : item; | ||
} | ||
nth(from) { | ||
let len = this.stack.length; | ||
return len < from ? null : unwrap(this.stack[len - from]); | ||
} | ||
isEmpty() { | ||
return this.stack.length === 0; | ||
} | ||
toArray() { | ||
return this.stack; | ||
} | ||
} | ||
const LOCAL_DEBUG = (() => { | ||
let location = typeof window !== 'undefined' && window.location; | ||
if (location && /[&?]disable_local_debug/u.test(window.location.search)) { | ||
return false; | ||
} | ||
return true; | ||
})(); | ||
/// <reference types="qunit" /> | ||
let beginTestSteps; | ||
let endTestSteps; | ||
let verifySteps; | ||
let logStep; | ||
if (LOCAL_DEBUG) { | ||
let LOGGED_STEPS = null; | ||
beginTestSteps = () => { | ||
debugAssert(LOGGED_STEPS === null, 'attempted to start steps, but it already began'); | ||
LOGGED_STEPS = {}; | ||
}; | ||
endTestSteps = () => { | ||
debugAssert(LOGGED_STEPS, 'attempted to end steps, but they were not started'); | ||
LOGGED_STEPS = null; | ||
}; | ||
logStep = (type, step) => { | ||
if (LOGGED_STEPS === null) return; | ||
let steps = LOGGED_STEPS[type]; | ||
if (!steps) steps = LOGGED_STEPS[type] = []; | ||
steps.push(step); | ||
}; | ||
verifySteps = (type, expectedSteps, message) => { | ||
let loggedSteps = expect(LOGGED_STEPS, 'attempetd to verify steps, but steps were not started'); | ||
let steps = loggedSteps[type] || []; | ||
loggedSteps[type] = []; | ||
if (Array.isArray(expectedSteps)) { | ||
QUnit.config.current.assert.deepEqual(steps, expectedSteps, message); | ||
} else { | ||
expectedSteps(steps); | ||
} | ||
}; | ||
} | ||
let debugToString; | ||
{ | ||
let getFunctionName = fn => { | ||
let functionName = fn.name; | ||
if (functionName === undefined) { | ||
let match = /function (\w+)\s*\(/u.exec(String(fn)); | ||
functionName = match && match[1] || ''; | ||
} | ||
return functionName.replace(/^bound /u, ''); | ||
}; | ||
let getObjectName = obj => { | ||
let name; | ||
let className; | ||
if (obj.constructor && typeof obj.constructor === 'function') { | ||
className = getFunctionName(obj.constructor); | ||
} | ||
if ('toString' in obj && obj.toString !== Object.prototype.toString && obj.toString !== Function.prototype.toString) { | ||
name = obj.toString(); | ||
} | ||
// If the class has a decent looking name, and the `toString` is one of the | ||
// default Ember toStrings, replace the constructor portion of the toString | ||
// with the class name. We check the length of the class name to prevent doing | ||
// this when the value is minified. | ||
if (name && /<.*:ember\d+>/u.test(name) && className && className[0] !== '_' && className.length > 2 && className !== 'Class') { | ||
return name.replace(/<.*:/u, `<${className}:`); | ||
} | ||
return name || className; | ||
}; | ||
let getPrimitiveName = value => { | ||
return String(value); | ||
}; | ||
debugToString = value => { | ||
if (typeof value === 'function') { | ||
return getFunctionName(value) || `(unknown function)`; | ||
} else if (typeof value === 'object' && value !== null) { | ||
return getObjectName(value) || `(unknown object)`; | ||
} else { | ||
return getPrimitiveName(value); | ||
} | ||
}; | ||
} | ||
var debugToString$1 = debugToString; | ||
function clearElement(parent) { | ||
let current = parent.firstChild; | ||
while (current) { | ||
let next = current.nextSibling; | ||
parent.removeChild(current); | ||
current = next; | ||
} | ||
} | ||
const RAW_NODE = -1; | ||
const ELEMENT_NODE = 1; | ||
const TEXT_NODE = 3; | ||
const COMMENT_NODE = 8; | ||
const DOCUMENT_NODE = 9; | ||
const DOCUMENT_TYPE_NODE = 10; | ||
const DOCUMENT_FRAGMENT_NODE = 11; | ||
const NS_HTML = 'http://www.w3.org/1999/xhtml'; | ||
const NS_MATHML = 'http://www.w3.org/1998/Math/MathML'; | ||
const NS_SVG = 'http://www.w3.org/2000/svg'; | ||
const NS_XLINK = 'http://www.w3.org/1999/xlink'; | ||
const NS_XML = 'http://www.w3.org/XML/1998/namespace'; | ||
const NS_XMLNS = 'http://www.w3.org/2000/xmlns/'; | ||
const INSERT_BEFORE_BEGIN = 'beforebegin'; | ||
const INSERT_AFTER_BEGIN = 'afterbegin'; | ||
const INSERT_BEFORE_END = 'beforeend'; | ||
const INSERT_AFTER_END = 'afterend'; | ||
/* | ||
Encoding notes | ||
We use 30 bit integers for encoding, so that we don't ever encode a non-SMI | ||
integer to push on the stack. | ||
Handles are >= 0 | ||
Immediates are < 0 | ||
True, False, Undefined and Null are pushed as handles into the symbol table, | ||
with well known handles (0, 1, 2, 3) | ||
The negative space is divided into positives and negatives. Positives are | ||
higher numbers (-1, -2, -3, etc), negatives are lower. | ||
We only encode immediates for two reasons: | ||
1. To transfer over the wire, so they're smaller in general | ||
2. When pushing values onto the stack from the low level/inner VM, which may | ||
be converted into WASM one day. | ||
This allows the low-level VM to always use SMIs, and to minimize using JS | ||
values via handles for things like the stack pointer and frame pointer. | ||
Externally, most code pushes values as JS values, except when being pulled | ||
from the append byte code where it was already encoded. | ||
Logically, this is because the low level VM doesn't really care about these | ||
higher level values. For instance, the result of a userland helper may be a | ||
number, or a boolean, or undefined/null, but it's extra work to figure that | ||
out and push it correctly, vs. just pushing the value as a JS value with a | ||
handle. | ||
Note: The details could change here in the future, this is just the current | ||
strategy. | ||
*/ | ||
let ImmediateConstants = /*#__PURE__*/function (ImmediateConstants) { | ||
ImmediateConstants[ImmediateConstants["MAX_SMI"] = 1073741823] = "MAX_SMI"; | ||
ImmediateConstants[ImmediateConstants["MIN_SMI"] = -1073741824] = "MIN_SMI"; | ||
ImmediateConstants[ImmediateConstants["SIGN_BIT"] = -536870913] = "SIGN_BIT"; | ||
ImmediateConstants[ImmediateConstants["MAX_INT"] = 536870911] = "MAX_INT"; | ||
ImmediateConstants[ImmediateConstants["MIN_INT"] = -536870912] = "MIN_INT"; | ||
ImmediateConstants[ImmediateConstants["FALSE_HANDLE"] = 0] = "FALSE_HANDLE"; | ||
ImmediateConstants[ImmediateConstants["TRUE_HANDLE"] = 1] = "TRUE_HANDLE"; | ||
ImmediateConstants[ImmediateConstants["NULL_HANDLE"] = 2] = "NULL_HANDLE"; | ||
ImmediateConstants[ImmediateConstants["UNDEFINED_HANDLE"] = 3] = "UNDEFINED_HANDLE"; | ||
ImmediateConstants[ImmediateConstants["ENCODED_FALSE_HANDLE"] = 0] = "ENCODED_FALSE_HANDLE"; | ||
ImmediateConstants[ImmediateConstants["ENCODED_TRUE_HANDLE"] = 1] = "ENCODED_TRUE_HANDLE"; | ||
ImmediateConstants[ImmediateConstants["ENCODED_NULL_HANDLE"] = 2] = "ENCODED_NULL_HANDLE"; | ||
ImmediateConstants[ImmediateConstants["ENCODED_UNDEFINED_HANDLE"] = 3] = "ENCODED_UNDEFINED_HANDLE"; | ||
return ImmediateConstants; | ||
}({}); | ||
function isHandle(value) { | ||
return value >= 0; | ||
} | ||
function isNonPrimitiveHandle(value) { | ||
return value > ImmediateConstants.ENCODED_UNDEFINED_HANDLE; | ||
} | ||
function constants() { | ||
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) { | ||
values[_key] = arguments[_key]; | ||
} | ||
return [false, true, null, undefined, ...values]; | ||
} | ||
function isSmallInt(value) { | ||
return value % 1 === 0 && value <= ImmediateConstants.MAX_INT && value >= ImmediateConstants.MIN_INT; | ||
} | ||
function encodeNegative(num) { | ||
if (LOCAL_DEBUG) { | ||
debugAssert(num % 1 === 0 && num >= ImmediateConstants.MIN_INT && num < 0, `Could not encode negative: ${num}`); | ||
} | ||
return num & ImmediateConstants.SIGN_BIT; | ||
} | ||
function decodeNegative(num) { | ||
if (LOCAL_DEBUG) { | ||
debugAssert(num % 1 === 0 && num < ~ImmediateConstants.MAX_INT && num >= ImmediateConstants.MIN_SMI, `Could not decode negative: ${num}`); | ||
} | ||
return num | ~ImmediateConstants.SIGN_BIT; | ||
} | ||
function encodePositive(num) { | ||
if (LOCAL_DEBUG) { | ||
debugAssert(num % 1 === 0 && num >= 0 && num <= ImmediateConstants.MAX_INT, `Could not encode positive: ${num}`); | ||
} | ||
return ~num; | ||
} | ||
function decodePositive(num) { | ||
if (LOCAL_DEBUG) { | ||
debugAssert(num % 1 === 0 && num <= 0 && num >= ~ImmediateConstants.MAX_INT, `Could not decode positive: ${num}`); | ||
} | ||
return ~num; | ||
} | ||
function encodeHandle(num) { | ||
if (LOCAL_DEBUG) { | ||
debugAssert(num % 1 === 0 && num >= 0 && num <= ImmediateConstants.MAX_SMI, `Could not encode handle: ${num}`); | ||
} | ||
return num; | ||
} | ||
function decodeHandle(num) { | ||
if (LOCAL_DEBUG) { | ||
debugAssert(num % 1 === 0 && num <= ImmediateConstants.MAX_SMI && num >= 0, `Could not decode handle: ${num}`); | ||
} | ||
return num; | ||
} | ||
function encodeImmediate(num) { | ||
num |= 0; | ||
return num < 0 ? encodeNegative(num) : encodePositive(num); | ||
} | ||
function decodeImmediate(num) { | ||
num |= 0; | ||
return num > ImmediateConstants.SIGN_BIT ? decodePositive(num) : decodeNegative(num); | ||
} | ||
// Warm | ||
[1, 2, 3].forEach(x => decodeHandle(encodeHandle(x))); | ||
[1, -1].forEach(x => decodeImmediate(encodeImmediate(x))); | ||
/** | ||
Strongly hint runtimes to intern the provided string. | ||
When do I need to use this function? | ||
For the most part, never. Pre-mature optimization is bad, and often the | ||
runtime does exactly what you need it to, and more often the trade-off isn't | ||
worth it. | ||
Why? | ||
Runtimes store strings in at least 2 different representations: | ||
Ropes and Symbols (interned strings). The Rope provides a memory efficient | ||
data-structure for strings created from concatenation or some other string | ||
manipulation like splitting. | ||
Unfortunately checking equality of different ropes can be quite costly as | ||
runtimes must resort to clever string comparison algorithms. These | ||
algorithms typically cost in proportion to the length of the string. | ||
Luckily, this is where the Symbols (interned strings) shine. As Symbols are | ||
unique by their string content, equality checks can be done by pointer | ||
comparison. | ||
How do I know if my string is a rope or symbol? | ||
Typically (warning general sweeping statement, but truthy in runtimes at | ||
present) static strings created as part of the JS source are interned. | ||
Strings often used for comparisons can be interned at runtime if some | ||
criteria are met. One of these criteria can be the size of the entire rope. | ||
For example, in chrome 38 a rope longer then 12 characters will not | ||
intern, nor will segments of that rope. | ||
Some numbers: http://jsperf.com/eval-vs-keys/8 | ||
Known Trickā¢ | ||
@private | ||
@return {String} interned version of the provided string | ||
*/ | ||
function intern(str) { | ||
let obj = {}; | ||
obj[str] = 1; | ||
for (let key in obj) { | ||
if (key === str) { | ||
return key; | ||
} | ||
} | ||
return str; | ||
} | ||
const SERIALIZATION_FIRST_NODE_STRING = '%+b:0%'; | ||
function isSerializationFirstNode(node) { | ||
return node.nodeValue === SERIALIZATION_FIRST_NODE_STRING; | ||
} | ||
let assign = Object.assign; | ||
function fillNulls(count) { | ||
let arr = new Array(count); | ||
for (let i = 0; i < count; i++) { | ||
arr[i] = null; | ||
} | ||
return arr; | ||
} | ||
function values(obj) { | ||
return Object.values(obj); | ||
} | ||
function entries(dict) { | ||
return Object.entries(dict); | ||
} | ||
function castToSimple(node) { | ||
if (isDocument(node)) { | ||
return node; | ||
} else if (isSimpleElement(node)) { | ||
return node; | ||
} else { | ||
return node; | ||
} | ||
} | ||
// If passed a document, verify we're in the browser and return it as a Document | ||
// If we don't know what this is, but the check requires it to be an element, | ||
// the cast will mandate that it's a browser element | ||
// Finally, if it's a more generic check, the cast will mandate that it's a | ||
// browser node and return a BrowserNodeUtils corresponding to the check | ||
function castToBrowser(node, sugaryCheck) { | ||
if (node === null || node === undefined) { | ||
return null; | ||
} | ||
if (typeof document === undefined) { | ||
throw new Error('Attempted to cast to a browser node in a non-browser context'); | ||
} | ||
if (isDocument(node)) { | ||
return node; | ||
} | ||
if (node.ownerDocument !== document) { | ||
throw new Error('Attempted to cast to a browser node with a node that was not created from this document'); | ||
} | ||
return checkBrowserNode(node, sugaryCheck); | ||
} | ||
function checkError(from, check) { | ||
return new Error(`cannot cast a ${from} into ${String(check)}`); | ||
} | ||
function isDocument(node) { | ||
return node.nodeType === DOCUMENT_NODE; | ||
} | ||
function isSimpleElement(node) { | ||
return node?.nodeType === ELEMENT_NODE; | ||
} | ||
function isElement(node) { | ||
return node?.nodeType === ELEMENT_NODE && node instanceof Element; | ||
} | ||
function checkBrowserNode(node, check) { | ||
let isMatch = false; | ||
if (node !== null) { | ||
if (typeof check === 'string') { | ||
isMatch = stringCheckNode(node, check); | ||
} else if (Array.isArray(check)) { | ||
isMatch = check.some(c => stringCheckNode(node, c)); | ||
} else { | ||
throw unreachable(); | ||
} | ||
} | ||
if (isMatch && node instanceof Node) { | ||
return node; | ||
} else { | ||
throw checkError(`SimpleElement(${node?.constructor?.name ?? 'null'})`, check); | ||
} | ||
} | ||
function stringCheckNode(node, check) { | ||
switch (check) { | ||
case 'NODE': | ||
return true; | ||
case 'HTML': | ||
return node instanceof HTMLElement; | ||
case 'SVG': | ||
return node instanceof SVGElement; | ||
case 'ELEMENT': | ||
return node instanceof Element; | ||
default: | ||
if (check.toUpperCase() === check) { | ||
throw new Error(`BUG: this code is missing handling for a generic node type`); | ||
} | ||
return node instanceof Element && node.tagName.toLowerCase() === check; | ||
} | ||
} | ||
function strip(strings) { | ||
let out = ''; | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
for (const [i, string] of enumerate(strings)) { | ||
let dynamic = args[i] !== undefined ? String(args[i]) : ''; | ||
out += `${string}${dynamic}`; | ||
} | ||
let lines = out.split('\n'); | ||
while (isPresentArray(lines) && /^\s*$/u.test(getFirst(lines))) { | ||
lines.shift(); | ||
} | ||
while (isPresentArray(lines) && /^\s*$/u.test(getLast(lines))) { | ||
lines.pop(); | ||
} | ||
let min = Infinity; | ||
for (let line of lines) { | ||
let leading = /^\s*/u.exec(line)[0].length; | ||
min = Math.min(min, leading); | ||
} | ||
let stripped = []; | ||
for (let line of lines) { | ||
stripped.push(line.slice(min)); | ||
} | ||
return stripped.join('\n'); | ||
} | ||
function unwrapHandle(handle) { | ||
if (typeof handle === 'number') { | ||
return handle; | ||
} else { | ||
let error = handle.errors[0]; | ||
throw new Error(`Compile Error: ${error.problem} @ ${error.span.start}..${error.span.end}`); | ||
} | ||
} | ||
function unwrapTemplate(template) { | ||
if (template.result === 'error') { | ||
throw new Error(`Compile Error: ${template.problem} @ ${template.span.start}..${template.span.end}`); | ||
} | ||
return template; | ||
} | ||
function extractHandle(handle) { | ||
if (typeof handle === 'number') { | ||
return handle; | ||
} else { | ||
return handle.handle; | ||
} | ||
} | ||
function isOkHandle(handle) { | ||
return typeof handle === 'number'; | ||
} | ||
function isErrHandle(handle) { | ||
return typeof handle === 'number'; | ||
} | ||
function buildUntouchableThis(source) { | ||
let context = null; | ||
{ | ||
let assertOnProperty = property => { | ||
let access = typeof property === 'symbol' || typeof property === 'number' ? `[${String(property)}]` : `.${property}`; | ||
throw new Error(`You accessed \`this${access}\` from a function passed to the ${source}, but the function itself was not bound to a valid \`this\` context. Consider updating to use a bound function (for instance, use an arrow function, \`() => {}\`).`); | ||
}; | ||
context = new Proxy({}, { | ||
get(_target, property) { | ||
assertOnProperty(property); | ||
}, | ||
set(_target, property) { | ||
assertOnProperty(property); | ||
return false; | ||
}, | ||
has(_target, property) { | ||
assertOnProperty(property); | ||
return false; | ||
} | ||
}); | ||
} | ||
return context; | ||
} | ||
/** | ||
* This constant exists to make it easier to differentiate normal logs from | ||
* errant console.logs. LOCAL_LOGGER should only be used inside a | ||
* LOCAL_SHOULD_LOG check. | ||
* | ||
* It does not alleviate the need to check LOCAL_SHOULD_LOG, which is used | ||
* for stripping. | ||
*/ | ||
const LOCAL_LOGGER = console; | ||
/** | ||
* This constant exists to make it easier to differentiate normal logs from | ||
* errant console.logs. LOGGER can be used outside of LOCAL_SHOULD_LOG checks, | ||
* and is meant to be used in the rare situation where a console.* call is | ||
* actually appropriate. | ||
*/ | ||
const LOGGER = console; | ||
function assertNever(value) { | ||
let desc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unexpected unreachable branch'; | ||
LOGGER.log('unreachable', value); | ||
LOGGER.log(`${desc} :: ${JSON.stringify(value)} (${value})`); | ||
throw new Error(`code reached unreachable`); | ||
} | ||
export { COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, EMPTY_ARRAY, EMPTY_NUMBER_ARRAY, EMPTY_STRING_ARRAY, INSERT_AFTER_BEGIN, INSERT_AFTER_END, INSERT_BEFORE_BEGIN, INSERT_BEFORE_END, ImmediateConstants, LOCAL_LOGGER, LOGGER, NS_HTML, NS_MATHML, NS_SVG, NS_XLINK, NS_XML, NS_XMLNS, RAW_NODE, SERIALIZATION_FIRST_NODE_STRING, StackImpl as Stack, TEXT_NODE, arrayToOption, asPresentArray, debugAssert as assert, assertNever, assertPresent, assertPresentArray, assign, beginTestSteps, buildUntouchableThis, castToBrowser, castToSimple, checkBrowserNode as checkNode, clearElement, constants, debugToString$1 as debugToString, decodeHandle, decodeImmediate, decodeNegative, decodePositive, deprecate, dict, emptyArray, encodeHandle, encodeImmediate, encodeNegative, encodePositive, endTestSteps, entries, enumerate, exhausted, expect, extractHandle, fillNulls, getFirst, getLast, ifPresent, intern, isDict, isElement, isEmptyArray, isErrHandle, isHandle, isNonPrimitiveHandle, isObject, isOkHandle, isPresent, isPresentArray, isSerializationFirstNode, isSimpleElement, isSmallInt, keys, logStep, mapPresentArray, reverse, strip, tuple, unreachable, unwrap, unwrapHandle, unwrapTemplate, values, verifySteps }; | ||
const t=Object.freeze([]);function n(){return t}const e=n(),r=n();function o(n){return n===t}function*u(t){for(let n=t.length-1;n>=0;n--)yield t[n]}function*i(t){let n=0;for(const e of t)yield[n++,e]}function c(t,n){if(!t)throw new Error(n||"assertion failure")}function l(t){Ot.warn(`DEPRECATION: ${t}`)}function s(t){return Object.keys(t)}function f(t){if(null==t)throw new Error("Expected value to be present");return t}function a(t,n){if(null==t)throw new Error(n);return t}function d(){return new Error(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"unreachable")}function h(t){throw new Error(`Exhausted ${String(t)}`)}const E=function(){for(var t=arguments.length,n=new Array(t),e=0;e<t;e++)n[e]=arguments[e];return n};function w(t){return null!=t}function p(t,n){if(!w(t))throw new Error(`Expected present, got ${"string"==typeof t?t:n}`)}function N(t){return t.length>0}function g(t,n,e){return N(t)?n(t):e()}function _(t){return N(t)?t:null}function D(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"unexpected empty list";if(!N(t))throw new Error(n)}function b(t){return D(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"unexpected empty list"),t}function A(t){return 0===t.length?void 0:t[t.length-1]}function m(t){return 0===t.length?void 0:t[0]}function y(t,n){if(null===t)return null;let e=[];for(let r of t)e.push(n(r));return e}function I(){return Object.create(null)}function L(t){return null!=t}function S(t){return"function"==typeof t||"object"==typeof t&&null!==t}class M{stack;current=null;constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.stack=t}get size(){return this.stack.length}push(t){this.current=t,this.stack.push(t)}pop(){let t=this.stack.pop();return this.current=A(this.stack)??null,void 0===t?null:t}nth(t){let n=this.stack.length;return n<t?null:f(this.stack[n-t])}isEmpty(){return 0===this.stack.length}toArray(){return this.stack}}const $=!("undefined"!=typeof window&&window.location&&/[&?]disable_local_debug/u.test(window.location.search));let T,v,C,H,O;if($){let t=null;T=()=>{c(null===t,"attempted to start steps, but it already began"),t={}},v=()=>{c(t,"attempted to end steps, but they were not started"),t=null},H=(n,e)=>{if(null===t)return;let r=t[n];r||(r=t[n]=[]),r.push(e)},C=(n,e,r)=>{let o=a(t,"attempetd to verify steps, but steps were not started"),u=o[n]||[];o[n]=[],Array.isArray(e)?QUnit.config.current.assert.deepEqual(u,e,r):e(u)}}{let t=t=>{let n=t.name;if(void 0===n){let e=/function (\w+)\s*\(/u.exec(String(t));n=e&&e[1]||""}return n.replace(/^bound /u,"")},n=n=>{let e,r;return n.constructor&&"function"==typeof n.constructor&&(r=t(n.constructor)),"toString"in n&&n.toString!==Object.prototype.toString&&n.toString!==Function.prototype.toString&&(e=n.toString()),e&&/<.*:ember\d+>/u.test(e)&&r&&"_"!==r[0]&&r.length>2&&"Class"!==r?e.replace(/<.*:/u,`<${r}:`):e||r},e=t=>String(t);O=r=>"function"==typeof r?t(r)||"(unknown function)":"object"==typeof r&&null!==r?n(r)||"(unknown object)":e(r)}var k=O;function x(t){let n=t.firstChild;for(;n;){let e=n.nextSibling;t.removeChild(n),n=e}}const U=-1,j=1,X=3,F=8,G=9,B=10,R=11,V="http://www.w3.org/1999/xhtml",z="http://www.w3.org/1998/Math/MathML",P="http://www.w3.org/2000/svg",q="http://www.w3.org/1999/xlink",J="http://www.w3.org/XML/1998/namespace",Q="http://www.w3.org/2000/xmlns/",Y="beforebegin",K="afterbegin",W="beforeend",Z="afterend";let tt=function(t){return t[t.MAX_SMI=1073741823]="MAX_SMI",t[t.MIN_SMI=-1073741824]="MIN_SMI",t[t.SIGN_BIT=-536870913]="SIGN_BIT",t[t.MAX_INT=536870911]="MAX_INT",t[t.MIN_INT=-536870912]="MIN_INT",t[t.FALSE_HANDLE=0]="FALSE_HANDLE",t[t.TRUE_HANDLE=1]="TRUE_HANDLE",t[t.NULL_HANDLE=2]="NULL_HANDLE",t[t.UNDEFINED_HANDLE=3]="UNDEFINED_HANDLE",t[t.ENCODED_FALSE_HANDLE=0]="ENCODED_FALSE_HANDLE",t[t.ENCODED_TRUE_HANDLE=1]="ENCODED_TRUE_HANDLE",t[t.ENCODED_NULL_HANDLE=2]="ENCODED_NULL_HANDLE",t[t.ENCODED_UNDEFINED_HANDLE=3]="ENCODED_UNDEFINED_HANDLE",t}({});function nt(t){return t>=0}function et(t){return t>tt.ENCODED_UNDEFINED_HANDLE}function rt(){for(var t=arguments.length,n=new Array(t),e=0;e<t;e++)n[e]=arguments[e];return[!1,!0,null,void 0,...n]}function ot(t){return t%1==0&&t<=tt.MAX_INT&&t>=tt.MIN_INT}function ut(t){return $&&c(t%1==0&&t>=tt.MIN_INT&&t<0,`Could not encode negative: ${t}`),t&tt.SIGN_BIT}function it(t){return $&&c(t%1==0&&t<~tt.MAX_INT&&t>=tt.MIN_SMI,`Could not decode negative: ${t}`),t|~tt.SIGN_BIT}function ct(t){return $&&c(t%1==0&&t>=0&&t<=tt.MAX_INT,`Could not encode positive: ${t}`),~t}function lt(t){return $&&c(t%1==0&&t<=0&&t>=~tt.MAX_INT,`Could not decode positive: ${t}`),~t}function st(t){return $&&c(t%1==0&&t>=0&&t<=tt.MAX_SMI,`Could not encode handle: ${t}`),t}function ft(t){return $&&c(t%1==0&&t<=tt.MAX_SMI&&t>=0,`Could not decode handle: ${t}`),t}function at(t){return(t|=0)<0?ut(t):ct(t)}function dt(t){return(t|=0)>tt.SIGN_BIT?lt(t):it(t)}function ht(t){let n={};n[t]=1;for(let e in n)if(e===t)return e;return t}[1,2,3].forEach((t=>ft(st(t)))),[1,-1].forEach((t=>dt(at(t))));const Et="%+b:0%";function wt(t){return t.nodeValue===Et}let pt=Object.assign;function Nt(t){let n=new Array(t);for(let e=0;e<t;e++)n[e]=null;return n}function gt(t){return Object.values(t)}function _t(t){return Object.entries(t)}function Dt(t){return At(t)||mt(t),t}function bt(t,n){if(null==t)return null;if(void 0===typeof document)throw new Error("Attempted to cast to a browser node in a non-browser context");if(At(t))return t;if(t.ownerDocument!==document)throw new Error("Attempted to cast to a browser node with a node that was not created from this document");return It(t,n)}function At(t){return t.nodeType===G}function mt(t){return t?.nodeType===j}function yt(t){return t?.nodeType===j&&t instanceof Element}function It(t,n){let e=!1;if(null!==t)if("string"==typeof n)e=Lt(t,n);else{if(!Array.isArray(n))throw d();e=n.some((n=>Lt(t,n)))}if(e&&t instanceof Node)return t;throw function(t,n){return new Error(`cannot cast a ${t} into ${String(n)}`)}(`SimpleElement(${t?.constructor?.name??"null"})`,n)}function Lt(t,n){switch(n){case"NODE":return!0;case"HTML":return t instanceof HTMLElement;case"SVG":return t instanceof SVGElement;case"ELEMENT":return t instanceof Element;default:if(n.toUpperCase()===n)throw new Error("BUG: this code is missing handling for a generic node type");return t instanceof Element&&t.tagName.toLowerCase()===n}}function St(t){let n="";for(var e=arguments.length,r=new Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=arguments[o];for(const[e,o]of i(t)){n+=`${o}${void 0!==r[e]?String(r[e]):""}`}let u=n.split("\n");for(;N(u)&&/^\s*$/u.test(m(u));)u.shift();for(;N(u)&&/^\s*$/u.test(A(u));)u.pop();let c=1/0;for(let t of u){let n=/^\s*/u.exec(t)[0].length;c=Math.min(c,n)}let l=[];for(let t of u)l.push(t.slice(c));return l.join("\n")}function Mt(t){if("number"==typeof t)return t;{let n=t.errors[0];throw new Error(`Compile Error: ${n.problem} @ ${n.span.start}..${n.span.end}`)}}function $t(t){if("error"===t.result)throw new Error(`Compile Error: ${t.problem} @ ${t.span.start}..${t.span.end}`);return t}function Tt(t){return"number"==typeof t?t:t.handle}function vt(t){return"number"==typeof t}function Ct(t){return"number"==typeof t}function Ht(t){let n=null;{let e=n=>{let e="symbol"==typeof n||"number"==typeof n?`[${String(n)}]`:`.${n}`;throw new Error(`You accessed \`this${e}\` from a function passed to the ${t}, but the function itself was not bound to a valid \`this\` context. Consider updating to use a bound function (for instance, use an arrow function, \`() => {}\`).`)};n=new Proxy({},{get(t,n){e(n)},set:(t,n)=>(e(n),!1),has:(t,n)=>(e(n),!1)})}return n}const Ot=console,kt=console;function xt(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"unexpected unreachable branch";throw kt.log("unreachable",t),kt.log(`${n} :: ${JSON.stringify(t)} (${t})`),new Error("code reached unreachable")}export{F as COMMENT_NODE,R as DOCUMENT_FRAGMENT_NODE,G as DOCUMENT_NODE,B as DOCUMENT_TYPE_NODE,j as ELEMENT_NODE,t as EMPTY_ARRAY,r as EMPTY_NUMBER_ARRAY,e as EMPTY_STRING_ARRAY,K as INSERT_AFTER_BEGIN,Z as INSERT_AFTER_END,Y as INSERT_BEFORE_BEGIN,W as INSERT_BEFORE_END,tt as ImmediateConstants,Ot as LOCAL_LOGGER,kt as LOGGER,V as NS_HTML,z as NS_MATHML,P as NS_SVG,q as NS_XLINK,J as NS_XML,Q as NS_XMLNS,U as RAW_NODE,Et as SERIALIZATION_FIRST_NODE_STRING,M as Stack,X as TEXT_NODE,_ as arrayToOption,b as asPresentArray,c as assert,xt as assertNever,p as assertPresent,D as assertPresentArray,pt as assign,T as beginTestSteps,Ht as buildUntouchableThis,bt as castToBrowser,Dt as castToSimple,It as checkNode,x as clearElement,rt as constants,k as debugToString,ft as decodeHandle,dt as decodeImmediate,it as decodeNegative,lt as decodePositive,l as deprecate,I as dict,n as emptyArray,st as encodeHandle,at as encodeImmediate,ut as encodeNegative,ct as encodePositive,v as endTestSteps,_t as entries,i as enumerate,h as exhausted,a as expect,Tt as extractHandle,Nt as fillNulls,m as getFirst,A as getLast,g as ifPresent,ht as intern,L as isDict,yt as isElement,o as isEmptyArray,Ct as isErrHandle,nt as isHandle,et as isNonPrimitiveHandle,S as isObject,vt as isOkHandle,w as isPresent,N as isPresentArray,wt as isSerializationFirstNode,mt as isSimpleElement,ot as isSmallInt,s as keys,H as logStep,y as mapPresentArray,u as reverse,St as strip,E as tuple,d as unreachable,f as unwrap,Mt as unwrapHandle,$t as unwrapTemplate,gt as values,C as verifySteps}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@glimmer/util", | ||
"type": "module", | ||
"version": "0.85.5", | ||
"version": "0.85.6", | ||
"description": "Common utilities used in Glimmer", | ||
@@ -10,3 +10,3 @@ "repository": "https://github.com/tildeio/glimmer/tree/master/packages/@glimmer/util", | ||
"@glimmer/env": "0.1.7", | ||
"@glimmer/interfaces": "^0.85.5" | ||
"@glimmer/interfaces": "^0.85.6" | ||
}, | ||
@@ -21,3 +21,3 @@ "files": [ | ||
"publint": "^0.2.5", | ||
"@glimmer/local-debug-flags": "^0.85.5", | ||
"@glimmer/local-debug-flags": "^0.85.6", | ||
"@glimmer-workspace/build-support": "^1.0.0" | ||
@@ -24,0 +24,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108899
1171
Updated@glimmer/interfaces@^0.85.6