UNPKG

@glimmer/util

Version:
3 lines (2 loc) 8.9 kB
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 s(t){Ot.warn(`DEPRECATION: ${t}`)}function l(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 E(t="unreachable"){return new Error(t)}function d(t){throw new Error(`Exhausted ${String(t)}`)}const h=(...t)=>t;function p(t){return null!=t}function w(t,n){if(!p(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,n="unexpected empty list"){if(!N(t))throw new Error(n)}function b(t,n="unexpected empty list"){return D(t,n),t}function m(t){return 0===t.length?void 0:t[t.length-1]}function I(t){return 0===t.length?void 0:t[0]}function A(t,n){if(null===t)return null;let e=[];for(let r of t)e.push(n(r));return e}function y(){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(t=[]){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=m(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,C,H,O,v;if($){let t=null;T=()=>{c(null===t,"attempted to start steps, but it already began"),t={}},C=()=>{c(t,"attempted to end steps, but they were not started"),t=null},O=(n,e)=>{if(null===t)return;let r=t[n];r||(r=t[n]=[]),r.push(e)},H=(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);v=r=>"function"==typeof r?t(r)||"(unknown function)":"object"==typeof r&&null!==r?n(r)||"(unknown object)":e(r)}var k=v;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(...t){return[!1,!0,null,void 0,...t]}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 st(t){return $&&c(t%1==0&&t<=0&&t>=~tt.MAX_INT,`Could not decode positive: ${t}`),~t}function lt(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 Et(t){return(t|=0)>tt.SIGN_BIT?st(t):it(t)}function dt(t){let n={};n[t]=1;for(let e in n)if(e===t)return e;return t}[1,2,3].forEach((t=>ft(lt(t)))),[1,-1].forEach((t=>Et(at(t))));const ht="%+b:0%";function pt(t){return t.nodeValue===ht}let wt=Object.assign;function Nt(t){return Object.values(t)}function gt(t){return Object.entries(t)}function _t(t){return bt(t)||mt(t),t}function Dt(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(bt(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 At(t,n)}function bt(t){return t.nodeType===G}function mt(t){return t?.nodeType===j}function It(t){return t?.nodeType===j&&t instanceof Element}function At(t,n){let e=!1;if(null!==t)if("string"==typeof n)e=yt(t,n);else{if(!Array.isArray(n))throw E();e=n.some((n=>yt(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 yt(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 Lt(t,...n){let e="";for(const[r,o]of i(t)){e+=`${o}${void 0!==n[r]?String(n[r]):""}`}let r=e.split("\n");for(;N(r)&&/^\s*$/u.test(I(r));)r.shift();for(;N(r)&&/^\s*$/u.test(m(r));)r.pop();let o=1/0;for(let t of r){let n=/^\s*/u.exec(t)[0].length;o=Math.min(o,n)}let u=[];for(let t of r)u.push(t.slice(o));return u.join("\n")}function St(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 Mt(t){if("error"===t.result)throw new Error(`Compile Error: ${t.problem} @ ${t.span.start}..${t.span.end}`);return t}function $t(t){return"number"==typeof t?t:t.handle}function Tt(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,vt=console;function kt(t,n="unexpected unreachable branch"){throw vt.log("unreachable",t),vt.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,vt 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,ht as SERIALIZATION_FIRST_NODE_STRING,M as Stack,X as TEXT_NODE,_ as arrayToOption,b as asPresentArray,c as assert,kt as assertNever,w as assertPresent,D as assertPresentArray,wt as assign,T as beginTestSteps,Ht as buildUntouchableThis,Dt as castToBrowser,_t as castToSimple,At as checkNode,x as clearElement,rt as constants,k as debugToString,ft as decodeHandle,Et as decodeImmediate,it as decodeNegative,st as decodePositive,s as deprecate,y as dict,n as emptyArray,lt as encodeHandle,at as encodeImmediate,ut as encodeNegative,ct as encodePositive,C as endTestSteps,gt as entries,i as enumerate,d as exhausted,a as expect,$t as extractHandle,I as getFirst,m as getLast,g as ifPresent,dt as intern,L as isDict,It as isElement,o as isEmptyArray,Ct as isErrHandle,nt as isHandle,et as isNonPrimitiveHandle,S as isObject,Tt as isOkHandle,p as isPresent,N as isPresentArray,pt as isSerializationFirstNode,mt as isSimpleElement,ot as isSmallInt,l as keys,O as logStep,A as mapPresentArray,u as reverse,Lt as strip,h as tuple,E as unreachable,f as unwrap,St as unwrapHandle,Mt as unwrapTemplate,Nt as values,H as verifySteps}; //# sourceMappingURL=index.js.map