import*as Platform from"../platform/platform.js";import*as TextUtils from"../text_utils/text_utils.js";import*as Acorn from"../third_party/acorn/acorn.js";export let TokenOrComment;export class AcornTokenizer{constructor(t){this._content=t,this._comments=[],this._tokenizer=Acorn.tokenizer(this._content,{onComment:this._comments,ecmaVersion:ECMA_VERSION,allowHashBang:!0});const e=Platform.StringUtilities.findLineEndingIndexes(this._content);this._textCursor=new TextUtils.TextCursor.TextCursor(e),this._tokenLineStart=0,this._tokenLineEnd=0,this._tokenColumnStart=0,0===this._comments.length&&this._nextTokenInternal(),this._bufferedToken}static punctuator(t,e){return t.type!==Acorn.tokTypes.num&&t.type!==Acorn.tokTypes.regexp&&t.type!==Acorn.tokTypes.string&&t.type!==Acorn.tokTypes.name&&!t.type.keyword&&(!e||1===t.type.label.length&&-1!==e.indexOf(t.type.label))}static keyword(t,e){return Boolean(t.type.keyword)&&t.type!==Acorn.tokTypes._true&&t.type!==Acorn.tokTypes._false&&t.type!==Acorn.tokTypes._null&&(!e||t.type.keyword===e)}static identifier(t,e){return t.type===Acorn.tokTypes.name&&(!e||t.value===e)}static lineComment(t){return"Line"===t.type}static blockComment(t){return"Block"===t.type}_nextTokenInternal(){if(this._comments.length){const t=this._comments.shift();return this._bufferedToken||0!==this._comments.length||(this._bufferedToken=this._tokenizer.getToken()),t}const t=this._bufferedToken;return this._bufferedToken=this._tokenizer.getToken(),t}nextToken(){const t=this._nextTokenInternal();return t&&t.type!==Acorn.tokTypes.eof?(this._textCursor.advance(t.start),this._tokenLineStart=this._textCursor.lineNumber(),this._tokenColumnStart=this._textCursor.columnNumber(),this._textCursor.advance(t.end),this._tokenLineEnd=this._textCursor.lineNumber(),t):null}peekToken(){return this._comments.length?this._comments[0]:this._bufferedToken&&this._bufferedToken.type!==Acorn.tokTypes.eof?this._bufferedToken:null}tokenLineStart(){return this._tokenLineStart}tokenLineEnd(){return this._tokenLineEnd}tokenColumnStart(){return this._tokenColumnStart}}export const ECMA_VERSION=2021;