You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
5.1 KiB

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