acorn.d.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. type ecmaVersion = 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 'latest'
  11. interface Options {
  12. ecmaVersion: ecmaVersion
  13. sourceType?: 'script' | 'module'
  14. onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: Position) => void
  15. onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: Position) => void
  16. allowReserved?: boolean | 'never'
  17. allowReturnOutsideFunction?: boolean
  18. allowImportExportEverywhere?: boolean
  19. allowAwaitOutsideFunction?: boolean
  20. allowSuperOutsideMethod?: boolean
  21. allowHashBang?: boolean
  22. locations?: boolean
  23. onToken?: ((token: Token) => any) | Token[]
  24. onComment?: ((
  25. isBlock: boolean, text: string, start: number, end: number, startLoc?: Position,
  26. endLoc?: Position
  27. ) => void) | Comment[]
  28. ranges?: boolean
  29. program?: Node
  30. sourceFile?: string
  31. directSourceFile?: string
  32. preserveParens?: boolean
  33. }
  34. class Parser {
  35. // state.js
  36. lineStart: number;
  37. options: Options;
  38. curLine: number;
  39. start: number;
  40. end: number;
  41. input: string;
  42. type: TokenType;
  43. // state.js
  44. constructor(options: Options, input: string, startPos?: number)
  45. parse(this: Parser): Node
  46. // tokenize.js
  47. next(): void;
  48. nextToken(): void;
  49. // statement.js
  50. parseTopLevel(node: Node): Node;
  51. // node.js
  52. finishNode(node: Node, type: string): Node;
  53. finishNodeAt(node: Node, type: string, pos: number, loc: Position): Node;
  54. // location.js
  55. raise(pos: number, message: string) : void;
  56. raiseRecoverable?(pos: number, message: string) : void;
  57. // parseutils.js
  58. unexpected(pos: number) : void;
  59. // index.js
  60. static acorn: typeof acorn;
  61. // state.js
  62. static parse(this: typeof Parser, input: string, options: Options): Node
  63. static parseExpressionAt(this: typeof Parser, input: string, pos: number, options: Options): Node
  64. static tokenizer(this: typeof Parser, input: string, options: Options): {
  65. getToken(): Token
  66. [Symbol.iterator](): Iterator<Token>
  67. }
  68. static extend(this: typeof Parser, ...plugins: ((BaseParser: typeof Parser) => typeof Parser)[]): typeof Parser
  69. }
  70. interface Position { line: number; column: number; offset: number }
  71. const defaultOptions: Options
  72. function getLineInfo(input: string, offset: number): Position
  73. class SourceLocation {
  74. start: Position
  75. end: Position
  76. source?: string | null
  77. constructor(p: Parser, start: Position, end: Position)
  78. }
  79. class Node {
  80. type: string
  81. start: number
  82. end: number
  83. loc?: SourceLocation
  84. sourceFile?: string
  85. range?: [number, number]
  86. constructor(parser: Parser, pos: number, loc?: SourceLocation)
  87. }
  88. class TokenType {
  89. label: string
  90. keyword: string
  91. beforeExpr: boolean
  92. startsExpr: boolean
  93. isLoop: boolean
  94. isAssign: boolean
  95. prefix: boolean
  96. postfix: boolean
  97. binop: number
  98. updateContext?: (prevType: TokenType) => void
  99. constructor(label: string, conf?: any)
  100. }
  101. const tokTypes: {
  102. num: TokenType
  103. regexp: TokenType
  104. string: TokenType
  105. name: TokenType
  106. privateId: TokenType
  107. eof: TokenType
  108. bracketL: TokenType
  109. bracketR: TokenType
  110. braceL: TokenType
  111. braceR: TokenType
  112. parenL: TokenType
  113. parenR: TokenType
  114. comma: TokenType
  115. semi: TokenType
  116. colon: TokenType
  117. dot: TokenType
  118. question: TokenType
  119. questionDot: TokenType
  120. arrow: TokenType
  121. template: TokenType
  122. invalidTemplate: TokenType
  123. ellipsis: TokenType
  124. backQuote: TokenType
  125. dollarBraceL: TokenType
  126. eq: TokenType
  127. assign: TokenType
  128. incDec: TokenType
  129. prefix: TokenType
  130. logicalOR: TokenType
  131. logicalAND: TokenType
  132. bitwiseOR: TokenType
  133. bitwiseXOR: TokenType
  134. bitwiseAND: TokenType
  135. equality: TokenType
  136. relational: TokenType
  137. bitShift: TokenType
  138. plusMin: TokenType
  139. modulo: TokenType
  140. star: TokenType
  141. slash: TokenType
  142. starstar: TokenType
  143. coalesce: TokenType
  144. _break: TokenType
  145. _case: TokenType
  146. _catch: TokenType
  147. _continue: TokenType
  148. _debugger: TokenType
  149. _default: TokenType
  150. _do: TokenType
  151. _else: TokenType
  152. _finally: TokenType
  153. _for: TokenType
  154. _function: TokenType
  155. _if: TokenType
  156. _return: TokenType
  157. _switch: TokenType
  158. _throw: TokenType
  159. _try: TokenType
  160. _var: TokenType
  161. _const: TokenType
  162. _while: TokenType
  163. _with: TokenType
  164. _new: TokenType
  165. _this: TokenType
  166. _super: TokenType
  167. _class: TokenType
  168. _extends: TokenType
  169. _export: TokenType
  170. _import: TokenType
  171. _null: TokenType
  172. _true: TokenType
  173. _false: TokenType
  174. _in: TokenType
  175. _instanceof: TokenType
  176. _typeof: TokenType
  177. _void: TokenType
  178. _delete: TokenType
  179. }
  180. class TokContext {
  181. constructor(token: string, isExpr: boolean, preserveSpace: boolean, override?: (p: Parser) => void)
  182. }
  183. const tokContexts: {
  184. b_stat: TokContext
  185. b_expr: TokContext
  186. b_tmpl: TokContext
  187. p_stat: TokContext
  188. p_expr: TokContext
  189. q_tmpl: TokContext
  190. f_expr: TokContext
  191. f_stat: TokContext
  192. f_expr_gen: TokContext
  193. f_gen: TokContext
  194. }
  195. function isIdentifierStart(code: number, astral?: boolean): boolean
  196. function isIdentifierChar(code: number, astral?: boolean): boolean
  197. interface AbstractToken {
  198. }
  199. interface Comment extends AbstractToken {
  200. type: 'Line' | 'Block'
  201. value: string
  202. start: number
  203. end: number
  204. loc?: SourceLocation
  205. range?: [number, number]
  206. }
  207. class Token {
  208. type: TokenType
  209. value: any
  210. start: number
  211. end: number
  212. loc?: SourceLocation
  213. range?: [number, number]
  214. constructor(p: Parser)
  215. }
  216. function isNewLine(code: number): boolean
  217. const lineBreak: RegExp
  218. const lineBreakG: RegExp
  219. const version: string
  220. const nonASCIIwhitespace: RegExp
  221. const keywordTypes: {
  222. _break: TokenType
  223. _case: TokenType
  224. _catch: TokenType
  225. _continue: TokenType
  226. _debugger: TokenType
  227. _default: TokenType
  228. _do: TokenType
  229. _else: TokenType
  230. _finally: TokenType
  231. _for: TokenType
  232. _function: TokenType
  233. _if: TokenType
  234. _return: TokenType
  235. _switch: TokenType
  236. _throw: TokenType
  237. _try: TokenType
  238. _var: TokenType
  239. _const: TokenType
  240. _while: TokenType
  241. _with: TokenType
  242. _new: TokenType
  243. _this: TokenType
  244. _super: TokenType
  245. _class: TokenType
  246. _extends: TokenType
  247. _export: TokenType
  248. _import: TokenType
  249. _null: TokenType
  250. _true: TokenType
  251. _false: TokenType
  252. _in: TokenType
  253. _instanceof: TokenType
  254. _typeof: TokenType
  255. _void: TokenType
  256. _delete: TokenType
  257. }
  258. }