// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/arcade/arcadeAsyncRuntime","require exports ../geometry/Geometry ../geometry/Polygon ../geometry/Polyline ../geometry/Point ../geometry/Extent ../geometry/Multipoint ../SpatialReference dojo/promise/all dojo/Deferred dojo/promise/Promise ./languageUtils ./treeAnalysis ./Dictionary ./Feature ./FunctionWrapper ./functions/date ./functions/maths ./functions/geometry ./ImmutablePathArray ./ImmutablePointArray ./kernel ./functions/string ./functions/stats ./functions/geomasync".split(" "),
function(L,t,M,ca,da,ea,fa,ga,ha,A,m,ia,f,n,u,w,D,ja,ka,la,N,ma,g,na,oa,pa){function p(b){var a=new m;b instanceof Error?a.reject(b):a.reject(Error(b));return a.promise}function O(b){var a=new m;a.resolve(b);return a.promise}function F(b,a){for(var c=new m,d=[],e=0;e<a.arguments.length;e++)d.push(h(b,a.arguments[e]));A(d).then(g.callback(function(a){c.resolve(a)},c),g.errback(c));return c.promise}function v(b,a,c){var d=new m;try{return F(b,a).then(g.callback(function(e){d.resolve(c(b,a,e))},d),g.errback(d)),
d.promise}catch(e){return p(e)}}function B(b,a,c){var d=new m;try{return F(b,a).then(g.callback(function(e){e=c(b,a,e);e instanceof ia?e.then(g.callback(function(c){d.resolve(c)},d),g.errback(d)):d.resolve(e)},d),g.errback(d)),d.promise}catch(e){return p(e)}}function h(b,a){try{switch(a.type){case "VariableDeclarator":return qa(b,a);case "VariableDeclaration":return P(b,a,0);case "BlockStatement":return ra(b,a);case "FunctionDeclaration":var c=new m;try{var d=a.id.name.toLowerCase();b.globalScope[d]=
{valueset:!0,node:null,value:new D(a,b)};c.resolve(f.voidOperation)}catch(q){c.reject(q)}return c.promise;case "ReturnStatement":return sa(b,a);case "IfStatement":return ta(b,a);case "ExpressionStatement":return ua(b,a);case "UpdateExpression":return va(b,a);case "AssignmentExpression":return wa(b,a);case "ForStatement":return xa(b,a);case "ForInStatement":return ya(b,a);case "BreakStatement":var e=new m;e.resolve(f.breakResult);return e.promise;case "EmptyStatement":var g=new m;g.resolve(f.voidOperation);
return g.promise;case "ContinueStatement":var l=new m;l.resolve(f.continueResult);return l.promise;case "Identifier":return G(b,a);case "MemberExpression":return za(b,a);case "Literal":return O(a.value);case "ThisExpression":return p(n.nodeErrorMessage(a,"RUNTIME","NOTSUPPORTED"));case "CallExpression":return Aa(b,a);case "UnaryExpression":return Ba(b,a);case "BinaryExpression":return Ca(b,a);case "LogicalExpression":return Da(b,a);case "ConditionalExpression":return p(n.nodeErrorMessage(a,"RUNTIME",
"NOTSUPPORTED"));case "ArrayExpression":return Ea(b,a);case "ObjectExpression":return Fa(b,a);case "Property":return Ga(b,a);case "Array":return p(n.nodeErrorMessage(a,"RUNTIME","NOTSUPPORTED"));default:return p(n.nodeErrorMessage(a,"RUNTIME","UNREOGNISED"))}}catch(q){return p(q)}}function Fa(b,a){try{for(var c=new m,d=[],e=0;e<a.properties.length;e++)d.push(h(b,a.properties[e]));A(d).then(g.callback(function(a){for(var b={},d=0;d<a.length;d++){var e=a[d];if(f.isFunctionParameter(e.value))throw Error("Illegal Argument");
if(!1===f.isString(e.key))throw Error("Illegal Argument");b[e.key.toString()]=e.value===f.voidOperation?null:e.value}a=new u(b);a.immutable=!1;c.resolve(a)},c),g.errback(c));return c.promise}catch(k){return p(k)}}function Ga(b,a){var c=new m;try{h(b,a.value).then(g.callback(function(b){c.resolve({key:"Identifier"===a.key.type?a.key.name:a.key.value,value:b})},c),g.errback(c))}catch(d){c.reject(d)}return c.promise}function Q(b,a,c){var d=new m;try{h(b,a.body).then(g.callback(function(e){c.lastAction=
e;c.lastAction===f.breakResult?(c.testResult=!1,d.resolve(c)):c.lastAction instanceof f.ReturnResult?(c.testResult=!1,d.resolve(c)):null!==a.update?h(b,a.update).then(g.callback(function(a){d.resolve(c)},d),g.errback(d)):d.resolve(c)},d),g.errback(d))}catch(e){d.reject(e)}return d.promise}function Ia(b,a,c){var d=new m;try{return null!==a.test?(h(b,a.test).then(g.callback(function(e){!0===b.progressTracker.isCanceled()?d.reject(Error("Cancelled")):(c.testResult=e,!1===c.testResult?d.resolve(c):!0!==
c.testResult?d.reject(Error(n.nodeErrorMessage(a,"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION"))):Q(b,a,c).then(g.callback(function(c){d.resolve(c)},d),g.errback(d)))},d),g.errback(d)),d.promise):Q(b,a,c)}catch(e){d.reject(e)}return d.promise}function H(b,a,c){var d=new m;try{Ia(b,a,c).then(g.callback(function(){!0===c.testResult?H(b,a,c).then(g.callback(function(c){d.resolve(c)},d),g.errback(d)):c.lastAction instanceof f.ReturnResult?d.resolve(c.lastAction):d.resolve(f.voidOperation)},d),g.errback(d))}catch(e){d.reject(e)}return d.promise}
function xa(b,a){var c=new m;try{null!==a.init?h(b,a.init).then(g.callback(function(){H(b,a,{testResult:!0,lastAction:f.voidOperation}).then(g.callback(function(a){c.resolve(a)},c),g.errback(c))},c),g.errback(c)):H(b,a,{testResult:!0,lastAction:f.voidOperation}).then(g.callback(function(a){c.resolve(a)},c),g.errback(c))}catch(d){c.reject(d)}return c.promise}function R(b,a,c,d,e,k,l){var q=new m;try{if(d<=k)return q.resolve(f.voidOperation),q.promise;e.value="k"===l?c[k]:k;h(b,a.body).then(g.callback(function(h){h instanceof
f.ReturnResult?q.resolve(h):h===f.breakResult?q.resolve(f.voidOperation):R(b,a,c,d,e,k+1,l).then(g.callback(function(c){q.resolve(c)},q),g.errback(q))},q),g.errback(q))}catch(Ha){q.reject(Ha)}return q.promise}function S(b,a,c,d,e,k){var l=new m;try{if(c.length()<=e)return l.resolve(f.voidOperation),l.promise;d.value="k"===k?c.get(e):e;h(b,a.body).then(g.callback(function(q){q instanceof f.ReturnResult?l.resolve(q):q===f.breakResult?l.resolve(f.voidOperation):S(b,a,c,d,e+1,k).then(g.callback(function(c){l.resolve(c)},
l),g.errback(l))},l),g.errback(l))}catch(q){l.reject(q)}return l.promise}function I(b,a,c,d,e,k){try{void 0===k&&(k="i"),0===c.length?d.resolve(f.voidOperation):R(b,a,c,c.length,e,0,k).then(g.callback(function(c){d.resolve(c)},d),g.errback(d))}catch(l){d.reject(l)}}function Ja(b,a,c,d,e,k){try{void 0===k&&(k="i"),0===c.length?d.resolve(f.voidOperation):S(b,a,c,e,0,k).then(g.callback(function(c){d.resolve(c)},d),g.errback(d))}catch(l){d.reject(l)}}function Ka(b,a,c,d,e){try{var g=c.keys();I(b,a,g,
d,e,"k")}catch(l){d.reject(l)}}function T(b,a,c,d,e){var k=new m;try{b.next().then(g.callback(function(l){if(null===l)k.resolve(f.voidOperation);else{var q=new w(l.attributes,l.geometry,d);q._underlyingGraphic=l;e.value=q;h(a,c.body).then(g.callback(function(l){l===f.breakResult?k.resolve(f.voidOperation):l instanceof f.ReturnResult?k.resolve(l):T(b,a,c,d,e).then(g.callback(function(c){k.resolve(c)},k),g.errback(k))},k),g.errback(k))}},k),g.errback(k))}catch(l){k.reject(l)}return k.promise}function ya(b,
a){var c=new m;try{h(b,a.right).then(g.callback(function(d){var e=null;"VariableDeclaration"===a.left.type?e=h(b,a.left):(e=new m,e.resolve(),e=e.promise);e.then(g.callback(function(){var e="VariableDeclaration"===a.left.type?a.left.declarations[0].id.name:a.left.name,l=null;null!==b.localScope&&void 0!==b.localScope[e]&&(l=b.localScope[e]);null===l&&void 0!==b.globalScope[e]&&(l=b.globalScope[e]);null===l?c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","VARIABLENOTDECLARED"))):f.isArray(d)||f.isString(d)?
I(b,a,d,c,l):f.isImmutableArray(d)?Ja(b,a,d,c,l):d instanceof u||d instanceof w?Ka(b,a,d,c,l):f.isFeatureCursor(d)?T(d.iterator(b.progressTracker),b,a,d,l).then(g.callback(function(a){c.resolve(a)},c),g.errback(c)):I(b,a,[],c,l)},c),g.errback(c))},c),g.errback(c))}catch(d){c.reject(d)}return c.promise}function va(b,a){var c=new m;try{if("MemberExpression"===a.argument.type)h(b,a.argument.object).then(g.callback(function(d){var e=null,e=null;!0===a.argument.computed?e=h(b,a.argument.property):(e=new m,
e.resolve(a.argument.property.name),e=e.promise);e.then(g.callback(function(b){var e;if(f.isArray(d))if(f.isNumber(b)){0>b&&(b=d.length+b);if(0>b||b>=d.length)throw Error("Assignment outside of array bounds");e=f.toNumber(d[b]);d[b]="++"===a.operator?e+1:e-1}else throw Error("Invalid Parameter");else if(d instanceof u){if(!1===f.isString(b))throw Error("Dictionary accessor must be a string");if(!0===d.hasField(b))e=f.toNumber(d.field(b)),d.setField(b,"++"===a.operator?e+1:e-1);else throw Error("Invalid Parameter");
}else if(d instanceof w){if(!1===f.isString(b))throw Error("Feature accessor must be a string");if(!0===d.hasField(b))e=f.toNumber(d.field(b)),d.setField(b,"++"===a.operator?e+1:e-1);else throw Error("Invalid Parameter");}else{if(f.isImmutableArray(d))throw Error("Array is Immutable");throw Error("Invalid Parameter");}!1===a.prefix?c.resolve(e):c.resolve("++"===a.operator?e+1:e-1)},c),g.errback(c))},c),g.errback(c));else{var d=a.argument.name.toLowerCase(),e=void 0;null!==b.localScope&&void 0!==b.localScope[d]&&
(e=f.toNumber(b.localScope[d].value),b.localScope[d]={value:"++"===a.operator?e+1:e-1,valueset:!0,node:a},!1===a.prefix?c.resolve(e):c.resolve("++"===a.operator?e+1:e-1));void 0!==b.globalScope[d]&&(e=f.toNumber(b.globalScope[d].value),b.globalScope[d]={value:"++"===a.operator?e+1:e-1,valueset:!0,node:a},!1===a.prefix?c.resolve(e):c.resolve("++"===a.operator?e+1:e-1));throw Error("Variable not recognised");}}catch(k){c.reject(k)}return c.promise}function y(b,a,c,d){switch(a){case "\x3d":return b===
f.voidOperation?null:b;case "/\x3d":return f.toNumber(c)/f.toNumber(b);case "*\x3d":return f.toNumber(c)*f.toNumber(b);case "-\x3d":return f.toNumber(c)-f.toNumber(b);case "+\x3d":return f.isString(c)||f.isString(b)?f.toString(c)+f.toString(b):f.toNumber(c)+f.toNumber(b);case "%\x3d":return f.toNumber(c)%f.toNumber(b);default:throw Error(n.nodeErrorMessage(d,"RUNTIME","OPERATORNOTRECOGNISED"));}}function wa(b,a){var c=new m;try{if("MemberExpression"===a.left.type)h(b,a.right).then(g.callback(function(d){h(b,
a.left.object).then(g.callback(function(e){var k=null,k=null;!0===a.left.computed?k=h(b,a.left.property):(k=new m,k.resolve(a.left.property.name),k=k.promise);k.then(g.callback(function(b){if(f.isArray(e))if(f.isNumber(b)){0>b&&(b=e.length+b);if(0>b||b>e.length)throw Error("Assignment outside of array bounds");if(b===e.length&&"\x3d"!==a.operator)throw Error("Invalid Parameter");e[b]=y(d,a.operator,e[b],a)}else throw Error("Invalid Parameter");else if(e instanceof u){if(!1===f.isString(b))throw Error("Dictionary accessor must be a string");
if(!0===e.hasField(b))e.setField(b,y(d,a.operator,e.field(b),a));else{if("\x3d"!==a.operator)throw Error("Invalid Parameter");e.setField(b,y(d,a.operator,null,a))}}else if(e instanceof w){if(!1===f.isString(b))throw Error("Feature accessor must be a string");if(!0===e.hasField(b))e.setField(b,y(d,a.operator,e.field(b),a));else{if("\x3d"!==a.operator)throw Error("Invalid Parameter");e.setField(b,y(d,a.operator,null,a))}}else{if(f.isImmutableArray(e))throw Error("Array is Immutable");throw Error("Invalid Parameter");
}c.resolve(f.voidOperation)},c),g.errback(c))},c),g.errback(c))},c),g.errback(c));else{var d=a.left.name.toLowerCase();if(null!==b.localScope&&void 0!==b.localScope[d])return h(b,a.right).then(g.callback(function(e){b.localScope[d]={value:y(e,a.operator,b.localScope[d].value,a),valueset:!0,node:a.right};c.resolve(f.voidOperation)},c),g.errback(c)),c.promise;if(void 0!==b.globalScope[d])return h(b,a.right).then(g.callback(function(e){b.globalScope[d]={value:y(e,a.operator,b.globalScope[d].value,a),
valueset:!0,node:a.right};c.resolve(f.voidOperation)},c),g.errback(c)),c.promise;c.reject(Error("Cannot assign undeclared variable"))}}catch(e){c.reject(e)}return c.promise}function ua(b,a){var c=new m;try{"AssignmentExpression"===a.expression.type?h(b,a.expression).then(g.callback(function(a){c.resolve(a)},c),g.errback(c)):h(b,a.expression).then(g.callback(function(a){a===f.voidOperation?c.resolve(f.voidOperation):c.resolve(new f.ImplicitResult(a))},c),g.errback(c))}catch(d){c.reject(d)}return c.promise}
function ta(b,a){var c=new m;try{if("AssignmentExpression"===a.test.type||"UpdateExpression"===a.test.type)return c.reject(Error(n.nodeErrorMessage(a.test,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"))),c.promise;h(b,a.test).then(g.callback(function(d){!0===d?h(b,a.consequent).then(g.callback(function(a){c.resolve(a)},c),g.errback(c)):!1===d?null!==a.alternate?h(b,a.alternate).then(g.callback(function(a){c.resolve(a)},c),g.errback(c)):c.resolve(f.voidOperation):c.reject(Error(n.nodeErrorMessage(a.test,
"RUNTIME","CANNOT_USE_NONBOOLEAN_IN_CONDITION")))},c),g.errback(c))}catch(d){c.reject(d)}return c.promise}function ra(b,a){var c=new m;try{U(b,a,0).then(g.callback(function(a){c.resolve(a)},c),g.errback(c))}catch(d){c.reject(d)}return c.promise}function U(b,a,c){var d=new m;try{c>=a.body.length?d.resolve(f.voidOperation):h(b,a.body[c]).then(g.callback(function(e){e instanceof f.ReturnResult||e===f.breakResult||e===f.continueResult?d.resolve(e):c===a.body.length-1?d.resolve(e):U(b,a,c+1).then(g.callback(function(a){d.resolve(a)},
d),g.errback(d))},d),g.errback(d))}catch(e){d.reject(e)}return d.promise}function sa(b,a){var c=new m;try{null===a.argument?c.resolve(new f.ReturnResult(f.voidOperation)):h(b,a.argument).then(g.callback(function(a){c.resolve(new f.ReturnResult(a))},c),g.errback(c))}catch(d){c.reject(d)}return c.promise}function P(b,a,c){var d=new m;try{if(c>=a.declarations.length)return d.resolve(f.voidOperation),d.promise;h(b,a.declarations[c]).then(g.callback(function(e){c===a.declarations.length-1?d.resolve(f.voidOperation):
P(b,a,c+1).then(g.callback(function(a){d.resolve(f.voidOperation)},d),g.errback(d))},d),g.errback(d))}catch(e){d.reject(e)}return d.promise}function qa(b,a){var c=new m;try{var d=null;null===a.init?(d=new m,d.resolve(null),d=d.promise):d=h(b,a.init);null!==b.localScope?d.then(g.callback(function(d){d===f.voidOperation&&(d=null);var e=a.id.name.toLowerCase();b.localScope[e]={value:d,valueset:!0,node:a.init};c.resolve(f.voidOperation)},c),g.errback(c)):d.then(g.callback(function(d){var e=a.id.name.toLowerCase();
d===f.voidOperation&&(d=null);b.globalScope[e]={value:d,valueset:!0,node:a.init};c.resolve(f.voidOperation)},c),g.errback(c))}catch(e){c.reject(e)}return c.promise}function V(b,a,c,d){a=a.toLowerCase();switch(a){case "hasz":return b=b.hasZ,void 0===b?!1:b;case "hasm":return b=b.hasM,void 0===b?!1:b;case "spatialreference":return a=b.spatialReference._arcadeCacheId,void 0===a&&(c=!0,Object.freeze&&Object.isFrozen(b.spatialReference)&&(c=!1),c&&(x++,a=b.spatialReference._arcadeCacheId=x)),b=new u({wkt:b.spatialReference.wkt,
wkid:b.spatialReference.wkid}),void 0!==a&&(b._arcadeCacheId="SPREF"+a.toString()),b}switch(b.type){case "extent":switch(a){case "xmin":case "xmax":case "ymin":case "ymax":case "zmin":case "zmax":case "mmin":case "mmax":return b=b[a],void 0!==b?b:null;case "type":return"Extent"}break;case "polygon":switch(a){case "rings":return a=f.isVersion4?b.cache._arcadeCacheId:b.getCacheValue("_arcadeCacheId"),void 0===a&&(x++,a=x,f.isVersion4?b.cache._arcadeCacheId=a:b.setCacheValue("_arcadeCacheId",a)),b=new N(b.rings,
b.spatialReference,!0===b.hasZ,!0===b.hasM,a);case "type":return"Polygon"}break;case "point":switch(a){case "x":case "y":case "z":case "m":return void 0!==b[a]?b[a]:null;case "type":return"Point"}break;case "polyline":switch(a){case "paths":return a=f.isVersion4?b.cache._arcadeCacheId:b.getCacheValue("_arcadeCacheId"),void 0===a&&(x++,a=x,f.isVersion4?b.cache._arcadeCacheId=a:b.setCacheValue("_arcadeCacheId",a)),b=new N(b.paths,b.spatialReference,!0===b.hasZ,!0===b.hasM,a);case "type":return"Polyline"}break;
case "multipoint":switch(a){case "points":return a=f.isVersion4?b.cache._arcadeCacheId:b.getCacheValue("_arcadeCacheId"),void 0===a&&(x++,a=x,f.isVersion4?b.cache._arcadeCacheId=a:b.setCacheValue("_arcadeCacheId",a)),b=new ma(b.points,b.spatialReference,!0===b.hasZ,!0===b.hasM,a,1);case "type":return"Multipoint"}}throw Error(n.nodeErrorMessage(d,"RUNTIME","PROPERTYNOTFOUND"));}function za(b,a){try{var c=new m;h(b,a.object).then(g.callback(function(d){null===d?c.reject(Error(n.nodeErrorMessage(a,"RUNTIME",
"NOTFOUND"))):!1===a.computed?d instanceof u||d instanceof w?c.resolve(d.field(a.property.name)):d instanceof M?c.resolve(V(d,a.property.name,b,a)):c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","INVALIDTYPE"))):h(b,a.property).then(g.callback(function(e){if(d instanceof u||d instanceof w)f.isString(e)?c.resolve(d.field(e)):c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","INVALIDTYPE")));else if(d instanceof M)f.isString(e)?c.resolve(V(d,e,b,a)):c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","INVALIDTYPE")));
else if(f.isArray(d))if(f.isNumber(e)&&isFinite(e)&&Math.floor(e)===e){0>e&&(e=d.length+e);if(e>=d.length||0>e)throw Error(n.nodeErrorMessage(a,"RUNTIME","OUTOFBOUNDS"));c.resolve(d[e])}else c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","INVALIDTYPE")));else if(f.isImmutableArray(d))if(f.isNumber(e)&&isFinite(e)&&Math.floor(e)===e){0>e&&(e=d.length()+e);if(e>=d.length()||0>e)throw Error(n.nodeErrorMessage(a,"RUNTIME","OUTOFBOUNDS"));c.resolve(d.get(e))}else c.reject(Error(n.nodeErrorMessage(a,"RUNTIME",
"INVALIDTYPE")));else if(f.isString(d))if(f.isNumber(e)&&isFinite(e)&&Math.floor(e)===e){0>e&&(e=d.length+e);if(e>=d.length||0>e)throw Error(n.nodeErrorMessage(a,"RUNTIME","OUTOFBOUNDS"));c.resolve(d[e])}else c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","INVALIDTYPE")));else c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","INVALIDTYPE")))},c),g.errback(c))},c),g.errback(c));return c.promise}catch(d){return p(d)}}function Ba(b,a){try{var c=new m;h(b,a.argument).then(g.callback(function(b){f.isBoolean(b)?
"!"===a.operator?c.resolve(!b):"-"===a.operator?c.resolve(-1*f.toNumber(b)):"+"===a.operator?c.resolve(1*f.toNumber(b)):c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR"))):"-"===a.operator?c.resolve(-1*f.toNumber(b)):"+"===a.operator?c.resolve(1*f.toNumber(b)):c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","NOTSUPPORTEDUNARYOPERATOR")))},c),g.errback(c));return c.promise}catch(d){return p(d)}}function Ea(b,a){try{for(var c=new m,d=[],e=0;e<a.elements.length;e++)d.push(h(b,
a.elements[e]));A(d).then(g.callback(function(b){for(var d=0;d<b.length;d++){if(f.isFunctionParameter(b[d])){c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","FUNCTIONCONTEXTILLEGAL")));return}b[d]===f.voidOperation&&(b[d]=null)}c.resolve(b)},c),g.errback(c));return c.promise}catch(k){return p(k)}}function Ca(b,a){try{var c=new m;A([h(b,a.left),h(b,a.right)]).then(g.callback(function(b){var d=b[0];b=b[1];switch(a.operator){case "\x3d\x3d":c.resolve(f.equalityTest(d,b));break;case "\x3d":c.resolve(f.equalityTest(d,
b));break;case "!\x3d":c.resolve(!f.equalityTest(d,b));break;case "\x3c":c.resolve(f.greaterThanLessThan(d,b,a.operator));break;case "\x3e":c.resolve(f.greaterThanLessThan(d,b,a.operator));break;case "\x3c\x3d":c.resolve(f.greaterThanLessThan(d,b,a.operator));break;case "\x3e\x3d":c.resolve(f.greaterThanLessThan(d,b,a.operator));break;case "+":f.isString(d)||f.isString(b)?c.resolve(f.toString(d)+f.toString(b)):c.resolve(f.toNumber(d)+f.toNumber(b));break;case "-":c.resolve(f.toNumber(d)-f.toNumber(b));
break;case "*":c.resolve(f.toNumber(d)*f.toNumber(b));break;case "/":c.resolve(f.toNumber(d)/f.toNumber(b));break;case "%":c.resolve(f.toNumber(d)%f.toNumber(b));break;default:c.reject(Error(n.nodeErrorMessage(a,"RUNTIME","OPERATORNOTRECOGNISED")))}},c),g.errback(c));return c.promise}catch(d){return p(d)}}function Da(b,a){try{var c=new m;if("AssignmentExpression"===a.left.type||"UpdateExpression"===a.left.type)return c.reject(Error(n.nodeErrorMessage(a.left,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"))),
c.promise;if("AssignmentExpression"===a.right.type||"UpdateExpression"===a.right.type)return c.reject(Error(n.nodeErrorMessage(a.right,"RUNTIME","CANNOT_USE_ASSIGNMENT_IN_CONDITION"))),c.promise;h(b,a.left).then(g.callback(function(d){if(f.isBoolean(d))switch(a.operator){case "||":!0===d?c.resolve(d):h(b,a.right).then(g.callback(function(b){if(f.isBoolean(b))c.resolve(b);else throw Error(n.nodeErrorMessage(a,"RUNTIME","ONLYORORAND"));},c),g.errback(c));break;case "\x26\x26":!1===d?c.resolve(d):h(b,
a.right).then(g.callback(function(b){if(f.isBoolean(b))c.resolve(b);else throw Error(n.nodeErrorMessage(a,"RUNTIME","ONLYORORAND"));},c),g.errback(c));break;default:throw Error(n.nodeErrorMessage(a,"RUNTIME","ONLYORORAND"));}else throw Error(n.nodeErrorMessage(a,"RUNTIME","ONLYBOOLEAN"));},c),g.errback(c));return c.promise}catch(d){return p(d)}}function G(b,a){try{var c=new m,d=a.name.toLowerCase();if(null!==b.localScope&&void 0!==b.localScope[d]){var e=b.localScope[d];!0===e.valueset?c.resolve(e.value):
null!==e.d?e.d.then(g.callback(function(a){c.resolve(a)},c),g.errback(c)):(e.d=h(b,e.node),e.d.then(g.callback(function(a){e.value=a;e.valueset=!0;c.resolve(a)},c),g.errback(c)));return c.promise}if(void 0!==b.globalScope[d]){var f=b.globalScope[d];!0===f.valueset?c.resolve(f.value):null!==f.d?f.d.then(g.callback(function(a){c.resolve(a)},c),g.errback(c)):(f.d=h(b,f.node),f.d.then(g.callback(function(a){f.value=a;f.valueset=!0;c.resolve(a)},c),g.errback(c)))}else c.reject(Error(n.nodeErrorMessage(a,
"RUNTIME","VARIABLENOTFOUND")));return c.promise}catch(l){return p(l)}}function Aa(b,a){try{if("Identifier"!==a.callee.type)return p(n.nodeErrorMessage(a,"RUNTIME","ONLYNODESSUPPORTED"));if(null!==b.localScope&&void 0!==b.localScope[a.callee.name.toLowerCase()]){var c=b.localScope[a.callee.name.toLowerCase()];return c.value instanceof f.NativeFunction?c.value.fn(b,a):c.value instanceof D?W(b,a,c.value.definition):p(n.nodeErrorMessage(a,"RUNTIME","NOTAFUNCTION"))}return void 0!==b.globalScope[a.callee.name.toLowerCase()]?
(c=b.globalScope[a.callee.name.toLowerCase()],c.value instanceof f.NativeFunction?c.value.fn(b,a):c.value instanceof D?W(b,a,c.value.definition):p(n.nodeErrorMessage(a,"RUNTIME","NOTAFUNCTION"))):p(n.nodeErrorMessage(a,"RUNTIME","NOTFOUND"))}catch(d){return p(d)}}function X(b){return null===b?"":f.isArray(b)||f.isImmutableArray(b)?"Array":f.isDate(b)?"Date":f.isString(b)?"String":f.isBoolean(b)?"Boolean":f.isNumber(b)?"Number":b instanceof u?"Dictionary":b instanceof w?"Feature":b instanceof ea?"Point":
b instanceof ca?"Polygon":b instanceof da?"Polyline":b instanceof ga?"Multipoint":b instanceof fa?"Extent":f.isFunctionParameter(b)?"Function":b===f.voidOperation?"":"number"===typeof b&&isNaN(b)?"Number":"Unrecognised Type"}function Y(b,a,c,d){try{var e=new m;h(b,a.arguments[c]).then(g.callback(function(k){f.equalityTest(k,d)?h(b,a.arguments[c+1]).then(g.callback(function(a){e.resolve(a)},e),g.errback(e)):(k=a.arguments.length-c,1===k?h(b,a.arguments[c]).then(g.callback(function(a){e.resolve(a)},
e),g.errback(e)):2===k&&e.resolve(null),3===k?h(b,a.arguments[c+2]).then(g.callback(function(a){e.resolve(a)},e),g.errback(e)):Y(b,a,c+2,d).then(g.callback(function(a){e.resolve(a)},e),g.errback(e)))},e),g.errback(e));return e.promise}catch(k){return p(k)}}function Z(b,a,c,d){try{var e=new m;!0===d?h(b,a.arguments[c+1]).then(g.callback(function(a){e.resolve(a)},e),g.errback(e)):3===a.arguments.length-c?h(b,a.arguments[c+2]).then(g.callback(function(a){e.resolve(a)},e),g.errback(e)):h(b,a.arguments[c+
2]).then(g.callback(function(d){!1===f.isBoolean(d)?e.reject(Error("WHEN needs boolean test conditions")):Z(b,a,c+2,d).then(g.callback(function(a){e.resolve(a)},e),g.errback(e))},e),g.errback(e));return e.promise}catch(k){return p(k)}}function J(b,a){var c=new m;try{var d=b.length,e=Math.floor(d/2);if(0===d)return c.resolve([]),c.promise;if(1===d)return c.resolve([b[0]]),c.promise;var f=[J(b.slice(0,e),a),J(b.slice(e,d),a)];A(f).then(g.callback(function(b){E(b[0],b[1],a,[]).then(g.callback(function(a){c.resolve(a)},
c),g.errback(c))},c),g.errback(c))}catch(l){c.reject(l)}return c.promise}function E(b,a,c,d){var e=new m;try{0<b.length||0<a.length?0<b.length&&0<a.length?c(b[0],a[0]).then(g.callback(function(f){isNaN(f)&&(f=1);0>=f?(d.push(b[0]),b=b.slice(1)):(d.push(a[0]),a=a.slice(1));E(b,a,c,d).then(g.callback(function(a){e.resolve(a)},e),g.errback(e))},e),g.errback(e)):0<b.length?(d.push(b[0]),b=b.slice(1),E(b,a,c,d).then(g.callback(function(a){e.resolve(a)},e),g.errback(e))):0<a.length&&(d.push(a[0]),a=a.slice(1),
E(b,a,c,d).then(g.callback(function(a){e.resolve(a)},e),g.errback(e))):e.resolve(d)}catch(k){e.reject(k)}return e.promise}function z(b,a){var c=b.length,d=Math.floor(c/2);a||(a=function(a,b){return a<b?-1:a===b?0:1});return 0===c?[]:1===c?[b[0]]:La(z(b.slice(0,d),a),z(b.slice(d,c),a),a)}function La(b,a,c){for(var d=[];0<b.length||0<a.length;)if(0<b.length&&0<a.length){var e=c(b[0],a[0]);isNaN(e)&&(e=1);0>=e?(d.push(b[0]),b=b.slice(1)):(d.push(a[0]),a=a.slice(1))}else 0<b.length?(d.push(b[0]),b=b.slice(1)):
0<a.length&&(d.push(a[0]),a=a.slice(1));return d}function aa(b,a,c){var d=new m;try{var e=b.body;if(c.length!==b.params.length)return p(Error("Invalid Parameter calls to function."));for(var k=0;k<c.length;k++)a.localScope[b.params[k].name.toLowerCase()]={d:null,value:c[k],valueset:!0,node:null};h(a,e).then(g.callback(function(a){a instanceof f.ReturnResult?d.resolve(a.value):a===f.breakResult?d.reject(Error("Cannot Break from a Function")):a===f.continueResult?d.reject(Error("Cannot Continue from a Function")):
a instanceof f.ImplicitResult?d.resolve(a.value):d.resolve(a)},d),g.errback(d))}catch(l){d.reject(l)}return d.promise}function W(b,a,c){return B(b,a,function(a,e,f){a={spatialReference:b.spatialReference,services:b.services,console:b.console,localScope:{},progressTracker:b.progressTracker,globalScope:b.globalScope,depthCounter:b.depthCounter+1};if(64<a.depthCounter)throw Error("Exceeded maximum function depth");return aa(c,a,f)})}function K(b){return function(){var a={applicationCache:void 0===b.context.applicationCache?
null:b.context.applicationCache,progressTracker:b.context.progressTracker,spatialReference:b.context.spatialReference,console:b.context.console,services:b.context.services,localScope:{},globalScope:b.context.globalScope,depthCounter:b.context.depthCounter+1};if(64<a.depthCounter)throw Error("Exceeded maximum function depth");return aa(b.definition,a,arguments)}}function Ma(b,a){var c=new C;if(void 0===b||null===b)b={};if(void 0===a||null===a)a={};var d=new u({newline:"\n",tab:"\t",singlequote:"'",
doublequote:'"',forwardslash:"/",backwardslash:"\\"});d.immutable=!1;c.textformatting={value:d,valueset:!0,node:null};for(var e in a)c[e]={value:new f.NativeFunction(a[e]),native:!0,valueset:!0,node:null};for(e in b)c[e]=b[e]&&"esri.Graphic"===b[e].declaredClass?{value:new w(b[e]),valueset:!0,node:null}:{value:b[e],valueset:!0,node:null};return c}function Na(b){console.log(b)}Object.defineProperty(t,"__esModule",{value:!0});var x=0,r={};ja.registerFunctions(r,v);na.registerFunctions(r,v);ka.registerFunctions(r,
v);la.registerFunctions(r,v);oa.registerFunctions(r,v);pa.registerFunctions(r,v,B);r.typeof=function(b,a){return v(b,a,function(a,b,e){f.pcCheck(e,1,1);a=X(e[0]);if("Unrecognised Type"===a)throw Error("Unrecognised Type");return a})};r.iif=function(b,a){try{var c=new m;f.pcCheck(null===a.arguments?[]:a.arguments,3,3);h(b,a.arguments[0]).then(g.callback(function(d){!1===f.isBoolean(d)?c.reject(Error("IF Function must have a boolean test condition")):!0===d?h(b,a.arguments[1]).then(g.callback(function(a){c.resolve(a)},
c),g.errback(c)):h(b,a.arguments[2]).then(g.callback(function(a){c.resolve(a)},c),g.errback(c))},c),g.errback(c));return c.promise}catch(d){return p(d)}};r.decode=function(b,a){try{var c=new m;if(2>a.arguments.length)return p("Missing Parameters");if(2===a.arguments.length)h(b,a.arguments[1]).then(g.callback(function(a){c.resolve(a)},c),g.errback(c));else{if(0===(a.arguments.length-1)%2)return p("Must have a default value result.");h(b,a.arguments[0]).then(g.callback(function(d){Y(b,a,1,d).then(g.callback(function(a){c.resolve(a)},
c),g.errback(c))},c),g.errback(c))}return c.promise}catch(d){return p(d)}};r.when=function(b,a){try{var c=new m;if(3>a.arguments.length)return p("Missing Parameters");if(0===a.arguments.length%2)return p("Must have a default value result.");h(b,a.arguments[0]).then(g.callback(function(d){!1===f.isBoolean(d)?c.reject(Error("WHEN needs boolean test conditions")):Z(b,a,0,d).then(g.callback(function(a){c.resolve(a)},c),g.errback(c))},c),g.errback(c));return c.promise}catch(d){return p(d)}};r.sort=function(b,
a){return B(b,a,function(a,b,e){var c=new m;f.pcCheck(e,1,2);a=e[0];f.isImmutableArray(a)&&(a=a.toArray());if(!1===f.isArray(a))return p(Error("Illegal Argument"));if(1<e.length){if(!1===f.isFunctionParameter(e[1]))return p(Error("Illegal Argument"));var d=K(e[1]);J(a,d).then(g.callback(function(a){c.resolve(a)},c),g.errback(c))}else{if(0===a.length)return c.resolve([]),c.promise;e={};for(b=0;b<a.length;b++){var h=X(a[b]);""!==h&&(e[h]=!0)}if(!0===e.Array||!0===e.Dictionary||!0===e.Feature||!0===
e.Point||!0===e.Polygon||!0===e.Polyline||!0===e.Multipoint||!0===e.Extent||!0===e.Function)return c.resolve(a.slice(0)),c.promise;b=0;h="";for(d in e)b++,h=d;1<b||"String"===h?a=z(a,function(a,b){if(null===a||void 0===a||a===f.voidOperation)return null===b||void 0===b||b===f.voidOperation?0:1;if(null===b||void 0===b||b===f.voidOperation)return-1;var c=f.toString(a),d=f.toString(b);return c<d?-1:c===d?0:1}):"Number"===h?a=z(a,function(a,b){return a-b}):"Boolean"===h?a=z(a,function(a,b){return a===
b?0:b?-1:1}):"Date"===h&&(a=z(a,function(a,b){return b-a}));c.resolve(a)}return c.promise})};L={failDefferred:p,resolveDeffered:O,fixSpatialReference:f.fixSpatialReference,parseArguments:F,standardFunction:v,standardFunctionAsync:B,evaluateIdentifier:G,arcadeCustomFunction:K};for(var ba in r)r[ba]={value:new f.NativeFunction(r[ba]),valueset:!0,node:null};var C=function(){};C.prototype=r;C.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null};C.prototype.pi={value:Math.PI,valueset:!0,
node:null};t.functionHelper=L;t.extend=function(b){for(var a={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:v,standardFunctionAsync:B,failDefferred:p,evaluateIdentifier:G,arcadeCustomFunctionHandler:K},c=0;c<b.length;c++)b[c].registerFunctions(a);for(var d in a.functions)r[d]={value:new f.NativeFunction(a.functions[d]),valueset:!0,node:null},C.prototype[d]=r[d];for(c=0;c<a.signatures.length;c++)n.addFunctionDeclaration(a.signatures[c],"f")};t.executeScript=function(b,a,c){var d=
new m;if(null===c||void 0===c)c=new ha({wkid:102100});var e=Ma(a.vars,a.customfunctions);h({spatialReference:c,services:a.services,progressTracker:void 0===a.progressTracker||null===a.progressTracker?d.promise:a.progressTracker,globalScope:e,console:a.console?a.console:Na,localScope:null,depthCounter:1},b.body[0].body).then(g.callback(function(a){a instanceof f.ReturnResult&&(a=a.value);a instanceof f.ImplicitResult&&(a=a.value);a===f.voidOperation&&(a=null);a===f.breakResult?d.reject(Error("Cannot return BREAK")):
a===f.continueResult?d.reject(Error("Cannot return CONTINUE")):a instanceof f.NativeFunction?d.reject(Error("Cannot return FUNCTION")):a instanceof D?d.reject(Error("Cannot return FUNCTION")):d.resolve(a)},d),g.errback(d));return d.promise};t.extractFieldLiterals=function(b,a){void 0===a&&(a=!1);return n.findFieldLiterals(b,a)};t.validateScript=function(b,a){return n.validateScript(b,a,"full")};t.referencesMember=function(b,a){return n.referencesMember(b,a)};t.referencesFunction=function(b,a){return n.referencesFunction(b,
a)};t.findFunctionCalls=function(b){return n.findFunctionCalls(b,!1)}});