babel-parser.d.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // This file is auto-generated! Do not modify it directly.
  2. /* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/consistent-type-imports, prettier/prettier */
  3. import * as _babel_types from '@babel/types';
  4. type Plugin =
  5. | "asyncDoExpressions"
  6. | "asyncGenerators"
  7. | "bigInt"
  8. | "classPrivateMethods"
  9. | "classPrivateProperties"
  10. | "classProperties"
  11. | "classStaticBlock" // Enabled by default
  12. | "decimal"
  13. | "decorators-legacy"
  14. | "decoratorAutoAccessors"
  15. | "destructuringPrivate"
  16. | "doExpressions"
  17. | "dynamicImport"
  18. | "explicitResourceManagement"
  19. | "exportDefaultFrom"
  20. | "exportNamespaceFrom" // deprecated
  21. | "flow"
  22. | "flowComments"
  23. | "functionBind"
  24. | "functionSent"
  25. | "importMeta"
  26. | "jsx"
  27. | "logicalAssignment"
  28. | "importAssertions"
  29. | "importReflection"
  30. | "moduleBlocks"
  31. | "moduleStringNames"
  32. | "nullishCoalescingOperator"
  33. | "numericSeparator"
  34. | "objectRestSpread"
  35. | "optionalCatchBinding"
  36. | "optionalChaining"
  37. | "partialApplication"
  38. | "placeholders"
  39. | "privateIn" // Enabled by default
  40. | "regexpUnicodeSets"
  41. | "throwExpressions"
  42. | "topLevelAwait"
  43. | "v8intrinsic"
  44. | ParserPluginWithOptions[0];
  45. type ParserPluginWithOptions =
  46. | ["decorators", DecoratorsPluginOptions]
  47. | ["estree", { classFeatures?: boolean }]
  48. // @deprecated
  49. | ["moduleAttributes", { version: "may-2020" }]
  50. | ["pipelineOperator", PipelineOperatorPluginOptions]
  51. | ["recordAndTuple", RecordAndTuplePluginOptions]
  52. | ["flow", FlowPluginOptions]
  53. | ["typescript", TypeScriptPluginOptions];
  54. type PluginConfig = Plugin | ParserPluginWithOptions;
  55. interface DecoratorsPluginOptions {
  56. decoratorsBeforeExport?: boolean;
  57. allowCallParenthesized?: boolean;
  58. }
  59. interface PipelineOperatorPluginOptions {
  60. proposal: "minimal" | "fsharp" | "hack" | "smart";
  61. topicToken?: "%" | "#" | "@@" | "^^" | "^";
  62. }
  63. interface RecordAndTuplePluginOptions {
  64. syntaxType: "bar" | "hash";
  65. }
  66. interface FlowPluginOptions {
  67. all?: boolean;
  68. enums?: boolean;
  69. }
  70. interface TypeScriptPluginOptions {
  71. dts?: boolean;
  72. disallowAmbiguousJSXLike?: boolean;
  73. }
  74. // Type definitions for @babel/parser
  75. // Project: https://github.com/babel/babel/tree/main/packages/babel-parser
  76. // Definitions by: Troy Gerwien <https://github.com/yortus>
  77. // Marvin Hagemeister <https://github.com/marvinhagemeister>
  78. // Avi Vahl <https://github.com/AviVahl>
  79. // TypeScript Version: 2.9
  80. /**
  81. * Parse the provided code as an entire ECMAScript program.
  82. */
  83. declare function parse(
  84. input: string,
  85. options?: ParserOptions
  86. ): ParseResult<_babel_types.File>;
  87. /**
  88. * Parse the provided code as a single expression.
  89. */
  90. declare function parseExpression(
  91. input: string,
  92. options?: ParserOptions
  93. ): ParseResult<_babel_types.Expression>;
  94. interface ParserOptions {
  95. /**
  96. * By default, import and export declarations can only appear at a program's top level.
  97. * Setting this option to true allows them anywhere where a statement is allowed.
  98. */
  99. allowImportExportEverywhere?: boolean;
  100. /**
  101. * By default, await use is not allowed outside of an async function.
  102. * Set this to true to accept such code.
  103. */
  104. allowAwaitOutsideFunction?: boolean;
  105. /**
  106. * By default, a return statement at the top level raises an error.
  107. * Set this to true to accept such code.
  108. */
  109. allowReturnOutsideFunction?: boolean;
  110. /**
  111. * By default, new.target use is not allowed outside of a function or class.
  112. * Set this to true to accept such code.
  113. */
  114. allowNewTargetOutsideFunction?: boolean;
  115. allowSuperOutsideMethod?: boolean;
  116. /**
  117. * By default, exported identifiers must refer to a declared variable.
  118. * Set this to true to allow export statements to reference undeclared variables.
  119. */
  120. allowUndeclaredExports?: boolean;
  121. /**
  122. * By default, Babel parser JavaScript code according to Annex B syntax.
  123. * Set this to `false` to disable such behavior.
  124. */
  125. annexB?: boolean;
  126. /**
  127. * By default, Babel attaches comments to adjacent AST nodes.
  128. * When this option is set to false, comments are not attached.
  129. * It can provide up to 30% performance improvement when the input code has many comments.
  130. * @babel/eslint-parser will set it for you.
  131. * It is not recommended to use attachComment: false with Babel transform,
  132. * as doing so removes all the comments in output code, and renders annotations such as
  133. * /* istanbul ignore next *\/ nonfunctional.
  134. */
  135. attachComment?: boolean;
  136. /**
  137. * By default, Babel always throws an error when it finds some invalid code.
  138. * When this option is set to true, it will store the parsing error and
  139. * try to continue parsing the invalid input file.
  140. */
  141. errorRecovery?: boolean;
  142. /**
  143. * Indicate the mode the code should be parsed in.
  144. * Can be one of "script", "module", or "unambiguous". Defaults to "script".
  145. * "unambiguous" will make @babel/parser attempt to guess, based on the presence
  146. * of ES6 import or export statements.
  147. * Files with ES6 imports and exports are considered "module" and are otherwise "script".
  148. */
  149. sourceType?: "script" | "module" | "unambiguous";
  150. /**
  151. * Correlate output AST nodes with their source filename.
  152. * Useful when generating code and source maps from the ASTs of multiple input files.
  153. */
  154. sourceFilename?: string;
  155. /**
  156. * By default, the first line of code parsed is treated as line 1.
  157. * You can provide a line number to alternatively start with.
  158. * Useful for integration with other source tools.
  159. */
  160. startLine?: number;
  161. /**
  162. * By default, the parsed code is treated as if it starts from line 1, column 0.
  163. * You can provide a column number to alternatively start with.
  164. * Useful for integration with other source tools.
  165. */
  166. startColumn?: number;
  167. /**
  168. * Array containing the plugins that you want to enable.
  169. */
  170. plugins?: ParserPlugin[];
  171. /**
  172. * Should the parser work in strict mode.
  173. * Defaults to true if sourceType === 'module'. Otherwise, false.
  174. */
  175. strictMode?: boolean;
  176. /**
  177. * Adds a ranges property to each node: [node.start, node.end]
  178. */
  179. ranges?: boolean;
  180. /**
  181. * Adds all parsed tokens to a tokens property on the File node.
  182. */
  183. tokens?: boolean;
  184. /**
  185. * By default, the parser adds information about parentheses by setting
  186. * `extra.parenthesized` to `true` as needed.
  187. * When this option is `true` the parser creates `ParenthesizedExpression`
  188. * AST nodes instead of using the `extra` property.
  189. */
  190. createParenthesizedExpressions?: boolean;
  191. }
  192. type ParserPlugin = PluginConfig;
  193. declare const tokTypes: {
  194. // todo(flow->ts) real token type
  195. [name: string]: any;
  196. };
  197. interface ParseError {
  198. code: string;
  199. reasonCode: string;
  200. }
  201. type ParseResult<Result> = Result & {
  202. errors: ParseError[];
  203. };
  204. export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParseResult, ParserOptions, ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes };