@lipsjs/lips 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -1
- package/dist/lips.js +3532 -1094
- package/dist/lips.js.map +44 -19
- package/dist/lips.min.js +13 -9
- package/dist/lips.min.js.map +44 -19
- package/dist/mf2.min.js +4 -0
- package/dist/mf2.min.js.map +38 -0
- package/dist/precompile.min.js +19 -16
- package/dist/precompile.min.js.map +7 -6
- package/dist/runtime.min.js +4 -3
- package/dist/runtime.min.js.map +13 -12
- package/dist/stylis.min.js +3 -0
- package/dist/stylis.min.js.map +16 -0
- package/dist/types/i18n/engine.d.ts +14 -0
- package/dist/types/i18n/index.d.ts +122 -5
- package/dist/types/i18n/intl.d.ts +1 -0
- package/dist/types/i18n/lookup.d.ts +22 -0
- package/dist/types/ir/compiler.d.ts +75 -2
- package/dist/types/ir/expression.d.ts +32 -3
- package/dist/types/ir/facade.d.ts +74 -30
- package/dist/types/ir/host.d.ts +75 -0
- package/dist/types/ir/index.d.ts +5 -2
- package/dist/types/ir/policy.d.ts +95 -0
- package/dist/types/ir/runtime.d.ts +54 -19
- package/dist/types/ir/signal.d.ts +6 -4
- package/dist/types/ir/style.d.ts +119 -0
- package/dist/types/ir/swap.d.ts +5 -0
- package/dist/types/ir/tree.d.ts +51 -0
- package/dist/types/lips.d.ts +20 -3
- package/dist/types/lynx/a11y.d.ts +61 -0
- package/dist/types/lynx/background.d.ts +71 -0
- package/dist/types/lynx/main.d.ts +46 -0
- package/dist/types/lynx/protocol.d.ts +52 -0
- package/dist/types/lynx/style.d.ts +49 -0
- package/dist/types/lynx/template.d.ts +37 -0
- package/dist/types/mf2.d.ts +14 -0
- package/dist/types/precompile.d.ts +30 -5
- package/dist/types/runtime.d.ts +1 -1
- package/dist/types/stylesheet.d.ts +12 -16
- package/dist/types/stylis.d.ts +2 -0
- package/dist/types/types.d.ts +138 -11
- package/dist/types/untrusted.d.ts +17 -0
- package/dist/untrusted.min.js +5 -0
- package/dist/untrusted.min.js.map +13 -0
- package/package.json +20 -3
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var G=["===","!==","...","=>","==","!=","<=",">=","&&","||","??","?.","++","--","+=","-=","*=","/=","%=","+","-","*","/","%","<",">","!","?",":",".",",","(",")","[","]","{","}","="];function z(t,e){let r=[],s=0,f=(g)=>/[A-Za-z_$]/.test(g),m=(g)=>/[A-Za-z0-9_$]/.test(g);while(s<t.length){let g=t[s];if(/\s/.test(g)){s++;continue}if(/[0-9]/.test(g)||g==="."&&/[0-9]/.test(t[s+1])){let p=s;while(s<t.length&&/[0-9]/.test(t[s]))s++;if(t[s]==="."){s++;while(s<t.length&&/[0-9]/.test(t[s]))s++}if(t[s]==="e"||t[s]==="E"){if(s++,t[s]==="+"||t[s]==="-")s++;while(s<t.length&&/[0-9]/.test(t[s]))s++}r.push({t:"num",value:t.slice(p,s),start:p,end:s});continue}if(g==="'"||g==='"'){let p=s;s++;let l="",o=!1;while(s<t.length){let n=t[s];if(n==="\\"){let a=t[s+1],c={n:`
|
|
2
|
+
`,t:"\t",r:"\r",b:"\b",f:"\f",v:"\v","0":"\x00"};if(a==="u"){let h=t.slice(s+2,s+6);l+=String.fromCharCode(parseInt(h,16)||0),s+=6}else l+=c[a]??a,s+=2;continue}if(n===g){o=!0,s++;break}l+=n,s++}if(!o)e.push({code:"LIPS-E001",message:"Unterminated string literal",loc:{offset:p,length:s-p}});r.push({t:"str",value:l,start:p,end:s});continue}if(f(g)){let p=s;while(s<t.length&&m(t[s]))s++;r.push({t:"id",value:t.slice(p,s),start:p,end:s});continue}let d=G.find((p)=>t.startsWith(p,s));if(d==="?."&&/[0-9]/.test(t[s+2]??""))d="?";if(d){r.push({t:"punct",value:d,start:s,end:s+d.length}),s+=d.length;continue}e.push({code:"LIPS-E002",message:`Unexpected character '${g}'`,loc:{offset:s,length:1}}),s++}return r.push({t:"eof",value:"",start:t.length,end:t.length}),r}class C{tokens;diagnostics;pos=0;constructor(t,e){this.tokens=t;this.diagnostics=e}peek(t=0){return this.tokens[Math.min(this.pos+t,this.tokens.length-1)]}next(){return this.tokens[this.pos++]??this.tokens[this.tokens.length-1]}at(t){let e=this.peek();return e.t==="punct"&&e.value===t}eat(t){if(this.at(t))return this.pos++,!0;return!1}error(t,e,r=this.peek()){return this.diagnostics.push({code:t,message:e,loc:{offset:r.start,length:Math.max(1,r.end-r.start)}}),{t:"error"}}expect(t,e){if(!this.eat(t))this.error(e,`Expected '${t}'`)}parse(){let t=this.assign();if(this.peek().t!=="eof")this.error("LIPS-E003",`Unexpected token '${this.peek().value}' after expression`);return t}isArrowAhead(){let t=this.peek();if(t.t==="id"){let e=this.peek(1);return e.t==="punct"&&e.value==="=>"}if(t.t==="punct"&&t.value==="("){let e=0,r=0;while(!0){let s=this.peek(r);if(s.t==="eof")return!1;if(s.t==="punct"&&s.value==="(")e++;if(s.t==="punct"&&s.value===")"){if(e--,e===0){let f=this.peek(r+1);return f.t==="punct"&&f.value==="=>"}}r++}}return!1}assign(){if(this.isArrowAhead()){let r=[];if(this.peek().t==="id")r.push(this.next().value);else{this.expect("(","LIPS-E004");while(!this.at(")")&&this.peek().t!=="eof"){let s=this.next();if(s.t!=="id")return this.error("LIPS-E005","Invalid arrow parameter",s);if(r.push(s.value),!this.eat(","))break}this.expect(")","LIPS-E004")}return this.expect("=>","LIPS-E004"),{t:"arrow",params:r,body:this.assign()}}let t=this.conditional(),e=this.peek();if(e.t==="punct"&&["=","+=","-=","*=","/=","%="].includes(e.value)){if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid assignment target",e);return this.next(),{t:"assign",op:e.value,target:t,value:this.assign()}}return t}conditional(){let t=this.nullish();if(this.eat("?")){let e=this.assign();return this.expect(":","LIPS-E007"),{t:"cond",test:t,cons:e,alt:this.assign()}}return t}nullish(){let t=this.or();while(this.at("??"))this.next(),t={t:"logic",op:"??",l:t,r:this.or()};return t}or(){let t=this.and();while(this.at("||"))this.next(),t={t:"logic",op:"||",l:t,r:this.and()};return t}and(){let t=this.equality();while(this.at("&&"))this.next(),t={t:"logic",op:"&&",l:t,r:this.equality()};return t}equality(){let t=this.relational();while(["===","!==","==","!="].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.relational()};return t}relational(){let t=this.additive();while(["<=",">=","<",">"].some((e)=>this.at(e)))t={t:"bin",op:this.next().value,l:t,r:this.additive()};return t}additive(){let t=this.multiplicative();while(this.at("+")||this.at("-"))t={t:"bin",op:this.next().value,l:t,r:this.multiplicative()};return t}multiplicative(){let t=this.unary();while(this.at("*")||this.at("/")||this.at("%"))t={t:"bin",op:this.next().value,l:t,r:this.unary()};return t}unary(){if(this.at("!")||this.at("-")||this.at("+"))return{t:"unary",op:this.next().value,arg:this.unary()};if(this.at("++")||this.at("--")){let t=this.next().value,e=this.unary();if(e.t!=="id"&&e.t!=="member")return this.error("LIPS-E006","Invalid update target");return{t:"update",op:t,arg:e,prefix:!0}}return this.postfix()}postfix(){let t=this.callMember();if(this.at("++")||this.at("--")){let e=this.next().value;if(t.t!=="id"&&t.t!=="member")return this.error("LIPS-E006","Invalid update target");t={t:"update",op:e,arg:t,prefix:!1}}return t}callMember(){let t=this.primary();while(!0)if(this.eat(".")){let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!1,at:e.start}}else if(this.eat("?."))if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!0};else if(this.eat("[")){let e=this.peek().start,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,computed:!0,optional:!0,at:e}}else{let e=this.next();if(e.t!=="id")return this.error("LIPS-E008","Expected property name",e);t={t:"member",obj:t,prop:e.value,computed:!1,optional:!0,at:e.start}}else if(this.eat("[")){let e=this.peek().start,r=this.assign();this.expect("]","LIPS-E009"),t={t:"member",obj:t,prop:r,computed:!0,optional:!1,at:e}}else if(this.at("("))t={t:"call",callee:t,args:this.argList(),optional:!1};else break;return t}argList(){this.expect("(","LIPS-E010");let t=[];while(!this.at(")")&&this.peek().t!=="eof")if(t.push(this.assign()),!this.eat(","))break;return this.expect(")","LIPS-E010"),t}primary(){let t=this.peek();if(t.t==="num")return this.next(),{t:"lit",v:parseFloat(t.value)};if(t.t==="str")return this.next(),{t:"lit",v:t.value};if(t.t==="id")switch(this.next(),t.value){case"true":return{t:"lit",v:!0};case"false":return{t:"lit",v:!1};case"null":return{t:"lit",v:null};case"undefined":return{t:"lit",v:void 0};case"NaN":return{t:"lit",v:NaN};case"Infinity":return{t:"lit",v:1/0};default:return{t:"id",name:t.value,at:t.start}}if(this.eat("(")){let e=this.assign();return this.expect(")","LIPS-E010"),e}if(this.eat("[")){let e=[];while(!this.at("]")&&this.peek().t!=="eof"){let r=this.eat("...");if(e.push({spread:r||void 0,value:this.assign()}),!this.eat(","))break}return this.expect("]","LIPS-E009"),{t:"arr",items:e}}if(this.eat("{")){let e=[];while(!this.at("}")&&this.peek().t!=="eof"){if(this.eat("..."))e.push({spread:!0,value:this.assign()});else{let r=this.next();if(r.t!=="id"&&r.t!=="str"&&r.t!=="num")return this.error("LIPS-E011","Invalid object key",r);if(this.eat(":"))e.push({key:String(r.value),value:this.assign(),at:r.start});else if(r.t==="id")e.push({key:r.value,value:{t:"id",name:r.value,at:r.start},at:r.start});else return this.error("LIPS-E011","Invalid shorthand property",r)}if(!this.eat(","))break}return this.expect("}","LIPS-E011"),{t:"obj",props:e}}return this.next(),this.error("LIPS-E012",t.t==="eof"?"Unexpected end of expression":`Unexpected token '${t.value}'`,t)}}function S(t){let e=[],r=z(t,e);return{ast:new C(r,e).parse(),diagnostics:e}}function A(t){let e=[],r=0,s=0;for(let f=0;f<t.length;f++){let m=t[f];if(m==="'"||m==='"'||m==="`"){f++;while(f<t.length&&t[f]!==m){if(t[f]==="\\")f++;f++}continue}if(m==="("||m==="["||m==="{")r++;else if(m===")"||m==="]"||m==="}")r--;else if(m===","&&r===0)e.push(t.slice(s,f)),s=f+1}return e.push(t.slice(s)),e.map((f)=>f.trim()).filter(Boolean)}var j=new Set(["if","else-if","else","for","switch","async","let","const","log","context","i18n"]),O=new Set(["case","default","then","catch","loading"]),L=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","svg","circle","clippath","defs","ellipse","foreignobject","g","image","line","lineargradient","marker","mask","path","pattern","polygon","polyline","radialgradient","rect","stop","symbol","text","tspan","use"]);var _=new WeakMap,M={clone(t){let e=_.get(t);if(!e)e=document.createElement("template"),e.innerHTML=t.html,_.set(t,e);return e.content.cloneNode(!0)},fragment:()=>document.createDocumentFragment(),element:(t)=>document.createElement(t),text:(t)=>document.createTextNode(t),marker:(t)=>document.createComment(t),child:(t,e)=>t.childNodes[e],next:(t)=>t.nextSibling,range(t,e){let r=[];for(let s=t;s;s=s.nextSibling)if(r.push(s),s===e)break;return r},insert:(t,e,r)=>{t.insertBefore(e,r)},insertAfter(t,e){let r=t.parentNode;if(!r)return;let s=t;for(let f of e)r.insertBefore(f,s.nextSibling),s=f},remove:(t)=>t.remove(),isElement:(t)=>t.nodeType===1,connected:(t)=>t.isConnected,precedes:(t,e)=>!!(t.compareDocumentPosition(e)&4),attr:(t,e,r)=>r===null?t.removeAttribute(e):t.setAttribute(e,r),setText:(t,e)=>{t.data=e},content:(t,e)=>{t.textContent=e},html:(t,e)=>{t.innerHTML=e},styleVar:(t,e,r)=>r===null?t.style.removeProperty(e):t.style.setProperty(e,r),scope:(t,e)=>{t.hasAttribute("rel")||t.setAttribute("rel",e)},listen(t,e,r){return t.addEventListener(e,r),()=>t.removeEventListener(e,r)},keepFocus(){let t=document.activeElement;return()=>{t&&t.isConnected&&t!==document.activeElement&&t.focus()}}};var J=Symbol.for("lips.self"),H=(t,e,r)=>{let s=t.slice(0,e).split(`
|
|
3
|
+
`);return{line:s.length,col:s[s.length-1].length+1,offset:e,length:r}},k=(t,e,r)=>({code:t,message:e,hint:r}),w=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),U=new Set(["constructor","__proto__","prototype","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","caller","callee"]),K=new Set(["script","iframe","frame","frameset","object","embed","applet","portal","fencedframe","base","link","meta","style","title","head","body","html","template","noscript","noembed","noframes","xmp","plaintext","animate","animatemotion","animatetransform","set"]),X=new Set(["href","src","action","formaction","xlink:href","poster","cite","background","longdesc","manifest","data","codebase","lowsrc","dynsrc","icon"]),Z=new Set(["http","https","mailto","tel"]),B={srcdoc:"It is a whole document, written into an attribute",is:"It makes the element one the page defined, running the page's code",form:"It joins a form of the host page by id"},W=new WeakSet,I=(t)=>(W.add(t),Object.freeze(t)),E=(t,e)=>Object.fromEntries(e.map((r)=>[r,t[r]])),P=(t,e={})=>I(Object.assign((...r)=>t(...r),e)),Y={Math:I(E(Math,Object.getOwnPropertyNames(Math))),JSON:I(E(JSON,["parse","stringify"])),Object:I(E(Object,["keys","values","entries","fromEntries"])),Array:I(E(Array,["isArray","from","of"])),String:P(String,E(String,["fromCharCode","fromCodePoint"])),Number:P(Number,E(Number,["isFinite","isInteger","isNaN","isSafeInteger","parseFloat","parseInt","EPSILON","MAX_SAFE_INTEGER","MIN_SAFE_INTEGER"])),Boolean:P(Boolean),Date:P(Date,E(Date,["now","parse","UTC"])),parseInt,parseFloat,isNaN,isFinite,encodeURIComponent,decodeURIComponent,encodeURI,decodeURI};function Q(t){let e="",r=0;while(r<t.length){let s=t[r];if(s==='"'||s==="'"){let f=r+1;while(f<t.length&&t[f]!==s)f+=t[f]==="\\"?2:1;e+=t.slice(r,f+1),r=f+1;continue}if(s==="/"&&t[r+1]==="*"){let f=t.indexOf("*/",r+2);r=f<0?t.length:f+2;continue}e+=s,r++}return e.replace(/\\(?:([\da-f]{1,6})[ \t\n\r\f]?|([^\n\r\f\da-f])|[\n\r\f])/gi,(s,f,m)=>f?String.fromCodePoint(Math.min(parseInt(f,16),1114111)||65533):m??"")}var tt=(t)=>t===globalThis||t===globalThis.eval||typeof t==="function"&&/^(Async|AsyncGenerator|Generator)?Function$/.test(t.name)&&t.prototype?.constructor===t||typeof Node==="function"&&t instanceof Node||typeof Event==="function"&&t instanceof Event||typeof EventTarget==="function"&&t instanceof EventTarget||typeof t==="object"&&(("nodeType"in t)&&("ownerDocument"in t)||t.window===t),T={globals:Y,member(t,e,r){if(U.has(t))return k("LIPS-U002",`'${t}' leads to prototypes and constructors, not data`,"An untrusted template reads and writes data; prototype machinery is not reachable");if(r!=null&&W.has(r)&&(e||!w(r,t)))return k("LIPS-U003",e?`Globals are read-only — '${t}' cannot be written`:`'${t}' is not offered`,"Offered: Math, JSON, Object.keys/values/entries/fromEntries, Array.isArray/from/of, String, Number, Boolean, Date, parseInt, parseFloat, isNaN, isFinite and the URI codecs")},self(t,e){if(e)return k("LIPS-U005",`self is read-only — '${t}' cannot be written`,"Write state instead: state.x = …");if(U.has(t))return this.member(t,!1);if(t==="node")return k("LIPS-U005","self.node holds the component's DOM nodes","An untrusted template reaches the page only through the template language")},value(t){if(t!==null&&(typeof t==="object"||typeof t==="function")&&tt(t))return k("LIPS-U004","A DOM node, window, event or code constructor cannot be held by an untrusted template","Hand the template data, not the platform object it came from")},event(t){let e=(r)=>r&&{value:r.value,checked:r.checked,name:r.name,id:r.id,type:r.type,tagName:r.tagName,dataset:{...r.dataset}};return{type:t.type,key:t.key,code:t.code,data:t.data,inputType:t.inputType,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey,repeat:t.repeat,button:t.button,buttons:t.buttons,clientX:t.clientX,clientY:t.clientY,deltaX:t.deltaX,deltaY:t.deltaY,target:e(t.target),currentTarget:e(t.currentTarget),preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()}},tag(t){let e=t.toLowerCase();if(K.has(e))return k("LIPS-U010",`<${e}> is refused in an untrusted template`,"It runs script, holds a document of its own, or acts on the whole page");if(e.includes("-"))return k("LIPS-U011",`<${e}> is a custom element`,"Custom elements run the page's own code — a Lips component the host registered renders instead")},component(t){if(t==="router")return k("LIPS-U012","<router> owns the page URL and window.navigate","Switch on state for pages — <switch( state.page )>; routing stays with the host")},attr(t,e,r){let s=e.toLowerCase();if(s.startsWith("on"))return k("LIPS-U020",`'${e}' is an event-handler attribute`,"Use the instruction form: on-click( … )");if(w(B,s))return k("LIPS-U021",`'${e}' is refused`,B[s]);if(r===void 0)return;if((s==="id"||s==="name")&&typeof document==="object"&&r in document)return k("LIPS-U022",`${s}="${r}" would shadow document.${r}`,"Choose another value");if(s==="style")return this.css(r);if(X.has(s))return this.url(r);if(s==="srcset"||s==="imagesrcset"||s==="ping")for(let f of r.split(s==="ping"?/\s+/:",")){let m=f.trim()?this.url(f.trim().split(/\s+/)[0]):void 0;if(m)return m}},url(t){let e=String(t).replace(/[\t\n\r]/g,"").replace(/^[\u0000- ]+/,""),r=/^([a-z][a-z\d+.-]*):/i.exec(e)?.[1].toLowerCase();if(!r||Z.has(r)||/^data:image\/(png|gif|jpe?g|webp|avif|bmp)[;,]/i.test(e))return;return k("LIPS-U030",`'${r}:' URLs are refused`,"Use a relative, http(s), mailto: or tel: URL — or a raster data:image")},css(t){let e=Q(t);if(/@import\b/i.test(e))return k("LIPS-U040","@import loads a stylesheet outside the component scope","Write the rules into the stylesheet itself");if(/(?:^|[^\w-])(?:-webkit-|-moz-)?(?:image-set|image|cross-fade|element)\(/i.test(e))return k("LIPS-U041","image-set(), image(), cross-fade() and element() load without url()","Use url( … ), which is held to the URL rule");for(let r of e.matchAll(/\b(?:url|src)\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*))/gi)){let s=this.url((r[1]??r[2]??r[3]).trim());if(s)return s}},report(t){console.warn("[lips:untrusted]",t)}},et=new Set(["state","input","context","static","self","arguments"]),rt=new Set([...j,...O,"macro"]),R=new Set;function V(t,e,r,s,f=!1){let{ast:m,diagnostics:g}=S(e);if(g.length)return!0;let d=!0,p=(n,a=0,c=1)=>{if(n)d=!1,s(n,a,c)},l=(n,a)=>a.has(n)||r.has(n)||et.has(n)||w(t.globals,n);if(f&&m.t==="id"&&!l(m.name,R))return p(t.self(m.name),m.at,m.name.length),d;let o=(n,a,c=!1)=>{switch(n.t){case"id":l(n.name,a)||p(k("LIPS-U001",`'${n.name}' is not provided to an untrusted template`,"Expressions read state, input, context, static, self, their scope, and the globals the policy offers"),n.at,n.name.length);return;case"member":{o(n.obj,a),n.computed&&o(n.prop,a);let h=n.prop,i=!n.computed?n.prop:h.t==="lit"&&(typeof h.v==="string"||typeof h.v==="number")?String(h.v):void 0;if(i===void 0)return;let u=n.obj.t==="id"&&!a.has(n.obj.name)&&!r.has(n.obj.name)?n.obj.name:"";p(u==="self"?t.self(i,c):u&&w(t.globals,u)?t.member(i,c,t.globals[u]):t.member(i,c),n.at,i.length);return}case"call":o(n.callee,a),n.args.forEach((h)=>o(h,a));return;case"unary":o(n.arg,a);return;case"update":o(n.arg,a,!0);return;case"bin":case"logic":o(n.l,a),o(n.r,a);return;case"cond":o(n.test,a),o(n.cons,a),o(n.alt,a);return;case"assign":o(n.target,a,!0),o(n.value,a);return;case"arrow":o(n.body,new Set([...a,...n.params]));return;case"arr":n.items.forEach((h)=>o(h.value,a));return;case"obj":for(let h of n.props)h.key!==void 0&&p(t.member(h.key,!0),h.at,h.key.length),o(h.value,a)}};return o(m,R),d}function q(t=T){return(e,r,s)=>{let f=new Set,m=(i,u,b=1)=>r.push({...i,severity:"error",loc:H(s,u,b)}),g=(i,u)=>{let b=s.indexOf(i,u);return b<0?u:b},d=(i,u,b=!1)=>V(t,i,f,(x,y,v)=>m(x,u+y,v),b),p=(i,u,b=!0)=>{let x=!0,y=0;return A(i).forEach((v,N)=>{y=i.indexOf(v,y),x=d(v,u+y,b&&N===0)&&x,y+=v.length}),x},l=(i)=>{for(let u of i)if(typeof u!=="string"&&!d(u.expr,g(u.expr,u.loc.offset)))u.expr="undefined"},o=(i)=>L.has(i)?t.tag(i):t.component(i),n=(i)=>{for(let u of i){if(u.t==="fragment")n(u.children);if(u.t!=="element")continue;for(let b of u.attrs)b.k==="args"?b.names.forEach((x)=>f.add(x)):(u.tag==="let"||u.tag==="const")&&("name"in b)&&f.add(b.name);n(u.children)}},a=(i,u)=>{let b=i.loc.offset;switch(i.k){case"args":return!0;case"event":return p(i.source,g(i.source,b));case"spread":case"fn":return d(i.source,g(i.source,b))}if(u&&!/^(@(?!html$)|i18n(-|$))/.test(i.name)){let x=t.attr(u,i.name,i.k==="literal"?i.value:i.k==="bool"?"":void 0);if(x)return m(x,b,i.name.length),!1}if(i.name==="@format"){let x=i.k==="literal"?i.value:i.k==="expr"?i.source:i.k==="interp"?i.parts.map((v)=>typeof v==="string"?v:`{${v.expr}}`).join(""):"",y=x.slice(x.indexOf(",")+1).trim();return!x.includes(",")||d(y,g(y,b))}if(i.k==="expr"&&!d(i.source,g(i.source,b)))i.source="undefined";if(i.k==="interp")l(i.parts);return!0},c=(i)=>{let{tag:u}=i;if(u==="#dynamic"){let x=i.dynamicTag,y=g(x.expr,x.loc.offset);if(!d(x.expr,y))x.expr="undefined";else{let{ast:v}=S(x.expr),N=v.t==="lit"&&typeof v.v==="string"?o(v.v.toLowerCase()):void 0;if(N)return m(N,y,x.expr.length),!1}}else if(!rt.has(u)){let x=o(u);if(x)return m(x,i.loc.offset,u.length+1),!1}if(i.head){let x=i.head,y=g(x.expr,x.loc.offset);(u==="log"?p(x.expr,y,!1):d(x.expr,y))||(x.expr="undefined")}let b=L.has(u)?u:null;return i.attrs=i.attrs.filter((x)=>a(x,b)),!0},h=(i)=>{for(let u=0;u<i.length;u++){let b=i[u];if(b.t==="fragment")h(b.children);else if(b.t==="interp")l(b.parts);else if(b.t==="element")c(b)?h(b.children):i.splice(u--,1)}};n(e),h(e)}}var D=(t)=>Object.assign(Error(t.message),{name:"PolicyError"},t),F={"+":(t,e)=>t+e,"-":(t,e)=>t-e,"*":(t,e)=>t*e,"/":(t,e)=>t/e,"%":(t,e)=>t%e,"<":(t,e)=>t<e,">":(t,e)=>t>e,"<=":(t,e)=>t<=e,">=":(t,e)=>t>=e,"==":(t,e)=>t==e,"!=":(t,e)=>t!=e,"===":(t,e)=>t===e,"!==":(t,e)=>t!==e};function st(t){let e=(m)=>{if(m)throw D(m)},r=(m)=>(e(t.value(m)),m),s=(m)=>{if(typeof m==="string")return m;if(typeof m==="number")return String(m);throw D(k("LIPS-U002","A computed member must be a string or a number"))},f=(m,g,d)=>e(m!=null&&typeof m==="object"&&m[J]?t.self(g,d):t.member(g,d,m));return(m,g)=>{let d=g.scope,p=(n,a)=>{for(let c of a)if(n in c)return c[n];if(d&&n in d)return r(d[n]);switch(n){case"state":return g.state;case"input":return g.input;case"context":return g.context;case"static":return g.static;case"self":return g.self;case"arguments":return g.arguments}return w(t.globals,n)?t.globals[n]:void 0},l=(n,a,c)=>{if(n.t==="id"){let h=c.find((i)=>(n.name in i))??d;h&&(h[n.name]=a)}else if(n.t==="member"){let h=o(n.obj,c),i=s(n.computed?o(n.prop,c):n.prop);if(f(h,i,!0),h!=null)h[i]=a}return a},o=(n,a)=>{switch(n.t){case"lit":return n.v;case"id":return p(n.name,a);case"member":{let c=o(n.obj,a);if(n.optional&&c==null)return;let h=s(n.computed?o(n.prop,a):n.prop);return f(c,h,!1),c==null?void 0:r(c[h])}case"call":{let c=n.callee,h,i;if(c.t==="member"){if(h=o(c.obj,a),(c.optional||n.optional)&&h==null)return;let u=s(c.computed?o(c.prop,a):c.prop);f(h,u,!1),i=h==null?void 0:r(h[u])}else i=o(c,a);if(n.optional&&i==null)return;return r(Reflect.apply(i,h,n.args.map((u)=>o(u,a))))}case"unary":{let c=o(n.arg,a);return n.op==="!"?!c:n.op==="-"?-c:+c}case"update":{let c=o(n.arg,a),h=n.op==="++"?c+1:c-1;return l(n.arg,h,a),n.prefix?h:c}case"bin":return F[n.op](o(n.l,a),o(n.r,a));case"logic":{let c=o(n.l,a);return n.op==="&&"?c&&o(n.r,a):n.op==="||"?c||o(n.r,a):c??o(n.r,a)}case"cond":return o(n.test,a)?o(n.cons,a):o(n.alt,a);case"assign":return l(n.target,n.op==="="?o(n.value,a):F[n.op[0]](o(n.target,a),o(n.value,a)),a);case"arrow":return(...c)=>{let h=Object.create(null);return n.params.forEach((i,u)=>h[i]=r(c[u])),o(n.body,[h,...a])};case"arr":{let c=[];for(let h of n.items)h.spread?c.push(...o(h.value,a)):c.push(o(h.value,a));return c}case"obj":{let c={},h=(i,u)=>{f(c,i,!0),c[i]=u};for(let i of n.props){let u=o(i.value,a);if(!i.spread)h(i.key,u);else if(u!=null)for(let b of Object.keys(u))h(b,r(u[b]))}return c}}};return o(m,[])}}function nt(t,e=M){let r=new WeakMap,s=(p)=>(p&&t.report(p),!!p),f=(p)=>p.localName.toLowerCase(),m=(p,l)=>{let o=p.createElement("template");return o.setAttribute("data-lips-refused",l),o},g=(p)=>{for(let l of[...p.querySelectorAll("*")]){let o=f(l);if(s(t.tag(o))){let a=m(l.ownerDocument,o);a.append(...l.childNodes),l.replaceWith(a);continue}let n=!1;for(let{name:a,value:c}of[...l.attributes])if(s(t.attr(o,a,c)))l.removeAttribute(a),n||=a.toLowerCase()==="is";if(n){let a=l.ownerDocument.createElementNS(l.namespaceURI,l.localName);for(let c of[...l.attributes])a.setAttribute(c.name,c.value);a.append(...l.childNodes),l.replaceWith(a)}}},d=(p)=>{let l=document.createElement("template");return l.innerHTML=p,g(l.content),l};return{...e,clone(p){let l=r.get(p);if(!l)r.set(p,l=d(p.html));return l.content.cloneNode(!0)},element:(p)=>s(t.tag(p.toLowerCase()))?m(document,p):e.element(p),attr(p,l,o){e.attr(p,l,o!==null&&s(t.attr(f(p),l,o))?null:o)},html(p,l){s(t.attr(f(p),"@html",l))?e.content(p,""):p.replaceChildren(d(l).content)},styleVar(p,l,o){e.styleVar(p,l,o!==null&&s(t.css(o))?null:o)},listen:(p,l,o)=>e.listen(p,l,(n)=>o(t.event(n)))}}var it={ir:{v:1,exprs:[],root:{html:"",scope:[],binds:[],blocks:[]}}};function ot(t=T){let e=st(t),r=new Map,s=nt(t),f=new Set,m={run(g){let d=r.get(g);if(!d)r.set(g,d=S(g).ast);return(p)=>e(d,p)},self:(g)=>t.self(g)};return{check:q(t),style:(g)=>(d,p)=>{let l=g(d,{...p,lint(c,h){let i=h!==void 0?t.css(h):c[0]==="@"?t.css(c):void 0;return i&&[{...i,severity:"error"}]}}),o=(c,h,i)=>l.diagnostics.push({...c,severity:"error",loc:H(d,Math.max(h,0),i)}),n=!l.diagnostics.some((c)=>c.code.startsWith("LIPS-U"));for(let c of l.ir.exprs){let h=d.indexOf(c);n=V(t,c,R,(i,u,b)=>o(i,h+u,b))&&n}let a=n?t.css(l.ir.css):void 0;if(a&&o(a,0,0),!n||a)return{...l,ir:{...l.ir,css:"",binds:[],props:void 0}};return f.add(l.ir.css),l},runtime(g){let{components:d,createStylesheet:p}=g;return{...g,guard:m,host:s,components:d&&new Proxy(d,{get:(l,o)=>at(t,o)?it:l[o]}),createStylesheet:p&&((l,o)=>{if(f.has(o))return p(l,o);return t.report(k("LIPS-U042",`A stylesheet Lips did not compile cannot be checked — <${l}> ships unstyled`,"Send the stylesheet source; precompiled sheets are trusted output")),{clear(){}}})}}}}var at=(t,e)=>{let r=typeof e==="string"?t.component(e):void 0;return r&&t.report(r),!!r};export{q as checkTemplate,ot as untrusted,T as untrustedPolicy};
|
|
4
|
+
|
|
5
|
+
//# debugId=DD4429B74F5A6C4F64756E2164756E21
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/ir/expression.ts", "../src/ir/compiler.ts", "../src/ir/host.ts", "../src/ir/policy.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Phase 2 — Expression subsystem (RFC-001 §5)\n *\n * A dedicated parser for the template expression subset with:\n * - positioned, machine-readable diagnostics (never throws)\n * - AST-derived precise dependency paths\n * - two interchangeable executors over the same AST:\n * compiled — one Function per unique expression\n * interpreted — an AST walker that never builds a Function (CSP)\n * Both are for templates you trust. Neither is a boundary: a template\n * you did not write runs under a policy instead (RFC-007, ./policy).\n *\n * Grammar (expression-only, no statements):\n * literals (number, string, boolean, null, undefined), identifiers,\n * member access (incl. optional/computed), calls, unary ! - + and\n * prefix/postfix ++ --, binary arithmetic/relational/equality,\n * && || ??, ternary, arrow functions, assignment (= += -= *= /= %=),\n * array/object literals with spread.\n */\n\n// ---------------------------------------------------------------- diagnostics\nexport interface ExprDiagnostic {\n code: string\n message: string\n loc: { offset: number, length: number }\n}\n\n// ------------------------------------------------------------------------ AST\nexport type Expr =\n | { t: 'lit', v: any }\n /** `at`: where the name (or a member's key) starts in the source — for diagnostics */\n | { t: 'id', name: string, at?: number }\n | { t: 'member', obj: Expr, prop: string | Expr, computed: boolean, optional: boolean, at?: number }\n | { t: 'call', callee: Expr, args: Expr[], optional: boolean }\n | { t: 'unary', op: '!' | '-' | '+', arg: Expr }\n | { t: 'update', op: '++' | '--', arg: Expr, prefix: boolean }\n | { t: 'bin', op: string, l: Expr, r: Expr }\n | { t: 'logic', op: '&&' | '||' | '??', l: Expr, r: Expr }\n | { t: 'cond', test: Expr, cons: Expr, alt: Expr }\n | { t: 'assign', op: string, target: Expr, value: Expr }\n | { t: 'arrow', params: string[], body: Expr }\n | { t: 'arr', items: { spread?: boolean, value: Expr }[] }\n | { t: 'obj', props: { key?: string, value: Expr, spread?: boolean, at?: number }[] }\n | { t: 'error' }\n\n// ------------------------------------------------------------------ tokenizer\ntype Token = {\n t: 'num' | 'str' | 'id' | 'punct' | 'eof'\n value: string\n start: number\n end: number\n}\n\nconst PUNCTS = [\n '===', '!==', '...', '=>', '==', '!=', '<=', '>=', '&&', '||', '??', '?.',\n '++', '--', '+=', '-=', '*=', '/=', '%=',\n '+', '-', '*', '/', '%', '<', '>', '!', '?', ':', '.', ',', '(', ')',\n '[', ']', '{', '}', '='\n]\n\nfunction tokenize( src: string, diagnostics: ExprDiagnostic[] ): Token[] {\n const tokens: Token[] = []\n let i = 0\n\n const isIdStart = ( c: string ) => /[A-Za-z_$]/.test( c )\n const isIdChar = ( c: string ) => /[A-Za-z0-9_$]/.test( c )\n\n while( i < src.length ){\n const c = src[ i ]\n\n if( /\\s/.test( c ) ){ i++; continue }\n\n // Numbers: int, float, exponent\n if( /[0-9]/.test( c ) || ( c === '.' && /[0-9]/.test( src[ i + 1 ] ) ) ){\n const start = i\n while( i < src.length && /[0-9]/.test( src[ i ] ) ) i++\n if( src[ i ] === '.' ){ i++; while( i < src.length && /[0-9]/.test( src[ i ] ) ) i++ }\n if( src[ i ] === 'e' || src[ i ] === 'E' ){\n i++\n if( src[ i ] === '+' || src[ i ] === '-' ) i++\n while( i < src.length && /[0-9]/.test( src[ i ] ) ) i++\n }\n tokens.push({ t: 'num', value: src.slice( start, i ), start, end: i })\n continue\n }\n\n // Strings: '…' or \"…\" with escapes\n if( c === \"'\" || c === '\"' ){\n const start = i\n i++\n let value = ''\n let closed = false\n while( i < src.length ){\n const ch = src[ i ]\n if( ch === '\\\\' ){\n const next = src[ i + 1 ]\n const escapes: Record<string, string> = { n: '\\n', t: '\\t', r: '\\r', b: '\\b', f: '\\f', v: '\\v', '0': '\\0' }\n if( next === 'u' ){\n const hex = src.slice( i + 2, i + 6 )\n value += String.fromCharCode( parseInt( hex, 16 ) || 0 )\n i += 6\n }\n else {\n value += escapes[ next ] ?? next\n i += 2\n }\n continue\n }\n if( ch === c ){ closed = true; i++; break }\n value += ch\n i++\n }\n if( !closed )\n diagnostics.push({ code: 'LIPS-E001', message: 'Unterminated string literal', loc: { offset: start, length: i - start } })\n tokens.push({ t: 'str', value, start, end: i })\n continue\n }\n\n // Identifiers / keywords\n if( isIdStart( c ) ){\n const start = i\n while( i < src.length && isIdChar( src[ i ] ) ) i++\n tokens.push({ t: 'id', value: src.slice( start, i ), start, end: i })\n continue\n }\n\n // Punctuators — longest match first\n let punct = PUNCTS.find( p => src.startsWith( p, i ) )\n // `a ? .5 : b` — '?.' must not swallow a ternary before a decimal\n if( punct === '?.' && /[0-9]/.test( src[ i + 2 ] ?? '' ) )\n punct = '?'\n if( punct ){\n tokens.push({ t: 'punct', value: punct, start: i, end: i + punct.length })\n i += punct.length\n continue\n }\n\n diagnostics.push({ code: 'LIPS-E002', message: `Unexpected character '${c}'`, loc: { offset: i, length: 1 } })\n i++\n }\n\n tokens.push({ t: 'eof', value: '', start: src.length, end: src.length })\n return tokens\n}\n\n// --------------------------------------------------------------------- parser\nclass Parser {\n private pos = 0\n constructor( private tokens: Token[], private diagnostics: ExprDiagnostic[] ){}\n\n private peek( offset = 0 ){ return this.tokens[ Math.min( this.pos + offset, this.tokens.length - 1 ) ] }\n private next(){ return this.tokens[ this.pos++ ] ?? this.tokens[ this.tokens.length - 1 ] }\n private at( value: string ){ const t = this.peek(); return t.t === 'punct' && t.value === value }\n private eat( value: string ){ if( this.at( value ) ){ this.pos++; return true } return false }\n private error( code: string, message: string, token = this.peek() ): Expr {\n this.diagnostics.push({ code, message, loc: { offset: token.start, length: Math.max( 1, token.end - token.start ) } })\n return { t: 'error' }\n }\n private expect( value: string, code: string ){\n if( !this.eat( value ) )\n this.error( code, `Expected '${value}'` )\n }\n\n parse(): Expr {\n const expr = this.assign()\n if( this.peek().t !== 'eof' )\n this.error( 'LIPS-E003', `Unexpected token '${this.peek().value}' after expression` )\n return expr\n }\n\n /**\n * Arrow lookahead: '(' … ')' '=>' or IDENT '=>'\n */\n private isArrowAhead(): boolean {\n const t = this.peek()\n if( t.t === 'id' ){\n const n = this.peek( 1 )\n return n.t === 'punct' && n.value === '=>'\n }\n if( t.t === 'punct' && t.value === '(' ){\n let depth = 0, k = 0\n while( true ){\n const tok = this.peek( k )\n if( tok.t === 'eof' ) return false\n if( tok.t === 'punct' && tok.value === '(' ) depth++\n if( tok.t === 'punct' && tok.value === ')' ){\n depth--\n if( depth === 0 ){\n const after = this.peek( k + 1 )\n return after.t === 'punct' && after.value === '=>'\n }\n }\n k++\n }\n }\n return false\n }\n\n private assign(): Expr {\n // Arrow functions\n if( this.isArrowAhead() ){\n const params: string[] = []\n if( this.peek().t === 'id' )\n params.push( this.next().value )\n else {\n this.expect( '(', 'LIPS-E004' )\n while( !this.at( ')' ) && this.peek().t !== 'eof' ){\n const p = this.next()\n if( p.t !== 'id' ) return this.error( 'LIPS-E005', 'Invalid arrow parameter', p )\n params.push( p.value )\n if( !this.eat( ',' ) ) break\n }\n this.expect( ')', 'LIPS-E004' )\n }\n this.expect( '=>', 'LIPS-E004' )\n return { t: 'arrow', params, body: this.assign() }\n }\n\n const target = this.conditional()\n\n const op = this.peek()\n if( op.t === 'punct' && [ '=', '+=', '-=', '*=', '/=', '%=' ].includes( op.value ) ){\n if( target.t !== 'id' && target.t !== 'member' )\n return this.error( 'LIPS-E006', 'Invalid assignment target', op )\n this.next()\n return { t: 'assign', op: op.value, target, value: this.assign() }\n }\n\n return target\n }\n\n private conditional(): Expr {\n const test = this.nullish()\n if( this.eat( '?' ) ){\n const cons = this.assign()\n this.expect( ':', 'LIPS-E007' )\n return { t: 'cond', test, cons, alt: this.assign() }\n }\n return test\n }\n\n private nullish(): Expr {\n let l = this.or()\n while( this.at( '??' ) ){ this.next(); l = { t: 'logic', op: '??', l, r: this.or() } }\n return l\n }\n private or(): Expr {\n let l = this.and()\n while( this.at( '||' ) ){ this.next(); l = { t: 'logic', op: '||', l, r: this.and() } }\n return l\n }\n private and(): Expr {\n let l = this.equality()\n while( this.at( '&&' ) ){ this.next(); l = { t: 'logic', op: '&&', l, r: this.equality() } }\n return l\n }\n private equality(): Expr {\n let l = this.relational()\n while( [ '===', '!==', '==', '!=' ].some( op => this.at( op ) ) ){\n const op = this.next().value\n l = { t: 'bin', op, l, r: this.relational() }\n }\n return l\n }\n private relational(): Expr {\n let l = this.additive()\n while( [ '<=', '>=', '<', '>' ].some( op => this.at( op ) ) ){\n const op = this.next().value\n l = { t: 'bin', op, l, r: this.additive() }\n }\n return l\n }\n private additive(): Expr {\n let l = this.multiplicative()\n while( this.at( '+' ) || this.at( '-' ) ){\n const op = this.next().value\n l = { t: 'bin', op, l, r: this.multiplicative() }\n }\n return l\n }\n private multiplicative(): Expr {\n let l = this.unary()\n while( this.at( '*' ) || this.at( '/' ) || this.at( '%' ) ){\n const op = this.next().value\n l = { t: 'bin', op, l, r: this.unary() }\n }\n return l\n }\n private unary(): Expr {\n if( this.at( '!' ) || this.at( '-' ) || this.at( '+' ) ){\n const op = this.next().value as '!' | '-' | '+'\n return { t: 'unary', op, arg: this.unary() }\n }\n if( this.at( '++' ) || this.at( '--' ) ){\n const op = this.next().value as '++' | '--'\n const arg = this.unary()\n if( arg.t !== 'id' && arg.t !== 'member' )\n return this.error( 'LIPS-E006', 'Invalid update target' )\n return { t: 'update', op, arg, prefix: true }\n }\n return this.postfix()\n }\n private postfix(): Expr {\n let expr = this.callMember()\n if( this.at( '++' ) || this.at( '--' ) ){\n const op = this.next().value as '++' | '--'\n if( expr.t !== 'id' && expr.t !== 'member' )\n return this.error( 'LIPS-E006', 'Invalid update target' )\n expr = { t: 'update', op, arg: expr, prefix: false }\n }\n return expr\n }\n\n private callMember(): Expr {\n let expr = this.primary()\n\n while( true ){\n if( this.eat( '.' ) ){\n const prop = this.next()\n if( prop.t !== 'id' ) return this.error( 'LIPS-E008', 'Expected property name', prop )\n expr = { t: 'member', obj: expr, prop: prop.value, computed: false, optional: false, at: prop.start }\n }\n else if( this.eat( '?.' ) ){\n if( this.at( '(' ) ){\n expr = { t: 'call', callee: expr, args: this.argList(), optional: true }\n }\n else if( this.eat( '[' ) ){\n const at = this.peek().start\n const idx = this.assign()\n this.expect( ']', 'LIPS-E009' )\n expr = { t: 'member', obj: expr, prop: idx, computed: true, optional: true, at }\n }\n else {\n const prop = this.next()\n if( prop.t !== 'id' ) return this.error( 'LIPS-E008', 'Expected property name', prop )\n expr = { t: 'member', obj: expr, prop: prop.value, computed: false, optional: true, at: prop.start }\n }\n }\n else if( this.eat( '[' ) ){\n const at = this.peek().start\n const idx = this.assign()\n this.expect( ']', 'LIPS-E009' )\n expr = { t: 'member', obj: expr, prop: idx, computed: true, optional: false, at }\n }\n else if( this.at( '(' ) ){\n expr = { t: 'call', callee: expr, args: this.argList(), optional: false }\n }\n else break\n }\n\n return expr\n }\n private argList(): Expr[] {\n this.expect( '(', 'LIPS-E010' )\n const args: Expr[] = []\n while( !this.at( ')' ) && this.peek().t !== 'eof' ){\n args.push( this.assign() )\n if( !this.eat( ',' ) ) break\n }\n this.expect( ')', 'LIPS-E010' )\n return args\n }\n\n private primary(): Expr {\n const t = this.peek()\n\n if( t.t === 'num' ){ this.next(); return { t: 'lit', v: parseFloat( t.value ) } }\n if( t.t === 'str' ){ this.next(); return { t: 'lit', v: t.value } }\n\n if( t.t === 'id' ){\n this.next()\n switch( t.value ){\n case 'true': return { t: 'lit', v: true }\n case 'false': return { t: 'lit', v: false }\n case 'null': return { t: 'lit', v: null }\n case 'undefined': return { t: 'lit', v: undefined }\n case 'NaN': return { t: 'lit', v: NaN }\n case 'Infinity': return { t: 'lit', v: Infinity }\n default: return { t: 'id', name: t.value, at: t.start }\n }\n }\n\n if( this.eat( '(' ) ){\n const expr = this.assign()\n this.expect( ')', 'LIPS-E010' )\n return expr\n }\n\n if( this.eat( '[' ) ){\n const items: { spread?: boolean, value: Expr }[] = []\n while( !this.at( ']' ) && this.peek().t !== 'eof' ){\n const spread = this.eat( '...' )\n items.push({ spread: spread || undefined, value: this.assign() })\n if( !this.eat( ',' ) ) break\n }\n this.expect( ']', 'LIPS-E009' )\n return { t: 'arr', items }\n }\n\n if( this.eat( '{' ) ){\n const props: { key?: string, value: Expr, spread?: boolean, at?: number }[] = []\n while( !this.at( '}' ) && this.peek().t !== 'eof' ){\n if( this.eat( '...' ) ){\n props.push({ spread: true, value: this.assign() })\n }\n else {\n const key = this.next()\n if( key.t !== 'id' && key.t !== 'str' && key.t !== 'num' )\n return this.error( 'LIPS-E011', 'Invalid object key', key )\n\n if( this.eat( ':' ) )\n props.push({ key: String( key.value ), value: this.assign(), at: key.start })\n else if( key.t === 'id' ) // shorthand { a }\n props.push({ key: key.value, value: { t: 'id', name: key.value, at: key.start }, at: key.start })\n else\n return this.error( 'LIPS-E011', 'Invalid shorthand property', key )\n }\n if( !this.eat( ',' ) ) break\n }\n this.expect( '}', 'LIPS-E011' )\n return { t: 'obj', props }\n }\n\n this.next()\n return this.error( 'LIPS-E012', t.t === 'eof' ? 'Unexpected end of expression' : `Unexpected token '${t.value}'`, t )\n }\n}\n\nexport function parseExpression( src: string ): { ast: Expr, diagnostics: ExprDiagnostic[] } {\n const diagnostics: ExprDiagnostic[] = []\n const tokens = tokenize( src, diagnostics )\n const ast = new Parser( tokens, diagnostics ).parse()\n\n return { ast, diagnostics }\n}\n\n/**\n * Split an instruction (`on-click( fn, a, b )`, `<log( a, b )>`) on its\n * top-level commas — strings and brackets are opaque.\n */\nexport function splitTopLevel( src: string ): string[] {\n const out: string[] = []\n let depth = 0, start = 0\n\n for( let i = 0; i < src.length; i++ ){\n const c = src[ i ]\n if( c === \"'\" || c === '\"' || c === '`' ){\n i++\n while( i < src.length && src[ i ] !== c ){\n if( src[ i ] === '\\\\' ) i++\n i++\n }\n continue\n }\n if( c === '(' || c === '[' || c === '{' ) depth++\n else if( c === ')' || c === ']' || c === '}' ) depth--\n else if( c === ',' && depth === 0 ){\n out.push( src.slice( start, i ) )\n start = i + 1\n }\n }\n out.push( src.slice( start ) )\n return out.map( s => s.trim() ).filter( Boolean )\n}\n\n// ------------------------------------------------------------ dep extraction\nconst METAVAR_ROOTS = new Set([ 'state', 'input', 'context', 'self', 'arguments' ])\n\n/**\n * Every root identifier an expression reads that is not bound by an\n * arrow parameter — the head of each member chain, plus bare reads.\n *\n * The complement of `extractDeps`, which drops names it does not\n * recognise. Callers that need to REPORT an unresolvable name (a\n * stylesheet has no template position, so a `<for>` iterator in one\n * can never resolve — RFC-004 §7.2) need to see them instead.\n */\nexport function freeRoots( ast: Expr ): string[] {\n const roots = new Set<string>()\n\n const walk = ( node: Expr, shadow: Set<string> ) => {\n switch( node.t ){\n case 'id':\n !shadow.has( node.name ) && roots.add( node.name )\n return\n case 'member':\n walk( node.obj, shadow )\n typeof node.prop !== 'string' && walk( node.prop, shadow )\n return\n case 'call':\n walk( node.callee, shadow )\n node.args.forEach( a => walk( a, shadow ) )\n return\n case 'unary': case 'update': walk( node.arg, shadow ); return\n case 'bin': case 'logic': walk( node.l, shadow ); walk( node.r, shadow ); return\n case 'cond':\n walk( node.test, shadow ); walk( node.cons, shadow ); walk( node.alt, shadow )\n return\n case 'assign': walk( node.target, shadow ); walk( node.value, shadow ); return\n case 'arrow': walk( node.body, new Set([ ...shadow, ...node.params ]) ); return\n case 'arr': node.items.forEach( i => walk( i.value, shadow ) ); return\n case 'obj': node.props.forEach( p => walk( p.value, shadow ) ); return\n }\n }\n\n walk( ast, new Set() )\n return [ ...roots ]\n}\n\n/**\n * Precise dependency paths from the AST: dotted member paths\n * rooted at metavars (up to the first computed/call boundary),\n * plus bare scope-variable reads. Arrow params shadow.\n */\nexport function extractDeps( ast: Expr, scopeNames: string[] = [] ): string[] {\n const\n deps = new Set<string>(),\n scope = new Set( scopeNames )\n\n const walk = ( node: Expr, shadow: Set<string> ) => {\n switch( node.t ){\n case 'id': {\n if( shadow.has( node.name ) ) return\n if( scope.has( node.name ) || node.name === 'arguments' ) deps.add( node.name )\n return\n }\n case 'member': {\n // Collect the static dotted chain\n const parts: string[] = []\n let cur: Expr = node\n while( cur.t === 'member' && !cur.computed && typeof cur.prop === 'string' ){\n parts.unshift( cur.prop )\n cur = cur.obj\n }\n // Computed segments: record the object chain and the index deps\n if( cur.t === 'member' ){\n walk( cur.obj, shadow )\n typeof cur.prop !== 'string' && walk( cur.prop, shadow )\n // Re-anchor: deps of the computed base were recorded above\n if( cur.obj.t === 'id' || cur.obj.t === 'member' ) { /* recorded via recursion */ }\n }\n else if( cur.t === 'id' && !shadow.has( cur.name ) ){\n if( METAVAR_ROOTS.has( cur.name ) )\n deps.add( parts.length ? `${cur.name}.${parts.join('.')}` : cur.name )\n else if( scope.has( cur.name ) )\n deps.add( cur.name )\n }\n else if( cur.t !== 'id' ) walk( cur, shadow )\n return\n }\n case 'call':\n walk( node.callee, shadow )\n node.args.forEach( a => walk( a, shadow ) )\n return\n case 'unary': walk( node.arg, shadow ); return\n case 'update': walk( node.arg, shadow ); return\n case 'bin': case 'logic': walk( node.l, shadow ); walk( node.r, shadow ); return\n case 'cond': walk( node.test, shadow ); walk( node.cons, shadow ); walk( node.alt, shadow ); return\n case 'assign': walk( node.target, shadow ); walk( node.value, shadow ); return\n case 'arrow': {\n const inner = new Set([ ...shadow, ...node.params ])\n walk( node.body, inner )\n return\n }\n case 'arr': node.items.forEach( i => walk( i.value, shadow ) ); return\n case 'obj': node.props.forEach( p => walk( p.value, shadow ) ); return\n }\n }\n\n walk( ast, new Set() )\n return [ ...deps ]\n}\n\n// -------------------------------------------------------------------- codegen\n/**\n * AST → JS source (fully parenthesized — semantics over beauty).\n * Reserved-as-parameter roots are renamed at the identifier node\n * (`static` → `__static`, `arguments` → `__args__`) — renaming in\n * codegen, never via regex on emitted source, keeps string literals\n * containing those words intact.\n */\n/**\n * Name tables are prototype-free (`__proto__: null`): looked up by an\n * author's identifier, a `{}` answered `constructor` with `Object`\n * (RFC-007 §8). A literal, not a helper call, so a bundle that never\n * reads a table can still drop it.\n */\nconst ID_RENAMES: Record<string, string> = { __proto__: null, static: '__static', arguments: '__args__' } as any\n\nfunction gen( node: Expr ): string {\n switch( node.t ){\n case 'lit':\n if( typeof node.v === 'string' ) return JSON.stringify( node.v )\n if( node.v === undefined ) return 'undefined'\n if( Number.isNaN( node.v ) ) return 'NaN'\n return String( node.v )\n case 'id': return ID_RENAMES[ node.name ] ?? node.name\n case 'member': {\n const obj = gen( node.obj )\n if( node.computed ) return `(${obj})${node.optional ? '?.' : ''}[${gen( node.prop as Expr )}]`\n return `(${obj})${node.optional ? '?.' : '.'}${node.prop}`\n }\n case 'call': return `(${gen( node.callee )})${node.optional ? '?.' : ''}(${node.args.map( gen ).join(',')})`\n case 'unary': return `(${node.op}(${gen( node.arg )}))`\n case 'update': return node.prefix ? `(${node.op}${genTarget( node.arg )})` : `(${genTarget( node.arg )}${node.op})`\n case 'bin': return `((${gen( node.l )})${node.op}(${gen( node.r )}))`\n case 'logic': return `((${gen( node.l )})${node.op}(${gen( node.r )}))`\n case 'cond': return `((${gen( node.test )})?(${gen( node.cons )}):(${gen( node.alt )}))`\n case 'assign': return `(${genTarget( node.target )}${node.op}(${gen( node.value )}))`\n case 'arrow': return `((${node.params.join(',')})=>(${gen( node.body )}))`\n case 'arr': return `[${node.items.map( i => ( i.spread ? '...' : '' ) + gen( i.value ) ).join(',')}]`\n case 'obj': return `({${node.props.map( p =>\n p.spread ? `...${gen( p.value )}` : `${JSON.stringify( p.key )}:${gen( p.value )}` ).join(',')}})`\n case 'error': return 'undefined'\n }\n}\n/** Assignment/update targets must not be over-parenthesized */\nfunction genTarget( node: Expr ): string {\n if( node.t === 'id' ) return ID_RENAMES[ node.name ] ?? node.name\n if( node.t === 'member' ){\n const obj = gen( node.obj )\n return node.computed ? `${obj}[${gen( node.prop as Expr )}]` : `${obj}.${node.prop}`\n }\n return gen( node )\n}\n\n// ------------------------------------------------------------------ executors\nexport interface ExprEnv {\n state?: any\n input?: any\n context?: any\n static?: any\n self?: any\n arguments?: any\n scope?: Record<string, any>\n /**\n * Effective language for this subtree, read reactively (RFC-005 §4).\n * Set by `<i18n lang=…>`; absent means \"the global language\". Not an\n * expression root — the evaluator only binds the named roots, so this\n * rides along for the runtime's own use.\n */\n lang?: () => string\n}\n\nexport interface CompiledExpr {\n run( env: ExprEnv ): any\n source: string\n}\n\nconst\nCOMPILE_CACHE = new Map<string, CompiledExpr>(),\nROOT_PARAMS = [ 'state', 'input', 'context', '__static', 'self' ]\n\n/**\n * Compiled mode: one Function per unique (source, scopeNames) —\n * strict-compatible, no `with`. Trusted contexts only.\n */\nexport function compileExpression( src: string, scopeNames: string[] = [] ): CompiledExpr {\n const key = `${scopeNames.join(',')}\\0${src}`\n const cached = COMPILE_CACHE.get( key )\n if( cached ) return cached\n\n const { ast, diagnostics } = parseExpression( src )\n if( diagnostics.length )\n console.warn( `[lips-ir] expression diagnostics for \"${src}\":`, diagnostics )\n\n const\n code = `return (${gen( ast )});`,\n params = [ ...ROOT_PARAMS, '__args__', ...scopeNames ],\n fn = new Function( ...params, code )\n\n const compiled: CompiledExpr = {\n source: src,\n run( env: ExprEnv ){\n const scope = env.scope || {}\n return fn(\n env.state, env.input, env.context, env.static, env.self, env.arguments,\n ...scopeNames.map( name => scope[ name ] )\n )\n }\n }\n\n COMPILE_CACHE.set( key, compiled )\n return compiled\n}\n\n/**\n * Interpreted mode: an AST walker. CSP-safe — it never builds a Function\n * and never calls eval — and names resolve only to the scope, the\n * metavars and the globals below.\n *\n * It is NOT a sandbox. Members, calls and writes are unrestricted, and\n * these globals are the page's own objects. For a template you did not\n * write, use `new Lips({ untrusted })` (RFC-007).\n */\nconst GLOBALS: Record<string, any> = {\n __proto__: null,\n Math, JSON, Object, Array, String, Number, Boolean, Date,\n parseInt, parseFloat, isNaN, isFinite,\n encodeURIComponent, decodeURIComponent, console\n} as any\n\nexport function interpretExpression( ast: Expr, env: ExprEnv ): any {\n const scope = env.scope || Object.create( null )\n\n const resolveId = ( name: string, locals: Record<string, any>[] ): any => {\n for( const frame of locals )\n if( name in frame ) return frame[ name ]\n\n if( name in scope ) return scope[ name ]\n\n switch( name ){\n case 'state': return env.state\n case 'input': return env.input\n case 'context': return env.context\n case 'static': return env.static\n case 'self': return env.self\n case 'arguments': return env.arguments\n }\n\n if( name in GLOBALS ) return GLOBALS[ name ]\n return undefined\n }\n\n const assignId = ( name: string, value: any, locals: Record<string, any>[] ) => {\n for( const frame of locals )\n if( name in frame ){ frame[ name ] = value; return value }\n scope[ name ] = value\n return value\n }\n\n const ev = ( node: Expr, locals: Record<string, any>[] ): any => {\n switch( node.t ){\n case 'lit': return node.v\n case 'id': return resolveId( node.name, locals )\n\n case 'member': {\n const obj = ev( node.obj, locals )\n if( node.optional && obj == null ) return undefined\n const prop = node.computed ? ev( node.prop as Expr, locals ) : node.prop as string\n return obj?.[ prop ]\n }\n\n case 'call': {\n // Member calls bind `this` to the object\n if( node.callee.t === 'member' ){\n const obj = ev( node.callee.obj, locals )\n if( ( node.callee.optional || node.optional ) && obj == null ) return undefined\n const prop = node.callee.computed ? ev( node.callee.prop as Expr, locals ) : node.callee.prop as string\n const fn = obj?.[ prop ]\n if( node.optional && fn == null ) return undefined\n return fn.apply( obj, node.args.map( a => ev( a, locals ) ) )\n }\n const fn = ev( node.callee, locals )\n if( node.optional && fn == null ) return undefined\n return fn( ...node.args.map( a => ev( a, locals ) ) )\n }\n\n case 'unary': {\n const v = ev( node.arg, locals )\n switch( node.op ){\n case '!': return !v\n case '-': return -v\n case '+': return +v\n }\n }\n\n case 'update': {\n const cur = ev( node.arg, locals )\n const nextVal = node.op === '++' ? cur + 1 : cur - 1\n setTarget( node.arg, nextVal, locals )\n return node.prefix ? nextVal : cur\n }\n\n case 'bin': {\n const l = ev( node.l, locals ), r = ev( node.r, locals )\n switch( node.op ){\n case '+': return l + r\n case '-': return l - r\n case '*': return l * r\n case '/': return l / r\n case '%': return l % r\n case '<': return l < r\n case '>': return l > r\n case '<=': return l <= r\n case '>=': return l >= r\n // eslint-disable-next-line eqeqeq\n case '==': return l == r\n // eslint-disable-next-line eqeqeq\n case '!=': return l != r\n case '===': return l === r\n case '!==': return l !== r\n }\n return undefined\n }\n\n case 'logic': {\n const l = ev( node.l, locals )\n switch( node.op ){\n case '&&': return l ? ev( node.r, locals ) : l\n case '||': return l ? l : ev( node.r, locals )\n case '??': return l != null ? l : ev( node.r, locals )\n }\n }\n\n case 'cond': return ev( node.test, locals ) ? ev( node.cons, locals ) : ev( node.alt, locals )\n\n case 'assign': {\n let value = ev( node.value, locals )\n if( node.op !== '=' ){\n const cur = ev( node.target, locals )\n switch( node.op ){\n case '+=': value = cur + value; break\n case '-=': value = cur - value; break\n case '*=': value = cur * value; break\n case '/=': value = cur / value; break\n case '%=': value = cur % value; break\n }\n }\n return setTarget( node.target, value, locals )\n }\n\n case 'arrow':\n return ( ...args: any[] ) => {\n const frame: Record<string, any> = Object.create( null )\n node.params.forEach( ( p, k ) => frame[ p ] = args[ k ] )\n return ev( node.body, [ frame, ...locals ] )\n }\n\n case 'arr': {\n const out: any[] = []\n for( const item of node.items ){\n const v = ev( item.value, locals )\n item.spread ? out.push( ...v ) : out.push( v )\n }\n return out\n }\n\n case 'obj': {\n const out: Record<string, any> = {}\n for( const p of node.props ){\n if( p.spread ) Object.assign( out, ev( p.value, locals ) )\n else out[ p.key as string ] = ev( p.value, locals )\n }\n return out\n }\n\n case 'error': return undefined\n }\n }\n\n const setTarget = ( target: Expr, value: any, locals: Record<string, any>[] ) => {\n if( target.t === 'id' ) return assignId( target.name, value, locals )\n if( target.t === 'member' ){\n const obj = ev( target.obj, locals )\n const prop = target.computed ? ev( target.prop as Expr, locals ) : target.prop as string\n if( obj != null ) obj[ prop ] = value\n return value\n }\n return value\n }\n\n return ev( ast, [] )\n}\n",
|
|
6
|
+
"/**\n * Phase 2 — IR compiler (RFC-001 §4)\n *\n * TemplateAST → TemplateIR:\n * - static HTML skeletons per block, ready for one-time <template>\n * parsing + per-instance cloneNode\n * - integer-path bind table (childNodes index walks — no string paths)\n * - control-flow block nodes anchored by comment placeholders whose\n * paths are precomputed (the compiler simulates browser text-node\n * coalescing so paths survive the HTML round-trip)\n * - deduped expression table; every authored expression is validated\n * at compile time and its diagnostics re-anchored to template\n * line/col\n *\n * The output is JSON-serializable and deterministic — it is the\n * Modela artifact, the runtime render program, and the hot-swap\n * diff unit.\n *\n * With `target: 'tree'` every block also carries `nodes`, the same\n * skeleton as a structural tree, for hosts that build nodes one by\n * one rather than parse markup (RFC-006 §4.1).\n */\n\nimport type {\n TemplateNode,\n ElementNode,\n AttrNode,\n ExprSlot,\n TemplateDiagnostic\n} from './parser'\nimport { parseTemplate } from './parser'\nimport { parseExpression } from './expression'\n\n// ------------------------------------------------------------------- types\nexport type Path = number[]\nexport type E = number\n\nexport type CompInput =\n | { e: E }\n | { lit: unknown }\n\nexport interface TemplateIR {\n v: 1\n exprs: string[]\n root: BlockIR\n}\n\n/**\n * One node of a block's structural skeleton (RFC-006 §4.1): the tree\n * `html` encodes, for hosts with no HTML parser. Bind and block paths\n * index it exactly as they index the parsed `html`.\n *\n * 'text' a static text run\n * 0 an anchor — where a text bind or a block attaches\n * [ tag, attrs?, children? ] an element and its static attributes\n */\nexport type NodeIR = string | 0 | [ tag: string, attrs?: Record<string, string>, children?: NodeIR[] ]\n\nexport interface BlockIR {\n html: string\n /** The skeleton as a tree — present when compiled with `target: 'tree'` */\n nodes?: NodeIR[]\n /**\n * Scope variable names visible to this block's binds\n * (iterator args, async arm args, let/const names —\n * let names are block-scoped from block start, see RFC)\n */\n scope: string[]\n binds: BindIR[]\n blocks: ChildIR[]\n}\n\n/**\n * `i18n` marks a bind as translatable; `ik` carries the STABLE key to\n * look it up by (RFC-005 §3). Without `ik` the rendered text is its own\n * key — reword the source and the translation is orphaned.\n */\nexport type BindIR =\n | { t: 'text', p: Path, e: E, i18n?: 1, ik?: string } // anchor; runtime inserts a text node after it\n | { t: 'attr', p: Path, name: string, e: E, i18n?: 1, ik?: string }\n | { t: 'prop', p: Path, name: string, e: E, i18n?: 1, ik?: string, ref?: string } // @html / @text / @format\n | { t: 'event', p: Path, name: string, e: E } // raw instruction — runtime resolves handler form\n | { t: 'spread', p: Path, e: E }\n\nexport interface ArmIR {\n args: string[]\n block: BlockIR\n}\n\n/**\n * One macro call-site assignment, in SOURCE ORDER so later\n * entries override earlier ones (`<option key=k ...each/>` —\n * the spread wins over `key` for keys it contains).\n */\nexport type MacroSet =\n | { name: string, ci: CompInput }\n | { spread: E }\n\nexport type ChildIR =\n | { t: 'macro', p: Path, name: string, sets: MacroSet[], args: string[], block: BlockIR }\n | { t: 'if', p: Path, branches: { when: E | null, block: BlockIR }[] }\n | { t: 'for', p: Path, of?: E, from?: CompInput, to?: CompInput, by?: CompInput, args: string[], block: BlockIR }\n | { t: 'switch', p: Path, on: E, cases: { is: CompInput | null, block: BlockIR }[] }\n | { t: 'async', p: Path, awaitE: E, then?: ArmIR, catch?: ArmIR, loading?: BlockIR }\n | { t: 'let', p: Path, const: boolean, vars: Record<string, CompInput> }\n | { t: 'log', p: Path, e: E }\n /**\n * `<context …>` / `<i18n lang=…>` — a context layer over the subtree\n * (RFC-005 §4). `vars` are the provided keys; `lang` is the scoped\n * language. One IR kind, two spellings: they differ only in which\n * field they fill.\n */\n | { t: 'provide', p: Path, vars: Record<string, CompInput>, lang?: CompInput, block: BlockIR }\n | { t: 'comp', p: Path, name: string, inputs: Record<string, CompInput>, spreads: E[], events: { name: string, e: E }[], contents?: ArmIR }\n | { t: 'dynamic', p: Path, tag: E, inputs: Record<string, CompInput>, spreads: E[], events: { name: string, e: E }[], contents?: ArmIR }\n\nexport interface CompileResult {\n ir: TemplateIR\n diagnostics: TemplateDiagnostic[]\n}\n\nexport interface CompileOptions {\n /** `<macro [argv] name=\"X\">…</macro>` definitions, inlined at call sites */\n macros?: string\n /**\n * The kind of host the IR is for. `'dom'` (default) needs only the\n * `html` skeletons. `'tree'` is for hosts with no HTML parser\n * (RFC-006 §4.1): blocks also carry `nodes`, comments are dropped\n * (they mean nothing off the DOM), and `@html` is an error.\n */\n target?: 'dom' | 'tree'\n /**\n * Rewrites the parsed template before it compiles, reporting into\n * `diagnostics` — how a host adapts the HTML-shaped vocabulary\n * (`compileLynxTemplate`, RFC-006 §4.3). Macro bodies are not passed.\n */\n transform?: ( nodes: TemplateNode[], diagnostics: TemplateDiagnostic[] ) => void\n /**\n * Inspects — and may rewrite — the parsed template AND the macros\n * source before either compiles, reporting into `diagnostics` located\n * against `src`, the source the nodes came from. How an untrusted\n * template is held to its policy (RFC-007 §5.1): a refusal is reported\n * where it is written, and the refused construct never compiles.\n */\n check?: ( nodes: TemplateNode[], diagnostics: TemplateDiagnostic[], src: string ) => void\n}\n\ninterface MacroDef {\n name: string\n argv: string[]\n children: TemplateNode[]\n}\n\n// ------------------------------------------------------------------ tables\nconst ANCHOR = '<!--$-->'\n\nexport const CONTROL_TAGS = new Set([\n 'if', 'else-if', 'else', 'for', 'switch', 'async', 'let', 'const', 'log',\n // RFC-005 §4 — scoped context / scoped language\n 'context', 'i18n'\n])\nexport const ARM_TAGS = new Set([ 'case', 'default', 'then', 'catch', 'loading' ])\n\n/** Standard HTML + common SVG tags — anything else is a component candidate */\nexport const HTML_TAGS = new Set([\n 'a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo',\n 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col',\n 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl',\n 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2',\n 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img',\n 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'menu',\n 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p',\n 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section',\n 'select', 'slot', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup',\n 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title',\n 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr',\n // SVG\n 'svg', 'circle', 'clippath', 'defs', 'ellipse', 'foreignobject', 'g', 'image', 'line',\n 'lineargradient', 'marker', 'mask', 'path', 'pattern', 'polygon', 'polyline',\n 'radialgradient', 'rect', 'stop', 'symbol', 'text', 'tspan', 'use'\n])\n\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\n])\n\n// ----------------------------------------------------------------- helpers\nconst escText = ( s: string ) => s.replace( /&/g, '&' ).replace( /</g, '<' ).replace( />/g, '>' )\nconst escAttr = ( s: string ) => s.replace( /&/g, '&' ).replace( /\"/g, '"' ).replace( /</g, '<' )\n\nconst isNumeric = ( s: string ) => s !== '' && !isNaN( Number( s ) )\n\n/**\n * Does this source denote an OBJECT LITERAL rather than a value?\n *\n * Two spellings arrive here and both are the same React habit:\n *\n * style=\"{ margin: '3rem' }\" — braces eaten as an interpolation slot,\n * so the source is bare `margin: '3rem'`\n * style={{ margin: '3rem' }} — a real object expression\n *\n * The discriminator is a top-level `:` reached before any top-level `?`,\n * which is what keeps the forms that DO work out of it: a ternary\n * (`{state.on ? 'color:red' : ''}`), `??` and `?.` all hit the `?` first,\n * and a `:` inside a string (`{!state.on && 'color: red'}`) is skipped.\n */\nconst isObjectLiteral = ( src: string ): boolean => {\n const s = src.trim()\n let depth = 0\n\n for( let i = 0; i < s.length; i++ ){\n const c = s[ i ]\n\n if( c === \"'\" || c === '\"' || c === '`' ){\n i++\n while( i < s.length && s[ i ] !== c ){\n if( s[ i ] === '\\\\' ) i++\n i++\n }\n continue\n }\n\n if( c === '(' || c === '[' || c === '{' ) depth++\n else if( c === ')' || c === ']' || c === '}' ){\n depth--\n // A leading `{` that closes on the last char wraps the whole value\n if( depth === 0 && s[ 0 ] === '{' && i === s.length - 1 )\n return isObjectLiteral( s.slice( 1, -1 ) )\n }\n else if( depth === 0 ){\n if( c === '?' ) return false\n if( c === ':' ) return true\n }\n }\n return false\n}\n\n/**\n * The attribute's value as ONE expression source, or '' when it is not a\n * single bare expression. `width: {state.w}px` has literal text around\n * its slot, so it is CSS with a value interpolated in — not a candidate.\n */\nconst objectishAttr = ( attr: AttrNode ) => {\n if( attr.k === 'expr' ) return attr.source\n if( attr.k !== 'interp' ) return ''\n\n const slots = attr.parts.filter( ( p ): p is ExprSlot => typeof p !== 'string' )\n\n return slots.length === 1\n && attr.parts.every( p => typeof p !== 'string' || !p.trim() )\n ? slots[ 0 ].expr\n : ''\n}\n\n// ---------------------------------------------------------------- compiler\nclass Compiler {\n private exprs: string[] = []\n private exprIndex = new Map<string, E>()\n private lineStarts: number[] | null = null\n /** Guards against macros that (indirectly) call themselves */\n private macroStack: string[] = []\n\n readonly diagnostics: TemplateDiagnostic[] = []\n\n constructor(\n private src: string,\n private macros = new Map<string, MacroDef>(),\n /** `target: 'tree'` — emit `BlockIR.nodes` alongside `html` */\n private tree = false\n ){}\n\n // ---- diagnostics\n private locate( offset: number ){\n if( !this.lineStarts ){\n this.lineStarts = [ 0 ]\n for( let i = 0; i < this.src.length; i++ )\n if( this.src[ i ] === '\\n' ) this.lineStarts.push( i + 1 )\n }\n\n let lo = 0, hi = this.lineStarts.length - 1\n while( lo < hi ){\n const mid = ( lo + hi + 1 ) >> 1\n this.lineStarts[ mid ] <= offset ? lo = mid : hi = mid - 1\n }\n\n return { line: lo + 1, col: offset - this.lineStarts[ lo ] + 1 }\n }\n private report( code: string, severity: 'error' | 'warning', message: string, offset: number, length = 1, hint?: string ){\n const { line, col } = this.locate( offset )\n this.diagnostics.push({ code, severity, message, hint, loc: { line, col, offset, length } })\n }\n\n // ---- expression table\n /** Register an authored expression: validate + dedupe */\n private expr( source: string, at?: { offset: number, length?: number } ): E {\n const cached = this.exprIndex.get( source )\n if( cached !== undefined ) return cached\n\n const { diagnostics } = parseExpression( source )\n for( const d of diagnostics ){\n const offset = ( at?.offset ?? 0 ) + d.loc.offset\n this.report( d.code, 'error', d.message, offset, d.loc.length )\n }\n\n const idx = this.exprs.length\n this.exprs.push( source )\n this.exprIndex.set( source, idx )\n return idx\n }\n /** Register a synthesized expression (parts already validated) */\n private synth( source: string ): E {\n const cached = this.exprIndex.get( source )\n if( cached !== undefined ) return cached\n\n const idx = this.exprs.length\n this.exprs.push( source )\n this.exprIndex.set( source, idx )\n return idx\n }\n /**\n * Interpolation parts → one concat expression.\n * Nullish parts render '' (RFC decision #4).\n */\n private concat( parts: ( string | ExprSlot )[] ): E {\n parts\n .filter( ( p ): p is ExprSlot => typeof p !== 'string' )\n .forEach( p => {\n const { diagnostics } = parseExpression( p.expr )\n for( const d of diagnostics )\n this.report( d.code, 'error', d.message, p.loc.offset + d.loc.offset, d.loc.length )\n })\n\n const source = parts\n .map( p => typeof p === 'string' ? JSON.stringify( p ) : `((${p.expr})??\"\")` )\n .join('+')\n\n return this.synth( source )\n }\n private compInput( attr: AttrNode & { k: 'literal' | 'expr' | 'interp' | 'bool' } ): CompInput {\n switch( attr.k ){\n case 'literal': return { lit: attr.value }\n case 'bool': return { lit: attr.value }\n case 'expr': return { e: this.expr( attr.source, attr.loc ) }\n case 'interp': return { e: this.concat( attr.parts ) }\n }\n }\n\n // ---- entry\n compile( children: TemplateNode[] ): TemplateIR {\n return { v: 1, exprs: this.exprs, root: this.block( children, [] ) }\n }\n\n /**\n * Compile a node list into a BlockIR: static HTML with\n * precomputed paths for every bind/anchor. `scope` may\n * grow when <let>/<const> introduce names.\n */\n private block( children: TemplateNode[], scope: string[] ): BlockIR {\n const\n block: BlockIR = { html: '', scope: [ ...scope ], binds: [], blocks: [] },\n html: string[] = [],\n tree = this.tree,\n roots: NodeIR[] = []\n\n /**\n * Emit a sibling list at `path` depth. Returns nothing —\n * appends to html / block.binds / block.blocks, and to `kids`\n * (this level of the node tree) for the tree target.\n * The index simulation must match browser parsing:\n * consecutive static text coalesces into ONE node — and the node\n * tree coalesces the same way, so one path fits both.\n */\n const emitSiblings = ( nodes: TemplateNode[], path: Path, kids: NodeIR[], i18nParent = false, i18nKey?: string ) => {\n let index = 0\n let lastWasText = false\n\n const anchor = (): Path => {\n html.push( ANCHOR )\n tree && kids.push( 0 )\n lastWasText = false\n return [ ...path, index++ ]\n }\n\n for( let i = 0; i < nodes.length; i++ ){\n const node = nodes[ i ]\n\n switch( node.t ){\n case 'text': {\n /**\n * Static text under an `i18n` element still needs a\n * bind — there is nothing to translate in a skeleton.\n */\n if( i18nParent ){\n const bind: BindIR = { t: 'text', p: anchor(), e: this.synth( JSON.stringify( node.value ) ), i18n: 1 }\n if( i18nKey ) bind.ik = i18nKey\n block.binds.push( bind )\n break\n }\n\n html.push( escText( node.value ) )\n tree && ( lastWasText ? kids[ kids.length - 1 ] += node.value : kids.push( node.value ) )\n if( !lastWasText ) index++\n lastWasText = true\n break\n }\n case 'comment': {\n /**\n * Dropped from BOTH forms for the tree target, so the text\n * on either side coalesces alike and paths still agree.\n */\n if( tree ) break\n\n /**\n * Round-trip it as ONE comment. `--` would close it early, and\n * a leading `>` or `->` makes `<!-->` / `<!--->` — an empty\n * comment for the browser, followed by the rest as markup.\n */\n const text = node.value.replace( /--/g, '- -' )\n html.push( `<!--${ /^-?>/.test( text ) ? ' ' + text : text }-->` )\n lastWasText = false\n index++\n break\n }\n case 'interp': {\n const bind: BindIR = { t: 'text', p: anchor(), e: this.concat( node.parts ) }\n if( i18nParent ) bind.i18n = 1\n if( i18nParent && i18nKey ) bind.ik = i18nKey\n block.binds.push( bind )\n break\n }\n case 'fragment': {\n /**\n * Nested fragments are transparent: children emit\n * into the current index space. Rebuild sibling\n * numbering by splicing children inline.\n */\n nodes = [ ...nodes.slice( 0, i ), ...node.children, ...nodes.slice( i + 1 ) ]\n i--\n break\n }\n case 'element': {\n // Control flow → anchored child block\n if( CONTROL_TAGS.has( node.tag ) ){\n this.controlBlock( node, nodes, i, anchor(), block, scope )\n\n // if-chains consume their else-if/else siblings\n if( node.tag === 'if' ){\n let j = i + 1\n while( j < nodes.length ){\n const sib = nodes[ j ]\n if( sib.t === 'element' && ( sib.tag === 'else-if' || sib.tag === 'else' ) ) j++\n else break\n }\n nodes = [ ...nodes.slice( 0, i + 1 ), ...nodes.slice( j ) ]\n }\n break\n }\n\n // Arm tags outside their parents\n if( ARM_TAGS.has( node.tag ) ){\n this.report( 'LIPS-C002', 'error',\n `<${node.tag}> is only valid inside its parent construct`, node.loc.offset, node.loc.length )\n break\n }\n\n // Dynamic tag\n if( node.tag === '#dynamic' ){\n block.blocks.push( this.compLike( node, anchor(), scope, 'dynamic' ) )\n break\n }\n\n // Macro call → inline the definition body\n if( this.macros.has( node.tag ) ){\n const macroBlock = this.macroCall( node, anchor(), scope )\n macroBlock && block.blocks.push( macroBlock )\n break\n }\n\n // Component candidate\n if( !HTML_TAGS.has( node.tag ) ){\n block.blocks.push( this.compLike( node, anchor(), scope, 'comp' ) )\n break\n }\n\n // Plain HTML element\n this.emitElement( node, path, index++, html, block, emitSiblings, kids )\n lastWasText = false\n break\n }\n }\n }\n }\n\n emitSiblings( children, [], roots )\n block.html = html.join('')\n if( tree ) block.nodes = roots\n return block\n }\n\n /** Static open tag + dynamic binds + children recursion */\n private emitElement(\n node: ElementNode,\n path: Path,\n index: number,\n html: string[],\n block: BlockIR,\n emitSiblings: ( nodes: TemplateNode[], path: Path, kids: NodeIR[], i18nParent?: boolean, i18nKey?: string ) => void,\n kids: NodeIR[]\n ){\n const p: Path = [ ...path, index ]\n let open = `<${node.tag}`\n\n /**\n * Tree target: the same element as a node. A repeated attribute\n * keeps its FIRST value, which is what the HTML parser does with\n * the `html` form.\n */\n const\n el: [ string, Record<string, string>?, NodeIR[]? ] = [ node.tag ],\n attrs: Record<string, string> = {},\n put = ( name: string, value: string ) => {\n Object.prototype.hasOwnProperty.call( attrs, name ) || ( attrs[ name ] = value )\n }\n this.tree && kids.push( el )\n\n /**\n * `i18n` marks an element's own text and its visual\n * attributes (title/placeholder) as translatable.\n */\n /** `args` (`[a,b]`) is the one attribute form with no name */\n const named = node.attrs.filter( a => 'name' in a ) as ( AttrNode & { name: string } )[]\n\n const i18n = named.some( a =>\n a.name === 'i18n' && ( ( a.k === 'bool' && a.value ) || a.k === 'literal' ) )\n const translatableAttr = ( name: string ) => i18n && ( name === 'title' || name === 'placeholder' )\n\n /**\n * Stable translation ids (RFC-005 §3).\n *\n * <h1 i18n=\"hero.title\">Welcome</h1>\n * <input i18n i18n-placeholder=\"search.hint\" placeholder=\"Search…\">\n *\n * `i18n=\"key\"` ids the element's own text; `i18n-<attr>=\"key\"` ids\n * that attribute. Bare `i18n` keeps the gettext model where the\n * source text is the key — fine when a human owns the wording,\n * lossy when a generator rewrites it.\n */\n const keyOf = ( name: string ) => {\n const a = named.find( x => x.name === name && x.k === 'literal' )\n return a && 'value' in a && a.value ? String( a.value ) : undefined\n }\n const textKey = keyOf('i18n')\n const attrKey = ( name: string ) => keyOf(`i18n-${name}`)\n\n /** `i18n-<attr>` on an element that never opted in translates nothing */\n !i18n && named.some( a => a.name.startsWith('i18n-') )\n && this.report( 'LIPS-C014', 'warning',\n `i18n-* key on <${node.tag}> without the 'i18n' marker — the attribute will not be translated`,\n node.loc.offset, node.loc.length )\n\n for( const attr of node.attrs ){\n /**\n * `@html` hands markup to the host's HTML parser. A tree host has\n * none, so the bind could only ever render as text — say so here\n * rather than let the content arrive silently unparsed.\n */\n if( this.tree && 'name' in attr && attr.name === '@html' ){\n this.report( 'LIPS-C021', 'error',\n `@html on <${node.tag}>: the 'tree' target has no HTML parser`,\n attr.loc.offset, attr.loc.length,\n 'Write the markup in the template, or use @text' )\n continue\n }\n\n /**\n * On an ELEMENT, `style=` is CSS text — `{…}` in it is an\n * interpolation slot, so a React-style object literal never reaches\n * the DOM: it goes to the expression compiler, which rejects the\n * `:` (LIPS-E003, naming the token and not the mistake) and the\n * element renders unstyled. Say what the fix is instead.\n *\n * Components are untouched: there `style` is an input like any\n * other, and an object is a perfectly good value for it.\n */\n if( 'name' in attr && attr.name === 'style' ){\n const source = objectishAttr( attr )\n\n if( source && isObjectLiteral( source ) ){\n this.report( 'LIPS-C019', 'error',\n `style= on <${node.tag}> takes CSS text, not an object literal`,\n attr.loc.offset, attr.loc.length,\n 'Write the declarations as CSS — style=\"border: 2px solid gray; margin: 3rem\" — '\n + 'and interpolate values into it where they vary: style=\"margin: {state.gap}rem\". '\n + 'Styles that need pseudo-classes, media queries or keyframes belong in the '\n + \"component's stylesheet.\" )\n continue\n }\n }\n\n // Quoted handler — reported and dropped, never emitted as a dead attribute\n if( this.quotedEvent( node.tag, attr ) ) continue\n\n switch( attr.k ){\n case 'literal':\n if( attr.name === '@format' ){\n block.binds.push( this.formatBind( p, attr ) )\n break\n }\n if( attr.name.startsWith('@') ){\n block.binds.push({ t: 'prop', p, name: attr.name.slice( 1 ), e: this.synth( JSON.stringify( attr.value ) ) })\n break\n }\n // `i18n=\"key\"` / `i18n-<attr>=\"key\"` are directives, not output\n if( attr.name === 'i18n' || attr.name.startsWith('i18n-') ) break\n // Literal title/placeholder under i18n must become a bind to be translated\n if( translatableAttr( attr.name ) ){\n const bind: BindIR = { t: 'attr', p, name: attr.name, e: this.synth( JSON.stringify( attr.value ) ), i18n: 1 }\n const k = attrKey( attr.name )\n if( k ) bind.ik = k\n block.binds.push( bind )\n break\n }\n open += ` ${attr.name}=\"${escAttr( attr.value )}\"`\n put( attr.name, attr.value )\n break\n case 'bool':\n // `i18n` is a compiler directive, not an output attribute\n if( attr.name !== 'i18n' && attr.value ){\n open += ` ${attr.name}`\n put( attr.name, '' )\n }\n break\n case 'expr': {\n if( attr.name === '@format' ){\n block.binds.push( this.formatBind( p, attr ) )\n break\n }\n if( attr.name.startsWith('@') ){\n block.binds.push({ t: 'prop', p, name: attr.name.slice( 1 ), e: this.expr( attr.source, attr.loc ) })\n break\n }\n\n const bind: BindIR = { t: 'attr', p, name: attr.name, e: this.expr( attr.source, attr.loc ) }\n if( translatableAttr( attr.name ) ){\n bind.i18n = 1\n const k = attrKey( attr.name )\n if( k ) bind.ik = k\n }\n block.binds.push( bind )\n break\n }\n case 'interp': {\n if( attr.name === '@format' ){\n block.binds.push( this.formatBind( p, attr ) )\n break\n }\n /**\n * `@text=\"Row {i + 1}\"` — an @-prop whose value INTERPOLATES.\n * Without this it fell through to the attribute branch and set a\n * literal `@text` attribute on the element, so the prop it names\n * was never written and nothing rendered.\n */\n if( attr.name.startsWith('@') ){\n block.binds.push({ t: 'prop', p, name: attr.name.slice( 1 ), e: this.concat( attr.parts ) })\n break\n }\n\n const bind: BindIR = { t: 'attr', p, name: attr.name, e: this.concat( attr.parts ) }\n if( translatableAttr( attr.name ) ){\n bind.i18n = 1\n const k = attrKey( attr.name )\n if( k ) bind.ik = k\n }\n block.binds.push( bind )\n break\n }\n case 'event':\n block.binds.push({ t: 'event', p, name: attr.name, e: this.synth( attr.source ) })\n break\n case 'spread':\n block.binds.push({ t: 'spread', p, e: this.expr( attr.source, attr.loc ) })\n break\n case 'fn':\n this.report( 'LIPS-C007', 'warning',\n `Callable attribute '${attr.name}(…)' has no meaning on <${node.tag}>`, attr.loc.offset, attr.loc.length )\n break\n case 'args':\n this.report( 'LIPS-C008', 'warning',\n `Iterator arguments are not applicable to <${node.tag}>`, attr.loc.offset, attr.loc.length )\n break\n }\n }\n\n const kept = Object.keys( attrs ).length\n kept && ( el[ 1 ] = attrs )\n\n if( VOID_ELEMENTS.has( node.tag ) ){\n html.push( open + '>' )\n return\n }\n\n html.push( open + '>' )\n\n /**\n * A key ids ONE FIXED string. Two shapes break that:\n *\n * <h1 i18n=\"k\">Hello {state.name}</h1> — interpolated\n * <h1 i18n=\"k\">a<b>x</b>c</h1> — several text runs\n *\n * In the first the key would resolve the whole entry and silently\n * drop the interpolated value; in the second every run would render\n * the same translation. Both are what `@format` exists for — it\n * takes a reference AND params — so name it and fall back to\n * source-text keying rather than emit something wrong.\n */\n let key = textKey\n const runs = node.children.filter( c => c.t === 'text' || c.t === 'interp' )\n if( key && ( runs.length > 1 || runs.some( c => c.t === 'interp' ) ) ){\n this.report( 'LIPS-C015', 'error',\n `<${node.tag} i18n=\"${key}\"> keys text that is not a single fixed string. `\n + `Use @format=\"${key}, { … }\" for interpolated text.`,\n node.loc.offset, node.loc.length )\n key = undefined\n }\n\n const children: NodeIR[] = []\n node.children.length && emitSiblings( node.children, p, children, i18n, key )\n if( children.length ){\n el[ 1 ] = attrs // `{}` when there are none: children sit at index 2\n el[ 2 ] = children\n }\n html.push( `</${node.tag}>` )\n }\n\n /**\n * `@format=\"reference, { params }\"` → a prop bind carrying the\n * dictionary reference plus a compiled params expression.\n */\n private formatBind( p: Path, attr: AttrNode & { k: 'literal' | 'expr' | 'interp' } ): BindIR {\n /**\n * `@format` carries a reference plus a params OBJECT, so the\n * braces are data — not interpolation. Reconstruct the raw\n * source when the parser split it into interpolation parts.\n */\n const raw = attr.k === 'literal' ? attr.value\n : attr.k === 'expr' ? attr.source\n : attr.parts.map( part => typeof part === 'string' ? part : `{${part.expr}}` ).join('')\n\n const comma = raw.indexOf(',')\n\n if( comma === -1 ){\n this.report( 'LIPS-C012', 'error',\n `@format expects \"reference, { params }\"`, attr.loc.offset, attr.loc.length )\n return { t: 'prop', p, name: 'format', e: this.synth('({})'), ref: raw.trim() }\n }\n\n const\n ref = raw.slice( 0, comma ).trim(),\n params = raw.slice( comma + 1 ).trim()\n\n return { t: 'prop', p, name: 'format', e: this.expr( params, attr.loc ), ref }\n }\n\n // ---- control-flow blocks\n private attrsOf( node: ElementNode ){\n const\n byName = new Map<string, AttrNode>(),\n args: string[] = []\n\n for( const attr of node.attrs ){\n if( attr.k === 'args' ) args.push( ...attr.names )\n else if( 'name' in attr ) byName.set( attr.name, attr )\n }\n return { byName, args }\n }\n\n private controlBlock( node: ElementNode, siblings: TemplateNode[], i: number, p: Path, block: BlockIR, scope: string[] ){\n switch( node.tag ){\n case 'if': {\n const branches: { when: E | null, block: BlockIR }[] = [{\n when: node.head ? this.expr( node.head.expr, node.head.loc ) : this.missingHead( node ),\n block: this.block( node.children, scope )\n }]\n\n for( let j = i + 1; j < siblings.length; j++ ){\n const sib = siblings[ j ]\n if( sib.t !== 'element' ) break\n\n if( sib.tag === 'else-if' )\n branches.push({\n when: sib.head ? this.expr( sib.head.expr, sib.head.loc ) : this.missingHead( sib ),\n block: this.block( sib.children, scope )\n })\n else if( sib.tag === 'else' ){\n branches.push({ when: null, block: this.block( sib.children, scope ) })\n break\n }\n else break\n }\n\n block.blocks.push({ t: 'if', p, branches })\n break\n }\n\n case 'else-if':\n case 'else':\n this.report( 'LIPS-C001', 'error', `<${node.tag}> without a preceding <if>`, node.loc.offset, node.loc.length )\n break\n\n case 'for': {\n const { byName, args } = this.attrsOf( node )\n const\n inAttr = byName.get('in'),\n fromAttr = byName.get('from'),\n toAttr = byName.get('to'),\n byAttr = byName.get('by')\n\n if( !inAttr && !fromAttr ){\n this.report( 'LIPS-C004', 'error', `<for> requires 'in' or 'from'/'to'`, node.loc.offset, node.loc.length )\n break\n }\n\n const child: ChildIR = {\n t: 'for', p, args,\n block: this.block( node.children, [ ...scope, ...args ] )\n }\n if( inAttr && inAttr.k === 'expr' ) child.of = this.expr( inAttr.source, inAttr.loc )\n if( fromAttr ) child.from = this.numInput( fromAttr )\n if( toAttr ) child.to = this.numInput( toAttr )\n if( byAttr && ( byAttr.k === 'literal' || byAttr.k === 'expr' ) )\n child.by = byAttr.k === 'literal' ? { lit: byAttr.value } : { e: this.expr( byAttr.source, byAttr.loc ) }\n\n block.blocks.push( child )\n break\n }\n\n case 'switch': {\n const on = node.head ? this.expr( node.head.expr, node.head.loc ) : this.missingHead( node )\n const cases: { is: CompInput | null, block: BlockIR }[] = []\n\n for( const child of node.children ){\n if( child.t !== 'element' ) continue\n\n if( child.tag === 'case' ){\n const { byName } = this.attrsOf( child )\n const isAttr = byName.get('is')\n\n if( !isAttr || ( isAttr.k !== 'literal' && isAttr.k !== 'expr' ) ){\n this.report( 'LIPS-C004', 'error', `<case> requires an 'is' attribute`, child.loc.offset, child.loc.length )\n continue\n }\n cases.push({\n is: isAttr.k === 'literal' ? { lit: isAttr.value } : { e: this.expr( isAttr.source, isAttr.loc ) },\n block: this.block( child.children, scope )\n })\n }\n else if( child.tag === 'default' )\n cases.push({ is: null, block: this.block( child.children, scope ) })\n else\n this.report( 'LIPS-C003', 'error', `Only <case>/<default> are valid inside <switch>`, child.loc.offset, child.loc.length )\n }\n\n block.blocks.push({ t: 'switch', p, on, cases })\n break\n }\n\n case 'async': {\n const awaitAttr = node.attrs.find( a => a.k === 'fn' && a.name === 'await' ) as ( AttrNode & { k: 'fn' } ) | undefined\n if( !awaitAttr ){\n this.report( 'LIPS-C004', 'error', `<async> requires await(…)`, node.loc.offset, node.loc.length )\n break\n }\n\n const child: ChildIR = { t: 'async', p, awaitE: this.expr( awaitAttr.source, awaitAttr.loc ) }\n\n for( const arm of node.children ){\n if( arm.t !== 'element' ) continue\n const { args } = this.attrsOf( arm )\n\n if( arm.tag === 'then' ) child.then = { args, block: this.block( arm.children, [ ...scope, ...args ] ) }\n else if( arm.tag === 'catch' ) child.catch = { args, block: this.block( arm.children, [ ...scope, ...args ] ) }\n else if( arm.tag === 'loading' ) child.loading = this.block( arm.children, scope )\n else this.report( 'LIPS-C003', 'error', `Only <then>/<catch>/<loading> are valid inside <async>`, arm.loc.offset, arm.loc.length )\n }\n\n block.blocks.push( child )\n break\n }\n\n case 'let':\n case 'const': {\n const vars: Record<string, CompInput> = {}\n\n for( const attr of node.attrs ){\n /**\n * Spread on <let> cannot work with compiled expressions:\n * the spread's keys are unknown at compile time, so binds\n * referencing them as bare identifiers can never resolve.\n * Assign the object to ONE name instead.\n */\n if( attr.k === 'spread' ){\n this.report( 'LIPS-C013', 'error',\n `Spread is not supported on <${node.tag}> — scope names must be known at compile time`,\n attr.loc.offset, attr.loc.length,\n `Assign it to one variable: <${node.tag} obj={ ${attr.source} }/> and read obj.<key>` )\n continue\n }\n\n if( attr.k === 'literal' || attr.k === 'expr' || attr.k === 'interp' || attr.k === 'bool' ){\n vars[ attr.name ] = this.compInput( attr )\n /**\n * RFC decision #1: let/const names are block-scoped\n * (visible to every bind of the enclosing block)\n */\n !block.scope.includes( attr.name ) && block.scope.push( attr.name )\n !scope.includes( attr.name ) && scope.push( attr.name )\n }\n }\n\n block.blocks.push({ t: 'let', p, const: node.tag === 'const', vars })\n break\n }\n\n case 'log':\n /**\n * A log head is an argument LIST (like an event\n * instruction), not a single expression — the\n * runtime resolves it; no single-expr validation.\n */\n block.blocks.push({ t: 'log', p, e: node.head ? this.synth( node.head.expr ) : this.missingHead( node ) })\n break\n\n /**\n * Scoped context (RFC-005 §4):\n *\n * <context selection=state.sel tool=state.tool> … </context>\n *\n * Every attribute becomes a context key visible to the subtree —\n * components included — shadowing the global store for that key\n * only. Unlike `<let>`, the names do NOT enter expression scope:\n * they are read as `context.selection`, which is what makes a\n * child component see them without the parent passing inputs.\n */\n case 'context': {\n const vars: Record<string, CompInput> = {}\n\n for( const attr of node.attrs ){\n /**\n * Same reasoning as <let>: a spread's keys are unknown at\n * compile time. Here they would also silently fail to shadow\n * anything, since lookup is by name at render.\n */\n if( attr.k === 'spread' ){\n this.report( 'LIPS-C016', 'error',\n `Spread is not supported on <context> — provided keys must be known at compile time`,\n attr.loc.offset, attr.loc.length,\n `Provide them one by one: <context a=obj.a b=obj.b>` )\n continue\n }\n\n if( attr.k === 'literal' || attr.k === 'expr' || attr.k === 'interp' || attr.k === 'bool' )\n vars[ attr.name ] = this.compInput( attr )\n }\n\n if( !Object.keys( vars ).length )\n this.report( 'LIPS-C017', 'warning',\n `<context> provides nothing — it renders its children unchanged`,\n node.loc.offset, node.loc.length )\n\n block.blocks.push({ t: 'provide', p, vars, block: this.block( node.children, scope ) })\n break\n }\n\n /**\n * Scoped language (RFC-005 §4):\n *\n * <i18n lang=state.docLang> … </i18n>\n *\n * The subtree's translatable binds resolve against `lang` instead\n * of the global language — a document pane in the content's\n * language while the chrome stays in the reader's.\n */\n case 'i18n': {\n const { byName } = this.attrsOf( node )\n const langAttr = byName.get('lang')\n\n if( !langAttr ){\n this.report( 'LIPS-C018', 'error',\n `<i18n> requires a 'lang' attribute: <i18n lang=state.docLang>`,\n node.loc.offset, node.loc.length )\n break\n }\n\n block.blocks.push({\n t: 'provide', p, vars: {},\n lang: this.compInput( langAttr as AttrNode & { k: 'literal' | 'expr' | 'interp' | 'bool' } ),\n block: this.block( node.children, scope )\n })\n break\n }\n }\n }\n\n private missingHead( node: ElementNode ): E {\n this.report( 'LIPS-C004', 'error', `<${node.tag}> requires a head expression: <${node.tag}( … )>`, node.loc.offset, node.loc.length )\n return this.synth('undefined')\n }\n private numInput( attr: AttrNode ): CompInput {\n if( attr.k === 'literal' ) return { lit: isNumeric( attr.value ) ? Number( attr.value ) : attr.value }\n if( attr.k === 'expr' ) return isNumeric( attr.source ) ? { lit: Number( attr.source ) } : { e: this.expr( attr.source, attr.loc ) }\n return { lit: undefined }\n }\n\n /**\n * Macro call site → inlined block.\n *\n * Every call-site attribute becomes a block-scoped variable\n * (the macro's declared `argv` are the named ones; all of them\n * together also form `arguments` at runtime).\n */\n private macroCall( node: ElementNode, p: Path, scope: string[] ): ChildIR | null {\n const macro = this.macros.get( node.tag )!\n\n if( this.macroStack.includes( macro.name ) ){\n this.report( 'LIPS-C009', 'error',\n `Recursive macro <${macro.name}> (${[ ...this.macroStack, macro.name ].join(' → ')})`,\n node.loc.offset, node.loc.length )\n return null\n }\n\n /**\n * Assignments in SOURCE ORDER — spreads participate like any\n * other set, so `key=k ...each` lets the spread override `key`\n * while `...each key=k` lets the explicit attr win.\n *\n * Undeclared argv default to `undefined` at runtime: falsy in\n * conditions, attribute-removing, renders '' in text (RFC #4).\n */\n const sets: MacroSet[] = []\n for( const attr of node.attrs ){\n if( attr.k === 'literal' || attr.k === 'expr' || attr.k === 'interp' || attr.k === 'bool' )\n sets.push({ name: attr.name, ci: this.compInput( attr ) })\n else if( attr.k === 'spread' )\n sets.push({ spread: this.expr( attr.source, attr.loc ) })\n }\n\n this.macroStack.push( macro.name )\n const block = this.block( macro.children, [ ...scope, ...macro.argv ] )\n this.macroStack.pop()\n\n return { t: 'macro', p, name: macro.name, sets, args: macro.argv, block }\n }\n\n /** Components and dynamic tags share input/event/spread shape */\n /**\n * `on-click=\"…\"` is NOT an event binding. The parser only produces an\n * `event` attribute for the instruction form `on-x( … )`; quoted, it\n * stays an ordinary attribute, so no listener is wired and the source\n * text lands in the DOM as a dead `on-click=\"() => …\"`. Nothing failed\n * loudly, which is exactly the problem — same class as the `@text=\"…\"`\n * and `style={…}` fall-throughs.\n */\n private quotedEvent( tag: string, attr: AttrNode ){\n if( !( 'name' in attr ) || !attr.name.startsWith('on-') ) return false\n\n this.report( 'LIPS-C020', 'error',\n `${attr.name}=\"…\" on <${tag}> wires no listener`,\n attr.loc.offset, attr.loc.length,\n `Handlers use the instruction form: ${attr.name}( … ). `\n + `Quoted, it is an ordinary attribute — the handler never runs and the source is emitted into the DOM.` )\n return true\n }\n\n private compLike( node: ElementNode, p: Path, scope: string[], kind: 'comp' | 'dynamic' ): ChildIR {\n const\n inputs: Record<string, CompInput> = {},\n spreads: E[] = [],\n events: { name: string, e: E }[] = []\n let args: string[] = []\n\n for( const attr of node.attrs ){\n // A quoted handler on a component is the same dead attribute, as an input\n if( attr.k !== 'event' && this.quotedEvent( node.tag, attr ) ) continue\n\n switch( attr.k ){\n case 'literal': case 'bool': case 'expr': case 'interp':\n inputs[ attr.name ] = this.compInput( attr )\n break\n case 'event':\n events.push({ name: attr.name, e: this.synth( attr.source ) })\n break\n case 'spread':\n spreads.push( this.expr( attr.source, attr.loc ) )\n break\n case 'args':\n args = [ ...args, ...attr.names ]\n break\n case 'fn':\n inputs[ attr.name ] = { e: this.expr( attr.source, attr.loc ) }\n break\n }\n }\n\n const contents: ArmIR | undefined = node.children.length\n ? { args, block: this.block( node.children, [ ...scope, ...args ] ) }\n : undefined\n\n return kind === 'comp'\n ? { t: 'comp', p, name: node.tag, inputs, spreads, events, contents }\n : { t: 'dynamic', p, tag: this.expr( node.dynamicTag!.expr, node.dynamicTag!.loc ), inputs, spreads, events, contents }\n }\n}\n\n// -------------------------------------------------------------------- API\n/** Parse `<macro [argv] name=\"X\">…</macro>` blocks into a lookup */\nfunction parseMacros( src: string, diagnostics: TemplateDiagnostic[], check?: CompileOptions['check'] ){\n const macros = new Map<string, MacroDef>()\n if( !src?.trim() ) return macros\n\n const parsed = parseTemplate( src )\n diagnostics.push( ...parsed.diagnostics )\n check?.( parsed.root.children, diagnostics, src )\n\n for( const node of parsed.root.children ){\n if( node.t !== 'element' ) continue\n\n if( node.tag !== 'macro' ){\n diagnostics.push({\n code: 'LIPS-C010', severity: 'warning',\n message: `Only <macro> definitions are allowed in the macros source — ignoring <${node.tag}>`,\n loc: { line: 1, col: 1, offset: node.loc.offset, length: node.loc.length }\n })\n continue\n }\n\n let name = ''\n const argv: string[] = []\n for( const attr of node.attrs ){\n if( attr.k === 'args' ) argv.push( ...attr.names )\n else if( attr.k === 'literal' && attr.name === 'name' ) name = attr.value\n }\n\n if( !name ){\n diagnostics.push({\n code: 'LIPS-C011', severity: 'error',\n message: `<macro> requires a name attribute`,\n loc: { line: 1, col: 1, offset: node.loc.offset, length: node.loc.length }\n })\n continue\n }\n\n // Tag names arrive lowercased — match call sites case-insensitively\n macros.set( name.toLowerCase(), { name, argv, children: node.children })\n }\n\n return macros\n}\n\nexport function compileTemplate( src: string, options?: CompileOptions ): CompileResult {\n const diagnostics: TemplateDiagnostic[] = []\n const macros = parseMacros( options?.macros || '', diagnostics, options?.check )\n\n const parsed = parseTemplate( src )\n options?.check?.( parsed.root.children, diagnostics, src )\n options?.transform?.( parsed.root.children, diagnostics )\n const compiler = new Compiler( src, macros, options?.target === 'tree' )\n const ir = compiler.compile( parsed.root.children )\n\n return { ir, diagnostics: [ ...diagnostics, ...parsed.diagnostics, ...compiler.diagnostics ] }\n}\n",
|
|
7
|
+
"/**\n * The host seam (RFC-006 §4.1).\n *\n * The IR runtime never touches a node itself. It creates, places, walks\n * and mutates nodes through a `Host`, so one runtime drives the DOM, an\n * in-memory tree (`./tree`) or a native element API. The node type is\n * the host's own and opaque to the runtime.\n *\n * What a host must provide is what the runtime actually does with\n * nodes, no more:\n *\n * - instantiate a block's skeleton (`clone`), and create the few nodes\n * the runtime adds itself: markers, text runs, unresolved elements\n * - a sibling-linked tree with parents: block instances are ranges\n * between two markers, walked and moved whole (`range`, `insertAfter`)\n * - attributes, text, inline custom properties, listeners\n * - two host decisions: how a stylesheet scope marks an element\n * (`rel` here, a class on Lynx) and whether markup can be parsed\n * (`html` is optional — the `'tree'` compile target rejects `@html`)\n *\n * Stylesheet injection is not here: it already reaches the runtime as\n * `RuntimeOptions.createStylesheet`, supplied by the facade.\n */\n\nimport type { BlockIR } from './compiler'\n\nexport interface Host<N = any> {\n /** A detached container holding a fresh copy of the block's skeleton */\n clone( block: BlockIR ): N\n /** An empty detached container */\n fragment(): N\n element( tag: string ): N\n text( value: string ): N\n /** An invisible node: block boundaries and control-flow anchors */\n marker( label: string ): N\n\n /** The child at `index` — skeleton paths are child-index walks */\n child( parent: N, index: number ): N\n next( node: N ): N | null\n /** `first`, its following siblings, up to and including `last` */\n range( first: N, last: N ): N[]\n /** Insert `node` before `ref`, or at the end when `ref` is null */\n insert( parent: N, node: N, ref: N | null ): void\n /** Place `nodes`, in order, right after `ref` — nothing when `ref` has no parent */\n insertAfter( ref: N, nodes: N[] ): void\n /**\n * `gone`: the node will never be inserted again — the runtime is\n * destroying it, not moving it. A host may release what it holds for\n * it (the Lynx host frees its ids); the DOM has nothing to free.\n */\n remove( node: N, gone?: boolean ): void\n isElement( node: N ): boolean\n /** In the live tree — what `onAttach` waits for */\n connected( node: N ): boolean\n /** `a` comes before `b` in tree order; false when they share no tree */\n precedes( a: N, b: N ): boolean\n\n /** A text node's value — the hot path of every text bind */\n setText( node: N, value: string ): void\n /** Replace an element's children with one text run (`@text`, `@format`) */\n content( el: N, value: string ): void\n /** `null` removes the attribute */\n attr( el: N, name: string, value: string | null ): void\n /** Replace the element's children with parsed markup (`@html`) — DOM only */\n html?( el: N, value: string ): void\n /** Set an inline custom property, or remove it when `null` (RFC-004 §8) */\n styleVar( el: N, prop: string, value: string | null ): void\n /** Mark a component root with its stylesheet scope. An inner scope already set wins */\n scope( el: N, nsp: string ): void\n /** Returns the unlisten function */\n listen( el: N, name: string, fn: ( event: any ) => void ): () => void\n /** Capture focus before a swap moves nodes; the returned function restores it */\n keepFocus?(): () => void\n}\n\n// ---------------------------------------------------------------- DOM host\nconst SKELETONS = new WeakMap<BlockIR, HTMLTemplateElement>()\n\n/**\n * Today's behaviour, unchanged: skeletons parsed once per block into a\n * `<template>` and cloned per instance, scope stamped as `rel`.\n */\nexport const domHost: Host<Node> = {\n clone( block ){\n let tpl = SKELETONS.get( block )\n if( !tpl ){\n tpl = document.createElement('template')\n tpl.innerHTML = block.html\n SKELETONS.set( block, tpl )\n }\n return tpl.content.cloneNode( true )\n },\n fragment: () => document.createDocumentFragment(),\n element: tag => document.createElement( tag ),\n text: value => document.createTextNode( value ),\n marker: label => document.createComment( label ),\n\n child: ( parent, index ) => parent.childNodes[ index ],\n next: node => node.nextSibling,\n /**\n * Range walks and range moves are the hottest node work there is (a\n * keyed list walks every row's range on every change), so they are ONE\n * host call per range with the loop inside, not a host call per node.\n */\n range( first, last ){\n const out: Node[] = []\n for( let n: Node | null = first; n; n = n.nextSibling ){\n out.push( n )\n if( n === last ) break\n }\n return out\n },\n insert: ( parent, node, ref ) => { parent.insertBefore( node, ref ) },\n /**\n * The reference is re-read after every insert rather than captured\n * once: `nodes` may already contain `ref`'s next sibling, and a fixed\n * reference would put the rest of the range in front of it.\n */\n insertAfter( ref, nodes ){\n const parent = ref.parentNode\n if( !parent ) return\n let anchor = ref\n for( const n of nodes ){\n parent.insertBefore( n, anchor.nextSibling )\n anchor = n\n }\n },\n remove: node => ( node as ChildNode ).remove(),\n isElement: node => node.nodeType === 1,\n connected: node => node.isConnected,\n /**\n * Nodes in different trees compare as DISCONNECTED plus an arbitrary\n * but consistent order, so a range test `precedes( from, n ) &&\n * precedes( n, to )` still fails for them: one side always does.\n */\n precedes: ( a, b ) => !!( a.compareDocumentPosition( b ) & 4 /* FOLLOWING */ ),\n\n attr: ( el, name, value ) => value === null\n ? ( el as Element ).removeAttribute( name )\n : ( el as Element ).setAttribute( name, value ),\n /** `.data`: the direct write, as before the seam — no node-type dispatch */\n setText: ( node, value ) => { ( node as Text ).data = value },\n content: ( el, value ) => { el.textContent = value },\n html: ( el, value ) => { ( el as Element ).innerHTML = value },\n styleVar: ( el, prop, value ) => value === null\n ? ( el as HTMLElement ).style.removeProperty( prop )\n : ( el as HTMLElement ).style.setProperty( prop, value ),\n scope: ( el, nsp ) => { ( el as Element ).hasAttribute('rel') || ( el as Element ).setAttribute('rel', nsp ) },\n listen( el, name, fn ){\n el.addEventListener( name, fn )\n return () => el.removeEventListener( name, fn )\n },\n /**\n * Salvaged nodes are detached and re-inserted, which drops focus. The\n * element survives the move, so put the caret back where the user left it.\n */\n keepFocus(){\n const focused = document.activeElement as HTMLElement | null\n return () => { focused && focused.isConnected && focused !== document.activeElement && focused.focus() }\n }\n}\n",
|
|
8
|
+
"/**\n * RFC-007 — what a template you did not write may touch.\n *\n * ONE policy decides; three places ask it:\n *\n * checkTemplate compile time — a refusal is a positioned diagnostic,\n * and the refused construct is dropped before it compiles\n * guard runtime, expressions — a second evaluator over the same\n * AST, asking the policy at every name, member and value\n * host runtime, the page — the DOM host with every write to\n * the page held to the same rules (RFC-006 §4.1's seam)\n *\n * Compile time REPORTS, runtime ENFORCES: a precompiled IR, a template\n * object built from data, or a value that only exists at runtime never\n * meets the compiler, so the runtime holds the line on its own.\n *\n * The policy is data plus predicates. Replace it whole, or in part —\n * methods call each other through `this`, so overriding `url` changes\n * what `attr` and `css` accept too:\n *\n * new Lips({ untrusted: { ...untrustedPolicy, url: sameOriginOnly } })\n *\n * It ships as its own entry, `@lipsjs/lips/untrusted`, passed to Lips by\n * value: an app that never renders an untrusted template pays nothing.\n */\n\nimport type { Expr, ExprEnv } from './expression'\nimport { parseExpression, splitTopLevel } from './expression'\nimport type { TemplateNode, ElementNode, AttrNode, ExprSlot } from './parser'\nimport type { BlockIR, CompileOptions } from './compiler'\nimport { HTML_TAGS, CONTROL_TAGS, ARM_TAGS } from './compiler'\nimport type { Host } from './host'\nimport { domHost } from './host'\nimport type { Guard, RuntimeOptions, IRComponentDef } from './runtime'\nimport type { StyleCompileOptions, StyleCompileResult } from './style'\n\n/** The runtime's mark on a component `self` — registered, so this bundle finds the same one */\nconst SELF = Symbol.for('lips.self')\n\n/** Line/col of `offset` in `src`, as every Lips diagnostic counts them */\nconst locOf = ( src: string, offset: number, length: number ) => {\n const before = src.slice( 0, offset ).split('\\n')\n return { line: before.length, col: before[ before.length - 1 ].length + 1, offset, length }\n}\n\ntype StyleCompiler = ( src: string, options: StyleCompileOptions ) => StyleCompileResult\n\n// ------------------------------------------------------------------- types\nexport interface Refusal {\n code: string\n message: string\n hint?: string\n}\n/** `undefined` allows */\nexport type Verdict = Refusal | undefined\n\nexport interface TemplatePolicy {\n /** Names an expression may read besides its metavars and its scope */\n globals: Record<string, unknown>\n /**\n * May an expression reach `key` — read it, call it, or with `write`\n * assign it? `obj` is the value when known: always at runtime, and at\n * compile time when it is one of `globals`.\n */\n member( key: string, write: boolean, obj?: unknown ): Verdict\n /** The same question for the component's own `self`, which has rules of its own */\n self( key: string, write?: boolean ): Verdict\n /** May an expression hold this value — read from data, returned by a call, passed to an arrow? */\n value( v: unknown ): Verdict\n /** What an inline handler receives in place of a DOM event */\n event( e: Event ): object\n /** May the template create this element (lower-case tag)? */\n tag( name: string ): Verdict\n /** May the template render this registered component? */\n component( name: string ): Verdict\n /**\n * May the template set this attribute on `tag`? `value` is undefined\n * when it is not known yet (an expression, at compile time). `@html` is\n * asked under the name '@html'.\n */\n attr( tag: string, name: string, value?: string ): Verdict\n /** May the page load this URL — an href, a src, a CSS url()? */\n url( value: string ): Verdict\n /** May this CSS reach the page — a stylesheet, a style=, a reactive declaration? */\n css( text: string ): Verdict\n /** Runtime refusals outside an expression land here (inside one, they throw into the component's onError) */\n report( refusal: Refusal ): void\n}\n\n/** What the facade needs, built once per untrusted Lips instance — `untrusted()` makes one */\nexport interface Untrusted {\n check: Check\n /** The style compiler, held to the policy: a sheet with a refusal ships empty */\n style( compile: StyleCompiler ): StyleCompiler\n /** The facade's runtime options, guarded */\n runtime( options: RuntimeOptions ): RuntimeOptions\n}\n\ntype Check = NonNullable<CompileOptions['check']>\n\n// ------------------------------------------------------------------ tables\nconst no = ( code: string, message: string, hint?: string ): Refusal => ({ code, message, hint })\nconst own = ( o: object, key: string ) => Object.prototype.hasOwnProperty.call( o, key )\n\n/** Members that lead to prototypes and constructors rather than data */\nconst PROTO = new Set([\n 'constructor', '__proto__', 'prototype',\n '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__',\n 'caller', 'callee'\n])\n\nconst TAGS = new Set([\n // run script, or are a document of their own\n 'script', 'iframe', 'frame', 'frameset', 'object', 'embed', 'applet', 'portal', 'fencedframe',\n // act on the whole page\n 'base', 'link', 'meta', 'style', 'title', 'head', 'body', 'html',\n // content the element check cannot follow\n 'template', 'noscript', 'noembed', 'noframes', 'xmp', 'plaintext',\n // SVG animation writes attributes, href among them\n 'animate', 'animatemotion', 'animatetransform', 'set'\n])\n\nconst URL_ATTRS = new Set([\n 'href', 'src', 'action', 'formaction', 'xlink:href', 'poster', 'cite', 'background',\n 'longdesc', 'manifest', 'data', 'codebase', 'lowsrc', 'dynsrc', 'icon'\n])\nconst SCHEMES = new Set([ 'http', 'https', 'mailto', 'tel' ])\n\nconst ATTRS: Record<string, string> = {\n srcdoc: 'It is a whole document, written into an attribute',\n is: \"It makes the element one the page defined, running the page's code\",\n form: 'It joins a form of the host page by id'\n}\n\n// ----------------------------------------------------------------- globals\n/**\n * What the default policy offers, and nothing else of the realm. Copies,\n * frozen — the page's own `Math` or `JSON` handed to a template would be\n * the page's to overwrite. Constructors are offered as plain calls with\n * chosen statics, so none of them leads anywhere.\n */\nconst OFFERED = new WeakSet<object>()\nconst offer = <T extends object>( o: T ): T => ( OFFERED.add( o ), Object.freeze( o ) )\nconst pick = ( from: any, keys: string[] ) => Object.fromEntries( keys.map( k => [ k, from[ k ] ] ) )\nconst call = ( fn: ( ...a: any[] ) => any, statics: Record<string, unknown> = {} ) =>\n offer( Object.assign( ( ...a: any[] ) => fn( ...a ), statics ) )\n\nconst GLOBALS: Record<string, unknown> = {\n Math: offer( pick( Math, Object.getOwnPropertyNames( Math ) ) ),\n JSON: offer( pick( JSON, [ 'parse', 'stringify' ] ) ),\n Object: offer( pick( Object, [ 'keys', 'values', 'entries', 'fromEntries' ] ) ),\n Array: offer( pick( Array, [ 'isArray', 'from', 'of' ] ) ),\n String: call( String, pick( String, [ 'fromCharCode', 'fromCodePoint' ] ) ),\n Number: call( Number, pick( Number, [ 'isFinite', 'isInteger', 'isNaN', 'isSafeInteger', 'parseFloat', 'parseInt', 'EPSILON', 'MAX_SAFE_INTEGER', 'MIN_SAFE_INTEGER' ] ) ),\n Boolean: call( Boolean ),\n Date: call( Date, pick( Date, [ 'now', 'parse', 'UTC' ] ) ),\n parseInt, parseFloat, isNaN, isFinite,\n encodeURIComponent, decodeURIComponent, encodeURI, decodeURI\n}\n\n// -------------------------------------------------------------------- css\n/** The CSS a browser reads: comments gone (outside strings), escapes decoded */\nfunction cssText( src: string ){\n let out = '', i = 0\n\n while( i < src.length ){\n const c = src[ i ]\n\n if( c === '\"' || c === \"'\" ){\n let j = i + 1\n while( j < src.length && src[ j ] !== c ) j += src[ j ] === '\\\\' ? 2 : 1\n out += src.slice( i, j + 1 )\n i = j + 1\n continue\n }\n if( c === '/' && src[ i + 1 ] === '*' ){\n const end = src.indexOf( '*/', i + 2 )\n i = end < 0 ? src.length : end + 2\n continue\n }\n out += c\n i++\n }\n\n return out.replace( /\\\\(?:([\\da-f]{1,6})[ \\t\\n\\r\\f]?|([^\\n\\r\\f\\da-f])|[\\n\\r\\f])/gi,\n ( _, hex, ch ) => hex ? String.fromCodePoint( Math.min( parseInt( hex, 16 ), 0x10FFFF ) || 0xFFFD ) : ch ?? '' )\n}\n\n/** Platform objects, and the constructors that turn text into code */\nconst isPlatform = ( v: any ): boolean =>\n v === globalThis\n || v === globalThis.eval\n || ( typeof v === 'function' && /^(Async|AsyncGenerator|Generator)?Function$/.test( v.name ) && v.prototype?.constructor === v )\n || ( typeof Node === 'function' && v instanceof Node )\n || ( typeof Event === 'function' && v instanceof Event )\n || ( typeof EventTarget === 'function' && v instanceof EventTarget )\n // another realm's (an iframe's) nodes and windows\n || ( typeof v === 'object' && ( ( 'nodeType' in v && 'ownerDocument' in v ) || v.window === v ) )\n\n// ---------------------------------------------------------- default policy\nexport const untrustedPolicy: TemplatePolicy = {\n globals: GLOBALS,\n\n member( key, write, obj ){\n if( PROTO.has( key ) )\n return no( 'LIPS-U002', `'${key}' leads to prototypes and constructors, not data`,\n 'An untrusted template reads and writes data; prototype machinery is not reachable' )\n\n if( obj != null && OFFERED.has( obj as object ) && ( write || !own( obj as object, key ) ) )\n return no( 'LIPS-U003', write ? `Globals are read-only — '${key}' cannot be written` : `'${key}' is not offered`,\n 'Offered: Math, JSON, Object.keys/values/entries/fromEntries, Array.isArray/from/of, String, Number, Boolean, Date, parseInt, parseFloat, isNaN, isFinite and the URI codecs' )\n },\n\n self( key, write ){\n if( write ) return no( 'LIPS-U005', `self is read-only — '${key}' cannot be written`, 'Write state instead: state.x = …' )\n if( PROTO.has( key ) ) return this.member( key, false )\n if( key === 'node' )\n return no( 'LIPS-U005', \"self.node holds the component's DOM nodes\",\n 'An untrusted template reaches the page only through the template language' )\n },\n\n value( v ){\n if( v !== null && ( typeof v === 'object' || typeof v === 'function' ) && isPlatform( v ) )\n return no( 'LIPS-U004', 'A DOM node, window, event or code constructor cannot be held by an untrusted template',\n 'Hand the template data, not the platform object it came from' )\n },\n\n event( e: any ){\n const el = ( t: any ) => t && {\n value: t.value, checked: t.checked, name: t.name, id: t.id, type: t.type,\n tagName: t.tagName, dataset: { ...t.dataset }\n }\n\n return {\n type: e.type, key: e.key, code: e.code, data: e.data, inputType: e.inputType,\n altKey: e.altKey, ctrlKey: e.ctrlKey, metaKey: e.metaKey, shiftKey: e.shiftKey, repeat: e.repeat,\n button: e.button, buttons: e.buttons, clientX: e.clientX, clientY: e.clientY,\n deltaX: e.deltaX, deltaY: e.deltaY,\n target: el( e.target ),\n currentTarget: el( e.currentTarget ),\n preventDefault: () => e.preventDefault(),\n stopPropagation: () => e.stopPropagation()\n }\n },\n\n tag( name ){\n const t = name.toLowerCase()\n\n if( TAGS.has( t ) )\n return no( 'LIPS-U010', `<${t}> is refused in an untrusted template`,\n 'It runs script, holds a document of its own, or acts on the whole page' )\n if( t.includes('-') )\n return no( 'LIPS-U011', `<${t}> is a custom element`,\n \"Custom elements run the page's own code — a Lips component the host registered renders instead\" )\n },\n\n component( name ){\n if( name === 'router' )\n return no( 'LIPS-U012', '<router> owns the page URL and window.navigate',\n 'Switch on state for pages — <switch( state.page )>; routing stays with the host' )\n },\n\n attr( tag, name, value ){\n const n = name.toLowerCase()\n\n if( n.startsWith('on') )\n return no( 'LIPS-U020', `'${name}' is an event-handler attribute`, 'Use the instruction form: on-click( … )' )\n if( own( ATTRS, n ) ) return no( 'LIPS-U021', `'${name}' is refused`, ATTRS[ n ] )\n if( value === undefined ) return\n\n if( ( n === 'id' || n === 'name' ) && typeof document === 'object' && value in document )\n return no( 'LIPS-U022', `${n}=\"${value}\" would shadow document.${value}`, 'Choose another value' )\n\n if( n === 'style' ) return this.css( value )\n if( URL_ATTRS.has( n ) ) return this.url( value )\n\n if( n === 'srcset' || n === 'imagesrcset' || n === 'ping' )\n for( const part of value.split( n === 'ping' ? /\\s+/ : ',' ) ){\n const r = part.trim() ? this.url( part.trim().split( /\\s+/ )[ 0 ] ) : undefined\n if( r ) return r\n }\n },\n\n url( value ){\n // What a URL parser does first: tabs and newlines go, leading controls and spaces go\n const v = String( value ).replace( /[\\t\\n\\r]/g, '' ).replace( /^[\\u0000- ]+/, '' )\n const scheme = /^([a-z][a-z\\d+.-]*):/i.exec( v )?.[ 1 ].toLowerCase()\n\n if( !scheme || SCHEMES.has( scheme ) || /^data:image\\/(png|gif|jpe?g|webp|avif|bmp)[;,]/i.test( v ) ) return\n\n return no( 'LIPS-U030', `'${scheme}:' URLs are refused`,\n 'Use a relative, http(s), mailto: or tel: URL — or a raster data:image' )\n },\n\n css( text ){\n const s = cssText( text )\n\n if( /@import\\b/i.test( s ) )\n return no( 'LIPS-U040', '@import loads a stylesheet outside the component scope', 'Write the rules into the stylesheet itself' )\n\n if( /(?:^|[^\\w-])(?:-webkit-|-moz-)?(?:image-set|image|cross-fade|element)\\(/i.test( s ) )\n return no( 'LIPS-U041', 'image-set(), image(), cross-fade() and element() load without url()',\n 'Use url( … ), which is held to the URL rule' )\n\n for( const m of s.matchAll( /\\b(?:url|src)\\(\\s*(?:\"([^\"]*)\"|'([^']*)'|([^)]*))/gi ) ){\n const r = this.url( ( m[ 1 ] ?? m[ 2 ] ?? m[ 3 ] ).trim() )\n if( r ) return r\n }\n },\n\n report( refusal ){ console.warn( '[lips:untrusted]', refusal ) }\n}\n\n// ----------------------------------------------------------- compile time\nconst METAVARS = new Set([ 'state', 'input', 'context', 'static', 'self', 'arguments' ])\n/** Elements that are template syntax, not output */\nconst SYNTAX = new Set([ ...CONTROL_TAGS, ...ARM_TAGS, 'macro' ])\nconst NONE = new Set<string>()\n\n/**\n * Check one expression. `fail` gets each refusal and where in `source` it\n * sits; the result says whether the expression may stay. A syntax error is\n * left to the compiler, which reports it already.\n *\n * `handler`: the expression is the first segment of an event instruction,\n * where a bare unknown name means a method of `self`.\n */\nfunction checkExpression(\n policy: TemplatePolicy,\n source: string,\n declared: Set<string>,\n fail: ( r: Refusal, at: number, length: number ) => void,\n handler = false\n): boolean {\n const { ast, diagnostics } = parseExpression( source )\n if( diagnostics.length ) return true\n\n let ok = true\n const refuse = ( r: Verdict, at = 0, length = 1 ) => { if( r ){ ok = false; fail( r, at, length ) } }\n const known = ( name: string, locals: Set<string> ) =>\n locals.has( name ) || declared.has( name ) || METAVARS.has( name ) || own( policy.globals, name )\n\n if( handler && ast.t === 'id' && !known( ast.name, NONE ) ){\n refuse( policy.self( ast.name ), ast.at, ast.name.length )\n return ok\n }\n\n const visit = ( n: Expr, locals: Set<string>, write = false ): void => {\n switch( n.t ){\n case 'id':\n known( n.name, locals ) || refuse( no( 'LIPS-U001', `'${n.name}' is not provided to an untrusted template`,\n 'Expressions read state, input, context, static, self, their scope, and the globals the policy offers' ),\n n.at, n.name.length )\n return\n\n case 'member': {\n visit( n.obj, locals )\n n.computed && visit( n.prop as Expr, locals )\n\n const prop = n.prop as Expr\n const key = !n.computed ? n.prop as string\n : prop.t === 'lit' && ( typeof prop.v === 'string' || typeof prop.v === 'number' ) ? String( prop.v )\n : undefined\n if( key === undefined ) return\n\n const root = n.obj.t === 'id' && !locals.has( n.obj.name ) && !declared.has( n.obj.name ) ? n.obj.name : ''\n refuse(\n root === 'self' ? policy.self( key, write )\n : root && own( policy.globals, root ) ? policy.member( key, write, policy.globals[ root ] )\n : policy.member( key, write ),\n n.at, key.length )\n return\n }\n\n case 'call': visit( n.callee, locals ); n.args.forEach( a => visit( a, locals ) ); return\n case 'unary': visit( n.arg, locals ); return\n case 'update': visit( n.arg, locals, true ); return\n case 'bin': case 'logic': visit( n.l, locals ); visit( n.r, locals ); return\n case 'cond': visit( n.test, locals ); visit( n.cons, locals ); visit( n.alt, locals ); return\n case 'assign': visit( n.target, locals, true ); visit( n.value, locals ); return\n case 'arrow': visit( n.body, new Set([ ...locals, ...n.params ]) ); return\n case 'arr': n.items.forEach( i => visit( i.value, locals ) ); return\n case 'obj':\n for( const p of n.props ){\n p.key !== undefined && refuse( policy.member( p.key, true ), p.at, p.key.length )\n visit( p.value, locals )\n }\n }\n }\n\n visit( ast, NONE )\n return ok\n}\n\n/**\n * The compile-time half: a `CompileOptions.check` that holds a parsed\n * template (and its macros) to `policy`. Every refusal is reported where\n * it is written; the refused element or attribute is removed, a refused\n * expression becomes `undefined`.\n *\n * compileTemplate( src, { check: checkTemplate( untrustedPolicy ) } )\n */\nexport function checkTemplate( policy: TemplatePolicy = untrustedPolicy ): Check {\n return ( nodes, diagnostics, src ) => {\n /**\n * Every name the template declares anywhere — iterator and arm\n * arguments, macro argv, let/const. Coarser than the runtime's scope,\n * on purpose: this only decides what to REPORT, and a name declared\n * somewhere else resolves to nothing, never to something of the page.\n */\n const declared = new Set<string>()\n\n const\n report = ( r: Refusal, offset: number, length = 1 ) =>\n diagnostics.push({ ...r, severity: 'error', loc: locOf( src, offset, length ) }),\n /** Where an expression's own text starts — attribute and slot locations start earlier */\n find = ( text: string, from: number ) => {\n const i = src.indexOf( text, from )\n return i < 0 ? from : i\n },\n expr = ( source: string, from: number, handler = false ) =>\n checkExpression( policy, source, declared, ( r, at, length ) => report( r, from + at, length ), handler ),\n /** `on-x( name, …args )` and `<log( … )>`: comma-separated expressions */\n instruction = ( source: string, from: number, handler = true ) => {\n let ok = true, at = 0\n splitTopLevel( source ).forEach( ( seg, i ) => {\n at = source.indexOf( seg, at )\n ok = expr( seg, from + at, handler && i === 0 ) && ok\n at += seg.length\n })\n return ok\n },\n slots = ( parts: ( string | ExprSlot )[] ) => {\n for( const p of parts )\n if( typeof p !== 'string' && !expr( p.expr, find( p.expr, p.loc.offset ) ) ) p.expr = 'undefined'\n },\n /** An HTML tag is an element; anything else is a component */\n kind = ( tag: string ) => HTML_TAGS.has( tag ) ? policy.tag( tag ) : policy.component( tag )\n\n const collect = ( list: TemplateNode[] ) => {\n for( const n of list ){\n if( n.t === 'fragment' ) collect( n.children )\n if( n.t !== 'element' ) continue\n\n for( const a of n.attrs )\n a.k === 'args' ? a.names.forEach( x => declared.add( x ) )\n : ( n.tag === 'let' || n.tag === 'const' ) && 'name' in a && declared.add( a.name )\n collect( n.children )\n }\n }\n\n /** False drops the attribute */\n const attr = ( a: AttrNode, tag: string | null ): boolean => {\n const from = a.loc.offset\n\n switch( a.k ){\n case 'args': return true\n case 'event': return instruction( a.source, find( a.source, from ) )\n case 'spread': case 'fn': return expr( a.source, find( a.source, from ) )\n }\n\n // On an element the attribute reaches the page. `@text` / `@format` / `i18n` are not attributes.\n if( tag && !/^(@(?!html$)|i18n(-|$))/.test( a.name ) ){\n const r = policy.attr( tag, a.name, a.k === 'literal' ? a.value : a.k === 'bool' ? '' : undefined )\n if( r ){\n report( r, from, a.name.length )\n return false\n }\n }\n\n // `@format=\"reference, { params }\"` — only the params are an expression\n if( a.name === '@format' ){\n const raw = a.k === 'literal' ? a.value\n : a.k === 'expr' ? a.source\n : a.k === 'interp' ? a.parts.map( p => typeof p === 'string' ? p : `{${p.expr}}` ).join('')\n : ''\n const params = raw.slice( raw.indexOf(',') + 1 ).trim()\n return !raw.includes(',') || expr( params, find( params, from ) )\n }\n\n if( a.k === 'expr' && !expr( a.source, find( a.source, from ) ) ) a.source = 'undefined'\n if( a.k === 'interp' ) slots( a.parts )\n return true\n }\n\n /** False drops the element and everything in it */\n const element = ( n: ElementNode ): boolean => {\n const { tag } = n\n\n if( tag === '#dynamic' ){\n const d = n.dynamicTag!, from = find( d.expr, d.loc.offset )\n\n if( !expr( d.expr, from ) ) d.expr = 'undefined'\n else {\n const { ast } = parseExpression( d.expr )\n const r = ast.t === 'lit' && typeof ast.v === 'string' ? kind( ast.v.toLowerCase() ) : undefined\n if( r ){\n report( r, from, d.expr.length )\n return false\n }\n }\n }\n else if( !SYNTAX.has( tag ) ){\n const r = kind( tag )\n if( r ){\n report( r, n.loc.offset, tag.length + 1 )\n return false\n }\n }\n\n if( n.head ){\n const h = n.head, from = find( h.expr, h.loc.offset )\n ;( tag === 'log' ? instruction( h.expr, from, false ) : expr( h.expr, from ) ) || ( h.expr = 'undefined' )\n }\n\n const html = HTML_TAGS.has( tag ) ? tag : null\n n.attrs = n.attrs.filter( a => attr( a, html ) )\n return true\n }\n\n const walk = ( list: TemplateNode[] ) => {\n for( let i = 0; i < list.length; i++ ){\n const n = list[ i ]\n\n if( n.t === 'fragment' ) walk( n.children )\n else if( n.t === 'interp' ) slots( n.parts )\n else if( n.t === 'element' )\n element( n ) ? walk( n.children ) : list.splice( i--, 1 )\n }\n }\n\n collect( nodes )\n walk( nodes )\n }\n}\n\n// ---------------------------------------------------------------- runtime\nconst fault = ( r: Refusal ) => Object.assign( new Error( r.message ), { name: 'PolicyError' }, r )\n\ntype Frame = Record<string, any>\n\nconst OPS: Record<string, ( l: any, r: any ) => any> = {\n '+': ( l, r ) => l + r, '-': ( l, r ) => l - r, '*': ( l, r ) => l * r,\n '/': ( l, r ) => l / r, '%': ( l, r ) => l % r,\n '<': ( l, r ) => l < r, '>': ( l, r ) => l > r, '<=': ( l, r ) => l <= r, '>=': ( l, r ) => l >= r,\n // eslint-disable-next-line eqeqeq\n '==': ( l, r ) => l == r, '!=': ( l, r ) => l != r,\n '===': ( l, r ) => l === r, '!==': ( l, r ) => l !== r\n}\n\n/**\n * The guarded evaluator. Same AST and same semantics as\n * `interpretExpression`, which it deliberately does not share: the trusted\n * walker stays as fast as it was, and this one stays small enough to read\n * in one sitting.\n *\n * Every value becomes visible to a template in one of four ways — a name,\n * a member read, a call's result, an arrow's argument — and each goes\n * through `policy.value`. Every member, read or written, goes through\n * `policy.member` (or `policy.self`). Refusals throw: an expression that\n * cannot finish must not finish with something else.\n */\nfunction evaluator( policy: TemplatePolicy ){\n const\n refuse = ( r: Verdict ) => { if( r ) throw fault( r ) },\n hold = <T>( v: T ): T => ( refuse( policy.value( v ) ), v ),\n keyOf = ( k: unknown ): string => {\n if( typeof k === 'string' ) return k\n if( typeof k === 'number' ) return String( k )\n throw fault( no( 'LIPS-U002', 'A computed member must be a string or a number' ) )\n },\n reach = ( obj: any, key: string, write: boolean ) =>\n refuse( obj != null && typeof obj === 'object' && obj[ SELF ] ? policy.self( key, write ) : policy.member( key, write, obj ) )\n\n return ( ast: Expr, env: ExprEnv ) => {\n const scope = env.scope\n\n const name = ( id: string, frames: Frame[] ) => {\n for( const f of frames ) if( id in f ) return f[ id ]\n if( scope && id in scope ) return hold( scope[ id ] )\n\n switch( id ){\n case 'state': return env.state\n case 'input': return env.input\n case 'context': return env.context\n case 'static': return env.static\n case 'self': return env.self\n case 'arguments': return env.arguments\n }\n return own( policy.globals, id ) ? policy.globals[ id ] : undefined\n }\n\n const set = ( t: Expr, v: any, frames: Frame[] ) => {\n if( t.t === 'id' ){\n const f = frames.find( f => t.name in f ) ?? scope\n f && ( f[ t.name ] = v )\n }\n else if( t.t === 'member' ){\n const obj = ev( t.obj, frames )\n const key = keyOf( t.computed ? ev( t.prop as Expr, frames ) : t.prop )\n reach( obj, key, true )\n if( obj != null ) obj[ key ] = v\n }\n return v\n }\n\n const ev = ( n: Expr, frames: Frame[] ): any => {\n switch( n.t ){\n case 'lit': return n.v\n case 'id': return name( n.name, frames )\n\n case 'member': {\n const obj = ev( n.obj, frames )\n if( n.optional && obj == null ) return undefined\n const key = keyOf( n.computed ? ev( n.prop as Expr, frames ) : n.prop )\n reach( obj, key, false )\n return obj == null ? undefined : hold( obj[ key ] )\n }\n\n case 'call': {\n const c = n.callee\n let self: any, fn: any\n\n if( c.t === 'member' ){\n self = ev( c.obj, frames )\n if( ( c.optional || n.optional ) && self == null ) return undefined\n const key = keyOf( c.computed ? ev( c.prop as Expr, frames ) : c.prop )\n reach( self, key, false )\n fn = self == null ? undefined : hold( self[ key ] )\n }\n else fn = ev( c, frames )\n\n if( n.optional && fn == null ) return undefined\n return hold( Reflect.apply( fn, self, n.args.map( a => ev( a, frames ) ) ) )\n }\n\n case 'unary': {\n const v = ev( n.arg, frames )\n return n.op === '!' ? !v : n.op === '-' ? -v : +v\n }\n case 'update': {\n const cur = ev( n.arg, frames ), next = n.op === '++' ? cur + 1 : cur - 1\n set( n.arg, next, frames )\n return n.prefix ? next : cur\n }\n case 'bin': return OPS[ n.op ]( ev( n.l, frames ), ev( n.r, frames ) )\n case 'logic': {\n const l = ev( n.l, frames )\n return n.op === '&&' ? l && ev( n.r, frames ) : n.op === '||' ? l || ev( n.r, frames ) : l ?? ev( n.r, frames )\n }\n case 'cond': return ev( n.test, frames ) ? ev( n.cons, frames ) : ev( n.alt, frames )\n case 'assign':\n return set( n.target, n.op === '=' ? ev( n.value, frames ) : OPS[ n.op[ 0 ] ]( ev( n.target, frames ), ev( n.value, frames ) ), frames )\n\n case 'arrow':\n return ( ...args: any[] ) => {\n const f: Frame = Object.create( null )\n n.params.forEach( ( p, k ) => f[ p ] = hold( args[ k ] ) )\n return ev( n.body, [ f, ...frames ] )\n }\n\n case 'arr': {\n const out: any[] = []\n for( const i of n.items ) i.spread ? out.push( ...ev( i.value, frames ) ) : out.push( ev( i.value, frames ) )\n return out\n }\n case 'obj': {\n const out: Frame = {}\n const put = ( k: string, v: any ) => { reach( out, k, true ); out[ k ] = v }\n\n for( const p of n.props ){\n const v = ev( p.value, frames )\n if( !p.spread ) put( p.key!, v )\n else if( v != null ) for( const k of Object.keys( v ) ) put( k, hold( v[ k ] ) )\n }\n return out\n }\n }\n }\n\n return ev( ast, [] )\n }\n}\n\n/**\n * The DOM host, held to the policy at the one place where nothing gets\n * past: what reaches the page. Skeletons — from the compiler or from a\n * precompiled IR nobody checked — are swept once, when first parsed, in\n * the inert `<template>` they are parsed into; `@html` goes through the\n * same sweep; every attribute, element, style value and listener after\n * that is asked one at a time.\n *\n * It never throws: a render cannot be half-aborted. A refused write is\n * skipped and reported.\n */\nfunction guardHost( policy: TemplatePolicy, base: Host<Node> = domHost ): Host<Node> {\n const\n swept = new WeakMap<BlockIR, HTMLTemplateElement>(),\n refused = ( r: Verdict ) => ( r && policy.report( r ), !!r ),\n tagOf = ( el: Node ) => ( el as Element ).localName.toLowerCase(),\n /**\n * What a refused element becomes: an inert, hidden `<template>` that\n * keeps the children, so the skeleton's paths still resolve.\n */\n standIn = ( doc: Document, tag: string ) => {\n const t = doc.createElement('template')\n t.setAttribute( 'data-lips-refused', tag )\n return t\n }\n\n const sweep = ( root: DocumentFragment ) => {\n for( const el of [ ...root.querySelectorAll('*') ] ){\n const tag = tagOf( el )\n\n if( refused( policy.tag( tag ) ) ){\n const t = standIn( el.ownerDocument, tag )\n t.append( ...el.childNodes )\n el.replaceWith( t )\n continue\n }\n\n let shed = false\n for( const { name, value } of [ ...el.attributes ] )\n if( refused( policy.attr( tag, name, value ) ) ){\n el.removeAttribute( name )\n shed ||= name.toLowerCase() === 'is'\n }\n\n /**\n * `is` outlives its attribute: the element was parsed as the page's\n * custom element and upgrades on insertion. Only a new one sheds it.\n */\n if( shed ){\n const fresh = el.ownerDocument.createElementNS( el.namespaceURI, el.localName )\n for( const a of [ ...el.attributes ] ) fresh.setAttribute( a.name, a.value )\n fresh.append( ...el.childNodes )\n el.replaceWith( fresh )\n }\n }\n }\n\n const parse = ( markup: string ) => {\n const tpl = document.createElement('template')\n tpl.innerHTML = markup\n sweep( tpl.content )\n return tpl\n }\n\n return {\n ...base,\n\n clone( block ){\n let tpl = swept.get( block )\n if( !tpl ) swept.set( block, tpl = parse( block.html ) )\n return tpl.content.cloneNode( true )\n },\n\n element: tag => refused( policy.tag( tag.toLowerCase() ) ) ? standIn( document, tag ) : base.element( tag ),\n\n attr( el, name, value ){\n base.attr( el, name, value !== null && refused( policy.attr( tagOf( el ), name, value ) ) ? null : value )\n },\n\n html( el, value ){\n refused( policy.attr( tagOf( el ), '@html', value ) )\n ? base.content( el, '' )\n : ( el as Element ).replaceChildren( parse( value ).content )\n },\n\n styleVar( el, prop, value ){\n base.styleVar( el, prop, value !== null && refused( policy.css( value ) ) ? null : value )\n },\n\n /** Handlers see the policy's view of an event, never the event */\n listen: ( el, name, fn ) => base.listen( el, name, e => fn( policy.event( e ) ) )\n }\n}\n\n/** A refused component renders as this — nothing */\nconst NOTHING: IRComponentDef = { ir: { v: 1, exprs: [], root: { html: '', scope: [], binds: [], blocks: [] } } }\n\n/**\n * Everything an untrusted Lips instance runs with:\n *\n * new Lips({ untrusted: untrusted() })\n * new Lips({ untrusted: untrusted({ ...untrustedPolicy, url: sameOriginOnly }) })\n */\nexport function untrusted( policy: TemplatePolicy = untrustedPolicy ): Untrusted {\n const\n run = evaluator( policy ),\n asts = new Map<string, Expr>(),\n host = guardHost( policy ),\n /** Stylesheets this instance compiled from source and found clean: the only ones injected */\n sheets = new Set<string>()\n\n const guard: Guard = {\n run( src ){\n let ast = asts.get( src )\n if( !ast ) asts.set( src, ast = parseExpression( src ).ast )\n return env => run( ast!, env )\n },\n self: key => policy.self( key )\n }\n\n return {\n check: checkTemplate( policy ),\n\n style: compile => ( src, options ) => {\n const\n result = compile( src, {\n ...options,\n lint( text, value ){\n const r = value !== undefined ? policy.css( value ) : text[ 0 ] === '@' ? policy.css( text ) : undefined\n return r && [{ ...r, severity: 'error' }]\n }\n }),\n fail = ( r: Refusal, at: number, length: number ) =>\n result.diagnostics.push({ ...r, severity: 'error', loc: locOf( src, Math.max( at, 0 ), length ) })\n\n let clean = !result.diagnostics.some( d => d.code.startsWith('LIPS-U') )\n\n // Stylesheet expressions are held to the same rules, where they are written\n for( const e of result.ir.exprs ){\n const at = src.indexOf( e )\n clean = checkExpression( policy, e, NONE, ( r, a, length ) => fail( r, at + a, length ) ) && clean\n }\n\n // What the statement-by-statement lint cannot see (an `@import` at EOF with no `;`)\n const whole = clean ? policy.css( result.ir.css ) : undefined\n whole && fail( whole, 0, 0 )\n\n if( !clean || whole ) return { ...result, ir: { ...result.ir, css: '', binds: [], props: undefined } }\n\n sheets.add( result.ir.css )\n return result\n },\n\n runtime( options ){\n const { components, createStylesheet } = options\n\n return {\n ...options,\n guard,\n host,\n\n components: components && new Proxy( components, {\n get: ( target, name: string ) => refusedComponent( policy, name ) ? NOTHING : target[ name ]\n }),\n\n /**\n * A stylesheet reaches the page only if this instance compiled it\n * from source: a precompiled sheet — or one in a definition built\n * from data — is injected verbatim and was never scoped by Lips.\n */\n createStylesheet: createStylesheet && ( ( nsp, css ) => {\n if( sheets.has( css ) ) return createStylesheet( nsp, css )\n policy.report( no( 'LIPS-U042', `A stylesheet Lips did not compile cannot be checked — <${nsp}> ships unstyled`,\n 'Send the stylesheet source; precompiled sheets are trusted output' ) )\n return { clear(){} }\n })\n }\n }\n }\n}\n\nconst refusedComponent = ( policy: TemplatePolicy, name: string ) => {\n const r = typeof name === 'string' ? policy.component( name ) : undefined\n r && policy.report( r )\n return !!r\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"mappings": "AAqDA,IAAM,EAAS,CACb,MAAO,MAAO,MAAO,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KACrE,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KACpC,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IAAK,IACjE,IAAK,IAAK,IAAK,IAAK,GACtB,EAEA,SAAS,CAAQ,CAAE,EAAa,EAAyC,CACvE,IAAM,EAAkB,CAAC,EACrB,EAAI,EAEF,EAAY,CAAE,IAAe,aAAa,KAAM,CAAE,EAClD,EAAW,CAAE,IAAe,gBAAgB,KAAM,CAAE,EAE1D,MAAO,EAAI,EAAI,OAAQ,CACrB,IAAM,EAAI,EAAK,GAEf,GAAI,KAAK,KAAM,CAAE,EAAG,CAAE,IAAK,SAG3B,GAAI,QAAQ,KAAM,CAAE,GAAO,IAAM,KAAO,QAAQ,KAAM,EAAK,EAAI,EAAI,EAAK,CACtE,IAAM,EAAQ,EACd,MAAO,EAAI,EAAI,QAAU,QAAQ,KAAM,EAAK,EAAI,EAAI,IACpD,GAAI,EAAK,KAAQ,IAAK,CAAE,IAAK,MAAO,EAAI,EAAI,QAAU,QAAQ,KAAM,EAAK,EAAI,EAAI,IACjF,GAAI,EAAK,KAAQ,KAAO,EAAK,KAAQ,IAAK,CAExC,GADA,IACI,EAAK,KAAQ,KAAO,EAAK,KAAQ,IAAM,IAC3C,MAAO,EAAI,EAAI,QAAU,QAAQ,KAA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BAAkB,IAAsB,CAAE,EAAK,IAAS,CACtD,GAAI,EAAO,IAAK,CAAI,EAAI,OAAO,EAAkB,EAAK,CAAI,EAG1D,OAFA,EAAO,OAAQ,EAAI,YAAa,0DAA0D,oBACxF,mEAAoE,CAAE,EACjE,CAAE,KAAK,EAAE,EAAG,GAEvB,EAEJ,EAGF,IAAM,GAAmB,CAAE,EAAwB,IAAkB,CACnE,IAAM,EAAI,OAAO,IAAS,SAAW,EAAO,UAAW,CAAK,EAAI,OAEhE,OADA,GAAK,EAAO,OAAQ,CAAE,EACf,CAAC,CAAC",
|
|
11
|
+
"debugId": "DD4429B74F5A6C4F64756E2164756E21",
|
|
12
|
+
"names": []
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lipsjs/lips",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Fast, Lightweight Reactive UI Framework",
|
|
5
5
|
"main": "./dist/lips.min.js",
|
|
6
6
|
"types": "./dist/types/lips.d.ts",
|
|
@@ -18,11 +18,26 @@
|
|
|
18
18
|
"import": "./dist/lips.js",
|
|
19
19
|
"default": "./dist/lips.js"
|
|
20
20
|
},
|
|
21
|
+
"./stylis": {
|
|
22
|
+
"types": "./dist/types/stylis.d.ts",
|
|
23
|
+
"import": "./dist/stylis.min.js",
|
|
24
|
+
"default": "./dist/stylis.min.js"
|
|
25
|
+
},
|
|
21
26
|
"./runtime": {
|
|
22
27
|
"types": "./dist/types/runtime.d.ts",
|
|
23
28
|
"import": "./dist/runtime.min.js",
|
|
24
29
|
"default": "./dist/runtime.min.js"
|
|
25
30
|
},
|
|
31
|
+
"./i18n": {
|
|
32
|
+
"types": "./dist/types/mf2.d.ts",
|
|
33
|
+
"import": "./dist/mf2.min.js",
|
|
34
|
+
"default": "./dist/mf2.min.js"
|
|
35
|
+
},
|
|
36
|
+
"./untrusted": {
|
|
37
|
+
"types": "./dist/types/untrusted.d.ts",
|
|
38
|
+
"import": "./dist/untrusted.min.js",
|
|
39
|
+
"default": "./dist/untrusted.min.js"
|
|
40
|
+
},
|
|
26
41
|
"./precompile": {
|
|
27
42
|
"types": "./dist/types/precompile.d.ts",
|
|
28
43
|
"import": "./dist/precompile.min.js",
|
|
@@ -33,19 +48,21 @@
|
|
|
33
48
|
"private": false,
|
|
34
49
|
"scripts": {
|
|
35
50
|
"dev": "bun build --entrypoints ./src/lips.ts --entry-naming lips.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external --watch",
|
|
36
|
-
"build": "bun build --entrypoints ./src/lips.ts --entry-naming lips.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external && bun build --entrypoints ./src/lips.ts --entry-naming lips.[ext] --outdir ./dist --target browser --format esm --sourcemap=external && bun build --entrypoints ./src/runtime.ts --entry-naming runtime.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external && bun build --entrypoints ./src/precompile.ts --entry-naming precompile.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external",
|
|
51
|
+
"build": "bun build --entrypoints ./src/lips.ts --entry-naming lips.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external && bun build --entrypoints ./src/lips.ts --entry-naming lips.[ext] --outdir ./dist --target browser --format esm --sourcemap=external && bun build --entrypoints ./src/runtime.ts --entry-naming runtime.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external && bun build --entrypoints ./src/precompile.ts --entry-naming precompile.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external && bun build --entrypoints ./src/stylis.ts --entry-naming stylis.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external && bun build --entrypoints ./src/mf2.ts --entry-naming mf2.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external && bun build --entrypoints ./src/untrusted.ts --entry-naming untrusted.min.[ext] --minify --outdir ./dist --target browser --format esm --sourcemap=external",
|
|
37
52
|
"build:declaration": "tsc --project tsconfig.types.json",
|
|
38
53
|
"compile": "bun run build",
|
|
39
|
-
"typecheck": "tsc --
|
|
54
|
+
"typecheck": "tsc --project tsconfig.test.json",
|
|
40
55
|
"prepack": "bun run build && bun run build:declaration",
|
|
41
56
|
"test": "vitest run",
|
|
42
57
|
"test:watch": "vitest",
|
|
43
58
|
"size": "node scripts/size-check.mjs"
|
|
44
59
|
},
|
|
45
60
|
"dependencies": {
|
|
61
|
+
"messageformat": "^4.1.0",
|
|
46
62
|
"stylis": "^4.3.4"
|
|
47
63
|
},
|
|
48
64
|
"devDependencies": {
|
|
65
|
+
"@lynx-js/testing-environment": "0.3.4",
|
|
49
66
|
"@types/stylis": "^4.2.7",
|
|
50
67
|
"jsdom": "^29.1.1",
|
|
51
68
|
"typescript": "^5.7.3",
|