@arcgis/core 4.32.0-next.20241205 → 4.32.0-next.20241207

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/arcade/arcadeAsyncRuntime.js +1 -1
  2. package/arcade/arcadeCompiler.js +1 -1
  3. package/arcade/arcadeRuntime.js +1 -1
  4. package/arcade/containerUtils.js +1 -1
  5. package/arcade/functions/geometry.js +1 -1
  6. package/arcade/parser.js +1 -1
  7. package/arcade/validation/arcadeValidator.js +1 -1
  8. package/arcade.js +1 -1
  9. package/assets/esri/core/workers/RemoteClient.js +1 -1
  10. package/assets/esri/core/workers/chunks/4f3aefd4f6ce93e7b9b8.js.LICENSE.txt +1 -1
  11. package/assets/esri/core/workers/chunks/5705167136ed410d99f4.js.LICENSE.txt +1 -1
  12. package/assets/esri/core/workers/chunks/{76800c372bf7dd083f03.js → 59a32bd035c33f05f431.js} +68 -73
  13. package/assets/esri/core/workers/chunks/{fa361339b7ef1462a0bf.js → 73448c61bc67d1d1d2ab.js} +1 -1
  14. package/assets/esri/core/workers/chunks/8df91ec86fdb448f98e8.js +2 -0
  15. package/assets/esri/core/workers/chunks/{908426c0952acf324bec.js.LICENSE.txt → 8df91ec86fdb448f98e8.js.LICENSE.txt} +1 -1
  16. package/assets/esri/core/workers/chunks/9d712a5be4cb32357a68.js +1 -0
  17. package/assets/esri/core/workers/chunks/9e88507679559221da9a.js +1 -0
  18. package/assets/esri/core/workers/chunks/a7a39a826ce944c15b77.js +1 -0
  19. package/assets/esri/core/workers/chunks/c80507443f896dbfaba6.js +1 -0
  20. package/assets/esri/core/workers/chunks/{c70baa3583829785fa6e.js → cd9c686be6137b3233d2.js} +2 -2
  21. package/assets/esri/core/workers/chunks/d0879c5563d4dfc5deda.js.LICENSE.txt +1 -1
  22. package/assets/esri/core/workers/chunks/{b5fe8906f00172a7574e.js → eef2d94a73064f9bc085.js} +1 -1
  23. package/assets/esri/core/workers/chunks/ef5d48e96c7d4ba4b4b2.js.LICENSE.txt +1 -1
  24. package/assets/esri/core/workers/chunks/f0e58773ff9a8a17637f.js +1 -0
  25. package/assets/esri/core/workers/chunks/{1e1a3900f6890dfb8f5a.js → f41cbb770b2e3cf274b9.js} +1 -1
  26. package/assets/esri/core/workers/chunks/f6915d62be41dc43108f.js.LICENSE.txt +1 -1
  27. package/assets/esri/core/workers/chunks/{a9171abf0a2848ef8e19.js → f96d803daeb43a1d7140.js} +2 -2
  28. package/assets/esri/core/workers/chunks/{a9171abf0a2848ef8e19.js.LICENSE.txt → f96d803daeb43a1d7140.js.LICENSE.txt} +1 -1
  29. package/assets/esri/libs/linkchartlayout/lclayout.wasm +0 -0
  30. package/chunks/CheckerBoard.glsl.js +2 -2
  31. package/chunks/ColorMaterial.glsl.js +4 -4
  32. package/chunks/ComponentShader.glsl.js +1 -1
  33. package/chunks/DefaultMaterial.glsl.js +1 -1
  34. package/chunks/EdgeShader.glsl.js +1 -1
  35. package/chunks/HUDMaterial.glsl.js +1 -1
  36. package/chunks/ImageMaterial.glsl.js +1 -1
  37. package/chunks/LineCallout.glsl.js +1 -1
  38. package/chunks/LineMarker.glsl.js +1 -1
  39. package/chunks/NativeLine.glsl.js +2 -2
  40. package/chunks/Path.glsl.js +10 -10
  41. package/chunks/Pattern.glsl.js +1 -1
  42. package/chunks/PointRenderer.glsl.js +4 -4
  43. package/chunks/RealisticTree.glsl.js +1 -1
  44. package/chunks/RibbonLine.glsl.js +1 -1
  45. package/chunks/ShadedColorMaterial.glsl.js +1 -1
  46. package/chunks/Terrain.glsl.js +5 -5
  47. package/chunks/WaterSurface.glsl.js +6 -6
  48. package/chunks/index.js +1 -1
  49. package/chunks/lclayout.js +1 -1
  50. package/core/arrayUtils.js +1 -1
  51. package/interfaces.d.ts +29 -13
  52. package/layers/LinkChartLayer.js +1 -1
  53. package/layers/video/VideoController.js +1 -1
  54. package/libs/linkchartlayout/LinkChartLayout.js +1 -1
  55. package/package.json +4 -4
  56. package/support/revision.js +1 -1
  57. package/views/2d/engine/flow/BrushFlow.js +1 -1
  58. package/views/2d/engine/flow/styles/Imagery.js +1 -1
  59. package/views/2d/engine/flow/styles/Particles.js +1 -1
  60. package/views/2d/engine/flow/styles/Streamlines.js +1 -1
  61. package/views/2d/engine/flow/utils.js +1 -1
  62. package/views/3d/layers/graphics/Graphics3DObjectSymbolLayer.js +1 -1
  63. package/views/3d/layers/graphics/Labeler.js +1 -1
  64. package/views/3d/layers/graphics/pipeline/rendering/FeaturePipelineRenderManager.js +1 -1
  65. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  66. package/views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js +13 -18
  67. package/views/3d/webgl-engine/core/shaderLibrary/default/DefaultMaterialAuxiliaryPasses.glsl.js +6 -6
  68. package/views/3d/webgl-engine/materials/DefaultMaterial.js +1 -1
  69. package/views/3d/webgl-engine/materials/DefaultTechniqueConfiguration.js +1 -1
  70. package/views/3d/webgl-engine/shaders/DefaultMaterialTechnique.js +1 -1
  71. package/views/3d/webgl-engine/shaders/DefaultMaterialTechniqueConfiguration.js +1 -1
  72. package/views/3d/webgl-engine/shaders/OutputColorHighlightOID.glsl.js +7 -7
  73. package/views/webgl/Program.js +1 -1
  74. package/widgets/BasemapLayerList.js +1 -1
  75. package/widgets/BatchAttributeForm/expressions/ExpressionsModel.js +5 -0
  76. package/widgets/BatchAttributeForm/templates/BatchFormTemplate.js +1 -1
  77. package/widgets/BatchAttributeForm/templates/FieldElementTemplate.js +1 -1
  78. package/widgets/BatchAttributeForm/templates/GroupElementTemplate.js +1 -1
  79. package/widgets/Bookmarks.js +1 -1
  80. package/widgets/Feature/FeatureUtilityNetworkAssociationType.js +1 -1
  81. package/widgets/Feature/FeatureUtilityNetworkAssociations.js +1 -1
  82. package/widgets/FeatureForm/FeatureFormViewModel.js +1 -1
  83. package/widgets/LayerList/LayerListItem.js +1 -1
  84. package/widgets/LayerList.js +1 -1
  85. package/widgets/TableList.js +1 -1
  86. package/widgets/UtilityNetworkValidateTopology.js +1 -1
  87. package/widgets/support/forms/expressions/FormExpressionArcadeExecutor.js +5 -0
  88. package/assets/esri/core/workers/chunks/428b64fe936e25cbdf64.js +0 -1
  89. package/assets/esri/core/workers/chunks/45fda7a1597ed9102fed.js +0 -1
  90. package/assets/esri/core/workers/chunks/5d212151b64fc2c720c7.js +0 -1
  91. package/assets/esri/core/workers/chunks/908426c0952acf324bec.js +0 -2
  92. package/assets/esri/core/workers/chunks/90c46d243faaa7739c2e.js +0 -1
  93. package/assets/esri/core/workers/chunks/c43fc10d2ce4c76fe773.js +0 -1
  94. package/widgets/FeatureForm/FormExpressionArcadeExecutor.js +0 -5
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{toSymbolId as e}from"./arcadeEnvironment.js";import{ArcadeModule as t}from"./ArcadeModule.js";import{ArcadeModuleLoader as n}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as r,geometryMember as o}from"./containerUtils.js";import a from"./Dictionary.js";import{ArcadeExecutionError as i,ExecutionErrorCodes as l,ensureArcadeExecutionError as s}from"./executionError.js";import c from"./Feature.js";import{NativeFunction as u,ScopeMarshalledFunction as f,ArcadeFunction as p,wrapModuleScopedResponse as w}from"./FunctionWrapper.js";import{B as d,z as h,i as m,v as g,d as y,n as b,m as v,f as S,y as x,A as F,R as I,I as M,w as R,x as k,s as A,p as C}from"../chunks/languageUtils.js";import{addFunctionDeclaration as N}from"./treeAnalysis.js";import{A as O}from"../chunks/array.js";import{registerFunctions as E}from"./functions/date.js";import{registerFunctions as j}from"./functions/geomasync.js";import{registerFunctions as B}from"./functions/geometry.js";import{registerFunctions as K}from"./functions/maths.js";import{registerFunctions as U}from"./functions/stats.js";import{registerFunctions as D}from"./functions/string.js";import Z from"../geometry/Geometry.js";import G from"../geometry/SpatialReference.js";import{isBoolean as L,isString as q,isArray as P,isNumber as W,isGraphic as T}from"../support/guards.js";async function V(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await J(e,t.arguments[r]));return n}async function _(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await V(e,t))}class z extends p{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}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,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new i(e,l.MaximumCallDepth,null);return Ce(this.definition,n,t,null)}}call(e,t){return H(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:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(a.depthCounter.depth>64)throw new i(e,l.MaximumCallDepth,t);return Ce(this.definition,a,o,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={spatialReference:e.spatialReference,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:{}};return i=i.map((t=>!m(t)||t instanceof f?t:w(t,e,r))),w(await Ce(this.definition,l,i,t),n,r)}))}}class Y extends t{constructor(e){super(),this.source=e}global(t){const n=this.executingContext.globalScope[e(t)];if(m(n.value)&&!(n.value instanceof f)){const e=new f;e.fn=n.value,e.parameterEvaluator=H,e.context=this.executingContext,n.value=e}return n.value}setGlobal(t,n){if(m(n))throw new i(null,l.AssignModuleFunction,null);this.executingContext.globalScope[e(t)]={value:n}}hasGlobal(t){return void 0===this.executingContext.exports[t]&&(t=e(t)),void 0!==this.executingContext.exports[t]}async loadModule(e){let t=e.spatialReference;null==t&&(t=new G({wkid:102100})),this.moduleScope=Ee({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:t,services:e.services,libraryResolver:new n(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,globalScope:this.moduleScope,console:e.console??je,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await ue(this.executingContext,this.source.syntax)}}async function H(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await V(e,t))}async function J(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"UpdateExpression":return await ae(e,t);case"AssignmentExpression":return await le(e,t);case"TemplateLiteral":return await Me(e,t);case"Identifier":return Fe(e,t);case"MemberExpression":return await ye(e,t);case"Literal":return t.value;case"CallExpression":return await Ie(e,t);case"UnaryExpression":return await be(e,t);case"BinaryExpression":return await Se(e,t);case"LogicalExpression":return await xe(e,t);case"ArrayExpression":return await ve(e,t);case"ObjectExpression":return await X(e,t);default:throw new i(e,l.Unrecognized,t)}}catch(n){throw s(e,t,n)}}async function Q(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"ImportDeclaration":return await de(e,t);case"ExportNamedDeclaration":return await he(e,t);case"VariableDeclaration":return await me(e,t,0);case"BlockStatement":return await ue(e,t);case"FunctionDeclaration":return await we(e,t);case"ReturnStatement":return await pe(e,t);case"IfStatement":return await ce(e,t);case"ExpressionStatement":return await se(e,t);case"ForStatement":return await ee(e,t);case"WhileStatement":return await $(e,t);case"ForInStatement":return await oe(e,t);case"BreakStatement":return R;case"EmptyStatement":return g;case"ContinueStatement":return k;default:throw new i(e,l.Unrecognized,t)}}catch(n){throw s(e,t,n)}}async function X(e,t){const n=[];for(let a=0;a<t.properties.length;a++){const r=t.properties[a],o=await J(e,r.value),i="Identifier"===r.key.type?r.key.name:await J(e,r.key);n[a]={key:i,value:o}}const r={},o=new Map;for(let a=0;a<n.length;a++){const s=n[a];if(m(s.value))throw new i(e,l.NoFunctionInDictionary,t);if(!1===q(s.key))throw new i(e,l.KeyMustBeString,t);let c=s.key.toString();const u=c.toLowerCase();o.has(u)?c=o.get(u):o.set(u,c),s.value===g?r[c]=null:r[c]=s.value}const s=new a(r);return s.immutable=!1,s}async function $(e,t){let n=await J(e,t.test);if(!1===n)return g;if(!0!==n)throw new i(e,l.BooleanConditionRequired,t);for(;!0===n;){const r=await Q(e,t.body);if(r===R)break;if(r instanceof I)return r;if(n=await J(e,t.test),!0!==n&&!1!==n)throw new i(e,l.BooleanConditionRequired,t)}return g}async function ee(e,t){try{for(null!==t.init&&("VariableDeclaration"===t.init.type?await Q(e,t.init):await J(e,t.init));;){if(null!==t.test){const n=await J(e,t.test);if(!0===e.abortSignal?.aborted)throw new i(e,l.Cancelled,t);if(!1===n)break;if(!0!==n)throw new i(e,l.BooleanConditionRequired,t)}const n=await Q(e,t.body);if(n===R)break;if(n instanceof I)return n;null!==t.update&&await J(e,t.update)}return g}catch(n){throw n}}async function te(e,t,n,r,o="i"){const a=n.length;for(let i=0;i<a;i++){r.value="k"===o?n[i]:i;const a=await Q(e,t.body);if(a===R)break;if(a instanceof I)return a}return g}async function ne(e,t,n,r,o="i"){const a=n.length();for(let i=0;i<a;i++){r.value="k"===o?n.get(i):i;const a=await Q(e,t.body);if(a===R)break;if(a instanceof I)return a}return g}async function re(e,t,n,r){const o=n.iterator(e.abortSignal);let a;for(;null!=(a=await o.next());){const o=c.createFromGraphicLikeObject(a.geometry,a.attributes,n,e.timeZone);o._underlyingGraphic=a,r.value=o;const i=await Q(e,t.body);if(i===R)break;if(i instanceof I)return i}return g}async function oe(t,n){const r=await J(t,n.right);"VariableDeclaration"===n.left.type&&await Q(t,n.left);const o=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let s=null;if(null!=t.localScope&&void 0!==t.localScope[o]&&(s=t.localScope[o]),null===s&&void 0!==t.globalScope[o]&&(s=t.globalScope[o]),null===s)throw new i(t,l.InvalidIdentifier,n);return P(r)||q(r)?await te(t,n,r,s):v(r)?await ne(t,n,r,s):r instanceof a||b(r)?await te(t,n,r.keys(),s,"k"):C(r)?await re(t,n,r,s):g}async function ae(t,n){const r=n.argument;if("CallExpression"===r.type)throw new i(t,l.NeverReach,n);if("MemberExpression"===r.type){const e=await J(t,r.object);let o,s;if(!0===r.computed)o=await J(t,r.property);else{if("Identifier"!==r.property.type)throw new i(t,l.Unrecognized,n);o=r.property.name}if(P(e)){if(!W(o))throw new i(t,l.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>=e.length)throw new i(t,l.OutOfBounds,n);s=y(e[o]),e[o]="++"===n.operator?s+1:s-1}else if(e instanceof a){if(!1===q(o))throw new i(t,l.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new i(t,l.FieldNotFound,n,{key:o});s=y(e.field(o)),e.setField(o,"++"===n.operator?s+1:s-1)}else if(e instanceof Y){if(!1===q(o))throw new i(t,l.ModuleAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new i(t,l.ModuleExportNotFound,n);s=y(e.global(o)),e.setGlobal(o,"++"===n.operator?s+1:s-1)}else{if(!b(e))throw v(e)?new i(t,l.Immutable,n):new i(t,l.InvalidParameter,n);if(!1===q(o))throw new i(t,l.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new i(t,l.FieldNotFound,n,{key:o});s=y(e.field(o)),e.setField(o,"++"===n.operator?s+1:s-1)}return!1===n.prefix?s:"++"===n.operator?s+1:s-1}const o=e(r);let s;if(null!=t.localScope&&void 0!==t.localScope[o])return s=y(t.localScope[o].value),t.localScope[o]={value:"++"===n.operator?s+1:s-1},!1===n.prefix?s:"++"===n.operator?s+1:s-1;if(void 0!==t.globalScope[o])return s=y(t.globalScope[o].value),t.globalScope[o]={value:"++"===n.operator?s+1:s-1},!1===n.prefix?s:"++"===n.operator?s+1:s-1;throw new i(t,l.InvalidIdentifier,n)}function ie(e,t,n,r,o){switch(t){case"=":return e===g?null:e;case"/=":return y(n)/y(e);case"*=":return y(n)*y(e);case"-=":return y(n)-y(e);case"+=":return q(n)||q(e)?S(n)+S(e):y(n)+y(e);case"%=":return y(n)%y(e);default:throw new i(o,l.UnsupportedOperator,r)}}async function le(t,n){const r=n.left;if("MemberExpression"===r.type){const e=await J(t,r.object);let o;if(!0===r.computed)o=await J(t,r.property);else{if("Identifier"!==r.property.type)throw new i(t,l.InvalidIdentifier,n);o=r.property.name}const s=await J(t,n.right);if(P(e)){if(!W(o))throw new i(t,l.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>e.length)throw new i(t,l.OutOfBounds,n);if(o===e.length){if("="!==n.operator)throw new i(t,l.OutOfBounds,n);e[o]=ie(s,n.operator,e[o],n,t)}else e[o]=ie(s,n.operator,e[o],n,t)}else if(e instanceof a){if(!1===q(o))throw new i(t,l.KeyAccessorMustBeString,n);if(!0===e.hasField(o))e.setField(o,ie(s,n.operator,e.field(o),n,t));else{if("="!==n.operator)throw new i(t,l.FieldNotFound,n,{key:o});e.setField(o,ie(s,n.operator,null,n,t))}}else if(e instanceof Y){if(!1===q(o))throw new i(t,l.KeyAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new i(t,l.ModuleExportNotFound,n);e.setGlobal(o,ie(s,n.operator,e.global(o),n,t))}else{if(!b(e))throw v(e)?new i(t,l.Immutable,n):new i(t,l.InvalidParameter,n);if(!1===q(o))throw new i(t,l.KeyAccessorMustBeString,n);if(!0===e.hasField(o))e.setField(o,ie(s,n.operator,e.field(o),n,t));else{if("="!==n.operator)throw new i(t,l.FieldNotFound,n,{key:o});e.setField(o,ie(s,n.operator,null,n,t))}}return g}const o=e(r);if(null!=t.localScope&&void 0!==t.localScope[o]){const e=await J(t,n.right);return t.localScope[o]={value:ie(e,n.operator,t.localScope[o].value,n,t)},g}if(void 0!==t.globalScope[o]){const e=await J(t,n.right);return t.globalScope[o]={value:ie(e,n.operator,t.globalScope[o].value,n,t)},g}throw new i(t,l.InvalidIdentifier,n)}async function se(e,t){const n=await J(e,t.expression);return n===g?g:new M(n)}async function ce(e,t){const n=await J(e,t.test);if(!0===n)return Q(e,t.consequent);if(!1===n)return null!==t.alternate?Q(e,t.alternate):g;throw new i(e,l.BooleanConditionRequired,t)}async function ue(e,t){return fe(e,t,0)}async function fe(e,t,n){if(n>=t.body.length)return g;const r=await Q(e,t.body[n]);return r instanceof I||r===R||r===k||n===t.body.length-1?r:fe(e,t,n+1)}async function pe(e,t){if(null===t.argument)return new I(g);const n=await J(e,t.argument);return new I(n)}async function we(t,n){const r=e(n.id);return t.globalScope[r]={value:new z(n,t)},g}async function de(t,n){const r=e(n.specifiers[0].local),o=t.libraryResolver.loadLibrary(r);let a;return t.libraryResolver._moduleSingletons?.has(o.uri)?a=t.libraryResolver._moduleSingletons.get(o.uri):(a=new Y(o),await a.loadModule(t),t.libraryResolver._moduleSingletons?.set(o.uri,a)),t.globalScope[r]={value:a},g}async function he(t,n){if(await Q(t,n.declaration),"FunctionDeclaration"===n.declaration.type)t.exports[e(n.declaration.id)]="function";else if("VariableDeclaration"===n.declaration.type)for(const r of n.declaration.declarations)t.exports[e(r.id)]="variable";return g}async function me(e,t,n){return n>=t.declarations.length?g:(await ge(e,t.declarations[n]),n===t.declarations.length-1||await me(e,t,n+1),g)}async function ge(t,n){let r=null;if(r=null===n.init?null:await J(t,n.init),null!==t.localScope){if(r===g&&(r=null),"Identifier"!==n.id.type)throw new i(t,l.InvalidIdentifier,n);const o=e(n.id);return void(null!=t.localScope&&(t.localScope[o]={value:r}))}if("Identifier"!==n.id.type)throw new i(t,l.InvalidIdentifier,n);const o=e(n.id);r===g&&(r=null),t.globalScope[o]={value:r}}async function ye(e,t){const n=await J(e,t.object);if(null===n)throw new i(e,l.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof a||b(n))return n.field(t.property.name);if(n instanceof Z)return o(n,t.property.name,e,t);if(n instanceof Y){if(!n.hasGlobal(t.property.name))throw new i(e,l.InvalidIdentifier,t);return n.global(t.property.name)}throw new i(e,l.InvalidMemberAccessKey,t)}throw new i(e,l.InvalidMemberAccessKey,t)}let r=await J(e,t.property);if(n instanceof a||b(n)){if(q(r))return n.field(r);throw new i(e,l.InvalidMemberAccessKey,t)}if(n instanceof Y){if(q(r))return n.global(r);throw new i(e,l.InvalidMemberAccessKey,t)}if(n instanceof Z){if(q(r))return o(n,r,e,t);throw new i(e,l.InvalidMemberAccessKey,t)}if(P(n)){if(W(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new i(e,l.OutOfBounds,t);return n[r]}throw new i(e,l.InvalidMemberAccessKey,t)}if(v(n)){if(W(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new i(e,l.OutOfBounds,t);return n.get(r)}throw new i(e,l.InvalidMemberAccessKey,t)}if(q(n)){if(W(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new i(e,l.OutOfBounds,t);return n[r]}throw new i(e,l.InvalidMemberAccessKey,t)}throw new i(e,l.InvalidMemberAccessKey,t)}async function be(e,t){const n=await J(e,t.argument);if(L(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*y(n);if("+"===t.operator)return 1*y(n);if("~"===t.operator)return~y(n);throw new i(e,l.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*y(n);if("+"===t.operator)return 1*y(n);if("~"===t.operator)return~y(n);throw new i(e,l.UnsupportedUnaryOperator,t)}async function ve(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await J(e,t.elements[r]));for(let r=0;r<n.length;r++){if(m(n[r]))throw new i(e,l.NoFunctionInArray,t);n[r]===g&&(n[r]=null)}return n}async function Se(e,t){const n=await J(e,t.left),r=await J(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return F(y(n),y(r),t.operator);case"==":return h(n,r);case"!=":return!h(n,r);case"<":case">":case"<=":case">=":return x(n,r,t.operator);case"+":return q(n)||q(r)?S(n)+S(r):y(n)+y(r);case"-":return y(n)-y(r);case"*":return y(n)*y(r);case"/":return y(n)/y(r);case"%":return y(n)%y(r);default:throw new i(e,l.UnsupportedOperator,t)}}async function xe(e,t){const n=await J(e,t.left);if(!L(n))throw new i(e,l.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":{if(!0===n)return n;const r=await J(e,t.right);if(L(r))return r;throw new i(e,l.LogicExpressionOrAnd,t)}case"&&":{if(!1===n)return n;const r=await J(e,t.right);if(L(r))return r;throw new i(e,l.LogicExpressionOrAnd,t)}default:throw new i(e,l.LogicExpressionOrAnd,t)}}function Fe(t,n){const r=e(n);if(null!=t.localScope&&void 0!==t.localScope[r])return t.localScope[r].value;if(void 0!==t.globalScope[r])return t.globalScope[r].value;throw new i(t,l.InvalidIdentifier,n)}async function Ie(t,n){if("MemberExpression"===n.callee.type){const e=await J(t,n.callee.object);if(!(e instanceof Y))throw new i(t,l.FunctionNotFound,n);const r=!1===n.callee.computed?n.callee.property.name:await J(t,n.callee.property);if(!e.hasGlobal(r))throw new i(t,l.FunctionNotFound,n);const o=e.global(r);if(!m(o))throw new i(t,l.CallNonFunction,n);return o.call(t,n)}if("Identifier"!==n.callee.type)throw new i(t,l.FunctionNotFound,n);const r=e(n.callee);if(null!=t.localScope&&void 0!==t.localScope[r]){const e=t.localScope[r];if(m(e.value))return e.value.call(t,n);throw new i(t,l.CallNonFunction,n)}if(void 0!==t.globalScope[r]){const e=t.globalScope[r];if(m(e.value))return e.value.call(t,n);throw new i(t,l.CallNonFunction,n)}throw new i(t,l.FunctionNotFound,n)}async function Me(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 J(e,t.expressions[r]);if(m(o))throw new i(e,l.NoFunctionInTemplateLiteral,t);n+=S(o)}r++}return n}const Re={};async function ke(e,t,n,r){const o=await J(e,t.arguments[n]);if(h(o,r))return J(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?J(e,t.arguments[n]):2===a?null:3===a?J(e,t.arguments[n+2]):ke(e,t,n+2,r)}async function Ae(e,t,n,r){if(!0===r)return J(e,t.arguments[n+1]);if(3===t.arguments.length-n)return J(e,t.arguments[n+2]);const o=await J(e,t.arguments[n+2]);if(!1===L(o))throw new i(e,l.ModuleExportNotFound,t.arguments[n+2]);return Ae(e,t,n+2,o)}async function Ce(t,n,r,o){const a=t.body;if(r.length!==t.params.length)throw new i(n,l.WrongNumberOfParameters,null);for(let i=0;i<r.length;i++){const o=t.params[i];"Identifier"===o.type&&null!=n.localScope&&(n.localScope[e(o)]={value:r[i]})}const s=await Q(n,a);if(s instanceof I)return s.value;if(s===R)throw new i(n,l.UnexpectedToken,o);if(s===k)throw new i(n,l.UnexpectedToken,o);return s instanceof M?s.value:s}E(Re,_),D(Re,_),K(Re,_),B(Re,_),U(Re,_),j({functions:Re,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:_,standardFunctionAsync:H}),Re.iif=async function(e,t){d(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await J(e,t.arguments[0]);if(!1===L(n))throw new i(e,l.BooleanConditionRequired,t);return J(e,n?t.arguments[1]:t.arguments[2])},Re.defaultvalue=async function(e,t){d(null===t.arguments?[]:t.arguments,2,3,e,t);const n=await J(e,t.arguments[0]);if(3===t.arguments.length){const o=await J(e,t.arguments[1]),a=r(n,o);return null!=a&&""!==a?a:J(e,t.arguments[2])}return null==n||""===n?J(e,t.arguments[1]):n},Re.decode=async function(e,t){if(t.arguments.length<2)throw new i(e,l.WrongNumberOfParameters,t);if(2===t.arguments.length)return J(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new i(e,l.WrongNumberOfParameters,t);return ke(e,t,1,await J(e,t.arguments[0]))},Re.when=async function(e,t){if(t.arguments.length<3)throw new i(e,l.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new i(e,l.WrongNumberOfParameters,t);const n=await J(e,t.arguments[0]);if(!1===L(n))throw new i(e,l.BooleanConditionRequired,t.arguments[0]);return Ae(e,t,0,n)};const Ne={fixSpatialReference:A,parseArguments:V,standardFunction:_,standardFunctionAsync:H,evaluateIdentifier:Fe};for(const De in Re)Re[De]={value:new u(Re[De])};const Oe=function(){};function Ee(e,t,n){const r=new Oe;null==e&&(e={}),null==t&&(t={});const o=new a({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});o.immutable=!1,r.textformatting={value:o};for(const a in t)r[a]={value:new u(t[a])};for(const a in e)r[a]={value:T(e[a])?c.createFromGraphic(e[a],n):e[a]};return r}function je(e){console.log(e)}Oe.prototype=Re,Oe.prototype.infinity={value:Number.POSITIVE_INFINITY},Oe.prototype.pi={value:Math.PI};const Be=Ne;function Ke(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:_,standardFunctionAsync:H,evaluateIdentifier:Fe};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Re[n]={value:new u(t.functions[n])},Oe.prototype[n]=Re[n];for(let n=0;n<t.signatures.length;n++)N(t.signatures[n],"async")}async function Ue(e,t){let r=t.spatialReference;null==r&&(r=new G({wkid:102100}));let o=null;e.usesModules&&(o=new n(new Map,e.loadedModules));const a=Ee(t.vars,t.customfunctions,t.timeZone),s={spatialReference:r,services:t.services,exports:{},libraryResolver:o,abortSignal:void 0===t.abortSignal||null===t.abortSignal?{aborted:!1}:t.abortSignal,globalScope:a,console:t.console??je,timeZone:t.timeZone??null,lrucache:t.lrucache,interceptor:t.interceptor,localScope:null,depthCounter:{depth:1}},c=await ue(s,e);if(c instanceof I||c instanceof M){const e=c.value;if(e===g)return null;if(m(e))throw new i(s,l.IllegalResult,null);return e}if(c===g)return null;if(c===R)throw new i(s,l.IllegalResult,null);if(c===k)throw new i(s,l.IllegalResult,null);throw new i(s,l.NeverReach,null)}Ke([O]);export{Ue as executeScript,Ke as extend,Be as functionHelper};
5
+ import{toSymbolId as e}from"./arcadeEnvironment.js";import{ArcadeModule as t}from"./ArcadeModule.js";import{ArcadeModuleLoader as n}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as r,geometryMember as o,getGeometryKeys as a}from"./containerUtils.js";import i from"./Dictionary.js";import{ArcadeExecutionError as l,ExecutionErrorCodes as s,ensureArcadeExecutionError as c}from"./executionError.js";import u from"./Feature.js";import{NativeFunction as f,ScopeMarshalledFunction as p,ArcadeFunction as w,wrapModuleScopedResponse as d}from"./FunctionWrapper.js";import{B as h,z as g,i as m,v as y,d as b,n as v,m as S,f as x,y as F,A as I,R as k,I as M,w as R,x as A,s as C,p as O,l as N}from"../chunks/languageUtils.js";import{addFunctionDeclaration as B}from"./treeAnalysis.js";import{A as E}from"../chunks/array.js";import{registerFunctions as j}from"./functions/date.js";import{registerFunctions as D}from"./functions/geomasync.js";import{registerFunctions as K}from"./functions/geometry.js";import{registerFunctions as U}from"./functions/maths.js";import{registerFunctions as Z}from"./functions/stats.js";import{registerFunctions as G}from"./functions/string.js";import L from"../geometry/Geometry.js";import q from"../geometry/SpatialReference.js";import{isBoolean as P,isString as V,isArray as W,isNumber as T,isGraphic as _}from"../support/guards.js";async function z(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await X(e,t.arguments[r]));return n}async function Y(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await z(e,t))}class H extends w{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}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,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new l(e,s.MaximumCallDepth,null);return je(this.definition,n,t,null)}}call(e,t){return Q(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:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(a.depthCounter.depth>64)throw new l(e,s.MaximumCallDepth,t);return je(this.definition,a,o,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={spatialReference:e.spatialReference,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:{}};return i=i.map((t=>!m(t)||t instanceof p?t:d(t,e,r))),d(await je(this.definition,l,i,t),n,r)}))}}class J extends t{constructor(e){super(),this.source=e}global(t){const n=this.executingContext.globalScope[e(t)];if(m(n.value)&&!(n.value instanceof p)){const e=new p;e.fn=n.value,e.parameterEvaluator=Q,e.context=this.executingContext,n.value=e}return n.value}setGlobal(t,n){if(m(n))throw new l(null,s.AssignModuleFunction,null);this.executingContext.globalScope[e(t)]={value:n}}hasGlobal(t){return void 0===this.executingContext.exports[t]&&(t=e(t)),void 0!==this.executingContext.exports[t]}async loadModule(e){let t=e.spatialReference;null==t&&(t=new q({wkid:102100})),this.moduleScope=Ue({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:t,services:e.services,libraryResolver:new n(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,globalScope:this.moduleScope,console:e.console??Ze,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await he(this.executingContext,this.source.syntax)}}async function Q(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await z(e,t))}async function X(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"UpdateExpression":return await ue(e,t);case"AssignmentExpression":return await pe(e,t);case"TemplateLiteral":return await Oe(e,t);case"Identifier":return Ae(e,t);case"MemberExpression":return await Fe(e,t);case"Literal":return t.value;case"CallExpression":return await Ce(e,t);case"UnaryExpression":return await Ie(e,t);case"BinaryExpression":return await Me(e,t);case"LogicalExpression":return await Re(e,t);case"ArrayExpression":return await ke(e,t);case"ObjectExpression":return await ee(e,t);default:throw new l(e,s.Unrecognized,t)}}catch(n){throw c(e,t,n)}}async function $(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"ImportDeclaration":return await be(e,t);case"ExportNamedDeclaration":return await ve(e,t);case"VariableDeclaration":return await Se(e,t,0);case"BlockStatement":return await he(e,t);case"FunctionDeclaration":return await ye(e,t);case"ReturnStatement":return await me(e,t);case"IfStatement":return await de(e,t);case"ExpressionStatement":return await we(e,t);case"ForStatement":return await ne(e,t);case"WhileStatement":return await te(e,t);case"ForInStatement":return await se(e,t);case"ForOfStatement":return await ce(e,t);case"BreakStatement":return R;case"EmptyStatement":return y;case"ContinueStatement":return A;default:throw new l(e,s.Unrecognized,t)}}catch(n){throw c(e,t,n)}}async function ee(e,t){const n=[];for(let i=0;i<t.properties.length;i++){const r=t.properties[i],o=await X(e,r.value),a="Identifier"===r.key.type?r.key.name:await X(e,r.key);n[i]={key:a,value:o}}const r={},o=new Map;for(let i=0;i<n.length;i++){const a=n[i];if(m(a.value))throw new l(e,s.NoFunctionInDictionary,t);if(!1===V(a.key))throw new l(e,s.KeyMustBeString,t);let c=a.key.toString();const u=c.toLowerCase();o.has(u)?c=o.get(u):o.set(u,c),a.value===y?r[c]=null:r[c]=a.value}const a=new i(r);return a.immutable=!1,a}async function te(e,t){let n=await X(e,t.test);if(!1===n)return y;if(!0!==n)throw new l(e,s.BooleanConditionRequired,t);for(;!0===n;){const r=await $(e,t.body);if(r===R)break;if(r instanceof k)return r;if(n=await X(e,t.test),!0!==n&&!1!==n)throw new l(e,s.BooleanConditionRequired,t)}return y}async function ne(e,t){try{for(null!==t.init&&("VariableDeclaration"===t.init.type?await $(e,t.init):await X(e,t.init));;){if(null!==t.test){const n=await X(e,t.test);if(!0===e.abortSignal?.aborted)throw new l(e,s.Cancelled,t);if(!1===n)break;if(!0!==n)throw new l(e,s.BooleanConditionRequired,t)}const n=await $(e,t.body);if(n===R)break;if(n instanceof k)return n;null!==t.update&&await X(e,t.update)}return y}catch(n){throw n}}async function re(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 l(e,s.OutOfBounds,t);r.value=n[i]}else r.value=i;const a=await $(e,t.body);if(a===R)break;if(a instanceof k)return a}return y}async function oe(e,t,n,r,o="i"){const a=n.length();for(let i=0;i<a;i++){r.value="k"===o?n.get(i):i;const a=await $(e,t.body);if(a===R)break;if(a instanceof k)return a}return y}async function ae(e,t,n,r){const o=n.iterator(e.abortSignal);let a;for(;null!=(a=await o.next());){const o=u.createFromGraphicLikeObject(a.geometry,a.attributes,n,e.timeZone);o._underlyingGraphic=a,r.value=o;const i=await $(e,t.body);if(i===R)break;if(i instanceof k)return i}return y}async function ie(e,t,n,r){for(const o of n.keys()){const a=n.field(o);r.value=new i({key:o,value:a});const l=await $(e,t.body);if(l===R)break;if(l instanceof k)return l}return y}async function le(e,t,n,r){for(const l of a(n)){const a=o(n,l,e,t,1);r.value=new i({key:l,value:a});const s=await $(e,t.body);if(s===R)break;if(s instanceof k)return s}return y}async function se(t,n){const r=await X(t,n.right);"VariableDeclaration"===n.left.type&&await $(t,n.left);const o=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let c=null;if(null!=t.localScope&&void 0!==t.localScope[o]&&(c=t.localScope[o]),null===c&&void 0!==t.globalScope[o]&&(c=t.globalScope[o]),null===c)throw new l(t,s.InvalidIdentifier,n);return W(r)||V(r)?await re(t,n,r,c):S(r)?await oe(t,n,r,c):r instanceof i||v(r)?await re(t,n,r.keys(),c,"k"):O(r)?await ae(t,n,r,c):N(r)?await re(t,n,a(r),c,"k"):y}async function ce(t,n){const r=await X(t,n.right);"VariableDeclaration"===n.left.type&&await $(t,n.left);const o=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let a=null;if(null!=t.localScope&&void 0!==t.localScope[o]&&(a=t.localScope[o]),null===a&&void 0!==t.globalScope[o]&&(a=t.globalScope[o]),null===a)throw new l(t,s.InvalidIdentifier,n);return W(r)||V(r)?await re(t,n,r,a,"k"):S(r)?await oe(t,n,r,a,"k"):r instanceof i||v(r)?await ie(t,n,r,a):O(r)?await ae(t,n,r,a):N(r)?await le(t,n,r,a):y}async function ue(t,n){const r=n.argument;if("CallExpression"===r.type)throw new l(t,s.NeverReach,n);if("MemberExpression"===r.type){const e=await X(t,r.object);let o,a;if(!0===r.computed)o=await X(t,r.property);else{if("Identifier"!==r.property.type)throw new l(t,s.Unrecognized,n);o=r.property.name}if(W(e)){if(!T(o))throw new l(t,s.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>=e.length)throw new l(t,s.OutOfBounds,n);a=b(e[o]),e[o]="++"===n.operator?a+1:a-1}else if(e instanceof i){if(!1===V(o))throw new l(t,s.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new l(t,s.FieldNotFound,n,{key:o});a=b(e.field(o)),e.setField(o,"++"===n.operator?a+1:a-1)}else if(e instanceof J){if(!1===V(o))throw new l(t,s.ModuleAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new l(t,s.ModuleExportNotFound,n);a=b(e.global(o)),e.setGlobal(o,"++"===n.operator?a+1:a-1)}else{if(!v(e))throw S(e)?new l(t,s.Immutable,n):new l(t,s.InvalidParameter,n);if(!1===V(o))throw new l(t,s.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new l(t,s.FieldNotFound,n,{key:o});a=b(e.field(o)),e.setField(o,"++"===n.operator?a+1:a-1)}return!1===n.prefix?a:"++"===n.operator?a+1:a-1}const o=e(r);let a;if(null!=t.localScope&&void 0!==t.localScope[o])return a=b(t.localScope[o].value),t.localScope[o]={value:"++"===n.operator?a+1:a-1},!1===n.prefix?a:"++"===n.operator?a+1:a-1;if(void 0!==t.globalScope[o])return a=b(t.globalScope[o].value),t.globalScope[o]={value:"++"===n.operator?a+1:a-1},!1===n.prefix?a:"++"===n.operator?a+1:a-1;throw new l(t,s.InvalidIdentifier,n)}function fe(e,t,n,r,o){switch(t){case"=":return e===y?null:e;case"/=":return b(n)/b(e);case"*=":return b(n)*b(e);case"-=":return b(n)-b(e);case"+=":return V(n)||V(e)?x(n)+x(e):b(n)+b(e);case"%=":return b(n)%b(e);default:throw new l(o,s.UnsupportedOperator,r)}}async function pe(t,n){const r=n.left;if("MemberExpression"===r.type){const e=await X(t,r.object);let o;if(!0===r.computed)o=await X(t,r.property);else{if("Identifier"!==r.property.type)throw new l(t,s.InvalidIdentifier,n);o=r.property.name}const a=await X(t,n.right);if(W(e)){if(!T(o))throw new l(t,s.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>e.length)throw new l(t,s.OutOfBounds,n);if(o===e.length){if("="!==n.operator)throw new l(t,s.OutOfBounds,n);e[o]=fe(a,n.operator,e[o],n,t)}else e[o]=fe(a,n.operator,e[o],n,t)}else if(e instanceof i){if(!1===V(o))throw new l(t,s.KeyAccessorMustBeString,n);if(!0===e.hasField(o))e.setField(o,fe(a,n.operator,e.field(o),n,t));else{if("="!==n.operator)throw new l(t,s.FieldNotFound,n,{key:o});e.setField(o,fe(a,n.operator,null,n,t))}}else if(e instanceof J){if(!1===V(o))throw new l(t,s.KeyAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new l(t,s.ModuleExportNotFound,n);e.setGlobal(o,fe(a,n.operator,e.global(o),n,t))}else{if(!v(e))throw S(e)?new l(t,s.Immutable,n):new l(t,s.InvalidParameter,n);if(!1===V(o))throw new l(t,s.KeyAccessorMustBeString,n);if(!0===e.hasField(o))e.setField(o,fe(a,n.operator,e.field(o),n,t));else{if("="!==n.operator)throw new l(t,s.FieldNotFound,n,{key:o});e.setField(o,fe(a,n.operator,null,n,t))}}return y}const o=e(r);if(null!=t.localScope&&void 0!==t.localScope[o]){const e=await X(t,n.right);return t.localScope[o]={value:fe(e,n.operator,t.localScope[o].value,n,t)},y}if(void 0!==t.globalScope[o]){const e=await X(t,n.right);return t.globalScope[o]={value:fe(e,n.operator,t.globalScope[o].value,n,t)},y}throw new l(t,s.InvalidIdentifier,n)}async function we(e,t){const n=await X(e,t.expression);return n===y?y:new M(n)}async function de(e,t){const n=await X(e,t.test);if(!0===n)return $(e,t.consequent);if(!1===n)return null!==t.alternate?$(e,t.alternate):y;throw new l(e,s.BooleanConditionRequired,t)}async function he(e,t){return ge(e,t,0)}async function ge(e,t,n){if(n>=t.body.length)return y;const r=await $(e,t.body[n]);return r instanceof k||r===R||r===A||n===t.body.length-1?r:ge(e,t,n+1)}async function me(e,t){if(null===t.argument)return new k(y);const n=await X(e,t.argument);return new k(n)}async function ye(t,n){const r=e(n.id);return t.globalScope[r]={value:new H(n,t)},y}async function be(t,n){const r=e(n.specifiers[0].local),o=t.libraryResolver.loadLibrary(r);let a;return t.libraryResolver._moduleSingletons?.has(o.uri)?a=t.libraryResolver._moduleSingletons.get(o.uri):(a=new J(o),await a.loadModule(t),t.libraryResolver._moduleSingletons?.set(o.uri,a)),t.globalScope[r]={value:a},y}async function ve(t,n){if(await $(t,n.declaration),"FunctionDeclaration"===n.declaration.type)t.exports[e(n.declaration.id)]="function";else if("VariableDeclaration"===n.declaration.type)for(const r of n.declaration.declarations)t.exports[e(r.id)]="variable";return y}async function Se(e,t,n){return n>=t.declarations.length?y:(await xe(e,t.declarations[n]),n===t.declarations.length-1||await Se(e,t,n+1),y)}async function xe(t,n){let r=null;if(r=null===n.init?null:await X(t,n.init),null!==t.localScope){if(r===y&&(r=null),"Identifier"!==n.id.type)throw new l(t,s.InvalidIdentifier,n);const o=e(n.id);return void(null!=t.localScope&&(t.localScope[o]={value:r}))}if("Identifier"!==n.id.type)throw new l(t,s.InvalidIdentifier,n);const o=e(n.id);r===y&&(r=null),t.globalScope[o]={value:r}}async function Fe(e,t){const n=await X(e,t.object);if(null===n)throw new l(e,s.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof i||v(n))return n.field(t.property.name);if(n instanceof L)return o(n,t.property.name,e,t);if(n instanceof J){if(!n.hasGlobal(t.property.name))throw new l(e,s.InvalidIdentifier,t);return n.global(t.property.name)}throw new l(e,s.InvalidMemberAccessKey,t)}throw new l(e,s.InvalidMemberAccessKey,t)}let r=await X(e,t.property);if(n instanceof i||v(n)){if(V(r))return n.field(r);throw new l(e,s.InvalidMemberAccessKey,t)}if(n instanceof J){if(V(r))return n.global(r);throw new l(e,s.InvalidMemberAccessKey,t)}if(n instanceof L){if(V(r))return o(n,r,e,t);throw new l(e,s.InvalidMemberAccessKey,t)}if(W(n)){if(T(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new l(e,s.OutOfBounds,t);return n[r]}throw new l(e,s.InvalidMemberAccessKey,t)}if(S(n)){if(T(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new l(e,s.OutOfBounds,t);return n.get(r)}throw new l(e,s.InvalidMemberAccessKey,t)}if(V(n)){if(T(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new l(e,s.OutOfBounds,t);return n[r]}throw new l(e,s.InvalidMemberAccessKey,t)}throw new l(e,s.InvalidMemberAccessKey,t)}async function Ie(e,t){const n=await X(e,t.argument);if(P(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*b(n);if("+"===t.operator)return 1*b(n);if("~"===t.operator)return~b(n);throw new l(e,s.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*b(n);if("+"===t.operator)return 1*b(n);if("~"===t.operator)return~b(n);throw new l(e,s.UnsupportedUnaryOperator,t)}async function ke(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await X(e,t.elements[r]));for(let r=0;r<n.length;r++){if(m(n[r]))throw new l(e,s.NoFunctionInArray,t);n[r]===y&&(n[r]=null)}return n}async function Me(e,t){const n=await X(e,t.left),r=await X(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return I(b(n),b(r),t.operator);case"==":return g(n,r);case"!=":return!g(n,r);case"<":case">":case"<=":case">=":return F(n,r,t.operator);case"+":return V(n)||V(r)?x(n)+x(r):b(n)+b(r);case"-":return b(n)-b(r);case"*":return b(n)*b(r);case"/":return b(n)/b(r);case"%":return b(n)%b(r);default:throw new l(e,s.UnsupportedOperator,t)}}async function Re(e,t){const n=await X(e,t.left);if(!P(n))throw new l(e,s.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":{if(!0===n)return n;const r=await X(e,t.right);if(P(r))return r;throw new l(e,s.LogicExpressionOrAnd,t)}case"&&":{if(!1===n)return n;const r=await X(e,t.right);if(P(r))return r;throw new l(e,s.LogicExpressionOrAnd,t)}default:throw new l(e,s.LogicExpressionOrAnd,t)}}function Ae(t,n){const r=e(n);if(null!=t.localScope&&void 0!==t.localScope[r])return t.localScope[r].value;if(void 0!==t.globalScope[r])return t.globalScope[r].value;throw new l(t,s.InvalidIdentifier,n)}async function Ce(t,n){if("MemberExpression"===n.callee.type){const e=await X(t,n.callee.object);if(!(e instanceof J))throw new l(t,s.FunctionNotFound,n);const r=!1===n.callee.computed?n.callee.property.name:await X(t,n.callee.property);if(!e.hasGlobal(r))throw new l(t,s.FunctionNotFound,n);const o=e.global(r);if(!m(o))throw new l(t,s.CallNonFunction,n);return o.call(t,n)}if("Identifier"!==n.callee.type)throw new l(t,s.FunctionNotFound,n);const r=e(n.callee);if(null!=t.localScope&&void 0!==t.localScope[r]){const e=t.localScope[r];if(m(e.value))return e.value.call(t,n);throw new l(t,s.CallNonFunction,n)}if(void 0!==t.globalScope[r]){const e=t.globalScope[r];if(m(e.value))return e.value.call(t,n);throw new l(t,s.CallNonFunction,n)}throw new l(t,s.FunctionNotFound,n)}async function Oe(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 X(e,t.expressions[r]);if(m(o))throw new l(e,s.NoFunctionInTemplateLiteral,t);n+=x(o)}r++}return n}const Ne={};async function Be(e,t,n,r){const o=await X(e,t.arguments[n]);if(g(o,r))return X(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?X(e,t.arguments[n]):2===a?null:3===a?X(e,t.arguments[n+2]):Be(e,t,n+2,r)}async function Ee(e,t,n,r){if(!0===r)return X(e,t.arguments[n+1]);if(3===t.arguments.length-n)return X(e,t.arguments[n+2]);const o=await X(e,t.arguments[n+2]);if(!1===P(o))throw new l(e,s.ModuleExportNotFound,t.arguments[n+2]);return Ee(e,t,n+2,o)}async function je(t,n,r,o){const a=t.body;if(r.length!==t.params.length)throw new l(n,s.WrongNumberOfParameters,null);for(let l=0;l<r.length;l++){const o=t.params[l];"Identifier"===o.type&&null!=n.localScope&&(n.localScope[e(o)]={value:r[l]})}const i=await $(n,a);if(i instanceof k)return i.value;if(i===R)throw new l(n,s.UnexpectedToken,o);if(i===A)throw new l(n,s.UnexpectedToken,o);return i instanceof M?i.value:i}j(Ne,Y),G(Ne,Y),U(Ne,Y),K(Ne,Y),Z(Ne,Y),D({functions:Ne,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:Y,standardFunctionAsync:Q}),Ne.iif=async function(e,t){h(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await X(e,t.arguments[0]);if(!1===P(n))throw new l(e,s.BooleanConditionRequired,t);return X(e,n?t.arguments[1]:t.arguments[2])},Ne.defaultvalue=async function(e,t){h(null===t.arguments?[]:t.arguments,2,3,e,t);const n=await X(e,t.arguments[0]);if(3===t.arguments.length){const o=await X(e,t.arguments[1]),a=r(n,o);return null!=a&&""!==a?a:X(e,t.arguments[2])}return null==n||""===n?X(e,t.arguments[1]):n},Ne.decode=async function(e,t){if(t.arguments.length<2)throw new l(e,s.WrongNumberOfParameters,t);if(2===t.arguments.length)return X(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new l(e,s.WrongNumberOfParameters,t);return Be(e,t,1,await X(e,t.arguments[0]))},Ne.when=async function(e,t){if(t.arguments.length<3)throw new l(e,s.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new l(e,s.WrongNumberOfParameters,t);const n=await X(e,t.arguments[0]);if(!1===P(n))throw new l(e,s.BooleanConditionRequired,t.arguments[0]);return Ee(e,t,0,n)};const De={fixSpatialReference:C,parseArguments:z,standardFunction:Y,standardFunctionAsync:Q,evaluateIdentifier:Ae};for(const Pe in Ne)Ne[Pe]={value:new f(Ne[Pe])};const Ke=function(){};function Ue(e,t,n){const r=new Ke;null==e&&(e={}),null==t&&(t={});const o=new i({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});o.immutable=!1,r.textformatting={value:o};for(const a in t)r[a]={value:new f(t[a])};for(const a in e)r[a]={value:_(e[a])?u.createFromGraphic(e[a],n):e[a]};return r}function Ze(e){console.log(e)}Ke.prototype=Ne,Ke.prototype.infinity={value:Number.POSITIVE_INFINITY},Ke.prototype.pi={value:Math.PI};const Ge=De;function Le(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:Y,standardFunctionAsync:Q,evaluateIdentifier:Ae};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Ne[n]={value:new f(t.functions[n])},Ke.prototype[n]=Ne[n];for(let n=0;n<t.signatures.length;n++)B(t.signatures[n],"async")}async function qe(e,t){let r=t.spatialReference;null==r&&(r=new q({wkid:102100}));let o=null;e.usesModules&&(o=new n(new Map,e.loadedModules));const a=Ue(t.vars,t.customfunctions,t.timeZone),i={spatialReference:r,services:t.services,exports:{},libraryResolver:o,abortSignal:void 0===t.abortSignal||null===t.abortSignal?{aborted:!1}:t.abortSignal,globalScope:a,console:t.console??Ze,timeZone:t.timeZone??null,lrucache:t.lrucache,interceptor:t.interceptor,localScope:null,depthCounter:{depth:1}},c=await he(i,e);if(c instanceof k||c instanceof M){const e=c.value;if(e===y)return null;if(m(e))throw new l(i,s.IllegalResult,null);return e}if(c===y)return null;if(c===R)throw new l(i,s.IllegalResult,null);if(c===A)throw new l(i,s.IllegalResult,null);throw new l(i,s.NeverReach,null)}Le([E]);export{qe as executeScript,Le as extend,Ge as functionHelper};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{toSymbolId as e}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import{geometryMember as o,getNestedOptionalValue as l}from"./containerUtils.js";import r from"./Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as s,ArcadeCompilationError as i,ArcadeUncompilableError as c}from"./executionError.js";import u from"./Feature.js";import{NativeFunction as p,ArcadeFunction as m,ScopeMarshalledFunction as g,wrapModuleScopedResponse as d}from"./FunctionWrapper.js";import{i as f,s as h,u as y,R as b,I as w,v as S,w as v,x,m as F,n as M,q as C,l as I,f as A,d as _,y as O,z as $,A as k}from"../chunks/languageUtils.js";import{addFunctionDeclaration as E}from"./treeAnalysis.js";import{A as G}from"../chunks/array.js";import{registerFunctions as B}from"./functions/date.js";import{registerFunctions as j}from"./functions/geometry.js";import{registerFunctions as N}from"./functions/geomsync.js";import{registerFunctions as R}from"./functions/maths.js";import{registerFunctions as L}from"./functions/stats.js";import{registerFunctions as U}from"./functions/string.js";import{isPromiseLike as D}from"../core/promiseUtils.js";import Z from"../geometry/Geometry.js";import K from"../geometry/SpatialReference.js";import{isGraphic as P,isNumber as W,isArray as T,isString as q,isBoolean as z}from"../support/guards.js";class V extends m{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new a(e,s.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,o){return o(e,n,((n,l,r)=>{r=r.map((n=>!f(n)||n instanceof g?n:d(n,e,o)));const a=this.call(t,{arguments:r});return D(a)?a.then((e=>d(e,t,o))):a}))}}function J(e,n){const t=[];for(let o=0;o<n.arguments.length;o++)t.push(H(e,n.arguments[o]));return t}function Y(e,n,t){try{return t(e,null,n.arguments)}catch(o){throw o}}function H(e,n){switch(n.type){case"AssignmentExpression":return le(e,n);case"UpdateExpression":return te(e,n);case"TemplateLiteral":return we(e,n);case"Identifier":return xe(e,n);case"MemberExpression":return he(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return Fe(e,n);case"UnaryExpression":return ye(e,n);case"BinaryExpression":return Se(e,n);case"LogicalExpression":return ve(e,n);case"ArrayExpression":return be(e,n);case"ObjectExpression":return X(e,n);default:throw new i(e,s.Unrecognized,n)}}function Q(e,n){switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclaration":return de(e,n);case"BlockStatement":return ie(e,n);case"FunctionDeclaration":return ge(e,n);case"ImportDeclaration":return ue(e,n);case"ExportNamedDeclaration":return pe(e,n);case"ReturnStatement":return ce(e,n);case"IfStatement":return se(e,n);case"ExpressionStatement":return re(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"ForStatement":return ne(e,n);case"ForInStatement":return ee(e,n);case"WhileStatement":return oe(e,n);default:throw new i(e,s.Unrecognized,n)}}function X(e,n){let t="lang.dictionary([";for(let o=0;o<n.properties.length;o++){const l=n.properties[o];let r;"Identifier"===l.key.type?(me(l.key.name),r="'"+l.key.name+"'"):r=H(e,l.key);o>0&&(t+=","),t+="lang.strCheck("+r+",'ObjectExpression'),lang.aCheck("+H(e,l.value)+", 'ObjectExpression')"}return t+="])",t}function ee(n,t){const o=$e(n),l=$e(n),r=$e(n);let a="var "+o+" = "+H(n,t.right)+";\n";"VariableDeclaration"===t.left.type&&(a+=Q(n,t.left));const s=e("VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);me(s);let i="";null!==n.localScope&&(void 0!==n.localScope[s]?i="lscope['"+s+"']":void 0!==n.localScope._SymbolsMap[s]&&(i="lscope['"+n.localScope._SymbolsMap[s]+"']"));let c="";if(""===i)if(void 0!==n.globalScope[s])i="gscope['"+s+"']";else if(void 0!==n.globalScope._SymbolsMap[s])i="gscope['"+n.globalScope._SymbolsMap[s]+"']";else if(null!==n.localScope)if(n.undeclaredGlobalsInFunctions.has(s))i="gscope['"+n.undeclaredGlobalsInFunctions.get(s).manglename+"']",c=n.undeclaredGlobalsInFunctions.get(s).manglename;else{const e={manglename:Oe(n),node:t.left};n.undeclaredGlobalsInFunctions.set(s,e),i="gscope['"+e.manglename+"']",c=e.manglename}return c&&(a+="lang.chkAssig('"+c+"',runtimeCtx); \n"),a+="if ("+o+"===null) { lastStatement = lc.voidOperation; }\n ",a+="else if (lc.isArray("+o+") || lc.isString("+o+")) {",a+="var "+l+"="+o+".length; \n",a+="for(var "+r+"=0; "+r+"<"+l+"; "+r+"++) {\n",a+=i+"="+r+";\n",a+=Q(n,t.body),a+="\n}\n",a+=" lastStatement = lc.voidOperation; \n",a+=" \n}\n",a+="else if (lc.isImmutableArray("+o+")) {",a+="var "+l+"="+o+".length(); \n",a+="for(var "+r+"=0; "+r+"<"+l+"; "+r+"++) {\n",a+=i+"="+r+";\n",a+=Q(n,t.body),a+="\n}\n",a+=" lastStatement = lc.voidOperation; \n",a+=" \n}\n",a+="else if (( "+o+" instanceof lang.Dictionary) || ( "+o+" instanceof lang.Feature)) {",a+="var "+l+"="+o+".keys(); \n",a+="for(var "+r+"=0; "+r+"<"+l+".length; "+r+"++) {\n",a+=i+"="+l+"["+r+"];\n",a+=Q(n,t.body),a+="\n}\n",a+=" lastStatement = lc.voidOperation; \n",a+=" \n}\n",n.isAsync&&(a+="else if (lc.isFeatureSet("+o+")) {",a+="var "+l+"="+o+".iterator(runtimeCtx.abortSignal); \n",a+="for(var "+r+"=lang. graphicToFeature( yield "+l+".next(),"+o+", runtimeCtx); "+r+"!=null; "+r+"=lang. graphicToFeature( yield "+l+".next(),"+o+", runtimeCtx)) {\n",a+=i+"="+r+";\n",a+=Q(n,t.body),a+="\n}\n",a+=" lastStatement = lc.voidOperation; \n",a+=" \n}\n"),a+="else { lastStatement = lc.voidOperation; } \n",a}function ne(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&("VariableDeclaration"===n.init.type?t+=Q(e,n.init):t+=H(e,n.init)+"; ");const o=$e(e),l=$e(e);return t+="var "+o+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+o+"===false) {\n "+H(e,n.update)+" \n}\n "+o+"=false; \n"),null!==n.test&&(t+="var "+l+" = "+H(e,n.test)+"; ",t+="if ("+l+"===false) { break; } else if ("+l+"!==true) { lang.error('"+s.BooleanConditionRequired+"'); }\n"),t+=Q(e,n.body),null!==n.update&&(t+="\n "+H(e,n.update)),t+="\n"+o+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function te(n,t){if("CallExpression"===t.argument.type)throw new i(n,s.NeverReach,t);let o;if("MemberExpression"===t.argument.type){const e=H(n,t.argument.object);return!0===t.argument.computed?o=H(n,t.argument.property):(me(t.argument.property.name),o="'"+t.argument.property.name+"'"),"lang.memberupdate("+e+","+o+",'"+t.operator+"',"+t.prefix+")"}const l=e(t.argument);if(me(l),null!==n.localScope){if(void 0!==n.localScope[l])return"lang.update(lscope, '"+l+"','"+t.operator+"',"+t.prefix+")";if(void 0!==n.localScope._SymbolsMap[l])return"lang.update(lscope, '"+n.localScope._SymbolsMap[l]+"','"+t.operator+"',"+t.prefix+")"}if(void 0!==n.globalScope[l])return"lang.update(gscope, '"+l+"','"+t.operator+"',"+t.prefix+")";if(void 0!==n.globalScope._SymbolsMap[l])return"lang.update(gscope, '"+n.globalScope._SymbolsMap[l]+"','"+t.operator+"',"+t.prefix+")";if(null!==n.localScope){if(n.undeclaredGlobalsInFunctions.has(l))return"lang.update(gscope,lang.chkAssig( '"+n.undeclaredGlobalsInFunctions.get(l).manglename+"',runtimeCtx),'"+t.operator+"',"+t.prefix+")";const e={manglename:Oe(n),node:t.argument};return n.undeclaredGlobalsInFunctions.set(l,e),"lang.update(gscope, lang.chkAssig('"+e.manglename+"',runtimeCtx),'"+t.operator+"',"+t.prefix+")"}throw new a(n,s.InvalidIdentifier,t)}function oe(e,n){let t="lastStatement = lc.voidOperation; \n";const o=$e(e);return t+=`\n var ${o} = true;\n do {\n ${o} = ${H(e,n.test)};\n if (${o}==false) {\n break;\n }\n if (${o}!==true) {\n lang.error('${s.BooleanConditionRequired}');\n }\n ${Q(e,n.body)}\n }\n while (${o} !== false);\n lastStatement = lc.voidOperation;\n `,t}function le(n,t){const o=H(n,t.right);if("MemberExpression"===t.left.type){let e;const l=H(n,t.left.object);return!0===t.left.computed?e=H(n,t.left.property):(e="'"+t.left.property.name+"'",me(t.left.property.name)),"lang.assignmember("+l+","+e+",'"+t.operator+"',"+o+")"}const l=e(t.left);if(me(l),null!==n.localScope){if(void 0!==n.localScope[l])return"lscope['"+l+"']=lang.assign("+o+",'"+t.operator+"', lscope['"+l+"'])";if(void 0!==n.localScope._SymbolsMap[l])return"lscope['"+n.localScope._SymbolsMap[l]+"']=lang.assign("+o+",'"+t.operator+"', lscope['"+n.localScope._SymbolsMap[l]+"'])"}if(void 0!==n.globalScope[l])return"gscope['"+l+"']=lang.assign("+o+",'"+t.operator+"', gscope['"+l+"'])";if(void 0!==n.globalScope._SymbolsMap[l])return"gscope['"+n.globalScope._SymbolsMap[l]+"']=lang.assign("+o+",'"+t.operator+"', gscope['"+n.globalScope._SymbolsMap[l]+"'])";if(null!==n.localScope){if(n.undeclaredGlobalsInFunctions.has(l))return"gscope[lang.chkAssig('"+n.undeclaredGlobalsInFunctions.get(l).manglename+"',runtimeCtx)]=lang.assign("+o+",'"+t.operator+"', gscope['"+n.undeclaredGlobalsInFunctions.get(l).manglename+"'])";const e={manglename:Oe(n),node:t.left};return n.undeclaredGlobalsInFunctions.set(l,e),"gscope[lang.chkAssig('"+e.manglename+"',runtimeCtx)]=lang.assign("+o+",'"+t.operator+"', gscope['"+e.manglename+"'])"}throw new a(n,s.InvalidIdentifier,t)}function re(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+H(e,n.expression)+"; \n ":"lastStatement = "+H(e,n.expression)+"; "}function ae(e,n){return"BlockStatement"===n.type?Q(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?Q(e,n)+"; ":"ExpressionStatement"===n.type?Q(e,n):Q(e,n)+"; "}function se(e,n){return`if (lang.mustBoolean(${H(e,n.test)}, runtimeCtx) === true) {\n ${ae(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+se(e,n.alternate):` else {\n ${ae(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function ie(e,n){let t="";for(let o=0;o<n.body.length;o++)"EmptyStatement"!==n.body[o].type&&("ReturnStatement"===n.body[o].type||"BreakStatement"===n.body[o].type||"ContinueStatement"===n.body[o].type?t+=Q(e,n.body[o])+"; \n":t+=Q(e,n.body[o])+" \n");return t}function ce(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+H(e,n.argument)}function ue(n,t){const o=e(t.specifiers[0].local);me(o);const l=n.libraryResolver?.loadLibrary(o),r=Oe(n);void 0===n.moduleFactory[l.uri]&&(n.moduleFactory[l.uri]=qe(l.syntax,{interceptor:n.interceptor,services:n.services,moduleFactory:n.moduleFactory,lrucache:n.lrucache,timeZone:n.timeZone??null,libraryResolver:n.libraryResolver,customfunctions:n.customfunctions,vars:{}},n.isAsync)),n.moduleFactoryMap[r]=l.uri;let a,s="";return s=n.isAsync?"(yield lang.loadModule('"+r+"', runtimeCtx) ); ":"lang.loadModule('"+r+"', runtimeCtx); ",void 0!==n.globalScope[o]?"gscope['"+o+"']="+s:void 0!==n.globalScope._SymbolsMap[o]?"gscope['"+n.globalScope._SymbolsMap[o]+"']="+s:(n.undeclaredGlobalsInFunctions.has(o)?(a=n.undeclaredGlobalsInFunctions.get(o).manglename,n.undeclaredGlobalsInFunctions.delete(o)):a=Oe(n),n.globalScope._SymbolsMap[o]=a,n.mangleMap[o]=a,"gscope[lang.setAssig('"+a+"', runtimeCtx)]="+s)}function pe(n,t){const o=Q(n,t.declaration);if("FunctionDeclaration"===t.declaration.type)n.exports[e(t.declaration.id)]="function";else if("VariableDeclaration"===t.declaration.type)for(const l of t.declaration.declarations)n.exports[e(l.id)]="variable";return o}function me(e){if("iif"===e)throw new c;if("decode"===e)throw new c;if("when"===e)throw new c;if("defaultvalue"===e)throw new c}function ge(n,t){const o=e(t.id);let l;me(o);let r=!1;void 0!==n.globalScope[o]?l=o:void 0!==n.globalScope._SymbolsMap[o]?l=n.globalScope._SymbolsMap[o]:n.undeclaredGlobalsInFunctions.has(o)?(l=n.undeclaredGlobalsInFunctions.get(o).manglename,n.globalScope._SymbolsMap[o]=l,n.mangleMap[o]=l,n.undeclaredGlobalsInFunctions.delete(o),r=!0):(l=Oe(n),n.globalScope._SymbolsMap[o]=l,n.mangleMap[o]=l);const a={isAsync:n.isAsync,console:n.console,exports:n.exports,undeclaredGlobalsInFunctions:n.undeclaredGlobalsInFunctions,customfunctions:n.customfunctions,moduleFactory:n.moduleFactory,moduleFactoryMap:n.moduleFactoryMap,libraryResolver:n.libraryResolver,lrucache:n.lrucache,interceptor:n.interceptor,services:n.services,symbols:n.symbols,mangleMap:n.mangleMap,localScope:{_SymbolsMap:{}},depthCounter:n.depthCounter,globalScope:n.globalScope};let s="new lang.UserDefinedCompiledFunction( lang.functionDepthchecker(function() { var lastStatement = lc.voidOperation; \n var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];\n";for(let i=0;i<t.params.length;i++){const o=e(t.params[i]);me(o);const l=Oe(n);a.localScope._SymbolsMap[o]=l,a.mangleMap[o]=l,s+="lscope['"+l+"']=arguments["+i.toString()+"];\n"}return!0===n.isAsync?(s+="return lang.__awaiter(this, void 0, void 0, function* () {\n",s+=ie(a,t.body)+"\n return lastStatement; ",s+="}); }",s+=", runtimeCtx),"+t.params.length+")",s+="\n lastStatement = lc.voidOperation; \n"):(s+=ie(a,t.body)+"\n return lastStatement; }, runtimeCtx),"+t.params.length+")",s+="\n lastStatement = lc.voidOperation; \n"),r?"gscope[lang.setAssig('"+l+"', runtimeCtx)]="+s:"gscope['"+l+"']="+s}function de(e,n){const t=[];for(let o=0;o<n.declarations.length;o++)t.push(fe(e,n.declarations[o]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function fe(n,t){const o=null===t.init?null:H(n,t.init),l=e(t.id);if(me(l),null!==n.localScope){if(void 0!==n.localScope[l])return"lscope['"+l+"']="+o+"; ";if(void 0!==n.localScope._SymbolsMap[l])return"lscope['"+n.localScope._SymbolsMap[l]+"']="+o+"; ";const e=Oe(n);return n.localScope._SymbolsMap[l]=e,n.mangleMap[l]=e,"lscope['"+e+"']="+o+"; "}if(void 0!==n.globalScope[l])return"gscope['"+l+"']="+o+"; ";if(void 0!==n.globalScope._SymbolsMap[l])return"gscope['"+n.globalScope._SymbolsMap[l]+"']="+o+"; ";if(n.undeclaredGlobalsInFunctions.has(l)){const e=n.undeclaredGlobalsInFunctions.get(l).manglename;return n.globalScope._SymbolsMap[l]=e,n.mangleMap[l]=e,n.undeclaredGlobalsInFunctions.delete(l),"gscope[lang.setAssig('"+e+"', runtimeCtx)]="+o+"; "}const r=Oe(n);return n.globalScope._SymbolsMap[l]=r,n.mangleMap[l]=r,"gscope['"+r+"']="+o+"; "}function he(e,n){try{let t;return!0===n.computed?t=H(e,n.property):(me(n.property.name),t="'"+n.property.name+"'"),"lang.member("+H(e,n.object)+","+t+")"}catch(t){throw t}}function ye(e,n){try{return"lang.unary("+H(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function be(e,n){try{const t=[];for(let o=0;o<n.elements.length;o++)"Literal"===n.elements[o].type?t.push(H(e,n.elements[o])):t.push("lang.aCheck("+H(e,n.elements[o])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function we(e,n){try{const t=[];let o=0;for(const l of n.quasis)t.push(l.value?JSON.stringify(l.value.cooked):JSON.stringify("")),!1===l.tail&&(t.push(n.expressions[o]?"lang.castString(lang.aCheck("+H(e,n.expressions[o])+", 'TemplateLiteral'))":""),o++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function Se(e,n){try{return"lang.binary("+H(e,n.left)+","+H(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function ve(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new i(e,s.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new i(e,s.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+H(e,n.left)+") "+n.operator+" lang.logicalCheck("+H(e,n.right)+"))";throw new i(null,s.LogicExpressionOrAnd,null)}catch(t){throw t}}function xe(n,t){try{const o=e(t);if(me(o),null!==n.localScope){if(void 0!==n.localScope[o])return"lscope['"+o+"']";if(void 0!==n.localScope._SymbolsMap[o])return"lscope['"+n.localScope._SymbolsMap[o]+"']"}if(void 0!==n.globalScope[o])return"gscope['"+o+"']";if(void 0!==n.globalScope._SymbolsMap[o])return"gscope['"+n.globalScope._SymbolsMap[o]+"']";if(null!==n.localScope){if(n.undeclaredGlobalsInFunctions.has(o))return"gscope[lang.chkAssig('"+n.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx)]";const e={manglename:Oe(n),node:t};return n.undeclaredGlobalsInFunctions.set(o,e),"gscope[lang.chkAssig('"+e.manglename+"',runtimeCtx)]"}throw new i(n,s.InvalidIdentifier,t)}catch(o){throw o}}function Fe(n,t){try{if("MemberExpression"===t.callee.type){let e;!0===t.callee.computed?e=H(n,t.callee.property):(me(t.callee.property.name),e="'"+t.callee.property.name+"'");let o="[";for(let l=0;l<t.arguments.length;l++)l>0&&(o+=", "),o+=H(n,t.arguments[l]);return o+="]",n.isAsync?"(yield lang.callModuleFunction("+H(n,t.callee.object)+","+o+","+e+",runtimeCtx))":"lang.callModuleFunction("+H(n,t.callee.object)+","+o+","+e+",runtimeCtx)"}if("Identifier"!==t.callee.type)throw new i(n,s.FunctionNotFound,t);const o=e(t.callee);if("iif"===o)return Me(n,t);if("when"===o)return Ie(n,t);if("defaultvalue"===o)return Ce(n,t);if("decode"===o)return Ae(n,t);let l="";if(null!==n.localScope&&(void 0!==n.localScope[o]?l="lscope['"+o+"']":void 0!==n.localScope._SymbolsMap[o]&&(l="lscope['"+n.localScope._SymbolsMap[o]+"']")),""===l)if(void 0!==n.globalScope[o])l="gscope['"+o+"']";else if(void 0!==n.globalScope._SymbolsMap[o])l="gscope['"+n.globalScope._SymbolsMap[o]+"']";else if(null!==n.localScope)if(n.undeclaredGlobalsInFunctions.has(o))l="gscope[lang.chkAssig('"+n.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx)]";else{const e={manglename:Oe(n),node:t.callee};n.undeclaredGlobalsInFunctions.set(o,e),l="gscope[lang.chkAssig('"+e.manglename+"',runtimeCtx)]"}if(""!==l){let e="[";for(let o=0;o<t.arguments.length;o++)o>0&&(e+=", "),e+=H(n,t.arguments[o]);return e+="]",n.isAsync?"(yield lang.callfunc("+l+","+e+",runtimeCtx) )":"lang.callfunc("+l+","+e+",runtimeCtx)"}throw new i(n,s.FunctionNotFound,t)}catch(o){throw o}}function Me(e,n){try{if(3!==n.arguments.length)throw new i(e,s.WrongNumberOfParameters,n);const t=$e(e);return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${H(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${H(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${H(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ce(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new i(e,s.WrongNumberOfParameters,n);const t=$e(e),o=$e(e);return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${H(e,n.arguments[0])};\n var ${o} = ${H(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${o});\n return ${t} != null && ${t} !== "" ? ${t} : ${H(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} = ${H(e,n.arguments[0])};\n if (${t} === null) {\n return ${H(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${H(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${H(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ie(e,n){try{if(n.arguments.length<3)throw new i(e,s.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new i(e,s.WrongNumberOfParameters,n);const t=$e(e);let o="var ";for(let l=0;l<n.arguments.length-1;l+=2)o+=`${t} = lang.mustBoolean(${H(e,n.arguments[l])}, runtimeCtx);\n if (${t} === true ) {\n return ${H(e,n.arguments[l+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${o}\n return ${H(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ae(e,n){try{if(n.arguments.length<2)throw new i(e,s.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${H(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new i(e,s.WrongNumberOfParameters,n);const t=$e(e),o=$e(e);let l="var ";for(let r=1;r<n.arguments.length-1;r+=2)l+=`${o} = ${H(e,n.arguments[r])};\n if (lang.binary(${o}, ${t}, "==") === true ) {\n return ${H(e,n.arguments[r+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${H(e,n.arguments[0])};\n ${l}\n return ${H(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const _e={};function Oe(e){return e.symbols.symbolCounter++,`_T${e.symbols.symbolCounter}`}function $e(e){return e.symbols.symbolCounter++,`_Tvar${e.symbols.symbolCounter}`}B(_e,Y),U(_e,Y),R(_e,Y),j(_e,Y),L(_e,Y),_e.iif=function(e,n){try{return Y(e,n,((t,o,l)=>{throw new a(e,s.Unrecognized,n)}))}catch(t){throw t}},_e.decode=function(e,n){try{return Y(e,n,((t,o,l)=>{throw new a(e,s.Unrecognized,n)}))}catch(t){throw t}},_e.when=function(e,n){try{return Y(e,n,((t,o,l)=>{throw new a(e,s.Unrecognized,n)}))}catch(t){throw t}},_e.defaultvalue=function(e,n){try{return Y(e,n,((t,o,l)=>{throw new a(e,s.Unrecognized,n)}))}catch(t){throw t}};const ke={};for(const ze in _e)ke[ze]=new p(_e[ze]);N(_e,Y);for(const ze in _e)_e[ze]=new p(_e[ze]);const Ee=function(){};Ee.prototype=_e;const Ge=function(){};function Be(e,n,t){const o={_SymbolsMap:{}};e||(e={}),t||(t={}),o.textformatting=1,o.infinity=1,o.pi=1;for(const l in n)o[l]=1;for(const l in t)o[l]=1;for(const l in e)o[l]=1;return o}function je(e,n,t,o){const l=t?new Ge:new Ee;e||(e={}),n||(n={});const a=new r({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,l._SymbolsMap={textformatting:1,infinity:1,pi:1},l.textformatting=a,l.infinity=Number.POSITIVE_INFINITY,l.pi=Math.PI;for(const r in n)l[r]=n[r],l._SymbolsMap[r]=1;for(const r in e){const n=e[r];l._SymbolsMap[r]=1,P(n)?l[r]=u.createFromGraphic(n,o??null):l[r]=n}return l}Ge.prototype=ke;const Ne={fixSpatialReference:h,parseArguments:J,standardFunction:Y};function Re(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:Y,standardFunctionAsync:Y,evaluateIdentifier:Ue};for(let o=0;o<e.length;o++)e[o].registerFunctions(t);if("sync"===n){for(const e in t.functions)_e[e]=new p(t.functions[e]),Ee.prototype[e]=_e[e];for(let e=0;e<t.signatures.length;e++)E(t.signatures[e],"sync")}else{for(const e in t.functions)ke[e]=new p(t.functions[e]),Ge.prototype[e]=ke[e];for(let e=0;e<t.signatures.length;e++)E(t.signatures[e],"async")}}function Le(e,n){return e(n)}function Ue(e,n){const t=n.name;if("_SymbolsMap"===t)throw new a(e,s.InvalidIdentifier,null);if(e.localStack.length>0){const n=e.localStack[e.localStack.length-1];if(!t.toLowerCase().startsWith("_t")&&void 0!==n[t])return n[t];const o=e.mangleMap[t];if(void 0!==o&&void 0!==n[o])return n[o]}if(!t.toLowerCase().startsWith("_t")&&void 0!==e.globalScope[t])return e.globalScope[t];if(1===e.globalScope._SymbolsMap[t])return e.globalScope[t];const o=e.mangleMap[t];return void 0!==o?e.globalScope[o]:void 0}Re([G],"sync"),Re([G],"async");let De=0;const Ze={isNumber:e=>W(e),isArray:e=>T(e),isImmutableArray:e=>F(e),isFeature:e=>M(e),isString:e=>q(e),isDictionary:e=>C(e),isGeometry:e=>I(e),geometryMember:(e,n,t,l,r=1)=>o(e,n,t,l,r),error(e){throw new a(null,e,null)},__awaiter:(e,n,t,o)=>new Promise(((t,l)=>{function r(e){try{s(o.next(e))}catch(n){l(n)}}function a(e){try{s(o.throw(e))}catch(n){l(n)}}function s(e){e.done?t(e.value):e.value?.then?e.value.then(r,a):(De++,De%100==0?setTimeout((()=>{De=0,r(e.value)}),0):r(e.value))}s((o=o.apply(e,n||[])).next())})),functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push({}),n.depthCounter.depth>64)throw new a(null,s.MaximumCallDepth,null);const t=e.apply(this,arguments);return D(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)},chkAssig(e,n){if(void 0===n.gdefs[e])throw new a(n,s.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new a(n,s.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>A(e),aCheck(e,n){if(f(e)){if("ArrayExpression"===n)throw new a(null,s.NoFunctionInArray,null);if("ObjectExpression"===n)throw new a(null,s.NoFunctionInDictionary,null);throw new a(null,s.NoFunctionInTemplateLiteral,null)}return e===S?null:e},Dictionary:r,Feature:u,UserDefinedCompiledFunction:V,dictionary(e){const n={},t=new Map;for(let l=0;l<e.length;l+=2){if(f(e[l+1]))throw new a(null,s.NoFunctionInDictionary,null);if(!1===q(e[l]))throw new a(null,s.KeyMustBeString,null);let o=e[l].toString();const r=o.toLowerCase();t.has(r)?o=t.get(r):t.set(r,o),e[l+1]===S?n[o]=null:n[o]=e[l+1]}const o=new r(n);return o.immutable=!1,o},strCheck(e){if(!1===q(e))throw new a(null,s.KeyMustBeString,null);return e},unary(e,n){if(z(e)){if("!"===n)return!e;if("-"===n)return-1*_(e);if("+"===n)return 1*_(e);if("~"===n)return~_(e);throw new a(null,s.UnsupportedUnaryOperator,null)}if("-"===n)return-1*_(e);if("+"===n)return 1*_(e);if("~"===n)return~_(e);throw new a(null,s.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===z(e))throw new a(null,s.LogicExpressionOrAnd,null);return e},logical(e,n,t){if(z(e)&&z(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new a(null,s.LogicExpressionOrAnd,null)}throw new a(null,s.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return k(_(e),_(n),t);case"==":case"=":return $(e,n);case"!=":return!$(e,n);case"<":case">":case"<=":case">=":return O(e,n,t);case"+":return q(e)||q(n)?A(e)+A(n):_(e)+_(n);case"-":return _(e)-_(n);case"*":return _(e)*_(n);case"/":return _(e)/_(n);case"%":return _(e)%_(n);default:throw new a(null,s.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===S?null:e;case"/=":return _(t)/_(e);case"*=":return _(t)*_(e);case"-=":return _(t)-_(e);case"+=":return q(t)||q(e)?A(t)+A(e):_(t)+_(e);case"%=":return _(t)%_(e);default:throw new a(null,s.UnsupportedOperator,null)}},update(e,n,t,o){const l=_(e[n]);return e[n]="++"===t?l+1:l-1,!1===o?l:"++"===t?l+1:l-1},graphicToFeature:(e,n,t)=>null===e?null:u.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,o){let l;if(T(e)){if(!W(n))throw new a(null,s.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new a(null,s.OutOfBounds,null);l=_(e[n]),e[n]="++"===t?l+1:l-1}else if(e instanceof r){if(!1===q(n))throw new a(null,s.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new a(null,s.FieldNotFound,null,{key:n});l=_(e.field(n)),e.setField(n,"++"===t?l+1:l-1)}else if(M(e)){if(!1===q(n))throw new a(null,s.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new a(null,s.FieldNotFound,null);l=_(e.field(n)),e.setField(n,"++"===t?l+1:l-1)}else{if(F(e))throw new a(null,s.Immutable,null);if(!(e instanceof Te))throw new a(null,s.InvalidIdentifier,null);if(!1===q(n))throw new a(null,s.ModuleAccessorMustBeString,null);if(!0!==e.hasGlobal(n))throw new a(null,s.ModuleExportNotFound,null);l=_(e.global(n)),e.setGlobal(n,"++"===t?l+1:l-1)}return!1===o?l:"++"===t?l+1:l-1},assignmember(e,n,t,o){if(T(e)){if(!W(n))throw new a(null,s.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new a(null,s.OutOfBounds,null);if(n===e.length){if("="!==t)throw new a(null,s.OutOfBounds,null);e[n]=this.assign(o,t,e[n])}else e[n]=this.assign(o,t,e[n])}else if(e instanceof r){if(!1===q(n))throw new a(null,s.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new a(null,s.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else if(M(e)){if(!1===q(n))throw new a(null,s.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new a(null,s.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else{if(F(e))throw new a(null,s.Immutable,null);if(!(e instanceof Te))throw new a(null,s.InvalidIdentifier,null);if(!1===q(n))throw new a(null,s.ModuleAccessorMustBeString,null);if(!e.hasGlobal(n))throw new a(null,s.ModuleExportNotFound,null);e.setGlobal(n,this.assign(o,t,e.global(n)))}},member(e,n){if(null===e)throw new a(null,s.MemberOfNull,null);if(e instanceof r||M(e)){if(q(n))return e.field(n);throw new a(null,s.InvalidMemberAccessKey,null)}if(e instanceof Z){if(q(n))return o(e,n,null,null);throw new a(null,s.InvalidMemberAccessKey,null)}if(T(e)){if(W(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new a(null,s.OutOfBounds,null);return e[n]}throw new a(null,s.InvalidMemberAccessKey,null)}if(q(e)){if(W(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new a(null,s.OutOfBounds,null);return e[n]}throw new a(null,s.InvalidMemberAccessKey,null)}if(F(e)){if(W(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new a(null,s.OutOfBounds,null);return e.get(n)}throw new a(null,s.InvalidMemberAccessKey,null)}if(e instanceof Te){if(q(n))return e.global(n);throw new a(null,s.InvalidMemberAccessKey,null)}throw new a(null,s.InvalidMemberAccessKey,null)},callfunc:(e,n,t)=>e.call(t,{arguments:n,preparsed:!0}),loadModule(e,n){const t=n.moduleFactoryMap[e];if(n.moduleSingletons[t])return n.moduleSingletons[t];const o=n.moduleFactory[t]({vars:{},moduleSingletons:n.moduleSingletons,depthCounter:n.depthCounter,console:n.console,abortSignal:n.abortSignal,isAsync:n.isAsync,services:n.services,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor},n.spatialReference);return n.moduleSingletons[t]=o,o},callModuleFunction(e,n,t,o){if(!(e instanceof Te))throw new a(null,s.FunctionNotFound,null);const l=e.global(t);if(!1===f(l))throw new a(null,s.CallNonFunction,null);return l.call(o,{preparsed:!0,arguments:n})},getNestedOptionalValue:(e,n)=>l(e,n)};function Ke(e){console.log(e)}function Pe(e,n,o=!1){null===n&&(n={vars:{},customfunctions:{}});let l=null;e.usesModules&&(l=new t(null,e.loadedModules));const r={isAsync:o,globalScope:Be(n.vars,o?ke:_e,n.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,customfunctions:n.customfunctions,libraryResolver:l,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},console:Ke,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor,services:n.services,symbols:{symbolCounter:0}};let c=ie(r,e);""===c&&(c="lc.voidOperation; "),r.undeclaredGlobalsInFunctions.size>0&&r.undeclaredGlobalsInFunctions.forEach((e=>{throw new i(n,s.InvalidIdentifier,e.node)}));let u="";u=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+c+"\n return lastStatement; }); } \n return this.postProcess(yield mainBody()); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+c+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const p=r.moduleFactory,m=r.moduleFactoryMap,g=r.exports,d={};let h;for(h in g)d[h]=r.mangleMap[h]??h;const F={lc:y,lang:Ze,mangles:r.mangleMap,postProcess(e){if(e instanceof b&&(e=e.value),e instanceof w&&(e=e.value),e===S&&(e=null),e===v)throw new a(null,s.IllegalResult,null);if(e===x)throw new a(null,s.IllegalResult,null);if(f(e))throw new a(null,s.IllegalResult,null);return e},prepare(e,n){let t=e.spatialReference;null==t&&(t=K.WebMercator);const o=je(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,moduleFactory:p,moduleFactoryMap:m,mangleMap:this.mangles,moduleSingletons:{},exports:g,gdefs:{},exportmangle:d,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??Ke,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:{depth:1}}}};return new Function("context","spatialReference",u).bind(F)}async function We(){return Re([await import("./functions/geomasync.js")],"async"),!0}class Te extends n{constructor(e){super(),this.moduleContext=e}hasGlobal(e){return void 0===this.moduleContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.moduleContext.exports[e]}setGlobal(e,n){const t=this.moduleContext.globalScope,o=e.toLowerCase();if(f(n))throw new a(null,s.AssignModuleFunction,null);t[this.moduleContext.exportmangle[o]]=n}global(e){const n=this.moduleContext.globalScope,t=e.toLowerCase(),o=n[this.moduleContext.exportmangle[t]];if(void 0===o)throw new a(null,s.InvalidIdentifier,null);if(f(o)&&!(o instanceof g)){const e=new g;return e.fn=o,e.parameterEvaluator=Y,e.context=this.moduleContext,n[this.moduleContext.exportmangle[t]]=e,e}return o}}function qe(e,n,o=!1){const l={isAsync:o,moduleFactory:n.moduleFactory,moduleFactoryMap:{},libraryResolver:new t(null,e.loadedModules),globalScope:Be(n.vars,o?ke:_e,n.customfunctions),customfunctions:n.customfunctions,localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},console:Ke,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor,services:n.services,symbols:{symbolCounter:0}};let r=ie(l,e);""===r&&(r="lc.voidOperation; ");let a="";a=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+r+"\n return lastStatement; }); } \n yield mainBody(); \n return this.prepareModule(runtimeCtx); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+r+"\n return lastStatement; } \n mainBody(); \n return this.prepareModule(runtimeCtx); ";const s=l.moduleFactory,i=l.moduleFactoryMap,c=l.exports,u={};let p;for(p in c)u[p]=l.mangleMap[p]??p;const m={lc:y,lang:Ze,mangles:l.mangleMap,prepareModule:e=>new Te(e),prepare(e,n){let t=e.spatialReference;null==t&&(t=new K({wkid:102100}));const o=je(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,exports:c,exportmangle:u,gdefs:{},moduleFactory:s,moduleFactoryMap:i,moduleSingletons:e.moduleSingletons,mangleMap:this.mangles,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??Ke,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:e.depthCounter}}};return new Function("context","spatialReference",a).bind(m)}export{V as UserDefinedCompiledFunction,Pe as compileScript,We as enableAsyncSupport,Le as executeScript,Re as extend,Ne as functionHelper};
5
+ import{toSymbolId as e}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import{getGeometryKeys as o,geometryMember as l,getNestedOptionalValue as r}from"./containerUtils.js";import a from"./Dictionary.js";import{ArcadeExecutionError as s,ExecutionErrorCodes as i,ArcadeCompilationError as c,ArcadeUncompilableError as u}from"./executionError.js";import p from"./Feature.js";import{NativeFunction as m,ArcadeFunction as g,ScopeMarshalledFunction as d,wrapModuleScopedResponse as f}from"./FunctionWrapper.js";import{i as h,s as y,u as b,R as S,I as w,v,w as x,x as F,m as M,n as $,q as C,l as I,f as A,d as _,y as O,z as k,A as G}from"../chunks/languageUtils.js";import{addFunctionDeclaration as E}from"./treeAnalysis.js";import{A as j}from"../chunks/array.js";import{registerFunctions as B}from"./functions/date.js";import{registerFunctions as N}from"./functions/geometry.js";import{registerFunctions as R}from"./functions/geomsync.js";import{registerFunctions as D}from"./functions/maths.js";import{registerFunctions as L}from"./functions/stats.js";import{registerFunctions as U}from"./functions/string.js";import{isPromiseLike as K}from"../core/promiseUtils.js";import Z from"../geometry/Geometry.js";import P from"../geometry/SpatialReference.js";import{isGraphic as W,isNumber as T,isArray as V,isString as q,isBoolean as z}from"../support/guards.js";class J extends g{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new s(e,i.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,o){return o(e,n,((n,l,r)=>{r=r.map((n=>!h(n)||n instanceof d?n:f(n,e,o)));const a=this.call(t,{arguments:r});return K(a)?a.then((e=>f(e,t,o))):a}))}}function Y(e,n){const t=[];for(let o=0;o<n.arguments.length;o++)t.push(Q(e,n.arguments[o]));return t}function H(e,n,t){try{return t(e,null,n.arguments)}catch(o){throw o}}function Q(e,n){switch(n.type){case"AssignmentExpression":return ce(e,n);case"UpdateExpression":return se(e,n);case"TemplateLiteral":return Me(e,n);case"Identifier":return Ie(e,n);case"MemberExpression":return ve(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return Ae(e,n);case"UnaryExpression":return xe(e,n);case"BinaryExpression":return $e(e,n);case"LogicalExpression":return Ce(e,n);case"ArrayExpression":return Fe(e,n);case"ObjectExpression":return ee(e,n);default:throw new c(e,i.Unrecognized,n)}}function X(e,n){switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclaration":return Se(e,n);case"BlockStatement":return ge(e,n);case"FunctionDeclaration":return be(e,n);case"ImportDeclaration":return fe(e,n);case"ExportNamedDeclaration":return he(e,n);case"ReturnStatement":return de(e,n);case"IfStatement":return me(e,n);case"ExpressionStatement":return ue(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"ForStatement":return ae(e,n);case"ForInStatement":return le(e,n);case"ForOfStatement":return re(e,n);case"WhileStatement":return ie(e,n);default:throw new c(e,i.Unrecognized,n)}}function ee(e,n){let t="lang.dictionary([";for(let o=0;o<n.properties.length;o++){const l=n.properties[o];let r;"Identifier"===l.key.type?(ye(l.key.name),r="'"+l.key.name+"'"):r=Q(e,l.key);o>0&&(t+=","),t+="lang.strCheck("+r+",'ObjectExpression'),lang.aCheck("+Q(e,l.value)+", 'ObjectExpression')"}return t+="])",t}function ne(e,n,t,o,l=(e,n)=>`${e} = ${n}`){const r=Be(e),a=Be(e);return[`var ${r} = ${t};`,`for (var ${a} = 0; ${a} < ${r}; ${a}++) {`,` ${l(n,a)}`,` ${X(e,o)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function te(e,n,t,o,l=e=>e){const r=Be(e),a=Be(e);return[`var ${r} = ${t};`,`for (var ${a} of ${r}) {`,` ${n} = ${l(a)};`,` ${X(e,o)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function oe(e,n,t,o){const l=Be(e);return[`var ${l} = ${t}.iterator(runtimeCtx.abortSignal);`,`while ((${n} = lang.graphicToFeature(yield ${l}.next(), ${t}, runtimeCtx)) != null) {`,` ${X(e,o)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function le(n,t){const o=Be(n);let l="var "+o+" = "+Q(n,t.right)+";\n";"VariableDeclaration"===t.left.type&&(l+=X(n,t.left));const r=e("VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);ye(r);let a="";null!==n.localScope&&(void 0!==n.localScope[r]?a="lscope['"+r+"']":void 0!==n.localScope._SymbolsMap[r]&&(a="lscope['"+n.localScope._SymbolsMap[r]+"']"));let s="";if(""===a)if(void 0!==n.globalScope[r])a="gscope['"+r+"']";else if(void 0!==n.globalScope._SymbolsMap[r])a="gscope['"+n.globalScope._SymbolsMap[r]+"']";else if(null!==n.localScope)if(n.undeclaredGlobalsInFunctions.has(r))a="gscope['"+n.undeclaredGlobalsInFunctions.get(r).manglename+"']",s=n.undeclaredGlobalsInFunctions.get(r).manglename;else{const e={manglename:je(n),node:t.left};n.undeclaredGlobalsInFunctions.set(r,e),a="gscope['"+e.manglename+"']",s=e.manglename}return s&&(l+="lang.chkAssig('"+s+"',runtimeCtx); \n"),l+="if ("+o+"===null) { lastStatement = lc.voidOperation; }\n ",l+="else if (lc.isArray("+o+") || lc.isString("+o+")) {\n",l+=ne(n,a,`${o}.length`,t.body),l+="}\n",l+="else if (lc.isImmutableArray("+o+")) {\n",l+=ne(n,a,`${o}.length()`,t.body),l+="}\n",l+="else if (( "+o+" instanceof lang.Dictionary) || lc.isFeature("+o+")) {\n",l+=te(n,a,`${o}.keys()`,t.body),l+="}\n",n.isAsync&&(l+="else if (lc.isFeatureSet("+o+")) {\n",l+=oe(n,a,o,t.body),l+="}\n"),l+=`else if (lc.isGeometry(${o})) {\n`,l+=te(n,a,`lang.getGeometryKeys(${o})`,t.body),l+="}\n",l+="else { lastStatement = lc.voidOperation; } \n",l}function re(n,t){const o=Be(n);let l="var "+o+" = "+Q(n,t.right)+";\n";"VariableDeclaration"===t.left.type&&(l+=X(n,t.left));const r=e("VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);ye(r);let a="";null!==n.localScope&&(void 0!==n.localScope[r]?a="lscope['"+r+"']":void 0!==n.localScope._SymbolsMap[r]&&(a="lscope['"+n.localScope._SymbolsMap[r]+"']"));let s="";if(""===a)if(void 0!==n.globalScope[r])a="gscope['"+r+"']";else if(void 0!==n.globalScope._SymbolsMap[r])a="gscope['"+n.globalScope._SymbolsMap[r]+"']";else if(null!==n.localScope)if(n.undeclaredGlobalsInFunctions.has(r))a="gscope['"+n.undeclaredGlobalsInFunctions.get(r).manglename+"']",s=n.undeclaredGlobalsInFunctions.get(r).manglename;else{const e={manglename:je(n),node:t.left};n.undeclaredGlobalsInFunctions.set(r,e),a="gscope['"+e.manglename+"']",s=e.manglename}return s&&(l+="lang.chkAssig('"+s+"',runtimeCtx); \n"),l+="if ("+o+"===null) { lastStatement = lc.voidOperation; }\n ",l+="else if (lc.isArray("+o+") || lc.isString("+o+")) {\n",l+=ne(n,a,`${o}.length`,t.body,((e,n)=>[`if (${n} >= ${o}.length) {`,` lang.error('${i.OutOfBounds}');`,"}",`${e} = ${o}[${n}];`].join("\n"))),l+="}\n",l+="else if (lc.isImmutableArray("+o+")) {\n",l+=ne(n,a,`${o}.length()`,t.body,((e,n)=>`${e} = ${o}.get(${n});`)),l+="}\n",l+="else if (( "+o+" instanceof lang.Dictionary) || lc.isFeature("+o+")) {\n",l+=te(n,a,`${o}.keys()`,t.body,(e=>`lang.entry(${e}, ${o}.field(${e}))`)),l+="}\n",n.isAsync&&(l+="else if (lc.isFeatureSet("+o+")) {\n",l+=oe(n,a,o,t.body),l+="}\n"),l+=`else if (lc.isGeometry(${o})) {\n`,l+=te(n,a,`lang.getGeometryKeys(${o})`,t.body,(e=>`lang.entry(${e}, lang.geometryMember(${o}, ${e}, runtimeCtx, null, 1))`)),l+="}\n",l+="else { lastStatement = lc.voidOperation; } \n",l}function ae(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&("VariableDeclaration"===n.init.type?t+=X(e,n.init):t+=Q(e,n.init)+"; ");const o=Be(e),l=Be(e);return t+="var "+o+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+o+"===false) {\n "+Q(e,n.update)+" \n}\n "+o+"=false; \n"),null!==n.test&&(t+="var "+l+" = "+Q(e,n.test)+"; ",t+="if ("+l+"===false) { break; } else if ("+l+"!==true) { lang.error('"+i.BooleanConditionRequired+"'); }\n"),t+=X(e,n.body),null!==n.update&&(t+="\n "+Q(e,n.update)),t+="\n"+o+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function se(n,t){if("CallExpression"===t.argument.type)throw new c(n,i.NeverReach,t);let o;if("MemberExpression"===t.argument.type){const e=Q(n,t.argument.object);return!0===t.argument.computed?o=Q(n,t.argument.property):(ye(t.argument.property.name),o="'"+t.argument.property.name+"'"),"lang.memberupdate("+e+","+o+",'"+t.operator+"',"+t.prefix+")"}const l=e(t.argument);if(ye(l),null!==n.localScope){if(void 0!==n.localScope[l])return"lang.update(lscope, '"+l+"','"+t.operator+"',"+t.prefix+")";if(void 0!==n.localScope._SymbolsMap[l])return"lang.update(lscope, '"+n.localScope._SymbolsMap[l]+"','"+t.operator+"',"+t.prefix+")"}if(void 0!==n.globalScope[l])return"lang.update(gscope, '"+l+"','"+t.operator+"',"+t.prefix+")";if(void 0!==n.globalScope._SymbolsMap[l])return"lang.update(gscope, '"+n.globalScope._SymbolsMap[l]+"','"+t.operator+"',"+t.prefix+")";if(null!==n.localScope){if(n.undeclaredGlobalsInFunctions.has(l))return"lang.update(gscope,lang.chkAssig( '"+n.undeclaredGlobalsInFunctions.get(l).manglename+"',runtimeCtx),'"+t.operator+"',"+t.prefix+")";const e={manglename:je(n),node:t.argument};return n.undeclaredGlobalsInFunctions.set(l,e),"lang.update(gscope, lang.chkAssig('"+e.manglename+"',runtimeCtx),'"+t.operator+"',"+t.prefix+")"}throw new s(n,i.InvalidIdentifier,t)}function ie(e,n){let t="lastStatement = lc.voidOperation; \n";const o=Be(e);return t+=`\n var ${o} = true;\n do {\n ${o} = ${Q(e,n.test)};\n if (${o}==false) {\n break;\n }\n if (${o}!==true) {\n lang.error('${i.BooleanConditionRequired}');\n }\n ${X(e,n.body)}\n }\n while (${o} !== false);\n lastStatement = lc.voidOperation;\n `,t}function ce(n,t){const o=Q(n,t.right);if("MemberExpression"===t.left.type){let e;const l=Q(n,t.left.object);return!0===t.left.computed?e=Q(n,t.left.property):(e="'"+t.left.property.name+"'",ye(t.left.property.name)),"lang.assignmember("+l+","+e+",'"+t.operator+"',"+o+")"}const l=e(t.left);if(ye(l),null!==n.localScope){if(void 0!==n.localScope[l])return"lscope['"+l+"']=lang.assign("+o+",'"+t.operator+"', lscope['"+l+"'])";if(void 0!==n.localScope._SymbolsMap[l])return"lscope['"+n.localScope._SymbolsMap[l]+"']=lang.assign("+o+",'"+t.operator+"', lscope['"+n.localScope._SymbolsMap[l]+"'])"}if(void 0!==n.globalScope[l])return"gscope['"+l+"']=lang.assign("+o+",'"+t.operator+"', gscope['"+l+"'])";if(void 0!==n.globalScope._SymbolsMap[l])return"gscope['"+n.globalScope._SymbolsMap[l]+"']=lang.assign("+o+",'"+t.operator+"', gscope['"+n.globalScope._SymbolsMap[l]+"'])";if(null!==n.localScope){if(n.undeclaredGlobalsInFunctions.has(l))return"gscope[lang.chkAssig('"+n.undeclaredGlobalsInFunctions.get(l).manglename+"',runtimeCtx)]=lang.assign("+o+",'"+t.operator+"', gscope['"+n.undeclaredGlobalsInFunctions.get(l).manglename+"'])";const e={manglename:je(n),node:t.left};return n.undeclaredGlobalsInFunctions.set(l,e),"gscope[lang.chkAssig('"+e.manglename+"',runtimeCtx)]=lang.assign("+o+",'"+t.operator+"', gscope['"+e.manglename+"'])"}throw new s(n,i.InvalidIdentifier,t)}function ue(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+Q(e,n.expression)+"; \n ":"lastStatement = "+Q(e,n.expression)+"; "}function pe(e,n){return"BlockStatement"===n.type?X(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?X(e,n)+"; ":"ExpressionStatement"===n.type?X(e,n):X(e,n)+"; "}function me(e,n){return`if (lang.mustBoolean(${Q(e,n.test)}, runtimeCtx) === true) {\n ${pe(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+me(e,n.alternate):` else {\n ${pe(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function ge(e,n){let t="";for(let o=0;o<n.body.length;o++)"EmptyStatement"!==n.body[o].type&&("ReturnStatement"===n.body[o].type||"BreakStatement"===n.body[o].type||"ContinueStatement"===n.body[o].type?t+=X(e,n.body[o])+"; \n":t+=X(e,n.body[o])+" \n");return t}function de(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+Q(e,n.argument)}function fe(n,t){const o=e(t.specifiers[0].local);ye(o);const l=n.libraryResolver?.loadLibrary(o),r=je(n);void 0===n.moduleFactory[l.uri]&&(n.moduleFactory[l.uri]=He(l.syntax,{interceptor:n.interceptor,services:n.services,moduleFactory:n.moduleFactory,lrucache:n.lrucache,timeZone:n.timeZone??null,libraryResolver:n.libraryResolver,customfunctions:n.customfunctions,vars:{}},n.isAsync)),n.moduleFactoryMap[r]=l.uri;let a,s="";return s=n.isAsync?"(yield lang.loadModule('"+r+"', runtimeCtx) ); ":"lang.loadModule('"+r+"', runtimeCtx); ",void 0!==n.globalScope[o]?"gscope['"+o+"']="+s:void 0!==n.globalScope._SymbolsMap[o]?"gscope['"+n.globalScope._SymbolsMap[o]+"']="+s:(n.undeclaredGlobalsInFunctions.has(o)?(a=n.undeclaredGlobalsInFunctions.get(o).manglename,n.undeclaredGlobalsInFunctions.delete(o)):a=je(n),n.globalScope._SymbolsMap[o]=a,n.mangleMap[o]=a,"gscope[lang.setAssig('"+a+"', runtimeCtx)]="+s)}function he(n,t){const o=X(n,t.declaration);if("FunctionDeclaration"===t.declaration.type)n.exports[e(t.declaration.id)]="function";else if("VariableDeclaration"===t.declaration.type)for(const l of t.declaration.declarations)n.exports[e(l.id)]="variable";return o}function ye(e){if("iif"===e)throw new u;if("decode"===e)throw new u;if("when"===e)throw new u;if("defaultvalue"===e)throw new u}function be(n,t){const o=e(t.id);let l;ye(o);let r=!1;void 0!==n.globalScope[o]?l=o:void 0!==n.globalScope._SymbolsMap[o]?l=n.globalScope._SymbolsMap[o]:n.undeclaredGlobalsInFunctions.has(o)?(l=n.undeclaredGlobalsInFunctions.get(o).manglename,n.globalScope._SymbolsMap[o]=l,n.mangleMap[o]=l,n.undeclaredGlobalsInFunctions.delete(o),r=!0):(l=je(n),n.globalScope._SymbolsMap[o]=l,n.mangleMap[o]=l);const a={isAsync:n.isAsync,console:n.console,exports:n.exports,undeclaredGlobalsInFunctions:n.undeclaredGlobalsInFunctions,customfunctions:n.customfunctions,moduleFactory:n.moduleFactory,moduleFactoryMap:n.moduleFactoryMap,libraryResolver:n.libraryResolver,lrucache:n.lrucache,interceptor:n.interceptor,services:n.services,symbols:n.symbols,mangleMap:n.mangleMap,localScope:{_SymbolsMap:{}},depthCounter:n.depthCounter,globalScope:n.globalScope};let s="new lang.UserDefinedCompiledFunction( lang.functionDepthchecker(function() { var lastStatement = lc.voidOperation; \n var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];\n";for(let i=0;i<t.params.length;i++){const o=e(t.params[i]);ye(o);const l=je(n);a.localScope._SymbolsMap[o]=l,a.mangleMap[o]=l,s+="lscope['"+l+"']=arguments["+i.toString()+"];\n"}return!0===n.isAsync?(s+="return lang.__awaiter(this, void 0, void 0, function* () {\n",s+=ge(a,t.body)+"\n return lastStatement; ",s+="}); }",s+=", runtimeCtx),"+t.params.length+")",s+="\n lastStatement = lc.voidOperation; \n"):(s+=ge(a,t.body)+"\n return lastStatement; }, runtimeCtx),"+t.params.length+")",s+="\n lastStatement = lc.voidOperation; \n"),r?"gscope[lang.setAssig('"+l+"', runtimeCtx)]="+s:"gscope['"+l+"']="+s}function Se(e,n){const t=[];for(let o=0;o<n.declarations.length;o++)t.push(we(e,n.declarations[o]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function we(n,t){const o=null===t.init?null:Q(n,t.init),l=e(t.id);if(ye(l),null!==n.localScope){if(void 0!==n.localScope[l])return"lscope['"+l+"']="+o+"; ";if(void 0!==n.localScope._SymbolsMap[l])return"lscope['"+n.localScope._SymbolsMap[l]+"']="+o+"; ";const e=je(n);return n.localScope._SymbolsMap[l]=e,n.mangleMap[l]=e,"lscope['"+e+"']="+o+"; "}if(void 0!==n.globalScope[l])return"gscope['"+l+"']="+o+"; ";if(void 0!==n.globalScope._SymbolsMap[l])return"gscope['"+n.globalScope._SymbolsMap[l]+"']="+o+"; ";if(n.undeclaredGlobalsInFunctions.has(l)){const e=n.undeclaredGlobalsInFunctions.get(l).manglename;return n.globalScope._SymbolsMap[l]=e,n.mangleMap[l]=e,n.undeclaredGlobalsInFunctions.delete(l),"gscope[lang.setAssig('"+e+"', runtimeCtx)]="+o+"; "}const r=je(n);return n.globalScope._SymbolsMap[l]=r,n.mangleMap[l]=r,"gscope['"+r+"']="+o+"; "}function ve(e,n){try{let t;return!0===n.computed?t=Q(e,n.property):(ye(n.property.name),t="'"+n.property.name+"'"),"lang.member("+Q(e,n.object)+","+t+")"}catch(t){throw t}}function xe(e,n){try{return"lang.unary("+Q(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function Fe(e,n){try{const t=[];for(let o=0;o<n.elements.length;o++)"Literal"===n.elements[o].type?t.push(Q(e,n.elements[o])):t.push("lang.aCheck("+Q(e,n.elements[o])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function Me(e,n){try{const t=[];let o=0;for(const l of n.quasis)t.push(l.value?JSON.stringify(l.value.cooked):JSON.stringify("")),!1===l.tail&&(t.push(n.expressions[o]?"lang.castString(lang.aCheck("+Q(e,n.expressions[o])+", 'TemplateLiteral'))":""),o++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function $e(e,n){try{return"lang.binary("+Q(e,n.left)+","+Q(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function Ce(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new c(e,i.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new c(e,i.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+Q(e,n.left)+") "+n.operator+" lang.logicalCheck("+Q(e,n.right)+"))";throw new c(null,i.LogicExpressionOrAnd,null)}catch(t){throw t}}function Ie(n,t){try{const o=e(t);if(ye(o),null!==n.localScope){if(void 0!==n.localScope[o])return"lscope['"+o+"']";if(void 0!==n.localScope._SymbolsMap[o])return"lscope['"+n.localScope._SymbolsMap[o]+"']"}if(void 0!==n.globalScope[o])return"gscope['"+o+"']";if(void 0!==n.globalScope._SymbolsMap[o])return"gscope['"+n.globalScope._SymbolsMap[o]+"']";if(null!==n.localScope){if(n.undeclaredGlobalsInFunctions.has(o))return"gscope[lang.chkAssig('"+n.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx)]";const e={manglename:je(n),node:t};return n.undeclaredGlobalsInFunctions.set(o,e),"gscope[lang.chkAssig('"+e.manglename+"',runtimeCtx)]"}throw new c(n,i.InvalidIdentifier,t)}catch(o){throw o}}function Ae(n,t){try{if("MemberExpression"===t.callee.type){let e;!0===t.callee.computed?e=Q(n,t.callee.property):(ye(t.callee.property.name),e="'"+t.callee.property.name+"'");let o="[";for(let l=0;l<t.arguments.length;l++)l>0&&(o+=", "),o+=Q(n,t.arguments[l]);return o+="]",n.isAsync?"(yield lang.callModuleFunction("+Q(n,t.callee.object)+","+o+","+e+",runtimeCtx))":"lang.callModuleFunction("+Q(n,t.callee.object)+","+o+","+e+",runtimeCtx)"}if("Identifier"!==t.callee.type)throw new c(n,i.FunctionNotFound,t);const o=e(t.callee);if("iif"===o)return _e(n,t);if("when"===o)return ke(n,t);if("defaultvalue"===o)return Oe(n,t);if("decode"===o)return Ge(n,t);let l="";if(null!==n.localScope&&(void 0!==n.localScope[o]?l="lscope['"+o+"']":void 0!==n.localScope._SymbolsMap[o]&&(l="lscope['"+n.localScope._SymbolsMap[o]+"']")),""===l)if(void 0!==n.globalScope[o])l="gscope['"+o+"']";else if(void 0!==n.globalScope._SymbolsMap[o])l="gscope['"+n.globalScope._SymbolsMap[o]+"']";else if(null!==n.localScope)if(n.undeclaredGlobalsInFunctions.has(o))l="gscope[lang.chkAssig('"+n.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx)]";else{const e={manglename:je(n),node:t.callee};n.undeclaredGlobalsInFunctions.set(o,e),l="gscope[lang.chkAssig('"+e.manglename+"',runtimeCtx)]"}if(""!==l){let e="[";for(let o=0;o<t.arguments.length;o++)o>0&&(e+=", "),e+=Q(n,t.arguments[o]);return e+="]",n.isAsync?"(yield lang.callfunc("+l+","+e+",runtimeCtx) )":"lang.callfunc("+l+","+e+",runtimeCtx)"}throw new c(n,i.FunctionNotFound,t)}catch(o){throw o}}function _e(e,n){try{if(3!==n.arguments.length)throw new c(e,i.WrongNumberOfParameters,n);const t=Be(e);return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${Q(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${Q(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${Q(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Oe(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new c(e,i.WrongNumberOfParameters,n);const t=Be(e),o=Be(e);return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${Q(e,n.arguments[0])};\n var ${o} = ${Q(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${o});\n return ${t} != null && ${t} !== "" ? ${t} : ${Q(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} = ${Q(e,n.arguments[0])};\n if (${t} === null) {\n return ${Q(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${Q(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${Q(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 c(e,i.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new c(e,i.WrongNumberOfParameters,n);const t=Be(e);let o="var ";for(let l=0;l<n.arguments.length-1;l+=2)o+=`${t} = lang.mustBoolean(${Q(e,n.arguments[l])}, runtimeCtx);\n if (${t} === true ) {\n return ${Q(e,n.arguments[l+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${o}\n return ${Q(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ge(e,n){try{if(n.arguments.length<2)throw new c(e,i.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${Q(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new c(e,i.WrongNumberOfParameters,n);const t=Be(e),o=Be(e);let l="var ";for(let r=1;r<n.arguments.length-1;r+=2)l+=`${o} = ${Q(e,n.arguments[r])};\n if (lang.binary(${o}, ${t}, "==") === true ) {\n return ${Q(e,n.arguments[r+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${Q(e,n.arguments[0])};\n ${l}\n return ${Q(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const Ee={};function je(e){return e.symbols.symbolCounter++,`_T${e.symbols.symbolCounter}`}function Be(e){return e.symbols.symbolCounter++,`_Tvar${e.symbols.symbolCounter}`}B(Ee,H),U(Ee,H),D(Ee,H),N(Ee,H),L(Ee,H),Ee.iif=function(e,n){try{return H(e,n,((t,o,l)=>{throw new s(e,i.Unrecognized,n)}))}catch(t){throw t}},Ee.decode=function(e,n){try{return H(e,n,((t,o,l)=>{throw new s(e,i.Unrecognized,n)}))}catch(t){throw t}},Ee.when=function(e,n){try{return H(e,n,((t,o,l)=>{throw new s(e,i.Unrecognized,n)}))}catch(t){throw t}},Ee.defaultvalue=function(e,n){try{return H(e,n,((t,o,l)=>{throw new s(e,i.Unrecognized,n)}))}catch(t){throw t}};const Ne={};for(const Qe in Ee)Ne[Qe]=new m(Ee[Qe]);R(Ee,H);for(const Qe in Ee)Ee[Qe]=new m(Ee[Qe]);const Re=function(){};Re.prototype=Ee;const De=function(){};function Le(e,n,t){const o={_SymbolsMap:{}};e||(e={}),t||(t={}),o.textformatting=1,o.infinity=1,o.pi=1;for(const l in n)o[l]=1;for(const l in t)o[l]=1;for(const l in e)o[l]=1;return o}function Ue(e,n,t,o){const l=t?new De:new Re;e||(e={}),n||(n={});const r=new a({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});r.immutable=!1,l._SymbolsMap={textformatting:1,infinity:1,pi:1},l.textformatting=r,l.infinity=Number.POSITIVE_INFINITY,l.pi=Math.PI;for(const a in n)l[a]=n[a],l._SymbolsMap[a]=1;for(const a in e){const n=e[a];l._SymbolsMap[a]=1,W(n)?l[a]=p.createFromGraphic(n,o??null):l[a]=n}return l}De.prototype=Ne;const Ke={fixSpatialReference:y,parseArguments:Y,standardFunction:H};function Ze(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:H,standardFunctionAsync:H,evaluateIdentifier:We};for(let o=0;o<e.length;o++)e[o].registerFunctions(t);if("sync"===n){for(const e in t.functions)Ee[e]=new m(t.functions[e]),Re.prototype[e]=Ee[e];for(let e=0;e<t.signatures.length;e++)E(t.signatures[e],"sync")}else{for(const e in t.functions)Ne[e]=new m(t.functions[e]),De.prototype[e]=Ne[e];for(let e=0;e<t.signatures.length;e++)E(t.signatures[e],"async")}}function Pe(e,n){return e(n)}function We(e,n){const t=n.name;if("_SymbolsMap"===t)throw new s(e,i.InvalidIdentifier,null);if(e.localStack.length>0){const n=e.localStack[e.localStack.length-1];if(!t.toLowerCase().startsWith("_t")&&void 0!==n[t])return n[t];const o=e.mangleMap[t];if(void 0!==o&&void 0!==n[o])return n[o]}if(!t.toLowerCase().startsWith("_t")&&void 0!==e.globalScope[t])return e.globalScope[t];if(1===e.globalScope._SymbolsMap[t])return e.globalScope[t];const o=e.mangleMap[t];return void 0!==o?e.globalScope[o]:void 0}Ze([j],"sync"),Ze([j],"async");let Te=0;const Ve={isNumber:e=>T(e),isArray:e=>V(e),isImmutableArray:e=>M(e),isFeature:e=>$(e),isString:e=>q(e),isDictionary:e=>C(e),isGeometry:e=>I(e),getGeometryKeys:e=>o(e),geometryMember:(e,n,t,o,r=1)=>l(e,n,t,o,r),error(e){throw new s(null,e,null)},__awaiter:(e,n,t,o)=>new Promise(((t,l)=>{function r(e){try{s(o.next(e))}catch(n){l(n)}}function a(e){try{s(o.throw(e))}catch(n){l(n)}}function s(e){e.done?t(e.value):e.value?.then?e.value.then(r,a):(Te++,Te%100==0?setTimeout((()=>{Te=0,r(e.value)}),0):r(e.value))}s((o=o.apply(e,n||[])).next())})),functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push({}),n.depthCounter.depth>64)throw new s(null,i.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)},chkAssig(e,n){if(void 0===n.gdefs[e])throw new s(n,i.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new s(n,i.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>A(e),aCheck(e,n){if(h(e)){if("ArrayExpression"===n)throw new s(null,i.NoFunctionInArray,null);if("ObjectExpression"===n)throw new s(null,i.NoFunctionInDictionary,null);throw new s(null,i.NoFunctionInTemplateLiteral,null)}return e===v?null:e},Dictionary:a,Feature:p,UserDefinedCompiledFunction:J,dictionary(e){const n={},t=new Map;for(let l=0;l<e.length;l+=2){if(h(e[l+1]))throw new s(null,i.NoFunctionInDictionary,null);if(!1===q(e[l]))throw new s(null,i.KeyMustBeString,null);let o=e[l].toString();const r=o.toLowerCase();t.has(r)?o=t.get(r):t.set(r,o),e[l+1]===v?n[o]=null:n[o]=e[l+1]}const o=new a(n);return o.immutable=!1,o},entry:(e,n)=>new a({key:e,value:n}),strCheck(e){if(!1===q(e))throw new s(null,i.KeyMustBeString,null);return e},unary(e,n){if(z(e)){if("!"===n)return!e;if("-"===n)return-1*_(e);if("+"===n)return 1*_(e);if("~"===n)return~_(e);throw new s(null,i.UnsupportedUnaryOperator,null)}if("-"===n)return-1*_(e);if("+"===n)return 1*_(e);if("~"===n)return~_(e);throw new s(null,i.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===z(e))throw new s(null,i.LogicExpressionOrAnd,null);return e},logical(e,n,t){if(z(e)&&z(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new s(null,i.LogicExpressionOrAnd,null)}throw new s(null,i.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return G(_(e),_(n),t);case"==":case"=":return k(e,n);case"!=":return!k(e,n);case"<":case">":case"<=":case">=":return O(e,n,t);case"+":return q(e)||q(n)?A(e)+A(n):_(e)+_(n);case"-":return _(e)-_(n);case"*":return _(e)*_(n);case"/":return _(e)/_(n);case"%":return _(e)%_(n);default:throw new s(null,i.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===v?null:e;case"/=":return _(t)/_(e);case"*=":return _(t)*_(e);case"-=":return _(t)-_(e);case"+=":return q(t)||q(e)?A(t)+A(e):_(t)+_(e);case"%=":return _(t)%_(e);default:throw new s(null,i.UnsupportedOperator,null)}},update(e,n,t,o){const l=_(e[n]);return e[n]="++"===t?l+1:l-1,!1===o?l:"++"===t?l+1:l-1},graphicToFeature:(e,n,t)=>null===e?null:p.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,o){let l;if(V(e)){if(!T(n))throw new s(null,i.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new s(null,i.OutOfBounds,null);l=_(e[n]),e[n]="++"===t?l+1:l-1}else if(e instanceof a){if(!1===q(n))throw new s(null,i.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new s(null,i.FieldNotFound,null,{key:n});l=_(e.field(n)),e.setField(n,"++"===t?l+1:l-1)}else if($(e)){if(!1===q(n))throw new s(null,i.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new s(null,i.FieldNotFound,null);l=_(e.field(n)),e.setField(n,"++"===t?l+1:l-1)}else{if(M(e))throw new s(null,i.Immutable,null);if(!(e instanceof Ye))throw new s(null,i.InvalidIdentifier,null);if(!1===q(n))throw new s(null,i.ModuleAccessorMustBeString,null);if(!0!==e.hasGlobal(n))throw new s(null,i.ModuleExportNotFound,null);l=_(e.global(n)),e.setGlobal(n,"++"===t?l+1:l-1)}return!1===o?l:"++"===t?l+1:l-1},assignmember(e,n,t,o){if(V(e)){if(!T(n))throw new s(null,i.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new s(null,i.OutOfBounds,null);if(n===e.length){if("="!==t)throw new s(null,i.OutOfBounds,null);e[n]=this.assign(o,t,e[n])}else e[n]=this.assign(o,t,e[n])}else if(e instanceof a){if(!1===q(n))throw new s(null,i.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new s(null,i.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else if($(e)){if(!1===q(n))throw new s(null,i.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new s(null,i.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else{if(M(e))throw new s(null,i.Immutable,null);if(!(e instanceof Ye))throw new s(null,i.InvalidIdentifier,null);if(!1===q(n))throw new s(null,i.ModuleAccessorMustBeString,null);if(!e.hasGlobal(n))throw new s(null,i.ModuleExportNotFound,null);e.setGlobal(n,this.assign(o,t,e.global(n)))}},member(e,n){if(null===e)throw new s(null,i.MemberOfNull,null);if(e instanceof a||$(e)){if(q(n))return e.field(n);throw new s(null,i.InvalidMemberAccessKey,null)}if(e instanceof Z){if(q(n))return l(e,n,null,null);throw new s(null,i.InvalidMemberAccessKey,null)}if(V(e)){if(T(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new s(null,i.OutOfBounds,null);return e[n]}throw new s(null,i.InvalidMemberAccessKey,null)}if(q(e)){if(T(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new s(null,i.OutOfBounds,null);return e[n]}throw new s(null,i.InvalidMemberAccessKey,null)}if(M(e)){if(T(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new s(null,i.OutOfBounds,null);return e.get(n)}throw new s(null,i.InvalidMemberAccessKey,null)}if(e instanceof Ye){if(q(n))return e.global(n);throw new s(null,i.InvalidMemberAccessKey,null)}throw new s(null,i.InvalidMemberAccessKey,null)},callfunc:(e,n,t)=>e.call(t,{arguments:n,preparsed:!0}),loadModule(e,n){const t=n.moduleFactoryMap[e];if(n.moduleSingletons[t])return n.moduleSingletons[t];const o=n.moduleFactory[t]({vars:{},moduleSingletons:n.moduleSingletons,depthCounter:n.depthCounter,console:n.console,abortSignal:n.abortSignal,isAsync:n.isAsync,services:n.services,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor},n.spatialReference);return n.moduleSingletons[t]=o,o},callModuleFunction(e,n,t,o){if(!(e instanceof Ye))throw new s(null,i.FunctionNotFound,null);const l=e.global(t);if(!1===h(l))throw new s(null,i.CallNonFunction,null);return l.call(o,{preparsed:!0,arguments:n})},getNestedOptionalValue:(e,n)=>r(e,n)};function qe(e){console.log(e)}function ze(e,n,o=!1){null===n&&(n={vars:{},customfunctions:{}});let l=null;e.usesModules&&(l=new t(null,e.loadedModules));const r={isAsync:o,globalScope:Le(n.vars,o?Ne:Ee,n.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,customfunctions:n.customfunctions,libraryResolver:l,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},console:qe,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor,services:n.services,symbols:{symbolCounter:0}};let a=ge(r,e);""===a&&(a="lc.voidOperation; "),r.undeclaredGlobalsInFunctions.size>0&&r.undeclaredGlobalsInFunctions.forEach((e=>{throw new c(n,i.InvalidIdentifier,e.node)}));let u="";u=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+a+"\n return lastStatement; }); } \n return this.postProcess(yield mainBody()); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+a+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const p=r.moduleFactory,m=r.moduleFactoryMap,g=r.exports,d={};let f;for(f in g)d[f]=r.mangleMap[f]??f;const y={lc:b,lang:Ve,mangles:r.mangleMap,postProcess(e){if(e instanceof S&&(e=e.value),e instanceof w&&(e=e.value),e===v&&(e=null),e===x)throw new s(null,i.IllegalResult,null);if(e===F)throw new s(null,i.IllegalResult,null);if(h(e))throw new s(null,i.IllegalResult,null);return e},prepare(e,n){let t=e.spatialReference;null==t&&(t=P.WebMercator);const o=Ue(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,moduleFactory:p,moduleFactoryMap:m,mangleMap:this.mangles,moduleSingletons:{},exports:g,gdefs:{},exportmangle:d,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??qe,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:{depth:1}}}};return new Function("context","spatialReference",u).bind(y)}async function Je(){return Ze([await import("./functions/geomasync.js")],"async"),!0}class Ye extends n{constructor(e){super(),this.moduleContext=e}hasGlobal(e){return void 0===this.moduleContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.moduleContext.exports[e]}setGlobal(e,n){const t=this.moduleContext.globalScope,o=e.toLowerCase();if(h(n))throw new s(null,i.AssignModuleFunction,null);t[this.moduleContext.exportmangle[o]]=n}global(e){const n=this.moduleContext.globalScope,t=e.toLowerCase(),o=n[this.moduleContext.exportmangle[t]];if(void 0===o)throw new s(null,i.InvalidIdentifier,null);if(h(o)&&!(o instanceof d)){const e=new d;return e.fn=o,e.parameterEvaluator=H,e.context=this.moduleContext,n[this.moduleContext.exportmangle[t]]=e,e}return o}}function He(e,n,o=!1){const l={isAsync:o,moduleFactory:n.moduleFactory,moduleFactoryMap:{},libraryResolver:new t(null,e.loadedModules),globalScope:Le(n.vars,o?Ne:Ee,n.customfunctions),customfunctions:n.customfunctions,localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},console:qe,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor,services:n.services,symbols:{symbolCounter:0}};let r=ge(l,e);""===r&&(r="lc.voidOperation; ");let a="";a=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+r+"\n return lastStatement; }); } \n yield mainBody(); \n return this.prepareModule(runtimeCtx); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+r+"\n return lastStatement; } \n mainBody(); \n return this.prepareModule(runtimeCtx); ";const s=l.moduleFactory,i=l.moduleFactoryMap,c=l.exports,u={};let p;for(p in c)u[p]=l.mangleMap[p]??p;const m={lc:b,lang:Ve,mangles:l.mangleMap,prepareModule:e=>new Ye(e),prepare(e,n){let t=e.spatialReference;null==t&&(t=new P({wkid:102100}));const o=Ue(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,exports:c,exportmangle:u,gdefs:{},moduleFactory:s,moduleFactoryMap:i,moduleSingletons:e.moduleSingletons,mangleMap:this.mangles,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??qe,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:e.depthCounter}}};return new Function("context","spatialReference",a).bind(m)}export{J as UserDefinedCompiledFunction,ze as compileScript,Je as enableAsyncSupport,Pe as executeScript,Ze as extend,Ke as functionHelper};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{toSymbolId as e}from"./arcadeEnvironment.js";import{ArcadeModule as t}from"./ArcadeModule.js";import{ArcadeModuleLoader as n}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as r,geometryMember as o}from"./containerUtils.js";import i from"./Dictionary.js";import{ArcadeExecutionError as l,ExecutionErrorCodes as s,ensureArcadeExecutionError as a}from"./executionError.js";import c from"./Feature.js";import{NativeFunction as u,ScopeMarshalledFunction as f,ArcadeFunction as p,wrapModuleScopedResponse as h}from"./FunctionWrapper.js";import{B as d,z as w,i as m,d as g,n as y,m as v,v as b,f as S,y as x,A as R,R as F,I,w as A,x as M,s as C}from"../chunks/languageUtils.js";import{addFunctionDeclaration as N}from"./treeAnalysis.js";import{A as O}from"../chunks/array.js";import{registerFunctions as B}from"./functions/date.js";import{registerFunctions as E}from"./functions/geometry.js";import{registerFunctions as j}from"./functions/geomsync.js";import{registerFunctions as k}from"./functions/maths.js";import{registerFunctions as U}from"./functions/stats.js";import{registerFunctions as D}from"./functions/string.js";import K from"../geometry/Geometry.js";import Z from"../geometry/SpatialReference.js";import{isBoolean as q,isString as L,isArray as G,isNumber as P,isGraphic as W}from"../support/guards.js";class T extends p{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,localScope:{},depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new l(e,s.MaximumCallDepth,null);return Ie(this.definition,n,t,null)}}call(e,t){return z(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,localScope:{}};if(i.depthCounter.depth>64)throw new l(e,s.MaximumCallDepth,t);return Ie(this.definition,i,o,t)}))}marshalledCall(e,t,n,r){return r(e,t,((o,i,l)=>{const s={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,localScope:{}};return l=l.map((t=>!m(t)||t instanceof f?t:h(t,e,r))),h(Ie(this.definition,s,l,t),n,r)}))}}class V extends t{constructor(e){super(),this.source=e}global(t){const n=this.executingContext.globalScope[e(t)];if(m(n.value)&&!(n.value instanceof f)){const e=new f;e.fn=n.value,e.parameterEvaluator=z,e.context=this.executingContext,n.value=e}return n.value}setGlobal(t,n){if(m(n))throw new l(null,s.AssignModuleFunction,null);this.executingContext.globalScope[e(t)]={value:n}}hasGlobal(t){return void 0===this.executingContext.exports[t]&&(t=e(t)),void 0!==this.executingContext.exports[t]}loadModule(e){let t=e.spatialReference;null==t&&(t=new Z({wkid:102100})),this.moduleScope=Me({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:t,globalScope:this.moduleScope,localScope:null,libraryResolver:new n(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},services:e.services,console:e.console??Ne,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,depthCounter:{depth:1}},le(this.executingContext,this.source.syntax)}}function _(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(Y(e,t.arguments[r]));return n}function z(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,_(e,t))}catch(r){throw r}}function Y(e,t){try{switch(t.type){case"AssignmentExpression":return re(e,t);case"UpdateExpression":return te(e,t);case"TemplateLiteral":return ve(e,t);case"Identifier":return be(e,t);case"MemberExpression":return he(e,t);case"Literal":return t.value;case"CallExpression":return Se(e,t);case"UnaryExpression":return de(e,t);case"BinaryExpression":return me(e,t);case"LogicalExpression":return ge(e,t);case"ArrayExpression":return we(e,t);case"ObjectExpression":return J(e,t);default:throw new l(e,s.Unrecognized,t)}}catch(n){throw a(e,t,n)}}function H(e,t){switch(t.type){case"EmptyStatement":return b;case"VariableDeclaration":return fe(e,t);case"ImportDeclaration":return ce(e,t);case"ExportNamedDeclaration":return ue(e,t);case"BlockStatement":return le(e,t);case"FunctionDeclaration":return ae(e,t);case"ReturnStatement":return se(e,t);case"IfStatement":return ie(e,t);case"ExpressionStatement":return oe(e,t);case"BreakStatement":return A;case"ContinueStatement":return M;case"ForStatement":return X(e,t);case"ForInStatement":return Q(e,t);case"WhileStatement":return $(e,t);default:throw new l(e,s.Unrecognized,t)}}function J(e,t){const n={},r=new Map;for(let i=0;i<t.properties.length;i++){const o=t.properties[i],a="Identifier"===o.key.type?o.key.name:Y(e,o.key),c=Y(e,o.value);if(m(c))throw new l(e,s.NoFunctionInDictionary,t);if(!1===L(a))throw new l(e,s.KeyMustBeString,t);let u=a.toString();const f=u.toLowerCase();r.has(f)?u=r.get(f):r.set(f,u),n[u]=c===b?null:c}const o=new i(n);return o.immutable=!1,o}function Q(t,n){const r=Y(t,n.right);"VariableDeclaration"===n.left.type&&fe(t,n.left);const o=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let a=null;if(null!=t.localScope&&void 0!==t.localScope[o]&&(a=t.localScope[o]),null===a&&void 0!==t.globalScope[o]&&(a=t.globalScope[o]),null===a)throw new l(t,s.InvalidIdentifier,n);if(G(r)||L(r)){const e=r.length;for(let r=0;r<e;r++){a.value=r;const e=H(t,n.body);if(e===A)break;if(e instanceof F)return e}return b}if(v(r)){for(let e=0;e<r.length();e++){a.value=e;const r=H(t,n.body);if(r===A)break;if(r instanceof F)return r}return b}if(r instanceof i||y(r)){const e=r.keys();for(let r=0;r<e.length;r++){a.value=e[r];const o=H(t,n.body);if(o===A)break;if(o instanceof F)return o}}return b}function X(e,t){null!==t.init&&("VariableDeclaration"===t.init.type?H(e,t.init):Y(e,t.init));const n={testResult:!0,lastAction:b};do{ee(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof F?n.lastAction:b}function $(e,t){const n={testResult:!0,lastAction:b};if(n.testResult=Y(e,t.test),!1===n.testResult)return b;if(!0!==n.testResult)throw new l(e,s.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=H(e,t.body),n.lastAction!==A)&&!(n.lastAction instanceof F);)if(n.testResult=Y(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new l(e,s.BooleanConditionRequired,t);return n.lastAction instanceof F?n.lastAction:b}function ee(e,t,n){if(null!==t.test){if(n.testResult=Y(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new l(e,s.BooleanConditionRequired,t)}n.lastAction=H(e,t.body),n.lastAction!==A?n.lastAction instanceof F?n.testResult=!1:null!==t.update&&Y(e,t.update):n.testResult=!1}function te(t,n){if("CallExpression"===n.argument.type)throw new l(t,s.NeverReach,n);let r;if("MemberExpression"===n.argument.type){const e=Y(t,n.argument.object);let o;if(!0===n.argument.computed)o=Y(t,n.argument.property);else{if("Identifier"!==n.argument.property.type)throw new l(t,s.Unrecognized,n);o=n.argument.property.name}if(G(e)){if(!P(o))throw new l(t,s.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>=e.length)throw new l(t,s.OutOfBounds,n);r=g(e[o]),e[o]="++"===n.operator?r+1:r-1}else if(e instanceof i){if(!1===L(o))throw new l(t,s.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new l(t,s.FieldNotFound,n);r=g(e.field(o)),e.setField(o,"++"===n.operator?r+1:r-1)}else if(y(e)){if(!1===L(o))throw new l(t,s.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new l(t,s.FieldNotFound,n);r=g(e.field(o)),e.setField(o,"++"===n.operator?r+1:r-1)}else{if(v(e))throw new l(t,s.Immutable,n);if(!(e instanceof V))throw new l(t,s.InvalidParameter,n);if(!1===L(o))throw new l(t,s.ModuleAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new l(t,s.ModuleExportNotFound,n);r=g(e.global(o)),e.setGlobal(o,"++"===n.operator?r+1:r-1)}return!1===n.prefix?r:"++"===n.operator?r+1:r-1}const o=e(n.argument);if(null!=t.localScope&&void 0!==t.localScope[o])return r=g(t.localScope[o].value),t.localScope[o]={value:"++"===n.operator?r+1:r-1},!1===n.prefix?r:"++"===n.operator?r+1:r-1;if(void 0!==t.globalScope[o])return r=g(t.globalScope[o].value),t.globalScope[o]={value:"++"===n.operator?r+1:r-1},!1===n.prefix?r:"++"===n.operator?r+1:r-1;throw new l(t,s.InvalidIdentifier,n)}function ne(e,t,n,r,o){switch(t){case"=":return e===b?null:e;case"/=":return g(n)/g(e);case"*=":return g(n)*g(e);case"-=":return g(n)-g(e);case"+=":return L(n)||L(e)?S(n)+S(e):g(n)+g(e);case"%=":return g(n)%g(e);default:throw new l(o,s.UnsupportedOperator,r)}}function re(t,n){if("MemberExpression"===n.left.type){const e=Y(t,n.left.object);let r;if(!0===n.left.computed)r=Y(t,n.left.property);else{if("Identifier"!==n.left.property.type)throw new l(t,s.InvalidIdentifier,n);r=n.left.property.name}const o=Y(t,n.right);if(G(e)){if(!P(r))throw new l(t,s.ArrayAccessorMustBeNumber,n);if(r<0&&(r=e.length+r),r<0||r>e.length)throw new l(t,s.OutOfBounds,n);if(r===e.length){if("="!==n.operator)throw new l(t,s.OutOfBounds,n);e[r]=ne(o,n.operator,e[r],n,t)}else e[r]=ne(o,n.operator,e[r],n,t)}else if(e instanceof i){if(!1===L(r))throw new l(t,s.KeyAccessorMustBeString,n);if(!0===e.hasField(r))e.setField(r,ne(o,n.operator,e.field(r),n,t));else{if("="!==n.operator)throw new l(t,s.FieldNotFound,n,{key:r});e.setField(r,ne(o,n.operator,null,n,t))}}else if(y(e)){if(!1===L(r))throw new l(t,s.KeyAccessorMustBeString,n);if(!0===e.hasField(r))e.setField(r,ne(o,n.operator,e.field(r),n,t));else{if("="!==n.operator)throw new l(t,s.FieldNotFound,n,{key:r});e.setField(r,ne(o,n.operator,null,n,t))}}else{if(v(e))throw new l(t,s.Immutable,n);if(!(e instanceof V))throw new l(t,s.InvalidIdentifier,n);if(!1===L(r))throw new l(t,s.ModuleAccessorMustBeString,n);if(!0!==e.hasGlobal(r))throw new l(t,s.ModuleExportNotFound,n);e.setGlobal(r,ne(o,n.operator,e.global(r),n,t))}return b}const r=e(n.left),o=Y(t,n.right);if(null!=t.localScope&&void 0!==t.localScope[r])return t.localScope[r]={value:ne(o,n.operator,t.localScope[r].value,n,t)},b;if(void 0!==t.globalScope[r])return t.globalScope[r]={value:ne(o,n.operator,t.globalScope[r].value,n,t)},b;throw new l(t,s.InvalidIdentifier,n)}function oe(e,t){const n=Y(e,t.expression);return n===b?b:new I(n)}function ie(e,t){const n=Y(e,t.test);if(!0===n)return H(e,t.consequent);if(!1===n)return null!==t.alternate?H(e,t.alternate):b;throw new l(e,s.BooleanConditionRequired,t)}function le(e,t){let n=b;for(let r=0;r<t.body.length;r++)if(n=H(e,t.body[r]),n instanceof F||n===A||n===M)return n;return n}function se(e,t){if(null===t.argument)return new F(b);const n=Y(e,t.argument);return new F(n)}function ae(t,n){const r=e(n.id);return t.globalScope[r]={value:new T(n,t)},b}function ce(t,n){const r=e(n.specifiers[0].local),o=t.libraryResolver.loadLibrary(r);let i;return t.libraryResolver._moduleSingletons?.has(o.uri)?i=t.libraryResolver._moduleSingletons.get(o.uri):(i=new V(o),i.loadModule(t),t.libraryResolver._moduleSingletons?.set(o.uri,i)),t.globalScope[r]={value:i},b}function ue(t,n){if(H(t,n.declaration),"FunctionDeclaration"===n.declaration.type)t.exports[e(n.declaration.id)]="function";else if("VariableDeclaration"===n.declaration.type)for(const r of n.declaration.declarations)t.exports[e(r.id)]="variable";return b}function fe(e,t){for(let n=0;n<t.declarations.length;n++)pe(e,t.declarations[n]);return b}function pe(t,n){let r=null===n.init?null:Y(t,n.init);if(r===b&&(r=null),"Identifier"!==n.id.type)throw new l(t,s.InvalidIdentifier,n);const o=e(n.id);null!=t.localScope?t.localScope[o]={value:r}:t.globalScope[o]={value:r}}function he(e,t){try{const n=Y(e,t.object);if(null===n)throw new l(e,s.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof i||y(n))return n.field(t.property.name);if(n instanceof K)return o(n,t.property.name,e,t);if(n instanceof V){if(!n.hasGlobal(t.property.name))throw new l(e,s.InvalidIdentifier,t);return n.global(t.property.name)}}throw new l(e,s.InvalidMemberAccessKey,t)}let r=Y(e,t.property);if(n instanceof i||y(n)){if(L(r))return n.field(r);throw new l(e,s.InvalidMemberAccessKey,t)}if(n instanceof V){if(L(r))return n.global(r);throw new l(e,s.InvalidMemberAccessKey,t)}if(n instanceof K){if(L(r))return o(n,r,e,t);throw new l(e,s.InvalidMemberAccessKey,t)}if(G(n)){if(P(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new l(e,s.OutOfBounds,t);return n[r]}throw new l(e,s.InvalidMemberAccessKey,t)}if(L(n)){if(P(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new l(e,s.OutOfBounds,t);return n[r]}throw new l(e,s.InvalidMemberAccessKey,t)}if(v(n)){if(P(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new l(e,s.OutOfBounds,t);return n.get(r)}throw new l(e,s.InvalidMemberAccessKey,t)}throw new l(e,s.InvalidMemberAccessKey,t)}catch(n){throw n}}function de(e,t){try{const n=Y(e,t.argument);if(q(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*g(n);if("+"===t.operator)return 1*g(n);if("~"===t.operator)return~g(n);throw new l(e,s.UnsupportedUnaryOperator,t)}if("~"===t.operator)return~g(n);if("-"===t.operator)return-1*g(n);if("+"===t.operator)return 1*g(n);throw new l(e,s.UnsupportedUnaryOperator,t)}catch(n){throw n}}function we(e,t){try{const n=[];for(let r=0;r<t.elements.length;r++){const o=Y(e,t.elements[r]);if(m(o))throw new l(e,s.NoFunctionInArray,t);o===b?n.push(null):n.push(o)}return n}catch(n){throw n}}function me(e,t){try{const n=Y(e,t.left),r=Y(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return R(g(n),g(r),t.operator);case"==":return w(n,r);case"!=":return!w(n,r);case"<":case">":case"<=":case">=":return x(n,r,t.operator);case"+":return L(n)||L(r)?S(n)+S(r):g(n)+g(r);case"-":return g(n)-g(r);case"*":return g(n)*g(r);case"/":return g(n)/g(r);case"%":return g(n)%g(r);default:throw new l(e,s.UnsupportedOperator,t)}}catch(n){throw n}}function ge(e,t){try{const n=Y(e,t.left);if(q(n))switch(t.operator){case"||":{if(!0===n)return n;const r=Y(e,t.right);if(q(r))return r;throw new l(e,s.LogicExpressionOrAnd,t)}case"&&":{if(!1===n)return n;const r=Y(e,t.right);if(q(r))return r;throw new l(e,s.LogicExpressionOrAnd,t)}default:throw new l(e,s.LogicExpressionOrAnd,t)}throw new l(e,s.LogicalExpressionOnlyBoolean,t)}catch(n){throw n}}function ye(e,t,n){if(m(e))throw new l(t,s.NoFunctionInTemplateLiteral,n);return e}function ve(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]?S(ye(Y(e,t.expressions[r]),e,t)):"",r++}return n}function be(t,n){try{const r=e(n);if(null!=t.localScope&&void 0!==t.localScope[r])return t.localScope[r].value;if(void 0!==t.globalScope[r])return t.globalScope[r].value;throw new l(t,s.InvalidIdentifier,n)}catch(r){throw r}}function Se(t,n){try{if("MemberExpression"===n.callee.type){const e=Y(t,n.callee.object);if(!(e instanceof V))throw new l(t,s.FunctionNotFound,n);const r=!1===n.callee.computed?n.callee.property.name:Y(t,n.callee.property);if(!e.hasGlobal(r))throw new l(t,s.FunctionNotFound,n);const o=e.global(r);if(!m(o))throw new l(t,s.CallNonFunction,n);return o.call(t,n)}if("Identifier"!==n.callee.type)throw new l(t,s.FunctionNotFound,n);const r=e(n.callee);if(null!=t.localScope&&void 0!==t.localScope[r]){const e=t.localScope[r];if(m(e.value))return e.value.call(t,n);throw new l(t,s.CallNonFunction,n)}if(void 0!==t.globalScope[r]){const e=t.globalScope[r];if(m(e.value))return e.value.call(t,n);throw new l(t,s.CallNonFunction,n)}throw new l(t,s.FunctionNotFound,n)}catch(r){throw r}}const xe={};function Re(e,t,n,r){try{const o=t.arguments,i=Y(e,o[n]);if(w(i,r))return Y(e,o[n+1]);{const i=o.length-n;return 1===i?Y(e,o[n]):2===i?null:3===i?Y(e,o[n+2]):Re(e,t,n+2,r)}}catch(o){throw o}}function Fe(e,t,n,r){try{const o=t.arguments;if(!0===r)return Y(e,o[n+1]);if(3===o.length-n)return Y(e,o[n+2]);{const r=Y(e,o[n+2]);if(!1===q(r))throw new l(e,s.BooleanConditionRequired,o[n+2]);return Fe(e,t,n+2,r)}}catch(o){throw o}}function Ie(t,n,r,o){try{const i=t.body;if(r.length!==t.params.length)throw new l(n,s.WrongNumberOfParameters,o);if(null!=n.localScope)for(let o=0;o<r.length;o++)n.localScope[e(t.params[o])]={value:r[o]};const a=H(n,i);if(a instanceof F)return a.value;if(a===A)throw new l(n,s.UnexpectedToken,o);if(a===M)throw new l(n,s.UnexpectedToken,o);return a instanceof I?a.value:a}catch(i){throw i}}B(xe,z),D(xe,z),k(xe,z),E(xe,z),U(xe,z),j(xe,z),xe.iif=function(e,t){try{if(!0===t.preparsed)throw new l(e,s.NeverReach,t);const n=t.arguments;d(null===n?[]:n,3,3,e,t);const r=Y(e,n[0]);if(!1===q(r))throw new l(e,s.BooleanConditionRequired,t);return Y(e,!0===r?n[1]:n[2])}catch(n){throw n}},xe.defaultvalue=function(e,t){try{if(!0===t.preparsed)throw new l(e,s.NeverReach,t);const n=t.arguments;d(null===n?[]:n,2,3,e,t);const o=Y(e,n[0]);if(3===n.length){const t=Y(e,n[1]),i=r(o,t);return null!=i&&""!==i?i:Y(e,n[2])}return null===o||""===o||void 0===o?Y(e,n[1]):o}catch(n){throw n}},xe.decode=function(e,t){try{if(!0===t.preparsed)throw new l(e,s.NeverReach,t);const n=t.arguments;if(n.length<2)throw new l(e,s.WrongNumberOfParameters,t);if(2===n.length)return Y(e,n[1]);{if((n.length-1)%2==0)throw new l(e,s.WrongNumberOfParameters,t);const r=Y(e,n[0]);return Re(e,t,1,r)}}catch(n){throw n}},xe.when=function(e,t){try{if(!0===t.preparsed)throw new l(e,s.NeverReach,t);const n=t.arguments;if(n.length<3)throw new l(e,s.WrongNumberOfParameters,t);if(n.length%2==0)throw new l(e,s.WrongNumberOfParameters,t);const r=Y(e,n[0]);if(!1===q(r))throw new l(e,s.BooleanConditionRequired,n[0]);return Fe(e,t,0,r)}catch(n){throw n}};for(const Ee in xe)xe[Ee]={value:new u(xe[Ee])};const Ae=function(){};function Me(e,t,n){const r=new Ae;e||(e={}),t||(t={});const o=new i({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});o.immutable=!1,r.textformatting={value:o};for(const i in t)r[i]={value:new u(t[i])};for(const i in e)r[i]={value:W(e[i])?c.createFromGraphic(e[i],n):e[i]};return r}Ae.prototype=xe,Ae.prototype.infinity={value:Number.POSITIVE_INFINITY},Ae.prototype.pi={value:Math.PI};const Ce={fixSpatialReference:C,parseArguments:_,standardFunction:z};function Ne(e){console.log(e)}function Oe(e){const t={mode:"sync",compiled:!1,functions:{},signatures:[],standardFunction:z,evaluateIdentifier:be};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)xe[n]={value:new u(t.functions[n])},Ae.prototype[n]=xe[n];for(let n=0;n<t.signatures.length;n++)N(t.signatures[n],"sync")}function Be(e,t){let r=t.spatialReference;null==r&&(r=new Z({wkid:102100}));let o=null;e.usesModules&&(o=new n(new Map,e.loadedModules));const i={spatialReference:r,globalScope:Me(t.vars,t.customfunctions,t.timeZone),localScope:null,services:t.services,exports:{},libraryResolver:o,console:t.console??Ne,timeZone:t.timeZone??null,lrucache:t.lrucache,interceptor:t.interceptor,depthCounter:{depth:1}},a=le(i,e);if(a instanceof F||a instanceof I){const e=a.value;if(e===b)return null;if(m(e))throw new l(i,s.IllegalResult,null);return e}if(a===b)return null;if(a===A)throw new l(i,s.IllegalResult,null);if(a===M)throw new l(i,s.IllegalResult,null);throw new l(i,s.NeverReach,null)}Oe([O]);export{Be as executeScript,Oe as extend,Ce as functionHelper};
5
+ import{toSymbolId as e}from"./arcadeEnvironment.js";import{ArcadeModule as t}from"./ArcadeModule.js";import{ArcadeModuleLoader as n}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as r,geometryMember as o,getGeometryKeys as i}from"./containerUtils.js";import l from"./Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as s,ensureArcadeExecutionError as c}from"./executionError.js";import u from"./Feature.js";import{NativeFunction as f,ScopeMarshalledFunction as p,ArcadeFunction as h,wrapModuleScopedResponse as d}from"./FunctionWrapper.js";import{B as w,z as m,i as g,d as y,n as v,m as b,v as S,f as x,y as R,A as F,R as I,I as A,w as M,x as C,s as N,l as O}from"../chunks/languageUtils.js";import{addFunctionDeclaration as B}from"./treeAnalysis.js";import{A as k}from"../chunks/array.js";import{registerFunctions as E}from"./functions/date.js";import{registerFunctions as j}from"./functions/geometry.js";import{registerFunctions as D}from"./functions/geomsync.js";import{registerFunctions as U}from"./functions/maths.js";import{registerFunctions as K}from"./functions/stats.js";import{registerFunctions as Z}from"./functions/string.js";import q from"../geometry/Geometry.js";import L from"../geometry/SpatialReference.js";import{isBoolean as G,isString as P,isArray as V,isNumber as W,isGraphic as T}from"../support/guards.js";class _ 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,localScope:{},depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new a(e,s.MaximumCallDepth,null);return Ce(this.definition,n,t,null)}}call(e,t){return H(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,localScope:{}};if(i.depthCounter.depth>64)throw new a(e,s.MaximumCallDepth,t);return Ce(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,localScope:{}};return l=l.map((t=>!g(t)||t instanceof p?t:d(t,e,r))),d(Ce(this.definition,a,l,t),n,r)}))}}class z extends t{constructor(e){super(),this.source=e}global(t){const n=this.executingContext.globalScope[e(t)];if(g(n.value)&&!(n.value instanceof p)){const e=new p;e.fn=n.value,e.parameterEvaluator=H,e.context=this.executingContext,n.value=e}return n.value}setGlobal(t,n){if(g(n))throw new a(null,s.AssignModuleFunction,null);this.executingContext.globalScope[e(t)]={value:n}}hasGlobal(t){return void 0===this.executingContext.exports[t]&&(t=e(t)),void 0!==this.executingContext.exports[t]}loadModule(e){let t=e.spatialReference;null==t&&(t=new L({wkid:102100})),this.moduleScope=Oe({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:t,globalScope:this.moduleScope,localScope:null,libraryResolver:new n(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},services:e.services,console:e.console??ke,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,depthCounter:{depth:1}},ce(this.executingContext,this.source.syntax)}}function Y(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(J(e,t.arguments[r]));return n}function H(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,Y(e,t))}catch(r){throw r}}function J(e,t){try{switch(t.type){case"AssignmentExpression":return le(e,t);case"UpdateExpression":return oe(e,t);case"TemplateLiteral":return xe(e,t);case"Identifier":return Re(e,t);case"MemberExpression":return me(e,t);case"Literal":return t.value;case"CallExpression":return Fe(e,t);case"UnaryExpression":return ge(e,t);case"BinaryExpression":return ve(e,t);case"LogicalExpression":return be(e,t);case"ArrayExpression":return ye(e,t);case"ObjectExpression":return X(e,t);default:throw new a(e,s.Unrecognized,t)}}catch(n){throw c(e,t,n)}}function Q(e,t){switch(t.type){case"EmptyStatement":return S;case"VariableDeclaration":return de(e,t);case"ImportDeclaration":return pe(e,t);case"ExportNamedDeclaration":return he(e,t);case"BlockStatement":return ce(e,t);case"FunctionDeclaration":return fe(e,t);case"ReturnStatement":return ue(e,t);case"IfStatement":return se(e,t);case"ExpressionStatement":return ae(e,t);case"BreakStatement":return M;case"ContinueStatement":return C;case"ForStatement":return te(e,t);case"ForInStatement":return $(e,t);case"ForOfStatement":return ee(e,t);case"WhileStatement":return ne(e,t);default:throw new a(e,s.Unrecognized,t)}}function X(e,t){const n={},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:J(e,o.key),c=J(e,o.value);if(g(c))throw new a(e,s.NoFunctionInDictionary,t);if(!1===P(l))throw new a(e,s.KeyMustBeString,t);let u=l.toString();const f=u.toLowerCase();r.has(f)?u=r.get(f):r.set(f,u),n[u]=c===S?null:c}const o=new l(n);return o.immutable=!1,o}function $(t,n){const r=J(t,n.right);"VariableDeclaration"===n.left.type&&de(t,n.left);const o=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let c=null;if(null!=t.localScope&&void 0!==t.localScope[o]&&(c=t.localScope[o]),null===c&&void 0!==t.globalScope[o]&&(c=t.globalScope[o]),null===c)throw new a(t,s.InvalidIdentifier,n);if(V(r)||P(r)){const e=r.length;for(let r=0;r<e;r++){c.value=r;const e=Q(t,n.body);if(e===M)break;if(e instanceof I)return e}return S}if(b(r)){for(let e=0;e<r.length();e++){c.value=e;const r=Q(t,n.body);if(r===M)break;if(r instanceof I)return r}return S}if(r instanceof l||v(r)){const e=r.keys();for(let r=0;r<e.length;r++){c.value=e[r];const o=Q(t,n.body);if(o===M)break;if(o instanceof I)return o}return S}if(O(r)){for(const e of i(r)){c.value=e;const r=Q(t,n.body);if(r===M)break;if(r instanceof I)return r}return S}return S}function ee(t,n){const r=J(t,n.right);"VariableDeclaration"===n.left.type&&Q(t,n.left);const c=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let u=null;if(null!=t.localScope&&void 0!==t.localScope[c]&&(u=t.localScope[c]),null===u&&void 0!==t.globalScope[c]&&(u=t.globalScope[c]),null===u)throw new a(t,s.InvalidIdentifier,n);if(V(r)||P(r)){const e=r.length;for(let o=0;o<e;o++){if(o>=r.length)throw new a(t,s.OutOfBounds,n);u.value=r[o];const e=Q(t,n.body);if(e===M)break;if(e instanceof I)return e}return S}if(b(r)){for(let e=0;e<r.length();e++){u.value=r.get(e);const o=Q(t,n.body);if(o===M)break;if(o instanceof I)return o}return S}if(r instanceof l||v(r)){for(const e of r.keys()){const o=r.field(e);u.value=new l({key:e,value:o});const i=Q(t,n.body);if(i===M)break;if(i instanceof I)return i}return S}if(O(r)){for(const e of i(r)){const i=o(r,e,t,n,1);u.value=new l({key:e,value:i});const a=Q(t,n.body);if(a===M)break;if(a instanceof I)return a}return S}return S}function te(e,t){null!==t.init&&("VariableDeclaration"===t.init.type?Q(e,t.init):J(e,t.init));const n={testResult:!0,lastAction:S};do{re(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof I?n.lastAction:S}function ne(e,t){const n={testResult:!0,lastAction:S};if(n.testResult=J(e,t.test),!1===n.testResult)return S;if(!0!==n.testResult)throw new a(e,s.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=Q(e,t.body),n.lastAction!==M)&&!(n.lastAction instanceof I);)if(n.testResult=J(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new a(e,s.BooleanConditionRequired,t);return n.lastAction instanceof I?n.lastAction:S}function re(e,t,n){if(null!==t.test){if(n.testResult=J(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new a(e,s.BooleanConditionRequired,t)}n.lastAction=Q(e,t.body),n.lastAction!==M?n.lastAction instanceof I?n.testResult=!1:null!==t.update&&J(e,t.update):n.testResult=!1}function oe(t,n){if("CallExpression"===n.argument.type)throw new a(t,s.NeverReach,n);let r;if("MemberExpression"===n.argument.type){const e=J(t,n.argument.object);let o;if(!0===n.argument.computed)o=J(t,n.argument.property);else{if("Identifier"!==n.argument.property.type)throw new a(t,s.Unrecognized,n);o=n.argument.property.name}if(V(e)){if(!W(o))throw new a(t,s.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>=e.length)throw new a(t,s.OutOfBounds,n);r=y(e[o]),e[o]="++"===n.operator?r+1:r-1}else if(e instanceof l){if(!1===P(o))throw new a(t,s.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new a(t,s.FieldNotFound,n);r=y(e.field(o)),e.setField(o,"++"===n.operator?r+1:r-1)}else if(v(e)){if(!1===P(o))throw new a(t,s.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new a(t,s.FieldNotFound,n);r=y(e.field(o)),e.setField(o,"++"===n.operator?r+1:r-1)}else{if(b(e))throw new a(t,s.Immutable,n);if(!(e instanceof z))throw new a(t,s.InvalidParameter,n);if(!1===P(o))throw new a(t,s.ModuleAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new a(t,s.ModuleExportNotFound,n);r=y(e.global(o)),e.setGlobal(o,"++"===n.operator?r+1:r-1)}return!1===n.prefix?r:"++"===n.operator?r+1:r-1}const o=e(n.argument);if(null!=t.localScope&&void 0!==t.localScope[o])return r=y(t.localScope[o].value),t.localScope[o]={value:"++"===n.operator?r+1:r-1},!1===n.prefix?r:"++"===n.operator?r+1:r-1;if(void 0!==t.globalScope[o])return r=y(t.globalScope[o].value),t.globalScope[o]={value:"++"===n.operator?r+1:r-1},!1===n.prefix?r:"++"===n.operator?r+1:r-1;throw new a(t,s.InvalidIdentifier,n)}function ie(e,t,n,r,o){switch(t){case"=":return e===S?null:e;case"/=":return y(n)/y(e);case"*=":return y(n)*y(e);case"-=":return y(n)-y(e);case"+=":return P(n)||P(e)?x(n)+x(e):y(n)+y(e);case"%=":return y(n)%y(e);default:throw new a(o,s.UnsupportedOperator,r)}}function le(t,n){if("MemberExpression"===n.left.type){const e=J(t,n.left.object);let r;if(!0===n.left.computed)r=J(t,n.left.property);else{if("Identifier"!==n.left.property.type)throw new a(t,s.InvalidIdentifier,n);r=n.left.property.name}const o=J(t,n.right);if(V(e)){if(!W(r))throw new a(t,s.ArrayAccessorMustBeNumber,n);if(r<0&&(r=e.length+r),r<0||r>e.length)throw new a(t,s.OutOfBounds,n);if(r===e.length){if("="!==n.operator)throw new a(t,s.OutOfBounds,n);e[r]=ie(o,n.operator,e[r],n,t)}else e[r]=ie(o,n.operator,e[r],n,t)}else if(e instanceof l){if(!1===P(r))throw new a(t,s.KeyAccessorMustBeString,n);if(!0===e.hasField(r))e.setField(r,ie(o,n.operator,e.field(r),n,t));else{if("="!==n.operator)throw new a(t,s.FieldNotFound,n,{key:r});e.setField(r,ie(o,n.operator,null,n,t))}}else if(v(e)){if(!1===P(r))throw new a(t,s.KeyAccessorMustBeString,n);if(!0===e.hasField(r))e.setField(r,ie(o,n.operator,e.field(r),n,t));else{if("="!==n.operator)throw new a(t,s.FieldNotFound,n,{key:r});e.setField(r,ie(o,n.operator,null,n,t))}}else{if(b(e))throw new a(t,s.Immutable,n);if(!(e instanceof z))throw new a(t,s.InvalidIdentifier,n);if(!1===P(r))throw new a(t,s.ModuleAccessorMustBeString,n);if(!0!==e.hasGlobal(r))throw new a(t,s.ModuleExportNotFound,n);e.setGlobal(r,ie(o,n.operator,e.global(r),n,t))}return S}const r=e(n.left),o=J(t,n.right);if(null!=t.localScope&&void 0!==t.localScope[r])return t.localScope[r]={value:ie(o,n.operator,t.localScope[r].value,n,t)},S;if(void 0!==t.globalScope[r])return t.globalScope[r]={value:ie(o,n.operator,t.globalScope[r].value,n,t)},S;throw new a(t,s.InvalidIdentifier,n)}function ae(e,t){const n=J(e,t.expression);return n===S?S:new A(n)}function se(e,t){const n=J(e,t.test);if(!0===n)return Q(e,t.consequent);if(!1===n)return null!==t.alternate?Q(e,t.alternate):S;throw new a(e,s.BooleanConditionRequired,t)}function ce(e,t){let n=S;for(let r=0;r<t.body.length;r++)if(n=Q(e,t.body[r]),n instanceof I||n===M||n===C)return n;return n}function ue(e,t){if(null===t.argument)return new I(S);const n=J(e,t.argument);return new I(n)}function fe(t,n){const r=e(n.id);return t.globalScope[r]={value:new _(n,t)},S}function pe(t,n){const r=e(n.specifiers[0].local),o=t.libraryResolver.loadLibrary(r);let i;return t.libraryResolver._moduleSingletons?.has(o.uri)?i=t.libraryResolver._moduleSingletons.get(o.uri):(i=new z(o),i.loadModule(t),t.libraryResolver._moduleSingletons?.set(o.uri,i)),t.globalScope[r]={value:i},S}function he(t,n){if(Q(t,n.declaration),"FunctionDeclaration"===n.declaration.type)t.exports[e(n.declaration.id)]="function";else if("VariableDeclaration"===n.declaration.type)for(const r of n.declaration.declarations)t.exports[e(r.id)]="variable";return S}function de(e,t){for(let n=0;n<t.declarations.length;n++)we(e,t.declarations[n]);return S}function we(t,n){let r=null===n.init?null:J(t,n.init);if(r===S&&(r=null),"Identifier"!==n.id.type)throw new a(t,s.InvalidIdentifier,n);const o=e(n.id);null!=t.localScope?t.localScope[o]={value:r}:t.globalScope[o]={value:r}}function me(e,t){try{const n=J(e,t.object);if(null===n)throw new a(e,s.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof l||v(n))return n.field(t.property.name);if(n instanceof q)return o(n,t.property.name,e,t);if(n instanceof z){if(!n.hasGlobal(t.property.name))throw new a(e,s.InvalidIdentifier,t);return n.global(t.property.name)}}throw new a(e,s.InvalidMemberAccessKey,t)}let r=J(e,t.property);if(n instanceof l||v(n)){if(P(r))return n.field(r);throw new a(e,s.InvalidMemberAccessKey,t)}if(n instanceof z){if(P(r))return n.global(r);throw new a(e,s.InvalidMemberAccessKey,t)}if(n instanceof q){if(P(r))return o(n,r,e,t);throw new a(e,s.InvalidMemberAccessKey,t)}if(V(n)){if(W(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new a(e,s.OutOfBounds,t);return n[r]}throw new a(e,s.InvalidMemberAccessKey,t)}if(P(n)){if(W(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new a(e,s.OutOfBounds,t);return n[r]}throw new a(e,s.InvalidMemberAccessKey,t)}if(b(n)){if(W(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new a(e,s.OutOfBounds,t);return n.get(r)}throw new a(e,s.InvalidMemberAccessKey,t)}throw new a(e,s.InvalidMemberAccessKey,t)}catch(n){throw n}}function ge(e,t){try{const n=J(e,t.argument);if(G(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*y(n);if("+"===t.operator)return 1*y(n);if("~"===t.operator)return~y(n);throw new a(e,s.UnsupportedUnaryOperator,t)}if("~"===t.operator)return~y(n);if("-"===t.operator)return-1*y(n);if("+"===t.operator)return 1*y(n);throw new a(e,s.UnsupportedUnaryOperator,t)}catch(n){throw n}}function ye(e,t){try{const n=[];for(let r=0;r<t.elements.length;r++){const o=J(e,t.elements[r]);if(g(o))throw new a(e,s.NoFunctionInArray,t);o===S?n.push(null):n.push(o)}return n}catch(n){throw n}}function ve(e,t){try{const n=J(e,t.left),r=J(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return F(y(n),y(r),t.operator);case"==":return m(n,r);case"!=":return!m(n,r);case"<":case">":case"<=":case">=":return R(n,r,t.operator);case"+":return P(n)||P(r)?x(n)+x(r):y(n)+y(r);case"-":return y(n)-y(r);case"*":return y(n)*y(r);case"/":return y(n)/y(r);case"%":return y(n)%y(r);default:throw new a(e,s.UnsupportedOperator,t)}}catch(n){throw n}}function be(e,t){try{const n=J(e,t.left);if(G(n))switch(t.operator){case"||":{if(!0===n)return n;const r=J(e,t.right);if(G(r))return r;throw new a(e,s.LogicExpressionOrAnd,t)}case"&&":{if(!1===n)return n;const r=J(e,t.right);if(G(r))return r;throw new a(e,s.LogicExpressionOrAnd,t)}default:throw new a(e,s.LogicExpressionOrAnd,t)}throw new a(e,s.LogicalExpressionOnlyBoolean,t)}catch(n){throw n}}function Se(e,t,n){if(g(e))throw new a(t,s.NoFunctionInTemplateLiteral,n);return e}function xe(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]?x(Se(J(e,t.expressions[r]),e,t)):"",r++}return n}function Re(t,n){try{const r=e(n);if(null!=t.localScope&&void 0!==t.localScope[r])return t.localScope[r].value;if(void 0!==t.globalScope[r])return t.globalScope[r].value;throw new a(t,s.InvalidIdentifier,n)}catch(r){throw r}}function Fe(t,n){try{if("MemberExpression"===n.callee.type){const e=J(t,n.callee.object);if(!(e instanceof z))throw new a(t,s.FunctionNotFound,n);const r=!1===n.callee.computed?n.callee.property.name:J(t,n.callee.property);if(!e.hasGlobal(r))throw new a(t,s.FunctionNotFound,n);const o=e.global(r);if(!g(o))throw new a(t,s.CallNonFunction,n);return o.call(t,n)}if("Identifier"!==n.callee.type)throw new a(t,s.FunctionNotFound,n);const r=e(n.callee);if(null!=t.localScope&&void 0!==t.localScope[r]){const e=t.localScope[r];if(g(e.value))return e.value.call(t,n);throw new a(t,s.CallNonFunction,n)}if(void 0!==t.globalScope[r]){const e=t.globalScope[r];if(g(e.value))return e.value.call(t,n);throw new a(t,s.CallNonFunction,n)}throw new a(t,s.FunctionNotFound,n)}catch(r){throw r}}const Ie={};function Ae(e,t,n,r){try{const o=t.arguments,i=J(e,o[n]);if(m(i,r))return J(e,o[n+1]);{const i=o.length-n;return 1===i?J(e,o[n]):2===i?null:3===i?J(e,o[n+2]):Ae(e,t,n+2,r)}}catch(o){throw o}}function Me(e,t,n,r){try{const o=t.arguments;if(!0===r)return J(e,o[n+1]);if(3===o.length-n)return J(e,o[n+2]);{const r=J(e,o[n+2]);if(!1===G(r))throw new a(e,s.BooleanConditionRequired,o[n+2]);return Me(e,t,n+2,r)}}catch(o){throw o}}function Ce(t,n,r,o){try{const i=t.body;if(r.length!==t.params.length)throw new a(n,s.WrongNumberOfParameters,o);if(null!=n.localScope)for(let o=0;o<r.length;o++)n.localScope[e(t.params[o])]={value:r[o]};const l=Q(n,i);if(l instanceof I)return l.value;if(l===M)throw new a(n,s.UnexpectedToken,o);if(l===C)throw new a(n,s.UnexpectedToken,o);return l instanceof A?l.value:l}catch(i){throw i}}E(Ie,H),Z(Ie,H),U(Ie,H),j(Ie,H),K(Ie,H),D(Ie,H),Ie.iif=function(e,t){try{if(!0===t.preparsed)throw new a(e,s.NeverReach,t);const n=t.arguments;w(null===n?[]:n,3,3,e,t);const r=J(e,n[0]);if(!1===G(r))throw new a(e,s.BooleanConditionRequired,t);return J(e,!0===r?n[1]:n[2])}catch(n){throw n}},Ie.defaultvalue=function(e,t){try{if(!0===t.preparsed)throw new a(e,s.NeverReach,t);const n=t.arguments;w(null===n?[]:n,2,3,e,t);const o=J(e,n[0]);if(3===n.length){const t=J(e,n[1]),i=r(o,t);return null!=i&&""!==i?i:J(e,n[2])}return null===o||""===o||void 0===o?J(e,n[1]):o}catch(n){throw n}},Ie.decode=function(e,t){try{if(!0===t.preparsed)throw new a(e,s.NeverReach,t);const n=t.arguments;if(n.length<2)throw new a(e,s.WrongNumberOfParameters,t);if(2===n.length)return J(e,n[1]);{if((n.length-1)%2==0)throw new a(e,s.WrongNumberOfParameters,t);const r=J(e,n[0]);return Ae(e,t,1,r)}}catch(n){throw n}},Ie.when=function(e,t){try{if(!0===t.preparsed)throw new a(e,s.NeverReach,t);const n=t.arguments;if(n.length<3)throw new a(e,s.WrongNumberOfParameters,t);if(n.length%2==0)throw new a(e,s.WrongNumberOfParameters,t);const r=J(e,n[0]);if(!1===G(r))throw new a(e,s.BooleanConditionRequired,n[0]);return Me(e,t,0,r)}catch(n){throw n}};for(const De in Ie)Ie[De]={value:new f(Ie[De])};const Ne=function(){};function Oe(e,t,n){const r=new Ne;e||(e={}),t||(t={});const o=new l({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});o.immutable=!1,r.textformatting={value:o};for(const i in t)r[i]={value:new f(t[i])};for(const i in e)r[i]={value:T(e[i])?u.createFromGraphic(e[i],n):e[i]};return r}Ne.prototype=Ie,Ne.prototype.infinity={value:Number.POSITIVE_INFINITY},Ne.prototype.pi={value:Math.PI};const Be={fixSpatialReference:N,parseArguments:Y,standardFunction:H};function ke(e){console.log(e)}function Ee(e){const t={mode:"sync",compiled:!1,functions:{},signatures:[],standardFunction:H,evaluateIdentifier:Re};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Ie[n]={value:new f(t.functions[n])},Ne.prototype[n]=Ie[n];for(let n=0;n<t.signatures.length;n++)B(t.signatures[n],"sync")}function je(e,t){let r=t.spatialReference;null==r&&(r=new L({wkid:102100}));let o=null;e.usesModules&&(o=new n(new Map,e.loadedModules));const i={spatialReference:r,globalScope:Oe(t.vars,t.customfunctions,t.timeZone),localScope:null,services:t.services,exports:{},libraryResolver:o,console:t.console??ke,timeZone:t.timeZone??null,lrucache:t.lrucache,interceptor:t.interceptor,depthCounter:{depth:1}},l=ce(i,e);if(l instanceof I||l instanceof A){const e=l.value;if(e===S)return null;if(g(e))throw new a(i,s.IllegalResult,null);return e}if(l===S)return null;if(l===M)throw new a(i,s.IllegalResult,null);if(l===C)throw new a(i,s.IllegalResult,null);throw new a(i,s.NeverReach,null)}Ee([k]);export{je as executeScript,Ee as extend,Be as functionHelper};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import e from"./Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as r}from"./executionError.js";import t from"./ImmutablePathArray.js";import n from"./ImmutablePointArray.js";import{m as s,n as c,q as i,l}from"../chunks/languageUtils.js";import o from"../core/Accessor.js";import{isArray as u,isString as f,isNumber as h}from"../support/guards.js";let d=0;function p(s,c,i,l,u=1){let f;switch(c=c.toLowerCase()){case"hasz":{const e=s.hasZ;return void 0!==e&&e}case"hasm":{const e=s.hasM;return void 0!==e&&e}case"spatialreference":{let a=s.spatialReference._arcadeCacheId;if(void 0===a){let e=!0;o.isFrozen(s.spatialReference)&&(e=!1),e&&(d++,s.spatialReference._arcadeCacheId=d,a=d)}const r=new e({wkt:s.spatialReference.wkt,wkid:s.spatialReference.wkid});return void 0!==a&&(r._arcadeCacheId="SPREF"+a.toString()),r}}switch(s.type){case"extent":switch(c){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const e=s[c];return void 0!==e?e:null}case"type":return"Extent"}break;case"polygon":switch(c){case"rings":f=s.cache._arcadeCacheId,void 0===f&&(d++,f=d,s.cache._arcadeCacheId=f);return new t(s.rings,s.spatialReference,!0===s.hasZ,!0===s.hasM,f);case"type":return"Polygon"}break;case"point":switch(c){case"x":case"y":case"z":case"m":return s[c]??null;case"type":return"Point"}break;case"polyline":switch(c){case"paths":f=s.cache._arcadeCacheId,void 0===f&&(d++,f=d,s.cache._arcadeCacheId=f);return new t(s.paths,s.spatialReference,!0===s.hasZ,!0===s.hasM,f);case"type":return"Polyline"}break;case"multipoint":switch(c){case"points":f=s.cache._arcadeCacheId,void 0===f&&(d++,f=d,s.cache._arcadeCacheId=f);return new n(s.points,s.spatialReference,!0===s.hasZ,!0===s.hasM,f,1);case"type":return"Multipoint"}}if(1===u)throw new a(i,r.InvalidIdentifier,l);return 2===u?{keystate:"notfound"}:null}function m(e,a){let r,t=e;if(null==t)return null;if(u(a))r=a;else if(s(a))r=a.toArray();else{if(null==a)return null;r=[a]}for(const n of r){if(c(t)){if(!1===f(n))return null;if(!t.hasField(n))return null;t=t.field(n)}else if(i(t)){if(!1===f(n))return null;if(!t.hasField(n))return null;t=t.field(n)}else if(l(t)){if(!1===f(n))return null;t=p(t,n,null,null,0)}else if(u(t)){if(!1===h(n))return null;t=n>=0?t[n]:t[t.length+n]}else{if(!s(t))return null;if(!1===h(n))return null;t=n>=0?t.get(n):t.get(t.length()+n)}if(null==t)return null}return t}export{p as geometryMember,m as getNestedOptionalValue};
5
+ import e from"./Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as t}from"./executionError.js";import n from"./ImmutablePathArray.js";import r from"./ImmutablePointArray.js";import{m as s,n as i,q as c,l}from"../chunks/languageUtils.js";import o from"../core/Accessor.js";import{isArray as u,isString as h,isNumber as p}from"../support/guards.js";const f={point:["hasZ","hasM","spatialReference","type","x","y","z","m"],multipoint:["hasZ","hasM","spatialReference","type","points"],polyline:["hasZ","hasM","spatialReference","type","paths"],polygon:["hasZ","hasM","spatialReference","type","rings"],extent:["hasZ","hasM","spatialReference","type","xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]};function m(e){return f[e.type]}let d=0;function y(s,i,c,l,u=1){let h;switch(i=i.toLowerCase()){case"hasz":{const e=s.hasZ;return void 0!==e&&e}case"hasm":{const e=s.hasM;return void 0!==e&&e}case"spatialreference":{let a=s.spatialReference._arcadeCacheId;if(void 0===a){let e=!0;o.isFrozen(s.spatialReference)&&(e=!1),e&&(d++,s.spatialReference._arcadeCacheId=d,a=d)}const t=new e({wkt:s.spatialReference.wkt,wkid:s.spatialReference.wkid});return void 0!==a&&(t._arcadeCacheId="SPREF"+a.toString()),t}}switch(s.type){case"extent":switch(i){case"xmin":case"xmax":case"ymin":case"ymax":case"zmin":case"zmax":case"mmin":case"mmax":{const e=s[i];return void 0!==e?e:null}case"type":return"Extent"}break;case"polygon":switch(i){case"rings":h=s.cache._arcadeCacheId,void 0===h&&(d++,h=d,s.cache._arcadeCacheId=h);return new n(s.rings,s.spatialReference,!0===s.hasZ,!0===s.hasM,h);case"type":return"Polygon"}break;case"point":switch(i){case"x":case"y":case"z":case"m":return s[i]??null;case"type":return"Point"}break;case"polyline":switch(i){case"paths":h=s.cache._arcadeCacheId,void 0===h&&(d++,h=d,s.cache._arcadeCacheId=h);return new n(s.paths,s.spatialReference,!0===s.hasZ,!0===s.hasM,h);case"type":return"Polyline"}break;case"multipoint":switch(i){case"points":h=s.cache._arcadeCacheId,void 0===h&&(d++,h=d,s.cache._arcadeCacheId=h);return new r(s.points,s.spatialReference,!0===s.hasZ,!0===s.hasM,h,1);case"type":return"Multipoint"}}if(1===u)throw new a(c,t.InvalidIdentifier,l);return 2===u?{keystate:"notfound"}:null}function x(e,a){let t,n=e;if(null==n)return null;if(u(a))t=a;else if(s(a))t=a.toArray();else{if(null==a)return null;t=[a]}for(const r of t){if(i(n)){if(!1===h(r))return null;if(!n.hasField(r))return null;n=n.field(r)}else if(c(n)){if(!1===h(r))return null;if(!n.hasField(r))return null;n=n.field(r)}else if(l(n)){if(!1===h(r))return null;n=y(n,r,null,null,0)}else if(u(n)){if(!1===p(r))return null;n=r>=0?n[r]:n[n.length+r]}else{if(!s(n))return null;if(!1===p(r))return null;n=r>=0?n.get(r):n.get(n.length()+r)}if(null==n)return null}return n}export{y as geometryMember,m as getGeometryKeys,x as getNestedOptionalValue};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{geometryMember as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as a}from"../executionError.js";import i from"../Feature.js";import o from"../ImmutablePointArray.js";import{B as l,m as s,s as f,M as c,C as m,n as u,v as p,f as h,g as w,k as y,j as R,i as g,b as d,H as P,z as v,F as I}from"../../chunks/languageUtils.js";import{angle2D as b,angleBetween2D as F,bearing2D as O,bearingBetween2D as S,pathsSelfIntersecting as j}from"./centroid.js";import N from"../../geometry/Extent.js";import x from"../../geometry/Geometry.js";import J from"../../geometry/Multipoint.js";import D from"../../geometry/Point.js";import G from"../../geometry/Polygon.js";import k from"../../geometry/Polyline.js";import{isClockwise as Z}from"../../geometry/support/coordsUtils.js";import{fromJSON as z}from"../../geometry/support/jsonUtils.js";import{isArray as W,isString as A,isNumber as M,isBoolean as q}from"../../support/guards.js";function L(L,U){L.ringisclockwise=function(e,t){return U(e,t,((n,i,f)=>{l(f,1,1,e,t);let c=[];if(null===f[0])return!1;if(W(f[0]))for(const o of f[0]){if(!(o instanceof D))throw new r(e,a.InvalidParameter,t);c.push(o.hasZ?o.hasM?[o.x,o.y,o.z,o.m]:[o.x,o.y,o.z]:[o.x,o.y])}else if(f[0]instanceof o)c=f[0]._elements;else{if(!s(f[0]))throw new r(e,a.InvalidParameter,t);for(const n of f[0].toArray()){if(!(n instanceof D))throw new r(e,a.InvalidParameter,t);c.push(n.hasZ?n.hasM?[n.x,n.y,n.z,n.m]:[n.x,n.y,n.z]:[n.x,n.y])}}return!(c.length<3)&&Z(c)}))},L.polygon=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof G==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof G)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new G(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.polyline=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof k==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof k)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new k(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.point=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof D==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof D)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new D(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.multipoint=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof J==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof J)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new J(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.extent=function(e,t){return U(e,t,((o,s,u)=>{u=m(u),l(u,1,1,e,t);let p=null;if(u[0]instanceof n)p=f(i.parseGeometryFromDictionary(u[0],e.spatialReference),e.spatialReference);else if(u[0]instanceof D){const e={xmin:u[0].x,ymin:u[0].y,xmax:u[0].x,ymax:u[0].y,spatialReference:u[0].spatialReference.toJSON()},t=u[0];t.hasZ?(e.zmin=t.z,e.zmax=t.z):t.hasM&&(e.mmin=t.m,e.mmax=t.m),p=z(e)}else if(u[0]instanceof G)p=z(u[0].extent?.toJSON());else if(u[0]instanceof k)p=z(u[0].extent?.toJSON());else if(u[0]instanceof J)p=z(u[0].extent?.toJSON());else if(u[0]instanceof N)p=z(u[0].toJSON());else{const t=JSON.parse(u[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),p=f(new N(t),e.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(p)}))},L.geometry=function(e,t){return U(e,t,((o,s,m)=>{l(m,1,1,e,t);let p=null;if(null===m[0])return null;if(u(m[0]))p=f(m[0].geometry(),e.spatialReference);else if(m[0]instanceof n)p=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),p=f(z(t),e.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(p)}))},L.setgeometry=function(e,t){return U(e,t,((n,i,o)=>{if(l(o,2,2,e,t),!u(o[0]))throw new r(e,a.InvalidParameter,t);if(!0===o[0].immutable)throw new r(e,a.Immutable,t);if(!(o[1]instanceof x||null===o[1]))throw new r(e,a.InvalidParameter,t);return o[0]._geometry=o[1],p}))},L.feature=function(e,t){return U(e,t,((o,l,s)=>{if(0===s.length)throw new r(e,a.WrongNumberOfParameters,t);let c;if(1===s.length)if(A(s[0]))c=i.fromJson(JSON.parse(s[0]),e.timeZone);else if(u(s[0]))c=i.createFromArcadeFeature(s[0]);else if(s[0]instanceof x)c=i.createFromGraphicLikeObject(s[0],null,null,e.timeZone);else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);{let t=s[0].hasField("geometry")?s[0].field("geometry"):null,r=s[0].hasField("attributes")?s[0].field("attributes"):null;null!==t&&t instanceof n&&(t=i.parseGeometryFromDictionary(t,e.spatialReference)),null!==r&&(r=i.parseAttributesFromDictionary(r)),c=i.createFromGraphicLikeObject(t,r,null,e.timeZone)}}else if(2===s.length){let o=null,l=null;if(null!==s[0])if(s[0]instanceof x)o=s[0];else{if(!(o instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}if(null!==s[1]){if(!(s[1]instanceof n))throw new r(e,a.InvalidParameter,t);l=i.parseAttributesFromDictionary(s[1])}c=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}else{let o=null;const l={};if(null!==s[0])if(s[0]instanceof x)o=s[0];else{if(!(o instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}for(let n=1;n<s.length;n+=2){const i=h(s[n]),o=s[n+1];if(!(null==o||A(o)||isNaN(o)||w(o)||M(o)||y(o)||R(o)||q(o)))throw new r(e,a.InvalidParameter,t);if(g(o)||!1===d(o))throw new r(e,a.InvalidParameter,t);l[i]=o===p?null:o}c=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}return c._geometry=f(c.geometry(),e.spatialReference),c.immutable=!1,c}))},L.dictionary=function(e,t){return U(e,t,((i,o,l)=>{if(0===l.length||1===l.length&&null===l[0]){const e=new n;return e.immutable=!1,e}if(1===l.length&&A(l[0]))try{const t=JSON.parse(l[0]),r=n.convertObjectToArcadeDictionary(t,P(e),!1);return r.immutable=!1,r}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof x)try{const t=l[0].toJSON();t.hasZ=!0===l[0].hasZ,t.hasM=!0===l[0].hasM;const r=n.convertObjectToArcadeDictionary(t,P(e),!1);return r.immutable=!1,r}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&u(l[0]))try{const e=new n;e.immutable=!1,e.setField("geometry",l[0].geometry());const t=new n;t.immutable=!1,e.setField("attributes",t);for(const n of l[0].keys())t.setField(n,l[0].field(n));return e}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof n)try{const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}catch(m){throw new r(e,a.InvalidParameter,t)}if(2===l.length&&l[0]instanceof n&&q(l[1]))try{if(!(!0===l[1])){const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}return l[0].deepClone()}catch(m){throw new r(e,a.InvalidParameter,t)}if(l.length%2!=0)throw new r(e,a.WrongNumberOfParameters,t);const f={};for(let n=0;n<l.length;n+=2){const i=h(l[n]),o=l[n+1];if(!(null==o||A(o)||isNaN(o)||w(o)||M(o)||q(o)||R(o)||y(o)||W(o)||s(o)))throw new r(e,a.InvalidParameter,t);if(g(o))throw new r(e,a.InvalidParameter,t);f[i]=o===p?null:o}const c=new n(f);return c.immutable=!1,c}))},L.haskey=function(t,i){return U(t,i,((o,s,f)=>{l(f,2,2,t,i);const c=h(f[1]);if(u(f[0]))return f[0].hasField(c);if(f[0]instanceof n)return f[0].hasField(c);if(f[0]instanceof x){const t=e(f[0],c,null,null,2);return!t||"notfound"!==t.keystate}throw new r(t,a.InvalidParameter,i)}))},L.hasvalue=function(e,n){return U(e,n,((r,a,i)=>(l(i,2,2,e,n),null!=t(i[0],i[1]))))},L.indexof=function(e,t){return U(e,t,((n,i,o)=>{l(o,2,2,e,t);const f=o[1];if(W(o[0])){for(let e=0;e<o[0].length;e++)if(v(f,o[0][e]))return e;return-1}if(s(o[0])){const e=o[0].length();for(let t=0;t<e;t++)if(v(f,o[0].get(t)))return t;return-1}throw new r(e,a.InvalidParameter,t)}))},L.angle=function(e,t){return U(e,t,((n,i,o)=>{if(o=m(o),l(o,2,3,e,t),!(o[0]instanceof D))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof D))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof D))throw new r(e,a.InvalidParameter,t);return 2===o.length?b(o[0],o[1]):F(o[0],o[1],o[2])}))},L.bearing=function(e,t){return U(e,t,((n,i,o)=>{if(o=m(o),l(o,2,3,e,t),!(o[0]instanceof D))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof D))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof D))throw new r(e,a.InvalidParameter,t);return 2===o.length?O(o[0],o[1]):S(o[0],o[1],o[2])}))},L.isselfintersecting=function(e,t){return U(e,t,((n,r,a)=>{a=m(a),l(a,1,1,e,t);let i=a[0];if(i instanceof G)return i.isSelfIntersecting;if(i instanceof k)return j(i.paths);if(i instanceof J){const e=i.points;for(let t=0;t<e.length;t++)for(let n=0;n<e.length;n++)if(n!==t){let r=!0;for(let a=0;a<e[t].length;a++)if(e[t][a]!==e[n][a]){r=!1;break}if(!0===r)return!0}}if(W(i)||s(i)){const t=I(i,e.spatialReference);return null!==t&&(i=t.paths),j(i)}return!1}))}}export{L as registerFunctions};
5
+ import{geometryMember as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as a}from"../executionError.js";import i from"../Feature.js";import o from"../ImmutablePointArray.js";import{B as l,m as s,s as f,M as c,C as m,n as u,v as p,f as h,g as w,k as y,j as R,i as g,b as d,H as P,z as v,F as I}from"../../chunks/languageUtils.js";import{angle2D as b,angleBetween2D as F,bearing2D as O,bearingBetween2D as S,pathsSelfIntersecting as j}from"./centroid.js";import N from"../../geometry/Extent.js";import x from"../../geometry/Geometry.js";import J from"../../geometry/Multipoint.js";import D from"../../geometry/Point.js";import G from"../../geometry/Polygon.js";import k from"../../geometry/Polyline.js";import{isClockwise as Z}from"../../geometry/support/coordsUtils.js";import{fromJSON as z}from"../../geometry/support/jsonUtils.js";import{isArray as W,isString as A,isNumber as M,isBoolean as q}from"../../support/guards.js";function L(L,U){L.ringisclockwise=function(e,t){return U(e,t,((n,i,f)=>{l(f,1,1,e,t);let c=[];if(null===f[0])return!1;if(W(f[0]))for(const o of f[0]){if(!(o instanceof D))throw new r(e,a.InvalidParameter,t);c.push(o.hasZ?o.hasM?[o.x,o.y,o.z,o.m]:[o.x,o.y,o.z]:[o.x,o.y])}else if(f[0]instanceof o)c=f[0]._elements;else{if(!s(f[0]))throw new r(e,a.InvalidParameter,t);for(const n of f[0].toArray()){if(!(n instanceof D))throw new r(e,a.InvalidParameter,t);c.push(n.hasZ?n.hasM?[n.x,n.y,n.z,n.m]:[n.x,n.y,n.z]:[n.x,n.y])}}return!(c.length<3)&&Z(c)}))},L.polygon=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof G==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof G)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new G(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.polyline=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof k==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof k)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new k(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.point=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof D==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof D)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new D(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.multipoint=function(e,t){return U(e,t,((o,s,m)=>{let u;if(l(m,1,1,e,t),m[0]instanceof n){const n=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);if(n instanceof J==!1)throw new r(e,a.InvalidParameter,t);u=n}else if(m[0]instanceof J)u=z(m[0].toJSON());else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=f(new J(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(u)}))},L.extent=function(e,t){return U(e,t,((o,s,u)=>{u=m(u),l(u,1,1,e,t);let p=null;if(u[0]instanceof n)p=f(i.parseGeometryFromDictionary(u[0],e.spatialReference),e.spatialReference);else if(u[0]instanceof D){const e={xmin:u[0].x,ymin:u[0].y,xmax:u[0].x,ymax:u[0].y,spatialReference:u[0].spatialReference.toJSON()},t=u[0];t.hasZ&&(e.zmin=t.z,e.zmax=t.z),t.hasM&&(e.mmin=t.m,e.mmax=t.m),p=z(e)}else if(u[0]instanceof G)p=z(u[0].extent?.toJSON());else if(u[0]instanceof k)p=z(u[0].extent?.toJSON());else if(u[0]instanceof J)p=z(u[0].extent?.toJSON());else if(u[0]instanceof N)p=z(u[0].toJSON());else{const t=JSON.parse(u[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),p=f(new N(t),e.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(p)}))},L.geometry=function(e,t){return U(e,t,((o,s,m)=>{l(m,1,1,e,t);let p=null;if(null===m[0])return null;if(u(m[0]))p=f(m[0].geometry(),e.spatialReference);else if(m[0]instanceof n)p=f(i.parseGeometryFromDictionary(m[0],e.spatialReference),e.spatialReference);else{const t=JSON.parse(m[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),p=f(z(t),e.spatialReference)}if(null!==p&&!1===p.spatialReference.equals(e.spatialReference))throw new r(e,a.WrongSpatialReference,t);return c(p)}))},L.setgeometry=function(e,t){return U(e,t,((n,i,o)=>{if(l(o,2,2,e,t),!u(o[0]))throw new r(e,a.InvalidParameter,t);if(!0===o[0].immutable)throw new r(e,a.Immutable,t);if(!(o[1]instanceof x||null===o[1]))throw new r(e,a.InvalidParameter,t);return o[0]._geometry=o[1],p}))},L.feature=function(e,t){return U(e,t,((o,l,s)=>{if(0===s.length)throw new r(e,a.WrongNumberOfParameters,t);let c;if(1===s.length)if(A(s[0]))c=i.fromJson(JSON.parse(s[0]),e.timeZone);else if(u(s[0]))c=i.createFromArcadeFeature(s[0]);else if(s[0]instanceof x)c=i.createFromGraphicLikeObject(s[0],null,null,e.timeZone);else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);{let t=s[0].hasField("geometry")?s[0].field("geometry"):null,r=s[0].hasField("attributes")?s[0].field("attributes"):null;null!==t&&t instanceof n&&(t=i.parseGeometryFromDictionary(t,e.spatialReference)),null!==r&&(r=i.parseAttributesFromDictionary(r)),c=i.createFromGraphicLikeObject(t,r,null,e.timeZone)}}else if(2===s.length){let o=null,l=null;if(null!==s[0])if(s[0]instanceof x)o=s[0];else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}if(null!==s[1]){if(!(s[1]instanceof n))throw new r(e,a.InvalidParameter,t);l=i.parseAttributesFromDictionary(s[1])}c=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}else{let o=null;const l={};if(null!==s[0])if(s[0]instanceof x)o=s[0];else{if(!(s[0]instanceof n))throw new r(e,a.InvalidParameter,t);o=i.parseGeometryFromDictionary(s[0],e.spatialReference)}for(let n=1;n<s.length;n+=2){const i=h(s[n]),o=s[n+1];if(!(null==o||A(o)||isNaN(o)||w(o)||M(o)||y(o)||R(o)||q(o)))throw new r(e,a.InvalidParameter,t);if(g(o)||!1===d(o))throw new r(e,a.InvalidParameter,t);l[i]=o===p?null:o}c=i.createFromGraphicLikeObject(o,l,null,e.timeZone)}return c._geometry=f(c.geometry(),e.spatialReference),c.immutable=!1,c}))},L.dictionary=function(e,t){return U(e,t,((i,o,l)=>{if(0===l.length||1===l.length&&null===l[0]){const e=new n;return e.immutable=!1,e}if(1===l.length&&A(l[0]))try{const t=JSON.parse(l[0]),r=n.convertObjectToArcadeDictionary(t,P(e),!1);return r.immutable=!1,r}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof x)try{const t=l[0].toJSON();t.hasZ=!0===l[0].hasZ,t.hasM=!0===l[0].hasM;const r=n.convertObjectToArcadeDictionary(t,P(e),!1);return r.immutable=!1,r}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&u(l[0]))try{const e=new n;e.immutable=!1,e.setField("geometry",l[0].geometry());const t=new n;t.immutable=!1,e.setField("attributes",t);for(const n of l[0].keys())t.setField(n,l[0].field(n));return e}catch(m){throw new r(e,a.InvalidParameter,t)}if(1===l.length&&l[0]instanceof n)try{const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}catch(m){throw new r(e,a.InvalidParameter,t)}if(2===l.length&&l[0]instanceof n&&q(l[1]))try{if(!(!0===l[1])){const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}return l[0].deepClone()}catch(m){throw new r(e,a.InvalidParameter,t)}if(l.length%2!=0)throw new r(e,a.WrongNumberOfParameters,t);const f={};for(let n=0;n<l.length;n+=2){const i=h(l[n]),o=l[n+1];if(!(null==o||A(o)||isNaN(o)||w(o)||M(o)||q(o)||R(o)||y(o)||W(o)||s(o)))throw new r(e,a.InvalidParameter,t);if(g(o))throw new r(e,a.InvalidParameter,t);f[i]=o===p?null:o}const c=new n(f);return c.immutable=!1,c}))},L.haskey=function(t,i){return U(t,i,((o,s,f)=>{l(f,2,2,t,i);const c=h(f[1]);if(u(f[0]))return f[0].hasField(c);if(f[0]instanceof n)return f[0].hasField(c);if(f[0]instanceof x){const t=e(f[0],c,null,null,2);return!t||"notfound"!==t.keystate}throw new r(t,a.InvalidParameter,i)}))},L.hasvalue=function(e,n){return U(e,n,((r,a,i)=>(l(i,2,2,e,n),null!=t(i[0],i[1]))))},L.indexof=function(e,t){return U(e,t,((n,i,o)=>{l(o,2,2,e,t);const f=o[1];if(W(o[0])){for(let e=0;e<o[0].length;e++)if(v(f,o[0][e]))return e;return-1}if(s(o[0])){const e=o[0].length();for(let t=0;t<e;t++)if(v(f,o[0].get(t)))return t;return-1}throw new r(e,a.InvalidParameter,t)}))},L.angle=function(e,t){return U(e,t,((n,i,o)=>{if(o=m(o),l(o,2,3,e,t),!(o[0]instanceof D))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof D))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof D))throw new r(e,a.InvalidParameter,t);return 2===o.length?b(o[0],o[1]):F(o[0],o[1],o[2])}))},L.bearing=function(e,t){return U(e,t,((n,i,o)=>{if(o=m(o),l(o,2,3,e,t),!(o[0]instanceof D))throw new r(e,a.InvalidParameter,t);if(!(o[1]instanceof D))throw new r(e,a.InvalidParameter,t);if(o.length>2&&!(o[2]instanceof D))throw new r(e,a.InvalidParameter,t);return 2===o.length?O(o[0],o[1]):S(o[0],o[1],o[2])}))},L.isselfintersecting=function(e,t){return U(e,t,((n,r,a)=>{a=m(a),l(a,1,1,e,t);let i=a[0];if(i instanceof G)return i.isSelfIntersecting;if(i instanceof k)return j(i.paths);if(i instanceof J){const e=i.points;for(let t=0;t<e.length;t++)for(let n=0;n<e.length;n++)if(n!==t){let r=!0;for(let a=0;a<e[t].length;a++)if(e[t][a]!==e[n][a]){r=!1;break}if(!0===r)return!0}}if(W(i)||s(i)){const t=I(i,e.spatialReference);return null!==t&&(i=t.paths),j(i)}return!1}))}}export{L as registerFunctions};
package/arcade/parser.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{r as o,T as n,o as e}from"../chunks/index.js";import{findScriptDependencies as i}from"./treeAnalysis.js";function d(d,r=[]){const s=o(d);if(null===s.body||void 0===s.body)throw new n({index:0,line:0,column:0,data:null,description:"",code:e.InvalidExpression});return s.loadedModules={},i(s,r),s}export{d as parseScript};
5
+ import{i as o,F as n,o as i}from"../chunks/index.js";import{findScriptDependencies as e}from"./treeAnalysis.js";function d(d,r=[]){const s=o(d);if(null===s.body||void 0===s.body)throw new n({index:0,line:0,column:0,data:null,description:"",code:i.InvalidExpression});return s.loadedModules={},e(s,r),s}export{d as parseScript};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{r as e,q as i,i as t,E as n,k as s,Q as a,j as o}from"../../chunks/index.js";import{DiagnosticCodes as r,diagnosticMessages as d}from"./diagnosticMessages.js";import{arcadeReservedKeywords as c}from"./languageKeywords.js";import{DiagnosticSeverity as l}from"./types.js";function h(e,i){return i?e.replaceAll(/\${(.*?)}/g,((e,t)=>i[t]?.toString()??"")):e}function f(e){return!!e&&"dictionary"!==e.type}class p{constructor(e,i=[]){this._apiDefinitions=e,this._profileVariables=i,this._isInBlock=!1,this._identifierBeingAssigned=void 0,this._assignmentValidationMode="disabled",this._scriptScopeIdentifiers=new Map,this._diagnostics=new Array,this._undeclaredIdentifiersInFunctions=new Map}validateScript(i){if(!i)return{diagnostics:[],program:null};this._isInBlock=!1,this._identifierBeingAssigned=void 0,this._assignmentValidationMode="disabled",this._diagnostics=[],this._scriptScopeIdentifiers.clear(),this._undeclaredIdentifiersInFunctions.clear(),this._functionScopeIdentifiers=void 0;let t=null;try{t=e(i,{tolerant:!0}),this.handleErrors(t.errors),t.body.forEach((e=>this.validateStatement(e))),this.diagnoseIdentifiers(),this._undeclaredIdentifiersInFunctions.size>0&&this._undeclaredIdentifiersInFunctions.forEach((e=>{for(const i of e)this.logDiagnostic(i.node.loc,{code:r.NotDefined,data:{identifier:i.node.name}})}))}catch(n){this.handleException(n)}return{diagnostics:this._diagnostics,program:t}}disableRecordIdentifierAssignment(e,i){const t=this._assignmentValidationMode;this._assignmentValidationMode="disabled",e.call(this,i),this._assignmentValidationMode=t}inBlock(e,i){const t=this._isInBlock;this._isInBlock=!0,e.call(this,i),this._isInBlock=t}get _isInFunctionScope(){return!!this._functionScopeIdentifiers}inFunctionScope(e){this._functionScopeIdentifiers=new Map,e.call(this),this.diagnoseIdentifiers(),this._functionScopeIdentifiers=void 0}logDiagnostic(e,t){const n={severity:l.Error,...t,message:h(d[t.code]??i[t.code],t.data),range:{start:{line:e.start.line-1,character:e.start.column},end:{line:e.end.line-1,character:e.end.column}}};this._diagnostics.push(n)}handleErrors(e){(e??[]).forEach(this.handleException,this)}handleException(e){if(g(e)){const{range:i,code:t,data:n}=e;this.logDiagnostic(i,{code:t,data:n})}else this.logDiagnostic({start:{line:1,column:0},end:{line:1,column:0}},{code:r.ExecutionError,data:{stack:e.stack}})}getIdentifierInfo(e){return this._functionScopeIdentifiers?.get(e)??this._scriptScopeIdentifiers.get(e)}setIdentiferInfo(e,i){this._functionScopeIdentifiers?this._functionScopeIdentifiers.set(e,i):((this._functionScopeIdentifiers??this._scriptScopeIdentifiers).set(e,i),this._functionScopeIdentifiers||this._undeclaredIdentifiersInFunctions.has(e)&&(this._undeclaredIdentifiersInFunctions.delete(e),i.used=!0))}isProfileVariable(e){return(this._profileVariables??[]).some((i=>i.name.toLowerCase()===e))}isApiItem(e){const i=!!this._apiDefinitions?.constantDefinitions?.get(e),t=!!this._apiDefinitions?.functionDefinitions?.get(e);return i||t}validateStatement(e){if(e)switch(e.type){case t.BlockStatement:return void e.body.forEach((e=>this.validateStatement(e)));case t.VariableDeclaration:return void e.declarations.forEach((e=>this.validateVariableDeclarator(e)));case t.FunctionDeclaration:return void this.validateFunctionDeclaration(e);case t.ExportNamedDeclaration:return void this.validateExportDeclaration(e);case t.ImportDeclaration:return void this.validateImportDeclaration(e);case t.WhileStatement:return void this.validateWhileStatement(e);case t.ForStatement:return void this.validateForStatement(e);case t.ForInStatement:return void this.validateForInStatement(e);case t.IfStatement:return void this.validateIfStatement(e);case t.ReturnStatement:return void this.validateExpression(e.argument);case t.ExpressionStatement:return void this.validateExpression(e.expression);case t.BreakStatement:case t.ContinueStatement:case t.EmptyStatement:return}}validateVariableDeclarator(e){this.validateExpression(e.init),this.recordVariableIdentifier(e.id,{initialized:!!e.init})}validateFunctionDeclaration(e){this.recordFunctionIdentifier(e),this.inFunctionScope((()=>{e.params.forEach((e=>this.recordParamAsIdentifier(e))),m(e.body)&&this.logDiagnostic(e.body.loc,{code:r.UnexpectedEmptyFunction,data:{identifier:e.id.name},severity:l.Warning}),this.validateStatement(e.body)}))}validateExportDeclaration(e){this.validateStatement(e.declaration)}validateImportDeclaration(e){this.recordImportIdentifier(e)}validateForStatement(e){n(e.init)?this.inBlock(this.validateStatement,e.init):this.validateExpression(e.init),this.validateExpression(e.update),this.validateExpression(e.test),m(e.body)&&this.logDiagnostic(e.body.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),this.inBlock(this.validateStatement,e.body)}validateWhileStatement(e){this.validateExpression(e.test),m(e.body)&&this.logDiagnostic(e.body.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),this.inBlock(this.validateStatement,e.body)}validateForInStatement(e){s(e.left)?this.validateExpression(e.left):this.recordVariableIdentifier(e.left.declarations[0].id,{initialized:!0,inBlock:!0}),this.validateExpression(e.right),m(e.body)&&this.logDiagnostic(e.body.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),this.validateStatement(e.body)}validateIfStatement(e){this.validateExpression(e.test),m(e.consequent)&&this.logDiagnostic(e.consequent.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),e.alternate&&m(e.alternate)&&this.logDiagnostic(e.alternate.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),this.inBlock(this.validateStatement,e.consequent),this.inBlock(this.validateStatement,e.alternate)}validateExpression(e){if(e)switch(e.type){case t.AssignmentExpression:return void this.validateAssignmentExpression(e);case t.CallExpression:return void this.validateCallExpression(e);case t.Identifier:return void this.validateIdentifier(e);case t.Literal:return void this.validateLiteral(e);case t.ArrayExpression:return void e.elements.forEach((e=>this.validateExpression(e)));case t.ObjectExpression:return void this.validateObjectExpression(e);case t.UnaryExpression:return void this.validateUnaryExpression(e);case t.UpdateExpression:return void this.validateUpdateExpression(e);case t.BinaryExpression:case t.LogicalExpression:return void this.validateBinaryAndLogicalExpression(e);case t.MemberExpression:return void this.validateMemberExpression(e);case t.TemplateLiteral:return void e.expressions.forEach((e=>this.validateExpression(e)));default:return}}validateAssignmentExpression(e){const i=this._identifierBeingAssigned,t=this._assignmentValidationMode;s(e.left)&&(this._identifierBeingAssigned=e.left.name.toLowerCase(),this._assignmentValidationMode="left"),this.validateExpression(e.left),s(e.left)&&(this._assignmentValidationMode="right"),this.validateExpression(e.right),this._identifierBeingAssigned=i,this._assignmentValidationMode=t}validateCallExpression(e){if(this.validateExpression(e.callee),s(e.callee)){const i=e.callee.name.toLowerCase(),t=this.getIdentifierInfo(i),n=this._apiDefinitions?.functionDefinitions?.get(i);if(!t&&n){const i=u(n,e.arguments.length);i&&this.logDiagnostic(e.loc,i)}}e.arguments.forEach((e=>this.validateExpression(e)))}validateIdentifier(e){const i=e.name.toLowerCase(),t=this.getIdentifierInfo(i);if(t){if("left"===this._assignmentValidationMode&&this._identifierBeingAssigned===i)return void(t.initialized=!0);if("right"===this._assignmentValidationMode&&this._identifierBeingAssigned===i)return;t.used=!0}else if(!this.isProfileVariable(i)&&!this.isApiItem(i)){if(this._isInFunctionScope){let t=this._undeclaredIdentifiersInFunctions.get(i);return t||(t=[],this._undeclaredIdentifiersInFunctions.set(i,t)),void t.push({node:e,identifier:i})}this.logDiagnostic(e.loc,{code:r.NotDefined,data:{identifier:e.name}})}}validateLiteral(e){I(e.raw).forEach((e=>{const i=this.getIdentifierInfo(e.toLowerCase());i&&(i.used=!0)}))}logProfileOrApiConflict(e){const i=e.name.toLowerCase(),t=this.isProfileVariable(i),n=this.isApiItem(i);(t||n)&&this.logDiagnostic(e.loc,{code:t?r.ProfileVariablesConflict:r.ApiConflict,severity:l.Warning,data:{identifier:e.name}})}logReservedKeywordsConflict(e){const i=e.name.toLowerCase();c.includes(i)&&this.logDiagnostic(e.loc,{code:r.ReservedKeyword,severity:l.Warning,data:{identifier:e.name}})}validateObjectExpression(e){e.properties.forEach((e=>{this.validateExpression(e.value)}))}validateUnaryExpression(e){this.validateExpression(e.argument)}validateUpdateExpression(e){this.validateExpression(e.argument)}validateBinaryAndLogicalExpression(e){this.validateExpression(e.left),this.validateExpression(e.right)}validateMemberExpression(e){const i=this.flattenMemberExpressionAndValidate(e),t=i[0].object;this.disableRecordIdentifierAssignment(this.validateExpression,t),s(t)&&(this.getIdentifierInfo(t.name.toLowerCase())||this.validateMemberExpressionWithProfile(i)||this.validateConstantMemberExpression(i))}flattenMemberExpressionAndValidate(e){return e.type===t.MemberExpression?(s(e.property)&&!e.computed||this.validateExpression(e.property),[...this.flattenMemberExpressionAndValidate(e.object),e]):[]}extractAndValidatePropertyName(e){switch(e.type){case"Identifier":return e.name.toLowerCase();case"Literal":return"string"!=typeof e.value?(this.logDiagnostic(e.loc,{code:r.UnexpectedPropertyIdentifier}),null):e.value.toLowerCase();default:return this.logDiagnostic(e.loc,{code:r.UnexpectedPropertyIdentifier}),null}}validateConstantMemberExpression(e){const i=e[0];if(!s(i.object))return!1;const t=i.object.name.toLowerCase(),n=this._apiDefinitions?.constantDefinitions?.get(t);if(!n)return!1;if("namespace"!==n.type)return this.logDiagnostic(i.property.loc,{code:r.NotADictionary,data:{identifier:t}}),!0;const a=this.extractAndValidatePropertyName(i.property);if(!a)return!0;if(!n.members.some((e=>e.key===a))){const e=n.members.reduce(((e,i)=>`${e}${e?" | ":""}${i.completion.label.split(".").pop()}`),"");this.logDiagnostic(i.property.loc,{code:r.InvalidConstantIdentifier,data:{list:e}})}return e.length>1&&this.logDiagnostic(e[1].property.loc,{code:r.UnexpectedPropertyIdentifier}),!0}validateMemberExpressionWithProfile(e){const i=e[0];if(i.object.type!==t.Identifier)return!1;const n=i.object.name.toLowerCase(),s=this._profileVariables?.find((e=>e.key===n));if(!s)return!1;if(f(s))return this.logDiagnostic(i.object.loc,{code:r.NotADictionary,data:{identifier:s.name}}),!0;if(this._identifierBeingAssigned===n)return this.logDiagnostic(i.loc,{code:r.ProfileVariablesAreImmutable}),!0;let a=s;for(let t=0;t<e.length;t++){if(e[t].computed)return!0;if(f(a))return this.logDiagnostic(e[t-1]?.property.loc??e[t].object.loc,{code:r.NotADictionary,data:{identifier:a.name}}),!0;const i=this.extractAndValidatePropertyName(e[t].property);if(!i)return!0;if(0===a.properties.length)return this.logDiagnostic(e[t].property.loc,{code:r.UnknownPropertyIdentifier,data:{identifier:i},severity:l.Warning}),!0;const n=a.properties.find((e=>e.name.toLowerCase()===i));if(!n){const i=a.properties.reduce(((e,i)=>`${e}${e?" | ":""}${i.name.split(".").pop()}`),"");return this.logDiagnostic(e[t].property.loc,{code:r.InvalidPropertyIdentifier,data:{list:i}}),!0}a=n}return!0}recordVariableIdentifier(e,i){this.logReservedKeywordsConflict(e),this.logProfileOrApiConflict(e);const t=e.name.toLowerCase();let n=this.getIdentifierInfo(t);const s=n&&this._isInFunctionScope&&"function"===n.scope,a=n&&!this._isInFunctionScope&&"script"===n.scope;(s||a)&&this.logDiagnostic(e.loc,{code:r.AlreadyDefined,data:{identifier:e.name},severity:l.Warning});const o=i.inBlock??this._isInBlock,{initialized:d}=i;if(!n||this._isInFunctionScope&&"function"!==n.scope){n={node:e,used:!1,initialized:d,scope:this._isInFunctionScope?"function":o?"block":"script"}}else n.node=e,n.used=!1,n.initialized=d;return"block"!==n.scope||o||(n.scope="script",this.logDiagnostic(e.loc,{code:r.AlreadyDefined,data:{identifier:e.name},severity:l.Warning})),this.setIdentiferInfo(t,n),!1}recordImportIdentifier(e){const i=e.specifiers[0].local;this.logProfileOrApiConflict(i);const t=i.name.toLowerCase();let n=this.getIdentifierInfo(t);n?.scope&&this.logDiagnostic(e.specifiers[0].local.loc,{code:r.AlreadyDefined,data:{identifier:e.specifiers[0].local.name},severity:l.Warning}),n={node:e.specifiers[0].local,used:!1,...n,scope:"script",initialized:!0},this.setIdentiferInfo(t,n)}recordFunctionIdentifier(e){this.logProfileOrApiConflict(e.id);const i=e.id.name.toLowerCase();let t=this.getIdentifierInfo(i);t?.scope&&this.logDiagnostic(e.id.loc,{code:r.AlreadyDefined,data:{identifier:e.id.name},severity:l.Warning}),t={node:e.id,used:!1,...t,scope:"script",initialized:!0},this.setIdentiferInfo(i,t)}recordParamAsIdentifier(e){return this.recordVariableIdentifier(e,{initialized:!0})}diagnoseIdentifiers(){(this._functionScopeIdentifiers??this._scriptScopeIdentifiers).forEach((e=>{e.node&&(e.used?e.initialized||this.logDiagnostic(e.node.loc,{code:r.DefinedNeverAssigned,data:{identifier:e.node.name},severity:l.Warning}):this.logDiagnostic(e.node.loc,{code:e.initialized?r.AssignedNeverUsed:r.DefinedNeverUsed,data:{identifier:e.node.name},severity:l.Warning}))}))}}function g(e){return"ParsingError"===e?.name}function m(e){return a(e)||o(e)&&!e?.body.length}function u(e,i){if(!e||null==i||i<0)return null;const{min:t,max:n}=e.overloads.reduce(((e,i)=>{const{min:t,max:n}=i.parametersInfo;return e.min>=0&&(e.min=Math.min(t,e.min)),e.max>=0&&(e.max=n<0?n:Math.max(n,e.max)),e}),{min:1/0,max:0});return i<t?t>0?{code:r.NotEnoughArguments,data:{min:t}}:{code:r.NoArgumentExpected}:n>=0&&i>n?{code:r.TooManyArguments,data:{max:n}}:null}const v=new RegExp(/\B@\w+/g);function I(e){return Array.from((e??"").matchAll(v),(e=>e[0].slice(1)))}function E(e,i=[],t){if(!e)return{diagnostics:[]};return new p(t,i).validateScript(e)}export{p as ArcadeValidationService,h as format,f as isValueVariable,E as validateScript};
5
+ import{i as e,$ as i,a as t,f as n,B as s,Y as a,V as o}from"../../chunks/index.js";import{DiagnosticCodes as r,diagnosticMessages as d}from"./diagnosticMessages.js";import{arcadeReservedKeywords as c}from"./languageKeywords.js";import{DiagnosticSeverity as l}from"./types.js";function h(e,i){return i?e.replaceAll(/\${(.*?)}/g,((e,t)=>i[t]?.toString()??"")):e}function f(e){return!!e&&"dictionary"!==e.type}class p{constructor(e,i=[]){this._apiDefinitions=e,this._profileVariables=i,this._isInBlock=!1,this._identifierBeingAssigned=void 0,this._assignmentValidationMode="disabled",this._scriptScopeIdentifiers=new Map,this._diagnostics=new Array,this._undeclaredIdentifiersInFunctions=new Map}validateScript(i){if(!i)return{diagnostics:[],program:null};this._isInBlock=!1,this._identifierBeingAssigned=void 0,this._assignmentValidationMode="disabled",this._diagnostics=[],this._scriptScopeIdentifiers.clear(),this._undeclaredIdentifiersInFunctions.clear(),this._functionScopeIdentifiers=void 0;let t=null;try{t=e(i,{tolerant:!0}),this.handleErrors(t.errors),t.body.forEach((e=>this.validateStatement(e))),this.diagnoseIdentifiers(),this._undeclaredIdentifiersInFunctions.size>0&&this._undeclaredIdentifiersInFunctions.forEach((e=>{for(const i of e)this.logDiagnostic(i.node.loc,{code:r.NotDefined,data:{identifier:i.node.name}})}))}catch(n){this.handleException(n)}return{diagnostics:this._diagnostics,program:t}}disableRecordIdentifierAssignment(e,i){const t=this._assignmentValidationMode;this._assignmentValidationMode="disabled",e.call(this,i),this._assignmentValidationMode=t}inBlock(e,i){const t=this._isInBlock;this._isInBlock=!0,e.call(this,i),this._isInBlock=t}get _isInFunctionScope(){return!!this._functionScopeIdentifiers}inFunctionScope(e){this._functionScopeIdentifiers=new Map,e.call(this),this.diagnoseIdentifiers(),this._functionScopeIdentifiers=void 0}logDiagnostic(e,t){const n={severity:l.Error,...t,message:h(d[t.code]??i[t.code],t.data),range:{start:{line:e.start.line-1,character:e.start.column},end:{line:e.end.line-1,character:e.end.column}}};this._diagnostics.push(n)}handleErrors(e){(e??[]).forEach(this.handleException,this)}handleException(e){if(g(e)){const{range:i,code:t,data:n}=e;this.logDiagnostic(i,{code:t,data:n})}else this.logDiagnostic({start:{line:1,column:0},end:{line:1,column:0}},{code:r.ExecutionError,data:{stack:e.stack}})}getIdentifierInfo(e){return this._functionScopeIdentifiers?.get(e)??this._scriptScopeIdentifiers.get(e)}setIdentiferInfo(e,i){this._functionScopeIdentifiers?this._functionScopeIdentifiers.set(e,i):((this._functionScopeIdentifiers??this._scriptScopeIdentifiers).set(e,i),this._functionScopeIdentifiers||this._undeclaredIdentifiersInFunctions.has(e)&&(this._undeclaredIdentifiersInFunctions.delete(e),i.used=!0))}isProfileVariable(e){return(this._profileVariables??[]).some((i=>i.name.toLowerCase()===e))}isApiItem(e){const i=!!this._apiDefinitions?.constantDefinitions?.get(e),t=!!this._apiDefinitions?.functionDefinitions?.get(e);return i||t}validateStatement(e){if(e)switch(e.type){case t.BlockStatement:return void e.body.forEach((e=>this.validateStatement(e)));case t.VariableDeclaration:return void e.declarations.forEach((e=>this.validateVariableDeclarator(e)));case t.FunctionDeclaration:return void this.validateFunctionDeclaration(e);case t.ExportNamedDeclaration:return void this.validateExportDeclaration(e);case t.ImportDeclaration:return void this.validateImportDeclaration(e);case t.WhileStatement:return void this.validateWhileStatement(e);case t.ForStatement:return void this.validateForStatement(e);case t.ForInStatement:return void this.validateForInStatement(e);case t.IfStatement:return void this.validateIfStatement(e);case t.ReturnStatement:return void this.validateExpression(e.argument);case t.ExpressionStatement:return void this.validateExpression(e.expression);case t.BreakStatement:case t.ContinueStatement:case t.EmptyStatement:return}}validateVariableDeclarator(e){this.validateExpression(e.init),this.recordVariableIdentifier(e.id,{initialized:!!e.init})}validateFunctionDeclaration(e){this.recordFunctionIdentifier(e),this.inFunctionScope((()=>{e.params.forEach((e=>this.recordParamAsIdentifier(e))),m(e.body)&&this.logDiagnostic(e.body.loc,{code:r.UnexpectedEmptyFunction,data:{identifier:e.id.name},severity:l.Warning}),this.validateStatement(e.body)}))}validateExportDeclaration(e){this.validateStatement(e.declaration)}validateImportDeclaration(e){this.recordImportIdentifier(e)}validateForStatement(e){n(e.init)?this.inBlock(this.validateStatement,e.init):this.validateExpression(e.init),this.validateExpression(e.update),this.validateExpression(e.test),m(e.body)&&this.logDiagnostic(e.body.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),this.inBlock(this.validateStatement,e.body)}validateWhileStatement(e){this.validateExpression(e.test),m(e.body)&&this.logDiagnostic(e.body.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),this.inBlock(this.validateStatement,e.body)}validateForInStatement(e){s(e.left)?this.validateExpression(e.left):this.recordVariableIdentifier(e.left.declarations[0].id,{initialized:!0,inBlock:!0}),this.validateExpression(e.right),m(e.body)&&this.logDiagnostic(e.body.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),this.validateStatement(e.body)}validateIfStatement(e){this.validateExpression(e.test),m(e.consequent)&&this.logDiagnostic(e.consequent.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),e.alternate&&m(e.alternate)&&this.logDiagnostic(e.alternate.loc,{code:r.EmptyBlockStatement,severity:l.Warning}),this.inBlock(this.validateStatement,e.consequent),this.inBlock(this.validateStatement,e.alternate)}validateExpression(e){if(e)switch(e.type){case t.AssignmentExpression:return void this.validateAssignmentExpression(e);case t.CallExpression:return void this.validateCallExpression(e);case t.Identifier:return void this.validateIdentifier(e);case t.Literal:return void this.validateLiteral(e);case t.ArrayExpression:return void e.elements.forEach((e=>this.validateExpression(e)));case t.ObjectExpression:return void this.validateObjectExpression(e);case t.UnaryExpression:return void this.validateUnaryExpression(e);case t.UpdateExpression:return void this.validateUpdateExpression(e);case t.BinaryExpression:case t.LogicalExpression:return void this.validateBinaryAndLogicalExpression(e);case t.MemberExpression:return void this.validateMemberExpression(e);case t.TemplateLiteral:return void e.expressions.forEach((e=>this.validateExpression(e)));default:return}}validateAssignmentExpression(e){const i=this._identifierBeingAssigned,t=this._assignmentValidationMode;s(e.left)&&(this._identifierBeingAssigned=e.left.name.toLowerCase(),this._assignmentValidationMode="left"),this.validateExpression(e.left),s(e.left)&&(this._assignmentValidationMode="right"),this.validateExpression(e.right),this._identifierBeingAssigned=i,this._assignmentValidationMode=t}validateCallExpression(e){if(this.validateExpression(e.callee),s(e.callee)){const i=e.callee.name.toLowerCase(),t=this.getIdentifierInfo(i),n=this._apiDefinitions?.functionDefinitions?.get(i);if(!t&&n){const i=u(n,e.arguments.length);i&&this.logDiagnostic(e.loc,i)}}e.arguments.forEach((e=>this.validateExpression(e)))}validateIdentifier(e){const i=e.name.toLowerCase(),t=this.getIdentifierInfo(i);if(t){if("left"===this._assignmentValidationMode&&this._identifierBeingAssigned===i)return void(t.initialized=!0);if("right"===this._assignmentValidationMode&&this._identifierBeingAssigned===i)return;t.used=!0}else if(!this.isProfileVariable(i)&&!this.isApiItem(i)){if(this._isInFunctionScope){let t=this._undeclaredIdentifiersInFunctions.get(i);return t||(t=[],this._undeclaredIdentifiersInFunctions.set(i,t)),void t.push({node:e,identifier:i})}this.logDiagnostic(e.loc,{code:r.NotDefined,data:{identifier:e.name}})}}validateLiteral(e){I(e.raw).forEach((e=>{const i=this.getIdentifierInfo(e.toLowerCase());i&&(i.used=!0)}))}logProfileOrApiConflict(e){const i=e.name.toLowerCase(),t=this.isProfileVariable(i),n=this.isApiItem(i);(t||n)&&this.logDiagnostic(e.loc,{code:t?r.ProfileVariablesConflict:r.ApiConflict,severity:l.Warning,data:{identifier:e.name}})}logReservedKeywordsConflict(e){const i=e.name.toLowerCase();c.includes(i)&&this.logDiagnostic(e.loc,{code:r.ReservedKeyword,severity:l.Warning,data:{identifier:e.name}})}validateObjectExpression(e){e.properties.forEach((e=>{this.validateExpression(e.value)}))}validateUnaryExpression(e){this.validateExpression(e.argument)}validateUpdateExpression(e){this.validateExpression(e.argument)}validateBinaryAndLogicalExpression(e){this.validateExpression(e.left),this.validateExpression(e.right)}validateMemberExpression(e){const i=this.flattenMemberExpressionAndValidate(e),t=i[0].object;this.disableRecordIdentifierAssignment(this.validateExpression,t),s(t)&&(this.getIdentifierInfo(t.name.toLowerCase())||this.validateMemberExpressionWithProfile(i)||this.validateConstantMemberExpression(i))}flattenMemberExpressionAndValidate(e){return e.type===t.MemberExpression?(s(e.property)&&!e.computed||this.validateExpression(e.property),[...this.flattenMemberExpressionAndValidate(e.object),e]):[]}extractAndValidatePropertyName(e){switch(e.type){case"Identifier":return e.name.toLowerCase();case"Literal":return"string"!=typeof e.value?(this.logDiagnostic(e.loc,{code:r.UnexpectedPropertyIdentifier}),null):e.value.toLowerCase();default:return this.logDiagnostic(e.loc,{code:r.UnexpectedPropertyIdentifier}),null}}validateConstantMemberExpression(e){const i=e[0];if(!s(i.object))return!1;const t=i.object.name.toLowerCase(),n=this._apiDefinitions?.constantDefinitions?.get(t);if(!n)return!1;if("namespace"!==n.type)return this.logDiagnostic(i.property.loc,{code:r.NotADictionary,data:{identifier:t}}),!0;const a=this.extractAndValidatePropertyName(i.property);if(!a)return!0;if(!n.members.some((e=>e.key===a))){const e=n.members.reduce(((e,i)=>`${e}${e?" | ":""}${i.completion.label.split(".").pop()}`),"");this.logDiagnostic(i.property.loc,{code:r.InvalidConstantIdentifier,data:{list:e}})}return e.length>1&&this.logDiagnostic(e[1].property.loc,{code:r.UnexpectedPropertyIdentifier}),!0}validateMemberExpressionWithProfile(e){const i=e[0];if(i.object.type!==t.Identifier)return!1;const n=i.object.name.toLowerCase(),s=this._profileVariables?.find((e=>e.key===n));if(!s)return!1;if(f(s))return this.logDiagnostic(i.object.loc,{code:r.NotADictionary,data:{identifier:s.name}}),!0;if(this._identifierBeingAssigned===n)return this.logDiagnostic(i.loc,{code:r.ProfileVariablesAreImmutable}),!0;let a=s;for(let t=0;t<e.length;t++){if(e[t].computed)return!0;if(f(a))return this.logDiagnostic(e[t-1]?.property.loc??e[t].object.loc,{code:r.NotADictionary,data:{identifier:a.name}}),!0;const i=this.extractAndValidatePropertyName(e[t].property);if(!i)return!0;if(0===a.properties.length)return this.logDiagnostic(e[t].property.loc,{code:r.UnknownPropertyIdentifier,data:{identifier:i},severity:l.Warning}),!0;const n=a.properties.find((e=>e.name.toLowerCase()===i));if(!n){const i=a.properties.reduce(((e,i)=>`${e}${e?" | ":""}${i.name.split(".").pop()}`),"");return this.logDiagnostic(e[t].property.loc,{code:r.InvalidPropertyIdentifier,data:{list:i}}),!0}a=n}return!0}recordVariableIdentifier(e,i){this.logReservedKeywordsConflict(e),this.logProfileOrApiConflict(e);const t=e.name.toLowerCase();let n=this.getIdentifierInfo(t);const s=n&&this._isInFunctionScope&&"function"===n.scope,a=n&&!this._isInFunctionScope&&"script"===n.scope;(s||a)&&this.logDiagnostic(e.loc,{code:r.AlreadyDefined,data:{identifier:e.name},severity:l.Warning});const o=i.inBlock??this._isInBlock,{initialized:d}=i;if(!n||this._isInFunctionScope&&"function"!==n.scope){n={node:e,used:!1,initialized:d,scope:this._isInFunctionScope?"function":o?"block":"script"}}else n.node=e,n.used=!1,n.initialized=d;return"block"!==n.scope||o||(n.scope="script",this.logDiagnostic(e.loc,{code:r.AlreadyDefined,data:{identifier:e.name},severity:l.Warning})),this.setIdentiferInfo(t,n),!1}recordImportIdentifier(e){const i=e.specifiers[0].local;this.logProfileOrApiConflict(i);const t=i.name.toLowerCase();let n=this.getIdentifierInfo(t);n?.scope&&this.logDiagnostic(e.specifiers[0].local.loc,{code:r.AlreadyDefined,data:{identifier:e.specifiers[0].local.name},severity:l.Warning}),n={node:e.specifiers[0].local,used:!1,...n,scope:"script",initialized:!0},this.setIdentiferInfo(t,n)}recordFunctionIdentifier(e){this.logProfileOrApiConflict(e.id);const i=e.id.name.toLowerCase();let t=this.getIdentifierInfo(i);t?.scope&&this.logDiagnostic(e.id.loc,{code:r.AlreadyDefined,data:{identifier:e.id.name},severity:l.Warning}),t={node:e.id,used:!1,...t,scope:"script",initialized:!0},this.setIdentiferInfo(i,t)}recordParamAsIdentifier(e){return this.recordVariableIdentifier(e,{initialized:!0})}diagnoseIdentifiers(){(this._functionScopeIdentifiers??this._scriptScopeIdentifiers).forEach((e=>{e.node&&(e.used?e.initialized||this.logDiagnostic(e.node.loc,{code:r.DefinedNeverAssigned,data:{identifier:e.node.name},severity:l.Warning}):this.logDiagnostic(e.node.loc,{code:e.initialized?r.AssignedNeverUsed:r.DefinedNeverUsed,data:{identifier:e.node.name},severity:l.Warning}))}))}}function g(e){return"ParsingError"===e?.name}function m(e){return a(e)||o(e)&&!e?.body.length}function u(e,i){if(!e||null==i||i<0)return null;const{min:t,max:n}=e.overloads.reduce(((e,i)=>{const{min:t,max:n}=i.parametersInfo;return e.min>=0&&(e.min=Math.min(t,e.min)),e.max>=0&&(e.max=n<0?n:Math.max(n,e.max)),e}),{min:1/0,max:0});return i<t?t>0?{code:r.NotEnoughArguments,data:{min:t}}:{code:r.NoArgumentExpected}:n>=0&&i>n?{code:r.TooManyArguments,data:{max:n}}:null}const v=new RegExp(/\B@\w+/g);function I(e){return Array.from((e??"").matchAll(v),(e=>e[0].slice(1)))}function y(e,i=[],t){if(!e)return{diagnostics:[]};return new p(t,i).validateScript(e)}export{p as ArcadeValidationService,h as format,f as isValueVariable,y as validateScript};