12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import e from"./ArcadePortal.js";import r from"./Attachment.js";import t from"./Dictionary.js";import n from"./Feature.js";import o from"./FunctionWrapper.js";import a from"./ImmutablePathArray.js";import i from"./ImmutablePointArray.js";import{p as s,i as l,m as c,N as u,x as f,w as p,v as h,o as w,b as m,l as E,R as d,n as g,s as N,a as y,f as I,I as v,h as T,q as R,r as O,j as S,y as b,z as A,A as U}from"../chunks/languageUtils.js";import{nodeErrorMessage as C,addFunctionDeclaration as x,findFieldLiterals as M,findExpectedFieldLiterals as F,validateScript as P,referencesMember as D,referencesFunction as L,findFunctionCalls as j}from"./treeAnalysis.js";import{A as _}from"../chunks/array.js";import{registerFunctions as k}from"./functions/date.js";import{registerFunctions as V}from"./functions/geometry.js";import{registerFunctions as B}from"./functions/geomsync.js";import{registerFunctions as Y}from"./functions/maths.js";import{registerFunctions as G}from"./functions/stats.js";import{registerFunctions as z}from"./functions/string.js";import q from"../geometry/Extent.js";import Z from"../geometry/Geometry.js";import H from"../geometry/Multipoint.js";import W from"../geometry/Point.js";import K from"../geometry/Polygon.js";import X from"../geometry/Polyline.js";import J from"../geometry/SpatialReference.js";function Q(e,r){const t=[];for(let n=0;n<r.arguments.length;n++)t.push(ee(e,r.arguments[n]));return t}function $(e,r,t){try{return!0===r.preparsed?t(e,null,r.arguments):t(e,r,Q(e,r))}catch(n){throw n}}function ee(e,r){try{switch(r.type){case"EmptyStatement":return h;case"VariableDeclarator":return me(e,r);case"VariableDeclaration":return we(e,r);case"BlockStatement":return fe(e,r);case"FunctionDeclaration":return he(e,r);case"ReturnStatement":return pe(e,r);case"IfStatement":return ue(e,r);case"ExpressionStatement":return ce(e,r);case"AssignmentExpression":return le(e,r);case"UpdateExpression":return ie(e,r);case"BreakStatement":return p;case"ContinueStatement":return f;case"TemplateElement":return Te(e,r);case"TemplateLiteral":return Re(e,r);case"ForStatement":return oe(e,r);case"ForInStatement":return ne(e,r);case"Identifier":return Oe(e,r);case"MemberExpression":return ge(e,r);case"Literal":return r.value;case"CallExpression":return Se(e,r);case"UnaryExpression":return Ne(e,r);case"BinaryExpression":return Ie(e,r);case"LogicalExpression":return ve(e,r);case"ArrayExpression":return ye(e,r);case"ObjectExpression":return re(e,r);case"Property":return te(e,r);default:throw new Error(C(r,"RUNTIME","UNREOGNISED"))}}catch(t){throw t}}function re(e,r){const n={};for(let t=0;t<r.properties.length;t++){const o=ee(e,r.properties[t]);if(w(o.value))throw new Error("Illegal Argument");if(!1===m(o.key))throw new Error("Illegal Argument");o.value===h?n[o.key.toString()]=null:n[o.key.toString()]=o.value}const o=new t(n);return o.immutable=!1,o}function te(e,r){return{key:"Identifier"===r.key.type?r.key.name:ee(e,r.key),value:ee(e,r.value)}}function ne(e,r){const n=ee(e,r.right);"VariableDeclaration"===r.left.type&&ee(e,r.left);let o=null,a="";if("VariableDeclaration"===r.left.type){const e=r.left.declarations[0].id;"Identifier"===e.type&&(a=e.name)}else"Identifier"===r.left.type&&(a=r.left.name);if(!a)throw new Error(C(r,"RUNTIME","INVALIDVARIABLE"));if(a=a.toLowerCase(),null!==e.localScope&&void 0!==e.localScope[a]&&(o=e.localScope[a]),null===o&&void 0!==e.globalScope[a]&&(o=e.globalScope[a]),null===o)throw new Error(C(r,"RUNTIME","VARIABLENOTDECLARED"));if(E(n)||m(n)){const t=n.length;for(let n=0;n<t;n++){o.value=n;const t=ee(e,r.body);if(t===p)break;if(t instanceof d)return t}return h}if(g(n)){for(let t=0;t<n.length();t++){o.value=t;const n=ee(e,r.body);if(n===p)break;if(n instanceof d)return n}return h}if(!(n instanceof t||N(n)))return h;{const t=n.keys();for(let n=0;n<t.length;n++){o.value=t[n];const a=ee(e,r.body);if(a===p)break;if(a instanceof d)return a}}}function oe(e,r){null!==r.init&&ee(e,r.init);const t={testResult:!0,lastAction:h};do{ae(e,r,t)}while(!0===t.testResult);return t.lastAction instanceof d?t.lastAction:h}function ae(e,r,t){if(null!==r.test){if(t.testResult=ee(e,r.test),!1===t.testResult)return;if(!0!==t.testResult)throw new Error(C(r,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"))}t.lastAction=ee(e,r.body),t.lastAction!==p?t.lastAction instanceof d?t.testResult=!1:null!==r.update&&ee(e,r.update):t.testResult=!1}function ie(e,r){let n,o=null,a="";if("MemberExpression"===r.argument.type){if(o=ee(e,r.argument.object),!0===r.argument.computed?a=ee(e,r.argument.property):"Identifier"===r.argument.property.type&&(a=r.argument.property.name),E(o)){if(!y(a))throw new Error("Invalid Parameter");if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new Error("Assignment outside of array bounds");n=I(o[a]),o[a]="++"===r.operator?n+1:n-1}else if(o instanceof t){if(!1===m(a))throw new Error("Dictionary accessor must be a string");if(!0!==o.hasField(a))throw new Error("Invalid Parameter");n=I(o.field(a)),o.setField(a,"++"===r.operator?n+1:n-1)}else{if(!N(o))throw g(o)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===m(a))throw new Error("Feature accessor must be a string");if(!0!==o.hasField(a))throw new Error("Invalid Parameter");n=I(o.field(a)),o.setField(a,"++"===r.operator?n+1:n-1)}return!1===r.prefix?n:"++"===r.operator?n+1:n-1}if(o="Identifier"===r.argument.type?r.argument.name.toLowerCase():"",!o)throw new Error("Invalid identifier");if(null!==e.localScope&&void 0!==e.localScope[o])return n=I(e.localScope[o].value),e.localScope[o]={value:"++"===r.operator?n+1:n-1,valueset:!0,node:r},!1===r.prefix?n:"++"===r.operator?n+1:n-1;if(void 0!==e.globalScope[o])return n=I(e.globalScope[o].value),e.globalScope[o]={value:"++"===r.operator?n+1:n-1,valueset:!0,node:r},!1===r.prefix?n:"++"===r.operator?n+1:n-1;throw new Error("Variable not recognised")}function se(e,r,t,n){switch(r){case"=":return e===h?null:e;case"/=":return I(t)/I(e);case"*=":return I(t)*I(e);case"-=":return I(t)-I(e);case"+=":return m(t)||m(e)?T(t)+T(e):I(t)+I(e);case"%=":return I(t)%I(e);default:throw new Error(C(n,"RUNTIME","OPERATORNOTRECOGNISED"))}}function le(e,r){const n=ee(e,r.right);let o=null,a="";if("MemberExpression"===r.left.type){if(o=ee(e,r.left.object),!0===r.left.computed?a=ee(e,r.left.property):"Identifier"===r.left.property.type&&(a=r.left.property.name),E(o)){if(!y(a))throw new Error("Invalid Parameter");if(a<0&&(a=o.length+a),a<0||a>o.length)throw new Error("Assignment outside of array bounds");if(a===o.length){if("="!==r.operator)throw new Error("Invalid Parameter");o[a]=se(n,r.operator,o[a],r)}else o[a]=se(n,r.operator,o[a],r)}else if(o instanceof t){if(!1===m(a))throw new Error("Dictionary accessor must be a string");if(!0===o.hasField(a))o.setField(a,se(n,r.operator,o.field(a),r));else{if("="!==r.operator)throw new Error("Invalid Parameter");o.setField(a,se(n,r.operator,null,r))}}else{if(!N(o))throw g(o)?new Error("Array is Immutable"):new Error("Invalid Parameter");if(!1===m(a))throw new Error("Feature accessor must be a string");if(!0===o.hasField(a))o.setField(a,se(n,r.operator,o.field(a),r));else{if("="!==r.operator)throw new Error("Invalid Parameter");o.setField(a,se(n,r.operator,null,r))}}return h}if(o=r.left.name.toLowerCase(),null!==e.localScope&&void 0!==e.localScope[o])return e.localScope[o]={value:se(n,r.operator,e.localScope[o].value,r),valueset:!0,node:r.right},h;if(void 0!==e.globalScope[o])return e.globalScope[o]={value:se(n,r.operator,e.globalScope[o].value,r),valueset:!0,node:r.right},h;throw new Error("Variable not recognised")}function ce(e,r){if("AssignmentExpression"===r.expression.type||"UpdateExpression"===r.expression.type)return ee(e,r.expression);if("CallExpression"===r.expression.type){const t=ee(e,r.expression);return t===h?h:new v(t)}{const t=ee(e,r.expression);return t===h?h:new v(t)}}function ue(e,r){if("AssignmentExpression"===r.test.type||"UpdateExpression"===r.test.type)throw new Error(C(r.test,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const t=ee(e,r.test);if(!0===t)return ee(e,r.consequent);if(!1===t)return null!==r.alternate?ee(e,r.alternate):h;throw new Error(C(r,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"))}function fe(e,r){let t=h;for(let n=0;n<r.body.length;n++)if(t=ee(e,r.body[n]),t instanceof d||t===p||t===f)return t;return t}function pe(e,r){if(null===r.argument)return new d(h);const t=ee(e,r.argument);return new d(t)}function he(e,r){const t=r.id.name.toLowerCase();return e.globalScope[t]={valueset:!0,node:null,value:new o(r,e)},h}function we(e,r){for(let t=0;t<r.declarations.length;t++)ee(e,r.declarations[t]);return h}function me(e,r){let t=null===r.init?null:ee(e,r.init);if(t===h&&(t=null),"Identifier"!==r.id.type)throw new Error("Can only assign a regular variable");const n=r.id.name.toLowerCase();return null!==e.localScope?e.localScope[n]={value:t,valueset:!0,node:r.init}:e.globalScope[n]={value:t,valueset:!0,node:r.init},h}let Ee=0;function de(e,r,n){let o;switch(r=r.toLowerCase()){case"hasz":{const r=e.hasZ;return void 0!==r&&r}case"hasm":{const r=e.hasM;return void 0!==r&&r}case"spatialreference":{let r=e.spatialReference._arcadeCacheId;if(void 0===r){let t=!0;Object.freeze&&Object.isFrozen(e.spatialReference)&&(t=!1),t&&(Ee++,e.spatialReference._arcadeCacheId=Ee,r=Ee)}const n=new t({wkt:e.spatialReference.wkt,wkid:e.spatialReference.wkid});return void 0!==r&&(n._arcadeCacheId="SPREF"+r.toString()),n}}switch(e.type){case"extent":switch(r){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const t=e[r];return void 0!==t?t:null}case"type":return"Extent"}break;case"polygon":switch(r){case"rings":o=e.cache._arcadeCacheId,void 0===o&&(Ee++,o=Ee,e.cache._arcadeCacheId=o);return new a(e.rings,e.spatialReference,!0===e.hasZ,!0===e.hasM,o);case"type":return"Polygon"}break;case"point":switch(r){case"x":case"y":case"z":case"m":return void 0!==e[r]?e[r]:null;case"type":return"Point"}break;case"polyline":switch(r){case"paths":o=e.cache._arcadeCacheId,void 0===o&&(Ee++,o=Ee,e.cache._arcadeCacheId=o);return new a(e.paths,e.spatialReference,!0===e.hasZ,!0===e.hasM,o);case"type":return"Polyline"}break;case"multipoint":switch(r){case"points":o=e.cache._arcadeCacheId,void 0===o&&(Ee++,o=Ee,e.cache._arcadeCacheId=o);return new i(e.points,e.spatialReference,!0===e.hasZ,!0===e.hasM,o,1);case"type":return"Multipoint"}}throw new Error(C(n,"RUNTIME","PROPERTYNOTFOUND"))}function ge(e,r){try{const n=ee(e,r.object);if(null===n)throw new Error(C(r,"RUNTIME","NOTFOUND"));if(!1===r.computed){if("Identifier"===r.property.type){if(n instanceof t||N(n))return n.field(r.property.name);if(n instanceof Z)return de(n,r.property.name,r)}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}{let o=ee(e,r.property);if(n instanceof t||N(n)){if(m(o))return n.field(o);throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(n instanceof Z){if(m(o))return de(n,o,r);throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(E(n)){if(y(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(r,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(m(n)){if(y(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length+o),o>=n.length||o<0)throw new Error(C(r,"RUNTIME","OUTOFBOUNDS"));return n[o]}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}if(g(n)){if(y(o)&&isFinite(o)&&Math.floor(o)===o){if(o<0&&(o=n.length()+o),o>=n.length()||o<0)throw new Error(C(r,"RUNTIME","OUTOFBOUNDS"));return n.get(o)}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}throw new Error(C(r,"RUNTIME","INVALIDTYPE"))}}catch(n){throw n}}function Ne(e,r){try{const t=ee(e,r.argument);if(l(t)){if("!"===r.operator)return!t;if("-"===r.operator)return-1*I(t);if("+"===r.operator)return 1*I(t);if("~"===r.operator)return~I(t);throw new Error(C(r,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}if("~"===r.operator)return~I(t);if("-"===r.operator)return-1*I(t);if("+"===r.operator)return 1*I(t);throw new Error(C(r,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))}catch(t){throw t}}function ye(e,r){try{const t=[];for(let n=0;n<r.elements.length;n++){const o=ee(e,r.elements[n]);if(w(o))throw new Error(C(r,"RUNTIME","FUNCTIONCONTEXTILLEGAL"));o===h?t.push(null):t.push(o)}return t}catch(t){throw t}}function Ie(e,r){try{const t=[ee(e,r.left),ee(e,r.right)],n=t[0],o=t[1];switch(r.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return O(I(n),I(o),r.operator);case"==":return c(n,o);case"!=":return!c(n,o);case"<":case">":case"<=":case">=":return R(n,o,r.operator);case"+":return m(n)||m(o)?T(n)+T(o):I(n)+I(o);case"-":return I(n)-I(o);case"*":return I(n)*I(o);case"/":return I(n)/I(o);case"%":return I(n)%I(o);default:throw new Error(C(r,"RUNTIME","OPERATORNOTRECOGNISED"))}}catch(t){throw t}}function ve(e,r){try{if("AssignmentExpression"===r.left.type||"UpdateExpression"===r.left.type)throw new Error(C(r.left,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));if("AssignmentExpression"===r.right.type||"UpdateExpression"===r.right.type)throw new Error(C(r.right,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"));const t=ee(e,r.left);if(l(t))switch(r.operator){case"||":if(!0===t)return t;{const t=ee(e,r.right);if(l(t))return t;throw new Error(C(r,"RUNTIME","ONLYORORAND"))}case"&&":if(!1===t)return t;{const t=ee(e,r.right);if(l(t))return t;throw new Error(C(r,"RUNTIME","ONLYORORAND"))}default:throw new Error(C(r,"RUNTIME","ONLYORORAND"))}throw new Error(C(r,"RUNTIME","ONLYBOOLEAN"))}catch(t){throw t}}function Te(e,r){return r.value?r.value.cooked:""}function Re(e,r){let t="",n=0;for(const o of r.quasis)if(t+=o.value?o.value.cooked:"",!1===o.tail){t+=r.expressions[n]?T(ee(e,r.expressions[n])):"",n++}return t}function Oe(e,r){let t;try{const n=r.name.toLowerCase();if(null!==e.localScope&&void 0!==e.localScope[n])return t=e.localScope[n],!0===t.valueset||(t.value=ee(e,t.node),t.valueset=!0),t.value;if(void 0!==e.globalScope[n])return t=e.globalScope[n],!0===t.valueset||(t.value=ee(e,t.node),t.valueset=!0),t.value;throw new Error(C(r,"RUNTIME","VARIABLENOTFOUND"))}catch(n){throw n}}function Se(e,r){try{if("Identifier"!==r.callee.type)throw new Error(C(r,"RUNTIME","ONLYNODESSUPPORTED"));if(null!==e.localScope&&void 0!==e.localScope[r.callee.name.toLowerCase()]){const t=e.localScope[r.callee.name.toLowerCase()];if(t.value instanceof u)return t.value.fn(e,r);if(t.value instanceof o)return Pe(e,r,t.value.definition);throw new Error(C(r,"RUNTIME","NOTAFUNCTION"))}if(void 0!==e.globalScope[r.callee.name.toLowerCase()]){const t=e.globalScope[r.callee.name.toLowerCase()];if(t.value instanceof u)return t.value.fn(e,r);if(t.value instanceof o)return Pe(e,r,t.value.definition);throw new Error(C(r,"RUNTIME","NOTAFUNCTION"))}throw new Error(C(r,"RUNTIME","NOTFOUND"))}catch(t){throw t}}const be={};function Ae(n){return null==n?"":E(n)||g(n)?"Array":S(n)?"Date":m(n)?"String":l(n)?"Boolean":y(n)?"Number":n instanceof r?"Attachment":n instanceof e?"Portal":n instanceof t?"Dictionary":N(n)?"Feature":n instanceof W?"Point":n instanceof K?"Polygon":n instanceof X?"Polyline":n instanceof H?"Multipoint":n instanceof q?"Extent":w(n)?"Function":b(n)?"FeatureSet":A(n)?"FeatureSetCollection":n===h?"":"number"==typeof n&&isNaN(n)?"Number":"Unrecognised Type"}function Ue(e,r,t,n){try{const o=ee(e,r.arguments[t]);if(c(o,n))return ee(e,r.arguments[t+1]);{const o=r.arguments.length-t;return 1===o?ee(e,r.arguments[t]):2===o?null:3===o?ee(e,r.arguments[t+2]):Ue(e,r,t+2,n)}}catch(o){throw o}}function Ce(e,r,t,n){try{if(!0===n)return ee(e,r.arguments[t+1]);if(3===r.arguments.length-t)return ee(e,r.arguments[t+2]);{const n=ee(e,r.arguments[t+2]);if(!1===l(n))throw new Error("WHEN needs boolean test conditions");return Ce(e,r,t+2,n)}}catch(o){throw o}}function xe(e,r){const t=e.length,n=Math.floor(t/2);return 0===t?[]:1===t?[e[0]]:Me(xe(e.slice(0,n),r),xe(e.slice(n,t),r),r)}function Me(e,r,t){const n=[];for(;e.length>0||r.length>0;)if(e.length>0&&r.length>0){let o=t(e[0],r[0]);isNaN(o)&&(o=0),o<=0?(n.push(e[0]),e=e.slice(1)):(n.push(r[0]),r=r.slice(1))}else e.length>0?(n.push(e[0]),e=e.slice(1)):r.length>0&&(n.push(r[0]),r=r.slice(1));return n}function Fe(e,r,t){try{const n=e.body;if(t.length!==e.params.length)throw new Error("Invalid Parameter calls to function.");for(let a=0;a<t.length;a++)r.localScope[e.params[a].name.toLowerCase()]={value:t[a],valueset:!0,node:null};const o=ee(r,n);if(o instanceof d)return o.value;if(o===p)throw new Error("Cannot Break from a Function");if(o===f)throw new Error("Cannot Continue from a Function");return o instanceof v?o.value:o}catch(n){throw n}}function Pe(e,r,t){return $(e,r,(function(r,n,o){const a={spatialReference:e.spatialReference,globalScope:e.globalScope,depthCounter:e.depthCounter+1,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};if(a.depthCounter>64)throw new Error("Exceeded maximum function depth");return Fe(t,a,o)}))}function De(e){const r=function(){const r={spatialReference:e.context.spatialReference,console:e.context.console,lrucache:e.context.lrucache,interceptor:e.context.interceptor,localScope:{},depthCounter:e.context.depthCounter+1,globalScope:e.context.globalScope};if(r.depthCounter>64)throw new Error("Exceeded maximum function depth");return Fe(e.definition,r,arguments)};return r}k(be,$),z(be,$),Y(be,$),V(be,$),G(be,$),B(be,$),be.typeof=function(e,r){return $(e,r,(function(e,r,t){s(t,1,1);const n=Ae(t[0]);if("Unrecognised Type"===n)throw new Error("Unrecognised Type");return n}))},be.iif=function(e,r){try{s(null===r.arguments?[]:r.arguments,3,3);const t=ee(e,r.arguments[0]);if(!1===l(t))throw new Error("IF Function must have a boolean test condition");const n=ee(e,r.arguments[1]),o=ee(e,r.arguments[2]);return!0===t?n:o}catch(t){throw t}},be.decode=function(e,r){try{if(r.arguments.length<2)throw new Error("Missing Parameters");if(2===r.arguments.length)return ee(e,r.arguments[1]);{if((r.arguments.length-1)%2==0)throw new Error("Must have a default value result.");const t=ee(e,r.arguments[0]);return Ue(e,r,1,t)}}catch(t){throw t}},be.when=function(e,r){try{if(r.arguments.length<3)throw new Error("Missing Parameters");if(r.arguments.length%2==0)throw new Error("Must have a default value result.");const t=ee(e,r.arguments[0]);if(!1===l(t))throw new Error("WHEN needs boolean test conditions");return Ce(e,r,0,t)}catch(t){throw t}},be.top=function(e,r){return $(e,r,(function(e,r,t){if(s(t,2,2),E(t[0]))return I(t[1])>=t[0].length?t[0].slice(0):t[0].slice(0,I(t[1]));if(g(t[0]))return I(t[1])>=t[0].length()?t[0].slice(0):t[0].slice(0,I(t[1]));throw new Error("Top cannot accept this parameter type")}))},be.first=function(e,r){return $(e,r,(function(e,r,t){return s(t,1,1),E(t[0])?0===t[0].length?null:t[0][0]:g(t[0])?0===t[0].length()?null:t[0].get(0):null}))},be.sort=function(e,r){return $(e,r,(function(e,r,t){s(t,1,2);let n=t[0];if(g(n)&&(n=n.toArray()),!1===E(n))throw new Error("Illegal Argument");if(t.length>1){if(!1===w(t[1]))throw new Error("Illegal Argument");let e=n;const r=De(t[1]);return e=xe(e,(function(e,t){return r(e,t)})),e}{let e=n;if(0===e.length)return[];const r={};for(let n=0;n<e.length;n++){const t=Ae(e[n]);""!==t&&(r[t]=!0)}if(!0===r.Array||!0===r.Dictionary||!0===r.Feature||!0===r.Point||!0===r.Polygon||!0===r.Polyline||!0===r.Multipoint||!0===r.Extent||!0===r.Function)return e.slice(0);let t=0,o="";for(const n in r)t++,o=n;return e=t>1||"String"===o?xe(e,(function(e,r){if(null==e||e===h)return null==r||r===h?0:1;if(null==r||r===h)return-1;const t=T(e),n=T(r);return t<n?-1:t===n?0:1})):"Number"===o?xe(e,(function(e,r){return e-r})):"Boolean"===o?xe(e,(function(e,r){return e===r?0:r?-1:1})):"Date"===o?xe(e,(function(e,r){return r-e})):e.slice(0),e}}))};for(const We in be)be[We]={value:new u(be[We]),valueset:!0,node:null};const Le=function(){};function je(e,r){const o=new Le;e||(e={}),r||(r={});const a=new t({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,o.textformatting={value:a,valueset:!0,node:null};for(const t in r)o[t]={value:new u(r[t]),native:!0,valueset:!0,node:null};for(const t in e)e[t]&&"esri.Graphic"===e[t].declaredClass?o[t]={value:n.createFromGraphic(e[t]),valueset:!0,node:null}:o[t]={value:e[t],valueset:!0,node:null};return o}Le.prototype=be,Le.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Le.prototype.pi={value:Math.PI,valueset:!0,node:null};const _e={fixSpatialReference:U,parseArguments:Q,standardFunction:$};function ke(e){console.log(e)}function Ve(e){const r={mode:"sync",compiled:!1,functions:{},signatures:[],standardFunction:$,evaluateIdentifier:Oe,arcadeCustomFunctionHandler:De};for(let t=0;t<e.length;t++)e[t].registerFunctions(r);for(const t in r.functions)be[t]={value:new u(r.functions[t]),valueset:!0,node:null},Le.prototype[t]=be[t];for(let t=0;t<r.signatures.length;t++)x(r.signatures[t],"async")}function Be(e,r){let t=r.spatialReference;null==t&&(t=new J({wkid:102100}));let n=ee({spatialReference:t,globalScope:je(r.vars,r.customfunctions),localScope:null,console:r.console?r.console:ke,lrucache:r.lrucache,interceptor:r.interceptor,depthCounter:1},e.body[0].body);if(n instanceof d&&(n=n.value),n instanceof v&&(n=n.value),n===h&&(n=null),n===p)throw new Error("Cannot return BREAK");if(n===f)throw new Error("Cannot return CONTINUE");if(n instanceof o)throw new Error("Cannot return FUNCTION");if(n instanceof u)throw new Error("Cannot return FUNCTION");return n}function Ye(e,r){return M(e)}function Ge(e){return F(e)}function ze(e,r){return P(e,r,"simple")}function qe(e,r){return D(e,r)}function Ze(e,r){return L(e,r)}function He(e){return j(e)}Ve([_]);export{Be as executeScript,Ve as extend,Ge as extractExpectedFieldLiterals,Ye as extractFieldLiterals,He as findFunctionCalls,_e as functionHelper,Ze as referencesFunction,qe as referencesMember,ze as validateScript};
|