/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import{ErrorHandler as e}from"./error-handler.js";import{AssignmentOperators as t,BinaryOperators as s,LogicalOperators as n,UnaryOperators as r}from"./nodes.js";import{Scanner as i}from"./scanner.js";import{TokenName as a,TokenType as c}from"./token.js";class o{constructor(){this.values=[],this.curly=this.paren=-1}beforeFunctionExpression(e){return["(","{","[","return",",",...t,...s,...n,...r].includes(e)}isRegexStart(){const e=this.values[this.values.length-1];let t=null!==e;switch(e){case"this":case"]":t=!1;break;case")":{const e=this.values[this.paren-1];t="if"===e||"while"===e||"for"===e||"with"===e}break;case"}":if(t=!0,"function"===this.values[this.curly-3]){const e=this.values[this.curly-4];t=!!e&&!this.beforeFunctionExpression(e)}else if("function"===this.values[this.curly-4]){const e=this.values[this.curly-5];t=!e||!this.beforeFunctionExpression(e)}}return t}push(e){e.type===c.Punctuator||e.type===c.Keyword?("{"===e.value?this.curly=this.values.length:"("===e.value&&(this.paren=this.values.length),this.values.push(e.value)):this.values.push(null)}}class l{constructor(t,s){this.errorHandler=new e,this.errorHandler.tolerant=!!s&&("boolean"==typeof s.tolerant&&s.tolerant),this.scanner=new i(t,this.errorHandler),this.scanner.trackComment=!!s&&("boolean"==typeof s.comment&&s.comment),this.trackRange=!!s&&("boolean"==typeof s.range&&s.range),this.trackLoc=!!s&&("boolean"==typeof s.loc&&s.loc),this.buffer=[],this.reader=new o}errors(){return this.errorHandler.errors}getNextToken(){if(0===this.buffer.length){const t=this.scanner.scanComments();if(t)for(let e=0;e