/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","./syntax"],(function(t,n){"use strict";let e=function(){function t(){this.attach=!1,this.comments=[],this.stack=[],this.leading=[],this.trailing=[]}var e=t.prototype;return e.insertInnerComments=function(t,e){if(t.type===n.Syntax.BlockStatement&&0===t.body.length){const n=[];for(let t=this.leading.length-1;t>=0;--t){const i=this.leading[t];e.end.offset>=i.start&&(n.unshift(i.comment),this.leading.splice(t,1),this.trailing.splice(t,1))}n.length&&(t.innerComments=n)}},e.findTrailingComments=function(t){let n=[];if(this.trailing.length>0){for(let e=this.trailing.length-1;e>=0;--e){const i=this.trailing[e];i.start>=t.end.offset&&n.unshift(i.comment)}return this.trailing.length=0,n}const e=this.stack[this.stack.length-1];if(e&&e.node.trailingComments){const i=e.node.trailingComments[0];i&&i.range[0]>=t.end.offset&&(n=e.node.trailingComments,delete e.node.trailingComments)}return n},e.findLeadingComments=function(t){const n=[];let e;for(;this.stack.length>0;){const n=this.stack[this.stack.length-1];if(!(n&&n.start>=t.start.offset))break;e=n.node,this.stack.pop()}if(e){for(let i=(e.leadingComments?e.leadingComments.length:0)-1;i>=0;--i){const s=e.leadingComments[i];s.range[1]<=t.start.offset&&(n.unshift(s),e.leadingComments.splice(i,1))}return e.leadingComments&&0===e.leadingComments.length&&delete e.leadingComments,n}for(let i=this.leading.length-1;i>=0;--i){const e=this.leading[i];e.start<=t.start.offset&&(n.unshift(e.comment),this.leading.splice(i,1))}return n},e.visitNode=function(t,e){if(t.type===n.Syntax.Program&&t.body.length>0)return;this.insertInnerComments(t,e);const i=this.findTrailingComments(e),s=this.findLeadingComments(e);s.length>0&&(t.leadingComments=s),i.length>0&&(t.trailingComments=i),this.stack.push({node:t,start:e.start.offset})},e.visitComment=function(t,n){if(this.comments.push(t),this.attach){const e={comment:{type:t.type,value:t.value,range:[n.start.offset,n.end.offset]},start:n.start.offset};t.loc&&(e.comment.loc=t.loc),this.leading.push(e),this.trailing.push(e)}},e.visit=function(t,n){"Line"===t.type||"Block"===t.type?this.visitComment(t,n):this.attach&&this.visitNode(t,n)},t}();t.CommentHandler=e,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
