babel-parser.d.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. allowSuperOutsideMethod?: boolean;
  111. /**
  112. * By default, exported identifiers must refer to a declared variable.
  113. * Set this to true to allow export statements to reference undeclared variables.
  114. */
  115. allowUndeclaredExports?: boolean;
  116. /**
  117. * By default, Babel attaches comments to adjacent AST nodes.
  118. * When this option is set to false, comments are not attached.
  119. * It can provide up to 30% performance improvement when the input code has many comments.
  120. * @babel/eslint-parser will set it for you.
  121. * It is not recommended to use attachComment: false with Babel transform,
  122. * as doing so removes all the comments in output code, and renders annotations such as
  123. * /* istanbul ignore next *\/ nonfunctional.
  124. */
  125. attachComment?: boolean;
  126. /**
  127. * By default, Babel always throws an error when it finds some invalid code.
  128. * When this option is set to true, it will store the parsing error and
  129. * try to continue parsing the invalid input file.
  130. */
  131. errorRecovery?: boolean;
  132. /**
  133. * Indicate the mode the code should be parsed in.
  134. * Can be one of "script", "module", or "unambiguous". Defaults to "script".
  135. * "unambiguous" will make @babel/parser attempt to guess, based on the presence
  136. * of ES6 import or export statements.
  137. * Files with ES6 imports and exports are considered "module" and are otherwise "script".
  138. */
  139. sourceType?: "script" | "module" | "unambiguous";
  140. /**
  141. * Correlate output AST nodes with their source filename.
  142. * Useful when generating code and source maps from the ASTs of multiple input files.
  143. */
  144. sourceFilename?: string;
  145. /**
  146. * By default, the first line of code parsed is treated as line 1.
  147. * You can provide a line number to alternatively start with.
  148. * Useful for integration with other source tools.
  149. */
  150. startLine?: number;
  151. /**
  152. * By default, the parsed code is treated as if it starts from line 1, column 0.
  153. * You can provide a column number to alternatively start with.
  154. * Useful for integration with other source tools.
  155. */
  156. startColumn?: number;
  157. /**
  158. * Array containing the plugins that you want to enable.
  159. */
  160. plugins?: ParserPlugin[];
  161. /**
  162. * Should the parser work in strict mode.
  163. * Defaults to true if sourceType === 'module'. Otherwise, false.
  164. */
  165. strictMode?: boolean;
  166. /**
  167. * Adds a ranges property to each node: [node.start, node.end]
  168. */
  169. ranges?: boolean;
  170. /**
  171. * Adds all parsed tokens to a tokens property on the File node.
  172. */
  173. tokens?: boolean;
  174. /**
  175. * By default, the parser adds information about parentheses by setting
  176. * `extra.parenthesized` to `true` as needed.
  177. * When this option is `true` the parser creates `ParenthesizedExpression`
  178. * AST nodes instead of using the `extra` property.
  179. */
  180. createParenthesizedExpressions?: boolean;
  181. }
  182. type ParserPlugin = PluginConfig;
  183. declare const tokTypes: {
  184. // todo(flow->ts) real token type
  185. [name: string]: any;
  186. };
  187. interface ParseError {
  188. code: string;
  189. reasonCode: string;
  190. }
  191. type ParseResult<Result> = Result & {
  192. errors: ParseError[];
  193. };
  194. export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParseResult, ParserOptions, ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes };