acorn.d.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. export as namespace acorn
  2. export = acorn
  3. declare namespace acorn {
  4. function parse(input: string, options: Options): Node
  5. function parseExpressionAt(input: string, pos: number, options: Options): Node
  6. function tokenizer(input: string, options: Options): {
  7. getToken(): Token
  8. [Symbol.iterator](): Iterator<Token>
  9. }
  10. interface Options {
  11. ecmaVersion: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 'latest'
  12. sourceType?: 'script' | 'module'
  13. onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: Position) => void
  14. onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: Position) => void
  15. allowReserved?: boolean | 'never'
  16. allowReturnOutsideFunction?: boolean
  17. allowImportExportEverywhere?: boolean
  18. allowAwaitOutsideFunction?: boolean
  19. allowSuperOutsideMethod?: boolean
  20. allowHashBang?: boolean
  21. locations?: boolean
  22. onToken?: ((token: Token) => any) | Token[]
  23. onComment?: ((
  24. isBlock: boolean, text: string, start: number, end: number, startLoc?: Position,
  25. endLoc?: Position
  26. ) => void) | Comment[]
  27. ranges?: boolean
  28. program?: Node
  29. sourceFile?: string
  30. directSourceFile?: string
  31. preserveParens?: boolean
  32. }
  33. class Parser {
  34. constructor(options: Options, input: string, startPos?: number)
  35. parse(this: Parser): Node
  36. static parse(this: typeof Parser, input: string, options: Options): Node
  37. static parseExpressionAt(this: typeof Parser, input: string, pos: number, options: Options): Node
  38. static tokenizer(this: typeof Parser, input: string, options: Options): {
  39. getToken(): Token
  40. [Symbol.iterator](): Iterator<Token>
  41. }
  42. static extend(this: typeof Parser, ...plugins: ((BaseParser: typeof Parser) => typeof Parser)[]): typeof Parser
  43. }
  44. interface Position { line: number; column: number; offset: number }
  45. const defaultOptions: Options
  46. function getLineInfo(input: string, offset: number): Position
  47. class SourceLocation {
  48. start: Position
  49. end: Position
  50. source?: string | null
  51. constructor(p: Parser, start: Position, end: Position)
  52. }
  53. class Node {
  54. type: string
  55. start: number
  56. end: number
  57. loc?: SourceLocation
  58. sourceFile?: string
  59. range?: [number, number]
  60. constructor(parser: Parser, pos: number, loc?: SourceLocation)
  61. }
  62. class TokenType {
  63. label: string
  64. keyword: string
  65. beforeExpr: boolean
  66. startsExpr: boolean
  67. isLoop: boolean
  68. isAssign: boolean
  69. prefix: boolean
  70. postfix: boolean
  71. binop: number
  72. updateContext?: (prevType: TokenType) => void
  73. constructor(label: string, conf?: any)
  74. }
  75. const tokTypes: {
  76. num: TokenType
  77. regexp: TokenType
  78. string: TokenType
  79. name: TokenType
  80. privateId: TokenType
  81. eof: TokenType
  82. bracketL: TokenType
  83. bracketR: TokenType
  84. braceL: TokenType
  85. braceR: TokenType
  86. parenL: TokenType
  87. parenR: TokenType
  88. comma: TokenType
  89. semi: TokenType
  90. colon: TokenType
  91. dot: TokenType
  92. question: TokenType
  93. arrow: TokenType
  94. template: TokenType
  95. ellipsis: TokenType
  96. backQuote: TokenType
  97. dollarBraceL: TokenType
  98. eq: TokenType
  99. assign: TokenType
  100. incDec: TokenType
  101. prefix: TokenType
  102. logicalOR: TokenType
  103. logicalAND: TokenType
  104. bitwiseOR: TokenType
  105. bitwiseXOR: TokenType
  106. bitwiseAND: TokenType
  107. equality: TokenType
  108. relational: TokenType
  109. bitShift: TokenType
  110. plusMin: TokenType
  111. modulo: TokenType
  112. star: TokenType
  113. slash: TokenType
  114. starstar: TokenType
  115. _break: TokenType
  116. _case: TokenType
  117. _catch: TokenType
  118. _continue: TokenType
  119. _debugger: TokenType
  120. _default: TokenType
  121. _do: TokenType
  122. _else: TokenType
  123. _finally: TokenType
  124. _for: TokenType
  125. _function: TokenType
  126. _if: TokenType
  127. _return: TokenType
  128. _switch: TokenType
  129. _throw: TokenType
  130. _try: TokenType
  131. _var: TokenType
  132. _const: TokenType
  133. _while: TokenType
  134. _with: TokenType
  135. _new: TokenType
  136. _this: TokenType
  137. _super: TokenType
  138. _class: TokenType
  139. _extends: TokenType
  140. _export: TokenType
  141. _import: TokenType
  142. _null: TokenType
  143. _true: TokenType
  144. _false: TokenType
  145. _in: TokenType
  146. _instanceof: TokenType
  147. _typeof: TokenType
  148. _void: TokenType
  149. _delete: TokenType
  150. }
  151. class TokContext {
  152. constructor(token: string, isExpr: boolean, preserveSpace: boolean, override?: (p: Parser) => void)
  153. }
  154. const tokContexts: {
  155. b_stat: TokContext
  156. b_expr: TokContext
  157. b_tmpl: TokContext
  158. p_stat: TokContext
  159. p_expr: TokContext
  160. q_tmpl: TokContext
  161. f_expr: TokContext
  162. f_stat: TokContext
  163. f_expr_gen: TokContext
  164. f_gen: TokContext
  165. }
  166. function isIdentifierStart(code: number, astral?: boolean): boolean
  167. function isIdentifierChar(code: number, astral?: boolean): boolean
  168. interface AbstractToken {
  169. }
  170. interface Comment extends AbstractToken {
  171. type: string
  172. value: string
  173. start: number
  174. end: number
  175. loc?: SourceLocation
  176. range?: [number, number]
  177. }
  178. class Token {
  179. type: TokenType
  180. value: any
  181. start: number
  182. end: number
  183. loc?: SourceLocation
  184. range?: [number, number]
  185. constructor(p: Parser)
  186. }
  187. function isNewLine(code: number): boolean
  188. const lineBreak: RegExp
  189. const lineBreakG: RegExp
  190. const version: string
  191. }