babel-parser.d.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Type definitions for @babel/parser
  2. // Project: https://github.com/babel/babel/tree/main/packages/babel-parser
  3. // Definitions by: Troy Gerwien <https://github.com/yortus>
  4. // Marvin Hagemeister <https://github.com/marvinhagemeister>
  5. // Avi Vahl <https://github.com/AviVahl>
  6. // TypeScript Version: 2.9
  7. /**
  8. * Parse the provided code as an entire ECMAScript program.
  9. */
  10. export function parse(
  11. input: string,
  12. options?: ParserOptions
  13. ): import("@babel/types").File;
  14. /**
  15. * Parse the provided code as a single expression.
  16. */
  17. export function parseExpression(
  18. input: string,
  19. options?: ParserOptions
  20. ): import("@babel/types").Expression;
  21. export interface ParserOptions {
  22. /**
  23. * By default, import and export declarations can only appear at a program's top level.
  24. * Setting this option to true allows them anywhere where a statement is allowed.
  25. */
  26. allowImportExportEverywhere?: boolean;
  27. /**
  28. * By default, await use is not allowed outside of an async function.
  29. * Set this to true to accept such code.
  30. */
  31. allowAwaitOutsideFunction?: boolean;
  32. /**
  33. * By default, a return statement at the top level raises an error.
  34. * Set this to true to accept such code.
  35. */
  36. allowReturnOutsideFunction?: boolean;
  37. allowSuperOutsideMethod?: boolean;
  38. /**
  39. * By default, exported identifiers must refer to a declared variable.
  40. * Set this to true to allow export statements to reference undeclared variables.
  41. */
  42. allowUndeclaredExports?: boolean;
  43. /**
  44. * Indicate the mode the code should be parsed in.
  45. * Can be one of "script", "module", or "unambiguous". Defaults to "script".
  46. * "unambiguous" will make @babel/parser attempt to guess, based on the presence
  47. * of ES6 import or export statements.
  48. * Files with ES6 imports and exports are considered "module" and are otherwise "script".
  49. */
  50. sourceType?: "script" | "module" | "unambiguous";
  51. /**
  52. * Correlate output AST nodes with their source filename.
  53. * Useful when generating code and source maps from the ASTs of multiple input files.
  54. */
  55. sourceFilename?: string;
  56. /**
  57. * By default, the first line of code parsed is treated as line 1.
  58. * You can provide a line number to alternatively start with.
  59. * Useful for integration with other source tools.
  60. */
  61. startLine?: number;
  62. /**
  63. * Array containing the plugins that you want to enable.
  64. */
  65. plugins?: ParserPlugin[];
  66. /**
  67. * Should the parser work in strict mode.
  68. * Defaults to true if sourceType === 'module'. Otherwise, false.
  69. */
  70. strictMode?: boolean;
  71. /**
  72. * Adds a ranges property to each node: [node.start, node.end]
  73. */
  74. ranges?: boolean;
  75. /**
  76. * Adds all parsed tokens to a tokens property on the File node.
  77. */
  78. tokens?: boolean;
  79. /**
  80. * By default, the parser adds information about parentheses by setting
  81. * `extra.parenthesized` to `true` as needed.
  82. * When this option is `true` the parser creates `ParenthesizedExpression`
  83. * AST nodes instead of using the `extra` property.
  84. */
  85. createParenthesizedExpressions?: boolean;
  86. }
  87. export type ParserPlugin =
  88. | "asyncGenerators"
  89. | "bigInt"
  90. | "classPrivateMethods"
  91. | "classPrivateProperties"
  92. | "classProperties"
  93. | "classStaticBlock"
  94. | "decimal"
  95. | "decorators"
  96. | "decorators-legacy"
  97. | "doExpressions"
  98. | "dynamicImport"
  99. | "estree"
  100. | "exportDefaultFrom"
  101. | "exportNamespaceFrom" // deprecated
  102. | "flow"
  103. | "flowComments"
  104. | "functionBind"
  105. | "functionSent"
  106. | "importMeta"
  107. | "jsx"
  108. | "logicalAssignment"
  109. | "importAssertions"
  110. | "moduleStringNames"
  111. | "nullishCoalescingOperator"
  112. | "numericSeparator"
  113. | "objectRestSpread"
  114. | "optionalCatchBinding"
  115. | "optionalChaining"
  116. | "partialApplication"
  117. | "pipelineOperator"
  118. | "placeholders"
  119. | "privateIn"
  120. | "throwExpressions"
  121. | "topLevelAwait"
  122. | "typescript"
  123. | "v8intrinsic"
  124. | ParserPluginWithOptions;
  125. export type ParserPluginWithOptions =
  126. | ["decorators", DecoratorsPluginOptions]
  127. | ["pipelineOperator", PipelineOperatorPluginOptions]
  128. | ["recordAndTuple", RecordAndTuplePluginOptions]
  129. | ["flow", FlowPluginOptions];
  130. export interface DecoratorsPluginOptions {
  131. decoratorsBeforeExport?: boolean;
  132. }
  133. export interface PipelineOperatorPluginOptions {
  134. proposal: "fsharp" | "minimal" | "smart";
  135. }
  136. export interface RecordAndTuplePluginOptions {
  137. syntaxType: "bar" | "hash";
  138. }
  139. export interface FlowPluginOptions {
  140. all?: boolean;
  141. }