UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) • 31.9 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{toSymbolId as e,neverAbortedSignal as n}from"./arcadeEnvironment.js";import{ArcadeModule as t}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,collectDeclaredLocalNames as l,flattenAccessChain as a}from"./compilerUtils.js";import{getNestedOptionalValue as s,tryGetMember as i,getMember as u,getGeometryMember as c,getGeometryKeys as m}from"./containerUtils.js";import p from"./Dictionary.js";import{ArcadeExecutionError as f,ArcadeCompilationError as d,ArcadeUncompilableError as g}from"./executionError.js";import{Feature as h}from"./Feature.js";import{NativeFunction as y,ArcadeFunction as w,ScopeMarshalledFunction as b,wrapModuleScopedResponse as $}from"./FunctionWrapper.js";import{p as v,q as S,i as x,k as I,j as C,r as F,s as M,v as O,u as j,w as A,x as k,h as E,n as N,y as B}from"../chunks/languageUtils.js";import{addFunctionDeclaration as _}from"./treeAnalysis.js";import{A as V}from"../chunks/aiServices.js";import{A as T}from"../chunks/array.js";import{registerFunctions as L}from"./functions/date.js";import{registerFunctions as R}from"./functions/feature.js";import{registerFunctions as U}from"./functions/geometry.js";import{registerFunctions as D}from"./functions/geomsync.js";import{registerFunctions as G}from"./functions/maths.js";import{registerFunctions as q}from"./functions/stats.js";import{registerFunctions as z}from"./functions/string.js";import{registerFunctions as P}from"./functions/track.js";import W from"../core/Logger.js";import{isPromiseLike as K}from"../core/promiseUtils.js";import{addMany as Z}from"../core/SetUtils.js";import J from"../geometry/SpatialReference.js";import{isGraphic as Y}from"../support/graphicInstanceUtils.js";import{isArray as H,isNumber as Q,isString as X,isBoolean as ee}from"../support/guards.js";const ne=()=>W.getLogger("esri.arcade.arcadeCompiler");class te{constructor(){this._symbolCounter=0,this.safeAccessTempVarId="_Tsat"}nextVarId(){return this._symbolCounter+=1,`_T${this._symbolCounter}`}nextTempVarId(){return this._symbolCounter+=1,`_Tvar${this._symbolCounter}`}nextLocalsSymbolMapId(){return this._symbolCounter+=1,`_Locals${this._symbolCounter}`}}function re(e,n){const t=e.localScope?.get(n);if(null!=t)return{scope:"local",name:n,var:t};const r=e.globalScope.get(n);return null!=r?{scope:"global",name:n,var:r}:e.standardGlobals.has(n)?{scope:"global",name:n,var:n}:null}function oe(n,t,r="InvalidIdentifier"){const o=re(n,e(t));if(null!=o)return o;throw new d(null,r,t)}function le(n,t,r){const o=re(n,e(t));if(null==o)throw ne().error(`Internal error: Symbol "${t.name}" not declared.`),new d(null,"NeverReach",t);if(null!=r&&o.scope!==r)throw ne().error(`Internal error: Expected to resolve "${t.name}" in the ${r} scope but is in the ${o.scope} scope.`),new d(null,"NeverReach",t);return o}function ae(n,t){const r=e(t),o=n.symbolMetadata;if(n.localStack.length>0){const e=n.localStack[n.localStack.length-1],t=o.locals.get(e._SymbolsMapId);if(null==t)return void ne().error(`Internal error: no reflection metadata for ${e._SymbolsMapId}`);const l=t.get(r);if(null!=l)return on.requireInitialized(e[l])}const l=o.globals.get(r);if(null!=l)return on.requireInitialized(n.globalScope[l]);if(o.standardGlobals.has(r))return on.requireInitialized(n.globalScope[r]);throw new f(null,"InvalidIdentifier",null)}class se extends w{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new f(e,"WrongNumberOfParameters",null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,r){return r(e,n,(n,o,l)=>{l=l.map(n=>!x(n)||n instanceof b?n:$(n,e,r));const a=this.call(t,{arguments:l});return K(a)?a.then(e=>$(e,t,r)):a})}}function ie(e,n,t){try{return t(e,null,n.arguments)}catch(r){throw r}}function ue(e,n,t,r,l,a){const{globals:s,exports:i}=o(e);Z(s,t);const u=new te,c=[],m=new Map;for(const o of s)if(t.has(o)||n.has(o))m.set(o,o);else{const e=u.nextVarId();m.set(o,e),c.push(`gscope[${JSON.stringify(e)}] = ${tn};`)}const p=new Map,f=Object.create(null),d={isAsync:r,symbols:u,standardGlobals:n,globalScope:m,exports:i,localScope:null,allLocalSymbolMetadata:p,moduleFactory:a,moduleFactoryMap:f,libraryResolver:l};return{body:[...c,`var ${u.safeAccessTempVarId};`,"var lastStatement = lc.voidOperation;",Ce(d,e),"return lastStatement;"].join("\n"),symbolMetadata:{standardGlobals:n,exports:i,globals:m,locals:p},moduleFactoryMap:f}}function ce(e,n){switch(n.type){case"AssignmentExpression":return ve(e,n);case"UpdateExpression":return be(e,n);case"TemplateLiteral":return Re(e,n);case"Identifier":return Ge(e,n);case"MemberExpression":return Ee(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return qe(e,n);case"UnaryExpression":return Te(e,n);case"BinaryExpression":return Ue(e,n);case"LogicalExpression":return De(e,n);case"ArrayExpression":return Le(e,n);case"ObjectExpression":return pe(e,n);case"MemberAccessChainExpression":return Ve(e,n);case"SafeMemberExpression":throw ne().error("SafeMemberExpression outside of MemberAccessChainExpression"),new d(null,"Unrecognized",n);default:throw new d(null,"Unrecognized",n)}}function me(e,n){switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclaration":return Ae(e,n);case"BlockStatement":return Ce(e,n);case"FunctionDeclaration":return je(e,n);case"ImportDeclaration":return Me(e,n);case"ExportNamedDeclaration":return me(e,n.declaration);case"ReturnStatement":return Fe(e,n);case"IfStatement":return Ie(e,n);case"ExpressionStatement":return Se(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"ForStatement":return we(e,n);case"ForInStatement":return he(e,n);case"ForOfStatement":return ye(e,n);case"WhileStatement":return $e(e,n);default:throw new d(null,"Unrecognized",n)}}function pe(e,n){let t="lang.dictionary([";for(let r=0;r<n.properties.length;r++){const o=n.properties[r];let l;l="Identifier"===o.key.type?"'"+o.key.name+"'":ce(e,o.key);r>0&&(t+=","),t+="lang.strCheck("+l+",'ObjectExpression'),lang.aCheck("+ce(e,o.value)+", 'ObjectExpression')"}return t+="])",t}function fe(e,n,t,r,o=(e,n)=>`${e} = ${n}`){const l=e.symbols.nextTempVarId(),a=e.symbols.nextTempVarId();return[`var ${l} = ${t};`,`for (var ${a} = 0; ${a} < ${l}; ${a}++) {`,` ${o(n,a)}`,` ${me(e,r)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function de(e,n,t,r,o=e=>e){const l=e.symbols.nextTempVarId(),a=e.symbols.nextTempVarId();return[`var ${l} = ${t};`,`for (var ${a} of ${l}) {`,` ${n} = ${o(a)};`,` ${me(e,r)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function ge(e,n,t,r){const o=e.symbols.nextTempVarId(),l=e.symbols.nextTempVarId(),a=e.symbols.nextTempVarId(),s=e.symbols.nextTempVarId();return[`var ${o} = yield ${t}.queryAll(runtimeCtx.abortSignal);`,`var ${l} = { done: false, value: [] };`,`for (var ${a} = 0; ${a} < ${l}.value.length || ((${a} = 0), !(${l} = yield ${o}.next()).done); ${a}++) {`,` if (${l}.value.length === 0) continue;`,` var ${s} = ${l}.value[${a}];`,` ${n} = lang.createFeature(${s}, ${t}, runtimeCtx);`,` ${me(e,r)}`,"}"].join("\n")}function he(e,n){const t=e.symbols.nextTempVarId();let r,o,l="var "+t+" = "+ce(e,n.right)+";\n";switch("VariableDeclaration"===n.left.type?(r=le(e,n.left.declarations[0].id),l+=me(e,n.left)):r=oe(e,n.left),r.scope){case"local":o=`lscope['${r.var}']`;break;case"global":o=`gscope['${r.var}']`;break;default:throw r.scope,new d(null,"NeverReach",n.left)}return l+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",l+="else if (lc.isArray("+t+") || lc.isString("+t+")) {\n",l+=fe(e,o,`${t}.length`,n.body),l+="}\n",l+="else if (lc.isImmutableArray("+t+")) {\n",l+=fe(e,o,`${t}.length()`,n.body),l+="}\n",l+="else if (( "+t+" instanceof lang.Dictionary) || lc.isDictionaryLike("+t+")) {\n",l+=de(e,o,`${t}.keys()`,n.body),l+="}\n",e.isAsync&&(l+="else if (lc.isFeatureSet("+t+")) {\n",l+=ge(e,o,t,n.body),l+="}\n"),l+=`else if (lc.isGeometry(${t})) {\n`,l+=de(e,o,`lang.getGeometryKeys(${t})`,n.body),l+="}\n",l+="else { lastStatement = lc.voidOperation; } \n",l}function ye(e,n){const t=e.symbols.nextTempVarId();let r,o,l="var "+t+" = "+ce(e,n.right)+";\n";switch("VariableDeclaration"===n.left.type?(r=le(e,n.left.declarations[0].id),l+=me(e,n.left)):r=oe(e,n.left),r.scope){case"local":o=`lscope['${r.var}']`;break;case"global":o=`gscope['${r.var}']`;break;default:throw r.scope,new d(null,"NeverReach",n.left)}return l+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",l+="else if (lc.isArray("+t+") || lc.isString("+t+")) {\n",l+=fe(e,o,`${t}.length`,n.body,(e,n)=>[`if (${n} >= ${t}.length) {`," lang.error('OutOfBounds');","}",`${e} = ${t}[${n}];`].join("\n")),l+="}\n",l+="else if (lc.isImmutableArray("+t+")) {\n",l+=fe(e,o,`${t}.length()`,n.body,(e,n)=>`${e} = ${t}.get(${n});`),l+="}\n",l+="else if (( "+t+" instanceof lang.Dictionary) || lc.isDictionaryLike("+t+")) {\n",l+=de(e,o,`${t}.keys()`,n.body,e=>`lang.entry(${e}, ${t}.field(${e}))`),l+="}\n",e.isAsync&&(l+="else if (lc.isFeatureSet("+t+")) {\n",l+=ge(e,o,t,n.body),l+="}\n"),l+=`else if (lc.isGeometry(${t})) {\n`,l+=de(e,o,`lang.getGeometryKeys(${t})`,n.body,e=>`lang.entry(${e}, lang.getGeometryMember(${t}, ${e}, runtimeCtx))`),l+="}\n",l+="else { lastStatement = lc.voidOperation; } \n",l}function we(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&("VariableDeclaration"===n.init.type?t+=me(e,n.init):t+=ce(e,n.init)+"; ");const r=e.symbols.nextTempVarId(),o=e.symbols.nextTempVarId();return t+="var "+r+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+r+"===false) {\n "+ce(e,n.update)+" \n}\n "+r+"=false; \n"),null!==n.test&&(t+="var "+o+" = "+ce(e,n.test)+"; ",t+="if ("+o+"===false) { break; } else if ("+o+"!==true) { lang.error('BooleanConditionRequired'); }\n"),t+=me(e,n.body),null!==n.update&&(t+="\n "+ce(e,n.update)),t+="\n"+r+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function be(e,n){if("CallExpression"===n.argument.type)throw new d(null,"NeverReach",n);let t;if("MemberExpression"===n.argument.type){const r=ce(e,n.argument.object);return t=!0===n.argument.computed?ce(e,n.argument.property):"'"+n.argument.property.name+"'","lang.memberupdate("+r+","+t+",'"+n.operator+"',"+n.prefix+")"}const r=oe(e,n.argument);switch(Oe(r),r.scope){case"local":return`lang.update(lscope, '${r.var}', '${n.operator}', ${n.prefix})`;case"global":return`lang.update(gscope, '${r.var}', '${n.operator}', ${n.prefix})`;default:throw r.scope,new d(null,"NeverReach",n.argument)}}function $e(e,n){let t="lastStatement = lc.voidOperation; \n";const r=e.symbols.nextTempVarId();return t+=`\n var ${r} = true;\n do {\n ${r} = ${ce(e,n.test)};\n if (${r}==false) {\n break;\n }\n if (${r}!==true) {\n lang.error('BooleanConditionRequired');\n }\n ${me(e,n.body)}\n }\n while (${r} !== false);\n lastStatement = lc.voidOperation;\n `,t}function ve(e,n){const t=ce(e,n.right);if("MemberExpression"===n.left.type){let r;const o=ce(e,n.left.object);return r=!0===n.left.computed?ce(e,n.left.property):"'"+n.left.property.name+"'","lang.assignmember("+o+","+r+",'"+n.operator+"',"+t+")"}const r=oe(e,n.left);switch(Oe(r),r.scope){case"local":return`lscope['${r.var}']=lang.assign(${t},'${n.operator}', ${"="===n.operator?"null":rn(`lscope['${r.var}']`)})`;case"global":return`gscope['${r.var}']=lang.assign(${t},'${n.operator}', ${"="===n.operator?"null":rn(`gscope['${r.var}']`)})`;default:throw r.scope,new d(null,"NeverReach",n.left)}}function Se(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+ce(e,n.expression)+"; \n ":"lastStatement = "+ce(e,n.expression)+"; "}function xe(e,n){return"BlockStatement"===n.type?me(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?me(e,n)+"; ":"ExpressionStatement"===n.type?me(e,n):me(e,n)+"; "}function Ie(e,n){return`if (lang.mustBoolean(${ce(e,n.test)}, runtimeCtx) === true) {\n ${xe(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+Ie(e,n.alternate):` else {\n ${xe(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function Ce(e,n){let t="";for(let r=0;r<n.body.length;r++)"EmptyStatement"!==n.body[r].type&&("ReturnStatement"===n.body[r].type||"BreakStatement"===n.body[r].type||"ContinueStatement"===n.body[r].type?t+=me(e,n.body[r])+"; \n":t+=me(e,n.body[r])+" \n");return t}function Fe(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+ce(e,n.argument)}function Me(e,n){const t=le(e,n.specifiers[0].local,"global"),r=e.libraryResolver?.loadLibrary(t.name),o=e.symbols.nextVarId();void 0===e.moduleFactory[r.uri]&&(e.moduleFactory[r.uri]=cn(r.syntax,e.moduleFactory,e.isAsync)),e.moduleFactoryMap[o]=r.uri;let l="";return l=e.isAsync?"(yield lang.loadModule('"+o+"', runtimeCtx) ); ":"lang.loadModule('"+o+"', runtimeCtx); ",Oe(t),`gscope['${t.var}']=${l}`}function Oe(e){if("global"===e.scope)switch(e.name){case"iif":case"when":case"defaultvalue":case"decode":throw new g}}function je(n,t){const r=new Set(t.params.map(n=>e(n))),o=l(t);Z(o,r);const a=n.symbols,s=new Map;for(const e of o)s.set(e,a.nextVarId());const i=a.nextLocalsSymbolMapId();n.allLocalSymbolMetadata.set(i,s);const u={...n,localScope:s},c=[`lscope._SymbolsMapId = ${JSON.stringify(i)};`];for(let e=0;e<t.params.length;e++){const n=le(u,t.params[e],"local");Oe(n),c.push(`lscope['${n.var}'] = arguments[${e}];`)}for(const[e,l]of s)r.has(e)||c.push(`lscope['${l}'] = ${tn};`);const m=Ce(u,t.body),p=!0===n.isAsync?["return lang.__awaiter(this, void 0, void 0, function* () {",` ${m}`," return lastStatement;","});"]:[m,"return lastStatement;"],f=["new lang.UserDefinedCompiledFunction("," lang.functionDepthchecker("," function() {"," var lastStatement = lc.voidOperation;"," var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];",...c,...p," },"," runtimeCtx,"," ),",` ${t.params.length},`,")"].join("\n"),d=le(n,t.id,"global");return Oe(d),`gscope['${d.var}']=${f}; lastStatement = lc.voidOperation;`}function Ae(e,n){const t=[];for(let r=0;r<n.declarations.length;r++)t.push(ke(e,n.declarations[r]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function ke(e,n){const t=null===n.init?"null":ce(e,n.init),r=le(e,n.id);switch(Oe(r),r.scope){case"local":return`lscope['${r.var}']=${t};`;case"global":return`gscope['${r.var}']=${t};`;default:throw r.scope,new d(null,"NeverReach",n.id)}}function Ee(e,n){return Ne(e,ce(e,n.object),n)}function Ne(e,n,t){return`lang.member(${n}, ${t.computed?ce(e,t.property):`'${t.property.name}'`})`}function Be(e,n,t){for(const r of t)switch(r.type){case"MemberExpression":n=Ne(e,n,r);break;case"CallExpression":n=ze(e,n,r.arguments);break;default:throw new d(null,"Unrecognized",r)}return n}function _e(e,n,t){return`lang.tryMember(${n}, ${t.computed?ce(e,t.property):`'${t.property.name}'`})`}function Ve(e,n){const t=a(n);let r="",o=ce(e,t.root);for(const l of t.sections)r+=`(${e.symbols.safeAccessTempVarId} = ${_e(e,o,l.checked)}) == null ? null : `,o=Be(e,e.symbols.safeAccessTempVarId,l.unchecked);return`(${r}${o})`}function Te(e,n){try{return"lang.unary("+ce(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function Le(e,n){try{const t=[];for(let r=0;r<n.elements.length;r++)"Literal"===n.elements[r].type?t.push(ce(e,n.elements[r])):t.push("lang.aCheck("+ce(e,n.elements[r])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function Re(e,n){try{const t=[];let r=0;for(const o of n.quasis)t.push(o.value?JSON.stringify(o.value.cooked):JSON.stringify("")),!1===o.tail&&(t.push(n.expressions[r]?"lang.castString(lang.aCheck("+ce(e,n.expressions[r])+", 'TemplateLiteral'))":""),r++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function Ue(e,n){try{return"lang.binary("+ce(e,n.left)+","+ce(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function De(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new d(null,"LogicalExpressionOnlyBoolean",n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new d(null,"LogicalExpressionOnlyBoolean",n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+ce(e,n.left)+") "+n.operator+" lang.logicalCheck("+ce(e,n.right)+"))";throw new d(null,"LogicExpressionOrAnd",null)}catch(t){throw t}}function Ge(e,n){const t=oe(e,n);switch(Oe(t),t.scope){case"local":return rn(`lscope['${t.var}']`);case"global":return rn(`gscope['${t.var}']`);default:throw t.scope,new d(null,"NeverReach",n)}}function qe(e,n){if("Identifier"===n.callee.type){const t=oe(e,n.callee,"FunctionNotFound");if("global"===t.scope)switch(t.name){case"iif":return Pe(e,n);case"when":return Ke(e,n);case"defaultvalue":return We(e,n);case"decode":return Ze(e,n)}}return ze(e,ce(e,n.callee),n.arguments)}function ze(e,n,t){const r=`lang.callfunc(${n}, [${t.map(n=>ce(e,n)).join(", ")}], runtimeCtx)`;return e.isAsync?`(yield ${r})`:r}function Pe(e,n){try{if(3!==n.arguments.length)throw new d(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId();return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ce(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${ce(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${ce(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function We(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new d(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId(),r=e.symbols.nextTempVarId();return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ce(e,n.arguments[0])};\n var ${r} = ${ce(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${r});\n return ${t} != null && ${t} !== "" ? ${t} : ${ce(e,n.arguments[2])};\n ${e.isAsync?"})}()))":"}()"}`:`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ce(e,n.arguments[0])};\n if (${t} === null) {\n return ${ce(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${ce(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${ce(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ke(e,n){try{if(n.arguments.length<3)throw new d(null,"WrongNumberOfParameters",n);if(n.arguments.length%2==0)throw new d(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId();let r="var ";for(let o=0;o<n.arguments.length-1;o+=2)r+=`${t} = lang.mustBoolean(${ce(e,n.arguments[o])}, runtimeCtx);\n if (${t} === true ) {\n return ${ce(e,n.arguments[o+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${r}\n return ${ce(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ze(e,n){try{if(n.arguments.length<2)throw new d(null,"WrongNumberOfParameters",n);if(2===n.arguments.length)return`(${ce(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new d(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId();let r;if(n.arguments.every((e,n)=>n%2==0||"Literal"===e.type)){r=`switch (${t}) {`;for(let t=1;t<n.arguments.length-1;t+=2){const o=n.arguments[t],l=n.arguments[t+1];null==o.value?r+="\n case null:\n case lc.voidOperation:\n ":r+=`\n case ${JSON.stringify(o.value)}:\n `,r+=`return ${ce(e,l)}`}r+="}"}else{const o=e.symbols.nextTempVarId();r="var ";for(let l=1;l<n.arguments.length-1;l+=2){const a=n.arguments[l],s=n.arguments[l+1];r+=`${o} = ${ce(e,a)};\n if (lang.binary(${o}, ${t}, "==") === true ) {\n return ${ce(e,s)}\n }\n `}}return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ce(e,n.arguments[0])};\n ${r}\n return ${ce(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Je(e,n){try{return ie(e,n,(e,n)=>{throw new f(e,"Unrecognized",n)})}catch(t){throw t}}function Ye(e){const n=function(){this.textformatting=p.textFormatting()};n.prototype=Object.create(null),n.provided=new Set(["textformatting","infinity","pi"]),n.prototype.infinity=Number.POSITIVE_INFINITY,n.prototype.pi=Math.PI;for(const[t,r]of Object.entries(e))n.prototype[t]=new y(r),n.provided.add(t);return n}function He(){const e=Object.create(null);L(e,ie),z(e,ie),R(e,ie,ae),G(e,ie),U(e,ie),q(e,ie),P(e,ie),e.iif=Je,e.decode=Je,e.when=Je,e.defaultvalue=Je;const n=Ye(e);D(e,ie);return{ScopeSync:Ye(e),ScopeAsync:n}}const{ScopeSync:Qe,ScopeAsync:Xe}=He();function en(e,n){const t={mode:n,compiled:!0,functions:Object.create(null),signatures:[],standardFunction:ie,standardFunctionAsync:ie,evaluateIdentifier:ae};for(const r of e)r.registerFunctions(t);if("sync"===n)for(const[r,o]of Object.entries(t.functions))Qe.prototype[r]=new y(o),Qe.provided.add(r);else for(const[r,o]of Object.entries(t.functions))Xe.prototype[r]=new y(o),Xe.provided.add(r);for(const r of t.signatures)_(r,n)}en([T],"sync"),en([T],"async"),en([V],"async");const nn=Symbol("uninitialized"),tn="lang.uninitialized";function rn(e){return`lang.requireInitialized(${e})`}const on={uninitialized:nn,requireInitialized(e){if(e===nn)throw new f(null,"InvalidIdentifier",null);return e},isNumber:e=>Q(e),isArray:e=>H(e),isImmutableArray:e=>C(e),isDictionaryLike:e=>B(e),isString:e=>X(e),isDictionary:e=>N(e),isGeometry:e=>E(e),getGeometryKeys:e=>m(e),getGeometryMember:(e,n,t)=>c(e,n,t,null),error(e){throw new f(null,e,null)},__awaiter(e,n,t,r){const o=r.apply(e,n||[]);let l=o.next();for(;!l.done&&!K(l.value);)l=o.next(l.value);return l.done?l.value:new Promise((e,n)=>{function t(r){for(;!r.done;){if(K(r.value))return void Promise.resolve(r.value).then(e=>{try{t(o.next(e))}catch(r){n(r)}},e=>{try{t(o.throw(e))}catch(r){n(r)}});try{r=o.next(r.value)}catch(l){return void n(l)}}e(r.value)}t(l)})},functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push({}),n.depthCounter.depth>64)throw new f(null,"MaximumCallDepth",null);const t=e.apply(this,arguments);return K(t)?t.then(e=>(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,e)):(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,t)},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new f(n,"BooleanConditionRequired",null)},castString:e=>M(e),aCheck(e,n){if(x(e)){if("ArrayExpression"===n)throw new f(null,"NoFunctionInArray",null);if("ObjectExpression"===n)throw new f(null,"NoFunctionInDictionary",null);throw new f(null,"NoFunctionInTemplateLiteral",null)}return e===O?null:e},Dictionary:p,Feature:h,UserDefinedCompiledFunction:se,dictionary(e){const n=Object.create(null),t=new Map;for(let o=0;o<e.length;o+=2){if(x(e[o+1]))throw new f(null,"NoFunctionInDictionary",null);if(!1===X(e[o]))throw new f(null,"KeyMustBeString",null);let r=e[o].toString();const l=r.toLowerCase();t.has(l)?r=t.get(l):t.set(l,r),e[o+1]===O?n[r]=null:n[r]=e[o+1]}const r=new p(n);return r.immutable=!1,r},entry:(e,n)=>p.containerEntry(e,n),strCheck(e){if(!1===X(e))throw new f(null,"KeyMustBeString",null);return e},unary(e,n){if(ee(e)){if("!"===n)return!e;if("-"===n)return-1*F(e);if("+"===n)return 1*F(e);if("~"===n)return~F(e);throw new f(null,"UnsupportUnaryOperator",null)}if("-"===n)return-1*F(e);if("+"===n)return 1*F(e);if("~"===n)return~F(e);throw new f(null,"UnsupportUnaryOperator",null)},logicalCheck(e){if(!1===ee(e))throw new f(null,"LogicExpressionOrAnd",null);return e},logical(e,n,t){if(ee(e)&&ee(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new f(null,"LogicExpressionOrAnd",null)}throw new f(null,"LogicExpressionOrAnd",null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return k(F(e),F(n),t);case"==":return A(e,n);case"!=":return!A(e,n);case"<":case">":case"<=":case">=":return j(e,n,t);case"+":return X(e)||X(n)?M(e)+M(n):F(e)+F(n);case"-":return F(e)-F(n);case"*":return F(e)*F(n);case"/":return F(e)/F(n);case"%":return F(e)%F(n);default:throw new f(null,"UnsupportedOperator",null)}},assign(e,n,t){switch(n){case"=":return e===O?null:e;case"/=":return F(t)/F(e);case"*=":return F(t)*F(e);case"-=":return F(t)-F(e);case"+=":return X(t)||X(e)?M(t)+M(e):F(t)+F(e);case"%=":return F(t)%F(e);default:throw new f(null,"UnsupportedOperator",null)}},update(e,n,t,r){const o=F(this.requireInitialized(e[n]));return e[n]="++"===t?o+1:o-1,!1===r?o:"++"===t?o+1:o-1},createFeature:(e,n,t)=>h.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,r){let o;if(H(e)){if(!Q(n))throw new f(null,"ArrayAccessMustBeNumber",null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new f(null,"OutOfBounds",null);o=F(e[n]),e[n]="++"===t?o+1:o-1}else if(e instanceof p){if(!1===X(n))throw new f(null,"KeyAccessorMustBeString",null);if(!0!==e.hasField(n))throw new f(null,"FieldNotFound",null,{key:n});o=F(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else if(I(e)){if(!1===X(n))throw new f(null,"KeyAccessorMustBeString",null);if(!0!==e.hasField(n))throw new f(null,"FieldNotFound",null);o=F(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else{if(C(e))throw new f(null,"Immutable",null);if(!(e instanceof un))throw new f(null,"InvalidIdentifier",null);if(!1===X(n))throw new f(null,"ModuleAccessorMustBeString",null);if(!0!==e.hasGlobal(n))throw new f(null,"ModuleExportNotFound",null);o=F(e.global(n)),e.setGlobal(n,"++"===t?o+1:o-1)}return!1===r?o:"++"===t?o+1:o-1},assignmember(e,n,t,r){if(H(e)){if(!Q(n))throw new f(null,"ArrayAccessMustBeNumber",null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new f(null,"OutOfBounds",null);if(n===e.length){if("="!==t)throw new f(null,"OutOfBounds",null);e[n]=this.assign(r,t,e[n])}else e[n]=this.assign(r,t,e[n])}else if(e instanceof p){if(!1===X(n))throw new f(null,"KeyAccessorMustBeString",null);if(!0===e.hasField(n))e.setField(n,this.assign(r,t,e.field(n)));else{if("="!==t)throw new f(null,"FieldNotFound",null);e.setField(n,this.assign(r,t,null))}}else if(I(e)){if(!1===X(n))throw new f(null,"KeyAccessorMustBeString",null);if(!0===e.hasField(n))e.setField(n,this.assign(r,t,e.field(n)));else{if("="!==t)throw new f(null,"FieldNotFound",null);e.setField(n,this.assign(r,t,null))}}else{if(C(e))throw new f(null,"Immutable",null);if(!(e instanceof un))throw new f(null,"InvalidIdentifier",null);if(!1===X(n))throw new f(null,"ModuleAccessorMustBeString",null);if(!e.hasGlobal(n))throw new f(null,"ModuleExportNotFound",null);e.setGlobal(n,this.assign(r,t,e.global(n)))}},member:(e,n)=>u(e,n),tryMember:(e,n)=>i(e,n),callfunc(e,n,t){if(x(e))return e.call(t,{arguments:n,preparsed:!0});throw new f(null,"CallNonFunction",null)},loadModule(e,n){const t=n.moduleFactoryMap[e];if(n.moduleSingletons[t])return n.moduleSingletons[t];const r=n.moduleFactory[t]({moduleSingletons:n.moduleSingletons,depthCounter:n.depthCounter,lrucache:n.lrucache,interceptor:n.interceptor,services:n.services,console:n.console,abortSignal:n.abortSignal,timeZone:n.timeZone??null,spatialReference:n.spatialReference});return n.moduleSingletons[t]=r,r},getNestedOptionalValue:(e,n)=>s(e,n)};function ln(e){console.log(e)}function an(t,o,l=!1){let a=null;t.usesModules&&(a=new r(null,t.loadedModules));const s=Object.create(null),i=new Set(Object.keys(o?.vars||{}).map(n=>e(n))),u=new Set(Object.keys(o?.customfunctions||{}).map(n=>e(n))),c=ue(t,l?Xe.provided:Qe.provided,new Set([...i,...u]),l,a,s);let m;m=l?["var runtimeCtx = this.prepare(context, true);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","return lang.__awaiter(this, void 0, void 0, function* () {"," function mainBody() {"," return lang.__awaiter(this, void 0, void 0, function* () {",` ${c.body}`," });"," }"," return this.postProcess(yield mainBody());","});"].join("\n"):["var runtimeCtx = this.prepare(context, false);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","function mainBody() {",` ${c.body}`,"}","return this.postProcess(mainBody());"].join("\n");const{symbolMetadata:p,moduleFactoryMap:d}=c,g={lc:v,lang:on,postProcess(e){if(S(e))return null;if(x(e))throw new f(null,"IllegalResult",null);return e},prepare(e,t){const r=e.spatialReference??J.WebMercator,o=t?new Xe:new Qe;for(const n of u)null!=e.customfunctions&&n in e.customfunctions?o[n]=e.customfunctions[n]??null:o[n]=nn;for(const n of i){if(null==e.vars||!(n in e.vars)){n in o||(o[n]=nn);continue}const t=e.vars[n]??null;Y(t)?o[n]=h.createFromGraphic(t,e.timeZone??null):o[n]=t}return{lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??ln,abortSignal:e.abortSignal??n,timeZone:e.timeZone??null,spatialReference:r,track:e.track,globalScope:o,localStack:[],depthCounter:{depth:1},symbolMetadata:p,moduleFactory:s,moduleFactoryMap:d,moduleSingletons:Object.create(null)}}};return new Function("context",m).bind(g)}async function sn(){return en([await import("./functions/geomasync.js")],"async"),!0}class un extends t{constructor(e){super(),this.moduleContext=e}hasGlobal(n){const t=this.moduleContext.symbolMetadata.exports;return t.has(n)||t.has(e(n))}setGlobal(n,t){if(x(t))throw new f(null,"AssignModuleFunction",null);const r=this.moduleContext.symbolMetadata.globals.get(e(n));if(null==r)throw new f(null,"ModuleExportNotFound",null);this.moduleContext.globalScope[r]=t}global(n){const t=this.moduleContext.symbolMetadata.globals.get(e(n));if(null==t)throw new f(null,"ModuleExportNotFound",null);const r=this.moduleContext.globalScope,o=on.requireInitialized(r[t]);if(x(o)&&!(o instanceof b)){const e=new b;return e.fn=o,e.parameterEvaluator=ie,e.context=this.moduleContext,r[t]=e,e}return o}}function cn(e,t,o){const l=new r(null,e.loadedModules),a=ue(e,o?Xe.provided:Qe.provided,new Set,o,l,t);let s;s=o?["var runtimeCtx = this.prepare(context, true);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","return lang.__awaiter(this, void 0, void 0, function* () {"," function mainBody() {"," return lang.__awaiter(this, void 0, void 0, function* () {",` ${a.body}`," });"," }"," yield mainBody();"," return this.prepareModule(runtimeCtx);","});"].join("\n"):["var runtimeCtx = this.prepare(context, false);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","function mainBody() {",` ${a.body}`,"}","mainBody();","return this.prepareModule(runtimeCtx);"].join("\n");const{symbolMetadata:i,moduleFactoryMap:u}=a,c={lc:v,lang:on,prepareModule:e=>new un(e),prepare(e,r){const o=e.spatialReference??J.WebMercator,l=r?new Xe:new Qe;return{lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??ln,abortSignal:e.abortSignal??n,timeZone:e.timeZone??null,spatialReference:o,track:null,globalScope:l,localStack:[],depthCounter:e.depthCounter,symbolMetadata:i,moduleFactory:t,moduleFactoryMap:u,moduleSingletons:e.moduleSingletons}}};return new Function("context",s).bind(c)}export{se as UserDefinedCompiledFunction,an as compileScript,sn as enableAsyncSupport,en as extend};