babel-parser.d.ts 9.1 KB

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