babel-parser.d.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. | IF_BABEL_7<"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. | ["discardBinding", { syntaxType: "void" }]
  55. | ["estree", { classFeatures?: boolean }]
  56. | IF_BABEL_7<["importAttributes", { deprecatedAssertSyntax: boolean }]>
  57. | IF_BABEL_7<["moduleAttributes", { version: "may-2020" }]>
  58. | ["optionalChainingAssign", { version: "2023-07" }]
  59. | ["pipelineOperator", PipelineOperatorPluginOptions]
  60. | ["recordAndTuple", RecordAndTuplePluginOptions]
  61. | ["flow", FlowPluginOptions]
  62. | ["typescript", TypeScriptPluginOptions];
  63. type PluginConfig = Plugin$1 | ParserPluginWithOptions;
  64. interface DecoratorsPluginOptions {
  65. decoratorsBeforeExport?: boolean;
  66. allowCallParenthesized?: boolean;
  67. }
  68. interface PipelineOperatorPluginOptions {
  69. proposal: BABEL_8_BREAKING extends false
  70. ? "minimal" | "fsharp" | "hack" | "smart"
  71. : "fsharp" | "hack";
  72. topicToken?: "%" | "#" | "@@" | "^^" | "^";
  73. }
  74. interface RecordAndTuplePluginOptions {
  75. syntaxType: "bar" | "hash";
  76. }
  77. type FlowPluginOptions = BABEL_8_BREAKING extends true
  78. ? {
  79. all?: boolean;
  80. enums?: boolean;
  81. }
  82. : {
  83. all?: boolean;
  84. };
  85. interface TypeScriptPluginOptions {
  86. dts?: boolean;
  87. disallowAmbiguousJSXLike?: boolean;
  88. }
  89. type Plugin = PluginConfig;
  90. type SourceType = "script" | "commonjs" | "module" | "unambiguous";
  91. interface Options {
  92. /**
  93. * By default, import and export declarations can only appear at a program's top level.
  94. * Setting this option to true allows them anywhere where a statement is allowed.
  95. */
  96. allowImportExportEverywhere?: boolean;
  97. /**
  98. * By default, await use is not allowed outside of an async function.
  99. * Set this to true to accept such code.
  100. */
  101. allowAwaitOutsideFunction?: boolean;
  102. /**
  103. * By default, a return statement at the top level raises an error.
  104. * Set this to true to accept such code.
  105. */
  106. allowReturnOutsideFunction?: boolean;
  107. /**
  108. * By default, new.target use is not allowed outside of a function or class.
  109. * Set this to true to accept such code.
  110. */
  111. allowNewTargetOutsideFunction?: boolean;
  112. allowSuperOutsideMethod?: boolean;
  113. /**
  114. * By default, exported identifiers must refer to a declared variable.
  115. * Set this to true to allow export statements to reference undeclared variables.
  116. */
  117. allowUndeclaredExports?: boolean;
  118. /**
  119. * By default, yield use is not allowed outside of a generator function.
  120. * Set this to true to accept such code.
  121. */
  122. allowYieldOutsideFunction?: 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", "commonjs", "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. * Use "commonjs" to parse code that is intended to be run in a CommonJS environment such as Node.js.
  152. */
  153. sourceType?: SourceType;
  154. /**
  155. * Correlate output AST nodes with their source filename.
  156. * Useful when generating code and source maps from the ASTs of multiple input files.
  157. */
  158. sourceFilename?: string;
  159. /**
  160. * By default, all source indexes start from 0.
  161. * You can provide a start index to alternatively start with.
  162. * Useful for integration with other source tools.
  163. */
  164. startIndex?: number;
  165. /**
  166. * By default, the first line of code parsed is treated as line 1.
  167. * You can provide a line number to alternatively start with.
  168. * Useful for integration with other source tools.
  169. */
  170. startLine?: number;
  171. /**
  172. * By default, the parsed code is treated as if it starts from line 1, column 0.
  173. * You can provide a column number to alternatively start with.
  174. * Useful for integration with other source tools.
  175. */
  176. startColumn?: number;
  177. /**
  178. * Array containing the plugins that you want to enable.
  179. */
  180. plugins?: Plugin[];
  181. /**
  182. * Should the parser work in strict mode.
  183. * Defaults to true if sourceType === 'module'. Otherwise, false.
  184. */
  185. strictMode?: boolean;
  186. /**
  187. * Adds a ranges property to each node: [node.start, node.end]
  188. */
  189. ranges?: boolean;
  190. /**
  191. * Adds all parsed tokens to a tokens property on the File node.
  192. */
  193. tokens?: boolean;
  194. /**
  195. * By default, the parser adds information about parentheses by setting
  196. * `extra.parenthesized` to `true` as needed.
  197. * When this option is `true` the parser creates `ParenthesizedExpression`
  198. * AST nodes instead of using the `extra` property.
  199. */
  200. createParenthesizedExpressions?: boolean;
  201. /**
  202. * The default is false in Babel 7 and true in Babel 8
  203. * Set this to true to parse it as an `ImportExpression` node.
  204. * Otherwise `import(foo)` is parsed as `CallExpression(Import, [Identifier(foo)])`.
  205. */
  206. createImportExpressions?: boolean;
  207. }
  208. type ParserOptions = Partial<Options>;
  209. interface ParseError {
  210. code: string;
  211. reasonCode: string;
  212. }
  213. type ParseResult<Result extends File | Expression = File> = Result & {
  214. errors: null | ParseError[];
  215. };
  216. /**
  217. * Parse the provided code as an entire ECMAScript program.
  218. */
  219. declare function parse(input: string, options?: ParserOptions): ParseResult<File>;
  220. declare function parseExpression(input: string, options?: ParserOptions): ParseResult<Expression>;
  221. declare const tokTypes: {
  222. // todo(flow->ts) real token type
  223. [name: string]: any;
  224. };
  225. export { DecoratorsPluginOptions, FlowPluginOptions, ParseError, ParseResult, ParserOptions, PluginConfig as ParserPlugin, ParserPluginWithOptions, PipelineOperatorPluginOptions, RecordAndTuplePluginOptions, TypeScriptPluginOptions, parse, parseExpression, tokTypes };