babel-parser.d.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Type definitions for @babel/parser
  2. // Project: https://github.com/babel/babel/tree/master/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(input: string, options?: ParserOptions): import('@babel/types').File;
  11. /**
  12. * Parse the provided code as a single expression.
  13. */
  14. export function parseExpression(input: string, options?: ParserOptions): import('@babel/types').Expression;
  15. export interface ParserOptions {
  16. /**
  17. * By default, import and export declarations can only appear at a program's top level.
  18. * Setting this option to true allows them anywhere where a statement is allowed.
  19. */
  20. allowImportExportEverywhere?: boolean;
  21. /**
  22. * By default, await use is not allowed outside of an async function.
  23. * Set this to true to accept such code.
  24. */
  25. allowAwaitOutsideFunction?: boolean;
  26. /**
  27. * By default, a return statement at the top level raises an error.
  28. * Set this to true to accept such code.
  29. */
  30. allowReturnOutsideFunction?: boolean;
  31. allowSuperOutsideMethod?: boolean;
  32. /**
  33. * Indicate the mode the code should be parsed in.
  34. * Can be one of "script", "module", or "unambiguous". Defaults to "script".
  35. * "unambiguous" will make @babel/parser attempt to guess, based on the presence
  36. * of ES6 import or export statements.
  37. * Files with ES6 imports and exports are considered "module" and are otherwise "script".
  38. */
  39. sourceType?: 'script' | 'module' | 'unambiguous';
  40. /**
  41. * Correlate output AST nodes with their source filename.
  42. * Useful when generating code and source maps from the ASTs of multiple input files.
  43. */
  44. sourceFilename?: string;
  45. /**
  46. * By default, the first line of code parsed is treated as line 1.
  47. * You can provide a line number to alternatively start with.
  48. * Useful for integration with other source tools.
  49. */
  50. startLine?: number;
  51. /**
  52. * Array containing the plugins that you want to enable.
  53. */
  54. plugins?: ParserPlugin[];
  55. /**
  56. * Should the parser work in strict mode.
  57. * Defaults to true if sourceType === 'module'. Otherwise, false.
  58. */
  59. strictMode?: boolean;
  60. /**
  61. * Adds a ranges property to each node: [node.start, node.end]
  62. */
  63. ranges?: boolean;
  64. /**
  65. * Adds all parsed tokens to a tokens property on the File node.
  66. */
  67. tokens?: boolean;
  68. /**
  69. * By default, the parser adds information about parentheses by setting
  70. * `extra.parenthesized` to `true` as needed.
  71. * When this option is `true` the parser creates `ParenthesizedExpression`
  72. * AST nodes instead of using the `extra` property.
  73. */
  74. createParenthesizedExpressions?: boolean;
  75. }
  76. export type ParserPlugin =
  77. 'estree' |
  78. 'jsx' |
  79. 'flow' |
  80. 'flowComments' |
  81. 'typescript' |
  82. 'doExpressions' |
  83. 'objectRestSpread' |
  84. 'decorators' |
  85. 'decorators-legacy' |
  86. 'classProperties' |
  87. 'classPrivateProperties' |
  88. 'classPrivateMethods' |
  89. 'exportDefaultFrom' |
  90. 'exportNamespaceFrom' |
  91. 'asyncGenerators' |
  92. 'functionBind' |
  93. 'functionSent' |
  94. 'dynamicImport' |
  95. 'numericSeparator' |
  96. 'optionalChaining' |
  97. 'importMeta' |
  98. 'bigInt' |
  99. 'optionalCatchBinding' |
  100. 'throwExpressions' |
  101. 'pipelineOperator' |
  102. 'nullishCoalescingOperator' |
  103. ParserPluginWithOptions;
  104. export type ParserPluginWithOptions =
  105. ['decorators', DecoratorsPluginOptions] |
  106. ['pipelineOperator', PipelineOperatorPluginOptions] |
  107. ['flow', FlowPluginOptions];
  108. export interface DecoratorsPluginOptions {
  109. decoratorsBeforeExport?: boolean;
  110. }
  111. export interface PipelineOperatorPluginOptions {
  112. proposal: 'minimal' | 'smart';
  113. }
  114. export interface FlowPluginOptions {
  115. all?: boolean;
  116. }