babel-parser.d.ts 7.9 KB

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