tjs-lang 0.7.5 → 0.7.6
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/demo/docs.json +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/tjs-eval.js +1 -1
- package/dist/tjs-eval.js.map +2 -2
- package/dist/tjs-lang.js +1 -1
- package/dist/tjs-lang.js.map +2 -2
- package/dist/tjs-vm.js +1 -1
- package/dist/tjs-vm.js.map +2 -2
- package/package.json +1 -1
- package/src/lang/parser-transforms.ts +3 -1
package/dist/tjs-eval.js
CHANGED
|
@@ -4,7 +4,7 @@ Supported: comparisons, &&, ||, !, arithmetic, member access (a.b), literals`)}r
|
|
|
4
4
|
`)}};function q(e){return{depth:e.depth+1,locals:new Map,parent:e,parameters:e.parameters,atoms:e.atoms,warnings:e.warnings,source:e.source,filename:e.filename,options:e.options}}function I(e){return e.loc?{line:e.loc.start.line,column:e.loc.start.column}:{line:1,column:0}}function ye(e,n){let t="",r=0,s,i,o="normal",a=[],c=[{type:"top-level",braceDepth:0}],l=0,p=()=>c[c.length-1]?.type||"top-level",d=()=>{let u=c[c.length-1];return u?.type==="class-body"&&l===u.braceDepth+1};for(;r<e.length;){let u=e[r],m=e[r+1];switch(o){case"single-string":if(t+=u,u==="\\"&&r+1<e.length){t+=m,r+=2;continue}u==="'"&&(o="normal"),r++;continue;case"double-string":if(t+=u,u==="\\"&&r+1<e.length){t+=m,r+=2;continue}u==='"'&&(o="normal"),r++;continue;case"template-string":if(t+=u,u==="\\"&&r+1<e.length){t+=m,r+=2;continue}if(u==="$"&&m==="{"){t+=m,r+=2,a.push(1),o="normal";continue}u==="`"&&(o="normal"),r++;continue;case"line-comment":t+=u,u===`
|
|
5
5
|
`&&(o="normal"),r++;continue;case"block-comment":if(t+=u,u==="*"&&m==="/"){t+=m,r+=2,o="normal";continue}r++;continue;case"regex":if(t+=u,u==="\\"&&r+1<e.length){t+=m,r+=2;continue}if(u==="["){for(r++;r<e.length&&e[r]!=="]";)t+=e[r],e[r]==="\\"&&r+1<e.length?(t+=e[r+1],r+=2):r++;r<e.length&&(t+=e[r],r++);continue}if(u==="/"){for(r++;r<e.length&&/[gimsuy]/.test(e[r]);)t+=e[r],r++;o="normal";continue}r++;continue;case"normal":if(a.length>0){if(u==="{")a[a.length-1]++;else if(u==="}"&&(a[a.length-1]--,a[a.length-1]===0)){a.pop(),t+=u,r++,o="template-string";continue}}if(u==="'"){t+=u,r++,o="single-string";continue}if(u==='"'){t+=u,r++,o="double-string";continue}if(u==="`"){t+=u,r++,o="template-string";continue}if(u==="/"&&m==="/"){t+=u+m,r+=2,o="line-comment";continue}if(u==="/"&&m==="*"){t+=u+m,r+=2,o="block-comment";continue}if(u==="/"){let g=t.trimEnd();if(!g[g.length-1]||/[=(!,;:{[&|?+\-*%<>~^]$/.test(g)||/\b(return|case|throw|in|of|typeof|instanceof|new|delete|void)\s*$/.test(g)){t+=u,r++,o="regex";continue}}break}if(u==="{"){l++,t+=u,r++;continue}if(u==="}"){l--;let g=c[c.length-1];g&&l===g.braceDepth&&c.pop(),t+=u,r++;continue}let y=e.slice(r).match(/^class\s+\w+(?:\s+extends\s+\w+)?\s*\{/);if(y){let g=y[0].slice(0,-1);t+=g,r+=g.length,c.push({type:"class-body",braceDepth:l});continue}let b=e.slice(r).match(/^function\s+(\w+)\s*\(/);if(b){let g=b[1],E=b[0].length,A=e[r+E],$=null,T=r+E;(A==="?"||A==="!")&&($=A,T++,$==="!"?n.unsafeFunctions.add(g):n.safeFunctions.add(g)),t+=`function ${g}(`,r=T;let v=pe(e,r,"(",")");if(!v){t+=e[r],r++;continue}let{content:M,endPos:k}=v;r=k;let C=Me(M,n,!0);t+=C+")";let N=r;for(;N<e.length&&/\s/.test(e[N]);)N++;if(e[N]===":"){let O=e.slice(N,N+2),z;for(O===":?"||O===":!"?(N+=2,z=O===":?"?"safe":"unsafe"):N+=1;N<e.length&&/\s/.test(e[N]);)N++;let H=je(e,N);H&&(s===void 0&&(s=H.type,z&&(i=z)),r=H.endPos)}continue}let h=e.slice(r).match(/^(constructor|(?:get|set)\s+\w+|async\s+\w+|\w+)\s*\(/),S=(()=>{for(let g=t.length-1;g>=0;g--)if(!/\s/.test(t[g]))return t[g];return`
|
|
6
6
|
`})(),x=S!=="="&&S!==","&&S!=="("&&S!=="["&&S!==">";if(h&&d()&&!x){let g=h[1].length;t+=e.slice(r,r+g),r+=g;continue}if(h&&d()&&x){let g=h[1],E=h[0].length,A=r+E;t+=g+"(",r=A;let $=pe(e,r,"(",")");if(!$){t+=e[r],r++;continue}let{content:T,endPos:v}=$;r=v;let M=Me(T,n,!0);t+=M+")";let k=r;for(;k<e.length&&/\s/.test(e[k]);)k++;if(e[k]===":"){let C=e.slice(k,k+2);for(C===":?"||C===":!"?k+=2:k++;k<e.length&&/\s/.test(e[k]);)k++;let N=je(e,k);N&&(r=N.endPos)}continue}if(e[r]==="("){let g=pe(e,r+1,"(",")");if(!g){t+=e[r],r++;continue}let E=g.content,A=g.endPos,$=A;for(;$<e.length&&/\s/.test(e[$]);)$++;let T;if(e[$]===":"){let v=e.slice($,$+2);for(v===":?"||v===":!"?$+=2:$++;$<e.length&&/\s/.test(e[$]);)$++;let M=je(e,$);if(M)for(T=M.type,$=M.endPos;$<e.length&&/\s/.test(e[$]);)$++}if(e.slice($,$+2)==="=>"){let v=null,M=E,k=E.trimStart();k.startsWith("?")&&(k.length===1||/\s/.test(k[1]))?(v="?",M=k.slice(1)):k.startsWith("!")&&(k.length===1||/\s/.test(k[1]))&&(v="!",M=k.slice(1));let C=Me(M,n,!1);for(t+=`(${v==="?"?"/* safe */ ":v==="!"?"/* unsafe */ ":""}${C})`,r=A;r<$&&/\s/.test(e[r]);)t+=e[r],r++;T&&(r=$)}else{let v=ye(E,n);t+=`(${v.source})`,r=A}continue}t+=e[r],r++}return{source:t,returnType:s,returnSafety:i}}function pe(e,n,t,r){let s=1,i=n,o=!1,a="";for(;i<e.length&&s>0;){let c=e[i];!o&&(c==="'"||c==='"'||c==="`")?(o=!0,a=c):o&&c===a&&e[i-1]!=="\\"?o=!1:o||(c===t?s++:c===r&&s--),i++}return s!==0?null:{content:e.slice(n,i-1),endPos:i}}function Ze(e,n){let t=n;for(;t<e.length&&/\s/.test(e[t]);)t++;if(t>=e.length)return null;let r=t,s=e[t];if(s==="{"||s==="["){let o=s==="{"?"}":"]",a=pe(e,t+1,s,o);return a?{value:e.slice(r,a.endPos),endPos:a.endPos}:null}if(s==="'"||s==='"'||s==="`"){for(t++;t<e.length;){if(e[t]===s&&e[t-1]!=="\\")return t++,{value:e.slice(r,t),endPos:t};t++}return null}if(/[-+\d]/.test(s)){for(;t<e.length&&/[\d.eE+-]/.test(e[t]);)t++;return{value:e.slice(r,t),endPos:t}}let i=e.slice(t).match(/^(true|false|null|undefined)\b/);return i?{value:i[1],endPos:t+i[1].length}:null}function ne(e){return e.replace(/(?<!\|)\|(?!\|)/g," || ")}function je(e,n){let t=n,r=0,s=!1,i="",o=!1,a=c=>({type:ne(e.slice(n,c).trim()),endPos:c});for(;t<e.length;){let c=e[t];if(!s&&(c==="'"||c==='"'||c==="`")){s=!0,i=c,o=!0,t++;continue}if(s){if(c===i&&e[t-1]!=="\\"){if(s=!1,t++,r===0){let l=t;for(;l<e.length&&/\s/.test(e[l]);)l++;if(e[l]==="{"&&!e.slice(l+1).match(/^\s*(\w+)\s*:/)||e[l]!=="|"&&e[l]!=="&")return a(t)}continue}t++;continue}if(c==="{"||c==="["||c==="("){r++,o=!0,t++;continue}if(c==="}"||c==="]"||c===")"){if(r--,r===0){t++;let l=t;for(;l<e.length&&/\s/.test(e[l]);)l++;if(e[l]==="|"||e[l]==="&")continue;return a(t)}t++;continue}if(r===0&&c==="{"){if(o)return a(t);if(e.slice(t+1).match(/^\s*(\w+)\s*:/)){r++,o=!0,t++;continue}return a(t)}if(r===0&&(c==="|"||c==="&")){for(t++,t<e.length&&e[t]==="|"&&t++;t<e.length&&/\s/.test(e[t]);)t++;continue}if(r===0&&(/\d/.test(c)||c==="-"&&/\d/.test(e[t+1]))){let l=t;for(e[l]==="-"&&l++;l<e.length&&/\d/.test(e[l]);)l++;if(l<e.length&&e[l]==="."&&/\d/.test(e[l+1]))for(l++;l<e.length&&/\d/.test(e[l]);)l++;if(l<e.length&&(e[l]==="e"||e[l]==="E"))for(l++,l<e.length&&(e[l]==="+"||e[l]==="-")&&l++;l<e.length&&/\d/.test(e[l]);)l++;for(o=!0,t=l;t<e.length&&/\s/.test(e[t]);)t++;if(t<e.length&&e[t]==="{")return{type:ne(e.slice(n,l).trim()),endPos:l};if(e[t]!=="|"&&e[t]!=="&")return{type:ne(e.slice(n,l).trim()),endPos:l};continue}if(r===0&&/[a-zA-Z_]/.test(c)){let l=t;for(;l<e.length&&/\w/.test(e[l]);)l++;for(o=!0,t=l;t<e.length&&/\s/.test(e[t]);)t++;if(t<e.length&&e[t]==="("){r++,t++;continue}if(t<e.length&&e[t]==="{"&&!e.slice(t+1).match(/^\s*(\w+)\s*:/)){let d=l;for(;d>n&&/\s/.test(e[d-1]);)d--;return{type:ne(e.slice(n,d).trim()),endPos:l}}if(e[t]!=="|"&&e[t]!=="&")return{type:ne(e.slice(n,l).trim()),endPos:l};continue}t++}return o?a(t):null}function ge(e){let n=[],t="",r=0,s=!1,i=!1,o=0;for(;o<e.length;){let a=e[o],c=e[o+1];if(!i&&a==="/"&&c==="/"){s=!0,t+="//",o+=2;continue}if(!s&&a==="/"&&c==="*"){i=!0,t+="/*",o+=2;continue}if(s&&a===`
|
|
7
|
-
`){s=!1,t+=a,o++;continue}if(i&&a==="*"&&c==="/"){i=!1,t+="*/",o+=2;continue}if(s||i){t+=a,o++;continue}a==="("||a==="{"||a==="["?(r++,t+=a):a===")"||a==="}"||a==="]"?(r--,t+=a):a===","&&r===0?(n.push(t),t=""):t+=a,o++}return t.trim()&&n.push(t),n}function Me(e,n,t){let r=ye(e,{originalSource:e,requiredParams:n.requiredParams,unsafeFunctions:n.unsafeFunctions,safeFunctions:n.safeFunctions}).source,s=ge(r),i=!1,o=new Set,a=l=>{if(t&&/^\w+$/.test(l)){if(o.has(l))throw new Error(`Duplicate parameter name '${l}'`);o.add(l)}};return s.map(l=>{let p=l.trim();if(!p)return l;if(t&&p.startsWith("{")&&p.endsWith("}")){let m=p.slice(1,-1);return`{ ${Je(m,n)} }`}if(t&&p.startsWith("[")&&p.endsWith("]")){let m=p.slice(1,-1);return`[ ${Je(m,n)} ]`}if(p.startsWith("...")){let m=ze(p);return m!==-1?p.slice(0,m).trim():l}let d=p.match(/^(\w+)\s*\?\s*:\s*(.+)$/);if(d){let[,m,y]=d;return a(m),i=!0,`${m} = ${y}`}if(!Wn(p)){let m=p.match(/^(\w+)\s*=/);return m&&a(m[1]),i=!0,l}let u=ze(p);if(u!==-1){let m=p.slice(0,u).trim(),y=p.slice(u+1).trim();return a(m),i&&t&&/^\w+$/.test(m),t&&/^\w+$/.test(m)&&n.requiredParams.add(m),`${m} = ${y}`}return l}).join(",")}function Je(e,n){return ge(e).map(s=>{let i=s.trim();if(!i)return s;let o=i.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(o){let[,l,p]=o;n.requiredParams.add(l);let d=de(p);return`${l} = ${d}`}let a=i.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(a){let[,l,p]=a;n.requiredParams.add(l);let d=me(p);return`${l} = ${d}`}let c=i.match(/^(\w+)\s*:\s*([\s\S]+)$/);if(c){let[,l,p]=c;return n.requiredParams.add(l),`${l} = ${p}`}return s}).join(", ")}function de(e){let n=e.slice(1,-1).trim();return`{ ${ge(n).map(s=>{let i=s.trim();if(!i)return s;let o=i.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(o){let[,d,u]=o;return`${d}: ${de(u)}`}let a=i.match(/^(\w+)\s*=\s*(\{[\s\S]*\})$/);if(a){let[,d,u]=a;return`${d}: ${de(u)}`}let c=i.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(c){let[,d,u]=c;return`${d}: ${me(u)}`}let l=i.match(/^(\w+)\s*=\s*(\[[\s\S]*\])$/);if(l){let[,d,u]=l;return`${d}: ${me(u)}`}let p=i.match(/^(\w+)\s*=\s*([\s\S]+)$/);if(p){let[,d,u]=p;return`${d}: ${u}`}return s}).join(", ")} }`}function me(e){let n=e.slice(1,-1).trim();return`[ ${ge(n).map(s=>{let i=s.trim();return i?i.startsWith("{")&&i.endsWith("}")?de(i):i.startsWith("[")&&i.endsWith("]")?me(i):s:s}).join(", ")} ]`}function Wn(e){let n=0,t=!1,r=!1,s=!1,i="";for(let o=0;o<e.length;o++){let a=e[o];if(!s&&(a==="'"||a==='"'||a==="`")){s=!0,i=a;continue}if(s){a===i&&e[o-1]!=="\\"&&(s=!1);continue}a==="("||a==="{"||a==="["?n++:a===")"||a==="}"||a==="]"?n--:n===0&&(a===":"&&(t=!0),a==="="&&e[o+1]!==">"&&(r=!0))}return t&&!r}function ze(e){let n=0,t=!1,r="";for(let s=0;s<e.length;s++){let i=e[s];if(!t&&(i==="'"||i==='"'||i==="`")){t=!0,r=i;continue}if(t){i===r&&e[s-1]!=="\\"&&(t=!1);continue}if(i==="("||i==="{"||i==="[")n++;else if(i===")"||i==="}"||i==="]")n--;else if(n===0&&i===":")return s}return-1}function Vn(e,n){let t=e.match(n);if(!t)return null;let r=t.index+t[0].length-1,s=1,i=r+1;for(;i<e.length&&s>0;)e[i]==="{"?s++:e[i]==="}"&&s--,i++;if(s!==0)return null;let o=e.slice(r,i),a=[t[0].slice(0,-1)+o,o];return a.index=t.index,a}function Xe(e){let n="",t=0;for(;t<e.length;){let r=e.slice(t).match(/^\btry\s*\{/);if(r){let i=t+r[0].length-1+1,o=1,a=i;for(;a<e.length&&o>0;){let l=e[a];l==="{"?o++:l==="}"&&o--,a++}if(o!==0){n+=e[t],t++;continue}if(e.slice(a).match(/^\s*(catch|finally)\b/))n+=e.slice(t,a),t=a;else{let l=e.slice(i,a-1);n+=`try {${l}} catch (__try_err) { return new (__tjs?.MonadicError ?? Error)(__try_err?.message || String(__try_err), 'try', undefined, undefined, __tjs?.getStack?.()) }`,t=a}}else n+=e[t],t++}return n}function Qe(e){let n=[],t="",r=0,s=0;for(;r<e.length;){let i=e.slice(r).match(/^\bwasm\s*\{/);if(i){let o=r,a=r+i[0].length,c=1,l=a;for(;l<e.length&&c>0;){let $=e[l];$==="{"?c++:$==="}"&&c--,l++}if(c!==0){t+=e[r],r++;continue}let p=e.slice(a,l-1),d,u=l,m=e.slice(l).match(/^\s*fallback\s*\{/);if(m){let $=l+m[0].length;c=1;let T=$;for(;T<e.length&&c>0;){let v=e[T];v==="{"?c++:v==="}"&&c--,T++}c===0&&(d=e.slice($,T-1),u=T)}let b=zn(p).map($=>{let T=Zn(e,o,$);return T?`${$}: ${T}`:$}),h={id:`__tjs_wasm_${s}`,body:p,fallback:d,captures:b,start:o,end:u};n.push(h);let S=d??p,x=b.map($=>$.split(":")[0].trim()),g=x.length>0?x.join(", "):"",E=x.length>0?`globalThis.${h.id}(${g})`:`globalThis.${h.id}()`,A=`(globalThis.${h.id} ? ${E} : (() => {${S}})())`;t+=A,r=u,s++}else t+=e[r],r++}return{source:t,blocks:n}}function Jn(e){return e.startsWith("f32x4_")||e.startsWith("v128_")}function zn(e){let n=e.replace(/\/\/[^\n]*/g,"").replace(/\/\*[\s\S]*?\*\//g,""),t=new Set,r=/\.([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,s;for(;(s=r.exec(n))!==null;)t.add(s[1]);let i=/(?<!\.)(\b[a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,o=new Set;for(;(s=i.exec(n))!==null;)o.add(s[1]);for(let u of t){if(!o.has(u))continue;let m=new RegExp(`(?<!\\.)\\b${u}\\b`,"g"),y=new RegExp(`\\.${u}\\b`,"g"),b=n.match(m)?.length||0,h=n.match(y)?.length||0;b<=h&&o.delete(u)}let a=new Set,c=/\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=c.exec(n))!==null;)a.add(s[1]);let l=/\bfor\s*\(\s*(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=l.exec(n))!==null;)a.add(s[1]);let p=new Set(["if","else","for","while","do","switch","case","break","continue","return","function","let","const","var","new","this","true","false","null","undefined","typeof","instanceof","in","of","try","catch","finally","throw","async","await","class","extends","super","import","export","default","from","as","static","get","set","yield","console","Math","Array","Object","String","Number","Boolean","Date","JSON","Promise","Map","Set","WeakMap","WeakSet","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array","ArrayBuffer","DataView","Error","TypeError","RangeError","length","push","pop","shift","unshift","slice","splice","map","filter","reduce","forEach","find","findIndex","indexOf","includes","globalThis","window","document","Infinity","NaN","isNaN","isFinite","parseInt","parseFloat","encodeURI","decodeURI","eval","wasmBuffer"]),d=[];for(let u of o)!a.has(u)&&!p.has(u)&&!Jn(u)&&d.push(u);return d.sort()}function Zn(e,n,t){let r=e.slice(0,n),s=/function\s+\w+\s*\(([^)]*)\)\s*(?:->.*?)?\s*\{[^}]*$/,i=r.match(s);if(!i){let o=/(?:const|let|var)?\s*\w+\s*=\s*(?:async\s*)?\(([^)]*)\)\s*(?:=>|->)?\s*\{[^}]*$/,a=r.match(o);return a?Ge(a[1],t):void 0}return Ge(i[1],t)}function Ge(e,n){let t=e.split(",").map(r=>r.trim());for(let r of t){let s=r.match(new RegExp(`^${n}\\s*:\\s*([A-Za-z][A-Za-z0-9]*)`));if(s)return s[1];let i=r.match(new RegExp(`^${n}\\s*=\\s*(Float32Array|Float64Array|Int32Array|Uint8Array|Int8Array|Int16Array|Uint16Array|Uint32Array)`));if(i)return i[1]}}function et(e){let n=`([\\w][\\w.\\[\\]()]*|null|undefined|true|false|\\d+(?:\\.\\d+)?|'[^']*'|"[^"]*")`,t=new RegExp(n+"\\s+IsNot\\s+"+n,"g");e=e.replace(t,"IsNot($1, $2)");let r=new RegExp(n+"\\s+Is\\s+"+n,"g");return e=e.replace(r,"Is($1, $2)"),e}function tt(e){let n=/^[\s]*[([
|
|
7
|
+
`){s=!1,t+=a,o++;continue}if(i&&a==="*"&&c==="/"){i=!1,t+="*/",o+=2;continue}if(s||i){t+=a,o++;continue}a==="("||a==="{"||a==="["?(r++,t+=a):a===")"||a==="}"||a==="]"?(r--,t+=a):a===","&&r===0?(n.push(t),t=""):t+=a,o++}return t.trim()&&n.push(t),n}function Me(e,n,t){let r=ye(e,{originalSource:e,requiredParams:n.requiredParams,unsafeFunctions:n.unsafeFunctions,safeFunctions:n.safeFunctions}).source,s=ge(r),i=!1,o=new Set,a=l=>{if(t&&/^\w+$/.test(l)){if(o.has(l))throw new Error(`Duplicate parameter name '${l}'`);o.add(l)}};return s.map(l=>{let p=l.trim();if(!p)return l;if(t&&p.startsWith("{")&&p.endsWith("}")){let m=p.slice(1,-1);return`{ ${Je(m,n)} }`}if(t&&p.startsWith("[")&&p.endsWith("]")){let m=p.slice(1,-1);return`[ ${Je(m,n)} ]`}if(p.startsWith("...")){let m=ze(p);return m!==-1?p.slice(0,m).trim():l}let d=p.match(/^(\w+)\s*\?\s*:\s*(.+)$/);if(d){let[,m,y]=d;return a(m),i=!0,`${m} = ${y}`}if(!Wn(p)){let m=p.match(/^(\w+)\s*=/);return m&&a(m[1]),i=!0,l}let u=ze(p);if(u!==-1){let m=p.slice(0,u).trim(),y=p.slice(u+1).trim();return a(m),i&&t&&/^\w+$/.test(m),t&&/^\w+$/.test(m)&&n.requiredParams.add(m),`${m} = ${y}`}return l}).join(",")}function Je(e,n){return ge(e).map(s=>{let i=s.trim();if(!i)return s;let o=i.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(o){let[,l,p]=o;n.requiredParams.add(l);let d=de(p);return`${l} = ${d}`}let a=i.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(a){let[,l,p]=a;n.requiredParams.add(l);let d=me(p);return`${l} = ${d}`}let c=i.match(/^(\w+)\s*:\s*([\s\S]+)$/);if(c){let[,l,p]=c;return n.requiredParams.add(l),`${l} = ${p}`}return s}).join(", ")}function de(e){let n=e.slice(1,-1).trim();return`{ ${ge(n).map(s=>{let i=s.trim();if(!i)return s;let o=i.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(o){let[,d,u]=o;return`${d}: ${de(u)}`}let a=i.match(/^(\w+)\s*=\s*(\{[\s\S]*\})$/);if(a){let[,d,u]=a;return`${d}: ${de(u)}`}let c=i.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(c){let[,d,u]=c;return`${d}: ${me(u)}`}let l=i.match(/^(\w+)\s*=\s*(\[[\s\S]*\])$/);if(l){let[,d,u]=l;return`${d}: ${me(u)}`}let p=i.match(/^(\w+)\s*=\s*([\s\S]+)$/);if(p){let[,d,u]=p;return`${d}: ${u}`}return s}).join(", ")} }`}function me(e){let n=e.slice(1,-1).trim();return`[ ${ge(n).map(s=>{let i=s.trim();return i?i.startsWith("{")&&i.endsWith("}")?de(i):i.startsWith("[")&&i.endsWith("]")?me(i):s:s}).join(", ")} ]`}function Wn(e){let n=0,t=!1,r=!1,s=!1,i="";for(let o=0;o<e.length;o++){let a=e[o];if(!s&&(a==="'"||a==='"'||a==="`")){s=!0,i=a;continue}if(s){a===i&&e[o-1]!=="\\"&&(s=!1);continue}a==="("||a==="{"||a==="["?n++:a===")"||a==="}"||a==="]"?n--:n===0&&(a===":"&&(t=!0),a==="="&&e[o+1]!==">"&&(r=!0))}return t&&!r}function ze(e){let n=0,t=!1,r="";for(let s=0;s<e.length;s++){let i=e[s];if(!t&&(i==="'"||i==='"'||i==="`")){t=!0,r=i;continue}if(t){i===r&&e[s-1]!=="\\"&&(t=!1);continue}if(i==="("||i==="{"||i==="[")n++;else if(i===")"||i==="}"||i==="]")n--;else if(n===0&&i===":")return s}return-1}function Vn(e,n){let t=e.match(n);if(!t)return null;let r=t.index+t[0].length-1,s=1,i=r+1;for(;i<e.length&&s>0;)e[i]==="{"?s++:e[i]==="}"&&s--,i++;if(s!==0)return null;let o=e.slice(r,i),a=[t[0].slice(0,-1)+o,o];return a.index=t.index,a}function Xe(e){let n="",t=0;for(;t<e.length;){let r=e.slice(t).match(/^\btry\s*\{/);if(r){let i=t+r[0].length-1+1,o=1,a=i;for(;a<e.length&&o>0;){let l=e[a];l==="{"?o++:l==="}"&&o--,a++}if(o!==0){n+=e[t],t++;continue}if(e.slice(a).match(/^\s*(catch|finally)\b/))n+=e.slice(t,a),t=a;else{let l=e.slice(i,a-1);n+=`try {${l}} catch (__try_err) { return new (__tjs?.MonadicError ?? Error)(__try_err?.message || String(__try_err), 'try', undefined, undefined, __tjs?.getStack?.()) }`,t=a}}else n+=e[t],t++}return n}function Qe(e){let n=[],t="",r=0,s=0;for(;r<e.length;){let i=e.slice(r).match(/^\bwasm\s*\{/);if(i){let o=r,a=r+i[0].length,c=1,l=a;for(;l<e.length&&c>0;){let $=e[l];$==="{"?c++:$==="}"&&c--,l++}if(c!==0){t+=e[r],r++;continue}let p=e.slice(a,l-1),d,u=l,m=e.slice(l).match(/^\s*fallback\s*\{/);if(m){let $=l+m[0].length;c=1;let T=$;for(;T<e.length&&c>0;){let v=e[T];v==="{"?c++:v==="}"&&c--,T++}c===0&&(d=e.slice($,T-1),u=T)}let b=zn(p).map($=>{let T=Zn(e,o,$);return T?`${$}: ${T}`:$}),h={id:`__tjs_wasm_${s}`,body:p,fallback:d,captures:b,start:o,end:u};n.push(h);let S=d??p,x=b.map($=>$.split(":")[0].trim()),g=x.length>0?x.join(", "):"",E=x.length>0?`globalThis.${h.id}(${g})`:`globalThis.${h.id}()`,A=`(globalThis.${h.id} ? ${E} : (() => {${S}})())`;t+=A,r=u,s++}else t+=e[r],r++}return{source:t,blocks:n}}function Jn(e){return e.startsWith("f32x4_")||e.startsWith("v128_")}function zn(e){let n=e.replace(/\/\/[^\n]*/g,"").replace(/\/\*[\s\S]*?\*\//g,""),t=new Set,r=/\.([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,s;for(;(s=r.exec(n))!==null;)t.add(s[1]);let i=/(?<!\.)(\b[a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,o=new Set;for(;(s=i.exec(n))!==null;)o.add(s[1]);for(let u of t){if(!o.has(u))continue;let m=new RegExp(`(?<!\\.)\\b${u}\\b`,"g"),y=new RegExp(`\\.${u}\\b`,"g"),b=n.match(m)?.length||0,h=n.match(y)?.length||0;b<=h&&o.delete(u)}let a=new Set,c=/\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=c.exec(n))!==null;)a.add(s[1]);let l=/\bfor\s*\(\s*(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=l.exec(n))!==null;)a.add(s[1]);let p=new Set(["if","else","for","while","do","switch","case","break","continue","return","function","let","const","var","new","this","true","false","null","undefined","typeof","instanceof","in","of","try","catch","finally","throw","async","await","class","extends","super","import","export","default","from","as","static","get","set","yield","console","Math","Array","Object","String","Number","Boolean","Date","JSON","Promise","Map","Set","WeakMap","WeakSet","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint16Array","Uint32Array","BigInt64Array","BigUint64Array","ArrayBuffer","DataView","Error","TypeError","RangeError","length","push","pop","shift","unshift","slice","splice","map","filter","reduce","forEach","find","findIndex","indexOf","includes","globalThis","window","document","Infinity","NaN","isNaN","isFinite","parseInt","parseFloat","encodeURI","decodeURI","eval","wasmBuffer"]),d=[];for(let u of o)!a.has(u)&&!p.has(u)&&!Jn(u)&&d.push(u);return d.sort()}function Zn(e,n,t){let r=e.slice(0,n),s=/function\s+\w+\s*\(([^)]*)\)\s*(?:->.*?)?\s*\{[^}]*$/,i=r.match(s);if(!i){let o=/(?:const|let|var)?\s*\w+\s*=\s*(?:async\s*)?\(([^)]*)\)\s*(?:=>|->)?\s*\{[^}]*$/,a=r.match(o);return a?Ge(a[1],t):void 0}return Ge(i[1],t)}function Ge(e,n){let t=e.split(",").map(r=>r.trim());for(let r of t){let s=r.match(new RegExp(`^${n}\\s*:\\s*([A-Za-z][A-Za-z0-9]*)`));if(s)return s[1];let i=r.match(new RegExp(`^${n}\\s*=\\s*(Float32Array|Float64Array|Int32Array|Uint8Array|Int8Array|Int16Array|Uint16Array|Uint32Array)`));if(i)return i[1]}}function et(e){let n=`([\\w][\\w.\\[\\]()]*|null|undefined|true|false|\\d+(?:\\.\\d+)?|'[^']*'|"[^"]*")`,t=new RegExp(n+"\\s+IsNot\\s+"+n,"g");e=e.replace(t,"IsNot($1, $2)");let r=new RegExp(n+"\\s+Is\\s+"+n,"g");return e=e.replace(r,"Is($1, $2)"),e}function tt(e){let n=/^[\s]*[([`]/,t=/[{([,;:+\-*/%=&|?<>!~^]\s*$|^\s*$/,r=/\b(return|throw|yield|await|case|default|extends|new|typeof|void|delete|in|of|instanceof)\s*$/,s=e.split(`
|
|
8
8
|
`),i=[],o=!1;for(let a=0;a<s.length;a++){let c=s[a],l=a>0?s[a-1]:"";if(o){i.push(c),c.includes("*/")&&(o=!1);continue}let p=c.indexOf("/*"),d=c.indexOf("*/");if(p!==-1&&(d===-1||d<p)){o=!0,i.push(c);continue}if(a>0&&n.test(c)){let u=l.replace(/\/\/.*$/,"").replace(/\/\*.*\*\/\s*$/,"");if(!t.test(u)&&!r.test(u)){let m=c.match(/^(\s*)/),y=m?m[1]:"",b=c.slice(y.length);i.push(y+";"+b);continue}}i.push(c)}return i.join(`
|
|
9
9
|
`)}function nt(e){e=e.replace(/\btypeof\s+([a-zA-Z_$][\w$.]*(?:\?\.[\w$]+)*)/g,"TypeOf($1)");let n=[],t=0,r="normal",s=[];for(;t<e.length;){let o=e[t],a=e[t+1];switch(r){case"single-string":if(o==="\\"&&t+1<e.length){t+=2;continue}o==="'"&&(r="normal"),t++;continue;case"double-string":if(o==="\\"&&t+1<e.length){t+=2;continue}o==='"'&&(r="normal"),t++;continue;case"template-string":if(o==="\\"&&t+1<e.length){t+=2;continue}if(o==="$"&&a==="{"){t+=2,s.push(1),r="normal";continue}o==="`"&&(r="normal"),t++;continue;case"line-comment":o===`
|
|
10
10
|
`&&(r="normal"),t++;continue;case"block-comment":if(o==="*"&&a==="/"){t+=2,r="normal";continue}t++;continue;case"regex":if(o==="\\"&&t+1<e.length){t+=2;continue}if(o==="["){for(t++;t<e.length&&e[t]!=="]";)e[t]==="\\"&&t+1<e.length?t+=2:t++;t<e.length&&t++;continue}if(o==="/"){for(t++;t<e.length&&/[gimsuy]/.test(e[t]);)t++;r="normal";continue}t++;continue;case"normal":if(s.length>0){if(o==="{")s[s.length-1]++;else if(o==="}"&&(s[s.length-1]--,s[s.length-1]===0)){s.pop(),t++,r="template-string";continue}}if(o==="'"){t++,r="single-string";continue}if(o==='"'){t++,r="double-string";continue}if(o==="`"){t++,r="template-string";continue}if(o==="/"&&a==="/"){t+=2,r="line-comment";continue}if(o==="/"&&a==="*"){t+=2,r="block-comment";continue}if(o==="/"){let c=t-1;for(;c>=0&&/\s/.test(e[c]);)c--;let l=c>=0?e[c]:"";if(!l||/[=(!,;:{[&|?+\-*%<>~^]/.test(l)||c>=5&&/\b(return|case|throw|in|of|typeof|instanceof|new|delete|void)$/.test(e.slice(Math.max(0,c-10),c+1))){t++,r="regex";continue}}if(o==="="&&a==="="&&e[t+2]!=="="&&e[t-1]!=="!"){n.push({pos:t,op:"=="}),t+=2;continue}if(o==="!"&&a==="="&&e[t+2]!=="="){n.push({pos:t,op:"!="}),t+=2;continue}break}t++}if(n.length===0)return e;let i=e;for(let o=n.length-1;o>=0;o--){let{pos:a,op:c}=n[o],l=c==="=="?"Eq":"NotEq",p=Gn(i,a),d=Hn(i,a+2),u=i.slice(p,a).trim(),m=i.slice(a+2,d).trim();if(u&&m){let y=i.slice(0,p),b=i.slice(d),S=/[a-zA-Z0-9_$]$/.test(y)?" ":"";i=`${y}${S}${l}(${u}, ${m})${b}`}}return i}function Gn(e,n){let t=n-1;for(;t>=0&&/\s/.test(e[t]);)t--;if(t<0)return 0;let r=0,s=!1,i="";for(;t>=0;){let o=e[t],a=t>0?e[t-1]:"";if(s){o===i&&a!=="\\"&&(s=!1),t--;continue}if((o==='"'||o==="'"||o==="`")&&a!=="\\"){s=!0,i=o,t--;continue}if(o===")"||o==="]"||o==="}"){r++,t--;continue}if(o==="("||o==="["){if(r>0){r--,t--;continue}return t+1}if(o==="{"){if(r>0){r--,t--;continue}return t+1}if(r>0){t--;continue}if(o===";")return t+1;if(/[a-z]/.test(o)){let c=t+1,l=t;for(;l>0&&/[a-z]/i.test(e[l-1]);)l--;let p=e.slice(l,c),d=l>0?e[l-1]:"";if(!/[a-zA-Z0-9_$]/.test(d)){if(["return","throw","case","typeof","void","delete","await","yield"].includes(p))return c;if(p==="new")return l}}if(o===">"&&a==="="||o==="="&&a!=="="&&a!=="!"&&a!=="<"&&a!==">"||o==="&"&&a==="&"||o==="|"&&a==="|"||o==="?"||o===":"||o===",")return t+1;t--}return 0}function Hn(e,n){let t=n;for(;t<e.length&&/\s/.test(e[t]);)t++;if(t>=e.length)return e.length;let r=0,s=!1,i="";for(;t<e.length;){let o=e[t],a=t+1<e.length?e[t+1]:"";if(s){o===i&&e[t-1]!=="\\"&&(s=!1),t++;continue}if((o==='"'||o==="'"||o==="`")&&e[t-1]!=="\\"){s=!0,i=o,t++;continue}if(o==="("||o==="["||o==="{"){r++,t++;continue}if(o===")"||o==="]"||o==="}"){if(r>0){r--,t++;continue}return t}if(r>0){t++;continue}if(o===";"||o==="&"&&a==="&"||o==="|"&&a==="|"||o==="?"||o===":"||o===","||(o==="="||o==="!")&&a==="="&&e[t+2]!=="=")return t;t++}return e.length}function rt(e){let n="",t=0;for(;t<e.length;){let r=e.slice(t).match(/^\bType\s+([A-Z_][a-zA-Z0-9_]*)\s*/);if(r){let s=r[1],i=t+r[0].length,o=s,a=!1,c=e.slice(i).match(/^(['"`])([^]*?)\1\s*/);if(c){let u=i+c[0].length,m=e[u],y=m===void 0||u>=e.length||m!=="="&&m!=="{";if(m==="="||m==="{")o=c[2],a=!0,i=u;else if(y){let b=c[0].trim(),h=c[0].slice(b.length);n+=`const ${s} = Type('${s}', ${b})${h}`,t=u;continue}}let l,p=i,d=e.slice(i).match(/^=\s*/);if(d){i+=d[0].length;let u=e.slice(i).match(/^(\+?\d+(?:\.\d+)?|['"`][^'"`]*['"`]|\{[^}]*\}|\[[^\]]*\]|true|false|null)/);if(u){l=u[0],i+=u[0].length,p=i;let m=e.slice(i).match(/^\s*/);m&&(i+=m[0].length)}}if(e[i]==="{"){let u=i+1,m=1,y=u;for(;y<e.length&&m>0;){let A=e[y];A==="{"?m++:A==="}"&&m--,y++}if(m!==0){n+=e[t],t++;continue}let b=e.slice(u,y-1).trim(),h=y,S=b.match(/description\s*:\s*(['"`])([^]*?)\1/);S&&!a&&(o=S[2]);let x,g=b.match(/example\s*:\s*/);if(g){let A=g.index+g[0].length,$=Ze(b,A);$&&(x=$.value.trim())}let E=b.match(/predicate\s*\(([^)]*)\)\s*\{([^]*)\}/);if(E&&x){let A=E[1].trim(),$=E[2].trim(),T=l?`, ${l}`:"";n+=`const ${s} = Type('${o}', (${A}) => { if (!globalThis.__tjs?.validate(${A}, globalThis.__tjs?.infer(${x}))) return false; ${$} }, ${x}${T})`}else if(E){let A=E[1].trim(),$=E[2].trim(),T=l?`, undefined, ${l}`:"";n+=`const ${s} = Type('${o}', (${A}) => { ${$} }${T})`}else if(x){let A=l?`, ${l}`:"";n+=`const ${s} = Type('${o}', undefined, ${x}${A})`}else l?n+=`const ${s} = Type('${o}', ${l})`:n+=`const ${s} = Type('${o}')`;t=h;continue}else if(l){n+=`const ${s} = Type('${o}', ${l})`,t=p;continue}else if(!c){let u=e.slice(i).match(/^(['"`][^]*?['"`]|\+?\d+(?:\.\d+)?|true|false|null|\{[^]*?\}|\[[^]*?\])/);if(u){let m=u[0];n+=`const ${s} = Type('${s}', ${m})`,t=i+u[0].length;continue}}}n+=e[t],t++}return n}function st(e){let n="",t=0;for(;t<e.length;){let r=e.slice(t).match(/^\bFunctionPredicate\s+([A-Z_][a-zA-Z0-9_]*)\s*(?:<([^>]+)>)?\s*/);if(r){let s=r[1],i=r[2],o=t+r[0].length;if(e[o]==="{"){let a=1,c=o+1;for(;c<e.length&&a>0;)e[c]==="{"?a++:e[c]==="}"&&a--,c++;if(a===0){let l=e.slice(o+1,c-1).trim(),p=Vn(l,/params\s*:\s*\{/),d=l.match(/returns\s*:\s*(.+?)(?:\n|$)/),u=l.match(/returnContract\s*:\s*['"](\w+)['"]/),m=l.match(/description\s*:\s*(['"])([^]*?)\1/),y=[];p&&y.push(`params: ${p[1]}`),d&&y.push(`returns: ${d[1].trim()}`),u&&y.push(`returnContract: '${u[1]}'`);let b=m?m[2]:s;if(i){let h=i.split(",").map(x=>{let g=x.trim().split("=").map(E=>E.trim());if(g.length===2){let E=g[1]==="any"||g[1]==="undefined"?"null":g[1];return`['${g[0]}', ${E}]`}return`'${g[0]}'`}),S=i.split(",").map(x=>x.trim().split("=")[0].trim());n+=`const ${s} = FunctionPredicate('${b}', [${h.join(", ")}], (${S.join(", ")}) => ({ ${y.join(", ")} }))`}else n+=`const ${s} = FunctionPredicate('${b}', { ${y.join(", ")} })`;t=c;continue}}if(e[o]==="("){let a=1,c=o+1;for(;c<e.length&&a>0;)e[c]==="("?a++:e[c]===")"&&a--,c++;if(a===0){let l=e.slice(o+1,c-1).trim(),p=l.indexOf(",");if(p!==-1){let d=l.slice(0,p).trim(),u=l.slice(p+1).trim();n+=`const ${s} = FunctionPredicate(${u}, ${d})`}else n+=`const ${s} = FunctionPredicate('${s}', ${l})`;t=c;continue}}}n+=e[t],t++}return n}function ot(e){let n="",t=0;for(;t<e.length;){let r=e.slice(t).match(/^\bGeneric\s+([A-Z][a-zA-Z0-9_]*)\s*<([^>]+)>\s*\{/);if(r){let s=r[1],i=r[2],a=t+r[0].length-1+1,c=1,l=a;for(;l<e.length&&c>0;){let x=e[l];x==="{"?c++:x==="}"&&c--,l++}if(c!==0){n+=e[t],t++;continue}let p=e.slice(a,l-1).trim(),d=l,u=i.split(",").map(x=>{let g=x.trim().split("=").map(E=>E.trim());if(g.length===2){let E=g[1]==="any"||g[1]==="undefined"?"null":g[1];return`['${g[0]}', ${E}]`}return`'${g[0]}'`}),m=p,y=m.search(/\bdeclaration\s*\{/);if(y!==-1){let x=m.indexOf("{",y),g=1,E=x+1;for(;E<m.length&&g>0;)m[E]==="{"?g++:m[E]==="}"&&g--,E++;m=m.slice(0,y)+m.slice(E)}let b=m.match(/description\s*:\s*(['"`])([^]*?)\1/),h=m.match(/predicate\s*\(([^)]*)\)\s*\{([^]*)\}/),S=b?b[2]:s;if(h){let x=h[1].trim().split(",").map(T=>T.trim()),g=h[2].trim(),E=x[0]||"x",A=x.slice(1),$=A.map(T=>`check${T}`);A.forEach((T,v)=>{g=g.replace(new RegExp(`\\b${T}\\s*\\(`,"g"),`${$[v]}(`)}),n+=`const ${s} = Generic([${u.join(", ")}], (${E}, ${$.join(", ")}) => { ${g} }, '${S}')`}else n+=`const ${s} = Generic([${u.join(", ")}], () => true, '${S}')`;t=d;continue}n+=e[t],t++}return n}function it(e){let n="",t=0;for(;t<e.length;){let r=e.slice(t).match(/^\bUnion\s+([A-Z][a-zA-Z0-9_]*)\s+(['"`])([^]*?)\2\s*/);if(r){let s=r[1],i=r[3],o=t+r[0].length;if(e[o]==="{"){let a=o+1,c=1,l=a;for(;l<e.length&&c>0;){let m=e[l];m==="{"?c++:m==="}"&&c--,l++}if(c!==0){n+=e[t],t++;continue}let p=e.slice(a,l-1).trim(),d=l,u=He(p);n+=`const ${s} = Union('${i}', [${u.join(", ")}])`,t=d;continue}else{let a=e.indexOf(`
|