UNPKG

@logicflow/engine

Version:

a process engine for javascript

1 lines 78.6 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Engine={})}(this,(function(exports){"use strict";function __awaiter(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}var ErrorCode,WarningCode;"function"==typeof SuppressedError&&SuppressedError,exports.ErrorCode=void 0,ErrorCode=exports.ErrorCode||(exports.ErrorCode={}),ErrorCode[ErrorCode.NONE_START_NODE=1e3]="NONE_START_NODE",ErrorCode[ErrorCode.NONE_NODE_ID=1001]="NONE_NODE_ID",ErrorCode[ErrorCode.NO_DOCUMENT_BODY=2001]="NO_DOCUMENT_BODY",exports.WarningCode=void 0,WarningCode=exports.WarningCode||(exports.WarningCode={}),WarningCode[WarningCode.NONE_START_NODE_IN_DATA=2e3]="NONE_START_NODE_IN_DATA",WarningCode[WarningCode.START_NODE_INCOMING=2001]="START_NODE_INCOMING",WarningCode[WarningCode.EXPRESSION_EXEC_ERROR=3e3]="EXPRESSION_EXEC_ERROR";const errorMsgMapCn={[exports.ErrorCode.NONE_START_NODE]:"未找到入度为0的节点",[exports.ErrorCode.NONE_NODE_ID]:"流程数据中存在没有此节点",[exports.ErrorCode.NO_DOCUMENT_BODY]:"找不到document.body, 请在DOM加载完成后再执行"},warningMsgMapCn={[exports.WarningCode.NONE_START_NODE_IN_DATA]:"初始化数据中未找到入度为0的节点",[exports.WarningCode.START_NODE_INCOMING]:"开始节点不允许被连入",[exports.WarningCode.EXPRESSION_EXEC_ERROR]:"表达式执行异常"},getErrorMsg=e=>`error[${e}]: ${errorMsgMapCn[e]}`,getWarningMsg=e=>`warning[${e}]: ${warningMsgMapCn[e]}`,BASE_START_NODE="start",EVENT_INSTANCE_COMPLETE="instance:complete",EVENT_INSTANCE_INTERRUPTED="instance:interrupted",EVENT_INSTANCE_ERROR="instance:error";var FlowStatus,ActionStatus;function parseHexToInt(e){return!e.match(/[^a-f0-9]/i)?parseInt(e,16):NaN}function validateAndParseHex(e,t,n){const r=parseHexToInt(e);if(Number.isNaN(r)||void 0!==n&&n!==e.length)throw new SyntaxError(t+": "+e);return r}function parseHexadecimalCode(e){const t=validateAndParseHex(e,"Malformed Hexadecimal",2);return String.fromCharCode(t)}function parseUnicodeCode(e,t){const n=validateAndParseHex(e,"Malformed Unicode",4);if(void 0!==t){const e=validateAndParseHex(t,"Malformed Unicode",4);return String.fromCharCode(n,e)}return String.fromCharCode(n)}function isCurlyBraced(e){return"{"===e.charAt(0)&&"}"===e.charAt(e.length-1)}function parseUnicodeCodePointCode(e){if(!isCurlyBraced(e))throw new SyntaxError("Malformed Unicode: +"+e);const t=validateAndParseHex(e.slice(1,-1),"Malformed Unicode");try{return String.fromCodePoint(t)}catch(e){throw e instanceof RangeError?new SyntaxError("Code Point Limit:"+t):e}}exports.FlowStatus=void 0,FlowStatus=exports.FlowStatus||(exports.FlowStatus={}),FlowStatus.COMPLETED="completed",FlowStatus.INTERRUPTED="interrupted",FlowStatus.RUNNING="running",FlowStatus.PENDING="pending",FlowStatus.ERROR="error",exports.ActionStatus=void 0,ActionStatus=exports.ActionStatus||(exports.ActionStatus={}),ActionStatus.SUCCESS="success",ActionStatus.ERROR="error",ActionStatus.INTERRUPTED="interrupted";const singleCharacterEscapes=new Map([["b","\b"],["f","\f"],["n","\n"],["r","\r"],["t","\t"],["v","\v"],["0","\0"]]);function parseSingleCharacterCode(e){return singleCharacterEscapes.get(e)||e}const escapeMatch=/\\(?:(\\)|x([\s\S]{0,2})|u(\{[^}]*\}?)|u([\s\S]{4})\\u([^{][\s\S]{0,3})|u([\s\S]{0,4})|([0-3]?[0-7]{1,2})|([\s\S])|$)/g;function unraw(e){return e.replace(escapeMatch,(function(e,t,n,r,i,o,s,a,c){if(void 0!==t)return"\\";if(void 0!==n)return parseHexadecimalCode(n);if(void 0!==r)return parseUnicodeCodePointCode(r);if(void 0!==i)return parseUnicodeCode(i,o);if(void 0!==s)return parseUnicodeCode(s);if("0"===a)return"\0";if(void 0!==a)throw new SyntaxError("Octal Deprecation: "+a);if(void 0!==c)return parseSingleCharacterCode(c);throw new SyntaxError("End of string")}))}function createLisp(e){return[e.op,e.a,e.b]}let lispTypes=new Map;class ParseError extends Error{constructor(e,t){super(e+": "+t.substring(0,40)),this.code=t}}const inlineIfElse=/^:/,elseIf=/^else(?![\w\$])/,ifElse=/^if(?![\w\$])/,space=/^\s/;let expectTypes={splitter:{types:{opHigh:/^(\/|\*\*|\*(?!\*)|\%)(?!\=)/,op:/^(\+(?!(\+))|\-(?!(\-)))(?!\=)/,comparitor:/^(<=|>=|<(?!<)|>(?!>)|!==|!=(?!\=)|===|==)/,boolOp:/^(&&|\|\||instanceof(?![\w\$])|in(?![\w\$]))/,bitwise:/^(&(?!&)|\|(?!\|)|\^|<<|>>(?!>)|>>>)(?!\=)/},next:["modifier","value","prop","incrementerBefore"]},inlineIf:{types:{inlineIf:/^\?(?!\.(?!\d))/},next:["expEnd"]},assignment:{types:{assignModify:/^(\-=|\+=|\/=|\*\*=|\*=|%=|\^=|\&=|\|=|>>>=|>>=|<<=)/,assign:/^(=)(?!=)/},next:["modifier","value","prop","incrementerBefore"]},incrementerBefore:{types:{incrementerBefore:/^(\+\+|\-\-)/},next:["prop"]},expEdge:{types:{call:/^(\?\.)?[\(]/,incrementerAfter:/^(\+\+|\-\-)/},next:["splitter","expEdge","dot","inlineIf","expEnd"]},modifier:{types:{not:/^!/,inverse:/^~/,negative:/^\-(?!\-)/,positive:/^\+(?!\+)/,typeof:/^typeof(?![\w\$])/,delete:/^delete(?![\w\$])/},next:["modifier","value","prop","incrementerBefore"]},dot:{types:{arrayProp:/^(\?\.)?\[/,dot:/^(\?)?\.(?=\s*[a-zA-Z\$\_])/},next:["splitter","assignment","expEdge","dot","inlineIf","expEnd"]},prop:{types:{prop:/^[a-zA-Z\$\_][a-zA-Z\d\$\_]*/},next:["splitter","assignment","expEdge","dot","inlineIf","expEnd"]},value:{types:{createObject:/^\{/,createArray:/^\[/,number:/^(0x[\da-f]+(_[\da-f]+)*|(\d+(_\d+)*(\.\d+(_\d+)*)?|\.\d+(_\d+)*))(e[\+\-]?\d+(_\d+)*)?(n)?(?!\d)/i,string:/^"(\d+)"/,literal:/^`(\d+)`/,regex:/^\/(\d+)\/r(?![\w\$])/,boolean:/^(true|false)(?![\w\$])/,null:/^null(?![\w\$])/,und:/^undefined(?![\w\$])/,arrowFunctionSingle:/^(async\s+)?([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*=>\s*({)?/,arrowFunction:/^(async\s*)?\(\s*((\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*(\s*,\s*(\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)*)?\s*\)\s*=>\s*({)?/,inlineFunction:/^(async\s+)?function(\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)?\s*\(\s*((\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*(\s*,\s*(\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)*)?\s*\)\s*{/,group:/^\(/,NaN:/^NaN(?![\w\$])/,Infinity:/^Infinity(?![\w\$])/,void:/^void(?![\w\$])\s*/,await:/^await(?![\w\$])\s*/,new:/^new(?![\w\$])\s*/},next:["splitter","expEdge","dot","inlineIf","expEnd"]},initialize:{types:{initialize:/^(var|let|const)\s+([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*(=)?/,return:/^return(?![\w\$])/,throw:/^throw(?![\w\$])\s*/},next:["modifier","value","prop","incrementerBefore","expEnd"]},spreadObject:{types:{spreadObject:/^\.\.\./},next:["value","prop"]},spreadArray:{types:{spreadArray:/^\.\.\./},next:["value","prop"]},expEnd:{types:{},next:[]},expFunction:{types:{function:/^(async\s+)?function(\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)\s*\(\s*((\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*(\s*,\s*(\.\.\.)?\s*[a-zA-Z\$_][a-zA-Z\d\$_]*)*)?\s*\)\s*{/},next:["expEdge","expEnd"]},expSingle:{types:{for:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*for\s*\(/,do:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*do(?![\w\$])\s*(\{)?/,while:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*while\s*\(/,loopAction:/^(break|continue)(?![\w\$])\s*([a-zA-Z\$\_][\w\$]*)?/,if:/^((([a-zA-Z\$\_][\w\$]*)\s*:)?\s*)if\s*\(/,try:/^try\s*{/,block:/^{/,switch:/^(([a-zA-Z\$\_][\w\$]*)\s*:)?\s*switch\s*\(/},next:["expEnd"]}},closings={"(":")","[":"]","{":"}","'":"'",'"':'"',"`":"`"};function testMultiple(e,t){let n;for(let r=0;r<t.length;r++){if(n=t[r].exec(e),n)break}return n}class CodeString{constructor(e){this.ref={str:""},e instanceof CodeString?(this.ref=e.ref,this.start=e.start,this.end=e.end):(this.ref.str=e,this.start=0,this.end=e.length)}substring(e,t){if(!this.length)return this;(e=this.start+e)<0&&(e=0),e>this.end&&(e=this.end),(t=void 0===t?this.end:this.start+t)<0&&(t=0),t>this.end&&(t=this.end);const n=new CodeString(this);return n.start=e,n.end=t,n}get length(){const e=this.end-this.start;return e<0?0:e}char(e){if(this.start!==this.end)return this.ref.str[this.start+e]}toString(){return this.ref.str.substring(this.start,this.end)}trimStart(){const e=/^\s+/.exec(this.toString()),t=new CodeString(this);return e&&(t.start+=e[0].length),t}slice(e,t){return e<0&&(e=this.end-this.start+e),e<0&&(e=0),void 0===t&&(t=this.end-this.start),t<0&&(t=this.end-this.start+t),t<0&&(t=0),this.substring(e,t)}trim(){const e=this.trimStart(),t=/\s+$/.exec(e.toString());return t&&(e.end-=t[0].length),e}valueOf(){return this.toString()}}const emptyString=new CodeString(""),okFirstChars=/^[\+\-~ !]/,aNumber=expectTypes.value.types.number,wordReg=/^((if|for|else|while|do|function)(?![\w\$])|[\w\$]+)/,semiColon=/^;/,insertedSemicolons=new WeakMap,quoteCache=new WeakMap;function restOfExp(e,t,n,r,i,o,s={}){if(!t.length)return t;s.words=s.words||[];let a=!0;const c=(n=n||[]).includes(semiColon);c&&(n=n.filter((e=>e!==semiColon)));const l=insertedSemicolons.get(t.ref)||[],d=quoteCache.get(t.ref)||new Map;if(quoteCache.set(t.ref,d),r&&d.has(t.start-1))return t.substring(0,d.get(t.start-1)-t.start);let p,u=!1,f=!1,h="",g=!1,y=!1;for(p=0;p<t.length&&!f;p++){let x=t.char(p);if('"'===r||"'"===r||"`"===r){if("`"!==r||"$"!==x||"{"!==t.char(p+1)||u){if(x===r&&!u)return t.substring(0,p)}else{p+=restOfExp(e,t.substring(p+2),[],"{").length+2}u=!u&&"\\"===x}else if(closings[x]){if(!y&&l[p+t.start]){if(y=!0,c)break;p--,h=";";continue}if(g&&"{"===x&&(g=!1),x===i){f=!0;break}{let n=restOfExp(e,t.substring(p+1),[],x);if(d.set(n.start-1,n.end),p+=n.length+1,a=!1,o){let e;(e=testMultiple(t.substring(p).toString(),o))&&(s.regRes=e,f=!0)}}}else if(r){if(x===closings[r])return t.substring(0,p)}else{let e,r,i=t.substring(p).toString();if(o){let e;if(e=testMultiple(i,o)){s.regRes=e,p++,f=!0;break}}if(r=aNumber.exec(i))p+=r[0].length-1,i=t.substring(p).toString();else if(h!=x){let r;if(";"===x||l[p+t.start]&&!a&&!y){if(c)r=[";"];else if(l[p+t.start]){y=!0,p--,h=";";continue}x=i=";"}else y=!1;r||(r=testMultiple(i,n)),r&&(f=!0),!f&&(e=wordReg.exec(i))&&(g=!0,e[0].length>1&&(s.words.push(e[1]),s.lastAnyWord=e[1],e[2]&&(s.lastWord=e[2])),e[0].length>2&&(p+=e[0].length-2))}if(a&&(okFirstChars.test(i)?f=!1:a=!1),f)break}h=x}if(r)throw new SyntaxError("Unclosed '"+r+"'");return s&&(s.oneliner=g),t.substring(0,p)}restOfExp.next=["splitter","expEnd","inlineIf"];const startingExecpted=["initialize","expSingle","expFunction","value","modifier","prop","incrementerBefore","expEnd"],setLispType=(e,t)=>{e.forEach((e=>{lispTypes.set(e,t)}))},closingsCreate={createArray:/^\]/,createObject:/^\}/,group:/^\)/,arrayProp:/^\]/,call:/^\)/},typesCreate={createArray:12,createObject:22,group:23,arrayProp:19,call:5,prop:1,"?prop":20,"?call":21};setLispType(["createArray","createObject","group","arrayProp","call"],((e,t,n,r,i,o)=>{let s=emptyString,a=[],c=!1,l=r[0].length;const d=l;for(;l<n.length&&!c;)s=restOfExp(e,n.substring(l),[closingsCreate[t],/^,/]),l+=s.length,s.trim().length&&a.push(s),","!==n.char(l)?c=!0:l++;const p=["value","modifier","prop","incrementerBefore","expEnd"];let u,f;switch(t){case"group":case"arrayProp":u=lispifyExpr(e,n.substring(d,l));break;case"call":case"createArray":u=a.map((t=>lispify(e,t,[...p,"spreadArray"])));break;case"createObject":u=a.map((t=>{let n;t=t.trimStart();let r="";if(f=expectTypes.expFunction.types.function.exec("function "+t),f)r=f[2].trimStart(),n=lispify(e,new CodeString("function "+t.toString().replace(r,"")));else{let i=restOfExp(e,t,[/^:/]);r=lispify(e,i,[...p,"spreadObject"]),1===r[0]&&(r=r[2]),n=lispify(e,t.substring(i.length+1))}return createLisp({op:6,a:r,b:n})}))}let h="arrayProp"===t?r[1]?20:1:"call"===t?r[1]?21:5:typesCreate[t];o.lispTree=lispify(e,n.substring(l+1),expectTypes[i].next,createLisp({op:h,a:o.lispTree,b:u}))}));const modifierTypes={inverse:64,not:24,positive:59,negative:58,typeof:60,delete:61};setLispType(["inverse","not","negative","positive","typeof","delete"],((e,t,n,r,i,o)=>{let s=restOfExp(e,n.substring(r[0].length),[/^([^\s\.\?\w\$]|\?[^\.])/]);o.lispTree=lispify(e,n.substring(s.length+r[0].length),restOfExp.next,createLisp({op:modifierTypes[t],a:o.lispTree,b:lispify(e,s,expectTypes[i].next)}))}));const incrementTypes={"++$":25,"--$":27,"$++":26,"$--":28};setLispType(["incrementerBefore"],((e,t,n,r,i,o)=>{let s=restOfExp(e,n.substring(2),[/^[^\s\.\w\$]/]);o.lispTree=lispify(e,n.substring(s.length+2),restOfExp.next,createLisp({op:incrementTypes[r[0]+"$"],a:lispify(e,s,expectTypes[i].next),b:0}))})),setLispType(["incrementerAfter"],((e,t,n,r,i,o)=>{o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:incrementTypes["$"+r[0]],a:o.lispTree,b:0}))}));const adderTypes={"&&":29,"||":30,instanceof:62,in:63,"=":9,"-=":65,"+=":66,"/=":67,"**=":68,"*=":69,"%=":70,"^=":71,"&=":72,"|=":73,">>>=":74,"<<=":76,">>=":75};setLispType(["assign","assignModify","boolOp"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:adderTypes[r[0]],a:o.lispTree,b:lispify(e,n.substring(r[0].length),expectTypes[i].next)})}));const opTypes={"&":77,"|":78,"^":79,"<<":80,">>":81,">>>":82,"<=":54,">=":55,"<":56,">":57,"!==":31,"!=":53,"===":32,"==":52,"+":33,"-":47,"/":48,"**":49,"*":50,"%":51};function extractIfElse(e,t){let n,r,i=0,o=t.substring(0,0),s=emptyString,a=!0,c={};for(;(o=restOfExp(e,t.substring(o.end-t.start),[elseIf,ifElse,semiColon],void 0,void 0,void 0,c)).length||a;){a=!1;const l=t.substring(o.end-t.start).toString();if(l.startsWith("if"))o.end++,i++;else if(l.startsWith("else"))n=t.substring(0,o.end-t.start),o.end++,i--,i||o.end--;else{if(!(r=/^;?\s*else(?![\w\$])/.exec(l))){n=s.length?n:t.substring(0,o.end-t.start);break}n=t.substring(0,o.end-t.start),o.end+=r[0].length-1,i--,i||(o.end-=r[0].length-1)}if(!i){s=extractIfElse(e,t.substring(o.end-t.start+/^;?\s*else(?![\w\$])/.exec(l)?.[0].length)).all;break}c={}}return n=n||t.substring(0,o.end-t.start),{all:t.substring(0,Math.max(n.end,s.end)-t.start),true:n,false:s}}setLispType(["opHigh","op","comparitor","bitwise"],((e,t,n,r,i,o)=>{const s=[expectTypes.inlineIf.types.inlineIf,inlineIfElse];switch(t){case"opHigh":s.push(expectTypes.splitter.types.opHigh);case"op":s.push(expectTypes.splitter.types.op);case"comparitor":s.push(expectTypes.splitter.types.comparitor);case"bitwise":s.push(expectTypes.splitter.types.bitwise),s.push(expectTypes.splitter.types.boolOp)}let a=restOfExp(e,n.substring(r[0].length),s);o.lispTree=lispify(e,n.substring(a.length+r[0].length),restOfExp.next,createLisp({op:opTypes[r[0]],a:o.lispTree,b:lispify(e,a,expectTypes[i].next)}))})),setLispType(["inlineIf"],((e,t,n,r,i,o)=>{let s=!1,a=n.substring(0,0),c=1;for(;!s&&a.length<n.length;)a.end=restOfExp(e,n.substring(a.length+1),[expectTypes.inlineIf.types.inlineIf,inlineIfElse]).end,"?"===n.char(a.length)?c++:c--,c||(s=!0);a.start=n.start+1,o.lispTree=createLisp({op:15,a:o.lispTree,b:createLisp({op:16,a:lispifyExpr(e,a),b:lispifyExpr(e,n.substring(r[0].length+a.length+1))})})})),setLispType(["if"],((e,t,n,r,i,o)=>{let s=restOfExp(e,n.substring(r[0].length),[],"(");const a=extractIfElse(e,n.substring(r[1].length));/^\s*\{/.exec(n.substring(r[0].length+s.length+1).toString());const c=r[0].length-r[1].length+s.length+1;let l=a.true.substring(c),d=a.false;s=s.trim(),l=l.trim(),d=d.trim(),"{"===l.char(0)&&(l=l.slice(1,-1)),"{"===d.char(0)&&(d=d.slice(1,-1)),o.lispTree=createLisp({op:13,a:lispifyExpr(e,s),b:createLisp({op:14,a:lispifyBlock(l,e),b:lispifyBlock(d,e)})})})),setLispType(["switch"],((e,t,n,r,i,o)=>{const s=restOfExp(e,n.substring(r[0].length),[],"(");let a=n.toString().indexOf("{",r[0].length+s.length+1);if(-1===a)throw new SyntaxError("Invalid switch");let c,l=insertSemicolons(e,restOfExp(e,n.substring(a+1),[],"{"));const d=/^\s*(case\s|default)\s*/;let p=[],u=!1;for(;c=d.exec(l.toString());){if("default"===c[1]){if(u)throw new SyntaxError("Only one default switch case allowed");u=!0}let t=restOfExp(e,l.substring(c[0].length),[/^:/]),n=emptyString,r=a=c[0].length+t.length+1,i=/^\s*\{/.exec(l.substring(r).toString()),o=[];if(i)r+=i[0].length,n=restOfExp(e,l.substring(r),[],"{"),r+=n.length+1,o=lispifyBlock(n,e);else{let t=restOfExp(e,l.substring(r),[d]);if(t.trim().length){for(;(n=restOfExp(e,l.substring(r),[semiColon])).length&&(r+=n.length+(";"===l.char(r+n.length)?1:0),!d.test(l.substring(r).toString())););o=lispifyBlock(l.substring(a,n.end-l.start),e)}else o=[],r+=t.length}l=l.substring(r),p.push(createLisp({op:41,a:"default"===c[1]?void 0:lispifyExpr(e,t),b:o}))}o.lispTree=createLisp({op:40,a:lispifyExpr(e,s),b:p})})),setLispType(["dot","prop"],((e,t,n,r,i,o)=>{let s=r[0],a=r[0].length,c="prop";if("dot"===t){r[1]&&(c="?prop");let e=n.substring(r[0].length).toString().match(expectTypes.prop.types.prop);if(!e||!e.length)throw new SyntaxError("Hanging dot");s=e[0],a=s.length+r[0].length}o.lispTree=lispify(e,n.substring(a),expectTypes[i].next,createLisp({op:typesCreate[c],a:o.lispTree,b:s}))})),setLispType(["spreadArray","spreadObject"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:"spreadArray"===t?18:17,a:0,b:lispify(e,n.substring(r[0].length),expectTypes[i].next)})})),setLispType(["return","throw"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:"return"===t?8:46,a:0,b:lispifyExpr(e,n.substring(r[0].length))})})),setLispType(["number","boolean","null","und","NaN","Infinity"],((e,t,n,r,i,o)=>{o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:"number"===t?r[10]?83:7:35,a:0,b:r[10]?r[1]:r[0]}))})),setLispType(["string","literal","regex"],((e,t,n,r,i,o)=>{o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:"string"===t?2:"literal"===t?84:85,a:0,b:r[1]}))})),setLispType(["initialize"],((e,t,n,r,i,o)=>{const s="var"===r[1]?34:"let"===r[1]?3:4;r[3]?o.lispTree=createLisp({op:s,a:r[2],b:lispify(e,n.substring(r[0].length),expectTypes[i].next)}):o.lispTree=lispify(e,n.substring(r[0].length),expectTypes[i].next,createLisp({op:s,a:r[2],b:0}))})),setLispType(["function","inlineFunction","arrowFunction","arrowFunctionSingle"],((e,t,n,r,i,o)=>{const s="function"!==t&&"inlineFunction"!==t,a=s&&!r[r.length-1],c=s?2:3,l=r[1]?88:0,d=r[c]?r[c].replace(/\s+/g,"").split(/,/g):[];s||d.unshift((r[2]||"").trimStart());let p=!1;d.forEach((e=>{if(p)throw new SyntaxError("Rest parameter must be last formal parameter");e.startsWith("...")&&(p=!0)})),d.unshift(l);const u=restOfExp(e,n.substring(r[0].length),a?[/^[,\)\}\]]/,semiColon]:[/^}/]),f=a?"return "+u:u.toString();o.lispTree=lispify(e,n.substring(r[0].length+f.length+1),expectTypes[i].next,createLisp({op:s?11:"function"===t?37:10,a:d,b:e.eager?lispifyFunction(new CodeString(f),e):f}))}));const iteratorRegex=/^((let|var|const)\s+)?\s*([a-zA-Z\$_][a-zA-Z\d\$_]*)\s+(in|of)(?![\w\$])/;setLispType(["for","do","while"],((e,t,n,r,i,o)=>{let s,a,c,l=0,d=88,p=[],u=0,f=88,h=88;switch(t){case"while":l=n.toString().indexOf("(")+1;let t=restOfExp(e,n.substring(l),[],"(");a=lispifyReturnExpr(e,t),c=restOfExp(e,n.substring(l+t.length+1)).trim(),"{"===c[0]&&(c=c.slice(1,-1));break;case"for":l=n.toString().indexOf("(")+1;let i,o=[],g=emptyString;for(let t=0;t<3&&(g=restOfExp(e,n.substring(l),[/^[;\)]/]),o.push(g.trim()),l+=g.length+1,")"!==n.char(l-1));t++);if(1===o.length&&(i=iteratorRegex.exec(o[0].toString())))"of"===i[4]?(s=lispifyReturnExpr(e,o[0].substring(i[0].length)),p=[ofStart2,ofStart3],a=ofCondition,h=ofStep,u=lispify(e,new CodeString((i[1]||"let ")+i[3]+" = $$next.value"),["initialize"])):(s=lispifyReturnExpr(e,o[0].substring(i[0].length)),p=[inStart2,inStart3],h=inStep,a=inCondition,u=lispify(e,new CodeString((i[1]||"let ")+i[3]+" = $$keys[$$keyIndex]"),["initialize"]));else{if(3!==o.length)throw new SyntaxError("Invalid for loop definition");d=lispifyExpr(e,o.shift(),startingExecpted),a=lispifyReturnExpr(e,o.shift()),h=lispifyExpr(e,o.shift())}c=restOfExp(e,n.substring(l)).trim(),"{"===c[0]&&(c=c.slice(1,-1));break;case"do":f=0;const y=!!r[3];c=restOfExp(e,n.substring(r[0].length),y?[/^\}/]:[semiColon]),a=lispifyReturnExpr(e,restOfExp(e,n.substring(n.toString().indexOf("(",r[0].length+c.length)+1),[],"("))}const g=[f,p,s,d,h,a,u];o.lispTree=createLisp({op:38,a:g,b:lispifyBlock(c,e)})})),setLispType(["block"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:42,a:lispifyBlock(restOfExp(e,n.substring(1),[],"{"),e),b:0})})),setLispType(["loopAction"],((e,t,n,r,i,o)=>{o.lispTree=createLisp({op:86,a:r[1],b:0})}));const catchReg=/^\s*(catch\s*(\(\s*([a-zA-Z\$_][a-zA-Z\d\$_]*)\s*\))?|finally)\s*\{/;setLispType(["try"],((e,t,n,r,i,o)=>{const s=restOfExp(e,n.substring(r[0].length),[],"{");let a,c,l=catchReg.exec(n.substring(r[0].length+s.length+1).toString()),d="",p=0;l[1].startsWith("catch")?(l=catchReg.exec(n.substring(r[0].length+s.length+1).toString()),d=l[2],c=restOfExp(e,n.substring(r[0].length+s.length+1+l[0].length),[],"{"),p=r[0].length+s.length+1+l[0].length+c.length+1,(l=catchReg.exec(n.substring(p).toString()))&&l[1].startsWith("finally")&&(a=restOfExp(e,n.substring(p+l[0].length),[],"{"))):a=restOfExp(e,n.substring(r[0].length+s.length+1+l[0].length),[],"{");const u=[d,lispifyBlock(insertSemicolons(e,c||emptyString),e),lispifyBlock(insertSemicolons(e,a||emptyString),e)];o.lispTree=createLisp({op:39,a:lispifyBlock(insertSemicolons(e,s),e),b:u})})),setLispType(["void","await"],((e,t,n,r,i,o)=>{const s=restOfExp(e,n.substring(r[0].length),[/^([^\s\.\?\w\$]|\?[^\.])/]);o.lispTree=lispify(e,n.substring(r[0].length+s.length),expectTypes[i].next,createLisp({op:"void"===t?87:44,a:lispify(e,s),b:0}))})),setLispType(["new"],((e,t,n,r,i,o)=>{let s=r[0].length;const a=restOfExp(e,n.substring(s),[],void 0,"(");s+=a.length+1;const c=[];if("("===n.char(s-1)){const t=restOfExp(e,n.substring(s),[],"(");let r;s+=t.length+1;let i=0;for(;(r=restOfExp(e,t.substring(i),[/^,/])).length;)i+=r.length+1,c.push(r.trim())}o.lispTree=lispify(e,n.substring(s),expectTypes.expEdge.next,createLisp({op:45,a:lispify(e,a,expectTypes.initialize.next),b:c.map((t=>lispify(e,t,expectTypes.initialize.next)))}))}));const ofStart2=lispify(void 0,new CodeString("let $$iterator = $$obj[Symbol.iterator]()"),["initialize"]),ofStart3=lispify(void 0,new CodeString("let $$next = $$iterator.next()"),["initialize"]),ofCondition=lispify(void 0,new CodeString("return !$$next.done"),["initialize"]),ofStep=lispify(void 0,new CodeString("$$next = $$iterator.next()")),inStart2=lispify(void 0,new CodeString("let $$keys = Object.keys($$obj)"),["initialize"]),inStart3=lispify(void 0,new CodeString("let $$keyIndex = 0"),["initialize"]),inStep=lispify(void 0,new CodeString("$$keyIndex++")),inCondition=lispify(void 0,new CodeString("return $$keyIndex < $$keys.length"),["initialize"]);var lastType;function lispify(e,t,n,r,i=!1){if(r=r||[0,0,0],n=n||expectTypes.initialize.next,void 0===t)return r;const o=(t=t.trimStart()).toString();if(!t.length&&!n.includes("expEnd"))throw new SyntaxError("Unexpected end of expression");if(!t.length)return r;let s,a={lispTree:r};for(let r of n)if("expEnd"!==r){for(let n in expectTypes[r].types)if("expEnd"!==n&&(s=expectTypes[r].types[n].exec(o))){lastType=n;try{lispTypes.get(n)(e,n,t,s,r,a)}catch(e){if(i&&e instanceof SyntaxError)throw new ParseError(e.message,o);throw e}break}if(s)break}if(!s&&t.length){if(t.char(0),i)throw new ParseError(`Unexpected token after ${lastType}: ${t.char(0)}`,o);throw new SyntaxError(`Unexpected token after ${lastType}: ${t.char(0)}`)}return a.lispTree}const startingExpectedWithoutSingle=startingExecpted.filter((e=>"expSingle"!==e));function lispifyExpr(e,t,n){if(!t.trimStart().length)return;let r,i=[],o=0;if((n=n||expectTypes.initialize.next).includes("expSingle")&&testMultiple(t.toString(),Object.values(expectTypes.expSingle.types)))return lispify(e,t,["expSingle"],void 0,!0);for(n===startingExecpted&&(n=startingExpectedWithoutSingle);(r=restOfExp(e,t.substring(o),[/^,/])).length;)i.push(r.trimStart()),o+=r.length+1;if(1===i.length)return lispify(e,t,n,void 0,!0);if(n.includes("initialize")){let r=expectTypes.initialize.types.initialize.exec(i[0].toString());if(r)return createLisp({op:42,a:i.map(((t,n)=>lispify(e,n?new CodeString(r[1]+" "+t):t,["initialize"],void 0,!0))),b:0});if(expectTypes.initialize.types.return.exec(i[0].toString()))return lispify(e,t,n,void 0,!0)}const s=i.map(((t,r)=>lispify(e,t,n,void 0,!0)));return createLisp({op:43,a:s,b:0})}function lispifyReturnExpr(e,t){return createLisp({op:8,a:0,b:lispifyExpr(e,t)})}function lispifyBlock(e,t,n=!1){if(!(e=insertSemicolons(t,e)).trim().length)return[];let r,i=[],o=0,s=0,a={},c=!1,l=!1;for(;(r=restOfExp(t,e.substring(o),[semiColon],void 0,void 0,void 0,a)).length&&(l=e.char(o+r.length)&&";"!==e.char(o+r.length),o+=r.length+(l?0:1),/^\s*else(?![\w\$])/.test(e.substring(o).toString())||a.words.includes("do")&&/^\s*while(?![\w\$])/.test(e.substring(o).toString())?c=!0:(c=!1,i.push(e.substring(s,o-(l?0:1))),s=o),a={},!n););return c&&i.push(e.substring(s,o-(l?0:1))),i.map((e=>e.trimStart())).filter((e=>e.length)).map(((e,n)=>lispifyExpr(t,e.trimStart(),startingExecpted)))}function lispifyFunction(e,t,n=!1){if(!e.trim().length)return[];const r=lispifyBlock(e,t,n);let i=[];return hoist(r,i),i.concat(r)}function isLisp(e){return Array.isArray(e)&&"number"==typeof e[0]&&0!==e[0]&&88!==e[0]}function hoist(e,t){if(isLisp(e)){const[n,r,i]=e;if(39===n||13===n||38===n||40===n)hoist(r,t),hoist(i,t);else if(34===n)t.push(createLisp({op:34,a:r,b:0}));else if(37===n&&r[1])return t.push(e),!0}else if(Array.isArray(e)){const n=[];for(let r of e)hoist(r,t)||n.push(r);n.length!==e.length&&(e.length=0,e.push(...n))}return!1}const closingsNoInsertion=/^(\})\s*(catch|finally|else|while|instanceof)(?![\w\$])/,colonsRegex=/^((([\w\$\]\)\"\'\`]|\+\+|\-\-)\s*\r?\n\s*([\w\$\+\-\!~]))|(\}\s*[\w\$\!~\+\-\{\(\"\'\`]))/;function insertSemicolons(e,t){let n=t,r=emptyString,i={};const o=insertedSemicolons.get(t.ref)||new Array(t.ref.str.length);for(;(r=restOfExp(e,n,[],void 0,void 0,[colonsRegex],i)).length;){let e=!1,t=r,s=r.length;if(i.regRes){e=!0;const[,,o,,,a]=i.regRes;if(s="++"===i.regRes[3]||"--"===i.regRes[3]?r.length+1:r.length,t=n.substring(0,s),a){let t=closingsNoInsertion.exec(n.substring(r.length-1).toString());t?e="while"===t[2]&&"do"!==i.lastWord:"function"===i.lastWord&&"}"===i.regRes[5][0]&&"("===i.regRes[5].slice(-1)&&(e=!1)}else o&&("if"!==i.lastWord&&"while"!==i.lastWord&&"for"!==i.lastWord&&"else"!==i.lastWord||(e=!1))}e&&(o[t.end]=!0),n=n.substring(s),i={}}return insertedSemicolons.set(t.ref,o),t}function checkRegex(e){let t=1,n=!1,r=!1,i=!1;for(;t<e.length&&!r&&!i;)r="/"===e[t]&&!n,n="\\"===e[t]&&!n,i="\n"===e[t],t++;let o=e.substring(t);if(i=i||!r||/^\s*\d/.test(o),i)return null;let s=/^[a-z]*/.exec(o);return/^\s+[\w\$]/.test(e.substring(t+s[0].length))?null:{regex:e.substring(1,t-1),flags:s&&s[0]||"",length:t+(s&&s[0].length||0)}}const notDivide=/(typeof|delete|instanceof|return|in|of|throw|new|void|do|if)$/,possibleDivide=/^([\w\$\]\)]|\+\+|\-\-)[\s\/]/;function extractConstants(e,t,n=""){let r,i,o=[],s=!1,a="",c=-1,l=[],d="";const p=[],u=[];let f;for(var h=0;h<t.length;h++)if(d=t[h],a)d===a&&("*"===a&&"/"===t[h+1]?(a="",h++):"\n"===a&&(a=""));else{if(s){s=!1,o.push(d);continue}if(r)if("`"===r&&"$"===d&&"{"===t[h+1]){let n=extractConstants(e,t.substring(h+2),"{");l.push(n.str),o.push("${",l.length-1,"}"),h+=n.length+2}else if(r===d){if("`"===r){const t=createLisp({op:36,a:unraw(o.join("")),b:[]});t.tempJsStrings=l,e.literals.push(t),p.push("`",e.literals.length-1,"`")}else e.strings.push(unraw(o.join(""))),p.push('"',e.strings.length-1,'"');r=null,o=[]}else o.push(d);else{if("'"===d||'"'===d||"`"===d)l=[],r=d;else{if(closings[n]===d&&!u.length)return{str:p.join(""),length:h};closings[d]?(u.push(d),p.push(d)):closings[u[u.length-1]]===d?(u.pop(),p.push(d)):"/"!==d||"*"!==t[h+1]&&"/"!==t[h+1]?"/"===d&&!f&&(i=checkRegex(t.substring(h)))?(e.regexes.push(i),p.push("/",e.regexes.length-1,"/r"),h+=i.length-1):p.push(d):(a="*"===t[h+1]?"*":"\n",c=h)}f&&space.test(d)||(f=possibleDivide.exec(t.substring(h)))&&notDivide.test(t.substring(0,h+f[1].length))&&(f=null)}s=r&&"\\"===d}if(a&&"*"===a)throw new SyntaxError(`Unclosed comment '/*': ${t.substring(c)}`);return{str:p.join(""),length:h}}function parse$2(e,t=!1,n=!1){if("string"!=typeof e)throw new ParseError(`Cannot parse ${e}`,e);let r=" "+e;const i={strings:[],literals:[],regexes:[],eager:t};r=extractConstants(i,r).str;for(let e of i.literals)e[2]=e.tempJsStrings.map((e=>lispifyExpr(i,new CodeString(e)))),delete e.tempJsStrings;return{tree:lispifyFunction(new CodeString(r),i,n),constants:i}}class ExecReturn{constructor(e,t,n,r=!1,i=!1){this.auditReport=e,this.result=t,this.returned=n,this.breakLoop=r,this.continueLoop=i}}class Prop{constructor(e,t,n=!1,r=!1,i=!1){this.context=e,this.prop=t,this.isConst=n,this.isGlobal=r,this.isVariable=i}get(e){if(void 0===this.context)throw new ReferenceError(`${this.prop} is not defined`);return e.getSubscriptions.forEach((e=>e(this.context,this.prop))),this.context[this.prop]}}const optional={},reservedWords=new Set(["instanceof","typeof","return","try","catch","if","finally","else","in","of","var","let","const","for","delete","false","true","while","do","break","continue","new","function","async","await","switch","case"]);var VarType;function keysOnly(e){const t=Object.assign({},e);for(let e in t)t[e]=!0;return t}!function(e){e.let="let",e.const="const",e.var="var"}(VarType||(VarType={}));class Scope{constructor(e,t={},n){this.const={},this.let={},this.var={};const r=void 0!==n||null===e;this.parent=e,this.allVars=t,this.let=r?this.let:keysOnly(t),this.var=r?keysOnly(t):this.var,this.globals=null===e?keysOnly(t):{},this.functionThis=n}get(e,t=!1){if("this"===e&&void 0!==this.functionThis)return new Prop({this:this.functionThis},e,!0,!1,!0);if(reservedWords.has(e))throw new SyntaxError("Unexepected token '"+e+"'");if(null===this.parent||!t||void 0!==this.functionThis){if(this.globals.hasOwnProperty(e))return new Prop(this.functionThis,e,!1,!0,!0);if(e in this.allVars&&(!(e in{})||this.allVars.hasOwnProperty(e)))return new Prop(this.allVars,e,this.const.hasOwnProperty(e),this.globals.hasOwnProperty(e),!0);if(null===this.parent)return new Prop(void 0,e)}return this.parent.get(e,t)}set(e,t){if("this"===e)throw new SyntaxError('"this" cannot be assigned');if(reservedWords.has(e))throw new SyntaxError("Unexepected token '"+e+"'");let n=this.get(e);if(void 0===n.context)throw new ReferenceError(`Variable '${e}' was not declared.`);if(n.isConst)throw new TypeError(`Cannot assign to const variable '${e}'`);if(n.isGlobal)throw new SandboxError(`Cannot override global variable '${e}'`);return n.context[n.prop]=t,n}declare(e,t=null,n=void 0,r=!1){if("this"===e)throw new SyntaxError('"this" cannot be declared');if(reservedWords.has(e))throw new SyntaxError("Unexepected token '"+e+"'");if("var"===t&&void 0===this.functionThis&&null!==this.parent)return this.parent.declare(e,t,n,r);if((!this[t].hasOwnProperty(e)||"const"===t||this.globals.hasOwnProperty(e))&&e in this.allVars)throw new SandboxError(`Identifier '${e}' has already been declared`);return r&&(this.globals[e]=!0),this[t][e]=!0,this.allVars[e]=n,new Prop(this.allVars,e,this.const.hasOwnProperty(e),r)}}class LocalScope{}class SandboxError extends Error{}let currentTicks;function sandboxFunction(e,t){return function(...t){let n=parse$2(t.pop()||"");return createFunction(t,n.tree,currentTicks,{...e,constants:n.constants,tree:n.tree},void 0,"anonymous")}}function generateArgs(e,t){const n={};return e.forEach(((e,r)=>{e.startsWith("...")?n[e.substring(3)]=t.slice(r):n[e]=t[r]})),n}const sandboxedFunctions=new WeakSet;function createFunction(e,t,n,r,i,o){if(r.ctx.options.forbidFunctionCreation)throw new SandboxError("Function creation is forbidden");let s;return s=void 0===o?(...o)=>{const s=generateArgs(e,o);return executeTree(n,r,t,void 0===i?[]:[new Scope(i,s)]).result}:function(...o){const s=generateArgs(e,o);return executeTree(n,r,t,void 0===i?[]:[new Scope(i,s,this)]).result},r.registerSandboxFunction(s),sandboxedFunctions.add(s),s}function createFunctionAsync(e,t,n,r,i,o){if(r.ctx.options.forbidFunctionCreation)throw new SandboxError("Function creation is forbidden");if(!r.ctx.prototypeWhitelist?.has(Promise.prototype))throw new SandboxError("Async/await not permitted");let s;return s=void 0===o?async(...o)=>{const s=generateArgs(e,o);return(await executeTreeAsync(n,r,t,void 0===i?[]:[new Scope(i,s)])).result}:async function(...o){const s=generateArgs(e,o);return(await executeTreeAsync(n,r,t,void 0===i?[]:[new Scope(i,s,this)])).result},r.registerSandboxFunction(s),sandboxedFunctions.add(s),s}function sandboxedEval(e){return function(t){return e(t)()}}function sandboxedSetTimeout(e){return function(t,...n){return"string"!=typeof t?setTimeout(t,...n):setTimeout(e(t),...n)}}function sandboxedSetInterval(e){return function(t,...n){return"string"!=typeof t?setInterval(t,...n):setInterval(e(t),...n)}}function assignCheck(e,t,n="assign"){if(void 0===e.context)throw new ReferenceError(`Cannot ${n} value to undefined.`);if("object"!=typeof e.context&&"function"!=typeof e.context)throw new SyntaxError(`Cannot ${n} value to a primitive.`);if(e.isConst)throw new TypeError(`Cannot set value to const variable '${e.prop}'`);if(e.isGlobal)throw new SandboxError(`Cannot ${n} property '${e.prop}' of a global object`);if("function"==typeof e.context[e.prop]&&!e.context.hasOwnProperty(e.prop))throw new SandboxError(`Override prototype property '${e.prop}' not allowed`);"delete"===n?e.context.hasOwnProperty(e.prop)&&(t.changeSubscriptions.get(e.context)?.forEach((t=>t({type:"delete",prop:e.prop}))),t.changeSubscriptionsGlobal.get(e.context)?.forEach((t=>t({type:"delete",prop:e.prop})))):e.context.hasOwnProperty(e.prop)?(t.setSubscriptions.get(e.context)?.get(e.prop)?.forEach((e=>e({type:"replace"}))),t.setSubscriptionsGlobal.get(e.context)?.get(e.prop)?.forEach((e=>e({type:"replace"})))):(t.changeSubscriptions.get(e.context)?.forEach((t=>t({type:"create",prop:e.prop}))),t.changeSubscriptionsGlobal.get(e.context)?.forEach((t=>t({type:"create",prop:e.prop}))))}const arrayChange=new Set([[].push,[].pop,[].shift,[].unshift,[].splice,[].reverse,[].sort,[].copyWithin]);class KeyVal{constructor(e,t){this.key=e,this.val=t}}class SpreadObject{constructor(e){this.item=e}}class SpreadArray{constructor(e){this.item=e}}class If{constructor(e,t){this.t=e,this.f=t}}const literalRegex=/(\$\$)*(\$)?\${(\d+)}/g,ops=new Map;function addOps(e,t){ops.set(e,t)}function valueOrProp(e,t){return e instanceof Prop?e.get(t):e!==optional?e:void 0}function execMany(e,t,n,r,i,o,s){t===execSync?_execManySync(e,n,r,i,o,s):_execManyAsync(e,n,r,i,o,s).catch(r)}function _execManySync(e,t,n,r,i,o){let s=[];for(let a=0;a<t.length;a++){let c;try{c=syncDone((n=>execSync(e,t[a],r,i,n,o))).result}catch(e){return void n(e)}if(c instanceof ExecReturn&&(c.returned||c.breakLoop||c.continueLoop))return void n(void 0,c);if(isLisp(t[a])&&8===t[a][0])return void n(void 0,new ExecReturn(i.ctx.auditReport,c,!0));s.push(c)}n(void 0,s)}async function _execManyAsync(e,t,n,r,i,o){let s=[];for(let a=0;a<t.length;a++){let c;try{let n;c=!0===(n=asyncDone((n=>execAsync(e,t[a],r,i,n,o)))).isInstant?n.instant:(await n.p).result}catch(e){return void n(e)}if(c instanceof ExecReturn&&(c.returned||c.breakLoop||c.continueLoop))return void n(void 0,c);if(isLisp(t[a])&&8===t[a][0])return void n(void 0,new ExecReturn(i.ctx.auditReport,c,!0));s.push(c)}n(void 0,s)}function asyncDone(e){let t,n=!1;const r=new Promise(((r,i)=>{e(((e,o)=>{e?i(e):(n=!0,t=o,r({result:o}))}))}));return{isInstant:n,instant:t,p:r}}function syncDone(e){let t,n;if(e(((e,r)=>{n=e,t=r})),n)throw n;return{result:t}}async function execAsync(e,t,n,r,i,o){let s=i;const a=new Promise((e=>{s=(t,n)=>{i(t,n),e()}}));if(_execNoneRecurse(e,t,n,r,s,!0,o));else if(isLisp(t)){let i,a=t[0];try{let s;i=!0===(s=asyncDone((i=>execAsync(e,t[1],n,r,i,o)))).isInstant?s.instant:(await s.p).result}catch(e){return void s(e)}let c,l=i;try{l=i instanceof Prop?i.get(r):i}catch(e){return void s(e)}if(20===a||21===a){if(null==l)return void s(void 0,optional);a=20===a?1:5}if(l===optional){if(1===a||5===a)return void s(void 0,l);l=void 0}try{let i;c=!0===(i=asyncDone((i=>execAsync(e,t[2],n,r,i,o)))).isInstant?i.instant:(await i.p).result}catch(e){return void s(e)}let d=c;try{d=c instanceof Prop?c.get(r):c}catch(e){return void s(e)}if(d===optional&&(d=void 0),ops.has(a))try{ops.get(a)(execAsync,s,e,l,d,i,r,n,c,o)}catch(e){s(e)}else s(new SyntaxError("Unknown operator: "+a))}await a}function execSync(e,t,n,r,i,o){if(_execNoneRecurse(e,t,n,r,i,!1,o));else if(isLisp(t)){let s,a=t[0];try{s=syncDone((i=>execSync(e,t[1],n,r,i,o))).result}catch(e){return void i(e)}let c,l=s;try{l=s instanceof Prop?s.get(r):s}catch(e){return void i(e)}if(20===a||21===a){if(null==l)return void i(void 0,optional);a=20===a?1:5}if(l===optional){if(1===a||5===a)return void i(void 0,l);l=void 0}try{c=syncDone((i=>execSync(e,t[2],n,r,i,o))).result}catch(e){return void i(e)}let d=c;try{d=c instanceof Prop?c.get(r):c}catch(e){return void i(e)}if(d===optional&&(d=void 0),ops.has(a))try{ops.get(a)(execSync,i,e,l,d,s,r,n,c,o)}catch(e){i(e)}else i(new SyntaxError("Unknown operator: "+a))}}addOps(1,((e,t,n,r,i,o,s,a)=>{if(null===r)throw new TypeError(`Cannot get property ${i} of null`);const c=typeof r;if("undefined"===c&&void 0===o){let e=a.get(i);if(e.context===s.ctx.sandboxGlobal){s.ctx.options.audit&&s.ctx.auditReport.globalsAccess.add(i);const e=s.ctx.globalsWhitelist.has(s.ctx.sandboxGlobal[i])?s.evals.get(s.ctx.sandboxGlobal[i]):void 0;if(e)return void t(void 0,e)}return e.context&&e.context[i]===globalThis?void t(void 0,s.ctx.globalScope.get("this")):void t(void 0,e)}if(void 0===r)throw new SandboxError("Cannot get property '"+i+"' of undefined");if("object"!==c)"number"===c?r=new Number(r):"string"===c?r=new String(r):"boolean"===c&&(r=new Boolean(r));else if(void 0===r.hasOwnProperty)return void t(void 0,new Prop(void 0,i));const l="function"===c;let d=l||!(r.hasOwnProperty(i)||"number"==typeof i);if(s.ctx.options.audit&&d&&"string"==typeof i){let e=Object.getPrototypeOf(r);do{e.hasOwnProperty(i)&&(s.ctx.auditReport.prototypeAccess[e.constructor.name]||(s.ctx.auditReport.prototypeAccess[e.constructor.name]=new Set),s.ctx.auditReport.prototypeAccess[e.constructor.name].add(i))}while(e=Object.getPrototypeOf(e))}if(d)if(l){if(!["name","length","constructor"].includes(i)&&r.hasOwnProperty(i)){const e=s.ctx.prototypeWhitelist.get(r.prototype),n=s.ctx.options.prototypeReplacements.get(r);if(n)return void t(void 0,new Prop(n(r,!0),i));if(!e||e.size&&!e.has(i))throw new SandboxError(`Static method or property access not permitted: ${r.name}.${i}`)}}else if("constructor"!==i){let e=r;for(;e=Object.getPrototypeOf(e);)if(e.hasOwnProperty(i)){const n=s.ctx.prototypeWhitelist.get(e),o=s.ctx.options.prototypeReplacements.get(e.constuctor);if(o)return void t(void 0,new Prop(o(r,!1),i));if(n&&(!n.size||n.has(i)))break;throw new SandboxError(`Method or property access not permitted: ${e.constructor.name}.${i}`)}}if(s.evals.has(r[i]))return void t(void 0,s.evals.get(r[i]));if(r[i]===globalThis)return void t(void 0,s.ctx.globalScope.get("this"));let p=o.isGlobal||l&&!sandboxedFunctions.has(r)||s.ctx.globalsWhitelist.has(r);t(void 0,new Prop(r,i,!1,p))})),addOps(5,((e,t,n,r,i,o,s,a)=>{if(s.ctx.options.forbidFunctionCalls)throw new SandboxError("Function invocations are not allowed");if("function"!=typeof r)throw new TypeError(`${"symbol"==typeof o.prop?"Symbol":o.prop} is not a function`);const c=i.map((e=>e instanceof SpreadArray?[...e.item]:[e])).flat().map((e=>valueOrProp(e,s)));if("function"!=typeof o){if(o.context[o.prop]===JSON.stringify&&s.getSubscriptions.size){const e=new Set,t=n=>{if(n&&"object"==typeof n&&!e.has(n)){e.add(n);for(let e in n)s.getSubscriptions.forEach((t=>t(n,e))),t(n[e])}};t(c[0])}if(o.context instanceof Array&&arrayChange.has(o.context[o.prop])&&(s.changeSubscriptions.get(o.context)||s.changeSubscriptionsGlobal.get(o.context))){let e,t=!1;if("push"===o.prop)e={type:"push",added:c},t=!!c.length;else if("pop"===o.prop)e={type:"pop",removed:o.context.slice(-1)},t=!!e.removed.length;else if("shift"===o.prop)e={type:"shift",removed:o.context.slice(0,1)},t=!!e.removed.length;else if("unshift"===o.prop)e={type:"unshift",added:c},t=!!c.length;else if("splice"===o.prop)e={type:"splice",startIndex:c[0],deleteCount:void 0===c[1]?o.context.length:c[1],added:c.slice(2),removed:o.context.slice(c[0],void 0===c[1]?void 0:c[0]+c[1])},t=!!e.added.length||!!e.removed.length;else if("reverse"===o.prop||"sort"===o.prop)e={type:o.prop},t=!!o.context.length;else if("copyWithin"===o.prop){let n=void 0===c[2]?o.context.length-c[1]:Math.min(o.context.length,c[2]-c[1]);e={type:"copyWithin",startIndex:c[0],endIndex:c[0]+n,added:o.context.slice(c[1],c[1]+n),removed:o.context.slice(c[0],c[0]+n)},t=!!e.added.length||!!e.removed.length}t&&(s.changeSubscriptions.get(o.context)?.forEach((t=>t(e))),s.changeSubscriptionsGlobal.get(o.context)?.forEach((t=>t(e))))}o.get(s),t(void 0,o.context[o.prop](...c))}else t(void 0,o(...c))})),addOps(22,((e,t,n,r,i,o,s,a)=>{let c={};for(let e of i)e.key instanceof SpreadObject?c={...c,...e.key.item}:c[e.key]=e.val;t(void 0,c)})),addOps(6,((e,t,n,r,i)=>t(void 0,new KeyVal(r,i)))),addOps(12,((e,t,n,r,i,o,s,a)=>{t(void 0,i.map((e=>e instanceof SpreadArray?[...e.item]:[e])).flat().map((e=>valueOrProp(e,s))))})),addOps(23,((e,t,n,r,i)=>t(void 0,i))),addOps(35,((e,t,n,r,i)=>{switch(i){case"true":return t(void 0,!0);case"false":return t(void 0,!1);case"null":return t(void 0,null);case"undefined":return t(void 0,void 0);case"NaN":return t(void 0,NaN);case"Infinity":return t(void 0,1/0)}t(new Error("Unknown symbol: "+i))})),addOps(7,((e,t,n,r,i)=>t(void 0,Number(i)))),addOps(83,((e,t,n,r,i)=>t(void 0,BigInt(i)))),addOps(2,((e,t,n,r,i,o,s)=>t(void 0,s.constants.strings[parseInt(i)]))),addOps(85,((e,t,n,r,i,o,s)=>{const a=s.constants.regexes[parseInt(i)];if(!s.ctx.globalsWhitelist.has(RegExp))throw new SandboxError("Regex not permitted");t(void 0,new RegExp(a.regex,a.flags))})),addOps(84,((e,t,n,r,i,o,s,a)=>{let c=s.constants.literals[parseInt(i)];const[,l,d]=c;let p,u=[],f=[];for(;p=literalRegex.exec(l);)p[2]||(u.push(d[parseInt(p[3],10)]),f.push(p[3]));e(n,u,a,s,((e,n)=>{const r={};if(e)t(e);else{for(let e in f){const t=f[e];r[t]=n[e]}t(void 0,l.replace(/(\\\\)*(\\)?\${(\d+)}/g,((e,t,n,i)=>{if(n)return e;return(t||"")+`${valueOrProp(r[i],s)}`})))}}))})),addOps(18,((e,t,n,r,i,o,s,a)=>{t(void 0,new SpreadArray(i))})),addOps(17,((e,t,n,r,i,o,s,a)=>{t(void 0,new SpreadObject(i))})),addOps(24,((e,t,n,r,i)=>t(void 0,!i))),addOps(64,((e,t,n,r,i)=>t(void 0,~i))),addOps(25,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,++o.context[o.prop])})),addOps(26,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]++)})),addOps(27,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,--o.context[o.prop])})),addOps(28,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]--)})),addOps(9,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]=i)})),addOps(66,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]+=i)})),addOps(65,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]-=i)})),addOps(67,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]/=i)})),addOps(69,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]*=i)})),addOps(68,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]**=i)})),addOps(70,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]%=i)})),addOps(71,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]^=i)})),addOps(72,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]&=i)})),addOps(73,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]|=i)})),addOps(76,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]<<=i)})),addOps(75,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]>>=i)})),addOps(74,((e,t,n,r,i,o,s)=>{assignCheck(o,s),t(void 0,o.context[o.prop]>>=i)})),addOps(57,((e,t,n,r,i)=>t(void 0,r>i))),addOps(56,((e,t,n,r,i)=>t(void 0,r<i))),addOps(55,((e,t,n,r,i)=>t(void 0,r>=i))),addOps(54,((e,t,n,r,i)=>t(void 0,r<=i))),addOps(52,((e,t,n,r,i)=>t(void 0,r==i))),addOps(32,((e,t,n,r,i)=>t(void 0,r===i))),addOps(53,((e,t,n,r,i)=>t(void 0,r!=i))),addOps(31,((e,t,n,r,i)=>t(void 0,r!==i))),addOps(29,((e,t,n,r,i)=>t(void 0,r&&i))),addOps(30,((e,t,n,r,i)=>t(void 0,r||i))),addOps(77,((e,t,n,r,i)=>t(void 0,r&i))),addOps(78,((e,t,n,r,i)=>t(void 0,r|i))),addOps(33,((e,t,n,r,i)=>t(void 0,r+i))),addOps(47,((e,t,n,r,i)=>t(void 0,r-i))),addOps(59,((e,t,n,r,i)=>t(void 0,+i))),addOps(58,((e,t,n,r,i)=>t(void 0,-i))),addOps(48,((e,t,n,r,i)=>t(void 0,r/i))),addOps(79,((e,t,n,r,i)=>t(void 0,r^i))),addOps(50,((e,t,n,r,i)=>t(void 0,r*i))),addOps(51,((e,t,n,r,i)=>t(void 0,r%i))),addOps(80,((e,t,n,r,i)=>t(void 0,r<<i))),addOps(81,((e,t,n,r,i)=>t(void 0,r>>i))),addOps(82,((e,t,n,r,i)=>t(void 0,r>>>i))),addOps(60,((e,t,n,r,i,o,s,a)=>{e(n,i,a,s,((e,n)=>{t(void 0,typeof valueOrProp(n,s))}))})),addOps(62,((e,t,n,r,i)=>t(void 0,r instanceof i))),addOps(63,((e,t,n,r,i)=>t(void 0,r in i))),addOps(61,((e,t,n,r,i,o,s,a,c)=>{void 0!==c.context?(assignCheck(c,s,"delete"),c.isVariable?t(void 0,!1):t(void 0,delete c.context[c.prop])):t(void 0,!0)})),addOps(8,((e,t,n,r,i,o,s)=>t(void 0,i))),addOps(34,((e,t,n,r,i,o,s,a,c)=>{t(void 0,a.declare(r,VarType.var,i))})),addOps(3,((e,t,n,r,i,o,s,a,c)=>{t(void 0,a.declare(r,VarType.let,i,c&&c.isGlobal))})),addOps(4,((e,t,n,r,i,o,s,a,c)=>{t(void 0,a.declare(r,VarType.const,i))})),addOps(11,((e,t,n,r,i,o,s,a)=>{r=[...r],("string"==typeof o[2]||o[2]instanceof CodeString)&&(o[2]=i=lispifyFunction(new CodeString(o[2]),s.constants)),r.shift()?t(void 0,createFunctionAsync(r,i,n,s,a)):t(void 0,createFunction(r,i,n,s,a))})),addOps(37,((e,t,n,r,i,o,s,a)=>{("string"==typeof o[2]||o[2]instanceof CodeString)&&(o[2]=i=lispifyFunction(new CodeString(o[2]),s.constants));let c,l=r.shift(),d=r.shift();c=88===l?createFunctionAsync(r,i,n,s,a,d):createFunction(r,i,n,s,a,d),d&&a.declare(d,VarType.var,c),t(void 0,c)})),addOps(10,((e,t,n,r,i,o,s,a)=>{("string"==typeof o[2]||o[2]instanceof CodeString)&&(o[2]=i=lispifyFunction(new CodeString(o[2]),s.constants));let c,l=r.shift(),d=r.shift();d&&(a=new Scope(a,{})),c=88===l?createFunctionAsync(r,i,n,s,a,d):createFunction(r,i,n,s,a,d),d&&a.declare(d,VarType.let,c),t(void 0,c)})),addOps(38,((e,t,n,r,i,o,s,a)=>{const[c,l,d,p,u,f,h]=r;let g=!0;const y=new Scope(a,{});let x={$$obj:void 0};const v=new Scope(y,x);if(e===execAsync)(async()=>{let r;for(r=asyncDone((t=>e(n,p,y,s,t))),x.$$obj=!0===(r=asyncDone((t=>e(n,d,y,s,t)))).isInstant?r.instant:(await r.p).result,r=asyncDone((t=>e(n,l,v,s,t))),c&&(g=!0===(r=asyncDone((t=>e(n,f,v,s,t)))).isInstant?r.instant:(await r.p).result);g;){let o={};r=asyncDone((t=>e(n,h,new Scope(v,o),s,t))),!0===r.isInstant?r.instant:(await r.p).result;let a=await executeTreeAsync(n,s,i,[new Scope(y,o)],"loop");if(a instanceof ExecReturn&&a.returned)return void t(void 0,a);if(a instanceof ExecReturn&&a.breakLoop)break;r=asyncDone((t=>e(n,u,v,s,t))),g=!0===(r=asyncDone((t=>e(n,f,v,s,t)))).isInstant?r.instant:(await r.p).result}t()})().catch(t);else{for(syncDone((t=>e(n,p,y,s,t))),x.$$obj=syncDone((t=>e(n,d,y,s,t))).result,syncDone((t=>e(n,l,v,s,t))),c&&(g=syncDone((t=>e(n,f,v,s,t))).result);g;){let r={};syncDone((t=>e(n,h,new Scope(v,r),s,t)));let o=executeTree(n,s,i,[new Scope(y,r)],"loop");if(o instanceof ExecReturn&&o.returned)return void t(void 0,o);if(o instanceof ExecReturn&&o.breakLoop)break;syncDone((t=>e(n,u,v,s,t))),g=syncDone((t=>e(n,f,v,s,t))).result}t()}})),addOps(86,((e,t,n,r,i,o,s,a,c,l)=>{if("switch"===l&&"continue"===r||!l)throw new SandboxError("Illegal "+r+" statement");t(void 0,new ExecReturn(s.ctx.auditReport,void 0,!1,"break"===r,"continue"===r))})),addOps(13,((e,t,n,r,i,o,s,a,c,l)=>{e(n,valueOrProp(r,s)?i.t:i.f,a,s,t)})),addOps(15,((e,t,n,r,i,o,s,a)=>{e(n,valueOrProp(r,s)?i.t:i.f,a,s,t)})),addOps(16,((e,t,n,r,i)=>t(void 0,new If(r,i)))),addOps(14,((e,t,n,r,i)=>t(void 0,new If(r,i)))),addOps(40,((e,t,n,r,i,o,s,a)=>{e(n,r,a,s,((r,o)=>{if(r)t(r);else if(o=valueOrProp(o,s),e===execSync){let r,c=!1;for(let l of i)if(c||(c=!l[1]||o===valueOrProp(syncDone((t=>e(n,l[1],a,s,t))).result,s))){if(!l[2])continue;if(r=executeTree(n,s,l[2],[a],"switch"),r.breakLoop)break;if(r.returned)return void t(void 0,r);if(!l[1])break}t()}else(async()=>{let r,c=!1;for(let l of i){let i;if(c||(c=!l[1]||o===valueOrProp(!0===(i=asyncDone((t=>e(n,l[1],a,s,t)))).isInstant?i.instant:(await i.p).result,s))){if(!l[2])continue;if(r=await executeTreeAsync(n,s,l[2],[a],"switch"),r.breakLoop)break;if(r.returned)return void t(void 0,r);if(!l[1])break}}t()})().catch(t)}))})),addOps(39,((e,t,n,r,i,o,s,a,c,l)=>{const[d,p,u]=i;executeTreeWithDone(e,((r,i)=>{executeTreeWithDone(e,(o=>{o?t(o):r?executeTreeWithDone(e,t,n,s,p,[new Scope(a)],l):t(void 0,i)}),n,s,u,[new Scope(a,{})])}),n,s,r,[new Scope(a)],l)})),addOps(87,((e,t,n,r)=>{t()})),addOps(45,((e,t,n,r,i,o,s)=>{if(!s.ctx.globalsWhitelist.has(r)&&!sandboxedFunctions.has(r))throw new SandboxError(`Object construction not allowed: ${r.constructor.name}`);t(void 0,new r(...i))})),addOps(46,((e,t,n,r,i)=>{t(i)})),addOps(43,((e,t,n,r)=>t(void 0,r.pop()))),addOps(0,((e,t,n,r)=>t()));const unexecTypes=new Set([11,37,10,38,39,40,14,16,60]);function _execNoneRecurse(e,t,n,r,i,o,s){const a=o?execAsync:execSync;if(!(r.ctx.options.executionQuota<=e.ticks)||"function"==typeof r.ctx.options.onExecutionQuotaReached&&r.ctx.options.onExecutionQuotaReached(e,n,r,t)){if(e.ticks++,currentTicks=e,t instanceof Prop)try{i(void 0,t.get(r))}catch(e){i(e)}else if(t===optional)i();else if(Array.isArray(t)&&!isLisp(t))0===t[0]?i():execMany(e,a,t,i,n,r,s);else if(isLisp(t))if(42===t[0])execMany(e,a,t[1],i,n,r,s);else if(44===t[0])o?r.ctx.prototypeWhitelist?.has(Promise.prototype)?execAsync(e,t[1],n,r,(async(e,t)=>{if(e)i(e);else try{i(void 0,await valueOrProp(t,r))}catch(e){i(e)}}),s).catch(i):i(new SandboxError("Async/await is not permitted")):i(new SandboxError("Illegal use of 'await', must be inside async function"));else{i