acorn.d.mts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. export interface Node {
  2. start: number
  3. end: number
  4. type: string
  5. range?: [number, number]
  6. loc?: SourceLocation | null
  7. }
  8. export interface SourceLocation {
  9. source?: string | null
  10. start: Position
  11. end: Position
  12. }
  13. export interface Position {
  14. /** 1-based */
  15. line: number
  16. /** 0-based */
  17. column: number
  18. }
  19. export interface Identifier extends Node {
  20. type: "Identifier"
  21. name: string
  22. }
  23. export interface Literal extends Node {
  24. type: "Literal"
  25. value?: string | boolean | null | number | RegExp | bigint
  26. raw?: string
  27. regex?: {
  28. pattern: string
  29. flags: string
  30. }
  31. bigint?: string
  32. }
  33. export interface Program extends Node {
  34. type: "Program"
  35. body: Array<Statement | ModuleDeclaration>
  36. sourceType: "script" | "module"
  37. }
  38. export interface Function extends Node {
  39. id?: Identifier | null
  40. params: Array<Pattern>
  41. body: BlockStatement | Expression
  42. generator: boolean
  43. expression: boolean
  44. async: boolean
  45. }
  46. export interface ExpressionStatement extends Node {
  47. type: "ExpressionStatement"
  48. expression: Expression | Literal
  49. directive?: string
  50. }
  51. export interface BlockStatement extends Node {
  52. type: "BlockStatement"
  53. body: Array<Statement>
  54. }
  55. export interface EmptyStatement extends Node {
  56. type: "EmptyStatement"
  57. }
  58. export interface DebuggerStatement extends Node {
  59. type: "DebuggerStatement"
  60. }
  61. export interface WithStatement extends Node {
  62. type: "WithStatement"
  63. object: Expression
  64. body: Statement
  65. }
  66. export interface ReturnStatement extends Node {
  67. type: "ReturnStatement"
  68. argument?: Expression | null
  69. }
  70. export interface LabeledStatement extends Node {
  71. type: "LabeledStatement"
  72. label: Identifier
  73. body: Statement
  74. }
  75. export interface BreakStatement extends Node {
  76. type: "BreakStatement"
  77. label?: Identifier | null
  78. }
  79. export interface ContinueStatement extends Node {
  80. type: "ContinueStatement"
  81. label?: Identifier | null
  82. }
  83. export interface IfStatement extends Node {
  84. type: "IfStatement"
  85. test: Expression
  86. consequent: Statement
  87. alternate?: Statement | null
  88. }
  89. export interface SwitchStatement extends Node {
  90. type: "SwitchStatement"
  91. discriminant: Expression
  92. cases: Array<SwitchCase>
  93. }
  94. export interface SwitchCase extends Node {
  95. type: "SwitchCase"
  96. test?: Expression | null
  97. consequent: Array<Statement>
  98. }
  99. export interface ThrowStatement extends Node {
  100. type: "ThrowStatement"
  101. argument: Expression
  102. }
  103. export interface TryStatement extends Node {
  104. type: "TryStatement"
  105. block: BlockStatement
  106. handler?: CatchClause | null
  107. finalizer?: BlockStatement | null
  108. }
  109. export interface CatchClause extends Node {
  110. type: "CatchClause"
  111. param?: Pattern | null
  112. body: BlockStatement
  113. }
  114. export interface WhileStatement extends Node {
  115. type: "WhileStatement"
  116. test: Expression
  117. body: Statement
  118. }
  119. export interface DoWhileStatement extends Node {
  120. type: "DoWhileStatement"
  121. body: Statement
  122. test: Expression
  123. }
  124. export interface ForStatement extends Node {
  125. type: "ForStatement"
  126. init?: VariableDeclaration | Expression | null
  127. test?: Expression | null
  128. update?: Expression | null
  129. body: Statement
  130. }
  131. export interface ForInStatement extends Node {
  132. type: "ForInStatement"
  133. left: VariableDeclaration | Pattern
  134. right: Expression
  135. body: Statement
  136. }
  137. export interface FunctionDeclaration extends Function {
  138. type: "FunctionDeclaration"
  139. id: Identifier
  140. body: BlockStatement
  141. }
  142. export interface VariableDeclaration extends Node {
  143. type: "VariableDeclaration"
  144. declarations: Array<VariableDeclarator>
  145. kind: "var" | "let" | "const"
  146. }
  147. export interface VariableDeclarator extends Node {
  148. type: "VariableDeclarator"
  149. id: Pattern
  150. init?: Expression | null
  151. }
  152. export interface ThisExpression extends Node {
  153. type: "ThisExpression"
  154. }
  155. export interface ArrayExpression extends Node {
  156. type: "ArrayExpression"
  157. elements: Array<Expression | SpreadElement | null>
  158. }
  159. export interface ObjectExpression extends Node {
  160. type: "ObjectExpression"
  161. properties: Array<Property | SpreadElement>
  162. }
  163. export interface Property extends Node {
  164. type: "Property"
  165. key: Expression
  166. value: Expression
  167. kind: "init" | "get" | "set"
  168. method: boolean
  169. shorthand: boolean
  170. computed: boolean
  171. }
  172. export interface FunctionExpression extends Function {
  173. type: "FunctionExpression"
  174. body: BlockStatement
  175. }
  176. export interface UnaryExpression extends Node {
  177. type: "UnaryExpression"
  178. operator: UnaryOperator
  179. prefix: boolean
  180. argument: Expression
  181. }
  182. export type UnaryOperator = "-" | "+" | "!" | "~" | "typeof" | "void" | "delete"
  183. export interface UpdateExpression extends Node {
  184. type: "UpdateExpression"
  185. operator: UpdateOperator
  186. argument: Expression
  187. prefix: boolean
  188. }
  189. export type UpdateOperator = "++" | "--"
  190. export interface BinaryExpression extends Node {
  191. type: "BinaryExpression"
  192. operator: BinaryOperator
  193. left: Expression | PrivateIdentifier
  194. right: Expression
  195. }
  196. export type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "|" | "^" | "&" | "in" | "instanceof" | "**"
  197. export interface AssignmentExpression extends Node {
  198. type: "AssignmentExpression"
  199. operator: AssignmentOperator
  200. left: Pattern
  201. right: Expression
  202. }
  203. export type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=" | "**=" | "||=" | "&&=" | "??="
  204. export interface LogicalExpression extends Node {
  205. type: "LogicalExpression"
  206. operator: LogicalOperator
  207. left: Expression
  208. right: Expression
  209. }
  210. export type LogicalOperator = "||" | "&&" | "??"
  211. export interface MemberExpression extends Node {
  212. type: "MemberExpression"
  213. object: Expression | Super
  214. property: Expression | PrivateIdentifier
  215. computed: boolean
  216. optional: boolean
  217. }
  218. export interface ConditionalExpression extends Node {
  219. type: "ConditionalExpression"
  220. test: Expression
  221. alternate: Expression
  222. consequent: Expression
  223. }
  224. export interface CallExpression extends Node {
  225. type: "CallExpression"
  226. callee: Expression | Super
  227. arguments: Array<Expression | SpreadElement>
  228. optional: boolean
  229. }
  230. export interface NewExpression extends Node {
  231. type: "NewExpression"
  232. callee: Expression
  233. arguments: Array<Expression | SpreadElement>
  234. }
  235. export interface SequenceExpression extends Node {
  236. type: "SequenceExpression"
  237. expressions: Array<Expression>
  238. }
  239. export interface ForOfStatement extends Node {
  240. type: "ForOfStatement"
  241. left: VariableDeclaration | Pattern
  242. right: Expression
  243. body: Statement
  244. await: boolean
  245. }
  246. export interface Super extends Node {
  247. type: "Super"
  248. }
  249. export interface SpreadElement extends Node {
  250. type: "SpreadElement"
  251. argument: Expression
  252. }
  253. export interface ArrowFunctionExpression extends Function {
  254. type: "ArrowFunctionExpression"
  255. }
  256. export interface YieldExpression extends Node {
  257. type: "YieldExpression"
  258. argument?: Expression | null
  259. delegate: boolean
  260. }
  261. export interface TemplateLiteral extends Node {
  262. type: "TemplateLiteral"
  263. quasis: Array<TemplateElement>
  264. expressions: Array<Expression>
  265. }
  266. export interface TaggedTemplateExpression extends Node {
  267. type: "TaggedTemplateExpression"
  268. tag: Expression
  269. quasi: TemplateLiteral
  270. }
  271. export interface TemplateElement extends Node {
  272. type: "TemplateElement"
  273. tail: boolean
  274. value: {
  275. cooked?: string | null
  276. raw: string
  277. }
  278. }
  279. export interface AssignmentProperty extends Node {
  280. type: "Property"
  281. key: Expression
  282. value: Pattern
  283. kind: "init"
  284. method: false
  285. shorthand: boolean
  286. computed: boolean
  287. }
  288. export interface ObjectPattern extends Node {
  289. type: "ObjectPattern"
  290. properties: Array<AssignmentProperty | RestElement>
  291. }
  292. export interface ArrayPattern extends Node {
  293. type: "ArrayPattern"
  294. elements: Array<Pattern | null>
  295. }
  296. export interface RestElement extends Node {
  297. type: "RestElement"
  298. argument: Pattern
  299. }
  300. export interface AssignmentPattern extends Node {
  301. type: "AssignmentPattern"
  302. left: Pattern
  303. right: Expression
  304. }
  305. export interface Class extends Node {
  306. id?: Identifier | null
  307. superClass?: Expression | null
  308. body: ClassBody
  309. }
  310. export interface ClassBody extends Node {
  311. type: "ClassBody"
  312. body: Array<MethodDefinition | PropertyDefinition | StaticBlock>
  313. }
  314. export interface MethodDefinition extends Node {
  315. type: "MethodDefinition"
  316. key: Expression | PrivateIdentifier
  317. value: FunctionExpression
  318. kind: "constructor" | "method" | "get" | "set"
  319. computed: boolean
  320. static: boolean
  321. }
  322. export interface ClassDeclaration extends Class {
  323. type: "ClassDeclaration"
  324. id: Identifier
  325. }
  326. export interface ClassExpression extends Class {
  327. type: "ClassExpression"
  328. }
  329. export interface MetaProperty extends Node {
  330. type: "MetaProperty"
  331. meta: Identifier
  332. property: Identifier
  333. }
  334. export interface ImportDeclaration extends Node {
  335. type: "ImportDeclaration"
  336. specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>
  337. source: Literal
  338. attributes: Array<ImportAttribute>
  339. }
  340. export interface ImportSpecifier extends Node {
  341. type: "ImportSpecifier"
  342. imported: Identifier | Literal
  343. local: Identifier
  344. }
  345. export interface ImportDefaultSpecifier extends Node {
  346. type: "ImportDefaultSpecifier"
  347. local: Identifier
  348. }
  349. export interface ImportNamespaceSpecifier extends Node {
  350. type: "ImportNamespaceSpecifier"
  351. local: Identifier
  352. }
  353. export interface ImportAttribute extends Node {
  354. type: "ImportAttribute"
  355. key: Identifier | Literal
  356. value: Literal
  357. }
  358. export interface ExportNamedDeclaration extends Node {
  359. type: "ExportNamedDeclaration"
  360. declaration?: Declaration | null
  361. specifiers: Array<ExportSpecifier>
  362. source?: Literal | null
  363. attributes: Array<ImportAttribute>
  364. }
  365. export interface ExportSpecifier extends Node {
  366. type: "ExportSpecifier"
  367. exported: Identifier | Literal
  368. local: Identifier | Literal
  369. }
  370. export interface AnonymousFunctionDeclaration extends Function {
  371. type: "FunctionDeclaration"
  372. id: null
  373. body: BlockStatement
  374. }
  375. export interface AnonymousClassDeclaration extends Class {
  376. type: "ClassDeclaration"
  377. id: null
  378. }
  379. export interface ExportDefaultDeclaration extends Node {
  380. type: "ExportDefaultDeclaration"
  381. declaration: AnonymousFunctionDeclaration | FunctionDeclaration | AnonymousClassDeclaration | ClassDeclaration | Expression
  382. }
  383. export interface ExportAllDeclaration extends Node {
  384. type: "ExportAllDeclaration"
  385. source: Literal
  386. exported?: Identifier | Literal | null
  387. attributes: Array<ImportAttribute>
  388. }
  389. export interface AwaitExpression extends Node {
  390. type: "AwaitExpression"
  391. argument: Expression
  392. }
  393. export interface ChainExpression extends Node {
  394. type: "ChainExpression"
  395. expression: MemberExpression | CallExpression
  396. }
  397. export interface ImportExpression extends Node {
  398. type: "ImportExpression"
  399. source: Expression
  400. options: Expression | null
  401. }
  402. export interface ParenthesizedExpression extends Node {
  403. type: "ParenthesizedExpression"
  404. expression: Expression
  405. }
  406. export interface PropertyDefinition extends Node {
  407. type: "PropertyDefinition"
  408. key: Expression | PrivateIdentifier
  409. value?: Expression | null
  410. computed: boolean
  411. static: boolean
  412. }
  413. export interface PrivateIdentifier extends Node {
  414. type: "PrivateIdentifier"
  415. name: string
  416. }
  417. export interface StaticBlock extends Node {
  418. type: "StaticBlock"
  419. body: Array<Statement>
  420. }
  421. export type Statement =
  422. | ExpressionStatement
  423. | BlockStatement
  424. | EmptyStatement
  425. | DebuggerStatement
  426. | WithStatement
  427. | ReturnStatement
  428. | LabeledStatement
  429. | BreakStatement
  430. | ContinueStatement
  431. | IfStatement
  432. | SwitchStatement
  433. | ThrowStatement
  434. | TryStatement
  435. | WhileStatement
  436. | DoWhileStatement
  437. | ForStatement
  438. | ForInStatement
  439. | ForOfStatement
  440. | Declaration
  441. export type Declaration =
  442. | FunctionDeclaration
  443. | VariableDeclaration
  444. | ClassDeclaration
  445. export type Expression =
  446. | Identifier
  447. | Literal
  448. | ThisExpression
  449. | ArrayExpression
  450. | ObjectExpression
  451. | FunctionExpression
  452. | UnaryExpression
  453. | UpdateExpression
  454. | BinaryExpression
  455. | AssignmentExpression
  456. | LogicalExpression
  457. | MemberExpression
  458. | ConditionalExpression
  459. | CallExpression
  460. | NewExpression
  461. | SequenceExpression
  462. | ArrowFunctionExpression
  463. | YieldExpression
  464. | TemplateLiteral
  465. | TaggedTemplateExpression
  466. | ClassExpression
  467. | MetaProperty
  468. | AwaitExpression
  469. | ChainExpression
  470. | ImportExpression
  471. | ParenthesizedExpression
  472. export type Pattern =
  473. | Identifier
  474. | MemberExpression
  475. | ObjectPattern
  476. | ArrayPattern
  477. | RestElement
  478. | AssignmentPattern
  479. export type ModuleDeclaration =
  480. | ImportDeclaration
  481. | ExportNamedDeclaration
  482. | ExportDefaultDeclaration
  483. | ExportAllDeclaration
  484. export type AnyNode = Statement | Expression | Declaration | ModuleDeclaration | Literal | Program | SwitchCase | CatchClause | Property | Super | SpreadElement | TemplateElement | AssignmentProperty | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | ClassBody | MethodDefinition | MetaProperty | ImportAttribute | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier | AnonymousFunctionDeclaration | AnonymousClassDeclaration | PropertyDefinition | PrivateIdentifier | StaticBlock | VariableDeclarator
  485. export function parse(input: string, options: Options): Program
  486. export function parseExpressionAt(input: string, pos: number, options: Options): Expression
  487. export function tokenizer(input: string, options: Options): {
  488. getToken(): Token
  489. [Symbol.iterator](): Iterator<Token>
  490. }
  491. export type ecmaVersion = 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025 | "latest"
  492. export interface Options {
  493. /**
  494. * `ecmaVersion` indicates the ECMAScript version to parse. Can be a
  495. * number, either in year (`2022`) or plain version number (`6`) form,
  496. * or `"latest"` (the latest the library supports). This influences
  497. * support for strict mode, the set of reserved words, and support for
  498. * new syntax features.
  499. */
  500. ecmaVersion: ecmaVersion
  501. /**
  502. * `sourceType` indicates the mode the code should be parsed in.
  503. * Can be either `"script"` or `"module"`. This influences global
  504. * strict mode and parsing of `import` and `export` declarations.
  505. */
  506. sourceType?: "script" | "module"
  507. /**
  508. * a callback that will be called when a semicolon is automatically inserted.
  509. * @param lastTokEnd the position of the comma as an offset
  510. * @param lastTokEndLoc location if {@link locations} is enabled
  511. */
  512. onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: Position) => void
  513. /**
  514. * similar to `onInsertedSemicolon`, but for trailing commas
  515. * @param lastTokEnd the position of the comma as an offset
  516. * @param lastTokEndLoc location if `locations` is enabled
  517. */
  518. onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: Position) => void
  519. /**
  520. * By default, reserved words are only enforced if ecmaVersion >= 5.
  521. * Set `allowReserved` to a boolean value to explicitly turn this on
  522. * an off. When this option has the value "never", reserved words
  523. * and keywords can also not be used as property names.
  524. */
  525. allowReserved?: boolean | "never"
  526. /**
  527. * When enabled, a return at the top level is not considered an error.
  528. */
  529. allowReturnOutsideFunction?: boolean
  530. /**
  531. * When enabled, import/export statements are not constrained to
  532. * appearing at the top of the program, and an import.meta expression
  533. * in a script isn't considered an error.
  534. */
  535. allowImportExportEverywhere?: boolean
  536. /**
  537. * By default, `await` identifiers are allowed to appear at the top-level scope only if {@link ecmaVersion} >= 2022.
  538. * When enabled, await identifiers are allowed to appear at the top-level scope,
  539. * but they are still not allowed in non-async functions.
  540. */
  541. allowAwaitOutsideFunction?: boolean
  542. /**
  543. * When enabled, super identifiers are not constrained to
  544. * appearing in methods and do not raise an error when they appear elsewhere.
  545. */
  546. allowSuperOutsideMethod?: boolean
  547. /**
  548. * When enabled, hashbang directive in the beginning of file is
  549. * allowed and treated as a line comment. Enabled by default when
  550. * {@link ecmaVersion} >= 2023.
  551. */
  552. allowHashBang?: boolean
  553. /**
  554. * By default, the parser will verify that private properties are
  555. * only used in places where they are valid and have been declared.
  556. * Set this to false to turn such checks off.
  557. */
  558. checkPrivateFields?: boolean
  559. /**
  560. * When `locations` is on, `loc` properties holding objects with
  561. * `start` and `end` properties as {@link Position} objects will be attached to the
  562. * nodes.
  563. */
  564. locations?: boolean
  565. /**
  566. * a callback that will cause Acorn to call that export function with object in the same
  567. * format as tokens returned from `tokenizer().getToken()`. Note
  568. * that you are not allowed to call the parser from the
  569. * callback—that will corrupt its internal state.
  570. */
  571. onToken?: ((token: Token) => void) | Token[]
  572. /**
  573. * This takes a export function or an array.
  574. *
  575. * When a export function is passed, Acorn will call that export function with `(block, text, start,
  576. * end)` parameters whenever a comment is skipped. `block` is a
  577. * boolean indicating whether this is a block (`/* *\/`) comment,
  578. * `text` is the content of the comment, and `start` and `end` are
  579. * character offsets that denote the start and end of the comment.
  580. * When the {@link locations} option is on, two more parameters are
  581. * passed, the full locations of {@link Position} export type of the start and
  582. * end of the comments.
  583. *
  584. * When a array is passed, each found comment of {@link Comment} export type is pushed to the array.
  585. *
  586. * Note that you are not allowed to call the
  587. * parser from the callback—that will corrupt its internal state.
  588. */
  589. onComment?: ((
  590. isBlock: boolean, text: string, start: number, end: number, startLoc?: Position,
  591. endLoc?: Position
  592. ) => void) | Comment[]
  593. /**
  594. * Nodes have their start and end characters offsets recorded in
  595. * `start` and `end` properties (directly on the node, rather than
  596. * the `loc` object, which holds line/column data. To also add a
  597. * [semi-standardized][range] `range` property holding a `[start,
  598. * end]` array with the same numbers, set the `ranges` option to
  599. * `true`.
  600. */
  601. ranges?: boolean
  602. /**
  603. * It is possible to parse multiple files into a single AST by
  604. * passing the tree produced by parsing the first file as
  605. * `program` option in subsequent parses. This will add the
  606. * toplevel forms of the parsed file to the `Program` (top) node
  607. * of an existing parse tree.
  608. */
  609. program?: Node
  610. /**
  611. * When {@link locations} is on, you can pass this to record the source
  612. * file in every node's `loc` object.
  613. */
  614. sourceFile?: string
  615. /**
  616. * This value, if given, is stored in every node, whether {@link locations} is on or off.
  617. */
  618. directSourceFile?: string
  619. /**
  620. * When enabled, parenthesized expressions are represented by
  621. * (non-standard) ParenthesizedExpression nodes
  622. */
  623. preserveParens?: boolean
  624. }
  625. export class Parser {
  626. options: Options
  627. input: string
  628. protected constructor(options: Options, input: string, startPos?: number)
  629. parse(): Program
  630. static parse(input: string, options: Options): Program
  631. static parseExpressionAt(input: string, pos: number, options: Options): Expression
  632. static tokenizer(input: string, options: Options): {
  633. getToken(): Token
  634. [Symbol.iterator](): Iterator<Token>
  635. }
  636. static extend(...plugins: ((BaseParser: typeof Parser) => typeof Parser)[]): typeof Parser
  637. }
  638. export const defaultOptions: Options
  639. export function getLineInfo(input: string, offset: number): Position
  640. export class TokenType {
  641. label: string
  642. keyword: string | undefined
  643. }
  644. export const tokTypes: {
  645. num: TokenType
  646. regexp: TokenType
  647. string: TokenType
  648. name: TokenType
  649. privateId: TokenType
  650. eof: TokenType
  651. bracketL: TokenType
  652. bracketR: TokenType
  653. braceL: TokenType
  654. braceR: TokenType
  655. parenL: TokenType
  656. parenR: TokenType
  657. comma: TokenType
  658. semi: TokenType
  659. colon: TokenType
  660. dot: TokenType
  661. question: TokenType
  662. questionDot: TokenType
  663. arrow: TokenType
  664. template: TokenType
  665. invalidTemplate: TokenType
  666. ellipsis: TokenType
  667. backQuote: TokenType
  668. dollarBraceL: TokenType
  669. eq: TokenType
  670. assign: TokenType
  671. incDec: TokenType
  672. prefix: TokenType
  673. logicalOR: TokenType
  674. logicalAND: TokenType
  675. bitwiseOR: TokenType
  676. bitwiseXOR: TokenType
  677. bitwiseAND: TokenType
  678. equality: TokenType
  679. relational: TokenType
  680. bitShift: TokenType
  681. plusMin: TokenType
  682. modulo: TokenType
  683. star: TokenType
  684. slash: TokenType
  685. starstar: TokenType
  686. coalesce: TokenType
  687. _break: TokenType
  688. _case: TokenType
  689. _catch: TokenType
  690. _continue: TokenType
  691. _debugger: TokenType
  692. _default: TokenType
  693. _do: TokenType
  694. _else: TokenType
  695. _finally: TokenType
  696. _for: TokenType
  697. _function: TokenType
  698. _if: TokenType
  699. _return: TokenType
  700. _switch: TokenType
  701. _throw: TokenType
  702. _try: TokenType
  703. _var: TokenType
  704. _const: TokenType
  705. _while: TokenType
  706. _with: TokenType
  707. _new: TokenType
  708. _this: TokenType
  709. _super: TokenType
  710. _class: TokenType
  711. _extends: TokenType
  712. _export: TokenType
  713. _import: TokenType
  714. _null: TokenType
  715. _true: TokenType
  716. _false: TokenType
  717. _in: TokenType
  718. _instanceof: TokenType
  719. _typeof: TokenType
  720. _void: TokenType
  721. _delete: TokenType
  722. }
  723. export interface Comment {
  724. type: "Line" | "Block"
  725. value: string
  726. start: number
  727. end: number
  728. loc?: SourceLocation
  729. range?: [number, number]
  730. }
  731. export class Token {
  732. type: TokenType
  733. start: number
  734. end: number
  735. loc?: SourceLocation
  736. range?: [number, number]
  737. }
  738. export const version: string