babel-parser.d.ts 8.0 KB

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