UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) • 21.8 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{toSymbolId as e,neverAbortedSignal as t}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,flattenAccessChain as a,collectDeclaredLocalNames as i}from"./compilerUtils.js";import{getNestedOptionalValue as s,getGeometryKeys as c,tryGetMember as l,getMember as u,getGeometryMember as f}from"./containerUtils.js";import p from"./Dictionary.js";import{ArcadeExecutionError as w,ensureArcadeExecutionError as d}from"./executionError.js";import{Feature as h}from"./Feature.js";import{NativeFunction as m,ScopeMarshalledFunction as g,ArcadeFunction as y,wrapModuleScopedResponse as b}from"./FunctionWrapper.js";import{R as v,I as x,q as S,i as k,z as F,A as j,v as O,B as R,r as I,s as C,u as E,w as M,x as A,k as N,j as B,y as U,m as G,h as L}from"../chunks/languageUtils.js";import{addFunctionDeclaration as z}from"./treeAnalysis.js";import{A as D}from"../chunks/aiServices.js";import{A as _}from"../chunks/array.js";import{registerFunctions as Z}from"./functions/date.js";import{registerFunctions as q}from"./functions/feature.js";import{registerFunctions as P}from"./functions/geomasync.js";import{registerFunctions as W}from"./functions/geometry.js";import{registerFunctions as V}from"./functions/maths.js";import{registerFunctions as K}from"./functions/stats.js";import{registerFunctions as T}from"./functions/string.js";import{registerFunctions as Y}from"./functions/track.js";import $ from"../core/Logger.js";import H from"../geometry/SpatialReference.js";import{isGraphic as J}from"../support/graphicInstanceUtils.js";import{isBoolean as Q,isString as X,isArray as ee,isNumber as te}from"../support/guards.js";const ne=()=>$.getLogger("esri.arcade.arcadeAsyncRuntime"),re=Symbol("uninitialized");function oe(e){if(e===re)throw new w(null,"InvalidIdentifier",null)}function ae(e){return oe(e),e}function ie(t,n){const r=e(n);if(null!==t.localScope){const e=t.localScope[r];if(void 0!==e)return{scope:t.localScope,id:r,var:e}}const o=t.globalScope[r];if(void 0!==o)return{scope:t.globalScope,id:r,var:o};throw new w(t,"InvalidIdentifier",n)}function se(t,n,r="InvalidIdentifier"){const o=e(n);if(null!==t.localScope){const e=t.localScope[o];if(void 0!==e)return oe(e),e.value}const a=t.globalScope[o];if(void 0!==a)return oe(a),a.value;throw new w(t,r,n)}const ce=function(){};async function le(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await he(e,t.arguments[r]));return n}async function ue(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await le(e,t))}ce.prototype=Object.freeze(Object.create(null));class fe extends y{constructor(e,t,n,r){super(),this.definition=e,this.context=t,this._params=n,this._locals=r}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,lrucache:this.context.lrucache,timeZone:this.context.timeZone??null,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,services:this.context.services,abortSignal:this.context.abortSignal,localScope:new ce,depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope,track:this.context.track};if(n.depthCounter.depth>64)throw new w(e,"MaximumCallDepth",null);return pe(n,this.definition.body,this._params,this._locals,t,null)}}call(e,t){return de(e,t,(n,r,o)=>{const a={spatialReference:e.spatialReference,services:e.services,console:e.console,libraryResolver:e.libraryResolver,exports:e.exports,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:new ce,abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1},track:e.track};if(a.depthCounter.depth>64)throw new w(e,"MaximumCallDepth",t);return pe(a,this.definition.body,this._params,this._locals,o,t)})}marshalledCall(e,t,n,r){return r(e,t,async(o,a,i)=>{const s={spatialReference:e.spatialReference,services:e.services,globalScope:n.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,abortSignal:e.abortSignal,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:new ce,track:e.track};return i=i.map(t=>!k(t)||t instanceof g?t:b(t,e,r)),b(await pe(s,this.definition.body,this._params,this._locals,i,t),n,r)})}}async function pe(e,t,n,r,o,a){if(n.length!==o.length)throw new w(e,"WrongNumberOfParameters",a);if(null!=e.localScope){for(let t=0;t<n.length;t++)e.localScope[n[t]]={value:o[t]};for(const t of r)e.localScope[t]=re}const i=await me(e,t);if(i instanceof v)return i.value;if(i===F)throw new w(e,"UnexpectedToken",a);if(i===j)throw new w(e,"UnexpectedToken",a);return i instanceof x?i.value:i}class we extends n{constructor(e){super(),this.moduleGlobalContext=e}global(t){const n=e(t);if(!this.moduleGlobalContext.exports.has(n))throw new w(null,"ModuleExportNotFound",null);const r=this.moduleGlobalContext.globalScope[n];if(oe(r),k(r.value)&&!(r.value instanceof g)){const e=new g;return e.fn=r.value,e.parameterEvaluator=ue,e.context=this.moduleGlobalContext,this.moduleGlobalContext.globalScope[n]={value:e},e}return r.value}setGlobal(t,n){if(k(n))throw new w(null,"AssignModuleFunction",null);const r=e(t);if(!this.moduleGlobalContext.exports.has(r))throw new w(null,"ModuleExportNotFound",null);this.moduleGlobalContext.globalScope[r]={value:n}}hasGlobal(t){return this.moduleGlobalContext.exports.has(e(t))}static async load(e,n){const{globals:a,exports:i}=o(n),s=new it;for(const t of a)t in s||(s[t]=re);const c=e.spatialReference??H.WebMercator,l={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??ct,abortSignal:e.abortSignal??t,timeZone:e.timeZone??null,spatialReference:c,track:null,depthCounter:{depth:1},libraryResolver:new r(e.libraryResolver._moduleSingletons,n.loadedModules),exports:i,localScope:null,globalScope:s};return await Ae(l,n),new we(l)}}async function de(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await le(e,t))}async function he(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"UpdateExpression":return await Re(e,t);case"AssignmentExpression":return await Ce(e,t);case"TemplateLiteral":return await Qe(e,t);case"Identifier":return $e(e,t);case"MemberExpression":return await _e(e,t);case"Literal":return t.value;case"CallExpression":return await He(e,t);case"UnaryExpression":return await Ve(e,t);case"BinaryExpression":return await Te(e,t);case"LogicalExpression":return await Ye(e,t);case"ArrayExpression":return await Ke(e,t);case"ObjectExpression":return await ge(e,t);case"MemberAccessChainExpression":return await We(e,t);case"SafeMemberExpression":throw ne().error("SafeMemberExpression outside of MemberAccessChainExpression"),new w(null,"Unrecognized",t);default:throw new w(e,"Unrecognized",t)}}catch(n){throw d(e,t,n)}}async function me(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"ImportDeclaration":return await Ge(e,t);case"ExportNamedDeclaration":return await Le(e,t);case"VariableDeclaration":return await ze(e,t);case"BlockStatement":return await Ae(e,t);case"FunctionDeclaration":return await Ue(e,t);case"ReturnStatement":return await Be(e,t);case"IfStatement":return await Me(e,t);case"ExpressionStatement":return await Ee(e,t);case"ForStatement":return await be(e,t);case"WhileStatement":return await ye(e,t);case"ForInStatement":return await je(e,t);case"ForOfStatement":return await Oe(e,t);case"BreakStatement":return F;case"EmptyStatement":return O;case"ContinueStatement":return j;default:throw new w(e,"Unrecognized",t)}}catch(n){throw d(e,t,n)}}async function ge(e,t){const n=[];for(let i=0;i<t.properties.length;i++){const r=t.properties[i],o=await he(e,r.value),a="Identifier"===r.key.type?r.key.name:await he(e,r.key);n[i]={key:a,value:o}}const r=Object.create(null),o=new Map;for(let i=0;i<n.length;i++){const a=n[i];if(k(a.value))throw new w(e,"NoFunctionInDictionary",t);if(!1===X(a.key))throw new w(e,"KeyMustBeString",t);let s=a.key.toString();const c=s.toLowerCase();o.has(c)?s=o.get(c):o.set(c,s),a.value===O?r[s]=null:r[s]=a.value}const a=new p(r);return a.immutable=!1,a}async function ye(e,t){let n=await he(e,t.test);if(!1===n)return O;if(!0!==n)throw new w(e,"BooleanConditionRequired",t);for(;!0===n;){const r=await me(e,t.body);if(r===F)break;if(r instanceof v)return r;if(n=await he(e,t.test),!0!==n&&!1!==n)throw new w(e,"BooleanConditionRequired",t)}return O}async function be(e,t){try{for(null!==t.init&&("VariableDeclaration"===t.init.type?await me(e,t.init):await he(e,t.init));;){if(null!==t.test){const n=await he(e,t.test);if(!0===e.abortSignal?.aborted)throw new w(e,"Cancelled",t);if(!1===n)break;if(!0!==n)throw new w(e,"BooleanConditionRequired",t)}const n=await me(e,t.body);if(n===F)break;if(n instanceof v)return n;null!==t.update&&await he(e,t.update)}return O}catch(n){throw n}}async function ve(e,t,n,r,o="i"){const a=n.length;for(let i=0;i<a;i++){if("k"===o){if(i>=n.length)throw new w(e,"OutOfBounds",t);r.scope[r.id]={value:n[i]}}else r.scope[r.id]={value:i};const a=await me(e,t.body);if(a===F)break;if(a instanceof v)return a}return O}async function xe(e,t,n,r,o="i"){const a=n.length();for(let i=0;i<a;i++){r.scope[r.id]="k"===o?{value:n.get(i)}:{value:i};const a=await me(e,t.body);if(a===F)break;if(a instanceof v)return a}return O}async function Se(e,t,n,r){e:for await(const o of await n.queryAll(e.abortSignal))for(const a of o){r.scope[r.id]={value:h.createFromGraphicLikeObject(a.geometry,a.attributes,n,e.timeZone)};const o=await me(e,t.body);if(o===F)break e;if(o instanceof v)return o}return O}async function ke(e,t,n,r){for(const o of n.keys()){const a=n.field(o);r.scope[r.id]={value:p.containerEntry(o,a)};const i=await me(e,t.body);if(i===F)break;if(i instanceof v)return i}return O}async function Fe(e,t,n,r){for(const o of c(n)){const a=f(n,o,e,t);r.scope[r.id]={value:p.containerEntry(o,a)};const i=await me(e,t.body);if(i===F)break;if(i instanceof v)return i}return O}async function je(e,t){const n=await he(e,t.right);"VariableDeclaration"===t.left.type&&await me(e,t.left);const r=ie(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);return ee(n)||X(n)?await ve(e,t,n,r):B(n)?await xe(e,t,n,r):n instanceof p||U(n)?await ve(e,t,n.keys(),r,"k"):G(n)?await Se(e,t,n,r):L(n)?await ve(e,t,c(n),r,"k"):O}async function Oe(e,t){const n=await he(e,t.right);"VariableDeclaration"===t.left.type&&await me(e,t.left);const r=ie(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);return ee(n)||X(n)?await ve(e,t,n,r,"k"):B(n)?await xe(e,t,n,r,"k"):n instanceof p||U(n)?await ke(e,t,n,r):G(n)?await Se(e,t,n,r):L(n)?await Fe(e,t,n,r):O}async function Re(e,t){const n=t.argument;if("CallExpression"===n.type)throw new w(e,"NeverReach",t);if("MemberExpression"===n.type){const r=await he(e,n.object);let o,a;if(!0===n.computed)o=await he(e,n.property);else{if("Identifier"!==n.property.type)throw new w(e,"Unrecognized",t);o=n.property.name}if(ee(r)){if(!te(o))throw new w(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>=r.length)throw new w(e,"OutOfBounds",t);a=I(r[o]),r[o]="++"===t.operator?a+1:a-1}else if(r instanceof p){if(!1===X(o))throw new w(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new w(e,"FieldNotFound",t,{key:o});a=I(r.field(o)),r.setField(o,"++"===t.operator?a+1:a-1)}else if(r instanceof we){if(!1===X(o))throw new w(e,"ModuleAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new w(e,"ModuleExportNotFound",t);a=I(r.global(o)),r.setGlobal(o,"++"===t.operator?a+1:a-1)}else{if(!N(r))throw B(r)?new w(e,"Immutable",t):new w(e,"InvalidParameter",t);if(!1===X(o))throw new w(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new w(e,"FieldNotFound",t,{key:o});a=I(r.field(o)),r.setField(o,"++"===t.operator?a+1:a-1)}return!1===t.prefix?a:"++"===t.operator?a+1:a-1}const r=ie(e,n),o=I(ae(r.var).value),a="++"===t.operator?o+1:o-1;return r.scope[r.id]={value:a},!1===t.prefix?o:"++"===t.operator?o+1:o-1}function Ie(e,t,n,r,o){switch(t){case"=":return e===O?null:e;case"/=":return I(n)/I(e);case"*=":return I(n)*I(e);case"-=":return I(n)-I(e);case"+=":return X(n)||X(e)?C(n)+C(e):I(n)+I(e);case"%=":return I(n)%I(e);default:throw new w(o,"UnsupportedOperator",r)}}async function Ce(e,t){const n=t.left;if("MemberExpression"===n.type){const r=await he(e,n.object);let o;if(!0===n.computed)o=await he(e,n.property);else{if("Identifier"!==n.property.type)throw new w(e,"InvalidIdentifier",t);o=n.property.name}const a=await he(e,t.right);if(ee(r)){if(!te(o))throw new w(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>r.length)throw new w(e,"OutOfBounds",t);if(o===r.length){if("="!==t.operator)throw new w(e,"OutOfBounds",t);r[o]=Ie(a,t.operator,r[o],t,e)}else r[o]=Ie(a,t.operator,r[o],t,e)}else if(r instanceof p){if(!1===X(o))throw new w(e,"KeyAccessorMustBeString",t);if(!0===r.hasField(o))r.setField(o,Ie(a,t.operator,r.field(o),t,e));else{if("="!==t.operator)throw new w(e,"FieldNotFound",t,{key:o});r.setField(o,Ie(a,t.operator,null,t,e))}}else if(r instanceof we){if(!1===X(o))throw new w(e,"KeyAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new w(e,"ModuleExportNotFound",t);r.setGlobal(o,Ie(a,t.operator,r.global(o),t,e))}else{if(!N(r))throw B(r)?new w(e,"Immutable",t):new w(e,"InvalidParameter",t);if(!1===X(o))throw new w(e,"KeyAccessorMustBeString",t);if(!0===r.hasField(o))r.setField(o,Ie(a,t.operator,r.field(o),t,e));else{if("="!==t.operator)throw new w(e,"FieldNotFound",t,{key:o});r.setField(o,Ie(a,t.operator,null,t,e))}}return O}const r=ie(e,n),o=await he(e,t.right);return r.scope[r.id]={value:Ie(o,t.operator,"="!==t.operator?ae(r.var).value:null,t,e)},O}async function Ee(e,t){const n=await he(e,t.expression);return n===O?O:new x(n)}async function Me(e,t){const n=await he(e,t.test);if(!0===n)return me(e,t.consequent);if(!1===n)return null!==t.alternate?me(e,t.alternate):O;throw new w(e,"BooleanConditionRequired",t)}async function Ae(e,t){return Ne(e,t,0)}async function Ne(e,t,n){if(n>=t.body.length)return O;const r=await me(e,t.body[n]);return r instanceof v||r===F||r===j||n===t.body.length-1?r:Ne(e,t,n+1)}async function Be(e,t){if(null===t.argument)return new v(O);const n=await he(e,t.argument);return new v(n)}async function Ue(t,n){if(null!=t.localScope)throw ne().error("Function declarations are only valid in global scope."),new w(t,"NeverReach",n);const r=e(n.id);if(!(r in t.globalScope))throw ne().error(`Function "${r}" not declared.`),new w(t,"NeverReach",n);const o=i(n),a=n.params.map(t=>e(t)),s=Array.from(o).filter(e=>!a.includes(e));return t.globalScope[r]={value:new fe(n,t,a,s)},O}async function Ge(e,t){const n=ie(e,t.specifiers[0].local),r=e.libraryResolver;if(null==r)throw ne().error("Internal error: module loader not initialized"),new w(e,"NeverReach",t);const o=r.loadLibrary(n.id);let a;return r._moduleSingletons?.has(o.uri)?a=r._moduleSingletons.get(o.uri):(a=await we.load(e,o.syntax),r._moduleSingletons?.set(o.uri,a)),n.scope[n.id]={value:a},O}async function Le(e,t){return await me(e,t.declaration),O}async function ze(e,t){for(const n of t.declarations)await De(e,n);return O}async function De(e,t){let n=null;n=null===t.init?null:await he(e,t.init),n===O&&(n=null);const r=ie(e,t.id);r.scope[r.id]={value:n}}async function _e(e,t){return Ze(e,await he(e,t.object),t)}async function Ze(e,t,n){const r=n.computed?await he(e,n.property):n.property.name;return u(t,r)}async function qe(e,t,n){for(const r of n)switch(r.type){case"MemberExpression":t=await Ze(e,t,r);break;case"CallExpression":t=await Je(e,t,r);break;default:throw new w(null,"Unrecognized",r)}return t}async function Pe(e,t,n){const r=n.computed?await he(e,n.property):n.property.name;return l(t,r)}async function We(e,t){const n=a(t);let r=await he(e,n.root);for(const o of n.sections){const t=await Pe(e,r,o.checked);if(null==t)return null;r=await qe(e,t,o.unchecked)}return r}async function Ve(e,t){const n=await he(e,t.argument);if(Q(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*I(n);if("+"===t.operator)return 1*I(n);if("~"===t.operator)return~I(n);throw new w(e,"UnsupportUnaryOperator",t)}if("-"===t.operator)return-1*I(n);if("+"===t.operator)return 1*I(n);if("~"===t.operator)return~I(n);throw new w(e,"UnsupportUnaryOperator",t)}async function Ke(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await he(e,t.elements[r]));for(let r=0;r<n.length;r++){if(k(n[r]))throw new w(e,"NoFunctionInArray",t);n[r]===O&&(n[r]=null)}return n}async function Te(e,t){const n=await he(e,t.left),r=await he(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return A(I(n),I(r),t.operator);case"==":return M(n,r);case"!=":return!M(n,r);case"<":case">":case"<=":case">=":return E(n,r,t.operator);case"+":return X(n)||X(r)?C(n)+C(r):I(n)+I(r);case"-":return I(n)-I(r);case"*":return I(n)*I(r);case"/":return I(n)/I(r);case"%":return I(n)%I(r);default:throw t.operator,new w(e,"UnsupportedOperator",t)}}async function Ye(e,t){const n=await he(e,t.left);if(!Q(n))throw new w(e,"LogicalExpressionOnlyBoolean",t);switch(t.operator){case"||":{if(!0===n)return n;const r=await he(e,t.right);if(Q(r))return r;throw new w(e,"LogicExpressionOrAnd",t)}case"&&":{if(!1===n)return n;const r=await he(e,t.right);if(Q(r))return r;throw new w(e,"LogicExpressionOrAnd",t)}default:throw t.operator,new w(e,"LogicExpressionOrAnd",t)}}function $e(e,t){return se(e,t)}async function He(e,t){return Je(e,"Identifier"===t.callee.type?se(e,t.callee,"FunctionNotFound"):await he(e,t.callee),t)}async function Je(e,t,n){if(k(t))return t.call(e,n);throw new w(e,"CallNonFunction",n)}async function Qe(e,t){let n="",r=0;for(const o of t.quasis)if(n+=o.value?o.value.cooked:"",!1===o.tail){if(t.expressions[r]){const o=await he(e,t.expressions[r]);if(k(o))throw new w(e,"NoFunctionInTemplateLiteral",t);n+=C(o)}r++}return n}async function Xe(e,t){R(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await he(e,t.arguments[0]);if(!1===Q(n))throw new w(e,"BooleanConditionRequired",t);return he(e,n?t.arguments[1]:t.arguments[2])}async function et(e,t){R(null===t.arguments?[]:t.arguments,2,3,e,t);const n=await he(e,t.arguments[0]);if(3===t.arguments.length){const r=await he(e,t.arguments[1]),o=s(n,r);return null!=o&&""!==o?o:he(e,t.arguments[2])}return null==n||""===n?he(e,t.arguments[1]):n}async function tt(e,t){if(t.arguments.length<2)throw new w(e,"WrongNumberOfParameters",t);if(2===t.arguments.length)return he(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new w(e,"WrongNumberOfParameters",t);return nt(e,t,1,await he(e,t.arguments[0]))}async function nt(e,t,n,r){const o=await he(e,t.arguments[n]);if(M(o,r))return he(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?he(e,t.arguments[n]):2===a?null:3===a?he(e,t.arguments[n+2]):nt(e,t,n+2,r)}async function rt(e,t){if(t.arguments.length<3)throw new w(e,"WrongNumberOfParameters",t);if(t.arguments.length%2==0)throw new w(e,"WrongNumberOfParameters",t);const n=await he(e,t.arguments[0]);if(!1===Q(n))throw new w(e,"BooleanConditionRequired",t.arguments[0]);return ot(e,t,0,n)}async function ot(e,t,n,r){if(!0===r)return he(e,t.arguments[n+1]);if(3===t.arguments.length-n)return he(e,t.arguments[n+2]);const o=await he(e,t.arguments[n+2]);if(!1===Q(o))throw new w(e,"ModuleExportNotFound",t.arguments[n+2]);return ot(e,t,n+2,o)}function at(){const e=Object.create(null);Z(e,ue),T(e,ue),q(e,ue,$e),V(e,ue),W(e,ue),K(e,ue),Y(e,ue),P({functions:e,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:ue,standardFunctionAsync:de}),e.iif=Xe,e.defaultvalue=et,e.decode=tt,e.when=rt;const t=function(){this.textformatting={value:p.textFormatting()}};t.prototype=Object.create(null),t.prototype.infinity=Object.freeze({value:Number.POSITIVE_INFINITY}),t.prototype.pi=Object.freeze({value:Math.PI});for(const[n,r]of Object.entries(e))t.prototype[n]=Object.freeze({value:new m(r)});return t}const it=at();function st(e){const t={mode:"async",compiled:!1,functions:Object.create(null),signatures:[],standardFunction:ue,standardFunctionAsync:de,evaluateIdentifier:$e};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const[n,r]of Object.entries(t.functions))it.prototype[n]=Object.freeze({value:new m(r)});for(let n=0;n<t.signatures.length;n++)z(t.signatures[n],"async")}function ct(e){console.log(e)}function lt(n,a){const i=new Set(Object.keys(a?.vars||{}).map(t=>e(t))),s=new Set(Object.keys(a?.customfunctions||{}).map(t=>e(t))),{globals:c,exports:l}=o(n);return async e=>{const o=e.spatialReference??H.WebMercator;let a=null;n.usesModules&&(a=new r(new Map,n.loadedModules));const u=new it;for(const t of s)null!=e.customfunctions&&t in e.customfunctions?u[t]={value:new m(e.customfunctions[t])}:u[t]=re;for(const t of i){if(null==e.vars||!(t in e.vars)){t in u||(u[t]=re);continue}const n=e.vars[t]??null;J(n)?u[t]={value:h.createFromGraphic(n,e.timeZone??null)}:u[t]={value:n}}for(const t of c)t in u||(u[t]=re);const f={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??ct,abortSignal:e.abortSignal??t,timeZone:e.timeZone??null,spatialReference:o,track:e.track,depthCounter:{depth:1},libraryResolver:a,exports:l,localScope:null,globalScope:u},p=await Ae(f,n);if(p instanceof v||p instanceof x){const e=p.value;if(S(e))return null;if(k(e))throw new w(f,"IllegalResult",null);return e}if(S(p))return null;if(p===F)throw new w(f,"IllegalResult",null);if(p===j)throw new w(f,"IllegalResult",null);throw new w(f,"NeverReach",null)}}function ut(e,t){return lt(e,t)(t)}st([_]),st([D]);export{ut as executeScript,st as extend,lt as prepareScript};