UNPKG

@arcgis/core

Version:

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

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