tjs-lang 0.8.3 → 0.8.5
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/CLAUDE.md +23 -1
- package/demo/docs.json +7 -7
- package/dist/experiments/predicates/css.predicates.d.ts +13 -0
- package/dist/experiments/predicates/verify.d.ts +39 -0
- package/dist/index.js +104 -100
- package/dist/index.js.map +4 -4
- package/dist/src/lang/browser-from-ts.d.ts +38 -0
- package/dist/src/lang/browser.d.ts +13 -0
- package/dist/src/lang/index.d.ts +2 -0
- package/dist/src/lang/predicate-schema.d.ts +39 -0
- package/dist/src/lang/predicate.d.ts +103 -0
- package/dist/src/lang/transpiler.d.ts +2 -0
- package/dist/src/lang/ts-cdn-shim.d.ts +2 -0
- package/dist/src/vm/runtime.d.ts +22 -0
- package/dist/tjs-browser-from-ts.js +58 -0
- package/dist/tjs-browser-from-ts.js.map +7 -0
- package/dist/tjs-browser.js +370 -0
- package/dist/tjs-browser.js.map +7 -0
- package/dist/tjs-eval.js +29 -29
- package/dist/tjs-eval.js.map +3 -3
- package/dist/tjs-from-ts.js +1 -1
- package/dist/tjs-from-ts.js.map +2 -2
- package/dist/tjs-lang.js +86 -82
- package/dist/tjs-lang.js.map +4 -4
- package/dist/tjs-vm.js +45 -45
- package/dist/tjs-vm.js.map +3 -3
- package/llms.txt +2 -0
- package/package.json +15 -1
- package/src/lang/browser-bundle.test.ts +69 -0
- package/src/lang/browser-from-ts.ts +81 -0
- package/src/lang/browser.ts +13 -0
- package/src/lang/runtime.test.ts +46 -0
- package/src/lang/ts-cdn-shim.ts +35 -0
- package/src/runtime.test.ts +6 -6
- package/src/vm/equality.test.ts +59 -0
- package/src/vm/runtime.ts +26 -59
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
var fa=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ei=fa((Pc,Fo)=>{Fo.exports={name:"tjs-lang",version:"0.8.5",description:"Type-safe JavaScript dialect with runtime validation, sandboxed VM execution, and AI agent orchestration. Transpiles TypeScript to validated JS with fuel-metered execution for untrusted code.",keywords:["typescript","transpiler","runtime-validation","type-safety","sandbox","virtual-machine","wasm-alternative","ai-agents","llm","orchestration","security","fuel-metering","capability-based","json-ast","untrusted-code"],license:"Apache-2.0",main:"./dist/index.js",types:"./dist/src/index.d.ts",typesVersions:{"*":{eval:["./dist/src/lang/eval.d.ts"],lang:["./dist/src/lang/transpiler.d.ts"],"lang/from-ts":["./dist/src/lang/emitters/from-ts.d.ts"],browser:["./dist/src/lang/browser.d.ts"],"browser/from-ts":["./dist/src/lang/browser-from-ts.d.ts"],vm:["./dist/src/vm/index.d.ts"],batteries:["./dist/src/batteries/index.d.ts"]}},exports:{".":{bun:"./src/index.ts",types:"./dist/src/index.d.ts",default:"./dist/index.js"},"./eval":{bun:"./src/lang/eval.ts",types:"./dist/src/lang/eval.d.ts",default:"./dist/tjs-eval.js"},"./lang":{bun:"./src/lang/transpiler.ts",types:"./dist/src/lang/transpiler.d.ts",default:"./dist/tjs-lang.js"},"./lang/from-ts":{bun:"./src/lang/emitters/from-ts.ts",types:"./dist/src/lang/emitters/from-ts.d.ts",default:"./dist/tjs-from-ts.js"},"./browser":{types:"./dist/src/lang/browser.d.ts",default:"./dist/tjs-browser.js"},"./browser/from-ts":{types:"./dist/src/lang/browser-from-ts.d.ts",default:"./dist/tjs-browser-from-ts.js"},"./vm":{bun:"./src/vm/index.ts",types:"./dist/src/vm/index.d.ts",default:"./dist/tjs-vm.js"},"./batteries":{bun:"./src/batteries/index.ts",types:"./dist/src/batteries/index.d.ts",default:"./dist/tjs-batteries.js"},"./linalg":{bun:"./src/linalg/index.tjs",default:"./dist/tjs-linalg.js"},"./src":"./src/index.ts","./editors/monaco":"./editors/monaco/ajs-monarch.js","./editors/codemirror":"./editors/codemirror/ajs-language.js","./editors/ace":"./editors/ace/ajs-mode.js"},bin:{tjs:"./src/cli/tjs.ts",tjsx:"./src/cli/tjsx.ts","tjs-playground":"./src/cli/playground.ts","create-tjs-app":"./src/cli/create-app.ts","ajs-install-vscode":"./bin/install-vscode.sh","ajs-install-cursor":"./bin/install-cursor.sh"},type:"module",files:["dist","src","docs","editors","bin","demo","tjs-lang.svg","CONTEXT.md","CLAUDE.md","llms.txt"],sideEffects:!1,repository:{type:"git",url:"https://github.com/tonioloewald/tjs-lang.git"},devDependencies:{"@codemirror/lang-css":"^6.3.1","@codemirror/lang-html":"^6.4.11","@codemirror/lang-javascript":"^6.2.4","@codemirror/lang-markdown":"^6.5.0","@codemirror/state":"^6.5.3","@codemirror/theme-one-dark":"^6.1.3","@codemirror/view":"^6.39.9","@eslint/js":"^10.0.1","@happy-dom/global-registrator":"^20.1.0","@types/bun":"latest","@types/jsdom":"^21.1.7","acorn-walk":"^8.3.4",chokidar:"^4.0.3",codemirror:"^6.0.2",esbuild:"^0.28.0",eslint:"^10.4.1",firebase:"^10.12.0","firebase-admin":"^13.6.0","firebase-functions":"^7.0.5",globals:"^17.6.0",marked:"^9.1.6",prettier:"^2.8.8",tosijs:"^1.5.6","tosijs-ui":"^1.4.7",typescript:"^5.6.2","typescript-eslint":"^8.61.0",valibot:"^0.36.0",vitest:"^2.0.5"},scripts:{format:"bun eslint src --fix && bun prettier --write .",lint:"eslint src","build:grammars":"bun editors/build-grammars.ts","test:fast":"SKIP_LLM_TESTS=1 SKIP_BENCHMARKS=1 bun test","test:llm":"bun test src/batteries/models.integration.test.ts",bench:"bun bin/benchmarks.ts",make:"rm -rf dist && bun format && bun run build:grammars && tsc -p tsconfig.build.json && bun scripts/build.ts","build:bundles":"bun scripts/build.ts",typecheck:"tsc --noEmit",latest:"rm -rf node_modules && bun install",docs:"node bin/docs.js",dev:"bun run bin/dev.ts","build:demo":"bun scripts/build-demo.ts","build:cli":"bun build src/cli/tjs.ts --compile --outfile=dist/tjs && bun build src/cli/tjsx.ts --compile --outfile=dist/tjsx","functions:build":"cd functions && npm run build","functions:deploy":"cd functions && npm run deploy","functions:serve":"cd functions && npm run serve","deploy:hosting":"bun run build:demo && firebase deploy --only hosting",deploy:"bun run build:demo && bun run functions:deploy && firebase deploy --only hosting",start:"bun run build:demo && bun run dev"},dependencies:{acorn:"^8.15.0","acorn-loose":"^8.5.2","acorn-walk":"^8.3.4","tosijs-schema":"^1.3.0"}}});var pa=[509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,574,3,9,9,7,9,32,4,318,1,80,3,71,10,50,3,123,2,54,14,32,10,3,1,11,3,46,10,8,0,46,9,7,2,37,13,2,9,6,1,45,0,13,2,49,13,9,3,2,11,83,11,7,0,3,0,158,11,6,9,7,3,56,1,2,6,3,1,3,2,10,0,11,1,3,6,4,4,68,8,2,0,3,0,2,3,2,4,2,0,15,1,83,17,10,9,5,0,82,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,7,19,58,14,5,9,243,14,166,9,71,5,2,1,3,3,2,0,2,1,13,9,120,6,3,6,4,0,29,9,41,6,2,3,9,0,10,10,47,15,343,9,54,7,2,7,17,9,57,21,2,13,123,5,4,0,2,1,2,6,2,0,9,9,49,4,2,1,2,4,9,9,330,3,10,1,2,0,49,6,4,4,14,10,5350,0,7,14,11465,27,2343,9,87,9,39,4,60,6,26,9,535,9,470,0,2,54,8,3,82,0,12,1,19628,1,4178,9,519,45,3,22,543,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,1361,6,2,16,3,6,2,1,2,4,101,0,161,6,10,9,357,0,62,13,499,13,245,1,2,9,726,6,110,6,6,9,4759,9,787719,239],Yr=[0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,14,29,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,13,10,2,14,2,6,2,1,2,10,2,14,2,6,2,1,4,51,13,310,10,21,11,7,25,5,2,41,2,8,70,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,28,43,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,14,35,39,27,10,22,251,41,7,1,17,2,60,28,11,0,9,21,43,17,47,20,28,22,13,52,58,1,3,0,14,44,33,24,27,35,30,0,3,0,9,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,20,1,64,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,31,9,2,0,3,0,2,37,2,0,26,0,2,0,45,52,19,3,21,2,31,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,14,0,72,26,38,6,186,43,117,63,32,7,3,0,3,7,2,1,2,23,16,0,2,0,95,7,3,38,17,0,2,0,29,0,11,39,8,0,22,0,12,45,20,0,19,72,200,32,32,8,2,36,18,0,50,29,113,6,2,1,2,37,22,0,26,5,2,1,2,31,15,0,328,18,16,0,2,12,2,33,125,0,80,921,103,110,18,195,2637,96,16,1071,18,5,26,3994,6,582,6842,29,1763,568,8,30,18,78,18,29,19,47,17,3,32,20,6,18,433,44,212,63,129,74,6,0,67,12,65,1,2,0,29,6135,9,1237,42,9,8936,3,2,6,2,1,2,290,16,0,30,2,3,0,15,3,9,395,2309,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,1845,30,7,5,262,61,147,44,11,6,17,0,322,29,19,43,485,27,229,29,3,0,496,6,2,3,2,1,2,14,2,196,60,67,8,0,1205,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42719,33,4153,7,221,3,5761,15,7472,16,621,2467,541,1507,4938,6,4191],ha="\u200C\u200D\xB7\u0300-\u036F\u0387\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0897-\u089F\u08CA-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\u096F\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09E6-\u09EF\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A66-\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AE6-\u0AEF\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B55-\u0B57\u0B62\u0B63\u0B66-\u0B6F\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0BE6-\u0BEF\u0C00-\u0C04\u0C3C\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0CE6-\u0CEF\u0CF3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D66-\u0D6F\u0D81-\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0E50-\u0E59\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECE\u0ED0-\u0ED9\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1040-\u1049\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F-\u109D\u135D-\u135F\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u17E0-\u17E9\u180B-\u180D\u180F-\u1819\u18A9\u1920-\u192B\u1930-\u193B\u1946-\u194F\u19D0-\u19DA\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AB0-\u1ABD\u1ABF-\u1ACE\u1B00-\u1B04\u1B34-\u1B44\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BB0-\u1BB9\u1BE6-\u1BF3\u1C24-\u1C37\u1C40-\u1C49\u1C50-\u1C59\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DFF\u200C\u200D\u203F\u2040\u2054\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\u30FB\uA620-\uA629\uA66F\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA82C\uA880\uA881\uA8B4-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F1\uA8FF-\uA909\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9D0-\uA9D9\uA9E5\uA9F0-\uA9F9\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA50-\uAA59\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uABF0-\uABF9\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFF10-\uFF19\uFF3F\uFF65",Xr="\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C8A\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CD\uA7D0\uA7D1\uA7D3\uA7D5-\uA7DC\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC",Rn={3:"abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",5:"class enum extends super const export import",6:"enum",strict:"implements interface let package private protected public static yield",strictBind:"eval arguments"},Mn="break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this",da={5:Mn,"5module":Mn+" export import",6:Mn+" const class extends export import super"},ma=/^in(stanceof)?$/,ga=new RegExp("["+Xr+"]"),ya=new RegExp("["+Xr+ha+"]");function Bn(e,t){for(var n=65536,r=0;r<t.length;r+=2){if(n+=t[r],n>e)return!1;if(n+=t[r+1],n>=e)return!0}return!1}function Ce(e,t){return e<65?e===36:e<91?!0:e<97?e===95:e<123?!0:e<=65535?e>=170&&ga.test(String.fromCharCode(e)):t===!1?!1:Bn(e,Yr)}function Je(e,t){return e<48?e===36:e<58?!0:e<65?!1:e<91?!0:e<97?e===95:e<123?!0:e<=65535?e>=170&&ya.test(String.fromCharCode(e)):t===!1?!1:Bn(e,Yr)||Bn(e,pa)}var q=function(t,n){n===void 0&&(n={}),this.label=t,this.keyword=n.keyword,this.beforeExpr=!!n.beforeExpr,this.startsExpr=!!n.startsExpr,this.isLoop=!!n.isLoop,this.isAssign=!!n.isAssign,this.prefix=!!n.prefix,this.postfix=!!n.postfix,this.binop=n.binop||null,this.updateContext=null};function be(e,t){return new q(e,{beforeExpr:!0,binop:t})}var xe={beforeExpr:!0},de={startsExpr:!0},Vn={};function L(e,t){return t===void 0&&(t={}),t.keyword=e,Vn[e]=new q(e,t)}var h={num:new q("num",de),regexp:new q("regexp",de),string:new q("string",de),name:new q("name",de),privateId:new q("privateId",de),eof:new q("eof"),bracketL:new q("[",{beforeExpr:!0,startsExpr:!0}),bracketR:new q("]"),braceL:new q("{",{beforeExpr:!0,startsExpr:!0}),braceR:new q("}"),parenL:new q("(",{beforeExpr:!0,startsExpr:!0}),parenR:new q(")"),comma:new q(",",xe),semi:new q(";",xe),colon:new q(":",xe),dot:new q("."),question:new q("?",xe),questionDot:new q("?."),arrow:new q("=>",xe),template:new q("template"),invalidTemplate:new q("invalidTemplate"),ellipsis:new q("...",xe),backQuote:new q("`",de),dollarBraceL:new q("${",{beforeExpr:!0,startsExpr:!0}),eq:new q("=",{beforeExpr:!0,isAssign:!0}),assign:new q("_=",{beforeExpr:!0,isAssign:!0}),incDec:new q("++/--",{prefix:!0,postfix:!0,startsExpr:!0}),prefix:new q("!/~",{beforeExpr:!0,prefix:!0,startsExpr:!0}),logicalOR:be("||",1),logicalAND:be("&&",2),bitwiseOR:be("|",3),bitwiseXOR:be("^",4),bitwiseAND:be("&",5),equality:be("==/!=/===/!==",6),relational:be("</>/<=/>=",7),bitShift:be("<</>>/>>>",8),plusMin:new q("+/-",{beforeExpr:!0,binop:9,prefix:!0,startsExpr:!0}),modulo:be("%",10),star:be("*",10),slash:be("/",10),starstar:new q("**",{beforeExpr:!0}),coalesce:be("??",1),_break:L("break"),_case:L("case",xe),_catch:L("catch"),_continue:L("continue"),_debugger:L("debugger"),_default:L("default",xe),_do:L("do",{isLoop:!0,beforeExpr:!0}),_else:L("else",xe),_finally:L("finally"),_for:L("for",{isLoop:!0}),_function:L("function",de),_if:L("if"),_return:L("return",xe),_switch:L("switch"),_throw:L("throw",xe),_try:L("try"),_var:L("var"),_const:L("const"),_while:L("while",{isLoop:!0}),_with:L("with"),_new:L("new",{beforeExpr:!0,startsExpr:!0}),_this:L("this",de),_super:L("super",de),_class:L("class",de),_extends:L("extends",xe),_export:L("export"),_import:L("import",de),_null:L("null",de),_true:L("true",de),_false:L("false",de),_in:L("in",{beforeExpr:!0,binop:7}),_instanceof:L("instanceof",{beforeExpr:!0,binop:7}),_typeof:L("typeof",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_void:L("void",{beforeExpr:!0,prefix:!0,startsExpr:!0}),_delete:L("delete",{beforeExpr:!0,prefix:!0,startsExpr:!0})},me=/\r\n?|\n|\u2028|\u2029/,ba=new RegExp(me.source,"g");function ct(e){return e===10||e===13||e===8232||e===8233}function es(e,t,n){n===void 0&&(n=e.length);for(var r=t;r<n;r++){var s=e.charCodeAt(r);if(ct(s))return r<n-1&&s===13&&e.charCodeAt(r+1)===10?r+2:r+1}return-1}var ts=/[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/,oe=/(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g,ns=Object.prototype,xa=ns.hasOwnProperty,_a=ns.toString,lt=Object.hasOwn||(function(e,t){return xa.call(e,t)}),Gr=Array.isArray||(function(e){return _a.call(e)==="[object Array]"}),Hr=Object.create(null);function We(e){return Hr[e]||(Hr[e]=new RegExp("^(?:"+e.replace(/ /g,"|")+")$"))}function Be(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}var wa=/(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/,vt=function(t,n){this.line=t,this.column=n};vt.prototype.offset=function(t){return new vt(this.line,this.column+t)};var Xt=function(t,n,r){this.start=n,this.end=r,t.sourceFile!==null&&(this.source=t.sourceFile)};function rs(e,t){for(var n=1,r=0;;){var s=es(e,r,t);if(s<0)return new vt(n,t-r);++n,r=s}}var Fn={ecmaVersion:null,sourceType:"script",onInsertedSemicolon:null,onTrailingComma:null,allowReserved:null,allowReturnOutsideFunction:!1,allowImportExportEverywhere:!1,allowAwaitOutsideFunction:null,allowSuperOutsideMethod:null,allowHashBang:!1,checkPrivateFields:!0,locations:!1,onToken:null,onComment:null,ranges:!1,program:null,sourceFile:null,directSourceFile:null,preserveParens:!1},Kr=!1;function Sa(e){var t={};for(var n in Fn)t[n]=e&<(e,n)?e[n]:Fn[n];if(t.ecmaVersion==="latest"?t.ecmaVersion=1e8:t.ecmaVersion==null?(!Kr&&typeof console=="object"&&console.warn&&(Kr=!0,console.warn(`Since Acorn 8.0.0, options.ecmaVersion is required.
|
|
2
|
+
Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=11):t.ecmaVersion>=2015&&(t.ecmaVersion-=2009),t.allowReserved==null&&(t.allowReserved=t.ecmaVersion<5),(!e||e.allowHashBang==null)&&(t.allowHashBang=t.ecmaVersion>=14),Gr(t.onToken)){var r=t.onToken;t.onToken=function(s){return r.push(s)}}return Gr(t.onComment)&&(t.onComment=va(t,t.onComment)),t}function va(e,t){return function(n,r,s,a,i,o){var u={type:n?"Block":"Line",value:r,start:s,end:a};e.locations&&(u.loc=new Xt(this,i,o)),e.ranges&&(u.range=[s,a]),t.push(u)}}var kt=1,ft=2,qn=4,ss=8,Un=16,is=32,en=64,as=128,Ze=256,Et=512,tn=kt|ft|Ze;function Wn(e,t){return ft|(e?qn:0)|(t?ss:0)}var Kt=0,Jn=1,De=2,os=3,us=4,cs=5,ne=function(t,n,r){this.options=t=Sa(t),this.sourceFile=t.sourceFile,this.keywords=We(da[t.ecmaVersion>=6?6:t.sourceType==="module"?"5module":5]);var s="";t.allowReserved!==!0&&(s=Rn[t.ecmaVersion>=6?6:t.ecmaVersion===5?5:3],t.sourceType==="module"&&(s+=" await")),this.reservedWords=We(s);var a=(s?s+" ":"")+Rn.strict;this.reservedWordsStrict=We(a),this.reservedWordsStrictBind=We(a+" "+Rn.strictBind),this.input=String(n),this.containsEsc=!1,r?(this.pos=r,this.lineStart=this.input.lastIndexOf(`
|
|
3
|
+
`,r-1)+1,this.curLine=this.input.slice(0,this.lineStart).split(me).length):(this.pos=this.lineStart=0,this.curLine=1),this.type=h.eof,this.value=null,this.start=this.end=this.pos,this.startLoc=this.endLoc=this.curPosition(),this.lastTokEndLoc=this.lastTokStartLoc=null,this.lastTokStart=this.lastTokEnd=this.pos,this.context=this.initialContext(),this.exprAllowed=!0,this.inModule=t.sourceType==="module",this.strict=this.inModule||this.strictDirective(this.pos),this.potentialArrowAt=-1,this.potentialArrowInForAwait=!1,this.yieldPos=this.awaitPos=this.awaitIdentPos=0,this.labels=[],this.undefinedExports=Object.create(null),this.pos===0&&t.allowHashBang&&this.input.slice(0,2)==="#!"&&this.skipLineComment(2),this.scopeStack=[],this.enterScope(kt),this.regexpState=null,this.privateNameStack=[]},Ae={inFunction:{configurable:!0},inGenerator:{configurable:!0},inAsync:{configurable:!0},canAwait:{configurable:!0},allowSuper:{configurable:!0},allowDirectSuper:{configurable:!0},treatFunctionsAsVar:{configurable:!0},allowNewDotTarget:{configurable:!0},inClassStaticBlock:{configurable:!0}};ne.prototype.parse=function(){var t=this.options.program||this.startNode();return this.nextToken(),this.parseTopLevel(t)};Ae.inFunction.get=function(){return(this.currentVarScope().flags&ft)>0};Ae.inGenerator.get=function(){return(this.currentVarScope().flags&ss)>0};Ae.inAsync.get=function(){return(this.currentVarScope().flags&qn)>0};Ae.canAwait.get=function(){for(var e=this.scopeStack.length-1;e>=0;e--){var t=this.scopeStack[e],n=t.flags;if(n&(Ze|Et))return!1;if(n&ft)return(n&qn)>0}return this.inModule&&this.options.ecmaVersion>=13||this.options.allowAwaitOutsideFunction};Ae.allowSuper.get=function(){var e=this.currentThisScope(),t=e.flags;return(t&en)>0||this.options.allowSuperOutsideMethod};Ae.allowDirectSuper.get=function(){return(this.currentThisScope().flags&as)>0};Ae.treatFunctionsAsVar.get=function(){return this.treatFunctionsAsVarInScope(this.currentScope())};Ae.allowNewDotTarget.get=function(){for(var e=this.scopeStack.length-1;e>=0;e--){var t=this.scopeStack[e],n=t.flags;if(n&(Ze|Et)||n&ft&&!(n&Un))return!0}return!1};Ae.inClassStaticBlock.get=function(){return(this.currentVarScope().flags&Ze)>0};ne.extend=function(){for(var t=[],n=arguments.length;n--;)t[n]=arguments[n];for(var r=this,s=0;s<t.length;s++)r=t[s](r);return r};ne.parse=function(t,n){return new this(n,t).parse()};ne.parseExpressionAt=function(t,n,r){var s=new this(r,t,n);return s.nextToken(),s.parseExpression()};ne.tokenizer=function(t,n){return new this(n,t)};Object.defineProperties(ne.prototype,Ae);var pe=ne.prototype,ka=/^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/;pe.strictDirective=function(e){if(this.options.ecmaVersion<5)return!1;for(;;){oe.lastIndex=e,e+=oe.exec(this.input)[0].length;var t=ka.exec(this.input.slice(e));if(!t)return!1;if((t[1]||t[2])==="use strict"){oe.lastIndex=e+t[0].length;var n=oe.exec(this.input),r=n.index+n[0].length,s=this.input.charAt(r);return s===";"||s==="}"||me.test(n[0])&&!(/[(`.[+\-/*%<>=,?^&]/.test(s)||s==="!"&&this.input.charAt(r+1)==="=")}e+=t[0].length,oe.lastIndex=e,e+=oe.exec(this.input)[0].length,this.input[e]===";"&&e++}};pe.eat=function(e){return this.type===e?(this.next(),!0):!1};pe.isContextual=function(e){return this.type===h.name&&this.value===e&&!this.containsEsc};pe.eatContextual=function(e){return this.isContextual(e)?(this.next(),!0):!1};pe.expectContextual=function(e){this.eatContextual(e)||this.unexpected()};pe.canInsertSemicolon=function(){return this.type===h.eof||this.type===h.braceR||me.test(this.input.slice(this.lastTokEnd,this.start))};pe.insertSemicolon=function(){if(this.canInsertSemicolon())return this.options.onInsertedSemicolon&&this.options.onInsertedSemicolon(this.lastTokEnd,this.lastTokEndLoc),!0};pe.semicolon=function(){!this.eat(h.semi)&&!this.insertSemicolon()&&this.unexpected()};pe.afterTrailingComma=function(e,t){if(this.type===e)return this.options.onTrailingComma&&this.options.onTrailingComma(this.lastTokStart,this.lastTokStartLoc),t||this.next(),!0};pe.expect=function(e){this.eat(e)||this.unexpected()};pe.unexpected=function(e){this.raise(e??this.start,"Unexpected token")};var nn=function(){this.shorthandAssign=this.trailingComma=this.parenthesizedAssign=this.parenthesizedBind=this.doubleProto=-1};pe.checkPatternErrors=function(e,t){if(e){e.trailingComma>-1&&this.raiseRecoverable(e.trailingComma,"Comma is not permitted after the rest element");var n=t?e.parenthesizedAssign:e.parenthesizedBind;n>-1&&this.raiseRecoverable(n,t?"Assigning to rvalue":"Parenthesized pattern")}};pe.checkExpressionErrors=function(e,t){if(!e)return!1;var n=e.shorthandAssign,r=e.doubleProto;if(!t)return n>=0||r>=0;n>=0&&this.raise(n,"Shorthand property assignments are valid only in destructuring patterns"),r>=0&&this.raiseRecoverable(r,"Redefinition of __proto__ property")};pe.checkYieldAwaitInDefaultParams=function(){this.yieldPos&&(!this.awaitPos||this.yieldPos<this.awaitPos)&&this.raise(this.yieldPos,"Yield expression cannot be a default value"),this.awaitPos&&this.raise(this.awaitPos,"Await expression cannot be a default value")};pe.isSimpleAssignTarget=function(e){return e.type==="ParenthesizedExpression"?this.isSimpleAssignTarget(e.expression):e.type==="Identifier"||e.type==="MemberExpression"};var j=ne.prototype;j.parseTopLevel=function(e){var t=Object.create(null);for(e.body||(e.body=[]);this.type!==h.eof;){var n=this.parseStatement(null,!0,t);e.body.push(n)}if(this.inModule)for(var r=0,s=Object.keys(this.undefinedExports);r<s.length;r+=1){var a=s[r];this.raiseRecoverable(this.undefinedExports[a].start,"Export '"+a+"' is not defined")}return this.adaptDirectivePrologue(e.body),this.next(),e.sourceType=this.options.sourceType,this.finishNode(e,"Program")};var zn={kind:"loop"},Ea={kind:"switch"};j.isLet=function(e){if(this.options.ecmaVersion<6||!this.isContextual("let"))return!1;oe.lastIndex=this.pos;var t=oe.exec(this.input),n=this.pos+t[0].length,r=this.input.charCodeAt(n);if(r===91||r===92)return!0;if(e)return!1;if(r===123||r>55295&&r<56320)return!0;if(Ce(r,!0)){for(var s=n+1;Je(r=this.input.charCodeAt(s),!0);)++s;if(r===92||r>55295&&r<56320)return!0;var a=this.input.slice(n,s);if(!ma.test(a))return!0}return!1};j.isAsyncFunction=function(){if(this.options.ecmaVersion<8||!this.isContextual("async"))return!1;oe.lastIndex=this.pos;var e=oe.exec(this.input),t=this.pos+e[0].length,n;return!me.test(this.input.slice(this.pos,t))&&this.input.slice(t,t+8)==="function"&&(t+8===this.input.length||!(Je(n=this.input.charCodeAt(t+8))||n>55295&&n<56320))};j.isUsingKeyword=function(e,t){if(this.options.ecmaVersion<17||!this.isContextual(e?"await":"using"))return!1;oe.lastIndex=this.pos;var n=oe.exec(this.input),r=this.pos+n[0].length;if(me.test(this.input.slice(this.pos,r)))return!1;if(e){var s=r+5,a;if(this.input.slice(r,s)!=="using"||s===this.input.length||Je(a=this.input.charCodeAt(s))||a>55295&&a<56320)return!1;oe.lastIndex=s;var i=oe.exec(this.input);if(i&&me.test(this.input.slice(s,s+i[0].length)))return!1}if(t){var o=r+2,u;if(this.input.slice(r,o)==="of"&&(o===this.input.length||!Je(u=this.input.charCodeAt(o))&&!(u>55295&&u<56320)))return!1}var c=this.input.charCodeAt(r);return Ce(c,!0)||c===92};j.isAwaitUsing=function(e){return this.isUsingKeyword(!0,e)};j.isUsing=function(e){return this.isUsingKeyword(!1,e)};j.parseStatement=function(e,t,n){var r=this.type,s=this.startNode(),a;switch(this.isLet(e)&&(r=h._var,a="let"),r){case h._break:case h._continue:return this.parseBreakContinueStatement(s,r.keyword);case h._debugger:return this.parseDebuggerStatement(s);case h._do:return this.parseDoStatement(s);case h._for:return this.parseForStatement(s);case h._function:return e&&(this.strict||e!=="if"&&e!=="label")&&this.options.ecmaVersion>=6&&this.unexpected(),this.parseFunctionStatement(s,!1,!e);case h._class:return e&&this.unexpected(),this.parseClass(s,!0);case h._if:return this.parseIfStatement(s);case h._return:return this.parseReturnStatement(s);case h._switch:return this.parseSwitchStatement(s);case h._throw:return this.parseThrowStatement(s);case h._try:return this.parseTryStatement(s);case h._const:case h._var:return a=a||this.value,e&&a!=="var"&&this.unexpected(),this.parseVarStatement(s,a);case h._while:return this.parseWhileStatement(s);case h._with:return this.parseWithStatement(s);case h.braceL:return this.parseBlock(!0,s);case h.semi:return this.parseEmptyStatement(s);case h._export:case h._import:if(this.options.ecmaVersion>10&&r===h._import){oe.lastIndex=this.pos;var i=oe.exec(this.input),o=this.pos+i[0].length,u=this.input.charCodeAt(o);if(u===40||u===46)return this.parseExpressionStatement(s,this.parseExpression())}return this.options.allowImportExportEverywhere||(t||this.raise(this.start,"'import' and 'export' may only appear at the top level"),this.inModule||this.raise(this.start,"'import' and 'export' may appear only with 'sourceType: module'")),r===h._import?this.parseImport(s):this.parseExport(s,n);default:if(this.isAsyncFunction())return e&&this.unexpected(),this.next(),this.parseFunctionStatement(s,!0,!e);var c=this.isAwaitUsing(!1)?"await using":this.isUsing(!1)?"using":null;if(c)return t&&this.options.sourceType==="script"&&this.raise(this.start,"Using declaration cannot appear in the top level when source type is `script`"),c==="await using"&&(this.canAwait||this.raise(this.start,"Await using cannot appear outside of async function"),this.next()),this.next(),this.parseVar(s,!1,c),this.semicolon(),this.finishNode(s,"VariableDeclaration");var l=this.value,p=this.parseExpression();return r===h.name&&p.type==="Identifier"&&this.eat(h.colon)?this.parseLabeledStatement(s,l,p,e):this.parseExpressionStatement(s,p)}};j.parseBreakContinueStatement=function(e,t){var n=t==="break";this.next(),this.eat(h.semi)||this.insertSemicolon()?e.label=null:this.type!==h.name?this.unexpected():(e.label=this.parseIdent(),this.semicolon());for(var r=0;r<this.labels.length;++r){var s=this.labels[r];if((e.label==null||s.name===e.label.name)&&(s.kind!=null&&(n||s.kind==="loop")||e.label&&n))break}return r===this.labels.length&&this.raise(e.start,"Unsyntactic "+t),this.finishNode(e,n?"BreakStatement":"ContinueStatement")};j.parseDebuggerStatement=function(e){return this.next(),this.semicolon(),this.finishNode(e,"DebuggerStatement")};j.parseDoStatement=function(e){return this.next(),this.labels.push(zn),e.body=this.parseStatement("do"),this.labels.pop(),this.expect(h._while),e.test=this.parseParenExpression(),this.options.ecmaVersion>=6?this.eat(h.semi):this.semicolon(),this.finishNode(e,"DoWhileStatement")};j.parseForStatement=function(e){this.next();var t=this.options.ecmaVersion>=9&&this.canAwait&&this.eatContextual("await")?this.lastTokStart:-1;if(this.labels.push(zn),this.enterScope(0),this.expect(h.parenL),this.type===h.semi)return t>-1&&this.unexpected(t),this.parseFor(e,null);var n=this.isLet();if(this.type===h._var||this.type===h._const||n){var r=this.startNode(),s=n?"let":this.value;return this.next(),this.parseVar(r,!0,s),this.finishNode(r,"VariableDeclaration"),this.parseForAfterInit(e,r,t)}var a=this.isContextual("let"),i=!1,o=this.isUsing(!0)?"using":this.isAwaitUsing(!0)?"await using":null;if(o){var u=this.startNode();return this.next(),o==="await using"&&this.next(),this.parseVar(u,!0,o),this.finishNode(u,"VariableDeclaration"),this.parseForAfterInit(e,u,t)}var c=this.containsEsc,l=new nn,p=this.start,f=t>-1?this.parseExprSubscripts(l,"await"):this.parseExpression(!0,l);return this.type===h._in||(i=this.options.ecmaVersion>=6&&this.isContextual("of"))?(t>-1?(this.type===h._in&&this.unexpected(t),e.await=!0):i&&this.options.ecmaVersion>=8&&(f.start===p&&!c&&f.type==="Identifier"&&f.name==="async"?this.unexpected():this.options.ecmaVersion>=9&&(e.await=!1)),a&&i&&this.raise(f.start,"The left-hand side of a for-of loop may not start with 'let'."),this.toAssignable(f,!1,l),this.checkLValPattern(f),this.parseForIn(e,f)):(this.checkExpressionErrors(l,!0),t>-1&&this.unexpected(t),this.parseFor(e,f))};j.parseForAfterInit=function(e,t,n){return(this.type===h._in||this.options.ecmaVersion>=6&&this.isContextual("of"))&&t.declarations.length===1?(this.options.ecmaVersion>=9&&(this.type===h._in?n>-1&&this.unexpected(n):e.await=n>-1),this.parseForIn(e,t)):(n>-1&&this.unexpected(n),this.parseFor(e,t))};j.parseFunctionStatement=function(e,t,n){return this.next(),this.parseFunction(e,St|(n?0:Dn),!1,t)};j.parseIfStatement=function(e){return this.next(),e.test=this.parseParenExpression(),e.consequent=this.parseStatement("if"),e.alternate=this.eat(h._else)?this.parseStatement("if"):null,this.finishNode(e,"IfStatement")};j.parseReturnStatement=function(e){return!this.inFunction&&!this.options.allowReturnOutsideFunction&&this.raise(this.start,"'return' outside of function"),this.next(),this.eat(h.semi)||this.insertSemicolon()?e.argument=null:(e.argument=this.parseExpression(),this.semicolon()),this.finishNode(e,"ReturnStatement")};j.parseSwitchStatement=function(e){this.next(),e.discriminant=this.parseParenExpression(),e.cases=[],this.expect(h.braceL),this.labels.push(Ea),this.enterScope(0);for(var t,n=!1;this.type!==h.braceR;)if(this.type===h._case||this.type===h._default){var r=this.type===h._case;t&&this.finishNode(t,"SwitchCase"),e.cases.push(t=this.startNode()),t.consequent=[],this.next(),r?t.test=this.parseExpression():(n&&this.raiseRecoverable(this.lastTokStart,"Multiple default clauses"),n=!0,t.test=null),this.expect(h.colon)}else t||this.unexpected(),t.consequent.push(this.parseStatement(null));return this.exitScope(),t&&this.finishNode(t,"SwitchCase"),this.next(),this.labels.pop(),this.finishNode(e,"SwitchStatement")};j.parseThrowStatement=function(e){return this.next(),me.test(this.input.slice(this.lastTokEnd,this.start))&&this.raise(this.lastTokEnd,"Illegal newline after throw"),e.argument=this.parseExpression(),this.semicolon(),this.finishNode(e,"ThrowStatement")};var Ta=[];j.parseCatchClauseParam=function(){var e=this.parseBindingAtom(),t=e.type==="Identifier";return this.enterScope(t?is:0),this.checkLValPattern(e,t?us:De),this.expect(h.parenR),e};j.parseTryStatement=function(e){if(this.next(),e.block=this.parseBlock(),e.handler=null,this.type===h._catch){var t=this.startNode();this.next(),this.eat(h.parenL)?t.param=this.parseCatchClauseParam():(this.options.ecmaVersion<10&&this.unexpected(),t.param=null,this.enterScope(0)),t.body=this.parseBlock(!1),this.exitScope(),e.handler=this.finishNode(t,"CatchClause")}return e.finalizer=this.eat(h._finally)?this.parseBlock():null,!e.handler&&!e.finalizer&&this.raise(e.start,"Missing catch or finally clause"),this.finishNode(e,"TryStatement")};j.parseVarStatement=function(e,t,n){return this.next(),this.parseVar(e,!1,t,n),this.semicolon(),this.finishNode(e,"VariableDeclaration")};j.parseWhileStatement=function(e){return this.next(),e.test=this.parseParenExpression(),this.labels.push(zn),e.body=this.parseStatement("while"),this.labels.pop(),this.finishNode(e,"WhileStatement")};j.parseWithStatement=function(e){return this.strict&&this.raise(this.start,"'with' in strict mode"),this.next(),e.object=this.parseParenExpression(),e.body=this.parseStatement("with"),this.finishNode(e,"WithStatement")};j.parseEmptyStatement=function(e){return this.next(),this.finishNode(e,"EmptyStatement")};j.parseLabeledStatement=function(e,t,n,r){for(var s=0,a=this.labels;s<a.length;s+=1){var i=a[s];i.name===t&&this.raise(n.start,"Label '"+t+"' is already declared")}for(var o=this.type.isLoop?"loop":this.type===h._switch?"switch":null,u=this.labels.length-1;u>=0;u--){var c=this.labels[u];if(c.statementStart===e.start)c.statementStart=this.start,c.kind=o;else break}return this.labels.push({name:t,kind:o,statementStart:this.start}),e.body=this.parseStatement(r?r.indexOf("label")===-1?r+"label":r:"label"),this.labels.pop(),e.label=n,this.finishNode(e,"LabeledStatement")};j.parseExpressionStatement=function(e,t){return e.expression=t,this.semicolon(),this.finishNode(e,"ExpressionStatement")};j.parseBlock=function(e,t,n){for(e===void 0&&(e=!0),t===void 0&&(t=this.startNode()),t.body=[],this.expect(h.braceL),e&&this.enterScope(0);this.type!==h.braceR;){var r=this.parseStatement(null);t.body.push(r)}return n&&(this.strict=!1),this.next(),e&&this.exitScope(),this.finishNode(t,"BlockStatement")};j.parseFor=function(e,t){return e.init=t,this.expect(h.semi),e.test=this.type===h.semi?null:this.parseExpression(),this.expect(h.semi),e.update=this.type===h.parenR?null:this.parseExpression(),this.expect(h.parenR),e.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(e,"ForStatement")};j.parseForIn=function(e,t){var n=this.type===h._in;return this.next(),t.type==="VariableDeclaration"&&t.declarations[0].init!=null&&(!n||this.options.ecmaVersion<8||this.strict||t.kind!=="var"||t.declarations[0].id.type!=="Identifier")&&this.raise(t.start,(n?"for-in":"for-of")+" loop variable declaration may not have an initializer"),e.left=t,e.right=n?this.parseExpression():this.parseMaybeAssign(),this.expect(h.parenR),e.body=this.parseStatement("for"),this.exitScope(),this.labels.pop(),this.finishNode(e,n?"ForInStatement":"ForOfStatement")};j.parseVar=function(e,t,n,r){for(e.declarations=[],e.kind=n;;){var s=this.startNode();if(this.parseVarId(s,n),this.eat(h.eq)?s.init=this.parseMaybeAssign(t):!r&&n==="const"&&!(this.type===h._in||this.options.ecmaVersion>=6&&this.isContextual("of"))?this.unexpected():!r&&(n==="using"||n==="await using")&&this.options.ecmaVersion>=17&&this.type!==h._in&&!this.isContextual("of")?this.raise(this.lastTokEnd,"Missing initializer in "+n+" declaration"):!r&&s.id.type!=="Identifier"&&!(t&&(this.type===h._in||this.isContextual("of")))?this.raise(this.lastTokEnd,"Complex binding patterns require an initialization value"):s.init=null,e.declarations.push(this.finishNode(s,"VariableDeclarator")),!this.eat(h.comma))break}return e};j.parseVarId=function(e,t){e.id=t==="using"||t==="await using"?this.parseIdent():this.parseBindingAtom(),this.checkLValPattern(e.id,t==="var"?Jn:De,!1)};var St=1,Dn=2,ls=4;j.parseFunction=function(e,t,n,r,s){this.initFunction(e),(this.options.ecmaVersion>=9||this.options.ecmaVersion>=6&&!r)&&(this.type===h.star&&t&Dn&&this.unexpected(),e.generator=this.eat(h.star)),this.options.ecmaVersion>=8&&(e.async=!!r),t&St&&(e.id=t&ls&&this.type!==h.name?null:this.parseIdent(),e.id&&!(t&Dn)&&this.checkLValSimple(e.id,this.strict||e.generator||e.async?this.treatFunctionsAsVar?Jn:De:os));var a=this.yieldPos,i=this.awaitPos,o=this.awaitIdentPos;return this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(Wn(e.async,e.generator)),t&St||(e.id=this.type===h.name?this.parseIdent():null),this.parseFunctionParams(e),this.parseFunctionBody(e,n,!1,s),this.yieldPos=a,this.awaitPos=i,this.awaitIdentPos=o,this.finishNode(e,t&St?"FunctionDeclaration":"FunctionExpression")};j.parseFunctionParams=function(e){this.expect(h.parenL),e.params=this.parseBindingList(h.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams()};j.parseClass=function(e,t){this.next();var n=this.strict;this.strict=!0,this.parseClassId(e,t),this.parseClassSuper(e);var r=this.enterClassBody(),s=this.startNode(),a=!1;for(s.body=[],this.expect(h.braceL);this.type!==h.braceR;){var i=this.parseClassElement(e.superClass!==null);i&&(s.body.push(i),i.type==="MethodDefinition"&&i.kind==="constructor"?(a&&this.raiseRecoverable(i.start,"Duplicate constructor in the same class"),a=!0):i.key&&i.key.type==="PrivateIdentifier"&&$a(r,i)&&this.raiseRecoverable(i.key.start,"Identifier '#"+i.key.name+"' has already been declared"))}return this.strict=n,this.next(),e.body=this.finishNode(s,"ClassBody"),this.exitClassBody(),this.finishNode(e,t?"ClassDeclaration":"ClassExpression")};j.parseClassElement=function(e){if(this.eat(h.semi))return null;var t=this.options.ecmaVersion,n=this.startNode(),r="",s=!1,a=!1,i="method",o=!1;if(this.eatContextual("static")){if(t>=13&&this.eat(h.braceL))return this.parseClassStaticBlock(n),n;this.isClassElementNameStart()||this.type===h.star?o=!0:r="static"}if(n.static=o,!r&&t>=8&&this.eatContextual("async")&&((this.isClassElementNameStart()||this.type===h.star)&&!this.canInsertSemicolon()?a=!0:r="async"),!r&&(t>=9||!a)&&this.eat(h.star)&&(s=!0),!r&&!a&&!s){var u=this.value;(this.eatContextual("get")||this.eatContextual("set"))&&(this.isClassElementNameStart()?i=u:r=u)}if(r?(n.computed=!1,n.key=this.startNodeAt(this.lastTokStart,this.lastTokStartLoc),n.key.name=r,this.finishNode(n.key,"Identifier")):this.parseClassElementName(n),t<13||this.type===h.parenL||i!=="method"||s||a){var c=!n.static&&Zt(n,"constructor"),l=c&&e;c&&i!=="method"&&this.raise(n.key.start,"Constructor can't have get/set modifier"),n.kind=c?"constructor":i,this.parseClassMethod(n,s,a,l)}else this.parseClassField(n);return n};j.isClassElementNameStart=function(){return this.type===h.name||this.type===h.privateId||this.type===h.num||this.type===h.string||this.type===h.bracketL||this.type.keyword};j.parseClassElementName=function(e){this.type===h.privateId?(this.value==="constructor"&&this.raise(this.start,"Classes can't have an element named '#constructor'"),e.computed=!1,e.key=this.parsePrivateIdent()):this.parsePropertyName(e)};j.parseClassMethod=function(e,t,n,r){var s=e.key;e.kind==="constructor"?(t&&this.raise(s.start,"Constructor can't be a generator"),n&&this.raise(s.start,"Constructor can't be an async method")):e.static&&Zt(e,"prototype")&&this.raise(s.start,"Classes may not have a static property named prototype");var a=e.value=this.parseMethod(t,n,r);return e.kind==="get"&&a.params.length!==0&&this.raiseRecoverable(a.start,"getter should have no params"),e.kind==="set"&&a.params.length!==1&&this.raiseRecoverable(a.start,"setter should have exactly one param"),e.kind==="set"&&a.params[0].type==="RestElement"&&this.raiseRecoverable(a.params[0].start,"Setter cannot use rest params"),this.finishNode(e,"MethodDefinition")};j.parseClassField=function(e){return Zt(e,"constructor")?this.raise(e.key.start,"Classes can't have a field named 'constructor'"):e.static&&Zt(e,"prototype")&&this.raise(e.key.start,"Classes can't have a static field named 'prototype'"),this.eat(h.eq)?(this.enterScope(Et|en),e.value=this.parseMaybeAssign(),this.exitScope()):e.value=null,this.semicolon(),this.finishNode(e,"PropertyDefinition")};j.parseClassStaticBlock=function(e){e.body=[];var t=this.labels;for(this.labels=[],this.enterScope(Ze|en);this.type!==h.braceR;){var n=this.parseStatement(null);e.body.push(n)}return this.next(),this.exitScope(),this.labels=t,this.finishNode(e,"StaticBlock")};j.parseClassId=function(e,t){this.type===h.name?(e.id=this.parseIdent(),t&&this.checkLValSimple(e.id,De,!1)):(t===!0&&this.unexpected(),e.id=null)};j.parseClassSuper=function(e){e.superClass=this.eat(h._extends)?this.parseExprSubscripts(null,!1):null};j.enterClassBody=function(){var e={declared:Object.create(null),used:[]};return this.privateNameStack.push(e),e.declared};j.exitClassBody=function(){var e=this.privateNameStack.pop(),t=e.declared,n=e.used;if(this.options.checkPrivateFields)for(var r=this.privateNameStack.length,s=r===0?null:this.privateNameStack[r-1],a=0;a<n.length;++a){var i=n[a];lt(t,i.name)||(s?s.used.push(i):this.raiseRecoverable(i.start,"Private field '#"+i.name+"' must be declared in an enclosing class"))}};function $a(e,t){var n=t.key.name,r=e[n],s="true";return t.type==="MethodDefinition"&&(t.kind==="get"||t.kind==="set")&&(s=(t.static?"s":"i")+t.kind),r==="iget"&&s==="iset"||r==="iset"&&s==="iget"||r==="sget"&&s==="sset"||r==="sset"&&s==="sget"?(e[n]="true",!1):r?!0:(e[n]=s,!1)}function Zt(e,t){var n=e.computed,r=e.key;return!n&&(r.type==="Identifier"&&r.name===t||r.type==="Literal"&&r.value===t)}j.parseExportAllDeclaration=function(e,t){return this.options.ecmaVersion>=11&&(this.eatContextual("as")?(e.exported=this.parseModuleExportName(),this.checkExport(t,e.exported,this.lastTokStart)):e.exported=null),this.expectContextual("from"),this.type!==h.string&&this.unexpected(),e.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(e.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(e,"ExportAllDeclaration")};j.parseExport=function(e,t){if(this.next(),this.eat(h.star))return this.parseExportAllDeclaration(e,t);if(this.eat(h._default))return this.checkExport(t,"default",this.lastTokStart),e.declaration=this.parseExportDefaultDeclaration(),this.finishNode(e,"ExportDefaultDeclaration");if(this.shouldParseExportStatement())e.declaration=this.parseExportDeclaration(e),e.declaration.type==="VariableDeclaration"?this.checkVariableExport(t,e.declaration.declarations):this.checkExport(t,e.declaration.id,e.declaration.id.start),e.specifiers=[],e.source=null,this.options.ecmaVersion>=16&&(e.attributes=[]);else{if(e.declaration=null,e.specifiers=this.parseExportSpecifiers(t),this.eatContextual("from"))this.type!==h.string&&this.unexpected(),e.source=this.parseExprAtom(),this.options.ecmaVersion>=16&&(e.attributes=this.parseWithClause());else{for(var n=0,r=e.specifiers;n<r.length;n+=1){var s=r[n];this.checkUnreserved(s.local),this.checkLocalExport(s.local),s.local.type==="Literal"&&this.raise(s.local.start,"A string literal cannot be used as an exported binding without `from`.")}e.source=null,this.options.ecmaVersion>=16&&(e.attributes=[])}this.semicolon()}return this.finishNode(e,"ExportNamedDeclaration")};j.parseExportDeclaration=function(e){return this.parseStatement(null)};j.parseExportDefaultDeclaration=function(){var e;if(this.type===h._function||(e=this.isAsyncFunction())){var t=this.startNode();return this.next(),e&&this.next(),this.parseFunction(t,St|ls,!1,e)}else if(this.type===h._class){var n=this.startNode();return this.parseClass(n,"nullableID")}else{var r=this.parseMaybeAssign();return this.semicolon(),r}};j.checkExport=function(e,t,n){e&&(typeof t!="string"&&(t=t.type==="Identifier"?t.name:t.value),lt(e,t)&&this.raiseRecoverable(n,"Duplicate export '"+t+"'"),e[t]=!0)};j.checkPatternExport=function(e,t){var n=t.type;if(n==="Identifier")this.checkExport(e,t,t.start);else if(n==="ObjectPattern")for(var r=0,s=t.properties;r<s.length;r+=1){var a=s[r];this.checkPatternExport(e,a)}else if(n==="ArrayPattern")for(var i=0,o=t.elements;i<o.length;i+=1){var u=o[i];u&&this.checkPatternExport(e,u)}else n==="Property"?this.checkPatternExport(e,t.value):n==="AssignmentPattern"?this.checkPatternExport(e,t.left):n==="RestElement"&&this.checkPatternExport(e,t.argument)};j.checkVariableExport=function(e,t){if(e)for(var n=0,r=t;n<r.length;n+=1){var s=r[n];this.checkPatternExport(e,s.id)}};j.shouldParseExportStatement=function(){return this.type.keyword==="var"||this.type.keyword==="const"||this.type.keyword==="class"||this.type.keyword==="function"||this.isLet()||this.isAsyncFunction()};j.parseExportSpecifier=function(e){var t=this.startNode();return t.local=this.parseModuleExportName(),t.exported=this.eatContextual("as")?this.parseModuleExportName():t.local,this.checkExport(e,t.exported,t.exported.start),this.finishNode(t,"ExportSpecifier")};j.parseExportSpecifiers=function(e){var t=[],n=!0;for(this.expect(h.braceL);!this.eat(h.braceR);){if(n)n=!1;else if(this.expect(h.comma),this.afterTrailingComma(h.braceR))break;t.push(this.parseExportSpecifier(e))}return t};j.parseImport=function(e){return this.next(),this.type===h.string?(e.specifiers=Ta,e.source=this.parseExprAtom()):(e.specifiers=this.parseImportSpecifiers(),this.expectContextual("from"),e.source=this.type===h.string?this.parseExprAtom():this.unexpected()),this.options.ecmaVersion>=16&&(e.attributes=this.parseWithClause()),this.semicolon(),this.finishNode(e,"ImportDeclaration")};j.parseImportSpecifier=function(){var e=this.startNode();return e.imported=this.parseModuleExportName(),this.eatContextual("as")?e.local=this.parseIdent():(this.checkUnreserved(e.imported),e.local=e.imported),this.checkLValSimple(e.local,De),this.finishNode(e,"ImportSpecifier")};j.parseImportDefaultSpecifier=function(){var e=this.startNode();return e.local=this.parseIdent(),this.checkLValSimple(e.local,De),this.finishNode(e,"ImportDefaultSpecifier")};j.parseImportNamespaceSpecifier=function(){var e=this.startNode();return this.next(),this.expectContextual("as"),e.local=this.parseIdent(),this.checkLValSimple(e.local,De),this.finishNode(e,"ImportNamespaceSpecifier")};j.parseImportSpecifiers=function(){var e=[],t=!0;if(this.type===h.name&&(e.push(this.parseImportDefaultSpecifier()),!this.eat(h.comma)))return e;if(this.type===h.star)return e.push(this.parseImportNamespaceSpecifier()),e;for(this.expect(h.braceL);!this.eat(h.braceR);){if(t)t=!1;else if(this.expect(h.comma),this.afterTrailingComma(h.braceR))break;e.push(this.parseImportSpecifier())}return e};j.parseWithClause=function(){var e=[];if(!this.eat(h._with))return e;this.expect(h.braceL);for(var t={},n=!0;!this.eat(h.braceR);){if(n)n=!1;else if(this.expect(h.comma),this.afterTrailingComma(h.braceR))break;var r=this.parseImportAttribute(),s=r.key.type==="Identifier"?r.key.name:r.key.value;lt(t,s)&&this.raiseRecoverable(r.key.start,"Duplicate attribute key '"+s+"'"),t[s]=!0,e.push(r)}return e};j.parseImportAttribute=function(){var e=this.startNode();return e.key=this.type===h.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never"),this.expect(h.colon),this.type!==h.string&&this.unexpected(),e.value=this.parseExprAtom(),this.finishNode(e,"ImportAttribute")};j.parseModuleExportName=function(){if(this.options.ecmaVersion>=13&&this.type===h.string){var e=this.parseLiteral(this.value);return wa.test(e.value)&&this.raise(e.start,"An export name cannot include a lone surrogate."),e}return this.parseIdent(!0)};j.adaptDirectivePrologue=function(e){for(var t=0;t<e.length&&this.isDirectiveCandidate(e[t]);++t)e[t].directive=e[t].expression.raw.slice(1,-1)};j.isDirectiveCandidate=function(e){return this.options.ecmaVersion>=5&&e.type==="ExpressionStatement"&&e.expression.type==="Literal"&&typeof e.expression.value=="string"&&(this.input[e.start]==='"'||this.input[e.start]==="'")};var we=ne.prototype;we.toAssignable=function(e,t,n){if(this.options.ecmaVersion>=6&&e)switch(e.type){case"Identifier":this.inAsync&&e.name==="await"&&this.raise(e.start,"Cannot use 'await' as identifier inside an async function");break;case"ObjectPattern":case"ArrayPattern":case"AssignmentPattern":case"RestElement":break;case"ObjectExpression":e.type="ObjectPattern",n&&this.checkPatternErrors(n,!0);for(var r=0,s=e.properties;r<s.length;r+=1){var a=s[r];this.toAssignable(a,t),a.type==="RestElement"&&(a.argument.type==="ArrayPattern"||a.argument.type==="ObjectPattern")&&this.raise(a.argument.start,"Unexpected token")}break;case"Property":e.kind!=="init"&&this.raise(e.key.start,"Object pattern can't contain getter or setter"),this.toAssignable(e.value,t);break;case"ArrayExpression":e.type="ArrayPattern",n&&this.checkPatternErrors(n,!0),this.toAssignableList(e.elements,t);break;case"SpreadElement":e.type="RestElement",this.toAssignable(e.argument,t),e.argument.type==="AssignmentPattern"&&this.raise(e.argument.start,"Rest elements cannot have a default value");break;case"AssignmentExpression":e.operator!=="="&&this.raise(e.left.end,"Only '=' operator can be used for specifying default value."),e.type="AssignmentPattern",delete e.operator,this.toAssignable(e.left,t);break;case"ParenthesizedExpression":this.toAssignable(e.expression,t,n);break;case"ChainExpression":this.raiseRecoverable(e.start,"Optional chaining cannot appear in left-hand side");break;case"MemberExpression":if(!t)break;default:this.raise(e.start,"Assigning to rvalue")}else n&&this.checkPatternErrors(n,!0);return e};we.toAssignableList=function(e,t){for(var n=e.length,r=0;r<n;r++){var s=e[r];s&&this.toAssignable(s,t)}if(n){var a=e[n-1];this.options.ecmaVersion===6&&t&&a&&a.type==="RestElement"&&a.argument.type!=="Identifier"&&this.unexpected(a.argument.start)}return e};we.parseSpread=function(e){var t=this.startNode();return this.next(),t.argument=this.parseMaybeAssign(!1,e),this.finishNode(t,"SpreadElement")};we.parseRestBinding=function(){var e=this.startNode();return this.next(),this.options.ecmaVersion===6&&this.type!==h.name&&this.unexpected(),e.argument=this.parseBindingAtom(),this.finishNode(e,"RestElement")};we.parseBindingAtom=function(){if(this.options.ecmaVersion>=6)switch(this.type){case h.bracketL:var e=this.startNode();return this.next(),e.elements=this.parseBindingList(h.bracketR,!0,!0),this.finishNode(e,"ArrayPattern");case h.braceL:return this.parseObj(!0)}return this.parseIdent()};we.parseBindingList=function(e,t,n,r){for(var s=[],a=!0;!this.eat(e);)if(a?a=!1:this.expect(h.comma),t&&this.type===h.comma)s.push(null);else{if(n&&this.afterTrailingComma(e))break;if(this.type===h.ellipsis){var i=this.parseRestBinding();this.parseBindingListItem(i),s.push(i),this.type===h.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.expect(e);break}else s.push(this.parseAssignableListItem(r))}return s};we.parseAssignableListItem=function(e){var t=this.parseMaybeDefault(this.start,this.startLoc);return this.parseBindingListItem(t),t};we.parseBindingListItem=function(e){return e};we.parseMaybeDefault=function(e,t,n){if(n=n||this.parseBindingAtom(),this.options.ecmaVersion<6||!this.eat(h.eq))return n;var r=this.startNodeAt(e,t);return r.left=n,r.right=this.parseMaybeAssign(),this.finishNode(r,"AssignmentPattern")};we.checkLValSimple=function(e,t,n){t===void 0&&(t=Kt);var r=t!==Kt;switch(e.type){case"Identifier":this.strict&&this.reservedWordsStrictBind.test(e.name)&&this.raiseRecoverable(e.start,(r?"Binding ":"Assigning to ")+e.name+" in strict mode"),r&&(t===De&&e.name==="let"&&this.raiseRecoverable(e.start,"let is disallowed as a lexically bound name"),n&&(lt(n,e.name)&&this.raiseRecoverable(e.start,"Argument name clash"),n[e.name]=!0),t!==cs&&this.declareName(e.name,t,e.start));break;case"ChainExpression":this.raiseRecoverable(e.start,"Optional chaining cannot appear in left-hand side");break;case"MemberExpression":r&&this.raiseRecoverable(e.start,"Binding member expression");break;case"ParenthesizedExpression":return r&&this.raiseRecoverable(e.start,"Binding parenthesized expression"),this.checkLValSimple(e.expression,t,n);default:this.raise(e.start,(r?"Binding":"Assigning to")+" rvalue")}};we.checkLValPattern=function(e,t,n){switch(t===void 0&&(t=Kt),e.type){case"ObjectPattern":for(var r=0,s=e.properties;r<s.length;r+=1){var a=s[r];this.checkLValInnerPattern(a,t,n)}break;case"ArrayPattern":for(var i=0,o=e.elements;i<o.length;i+=1){var u=o[i];u&&this.checkLValInnerPattern(u,t,n)}break;default:this.checkLValSimple(e,t,n)}};we.checkLValInnerPattern=function(e,t,n){switch(t===void 0&&(t=Kt),e.type){case"Property":this.checkLValInnerPattern(e.value,t,n);break;case"AssignmentPattern":this.checkLValPattern(e.left,t,n);break;case"RestElement":this.checkLValPattern(e.argument,t,n);break;default:this.checkLValPattern(e,t,n)}};var ke=function(t,n,r,s,a){this.token=t,this.isExpr=!!n,this.preserveSpace=!!r,this.override=s,this.generator=!!a},Q={b_stat:new ke("{",!1),b_expr:new ke("{",!0),b_tmpl:new ke("${",!1),p_stat:new ke("(",!1),p_expr:new ke("(",!0),q_tmpl:new ke("`",!0,!0,function(e){return e.tryReadTemplateToken()}),f_stat:new ke("function",!1),f_expr:new ke("function",!0),f_expr_gen:new ke("function",!0,!1,null,!0),f_gen:new ke("function",!1,!1,null,!0)},pt=ne.prototype;pt.initialContext=function(){return[Q.b_stat]};pt.curContext=function(){return this.context[this.context.length-1]};pt.braceIsBlock=function(e){var t=this.curContext();return t===Q.f_expr||t===Q.f_stat?!0:e===h.colon&&(t===Q.b_stat||t===Q.b_expr)?!t.isExpr:e===h._return||e===h.name&&this.exprAllowed?me.test(this.input.slice(this.lastTokEnd,this.start)):e===h._else||e===h.semi||e===h.eof||e===h.parenR||e===h.arrow?!0:e===h.braceL?t===Q.b_stat:e===h._var||e===h._const||e===h.name?!1:!this.exprAllowed};pt.inGeneratorContext=function(){for(var e=this.context.length-1;e>=1;e--){var t=this.context[e];if(t.token==="function")return t.generator}return!1};pt.updateContext=function(e){var t,n=this.type;n.keyword&&e===h.dot?this.exprAllowed=!1:(t=n.updateContext)?t.call(this,e):this.exprAllowed=n.beforeExpr};pt.overrideContext=function(e){this.curContext()!==e&&(this.context[this.context.length-1]=e)};h.parenR.updateContext=h.braceR.updateContext=function(){if(this.context.length===1){this.exprAllowed=!0;return}var e=this.context.pop();e===Q.b_stat&&this.curContext().token==="function"&&(e=this.context.pop()),this.exprAllowed=!e.isExpr};h.braceL.updateContext=function(e){this.context.push(this.braceIsBlock(e)?Q.b_stat:Q.b_expr),this.exprAllowed=!0};h.dollarBraceL.updateContext=function(){this.context.push(Q.b_tmpl),this.exprAllowed=!0};h.parenL.updateContext=function(e){var t=e===h._if||e===h._for||e===h._with||e===h._while;this.context.push(t?Q.p_stat:Q.p_expr),this.exprAllowed=!0};h.incDec.updateContext=function(){};h._function.updateContext=h._class.updateContext=function(e){e.beforeExpr&&e!==h._else&&!(e===h.semi&&this.curContext()!==Q.p_stat)&&!(e===h._return&&me.test(this.input.slice(this.lastTokEnd,this.start)))&&!((e===h.colon||e===h.braceL)&&this.curContext()===Q.b_stat)?this.context.push(Q.f_expr):this.context.push(Q.f_stat),this.exprAllowed=!1};h.colon.updateContext=function(){this.curContext().token==="function"&&this.context.pop(),this.exprAllowed=!0};h.backQuote.updateContext=function(){this.curContext()===Q.q_tmpl?this.context.pop():this.context.push(Q.q_tmpl),this.exprAllowed=!1};h.star.updateContext=function(e){if(e===h._function){var t=this.context.length-1;this.context[t]===Q.f_expr?this.context[t]=Q.f_expr_gen:this.context[t]=Q.f_gen}this.exprAllowed=!0};h.name.updateContext=function(e){var t=!1;this.options.ecmaVersion>=6&&e!==h.dot&&(this.value==="of"&&!this.exprAllowed||this.value==="yield"&&this.inGeneratorContext())&&(t=!0),this.exprAllowed=t};var R=ne.prototype;R.checkPropClash=function(e,t,n){if(!(this.options.ecmaVersion>=9&&e.type==="SpreadElement")&&!(this.options.ecmaVersion>=6&&(e.computed||e.method||e.shorthand))){var r=e.key,s;switch(r.type){case"Identifier":s=r.name;break;case"Literal":s=String(r.value);break;default:return}var a=e.kind;if(this.options.ecmaVersion>=6){s==="__proto__"&&a==="init"&&(t.proto&&(n?n.doubleProto<0&&(n.doubleProto=r.start):this.raiseRecoverable(r.start,"Redefinition of __proto__ property")),t.proto=!0);return}s="$"+s;var i=t[s];if(i){var o;a==="init"?o=this.strict&&i.init||i.get||i.set:o=i.init||i[a],o&&this.raiseRecoverable(r.start,"Redefinition of property")}else i=t[s]={init:!1,get:!1,set:!1};i[a]=!0}};R.parseExpression=function(e,t){var n=this.start,r=this.startLoc,s=this.parseMaybeAssign(e,t);if(this.type===h.comma){var a=this.startNodeAt(n,r);for(a.expressions=[s];this.eat(h.comma);)a.expressions.push(this.parseMaybeAssign(e,t));return this.finishNode(a,"SequenceExpression")}return s};R.parseMaybeAssign=function(e,t,n){if(this.isContextual("yield")){if(this.inGenerator)return this.parseYield(e);this.exprAllowed=!1}var r=!1,s=-1,a=-1,i=-1;t?(s=t.parenthesizedAssign,a=t.trailingComma,i=t.doubleProto,t.parenthesizedAssign=t.trailingComma=-1):(t=new nn,r=!0);var o=this.start,u=this.startLoc;(this.type===h.parenL||this.type===h.name)&&(this.potentialArrowAt=this.start,this.potentialArrowInForAwait=e==="await");var c=this.parseMaybeConditional(e,t);if(n&&(c=n.call(this,c,o,u)),this.type.isAssign){var l=this.startNodeAt(o,u);return l.operator=this.value,this.type===h.eq&&(c=this.toAssignable(c,!1,t)),r||(t.parenthesizedAssign=t.trailingComma=t.doubleProto=-1),t.shorthandAssign>=c.start&&(t.shorthandAssign=-1),this.type===h.eq?this.checkLValPattern(c):this.checkLValSimple(c),l.left=c,this.next(),l.right=this.parseMaybeAssign(e),i>-1&&(t.doubleProto=i),this.finishNode(l,"AssignmentExpression")}else r&&this.checkExpressionErrors(t,!0);return s>-1&&(t.parenthesizedAssign=s),a>-1&&(t.trailingComma=a),c};R.parseMaybeConditional=function(e,t){var n=this.start,r=this.startLoc,s=this.parseExprOps(e,t);if(this.checkExpressionErrors(t))return s;if(this.eat(h.question)){var a=this.startNodeAt(n,r);return a.test=s,a.consequent=this.parseMaybeAssign(),this.expect(h.colon),a.alternate=this.parseMaybeAssign(e),this.finishNode(a,"ConditionalExpression")}return s};R.parseExprOps=function(e,t){var n=this.start,r=this.startLoc,s=this.parseMaybeUnary(t,!1,!1,e);return this.checkExpressionErrors(t)||s.start===n&&s.type==="ArrowFunctionExpression"?s:this.parseExprOp(s,n,r,-1,e)};R.parseExprOp=function(e,t,n,r,s){var a=this.type.binop;if(a!=null&&(!s||this.type!==h._in)&&a>r){var i=this.type===h.logicalOR||this.type===h.logicalAND,o=this.type===h.coalesce;o&&(a=h.logicalAND.binop);var u=this.value;this.next();var c=this.start,l=this.startLoc,p=this.parseExprOp(this.parseMaybeUnary(null,!1,!1,s),c,l,a,s),f=this.buildBinary(t,n,e,p,u,i||o);return(i&&this.type===h.coalesce||o&&(this.type===h.logicalOR||this.type===h.logicalAND))&&this.raiseRecoverable(this.start,"Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"),this.parseExprOp(f,t,n,r,s)}return e};R.buildBinary=function(e,t,n,r,s,a){r.type==="PrivateIdentifier"&&this.raise(r.start,"Private identifier can only be left side of binary expression");var i=this.startNodeAt(e,t);return i.left=n,i.operator=s,i.right=r,this.finishNode(i,a?"LogicalExpression":"BinaryExpression")};R.parseMaybeUnary=function(e,t,n,r){var s=this.start,a=this.startLoc,i;if(this.isContextual("await")&&this.canAwait)i=this.parseAwait(r),t=!0;else if(this.type.prefix){var o=this.startNode(),u=this.type===h.incDec;o.operator=this.value,o.prefix=!0,this.next(),o.argument=this.parseMaybeUnary(null,!0,u,r),this.checkExpressionErrors(e,!0),u?this.checkLValSimple(o.argument):this.strict&&o.operator==="delete"&&fs(o.argument)?this.raiseRecoverable(o.start,"Deleting local variable in strict mode"):o.operator==="delete"&&Ln(o.argument)?this.raiseRecoverable(o.start,"Private fields can not be deleted"):t=!0,i=this.finishNode(o,u?"UpdateExpression":"UnaryExpression")}else if(!t&&this.type===h.privateId)(r||this.privateNameStack.length===0)&&this.options.checkPrivateFields&&this.unexpected(),i=this.parsePrivateIdent(),this.type!==h._in&&this.unexpected();else{if(i=this.parseExprSubscripts(e,r),this.checkExpressionErrors(e))return i;for(;this.type.postfix&&!this.canInsertSemicolon();){var c=this.startNodeAt(s,a);c.operator=this.value,c.prefix=!1,c.argument=i,this.checkLValSimple(i),this.next(),i=this.finishNode(c,"UpdateExpression")}}if(!n&&this.eat(h.starstar))if(t)this.unexpected(this.lastTokStart);else return this.buildBinary(s,a,i,this.parseMaybeUnary(null,!1,!1,r),"**",!1);else return i};function fs(e){return e.type==="Identifier"||e.type==="ParenthesizedExpression"&&fs(e.expression)}function Ln(e){return e.type==="MemberExpression"&&e.property.type==="PrivateIdentifier"||e.type==="ChainExpression"&&Ln(e.expression)||e.type==="ParenthesizedExpression"&&Ln(e.expression)}R.parseExprSubscripts=function(e,t){var n=this.start,r=this.startLoc,s=this.parseExprAtom(e,t);if(s.type==="ArrowFunctionExpression"&&this.input.slice(this.lastTokStart,this.lastTokEnd)!==")")return s;var a=this.parseSubscripts(s,n,r,!1,t);return e&&a.type==="MemberExpression"&&(e.parenthesizedAssign>=a.start&&(e.parenthesizedAssign=-1),e.parenthesizedBind>=a.start&&(e.parenthesizedBind=-1),e.trailingComma>=a.start&&(e.trailingComma=-1)),a};R.parseSubscripts=function(e,t,n,r,s){for(var a=this.options.ecmaVersion>=8&&e.type==="Identifier"&&e.name==="async"&&this.lastTokEnd===e.end&&!this.canInsertSemicolon()&&e.end-e.start===5&&this.potentialArrowAt===e.start,i=!1;;){var o=this.parseSubscript(e,t,n,r,a,i,s);if(o.optional&&(i=!0),o===e||o.type==="ArrowFunctionExpression"){if(i){var u=this.startNodeAt(t,n);u.expression=o,o=this.finishNode(u,"ChainExpression")}return o}e=o}};R.shouldParseAsyncArrow=function(){return!this.canInsertSemicolon()&&this.eat(h.arrow)};R.parseSubscriptAsyncArrow=function(e,t,n,r){return this.parseArrowExpression(this.startNodeAt(e,t),n,!0,r)};R.parseSubscript=function(e,t,n,r,s,a,i){var o=this.options.ecmaVersion>=11,u=o&&this.eat(h.questionDot);r&&u&&this.raise(this.lastTokStart,"Optional chaining cannot appear in the callee of new expressions");var c=this.eat(h.bracketL);if(c||u&&this.type!==h.parenL&&this.type!==h.backQuote||this.eat(h.dot)){var l=this.startNodeAt(t,n);l.object=e,c?(l.property=this.parseExpression(),this.expect(h.bracketR)):this.type===h.privateId&&e.type!=="Super"?l.property=this.parsePrivateIdent():l.property=this.parseIdent(this.options.allowReserved!=="never"),l.computed=!!c,o&&(l.optional=u),e=this.finishNode(l,"MemberExpression")}else if(!r&&this.eat(h.parenL)){var p=new nn,f=this.yieldPos,d=this.awaitPos,g=this.awaitIdentPos;this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0;var y=this.parseExprList(h.parenR,this.options.ecmaVersion>=8,!1,p);if(s&&!u&&this.shouldParseAsyncArrow())return this.checkPatternErrors(p,!1),this.checkYieldAwaitInDefaultParams(),this.awaitIdentPos>0&&this.raise(this.awaitIdentPos,"Cannot use 'await' as identifier inside an async function"),this.yieldPos=f,this.awaitPos=d,this.awaitIdentPos=g,this.parseSubscriptAsyncArrow(t,n,y,i);this.checkExpressionErrors(p,!0),this.yieldPos=f||this.yieldPos,this.awaitPos=d||this.awaitPos,this.awaitIdentPos=g||this.awaitIdentPos;var w=this.startNodeAt(t,n);w.callee=e,w.arguments=y,o&&(w.optional=u),e=this.finishNode(w,"CallExpression")}else if(this.type===h.backQuote){(u||a)&&this.raise(this.start,"Optional chaining cannot appear in the tag of tagged template expressions");var k=this.startNodeAt(t,n);k.tag=e,k.quasi=this.parseTemplate({isTagged:!0}),e=this.finishNode(k,"TaggedTemplateExpression")}return e};R.parseExprAtom=function(e,t,n){this.type===h.slash&&this.readRegexp();var r,s=this.potentialArrowAt===this.start;switch(this.type){case h._super:return this.allowSuper||this.raise(this.start,"'super' keyword outside a method"),r=this.startNode(),this.next(),this.type===h.parenL&&!this.allowDirectSuper&&this.raise(r.start,"super() call outside constructor of a subclass"),this.type!==h.dot&&this.type!==h.bracketL&&this.type!==h.parenL&&this.unexpected(),this.finishNode(r,"Super");case h._this:return r=this.startNode(),this.next(),this.finishNode(r,"ThisExpression");case h.name:var a=this.start,i=this.startLoc,o=this.containsEsc,u=this.parseIdent(!1);if(this.options.ecmaVersion>=8&&!o&&u.name==="async"&&!this.canInsertSemicolon()&&this.eat(h._function))return this.overrideContext(Q.f_expr),this.parseFunction(this.startNodeAt(a,i),0,!1,!0,t);if(s&&!this.canInsertSemicolon()){if(this.eat(h.arrow))return this.parseArrowExpression(this.startNodeAt(a,i),[u],!1,t);if(this.options.ecmaVersion>=8&&u.name==="async"&&this.type===h.name&&!o&&(!this.potentialArrowInForAwait||this.value!=="of"||this.containsEsc))return u=this.parseIdent(!1),(this.canInsertSemicolon()||!this.eat(h.arrow))&&this.unexpected(),this.parseArrowExpression(this.startNodeAt(a,i),[u],!0,t)}return u;case h.regexp:var c=this.value;return r=this.parseLiteral(c.value),r.regex={pattern:c.pattern,flags:c.flags},r;case h.num:case h.string:return this.parseLiteral(this.value);case h._null:case h._true:case h._false:return r=this.startNode(),r.value=this.type===h._null?null:this.type===h._true,r.raw=this.type.keyword,this.next(),this.finishNode(r,"Literal");case h.parenL:var l=this.start,p=this.parseParenAndDistinguishExpression(s,t);return e&&(e.parenthesizedAssign<0&&!this.isSimpleAssignTarget(p)&&(e.parenthesizedAssign=l),e.parenthesizedBind<0&&(e.parenthesizedBind=l)),p;case h.bracketL:return r=this.startNode(),this.next(),r.elements=this.parseExprList(h.bracketR,!0,!0,e),this.finishNode(r,"ArrayExpression");case h.braceL:return this.overrideContext(Q.b_expr),this.parseObj(!1,e);case h._function:return r=this.startNode(),this.next(),this.parseFunction(r,0);case h._class:return this.parseClass(this.startNode(),!1);case h._new:return this.parseNew();case h.backQuote:return this.parseTemplate();case h._import:return this.options.ecmaVersion>=11?this.parseExprImport(n):this.unexpected();default:return this.parseExprAtomDefault()}};R.parseExprAtomDefault=function(){this.unexpected()};R.parseExprImport=function(e){var t=this.startNode();if(this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword import"),this.next(),this.type===h.parenL&&!e)return this.parseDynamicImport(t);if(this.type===h.dot){var n=this.startNodeAt(t.start,t.loc&&t.loc.start);return n.name="import",t.meta=this.finishNode(n,"Identifier"),this.parseImportMeta(t)}else this.unexpected()};R.parseDynamicImport=function(e){if(this.next(),e.source=this.parseMaybeAssign(),this.options.ecmaVersion>=16)this.eat(h.parenR)?e.options=null:(this.expect(h.comma),this.afterTrailingComma(h.parenR)?e.options=null:(e.options=this.parseMaybeAssign(),this.eat(h.parenR)||(this.expect(h.comma),this.afterTrailingComma(h.parenR)||this.unexpected())));else if(!this.eat(h.parenR)){var t=this.start;this.eat(h.comma)&&this.eat(h.parenR)?this.raiseRecoverable(t,"Trailing comma is not allowed in import()"):this.unexpected(t)}return this.finishNode(e,"ImportExpression")};R.parseImportMeta=function(e){this.next();var t=this.containsEsc;return e.property=this.parseIdent(!0),e.property.name!=="meta"&&this.raiseRecoverable(e.property.start,"The only valid meta property for import is 'import.meta'"),t&&this.raiseRecoverable(e.start,"'import.meta' must not contain escaped characters"),this.options.sourceType!=="module"&&!this.options.allowImportExportEverywhere&&this.raiseRecoverable(e.start,"Cannot use 'import.meta' outside a module"),this.finishNode(e,"MetaProperty")};R.parseLiteral=function(e){var t=this.startNode();return t.value=e,t.raw=this.input.slice(this.start,this.end),t.raw.charCodeAt(t.raw.length-1)===110&&(t.bigint=t.value!=null?t.value.toString():t.raw.slice(0,-1).replace(/_/g,"")),this.next(),this.finishNode(t,"Literal")};R.parseParenExpression=function(){this.expect(h.parenL);var e=this.parseExpression();return this.expect(h.parenR),e};R.shouldParseArrow=function(e){return!this.canInsertSemicolon()};R.parseParenAndDistinguishExpression=function(e,t){var n=this.start,r=this.startLoc,s,a=this.options.ecmaVersion>=8;if(this.options.ecmaVersion>=6){this.next();var i=this.start,o=this.startLoc,u=[],c=!0,l=!1,p=new nn,f=this.yieldPos,d=this.awaitPos,g;for(this.yieldPos=0,this.awaitPos=0;this.type!==h.parenR;)if(c?c=!1:this.expect(h.comma),a&&this.afterTrailingComma(h.parenR,!0)){l=!0;break}else if(this.type===h.ellipsis){g=this.start,u.push(this.parseParenItem(this.parseRestBinding())),this.type===h.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element");break}else u.push(this.parseMaybeAssign(!1,p,this.parseParenItem));var y=this.lastTokEnd,w=this.lastTokEndLoc;if(this.expect(h.parenR),e&&this.shouldParseArrow(u)&&this.eat(h.arrow))return this.checkPatternErrors(p,!1),this.checkYieldAwaitInDefaultParams(),this.yieldPos=f,this.awaitPos=d,this.parseParenArrowList(n,r,u,t);(!u.length||l)&&this.unexpected(this.lastTokStart),g&&this.unexpected(g),this.checkExpressionErrors(p,!0),this.yieldPos=f||this.yieldPos,this.awaitPos=d||this.awaitPos,u.length>1?(s=this.startNodeAt(i,o),s.expressions=u,this.finishNodeAt(s,"SequenceExpression",y,w)):s=u[0]}else s=this.parseParenExpression();if(this.options.preserveParens){var k=this.startNodeAt(n,r);return k.expression=s,this.finishNode(k,"ParenthesizedExpression")}else return s};R.parseParenItem=function(e){return e};R.parseParenArrowList=function(e,t,n,r){return this.parseArrowExpression(this.startNodeAt(e,t),n,!1,r)};var Ca=[];R.parseNew=function(){this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword new");var e=this.startNode();if(this.next(),this.options.ecmaVersion>=6&&this.type===h.dot){var t=this.startNodeAt(e.start,e.loc&&e.loc.start);t.name="new",e.meta=this.finishNode(t,"Identifier"),this.next();var n=this.containsEsc;return e.property=this.parseIdent(!0),e.property.name!=="target"&&this.raiseRecoverable(e.property.start,"The only valid meta property for new is 'new.target'"),n&&this.raiseRecoverable(e.start,"'new.target' must not contain escaped characters"),this.allowNewDotTarget||this.raiseRecoverable(e.start,"'new.target' can only be used in functions and class static block"),this.finishNode(e,"MetaProperty")}var r=this.start,s=this.startLoc;return e.callee=this.parseSubscripts(this.parseExprAtom(null,!1,!0),r,s,!0,!1),this.eat(h.parenL)?e.arguments=this.parseExprList(h.parenR,this.options.ecmaVersion>=8,!1):e.arguments=Ca,this.finishNode(e,"NewExpression")};R.parseTemplateElement=function(e){var t=e.isTagged,n=this.startNode();return this.type===h.invalidTemplate?(t||this.raiseRecoverable(this.start,"Bad escape sequence in untagged template literal"),n.value={raw:this.value.replace(/\r\n?/g,`
|
|
4
|
+
`),cooked:null}):n.value={raw:this.input.slice(this.start,this.end).replace(/\r\n?/g,`
|
|
5
|
+
`),cooked:this.value},this.next(),n.tail=this.type===h.backQuote,this.finishNode(n,"TemplateElement")};R.parseTemplate=function(e){e===void 0&&(e={});var t=e.isTagged;t===void 0&&(t=!1);var n=this.startNode();this.next(),n.expressions=[];var r=this.parseTemplateElement({isTagged:t});for(n.quasis=[r];!r.tail;)this.type===h.eof&&this.raise(this.pos,"Unterminated template literal"),this.expect(h.dollarBraceL),n.expressions.push(this.parseExpression()),this.expect(h.braceR),n.quasis.push(r=this.parseTemplateElement({isTagged:t}));return this.next(),this.finishNode(n,"TemplateLiteral")};R.isAsyncProp=function(e){return!e.computed&&e.key.type==="Identifier"&&e.key.name==="async"&&(this.type===h.name||this.type===h.num||this.type===h.string||this.type===h.bracketL||this.type.keyword||this.options.ecmaVersion>=9&&this.type===h.star)&&!me.test(this.input.slice(this.lastTokEnd,this.start))};R.parseObj=function(e,t){var n=this.startNode(),r=!0,s={};for(n.properties=[],this.next();!this.eat(h.braceR);){if(r)r=!1;else if(this.expect(h.comma),this.options.ecmaVersion>=5&&this.afterTrailingComma(h.braceR))break;var a=this.parseProperty(e,t);e||this.checkPropClash(a,s,t),n.properties.push(a)}return this.finishNode(n,e?"ObjectPattern":"ObjectExpression")};R.parseProperty=function(e,t){var n=this.startNode(),r,s,a,i;if(this.options.ecmaVersion>=9&&this.eat(h.ellipsis))return e?(n.argument=this.parseIdent(!1),this.type===h.comma&&this.raiseRecoverable(this.start,"Comma is not permitted after the rest element"),this.finishNode(n,"RestElement")):(n.argument=this.parseMaybeAssign(!1,t),this.type===h.comma&&t&&t.trailingComma<0&&(t.trailingComma=this.start),this.finishNode(n,"SpreadElement"));this.options.ecmaVersion>=6&&(n.method=!1,n.shorthand=!1,(e||t)&&(a=this.start,i=this.startLoc),e||(r=this.eat(h.star)));var o=this.containsEsc;return this.parsePropertyName(n),!e&&!o&&this.options.ecmaVersion>=8&&!r&&this.isAsyncProp(n)?(s=!0,r=this.options.ecmaVersion>=9&&this.eat(h.star),this.parsePropertyName(n)):s=!1,this.parsePropertyValue(n,e,r,s,a,i,t,o),this.finishNode(n,"Property")};R.parseGetterSetter=function(e){var t=e.key.name;this.parsePropertyName(e),e.value=this.parseMethod(!1),e.kind=t;var n=e.kind==="get"?0:1;if(e.value.params.length!==n){var r=e.value.start;e.kind==="get"?this.raiseRecoverable(r,"getter should have no params"):this.raiseRecoverable(r,"setter should have exactly one param")}else e.kind==="set"&&e.value.params[0].type==="RestElement"&&this.raiseRecoverable(e.value.params[0].start,"Setter cannot use rest params")};R.parsePropertyValue=function(e,t,n,r,s,a,i,o){(n||r)&&this.type===h.colon&&this.unexpected(),this.eat(h.colon)?(e.value=t?this.parseMaybeDefault(this.start,this.startLoc):this.parseMaybeAssign(!1,i),e.kind="init"):this.options.ecmaVersion>=6&&this.type===h.parenL?(t&&this.unexpected(),e.method=!0,e.value=this.parseMethod(n,r),e.kind="init"):!t&&!o&&this.options.ecmaVersion>=5&&!e.computed&&e.key.type==="Identifier"&&(e.key.name==="get"||e.key.name==="set")&&this.type!==h.comma&&this.type!==h.braceR&&this.type!==h.eq?((n||r)&&this.unexpected(),this.parseGetterSetter(e)):this.options.ecmaVersion>=6&&!e.computed&&e.key.type==="Identifier"?((n||r)&&this.unexpected(),this.checkUnreserved(e.key),e.key.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=s),t?e.value=this.parseMaybeDefault(s,a,this.copyNode(e.key)):this.type===h.eq&&i?(i.shorthandAssign<0&&(i.shorthandAssign=this.start),e.value=this.parseMaybeDefault(s,a,this.copyNode(e.key))):e.value=this.copyNode(e.key),e.kind="init",e.shorthand=!0):this.unexpected()};R.parsePropertyName=function(e){if(this.options.ecmaVersion>=6){if(this.eat(h.bracketL))return e.computed=!0,e.key=this.parseMaybeAssign(),this.expect(h.bracketR),e.key;e.computed=!1}return e.key=this.type===h.num||this.type===h.string?this.parseExprAtom():this.parseIdent(this.options.allowReserved!=="never")};R.initFunction=function(e){e.id=null,this.options.ecmaVersion>=6&&(e.generator=e.expression=!1),this.options.ecmaVersion>=8&&(e.async=!1)};R.parseMethod=function(e,t,n){var r=this.startNode(),s=this.yieldPos,a=this.awaitPos,i=this.awaitIdentPos;return this.initFunction(r),this.options.ecmaVersion>=6&&(r.generator=e),this.options.ecmaVersion>=8&&(r.async=!!t),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,this.enterScope(Wn(t,r.generator)|en|(n?as:0)),this.expect(h.parenL),r.params=this.parseBindingList(h.parenR,!1,this.options.ecmaVersion>=8),this.checkYieldAwaitInDefaultParams(),this.parseFunctionBody(r,!1,!0,!1),this.yieldPos=s,this.awaitPos=a,this.awaitIdentPos=i,this.finishNode(r,"FunctionExpression")};R.parseArrowExpression=function(e,t,n,r){var s=this.yieldPos,a=this.awaitPos,i=this.awaitIdentPos;return this.enterScope(Wn(n,!1)|Un),this.initFunction(e),this.options.ecmaVersion>=8&&(e.async=!!n),this.yieldPos=0,this.awaitPos=0,this.awaitIdentPos=0,e.params=this.toAssignableList(t,!0),this.parseFunctionBody(e,!0,!1,r),this.yieldPos=s,this.awaitPos=a,this.awaitIdentPos=i,this.finishNode(e,"ArrowFunctionExpression")};R.parseFunctionBody=function(e,t,n,r){var s=t&&this.type!==h.braceL,a=this.strict,i=!1;if(s)e.body=this.parseMaybeAssign(r),e.expression=!0,this.checkParams(e,!1);else{var o=this.options.ecmaVersion>=7&&!this.isSimpleParamList(e.params);(!a||o)&&(i=this.strictDirective(this.end),i&&o&&this.raiseRecoverable(e.start,"Illegal 'use strict' directive in function with non-simple parameter list"));var u=this.labels;this.labels=[],i&&(this.strict=!0),this.checkParams(e,!a&&!i&&!t&&!n&&this.isSimpleParamList(e.params)),this.strict&&e.id&&this.checkLValSimple(e.id,cs),e.body=this.parseBlock(!1,void 0,i&&!a),e.expression=!1,this.adaptDirectivePrologue(e.body.body),this.labels=u}this.exitScope()};R.isSimpleParamList=function(e){for(var t=0,n=e;t<n.length;t+=1){var r=n[t];if(r.type!=="Identifier")return!1}return!0};R.checkParams=function(e,t){for(var n=Object.create(null),r=0,s=e.params;r<s.length;r+=1){var a=s[r];this.checkLValInnerPattern(a,Jn,t?null:n)}};R.parseExprList=function(e,t,n,r){for(var s=[],a=!0;!this.eat(e);){if(a)a=!1;else if(this.expect(h.comma),t&&this.afterTrailingComma(e))break;var i=void 0;n&&this.type===h.comma?i=null:this.type===h.ellipsis?(i=this.parseSpread(r),r&&this.type===h.comma&&r.trailingComma<0&&(r.trailingComma=this.start)):i=this.parseMaybeAssign(!1,r),s.push(i)}return s};R.checkUnreserved=function(e){var t=e.start,n=e.end,r=e.name;if(this.inGenerator&&r==="yield"&&this.raiseRecoverable(t,"Cannot use 'yield' as identifier inside a generator"),this.inAsync&&r==="await"&&this.raiseRecoverable(t,"Cannot use 'await' as identifier inside an async function"),!(this.currentThisScope().flags&tn)&&r==="arguments"&&this.raiseRecoverable(t,"Cannot use 'arguments' in class field initializer"),this.inClassStaticBlock&&(r==="arguments"||r==="await")&&this.raise(t,"Cannot use "+r+" in class static initialization block"),this.keywords.test(r)&&this.raise(t,"Unexpected keyword '"+r+"'"),!(this.options.ecmaVersion<6&&this.input.slice(t,n).indexOf("\\")!==-1)){var s=this.strict?this.reservedWordsStrict:this.reservedWords;s.test(r)&&(!this.inAsync&&r==="await"&&this.raiseRecoverable(t,"Cannot use keyword 'await' outside an async function"),this.raiseRecoverable(t,"The keyword '"+r+"' is reserved"))}};R.parseIdent=function(e){var t=this.parseIdentNode();return this.next(!!e),this.finishNode(t,"Identifier"),e||(this.checkUnreserved(t),t.name==="await"&&!this.awaitIdentPos&&(this.awaitIdentPos=t.start)),t};R.parseIdentNode=function(){var e=this.startNode();return this.type===h.name?e.name=this.value:this.type.keyword?(e.name=this.type.keyword,(e.name==="class"||e.name==="function")&&(this.lastTokEnd!==this.lastTokStart+1||this.input.charCodeAt(this.lastTokStart)!==46)&&this.context.pop(),this.type=h.name):this.unexpected(),e};R.parsePrivateIdent=function(){var e=this.startNode();return this.type===h.privateId?e.name=this.value:this.unexpected(),this.next(),this.finishNode(e,"PrivateIdentifier"),this.options.checkPrivateFields&&(this.privateNameStack.length===0?this.raise(e.start,"Private field '#"+e.name+"' must be declared in an enclosing class"):this.privateNameStack[this.privateNameStack.length-1].used.push(e)),e};R.parseYield=function(e){this.yieldPos||(this.yieldPos=this.start);var t=this.startNode();return this.next(),this.type===h.semi||this.canInsertSemicolon()||this.type!==h.star&&!this.type.startsExpr?(t.delegate=!1,t.argument=null):(t.delegate=this.eat(h.star),t.argument=this.parseMaybeAssign(e)),this.finishNode(t,"YieldExpression")};R.parseAwait=function(e){this.awaitPos||(this.awaitPos=this.start);var t=this.startNode();return this.next(),t.argument=this.parseMaybeUnary(null,!0,!1,e),this.finishNode(t,"AwaitExpression")};var Qt=ne.prototype;Qt.raise=function(e,t){var n=rs(this.input,e);t+=" ("+n.line+":"+n.column+")",this.sourceFile&&(t+=" in "+this.sourceFile);var r=new SyntaxError(t);throw r.pos=e,r.loc=n,r.raisedAt=this.pos,r};Qt.raiseRecoverable=Qt.raise;Qt.curPosition=function(){if(this.options.locations)return new vt(this.curLine,this.pos-this.lineStart)};var ze=ne.prototype,Aa=function(t){this.flags=t,this.var=[],this.lexical=[],this.functions=[]};ze.enterScope=function(e){this.scopeStack.push(new Aa(e))};ze.exitScope=function(){this.scopeStack.pop()};ze.treatFunctionsAsVarInScope=function(e){return e.flags&ft||!this.inModule&&e.flags&kt};ze.declareName=function(e,t,n){var r=!1;if(t===De){var s=this.currentScope();r=s.lexical.indexOf(e)>-1||s.functions.indexOf(e)>-1||s.var.indexOf(e)>-1,s.lexical.push(e),this.inModule&&s.flags&kt&&delete this.undefinedExports[e]}else if(t===us){var a=this.currentScope();a.lexical.push(e)}else if(t===os){var i=this.currentScope();this.treatFunctionsAsVar?r=i.lexical.indexOf(e)>-1:r=i.lexical.indexOf(e)>-1||i.var.indexOf(e)>-1,i.functions.push(e)}else for(var o=this.scopeStack.length-1;o>=0;--o){var u=this.scopeStack[o];if(u.lexical.indexOf(e)>-1&&!(u.flags&is&&u.lexical[0]===e)||!this.treatFunctionsAsVarInScope(u)&&u.functions.indexOf(e)>-1){r=!0;break}if(u.var.push(e),this.inModule&&u.flags&kt&&delete this.undefinedExports[e],u.flags&tn)break}r&&this.raiseRecoverable(n,"Identifier '"+e+"' has already been declared")};ze.checkLocalExport=function(e){this.scopeStack[0].lexical.indexOf(e.name)===-1&&this.scopeStack[0].var.indexOf(e.name)===-1&&(this.undefinedExports[e.name]=e)};ze.currentScope=function(){return this.scopeStack[this.scopeStack.length-1]};ze.currentVarScope=function(){for(var e=this.scopeStack.length-1;;e--){var t=this.scopeStack[e];if(t.flags&(tn|Et|Ze))return t}};ze.currentThisScope=function(){for(var e=this.scopeStack.length-1;;e--){var t=this.scopeStack[e];if(t.flags&(tn|Et|Ze)&&!(t.flags&Un))return t}};var rn=function(t,n,r){this.type="",this.start=n,this.end=0,t.options.locations&&(this.loc=new Xt(t,r)),t.options.directSourceFile&&(this.sourceFile=t.options.directSourceFile),t.options.ranges&&(this.range=[n,0])},Tt=ne.prototype;Tt.startNode=function(){return new rn(this,this.start,this.startLoc)};Tt.startNodeAt=function(e,t){return new rn(this,e,t)};function ps(e,t,n,r){return e.type=t,e.end=n,this.options.locations&&(e.loc.end=r),this.options.ranges&&(e.range[1]=n),e}Tt.finishNode=function(e,t){return ps.call(this,e,t,this.lastTokEnd,this.lastTokEndLoc)};Tt.finishNodeAt=function(e,t,n,r){return ps.call(this,e,t,n,r)};Tt.copyNode=function(e){var t=new rn(this,e.start,this.startLoc);for(var n in e)t[n]=e[n];return t};var Pa="Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sunu Sunuwar Todhri Todr Tulu_Tigalari Tutg Unknown Zzzz",hs="ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS",ds=hs+" Extended_Pictographic",ms=ds,gs=ms+" EBase EComp EMod EPres ExtPict",ys=gs,ja=ys,Ia={9:hs,10:ds,11:ms,12:gs,13:ys,14:ja},Na="Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji",Ra={9:"",10:"",11:"",12:"",13:"",14:Na},Zr="Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu",bs="Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb",xs=bs+" Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd",_s=xs+" Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho",ws=_s+" Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi",Ss=ws+" Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith",Ma=Ss+" "+Pa,Oa={9:bs,10:xs,11:_s,12:ws,13:Ss,14:Ma},vs={};function Ba(e){var t=vs[e]={binary:We(Ia[e]+" "+Zr),binaryOfStrings:We(Ra[e]),nonBinary:{General_Category:We(Zr),Script:We(Oa[e])}};t.nonBinary.Script_Extensions=t.nonBinary.Script,t.nonBinary.gc=t.nonBinary.General_Category,t.nonBinary.sc=t.nonBinary.Script,t.nonBinary.scx=t.nonBinary.Script_Extensions}for(Ht=0,On=[9,10,11,12,13,14];Ht<On.length;Ht+=1)Qr=On[Ht],Ba(Qr);var Qr,Ht,On,P=ne.prototype,Yt=function(t,n){this.parent=t,this.base=n||this};Yt.prototype.separatedFrom=function(t){for(var n=this;n;n=n.parent)for(var r=t;r;r=r.parent)if(n.base===r.base&&n!==r)return!0;return!1};Yt.prototype.sibling=function(){return new Yt(this.parent,this.base)};var Pe=function(t){this.parser=t,this.validFlags="gim"+(t.options.ecmaVersion>=6?"uy":"")+(t.options.ecmaVersion>=9?"s":"")+(t.options.ecmaVersion>=13?"d":"")+(t.options.ecmaVersion>=15?"v":""),this.unicodeProperties=vs[t.options.ecmaVersion>=14?14:t.options.ecmaVersion],this.source="",this.flags="",this.start=0,this.switchU=!1,this.switchV=!1,this.switchN=!1,this.pos=0,this.lastIntValue=0,this.lastStringValue="",this.lastAssertionIsQuantifiable=!1,this.numCapturingParens=0,this.maxBackReference=0,this.groupNames=Object.create(null),this.backReferenceNames=[],this.branchID=null};Pe.prototype.reset=function(t,n,r){var s=r.indexOf("v")!==-1,a=r.indexOf("u")!==-1;this.start=t|0,this.source=n+"",this.flags=r,s&&this.parser.options.ecmaVersion>=15?(this.switchU=!0,this.switchV=!0,this.switchN=!0):(this.switchU=a&&this.parser.options.ecmaVersion>=6,this.switchV=!1,this.switchN=a&&this.parser.options.ecmaVersion>=9)};Pe.prototype.raise=function(t){this.parser.raiseRecoverable(this.start,"Invalid regular expression: /"+this.source+"/: "+t)};Pe.prototype.at=function(t,n){n===void 0&&(n=!1);var r=this.source,s=r.length;if(t>=s)return-1;var a=r.charCodeAt(t);if(!(n||this.switchU)||a<=55295||a>=57344||t+1>=s)return a;var i=r.charCodeAt(t+1);return i>=56320&&i<=57343?(a<<10)+i-56613888:a};Pe.prototype.nextIndex=function(t,n){n===void 0&&(n=!1);var r=this.source,s=r.length;if(t>=s)return s;var a=r.charCodeAt(t),i;return!(n||this.switchU)||a<=55295||a>=57344||t+1>=s||(i=r.charCodeAt(t+1))<56320||i>57343?t+1:t+2};Pe.prototype.current=function(t){return t===void 0&&(t=!1),this.at(this.pos,t)};Pe.prototype.lookahead=function(t){return t===void 0&&(t=!1),this.at(this.nextIndex(this.pos,t),t)};Pe.prototype.advance=function(t){t===void 0&&(t=!1),this.pos=this.nextIndex(this.pos,t)};Pe.prototype.eat=function(t,n){return n===void 0&&(n=!1),this.current(n)===t?(this.advance(n),!0):!1};Pe.prototype.eatChars=function(t,n){n===void 0&&(n=!1);for(var r=this.pos,s=0,a=t;s<a.length;s+=1){var i=a[s],o=this.at(r,n);if(o===-1||o!==i)return!1;r=this.nextIndex(r,n)}return this.pos=r,!0};P.validateRegExpFlags=function(e){for(var t=e.validFlags,n=e.flags,r=!1,s=!1,a=0;a<n.length;a++){var i=n.charAt(a);t.indexOf(i)===-1&&this.raise(e.start,"Invalid regular expression flag"),n.indexOf(i,a+1)>-1&&this.raise(e.start,"Duplicate regular expression flag"),i==="u"&&(r=!0),i==="v"&&(s=!0)}this.options.ecmaVersion>=15&&r&&s&&this.raise(e.start,"Invalid regular expression flag")};function Fa(e){for(var t in e)return!0;return!1}P.validateRegExpPattern=function(e){this.regexp_pattern(e),!e.switchN&&this.options.ecmaVersion>=9&&Fa(e.groupNames)&&(e.switchN=!0,this.regexp_pattern(e))};P.regexp_pattern=function(e){e.pos=0,e.lastIntValue=0,e.lastStringValue="",e.lastAssertionIsQuantifiable=!1,e.numCapturingParens=0,e.maxBackReference=0,e.groupNames=Object.create(null),e.backReferenceNames.length=0,e.branchID=null,this.regexp_disjunction(e),e.pos!==e.source.length&&(e.eat(41)&&e.raise("Unmatched ')'"),(e.eat(93)||e.eat(125))&&e.raise("Lone quantifier brackets")),e.maxBackReference>e.numCapturingParens&&e.raise("Invalid escape");for(var t=0,n=e.backReferenceNames;t<n.length;t+=1){var r=n[t];e.groupNames[r]||e.raise("Invalid named capture referenced")}};P.regexp_disjunction=function(e){var t=this.options.ecmaVersion>=16;for(t&&(e.branchID=new Yt(e.branchID,null)),this.regexp_alternative(e);e.eat(124);)t&&(e.branchID=e.branchID.sibling()),this.regexp_alternative(e);t&&(e.branchID=e.branchID.parent),this.regexp_eatQuantifier(e,!0)&&e.raise("Nothing to repeat"),e.eat(123)&&e.raise("Lone quantifier brackets")};P.regexp_alternative=function(e){for(;e.pos<e.source.length&&this.regexp_eatTerm(e););};P.regexp_eatTerm=function(e){return this.regexp_eatAssertion(e)?(e.lastAssertionIsQuantifiable&&this.regexp_eatQuantifier(e)&&e.switchU&&e.raise("Invalid quantifier"),!0):(e.switchU?this.regexp_eatAtom(e):this.regexp_eatExtendedAtom(e))?(this.regexp_eatQuantifier(e),!0):!1};P.regexp_eatAssertion=function(e){var t=e.pos;if(e.lastAssertionIsQuantifiable=!1,e.eat(94)||e.eat(36))return!0;if(e.eat(92)){if(e.eat(66)||e.eat(98))return!0;e.pos=t}if(e.eat(40)&&e.eat(63)){var n=!1;if(this.options.ecmaVersion>=9&&(n=e.eat(60)),e.eat(61)||e.eat(33))return this.regexp_disjunction(e),e.eat(41)||e.raise("Unterminated group"),e.lastAssertionIsQuantifiable=!n,!0}return e.pos=t,!1};P.regexp_eatQuantifier=function(e,t){return t===void 0&&(t=!1),this.regexp_eatQuantifierPrefix(e,t)?(e.eat(63),!0):!1};P.regexp_eatQuantifierPrefix=function(e,t){return e.eat(42)||e.eat(43)||e.eat(63)||this.regexp_eatBracedQuantifier(e,t)};P.regexp_eatBracedQuantifier=function(e,t){var n=e.pos;if(e.eat(123)){var r=0,s=-1;if(this.regexp_eatDecimalDigits(e)&&(r=e.lastIntValue,e.eat(44)&&this.regexp_eatDecimalDigits(e)&&(s=e.lastIntValue),e.eat(125)))return s!==-1&&s<r&&!t&&e.raise("numbers out of order in {} quantifier"),!0;e.switchU&&!t&&e.raise("Incomplete quantifier"),e.pos=n}return!1};P.regexp_eatAtom=function(e){return this.regexp_eatPatternCharacters(e)||e.eat(46)||this.regexp_eatReverseSolidusAtomEscape(e)||this.regexp_eatCharacterClass(e)||this.regexp_eatUncapturingGroup(e)||this.regexp_eatCapturingGroup(e)};P.regexp_eatReverseSolidusAtomEscape=function(e){var t=e.pos;if(e.eat(92)){if(this.regexp_eatAtomEscape(e))return!0;e.pos=t}return!1};P.regexp_eatUncapturingGroup=function(e){var t=e.pos;if(e.eat(40)){if(e.eat(63)){if(this.options.ecmaVersion>=16){var n=this.regexp_eatModifiers(e),r=e.eat(45);if(n||r){for(var s=0;s<n.length;s++){var a=n.charAt(s);n.indexOf(a,s+1)>-1&&e.raise("Duplicate regular expression modifiers")}if(r){var i=this.regexp_eatModifiers(e);!n&&!i&&e.current()===58&&e.raise("Invalid regular expression modifiers");for(var o=0;o<i.length;o++){var u=i.charAt(o);(i.indexOf(u,o+1)>-1||n.indexOf(u)>-1)&&e.raise("Duplicate regular expression modifiers")}}}}if(e.eat(58)){if(this.regexp_disjunction(e),e.eat(41))return!0;e.raise("Unterminated group")}}e.pos=t}return!1};P.regexp_eatCapturingGroup=function(e){if(e.eat(40)){if(this.options.ecmaVersion>=9?this.regexp_groupSpecifier(e):e.current()===63&&e.raise("Invalid group"),this.regexp_disjunction(e),e.eat(41))return e.numCapturingParens+=1,!0;e.raise("Unterminated group")}return!1};P.regexp_eatModifiers=function(e){for(var t="",n=0;(n=e.current())!==-1&&Da(n);)t+=Be(n),e.advance();return t};function Da(e){return e===105||e===109||e===115}P.regexp_eatExtendedAtom=function(e){return e.eat(46)||this.regexp_eatReverseSolidusAtomEscape(e)||this.regexp_eatCharacterClass(e)||this.regexp_eatUncapturingGroup(e)||this.regexp_eatCapturingGroup(e)||this.regexp_eatInvalidBracedQuantifier(e)||this.regexp_eatExtendedPatternCharacter(e)};P.regexp_eatInvalidBracedQuantifier=function(e){return this.regexp_eatBracedQuantifier(e,!0)&&e.raise("Nothing to repeat"),!1};P.regexp_eatSyntaxCharacter=function(e){var t=e.current();return ks(t)?(e.lastIntValue=t,e.advance(),!0):!1};function ks(e){return e===36||e>=40&&e<=43||e===46||e===63||e>=91&&e<=94||e>=123&&e<=125}P.regexp_eatPatternCharacters=function(e){for(var t=e.pos,n=0;(n=e.current())!==-1&&!ks(n);)e.advance();return e.pos!==t};P.regexp_eatExtendedPatternCharacter=function(e){var t=e.current();return t!==-1&&t!==36&&!(t>=40&&t<=43)&&t!==46&&t!==63&&t!==91&&t!==94&&t!==124?(e.advance(),!0):!1};P.regexp_groupSpecifier=function(e){if(e.eat(63)){this.regexp_eatGroupName(e)||e.raise("Invalid group");var t=this.options.ecmaVersion>=16,n=e.groupNames[e.lastStringValue];if(n)if(t)for(var r=0,s=n;r<s.length;r+=1){var a=s[r];a.separatedFrom(e.branchID)||e.raise("Duplicate capture group name")}else e.raise("Duplicate capture group name");t?(n||(e.groupNames[e.lastStringValue]=[])).push(e.branchID):e.groupNames[e.lastStringValue]=!0}};P.regexp_eatGroupName=function(e){if(e.lastStringValue="",e.eat(60)){if(this.regexp_eatRegExpIdentifierName(e)&&e.eat(62))return!0;e.raise("Invalid capture group name")}return!1};P.regexp_eatRegExpIdentifierName=function(e){if(e.lastStringValue="",this.regexp_eatRegExpIdentifierStart(e)){for(e.lastStringValue+=Be(e.lastIntValue);this.regexp_eatRegExpIdentifierPart(e);)e.lastStringValue+=Be(e.lastIntValue);return!0}return!1};P.regexp_eatRegExpIdentifierStart=function(e){var t=e.pos,n=this.options.ecmaVersion>=11,r=e.current(n);return e.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(e,n)&&(r=e.lastIntValue),La(r)?(e.lastIntValue=r,!0):(e.pos=t,!1)};function La(e){return Ce(e,!0)||e===36||e===95}P.regexp_eatRegExpIdentifierPart=function(e){var t=e.pos,n=this.options.ecmaVersion>=11,r=e.current(n);return e.advance(n),r===92&&this.regexp_eatRegExpUnicodeEscapeSequence(e,n)&&(r=e.lastIntValue),Va(r)?(e.lastIntValue=r,!0):(e.pos=t,!1)};function Va(e){return Je(e,!0)||e===36||e===95||e===8204||e===8205}P.regexp_eatAtomEscape=function(e){return this.regexp_eatBackReference(e)||this.regexp_eatCharacterClassEscape(e)||this.regexp_eatCharacterEscape(e)||e.switchN&&this.regexp_eatKGroupName(e)?!0:(e.switchU&&(e.current()===99&&e.raise("Invalid unicode escape"),e.raise("Invalid escape")),!1)};P.regexp_eatBackReference=function(e){var t=e.pos;if(this.regexp_eatDecimalEscape(e)){var n=e.lastIntValue;if(e.switchU)return n>e.maxBackReference&&(e.maxBackReference=n),!0;if(n<=e.numCapturingParens)return!0;e.pos=t}return!1};P.regexp_eatKGroupName=function(e){if(e.eat(107)){if(this.regexp_eatGroupName(e))return e.backReferenceNames.push(e.lastStringValue),!0;e.raise("Invalid named reference")}return!1};P.regexp_eatCharacterEscape=function(e){return this.regexp_eatControlEscape(e)||this.regexp_eatCControlLetter(e)||this.regexp_eatZero(e)||this.regexp_eatHexEscapeSequence(e)||this.regexp_eatRegExpUnicodeEscapeSequence(e,!1)||!e.switchU&&this.regexp_eatLegacyOctalEscapeSequence(e)||this.regexp_eatIdentityEscape(e)};P.regexp_eatCControlLetter=function(e){var t=e.pos;if(e.eat(99)){if(this.regexp_eatControlLetter(e))return!0;e.pos=t}return!1};P.regexp_eatZero=function(e){return e.current()===48&&!sn(e.lookahead())?(e.lastIntValue=0,e.advance(),!0):!1};P.regexp_eatControlEscape=function(e){var t=e.current();return t===116?(e.lastIntValue=9,e.advance(),!0):t===110?(e.lastIntValue=10,e.advance(),!0):t===118?(e.lastIntValue=11,e.advance(),!0):t===102?(e.lastIntValue=12,e.advance(),!0):t===114?(e.lastIntValue=13,e.advance(),!0):!1};P.regexp_eatControlLetter=function(e){var t=e.current();return Es(t)?(e.lastIntValue=t%32,e.advance(),!0):!1};function Es(e){return e>=65&&e<=90||e>=97&&e<=122}P.regexp_eatRegExpUnicodeEscapeSequence=function(e,t){t===void 0&&(t=!1);var n=e.pos,r=t||e.switchU;if(e.eat(117)){if(this.regexp_eatFixedHexDigits(e,4)){var s=e.lastIntValue;if(r&&s>=55296&&s<=56319){var a=e.pos;if(e.eat(92)&&e.eat(117)&&this.regexp_eatFixedHexDigits(e,4)){var i=e.lastIntValue;if(i>=56320&&i<=57343)return e.lastIntValue=(s-55296)*1024+(i-56320)+65536,!0}e.pos=a,e.lastIntValue=s}return!0}if(r&&e.eat(123)&&this.regexp_eatHexDigits(e)&&e.eat(125)&&qa(e.lastIntValue))return!0;r&&e.raise("Invalid unicode escape"),e.pos=n}return!1};function qa(e){return e>=0&&e<=1114111}P.regexp_eatIdentityEscape=function(e){if(e.switchU)return this.regexp_eatSyntaxCharacter(e)?!0:e.eat(47)?(e.lastIntValue=47,!0):!1;var t=e.current();return t!==99&&(!e.switchN||t!==107)?(e.lastIntValue=t,e.advance(),!0):!1};P.regexp_eatDecimalEscape=function(e){e.lastIntValue=0;var t=e.current();if(t>=49&&t<=57){do e.lastIntValue=10*e.lastIntValue+(t-48),e.advance();while((t=e.current())>=48&&t<=57);return!0}return!1};var Ts=0,Fe=1,_e=2;P.regexp_eatCharacterClassEscape=function(e){var t=e.current();if(Ua(t))return e.lastIntValue=-1,e.advance(),Fe;var n=!1;if(e.switchU&&this.options.ecmaVersion>=9&&((n=t===80)||t===112)){e.lastIntValue=-1,e.advance();var r;if(e.eat(123)&&(r=this.regexp_eatUnicodePropertyValueExpression(e))&&e.eat(125))return n&&r===_e&&e.raise("Invalid property name"),r;e.raise("Invalid property name")}return Ts};function Ua(e){return e===100||e===68||e===115||e===83||e===119||e===87}P.regexp_eatUnicodePropertyValueExpression=function(e){var t=e.pos;if(this.regexp_eatUnicodePropertyName(e)&&e.eat(61)){var n=e.lastStringValue;if(this.regexp_eatUnicodePropertyValue(e)){var r=e.lastStringValue;return this.regexp_validateUnicodePropertyNameAndValue(e,n,r),Fe}}if(e.pos=t,this.regexp_eatLoneUnicodePropertyNameOrValue(e)){var s=e.lastStringValue;return this.regexp_validateUnicodePropertyNameOrValue(e,s)}return Ts};P.regexp_validateUnicodePropertyNameAndValue=function(e,t,n){lt(e.unicodeProperties.nonBinary,t)||e.raise("Invalid property name"),e.unicodeProperties.nonBinary[t].test(n)||e.raise("Invalid property value")};P.regexp_validateUnicodePropertyNameOrValue=function(e,t){if(e.unicodeProperties.binary.test(t))return Fe;if(e.switchV&&e.unicodeProperties.binaryOfStrings.test(t))return _e;e.raise("Invalid property name")};P.regexp_eatUnicodePropertyName=function(e){var t=0;for(e.lastStringValue="";$s(t=e.current());)e.lastStringValue+=Be(t),e.advance();return e.lastStringValue!==""};function $s(e){return Es(e)||e===95}P.regexp_eatUnicodePropertyValue=function(e){var t=0;for(e.lastStringValue="";Wa(t=e.current());)e.lastStringValue+=Be(t),e.advance();return e.lastStringValue!==""};function Wa(e){return $s(e)||sn(e)}P.regexp_eatLoneUnicodePropertyNameOrValue=function(e){return this.regexp_eatUnicodePropertyValue(e)};P.regexp_eatCharacterClass=function(e){if(e.eat(91)){var t=e.eat(94),n=this.regexp_classContents(e);return e.eat(93)||e.raise("Unterminated character class"),t&&n===_e&&e.raise("Negated character class may contain strings"),!0}return!1};P.regexp_classContents=function(e){return e.current()===93?Fe:e.switchV?this.regexp_classSetExpression(e):(this.regexp_nonEmptyClassRanges(e),Fe)};P.regexp_nonEmptyClassRanges=function(e){for(;this.regexp_eatClassAtom(e);){var t=e.lastIntValue;if(e.eat(45)&&this.regexp_eatClassAtom(e)){var n=e.lastIntValue;e.switchU&&(t===-1||n===-1)&&e.raise("Invalid character class"),t!==-1&&n!==-1&&t>n&&e.raise("Range out of order in character class")}}};P.regexp_eatClassAtom=function(e){var t=e.pos;if(e.eat(92)){if(this.regexp_eatClassEscape(e))return!0;if(e.switchU){var n=e.current();(n===99||Ps(n))&&e.raise("Invalid class escape"),e.raise("Invalid escape")}e.pos=t}var r=e.current();return r!==93?(e.lastIntValue=r,e.advance(),!0):!1};P.regexp_eatClassEscape=function(e){var t=e.pos;if(e.eat(98))return e.lastIntValue=8,!0;if(e.switchU&&e.eat(45))return e.lastIntValue=45,!0;if(!e.switchU&&e.eat(99)){if(this.regexp_eatClassControlLetter(e))return!0;e.pos=t}return this.regexp_eatCharacterClassEscape(e)||this.regexp_eatCharacterEscape(e)};P.regexp_classSetExpression=function(e){var t=Fe,n;if(!this.regexp_eatClassSetRange(e))if(n=this.regexp_eatClassSetOperand(e)){n===_e&&(t=_e);for(var r=e.pos;e.eatChars([38,38]);){if(e.current()!==38&&(n=this.regexp_eatClassSetOperand(e))){n!==_e&&(t=Fe);continue}e.raise("Invalid character in character class")}if(r!==e.pos)return t;for(;e.eatChars([45,45]);)this.regexp_eatClassSetOperand(e)||e.raise("Invalid character in character class");if(r!==e.pos)return t}else e.raise("Invalid character in character class");for(;;)if(!this.regexp_eatClassSetRange(e)){if(n=this.regexp_eatClassSetOperand(e),!n)return t;n===_e&&(t=_e)}};P.regexp_eatClassSetRange=function(e){var t=e.pos;if(this.regexp_eatClassSetCharacter(e)){var n=e.lastIntValue;if(e.eat(45)&&this.regexp_eatClassSetCharacter(e)){var r=e.lastIntValue;return n!==-1&&r!==-1&&n>r&&e.raise("Range out of order in character class"),!0}e.pos=t}return!1};P.regexp_eatClassSetOperand=function(e){return this.regexp_eatClassSetCharacter(e)?Fe:this.regexp_eatClassStringDisjunction(e)||this.regexp_eatNestedClass(e)};P.regexp_eatNestedClass=function(e){var t=e.pos;if(e.eat(91)){var n=e.eat(94),r=this.regexp_classContents(e);if(e.eat(93))return n&&r===_e&&e.raise("Negated character class may contain strings"),r;e.pos=t}if(e.eat(92)){var s=this.regexp_eatCharacterClassEscape(e);if(s)return s;e.pos=t}return null};P.regexp_eatClassStringDisjunction=function(e){var t=e.pos;if(e.eatChars([92,113])){if(e.eat(123)){var n=this.regexp_classStringDisjunctionContents(e);if(e.eat(125))return n}else e.raise("Invalid escape");e.pos=t}return null};P.regexp_classStringDisjunctionContents=function(e){for(var t=this.regexp_classString(e);e.eat(124);)this.regexp_classString(e)===_e&&(t=_e);return t};P.regexp_classString=function(e){for(var t=0;this.regexp_eatClassSetCharacter(e);)t++;return t===1?Fe:_e};P.regexp_eatClassSetCharacter=function(e){var t=e.pos;if(e.eat(92))return this.regexp_eatCharacterEscape(e)||this.regexp_eatClassSetReservedPunctuator(e)?!0:e.eat(98)?(e.lastIntValue=8,!0):(e.pos=t,!1);var n=e.current();return n<0||n===e.lookahead()&&Ja(n)||za(n)?!1:(e.advance(),e.lastIntValue=n,!0)};function Ja(e){return e===33||e>=35&&e<=38||e>=42&&e<=44||e===46||e>=58&&e<=64||e===94||e===96||e===126}function za(e){return e===40||e===41||e===45||e===47||e>=91&&e<=93||e>=123&&e<=125}P.regexp_eatClassSetReservedPunctuator=function(e){var t=e.current();return Ga(t)?(e.lastIntValue=t,e.advance(),!0):!1};function Ga(e){return e===33||e===35||e===37||e===38||e===44||e===45||e>=58&&e<=62||e===64||e===96||e===126}P.regexp_eatClassControlLetter=function(e){var t=e.current();return sn(t)||t===95?(e.lastIntValue=t%32,e.advance(),!0):!1};P.regexp_eatHexEscapeSequence=function(e){var t=e.pos;if(e.eat(120)){if(this.regexp_eatFixedHexDigits(e,2))return!0;e.switchU&&e.raise("Invalid escape"),e.pos=t}return!1};P.regexp_eatDecimalDigits=function(e){var t=e.pos,n=0;for(e.lastIntValue=0;sn(n=e.current());)e.lastIntValue=10*e.lastIntValue+(n-48),e.advance();return e.pos!==t};function sn(e){return e>=48&&e<=57}P.regexp_eatHexDigits=function(e){var t=e.pos,n=0;for(e.lastIntValue=0;Cs(n=e.current());)e.lastIntValue=16*e.lastIntValue+As(n),e.advance();return e.pos!==t};function Cs(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function As(e){return e>=65&&e<=70?10+(e-65):e>=97&&e<=102?10+(e-97):e-48}P.regexp_eatLegacyOctalEscapeSequence=function(e){if(this.regexp_eatOctalDigit(e)){var t=e.lastIntValue;if(this.regexp_eatOctalDigit(e)){var n=e.lastIntValue;t<=3&&this.regexp_eatOctalDigit(e)?e.lastIntValue=t*64+n*8+e.lastIntValue:e.lastIntValue=t*8+n}else e.lastIntValue=t;return!0}return!1};P.regexp_eatOctalDigit=function(e){var t=e.current();return Ps(t)?(e.lastIntValue=t-48,e.advance(),!0):(e.lastIntValue=0,!1)};function Ps(e){return e>=48&&e<=55}P.regexp_eatFixedHexDigits=function(e,t){var n=e.pos;e.lastIntValue=0;for(var r=0;r<t;++r){var s=e.current();if(!Cs(s))return e.pos=n,!1;e.lastIntValue=16*e.lastIntValue+As(s),e.advance()}return!0};var Gn=function(t){this.type=t.type,this.value=t.value,this.start=t.start,this.end=t.end,t.options.locations&&(this.loc=new Xt(t,t.startLoc,t.endLoc)),t.options.ranges&&(this.range=[t.start,t.end])},D=ne.prototype;D.next=function(e){!e&&this.type.keyword&&this.containsEsc&&this.raiseRecoverable(this.start,"Escape sequence in keyword "+this.type.keyword),this.options.onToken&&this.options.onToken(new Gn(this)),this.lastTokEnd=this.end,this.lastTokStart=this.start,this.lastTokEndLoc=this.endLoc,this.lastTokStartLoc=this.startLoc,this.nextToken()};D.getToken=function(){return this.next(),new Gn(this)};typeof Symbol<"u"&&(D[Symbol.iterator]=function(){var e=this;return{next:function(){var t=e.getToken();return{done:t.type===h.eof,value:t}}}});D.nextToken=function(){var e=this.curContext();if((!e||!e.preserveSpace)&&this.skipSpace(),this.start=this.pos,this.options.locations&&(this.startLoc=this.curPosition()),this.pos>=this.input.length)return this.finishToken(h.eof);if(e.override)return e.override(this);this.readToken(this.fullCharCodeAtPos())};D.readToken=function(e){return Ce(e,this.options.ecmaVersion>=6)||e===92?this.readWord():this.getTokenFromCode(e)};D.fullCharCodeAtPos=function(){var e=this.input.charCodeAt(this.pos);if(e<=55295||e>=56320)return e;var t=this.input.charCodeAt(this.pos+1);return t<=56319||t>=57344?e:(e<<10)+t-56613888};D.skipBlockComment=function(){var e=this.options.onComment&&this.curPosition(),t=this.pos,n=this.input.indexOf("*/",this.pos+=2);if(n===-1&&this.raise(this.pos-2,"Unterminated comment"),this.pos=n+2,this.options.locations)for(var r=void 0,s=t;(r=es(this.input,s,this.pos))>-1;)++this.curLine,s=this.lineStart=r;this.options.onComment&&this.options.onComment(!0,this.input.slice(t+2,n),t,this.pos,e,this.curPosition())};D.skipLineComment=function(e){for(var t=this.pos,n=this.options.onComment&&this.curPosition(),r=this.input.charCodeAt(this.pos+=e);this.pos<this.input.length&&!ct(r);)r=this.input.charCodeAt(++this.pos);this.options.onComment&&this.options.onComment(!1,this.input.slice(t+e,this.pos),t,this.pos,n,this.curPosition())};D.skipSpace=function(){e:for(;this.pos<this.input.length;){var e=this.input.charCodeAt(this.pos);switch(e){case 32:case 160:++this.pos;break;case 13:this.input.charCodeAt(this.pos+1)===10&&++this.pos;case 10:case 8232:case 8233:++this.pos,this.options.locations&&(++this.curLine,this.lineStart=this.pos);break;case 47:switch(this.input.charCodeAt(this.pos+1)){case 42:this.skipBlockComment();break;case 47:this.skipLineComment(2);break;default:break e}break;default:if(e>8&&e<14||e>=5760&&ts.test(String.fromCharCode(e)))++this.pos;else break e}}};D.finishToken=function(e,t){this.end=this.pos,this.options.locations&&(this.endLoc=this.curPosition());var n=this.type;this.type=e,this.value=t,this.updateContext(n)};D.readToken_dot=function(){var e=this.input.charCodeAt(this.pos+1);if(e>=48&&e<=57)return this.readNumber(!0);var t=this.input.charCodeAt(this.pos+2);return this.options.ecmaVersion>=6&&e===46&&t===46?(this.pos+=3,this.finishToken(h.ellipsis)):(++this.pos,this.finishToken(h.dot))};D.readToken_slash=function(){var e=this.input.charCodeAt(this.pos+1);return this.exprAllowed?(++this.pos,this.readRegexp()):e===61?this.finishOp(h.assign,2):this.finishOp(h.slash,1)};D.readToken_mult_modulo_exp=function(e){var t=this.input.charCodeAt(this.pos+1),n=1,r=e===42?h.star:h.modulo;return this.options.ecmaVersion>=7&&e===42&&t===42&&(++n,r=h.starstar,t=this.input.charCodeAt(this.pos+2)),t===61?this.finishOp(h.assign,n+1):this.finishOp(r,n)};D.readToken_pipe_amp=function(e){var t=this.input.charCodeAt(this.pos+1);if(t===e){if(this.options.ecmaVersion>=12){var n=this.input.charCodeAt(this.pos+2);if(n===61)return this.finishOp(h.assign,3)}return this.finishOp(e===124?h.logicalOR:h.logicalAND,2)}return t===61?this.finishOp(h.assign,2):this.finishOp(e===124?h.bitwiseOR:h.bitwiseAND,1)};D.readToken_caret=function(){var e=this.input.charCodeAt(this.pos+1);return e===61?this.finishOp(h.assign,2):this.finishOp(h.bitwiseXOR,1)};D.readToken_plus_min=function(e){var t=this.input.charCodeAt(this.pos+1);return t===e?t===45&&!this.inModule&&this.input.charCodeAt(this.pos+2)===62&&(this.lastTokEnd===0||me.test(this.input.slice(this.lastTokEnd,this.pos)))?(this.skipLineComment(3),this.skipSpace(),this.nextToken()):this.finishOp(h.incDec,2):t===61?this.finishOp(h.assign,2):this.finishOp(h.plusMin,1)};D.readToken_lt_gt=function(e){var t=this.input.charCodeAt(this.pos+1),n=1;return t===e?(n=e===62&&this.input.charCodeAt(this.pos+2)===62?3:2,this.input.charCodeAt(this.pos+n)===61?this.finishOp(h.assign,n+1):this.finishOp(h.bitShift,n)):t===33&&e===60&&!this.inModule&&this.input.charCodeAt(this.pos+2)===45&&this.input.charCodeAt(this.pos+3)===45?(this.skipLineComment(4),this.skipSpace(),this.nextToken()):(t===61&&(n=2),this.finishOp(h.relational,n))};D.readToken_eq_excl=function(e){var t=this.input.charCodeAt(this.pos+1);return t===61?this.finishOp(h.equality,this.input.charCodeAt(this.pos+2)===61?3:2):e===61&&t===62&&this.options.ecmaVersion>=6?(this.pos+=2,this.finishToken(h.arrow)):this.finishOp(e===61?h.eq:h.prefix,1)};D.readToken_question=function(){var e=this.options.ecmaVersion;if(e>=11){var t=this.input.charCodeAt(this.pos+1);if(t===46){var n=this.input.charCodeAt(this.pos+2);if(n<48||n>57)return this.finishOp(h.questionDot,2)}if(t===63){if(e>=12){var r=this.input.charCodeAt(this.pos+2);if(r===61)return this.finishOp(h.assign,3)}return this.finishOp(h.coalesce,2)}}return this.finishOp(h.question,1)};D.readToken_numberSign=function(){var e=this.options.ecmaVersion,t=35;if(e>=13&&(++this.pos,t=this.fullCharCodeAtPos(),Ce(t,!0)||t===92))return this.finishToken(h.privateId,this.readWord1());this.raise(this.pos,"Unexpected character '"+Be(t)+"'")};D.getTokenFromCode=function(e){switch(e){case 46:return this.readToken_dot();case 40:return++this.pos,this.finishToken(h.parenL);case 41:return++this.pos,this.finishToken(h.parenR);case 59:return++this.pos,this.finishToken(h.semi);case 44:return++this.pos,this.finishToken(h.comma);case 91:return++this.pos,this.finishToken(h.bracketL);case 93:return++this.pos,this.finishToken(h.bracketR);case 123:return++this.pos,this.finishToken(h.braceL);case 125:return++this.pos,this.finishToken(h.braceR);case 58:return++this.pos,this.finishToken(h.colon);case 96:if(this.options.ecmaVersion<6)break;return++this.pos,this.finishToken(h.backQuote);case 48:var t=this.input.charCodeAt(this.pos+1);if(t===120||t===88)return this.readRadixNumber(16);if(this.options.ecmaVersion>=6){if(t===111||t===79)return this.readRadixNumber(8);if(t===98||t===66)return this.readRadixNumber(2)}case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.readNumber(!1);case 34:case 39:return this.readString(e);case 47:return this.readToken_slash();case 37:case 42:return this.readToken_mult_modulo_exp(e);case 124:case 38:return this.readToken_pipe_amp(e);case 94:return this.readToken_caret();case 43:case 45:return this.readToken_plus_min(e);case 60:case 62:return this.readToken_lt_gt(e);case 61:case 33:return this.readToken_eq_excl(e);case 63:return this.readToken_question();case 126:return this.finishOp(h.prefix,1);case 35:return this.readToken_numberSign()}this.raise(this.pos,"Unexpected character '"+Be(e)+"'")};D.finishOp=function(e,t){var n=this.input.slice(this.pos,this.pos+t);return this.pos+=t,this.finishToken(e,n)};D.readRegexp=function(){for(var e,t,n=this.pos;;){this.pos>=this.input.length&&this.raise(n,"Unterminated regular expression");var r=this.input.charAt(this.pos);if(me.test(r)&&this.raise(n,"Unterminated regular expression"),e)e=!1;else{if(r==="[")t=!0;else if(r==="]"&&t)t=!1;else if(r==="/"&&!t)break;e=r==="\\"}++this.pos}var s=this.input.slice(n,this.pos);++this.pos;var a=this.pos,i=this.readWord1();this.containsEsc&&this.unexpected(a);var o=this.regexpState||(this.regexpState=new Pe(this));o.reset(n,s,i),this.validateRegExpFlags(o),this.validateRegExpPattern(o);var u=null;try{u=new RegExp(s,i)}catch{}return this.finishToken(h.regexp,{pattern:s,flags:i,value:u})};D.readInt=function(e,t,n){for(var r=this.options.ecmaVersion>=12&&t===void 0,s=n&&this.input.charCodeAt(this.pos)===48,a=this.pos,i=0,o=0,u=0,c=t??1/0;u<c;++u,++this.pos){var l=this.input.charCodeAt(this.pos),p=void 0;if(r&&l===95){s&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed in legacy octal numeric literals"),o===95&&this.raiseRecoverable(this.pos,"Numeric separator must be exactly one underscore"),u===0&&this.raiseRecoverable(this.pos,"Numeric separator is not allowed at the first of digits"),o=l;continue}if(l>=97?p=l-97+10:l>=65?p=l-65+10:l>=48&&l<=57?p=l-48:p=1/0,p>=e)break;o=l,i=i*e+p}return r&&o===95&&this.raiseRecoverable(this.pos-1,"Numeric separator is not allowed at the last of digits"),this.pos===a||t!=null&&this.pos-a!==t?null:i};function Ha(e,t){return t?parseInt(e,8):parseFloat(e.replace(/_/g,""))}function js(e){return typeof BigInt!="function"?null:BigInt(e.replace(/_/g,""))}D.readRadixNumber=function(e){var t=this.pos;this.pos+=2;var n=this.readInt(e);return n==null&&this.raise(this.start+2,"Expected number in radix "+e),this.options.ecmaVersion>=11&&this.input.charCodeAt(this.pos)===110?(n=js(this.input.slice(t,this.pos)),++this.pos):Ce(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(h.num,n)};D.readNumber=function(e){var t=this.pos;!e&&this.readInt(10,void 0,!0)===null&&this.raise(t,"Invalid number");var n=this.pos-t>=2&&this.input.charCodeAt(t)===48;n&&this.strict&&this.raise(t,"Invalid number");var r=this.input.charCodeAt(this.pos);if(!n&&!e&&this.options.ecmaVersion>=11&&r===110){var s=js(this.input.slice(t,this.pos));return++this.pos,Ce(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number"),this.finishToken(h.num,s)}n&&/[89]/.test(this.input.slice(t,this.pos))&&(n=!1),r===46&&!n&&(++this.pos,this.readInt(10),r=this.input.charCodeAt(this.pos)),(r===69||r===101)&&!n&&(r=this.input.charCodeAt(++this.pos),(r===43||r===45)&&++this.pos,this.readInt(10)===null&&this.raise(t,"Invalid number")),Ce(this.fullCharCodeAtPos())&&this.raise(this.pos,"Identifier directly after number");var a=Ha(this.input.slice(t,this.pos),n);return this.finishToken(h.num,a)};D.readCodePoint=function(){var e=this.input.charCodeAt(this.pos),t;if(e===123){this.options.ecmaVersion<6&&this.unexpected();var n=++this.pos;t=this.readHexChar(this.input.indexOf("}",this.pos)-this.pos),++this.pos,t>1114111&&this.invalidStringToken(n,"Code point out of bounds")}else t=this.readHexChar(4);return t};D.readString=function(e){for(var t="",n=++this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated string constant");var r=this.input.charCodeAt(this.pos);if(r===e)break;r===92?(t+=this.input.slice(n,this.pos),t+=this.readEscapedChar(!1),n=this.pos):r===8232||r===8233?(this.options.ecmaVersion<10&&this.raise(this.start,"Unterminated string constant"),++this.pos,this.options.locations&&(this.curLine++,this.lineStart=this.pos)):(ct(r)&&this.raise(this.start,"Unterminated string constant"),++this.pos)}return t+=this.input.slice(n,this.pos++),this.finishToken(h.string,t)};var Is={};D.tryReadTemplateToken=function(){this.inTemplateElement=!0;try{this.readTmplToken()}catch(e){if(e===Is)this.readInvalidTemplateToken();else throw e}this.inTemplateElement=!1};D.invalidStringToken=function(e,t){if(this.inTemplateElement&&this.options.ecmaVersion>=9)throw Is;this.raise(e,t)};D.readTmplToken=function(){for(var e="",t=this.pos;;){this.pos>=this.input.length&&this.raise(this.start,"Unterminated template");var n=this.input.charCodeAt(this.pos);if(n===96||n===36&&this.input.charCodeAt(this.pos+1)===123)return this.pos===this.start&&(this.type===h.template||this.type===h.invalidTemplate)?n===36?(this.pos+=2,this.finishToken(h.dollarBraceL)):(++this.pos,this.finishToken(h.backQuote)):(e+=this.input.slice(t,this.pos),this.finishToken(h.template,e));if(n===92)e+=this.input.slice(t,this.pos),e+=this.readEscapedChar(!0),t=this.pos;else if(ct(n)){switch(e+=this.input.slice(t,this.pos),++this.pos,n){case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:e+=`
|
|
6
|
+
`;break;default:e+=String.fromCharCode(n);break}this.options.locations&&(++this.curLine,this.lineStart=this.pos),t=this.pos}else++this.pos}};D.readInvalidTemplateToken=function(){for(;this.pos<this.input.length;this.pos++)switch(this.input[this.pos]){case"\\":++this.pos;break;case"$":if(this.input[this.pos+1]!=="{")break;case"`":return this.finishToken(h.invalidTemplate,this.input.slice(this.start,this.pos));case"\r":this.input[this.pos+1]===`
|
|
7
|
+
`&&++this.pos;case`
|
|
8
|
+
`:case"\u2028":case"\u2029":++this.curLine,this.lineStart=this.pos+1;break}this.raise(this.start,"Unterminated template")};D.readEscapedChar=function(e){var t=this.input.charCodeAt(++this.pos);switch(++this.pos,t){case 110:return`
|
|
9
|
+
`;case 114:return"\r";case 120:return String.fromCharCode(this.readHexChar(2));case 117:return Be(this.readCodePoint());case 116:return" ";case 98:return"\b";case 118:return"\v";case 102:return"\f";case 13:this.input.charCodeAt(this.pos)===10&&++this.pos;case 10:return this.options.locations&&(this.lineStart=this.pos,++this.curLine),"";case 56:case 57:if(this.strict&&this.invalidStringToken(this.pos-1,"Invalid escape sequence"),e){var n=this.pos-1;this.invalidStringToken(n,"Invalid escape sequence in template string")}default:if(t>=48&&t<=55){var r=this.input.substr(this.pos-1,3).match(/^[0-7]+/)[0],s=parseInt(r,8);return s>255&&(r=r.slice(0,-1),s=parseInt(r,8)),this.pos+=r.length-1,t=this.input.charCodeAt(this.pos),(r!=="0"||t===56||t===57)&&(this.strict||e)&&this.invalidStringToken(this.pos-1-r.length,e?"Octal literal in template string":"Octal literal in strict mode"),String.fromCharCode(s)}return ct(t)?(this.options.locations&&(this.lineStart=this.pos,++this.curLine),""):String.fromCharCode(t)}};D.readHexChar=function(e){var t=this.pos,n=this.readInt(16,e);return n===null&&this.invalidStringToken(t,"Bad character escape sequence"),n};D.readWord1=function(){this.containsEsc=!1;for(var e="",t=!0,n=this.pos,r=this.options.ecmaVersion>=6;this.pos<this.input.length;){var s=this.fullCharCodeAtPos();if(Je(s,r))this.pos+=s<=65535?1:2;else if(s===92){this.containsEsc=!0,e+=this.input.slice(n,this.pos);var a=this.pos;this.input.charCodeAt(++this.pos)!==117&&this.invalidStringToken(this.pos,"Expecting Unicode escape sequence \\uXXXX"),++this.pos;var i=this.readCodePoint();(t?Ce:Je)(i,r)||this.invalidStringToken(a,"Invalid Unicode escape"),e+=Be(i),n=this.pos}else break;t=!1}return e+this.input.slice(n,this.pos)};D.readWord=function(){var e=this.readWord1(),t=h.name;return this.keywords.test(e)&&(t=Vn[e]),this.finishToken(t,e)};var Ka="8.15.0";ne.acorn={Parser:ne,version:Ka,defaultOptions:Fn,Position:vt,SourceLocation:Xt,getLineInfo:rs,Node:rn,TokenType:q,tokTypes:h,keywordTypes:Vn,TokContext:ke,tokContexts:Q,isIdentifierChar:Je,isIdentifierStart:Ce,Token:Gn,isNewLine:ct,lineBreak:me,lineBreakG:ba,nonASCIIwhitespace:ts};function je(e,t){return ne.parse(e,t)}function $t(e,t,n){return ne.parseExpressionAt(e,t,n)}var K=class extends Error{line;column;source;filename;constructor(t,n,r,s){let a=`${s||"<source>"}:${n.line}:${n.column}`;super(`${t} at ${a}`),this.name="TranspileError",this.line=n.line,this.column=n.column,this.source=r,this.filename=s}},te=class extends K{constructor(t,n,r,s){super(t,n,r,s),this.name="SyntaxError"}formatWithContext(t=2){if(!this.source)return this.message;let n=this.source.split(`
|
|
10
|
+
`),r=this.line-1,s=Math.max(0,r-t),a=Math.min(n.length-1,r+t),i=[],o=String(a+1).length;for(let u=s;u<=a;u++){let c=String(u+1).padStart(o),l=u===r?">":" ";if(i.push(`${l} ${c} | ${n[u]}`),u===r){let p=" ".repeat(o+4+this.column);i.push(`${p}^ ${this.message.split(" at ")[0]}`)}}return i.join(`
|
|
11
|
+
`)}};function Se(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,helpers:e.helpers,helperSteps:e.helperSteps,helperTransforming:e.helperTransforming}}function Z(e){return e.loc?{line:e.loc.start.line,column:e.loc.start.column}:{line:1,column:0}}function Za(e,t){let n=e.match(t);if(!n)return null;let r=n.index+n[0].length-1,s=1,a=r+1;for(;a<e.length&&s>0;)e[a]==="{"?s++:e[a]==="}"&&s--,a++;if(s!==0)return null;let i=e.slice(r,a),o=[n[0].slice(0,-1)+i,i];return o.index=n.index,o}function Bs(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\btry\s*\{/);if(r){let a=n+r[0].length-1+1,i=1,o=a;for(;o<e.length&&i>0;){let c=e[o];c==="{"?i++:c==="}"&&i--,o++}if(i!==0){t+=e[n],n++;continue}if(e.slice(o).match(/^\s*(catch|finally)\b/))t+=e.slice(n,o),n=o;else{let c=e.slice(a,o-1);t+=`try {${c}} catch (__try_err) { return new (__tjs?.MonadicError ?? Error)(__try_err?.message || String(__try_err), 'try', undefined, undefined, __tjs?.getStack?.()) }`,n=o}}else t+=e[n],n++}return t}function Fs(e){let t=[],n="",r=0,s=0;for(;r<e.length;){let a=e.slice(r).match(/^\bwasm\s*\{/);if(a){let i=r,o=r+a[0].length,u=1,c=o;for(;c<e.length&&u>0;){let x=e[c];x==="{"?u++:x==="}"&&u--,c++}if(u!==0){n+=e[r],r++;continue}let l=e.slice(o,c-1),p,f=c,d=e.slice(c).match(/^\s*fallback\s*\{/);if(d){let x=c+d[0].length;u=1;let E=x;for(;E<e.length&&u>0;){let $=e[E];$==="{"?u++:$==="}"&&u--,E++}u===0&&(p=e.slice(x,E-1),f=E)}let y=Xa(l).map(x=>{let E=eo(e,i,x);return E?`${x}: ${E}`:x}),w={id:`__tjs_wasm_${s}`,body:l,fallback:p,captures:y,start:i,end:f};t.push(w);let k=p??l,S=y.map(x=>x.split(":")[0].trim()),b=S.length>0?S.join(", "):"",_=S.length>0?`globalThis.${w.id}(${b})`:`globalThis.${w.id}()`,v=`(globalThis.${w.id} ? ${_} : (() => {${k}})())`;n+=v,r=f,s++}else n+=e[r],r++}return{source:n,blocks:t}}function Ds(e){let t=[],n="",r=0;for(;r<e.length;){let s=/^\b(export\s+)?wasm\s+function\s+(\w+)\s*\(/,a=e.slice(r).match(s);if(!a){n+=e[r],r++;continue}let i=!!a[1],o=a[2],u=r,c=r+a[0].length,l=1,p=c;for(;p<e.length&&l>0;)e[p]==="("?l++:e[p]===")"&&l--,p++;if(l!==0){n+=e[r],r++;continue}let f=e.slice(c,p-1);if(f.match(/^\s*!/))throw new te(`Unsafe wasm functions (with \`!\` marker) are reserved for a future phase. Remove the bang from \`wasm function ${o}\` to declare it as a regular (pure) wasm function, or wait until the unsafe variant is implemented.`,Le(e,u));let g,y=p,w=e.slice(p).match(/^\s*:\s*(\w+)/);w&&(g=w[1],y=p+w[0].length);let k=e.slice(y).match(/^\s*\{/);if(!k){n+=e[r],r++;continue}let S=y+k[0].length,b=1,_=S;for(;_<e.length&&b>0;)e[_]==="{"?b++:e[_]==="}"&&b--,_++;if(b!==0){n+=e[r],r++;continue}let v=e.slice(S,_-1),x=Qa(f),E=`__tjs_wasm_${o}`,$={id:E,name:o,returnType:g,body:v,captures:x,start:u,end:_};t.push($);let C=x.map(F=>F.split(":")[0].trim()),M=`${i?"export ":""}function ${o}(${C.join(", ")}) { return globalThis.${E}(${C.join(", ")}) }`;n+=M,r=_}return{source:n,blocks:t}}function Ls(e,t){let{loader:n,importerPath:r}=t;if(!n)return{source:e,blocks:[]};let s=[],a=new Set;function i(c,l){if(!a.has(c.id)){s.push(c),a.add(c.id);for(let[p,f]of l){if(p===c.name||a.has(f.id))continue;new RegExp(`\\b${p}\\s*\\(`).test(c.body)&&i(f,l)}}}let o=/^(\s*)import\s*\{([^}]*?)\}\s*from\s*(['"])([^'"]+)\3\s*;?\s*$/gm;return{source:e.replace(o,(c,l,p,f,d)=>{let g=n.load(d,r);if(!g)return c;let y=new Map;for(let v of g.parseResult.wasmBlocks)v.name&&y.set(v.name,v);if(y.size===0)return c;let w=p.split(",").map(v=>v.trim()).filter(v=>v.length>0),k=[],S=[];for(let v of w){let x=v.match(/^(\w+)(?:\s+as\s+(\w+))?$/);if(!x){S.push(v);continue}let E=x[1],$=x[2]??x[1],C=y.get(E);if(!C){S.push(v);continue}i(C,y);let I=C.captures.map(M=>M.split(":")[0].trim());k.push(`function ${$}(${I.join(", ")}) { return globalThis.${C.id}(${I.join(", ")}) }`)}let b=k.join(`
|
|
12
|
+
`);if(S.length===0)return b?`${l}${b}`:`${l}`;let _=`${l}import { ${S.join(", ")} } from '${d}'`;return b?`${_}
|
|
13
|
+
${l}${b}`:_}),blocks:s}}function Qa(e){let t=e.trim();return t?t.split(",").map(n=>n.trim()).filter(n=>n.length>0):[]}function Ya(e){return e.startsWith("f32x4_")||e.startsWith("v128_")}function Xa(e){let t=e.replace(/\/\/[^\n]*/g,"").replace(/\/\*[\s\S]*?\*\//g,""),n=new Set,r=/\.([a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,s;for(;(s=r.exec(t))!==null;)n.add(s[1]);let a=/(?<!\.)(\b[a-zA-Z_$][a-zA-Z0-9_$]*)\b/g,i=new Set;for(;(s=a.exec(t))!==null;)i.add(s[1]);for(let f of n){if(!i.has(f))continue;let d=new RegExp(`(?<!\\.)\\b${f}\\b`,"g"),g=new RegExp(`\\.${f}\\b`,"g"),y=t.match(d)?.length||0,w=t.match(g)?.length||0;y<=w&&i.delete(f)}let o=new Set,u=/\b(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=u.exec(t))!==null;)o.add(s[1]);let c=/\bfor\s*\(\s*(?:let|const|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;for(;(s=c.exec(t))!==null;)o.add(s[1]);let l=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"]),p=[];for(let f of i)!o.has(f)&&!l.has(f)&&!Ya(f)&&p.push(f);return p.sort()}function eo(e,t,n){let r=e.slice(0,t),s=/function\s+\w+\s*\(([^)]*)\)\s*(?:->.*?)?\s*\{[^}]*$/,a=r.match(s);if(!a){let i=/(?:const|let|var)?\s*\w+\s*=\s*(?:async\s*)?\(([^)]*)\)\s*(?:=>|->)?\s*\{[^}]*$/,o=r.match(i);return o?Ns(o[1],n):void 0}return Ns(a[1],n)}function Ns(e,t){let n=e.split(",").map(r=>r.trim());for(let r of n){let s=r.match(new RegExp(`^${t}\\s*:\\s*([A-Za-z][A-Za-z0-9]*)`));if(s)return s[1];let a=r.match(new RegExp(`^${t}\\s*=\\s*(Float32Array|Float64Array|Int32Array|Uint8Array|Int8Array|Int16Array|Uint16Array|Uint32Array)`));if(a)return a[1]}}function At(e){let t=`([\\w][\\w.\\[\\]()]*|null|undefined|true|false|\\d+(?:\\.\\d+)?|'[^']*'|"[^"]*")`,n=new RegExp(t+"\\s+IsNot\\s+"+t,"g");e=e.replace(n,"IsNot($1, $2)");let r=new RegExp(t+"\\s+Is\\s+"+t,"g");return e=e.replace(r,"Is($1, $2)"),e}function Vs(e){let t=/^[\s]*[([`]/,n=/[{([,;:+\-*/%=&|?<>!~^]\s*$|^\s*$/,r=/\b(return|throw|yield|await|case|default|extends|new|typeof|void|delete|in|of|instanceof)\s*$/,s=e.split(`
|
|
14
|
+
`),a=[],i=!1;for(let o=0;o<s.length;o++){let u=s[o],c=o>0?s[o-1]:"";if(i){a.push(u),u.includes("*/")&&(i=!1);continue}let l=u.indexOf("/*"),p=u.indexOf("*/");if(l!==-1&&(p===-1||p<l)){i=!0,a.push(u);continue}if(o>0&&t.test(u)){let f=c.replace(/\/\/.*$/,"").replace(/\/\*.*\*\/\s*$/,"");if(!n.test(f)&&!r.test(f)){let d=u.match(/^(\s*)/),g=d?d[1]:"",y=u.slice(g.length);a.push(g+";"+y);continue}}a.push(u)}return a.join(`
|
|
15
|
+
`)}function to(e){let t=[],n=0,r="normal",s=[];for(;n<e.length;){let i=e[n],o=e[n+1];switch(r){case"single-string":if(i==="\\"&&n+1<e.length){n+=2;continue}i==="'"&&(r="normal"),n++;continue;case"double-string":if(i==="\\"&&n+1<e.length){n+=2;continue}i==='"'&&(r="normal"),n++;continue;case"template-string":if(i==="\\"&&n+1<e.length){n+=2;continue}if(i==="$"&&o==="{"){n+=2,s.push(1),r="normal";continue}i==="`"&&(r="normal"),n++;continue;case"line-comment":i===`
|
|
16
|
+
`&&(r="normal"),n++;continue;case"block-comment":if(i==="*"&&o==="/"){n+=2,r="normal";continue}n++;continue;case"regex":if(i==="\\"&&n+1<e.length){n+=2;continue}if(i==="["){for(n++;n<e.length&&e[n]!=="]";)e[n]==="\\"&&n+1<e.length?n+=2:n++;n<e.length&&n++;continue}if(i==="/"){for(n++;n<e.length&&/[gimsuy]/.test(e[n]);)n++;r="normal";continue}n++;continue;case"normal":if(s.length>0){if(i==="{")s[s.length-1]++;else if(i==="}"&&(s[s.length-1]--,s[s.length-1]===0)){s.pop(),n++,r="template-string";continue}}if(i==="'"){n++,r="single-string";continue}if(i==='"'){n++,r="double-string";continue}if(i==="`"){n++,r="template-string";continue}if(i==="/"&&o==="/"){n+=2,r="line-comment";continue}if(i==="/"&&o==="*"){n+=2,r="block-comment";continue}if(i==="/"){let u=n-1;for(;u>=0&&/\s/.test(e[u]);)u--;let c=u>=0?e[u]:"";if(!c||/[=(!,;:{[&|?+\-*%<>~^]/.test(c)||u>=5&&/\b(return|case|throw|in|of|typeof|instanceof|new|delete|void)$/.test(e.slice(Math.max(0,u-10),u+1))){n++,r="regex";continue}}if(i==="t"&&e.slice(n,n+6)==="typeof"&&(n===0||!/[\w$]/.test(e[n-1]))&&/\s/.test(e[n+6]??"")){let u=n+6;for(;u<e.length&&/\s/.test(e[u]);)u++;if(u<e.length&&/[a-zA-Z_$]/.test(e[u])){let c=u;for(;u<e.length&&/[\w$]/.test(e[u]);)u++;for(;u<e.length;)if(e[u]==="."&&/[a-zA-Z_$]/.test(e[u+1]??""))for(u++;u<e.length&&/[\w$]/.test(e[u]);)u++;else if(e[u]==="?"&&e[u+1]==="."&&/[a-zA-Z_$]/.test(e[u+2]??""))for(u+=2;u<e.length&&/[\w$]/.test(e[u]);)u++;else break;t.push({keywordStart:n,operandEnd:u,operand:e.slice(c,u)}),n=u;continue}}break}n++}if(t.length===0)return e;let a=e;for(let i=t.length-1;i>=0;i--){let o=t[i];a=a.slice(0,o.keywordStart)+`TypeOf(${o.operand})`+a.slice(o.operandEnd)}return a}function Pt(e){e=to(e);let t=[],n=0,r="normal",s=[];for(;n<e.length;){let i=e[n],o=e[n+1];switch(r){case"single-string":if(i==="\\"&&n+1<e.length){n+=2;continue}i==="'"&&(r="normal"),n++;continue;case"double-string":if(i==="\\"&&n+1<e.length){n+=2;continue}i==='"'&&(r="normal"),n++;continue;case"template-string":if(i==="\\"&&n+1<e.length){n+=2;continue}if(i==="$"&&o==="{"){n+=2,s.push(1),r="normal";continue}i==="`"&&(r="normal"),n++;continue;case"line-comment":i===`
|
|
17
|
+
`&&(r="normal"),n++;continue;case"block-comment":if(i==="*"&&o==="/"){n+=2,r="normal";continue}n++;continue;case"regex":if(i==="\\"&&n+1<e.length){n+=2;continue}if(i==="["){for(n++;n<e.length&&e[n]!=="]";)e[n]==="\\"&&n+1<e.length?n+=2:n++;n<e.length&&n++;continue}if(i==="/"){for(n++;n<e.length&&/[gimsuy]/.test(e[n]);)n++;r="normal";continue}n++;continue;case"normal":if(s.length>0){if(i==="{")s[s.length-1]++;else if(i==="}"&&(s[s.length-1]--,s[s.length-1]===0)){s.pop(),n++,r="template-string";continue}}if(i==="'"){n++,r="single-string";continue}if(i==='"'){n++,r="double-string";continue}if(i==="`"){n++,r="template-string";continue}if(i==="/"&&o==="/"){n+=2,r="line-comment";continue}if(i==="/"&&o==="*"){n+=2,r="block-comment";continue}if(i==="/"){let u=n-1;for(;u>=0&&/\s/.test(e[u]);)u--;let c=u>=0?e[u]:"";if(!c||/[=(!,;:{[&|?+\-*%<>~^]/.test(c)||u>=5&&/\b(return|case|throw|in|of|typeof|instanceof|new|delete|void)$/.test(e.slice(Math.max(0,u-10),u+1))){n++,r="regex";continue}}if(i==="="&&o==="="&&e[n+2]!=="="&&e[n-1]!=="!"){t.push({pos:n,op:"=="}),n+=2;continue}if(i==="!"&&o==="="&&e[n+2]!=="="){t.push({pos:n,op:"!="}),n+=2;continue}break}n++}if(t.length===0)return e;let a=e;for(let i=t.length-1;i>=0;i--){let{pos:o,op:u}=t[i],c=u==="=="?"Eq":"NotEq",l=no(a,o),p=ro(a,o+2),f=a.slice(l,o).trim(),d=a.slice(o+2,p).trim();if(f&&d){let g=a.slice(0,l),y=a.slice(p),k=/[a-zA-Z0-9_$]$/.test(g)?" ":"";a=`${g}${k}${c}(${f}, ${d})${y}`}}return a}function no(e,t){let n=t-1;for(;n>=0&&/\s/.test(e[n]);)n--;if(n<0)return 0;let r=0,s=!1,a="";for(;n>=0;){let i=e[n],o=n>0?e[n-1]:"";if(s){i===a&&o!=="\\"&&(s=!1),n--;continue}if((i==='"'||i==="'"||i==="`")&&o!=="\\"){s=!0,a=i,n--;continue}if(i===")"||i==="]"||i==="}"){r++,n--;continue}if(i==="("||i==="["){if(r>0){r--,n--;continue}return n+1}if(i==="{"){if(r>0){r--,n--;continue}return n+1}if(r>0){n--;continue}if(i===";")return n+1;if(/[a-z]/.test(i)){let u=n+1,c=n;for(;c>0&&/[a-z]/i.test(e[c-1]);)c--;let l=e.slice(c,u),p=c>0?e[c-1]:"";if(!/[a-zA-Z0-9_$]/.test(p)){if(["return","throw","case","typeof","void","delete","await","yield"].includes(l))return u;if(l==="new")return c}}if(i===">"&&o==="="||i==="="&&o!=="="&&o!=="!"&&o!=="<"&&o!==">"||i==="&"&&o==="&"||i==="|"&&o==="|"||i==="?"||i===":"||i===",")return n+1;n--}return 0}function ro(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;if(n>=e.length)return e.length;let r=0,s=!1,a="";for(;n<e.length;){let i=e[n],o=n+1<e.length?e[n+1]:"";if(s){i===a&&e[n-1]!=="\\"&&(s=!1),n++;continue}if((i==='"'||i==="'"||i==="`")&&e[n-1]!=="\\"){s=!0,a=i,n++;continue}if(i==="("||i==="["||i==="{"){r++,n++;continue}if(i===")"||i==="]"||i==="}"){if(r>0){r--,n++;continue}return n}if(r>0){n++;continue}if(i===";"||i==="&"&&o==="&"||i==="|"&&o==="|"||i==="?"||i===":"||i===","||(i==="="||i==="!")&&o==="="&&e[n+2]!=="=")return n;n++}return e.length}function qs(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\bType\s+([A-Z_][a-zA-Z0-9_]*)\s*/);if(r){let s=r[1],a=n+r[0].length,i=s,o=!1,u=e.slice(a).match(/^(['"`])([^]*?)\1\s*/);if(u){let f=a+u[0].length,d=e[f],g=d===void 0||f>=e.length||d!=="="&&d!=="{";if(d==="="||d==="{")i=u[2],o=!0,a=f;else if(g){let y=u[0].trim(),w=u[0].slice(y.length);t+=`const ${s} = Type('${s}', ${y})${w}`,n=f;continue}}let c,l=a,p=e.slice(a).match(/^=\s*/);if(p){a+=p[0].length;let f=e.slice(a).match(/^(\+?\d+(?:\.\d+)?|['"`][^'"`]*['"`]|\{[^}]*\}|\[[^\]]*\]|true|false|null)/);if(f){c=f[0],a+=f[0].length,l=a;let d=e.slice(a).match(/^\s*/);d&&(a+=d[0].length)}}if(e[a]==="{"){let f=a+1,d=1,g=f;for(;g<e.length&&d>0;){let v=e[g];v==="{"?d++:v==="}"&&d--,g++}if(d!==0){t+=e[n],n++;continue}let y=e.slice(f,g-1).trim(),w=g,k=y.match(/description\s*:\s*(['"`])([^]*?)\1/);k&&!o&&(i=k[2]);let S,b=y.match(/example\s*:\s*/);if(b){let v=b.index+b[0].length,x=ai(y,v);x&&(S=x.value.trim())}let _=y.match(/predicate\s*\(([^)]*)\)\s*\{([^]*)\}/);if(_&&S){let v=_[1].trim(),x=_[2].trim(),E=c?`, ${c}`:"";t+=`const ${s} = Type('${i}', (${v}) => { if (!globalThis.__tjs?.validate(${v}, globalThis.__tjs?.infer(${S}))) return false; ${x} }, ${S}${E})`}else if(_){let v=_[1].trim(),x=_[2].trim(),E=c?`, undefined, ${c}`:"";t+=`const ${s} = Type('${i}', (${v}) => { ${x} }${E})`}else if(S){let v=c?`, ${c}`:"";t+=`const ${s} = Type('${i}', undefined, ${S}${v})`}else c?t+=`const ${s} = Type('${i}', ${c})`:t+=`const ${s} = Type('${i}')`;n=w;continue}else if(c){t+=`const ${s} = Type('${i}', ${c})`,n=l;continue}else if(!u){let f=e.slice(a).match(/^(['"`][^]*?['"`]|\+?\d+(?:\.\d+)?|true|false|null|\{[^]*?\}|\[[^]*?\])/);if(f){let d=f[0];t+=`const ${s} = Type('${s}', ${d})`,n=a+f[0].length;continue}}}t+=e[n],n++}return t}function Us(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\bFunctionPredicate\s+([A-Z_][a-zA-Z0-9_]*)\s*(?:<([^>]+)>)?\s*/);if(r){let s=r[1],a=r[2],i=n+r[0].length;if(e[i]==="{"){let o=1,u=i+1;for(;u<e.length&&o>0;)e[u]==="{"?o++:e[u]==="}"&&o--,u++;if(o===0){let c=e.slice(i+1,u-1).trim(),l=Za(c,/params\s*:\s*\{/),p=c.match(/returns\s*:\s*(.+?)(?:\n|$)/),f=c.match(/returnContract\s*:\s*['"](\w+)['"]/),d=c.match(/description\s*:\s*(['"])([^]*?)\1/),g=[];l&&g.push(`params: ${l[1]}`),p&&g.push(`returns: ${p[1].trim()}`),f&&g.push(`returnContract: '${f[1]}'`);let y=d?d[2]:s;if(a){let w=a.split(",").map(S=>{let b=S.trim().split("=").map(_=>_.trim());if(b.length===2){let _=b[1]==="any"||b[1]==="undefined"?"null":b[1];return`['${b[0]}', ${_}]`}return`'${b[0]}'`}),k=a.split(",").map(S=>S.trim().split("=")[0].trim());t+=`const ${s} = FunctionPredicate('${y}', [${w.join(", ")}], (${k.join(", ")}) => ({ ${g.join(", ")} }))`}else t+=`const ${s} = FunctionPredicate('${y}', { ${g.join(", ")} })`;n=u;continue}}if(e[i]==="("){let o=1,u=i+1;for(;u<e.length&&o>0;)e[u]==="("?o++:e[u]===")"&&o--,u++;if(o===0){let c=e.slice(i+1,u-1).trim(),l=c.indexOf(",");if(l!==-1){let p=c.slice(0,l).trim(),f=c.slice(l+1).trim();t+=`const ${s} = FunctionPredicate(${f}, ${p})`}else t+=`const ${s} = FunctionPredicate('${s}', ${c})`;n=u;continue}}}t+=e[n],n++}return t}function Ws(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\bGeneric\s+([A-Z][a-zA-Z0-9_]*)\s*<([^>]+)>\s*\{/);if(r){let s=r[1],a=r[2],o=n+r[0].length-1+1,u=1,c=o;for(;c<e.length&&u>0;){let S=e[c];S==="{"?u++:S==="}"&&u--,c++}if(u!==0){t+=e[n],n++;continue}let l=e.slice(o,c-1).trim(),p=c,f=a.split(",").map(S=>{let b=S.trim().split("=").map(_=>_.trim());if(b.length===2){let _=b[1]==="any"||b[1]==="undefined"?"null":b[1];return`['${b[0]}', ${_}]`}return`'${b[0]}'`}),d=l,g=d.search(/\bdeclaration\s*\{/);if(g!==-1){let S=d.indexOf("{",g),b=1,_=S+1;for(;_<d.length&&b>0;)d[_]==="{"?b++:d[_]==="}"&&b--,_++;d=d.slice(0,g)+d.slice(_)}let y=d.match(/description\s*:\s*(['"`])([^]*?)\1/),w=d.match(/predicate\s*\(([^)]*)\)\s*\{([^]*)\}/),k=y?y[2]:s;if(w){let S=w[1].trim().split(",").map(E=>E.trim()),b=w[2].trim(),_=S[0]||"x",v=S.slice(1),x=v.map(E=>`check${E}`);v.forEach((E,$)=>{b=b.replace(new RegExp(`\\b${E}\\s*\\(`,"g"),`${x[$]}(`)}),t+=`const ${s} = Generic([${f.join(", ")}], (${_}, ${x.join(", ")}) => { ${b} }, '${k}')`}else t+=`const ${s} = Generic([${f.join(", ")}], () => true, '${k}')`;n=p;continue}t+=e[n],n++}return t}function Js(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\bUnion\s+([A-Z][a-zA-Z0-9_]*)\s+(['"`])([^]*?)\2\s*/);if(r){let s=r[1],a=r[3],i=n+r[0].length;if(e[i]==="{"){let o=i+1,u=1,c=o;for(;c<e.length&&u>0;){let d=e[c];d==="{"?u++:d==="}"&&u--,c++}if(u!==0){t+=e[n],n++;continue}let l=e.slice(o,c-1).trim(),p=c,f=Rs(l);t+=`const ${s} = Union('${a}', [${f.join(", ")}])`,n=p;continue}else{let o=e.indexOf(`
|
|
18
|
+
`,i);o===-1&&(o=e.length);let u=e.slice(i,o).trim();if(u){let c=Rs(u);t+=`const ${s} = Union('${a}', [${c.join(", ")}])`,n=o;continue}}}t+=e[n],n++}return t}function Rs(e){let t=[],n=e.split("|").map(r=>r.trim());for(let r of n)r&&t.push(r);return t}function zs(e){let t="",n=0;for(;n<e.length;){let r=e.slice(n).match(/^\bEnum\s+([A-Z][a-zA-Z0-9_]*)\s+(['"`])([^]*?)\2\s*\{/);if(r){let s=r[1],a=r[3],o=n+r[0].length-1+1,u=1,c=o;for(;c<e.length&&u>0;){let g=e[c];g==="{"?u++:g==="}"&&u--,c++}if(u!==0){t+=e[n],n++;continue}let l=e.slice(o,c-1).trim(),p=c,d=so(l).map(([g,y])=>`${g}: ${y}`).join(", ");t+=`const ${s} = Enum('${a}', { ${d} })`,n=p;continue}t+=e[n],n++}return t}function so(e){let t=[],n=0,r=e.split(/[\n,]/).map(s=>s.trim()).filter(s=>s&&!s.startsWith("//"));for(let s of r){let a=s.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*(?:=\s*(.+))?$/);if(a){let i=a[1],o=a[2]?.trim();if(o!==void 0){t.push([i,o]);let u=Number(o);isNaN(u)||(n=u+1)}else t.push([i,String(n)]),n++}}return t}function Gs(e){let t=new Map,n="",r=0;for(;r<e.length;){let s=e.slice(r),a=s.match(/^(\s*)extend\s+([A-Z]\w*)\s*\{/);if(!a){if(r===0||e[r-1]===`
|
|
19
|
+
`||e[r-1]===";"||e[r-1]==="}"){let b=s.match(/^(\s*)extend\s+([A-Z]\w*)\s*\{/)}n+=e[r],r++;continue}let i=a[1],o=a[2],u=r+a[0].length-1,c=Ct(e,u),l=e.slice(u+1,c-1).trim(),p=[],f=0,d=e.slice(u+1,c-1);for(;f<d.length;){let b=d.slice(f).match(/^(\s*)(async\s+)?(\w+)\s*\(/);if(!b){f++;continue}let _=b[1],v=!!b[2],x=b[3],E=f+b[0].length-1,$=1,C=E+1;for(;C<d.length&&$>0;)d[C]==="("&&$++,d[C]===")"&&$--,C++;let I=d.slice(E+1,C-1),M=C;for(;M<d.length&&/\s/.test(d[M]);)M++;if(d[M]==="="&&d[M+1]===">"){let ee=Le(e,u+1+f);throw new te(`Arrow functions are not allowed in extend blocks (method '${x}' in extend ${o}). Use regular function syntax instead, as extension methods need 'this' binding.`,ee)}if(d[M]!=="{"){f++;continue}let F=Ct(d,M),N=d.slice(f,F).trim(),U=I.split(",").map(ee=>ee.trim()).filter(ee=>ee.length>0).map(ee=>{let ce=ee.match(/^(\w+)\s*:\s*(.+)$/);return ce?`${ce[1]} = ${ce[2]}`:ee}).join(", "),J=v?"async ":"",X=d.slice(M+1,F-1);p.push({name:x,isAsync:v,fullText:`${x}: ${J}function(${U}) {${X}}`}),f=F}let g=!t.has(o);g&&t.set(o,new Set);let y=t.get(o);for(let S of p)y.add(S.name);let w=p.map(S=>` ${S.fullText}`).join(`,
|
|
20
|
+
`),k;g?k=`${i}const __ext_${o} = {
|
|
21
|
+
${w}
|
|
22
|
+
${i}}
|
|
23
|
+
`:k=`${i}Object.assign(__ext_${o}, {
|
|
24
|
+
${w}
|
|
25
|
+
${i}})
|
|
26
|
+
`;for(let S of p)k+=`${i}if (__tjs?.registerExtension) { __tjs.registerExtension('${o}', '${S.name}', __ext_${o}.${S.name}) }
|
|
27
|
+
`;n+=k,r=c}return r<=e.length&&n.length<e.length,{source:n,extensions:t}}function jt(e,t){if(t.size===0)return e;let n=new Map;for(let[s,a]of t)for(let i of a)n.has(i)||n.set(i,[]),n.get(i).push(s);let r=e;for(let[s,a]of n){if(!a.includes("String"))continue;let i=new RegExp(`('(?:[^'\\\\]|\\\\.)*')\\.(${s})\\((\\))?`,"g");r=r.replace(i,(c,l,p,f)=>f?`__ext_String.${p}.call(${l})`:`__ext_String.${p}.call(${l}, `);let o=new RegExp(`("(?:[^"\\\\]|\\\\.)*")\\.(${s})\\((\\))?`,"g");r=r.replace(o,(c,l,p,f)=>f?`__ext_String.${p}.call(${l})`:`__ext_String.${p}.call(${l}, `);let u=new RegExp("(`(?:[^`\\\\]|\\\\.)*`)\\."+s+"\\((\\))?","g");r=r.replace(u,(c,l,p)=>p?`__ext_String.${s}.call(${l})`:`__ext_String.${s}.call(${l}, `)}for(let[s,a]of n){if(!a.includes("Array"))continue;let i=`].${s}(`,o=0,u;for(;(u=r.indexOf(i,o))!==-1;){let c=1,l=u-1,p=!1;for(;l>=0&&c>0;){let f=r[l];p?f===p&&(l===0||r[l-1]!=="\\")&&(p=!1):(f==="]"&&c++,f==="["&&c--,(f==="'"||f==='"'||f==="`")&&(p=f)),l--}if(c===0){let f=r.slice(l+1,u+1),d=r.slice(0,l+1),g=r.slice(u+i.length);g[0]===")"?r=`${d}__ext_Array.${s}.call(${f})${g.slice(1)}`:r=`${d}__ext_Array.${s}.call(${f}, ${g}`}o=u+1}}for(let[s,a]of n){if(!a.includes("Number"))continue;let i=new RegExp(`(\\d+(?:\\.\\d+)?)\\.(${s})\\((\\))?`,"g");r=r.replace(i,(o,u,c,l)=>l?`__ext_Number.${c}.call(${u})`:`__ext_Number.${c}.call(${u}, `)}return r}function Le(e,t){let n=1,r=0;for(let s=0;s<t&&s<e.length;s++)e[s]===`
|
|
28
|
+
`?(n++,r=0):r++;return{line:n,column:r}}function Hs(e,t){let n=t.trim();return/^['"`]/.test(n)?`typeof ${e} === 'string'`:n==="true"||n==="false"?`typeof ${e} === 'boolean'`:n==="null"?`${e} === null`:n==="undefined"?`${e} === undefined`:n.startsWith("[")?`Array.isArray(${e})`:n.startsWith("{")?`(typeof ${e} === 'object' && ${e} !== null && !Array.isArray(${e}))`:/^\+\d+/.test(n)?`(typeof ${e} === 'number' && Number.isInteger(${e}) && ${e} >= 0)`:/^-?\d+\.\d+/.test(n)?`typeof ${e} === 'number'`:/^-?\d+$/.test(n)?`(typeof ${e} === 'number' && Number.isInteger(${e}))`:"true"}function on(e){let t=e.trim();return/^['"`]/.test(t)?"string":t==="true"||t==="false"?"boolean":t==="null"?"null":t==="undefined"?"undefined":t.startsWith("[")?"array":t.startsWith("{")?"object":/^\+\d+/.test(t)?"non-negative-integer":/^-?\d+\.\d+/.test(t)?"number":/^-?\d+$/.test(t)?"integer":"any"}function Hn(e,t){let n=[],r=0,s="",a=!1;for(let o=0;o<e.length;o++){let u=e[o];if(!a&&(u==="'"||u==='"'||u==="`")){a=u,s+=u;continue}if(a){if(s+=u,u==="\\"){o++,o<e.length&&(s+=e[o]);continue}u===a&&(a=!1);continue}if(u==="("||u==="["||u==="{"){r++,s+=u;continue}if(u===")"||u==="]"||u==="}"){r--,s+=u;continue}if(u===","&&r===0){let c=Ms(s.trim(),t);c&&n.push(c),s="";continue}s+=u}let i=s.trim();if(i){let o=Ms(i,t);o&&n.push(o)}return n}function Ms(e,t){let n=e.replace(/^\/\*\s*unsafe\s*\*\/\s*/,"");if(n.startsWith("..."))return null;let r=n.indexOf("=");if(r===-1)return{name:n.trim(),defaultValue:"",required:!0};let s=n.slice(0,r).trim(),a=n.slice(r+1).trim();return{name:s,defaultValue:a,required:t.has(s)}}function Ct(e,t){let n=1,r=t+1,s=!1,a=!1,i=!1;for(;r<e.length&&n>0;){let o=e[r],u=r+1<e.length?e[r+1]:"";if(a){o===`
|
|
29
|
+
`&&(a=!1),r++;continue}if(i){if(o==="*"&&u==="/"){i=!1,r+=2;continue}r++;continue}if(s){if(o==="\\"){r+=2;continue}o===s&&(s=!1),r++;continue}if(o==="/"&&u==="/"){a=!0,r+=2;continue}if(o==="/"&&u==="*"){i=!0,r+=2;continue}if(o==="'"||o==='"'||o==="`"){s=o,r++;continue}o==="{"&&n++,o==="}"&&n--,r++}return r}function Ks(e,t){let n=new Set,r=/(?:^|(?<=[\n;{}]))\s*(export\s+)?(async\s+)?function\s+(\w+)\s*\(/gm,s=new Map,a,i=[];for(;(a=r.exec(e))!==null;){let p=!!a[1],f=!!a[2],d=a[3],g=a.index,y=g,k=a[0].indexOf("function");k>=0&&(y=g+k),i.push({name:d,fullMatchStart:g,funcKeywordStart:y,exported:p,isAsync:f})}for(let p of i)s.has(p.name)||s.set(p.name,[]);let o=new Map;for(let p of i)o.set(p.name,(o.get(p.name)||0)+1);let u=new Set;for(let[p,f]of o)f>1&&u.add(p);if(u.size===0)return{source:e,polymorphicNames:n};for(let p of i){if(!u.has(p.name))continue;let f=e.indexOf("(",p.funcKeywordStart);if(f===-1)continue;let d=1,g=f+1;for(;g<e.length&&d>0;)e[g]==="("&&d++,e[g]===")"&&d--,g++;let y=g-1,w=e.slice(f+1,y),k=g;for(;k<e.length&&e[k]!=="{";)k++;if(k>=e.length)continue;let S=Ct(e,k),b=p.fullMatchStart;for(;b>0&&e[b-1]===" ";)b--;let _=s.get(p.name),v=Hn(w,t);if(w.includes("...")){let E=Le(e,p.funcKeywordStart);throw new te(`Rest parameters are not supported in polymorphic function '${p.name}'. Use separate function names instead.`,E)}_.push({index:_.length+1,start:b,end:S,text:e.slice(b,S),exported:p.exported,isAsync:p.isAsync,params:v})}for(let[p,f]of s){if(f.length<2)continue;let d=f.filter(g=>g.isAsync).length;if(d>0&&d<f.length){let g=Le(e,f[0].start);throw new te(`Polymorphic function '${p}': all variants must be either sync or async, not mixed.`,g)}for(let g=0;g<f.length;g++)for(let y=g+1;y<f.length;y++){let w=f[g],k=f[y];if(w.params.length!==k.params.length)continue;let S=!0;for(let b=0;b<w.params.length;b++){let _=w.params[b].defaultValue?on(w.params[b].defaultValue):"any",v=k.params[b].defaultValue?on(k.params[b].defaultValue):"any";if(_!==v){S=!1;break}}if(S){let b=Le(e,k.start);throw new te(`Polymorphic function '${p}': variants ${g+1} and ${y+1} have ambiguous signatures (same parameter types at every position). Overloads must differ by arity or parameter types.`,b)}}}let c=[];for(let[p,f]of s)if(!(f.length<2))for(let d of f)c.push({name:p,variant:d});c.sort((p,f)=>f.variant.start-p.variant.start);let l=e;for(let{name:p,variant:f}of c){let d=f.isAsync?"async ":"",g=f.text.replace(new RegExp(`(?:export\\s+)?${d?d.replace(/\s+$/,"\\s+"):""}function\\s+${p}\\s*\\(`),`${d}function ${p}$$${f.index}(`);l=l.slice(0,f.start)+g+l.slice(f.end)}for(let[p,f]of s){if(f.length<2)continue;n.add(p);let d=f[0].isAsync,g=f.some(_=>_.exported),y=d?"async ":"",w=g?"export ":"",k=[...f].sort((_,v)=>{if(_.params.length!==v.params.length)return 0;let x=0,E=0;for(let $ of _.params){let C=$.defaultValue?on($.defaultValue):"any";C==="non-negative-integer"?x+=3:C==="integer"?x+=2:C!=="any"&&(x+=1)}for(let $ of v.params){let C=$.defaultValue?on($.defaultValue):"any";C==="non-negative-integer"?E+=3:C==="integer"?E+=2:C!=="any"&&(E+=1)}return E-x}),S=[];for(let _ of k){let v=[`__args.length === ${_.params.length}`],x=[];for(let E=0;E<_.params.length;E++){let $=_.params[E];if(x.push(`__args[${E}]`),$.defaultValue){let C=Hs(`__args[${E}]`,$.defaultValue);C!=="true"&&v.push(C)}}S.push(` if (${v.join(" && ")}) return ${p}$${_.index}(${x.join(", ")})`)}let b=`
|
|
30
|
+
${w}${y}function ${p}(...__args) {
|
|
31
|
+
${S.join(`
|
|
32
|
+
`)}
|
|
33
|
+
return __tjs.typeError('${p}', 'no matching overload', __args)
|
|
34
|
+
}
|
|
35
|
+
`;l+=b}return{source:l,polymorphicNames:n}}function Zs(e){return e.replace(/(?<=^|[;\n{])\s*([A-Z][a-zA-Z0-9_]*)\s*=(?!=)/gm,(t,n)=>t.replace(n,`const ${n}`))}function Qs(e,t=!1){let n=[],r=[],s="",a=0;for(;a<e.length;){let i=e.slice(a).match(/^\btest\s+/);if(i){let o=a,u=a+i[0].length,c,l=e.slice(u).match(/^(['"`])([^]*?)\1\s*/);if(l&&(c=l[2],u+=l[0].length),e[u]==="{"){let p=u+1,f=1,d=p,g=null,y=!1;for(;d<e.length&&f>0;){let w=e[d];if(y){y=!1,d++;continue}if(w==="\\"&&g){y=!0,d++;continue}if(g){w===g&&(g=null),d++;continue}if(w==="/"&&e[d+1]==="/"){let k=e.indexOf(`
|
|
36
|
+
`,d);d=k===-1?e.length:k+1;continue}if(w==="/"&&e[d+1]==="*"){let k=e.indexOf("*/",d+2);d=k===-1?e.length:k+2;continue}if(w==="'"||w==='"'||w==="`"){g=w,d++;continue}w==="{"?f++:w==="}"&&f--,d++}if(f===0){let w=e.slice(p,d-1).trim(),k=d,S=(e.slice(0,o).match(/\n/g)||[]).length+1;if(n.push({description:c,body:w,start:o,end:k,line:S}),!t)try{new Function(w)()}catch(v){let x=c||`test at line ${S}`;r.push(`Test failed: ${x} (line ${S})
|
|
37
|
+
${v.message||v}`)}let _=(e.slice(o,k).match(/\n/g)||[]).length;s+=`
|
|
38
|
+
`.repeat(_),a=k;continue}}}s+=e[a],a++}return{source:s,tests:n,errors:r}}function Ys(e,t){let n=new Set,r=/\bclass\s+(\w+)(\s+extends\s+\w+)?\s*\{/g,s,a=[];for(;(s=r.exec(e))!==null;){let o=s[1],u=s[2]?.trim()||"",c=s.index+s[0].length-1,l=Ct(e,c),p=e.slice(c,l);a.push({className:o,extendsClause:u,bodyStart:c,bodyEnd:l,body:p})}let i=e;for(let o=a.length-1;o>=0;o--){let{className:u,extendsClause:c,bodyStart:l,bodyEnd:p,body:f}=a[o],d=/\bconstructor\s*\(/g,g,y=[];for(;(g=d.exec(f))!==null;)y.push(g.index);if(y.length<2)continue;n.add(u);let w=[];for(let v=0;v<y.length;v++){let x=y[v],E=f.indexOf("(",x),$=1,C=E+1;for(;C<f.length&&$>0;)f[C]==="("&&$++,f[C]===")"&&$--,C++;let I=f.slice(E+1,C-1),M=C;for(;M<f.length&&f[M]!=="{";)M++;let F=Ct(f,M),N=f.slice(M+1,F-1);w.push({index:v+1,paramStr:I,bodyText:N,fullStart:x,fullEnd:F})}let k=f;for(let v=w.length-1;v>=1;v--){let x=w[v],E=x.fullStart;for(;E>0&&k[E-1]===" ";)E--;E>0&&k[E-1]===`
|
|
39
|
+
`&&E--,k=k.slice(0,E)+k.slice(x.fullEnd)}let S="";for(let v=1;v<w.length;v++){let x=w[v],E=Hn(x.paramStr,t);if(x.paramStr.includes("...")){let C=Le(e,l+x.fullStart);throw new te(`Rest parameters are not supported in polymorphic constructors for '${u}'.`,C)}S+=`
|
|
40
|
+
function ${u}$ctor$${x.index}(${x.paramStr}) {`,S+=`
|
|
41
|
+
const __obj = Object.create(${u}.prototype)`,S+=`
|
|
42
|
+
;(function() {${x.bodyText}}).call(__obj)`,S+=`
|
|
43
|
+
return __obj`,S+=`
|
|
44
|
+
}
|
|
45
|
+
`}let b=[];for(let v=0;v<w.length;v++){let x=w[v],E=Hn(x.paramStr,t),$=[`a.length === ${E.length}`];for(let C=0;C<E.length;C++){let I=E[C];if(I.defaultValue){let M=Hs(`a[${C}]`,I.defaultValue);M!=="true"&&$.push(M)}}if(v===0)b.push(` if (${$.join(" && ")}) return Reflect.construct(t, a)`);else{let C=E.map((I,M)=>`a[${M}]`).join(", ");b.push(` if (${$.join(" && ")}) return ${u}$ctor$${x.index}(${C})`)}}S+=`
|
|
46
|
+
function ${u}$dispatch(t, a) {
|
|
47
|
+
`,S+=b.join(`
|
|
48
|
+
`)+`
|
|
49
|
+
`,S+=` return __tjs.typeError('${u}', 'no matching constructor', a)
|
|
50
|
+
`,S+=`}
|
|
51
|
+
`,i=i.slice(0,l)+k+i.slice(p);let _=l+k.length;i=i.slice(0,_)+S+i.slice(_)}return{source:i,polyCtorClasses:n}}function Xs(e,t=new Set){let n=/\bclass\s+(\w+)(\s+extends\s+\w+)?\s*\{/g,r="",s=0,a;for(;(a=n.exec(e))!==null;){let i=a[1],o=a[2]||"",u=a.index,c=u+a[0].length-1,l=1,p=c+1;for(;p<e.length&&l>0;){let f=e[p];f==="{"?l++:f==="}"&&l--,p++}if(l===0){let f=p,d=e.slice(c,f);r+=e.slice(s,u),r+=`let ${i} = class ${i}${o} ${d}; `,t.has(i)?r+=`${i} = new Proxy(${i}, { apply(t, _, a) { return ${i}$dispatch(t, a) }, construct(t, a) { return ${i}$dispatch(t, a) } });`:r+=`${i} = new Proxy(${i}, { apply(t, _, a) { return Reflect.construct(t, a) } });`,s=f}}return r+=e.slice(s),r}function ei(e){let t=[{pattern:/\bnew\s+Date\b/,message:"new Date() is not allowed in TjsDate mode. Use Timestamp.now() or Timestamp.from()"},{pattern:/\bDate\.now\b/,message:"Date.now() is not allowed in TjsDate mode. Use Timestamp.now()"},{pattern:/\bDate\.parse\b/,message:"Date.parse() is not allowed in TjsDate mode. Use Timestamp.parse()"},{pattern:/\bDate\.UTC\b/,message:"Date.UTC() is not allowed in TjsDate mode. Use Timestamp.from()"}];for(let{pattern:n,message:r}of t)if(n.test(e))throw new Error(r);return e}function ti(e){let t=new Set,n=/\bconst!\s+(\w+)\b/g,r;for(;(r=n.exec(e))!==null;)t.add(r[1]);if(t.size===0)return e;e=e.replace(/\bconst!\s+/g,"const ");let s=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/[^\n]*/g,"");for(let a of t){if(new RegExp(`\\b${a}\\s*(?:\\.[\\w]+|\\[[^\\]]+\\])\\s*(?:=(?!=)|\\+\\+|--|\\+=|-=|\\*=|\\/=|%=|&&=|\\|\\|=|\\?\\?=|<<=|>>=|>>>=|\\^=|&=|\\|=)`,"g").test(s))throw new Error(`Cannot mutate immutable binding '${a}'. const! bindings are read-only at compile time.`);if(new RegExp(`(?:\\+\\+|--)\\s*${a}\\s*(?:\\.[\\w]+|\\[[^\\]]+\\])`,"g").test(s))throw new Error(`Cannot mutate immutable binding '${a}'. const! bindings are read-only at compile time.`);if(new RegExp(`\\bdelete\\s+${a}\\s*(?:\\.[\\w]+|\\[[^\\]]+\\])`,"g").test(s))throw new Error(`Cannot mutate immutable binding '${a}'. const! bindings are read-only at compile time.`);let c="push|pop|splice|shift|unshift|sort|reverse|fill|copyWithin|set";if(new RegExp(`\\b${a}\\s*\\.\\s*(?:${c})\\s*\\(`,"g").test(s))throw new Error(`Cannot call mutating method on immutable binding '${a}'. const! bindings are read-only at compile time.`)}return e}function ni(e){if(/(?<![a-zA-Z_$])\bvar\s+/.test(e))throw new Error("var is not allowed in TjsNoVar mode. Use const or let instead.");return e}function ri(e){if(/(?<![A-Za-z_$])\beval\s*\(/.test(e))throw new Error("eval() is not allowed in TjsNoeval mode. Use Eval() from TJS runtime for safe evaluation.");if(/\bnew\s+Function\s*\(/.test(e))throw new Error("new Function() is not allowed in TjsNoeval mode. Use SafeFunction() from TJS runtime.");return e}function si(e){if(!e.includes("!."))return e;let t="",n=0,r="normal",s=0;for(;n<e.length;){let a=e[n],i=e[n+1];if(r==="normal"){if(a==="/"&&i==="/"){r="line-comment",t+=a,n++;continue}if(a==="/"&&i==="*"){r="block-comment",t+=a,n++;continue}if(a==="'"){r="string-single",t+=a,n++;continue}if(a==='"'){r="string-double",t+=a,n++;continue}if(a==="`"){r="string-template",s++,t+=a,n++;continue}if(a==="!"&&i==="."&&n+2<e.length&&/[a-zA-Z_$]/.test(e[n+2])){let o=t.length,u=io(t);if(u<o){let c=t.slice(u);t=t.slice(0,u);let l=n+2;for(;l<e.length&&/[\w$]/.test(e[l]);)l++;let p=e.slice(n+2,l);t+=`__tjs.bang(${c},'${p}')`,n=l;continue}}t+=a,n++}else r==="line-comment"?(t+=a,a===`
|
|
52
|
+
`&&(r="normal"),n++):r==="block-comment"?(t+=a,a==="*"&&i==="/"?(t+=i,r="normal",n+=2):n++):r==="string-single"?(t+=a,a==="\\"?(t+=i||"",n+=2):(a==="'"&&(r="normal"),n++)):r==="string-double"?(t+=a,a==="\\"?(t+=i||"",n+=2):(a==='"'&&(r="normal"),n++)):r==="string-template"?(t+=a,a==="\\"?(t+=i||"",n+=2):a==="`"?(s--,r=s>0?"string-template":"normal",n++):a==="$"&&i==="{"?(t+=i,n+=2,r="normal"):n++):(t+=a,n++)}return t}function io(e){let t=e.length-1;for(;t>=0&&/\s/.test(e[t]);)t--;if(t<0)return e.length;for(;t>=0;){let n=e[t];if(/[\w$]/.test(n)){for(;t>=0&&/[\w$]/.test(e[t]);)t--;if(t>=0&&e[t]==="."){t>=1&&e[t-1]==="?"?t-=2:t--;continue}return t+1}else if(n===")"){if(t=Os(e,t,"(",")"),t<0)return 0;if(t--,t>=0&&/[\w$]/.test(e[t]))continue;if(t>=0&&e[t]==="."){t>=1&&e[t-1]==="?"?t-=2:t--;continue}return t+1}else if(n==="]"){if(t=Os(e,t,"[","]"),t<0)return 0;if(t--,t>=0&&/[\w$]/.test(e[t]))continue;if(t>=0&&e[t]==="."){t>=1&&e[t-1]==="?"?t-=2:t--;continue}return t+1}else return t+1}return 0}function Os(e,t,n,r){let s=1;for(t--;t>=0&&s>0;)e[t]===r?s++:e[t]===n&&s--,s>0&&t--;return t}function ii(e){let t=new Map;if(!e.includes("let "))return{source:e,annotations:t};let n=[],r=0,s="normal",a=[];for(;r<e.length;){let o=e[r],u=e[r+1];switch(s){case"single-string":if(o==="\\"&&r+1<e.length){r+=2;continue}o==="'"&&(s="normal"),r++;continue;case"double-string":if(o==="\\"&&r+1<e.length){r+=2;continue}o==='"'&&(s="normal"),r++;continue;case"template-string":if(o==="\\"&&r+1<e.length){r+=2;continue}if(o==="$"&&u==="{"){r+=2,a.push(1),s="normal";continue}o==="`"&&(s="normal"),r++;continue;case"line-comment":o===`
|
|
53
|
+
`&&(s="normal"),r++;continue;case"block-comment":if(o==="*"&&u==="/"){r+=2,s="normal";continue}r++;continue;case"regex":if(o==="\\"&&r+1<e.length){r+=2;continue}if(o==="["){for(r++;r<e.length&&e[r]!=="]";)e[r]==="\\"&&r+1<e.length?r+=2:r++;r<e.length&&r++;continue}if(o==="/"){for(r++;r<e.length&&/[gimsuy]/.test(e[r]);)r++;s="normal";continue}r++;continue;case"normal":if(a.length>0){if(o==="{")a[a.length-1]++;else if(o==="}"&&(a[a.length-1]--,a[a.length-1]===0)){a.pop(),r++,s="template-string";continue}}if(o==="'"){r++,s="single-string";continue}if(o==='"'){r++,s="double-string";continue}if(o==="`"){r++,s="template-string";continue}if(o==="/"&&u==="/"){r+=2,s="line-comment";continue}if(o==="/"&&u==="*"){r+=2,s="block-comment";continue}if(o==="/"){let c=r-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))){r++,s="regex";continue}}if(o==="l"&&e.slice(r,r+4)==="let "&&(r===0||!/[\w$]/.test(e[r-1]))){let c=r+4;for(;c<e.length&&/\s/.test(e[c]);)c++;if(c<e.length&&/[a-zA-Z_$]/.test(e[c])){let l=c;for(;c<e.length&&/[\w$]/.test(e[c]);)c++;let p=c,f=e.slice(l,p),d=c;for(;d<e.length&&/\s/.test(e[d]);)d++;if(d<e.length&&e[d]===":"&&e[d+1]!==":"){let y=d+1;for(;y<e.length&&/[ \t]/.test(e[y]);)y++;let w=ao(e,y);if(w>y){let k=e.slice(y,w).trim();t.set(f,k),n.push({start:p,end:w,replacement:""}),r=w;continue}}}}break}r++}if(n.length===0)return{source:e,annotations:t};let i=e;for(let o=n.length-1;o>=0;o--){let u=n[o];i=i.slice(0,u.start)+u.replacement+i.slice(u.end)}return{source:i,annotations:t}}function ao(e,t){let n=t,r=0,s=0,a=0,i="normal",o=[];for(;n<e.length;){let u=e[n];if(i==="sq"){if(u==="\\"){n+=2;continue}u==="'"&&(i="normal"),n++;continue}if(i==="dq"){if(u==="\\"){n+=2;continue}u==='"'&&(i="normal"),n++;continue}if(i==="tpl"){if(u==="\\"){n+=2;continue}if(u==="$"&&e[n+1]==="{"){o.push(1),i="normal",n+=2;continue}u==="`"&&(i="normal"),n++;continue}if(o.length>0){if(u==="{")o[o.length-1]++;else if(u==="}"&&(o[o.length-1]--,o[o.length-1]===0)){o.pop(),i="tpl",n++;continue}}if(u==="'"){i="sq",n++;continue}if(u==='"'){i="dq",n++;continue}if(u==="`"){i="tpl",n++;continue}if(u==="("?r++:u===")"?r--:u==="{"?s++:u==="}"?s--:u==="["?a++:u==="]"&&a--,r===0&&s===0&&a===0&&(u==="="||u===","||u===";"||u===`
|
|
54
|
+
`))return n;n++}return n}function fn(e,t){let n="",r=0,s,a,i="normal",o=[],u=[{type:"top-level",braceDepth:0}],c=0,l=()=>u[u.length-1]?.type||"top-level",p=()=>{let f=u[u.length-1];return f?.type==="class-body"&&c===f.braceDepth+1};for(;r<e.length;){let f=e[r],d=e[r+1];switch(i){case"single-string":if(n+=f,f==="\\"&&r+1<e.length){n+=d,r+=2;continue}f==="'"&&(i="normal"),r++;continue;case"double-string":if(n+=f,f==="\\"&&r+1<e.length){n+=d,r+=2;continue}f==='"'&&(i="normal"),r++;continue;case"template-string":if(n+=f,f==="\\"&&r+1<e.length){n+=d,r+=2;continue}if(f==="$"&&d==="{"){n+=d,r+=2,o.push(1),i="normal";continue}f==="`"&&(i="normal"),r++;continue;case"line-comment":n+=f,f===`
|
|
55
|
+
`&&(i="normal"),r++;continue;case"block-comment":if(n+=f,f==="*"&&d==="/"){n+=d,r+=2,i="normal";continue}r++;continue;case"regex":if(n+=f,f==="\\"&&r+1<e.length){n+=d,r+=2;continue}if(f==="["){for(r++;r<e.length&&e[r]!=="]";)n+=e[r],e[r]==="\\"&&r+1<e.length?(n+=e[r+1],r+=2):r++;r<e.length&&(n+=e[r],r++);continue}if(f==="/"){for(r++;r<e.length&&/[gimsuy]/.test(e[r]);)n+=e[r],r++;i="normal";continue}r++;continue;case"normal":if(o.length>0){if(f==="{")o[o.length-1]++;else if(f==="}"&&(o[o.length-1]--,o[o.length-1]===0)){o.pop(),n+=f,r++,i="template-string";continue}}if(f==="'"){n+=f,r++,i="single-string";continue}if(f==='"'){n+=f,r++,i="double-string";continue}if(f==="`"){n+=f,r++,i="template-string";continue}if(f==="/"&&d==="/"){n+=f+d,r+=2,i="line-comment";continue}if(f==="/"&&d==="*"){n+=f+d,r+=2,i="block-comment";continue}if(f==="/"){let b=n.trimEnd();if(!b[b.length-1]||/[=(!,;:{[&|?+\-*%<>~^]$/.test(b)||/\b(return|case|throw|in|of|typeof|instanceof|new|delete|void)\s*$/.test(b)){n+=f,r++,i="regex";continue}}break}if(f==="{"){c++,n+=f,r++;continue}if(f==="}"){c--;let b=u[u.length-1];b&&c===b.braceDepth&&u.pop(),n+=f,r++;continue}let g=e.slice(r).match(/^class\s+\w+(?:\s+extends\s+\w+)?\s*\{/);if(g){let b=g[0].slice(0,-1);n+=b,r+=b.length,u.push({type:"class-body",braceDepth:c});continue}let y=e.slice(r).match(/^function\s+(\w+)\s*\(/);if(y){let b=y[1],_=y[0].length,v=e[r+_],x,E=r+_;(v==="?"||v==="!")&&(x=v,E++,x==="!"?t.unsafeFunctions.add(b):t.safeFunctions.add(b)),n+=`function ${b}(`,r=E;let $=un(e,r,"(",")");if(!$){n+=e[r],r++;continue}let{content:C,endPos:I}=$;r=I;let M=Zn(C,t,!0);n+=M+")";let F=r;for(;F<e.length&&/\s/.test(e[F]);)F++;if(e[F]===":"){let U=e.slice(F,F+2),J;for(U===":?"||U===":!"?(F+=2,J=U===":?"?"safe":"unsafe"):F+=1;F<e.length&&/\s/.test(e[F]);)F++;let X=Kn(e,F);X&&(s===void 0&&(s=X.type,J&&(a=J)),r=X.endPos)}let N=r;for(;N<e.length&&/\s/.test(e[N]);)N++;if(e[N]==="="&&e[N+1]===">")throw new te("Unexpected '=>' after function declaration. Function declarations use `function name(params) { body }`, not arrow syntax. Remove the `=>`.",Le(t.originalSource,N),t.originalSource);continue}let w=e.slice(r).match(/^(constructor|(?:get|set)\s+\w+|async\s+\w+|\w+)\s*\(/),k=(()=>{for(let b=n.length-1;b>=0;b--)if(!/\s/.test(n[b]))return n[b];return`
|
|
56
|
+
`})(),S=k!=="="&&k!==","&&k!=="("&&k!=="["&&k!==">";if(w&&p()&&!S){let b=w[1].length;n+=e.slice(r,r+b),r+=b;continue}if(w&&p()&&S){let b=w[1],_=w[0].length,v=r+_;n+=b+"(",r=v;let x=un(e,r,"(",")");if(!x){n+=e[r],r++;continue}let{content:E,endPos:$}=x;r=$;let C=Zn(E,t,!0);n+=C+")";let I=r;for(;I<e.length&&/\s/.test(e[I]);)I++;if(e[I]===":"){let F=e.slice(I,I+2);for(F===":?"||F===":!"?I+=2:I++;I<e.length&&/\s/.test(e[I]);)I++;let N=Kn(e,I);N&&(r=N.endPos)}let M=r;for(;M<e.length&&/\s/.test(e[M]);)M++;if(e[M]==="="&&e[M+1]===">")throw new te("Unexpected '=>' after method declaration. Methods use `name(params) { body }`, not arrow syntax. Remove the `=>`.",Le(t.originalSource,M),t.originalSource);continue}if(e[r]==="("){let b=un(e,r+1,"(",")");if(!b){n+=e[r],r++;continue}let _=b.content,v=b.endPos,x=v;for(;x<e.length&&/\s/.test(e[x]);)x++;let E;if(e[x]===":"){let $=e.slice(x,x+2);for($===":?"||$===":!"?x+=2:x++;x<e.length&&/\s/.test(e[x]);)x++;let C=Kn(e,x);if(C)for(E=C.type,x=C.endPos;x<e.length&&/\s/.test(e[x]);)x++}if(e.slice(x,x+2)==="=>"){let $=null,C=_,I=_.trimStart();I.startsWith("?")&&(I.length===1||/\s/.test(I[1]))?($="?",C=I.slice(1)):I.startsWith("!")&&(I.length===1||/\s/.test(I[1]))&&($="!",C=I.slice(1));let M=Zn(C,t,!1);for(n+=`(${$==="?"?"/* safe */ ":$==="!"?"/* unsafe */ ":""}${M})`,r=v;r<x&&/\s/.test(e[r]);)n+=e[r],r++;E&&(r=x)}else{let $=fn(_,t);n+=`(${$.source})`,r=v}continue}n+=e[r],r++}return{source:n,returnType:s,returnSafety:a}}function un(e,t,n,r){let s=1,a=t,i=!1,o="";for(;a<e.length&&s>0;){let u=e[a];!i&&(u==="'"||u==='"'||u==="`")?(i=!0,o=u):i&&u===o&&e[a-1]!=="\\"?i=!1:i||(u===n?s++:u===r&&s--),a++}return s!==0?null:{content:e.slice(t,a-1),endPos:a}}function ai(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;if(n>=e.length)return null;let r=n,s=e[n];if(s==="{"||s==="["){let i=s==="{"?"}":"]",o=un(e,n+1,s,i);return o?{value:e.slice(r,o.endPos),endPos:o.endPos}:null}if(s==="'"||s==='"'||s==="`"){for(n++;n<e.length;){if(e[n]===s&&e[n-1]!=="\\")return n++,{value:e.slice(r,n),endPos:n};n++}return null}if(/[-+\d]/.test(s)){for(;n<e.length&&/[\d.eE+-]/.test(e[n]);)n++;return{value:e.slice(r,n),endPos:n}}let a=e.slice(n).match(/^(true|false|null|undefined)\b/);return a?{value:a[1],endPos:n+a[1].length}:null}function It(e){return e.replace(/(?<!\|)\|(?!\|)/g," || ")}function Kn(e,t){let n=t,r=0,s=!1,a="",i=!1,o=u=>({type:It(e.slice(t,u).trim()),endPos:u});for(;n<e.length;){let u=e[n];if(!s&&(u==="'"||u==='"'||u==="`")){s=!0,a=u,i=!0,n++;continue}if(s){if(u===a&&e[n-1]!=="\\"){if(s=!1,n++,r===0){let c=n;for(;c<e.length&&/\s/.test(e[c]);)c++;if(e[c]==="{"&&!e.slice(c+1).match(/^\s*(\w+)\s*:/)||e[c]!=="|"&&e[c]!=="&")return o(n)}continue}n++;continue}if(u==="{"||u==="["||u==="("){r++,i=!0,n++;continue}if(u==="}"||u==="]"||u===")"){if(r--,r===0){n++;let c=n;for(;c<e.length&&/\s/.test(e[c]);)c++;if(e[c]==="|"||e[c]==="&")continue;return o(n)}n++;continue}if(r===0&&u==="{"){if(i)return o(n);if(e.slice(n+1).match(/^\s*(\w+)\s*:/)){r++,i=!0,n++;continue}return o(n)}if(r===0&&(u==="|"||u==="&")){for(n++,n<e.length&&e[n]==="|"&&n++;n<e.length&&/\s/.test(e[n]);)n++;continue}if(r===0&&(/\d/.test(u)||u==="-"&&/\d/.test(e[n+1]))){let c=n;for(e[c]==="-"&&c++;c<e.length&&/\d/.test(e[c]);)c++;if(c<e.length&&e[c]==="."&&/\d/.test(e[c+1]))for(c++;c<e.length&&/\d/.test(e[c]);)c++;if(c<e.length&&(e[c]==="e"||e[c]==="E"))for(c++,c<e.length&&(e[c]==="+"||e[c]==="-")&&c++;c<e.length&&/\d/.test(e[c]);)c++;for(i=!0,n=c;n<e.length&&/\s/.test(e[n]);)n++;if(n<e.length&&e[n]==="{")return{type:It(e.slice(t,c).trim()),endPos:c};if(e[n]!=="|"&&e[n]!=="&")return{type:It(e.slice(t,c).trim()),endPos:c};continue}if(r===0&&/[a-zA-Z_]/.test(u)){let c=n;for(;c<e.length&&/\w/.test(e[c]);)c++;for(i=!0,n=c;n<e.length&&/\s/.test(e[n]);)n++;if(n<e.length&&e[n]==="("){r++,n++;continue}if(n<e.length&&e[n]==="{"&&!e.slice(n+1).match(/^\s*(\w+)\s*:/)){let p=c;for(;p>t&&/\s/.test(e[p-1]);)p--;return{type:It(e.slice(t,p).trim()),endPos:c}}if(e[n]!=="|"&&e[n]!=="&")return{type:It(e.slice(t,c).trim()),endPos:c};continue}n++}return i?o(n):null}function pn(e){let t=[],n="",r=0,s=!1,a=!1,i=0;for(;i<e.length;){let o=e[i],u=e[i+1];if(!a&&o==="/"&&u==="/"){s=!0,n+="//",i+=2;continue}if(!s&&o==="/"&&u==="*"){a=!0,n+="/*",i+=2;continue}if(s&&o===`
|
|
57
|
+
`){s=!1,n+=o,i++;continue}if(a&&o==="*"&&u==="/"){a=!1,n+="*/",i+=2;continue}if(s||a){n+=o,i++;continue}o==="("||o==="{"||o==="["?(r++,n+=o):o===")"||o==="}"||o==="]"?(r--,n+=o):o===","&&r===0?(t.push(n),n=""):n+=o,i++}return n.trim()&&t.push(n),t}function Zn(e,t,n){let r=fn(e,{originalSource:e,requiredParams:t.requiredParams,unsafeFunctions:t.unsafeFunctions,safeFunctions:t.safeFunctions}).source,s=pn(r),a=!1,i=new Set,o=c=>{if(n&&/^\w+$/.test(c)){if(i.has(c))throw new Error(`Duplicate parameter name '${c}'`);i.add(c)}};return s.map(c=>{let l=c.trim();if(!l)return c;if(n&&l.startsWith("{")&&l.endsWith("}")){let d=l.slice(1,-1);return`{ ${oi(d,t)} }`}if(n&&l.startsWith("[")&&l.endsWith("]")){let d=l.slice(1,-1);return`[ ${oi(d,t)} ]`}if(l.startsWith("...")){let d=ui(l);return d!==-1?l.slice(0,d).trim():c}let p=l.match(/^(\w+)\s*\?\s*:\s*(.+)$/);if(p){let[,d,g]=p;return o(d),a=!0,`${d} = ${g}`}if(!oo(l)){let d=l.match(/^(\w+)\s*=/);return d&&o(d[1]),a=!0,c}let f=ui(l);if(f!==-1){let d=l.slice(0,f).trim(),g=l.slice(f+1).trim();return o(d),a&&n&&/^\w+$/.test(d),n&&/^\w+$/.test(d)&&t.requiredParams.add(d),`${d} = ${g}`}return c}).join(",")}function oi(e,t){return pn(e).map(s=>{let a=s.trim();if(!a)return s;let i=a.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(i){let[,c,l]=i;t.requiredParams.add(c);let p=cn(l);return`${c} = ${p}`}let o=a.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(o){let[,c,l]=o;t.requiredParams.add(c);let p=ln(l);return`${c} = ${p}`}let u=a.match(/^(\w+)\s*:\s*([\s\S]+)$/);if(u){let[,c,l]=u;return t.requiredParams.add(c),`${c} = ${l}`}return s}).join(", ")}function cn(e){let t=e.slice(1,-1).trim();return`{ ${pn(t).map(s=>{let a=s.trim();if(!a)return s;let i=a.match(/^(\w+)\s*:\s*(\{[\s\S]*\})$/);if(i){let[,p,f]=i;return`${p}: ${cn(f)}`}let o=a.match(/^(\w+)\s*=\s*(\{[\s\S]*\})$/);if(o){let[,p,f]=o;return`${p}: ${cn(f)}`}let u=a.match(/^(\w+)\s*:\s*(\[[\s\S]*\])$/);if(u){let[,p,f]=u;return`${p}: ${ln(f)}`}let c=a.match(/^(\w+)\s*=\s*(\[[\s\S]*\])$/);if(c){let[,p,f]=c;return`${p}: ${ln(f)}`}let l=a.match(/^(\w+)\s*=\s*([\s\S]+)$/);if(l){let[,p,f]=l;return`${p}: ${f}`}return s}).join(", ")} }`}function ln(e){let t=e.slice(1,-1).trim();return`[ ${pn(t).map(s=>{let a=s.trim();return a?a.startsWith("{")&&a.endsWith("}")?cn(a):a.startsWith("[")&&a.endsWith("]")?ln(a):s:s}).join(", ")} ]`}function oo(e){let t=0,n=!1,r=!1,s=!1,a="";for(let i=0;i<e.length;i++){let o=e[i];if(!s&&(o==="'"||o==='"'||o==="`")){s=!0,a=o;continue}if(s){o===a&&e[i-1]!=="\\"&&(s=!1);continue}o==="("||o==="{"||o==="["?t++:o===")"||o==="}"||o==="]"?t--:t===0&&(o===":"&&(n=!0),o==="="&&e[i+1]!==">"&&(r=!0))}return n&&!r}function ui(e){let t=0,n=!1,r="";for(let s=0;s<e.length;s++){let a=e[s];if(!n&&(a==="'"||a==='"'||a==="`")){n=!0,r=a;continue}if(n){a===r&&e[s-1]!=="\\"&&(n=!1);continue}if(a==="("||a==="{"||a==="[")t++;else if(a===")"||a==="}"||a==="]")t--;else if(t===0&&a===":")return s}return-1}function Qn(e){let t="",n=0;for(;n<e.length;){let r=e[n];if(r==="'"||r==='"'||r==="`"){let s=r;for(t+=r,n++;n<e.length&&e[n]!==s;)e[n]==="\\"&&(t+=e[n++]),n<e.length&&(t+=e[n++]);n<e.length&&(t+=e[n++]);continue}if(r==="/"&&e[n+1]==="*"){let s=e.indexOf("*/",n+2),a=s===-1?e.slice(n):e.slice(n,s+2);t+=a,n+=a.length;continue}if(r==="/"&&e[n+1]==="/"){let s=e.indexOf(`
|
|
58
|
+
`,n),a=s===-1?e.length:s;t+=" ".repeat(a-n),n=a;continue}t+=r,n++}return t}function hn(e,t={}){let n=e,r,s=new Set,a=new Set,i=new Set,o=/\/\*\s*tjs\s*<-\s*\S+\s*\*\//.test(e),u=t.dialect==="js"?!0:t.dialect==="tjs"?!1:o||t.vmTarget,c=u?{tjsEquals:!1,tjsClass:!1,tjsDate:!1,tjsNoeval:!1,tjsStandard:!1,tjsSafeEval:!1,tjsNoVar:!1,tjsSafeAssign:!1}:{tjsEquals:!0,tjsClass:!0,tjsDate:!0,tjsNoeval:!0,tjsStandard:!0,tjsSafeEval:!1,tjsNoVar:!0,tjsSafeAssign:!0};u&&(r="none");let l=e.match(/^(\s*(?:\/\/[^\n]*\n|\/\*[\s\S]*?\*\/\s*)*)\s*safety\s+(none|inputs|all)\b/);l&&(r=l[2],e=e.replace(/^(\s*(?:\/\/[^\n]*\n|\/\*[\s\S]*?\*\/\s*)*)\s*safety\s+(none|inputs|all)\s*/,"$1"));let p=/^(\s*(?:\/\/[^\n]*\n|\/\*[\s\S]*?\*\/\s*)*)\s*(TjsStrict|TjsCompat|TjsEquals|TjsClass|TjsDate|TjsNoeval|TjsNoVar|TjsStandard|TjsSafeEval|TjsSafeAssign)\b/,f;for(;f=e.match(p);){let I=f[2];I==="TjsStrict"?(c.tjsEquals=!0,c.tjsClass=!0,c.tjsDate=!0,c.tjsNoeval=!0,c.tjsNoVar=!0,c.tjsStandard=!0,c.tjsSafeAssign=!0):I==="TjsCompat"?(c.tjsEquals=!1,c.tjsClass=!1,c.tjsDate=!1,c.tjsNoeval=!1,c.tjsNoVar=!1,c.tjsStandard=!1,c.tjsSafeEval=!1,c.tjsSafeAssign=!1):I==="TjsEquals"?c.tjsEquals=!0:I==="TjsClass"?c.tjsClass=!0:I==="TjsDate"?c.tjsDate=!0:I==="TjsNoeval"?c.tjsNoeval=!0:I==="TjsNoVar"?c.tjsNoVar=!0:I==="TjsStandard"?c.tjsStandard=!0:I==="TjsSafeEval"?c.tjsSafeEval=!0:I==="TjsSafeAssign"&&(c.tjsSafeAssign=!0),e=e.replace(new RegExp(`^(\\s*(?:\\/\\/[^\\n]*\\n|\\/\\*[\\s\\S]*?\\*\\/\\s*)*)\\s*${I}\\s*`),"$1")}e=Qn(e),c.tjsStandard&&(e=Vs(e)),e=ti(e),e=si(e);let d=ii(e);e=d.source;let g=d.annotations,y=Ds(e);e=y.source,e=At(e),c.tjsEquals&&!t.vmTarget&&(e=Pt(e)),e=qs(e),e=Ws(e),e=Us(e),e=Js(e),e=zs(e),e=Zs(e);let w=Ls(e,{loader:t.moduleLoader,importerPath:t.filename});e=w.source;let{source:k,returnType:S,returnSafety:b}=fn(e,{originalSource:n,requiredParams:s,unsafeFunctions:a,safeFunctions:i});e=k;let _=Gs(e);e=_.source,e=Bs(e);let v=Ks(e,s);e=v.source;let x=Fs(e);e=x.source;let E=[...y.blocks,...w.blocks,...x.blocks],$=Qs(e,t.dangerouslySkipTests);e=$.source;let C=Ys(e,s);e=C.source;for(let I of C.polyCtorClasses)a.add(`${I}$dispatch`);return c.tjsClass&&(e=Xs(e,C.polyCtorClasses)),c.tjsDate&&(e=ei(e)),c.tjsNoeval&&(e=ri(e)),c.tjsNoVar&&(e=ni(e)),e=jt(e,_.extensions),{source:e,returnType:S,returnSafety:b,moduleSafety:r,tjsModes:c,originalSource:n,requiredParams:s,unsafeFunctions:a,safeFunctions:i,wasmBlocks:E,tests:$.tests,testErrors:$.errors,polymorphicNames:v.polymorphicNames,extensions:_.extensions,letAnnotations:g}}function Qe(e,t={}){let{filename:n="<source>",colonShorthand:r=!0,vmTarget:s=!1,dialect:a}=t,{source:i,returnType:o,returnSafety:u,moduleSafety:c,originalSource:l,requiredParams:p,unsafeFunctions:f,safeFunctions:d,wasmBlocks:g,tests:y,testErrors:w,letAnnotations:k,tjsModes:S}=r?hn(e,{vmTarget:s,dialect:a,moduleLoader:t.moduleLoader,filename:t.filename}):{source:e,returnType:void 0,returnSafety:void 0,moduleSafety:void 0,originalSource:e,requiredParams:new Set,unsafeFunctions:new Set,safeFunctions:new Set,wasmBlocks:[],tests:[],testErrors:[],letAnnotations:new Map,tjsModes:{tjsEquals:!1,tjsClass:!1,tjsDate:!1,tjsNoeval:!1,tjsStandard:!1,tjsSafeEval:!1,tjsNoVar:!1,tjsSafeAssign:!1}};try{return{ast:je(i,{ecmaVersion:2022,sourceType:"module",locations:!0,allowReturnOutsideFunction:!1}),returnType:o,returnSafety:u,moduleSafety:c,originalSource:l,requiredParams:p,unsafeFunctions:f,safeFunctions:d,wasmBlocks:g,tests:y,testErrors:w,letAnnotations:k,tjsModes:S}}catch(b){let _=b.loc||{line:1,column:0};throw new te(b.message.replace(/\s*\(\d+:\d+\)$/,""),_,l,n)}}function ci(e,t){for(let a of e.body){if(a.type==="ImportDeclaration")throw new te("Imports are not supported. All atoms must be registered with the VM.",a.loc?.start||{line:1,column:0},void 0,t);if(a.type==="ExportNamedDeclaration"||a.type==="ExportDefaultDeclaration")throw new te("Exports are not supported. The function is automatically exported.",a.loc?.start||{line:1,column:0},void 0,t);if(a.type==="ClassDeclaration")throw new te("Classes are not supported. Agent99 uses functional composition.",a.loc?.start||{line:1,column:0},void 0,t)}let n=e.body.filter(a=>a.type==="FunctionDeclaration");if(n.length===0)throw new te("Source must contain a function declaration",{line:1,column:0},void 0,t);let r=n[n.length-1],s=new Map;for(let a=0;a<n.length-1;a++){let i=n[a],o=i.id?.name;if(!o)throw new te("Helper function must have a name",i.loc?.start||{line:1,column:0},void 0,t);if(s.has(o))throw new te(`Duplicate helper function name: ${o}`,i.loc?.start||{line:1,column:0},void 0,t);if(o===r.id?.name)throw new te(`Helper function cannot share a name with the entry function: ${o}`,i.loc?.start||{line:1,column:0},void 0,t);s.set(o,i)}return{entry:r,helpers:s}}function Nt(e,t){let n={params:{}};if(!t.loc)return n;let r=e.substring(0,t.start),s=[...r.matchAll(/\/\*#([\s\S]*?)\*\//g)];if(s.length>0){let l=s[s.length-1],p=r.substring(l.index+l[0].length);if(/^(?:\s|\/\/[^\n]*)*$/.test(p)){let f=l[1],d=f.split(`
|
|
59
|
+
`),g=d.filter(y=>y.trim().length>0).reduce((y,w)=>{let k=w.match(/^(\s*)/)?.[1].length||0;return Math.min(y,k)},1/0);return g>0&&g<1/0&&(f=d.map(y=>y.slice(g)).join(`
|
|
60
|
+
`)),n.description=f.trim(),n}}let a=r.match(/\/\*\*[\s\S]*?\*\/\s*$/);if(!a)return n;let i=a[0],o=i.match(/\/\*\*\s*\n?\s*\*?\s*([^@\n][^\n]*)/m);o&&(n.description=o[1].trim());let u=/@param\s+(?:\{[^}]+\}\s+)?(\w+)\s*-?\s*(.*)/g,c;for(;(c=u.exec(i))!==null;)n.params[c[1]]=c[2].trim();return n}function ue(e){switch(e.type){case"Literal":{let t=e.value;if(t===null)return{kind:"null"};if(typeof t=="string")return{kind:"string"};if(typeof t=="number"){let n=e.raw;return n&&n.includes(".")?{kind:"number"}:{kind:"integer"}}return typeof t=="boolean"?{kind:"boolean"}:{kind:"any"}}case"ArrayExpression":{let t=e.elements;if(t.length===0)return{kind:"array",items:{kind:"any"}};let n=t.filter(i=>i!=null).map(i=>ue(i));if(n.length===0)return{kind:"array",items:{kind:"any"}};let r=new Map;for(let i of n){let o=JSON.stringify(i);r.has(o)||r.set(o,i)}let s=[...r.values()];return{kind:"array",items:s.length===1?s[0]:{kind:"union",members:s}}}case"ObjectExpression":{let t=e.properties,n={};for(let r of t)if(r.type==="Property"&&r.key.type==="Identifier"){let s=r.key.name;n[s]=ue(r.value)}return{kind:"object",shape:n}}case"LogicalExpression":{let{operator:t,left:n,right:r}=e;return t==="||"?ue(n):t==="&&"||t==="??"?ue(r):{kind:"any"}}case"BinaryExpression":{let{operator:t,left:n,right:r}=e;if(t==="|"){let s=ue(n),a=ue(r);return a.kind==="null"?{...s,nullable:!0}:s.kind==="null"?{...a,nullable:!0}:{kind:"union",members:[s,a]}}return{kind:"any"}}case"Identifier":return e.name==="undefined"?{kind:"undefined"}:{kind:"any"};case"ArrowFunctionExpression":case"FunctionExpression":{let t=e,n=t.params.map(s=>uo(s)),r={kind:"any"};return t.type==="ArrowFunctionExpression"&&t.body&&t.body.type!=="BlockStatement"&&(r=ue(t.body)),{kind:"function",params:n,returns:r}}case"UnaryExpression":{let t=e.operator,n=e.argument;if(t==="+"&&n.type==="Literal"&&typeof n.value=="number")return{kind:"non-negative-integer"};if(t==="-"&&n.type==="Literal"&&typeof n.value=="number"){let s=n.raw;return s&&s.includes(".")?{kind:"number"}:{kind:"integer"}}return{kind:"any"}}default:return{kind:"any"}}}function uo(e){return e.type==="Identifier"?{name:e.name,type:{kind:"any"}}:e.type==="AssignmentPattern"&&e.left?.type==="Identifier"?{name:e.left.name,type:ue(e.right)}:e.type==="RestElement"&&e.argument?.type==="Identifier"?{name:`...${e.argument.name}`,type:{kind:"array",items:{kind:"any"}}}:{name:"?",type:{kind:"any"}}}function Ge(e,t){if(e.type==="Identifier")return{name:e.name,type:{kind:"any"},required:!0};if(e.type==="AssignmentPattern"){let{left:n,right:r}=e;if(n.type!=="Identifier")throw new K("Only simple parameter names are supported",Z(e));let s=n.name,a=t?.has(s)??!1,i=ue(r),o=Ie(r);return{name:s,type:i,required:a,default:a?null:o,example:o,loc:{start:e.start,end:e.end}}}if(e.type==="ObjectPattern"){let n=e.properties,r={},s={};for(let a of n)if(a.type==="Property"){let i=a.key.type==="Identifier"?a.key.name:String(a.key.value);if(a.value.type==="Identifier")r[i]={kind:"any"},s[i]={name:i,type:{kind:"any"},required:!0};else if(a.value.type==="AssignmentPattern"){let o=Ge(a.value,t),u=t?.has(i)??!1;r[i]=o.type,s[i]={name:i,type:o.type,required:u,default:u?null:o.example,example:o.example}}}return{name:"__destructured__",type:{kind:"object",shape:r,destructuredParams:s},required:!0}}throw new K(`Unsupported parameter pattern: ${e.type}`,Z(e))}function Ie(e){switch(e.type){case"Literal":return e.value;case"ArrayExpression":return e.elements.map(t=>t?Ie(t):null);case"ObjectExpression":{let t={};for(let n of e.properties)n.type==="Property"&&n.key.type==="Identifier"&&(t[n.key.name]=Ie(n.value));return t}case"UnaryExpression":if(e.operator==="-"){let t=Ie(e.argument);return typeof t=="number"?-t:void 0}if(e.operator==="+"){let t=Ie(e.argument);return typeof t=="number"?+t:void 0}return;case"BinaryExpression":{let{operator:t,left:n}=e;return t==="|"?Ie(n):void 0}case"LogicalExpression":{let{operator:t,left:n,right:r}=e;return t==="&&"&&n.type==="Literal"&&n.value===null?null:t==="||"||t==="??"?Ie(n)??Ie(r):void 0}default:return}}function li(e){try{let t=$t(e,0,{ecmaVersion:2022});return ue(t)}catch{return{kind:"any"}}}function Yn(e){switch(e.kind){case"string":return e.nullable?"string | null":"string";case"number":return e.nullable?"number | null":"number";case"integer":return e.nullable?"integer | null":"integer";case"non-negative-integer":return e.nullable?"non-negative integer | null":"non-negative integer";case"boolean":return e.nullable?"boolean | null":"boolean";case"null":return"null";case"any":return"any";case"array":{let t=e.items?Yn(e.items):"any";return e.nullable?`${t}[] | null`:`${t}[]`}case"object":{if(!e.shape||Object.keys(e.shape).length===0)return e.nullable?"object | null":"object";let t=Object.entries(e.shape).map(([n,r])=>`${n}: ${Yn(r)}`).join(", ");return e.nullable?`{ ${t} } | null`:`{ ${t} }`}case"union":return e.members?.map(Yn).join(" | ")||"any";default:return"any"}}function dn(e){switch(e.kind){case"string":return{type:"string"};case"number":return{type:"number"};case"boolean":return{type:"boolean"};case"null":return{};case"undefined":return{};case"any":return{};case"array":return{type:"array",items:e.items?dn(e.items):{}};case"object":if(e.shape){let t={};for(let[n,r]of Object.entries(e.shape))t[n]=dn(r);return{type:"object",properties:t,additionalProperties:!1}}return{type:"object"};case"union":return e.members?{oneOf:e.members.map(dn)}:{};default:return{}}}function co(e){let t={},n=[];for(let[r,s]of Object.entries(e))t[r]=dn(s.type),s.required&&n.push(r);return{type:"object",properties:t,required:n.length>0?n:void 0,additionalProperties:!1}}function Xn(e,t,n,r={},s,a){let i=Nt(t,e),o=new Map;for(let S of e.params){let b=Ge(S,s);if(b.name==="__destructured__"&&b.type.kind==="object"&&b.type.destructuredParams)for(let[_,v]of Object.entries(b.type.destructuredParams))o.set(_,{...v,description:i.params[_]});else b.description=i.params[b.name],o.set(b.name,b)}let u;n&&(u=li(n));let c={depth:0,locals:new Map,parameters:o,atoms:new Set(Object.keys(r.atoms||{})),warnings:[],source:t,filename:r.filename||"<source>",options:r,helpers:a,helperSteps:a?new Map:void 0,helperTransforming:a?new Set:void 0},l=Ee(e.body,c),p=[],f=[],d=[];for(let[S,b]of o.entries())b.required?f.push(S):b.default!==void 0?d.push({name:S,defaultValue:b.default}):f.push(S);f.length>0&&p.push({op:"varsImport",keys:f});for(let{name:S,defaultValue:b}of d)p.push({op:"varsImport",keys:[S]}),p.push({op:"if",condition:{$expr:"binary",op:"==",left:{$expr:"ident",name:S},right:{$expr:"literal",value:null}},then:[{op:"varSet",key:S,value:b}]});p.push(...l);let g=Object.fromEntries(o),y={name:e.id?.name||"anonymous",description:i.description,parameters:g,returns:u},w=co(g),k=c.helperSteps&&c.helperSteps.size>0?Object.fromEntries(c.helperSteps):void 0;return{ast:{op:"seq",steps:p,inputSchema:w,...k&&{helpers:k}},signature:y,warnings:c.warnings}}function Ee(e,t){let n=[];for(let r of e.body){let s=Rt(r,t);s&&(Array.isArray(s)?n.push(...s):n.push(s))}return n}function Rt(e,t){switch(e.type){case"VariableDeclaration":return lo(e,t);case"ExpressionStatement":return fo(e,t);case"IfStatement":return ho(e,t);case"WhileStatement":return mo(e,t);case"ForOfStatement":return go(e,t);case"TryStatement":return yo(e,t);case"ReturnStatement":return bo(e,t);case"ThrowStatement":throw new K("'throw' is not supported in AsyncJS. Use Error('message') to trigger error flow",Z(e),t.source,t.filename);case"BlockStatement":return{op:"scope",steps:Ee(e,Se(t))};case"EmptyStatement":return null;default:throw new K(`Unsupported statement type: ${e.type}`,Z(e),t.source,t.filename)}}function lo(e,t){let n=[],r=e.kind==="const",s=r?"constSet":"varSet";for(let a of e.declarations){if(a.id.type!=="Identifier")throw new K("Only simple variable names are supported",Z(a),t.source,t.filename);let i=a.id.name;if(a.init){let{step:o,resultVar:u}=Ye(a.init,t,i,r);o?n.push(o):u!==i&&n.push({op:s,key:i,value:u});let c=ue(a.init);t.locals.set(i,c)}else{if(r)throw new K("const declarations must be initialized",Z(a),t.source,t.filename);n.push({op:"varSet",key:i,value:null}),t.locals.set(i,{kind:"any",nullable:!0})}}return n}function fo(e,t){let n=e.expression;if(n.type==="AssignmentExpression")return po(n,t);if(n.type==="CallExpression"){let{step:r,resultVar:s}=Ye(n,t);return r||(s?{op:"varSet",key:"_",value:s}:null)}return t.warnings.push({message:"Expression statement has no effect",line:Z(e).line,column:Z(e).column}),null}function po(e,t){if(e.left.type!=="Identifier")throw new K("Only simple variable assignment is supported",Z(e),t.source,t.filename);let n=e.left.name,{step:r,resultVar:s}=Ye(e.right,t,n);return r||{op:"varSet",key:n,value:s}}function ho(e,t){let n=G(e.test,t),r=e.consequent.type==="BlockStatement"?Ee(e.consequent,Se(t)):[Rt(e.consequent,t)].filter(Boolean),s;return e.alternate&&(s=e.alternate.type==="BlockStatement"?Ee(e.alternate,Se(t)):[Rt(e.alternate,t)].filter(Boolean)),{op:"if",condition:n,then:r,...s&&{else:s}}}function mo(e,t){let n=G(e.test,t),r=e.body.type==="BlockStatement"?Ee(e.body,Se(t)):[Rt(e.body,t)].filter(Boolean);return{op:"while",condition:n,body:r}}function go(e,t){let n;if(e.left.type==="VariableDeclaration"){let i=e.left.declarations[0];if(i.id.type!=="Identifier")throw new K("Only simple variable names are supported in for...of",Z(e.left),t.source,t.filename);n=i.id.name}else if(e.left.type==="Identifier")n=e.left.name;else throw new K("Unsupported for...of left-hand side",Z(e.left),t.source,t.filename);let r=ie(e.right,t),s=Se(t);s.locals.set(n,{kind:"any"});let a=e.body.type==="BlockStatement"?Ee(e.body,s):[Rt(e.body,s)].filter(Boolean);return{op:"map",items:r,as:n,steps:a}}function yo(e,t){let n=Ee(e.block,Se(t)),r,s;if(e.handler){let a=Se(t);e.handler.param?.type==="Identifier"&&(s=e.handler.param.name,a.locals.set(s,{kind:"any"})),r=Ee(e.handler.body,a)}return{op:"try",try:n,...r&&{catch:r},...s&&{catchParam:s}}}function bo(e,t){if(!e.argument)return{op:"return",value:{}};let{step:n,resultVar:r}=Ye(e.argument,t,"__returnVal__");return n?[n,{op:"return",value:r}]:{op:"return",value:ie(e.argument,t)}}var pi=new Set(["Math","JSON","Array","Object","String","Number","console","Date","Schema"]),xo=new Set(["parseInt","parseFloat","isNaN","isFinite","encodeURI","decodeURI","encodeURIComponent","decodeURIComponent","Set","Date","filter"]),Mt=new Set(["RegExp","Promise","Map","WeakSet","WeakMap","Symbol","Proxy","Reflect","Function","eval","setTimeout","setInterval","fetch","require","import","process","window","document","global","globalThis"]),_o=new Set(["toUpperCase","toLowerCase","trim","trimStart","trimEnd","charAt","charCodeAt","codePointAt","concat","includes","indexOf","lastIndexOf","startsWith","endsWith","slice","substring","substr","replace","replaceAll","match","search","padStart","padEnd","repeat","normalize","localeCompare","toString","valueOf","at","reverse","sort","fill","copyWithin","flat","flatMap","every","some","forEach","add","remove","has","clear","toArray","union","intersection","diff","format","isBefore","isAfter"]);function wo(e){if(e.callee.type==="Identifier"){let t=e.callee.name;return xo.has(t)||Mt.has(t)}if(e.callee.type==="MemberExpression"){let t=e.callee;if(t.object.type==="Identifier"){let n=t.object.name;if(pi.has(n)||Mt.has(n))return!0}if(t.property.type==="Identifier"){let n=t.property.name;if(_o.has(n))return!0}}return!1}function So(e){if(e.object.type==="Identifier"){let t=e.object.name;return pi.has(t)||Mt.has(t)}return!1}var fi={RegExp:"RegExp is not available. Use string methods or the regexMatch atom.",Promise:"Promise is not needed. All operations are implicitly async.",Map:"Map is not available. Use plain objects instead.",WeakSet:"WeakSet is not available.",WeakMap:"WeakMap is not available.",Symbol:"Symbol is not available.",Proxy:"Proxy is not available.",Reflect:"Reflect is not available.",Function:"Function constructor is not available. Define functions normally.",eval:"eval is not available. Code is compiled, not evaluated.",setTimeout:"setTimeout is not available. Use the delay atom.",setInterval:"setInterval is not available. Use while loops with delay.",fetch:"fetch is not available. Use the httpFetch atom.",require:"require is not available. Atoms must be registered with the VM.",import:"import is not available. Atoms must be registered with the VM.",process:"process is not available. AsyncJS runs in a sandboxed environment.",window:"window is not available. AsyncJS runs in a sandboxed environment.",document:"document is not available. AsyncJS runs in a sandboxed environment.",global:"global is not available. AsyncJS runs in a sandboxed environment.",globalThis:"globalThis is not available. Use builtins directly."};function vo(e){if(e.callee.type==="Identifier"){let t=e.callee.name;if(Mt.has(t))return fi[t]||`${t} is not available in AsyncJS.`}if(e.callee.type==="MemberExpression"){let t=e.callee;if(t.object.type==="Identifier"){let n=t.object.name;if(Mt.has(n))return fi[n]||`${n} is not available in AsyncJS.`}}return null}function hi(e){return{Date:" Use Date() or Date('2024-01-15') instead - no 'new' needed.",Set:" Use Set([items]) instead - no 'new' needed.",Map:" Use plain objects instead of Map.",Array:" Use array literals like [1, 2, 3] instead.",Object:" Use object literals like { key: value } instead.",Error:" Return an error object like { error: 'message' } instead.",RegExp:" Use string methods or the regexMatch atom.",Promise:" Not needed - all operations are implicitly async.",WeakSet:" WeakSet is not available.",WeakMap:" WeakMap is not available."}[e]||" Use factory functions or object literals instead."}function Ye(e,t,n,r){let s=r?"constSet":"varSet";if(e.type==="ChainExpression")return Ye(e.expression,t,n,r);if(e.type==="NewExpression"){let i=e,o="constructor";i.callee.type==="Identifier"&&(o=i.callee.name);let u=hi(o);throw new K(`The 'new' keyword is not supported in AsyncJS.${u}`,Z(e),t.source,t.filename)}if(e.type==="CallExpression"){let i=vo(e);if(i)throw new K(i,Z(e),t.source,t.filename)}if(e.type==="CallExpression"&&wo(e)){let i=G(e,t);return n?{step:{op:s,key:n,value:i},resultVar:n}:{step:null,resultVar:i}}if(e.type==="MemberExpression"&&So(e)){let i=G(e,t);return n?{step:{op:s,key:n,value:i},resultVar:n}:{step:null,resultVar:i}}if(e.type==="CallExpression")return ko(e,t,n,r);if(e.type==="TemplateLiteral")return $o(e,t,n,r);if(e.type==="BinaryExpression"||e.type==="LogicalExpression"||e.type==="UnaryExpression"){let i=G(e,t);return n?{step:{op:s,key:n,value:i},resultVar:n}:{step:null,resultVar:i}}return{step:null,resultVar:ie(e,t)}}function ko(e,t,n,r){let s,a=!1,i;if(e.callee.type==="Identifier")s=e.callee.name;else if(e.callee.type==="MemberExpression"){let u=e.callee;if(u.property.type==="Identifier")s=u.property.name,a=!0,i=ie(u.object,t);else throw new K("Computed method names are not supported",Z(e),t.source,t.filename)}else throw new K("Only named function calls are supported",Z(e),t.source,t.filename);if(a)return To(s,i,e.arguments,t,n,r);if(s==="console"&&e.callee.type,t.helpers?.has(s)){let u=Eo(s,t,e),c=e.arguments.map(l=>ie(l,t));if(c.length!==u.length)throw new K(`Helper '${s}' expects ${u.length} argument(s), got ${c.length}`,Z(e),t.source,t.filename);return{step:{op:"callLocal",name:s,args:c,...n&&{result:n},...n&&r&&{resultConst:!0}},resultVar:n}}let o=Co(e,t);return{step:{op:s,...o,...n&&{result:n},...n&&r&&{resultConst:!0}},resultVar:n}}function Eo(e,t,n){let r=t.helpers.get(e),s=[];for(let a of r.params){let i;if(a.type==="Identifier"?i=a:a.type==="AssignmentPattern"&&a.left?.type==="Identifier"&&(i=a.left),!i)throw new K(`Helper '${e}' parameters must be plain identifiers (optionally with an example value); destructuring is not supported`,a.loc?.start??Z(n),t.source,t.filename);s.push(i.name)}if(t.helperSteps.has(e)||t.helperTransforming.has(e))return s;t.helperTransforming.add(e);try{let a={depth:0,locals:new Map,parameters:new Map(s.map(o=>[o,{name:o,type:{kind:"any"},required:!0}])),atoms:t.atoms,warnings:t.warnings,source:t.source,filename:t.filename,options:t.options,helpers:t.helpers,helperSteps:t.helperSteps,helperTransforming:t.helperTransforming},i=Ee(r.body,a);t.helperSteps.set(e,{steps:i,paramNames:s})}finally{t.helperTransforming.delete(e)}return s}function To(e,t,n,r,s,a){switch(e){case"map":if(n.length>0&&(n[0].type==="ArrowFunctionExpression"||n[0].type==="FunctionExpression")){let i=n[0],o=i.params[0],u=o?.type==="Identifier"?o.name:"item",c=Se(r);c.locals.set(u,{kind:"any"});let l;if(i.body.type==="BlockStatement")l=Ee(i.body,c);else{let{step:p,resultVar:f}=Ye(i.body,c,"result");l=p?[p]:[{op:"varSet",key:"result",value:f}]}return{step:{op:"map",items:t,as:u,steps:l,...s&&{result:s},...s&&a&&{resultConst:!0}},resultVar:s}}break;case"filter":if(n.length>0&&(n[0].type==="ArrowFunctionExpression"||n[0].type==="FunctionExpression")){let i=n[0],o=i.params[0],u=o?.type==="Identifier"?o.name:"item",c=Se(r);c.locals.set(u,{kind:"any"});let l;if(i.body.type==="BlockStatement")throw new K("filter callback must be an expression, not a block",Z(n[0]),r.source,r.filename);return l=G(i.body,c),{step:{op:"filter",items:t,as:u,condition:l,...s&&{result:s},...s&&a&&{resultConst:!0}},resultVar:s}}break;case"find":if(n.length>0&&(n[0].type==="ArrowFunctionExpression"||n[0].type==="FunctionExpression")){let i=n[0],o=i.params[0],u=o?.type==="Identifier"?o.name:"item",c=Se(r);c.locals.set(u,{kind:"any"});let l;if(i.body.type==="BlockStatement")throw new K("find callback must be an expression, not a block",Z(n[0]),r.source,r.filename);return l=G(i.body,c),{step:{op:"find",items:t,as:u,condition:l,...s&&{result:s},...s&&a&&{resultConst:!0}},resultVar:s}}break;case"reduce":if(n.length>=2&&(n[0].type==="ArrowFunctionExpression"||n[0].type==="FunctionExpression")){let i=n[0],o=i.params[0],u=i.params[1],c=o?.type==="Identifier"?o.name:"acc",l=u?.type==="Identifier"?u.name:"item",p=Se(r);p.locals.set(c,{kind:"any"}),p.locals.set(l,{kind:"any"});let f;if(i.body.type==="BlockStatement")f=Ee(i.body,p);else{let{step:g,resultVar:y}=Ye(i.body,p,"result");f=g?[g]:[{op:"varSet",key:"result",value:y}]}let d=ie(n[1],r);return{step:{op:"reduce",items:t,as:l,accumulator:c,initial:d,steps:f,...s&&{result:s},...s&&a&&{resultConst:!0}},resultVar:s}}break;case"slice":break;case"push":return{step:{op:"push",list:t,item:ie(n[0],r),...s&&{result:s},...s&&a&&{resultConst:!0}},resultVar:s};case"join":return{step:{op:"join",list:t,sep:n.length>0?ie(n[0],r):"",...s&&{result:s},...s&&a&&{resultConst:!0}},resultVar:s};case"split":return{step:{op:"split",str:t,sep:n.length>0?ie(n[0],r):"",...s&&{result:s},...s&&a&&{resultConst:!0}},resultVar:s}}return r.warnings.push({message:`Unknown method '${e}' - treating as atom call`,line:0,column:0}),{step:{op:e,receiver:t,args:n.map(i=>ie(i,r)),...s&&{result:s},...s&&a&&{resultConst:!0}},resultVar:s}}function $o(e,t,n,r){let s="",a={};for(let i=0;i<e.quasis.length;i++)if(s+=e.quasis[i].value.cooked||e.quasis[i].value.raw,i<e.expressions.length){let o=e.expressions[i],u=`_${i}`;a[u]=ie(o,t),s+=`{{${u}}}`}return{step:{op:"template",tmpl:s,vars:a,...n&&{result:n},...n&&r&&{resultConst:!0}},resultVar:n}}function G(e,t){switch(e.type){case"Literal":return{$expr:"literal",value:e.value};case"Identifier":return{$expr:"ident",name:e.name};case"MemberExpression":{let n=e,r=G(n.object,t),s=n.optional===!0;if(n.computed){let i=n.property;return i.type==="Literal"?{$expr:"member",object:r,property:String(i.value),computed:!0,...s&&{optional:!0}}:{$expr:"member",object:r,property:G(i,t),computed:!0,...s&&{optional:!0}}}let a=n.property.name;return{$expr:"member",object:r,property:a,...s&&{optional:!0}}}case"ChainExpression":return G(e.expression,t);case"BinaryExpression":{let n=e;return{$expr:"binary",op:n.operator,left:G(n.left,t),right:G(n.right,t)}}case"LogicalExpression":{let n=e;return{$expr:"logical",op:n.operator,left:G(n.left,t),right:G(n.right,t)}}case"UnaryExpression":{let n=e;return{$expr:"unary",op:n.operator,argument:G(n.argument,t)}}case"ConditionalExpression":{let n=e;return{$expr:"conditional",test:G(n.test,t),consequent:G(n.consequent,t),alternate:G(n.alternate,t)}}case"ArrayExpression":return{$expr:"array",elements:e.elements.filter(r=>r!==null).map(r=>G(r,t))};case"ObjectExpression":{let n=e,r=[];for(let s of n.properties)if(s.type==="Property"){let a=s.key.type==="Identifier"?s.key.name:String(s.key.value);r.push({key:a,value:G(s.value,t)})}return{$expr:"object",properties:r}}case"CallExpression":{let n=e;if(n.callee.type==="MemberExpression"){let r=n.callee,s=r.property.type==="Identifier"?r.property.name:String(r.property.value),a=r.optional===!0||n.optional===!0;return{$expr:"methodCall",object:G(r.object,t),method:s,arguments:n.arguments.map(i=>G(i,t)),...a&&{optional:!0}}}if(n.callee.type==="Identifier"){let r=n.callee.name;if(t.helpers?.has(r))throw new K(`Helper '${r}' cannot be called inside an expression. Assign its result to a variable first: const result = ${r}(...); then use result.`,Z(e),t.source,t.filename);return{$expr:"call",callee:r,arguments:n.arguments.map(s=>G(s,t))}}throw new K("Complex function calls in expressions should be lifted to statements",Z(e),t.source,t.filename)}case"NewExpression":{let n=e,r="constructor";n.callee.type==="Identifier"&&(r=n.callee.name);let s=hi(r);throw new K(`The 'new' keyword is not supported in AsyncJS.${s}`,Z(e),t.source,t.filename)}case"TemplateLiteral":throw new K("Template literals inside expressions are not supported. Assign to a variable first: const msg = `hello ${name}`; then use msg",Z(e),t.source,t.filename);default:throw new K(`Unsupported expression type in condition: ${e.type}`,Z(e),t.source,t.filename)}}function ie(e,t){switch(e.type){case"Literal":return e.value;case"Identifier":return e.name;case"MemberExpression":{let n=e;if(n.optional===!0)return G(e,t);let s=ie(n.object,t);if(s&&typeof s=="object"&&s.$expr){let i=n.computed?String(n.property.value):n.property.name;return{$expr:"member",object:s,property:i,...n.computed&&{computed:!0}}}if(n.computed)return G(e,t);let a=n.property.name;return typeof s=="string"?`${s}.${a}`:s&&s.$kind==="arg"?{$kind:"arg",path:`${s.path}.${a}`}:`${s}.${a}`}case"ChainExpression":return ie(e.expression,t);case"ArrayExpression":return e.elements.map(n=>n?ie(n,t):null);case"ObjectExpression":{let n={};for(let r of e.properties)if(r.type==="Property"){let s=r.key.type==="Identifier"?r.key.name:String(r.key.value);n[s]=ie(r.value,t)}return n}case"TemplateLiteral":return G(e,t);case"CallExpression":return G(e,t);case"BinaryExpression":case"LogicalExpression":case"UnaryExpression":case"ConditionalExpression":return G(e,t);default:return null}}function Co(e,t){if(e.arguments.length===1&&e.arguments[0].type==="ObjectExpression"){let n=e.arguments[0],r={};for(let s of n.properties)if(s.type==="Property"){let a=s.key.type==="Identifier"?s.key.name:String(s.key.value);r[a]=ie(s.value,t)}return r}return{args:e.arguments.map(n=>ie(n,t))}}function Ao(e,t){let n=t;for(;n>0&&e[n-1]!==`
|
|
61
|
+
`;)n--;if(e.slice(n,t).includes("//"))return!0;let s=0,a=!1;for(;s<t;)!a&&e.slice(s,s+2)==="/*"?(a=!0,s+=2):a&&e.slice(s,s+2)==="*/"?(a=!1,s+=2):s++;return a}function Po(e){let t=[],n=/\/\*test\s+'([^']*)'\s*\{([\s\S]*?)\}\s*\*\/|\/\*test\s+"([^"]*)"\s*\{([\s\S]*?)\}\s*\*\/|\/\*test\s+`([^`]*)`\s*\{([\s\S]*?)\}\s*\*\/|\/\*test\s*\{([\s\S]*?)\}\s*\*\//g,r;for(;(r=n.exec(e))!==null;){let s=r[1]||r[3]||r[5]||`embedded test ${t.length+1}`,a=(r[2]||r[4]||r[6]||r[7]||"").trim();t.push({description:s,body:a,line:er(e,r.index)})}return t}function tr(e){let t=[],n=[],r=Po(e);t.push(...r);let s=/test\s+'([^']*)'\s*\{|test\s+"([^"]*)"\s*\{|test\s+`([^`]*)`\s*\{|test\s*\(\s*'([^']*)'\s*\)\s*\{|test\s*\(\s*"([^"]*)"\s*\)\s*\{|test\s*\(\s*`([^`]*)`\s*\)\s*\{|test\s*\{/g,a=/mock\s*\{/g,i=e,o,u=[];for(;(o=s.exec(e))!==null;){let f=o.index;if(Ao(e,f))continue;let d=o[1]||o[2]||o[3]||o[4]||o[5]||o[6]||`test ${t.length+1}`,g=o.index+o[0].length,y=di(e,g-1);if(y===-1)continue;let w=e.slice(g,y).trim();t.push({description:d,body:w,line:er(e,f)}),u.push({start:f,end:y+1,desc:d})}let c=[];for(;(o=a.exec(e))!==null;){let f=o.index,d=o.index+o[0].length,g=di(e,d-1);if(g===-1)continue;let y=e.slice(d,g).trim();n.push({body:y,line:er(e,f)}),c.push({start:f,end:g+1})}let l=[...u,...c].sort((f,d)=>d.start-f.start);for(let f of l)i=i.slice(0,f.start)+i.slice(f.end);i=i.replace(/\n\s*\n\s*\n/g,`
|
|
62
|
+
|
|
63
|
+
`).trim();let p=jo(t,n);return{code:i,tests:t,mocks:n,testRunner:p}}function di(e,t){let n=0,r=null,s=!1;for(let a=t;a<e.length;a++){let i=e[a];if(s){s=!1;continue}if(i==="\\"){s=!0;continue}if(!r&&(i==='"'||i==="'"||i==="`")){r=i;continue}if(r===i){r=null;continue}if(!r&&(i==="{"&&n++,i==="}"&&(n--,n===0)))return a}return-1}function er(e,t){return e.slice(0,t).split(`
|
|
64
|
+
`).length}function jo(e,t){if(e.length===0)return"// No tests defined";let n=t.map(s=>s.body).join(`
|
|
65
|
+
`);return`(async () => {
|
|
66
|
+
const __results = []
|
|
67
|
+
|
|
68
|
+
${e.map((s,a)=>`
|
|
69
|
+
// Test ${a+1}: ${s.description}
|
|
70
|
+
try {
|
|
71
|
+
${n}
|
|
72
|
+
await (async () => {
|
|
73
|
+
${s.body}
|
|
74
|
+
})()
|
|
75
|
+
__results.push({ description: ${JSON.stringify(s.description)}, passed: true })
|
|
76
|
+
} catch (__e) {
|
|
77
|
+
__results.push({ description: ${JSON.stringify(s.description)}, passed: false, error: __e.message })
|
|
78
|
+
}`).join(`
|
|
79
|
+
`)}
|
|
80
|
+
|
|
81
|
+
// Compute summary (no console output - caller handles reporting)
|
|
82
|
+
const __passed = __results.filter(r => r.passed).length
|
|
83
|
+
const __failed = __results.filter(r => !r.passed).length
|
|
84
|
+
|
|
85
|
+
// Return summary
|
|
86
|
+
return { passed: __passed, failed: __failed, results: __results }
|
|
87
|
+
})()`.trim()}var mi=`
|
|
88
|
+
function assert(condition, message) {
|
|
89
|
+
if (!condition) {
|
|
90
|
+
throw new Error(message || 'Assertion failed')
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
`,gi=`
|
|
94
|
+
function expect(actual) {
|
|
95
|
+
const deepEqual = (a, b) => {
|
|
96
|
+
if (a === b) return true
|
|
97
|
+
if (a === null || b === null) return a === b
|
|
98
|
+
if (a === undefined || b === undefined) return a === undefined && b === undefined
|
|
99
|
+
if (typeof a !== typeof b) return false
|
|
100
|
+
if (typeof a !== 'object') return a === b
|
|
101
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false
|
|
102
|
+
if (Array.isArray(a)) {
|
|
103
|
+
if (a.length !== b.length) return false
|
|
104
|
+
return a.every((v, i) => deepEqual(v, b[i]))
|
|
105
|
+
}
|
|
106
|
+
const keysA = Object.keys(a)
|
|
107
|
+
const keysB = Object.keys(b)
|
|
108
|
+
if (keysA.length !== keysB.length) return false
|
|
109
|
+
return keysA.every(k => deepEqual(a[k], b[k]))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const format = (v) => {
|
|
113
|
+
if (v === null) return 'null'
|
|
114
|
+
if (v === undefined) return 'undefined'
|
|
115
|
+
if (typeof v === 'string') return JSON.stringify(v)
|
|
116
|
+
if (typeof v === 'object') return JSON.stringify(v)
|
|
117
|
+
return String(v)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
toBe(expected) {
|
|
122
|
+
if (!deepEqual(actual, expected)) {
|
|
123
|
+
throw new Error(\`Expected \${format(expected)} but got \${format(actual)}\`)
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
toEqual(expected) {
|
|
127
|
+
if (!deepEqual(actual, expected)) {
|
|
128
|
+
throw new Error(\`Expected \${format(expected)} but got \${format(actual)}\`)
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
toContain(item) {
|
|
132
|
+
if (!Array.isArray(actual) || !actual.some(v => deepEqual(v, item))) {
|
|
133
|
+
throw new Error(\`Expected \${format(actual)} to contain \${format(item)}\`)
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
toThrow(message) {
|
|
137
|
+
let threw = false
|
|
138
|
+
let thrownMessage = ''
|
|
139
|
+
try {
|
|
140
|
+
if (typeof actual === 'function') actual()
|
|
141
|
+
} catch (e) {
|
|
142
|
+
threw = true
|
|
143
|
+
thrownMessage = e.message || String(e)
|
|
144
|
+
}
|
|
145
|
+
if (!threw) {
|
|
146
|
+
throw new Error('Expected function to throw but it did not')
|
|
147
|
+
}
|
|
148
|
+
if (message && !thrownMessage.includes(message)) {
|
|
149
|
+
throw new Error(\`Expected error containing "\${message}" but got "\${thrownMessage}"\`)
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
toBeTruthy() {
|
|
153
|
+
if (!actual) {
|
|
154
|
+
throw new Error(\`Expected \${format(actual)} to be truthy\`)
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
toBeFalsy() {
|
|
158
|
+
if (actual) {
|
|
159
|
+
throw new Error(\`Expected \${format(actual)} to be falsy\`)
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
toBeNull() {
|
|
163
|
+
if (actual !== null) {
|
|
164
|
+
throw new Error(\`Expected null but got \${format(actual)}\`)
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
toBeUndefined() {
|
|
168
|
+
if (actual !== undefined) {
|
|
169
|
+
throw new Error(\`Expected undefined but got \${format(actual)}\`)
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
toBeGreaterThan(n) {
|
|
173
|
+
if (!(actual > n)) {
|
|
174
|
+
throw new Error(\`Expected \${format(actual)} to be greater than \${n}\`)
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
toBeLessThan(n) {
|
|
178
|
+
if (!(actual < n)) {
|
|
179
|
+
throw new Error(\`Expected \${format(actual)} to be less than \${n}\`)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
`,Io=mi+`
|
|
185
|
+
`+gi;var O=e=>({schema:e,_type:null,validate:(t,n)=>Ne(t,e,n),get optional(){return O({...e,type:Array.isArray(e.type)?[...e.type,"null"]:[e.type,"null"]})},title:t=>O({...e,title:t}),describe:t=>O({...e,description:t}),default:t=>O({...e,default:t}),meta:t=>O({...t,...e,...t}),min:t=>{let n=e.type==="string"?"minLength":e.type==="array"?"minItems":e.type==="object"?"minProperties":"minimum";return O({...e,[n]:t})},max:t=>{let n=e.type==="string"?"maxLength":e.type==="array"?"maxItems":e.type==="object"?"maxProperties":"maximum";return O({...e,[n]:t})},pattern:t=>O({...e,pattern:typeof t=="string"?t:t.source}),get email(){return O({...e,format:"email"})},get uuid(){return O({...e,format:"uuid"})},get ipv4(){return O({...e,format:"ipv4"})},get url(){return O({...e,format:"uri"})},get datetime(){return O({...e,format:"date-time"})},get emoji(){return O({...e,pattern:"^\\p{Extended_Pictographic}+$",format:"emoji"})},get int(){return O({...e,type:"integer"})},step:t=>O({...e,multipleOf:t})}),nr={get email(){return O({type:"string",format:"email"})},get uuid(){return O({type:"string",format:"uuid"})},get ipv4(){return O({type:"string",format:"ipv4"})},get url(){return O({type:"string",format:"uri"})},get datetime(){return O({type:"string",format:"date-time"})},get emoji(){return O({type:"string",pattern:"^\\p{Extended_Pictographic}+$",format:"emoji"})},get null(){return O({type:"null"})},get undefined(){return O({type:"null","x-tjs-undefined":!0})},get any(){return O({})},pattern:e=>O({type:"string",pattern:typeof e=="string"?e:e.source}),union:e=>O({anyOf:e.map(t=>t.schema)}),enum:e=>O({type:typeof e[0],enum:e}),const:e=>O({const:e}),array:e=>O({type:"array",items:e.schema}),tuple:e=>O({type:"array",items:e.map(t=>t.schema),minItems:e.length,maxItems:e.length}),object:e=>{let t={},n=[];for(let r in e)t[r]=e[r].schema,(!Array.isArray(t[r].type)||!t[r].type.includes("null"))&&n.push(r);return O({type:"object",properties:t,required:n,additionalProperties:!1})},record:e=>O({type:"object",additionalProperties:e.schema}),infer:e=>{if(e===null)return O({type:"null"});if(e===void 0)return O({type:"null","x-tjs-undefined":!0});let t=typeof e;if(t==="string")return O({type:"string"});if(t==="number")return O({type:Number.isInteger(e)?"integer":"number"});if(t==="boolean")return O({type:"boolean"});if(Array.isArray(e))return e.length===0?O({type:"array"}):O({type:"array",items:nr.infer(e[0]).schema});if(t==="object"){let n={},r=[];for(let s in e)n[s]=nr.infer(e[s]).schema,r.push(s);return O({type:"object",properties:n,required:r,additionalProperties:!1})}return O({})}},ye=new Proxy(nr,{get(e,t){if(t in e)return e[t];if(t==="string"||t==="number"||t==="boolean"||t==="integer"){let n=O({type:t});return e[t]=n,n}}}),yi={email:e=>/^\S+@\S+\.\S+$/.test(e),uuid:e=>/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e),uri:e=>{try{return new URL(e),!0}catch{return!1}},ipv4:e=>/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(e),"date-time":e=>!isNaN(Date.parse(e)),emoji:e=>new RegExp("\\p{Extended_Pictographic}","u").test(e)};function Ne(e,t,n){let r=t?.schema||t,s=typeof n=="function"?n:n?.onError,a=typeof n=="object"?n?.strict??n?.fullScan??!1:!1,i=[],o=c=>(s&&s(i.join(".")||"root",c),!1),u=(c,l)=>{if(l.anyOf){for(let f of l.anyOf)if(Ne(c,f))return!0;return o("Union mismatch")}if(l.const!==void 0)return c===l.const||o("Const mismatch");if(c===null){let f=l.type==="null"&&!l["x-tjs-undefined"],d=Array.isArray(l.type)&&l.type.includes("null");return f||d||!l.type||o("Expected value, got null")}if(c===void 0){let f=l.type==="null"&&l["x-tjs-undefined"],d=Array.isArray(l.type)&&l.type.includes("null");return f||d||!l.type||o("Expected value, got undefined")}let p=Array.isArray(l.type)?l.type[0]:l.type;if(l.enum&&!l.enum.includes(c))return o("Enum mismatch");if(p==="integer"){if(typeof c!="number"||!Number.isInteger(c))return o("Expected integer")}else if(p==="array"){if(!Array.isArray(c))return o("Expected array")}else if(p==="object"){if(typeof c!="object"||Array.isArray(c))return o("Expected object")}else if(p&&typeof c!==p)return o(`Expected ${p}`);if(typeof c=="number"){if(!Number.isFinite(c))return o("Expected finite number");if(l.minimum!==void 0&&c<l.minimum)return o("Value < min");if(l.maximum!==void 0&&c>l.maximum)return o("Value > max");if(l.multipleOf!==void 0){let f=Math.abs(c%l.multipleOf),d=1e-10;if(f>1e-10&&Math.abs(f-Math.abs(l.multipleOf))>1e-10)return o("Value not step")}}if(typeof c=="string"){if(l.minLength!==void 0&&c.length<l.minLength)return o("Len < min");if(l.maxLength!==void 0&&c.length>l.maxLength)return o("Len > max");if(l.pattern&&!new RegExp(l.pattern,l.format==="emoji"?"u":"").test(c))return o("Pattern mismatch");if(l.format&&yi[l.format]&&!yi[l.format](c))return o("Format invalid")}if(p==="object"){let f=l.minProperties!==void 0,d=a&&l.maxProperties!==void 0;if(f||d){let g=0;for(let y in c)Object.prototype.hasOwnProperty.call(c,y)&&g++;if(f&&g<l.minProperties)return o("Too few props");if(d&&g>l.maxProperties)return o("Too many props")}if(l.required){for(let g of l.required)if(!(g in c))return o(`Missing ${g}`)}if(l.properties){for(let g in l.properties)if(g in c){i.push(g);let y=u(c[g],l.properties[g]);if(i.pop(),!y)return!1}}if(l.additionalProperties){let g=[];for(let k in c)l.properties&&k in l.properties||g.push(k);let y=g.length,w=a||y<=97?1:Math.floor(y/97);for(let k=0;k<y;k+=w){let S=w>1&&k>y-1-w?y-1:k,b=g[S];i.push(b);let _=u(c[b],l.additionalProperties);if(i.pop(),!_)return!1;if(S===y-1)break}}return!0}if(p==="array"&&l.items){let f=c.length;if(l.minItems!==void 0&&f<l.minItems)return o("Array too short");if(l.maxItems!==void 0&&f>l.maxItems)return o("Array too long");if(Array.isArray(l.items)){for(let g=0;g<l.items.length;g++){if(i.push(String(g)),!u(c[g],l.items[g]))return i.pop(),!1;i.pop()}return!0}let d=a||f<=97?1:Math.floor(f/97);for(let g=0;g<f;g+=d){let y=d>1&&g>f-1-d?f-1:g;i.push(String(y));let w=u(c[y],l.items);if(i.pop(),!w)return!1;if(y===f-1)break}return!0}return!0};return u(e,r)}function bi(e,t,n){let r=t?.schema||t,s=typeof n=="function"?n:n?.onError,a=typeof n=="object"?n?.strict??n?.fullScan??!1:!1;if(!(typeof n=="object"&&n?.skipValidation)){let i="",o="";if(!Ne(e,r,{onError:(u,c)=>{i||(i=u,o=c),s&&s(u,c)},fullScan:a}))return Error(`${i}: ${o}`)}return mn(e,r)}function mn(e,t){if(e==null)return e;let n=t.type;if(n==="object"&&t.properties&&typeof e=="object"&&!Array.isArray(e)){let r={};for(let s of Object.keys(t.properties))s in e&&(r[s]=mn(e[s],t.properties[s]));return r}return n==="array"&&Array.isArray(e)&&t.items?Array.isArray(t.items)?e.slice(0,t.items.length).map((r,s)=>mn(r,t.items[s])):e.map(r=>mn(r,t.items)):e}function ht(e){if(e.nullable)return{anyOf:[ht({...e,nullable:!1}),{type:"null"}]};switch(e.kind){case"string":return{type:"string"};case"number":return{type:"number"};case"integer":return{type:"integer"};case"non-negative-integer":return{type:"integer",minimum:0};case"boolean":return{type:"boolean"};case"null":return{type:"null"};case"undefined":return{};case"any":return{};case"array":return e.items?{type:"array",items:ht(e.items)}:{type:"array"};case"object":if(e.shape){let t={},n=[];for(let[r,s]of Object.entries(e.shape))t[r]=ht(s),n.push(r);return{type:"object",properties:t,required:n,additionalProperties:!1}}return{type:"object"};case"union":return e.members?{anyOf:e.members.map(ht)}:{};default:return{}}}function dt(e){if(e===null)return{type:"null"};if(e===void 0)return{};switch(typeof e){case"string":return{type:"string"};case"number":return Number.isInteger(e)?{type:"integer"}:{type:"number"};case"boolean":return{type:"boolean"};case"object":{if(Array.isArray(e))return e.length===0?{type:"array"}:{type:"array",items:dt(e[0])};let t={},n=[];for(let[r,s]of Object.entries(e))t[r]=dt(s),n.push(r);return{type:"object",properties:t,required:n,additionalProperties:!1}}default:return{}}}function rr(e){let t={},n=[];for(let[a,i]of Object.entries(e.params))i?.type?.kind?t[a]=ht(i.type):i?.example!==void 0?t[a]=dt(i.example):t[a]={},i?.required!==!1&&n.push(a),i?.example!==void 0&&(t[a].examples=[i.example]);let r={type:"object",properties:t,required:n},s;return e.returns&&(e.returns.type?.kind?s=ht(e.returns.type):e.returns.example!==void 0&&(s=dt(e.returns.example))),{input:r,output:s}}function Xe(e){return e!==null&&typeof e=="object"&&"__runtimeType"in e&&e.__runtimeType===!0}function xi(e){return e!==null&&typeof e=="object"&&"schema"in e&&typeof e.schema=="object"}function No(e){return e!==null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"}function se(e,t,n,r){let s,a,i,o=n,u=r;if(typeof e=="string")if(s=e,typeof t=="function")a=t,o!==void 0&&(i=ye.infer(o));else if(t===void 0&&o!==void 0)i=ye.infer(o);else if(xi(t))i=t;else if(No(t))i=t;else if(t!==void 0)o=t,u=o,i=ye.infer(o);else throw new Error("Type(description) requires a predicate, schema, or example");else xi(e),i=e,s=Ro(i);let c;if(i){let p=i?.schema??i;p&&typeof p=="object"&&Array.isArray(p.examples)&&(c=p.examples)}return o===void 0&&c&&c.length>0&&(o=c[0]),{description:s,check:p=>a?a(p):i?Ne(p,i):!1,schema:i,predicate:a,example:o,examples:c,default:u,toJSONSchema(){if(i){let p=i?.schema??i;if(p&&typeof p=="object"&&"type"in p)return p}return o!==void 0?dt(o):{description:s}},strip(p){return i?bi(p,i):p},__runtimeType:!0}}function Ro(e){let t=e?.schema??e;if(t&&typeof t=="object"&&"type"in t){let n=t;switch(n.type){case"string":return n.format?`string (${n.format})`:n.pattern?`string matching ${n.pattern}`:n.minLength!==void 0&&n.maxLength!==void 0?`string (${n.minLength}-${n.maxLength} chars)`:"string";case"number":case"integer":return n.minimum!==void 0&&n.maximum!==void 0?`${n.type} (${n.minimum}-${n.maximum})`:n.minimum!==void 0?`${n.type} >= ${n.minimum}`:n.maximum!==void 0?`${n.type} <= ${n.maximum}`:n.type;case"boolean":return"boolean";case"array":return"array";case"object":return"object";case"null":return"null"}}return"value"}var sr=se("string",e=>typeof e=="string"?!0:`expected string, got ${e===null?"null":typeof e}`),ir=se("number",e=>typeof e=="number"?!0:`expected number, got ${e===null?"null":typeof e}`),ar=se("boolean",e=>typeof e=="boolean"?!0:`expected boolean, got ${e===null?"null":typeof e}`),or=se("integer",e=>typeof e!="number"?`expected integer, got ${e===null?"null":typeof e}`:Number.isInteger(e)?!0:`${e} is not an integer`),ur=se("positive integer",e=>typeof e!="number"?`expected positive integer, got ${e===null?"null":typeof e}`:Number.isInteger(e)?e<=0?`${e} is not positive`:!0:`${e} is not an integer`),cr=se("non-empty string",e=>typeof e!="string"?`expected string, got ${e===null?"null":typeof e}`:e.length===0?"string is empty":!0),lr=se("email address",e=>typeof e!="string"?`expected string, got ${e===null?"null":typeof e}`:/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?!0:`"${e}" is not a valid email`),_i=e=>{try{return new URL(e),!0}catch{return!1}},fr=se("URL",e=>typeof e!="string"?`expected string, got ${e===null?"null":typeof e}`:_i(e)?!0:`"${e}" is not a valid URL`),pr=se("UUID",e=>typeof e!="string"?`expected string, got ${e===null?"null":typeof e}`:/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)?!0:`"${e}" is not a valid UUID`),wi=e=>{let t=new Date(e);return!isNaN(t.getTime())&&e.includes("T")},Si=e=>{if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;let t=new Date(e+"T00:00:00Z");return!isNaN(t.getTime())},vi=se("ISO 8601 timestamp",e=>typeof e=="string"&&wi(e)),ki=se("date (YYYY-MM-DD)",e=>typeof e=="string"&&Si(e));function hr(e){return se(`${e.description} or null`,t=>t===null||e.check(t)===!0)}function dr(e){return se(`${e.description} (optional)`,t=>t==null||e.check(t)===!0)}function mr(e,t,...n){if(typeof e=="string"&&Array.isArray(t)){let a=e,i=t,o=new Set(i);return{description:a,check:c=>o.has(c),toJSONSchema:()=>({enum:i}),strip:c=>c,__runtimeType:!0,values:i}}let r=[];Xe(e)&&r.push(e),Xe(t)&&r.push(t),r.push(...n);let s=r.map(a=>a.description).join(" | ");return se(s,a=>r.some(i=>i.check(a)===!0))}function gr(e){return se(`array of ${e.description}`,t=>Array.isArray(t)&&t.every(n=>e.check(n)===!0))}function Mo(e){if(Xe(e))return n=>e.check(n)===!0;if(e&&typeof e=="object"&&"schema"in e)return n=>Ne(n,e);let t=ye.infer(e);return n=>Ne(n,t)}function Ot(e,t,n){let r=[],s=[];for(let i of e)typeof i=="string"?(r.push(i),s.push(void 0)):(r.push(i[0]),s.push(i[1]));let a=(...i)=>{let o=r.map((c,l)=>{let p=l<i.length?i[l]:s[l];return p===void 0?()=>!0:Mo(p)}),u=n;return r.forEach((c,l)=>{let p=l<i.length?i[l]:s[l],f="any";Xe(p)?f=p.description:p!==void 0&&(f=typeof p=="string"?"string":JSON.stringify(p)),u=u.replace(new RegExp(`\\b${c}\\b`,"g"),f)}),se(u,c=>t(c,...o))};return a.params=r,a.description=n,a}var yr=Ot(["T","U"],(e,t,n)=>Array.isArray(e)&&e.length===2&&t(e[0])&&n(e[1]),"Pair<T, U>"),br=Ot(["V"],(e,t)=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.values(e).every(t),"Record<string, V>");function xr(e,t){let n=Object.values(t),r=new Set(n),s=Object.keys(t),a={};for(let[o,u]of Object.entries(t))a[u]=o;return{description:e,check:o=>r.has(o),toJSONSchema:()=>({enum:n}),strip:o=>o,__runtimeType:!0,members:t,names:a,values:n,keys:s}}function Oo(e){if(e===null)return"null";if(e===void 0)return"undefined";switch(typeof e){case"string":return"string";case"boolean":return"boolean";case"number":return Number.isInteger(e)?"integer":"number";case"object":return Array.isArray(e)?"array":"object";default:return null}}function gn(e,t,n){if(Array.isArray(t)&&n){let r=t,s=[],a=[];for(let o of r)Array.isArray(o)?(s.push(o[0]),a.push(o[1])):(s.push(o),a.push(void 0));let i=((...o)=>{let u=s.map((l,p)=>p<o.length?o[p]:a[p]),c=n(...u);return gn(e,c)});return Object.defineProperties(i,{typeParamNames:{value:s,enumerable:!0},description:{value:e,enumerable:!0},__runtimeType:{value:!0,enumerable:!0}}),i}return Bo(e,t)}function Bo(e,t){let n={},r,s="assertReturns";if(typeof t=="function"){let i=t.__tjs;if(i){if(i.params)for(let[o,u]of Object.entries(i.params))n[o]=u?.example??null;i.returns&&(r=i.returns?.example??null),i.safeReturn?s="checkedReturns":i.unsafe?s="assertReturns":s="returns"}}else n=t.params??{},r=t.returns,s=t.returnContract??"assertReturns";return{description:e,params:n,returns:r,returnContract:s,toJSONSchema:()=>({description:e,type:"function"}),strip:i=>i,check:i=>{if(typeof i!="function")return`expected function, got ${i===null?"null":typeof i}`;let o=Object.keys(n).length;if(o>0){let c=i.__tjs;if(c?.params){let l=Object.keys(c.params).length;if(l!==o)return`expected ${o} params, got ${l}`;let p=Object.keys(n),f=Object.keys(c.params);for(let d=0;d<p.length;d++){let g=c.params[f[d]],y=n[p[d]];if(g?.type?.kind&&y!==void 0){let w=Oo(y);if(w&&g.type.kind!==w&&g.type.kind!=="any")return`param '${p[d]}' expected ${w}, got ${g.type.kind}`}}}}return!0},__runtimeType:!0}}var Do=Ei(),Ve=Do.version,Bt=Symbol.for("tjs.equals");function bn(e){let[t=0,n=0,r=0]=e.split(".").map(Number);return{major:t,minor:n,patch:r}}function wr(e,t){let n=bn(e),r=bn(t);return n.major!==r.major?n.major<r.major?-1:1:n.minor!==r.minor?n.minor<r.minor?-1:1:n.patch!==r.patch?n.patch<r.patch?-1:1:0}function Sr(e,t){let n=bn(e),r=bn(t);return n.major===r.major}var He=class e extends Error{path;expected;actual;callStack;reason;constructor(t,n,r,s,a,i){super(t),this.name="MonadicError",this.path=n,this.expected=r,this.actual=s,this.callStack=a,this.reason=i,Error.captureStackTrace&&Error.captureStackTrace(this,e)}};function Lo(e,t,n,r){let s=n===null?"null":typeof n,a=H.callStacks||H.debug?kr():void 0,i=r?`Expected ${t} for '${e}': ${r}`:`Expected ${t} for '${e}', got ${s}`,o=new He(i,e,t,s,a,r);if(H.trackErrors!==!1){let u=H.maxErrors??xn;$i[mt]=o,mt=(mt+1)%u,nt<u&&nt++,_n++}if(H.logTypeErrors&&console.error(`[TJS TypeError] ${o.message}`),H.throwTypeErrors)throw o;return o}function _r(e){return e instanceof Error&&e.name==="MonadicError"&&"path"in e}var vr={debug:!1,safety:"inputs",requireReturnTypes:!1,callStacks:!1,maxStackSize:64,trackErrors:!0,maxErrors:64},H={...vr},Ft=64,Ti=new Array(Ft).fill(""),tt=0,Ue=0,xn=64,$i=new Array(xn).fill(null),mt=0,nt=0,_n=0,bt=0;function Vo(){bt++}function qo(){bt>0&&bt--}function Uo(){return bt>0}function Wo(e){H={...H,...e}}function Jo(){return{...H}}function Ci(e){if((H.callStacks||H.debug)&&e){let t=H.maxStackSize??Ft;Ti[tt]=e,tt=(tt+1)%t,Ue<t&&Ue++}}function yn(){if((H.callStacks||H.debug)&&Ue>0){let e=H.maxStackSize??Ft;tt=(tt-1+e)%e,Ue--}}function kr(){if(Ue===0)return[];let e=H.maxStackSize??Ft,t=[],n=(tt-Ue+e)%e;for(let r=0;r<Ue;r++)t.push(Ti[(n+r)%e]);return t}function Ai(){if(H.trackErrors===!1||nt===0)return[];let e=H.maxErrors??xn,t=[],n=(mt-nt+e)%e;for(let r=0;r<nt;r++)t.push($i[(n+r)%e]);return t}function zo(){let e=Ai();return mt=0,nt=0,_n=0,e}function Go(){return _n}function Ho(){H={...vr},tt=0,Ue=0,mt=0,nt=0,_n=0,bt=0}function gt(e,t){if(e!==null&&typeof e=="object"&&typeof e[Bt]=="function")return e[Bt](t);if(t!==null&&typeof t=="object"&&typeof t[Bt]=="function")return t[Bt](e);if(e!==null&&typeof e=="object"&&typeof e.Equals=="function")return e.Equals(t);if(t!==null&&typeof t=="object"&&typeof t.Equals=="function")return t.Equals(e);if((e instanceof String||e instanceof Number||e instanceof Boolean)&&(e=e.valueOf()),(t instanceof String||t instanceof Number||t instanceof Boolean)&&(t=t.valueOf()),e===t||typeof e=="number"&&typeof t=="number"&&isNaN(e)&&isNaN(t)||e==null&&t==null)return!0;if(e==null||t===null||t===void 0||typeof e!=typeof t||typeof e!="object")return!1;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(let s of e)if(!t.has(s))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(let[s,a]of e)if(!t.has(s)||!gt(a,t.get(s)))return!1;return!0}if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((s,a)=>gt(s,t[a]));if(Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(s=>gt(e[s],t[s]))}function Pi(e,t){return!gt(e,t)}function ji(e){return e===null?"null":typeof e}function Ii(e){return e instanceof Boolean||e instanceof Number||e instanceof String?!!e.valueOf():!!e}function Er(e,t){return(e instanceof String||e instanceof Number||e instanceof Boolean)&&(e=e.valueOf()),(t instanceof String||t instanceof Number||t instanceof Boolean)&&(t=t.valueOf()),!!(e===t||typeof e=="number"&&typeof t=="number"&&isNaN(e)&&isNaN(t)||e==null&&t==null)}function Ni(e,t){return!Er(e,t)}function qe(e){return e!==null&&typeof e=="object"&&e.$error===!0}function Re(e,t){let n={$error:!0,message:e,...t};if((H.callStacks||H.debug)&&Ue>0){let r=kr(),s=t?.path?[...r,t.path]:r;n.stack=s}return n}function Tr(e,t){if(e.length===0)return Re("Unknown error");if(e.length===1)return e[0];let n=e.map(s=>{if(s.path){let a=s.path.split(".");return a[a.length-1]}return"unknown"}).join(", "),r=`Multiple parameter errors in ${t||"function"}: ${n}`;return Re(r,{path:t,errors:e})}function yt(e){if(e===null)return"null";if(e===void 0)return"undefined";if(Array.isArray(e))return"array";let t=typeof e;if(t!=="object")return t;let n=e.constructor?.name;return n&&n!=="Object"?n:"object"}function Ri(e,t){if(e==null||typeof e!="object"&&typeof e!="function")return!1;let n=e;for(;n!==null;){if(n.constructor?.name===t)return!0;n=Object.getPrototypeOf(n)}return!1}function rt(e,t,n){if(qe(e))return e;if(typeof t=="object"&&t!==null&&"check"in t){let s=t.check(e);if(s===!0)return null;let a=typeof s=="string"?s:void 0,i=a?`Expected ${t.description} for '${n}': ${a}`:`Expected ${t.description} but got ${yt(e)}`;return Re(i,{path:n,expected:t.description,actual:yt(e),reason:a})}let r=yt(e);return t==="any"||t===r||t==="number"&&r==="number"||t==="integer"&&r==="number"&&Number.isInteger(e)||t==="non-negative-integer"&&r==="number"&&Number.isInteger(e)&&e>=0||t==="object"&&r==="object"?null:Re(`Expected ${t} but got ${r}`,{path:n,expected:t,actual:r})}function Mi(e,t,n,r){if(typeof e!="function")return e;let s=e.__tjs;if(!s||!s.params)return e;let a=Object.entries(s.params);for(let i=0;i<t.length;i++){let o=t[i];if(o==="any")continue;let u=a[i];if(!u)continue;let c=u[1]?.type?.kind;if(!(!c||c==="any")&&c!==o)return new He(`Expected (...arg${i}: ${o}, ...) for '${r}', but callback declares arg${i} as ${c}`,`${r}(arg${i})`,o,c)}if(n!=="any"&&s.returns){let i=s.returns.type?.kind??s.returns.kind;if(i&&i!=="any"&&i!==n)return new He(`Expected callback returning ${n} for '${r}', but callback returns ${i}`,`${r}(return)`,n,i)}return e}function $r(e,t,n){for(let[r,s]of Object.entries(t.params)){let a=e[r];if(qe(a))return a;if(s.required&&a===void 0){let o=typeof s.type=="string"?s.type:s.type.description;return Re(`Missing required parameter '${r}'`,{path:n?`${n}.${r}`:r,expected:o,actual:"undefined",loc:s.loc})}if(a===void 0)continue;let i=rt(a,s.type,n?`${n}.${r}`:r);if(i)return s.loc&&(i.loc=s.loc),i}return null}function Cr(e,t){if(e.__tjs=t,e.__tjs.schema=()=>rr(t),!(!t.polymorphic&&(t.safe||t.safeReturn||H.safety!=="none"&&!t.unsafe||t.returns&&H.safety==="all"&&!t.unsafeReturn)))return e;let r=!!t.returns,s=!!t.unsafe,a=!!t.safe,i=!!t.unsafeReturn,o=!!t.safeReturn,u=t.returns?.defaults,c=Object.entries(t.params),l=c.length,p=e.name||t.name||"anonymous",f=function(...d){if(bt>0)return e.apply(this,d);let g=a||!s&&H.safety!=="none",y=r&&(o||!i&&H.safety==="all");if(!g&&!y)return e.apply(this,d);if(d.length>0&&qe(d[0]))return d[0];if(g){let k=d.length===1&&typeof d[0]=="object"&&d[0]!==null&&!Array.isArray(d[0]),S=[];if(k){let b=d[0];for(let _=0;_<l;_++){let[v,x]=c[_],E=b[v];if(qe(E)){S.push(E);continue}if(x.required&&E===void 0){S.push(Re(`Missing required parameter '${v}'`,{path:`${p}.${v}`,expected:typeof x.type=="string"?x.type:x.type?.description||"value",actual:"undefined",loc:x.loc}));continue}if(E!==void 0){let $=rt(E,x.type,`${p}.${v}`);$&&(x.loc&&($.loc=x.loc),S.push($))}}}else for(let b=0;b<l;b++){let[_,v]=c[b],x=d[b];if(qe(x)){S.push(x);continue}if(v.required&&x===void 0){S.push(Re(`Missing required parameter '${_}'`,{path:`${p}.${_}`,expected:typeof v.type=="string"?v.type:v.type?.description||"value",actual:"undefined",loc:v.loc}));continue}if(x!==void 0){let E=rt(x,v.type,`${p}.${_}`);E&&(v.loc&&(E.loc=v.loc),S.push(E))}}if(S.length>0)return Tr(S,p)}let w=H.callStacks||H.debug;w&&Ci(p);try{let k=e.apply(this,d);if(y&&t.returns&&!qe(k)){let S=u&&typeof k=="object"&&k!==null?Object.assign({},u,k):k,b=rt(S,t.returns.type,`${p}()`);if(b)return w&&yn(),b}return w&&yn(),k}catch(k){return w&&yn(),Re(k.message||String(k),{path:p,cause:k})}};return Object.defineProperty(f,"name",{value:e.name}),f.__tjs=t,f.__tjs.schema=()=>rr(t),f}function Oi(e){let t=new Proxy(e,{construct(n,r,s){return Reflect.construct(n,r,s)},apply(n,r,s){return Reflect.construct(n,s)}});Object.defineProperty(t,"name",{value:e.name});for(let n of Object.getOwnPropertyNames(e))n!=="length"&&n!=="name"&&n!=="prototype"&&Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n));return t}function Bi(){let e={...H},t=e.maxStackSize??Ft,n=new Array(t).fill(""),r=0,s=0,a=e.maxErrors??xn,i=new Array(a).fill(null),o=0,u=0,c=0,l=0;function p(N){e={...e,...N}}function f(){return{...e}}function d(N){(e.callStacks||e.debug)&&N&&(n[r]=N,r=(r+1)%t,s<t&&s++)}function g(){(e.callStacks||e.debug)&&s>0&&(r=(r-1+t)%t,s--)}function y(){if(s===0)return[];let N=[],U=(r-s+t)%t;for(let J=0;J<s;J++)N.push(n[(U+J)%t]);return N}function w(){e={...vr},r=0,s=0,o=0,u=0,c=0,l=0}function k(){l++}function S(){l>0&&l--}function b(){return l>0}let _=new Map;function v(N,U,J){_.has(N)||_.set(N,new Map),_.get(N).set(U,J)}function x(N,U){let J=typeof N,X;if(N==null)return;if(J==="string")X="String";else if(J==="number")X="Number";else if(J==="boolean")X="Boolean";else if(Array.isArray(N))X="Array";else if(J==="object")X=N.constructor?.name||"Object";else return;let ee=X;for(;ee;){let ot=_.get(ee);if(ot?.has(U))return ot.get(U);if(J==="object"&&!Array.isArray(N)){if(ee=Object.getPrototypeOf(ee===X?N:Object.getPrototypeOf(N))?.constructor?.name,ee==="Object"||ee===X)break}else break}let ce=_.get("Object");if(ce?.has(U))return ce.get(U)}function E(N,U,J){let X=J===null?"null":typeof J,ee=e.callStacks||e.debug?y():void 0,ce=new He(`Expected ${U} for '${N}', got ${X}`,N,U,X,ee);if(e.trackErrors!==!1&&(i[o]=ce,o=(o+1)%a,u<a&&u++,c++),e.logTypeErrors&&console.error(`[TJS TypeError] ${ce.message}`),e.throwTypeErrors)throw ce;return ce}function $(){if(e.trackErrors===!1||u===0)return[];let N=[],U=(o-u+a)%a;for(let J=0;J<u;J++)N.push(i[(U+J)%a]);return N}function C(){let N=$();return o=0,u=0,c=0,N}function I(){return c}function M(N,U){let J={$error:!0,message:N,...U};if((e.callStacks||e.debug)&&s>0){let X=U?.path?[...y(),U.path]:y();J.stack=X}return J}function F(N,U){return N==null?E(`bang.${U}`,"non-null",N):_r(N)?N:N[U]}return{version:Ve,MonadicError:He,typeError:E,isMonadicError:_r,bang:F,isError:qe,error:M,composeErrors:Tr,typeOf:yt,isNativeType:Ri,checkType:rt,validateArgs:$r,wrap:Cr,checkFnShape:Mi,wrapClass:Oi,compareVersions:wr,versionsCompatible:Sr,createRuntime:Bi,configure:p,getConfig:f,pushStack:d,popStack:g,getStack:y,errors:$,clearErrors:C,getErrorCount:I,resetRuntime:w,enterUnsafe:k,exitUnsafe:S,isUnsafeMode:b,validate:Ne,infer:ye.infer.bind(ye),Type:se,isRuntimeType:Xe,Union:mr,Generic:Ot,Enum:xr,FunctionPredicate:gn,Nullable:hr,Optional:dr,TArray:gr,TString:sr,TNumber:ir,TBoolean:ar,TInteger:or,TPositiveInt:ur,TNonEmptyString:cr,TEmail:lr,TUrl:fr,TUuid:pr,TPair:yr,TRecord:br,Is:gt,IsNot:Pi,Eq:Er,NotEq:Ni,TypeOf:ji,toBool:Ii,tjsEquals:Bt,registerExtension:v,resolveExtension:x}}var et={version:Ve,MonadicError:He,typeError:Lo,isMonadicError:_r,isError:qe,error:Re,composeErrors:Tr,typeOf:yt,isNativeType:Ri,checkType:rt,validateArgs:$r,wrap:Cr,checkFnShape:Mi,wrapClass:Oi,compareVersions:wr,versionsCompatible:Sr,configure:Wo,getConfig:Jo,pushStack:Ci,popStack:yn,getStack:kr,errors:Ai,clearErrors:zo,getErrorCount:Go,resetRuntime:Ho,enterUnsafe:Vo,exitUnsafe:qo,isUnsafeMode:Uo,createRuntime:Bi,validate:Ne,infer:ye.infer.bind(ye),Type:se,isRuntimeType:Xe,Union:mr,Generic:Ot,Enum:xr,FunctionPredicate:gn,Nullable:hr,Optional:dr,TArray:gr,TString:sr,TNumber:ir,TBoolean:ar,TInteger:or,TPositiveInt:ur,TNonEmptyString:cr,TEmail:lr,TUrl:fr,TUuid:pr,Timestamp:vi,LegalDate:ki,TPair:yr,TRecord:br,Is:gt,IsNot:Pi,Eq:Er,NotEq:Ni,TypeOf:ji,toBool:Ii};function Ar(){let e=globalThis;if(e.__tjs){let t=e.__tjs.version;if(typeof t!="string")return e.__tjs=et,et;let n=wr(Ve,t);return n===0||(Sr(Ve,t)?n>0?(console.info(`TJS runtime: upgrading ${t} \u2192 ${Ve}`),e.__tjs=et):console.info(`TJS runtime: keeping ${t} (newer than ${Ve})`):(console.warn(`TJS runtime version conflict: ${t} vs ${Ve} (major version mismatch)`),n>0&&(console.warn(`Upgrading to ${Ve} - check for breaking changes`),e.__tjs=et))),e.__tjs}return e.__tjs=et,et}function Ko(e){return`
|
|
186
|
+
// TJS runtime wrapper (skips unsafe functions)
|
|
187
|
+
if (typeof ${e}.__tjs === 'object' && !${e}.__tjs.unsafe && typeof globalThis.__tjs?.wrap === 'function') {
|
|
188
|
+
${e} = globalThis.__tjs.wrap(${e}, ${e}.__tjs)
|
|
189
|
+
}
|
|
190
|
+
`.trim()}function Zo(e,t,n=1e-9){if(e===t)return!0;if(typeof e=="number"&&typeof t=="number"&&(!Number.isInteger(e)||!Number.isInteger(t))){let r=Math.abs(e-t),s=Math.max(Math.abs(e),Math.abs(t),1);return r/s<n}return!1}function jr(e,t){if(e===t||typeof e=="number"&&typeof t=="number"&&Number.isNaN(e)&&Number.isNaN(t)||Zo(e,t))return!0;if(e===null||t===null||e===void 0||t===void 0)return e===t;if(typeof e!=typeof t||typeof e!="object")return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((s,a)=>jr(s,t[a]));if(Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(s=>jr(e[s],t[s]))}function Ir(e,t,n=""){if(t===null)return e===null?{matches:!0}:{matches:!1,error:`Expected null at '${n}', got ${st(e)}`};if(t===void 0)return e===void 0?{matches:!0}:{matches:!1,error:`Expected undefined at '${n}', got ${st(e)}`};if(typeof t=="number")return typeof e=="number"?{matches:!0}:{matches:!1,error:`Expected number at '${n}', got ${st(e)}`};if(typeof t=="string")return typeof e=="string"?{matches:!0}:{matches:!1,error:`Expected string at '${n}', got ${st(e)}`};if(typeof t=="boolean")return typeof e=="boolean"?{matches:!0}:{matches:!1,error:`Expected boolean at '${n}', got ${st(e)}`};if(Array.isArray(t)){if(!Array.isArray(e))return{matches:!1,error:`Expected array at '${n}', got ${st(e)}`};if(t.length===0)return{matches:!0};let r=t[0];for(let s=0;s<e.length;s++){let a=Ir(e[s],r,`${n}[${s}]`);if(!a.matches)return a}return{matches:!0}}if(typeof t=="object"&&t!==null){if(typeof e!="object"||e===null||Array.isArray(e))return{matches:!1,error:`Expected object at '${n}', got ${st(e)}`};for(let r of Object.keys(t)){let s=n?`${n}.${r}`:r;if(!(r in e))return{matches:!1,error:`Missing property '${s}'`};let a=Ir(e[r],t[r],s);if(!a.matches)return a}return{matches:!0}}return e===t?{matches:!0}:{matches:!1,error:`Type mismatch at '${n}'`}}function st(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?"array":typeof e}function Dt(e,t=0){if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="string")return JSON.stringify(e);if(typeof e=="number"||typeof e=="boolean")return String(e);if(Array.isArray(e))return e.length===0?"[]":e.length<=3?`[${e.map(n=>Dt(n,t)).join(", ")}]`:`[${e.slice(0,3).map(n=>Dt(n,t)).join(", ")}, ...]`;if(typeof e=="object"){let n=Object.entries(e);if(n.length===0)return"{}";let r=u=>/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(u)?u:JSON.stringify(u);if(n.length<=2)return`{${n.map(([c,l])=>`${r(c)}: ${Dt(l,t)}`).join(", ")}}`;let s=" ".repeat(t+1),a=" ".repeat(t),i=n.slice(0,8).map(([u,c])=>`${s}${r(u)}: ${Dt(c,t+1)}`).join(`,
|
|
191
|
+
`),o=n.length>8?`,
|
|
192
|
+
${s}...`:"";return`{
|
|
193
|
+
${i}${o}
|
|
194
|
+
${a}}`}return String(e)}function Qo(e){let t=e.replace(/\/\*[\s\S]*?\*\//g,n=>{let r=n.split(`
|
|
195
|
+
`).length-1;return`
|
|
196
|
+
`.repeat(r)});return t=t.replace(/\/\/[^\n]*/g,""),t}function Di(e){let t=e.replace(/^import\s+.*?from\s+['"][^'"]+['"];?\s*$/gm,"");return t=t.replace(/^import\s+['"][^'"]+['"];?\s*$/gm,""),t=t.replace(/^export\s+default\s+/gm,""),t=t.replace(/^export\s+/gm,""),t=t.replace(/^(\s*)((?:const|let|var)\s+\w+\s*=\s*)?await\s+.+$/gm,"$1/* top-level await removed for test execution */"),t}function Yo(e){if(Object.keys(e).length===0)return"";let t=[];for(let[n,r]of Object.entries(e)){let s=Di(r);t.push(`// Resolved import: ${n}`),t.push(s)}return t.join(`
|
|
197
|
+
`)}function Fi(e){let t={},n=e.trim();if(!n.startsWith("{")||!n.includes("="))try{return{pattern:new Function(`return ${e}`)(),defaults:t}}catch{return null}let r="",s=0,a=0;for(;a<n.length;){let i=n[a];if(i==="{"||i==="["||i==="(")s++,r+=i,a++;else if(i==="}"||i==="]"||i===")")s--,r+=i,a++;else if(i==="'"||i==='"'||i==="`"){let o=i;for(r+=i,a++;a<n.length&&n[a]!==o;)n[a]==="\\"&&(r+=n[a++]),r+=n[a++];a<n.length&&(r+=n[a++])}else if(s===1&&i==="="){let c=(r.slice(r.lastIndexOf("{")+1).split(",").pop()||"").match(/\s*(\w+)\s*$/);if(c){let l=a+1;for(;l<n.length&&/\s/.test(n[l]);)l++;let p="",f=0;for(;l<n.length;){let d=n[l];if(d==="{"||d==="["||d==="(")f++;else if(d==="}"||d==="]"||d===")"){if(f===0)break;f--}else if(d===","&&f===0)break;p+=d,l++}try{t[c[1]]=new Function(`return ${p.trim()}`)()}catch{}r+=":",a++;continue}r+=i,a++}else r+=i,a++}try{return{pattern:new Function(`return ${r}`)(),defaults:t}}catch{return null}}function Li(e){let t=[],n=Qo(e),r=/(async\s+)?function\s+(\w+)\s*\(([^)]*)\)\s*(:[?!]?)\s*/g,s;for(;(s=r.exec(n))!==null;){let o=!!s[1],u=s[2],c=s[3],l=s[4],p=n.slice(0,s.index).split(`
|
|
198
|
+
`).length;if(l===":!")continue;let f=n.slice(s.index+s[0].length),d=wn(f);if(!d)continue;let g=Pr(c);if(!(c.trim()&&g.length===0))try{let y=Fi(d);if(!y)continue;let w=g.map(k=>new Function(`return ${k}`)());t.push({funcName:u,args:w,expected:y.pattern,defaults:Object.keys(y.defaults).length>0?y.defaults:void 0,line:p,isAsync:o})}catch{}}let a=/class\s+(\w+)(?:\s+extends\s+\w+)?\s*\{/g,i;for(;(i=a.exec(n))!==null;){let o=i[1],u=i.index+i[0].length,c=1,l=u;for(let b=u;b<n.length;b++)if(n[b]==="{")c++;else if(n[b]==="}"&&(c--,c===0)){l=b;break}let p=n.slice(u,l),d=/constructor\s*\(([^)]*)\)/.exec(p);if(!d)continue;let g=d[1],y=Pr(g);if(g.trim()&&y.length===0)continue;let w;try{w=y.map(b=>new Function(`return ${b}`)())}catch{continue}let k=/(async\s+)?(\w+)\s*\(([^)]*)\)\s*(:[?!]?)\s*/g,S;for(;(S=k.exec(p))!==null;){let b=S[2];if(b==="constructor")continue;let _=!!S[1],v=S[3];if(S[4]===":!")continue;let E=u+S.index,$=n.slice(0,E).split(`
|
|
199
|
+
`).length,C=p.slice(S.index+S[0].length),I=wn(C);if(!I)continue;let M=Pr(v);if(!(v.trim()&&M.length===0))try{let F=Fi(I);if(!F)continue;let N=M.map(U=>new Function(`return ${U}`)());t.push({funcName:b,args:N,expected:F.pattern,defaults:Object.keys(F.defaults).length>0?F.defaults:void 0,line:$,isAsync:_,className:o,constructorArgs:w})}catch{}}}return t}function Vi(e,t,n,r,s={},a=new Map){let i=[];if(e.length===0&&n.length===0)return i;let o=r.match(/^import\s+.*?from\s+['"]([^'"]+)['"];?\s*$/gm)||[],u=o.length>0&&o.some(_=>{let v=_.match(/from\s+['"]([^'"]+)['"]/);return v&&!(v[1]in s)}),c=Di(r),l=Yo(s),p=t.map(_=>_.body).join(`
|
|
200
|
+
`),f="const { Is, IsNot, Eq, NotEq, TypeOf } = globalThis.__tjs ?? {};",d=e.map((_,v)=>{let x=a.size>0?jt(_.body,a):_.body;return`
|
|
201
|
+
// Test ${v}: ${_.description}
|
|
202
|
+
try {
|
|
203
|
+
${f}
|
|
204
|
+
${x}
|
|
205
|
+
__testResults.push({ idx: ${v}, passed: true });
|
|
206
|
+
} catch (e) {
|
|
207
|
+
__testResults.push({ idx: ${v}, passed: false, isRef: e instanceof ReferenceError, error: e.message || String(e) });
|
|
208
|
+
}
|
|
209
|
+
`}).join(`
|
|
210
|
+
`),g=n.filter(_=>!_.isAsync),y=n.filter(_=>_.isAsync),w=g.map((_,v)=>{let x=_.className?`${_.className}.${_.funcName}`:_.funcName,E=_.className?`new ${_.className}(${(_.constructorArgs||[]).map($=>JSON.stringify($)).join(", ")}).${_.funcName}(${_.args.map($=>JSON.stringify($)).join(", ")})`:`${_.funcName}(${_.args.map($=>JSON.stringify($)).join(", ")})`;return`
|
|
211
|
+
// Signature test ${v}: ${x}
|
|
212
|
+
try {
|
|
213
|
+
let __actual = ${E};
|
|
214
|
+
const __expected = ${JSON.stringify(_.expected)};${_.defaults?`
|
|
215
|
+
const __defaults = ${JSON.stringify(_.defaults)};
|
|
216
|
+
if (typeof __actual === 'object' && __actual !== null) __actual = Object.assign({}, __defaults, __actual);`:""}
|
|
217
|
+
if (__deepEqual(__actual, __expected)) {
|
|
218
|
+
__sigTestResults.push({ idx: ${v}, passed: true });
|
|
219
|
+
} else {
|
|
220
|
+
__sigTestResults.push({ idx: ${v}, passed: false, error: 'Expected ' + __format(__expected) + ' at \\'${x}\\', got ' + __format(__actual) });
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {
|
|
223
|
+
// The function threw on its example inputs \u2014 the example couldn't be
|
|
224
|
+
// *evaluated* (e.g. it calls an atom that doesn't exist at build time).
|
|
225
|
+
// That's inconclusive, not a mismatch. Never block transpilation on it.
|
|
226
|
+
__sigTestResults.push({ idx: ${v}, passed: false, threw: true, error: e.message || String(e) });
|
|
227
|
+
}
|
|
228
|
+
`}).join(`
|
|
229
|
+
`);Ar();let b=`
|
|
230
|
+
|
|
231
|
+
const __saved_tjs = globalThis.__tjs;
|
|
232
|
+
|
|
233
|
+
const __testResults = [];
|
|
234
|
+
const __sigTestResults = [];
|
|
235
|
+
try {
|
|
236
|
+
// Test assertions
|
|
237
|
+
function assert(condition, message) {
|
|
238
|
+
if (!condition) throw new Error(message || 'Assertion failed')
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function expect(actual) {
|
|
242
|
+
return {
|
|
243
|
+
toBe(expected) {
|
|
244
|
+
if (!__deepEqual(actual, expected)) {
|
|
245
|
+
throw new Error('Expected ' + __format(expected) + ' but got ' + __format(actual))
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
toEqual(expected) {
|
|
249
|
+
if (!__deepEqual(actual, expected)) {
|
|
250
|
+
throw new Error('Expected ' + __format(expected) + ' but got ' + __format(actual))
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
toContain(item) {
|
|
254
|
+
if (!Array.isArray(actual) || !actual.some(function(v) { return __deepEqual(v, item) })) {
|
|
255
|
+
throw new Error('Expected ' + __format(actual) + ' to contain ' + __format(item))
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
toBeTruthy() {
|
|
259
|
+
if (!actual) {
|
|
260
|
+
throw new Error('Expected ' + __format(actual) + ' to be truthy')
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
toBeFalsy() {
|
|
264
|
+
if (actual) {
|
|
265
|
+
throw new Error('Expected ' + __format(actual) + ' to be falsy')
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
toBeNull() {
|
|
269
|
+
if (actual !== null) {
|
|
270
|
+
throw new Error('Expected null but got ' + __format(actual))
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
toBeUndefined() {
|
|
274
|
+
if (actual !== undefined) {
|
|
275
|
+
throw new Error('Expected undefined but got ' + __format(actual))
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
toBeGreaterThan(n) {
|
|
279
|
+
if (!(actual > n)) {
|
|
280
|
+
throw new Error('Expected ' + __format(actual) + ' to be greater than ' + n)
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
toBeLessThan(n) {
|
|
284
|
+
if (!(actual < n)) {
|
|
285
|
+
throw new Error('Expected ' + __format(actual) + ' to be less than ' + n)
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
toBeNaN() {
|
|
289
|
+
if (typeof actual !== 'number' || !Number.isNaN(actual)) {
|
|
290
|
+
throw new Error('Expected NaN but got ' + __format(actual))
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Inject resolved imports first (they may be dependencies)
|
|
297
|
+
${l}
|
|
298
|
+
|
|
299
|
+
// Execute the module code ONCE
|
|
300
|
+
${c}
|
|
301
|
+
${p}
|
|
302
|
+
|
|
303
|
+
// Run explicit test blocks
|
|
304
|
+
${d}
|
|
305
|
+
|
|
306
|
+
// Run signature tests
|
|
307
|
+
${w}
|
|
308
|
+
|
|
309
|
+
} finally {
|
|
310
|
+
globalThis.__tjs = __saved_tjs;
|
|
311
|
+
}
|
|
312
|
+
return { testResults: __testResults, sigTestResults: __sigTestResults };
|
|
313
|
+
`;try{let _=new Function("__deepEqual","__format","__typeMatches",b),{testResults:v,sigTestResults:x}=_(jr,Dt,Ir);for(let E of v){let $=e[E.idx],C=!E.passed&&(E.isRef||u&&E.error&&/is not defined$/.test(E.error));i.push({description:$.description,passed:E.passed,inconclusive:C||void 0,error:E.error,line:$.line})}for(let E of x){let $=g[E.idx],C=!E.passed&&(E.threw||u&&E.error&&/is not defined$/.test(E.error)),I=$.className?`${$.className}.${$.funcName}`:$.funcName;i.push({description:`${I} signature example`,passed:E.passed,inconclusive:C||void 0,error:E.error,isSignatureTest:!0,line:$.line})}}catch(_){let v=`Module could not be executed for testing: ${_.message}`;for(let x of e)i.push({description:x.description,passed:!1,inconclusive:!0,error:v});for(let x of g){let E=x.className?`${x.className}.${x.funcName}`:x.funcName;i.push({description:`${E} signature example`,passed:!1,inconclusive:!0,error:v,isSignatureTest:!0})}}for(let _ of y){let v=_.className?`${_.className}.${_.funcName}`:_.funcName;i.push({description:`${v} signature example`,passed:!0,isSignatureTest:!0,line:_.line})}return i}function wn(e){let t="",n=0,r=!1;for(let a=0;a<e.length;a++){let i=e[a];if(i==="{"||i==="["||i==="("){if(i==="{"&&n===0&&r)break;n++,t+=i,r=!0}else i==="}"||i==="]"||i===")"?(n--,t+=i):/\s/.test(i)?t+=i:(t+=i,r=!0)}return t.trim()||null}function Pr(e){if(!e.trim())return[];let t=[],n=Xo(e);for(let r of n){let s=r.trim(),a=s.match(/^\.\.\.(\w+)\s*[:=]\s*(\[.+\])$/);if(a){try{let o=new Function(`return ${a[2]}`)();if(Array.isArray(o))for(let u of o)t.push(JSON.stringify(u))}catch{}continue}if(s.startsWith("..."))continue;let i=s.match(/(?:\(\s*[?!]\s*)?(\w+)\s*[:=]\s*(.+?)(?:\))?$/);if(i)t.push(i[2].trim());else return[]}return t}function Xo(e){let t=[],n="",r=0;for(let s of e){if(s==="("||s==="["||s==="{")r++;else if(s===")"||s==="]"||s==="}")r--;else if(s===","&&r===0){t.push(n.trim()),n="";continue}n+=s}return n.trim()&&t.push(n.trim()),t}var Te={i32:127,i64:126,f32:125,f64:124,v128:123,funcref:112,externref:111,void:64},Lt={custom:0,type:1,import:2,function:3,table:4,memory:5,global:6,export:7,start:8,element:9,code:10,data:11},m={unreachable:0,nop:1,block:2,loop:3,if:4,else:5,end:11,br:12,br_if:13,br_table:14,return:15,call:16,call_indirect:17,drop:26,select:27,local_get:32,local_set:33,local_tee:34,global_get:35,global_set:36,i32_load:40,i64_load:41,f32_load:42,f64_load:43,i32_load8_s:44,i32_load8_u:45,i32_load16_s:46,i32_load16_u:47,i32_store:54,i64_store:55,f32_store:56,f64_store:57,i32_store8:58,i32_store16:59,memory_size:63,memory_grow:64,i32_const:65,i64_const:66,f32_const:67,f64_const:68,i32_eqz:69,i32_eq:70,i32_ne:71,i32_lt_s:72,i32_lt_u:73,i32_gt_s:74,i32_gt_u:75,i32_le_s:76,i32_le_u:77,i32_ge_s:78,i32_ge_u:79,i64_eqz:80,i64_eq:81,i64_ne:82,i64_lt_s:83,i64_lt_u:84,i64_gt_s:85,i64_gt_u:86,i64_le_s:87,i64_le_u:88,i64_ge_s:89,i64_ge_u:90,f32_eq:91,f32_ne:92,f32_lt:93,f32_gt:94,f32_le:95,f32_ge:96,f64_eq:97,f64_ne:98,f64_lt:99,f64_gt:100,f64_le:101,f64_ge:102,i32_clz:103,i32_ctz:104,i32_popcnt:105,i32_add:106,i32_sub:107,i32_mul:108,i32_div_s:109,i32_div_u:110,i32_rem_s:111,i32_rem_u:112,i32_and:113,i32_or:114,i32_xor:115,i32_shl:116,i32_shr_s:117,i32_shr_u:118,i32_rotl:119,i32_rotr:120,i64_add:124,i64_sub:125,i64_mul:126,i64_div_s:127,f32_abs:139,f32_neg:140,f32_ceil:141,f32_floor:142,f32_trunc:143,f32_nearest:144,f32_sqrt:145,f32_add:146,f32_sub:147,f32_mul:148,f32_div:149,f32_min:150,f32_max:151,f32_copysign:152,f64_abs:153,f64_neg:154,f64_ceil:155,f64_floor:156,f64_trunc:157,f64_nearest:158,f64_sqrt:159,f64_add:160,f64_sub:161,f64_mul:162,f64_div:163,f64_min:164,f64_max:165,f64_copysign:166,i32_wrap_i64:167,i32_trunc_f32_s:168,i32_trunc_f32_u:169,i32_trunc_f64_s:170,i32_trunc_f64_u:171,i64_extend_i32_s:172,i64_extend_i32_u:173,f32_convert_i32_s:178,f32_convert_i32_u:179,f32_convert_i64_s:180,f32_demote_f64:182,f64_convert_i32_s:183,f64_convert_i32_u:184,f64_convert_i64_s:185,f64_promote_f32:187,i32_reinterpret_f32:188,f32_reinterpret_i32:190,f64_reinterpret_i64:191,i32_extend8_s:192,i32_extend16_s:193},eu=Object.fromEntries(Object.entries(m).map(([e,t])=>[t,e.replace(/_/g,".")])),qt=253,ae={v128_load:0,v128_store:11,v128_const:12,f32x4_splat:19,f32x4_extract_lane:31,f32x4_replace_lane:32,f32x4_neg:225,f32x4_sqrt:227,f32x4_add:228,f32x4_sub:229,f32x4_mul:230,f32x4_div:231},tu=Object.fromEntries(Object.entries(ae).map(([e,t])=>[t,e.replace(/_/g,".")]));function Nr(e){return[qt,...B(e)]}function qi(e,t,n){return[qt,...B(e),...B(t),...B(n)]}function B(e){let t=[];do{let n=e&127;e>>>=7,e!==0&&(n|=128),t.push(n)}while(e!==0);return t}function Ut(e){let t=[],n=!0;for(;n;){let r=e&127;e>>=7,e===0&&(r&64)===0||e===-1&&(r&64)!==0?n=!1:r|=128,t.push(r)}return t}function Rr(e){let t=new ArrayBuffer(4);return new Float32Array(t)[0]=e,[...new Uint8Array(t)]}function ge(e){let t=new ArrayBuffer(8);return new Float64Array(t)[0]=e,[...new Uint8Array(t)]}function Mr(e){let t=new TextEncoder().encode(e);return[...B(t.length),...t]}function Vt(e,t){return[e,...B(t.length),...t]}function Ke(e,t){let n=0,r=0,s=t;for(;s<e.length;){let a=e[s];if(n|=(a&127)<<r,s++,(a&128)===0)break;r+=7}return[n,s-t]}function nu(e,t){let n=new ArrayBuffer(8),r=new Uint8Array(n);for(let s=0;s<8;s++)r[s]=e[t+s];return new Float64Array(n)[0]}function ru(e,t,n){let r=[],s=1,a=()=>" ".repeat(s),i=t.map((c,l)=>`(param $${c.name} ${c.type})`).join(" "),o=n.map((c,l)=>`(local $L${t.length+l} ${c})`).join(" ");r.push(`(func (export "compute") ${i} (result f64)`),o&&r.push(` ${o}`);let u=0;for(;u<e.length;){let c=e[u],l=eu[c]||`unknown(0x${c.toString(16)})`;if(u++,c===m.local_get||c===m.local_set||c===m.local_tee){let[p,f]=Ke(e,u);u+=f;let d=p<t.length?`$${t[p].name}`:`$L${p}`;r.push(`${a()}${l} ${d}`)}else if(c===m.br||c===m.br_if){let[p,f]=Ke(e,u);u+=f,r.push(`${a()}${l} ${p}`)}else if(c===m.i32_const){let[p,f]=Ke(e,u);u+=f,r.push(`${a()}i32.const ${p}`)}else if(c===m.f32_const){let p=new ArrayBuffer(4),f=new Uint8Array(p);for(let g=0;g<4;g++)f[g]=e[u+g];let d=new Float32Array(p)[0];u+=4,r.push(`${a()}f32.const ${d}`)}else if(c===m.f64_const){let p=nu(e,u);u+=8,r.push(`${a()}f64.const ${p}`)}else if(c===m.block||c===m.loop){let p=e[u];u++,r.push(`${a()}${l}${p===Te.void?"":` (result ${p===Te.f64?"f64":"i32"})`}`),s++}else if(c===m.if){let p=e[u];u++,r.push(`${a()}if${p===Te.void?"":` (result ${p===Te.f64?"f64":"i32"})`}`),s++}else if(c===m.else)s--,r.push(`${a()}else`),s++;else if(c===m.end)s=Math.max(1,s-1),r.push(`${a()}end`);else if(c===m.f64_load||c===m.f64_store||c===m.f32_load||c===m.f32_store||c===m.i32_load||c===m.i32_store){let[p,f]=Ke(e,u);u+=f;let[d,g]=Ke(e,u);u+=g,r.push(`${a()}${l}${d?` offset=${d}`:""}`)}else if(c===qt){let[p,f]=Ke(e,u);u+=f;let d=tu[p]||`simd.unknown(0x${p.toString(16)})`;if(p===ae.v128_load||p===ae.v128_store){let[g,y]=Ke(e,u);u+=y;let[w,k]=Ke(e,u);u+=k,r.push(`${a()}${d}${w?` offset=${w}`:""}`)}else if(p===ae.v128_const){let g=e.slice(u,u+16);u+=16,r.push(`${a()}v128.const ${g.map(y=>"0x"+y.toString(16).padStart(2,"0")).join(" ")}`)}else if(p===ae.f32x4_extract_lane||p===ae.f32x4_replace_lane){let g=e[u];u++,r.push(`${a()}${d} ${g}`)}else r.push(`${a()}${d}`)}else r.push(`${a()}${l}`)}return r.push(")"),r.join(`
|
|
314
|
+
`)}var vn={Int8Array:{elementType:"i32",bytesPerElement:1,loadOp:m.i32_load8_s,storeOp:m.i32_store8},Uint8Array:{elementType:"i32",bytesPerElement:1,loadOp:m.i32_load8_u,storeOp:m.i32_store8},Uint8ClampedArray:{elementType:"i32",bytesPerElement:1,loadOp:m.i32_load8_u,storeOp:m.i32_store8},Int16Array:{elementType:"i32",bytesPerElement:2,loadOp:m.i32_load16_s,storeOp:m.i32_store16},Uint16Array:{elementType:"i32",bytesPerElement:2,loadOp:m.i32_load16_u,storeOp:m.i32_store16},Int32Array:{elementType:"i32",bytesPerElement:4,loadOp:m.i32_load,storeOp:m.i32_store},Uint32Array:{elementType:"i32",bytesPerElement:4,loadOp:m.i32_load,storeOp:m.i32_store},Float32Array:{elementType:"f32",bytesPerElement:4,loadOp:m.f32_load,storeOp:m.f32_store},Float64Array:{elementType:"f64",bytesPerElement:8,loadOp:m.f64_load,storeOp:m.f64_store}};function su(e,t=new Map){let n={params:e,locals:new Map,nextLocalIndex:e.length,localTypes:[],warnings:[],errors:[],loopDepth:0,needsMathImports:new Set,needsMemory:!1,hasReturn:!1,wat:[],watIndent:1,moduleFunctions:t};return e.forEach((r,s)=>{n.locals.set(r.name,{index:s,type:r.type})}),n}function Sn(e,t,n){if(e.locals.has(t))return e.errors.push(`Duplicate local declaration: ${t}`),e.locals.get(t).index;let r=e.nextLocalIndex++;return e.locals.set(t,{index:r,type:n}),e.localTypes.push(n),r}function it(e,t){return e.locals.get(t)}function xt(e,t){switch(e.type){case"ExpressionStatement":{let n=e.expression;return[...z(n,t),m.drop]}case"ReturnStatement":{let n=e;if(t.hasReturn=!0,!n.argument)return[m.return];let r=z(n.argument,t),s=Y(n.argument,t);return s==="i32"?r.push(m.f64_convert_i32_s):s==="f32"&&r.push(m.f64_promote_f32),r.push(m.return),r}case"VariableDeclaration":{let n=e,r=[];for(let s of n.declarations){if(s.id.type!=="Identifier"){t.errors.push("Destructuring not supported in WASM blocks");continue}let a=s.id.name,i="f64";s.init&&(i=Y(s.init,t));let o=Sn(t,a,i);s.init&&(r.push(...z(s.init,t)),r.push(m.local_set,...B(o)))}return r}case"ForStatement":return iu(e,t);case"IfStatement":return au(e,t);case"BlockStatement":{let n=e,r=[];for(let s of n.body)r.push(...xt(s,t));return r}default:return t.errors.push(`Unsupported statement type: ${e.type}`),[]}}function iu(e,t){let n=[];return e.init&&(e.init.type==="VariableDeclaration"?n.push(...xt(e.init,t)):n.push(...z(e.init,t))),n.push(m.block,Te.void),n.push(m.loop,Te.void),e.test&&(n.push(...z(e.test,t)),n.push(m.i32_eqz),n.push(m.br_if,1)),t.loopDepth++,e.body&&n.push(...xt(e.body,t)),t.loopDepth--,e.update&&(n.push(...z(e.update,t)),n.push(m.drop)),n.push(m.br,0),n.push(m.end),n.push(m.end),n}function au(e,t){let n=[];return n.push(...z(e.test,t)),n.push(m.if,Te.void),n.push(...xt(e.consequent,t)),e.alternate&&(n.push(m.else),n.push(...xt(e.alternate,t))),n.push(m.end),n}function Y(e,t){switch(e.type){case"Literal":{let n=e;return typeof n.value=="number"?n.raw&&(n.raw.includes(".")||n.raw.includes("e"))?"f64":Number.isInteger(n.value)&&n.value>=-2147483648&&n.value<=2147483647?"i32":"f64":"f64"}case"Identifier":return it(t,e.name)?.type??"f64";case"BinaryExpression":case"AssignmentExpression":{let n=e;if(["<",">","<=",">=","==","!=","===","!=="].includes(n.operator)||["|","&","^","<<",">>",">>>"].includes(n.operator))return"i32";let r=Y(n.left,t),s=Y(n.right,t);return r==="v128"||s==="v128"?"v128":r==="f64"||s==="f64"?"f64":r==="f32"||s==="f32"?"f32":"i32"}case"UnaryExpression":{let n=e;return n.operator==="!"?"i32":Y(n.argument,t)}case"MemberExpression":{let n=e;if(n.object.type==="Identifier"&&it(t,n.object.name)){let s=t.params.find(a=>a.name===n.object.name);if(s?.arrayType){let a=vn[s.arrayType];if(a)return a.elementType}}return"f64"}case"CallExpression":{let n=e;if(n.callee.type==="MemberExpression"){let r=n.callee;if(r.object.type==="Identifier"&&r.object.name==="Math")return"f64"}if(n.callee.type==="Identifier"){let r=n.callee.name;if(r==="f32x4_extract_lane")return"f32";if(r.startsWith("f32x4_")||r==="v128_load")return"v128";let s=t.moduleFunctions.get(r);if(s)return s.hasReturn?"f64":"i32"}return"f64"}default:return"f64"}}function z(e,t){switch(e.type){case"Literal":{let n=e;if(typeof n.value=="number"){let r=Y(e,t);return r==="i32"?[m.i32_const,...Ut(n.value|0)]:r==="f32"?[m.f32_const,...Rr(n.value)]:[m.f64_const,...ge(n.value)]}return t.errors.push(`Unsupported literal type: ${typeof n.value}`),[m.f64_const,...ge(0)]}case"Identifier":{let n=e.name,r=it(t,n);return r?[m.local_get,...B(r.index)]:(t.errors.push(`Unknown identifier: ${n}`),[m.f64_const,...ge(0)])}case"BinaryExpression":return ou(e,t);case"UnaryExpression":return uu(e,t);case"AssignmentExpression":return cu(e,t);case"UpdateExpression":return lu(e,t);case"MemberExpression":return fu(e,t);case"CallExpression":return hu(e,t);case"SequenceExpression":{let n=e,r=[];for(let s=0;s<n.expressions.length;s++)r.push(...z(n.expressions[s],t)),s<n.expressions.length-1&&r.push(m.drop);return r}default:return t.errors.push(`Unsupported expression type: ${e.type}`),[m.f64_const,...ge(0)]}}function ou(e,t){let n=z(e.left,t),r=z(e.right,t),s=Y(e,t),a=Y(e.left,t),i=Y(e.right,t),o=["<",">","<=",">=","==","===","!=","!=="].includes(e.operator),u;a==="f64"||i==="f64"?u="f64":a==="f32"||i==="f32"?u="f32":u="i32",!o&&s==="f64"&&(u="f64");let c=n,l=r;u==="f64"?(a==="i32"?c=[...n,m.f64_convert_i32_s]:a==="f32"&&(c=[...n,m.f64_promote_f32]),i==="i32"?l=[...r,m.f64_convert_i32_s]:i==="f32"&&(l=[...r,m.f64_promote_f32])):u==="f32"&&(a==="i32"&&(c=[...n,m.f32_convert_i32_s]),i==="i32"&&(l=[...r,m.f32_convert_i32_s]));let f={"+":{i32:m.i32_add,f32:m.f32_add,f64:m.f64_add},"-":{i32:m.i32_sub,f32:m.f32_sub,f64:m.f64_sub},"*":{i32:m.i32_mul,f32:m.f32_mul,f64:m.f64_mul},"/":{i32:m.i32_div_s,f32:m.f32_div,f64:m.f64_div},"%":{i32:m.i32_rem_s},"<":{i32:m.i32_lt_s,f32:m.f32_lt,f64:m.f64_lt},">":{i32:m.i32_gt_s,f32:m.f32_gt,f64:m.f64_gt},"<=":{i32:m.i32_le_s,f32:m.f32_le,f64:m.f64_le},">=":{i32:m.i32_ge_s,f32:m.f32_ge,f64:m.f64_ge},"==":{i32:m.i32_eq,f32:m.f32_eq,f64:m.f64_eq},"===":{i32:m.i32_eq,f32:m.f32_eq,f64:m.f64_eq},"!=":{i32:m.i32_ne,f32:m.f32_ne,f64:m.f64_ne},"!==":{i32:m.i32_ne,f32:m.f32_ne,f64:m.f64_ne},"|":{i32:m.i32_or},"&":{i32:m.i32_and},"^":{i32:m.i32_xor},"<<":{i32:m.i32_shl},">>":{i32:m.i32_shr_s},">>>":{i32:m.i32_shr_u}}[e.operator];if(!f)return t.errors.push(`Unsupported operator: ${e.operator}`),[m.f64_const,...ge(0)];let d=f[u]??f.f64??f.i32;return d===void 0?(t.errors.push(`Operator ${e.operator} not supported for type ${u}`),[m.f64_const,...ge(0)]):[...c,...l,d]}function uu(e,t){let n=z(e.argument,t),r=Y(e.argument,t);switch(e.operator){case"-":return r==="i32"?[m.i32_const,0,...n,m.i32_sub]:r==="f32"?[...n,m.f32_neg]:[...n,m.f64_neg];case"!":return[...n,m.i32_eqz];case"~":return[...n,m.i32_const,...Ut(-1),m.i32_xor];default:return t.errors.push(`Unsupported unary operator: ${e.operator}`),n}}function cu(e,t){if(e.left.type==="MemberExpression")return pu(e.left,e.right,e.operator,t);if(e.left.type!=="Identifier")return t.errors.push("Assignment target must be identifier or array element"),[];let n=e.left.name,r=it(t,n);if(!r)return t.errors.push(`Unknown variable: ${n}`),[];let s=[];if(e.operator==="="){s.push(...z(e.right,t));let a=Y(e.right,t);r.type==="f64"&&a==="i32"?s.push(m.f64_convert_i32_s):r.type==="f64"&&a==="f32"?s.push(m.f64_promote_f32):r.type==="i32"&&a==="f64"?s.push(m.i32_trunc_f64_s):r.type==="i32"&&a==="f32"?s.push(m.i32_trunc_f32_s):r.type==="f32"&&a==="i32"?s.push(m.f32_convert_i32_s):r.type==="f32"&&a==="f64"&&s.push(m.f32_demote_f64)}else{let a=Y(e.right,t),i=r.type;a==="f64"||r.type==="f64"?i="f64":(a==="f32"||r.type==="f32")&&(i="f32"),s.push(m.local_get,...B(r.index)),i==="f64"&&r.type==="i32"?s.push(m.f64_convert_i32_s):i==="f64"&&r.type==="f32"?s.push(m.f64_promote_f32):i==="f32"&&r.type==="i32"&&s.push(m.f32_convert_i32_s),s.push(...z(e.right,t)),i==="f64"&&a==="i32"?s.push(m.f64_convert_i32_s):i==="f64"&&a==="f32"?s.push(m.f64_promote_f32):i==="f32"&&a==="i32"&&s.push(m.f32_convert_i32_s);let o=e.operator.slice(0,-1),c={"+":{i32:m.i32_add,f32:m.f32_add,f64:m.f64_add},"-":{i32:m.i32_sub,f32:m.f32_sub,f64:m.f64_sub},"*":{i32:m.i32_mul,f32:m.f32_mul,f64:m.f64_mul},"/":{i32:m.i32_div_s,f32:m.f32_div,f64:m.f64_div}}[o]?.[i];if(!c)return t.errors.push(`Unsupported compound assignment: ${e.operator}`),[];s.push(c),r.type==="i32"&&i==="f64"?s.push(m.i32_trunc_f64_s):r.type==="i32"&&i==="f32"?s.push(m.i32_trunc_f32_s):r.type==="f32"&&i==="f64"&&s.push(m.f32_demote_f64)}return s.push(m.local_tee,...B(r.index)),s}function lu(e,t){if(e.argument.type!=="Identifier")return t.errors.push("Update expression argument must be identifier"),[];let n=e.argument.name,r=it(t,n);if(!r)return t.errors.push(`Unknown variable: ${n}`),[];let s=[],a=r.type==="i32";return e.prefix?(s.push(m.local_get,...B(r.index)),a?(s.push(m.i32_const,1),s.push(e.operator==="++"?m.i32_add:m.i32_sub)):(s.push(m.f64_const,...ge(1)),s.push(e.operator==="++"?m.f64_add:m.f64_sub)),s.push(m.local_tee,...B(r.index))):(s.push(m.local_get,...B(r.index)),s.push(m.local_get,...B(r.index)),a?(s.push(m.i32_const,1),s.push(e.operator==="++"?m.i32_add:m.i32_sub)):(s.push(m.f64_const,...ge(1)),s.push(e.operator==="++"?m.f64_add:m.f64_sub)),s.push(m.local_set,...B(r.index))),s}function fu(e,t){if(e.object.type!=="Identifier")return t.errors.push("Array access requires identifier"),[];let n=e.object.name,r=t.params.find(c=>c.name===n);if(!r?.isArray||!r.arrayType)return t.errors.push(`${n} is not a typed array parameter`),[];let s=vn[r.arrayType];if(!s)return t.errors.push(`Unknown array type: ${r.arrayType}`),[];t.needsMemory=!0;let a=[],i=it(t,n);if(!i)return t.errors.push(`Unknown array: ${n}`),[];if(a.push(m.local_get,...B(i.index)),!e.computed||!e.property)return t.errors.push("Array access requires computed index"),[];let o=z(e.property,t),u=Y(e.property,t);return a.push(...o),u==="f64"&&a.push(m.i32_trunc_f64_s),s.bytesPerElement>1&&(a.push(m.i32_const,...Ut(s.bytesPerElement)),a.push(m.i32_mul)),a.push(m.i32_add),a.push(s.loadOp,0,0),a}function pu(e,t,n,r){if(e.object.type!=="Identifier")return r.errors.push("Array store requires identifier"),[];let s=e.object.name,a=r.params.find(g=>g.name===s);if(!a?.isArray||!a.arrayType)return r.errors.push(`${s} is not a typed array parameter`),[];let i=vn[a.arrayType];if(!i)return r.errors.push(`Unknown array type: ${a.arrayType}`),[];r.needsMemory=!0;let o=[],u=it(r,s);if(!u)return[];if(!e.computed||!e.property)return r.errors.push("Array store requires computed index"),[];let c=z(e.property,r),l=Y(e.property,r),p=()=>{let g=[];return g.push(m.local_get,...B(u.index)),g.push(...c),l==="f64"&&g.push(m.i32_trunc_f64_s),i.bytesPerElement>1&&(g.push(m.i32_const,...Ut(i.bytesPerElement)),g.push(m.i32_mul)),g.push(m.i32_add),g};if(n==="=")o.push(...z(t,r));else{let g=Sn(r,`__addr_${r.nextLocalIndex}`,"i32");o.push(...p()),o.push(m.local_tee,...B(g)),o.push(i.loadOp,0,0),o.push(...z(t,r));let y=Y(t,r);i.elementType==="f32"&&y==="f64"?o.push(m.f32_demote_f64):i.elementType==="f64"&&y==="f32"?o.push(m.f64_promote_f32):i.elementType==="f32"&&y==="i32"?o.push(m.f32_convert_i32_s):i.elementType==="f64"&&y==="i32"?o.push(m.f64_convert_i32_s):i.elementType==="i32"&&y==="f64"?o.push(m.i32_trunc_f64_s):i.elementType==="i32"&&y==="f32"&&o.push(m.i32_trunc_f32_s);let w=n.slice(0,-1),k={"+":i.elementType==="i32"?m.i32_add:i.elementType==="f32"?m.f32_add:m.f64_add,"-":i.elementType==="i32"?m.i32_sub:i.elementType==="f32"?m.f32_sub:m.f64_sub,"*":i.elementType==="i32"?m.i32_mul:i.elementType==="f32"?m.f32_mul:m.f64_mul};o.push(k[w]??m.f64_add);let S=Sn(r,`__val_${r.nextLocalIndex}`,i.elementType);return o.push(m.local_set,...B(S)),o.push(m.local_get,...B(g)),o.push(m.local_get,...B(S)),o.push(i.storeOp,0,0),o.push(m.local_get,...B(S)),o}let f=Y(t,r);i.elementType==="f32"&&f==="f64"?o.push(m.f32_demote_f64):i.elementType==="f64"&&f==="f32"?o.push(m.f64_promote_f32):i.elementType==="i32"&&f==="f64"&&o.push(m.i32_trunc_f64_s);let d=Sn(r,`__tmp_${r.nextLocalIndex}`,i.elementType);return o.push(m.local_set,...B(d)),o.push(m.local_get,...B(u.index)),o.push(...c),l==="f64"&&o.push(m.i32_trunc_f64_s),i.bytesPerElement>1&&(o.push(m.i32_const,...Ut(i.bytesPerElement)),o.push(m.i32_mul)),o.push(m.i32_add),o.push(m.local_get,...B(d)),o.push(i.storeOp,0,0),o.push(m.local_get,...B(d)),o}function hu(e,t){if(e.callee.type==="MemberExpression"){let n=e.callee;if(n.object.type==="Identifier"&&n.object.name==="Math"&&n.property.type==="Identifier"){let r=n.property.name;return yu(r,e.arguments,t)}}if(e.callee.type==="Identifier"){let n=e.callee.name;if(n.startsWith("f32x4_")||n.startsWith("v128_"))return gu(n,e.arguments,t);let r=t.moduleFunctions.get(n);if(r)return du(r,n,e.arguments,t)}return t.errors.push(`Unsupported function call: ${e.callee.type}`),[m.f64_const,...ge(0)]}function du(e,t,n,r){if(n.length!==e.params.length)return r.errors.push(`wasm function ${t} expects ${e.params.length} arguments, got ${n.length}`),[m.f64_const,...ge(0)];let s=[];for(let a=0;a<n.length;a++){let i=n[a],o=e.params[a].type,u=Y(i,r);if(s.push(...z(i,r)),u!==o){let c=mu(u,o);c===void 0?r.errors.push(`wasm function ${t} param ${a} expects ${o}, got ${u} (no conversion available)`):c!==null&&s.push(c)}}return s.push(m.call,...B(e.index)),e.hasReturn||s.push(m.i32_const,0),s}function mu(e,t){if(e===t)return null;if(!(e==="v128"||t==="v128")&&!(e==="i64"||t==="i64"))switch(`${e}->${t}`){case"f64->i32":return m.i32_trunc_f64_s;case"f32->i32":return m.i32_trunc_f32_s;case"i32->f64":return m.f64_convert_i32_s;case"i32->f32":return m.f32_convert_i32_s;case"f32->f64":return m.f64_promote_f32;case"f64->f32":return m.f32_demote_f64;default:return}}function gu(e,t,n){n.needsMemory=!0;let r=[];switch(e){case"v128_load":case"f32x4_load":{r.push(...z(t[0],n)),Y(t[0],n)==="f64"&&r.push(m.i32_trunc_f64_s),r.push(...z(t[1],n));let a=Y(t[1],n);return a==="f64"?r.push(m.i32_trunc_f64_s):a==="f32"&&r.push(m.i32_trunc_f32_s),r.push(m.i32_add),r.push(...qi(ae.v128_load,2,0)),r}case"v128_store":case"f32x4_store":{r.push(...z(t[0],n)),Y(t[0],n)==="f64"&&r.push(m.i32_trunc_f64_s),r.push(...z(t[1],n));let a=Y(t[1],n);return a==="f64"?r.push(m.i32_trunc_f64_s):a==="f32"&&r.push(m.i32_trunc_f32_s),r.push(m.i32_add),r.push(...z(t[2],n)),r.push(...qi(ae.v128_store,2,0)),r.push(m.i32_const,0),r}case"f32x4_splat":{r.push(...z(t[0],n));let s=Y(t[0],n);return s==="i32"?r.push(m.f32_convert_i32_s):s==="f64"&&r.push(m.f32_demote_f64),r.push(...Nr(ae.f32x4_splat)),r}case"f32x4_extract_lane":{r.push(...z(t[0],n));let s=t[1].value;return!Number.isInteger(s)||s<0||s>3?(n.errors.push(`f32x4_extract_lane: lane must be 0-3, got ${s}`),[m.f32_const,...Rr(0)]):(r.push(qt,...B(ae.f32x4_extract_lane),s),r)}case"f32x4_replace_lane":{r.push(...z(t[0],n));let s=t[1].value;if(!Number.isInteger(s)||s<0||s>3)return n.errors.push(`f32x4_replace_lane: lane must be 0-3, got ${s}`),[m.f32_const,...Rr(0)];r.push(...z(t[2],n));let a=Y(t[2],n);return a==="i32"?r.push(m.f32_convert_i32_s):a==="f64"&&r.push(m.f32_demote_f64),r.push(qt,...B(ae.f32x4_replace_lane),s),r}case"f32x4_add":case"f32x4_sub":case"f32x4_mul":case"f32x4_div":{r.push(...z(t[0],n)),r.push(...z(t[1],n));let s={f32x4_add:ae.f32x4_add,f32x4_sub:ae.f32x4_sub,f32x4_mul:ae.f32x4_mul,f32x4_div:ae.f32x4_div};return r.push(...Nr(s[e])),r}case"f32x4_neg":case"f32x4_sqrt":{r.push(...z(t[0],n));let s={f32x4_neg:ae.f32x4_neg,f32x4_sqrt:ae.f32x4_sqrt};return r.push(...Nr(s[e])),r}default:return n.errors.push(`Unknown SIMD intrinsic: ${e}`),[m.f64_const,...ge(0)]}}function yu(e,t,n){let r=[];for(let o of t){r.push(...z(o,n));let u=Y(o,n);u==="i32"?r.push(m.f64_convert_i32_s):u==="f32"&&r.push(m.f64_promote_f32)}let a={abs:m.f64_abs,ceil:m.f64_ceil,floor:m.f64_floor,trunc:m.f64_trunc,sqrt:m.f64_sqrt,min:m.f64_min,max:m.f64_max}[e];return a!==void 0?(r.push(a),r):["sin","cos","tan","asin","acos","atan","atan2","exp","log","pow"].includes(e)?(n.needsMathImports.add(e),n.errors.push(`Math.${e} requires JS import (not yet implemented)`),[m.f64_const,...ge(0)]):(n.errors.push(`Unknown Math method: ${e}`),[m.f64_const,...ge(0)])}function Ui(e){let t=e.split(":").map(a=>a.trim()),n=t[0];if(t.length===1)return{name:n,type:"f64"};let r=t[1];return vn[r]?{name:n,type:"i32",isArray:!0,arrayType:r}:{name:n,type:{i32:"i32",i64:"i64",f32:"f32",f64:"f64",number:"f64",int:"i32"}[r]??"f64"}}function bu(e,t){let n=e.map(s=>Te[s.type]),r=t?[1,Te.f64]:[0];return[96,...B(e.length),...n,...r]}function xu(e,t){let n=[];if(t.length>0){let a=t[0],i=1;for(let o=1;o<t.length;o++)t[o]===a?i++:(n.push([...B(i),Te[a]]),a=t[o],i=1);n.push([...B(i),Te[a]])}let s=[...[...B(n.length),...n.flat()],...e,m.end];return[...B(s.length),...s]}function _u(){return Vt(Lt.import,[1,...Mr("env"),...Mr("memory"),2,0,1])}function wu(e,t){if(e.length!==t.length)throw new Error("functions and exportNames length mismatch");let n=[0,97,115,109,1,0,0,0],r=e.map(f=>bu(f.params,f.hasReturn)),s=Vt(Lt.type,[...B(r.length),...r.flat()]),i=e.some(f=>f.needsMemory)?_u():[],o=Vt(Lt.function,[...B(e.length),...e.map((f,d)=>B(d)).flat()]),u=Vt(Lt.export,[...B(e.length),...t.map((f,d)=>[...Mr(f),0,...B(d)]).flat()]),c=e.map(f=>xu(f.bodyCode,f.localTypes)),l=Vt(Lt.code,[...B(c.length),...c.flat()]),p=[...n,...s];return i.length>0&&p.push(...i),p.push(...o,...u,...l),p}function Su(e,t=new Map){try{let n=e.captures.map(Ui),r;try{let u=`function __wasm__(${n.map(c=>c.name).join(", ")}) { ${e.body} }`;r=je(u,{ecmaVersion:2022})}catch(u){return{success:!1,warnings:[],error:`Parse error: ${u.message}`}}let a=r.body[0].body.body,i=su(n,t),o=[];for(let u of a)o.push(...xt(u,i));return i.errors.length>0?{success:!1,warnings:i.warnings,error:i.errors.join("; ")}:{success:!0,fn:{params:n,bodyCode:o,localTypes:i.localTypes,needsMemory:i.needsMemory,hasReturn:i.hasReturn},wat:ru(o,n,i.localTypes),warnings:i.warnings}}catch(n){return{success:!1,warnings:[],error:n.message}}}function Wi(e){let t=new Map,n=[];for(let u=0;u<e.length;u++){let c=e[u],l=c.captures.map(Ui),p=c.returnType!==void 0;n.push({params:l,hasReturn:p}),c.name&&t.set(c.name,{index:u,params:l,hasReturn:p})}let r=[],s=[],a=[],i=[];for(let u=0;u<e.length;u++){let c=e[u],l=Su(c,t);if(i.push(...l.warnings),!l.success||!l.fn){r.push({id:c.id,success:!1,error:l.error}),s.push(vu(n[u])),a.push({id:c.id,exportName:`compute_${u}`,captures:c.captures,needsMemory:!1,wat:`(failed: ${l.error??"unknown error"})`});continue}s.push(l.fn),a.push({id:c.id,exportName:`compute_${u}`,captures:c.captures,needsMemory:l.fn.needsMemory,wat:l.wat??""}),r.push({id:c.id,success:!0,exportIndex:u})}if(s.length===0)return{bytes:new Uint8Array,results:r,exports:[],needsMemory:!1,warnings:i};let o=wu(s,a.map(u=>u.exportName));return{bytes:new Uint8Array(o),results:r,exports:a,needsMemory:a.some(u=>u.needsMemory),warnings:i}}function vu(e){let t=e.hasReturn?[m.f64_const,...ge(0)]:[];return{params:e.params,bodyCode:t,localTypes:[],needsMemory:!1,hasReturn:e.hasReturn}}function Ji(e){let t=Wi(e),n=new Map(t.exports.map(l=>[l.id,l])),r=t.results.map(l=>{if(!l.success)return{id:l.id,success:!1,error:l.error};let p=n.get(l.id);return{id:l.id,success:!0,byteLength:t.bytes.length,_exportName:p.exportName}});if(t.exports.length===0)return{code:"",results:r};let s=t.exports.map(l=>{let p=l.wat.split(`
|
|
315
|
+
`).map(f=>` * ${f}`);return`/**
|
|
316
|
+
* WASM: ${l.id} (export: ${l.exportName})
|
|
317
|
+
${p.join(`
|
|
318
|
+
`)}
|
|
319
|
+
*/`}).join(`
|
|
320
|
+
`),a=t.exports.map(l=>`{id:${JSON.stringify(l.id)},n:${JSON.stringify(l.exportName)},c:${JSON.stringify(l.captures)},m:${l.needsMemory}}`).join(","),i=btoa(String.fromCharCode(...t.bytes)),o=t.needsMemory,u=`${s}
|
|
321
|
+
;(async()=>{
|
|
322
|
+
const __wasmExports=[${a}];
|
|
323
|
+
const __wasmModuleB64=${JSON.stringify(i)};
|
|
324
|
+
const __b64ToBytes=s=>{const b=atob(s),a=new Uint8Array(b.length);for(let i=0;i<b.length;i++)a[i]=b.charCodeAt(i);return a};
|
|
325
|
+
const __parseType=c=>{const m=c.match(/^(\\w+)\\s*:\\s*(\\w+)$/);if(!m)return{n:c,t:'f64',a:false};const[,n,ts]=m;const at={Float32Array:'f32',Float64Array:'f64',Int32Array:'i32',Uint8Array:'i32'};if(at[ts])return{n,t:'i32',a:true,at:ts};return{n,t:'f64',a:false}};
|
|
326
|
+
${o?`const __wasmMem=new WebAssembly.Memory({initial:1024});
|
|
327
|
+
let __woff=0;
|
|
328
|
+
globalThis.wasmBuffer=function(Ctor,len){const bytes=len*Ctor.BYTES_PER_ELEMENT;const align=Math.max(Ctor.BYTES_PER_ELEMENT,16);__woff=(__woff+align-1)&~(align-1);const arr=new Ctor(__wasmMem.buffer,__woff,len);__woff+=bytes;return arr};`:""}
|
|
329
|
+
const __wasmInst=await WebAssembly.instantiate(await WebAssembly.compile(__b64ToBytes(__wasmModuleB64)),${o?"{env:{memory:__wasmMem}}":"{}"});
|
|
330
|
+
for(const{id,n,c,m}of __wasmExports){
|
|
331
|
+
const compute=__wasmInst.exports[n];
|
|
332
|
+
const params=c.map(__parseType);
|
|
333
|
+
const hasArrays=params.some(p=>p.a);
|
|
334
|
+
if(!hasArrays){globalThis[id]=compute;continue}
|
|
335
|
+
globalThis[id]=function(...args){
|
|
336
|
+
const mv=new Uint8Array(__wasmMem.buffer);let off=__woff;const ptrs=[];
|
|
337
|
+
for(let i=0;i<params.length;i++){const p=params[i],a=args[i];
|
|
338
|
+
if(p.a&&a?.buffer){
|
|
339
|
+
if(a.buffer===__wasmMem.buffer){ptrs.push(a.byteOffset)}
|
|
340
|
+
else{const ab=new Uint8Array(a.buffer,a.byteOffset,a.byteLength);off=(off+15)&~15;mv.set(ab,off);ptrs.push(off);off+=ab.length}
|
|
341
|
+
} else ptrs.push(a)}
|
|
342
|
+
const r=compute(...ptrs);off=__woff;
|
|
343
|
+
for(let i=0;i<params.length;i++){const p=params[i],a=args[i];
|
|
344
|
+
if(p.a&&a?.buffer){
|
|
345
|
+
if(a.buffer===__wasmMem.buffer) continue;
|
|
346
|
+
const ab=new Uint8Array(a.buffer,a.byteOffset,a.byteLength);off=(off+15)&~15;ab.set(mv.slice(off,off+ab.length));off+=ab.length}}
|
|
347
|
+
return r};
|
|
348
|
+
}})();
|
|
349
|
+
`.trim(),c=r.map(({_exportName:l,...p})=>p);return{code:u,results:c}}function Br(e,t){let n=[];function r(a){n.push({start:a.start,end:a.end,newText:`__tjs.toBool(${he(a,t)})`})}function s(a){if(!(!a||typeof a!="object"||!("type"in a))){switch(a.type){case"IfStatement":case"WhileStatement":case"DoWhileStatement":{let i=a;r(i.test),i.consequent&&s(i.consequent),i.alternate&&s(i.alternate),i.body&&s(i.body);return}case"ForStatement":{let i=a;i.init&&s(i.init),i.test&&r(i.test),i.update&&s(i.update),i.body&&s(i.body);return}case"ConditionalExpression":{let i=a;n.push({start:i.start,end:i.end,newText:`__tjs.toBool(${he(i.test,t)})?(${he(i.consequent,t)}):(${he(i.alternate,t)})`});return}case"LogicalExpression":{let i=a;if(i.operator==="&&"||i.operator==="||"){n.push({start:i.start,end:i.end,newText:he(a,t)});return}break}case"UnaryExpression":{let i=a;if(i.operator==="!"){n.push({start:i.start,end:i.end,newText:`!__tjs.toBool(${he(i.argument,t)})`});return}break}case"CallExpression":{let i=a;if(i.callee&&i.callee.type==="Identifier"&&i.callee.name==="Boolean"&&i.arguments.length===1&&i.arguments[0].type!=="SpreadElement"){n.push({start:i.start,end:i.end,newText:`__tjs.toBool(${he(i.arguments[0],t)})`});return}break}}ku(a,s)}}return s(e),Eu(n)}function he(e,t){if(!e)return"";switch(e.type){case"LogicalExpression":{let n=e,r=he(n.left,t),s=he(n.right,t);return n.operator==="&&"?`((__tjs__t)=>__tjs.toBool(__tjs__t)?(${s}):__tjs__t)(${r})`:n.operator==="||"?`((__tjs__t)=>__tjs.toBool(__tjs__t)?__tjs__t:(${s}))(${r})`:`(${r})??(${s})`}case"ConditionalExpression":{let n=e;return`__tjs.toBool(${he(n.test,t)})?(${he(n.consequent,t)}):(${he(n.alternate,t)})`}case"UnaryExpression":{let n=e;return n.operator==="!"?`!__tjs.toBool(${he(n.argument,t)})`:Or(e,t)}case"CallExpression":{let n=e;return n.callee&&n.callee.type==="Identifier"&&n.callee.name==="Boolean"&&n.arguments.length===1&&n.arguments[0].type!=="SpreadElement"?`__tjs.toBool(${he(n.arguments[0],t)})`:Or(e,t)}}return Or(e,t)}function Or(e,t){let n=e.start,r=e.end;if(typeof n!="number"||typeof r!="number")return"";let s=zi(e);if(s.length===0)return t.slice(n,r);s.sort((o,u)=>o.start-u.start);let a="",i=n;for(let o of s)o.start<i||(o.start>i&&(a+=t.slice(i,o.start)),a+=he(o,t),i=o.end);return i<r&&(a+=t.slice(i,r)),a}function ku(e,t){for(let n of zi(e))t(n)}function zi(e){let t=[];for(let n in e){if(n==="type"||n==="start"||n==="end"||n==="loc")continue;let r=e[n];if(Array.isArray(r))for(let s of r)s&&typeof s=="object"&&typeof s.type=="string"&&t.push(s);else r&&typeof r=="object"&&typeof r.type=="string"&&t.push(r)}return t}function Eu(e){let t=[...e].sort((s,a)=>s.start-a.start||a.end-s.end),n=[],r=-1;for(let s of t)s.start>=r&&(n.push(s),r=s.end);return n}function Fr(e){let t;try{t=je(`function __wrap__(){${e}}`,{ecmaVersion:2022,sourceType:"module",locations:!1})}catch{return e}let n=`function __wrap__(){${e}}`,r=Br(t,n);if(r.length===0)return e;r.sort((o,u)=>u.start-o.start);let s=n;for(let o of r)s=s.slice(0,o.start)+o.newText+s.slice(o.end);return s.slice("function __wrap__(){".length,s.length-"}".length)}function Tu(e,t,n){if(!e||!t)return!1;let r=new RegExp(`function\\s+${t}\\s*\\([^)]*?\\b${n}\\s*([=:])`,"s"),s=e.match(r);return s?s[1]===":":!1}function $u(e,t,n,r,s){let a=[],i=Nt(t,e),o={},u=!1,c,l;if(e.params.length===1&&(e.params[0].type==="ObjectPattern"||e.params[0].type==="AssignmentPattern"&&e.params[0].left.type==="ObjectPattern")){u=!0;let d=e.params[0],g=d.type==="ObjectPattern"?d:d.left,y=Ge(g,n);if(y.type.kind==="object"&&y.type.destructuredParams){c={},l=new Set;for(let[w,k]of Object.entries(y.type.destructuredParams))o[w]={...k,description:i.params[w]},c[w]=k.type,k.required&&l.add(w)}}else for(let d of e.params)if(d.type==="Identifier"){let g=Ge(d,n);o[d.name]={...g,required:n.has(d.name),description:i.params[d.name]}}else if(d.type==="AssignmentPattern"&&d.left.type==="Identifier"){let g=Ge(d,n),y=Tu(s||"",e.id?.name||"",d.left.name);o[d.left.name]={...g,required:y,default:y?null:g.example??g.default,description:i.params[d.left.name]}}else if(d.type==="ObjectPattern"){let g=Ge(d,n);if(g.type.kind==="object"&&g.type.destructuredParams)for(let[y,w]of Object.entries(g.type.destructuredParams))o[y]={...w,description:i.params[y]}}else if(d.type==="RestElement"&&d.argument?.type==="Identifier"){let g=d.argument.name,y=t.match(new RegExp(`\\.\\.\\.${g}\\s*:\\s*([^)]+?)\\s*\\)`));if(y)try{let w=$t(y[1].trim(),0,{ecmaVersion:2022}),k=ue(w);o[g]={name:g,type:k,required:!1,description:i.params[g]}}catch{o[g]={name:g,type:{kind:"array"},required:!1,description:i.params[g]}}else o[g]={name:g,type:{kind:"array"},required:!1,description:i.params[g]}}let p;if(r)try{let d=r.includes("=")?Hi(r):r,g=$t(d,0,{ecmaVersion:2022});p=ue(g)}catch{p={kind:"any"},a.push(`Could not parse return type: ${r}`)}return{types:{name:e.id?.name||"anonymous",params:o,returns:p,description:i.description,isDestructuredParam:u,destructuredShape:c,destructuredRequired:l},warnings:a}}function Cu(e,t,n){let r=[],s=n?`${n}:`:"",a=n?`${n}:${e}`:e;if(t.isDestructuredParam&&t.destructuredShape){let o=t.destructuredShape,u=t.destructuredRequired||new Set,c=Object.keys(o);if(c.length===0)return null;for(let l of c)r.push(`if (${l} instanceof Error) return ${l};`);for(let[l,p]of Object.entries(o)){let f=u.has(l),d=`${s}${e}.${l}`,g=kn(l,p);if(g){let y=p.kind;f?r.push(`if (${g}) return __tjs.typeError('${d}', '${y}', ${l});`):r.push(`if (${l} !== undefined && ${g}) return __tjs.typeError('${d}', '${y}', ${l});`)}}return r.length===0?null:(r.unshift(`__tjs.pushStack('${a}');`),{preamble:r.join(`
|
|
350
|
+
`),suffix:"__tjs.popStack();"})}let i=Object.entries(t.params);if(i.length===0)return null;for(let[o]of i)r.push(`if (${o} instanceof Error) return ${o};`);for(let[o,u]of i){let c=`${s}${e}.${o}`;u.type.kind==="array"&&r.push(`if (Array.isArray(${o})) { for (const __i of ${o}) { if (__i instanceof Error && __i.path !== undefined) return __i } }`);let l=kn(o,u.type);if(l){let p=u.type.kind==="union"?u.type.members.map(f=>f.kind).join(" | "):u.type.kind;u.required?r.push(`if (${l}) return __tjs.typeError('${c}', '${p}', ${o});`):r.push(`if (${o} !== undefined && ${l}) return __tjs.typeError('${c}', '${p}', ${o});`)}if(u.type.kind==="function"){let p=Mu(o,u.type,c);p&&(r.push(p),r.push(`if (${o} instanceof Error) return ${o};`))}}return r.length===0?null:(r.unshift(`__tjs.pushStack('${a}');`),{preamble:r.join(`
|
|
351
|
+
`),suffix:"__tjs.popStack();"})}function Hi(e){let t="",n=0;for(let r=0;r<e.length;r++){let s=e[r];if(s==="{"||s==="["||s==="(")n++,t+=s;else if(s==="}"||s==="]"||s===")")n--,t+=s;else if(s==="'"||s==='"'||s==="`"){for(t+=s,r++;r<e.length&&e[r]!==s;)e[r]==="\\"&&(t+=e[r++]),t+=e[r++];r<e.length&&(t+=e[r])}else n===1&&s==="="&&e[r-1]!=="!"&&e[r+1]!=="="?t+=":":t+=s}return t}function Au(e,t){let r=new RegExp(`function\\s+${t}\\s*\\([^)]*\\)\\s*(:[?!]?)\\s*`,"g").exec(e);if(!r)return null;let s=e.slice(r.index+r[0].length);return wn(s)}function Pu(e,t){let r=new RegExp(`function\\s+${t}\\s*\\([^)]*\\)\\s*:([?!]?)`,"g").exec(e);if(!r)return;let s=r[1];if(s==="?")return"safe";if(s==="!")return"unsafe"}function ju(e){let t=e.match(/^\/\*\s*tjs\s*<-\s*([^*]+?)\s*\*\//);return t?t[1].trim():void 0}function Iu(e,t){let n=new RegExp(`\\/\\*\\s*line\\s+(\\d+)\\s*\\*\\/\\s*(?:async\\s+)?function\\s+${t}\\s*\\(`,"m"),r=e.match(n);return r?parseInt(r[1],10):void 0}function En(e,t={}){let{filename:n="<source>",runTests:r=!0,debug:s=!1,resolvedImports:a={}}=t,i=[];e=Qn(e);let u=ju(e)||n,{code:c,tests:l,mocks:p,testRunner:f}=tr(e),{ast:d,originalSource:g,requiredParams:y,unsafeFunctions:w}=Qe(c,{filename:n,colonShorthand:!0,dialect:t.dialect,moduleLoader:t.moduleLoader}),k=Nu(d),S=hn(c,{dialect:t.dialect,moduleLoader:t.moduleLoader,filename:n});for(let A of l)A.body=At(A.body),S.tjsModes.tjsEquals&&(A.body=Pt(A.body)),S.tjsModes.tjsStandard&&(A.body=Fr(A.body));for(let A of p)A.body=At(A.body),S.tjsModes.tjsEquals&&(A.body=Pt(A.body)),S.tjsModes.tjsStandard&&(A.body=Fr(A.body));let b={},_=[],v=[];for(let A of k){let W=A.id?.name||"anonymous",V=Au(c,W),ve;if(V&&V.includes("="))try{let re=V.matchAll(/(\w+)\s*=\s*/g),le=Hi(V),Oe=new Function(`return ${le}`)(),fe={};for(let Nn of re){let wt=Nn[1];wt in Oe&&(fe[wt]=Oe[wt])}Object.keys(fe).length>0&&(ve=fe)}catch{}let{types:Me,warnings:sa}=$u(A,g,y,V,c);i.push(...sa),b[W]=Me;for(let re of A.params)if(re.type==="AssignmentPattern"&&re.left.type==="Identifier"&&re.right.type==="Identifier"){let le=re.left.name,Oe=re.right.name,fe=b[Oe];if(fe&&Me.params[le]){let Nn=Object.entries(fe.params).map(([ca,la])=>({name:ca,type:la.type})),wt=fe.returns??{kind:"any"};Me.params[le].type={kind:"function",params:Nn,returns:wt}}}for(let re of A.params)if(re.type==="AssignmentPattern"){let le=re.left?.name||re.left?.value,Oe=le?Me.params[le]:null;if(Oe?.required&&Oe.default===null)v.push({start:re.left.end,end:re.right.end});else{let fe=re.right;fe.type==="BinaryExpression"&&fe.operator==="|"&&v.push({start:fe.left.end,end:fe.end})}}let Jr=S.moduleSafety==="none"||w.has(W),ia=S.safeFunctions.has(W),aa=Pu(c,W),oa=Iu(e,W),ut={file:u,line:oa??A.loc?.start.line??0,column:A.loc?.start.column??0},ua={unsafe:Jr,safe:ia,returnSafety:aa},zr=S.polymorphicNames.has(W),In;if(zr){let re=[];for(let Oe of k){let fe=Oe.id?.name||"";fe.startsWith(W+"$")&&re.push(fe)}let le={polymorphic:!0,variants:re};ut&&(le.source=`${ut.file}:${ut.line}`),In=`${W}.__tjs = ${JSON.stringify(le,null,2)}`}else In=Ru(W,Me,ua,{debug:s,source:ut,returnDefaults:ve});if(_.push({position:A.end,text:`
|
|
352
|
+
${In}`}),!Jr&&!zr){let re=`${ut.file}:${ut.line}`,le=Cu(W,Me,re);le&&A.body&&A.body.start!==void 0&&(_.push({position:A.body.start+1,text:`
|
|
353
|
+
${le.preamble}
|
|
354
|
+
`}),le.suffix&&_.push({position:A.body.end-1,text:`
|
|
355
|
+
${le.suffix}
|
|
356
|
+
`}))}}if(S.tjsModes.tjsStandard){let A=Br(d,S.source);for(let W of A)v.push({start:W.start,end:W.end}),_.push({position:W.start,text:W.newText})}v.sort((A,W)=>W.start-A.start);let x=S.source;for(let{start:A,end:W}of v)x=x.slice(0,A)+x.slice(W);for(let A of _){let W=0;for(let V of v)V.start<A.position&&(W+=V.end-V.start);A.position-=W}_.sort((A,W)=>W.position-A.position);for(let{position:A,text:W}of _)x=x.slice(0,A)+W+x.slice(A);let E=x.includes("__tjs.typeError("),$=x.includes("__tjs.pushStack("),C=x.includes("Is("),I=x.includes("IsNot("),M=x.includes("Eq("),F=x.includes("NotEq("),N=x.includes("TypeOf("),U=/\bType\(/.test(x),J=/\bGeneric\(/.test(x),X=/\bFunctionPredicate\(/.test(x),ee=/\bEnum\(/.test(x),ce=/\bUnion\(/.test(x),ot=x.includes("__tjs.bang("),Gt=x.includes("__tjs.toBool("),jn=x.includes("__tjs.checkFnShape("),Ur=S.tjsModes.tjsSafeEval;if(E||$||C||I||M||F||N||U||J||X||ee||ce||ot||Gt||jn||Ur){let A=[];E&&A.push("class MonadicError extends Error{constructor(m,p,e,a,c,r){super(m);this.name='MonadicError';this.path=p;this.expected=e;this.actual=a;this.callStack=c;this.reason=r}}",`function typeError(p,e,v,r){const a=v===null?'null':typeof v;const m=r?'Expected '+e+" for '"+p+"': "+r:'Expected '+e+" for '"+p+"', got "+a;const err=new MonadicError(m,p,e,a,undefined,r);const c=globalThis.__tjs?.getConfig?.();if(c?.logTypeErrors)console.error('[TJS TypeError] '+err.message);if(c?.throwTypeErrors)throw err;return err}`,"function isMonadicError(v){return v instanceof Error&&v.name==='MonadicError'&&'path' in v}"),$&&A.push("const __stack=[];function pushStack(n){__stack.push(n)}function popStack(){__stack.pop()}function getStack(){return[...__stack]}"),M&&A.push("function Eq(a,b){if(a instanceof String||a instanceof Number||a instanceof Boolean)a=a.valueOf();if(b instanceof String||b instanceof Number||b instanceof Boolean)b=b.valueOf();if(a===b)return true;if(typeof a==='number'&&typeof b==='number'&&isNaN(a)&&isNaN(b))return true;if((a===null||a===undefined)&&(b===null||b===undefined))return true;return false}"),F&&A.push("function NotEq(a,b){return!Eq(a,b)}"),N&&A.push("function TypeOf(v){return v===null?'null':typeof v}"),C&&A.push("const tjsEquals=Symbol.for('tjs.equals');function Is(a,b){if(a!=null&&typeof a==='object'&&typeof a[tjsEquals]==='function')return a[tjsEquals](b);if(b!=null&&typeof b==='object'&&typeof b[tjsEquals]==='function')return b[tjsEquals](a);if(a!=null&&typeof a==='object'&&typeof a.Equals==='function')return a.Equals(b);if(b!=null&&typeof b==='object'&&typeof b.Equals==='function')return b.Equals(a);if(a instanceof String||a instanceof Number||a instanceof Boolean)a=a.valueOf();if(b instanceof String||b instanceof Number||b instanceof Boolean)b=b.valueOf();if(a===b)return true;if(typeof a==='number'&&typeof b==='number'&&isNaN(a)&&isNaN(b))return true;if((a==null)&&(b==null))return true;if(a==null||b==null)return false;if(typeof a!==typeof b)return false;if(typeof a!=='object')return false;if(a instanceof Set&&b instanceof Set){if(a.size!==b.size)return false;for(const v of a)if(!b.has(v))return false;return true}if(a instanceof Map&&b instanceof Map){if(a.size!==b.size)return false;for(const[k,v]of a)if(!b.has(k)||!Is(v,b.get(k)))return false;return true}if(a instanceof Date&&b instanceof Date)return a.getTime()===b.getTime();if(a instanceof RegExp&&b instanceof RegExp)return a.toString()===b.toString();if(Array.isArray(a)&&Array.isArray(b)){if(a.length!==b.length)return false;return a.every((v,i)=>Is(v,b[i]))}if(Array.isArray(a)!==Array.isArray(b))return false;const ka=Object.keys(a),kb=Object.keys(b);if(ka.length!==kb.length)return false;return ka.every(k=>Is(a[k],b[k]))}"),I&&A.push("function IsNot(a,b){return!Is(a,b)}"),U&&A.push("function Type(d,p,e){const t={description:d,__runtimeType:true};if(typeof p==='function'){t.check=p;t.default=e??null}else{const ex=e??p;t.default=ex;t.check=v=>{if(ex===null)return true;return typeof v===typeof ex}}return t}"),J&&A.push("function Generic(tp,pred,d){const f=(...args)=>{const t={description:d||'generic',__runtimeType:true,check:v=>pred(v,...args)};return t};f.__runtimeType=true;f.description=d;return f}"),X&&A.push("function FunctionPredicate(n,s,b){if(Array.isArray(s)&&b){const f=(...a)=>FunctionPredicate(n,b(...a));f.typeParamNames=s.map(p=>Array.isArray(p)?p[0]:p);f.description=n;f.__runtimeType=true;return f}const spec=typeof s==='function'?{}:s||{};return{description:n,params:spec.params||{},returns:spec.returns,returnContract:spec.returnContract||'assertReturns',check:v=>typeof v==='function',__runtimeType:true}}"),ee&&A.push("function Enum(d,m){const vals=typeof m==='object'?Object.values(m):[];return{description:d,check:v=>vals.includes(v),values:vals,__runtimeType:true}}"),ce&&A.push("function Union(d,...v){const vals=v.flat();return{description:d,check:x=>vals.includes(x),values:vals,__runtimeType:true}}"),Gt&&A.push("function toBool(v){if(v instanceof Boolean||v instanceof Number||v instanceof String)return Boolean(v.valueOf());return Boolean(v)}"),jn&&(E||A.push("class MonadicError extends Error{constructor(m,p,e,a,c,r){super(m);this.name='MonadicError';this.path=p;this.expected=e;this.actual=a;this.callStack=c;this.reason=r}}",`function typeError(p,e,v,r){const a=v===null?'null':typeof v;const m=r?'Expected '+e+" for '"+p+"': "+r:'Expected '+e+" for '"+p+"', got "+a;const err=new MonadicError(m,p,e,a,undefined,r);const c=globalThis.__tjs?.getConfig?.();if(c?.logTypeErrors)console.error('[TJS TypeError] '+err.message);if(c?.throwTypeErrors)throw err;return err}`,"function isMonadicError(v){return v instanceof Error&&v.name==='MonadicError'&&'path' in v}"),A.push(`function checkFnShape(fn,expectedParams,expectedReturn,path){if(typeof fn!=='function')return fn;const meta=fn.__tjs;if(!meta||!meta.params)return fn;const entries=Object.entries(meta.params);for(let i=0;i<expectedParams.length;i++){const e=expectedParams[i];if(e==='any')continue;const a=entries[i];if(!a)continue;const ak=a[1]&&a[1].type&&a[1].type.kind;if(!ak||ak==='any')continue;if(ak!==e)return new MonadicError("Expected (...arg"+i+": "+e+", ...) for '"+path+"', but callback declares arg"+i+" as "+ak,path+"(arg"+i+")",e,ak)}if(expectedReturn!=='any'&&meta.returns){const ar=(meta.returns.type&&meta.returns.type.kind)||meta.returns.kind;if(ar&&ar!=='any'&&ar!==expectedReturn)return new MonadicError("Expected callback returning "+expectedReturn+" for '"+path+"', but callback returns "+ar,path+"(return)",expectedReturn,ar)}return fn}`)),ot&&(E||A.push("class MonadicError extends Error{constructor(m,p,e,a,c,r){super(m);this.name='MonadicError';this.path=p;this.expected=e;this.actual=a;this.callStack=c;this.reason=r}}",`function typeError(p,e,v,r){const a=v===null?'null':typeof v;const m=r?'Expected '+e+" for '"+p+"': "+r:'Expected '+e+" for '"+p+"', got "+a;const err=new MonadicError(m,p,e,a,undefined,r);const c=globalThis.__tjs?.getConfig?.();if(c?.logTypeErrors)console.error('[TJS TypeError] '+err.message);if(c?.throwTypeErrors)throw err;return err}`,"function isMonadicError(v){return v instanceof Error&&v.name==='MonadicError'&&'path' in v}"),A.push("function bang(o,p){if(o===null||o===undefined)return typeError('bang.'+p,'non-null',o);if(isMonadicError(o))return o;return o[p]}"));let W=A.length>0?A.join(`;
|
|
357
|
+
`)+`;
|
|
358
|
+
`:"",V=[];E&&V.push("typeError","isMonadicError"),$&&V.push("pushStack","popStack","getStack"),M&&V.push("Eq"),F&&V.push("NotEq"),N&&V.push("TypeOf"),C&&V.push("Is","tjsEquals"),I&&V.push("IsNot"),U&&V.push("Type"),J&&V.push("Generic"),X&&V.push("FunctionPredicate"),ee&&V.push("Enum"),ce&&V.push("Union"),Gt&&V.push("toBool"),jn&&(V.push("checkFnShape"),E||V.push("typeError","isMonadicError")),ot&&(V.push("bang"),E||V.push("typeError","isMonadicError"));let ve=V.length>0?`{${V.join(",")}}`:"undefined";x=W+`const __tjs = globalThis.__tjs?.createRuntime?.() ?? ${ve};
|
|
359
|
+
`+x}Ur&&(x=`import { Eval, SafeFunction } from 'tjs-lang';
|
|
360
|
+
`+x);let _t;if(r){let A=Li(e);_t=Vi(l,p,A,x,a,S.extensions);let W=_t.filter(V=>!V.passed&&!V.inconclusive);if(W.length>0&&r===!0){let V=W.map(ve=>{if(ve.isSignatureTest)return` Function signature example is inconsistent:
|
|
361
|
+
${ve.error}`;let Me=ve.line?` (line ${ve.line})`:"";return` Test '${ve.description}'${Me} failed:
|
|
362
|
+
${ve.error}`});throw new Error(`Transpile-time test failures:
|
|
363
|
+
${V.join(`
|
|
364
|
+
`)}`)}}if(r==="only")return{code:"",types:b,metadata:b,testResults:_t,testCount:_t?.length};let Wr;if(S.wasmBlocks.length>0){let A=Ji(S.wasmBlocks);A.code&&(x=A.code+`
|
|
365
|
+
`+x),Wr=A.results}return{code:x,types:b,metadata:b,warnings:i.length>0?i:void 0,testRunner:l.length>0?f:void 0,testCount:l.length>0?l.length:void 0,testResults:_t,wasmCompiled:Wr}}function Nu(e){let t=[];for(let n of e.body)n.type==="FunctionDeclaration"?t.push(n):(n.type==="ExportNamedDeclaration"&&n.declaration?.type==="FunctionDeclaration"||n.type==="ExportDefaultDeclaration"&&n.declaration?.type==="FunctionDeclaration")&&t.push(n.declaration);return t}function Wt(e){let t={kind:e.kind};return e.nullable&&(t.nullable=!0),e.items&&(t.items=Wt(e.items)),e.shape&&(t.shape=Object.fromEntries(Object.entries(e.shape).map(([n,r])=>[n,Wt(r)]))),e.members&&(t.members=e.members.map(Wt)),t}function Ru(e,t,n={},r={}){let s={};for(let[i,o]of Object.entries(t.params))s[i]={type:Wt(o.type),required:o.required},o.default!==void 0&&(s[i].default=o.default),o.description&&(s[i].description=o.description);let a={params:s};if(t.returns&&(a.returns={type:Wt(t.returns)},r.returnDefaults&&(a.returns.defaults=r.returnDefaults),n.returnSafety==="safe"?a.safeReturn=!0:n.returnSafety==="unsafe"&&(a.unsafeReturn=!0)),t.description&&(a.description=t.description),n.unsafe&&(a.unsafe=!0),n.safe&&(a.safe=!0),r.source){let{file:i,line:o}=r.source;a.source=`${i}:${o}`}return`${e}.__tjs = ${JSON.stringify(a,null,2)}`}function kn(e,t){let n;switch(t.kind){case"string":n=`typeof ${e} !== 'string'`;break;case"number":n=`typeof ${e} !== 'number'`;break;case"integer":n=`(typeof ${e} !== 'number' || !Number.isInteger(${e}))`;break;case"non-negative-integer":n=`(typeof ${e} !== 'number' || !Number.isInteger(${e}) || ${e} < 0)`;break;case"boolean":n=`typeof ${e} !== 'boolean'`;break;case"null":return`${e} !== null`;case"undefined":return`${e} !== undefined`;case"array":{let r=t.items&&t.items.kind!=="any"?kn("__a",t.items):null;r?n=`(!Array.isArray(${e}) || ${e}.some(__a => ${r}))`:n=`!Array.isArray(${e})`;break}case"object":n=`(typeof ${e} !== 'object' || ${e} === null || Array.isArray(${e}))`;break;case"function":n=`typeof ${e} !== 'function'`;break;case"union":{let r=t.members.map(s=>kn(e,s)).filter(s=>s!==null);if(r.length===0)return null;n=`(${r.join(" && ")})`;break}case"any":return null;default:return null}return n&&t.nullable&&(n=`(${e} !== null && ${n})`),n}var Gi=new Set(["string","number","integer","non-negative-integer","boolean","function","any","undefined","null","object"]);function Mu(e,t,n){let r=t.params??[],s=t.returns??{kind:"any"},a=r.map(c=>c.type?.kind),i=a.every(c=>c&&Gi.has(c))&&Gi.has(s.kind),o=a.some(c=>c!=="any")||s.kind!=="any";if(!i||!o)return null;let u=JSON.stringify(a);return`if (typeof ${e} === 'function') ${e} = __tjs.checkFnShape(${e}, ${u}, '${s.kind}', '${n}');`}function $n(e,t={}){let{ast:n,returnType:r,originalSource:s,requiredParams:a}=Qe(e,{filename:t.filename,colonShorthand:!0,vmTarget:!0}),{entry:i,helpers:o}=ci(n,t.filename),{ast:u,signature:c,warnings:l}=Xn(i,s,r,t,a,o.size>0?o:void 0);return{ast:u,signature:c,warnings:l}}function Ou(e,...t){if(typeof e=="string")return $n(e).ast;let n=e.reduce((r,s,a)=>r+s+(t[a]!==void 0?String(t[a]):""),"");return $n(n).ast}function Bu(e,t,n){let{ast:r,signature:s}=$n(e),a=async i=>(await t.run(r,i,n)).result;return a.signature=s,a.ast=r,a}function Tn(e){switch(e.kind){case"string":return{type:"string"};case"number":return{type:"number"};case"boolean":return{type:"boolean"};case"null":return{type:"null"};case"array":return{type:"array",items:e.items?Tn(e.items):{}};case"object":return e.shape?{type:"object",properties:Object.fromEntries(Object.entries(e.shape).map(([t,n])=>[t,Tn(n)]))}:{type:"object"};case"union":return e.members?{anyOf:e.members.map(Tn)}:{};default:return{}}}function Fu(e){return Object.entries(e).map(([t,n])=>{let r=n.signature,s={},a=[];for(let[i,o]of Object.entries(r.parameters))s[i]=Tn(o.type),o.description&&(s[i].description=o.description),o.required&&a.push(i);return{type:"function",function:{name:t,description:r.description,parameters:{type:"object",properties:s,required:a}}}})}function Du(e,t,...n){if(typeof e=="string")return En(e,t);let r=t!==void 0?[t,...n]:n,s=e.reduce((a,i,o)=>a+i+(r[o]!==void 0?String(r[o]):""),"");return En(s)}var Lu=/\.[mc]?js$/i,Vu=/\.[mc]?ts$/i,qu=/\.tjs$/i;function Ki(e){return qu.test(e)?"tjs":Lu.test(e)?"js":Vu.test(e)?"ts":"tjs"}function Uu(e){return Ki(e)==="js"?"js":"tjs"}function $e(e,t,n,r,s){n||(n=T),(function a(i,o,u){var c=u||i.type;n[c](i,o,a),t[c]&&t[c](i,o)})(e,r,s)}function Zi(e,t,n,r,s){var a=[];n||(n=T),(function i(o,u,c){var l=c||o.type,p=o!==a[a.length-1];p&&a.push(o),n[l](o,u,i),t[l]&&t[l](o,u||a,a),p&&a.pop()})(e,r,s)}function Dr(e,t,n){n(e,t)}function at(e,t,n){}var T={};T.Program=T.BlockStatement=T.StaticBlock=function(e,t,n){for(var r=0,s=e.body;r<s.length;r+=1){var a=s[r];n(a,t,"Statement")}};T.Statement=Dr;T.EmptyStatement=at;T.ExpressionStatement=T.ParenthesizedExpression=T.ChainExpression=function(e,t,n){return n(e.expression,t,"Expression")};T.IfStatement=function(e,t,n){n(e.test,t,"Expression"),n(e.consequent,t,"Statement"),e.alternate&&n(e.alternate,t,"Statement")};T.LabeledStatement=function(e,t,n){return n(e.body,t,"Statement")};T.BreakStatement=T.ContinueStatement=at;T.WithStatement=function(e,t,n){n(e.object,t,"Expression"),n(e.body,t,"Statement")};T.SwitchStatement=function(e,t,n){n(e.discriminant,t,"Expression");for(var r=0,s=e.cases;r<s.length;r+=1){var a=s[r];n(a,t)}};T.SwitchCase=function(e,t,n){e.test&&n(e.test,t,"Expression");for(var r=0,s=e.consequent;r<s.length;r+=1){var a=s[r];n(a,t,"Statement")}};T.ReturnStatement=T.YieldExpression=T.AwaitExpression=function(e,t,n){e.argument&&n(e.argument,t,"Expression")};T.ThrowStatement=T.SpreadElement=function(e,t,n){return n(e.argument,t,"Expression")};T.TryStatement=function(e,t,n){n(e.block,t,"Statement"),e.handler&&n(e.handler,t),e.finalizer&&n(e.finalizer,t,"Statement")};T.CatchClause=function(e,t,n){e.param&&n(e.param,t,"Pattern"),n(e.body,t,"Statement")};T.WhileStatement=T.DoWhileStatement=function(e,t,n){n(e.test,t,"Expression"),n(e.body,t,"Statement")};T.ForStatement=function(e,t,n){e.init&&n(e.init,t,"ForInit"),e.test&&n(e.test,t,"Expression"),e.update&&n(e.update,t,"Expression"),n(e.body,t,"Statement")};T.ForInStatement=T.ForOfStatement=function(e,t,n){n(e.left,t,"ForInit"),n(e.right,t,"Expression"),n(e.body,t,"Statement")};T.ForInit=function(e,t,n){e.type==="VariableDeclaration"?n(e,t):n(e,t,"Expression")};T.DebuggerStatement=at;T.FunctionDeclaration=function(e,t,n){return n(e,t,"Function")};T.VariableDeclaration=function(e,t,n){for(var r=0,s=e.declarations;r<s.length;r+=1){var a=s[r];n(a,t)}};T.VariableDeclarator=function(e,t,n){n(e.id,t,"Pattern"),e.init&&n(e.init,t,"Expression")};T.Function=function(e,t,n){e.id&&n(e.id,t,"Pattern");for(var r=0,s=e.params;r<s.length;r+=1){var a=s[r];n(a,t,"Pattern")}n(e.body,t,e.expression?"Expression":"Statement")};T.Pattern=function(e,t,n){e.type==="Identifier"?n(e,t,"VariablePattern"):e.type==="MemberExpression"?n(e,t,"MemberPattern"):n(e,t)};T.VariablePattern=at;T.MemberPattern=Dr;T.RestElement=function(e,t,n){return n(e.argument,t,"Pattern")};T.ArrayPattern=function(e,t,n){for(var r=0,s=e.elements;r<s.length;r+=1){var a=s[r];a&&n(a,t,"Pattern")}};T.ObjectPattern=function(e,t,n){for(var r=0,s=e.properties;r<s.length;r+=1){var a=s[r];a.type==="Property"?(a.computed&&n(a.key,t,"Expression"),n(a.value,t,"Pattern")):a.type==="RestElement"&&n(a.argument,t,"Pattern")}};T.Expression=Dr;T.ThisExpression=T.Super=T.MetaProperty=at;T.ArrayExpression=function(e,t,n){for(var r=0,s=e.elements;r<s.length;r+=1){var a=s[r];a&&n(a,t,"Expression")}};T.ObjectExpression=function(e,t,n){for(var r=0,s=e.properties;r<s.length;r+=1){var a=s[r];n(a,t)}};T.FunctionExpression=T.ArrowFunctionExpression=T.FunctionDeclaration;T.SequenceExpression=function(e,t,n){for(var r=0,s=e.expressions;r<s.length;r+=1){var a=s[r];n(a,t,"Expression")}};T.TemplateLiteral=function(e,t,n){for(var r=0,s=e.quasis;r<s.length;r+=1){var a=s[r];n(a,t)}for(var i=0,o=e.expressions;i<o.length;i+=1){var u=o[i];n(u,t,"Expression")}};T.TemplateElement=at;T.UnaryExpression=T.UpdateExpression=function(e,t,n){n(e.argument,t,"Expression")};T.BinaryExpression=T.LogicalExpression=function(e,t,n){n(e.left,t,"Expression"),n(e.right,t,"Expression")};T.AssignmentExpression=T.AssignmentPattern=function(e,t,n){n(e.left,t,"Pattern"),n(e.right,t,"Expression")};T.ConditionalExpression=function(e,t,n){n(e.test,t,"Expression"),n(e.consequent,t,"Expression"),n(e.alternate,t,"Expression")};T.NewExpression=T.CallExpression=function(e,t,n){if(n(e.callee,t,"Expression"),e.arguments)for(var r=0,s=e.arguments;r<s.length;r+=1){var a=s[r];n(a,t,"Expression")}};T.MemberExpression=function(e,t,n){n(e.object,t,"Expression"),e.computed&&n(e.property,t,"Expression")};T.ExportNamedDeclaration=T.ExportDefaultDeclaration=function(e,t,n){e.declaration&&n(e.declaration,t,e.type==="ExportNamedDeclaration"||e.declaration.id?"Statement":"Expression"),e.source&&n(e.source,t,"Expression")};T.ExportAllDeclaration=function(e,t,n){e.exported&&n(e.exported,t),n(e.source,t,"Expression")};T.ImportDeclaration=function(e,t,n){for(var r=0,s=e.specifiers;r<s.length;r+=1){var a=s[r];n(a,t)}n(e.source,t,"Expression")};T.ImportExpression=function(e,t,n){n(e.source,t,"Expression")};T.ImportSpecifier=T.ImportDefaultSpecifier=T.ImportNamespaceSpecifier=T.Identifier=T.PrivateIdentifier=T.Literal=at;T.TaggedTemplateExpression=function(e,t,n){n(e.tag,t,"Expression"),n(e.quasi,t,"Expression")};T.ClassDeclaration=T.ClassExpression=function(e,t,n){return n(e,t,"Class")};T.Class=function(e,t,n){e.id&&n(e.id,t,"Pattern"),e.superClass&&n(e.superClass,t,"Expression"),n(e.body,t)};T.ClassBody=function(e,t,n){for(var r=0,s=e.body;r<s.length;r+=1){var a=s[r];n(a,t)}};T.MethodDefinition=T.PropertyDefinition=T.Property=function(e,t,n){e.computed&&n(e.key,t,"Expression"),e.value&&n(e.value,t,"Expression")};var Wu=new Set(["parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","String","Number","Boolean","Array","Object"]),Ju=new Set(["Math","JSON","Object","Array","String","Number"]),zu=new Set(["Math.random","Date.now"]),Gu=new Set(["startsWith","endsWith","includes","indexOf","lastIndexOf","slice","substring","substr","toLowerCase","toUpperCase","trim","trimStart","trimEnd","split","replace","replaceAll","match","matchAll","charAt","charCodeAt","codePointAt","padStart","padEnd","repeat","concat","at","normalize","search","localeCompare","every","some","map","filter","reduce","reduceRight","find","findIndex","findLast","findLastIndex","flat","flatMap","join","keys","entries","values","forEach","test","exec","toFixed","toPrecision","toString","valueOf","hasOwnProperty"]),Lr=["fetch","XMLHttpRequest","WebSocket","Date","console","setTimeout","setInterval","requestAnimationFrame","queueMicrotask","localStorage","sessionStorage","indexedDB","document","window","globalThis","self","process","require","eval","Function","import","crypto","performance","navigator"];function Hu(e){let t=new Set(Lr);for(let[n,r]of Object.entries(e))r?.effects==="io"&&t.add(r.op??n);return t}function zt(e,t={}){let n=t.effectful??new Set(Lr),r;try{r=je(e,{ecmaVersion:"latest",locations:!0})}catch(i){return{safe:!1,predicates:[],diagnostics:[{predicate:"<source>",message:`parse error: ${i.message}`,line:i.loc?.line??0,column:i.loc?.column??0}]}}let s=new Set(t.knownPredicates??[]);for(let i of r.body)i.type==="FunctionDeclaration"&&i.id&&s.add(i.id.name);let a=[];for(let i of r.body){if(i.type!=="FunctionDeclaration"||!i.id)continue;let o=i.id.name,u=(l,p)=>a.push({predicate:o,message:l,line:p?.loc?.start?.line??0,column:p?.loc?.start?.column??0}),c=l=>u("loops are not allowed \u2014 iterate with recursion or array methods (every/some/map/filter/reduce) so work stays fuel-bounded",l);$e(i,{AwaitExpression(l){u("`await` not allowed \u2014 predicates must be synchronous",l)},NewExpression(l){u("`new` not allowed in a predicate (non-pure construction)",l)},WhileStatement:c,DoWhileStatement:c,ForStatement:c,ForInStatement:c,ForOfStatement:c,CallExpression(l){let p=l.callee;if(p.type==="Identifier"){let f=p.name;n.has(f)?u(`'${f}' is effectful \u2014 not allowed in a predicate`,p):s.has(f)||Wu.has(f)||u(`unknown reference '${f}' \u2014 not a predicate or pure builtin`,p);return}if(p.type==="MemberExpression"&&!p.computed){let f=p.property.name,d=p.object;d.type==="Identifier"&&n.has(d.name)?u(`'${d.name}.${f}' is effectful`,p):d.type==="Identifier"&&Ju.has(d.name)?zu.has(`${d.name}.${f}`)&&u(`'${d.name}.${f}' is nondeterministic`,p):Gu.has(f)||u(`method '.${f}()' is not a known pure method`,p.property);return}u("unsupported call form in a predicate",p)}})}return{safe:a.length===0,predicates:[...s],diagnostics:a}}function Yi(e){return e.map(t=>` ${t.predicate} (${t.line}:${t.column}): ${t.message}`).join(`
|
|
366
|
+
`)}var Cn=e=>e&&e.type==="Literal"&&typeof e.value=="string";function Ku(e,t={}){let n;try{n=je(e,{ecmaVersion:"latest"})}catch{return[]}let r=new Set,s=new Set;$e(n,{BinaryExpression(u){(u.operator==="=="||u.operator==="===")&&(Cn(u.left)&&r.add(u.left.value),Cn(u.right)&&r.add(u.right.value))},ArrayExpression(u){for(let c of u.elements)Cn(c)&&r.add(c.value)},CallExpression(u){let c=u.callee;if(c.type!=="MemberExpression"||c.computed)return;let l=c.property.name,p=u.arguments[0];Cn(p)&&l==="startsWith"&&s.add(p.value)}});let a=null;if(t.validate!==!1){let u=zt(e,t);if(u.safe&&u.predicates.length){let c=t.entry??u.predicates[u.predicates.length-1];try{let p=An(e,[c],t)[c];a=f=>{try{return p(f)===!0}catch{return!1}}}catch{a=null}}}let i=[];for(let u of r)(!a||a(u))&&i.push({value:u,kind:"value"});for(let u of s)i.push({value:u,kind:"stub"});let o=i;if(t.prefix){let u=t.prefix;o=i.filter(c=>c.value.startsWith(u)||c.kind==="stub"&&u.startsWith(c.value))}return o.sort((u,c)=>(u.kind===c.kind?0:u.kind==="value"?-1:1)||u.value.localeCompare(c.value)),t.limit?o.slice(0,t.limit):o}var Jt=class extends Error{constructor(t){super(`predicate exceeded its fuel budget (${t})`),this.name="PredicateFuelExhausted"}};function Zu(e){let t=je(e,{ecmaVersion:"latest"}),n=[],r=a=>n.push([a.body.start+1,"__fuel();"]);$e(t,{FunctionDeclaration:r,FunctionExpression:r,ArrowFunctionExpression(a){a.body.type==="BlockStatement"?n.push([a.body.start+1,"__fuel();"]):(n.push([a.body.start,"(__fuel(), "]),n.push([a.body.end,")"]))}}),n.sort((a,i)=>i[0]-a[0]);let s=e;for(let[a,i]of n)s=s.slice(0,a)+i+s.slice(a);return s}function An(e,t,n={}){let r=zt(e,n);if(!r.safe)throw new Error(`Not predicate-safe:
|
|
367
|
+
${Yi(r.diagnostics)}`);let s=n.fuel??1e6,a=Zu(e),i=Lr.filter(f=>f!=="import"&&f!=="eval"&&f!=="arguments"),o=new Function("__fuel",...i,`"use strict";
|
|
368
|
+
${a}
|
|
369
|
+
;return { ${t.join(", ")} };`),u=0,l=o(()=>{if(--u<0)throw new Jt(s)},...i.map(()=>{})),p={};for(let f of t){let d=l[f];p[f]=(...g)=>{u=s;try{return d(...g)}catch(y){throw y instanceof RangeError&&/stack/i.test(y.message)?new Jt(s):y}}}return p}var Xi=e=>e===null?"null":Array.isArray(e)?"array":typeof e;function Qu(e,t){return t==="integer"?typeof e=="number"&&Number.isInteger(e):Xi(e)===t}function ea(e,t={}){let{ignorePredicates:n,...r}=t,s=new Map,a=o=>{if(o.$predicate&&!n&&!s.has(o.$predicate)){let u=o.$predicate,c=zt(u,r).predicates,l=c[c.length-1];if(!l)throw new Error("$predicate must declare at least one function");let p=An(u,[l],r);s.set(u,p[l])}if(o.properties)for(let u of Object.values(o.properties))a(u);o.items&&a(o.items)};a(e);let i=(o,u,c,l)=>{if(o.type&&!Qu(u,o.type)){l.push({path:c||"/",message:`expected ${o.type}, got ${Xi(u)}`});return}if(o.type==="object"&&o.properties&&u&&typeof u=="object"){let p=u;for(let f of o.required??[])f in p||l.push({path:`${c}/${f}`,message:`missing required '${f}'`});for(let[f,d]of Object.entries(o.properties))f in p&&i(d,p[f],`${c}/${f}`,l)}o.type==="array"&&o.items&&Array.isArray(u)&&u.forEach((p,f)=>i(o.items,p,`${c}/${f}`,l)),o.$predicate&&!n&&(s.get(o.$predicate)(u)||l.push({path:c||"/",message:`failed predicate at ${c||"/"}`}))};return o=>{let u=[];return i(e,o,"",u),{valid:u.length===0,errors:u}}}function Yu(e,t,n){return ea(e,n)(t)}function ta(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?"array":typeof e}function Pn(e){return ye.infer(e)}function Vr(e){return Pn(e)}Vr.type=ta;Vr.infer=Pn;var Xu=new Proxy(Vr,{get(e,t){return t==="type"?ta:t==="infer"?Pn:ye[t]},apply(e,t,n){return Pn(n[0])}});var ec={unusedVariables:!0,undefinedVariables:!0,unreachableCode:!0,noExplicitNew:!0};function tc(e,t={}){let n={...ec,...t},r=[],s,a=new Map,i;try{let l=Qe(e,{filename:n.filename,colonShorthand:!0});s=l.ast,a=l.letAnnotations,i=l.tjsModes.tjsSafeAssign}catch(l){return{diagnostics:[{severity:"error",message:l.message,line:l.loc?.line,column:l.loc?.column,rule:"parse-error"}],valid:!1}}let o=n.safeAssign!==void 0?n.safeAssign:i,u=n.strict?"error":"warning",c=[na()];if(Zi(s,{FunctionDeclaration(l,p,f){let d=na();c.push(d);for(let g of l.params)nc(d,g,"parameter");l.id&&(c[c.length-2]||c[0]).declarations.set(l.id.name,{node:l.id,kind:"function",used:!1})},VariableDeclaration(l){let p=c[c.length-1];for(let f of l.declarations)f.id.type==="Identifier"&&p.declarations.set(f.id.name,{node:f.id,kind:l.kind,used:!1})}}),$e(s,{Identifier(l){for(let p=c.length-1;p>=0;p--){let f=c[p].declarations.get(l.name);if(f){f.used=!0;break}}}}),n.unusedVariables)for(let l of c)for(let[p,f]of l.declarations)p.startsWith("_")||!f.used&&f.kind!=="function"&&r.push({severity:"warning",message:`'${p}' is declared but never used`,line:f.node.loc?.start?.line,column:f.node.loc?.start?.column,rule:"no-unused-vars"});if(n.unreachableCode&&$e(s,{BlockStatement(l){let p=!1;for(let f of l.body){if(p){r.push({severity:"warning",message:"Unreachable code after return statement",line:f.loc?.start?.line,column:f.loc?.start?.column,rule:"no-unreachable"});break}f.type==="ReturnStatement"&&(p=!0)}}}),o){let l=new Set;$e(s,{VariableDeclaration(p){if(p.kind==="let")for(let f of p.declarations){if(f.id.type!=="Identifier")continue;let d=f.id.name,g=a.has(d),y=f.init;(g||y&&!qr(y))&&l.add(d)}}}),$e(s,{VariableDeclaration(p){if(p.kind==="let")for(let f of p.declarations){if(f.id.type!=="Identifier")continue;let d=f.id.name;a.has(d)||(f.init?qr(f.init)&&r.push({severity:u,message:`'let ${d}' is initialized to ${ra(f.init)} with no type annotation. Annotate (let ${d}: <example>) to record the intended type.`,line:f.loc?.start?.line,column:f.loc?.start?.column,rule:"safe-assign-let-needs-type"}):r.push({severity:u,message:`'let ${d}' has no initializer or type annotation. Add an initializer (let ${d} = ...) or annotate (let ${d}: <example>).`,line:f.loc?.start?.line,column:f.loc?.start?.column,rule:"safe-assign-let-needs-type"}))}}}),$e(s,{AssignmentExpression(p){if(p.operator!=="="||p.left.type!=="Identifier")return;let f=p.left.name;l.has(f)&&qr(p.right)&&r.push({severity:u,message:`Cannot assign ${ra(p.right)} to typed let '${f}'.`,line:p.loc?.start?.line,column:p.loc?.start?.column,rule:"safe-assign-no-nullish"})}})}return n.noExplicitNew&&$e(s,{NewExpression(l){let p="class";l.callee.type==="Identifier"?p=l.callee.name:l.callee.type==="MemberExpression"&&l.callee.property.type==="Identifier"&&(p=l.callee.property.name),r.push({severity:"warning",message:`Unnecessary 'new' keyword. In TJS, classes are callable without 'new': ${p}(...) instead of new ${p}(...)`,line:l.loc?.start?.line,column:l.loc?.start?.column,rule:"no-explicit-new"})}}),{diagnostics:r,valid:r.filter(l=>l.severity==="error").length===0}}function na(){return{declarations:new Map}}function qr(e){return e?e.type==="Identifier"&&e.name==="undefined"||e.type==="Literal"&&e.value===null||e.type==="UnaryExpression"&&e.operator==="void":!1}function ra(e){return e.type==="Identifier"?"undefined":e.type==="Literal"&&e.value===null?"null":e.type==="UnaryExpression"&&e.operator==="void"?"void <expr> (undefined)":"a nullish value"}function nc(e,t,n){t.type==="Identifier"?e.declarations.set(t.name,{node:t,kind:n,used:!1}):t.type==="AssignmentPattern"&&t.left.type==="Identifier"&&e.declarations.set(t.left.name,{node:t.left,kind:n,used:!1})}export{Jt as PredicateFuelExhausted,Xu as Schema,Ve as TJS_VERSION,Ou as ajs,mi as assertFunction,rt as checkType,An as compilePredicate,ea as compilePredicateSchema,Bu as createAgent,Uu as dialectForFilename,Hu as effectfulFromAtoms,Ko as emitRuntimeWrapper,Re as error,gi as expectFunction,Ie as extractLiteralValue,Nt as extractTDoc,tr as extractTests,Yi as formatPredicateDiagnostics,Fu as getToolDefinitions,ue as inferTypeFromValue,Ar as installRuntime,qe as isError,tc as lint,Qe as parse,Ge as parseParameter,li as parseReturnType,hn as preprocess,et as runtime,Ki as sourceKindForFilename,Ku as suggest,Io as testUtils,Du as tjs,Xn as transformFunction,$n as transpile,En as transpileToJS,yt as typeOf,Yn as typeToString,$r as validateArgs,Yu as validatePredicateSchema,zt as verifyPredicate,Cr as wrap};
|
|
370
|
+
//# sourceMappingURL=tjs-browser.js.map
|