babel-parser.d.ts 7.0 KB

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