mutorjs 1.3.0 → 1.3.1

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/dist/index.js CHANGED
@@ -1,13 +1,1327 @@
1
- function J(e,n){return`${" ".repeat(e+n+1)}^`}var g=class e extends Error{constructor(t){super(t);this.name="MutorError";Object.setPrototypeOf(this,e.prototype)}},I=class e extends g{constructor(t,a,o,p,f){let m=a.toString().length+2,i=`${t}
2
-
3
- `;i+=`at ${f}:${a}:${p+1}
4
- `,a>1&&(i+=`${(a-1).toString().padStart(m-2)} | ...
5
- `),i+=`${a} | ${o}
6
- `,i+=J(p,m);super(i);this.name="MutorCompilerError";Object.setPrototypeOf(this,e.prototype)}};var X=new Set(["for","if","else","true","false","null","undefined","end","in","of"]),F=new Set(["::","||","??","&&","**","^","|","&","!","-","%","+","*","/",">","<",">=","<=","==","!=",">>","<<",".","?.","(",")","[","]",",",":","?"]);var k=new Set(["==","!="]),q=new Set([">","<",">=","<="]);var ee=new Set(["+","-"]),te=new Set(["*","/","%"]),re=new Set([".","?.","[","::"]),ne=new Set(["-","+","!"]),oe={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},P={build:{include:new Set([".html",".txt"]),exclude:new Set(["node_modules",".git"])},autoEscape:!0,allowedProps:new Set,forbiddenProps:new Set(["__proto__","constructor","prototype"]),allowFnCalls:!1,delimiters:{closingTag:"}}",openingTag:"{{",openingTagEscape:"\\",whitespaceTrim:"~",commentTag:"#"},keepOpeningTagEscapeDelimiter:!1,cache:{active:!0,maxSize:50*1024*1024}},se={JSON:{stringify(e){try{return JSON.stringify(e)}catch{throw new g("JSON.stringify failed: invalid value")}},parse(e){if(typeof e!="string")throw new g("JSON.parse expects a string");try{return JSON.parse(e)}catch{throw new g("JSON.parse failed: invalid JSON string")}}},Object:{keys(e){if(!e||typeof e!="object")throw new g("Object.keys expects an object");return Object.keys(e)},values(e){if(!e||typeof e!="object")throw new g("Object.values expects an object");return Object.values(e)},entries(e){if(!e||typeof e!="object")throw new g("Object.entries expects an object");return Object.entries(e)},hasOwn(e,n){if(!e||typeof e!="object")throw new g("Object.hasOwn expects an object");return Object.hasOwn(e,n)},freeze(e){if(!e||typeof e!="object")throw new g("Object.freeze expects an object");return Object.freeze(e)},seal(e){if(!e||typeof e!="object")throw new g("Object.seal expects an object");return Object.seal(e)},fromEntries(e){if(!Array.isArray(e))throw new g("Object.fromEntries expects an array");return Object.fromEntries(e)}},Array:{isArray(e){return Array.isArray(e)},from(e){return Array.from(e)}},Number:{isFinite(e){return Number.isFinite(e)},isNaN(e){return Number.isNaN(e)},parseInt(e,n=10){return Number.parseInt(e,n)},parseFloat(e){return Number.parseFloat(e)}},String:{fromCharCode(...e){return String.fromCharCode(...e)}},Math:{abs(e){return Math.abs(e)},floor(e){return Math.floor(e)},ceil(e){return Math.ceil(e)},round(e){return Math.round(e)},max(...e){return Math.max(...e)},min(...e){return Math.min(...e)},random(){return Math.random()}},Date:{now(){return Date.now()},parse(e){if(typeof e!="string")throw new g("Date.parse expects a string");return Date.parse(e)}},Boolean:{valueOf(e){return!!e}}};function W(e){return typeof e!="string"?e:/[&<>"']/.test(e)?e.replace(/[&<>"']/g,n=>oe[n]):e}function Y(e,n,t){if(t.has(e)&&!n.has(e))throw new g(`Forbidden property access. Access to this computed property "${e}" is forbidden.`);return e}var D="object",ie=Symbol("__mutor_safe_context");function G(e){if(!e||typeof e!==D||ie in e)return e;let n=new WeakSet;function t(o,p=""){if(!o||typeof o!==D||n.has(o))return o;n.add(o);let f=Object.getPrototypeOf(o);if(f&&f!==Object.prototype&&f!==Array.prototype)throw new g(`Unsafe prototype detected at ${p||"root"}`);if(Array.isArray(o)){for(let i=0;i<o.length;i++)o[i]=t(o[i],`${p}[${i}]`);return o}if(o instanceof Map){for(let[i,u]of o.entries())typeof i===D&&t(i,`${p}.mapKey`),o.set(i,t(u,`${p}.mapValue`));return o}if(o instanceof Set){let i=new Set;for(let u of o.values())i.add(t(u,p));o.clear();for(let u of i)o.add(u);return o}let m=Object.getOwnPropertyDescriptors(o);for(let i of Object.keys(m)){let u=m[i];if(u.get||u.set)throw new g(`Getter/setter not allowed: ${p}.${i}`);let E=o[i];E&&typeof E===D&&(o[i]=t(E,`${p}.${i}`))}return o}let a=t(e);return a&&typeof a===D&&Object.defineProperty(a,ie,{value:!0,enumerable:!1,writable:!1,configurable:!1}),a}function j(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$")}function L(e,n){let a=e.slice(0,n).split(`
7
- `).length,o=e.lastIndexOf(`
8
- `,n-1)+1;return{line:a,lineIndex:o}}function B(e,n,t){let a=e.indexOf(`
9
- `,n);return{line:e.slice(n,a===-1?void 0:a),pos:t-n}}function M(e,n){let{scope:t,forbiddenProps:a,allowedProps:o}=n;function p(s){return t.includes(s)?s:`ctx.${s}`}function f(s){switch(s.type){case 17:return"}";case 5:return s.value;case 4:return`\`${/\$/.test(s.value)?s.value.replaceAll("$","\\$"):s.value}\``;case 10:return s.true?"true":"false";case 12:return"null";case 11:return"undefined";case 7:return p(s.value);case 9:return`(${f(s.expr)})`;case 2:return`${s.operator}${f(s.expr)}`;case 0:return`${f(s.left)} ${s.operator} ${f(s.right)}`;case 1:return`${f(s.condition)} ? ${f(s.left)} : ${f(s.right)}`;case 8:return i(s);case 3:return u(s);case 6:return m(s);case 13:return E(s);case 16:return"} else {";case 14:return _(s);case 15:return b(s);default:throw new g(`Unsupported expression type: ${s.type}`)}}function m(s){if(s.left.type!==7)throw{message:"Invalid usage of namespace operator.",pos:s.pos};return`namespaces.${s.left.value}.${s.right.value}`}function i(s){let O=f(s.left);if(s.bracketNotation){let h=f(s.right),y=s.optional?"?.":"";return s.right.type===4||s.right.type===5?`${O}${y}[${h}]`:`${O}${y}[validateComputedProps(${h}, allowedProps, forbiddenProps)]`}else{let h=s.right.value,y=s.optional?"?.":".";if(a.has(h)&&!o.has(h))throw{message:"Forbidden property access.",pos:s.right.pos};return`${O}${y}${h}`}}function u(s){let O=f(s.expr),h=s.optional?"?.":"",y=s.args.map(N=>f(N)).join(", ");return`${O}${h}(${y})`}function E(s){let{iterable:O,loopType:h,variable:y}=s;return`for(const ${y} ${h===1?"in":"of"} ${M(O,n)}){`}function _(s){let{condition:O}=s;return`if(${M(O,n)}){`}function b(s){let{condition:O}=s;return`}else if(${M(O,n)}){`}return f(e)}function U(e){switch(e){case 0:return"identifier";case 1:return"keyword";case 2:return"number";case 4:return"operator";case 3:return"string"}}function Z(e,n){let t=0,a=!1;function o(r,c){let l=e[t],C=e[e.length-1];if(!l)throw{message:`Unexpected end of expression. Expected ${c?`'${c}'`:`${r===0?"an":"a"} ${U(r)}`}.`,pos:C.pos+C.value.length-1};if(l.type!==r)throw{message:`Unexpected token type. Expected ${c?`'${c}'`:U(r)} but got ${U(l.type)} instead.`,pos:l.pos};if(c!==void 0&&l.value!==c)throw{message:`Unexpected token '${l?.value}'. Expected ${r===0?"an":"a"} ${U(r)} instead.`,pos:l.pos};return e[t++]}function p(){let r=e[t-1].pos,c=o(0).value,l;try{l=o(1,"in")}catch{l=o(1,"of")}let C=l.value==="in"?1:0,$=w();return{type:13,loopType:C,iterable:$,variable:c,pos:r}}function f(){let r=w();return{condition:r,pos:r.pos,type:14}}function m(){let r=e[t-1].pos;try{return o(1,"if"),{...f(),type:15,pos:r}}catch{return{type:16,pos:r}}}function i(){let r=[];if(e[t]?.type===4&&e[t]?.value===")")return r;for(r.push(w());e[t]?.type===4&&e[t]?.value===","&&e[t]?.value!==")";)t++,r.push(w());return r}function u(){let r=e[t++];if(r?.type===2)return{type:5,value:r.value,pos:r.pos};if(r?.type===3)return{type:4,value:r.value,pos:r.pos};if(r?.type===1){if(r.value==="for"&&t===1)return p();if(r.value==="true"||r.value==="false")return{type:10,true:r.value==="true",pos:r.pos};if(r.value==="undefined")return{type:11,pos:r.pos};if(r.value==="null")return{type:12,pos:r.pos};if(r.value==="end"&&e.length===1)return{type:17,pos:r.pos};if(r.value==="if"&&t===1)return f();if(r.value==="else"&&t===1)return m()}if(r?.type===0)return{type:7,value:r.value,pos:r.pos};if(r?.type===4&&r.value==="("){let c=w();return o(4,")"),{type:9,expr:c,pos:r.pos}}if(r?.type===4&&ne.has(r.value)){let c=r.value,l=w();return{type:2,operator:c,expr:l,pos:r.pos}}throw t>e.length?{message:"Unexpected end of expression.",pos:e[e.length-1].pos}:{message:`Unexpected token '${r?.value}'.`,pos:r.pos}}function E(){let r=u();for(;e[t];){let c=e[t];if(c?.type===4&&c?.value==="("){if(t++,!a&&!n.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let l=i();o(4,")"),r={type:3,expr:r,args:l,pos:e[t-1].pos}}else if(c?.type===4&&c?.value==="?."&&e[t+1]?.type===4&&e[t+1]?.value==="("){if(t++,t++,!a&&!n.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let l=i();o(4,")"),r={type:3,expr:r,args:l,optional:!0,pos:e[t-1].pos}}else if(c?.type===4&&re.has(c?.value)){let l=c?.value==="::",C=c?.value==="[",$=c?.value==="?.";if(t++,l&&(e[t-2]?.type!==0||e[t]?.type!==0))throw{message:`Invalid namespaces access. Expected syntax <IDENTIFIER>::<IDENTIFIER>, but got '${e[t-2]?.value}::${e[t]?.value}' instead.`,pos:e[t]?.pos};if(l){a=!0;let R=u();r={type:6,left:r,right:R,pos:e[t-1].pos}}else if(C){let R=w();o(4,"]"),r={type:8,right:R,left:r,bracketNotation:!0,pos:e[t-1].pos}}else if($)if(e[t]?.type===4&&e[t]?.value==="["){t++;let R=w();o(4,"]"),r={type:8,left:r,right:R,bracketNotation:!0,optional:!0,pos:e[t-1].pos}}else{let R=u();r={type:8,left:r,right:R,optional:!0,pos:e[t-1].pos}}else{let R=u();r={type:8,left:r,right:R,pos:e[t-1].pos}}}else break}return a=!1,r}function _(){let r=E();for(;e[t]?.type===4&&te.has(e[t]?.value);){let c=e[t++].value,l=E();r={type:0,left:r,right:l,operator:c,pos:e[t-1].pos}}return r}function b(){let r=_();for(;e[t]?.type===4&&ee.has(e[t]?.value);){let c=e[t++].value,l=_();r={type:0,left:r,right:l,operator:c,pos:e[t-1].pos}}return r}function s(){let r=b();for(;e[t]?.type===4&&q.has(e[t]?.value);){let c=e[t++].value,l=b();r={type:0,left:r,right:l,operator:c,pos:e[t-1].pos}}return r}function O(){let r=s();for(;e[t]?.type===4&&q.has(e[t]?.value);){let c=e[t++].value,l=s();r={type:0,left:r,right:l,operator:c,pos:e[t-1].pos}}return r}function h(){let r=O();for(;e[t]?.type===4&&k.has(e[t]?.value);){let c=e[t++].value,l=O();r={type:0,left:r,right:l,operator:c,pos:e[t-1].pos}}return r}function y(){let r=N();for(;e[t]?.type===4&&e[t]?.value==="||";){let c=e[t++].value,l=N();r={type:0,left:r,right:l,operator:c,pos:e[t-1].pos}}return r}function N(){let r=T();for(;e[t]?.type===4&&e[t]?.value==="&&";){let c=e[t++].value,l=T();r={type:0,left:r,right:l,operator:c,pos:e[t-1].pos}}return r}function T(){let r=h();for(;e[t]?.type===4&&e[t]?.value==="??";){let c=e[t++].value,l=h();r={type:0,left:r,right:l,operator:c,pos:e[t-1].pos}}return r}function w(){let r=y();if(e[t]?.type!==4||e[t]?.value!=="?")return r;t++;let c=w();o(4,":");let l=w();return{type:1,left:c,right:l,condition:r,pos:e[t-1].pos}}return w()}function V(e,{delimiters:n}){let t=`${n.openingTag}${n.whitespaceTrim}`,a=`${n.whitespaceTrim}${n.closingTag}`,o=e.startsWith(t),p=e.endsWith(a),f=e.startsWith(o?t+n.commentTag:n.openingTag+n.commentTag);if(f)return{isComment:f,leftTrim:o,rightTrim:p};let m=e.slice(o?t.length:n.openingTag.length,e.length-(p?a.length:n.closingTag.length)),i=m.trim(),u=i.startsWith("for")||i.startsWith("if")||i.startsWith("else"),E=i.startsWith("for")||i.startsWith("if"),_=i==="end",b=i.startsWith("for");return{leftTrim:o,rightTrim:p,inner:m,isBlock:u,isBlockEnd:_,hasContext:b,requiresBlockClose:E}}function H(e){let n=0,t="",a=[];function o(){let i="";if(/[a-zA-Z$_]/.test(t)){let u=n;for(;/[a-zA-Z$_0-9]/.test(e[u])&&u<e.length;)i+=e[u],u++;a.push({type:X.has(i)?1:0,value:i,pos:n}),n=u,t=e[n]}}function p(){let i="";if(t==='"'||t==="'"||t==="`"){let u=n+1;for(;e[u]!==t&&u<e.length;)i+=e[u],u++;if(u>e.length)throw{pos:n,message:"Found string without closing quote."};a.push({type:3,value:i,pos:n}),n=u}}function f(){if(/[0-9]/.test(t)){let i=n,u="";for(;/[0-9.oxe]/.test(e[i])&&i<e.length;)u+=e[i],i++;let E=Number(u);if(Number.isNaN(E))throw{pos:n,message:"Found invalid number literal."};a.push({type:2,value:`${E}`,pos:n}),n=i-1,t=e[n]}}function m(){let i=`${t}${e[n+1]}`;if(F.has(i)){a.push({type:4,value:i,pos:n}),n++;return}if(F.has(t)){a.push({type:4,value:t,pos:n});return}}for(;n<e.length;){if(t=e[n],f(),o(),p(),m(),!/[a-zA-Z$_0-9\s\t\r\n'"`]/.test(t)&&!F.has(t)&&!F.has(e[n-1]+t))throw{message:`Unexpected token '${t}' in expression.`,pos:n};n++}return a}function Q(e,n,t){let a=[],o=[],{delimiters:p,keepOpeningTagEscapeDelimiter:f,allowFnCalls:m,allowedProps:i,forbiddenProps:u,autoEscape:E}=n,_=!1,b=0,s='let acc="";';for(;b<e.length;){let y=function(){let d=h,S=0;for(;d>=p.openingTagEscape.length&&e.slice(d-p.openingTagEscape.length,d)===p.openingTagEscape;)S++,d-=p.openingTagEscape.length;return S%2===1};var O=y;let h=e.indexOf(p.openingTag,b);if(h===-1){let d=e.slice(b);_&&(d=d.trimStart()),d&&(s+=`acc+=\`${j(d)}\`;`);break}if(y()){let d=e.slice(b,f?h+p.openingTagEscape.length+1:h-p.openingTag.length+1);_&&(d=d.trimStart(),_=!1),s+=`acc+=\`${j(d)}\`;`,f||(s+=`acc+=\`${p.openingTag}\`;`),b=h+p.openingTag.length;continue}let N=e.indexOf(p.closingTag,h);if(N===-1){let{line:d,lineIndex:S}=L(e,h),{line:A,pos:v}=B(e,S,h);throw new I("No closing tag found.",d,A,v,t.path)}let T=e.slice(h,N+p.closingTag.length),{inner:w,leftTrim:K,rightTrim:r,isBlock:c,isBlockEnd:l,hasContext:C,requiresBlockClose:$,isComment:R}=V(T,{delimiters:p}),x=e.slice(b,h);x&&(_&&(x=x.trimStart()),K&&(x=x.trimEnd()),x&&(s+=`acc+=\`${j(x)}\`;`)),_=!1,b=N+p.closingTag.length;try{if(!R){let d=H(w),S=Z(d,{allowFnCalls:m});if(c&&$&&C?(a.push(S.variable),o.push({type:0,pos:h})):c&&$&&!C&&o.push({type:1,pos:h}),l){let v=o.pop();if(v?.type===0&&a.pop(),v===void 0)throw{message:"Unexpected end of block",pos:h}}let A=M(S,{allowedProps:i,forbiddenProps:u,scope:a});c||l?s+=A:s+=E&&!A.startsWith("namespaces.Mutor.include")?`acc+=escapeFn(${A});`:`acc+=${A};`}r&&(_=!0)}catch(d){let{message:S,pos:A}=d,{line:v,lineIndex:ce}=L(e,h),{line:pe,pos:le}=B(e,ce,h);throw new I(S,v,pe,le+A+(K?p.openingTag.length+p.whitespaceTrim.length:p.openingTag.length),t.path)}}if(o.length){let h=o.pop()?.pos,{line:y,lineIndex:N}=L(e,h),{line:T,pos:w}=B(e,N,h);throw new I("Unclosed block detected.",y,T,w+p.openingTag.length,t.path)}return s+="return acc;",new Function("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",s)}var z=class{constructor(n={}){this.__currentRenderedPath="";this.__includeStack=new Set;this.__cacheSize=0;this.__config={...P};this.__compiledTemplatesMap=new Map;this.__currentContext=null;this.__namespaces={...se,Mutor:{include:(n,t)=>{if(this.__includeStack.has(n))throw new g(`Circular include detected:
10
- ${Array.from(this.__includeStack).join(`
11
- `)}
12
- ${n}`);try{return this.__includeStack.add(n),this.renderComponent(n,t??this.__currentContext)}finally{this.__includeStack.delete(n)}}}};this.addConfig(n),Object.defineProperty(this.__namespaces.Mutor,"$$context",{get:()=>this.__currentContext})}addConfig(n){let{autoEscape:t,delimiters:a,allowedProps:o,forbiddenProps:p,keepOpeningTagEscapeDelimiter:f,allowFnCalls:m,cache:i,build:u}=n;return this.__config={build:{include:new Set([...u?.include||P.build.include]),exclude:new Set([...P.build.exclude,...u?.exclude||[]])},autoEscape:t===!0?!0:t!==!1,allowedProps:o||P.allowedProps,allowFnCalls:!!m,cache:{...P.cache,...i||{}},forbiddenProps:new Set([...P.forbiddenProps,...p||[]]),keepOpeningTagEscapeDelimiter:f===!0?!0:f!==!1,delimiters:{...P.delimiters,...a||{}}},this.__config}restoreDefaultConfig(){this.__config={...P}}compile(n){return Q(n,this.__config,{path:this.__currentRenderedPath||"anonymous"})}render(n,t){let a=this.__currentContext;a!==t&&(this.__currentContext=t);let o=this.compile(n)(G(t),this.__namespaces,this.__config.allowedProps,this.__config.forbiddenProps,W,Y);return this.__currentContext=a,o}renderComponent(n,t){if(!this.__compiledTemplatesMap.has(n))throw new g(`No template exists with the identifier '${n}'`);let a=this.__currentRenderedPath,o=this.__currentContext,p=this.__compiledTemplatesMap.get(n);this.__currentContext=t,this.__currentRenderedPath=n;let f=p.fn(G(t),this.__namespaces,this.__config.allowedProps,this.__config.forbiddenProps,W,Y);return this.__currentContext=o,this.__currentRenderedPath=a,f}registerComponent(n,t){let a=t.length*2+500;if(this.__cacheSize+a>this.__config.cache.maxSize&&!this.createEntrySpaceForTemplate(a))throw new g(`The template for the component '${n}' is too large. Consider increasing 'cache.maxSize' in the config`);this.__cacheSize+=t.length*2+500,this.__compiledTemplatesMap.set(n,{fn:this.compile(t),size:a})}reset(){this.__config={...P},this.__compiledTemplatesMap.clear(),this.__currentContext=null,this.__cacheSize=0}createEntrySpaceForTemplate(n){if(this.__cacheSize+n<this.__config.cache.maxSize)return!0;if(n>this.__config.cache.maxSize)return!1;let t=this.__compiledTemplatesMap.entries().next().value;if(t){let[a,o]=t;this.__compiledTemplatesMap.delete(a),this.__cacheSize-=o.size}return this.createEntrySpaceForTemplate(n)}getDiagnostics(){let n=this.__config.cache.maxSize;return{bytesUsed:this.__cacheSize,bytesMax:n,readableUsed:`${(this.__cacheSize/1024/1024).toFixed(2)} MB`,readableMax:`${(n/1024/1024).toFixed(2)} MB`,totalEntries:this.__compiledTemplatesMap.size,percentFull:n>0?Math.min(100,Math.round(this.__cacheSize/n*100)):0,avgTemplateSize:this.__compiledTemplatesMap.size>0?Math.round(this.__cacheSize/this.__compiledTemplatesMap.size):0}}};var it=z;export{it as default};
1
+ // src/utils/construct-pointer.ts
2
+ function constructPointer(pos, offset) {
3
+ return `${" ".repeat(pos + offset + 1)}^`;
4
+ }
5
+
6
+ // src/core/error.ts
7
+ var MutorError = class _MutorError extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = "MutorError";
11
+ Object.setPrototypeOf(this, _MutorError.prototype);
12
+ }
13
+ };
14
+ var MutorCompilerError = class _MutorCompilerError extends MutorError {
15
+ constructor(message, line, lineText, column, file) {
16
+ const gutterWidth = line.toString().length + 2;
17
+ let report = `${message}
18
+
19
+ `;
20
+ report += `at ${file}:${line}:${column + 1}
21
+ `;
22
+ if (line > 1) {
23
+ report += `${(line - 1).toString().padStart(gutterWidth - 2)} | ...
24
+ `;
25
+ }
26
+ report += `${line} | ${lineText}
27
+ `;
28
+ report += constructPointer(column, gutterWidth);
29
+ super(report);
30
+ this.name = "MutorCompilerError";
31
+ Object.setPrototypeOf(this, _MutorCompilerError.prototype);
32
+ }
33
+ };
34
+
35
+ // src/core/constants.ts
36
+ var keywords = /* @__PURE__ */ new Set([
37
+ "for",
38
+ "if",
39
+ "else",
40
+ "true",
41
+ "false",
42
+ "null",
43
+ "undefined",
44
+ "end",
45
+ "in",
46
+ "of"
47
+ ]);
48
+ var operators = /* @__PURE__ */ new Set([
49
+ "::",
50
+ // Namespace access
51
+ "||",
52
+ // Or
53
+ "??",
54
+ // Nullish coalesce
55
+ "&&",
56
+ // And
57
+ "**",
58
+ // Power
59
+ "^",
60
+ // Bitwise XOr
61
+ "|",
62
+ // Bitwise Or
63
+ "&",
64
+ // Bitwise And
65
+ "!",
66
+ // Not
67
+ "-",
68
+ // Minus
69
+ "%",
70
+ // Modulus
71
+ "+",
72
+ // Plus
73
+ "*",
74
+ // Times
75
+ "/",
76
+ // Divide
77
+ ">",
78
+ // Greater than
79
+ "<",
80
+ // Less than
81
+ ">=",
82
+ // Greater or equal
83
+ "<=",
84
+ // Less or equal
85
+ "==",
86
+ // Strict equal
87
+ "!=",
88
+ // Strict not equal
89
+ ">>",
90
+ // Bitwise right shift
91
+ "<<",
92
+ // Bitwise left shift
93
+ ".",
94
+ // Property acess
95
+ "?.",
96
+ // Optional property access
97
+ "(",
98
+ // Open parentheses
99
+ ")",
100
+ // Close parentheses
101
+ "[",
102
+ // Square open parentheses
103
+ "]",
104
+ // Square close parentheses
105
+ ",",
106
+ // Comma
107
+ ":",
108
+ // Column
109
+ "?"
110
+ // Ternary operator
111
+ ]);
112
+ var equalityOperators = /* @__PURE__ */ new Set(["==", "!="]);
113
+ var comparisonOperators = /* @__PURE__ */ new Set([">", "<", ">=", "<="]);
114
+ var additiveOperators = /* @__PURE__ */ new Set(["+", "-"]);
115
+ var multiplicativeOperators = /* @__PURE__ */ new Set(["*", "/", "%"]);
116
+ var propertyAccessOperators = /* @__PURE__ */ new Set([".", "?.", "[", "::"]);
117
+ var unaryOperators = /* @__PURE__ */ new Set(["-", "+", "!"]);
118
+ var ESCAPE_MAP = {
119
+ "&": "&amp;",
120
+ "<": "&lt;",
121
+ ">": "&gt;",
122
+ '"': "&quot;",
123
+ "'": "&#39;"
124
+ };
125
+ var defaultConfig = {
126
+ build: {
127
+ include: /* @__PURE__ */ new Set([".html", ".txt"]),
128
+ exclude: /* @__PURE__ */ new Set(["node_modules", ".git"])
129
+ },
130
+ autoEscape: true,
131
+ allowedProps: /* @__PURE__ */ new Set(),
132
+ forbiddenProps: /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]),
133
+ allowFnCalls: false,
134
+ delimiters: {
135
+ closingTag: "}}",
136
+ openingTag: "{{",
137
+ openingTagEscape: "\\",
138
+ whitespaceTrim: "~",
139
+ commentTag: "#"
140
+ },
141
+ keepOpeningTagEscapeDelimiter: false,
142
+ cache: {
143
+ active: true,
144
+ maxSize: 50 * 1024 * 1024
145
+ // 50MB
146
+ }
147
+ };
148
+ var namespaces = {
149
+ JSON: {
150
+ stringify(value) {
151
+ try {
152
+ return JSON.stringify(value);
153
+ } catch {
154
+ throw new MutorError("JSON.stringify failed: invalid value");
155
+ }
156
+ },
157
+ parse(str) {
158
+ if (typeof str !== "string") {
159
+ throw new MutorError("JSON.parse expects a string");
160
+ }
161
+ try {
162
+ return JSON.parse(str);
163
+ } catch {
164
+ throw new MutorError("JSON.parse failed: invalid JSON string");
165
+ }
166
+ }
167
+ },
168
+ Object: {
169
+ keys(obj) {
170
+ if (!obj || typeof obj !== "object") {
171
+ throw new MutorError("Object.keys expects an object");
172
+ }
173
+ return Object.keys(obj);
174
+ },
175
+ values(obj) {
176
+ if (!obj || typeof obj !== "object") {
177
+ throw new MutorError("Object.values expects an object");
178
+ }
179
+ return Object.values(obj);
180
+ },
181
+ entries(obj) {
182
+ if (!obj || typeof obj !== "object") {
183
+ throw new MutorError("Object.entries expects an object");
184
+ }
185
+ return Object.entries(obj);
186
+ },
187
+ hasOwn(obj, key) {
188
+ if (!obj || typeof obj !== "object") {
189
+ throw new MutorError("Object.hasOwn expects an object");
190
+ }
191
+ return Object.hasOwn(obj, key);
192
+ },
193
+ freeze(obj) {
194
+ if (!obj || typeof obj !== "object") {
195
+ throw new MutorError("Object.freeze expects an object");
196
+ }
197
+ return Object.freeze(obj);
198
+ },
199
+ seal(obj) {
200
+ if (!obj || typeof obj !== "object") {
201
+ throw new MutorError("Object.seal expects an object");
202
+ }
203
+ return Object.seal(obj);
204
+ },
205
+ fromEntries(entries) {
206
+ if (!Array.isArray(entries)) {
207
+ throw new MutorError("Object.fromEntries expects an array");
208
+ }
209
+ return Object.fromEntries(entries);
210
+ }
211
+ },
212
+ Array: {
213
+ isArray(value) {
214
+ return Array.isArray(value);
215
+ },
216
+ from(value) {
217
+ return Array.from(value);
218
+ }
219
+ },
220
+ Number: {
221
+ isFinite(value) {
222
+ return Number.isFinite(value);
223
+ },
224
+ isNaN(value) {
225
+ return Number.isNaN(value);
226
+ },
227
+ parseInt(value, radix = 10) {
228
+ return Number.parseInt(value, radix);
229
+ },
230
+ parseFloat(value) {
231
+ return Number.parseFloat(value);
232
+ }
233
+ },
234
+ String: {
235
+ fromCharCode(...args) {
236
+ return String.fromCharCode(...args);
237
+ }
238
+ },
239
+ Math: {
240
+ abs(x) {
241
+ return Math.abs(x);
242
+ },
243
+ floor(x) {
244
+ return Math.floor(x);
245
+ },
246
+ ceil(x) {
247
+ return Math.ceil(x);
248
+ },
249
+ round(x) {
250
+ return Math.round(x);
251
+ },
252
+ max(...args) {
253
+ return Math.max(...args);
254
+ },
255
+ min(...args) {
256
+ return Math.min(...args);
257
+ },
258
+ random() {
259
+ return Math.random();
260
+ }
261
+ },
262
+ Date: {
263
+ now() {
264
+ return Date.now();
265
+ },
266
+ parse(str) {
267
+ if (typeof str !== "string") {
268
+ throw new MutorError("Date.parse expects a string");
269
+ }
270
+ return Date.parse(str);
271
+ }
272
+ },
273
+ Boolean: {
274
+ valueOf(value) {
275
+ return Boolean(value);
276
+ }
277
+ }
278
+ };
279
+
280
+ // src/utils/escape-fn.ts
281
+ function escapeFn(e) {
282
+ if (typeof e !== "string") return e;
283
+ return /[&<>"']/.test(e) ? e.replace(/[&<>"']/g, (char) => ESCAPE_MAP[char]) : e;
284
+ }
285
+
286
+ // src/utils/validate-computed-prop.ts
287
+ function validateComputedProp(r, allowedProps, forbiddenProps) {
288
+ if (forbiddenProps.has(r) && !allowedProps.has(r)) {
289
+ throw new MutorError(
290
+ `Forbidden property access. Access to this computed property "${r}" is forbidden.`
291
+ );
292
+ }
293
+ return r;
294
+ }
295
+
296
+ // src/utils/validate-context.ts
297
+ var OBJECT = "object";
298
+ var MUTOR_SAFE = /* @__PURE__ */ Symbol("__mutor_safe_context");
299
+ function validateContext(ctx) {
300
+ if (!ctx || typeof ctx !== OBJECT) {
301
+ return ctx;
302
+ }
303
+ if (MUTOR_SAFE in ctx) {
304
+ return ctx;
305
+ }
306
+ const seen = /* @__PURE__ */ new WeakSet();
307
+ function walk(value, path = "") {
308
+ if (!value || typeof value !== OBJECT) return value;
309
+ if (seen.has(value)) return value;
310
+ seen.add(value);
311
+ const proto = Object.getPrototypeOf(value);
312
+ if (proto && proto !== Object.prototype && proto !== Array.prototype) {
313
+ throw new MutorError(`Unsafe prototype detected at ${path || "root"}`);
314
+ }
315
+ if (Array.isArray(value)) {
316
+ for (let i = 0; i < value.length; i++) {
317
+ value[i] = walk(value[i], `${path}[${i}]`);
318
+ }
319
+ return value;
320
+ }
321
+ if (value instanceof Map) {
322
+ for (const [k, v] of value.entries()) {
323
+ if (typeof k === OBJECT) walk(k, `${path}.mapKey`);
324
+ value.set(k, walk(v, `${path}.mapValue`));
325
+ }
326
+ return value;
327
+ }
328
+ if (value instanceof Set) {
329
+ const next = /* @__PURE__ */ new Set();
330
+ for (const v of value.values()) {
331
+ next.add(walk(v, path));
332
+ }
333
+ value.clear();
334
+ for (const v of next) value.add(v);
335
+ return value;
336
+ }
337
+ const descriptors = Object.getOwnPropertyDescriptors(value);
338
+ for (const key of Object.keys(descriptors)) {
339
+ const desc = descriptors[key];
340
+ if (desc.get || desc.set) {
341
+ throw new MutorError(`Getter/setter not allowed: ${path}.${key}`);
342
+ }
343
+ const prop = value[key];
344
+ if (prop && typeof prop === OBJECT) {
345
+ value[key] = walk(prop, `${path}.${key}`);
346
+ }
347
+ }
348
+ return value;
349
+ }
350
+ const safeData = walk(ctx);
351
+ if (safeData && typeof safeData === OBJECT) {
352
+ Object.defineProperty(safeData, MUTOR_SAFE, {
353
+ value: true,
354
+ enumerable: false,
355
+ writable: false,
356
+ configurable: false
357
+ });
358
+ }
359
+ return safeData;
360
+ }
361
+
362
+ // src/utils/escape-raw-text.ts
363
+ function escapeRawText(text) {
364
+ return text.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$");
365
+ }
366
+
367
+ // src/utils/get-line-and-column-nums.ts
368
+ function getLineAndColumnNumbers(str, idx) {
369
+ const lines = str.slice(0, idx).split("\n");
370
+ const line = lines.length;
371
+ const lineIndex = str.lastIndexOf("\n", idx - 1) + 1;
372
+ return { line, lineIndex };
373
+ }
374
+
375
+ // src/utils/get-line-snapshot.ts
376
+ function getLineSnapshot(str, lineIdx, idx) {
377
+ const nextNewlineIdx = str.indexOf("\n", lineIdx);
378
+ const line = str.slice(
379
+ lineIdx,
380
+ nextNewlineIdx === -1 ? void 0 : nextNewlineIdx
381
+ );
382
+ return { line, pos: idx - lineIdx };
383
+ }
384
+
385
+ // src/core/build.ts
386
+ function build(ast, context) {
387
+ const { scope, forbiddenProps, allowedProps } = context;
388
+ function prefixWithCtx(ident) {
389
+ return scope.includes(ident) ? ident : `ctx.${ident}`;
390
+ }
391
+ function buildExpr(expr) {
392
+ switch (expr.type) {
393
+ case 17 /* END */:
394
+ return "}";
395
+ case 5 /* NUMBER */:
396
+ return expr.value;
397
+ case 4 /* STRING */:
398
+ return `\`${/\$/.test(expr.value) ? expr.value.replaceAll("$", "\\$") : expr.value}\``;
399
+ case 10 /* BOOLEAN */:
400
+ return expr.true ? "true" : "false";
401
+ case 12 /* NULL */:
402
+ return "null";
403
+ case 11 /* UNDEFINED */:
404
+ return "undefined";
405
+ case 7 /* IDENT */:
406
+ return prefixWithCtx(expr.value);
407
+ case 9 /* GROUP */:
408
+ return `(${buildExpr(expr.expr)})`;
409
+ case 2 /* UNARY */:
410
+ return `${expr.operator}${buildExpr(expr.expr)}`;
411
+ case 0 /* BINARY */:
412
+ return `${buildExpr(expr.left)} ${expr.operator} ${buildExpr(expr.right)}`;
413
+ case 1 /* TERNARY */:
414
+ return `${buildExpr(expr.condition)} ? ${buildExpr(expr.left)} : ${buildExpr(expr.right)}`;
415
+ case 8 /* PROP_ACCESS */:
416
+ return buildPropAccess(expr);
417
+ case 3 /* CALL */:
418
+ return buildCall(expr);
419
+ case 6 /* NAMESPACE */:
420
+ return buildNamespace(expr);
421
+ case 13 /* FOR */:
422
+ return buildForLoop(expr);
423
+ case 16 /* ELSE */:
424
+ return "} else {";
425
+ case 14 /* IF */:
426
+ return buildIfBlock(expr);
427
+ case 15 /* ELSE_IF */:
428
+ return buildElseIfBlock(expr);
429
+ default:
430
+ throw new MutorError(
431
+ `Unsupported expression type: ${expr.type}`
432
+ );
433
+ }
434
+ }
435
+ function buildNamespace(expr) {
436
+ if (expr.left.type !== 7 /* IDENT */) {
437
+ throw {
438
+ message: "Invalid usage of namespace operator.",
439
+ pos: expr.pos
440
+ };
441
+ }
442
+ return `namespaces.${expr.left.value}.${expr.right.value}`;
443
+ }
444
+ function buildPropAccess(expr) {
445
+ const left = buildExpr(expr.left);
446
+ if (expr.bracketNotation) {
447
+ const right = buildExpr(expr.right);
448
+ const optionalChain = expr.optional ? "?." : "";
449
+ return expr.right.type === 4 /* STRING */ || expr.right.type === 5 /* NUMBER */ ? `${left}${optionalChain}[${right}]` : `${left}${optionalChain}[validateComputedProps(${right}, allowedProps, forbiddenProps)]`;
450
+ } else {
451
+ const propName = expr.right.value;
452
+ const optionalChain = expr.optional ? "?." : ".";
453
+ if (forbiddenProps.has(propName) && !allowedProps.has(propName)) {
454
+ throw { message: "Forbidden property access.", pos: expr.right.pos };
455
+ }
456
+ return `${left}${optionalChain}${propName}`;
457
+ }
458
+ }
459
+ function buildCall(expr) {
460
+ const func = buildExpr(expr.expr);
461
+ const optionalChain = expr.optional ? "?." : "";
462
+ const args = expr.args.map((arg) => buildExpr(arg)).join(", ");
463
+ return `${func}${optionalChain}(${args})`;
464
+ }
465
+ function buildForLoop(expr) {
466
+ const { iterable, loopType, variable } = expr;
467
+ return `for(const ${variable} ${loopType === 1 /* IN */ ? "in" : "of"} ${build(iterable, context)}){`;
468
+ }
469
+ function buildIfBlock(expr) {
470
+ const { condition } = expr;
471
+ return `if(${build(condition, context)}){`;
472
+ }
473
+ function buildElseIfBlock(expr) {
474
+ const { condition } = expr;
475
+ return `}else if(${build(condition, context)}){`;
476
+ }
477
+ return buildExpr(ast);
478
+ }
479
+
480
+ // src/utils/get-token-type-words.ts
481
+ function getTokenTypeWords(type) {
482
+ switch (type) {
483
+ case 0 /* IDENT */:
484
+ return "identifier";
485
+ case 1 /* KEYWORD */:
486
+ return "keyword";
487
+ case 2 /* NUMBER */:
488
+ return "number";
489
+ case 4 /* OPERATOR */:
490
+ return "operator";
491
+ case 3 /* STRING */:
492
+ return "string";
493
+ }
494
+ }
495
+
496
+ // src/core/generate-ast.ts
497
+ function generateAst(tokens, config) {
498
+ let cursor = 0, generatingNamespace = false;
499
+ function expectOrThrow(type, value) {
500
+ const token = tokens[cursor];
501
+ const lastToken = tokens[tokens.length - 1];
502
+ if (!token) {
503
+ throw {
504
+ message: `Unexpected end of expression. Expected ${value ? `'${value}'` : `${type === 0 /* IDENT */ ? "an" : "a"} ${getTokenTypeWords(type)}`}.`,
505
+ pos: lastToken.pos + lastToken.value.length - 1
506
+ };
507
+ }
508
+ if (token.type !== type) {
509
+ throw {
510
+ message: `Unexpected token type. Expected ${value ? `'${value}'` : getTokenTypeWords(type)} but got ${getTokenTypeWords(token.type)} instead.`,
511
+ pos: token.pos
512
+ };
513
+ }
514
+ if (value !== void 0 && token.value !== value) {
515
+ throw {
516
+ message: `Unexpected token '${token?.value}'. Expected ${type === 0 /* IDENT */ ? "an" : "a"} ${getTokenTypeWords(type)} instead.`,
517
+ pos: token.pos
518
+ };
519
+ }
520
+ return tokens[cursor++];
521
+ }
522
+ function parseForLoop() {
523
+ const pos = tokens[cursor - 1].pos;
524
+ const variable = expectOrThrow(0 /* IDENT */).value;
525
+ let token;
526
+ try {
527
+ token = expectOrThrow(1 /* KEYWORD */, "in");
528
+ } catch {
529
+ token = expectOrThrow(1 /* KEYWORD */, "of");
530
+ }
531
+ const loopType = token.value === "in" ? 1 /* IN */ : 0 /* OF */;
532
+ const iterable = parseTernaryExpr();
533
+ return { type: 13 /* FOR */, loopType, iterable, variable, pos };
534
+ }
535
+ function parseIfExpression() {
536
+ const condition = parseTernaryExpr();
537
+ return { condition, pos: condition.pos, type: 14 /* IF */ };
538
+ }
539
+ function parseElseExpression() {
540
+ const pos = tokens[cursor - 1].pos;
541
+ try {
542
+ expectOrThrow(1 /* KEYWORD */, "if");
543
+ return { ...parseIfExpression(), type: 15 /* ELSE_IF */, pos };
544
+ } catch {
545
+ return { type: 16 /* ELSE */, pos };
546
+ }
547
+ }
548
+ function extractFnArgs() {
549
+ const args = [];
550
+ const emptyArgs = tokens[cursor]?.type === 4 /* OPERATOR */ && tokens[cursor]?.value === ")";
551
+ if (emptyArgs) {
552
+ return args;
553
+ }
554
+ args.push(parseTernaryExpr());
555
+ while (tokens[cursor]?.type === 4 /* OPERATOR */ && tokens[cursor]?.value === "," && tokens[cursor]?.value !== ")") {
556
+ cursor++;
557
+ args.push(parseTernaryExpr());
558
+ }
559
+ return args;
560
+ }
561
+ function parsePrimaryExpr() {
562
+ const token = tokens[cursor++];
563
+ if (token?.type === 2 /* NUMBER */) {
564
+ return { type: 5 /* NUMBER */, value: token.value, pos: token.pos };
565
+ }
566
+ if (token?.type === 3 /* STRING */) {
567
+ return { type: 4 /* STRING */, value: token.value, pos: token.pos };
568
+ }
569
+ if (token?.type === 1 /* KEYWORD */) {
570
+ if (token.value === "for" && cursor === 1) {
571
+ return parseForLoop();
572
+ }
573
+ if (token.value === "true" || token.value === "false") {
574
+ return {
575
+ type: 10 /* BOOLEAN */,
576
+ true: token.value === "true",
577
+ pos: token.pos
578
+ };
579
+ }
580
+ if (token.value === "undefined") {
581
+ return { type: 11 /* UNDEFINED */, pos: token.pos };
582
+ }
583
+ if (token.value === "null") {
584
+ return { type: 12 /* NULL */, pos: token.pos };
585
+ }
586
+ if (token.value === "end" && tokens.length === 1) {
587
+ return { type: 17 /* END */, pos: token.pos };
588
+ }
589
+ if (token.value === "if" && cursor === 1) {
590
+ return parseIfExpression();
591
+ }
592
+ if (token.value === "else" && cursor === 1) {
593
+ return parseElseExpression();
594
+ }
595
+ }
596
+ if (token?.type === 0 /* IDENT */) {
597
+ return { type: 7 /* IDENT */, value: token.value, pos: token.pos };
598
+ }
599
+ if (token?.type === 4 /* OPERATOR */ && token.value === "(") {
600
+ const expr = parseTernaryExpr();
601
+ expectOrThrow(4 /* OPERATOR */, ")");
602
+ return { type: 9 /* GROUP */, expr, pos: token.pos };
603
+ }
604
+ if (token?.type === 4 /* OPERATOR */ && unaryOperators.has(token.value)) {
605
+ const operator = token.value;
606
+ const expr = parseTernaryExpr();
607
+ return { type: 2 /* UNARY */, operator, expr, pos: token.pos };
608
+ }
609
+ if (cursor > tokens.length) {
610
+ throw {
611
+ message: `Unexpected end of expression.`,
612
+ pos: tokens[tokens.length - 1].pos
613
+ };
614
+ }
615
+ throw {
616
+ message: `Unexpected token '${token?.value}'.`,
617
+ pos: token.pos
618
+ };
619
+ }
620
+ function parsePropertyAccess() {
621
+ let left = parsePrimaryExpr();
622
+ while (tokens[cursor]) {
623
+ const token = tokens[cursor];
624
+ if (token?.type === 4 /* OPERATOR */ && token?.value === "(") {
625
+ cursor++;
626
+ if (!generatingNamespace && !config.allowFnCalls) {
627
+ throw {
628
+ message: "Function calls are not allowed.",
629
+ pos: tokens[cursor - 1].pos
630
+ };
631
+ }
632
+ const args = extractFnArgs();
633
+ expectOrThrow(4 /* OPERATOR */, ")");
634
+ left = {
635
+ type: 3 /* CALL */,
636
+ expr: left,
637
+ args,
638
+ pos: tokens[cursor - 1].pos
639
+ };
640
+ } else if (token?.type === 4 /* OPERATOR */ && token?.value === "?." && tokens[cursor + 1]?.type === 4 /* OPERATOR */ && tokens[cursor + 1]?.value === "(") {
641
+ cursor++;
642
+ cursor++;
643
+ if (!generatingNamespace && !config.allowFnCalls) {
644
+ throw {
645
+ message: "Function calls are not allowed.",
646
+ pos: tokens[cursor - 1].pos
647
+ };
648
+ }
649
+ const args = extractFnArgs();
650
+ expectOrThrow(4 /* OPERATOR */, ")");
651
+ left = {
652
+ type: 3 /* CALL */,
653
+ expr: left,
654
+ args,
655
+ optional: true,
656
+ pos: tokens[cursor - 1].pos
657
+ };
658
+ } else if (token?.type === 4 /* OPERATOR */ && propertyAccessOperators.has(token?.value)) {
659
+ const isNamespace = token?.value === "::";
660
+ const isBracketNotation = token?.value === "[";
661
+ const isOptional = token?.value === "?.";
662
+ cursor++;
663
+ if (isNamespace && (tokens[cursor - 2]?.type !== 0 /* IDENT */ || tokens[cursor]?.type !== 0 /* IDENT */)) {
664
+ throw {
665
+ message: `Invalid namespaces access. Expected syntax <IDENTIFIER>::<IDENTIFIER>, but got '${tokens[cursor - 2]?.value}::${tokens[cursor]?.value}' instead.`,
666
+ pos: tokens[cursor]?.pos
667
+ };
668
+ }
669
+ if (isNamespace) {
670
+ generatingNamespace = true;
671
+ const right = parsePrimaryExpr();
672
+ left = {
673
+ type: 6 /* NAMESPACE */,
674
+ left,
675
+ right,
676
+ pos: tokens[cursor - 1].pos
677
+ };
678
+ } else if (isBracketNotation) {
679
+ const right = parseTernaryExpr();
680
+ expectOrThrow(4 /* OPERATOR */, "]");
681
+ left = {
682
+ type: 8 /* PROP_ACCESS */,
683
+ right,
684
+ left,
685
+ bracketNotation: true,
686
+ pos: tokens[cursor - 1].pos
687
+ };
688
+ } else if (isOptional) {
689
+ if (tokens[cursor]?.type === 4 /* OPERATOR */ && tokens[cursor]?.value === "[") {
690
+ cursor++;
691
+ const right = parseTernaryExpr();
692
+ expectOrThrow(4 /* OPERATOR */, "]");
693
+ left = {
694
+ type: 8 /* PROP_ACCESS */,
695
+ left,
696
+ right,
697
+ bracketNotation: true,
698
+ optional: true,
699
+ pos: tokens[cursor - 1].pos
700
+ };
701
+ } else {
702
+ const right = parsePrimaryExpr();
703
+ left = {
704
+ type: 8 /* PROP_ACCESS */,
705
+ left,
706
+ right,
707
+ optional: true,
708
+ pos: tokens[cursor - 1].pos
709
+ };
710
+ }
711
+ } else {
712
+ const right = parsePrimaryExpr();
713
+ left = {
714
+ type: 8 /* PROP_ACCESS */,
715
+ left,
716
+ right,
717
+ pos: tokens[cursor - 1].pos
718
+ };
719
+ }
720
+ } else {
721
+ break;
722
+ }
723
+ }
724
+ generatingNamespace = false;
725
+ return left;
726
+ }
727
+ function parseMultiplicativeExpr() {
728
+ let left = parsePropertyAccess();
729
+ while (tokens[cursor]?.type === 4 /* OPERATOR */ && multiplicativeOperators.has(tokens[cursor]?.value)) {
730
+ const operator = tokens[cursor++].value;
731
+ const right = parsePropertyAccess();
732
+ left = {
733
+ type: 0 /* BINARY */,
734
+ left,
735
+ right,
736
+ operator,
737
+ pos: tokens[cursor - 1].pos
738
+ };
739
+ }
740
+ return left;
741
+ }
742
+ function parseAdditiveExpr() {
743
+ let left = parseMultiplicativeExpr();
744
+ while (tokens[cursor]?.type === 4 /* OPERATOR */ && additiveOperators.has(tokens[cursor]?.value)) {
745
+ const operator = tokens[cursor++].value;
746
+ const right = parseMultiplicativeExpr();
747
+ left = {
748
+ type: 0 /* BINARY */,
749
+ left,
750
+ right,
751
+ operator,
752
+ pos: tokens[cursor - 1].pos
753
+ };
754
+ }
755
+ return left;
756
+ }
757
+ function parseBitwiseExpr() {
758
+ let left = parseAdditiveExpr();
759
+ while (tokens[cursor]?.type === 4 /* OPERATOR */ && comparisonOperators.has(tokens[cursor]?.value)) {
760
+ const operator = tokens[cursor++].value;
761
+ const right = parseAdditiveExpr();
762
+ left = {
763
+ type: 0 /* BINARY */,
764
+ left,
765
+ right,
766
+ operator,
767
+ pos: tokens[cursor - 1].pos
768
+ };
769
+ }
770
+ return left;
771
+ }
772
+ function parseComparisonExpr() {
773
+ let left = parseBitwiseExpr();
774
+ while (tokens[cursor]?.type === 4 /* OPERATOR */ && comparisonOperators.has(tokens[cursor]?.value)) {
775
+ const operator = tokens[cursor++].value;
776
+ const right = parseBitwiseExpr();
777
+ left = {
778
+ type: 0 /* BINARY */,
779
+ left,
780
+ right,
781
+ operator,
782
+ pos: tokens[cursor - 1].pos
783
+ };
784
+ }
785
+ return left;
786
+ }
787
+ function parseEqualityExpr() {
788
+ let left = parseComparisonExpr();
789
+ while (tokens[cursor]?.type === 4 /* OPERATOR */ && equalityOperators.has(tokens[cursor]?.value)) {
790
+ const operator = tokens[cursor++].value;
791
+ const right = parseComparisonExpr();
792
+ left = {
793
+ type: 0 /* BINARY */,
794
+ left,
795
+ right,
796
+ operator,
797
+ pos: tokens[cursor - 1].pos
798
+ };
799
+ }
800
+ return left;
801
+ }
802
+ function parseLogicalOrExpr() {
803
+ let left = parseLogicalAndExpr();
804
+ while (tokens[cursor]?.type === 4 /* OPERATOR */ && tokens[cursor]?.value === "||") {
805
+ const operator = tokens[cursor++].value;
806
+ const right = parseLogicalAndExpr();
807
+ left = {
808
+ type: 0 /* BINARY */,
809
+ left,
810
+ right,
811
+ operator,
812
+ pos: tokens[cursor - 1].pos
813
+ };
814
+ }
815
+ return left;
816
+ }
817
+ function parseLogicalAndExpr() {
818
+ let left = parseNullishCoalesceExpr();
819
+ while (tokens[cursor]?.type === 4 /* OPERATOR */ && tokens[cursor]?.value === "&&") {
820
+ const operator = tokens[cursor++].value;
821
+ const right = parseNullishCoalesceExpr();
822
+ left = {
823
+ type: 0 /* BINARY */,
824
+ left,
825
+ right,
826
+ operator,
827
+ pos: tokens[cursor - 1].pos
828
+ };
829
+ }
830
+ return left;
831
+ }
832
+ function parseNullishCoalesceExpr() {
833
+ let left = parseEqualityExpr();
834
+ while (tokens[cursor]?.type === 4 /* OPERATOR */ && tokens[cursor]?.value === "??") {
835
+ const operator = tokens[cursor++].value;
836
+ const right = parseEqualityExpr();
837
+ left = {
838
+ type: 0 /* BINARY */,
839
+ left,
840
+ right,
841
+ operator,
842
+ pos: tokens[cursor - 1].pos
843
+ };
844
+ }
845
+ return left;
846
+ }
847
+ function parseTernaryExpr() {
848
+ const condition = parseLogicalOrExpr();
849
+ if (tokens[cursor]?.type !== 4 /* OPERATOR */ || tokens[cursor]?.value !== "?") {
850
+ return condition;
851
+ }
852
+ cursor++;
853
+ const left = parseTernaryExpr();
854
+ expectOrThrow(4 /* OPERATOR */, ":");
855
+ const right = parseTernaryExpr();
856
+ return {
857
+ type: 1 /* TERNARY */,
858
+ left,
859
+ right,
860
+ condition,
861
+ pos: tokens[cursor - 1].pos
862
+ };
863
+ }
864
+ const ast = parseTernaryExpr();
865
+ return ast;
866
+ }
867
+
868
+ // src/core/parse.ts
869
+ function parse(templateBlock, { delimiters }) {
870
+ const openingTagWithWhitespaceCtrl = `${delimiters.openingTag}${delimiters.whitespaceTrim}`;
871
+ const closingTagWithWhitespaceCtrl = `${delimiters.whitespaceTrim}${delimiters.closingTag}`;
872
+ const leftTrim = templateBlock.startsWith(openingTagWithWhitespaceCtrl);
873
+ const rightTrim = templateBlock.endsWith(closingTagWithWhitespaceCtrl);
874
+ const isComment = templateBlock.startsWith(
875
+ leftTrim ? openingTagWithWhitespaceCtrl + delimiters.commentTag : delimiters.openingTag + delimiters.commentTag
876
+ );
877
+ if (isComment) {
878
+ return { isComment, leftTrim, rightTrim };
879
+ }
880
+ const inner = templateBlock.slice(
881
+ leftTrim ? openingTagWithWhitespaceCtrl.length : delimiters.openingTag.length,
882
+ templateBlock.length - (rightTrim ? closingTagWithWhitespaceCtrl.length : delimiters.closingTag.length)
883
+ );
884
+ const trimmed = inner.trim();
885
+ const isBlock = trimmed.startsWith("for") || trimmed.startsWith("if") || trimmed.startsWith("else");
886
+ const requiresBlockClose = trimmed.startsWith("for") || trimmed.startsWith("if");
887
+ const isBlockEnd = trimmed === "end";
888
+ const hasContext = trimmed.startsWith("for");
889
+ return {
890
+ leftTrim,
891
+ rightTrim,
892
+ inner,
893
+ isBlock,
894
+ isBlockEnd,
895
+ hasContext,
896
+ requiresBlockClose
897
+ };
898
+ }
899
+
900
+ // src/core/tokenize.ts
901
+ function tokenize(expr) {
902
+ let cursor = 0, char = "";
903
+ const tokens = [];
904
+ function accumulateKeywordOrIdentifier() {
905
+ let buffer = "";
906
+ if (/[a-zA-Z$_]/.test(char)) {
907
+ let j = cursor;
908
+ while (/[a-zA-Z$_0-9]/.test(expr[j]) && j < expr.length) {
909
+ buffer += expr[j];
910
+ j++;
911
+ }
912
+ tokens.push({
913
+ type: keywords.has(buffer) ? 1 /* KEYWORD */ : 0 /* IDENT */,
914
+ value: buffer,
915
+ pos: cursor
916
+ });
917
+ cursor = j;
918
+ char = expr[cursor];
919
+ }
920
+ }
921
+ function accumulateStr() {
922
+ let buffer = "";
923
+ if (char === '"' || char === "'" || char === "`") {
924
+ let j = cursor + 1;
925
+ while (expr[j] !== char && j < expr.length) {
926
+ buffer += expr[j];
927
+ j++;
928
+ }
929
+ if (j > expr.length) {
930
+ throw { pos: cursor, message: `Found string without closing quote.` };
931
+ }
932
+ tokens.push({ type: 3 /* STRING */, value: buffer, pos: cursor });
933
+ cursor = j;
934
+ }
935
+ }
936
+ function accumulateNumber() {
937
+ if (/[0-9]/.test(char)) {
938
+ let j = cursor, buffer = "";
939
+ while (/[0-9.oxe]/.test(expr[j]) && j < expr.length) {
940
+ buffer += expr[j];
941
+ j++;
942
+ }
943
+ const numVal = Number(buffer);
944
+ const isNan = Number.isNaN(numVal);
945
+ if (isNan) {
946
+ throw { pos: cursor, message: "Found invalid number literal." };
947
+ }
948
+ tokens.push({ type: 2 /* NUMBER */, value: `${numVal}`, pos: cursor });
949
+ cursor = j - 1;
950
+ char = expr[cursor];
951
+ }
952
+ }
953
+ function accumulateOperator() {
954
+ const op = `${char}${expr[cursor + 1]}`;
955
+ if (operators.has(op)) {
956
+ tokens.push({ type: 4 /* OPERATOR */, value: op, pos: cursor });
957
+ cursor++;
958
+ return;
959
+ }
960
+ if (operators.has(char)) {
961
+ tokens.push({ type: 4 /* OPERATOR */, value: char, pos: cursor });
962
+ return;
963
+ }
964
+ }
965
+ while (cursor < expr.length) {
966
+ char = expr[cursor];
967
+ accumulateNumber();
968
+ accumulateKeywordOrIdentifier();
969
+ accumulateStr();
970
+ accumulateOperator();
971
+ if (!/[a-zA-Z$_0-9\s\t\r\n'"`]/.test(char) && !operators.has(char) && !operators.has(expr[cursor - 1] + char)) {
972
+ throw {
973
+ message: `Unexpected token '${char}' in expression.`,
974
+ pos: cursor
975
+ };
976
+ }
977
+ cursor++;
978
+ }
979
+ return tokens;
980
+ }
981
+
982
+ // src/core/compile.ts
983
+ function compile(src, config, meta) {
984
+ const scope = [];
985
+ const blockOpeningStack = [];
986
+ const {
987
+ delimiters,
988
+ keepOpeningTagEscapeDelimiter,
989
+ allowFnCalls,
990
+ allowedProps,
991
+ forbiddenProps,
992
+ autoEscape
993
+ } = config;
994
+ let trimNext = false, cursor = 0, body = `let acc="";`;
995
+ while (cursor < src.length) {
996
+ let isEscaped2 = function() {
997
+ let j = templateOpenTagIdx, count = 0;
998
+ while (j >= delimiters.openingTagEscape.length && src.slice(j - delimiters.openingTagEscape.length, j) === delimiters.openingTagEscape) {
999
+ count++;
1000
+ j -= delimiters.openingTagEscape.length;
1001
+ }
1002
+ return count % 2 === 1;
1003
+ };
1004
+ var isEscaped = isEscaped2;
1005
+ const templateOpenTagIdx = src.indexOf(delimiters.openingTag, cursor);
1006
+ if (templateOpenTagIdx === -1) {
1007
+ let lastChunk = src.slice(cursor);
1008
+ if (trimNext) lastChunk = lastChunk.trimStart();
1009
+ if (lastChunk) body += `acc+=\`${escapeRawText(lastChunk)}\`;`;
1010
+ break;
1011
+ }
1012
+ if (isEscaped2()) {
1013
+ let escapedChunk = src.slice(
1014
+ cursor,
1015
+ keepOpeningTagEscapeDelimiter ? templateOpenTagIdx + delimiters.openingTagEscape.length + 1 : templateOpenTagIdx - delimiters.openingTag.length + 1
1016
+ );
1017
+ if (trimNext) {
1018
+ escapedChunk = escapedChunk.trimStart();
1019
+ trimNext = false;
1020
+ }
1021
+ body += `acc+=\`${escapeRawText(escapedChunk)}\`;`;
1022
+ if (!keepOpeningTagEscapeDelimiter)
1023
+ body += `acc+=\`${delimiters.openingTag}\`;`;
1024
+ cursor = templateOpenTagIdx + delimiters.openingTag.length;
1025
+ continue;
1026
+ }
1027
+ const templateEndTagIdx = src.indexOf(
1028
+ delimiters.closingTag,
1029
+ templateOpenTagIdx
1030
+ );
1031
+ if (templateEndTagIdx === -1) {
1032
+ const { line, lineIndex } = getLineAndColumnNumbers(
1033
+ src,
1034
+ templateOpenTagIdx
1035
+ );
1036
+ const { line: lineText, pos } = getLineSnapshot(
1037
+ src,
1038
+ lineIndex,
1039
+ templateOpenTagIdx
1040
+ );
1041
+ throw new MutorCompilerError(
1042
+ "No closing tag found.",
1043
+ line,
1044
+ lineText,
1045
+ pos,
1046
+ meta.path
1047
+ );
1048
+ }
1049
+ const template = src.slice(
1050
+ templateOpenTagIdx,
1051
+ templateEndTagIdx + delimiters.closingTag.length
1052
+ );
1053
+ const {
1054
+ inner,
1055
+ leftTrim,
1056
+ rightTrim,
1057
+ isBlock,
1058
+ isBlockEnd,
1059
+ hasContext,
1060
+ requiresBlockClose,
1061
+ isComment
1062
+ } = parse(template, { delimiters });
1063
+ let rawText = src.slice(cursor, templateOpenTagIdx);
1064
+ if (rawText) {
1065
+ if (trimNext) {
1066
+ rawText = rawText.trimStart();
1067
+ }
1068
+ if (leftTrim) {
1069
+ rawText = rawText.trimEnd();
1070
+ }
1071
+ if (rawText) {
1072
+ body += `acc+=\`${escapeRawText(rawText)}\`;`;
1073
+ }
1074
+ }
1075
+ trimNext = false;
1076
+ cursor = templateEndTagIdx + delimiters.closingTag.length;
1077
+ try {
1078
+ if (!isComment) {
1079
+ const tokens = tokenize(inner);
1080
+ const ast = generateAst(tokens, { allowFnCalls });
1081
+ if (isBlock && requiresBlockClose && hasContext) {
1082
+ scope.push(ast.variable);
1083
+ blockOpeningStack.push({
1084
+ type: 0 /* LOOP */,
1085
+ pos: templateOpenTagIdx
1086
+ });
1087
+ } else if (isBlock && requiresBlockClose && !hasContext) {
1088
+ blockOpeningStack.push({
1089
+ type: 1 /* NON_LOOP */,
1090
+ pos: templateOpenTagIdx
1091
+ });
1092
+ }
1093
+ if (isBlockEnd) {
1094
+ const lastBlockOpened = blockOpeningStack.pop();
1095
+ if (lastBlockOpened?.type === 0 /* LOOP */) scope.pop();
1096
+ if (lastBlockOpened === void 0)
1097
+ throw {
1098
+ message: "Unexpected end of block",
1099
+ pos: templateOpenTagIdx
1100
+ };
1101
+ }
1102
+ const js = build(ast, { allowedProps, forbiddenProps, scope });
1103
+ if (isBlock || isBlockEnd) {
1104
+ body += js;
1105
+ } else {
1106
+ body += autoEscape && !js.startsWith("namespaces.Mutor.include") ? `acc+=escapeFn(${js});` : `acc+=${js};`;
1107
+ }
1108
+ }
1109
+ if (rightTrim) trimNext = true;
1110
+ } catch (e) {
1111
+ const { message, pos: relPos } = e;
1112
+ const { line, lineIndex } = getLineAndColumnNumbers(
1113
+ src,
1114
+ templateOpenTagIdx
1115
+ );
1116
+ const { line: lineText, pos } = getLineSnapshot(
1117
+ src,
1118
+ lineIndex,
1119
+ templateOpenTagIdx
1120
+ );
1121
+ throw new MutorCompilerError(
1122
+ message,
1123
+ line,
1124
+ lineText,
1125
+ pos + relPos + (leftTrim ? delimiters.openingTag.length + delimiters.whitespaceTrim.length : delimiters.openingTag.length),
1126
+ meta.path
1127
+ );
1128
+ }
1129
+ }
1130
+ if (blockOpeningStack.length) {
1131
+ const lastPos = blockOpeningStack.pop()?.pos;
1132
+ const { line, lineIndex } = getLineAndColumnNumbers(src, lastPos);
1133
+ const { line: lineText, pos } = getLineSnapshot(src, lineIndex, lastPos);
1134
+ throw new MutorCompilerError(
1135
+ "Unclosed block detected.",
1136
+ line,
1137
+ lineText,
1138
+ pos + delimiters.openingTag.length,
1139
+ meta.path
1140
+ );
1141
+ }
1142
+ body += `return acc;`;
1143
+ return new Function(
1144
+ "ctx",
1145
+ "namespaces",
1146
+ "allowedProps",
1147
+ "forbiddenProps",
1148
+ "escapeFn",
1149
+ "validateComputedProps",
1150
+ body
1151
+ );
1152
+ }
1153
+
1154
+ // src/core/mutor.ts
1155
+ var Mutor = class {
1156
+ constructor(config = {}) {
1157
+ this.__currentRenderedPath = "";
1158
+ this.__includeStack = /* @__PURE__ */ new Set();
1159
+ this.__cacheSize = 0;
1160
+ this.__config = { ...defaultConfig };
1161
+ this.__compiledTemplatesMap = /* @__PURE__ */ new Map();
1162
+ this.__currentContext = null;
1163
+ this.__namespaces = {
1164
+ ...namespaces,
1165
+ Mutor: {
1166
+ include: (path, ctx) => {
1167
+ if (this.__includeStack.has(path)) {
1168
+ throw new MutorError(
1169
+ `Circular include detected:
1170
+ ${Array.from(this.__includeStack).join("\n")}
1171
+ ${path}`
1172
+ );
1173
+ }
1174
+ try {
1175
+ this.__includeStack.add(path);
1176
+ return this.renderComponent(path, ctx ?? this.__currentContext);
1177
+ } finally {
1178
+ this.__includeStack.delete(path);
1179
+ }
1180
+ }
1181
+ }
1182
+ };
1183
+ this.addConfig(config);
1184
+ Object.defineProperty(this.__namespaces.Mutor, "$$context", {
1185
+ get: () => {
1186
+ return this.__currentContext;
1187
+ }
1188
+ });
1189
+ }
1190
+ addConfig(conf) {
1191
+ const {
1192
+ autoEscape,
1193
+ delimiters: overrideDelimeters,
1194
+ allowedProps,
1195
+ forbiddenProps,
1196
+ keepOpeningTagEscapeDelimiter,
1197
+ allowFnCalls,
1198
+ cache,
1199
+ build: build2
1200
+ } = conf;
1201
+ this.__config = {
1202
+ build: {
1203
+ include: /* @__PURE__ */ new Set([...build2?.include || defaultConfig.build.include]),
1204
+ exclude: /* @__PURE__ */ new Set([
1205
+ ...defaultConfig.build.exclude,
1206
+ ...build2?.exclude || []
1207
+ ])
1208
+ },
1209
+ autoEscape: autoEscape === true ? true : autoEscape !== false,
1210
+ allowedProps: allowedProps || defaultConfig.allowedProps,
1211
+ allowFnCalls: !!allowFnCalls,
1212
+ cache: { ...defaultConfig.cache, ...cache || {} },
1213
+ forbiddenProps: /* @__PURE__ */ new Set([
1214
+ ...defaultConfig.forbiddenProps,
1215
+ ...forbiddenProps || []
1216
+ ]),
1217
+ keepOpeningTagEscapeDelimiter: keepOpeningTagEscapeDelimiter === true ? true : keepOpeningTagEscapeDelimiter !== false,
1218
+ delimiters: {
1219
+ ...defaultConfig.delimiters,
1220
+ ...overrideDelimeters || {}
1221
+ }
1222
+ };
1223
+ return this.__config;
1224
+ }
1225
+ restoreDefaultConfig() {
1226
+ this.__config = { ...defaultConfig };
1227
+ }
1228
+ compile(template) {
1229
+ return compile(template, this.__config, {
1230
+ path: this.__currentRenderedPath || "anonymous"
1231
+ });
1232
+ }
1233
+ render(template, context) {
1234
+ const prevContext = this.__currentContext;
1235
+ if (prevContext !== context) {
1236
+ this.__currentContext = context;
1237
+ }
1238
+ const result = this.compile(template)(
1239
+ validateContext(context),
1240
+ this.__namespaces,
1241
+ this.__config.allowedProps,
1242
+ this.__config.forbiddenProps,
1243
+ escapeFn,
1244
+ validateComputedProp
1245
+ );
1246
+ this.__currentContext = prevContext;
1247
+ return result;
1248
+ }
1249
+ renderComponent(identifier, context) {
1250
+ if (!this.__compiledTemplatesMap.has(identifier)) {
1251
+ throw new MutorError(
1252
+ `No template exists with the identifier '${identifier}'`
1253
+ );
1254
+ }
1255
+ const prevRenderComponentIdentifier = this.__currentRenderedPath;
1256
+ const prevContext = this.__currentContext;
1257
+ const compiled = this.__compiledTemplatesMap.get(identifier);
1258
+ this.__currentContext = context;
1259
+ this.__currentRenderedPath = identifier;
1260
+ const result = compiled.fn(
1261
+ validateContext(context),
1262
+ this.__namespaces,
1263
+ this.__config.allowedProps,
1264
+ this.__config.forbiddenProps,
1265
+ escapeFn,
1266
+ validateComputedProp
1267
+ );
1268
+ this.__currentContext = prevContext;
1269
+ this.__currentRenderedPath = prevRenderComponentIdentifier;
1270
+ return result;
1271
+ }
1272
+ registerComponent(identifier, template) {
1273
+ const templateSize = template.length * 2 + 500;
1274
+ if (this.__cacheSize + templateSize > this.__config.cache.maxSize) {
1275
+ if (!this.createEntrySpaceForTemplate(templateSize)) {
1276
+ throw new MutorError(
1277
+ `The template for the component '${identifier}' is too large. Consider increasing 'cache.maxSize' in the config`
1278
+ );
1279
+ }
1280
+ }
1281
+ this.__cacheSize += template.length * 2 + 500;
1282
+ this.__compiledTemplatesMap.set(identifier, {
1283
+ fn: this.compile(template),
1284
+ size: templateSize
1285
+ });
1286
+ }
1287
+ reset() {
1288
+ this.__config = { ...defaultConfig };
1289
+ this.__compiledTemplatesMap.clear();
1290
+ this.__currentContext = null;
1291
+ this.__cacheSize = 0;
1292
+ }
1293
+ createEntrySpaceForTemplate(targetSize) {
1294
+ if (this.__cacheSize + targetSize < this.__config.cache.maxSize) {
1295
+ return true;
1296
+ }
1297
+ if (targetSize > this.__config.cache.maxSize) {
1298
+ return false;
1299
+ }
1300
+ const firstEntry = this.__compiledTemplatesMap.entries().next().value;
1301
+ if (firstEntry) {
1302
+ const [oldestKey, oldestData] = firstEntry;
1303
+ this.__compiledTemplatesMap.delete(oldestKey);
1304
+ this.__cacheSize -= oldestData.size;
1305
+ }
1306
+ return this.createEntrySpaceForTemplate(targetSize);
1307
+ }
1308
+ getDiagnostics() {
1309
+ const maxSize = this.__config.cache.maxSize;
1310
+ return {
1311
+ bytesUsed: this.__cacheSize,
1312
+ bytesMax: maxSize,
1313
+ readableUsed: `${(this.__cacheSize / 1024 / 1024).toFixed(2)} MB`,
1314
+ readableMax: `${(maxSize / 1024 / 1024).toFixed(2)} MB`,
1315
+ totalEntries: this.__compiledTemplatesMap.size,
1316
+ percentFull: maxSize > 0 ? Math.min(100, Math.round(this.__cacheSize / maxSize * 100)) : 0,
1317
+ avgTemplateSize: this.__compiledTemplatesMap.size > 0 ? Math.round(this.__cacheSize / this.__compiledTemplatesMap.size) : 0
1318
+ };
1319
+ }
1320
+ };
1321
+
1322
+ // src/index.ts
1323
+ var index_default = Mutor;
1324
+ export {
1325
+ index_default as default
1326
+ };
13
1327
  //# sourceMappingURL=index.js.map