/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","./treeAnalysis","./lib/arcade-parser"],(function(e,n,r){"use strict";function t(e,t=[]){const i=r.parse("function _() { "+e+"\n}");if(null===i.body||void 0===i.body)throw new Error("No formula provided.");if(0===i.body.length)throw new Error("No formula provided.");if(0===i.body.length)throw new Error("No formula provided.");if("BlockStatement"!==i.body[0].body.type)throw new Error("Invalid formula content.");const o=n.validateLanguage(i);if(""!==o)throw new Error(o);return n.findScriptDependencies(i,t),i}function i(e,t,i,o,c){const l=[],a="function _() { \n".length-1,s="function _() { \n"+e+"\n}";try{const e=r.parse(s,{tolerant:!0,loc:!0,range:!0}),u=e.errors;if(u.length>0)for(let n=0;n<u.length;n++)l.push({line:u[n].lineNumber-2,character:u[n].column,reason:u[n].description});const d=n.checkScript(e,t,i,o,c);for(let n=0;n<d.length;n++)d[n].line=d[n].line-2,d[n].range&&(d[n].range=[d[n][0]-a,d[n][1]-a]),d[n].loc&&(d[n].loc.start.line=d[n].loc.start.line-2,d[n].loc.end.line=d[n].loc.end.line-2),l.push(d[n])}catch(u){try{if("Unexpected token }"===u.description){const e=s.split("\n").length;u.lineNumber===e?(u.index=s.length-1,l.push({line:u.lineNumber-4,character:u.column,reason:"Unexpected end of script"})):(u.index=s.length-1,l.push({line:u.lineNumber-2,character:u.column,reason:"Unexpected end of script"}))}else l.push({line:u.lineNumber-2,character:u.column,reason:u.description})}catch(d){}}return l}function o(e,r){return n.findFieldLiterals(e)}function c(e,r,t){return n.validateScript(e,r,t)}function l(e){return n.findExpectedFieldLiterals(e)}function a(e,r){return n.referencesMember(e,r)}function s(e,r){return n.referencesFunction(e,r)}e.extractExpectedFieldLiterals=l,e.extractFieldLiterals=o,e.parseScript=t,e.referencesFunction=s,e.referencesMember=a,e.scriptCheck=i,e.validateScript=c,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
