UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 21.5 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{neverAbortedSignal as e,toSymbolId as t}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as o,getGeometryKeys as i,geometryMember as l}from"./containerUtils.js";import a from"./Dictionary.js";import{ArcadeExecutionError as s,ExecutionErrorCodes as c,ensureArcadeExecutionError as u}from"./executionError.js";import f from"./Feature.js";import{NativeFunction as p,ArcadeFunction as h,ScopeMarshalledFunction as d,wrapModuleScopedResponse as w}from"./FunctionWrapper.js";import{R as g,I as m,A as b,i as y,q as v,r as S,v as x,B as F,j as R,s as I,h as M,y as A,u as O,w as j,x as C,z as N,k as B}from"../chunks/languageUtils.js";import{addFunctionDeclaration as E}from"./treeAnalysis.js";import{A as k}from"../chunks/array.js";import{registerFunctions as D}from"./functions/date.js";import{registerFunctions as U}from"./functions/feature.js";import{registerFunctions as K}from"./functions/geometry.js";import{registerFunctions as Z}from"./functions/geomsync.js";import{registerFunctions as L}from"./functions/maths.js";import{registerFunctions as q}from"./functions/stats.js";import{registerFunctions as G}from"./functions/string.js";import"../core/has.js";import W from"../geometry/Geometry.js";import z from"../geometry/SpatialReference.js";import{isGraphic as P,isBoolean as V,isArray as T,isString as _,isNumber as Y}from"../support/guards.js";class H extends h{constructor(e,t){super(),this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={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:{},depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new s(e,c.MaximumCallDepth,null);return J(this.definition,n,t,null)}}call(e,t){return $(e,t,((n,r,o)=>{const i={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:{}};if(i.depthCounter.depth>64)throw new s(e,c.MaximumCallDepth,t);return J(this.definition,i,o,t)}))}marshalledCall(e,t,n,r){return r(e,t,((o,i,l)=>{const a={spatialReference:e.spatialReference,globalScope:n.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:{}};return l=l.map((t=>!y(t)||t instanceof d?t:w(t,e,r))),w(J(this.definition,a,l,t),n,r)}))}}function J(e,n,r,o){try{const i=e.body;if(r.length!==e.params.length)throw new s(n,c.WrongNumberOfParameters,o);if(null!=n.localScope)for(let o=0;o<r.length;o++)n.localScope[t(e.params[o])]={value:r[o]};const l=te(n,i);if(l instanceof g)return l.value;if(l===v)throw new s(n,c.UnexpectedToken,o);if(l===S)throw new s(n,c.UnexpectedToken,o);return l instanceof m?l.value:l}catch(i){throw i}}class Q extends n{constructor(e){super(),this.source=e}global(e){const n=this.executingContext.globalScope[t(e)];if(y(n.value)&&!(n.value instanceof d)){const r=new d;return r.fn=n.value,r.parameterEvaluator=$,r.context=this.executingContext,this.executingContext.globalScope[t(e)]={value:r},r}return n.value}setGlobal(e,n){if(y(n))throw new s(null,c.AssignModuleFunction,null);this.executingContext.globalScope[t(e)]={value:n}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=t(e)),void 0!==this.executingContext.exports[e]}loadModule(t){const n=t.spatialReference??z.WebMercator;this.moduleScope=Ze(null,null,t.timeZone),this.executingContext={spatialReference:n,globalScope:this.moduleScope,localScope:null,libraryResolver:new r(t.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},services:t.services,console:t.console??Le,timeZone:t.timeZone??null,lrucache:t.lrucache,interceptor:t.interceptor,abortSignal:e,depthCounter:{depth:1}},he(this.executingContext,this.source.syntax)}}function X(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(ee(e,t.arguments[r]));return n}function $(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,X(e,t))}catch(r){throw r}}function ee(e,t){try{switch(t.type){case"AssignmentExpression":return ue(e,t);case"UpdateExpression":return se(e,t);case"TemplateLiteral":return Me(e,t);case"Identifier":return Ae(e,t);case"MemberExpression":return ve(e,t);case"Literal":return t.value;case"CallExpression":return Oe(e,t);case"UnaryExpression":return Se(e,t);case"BinaryExpression":return Fe(e,t);case"LogicalExpression":return Re(e,t);case"ArrayExpression":return xe(e,t);case"ObjectExpression":return ne(e,t);default:throw new s(e,c.Unrecognized,t)}}catch(n){throw u(e,t,n)}}function te(e,t){switch(t.type){case"EmptyStatement":return x;case"VariableDeclaration":return be(e,t);case"ImportDeclaration":return ge(e,t);case"ExportNamedDeclaration":return me(e,t);case"BlockStatement":return he(e,t);case"FunctionDeclaration":return we(e,t);case"ReturnStatement":return de(e,t);case"IfStatement":return pe(e,t);case"ExpressionStatement":return fe(e,t);case"BreakStatement":return v;case"ContinueStatement":return S;case"ForStatement":return ie(e,t);case"ForInStatement":return re(e,t);case"ForOfStatement":return oe(e,t);case"WhileStatement":return le(e,t);default:throw new s(e,c.Unrecognized,t)}}function ne(e,t){const n=Object.create(null),r=new Map;for(let i=0;i<t.properties.length;i++){const o=t.properties[i],l="Identifier"===o.key.type?o.key.name:ee(e,o.key),a=ee(e,o.value);if(y(a))throw new s(e,c.NoFunctionInDictionary,t);if(!1===_(l))throw new s(e,c.KeyMustBeString,t);let u=l.toString();const f=u.toLowerCase();r.has(f)?u=r.get(f):r.set(f,u),n[u]=a===x?null:a}const o=new a(n);return o.immutable=!1,o}function re(e,n){const r=ee(e,n.right);"VariableDeclaration"===n.left.type&&be(e,n.left);const o=t("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let l=null;if(null!=e.localScope&&void 0!==e.localScope[o]&&(l=e.localScope[o]),null===l&&void 0!==e.globalScope[o]){const t=e.globalScope[o].value;l=e.globalScope[o]={value:t}}if(null===l)throw new s(e,c.InvalidIdentifier,n);if(T(r)||_(r)){const t=r.length;for(let r=0;r<t;r++){l.value=r;const t=te(e,n.body);if(t===v)break;if(t instanceof g)return t}return x}if(R(r)){for(let t=0;t<r.length();t++){l.value=t;const r=te(e,n.body);if(r===v)break;if(r instanceof g)return r}return x}if(r instanceof a||I(r)){const t=r.keys();for(let r=0;r<t.length;r++){l.value=t[r];const o=te(e,n.body);if(o===v)break;if(o instanceof g)return o}return x}if(M(r)){for(const t of i(r)){l.value=t;const r=te(e,n.body);if(r===v)break;if(r instanceof g)return r}return x}return x}function oe(e,n){const r=ee(e,n.right);"VariableDeclaration"===n.left.type&&te(e,n.left);const o=t("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let u=null;if(null!=e.localScope&&void 0!==e.localScope[o]&&(u=e.localScope[o]),null===u&&void 0!==e.globalScope[o]){const t=e.globalScope[o].value;u=e.globalScope[o]={value:t}}if(null===u)throw new s(e,c.InvalidIdentifier,n);if(T(r)||_(r)){const t=r.length;for(let o=0;o<t;o++){if(o>=r.length)throw new s(e,c.OutOfBounds,n);u.value=r[o];const t=te(e,n.body);if(t===v)break;if(t instanceof g)return t}return x}if(R(r)){for(let t=0;t<r.length();t++){u.value=r.get(t);const o=te(e,n.body);if(o===v)break;if(o instanceof g)return o}return x}if(r instanceof a||I(r)){for(const t of r.keys()){const o=r.field(t);u.value=a.containerEntry(t,o);const i=te(e,n.body);if(i===v)break;if(i instanceof g)return i}return x}if(M(r)){for(const t of i(r)){const o=l(r,t,e,n,1);u.value=a.containerEntry(t,o);const i=te(e,n.body);if(i===v)break;if(i instanceof g)return i}return x}return x}function ie(e,t){null!==t.init&&("VariableDeclaration"===t.init.type?te(e,t.init):ee(e,t.init));const n={testResult:!0,lastAction:x};do{ae(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof g?n.lastAction:x}function le(e,t){const n={testResult:!0,lastAction:x};if(n.testResult=ee(e,t.test),!1===n.testResult)return x;if(!0!==n.testResult)throw new s(e,c.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=te(e,t.body),n.lastAction!==v)&&!(n.lastAction instanceof g);)if(n.testResult=ee(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new s(e,c.BooleanConditionRequired,t);return n.lastAction instanceof g?n.lastAction:x}function ae(e,t,n){if(null!==t.test){if(n.testResult=ee(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new s(e,c.BooleanConditionRequired,t)}n.lastAction=te(e,t.body),n.lastAction!==v?n.lastAction instanceof g?n.testResult=!1:null!==t.update&&ee(e,t.update):n.testResult=!1}function se(e,n){if("CallExpression"===n.argument.type)throw new s(e,c.NeverReach,n);let r;if("MemberExpression"===n.argument.type){const t=ee(e,n.argument.object);let o;if(!0===n.argument.computed)o=ee(e,n.argument.property);else{if("Identifier"!==n.argument.property.type)throw new s(e,c.Unrecognized,n);o=n.argument.property.name}if(T(t)){if(!Y(o))throw new s(e,c.ArrayAccessorMustBeNumber,n);if(o<0&&(o=t.length+o),o<0||o>=t.length)throw new s(e,c.OutOfBounds,n);r=O(t[o]),t[o]="++"===n.operator?r+1:r-1}else if(t instanceof a){if(!1===_(o))throw new s(e,c.KeyAccessorMustBeString,n);if(!0!==t.hasField(o))throw new s(e,c.FieldNotFound,n);r=O(t.field(o)),t.setField(o,"++"===n.operator?r+1:r-1)}else if(B(t)){if(!1===_(o))throw new s(e,c.KeyAccessorMustBeString,n);if(!0!==t.hasField(o))throw new s(e,c.FieldNotFound,n);r=O(t.field(o)),t.setField(o,"++"===n.operator?r+1:r-1)}else{if(R(t))throw new s(e,c.Immutable,n);if(!(t instanceof Q))throw new s(e,c.InvalidParameter,n);if(!1===_(o))throw new s(e,c.ModuleAccessorMustBeString,n);if(!0!==t.hasGlobal(o))throw new s(e,c.ModuleExportNotFound,n);r=O(t.global(o)),t.setGlobal(o,"++"===n.operator?r+1:r-1)}return!1===n.prefix?r:"++"===n.operator?r+1:r-1}const o=t(n.argument);if(null!=e.localScope&&void 0!==e.localScope[o])return r=O(e.localScope[o].value),e.localScope[o]={value:"++"===n.operator?r+1:r-1},!1===n.prefix?r:"++"===n.operator?r+1:r-1;if(void 0!==e.globalScope[o])return r=O(e.globalScope[o].value),e.globalScope[o]={value:"++"===n.operator?r+1:r-1},!1===n.prefix?r:"++"===n.operator?r+1:r-1;throw new s(e,c.InvalidIdentifier,n)}function ce(e,t,n,r,o){switch(t){case"=":return e===x?null:e;case"/=":return O(n)/O(e);case"*=":return O(n)*O(e);case"-=":return O(n)-O(e);case"+=":return _(n)||_(e)?j(n)+j(e):O(n)+O(e);case"%=":return O(n)%O(e);default:throw new s(o,c.UnsupportedOperator,r)}}function ue(e,n){if("MemberExpression"===n.left.type){const t=ee(e,n.left.object);let r;if(!0===n.left.computed)r=ee(e,n.left.property);else{if("Identifier"!==n.left.property.type)throw new s(e,c.InvalidIdentifier,n);r=n.left.property.name}const o=ee(e,n.right);if(T(t)){if(!Y(r))throw new s(e,c.ArrayAccessorMustBeNumber,n);if(r<0&&(r=t.length+r),r<0||r>t.length)throw new s(e,c.OutOfBounds,n);if(r===t.length){if("="!==n.operator)throw new s(e,c.OutOfBounds,n);t[r]=ce(o,n.operator,t[r],n,e)}else t[r]=ce(o,n.operator,t[r],n,e)}else if(t instanceof a){if(!1===_(r))throw new s(e,c.KeyAccessorMustBeString,n);if(!0===t.hasField(r))t.setField(r,ce(o,n.operator,t.field(r),n,e));else{if("="!==n.operator)throw new s(e,c.FieldNotFound,n,{key:r});t.setField(r,ce(o,n.operator,null,n,e))}}else if(B(t)){if(!1===_(r))throw new s(e,c.KeyAccessorMustBeString,n);if(!0===t.hasField(r))t.setField(r,ce(o,n.operator,t.field(r),n,e));else{if("="!==n.operator)throw new s(e,c.FieldNotFound,n,{key:r});t.setField(r,ce(o,n.operator,null,n,e))}}else{if(R(t))throw new s(e,c.Immutable,n);if(!(t instanceof Q))throw new s(e,c.InvalidIdentifier,n);if(!1===_(r))throw new s(e,c.ModuleAccessorMustBeString,n);if(!0!==t.hasGlobal(r))throw new s(e,c.ModuleExportNotFound,n);t.setGlobal(r,ce(o,n.operator,t.global(r),n,e))}return x}const r=t(n.left),o=ee(e,n.right);if(null!=e.localScope&&void 0!==e.localScope[r])return e.localScope[r]={value:ce(o,n.operator,e.localScope[r].value,n,e)},x;if(void 0!==e.globalScope[r])return e.globalScope[r]={value:ce(o,n.operator,e.globalScope[r].value,n,e)},x;throw new s(e,c.InvalidIdentifier,n)}function fe(e,t){const n=ee(e,t.expression);return n===x?x:new m(n)}function pe(e,t){const n=ee(e,t.test);if(!0===n)return te(e,t.consequent);if(!1===n)return null!==t.alternate?te(e,t.alternate):x;throw new s(e,c.BooleanConditionRequired,t)}function he(e,t){let n=x;for(let r=0;r<t.body.length;r++)if(n=te(e,t.body[r]),n instanceof g||n===v||n===S)return n;return n}function de(e,t){if(null===t.argument)return new g(x);const n=ee(e,t.argument);return new g(n)}function we(e,n){const r=t(n.id);return e.globalScope[r]={value:new H(n,e)},x}function ge(e,n){const r=t(n.specifiers[0].local),o=e.libraryResolver.loadLibrary(r);let i;return e.libraryResolver._moduleSingletons?.has(o.uri)?i=e.libraryResolver._moduleSingletons.get(o.uri):(i=new Q(o),i.loadModule(e),e.libraryResolver._moduleSingletons?.set(o.uri,i)),e.globalScope[r]={value:i},x}function me(e,n){if(te(e,n.declaration),"FunctionDeclaration"===n.declaration.type)e.exports[t(n.declaration.id)]="function";else if("VariableDeclaration"===n.declaration.type)for(const r of n.declaration.declarations)e.exports[t(r.id)]="variable";return x}function be(e,t){for(let n=0;n<t.declarations.length;n++)ye(e,t.declarations[n]);return x}function ye(e,n){let r=null===n.init?null:ee(e,n.init);if(r===x&&(r=null),"Identifier"!==n.id.type)throw new s(e,c.InvalidIdentifier,n);const o=t(n.id);null!=e.localScope?e.localScope[o]={value:r}:e.globalScope[o]={value:r}}function ve(e,t){try{const n=ee(e,t.object);if(null===n)throw new s(e,c.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof a||I(n))return n.field(t.property.name);if(n instanceof W)return l(n,t.property.name,e,t);if(n instanceof Q){if(!n.hasGlobal(t.property.name))throw new s(e,c.InvalidIdentifier,t);return n.global(t.property.name)}}throw new s(e,c.InvalidMemberAccessKey,t)}let r=ee(e,t.property);if(n instanceof a||I(n)){if(_(r))return n.field(r);throw new s(e,c.InvalidMemberAccessKey,t)}if(n instanceof Q){if(_(r))return n.global(r);throw new s(e,c.InvalidMemberAccessKey,t)}if(n instanceof W){if(_(r))return l(n,r,e,t);throw new s(e,c.InvalidMemberAccessKey,t)}if(T(n)){if(Y(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new s(e,c.OutOfBounds,t);return n[r]}throw new s(e,c.InvalidMemberAccessKey,t)}if(_(n)){if(Y(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new s(e,c.OutOfBounds,t);return n[r]}throw new s(e,c.InvalidMemberAccessKey,t)}if(R(n)){if(Y(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new s(e,c.OutOfBounds,t);return n.get(r)}throw new s(e,c.InvalidMemberAccessKey,t)}throw new s(e,c.InvalidMemberAccessKey,t)}catch(n){throw n}}function Se(e,t){try{const n=ee(e,t.argument);if(V(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*O(n);if("+"===t.operator)return 1*O(n);if("~"===t.operator)return~O(n);throw new s(e,c.UnsupportedUnaryOperator,t)}if("~"===t.operator)return~O(n);if("-"===t.operator)return-1*O(n);if("+"===t.operator)return 1*O(n);throw new s(e,c.UnsupportedUnaryOperator,t)}catch(n){throw n}}function xe(e,t){try{const n=[];for(let r=0;r<t.elements.length;r++){const o=ee(e,t.elements[r]);if(y(o))throw new s(e,c.NoFunctionInArray,t);o===x?n.push(null):n.push(o)}return n}catch(n){throw n}}function Fe(e,t){try{const n=ee(e,t.left),r=ee(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return N(O(n),O(r),t.operator);case"==":return A(n,r);case"!=":return!A(n,r);case"<":case">":case"<=":case">=":return C(n,r,t.operator);case"+":return _(n)||_(r)?j(n)+j(r):O(n)+O(r);case"-":return O(n)-O(r);case"*":return O(n)*O(r);case"/":return O(n)/O(r);case"%":return O(n)%O(r);default:throw new s(e,c.UnsupportedOperator,t)}}catch(n){throw n}}function Re(e,t){try{const n=ee(e,t.left);if(V(n))switch(t.operator){case"||":{if(!0===n)return n;const r=ee(e,t.right);if(V(r))return r;throw new s(e,c.LogicExpressionOrAnd,t)}case"&&":{if(!1===n)return n;const r=ee(e,t.right);if(V(r))return r;throw new s(e,c.LogicExpressionOrAnd,t)}default:throw new s(e,c.LogicExpressionOrAnd,t)}throw new s(e,c.LogicalExpressionOnlyBoolean,t)}catch(n){throw n}}function Ie(e,t,n){if(y(e))throw new s(t,c.NoFunctionInTemplateLiteral,n);return e}function Me(e,t){let n="",r=0;for(const o of t.quasis)if(n+=o.value?o.value.cooked:"",!1===o.tail){n+=t.expressions[r]?j(Ie(ee(e,t.expressions[r]),e,t)):"",r++}return n}function Ae(e,n){try{const r=t(n);if(null!=e.localScope&&void 0!==e.localScope[r])return e.localScope[r].value;if(void 0!==e.globalScope[r])return e.globalScope[r].value;throw new s(e,c.InvalidIdentifier,n)}catch(r){throw r}}function Oe(e,n){try{if("MemberExpression"===n.callee.type){const t=ee(e,n.callee.object);if(!(t instanceof Q))throw new s(e,c.FunctionNotFound,n);const r=!1===n.callee.computed?n.callee.property.name:ee(e,n.callee.property);if(!t.hasGlobal(r))throw new s(e,c.FunctionNotFound,n);const o=t.global(r);if(!y(o))throw new s(e,c.CallNonFunction,n);return o.call(e,n)}if("Identifier"!==n.callee.type)throw new s(e,c.FunctionNotFound,n);const r=t(n.callee);if(null!=e.localScope&&void 0!==e.localScope[r]){const t=e.localScope[r];if(y(t.value))return t.value.call(e,n);throw new s(e,c.CallNonFunction,n)}if(void 0!==e.globalScope[r]){const t=e.globalScope[r];if(y(t.value))return t.value.call(e,n);throw new s(e,c.CallNonFunction,n)}throw new s(e,c.FunctionNotFound,n)}catch(r){throw r}}function je(e,t){try{if(!0===t.preparsed)throw new s(e,c.NeverReach,t);const n=t.arguments;F(null===n?[]:n,3,3,e,t);const r=ee(e,n[0]);if(!1===V(r))throw new s(e,c.BooleanConditionRequired,t);return ee(e,!0===r?n[1]:n[2])}catch(n){throw n}}function Ce(e,t){try{if(!0===t.preparsed)throw new s(e,c.NeverReach,t);const n=t.arguments;F(null===n?[]:n,2,3,e,t);const r=ee(e,n[0]);if(3===n.length){const t=ee(e,n[1]),i=o(r,t);return null!=i&&""!==i?i:ee(e,n[2])}return null===r||""===r||void 0===r?ee(e,n[1]):r}catch(n){throw n}}function Ne(e,t){try{if(!0===t.preparsed)throw new s(e,c.NeverReach,t);const n=t.arguments;if(n.length<2)throw new s(e,c.WrongNumberOfParameters,t);if(2===n.length)return ee(e,n[1]);{if((n.length-1)%2==0)throw new s(e,c.WrongNumberOfParameters,t);const r=ee(e,n[0]);return Be(e,t,1,r)}}catch(n){throw n}}function Be(e,t,n,r){try{const o=t.arguments,i=ee(e,o[n]);if(A(i,r))return ee(e,o[n+1]);{const i=o.length-n;return 1===i?ee(e,o[n]):2===i?null:3===i?ee(e,o[n+2]):Be(e,t,n+2,r)}}catch(o){throw o}}function Ee(e,t){try{if(!0===t.preparsed)throw new s(e,c.NeverReach,t);const n=t.arguments;if(n.length<3)throw new s(e,c.WrongNumberOfParameters,t);if(n.length%2==0)throw new s(e,c.WrongNumberOfParameters,t);const r=ee(e,n[0]);if(!1===V(r))throw new s(e,c.BooleanConditionRequired,n[0]);return ke(e,t,0,r)}catch(n){throw n}}function ke(e,t,n,r){try{const o=t.arguments;if(!0===r)return ee(e,o[n+1]);if(3===o.length-n)return ee(e,o[n+2]);{const r=ee(e,o[n+2]);if(!1===V(r))throw new s(e,c.BooleanConditionRequired,o[n+2]);return ke(e,t,n+2,r)}}catch(o){throw o}}function De(){const e=Object.create(null);D(e,$),G(e,$),U(e,$,Ae),L(e,$),K(e,$),q(e,$),Z(e,$),e.iif=je,e.defaultvalue=Ce,e.decode=Ne,e.when=Ee;const t=function(){this.textformatting={value:a.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 p(r)});return t}const Ue=De();function Ke(e){const t={mode:"sync",compiled:!1,functions:Object.create(null),signatures:[],standardFunction:$,evaluateIdentifier:Ae};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const[n,r]of Object.entries(t.functions))Ue.prototype[n]=Object.freeze({value:new p(r)});for(let n=0;n<t.signatures.length;n++)E(t.signatures[n],"sync")}function Ze(e,t,n){const r=new Ue;e||(e={}),t||(t={});for(const o in t)r[o]={value:new p(t[o])};for(const o in e)r[o]={value:P(e[o])?f.createFromGraphic(e[o],n):e[o]};return r}function Le(e){console.log(e)}function qe(t,n){const o=n.spatialReference??z.WebMercator;let i=null;t.usesModules&&(i=new r(new Map,t.loadedModules));const l={spatialReference:o,globalScope:Ze(n.vars,n.customfunctions,n.timeZone),localScope:null,services:n.services,exports:{},libraryResolver:i,console:n.console??Le,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,abortSignal:e,depthCounter:{depth:1}},a=he(l,t);if(a instanceof g||a instanceof m){const e=a.value;if(b(e))return null;if(y(e))throw new s(l,c.IllegalResult,null);return e}if(b(a))return null;if(a===v)throw new s(l,c.IllegalResult,null);if(a===S)throw new s(l,c.IllegalResult,null);throw new s(l,c.NeverReach,null)}Ke([k]);export{qe as executeScript,Ke as extend};