You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.3 KiB

4 years ago
  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. * By default, exported identifiers must refer to a declared variable.
  34. * Set this to true to allow export statements to reference undeclared variables.
  35. */
  36. allowUndeclaredExports?: boolean;
  37. /**
  38. * Indicate the mode the code should be parsed in.
  39. * Can be one of "script", "module", or "unambiguous". Defaults to "script".
  40. * "unambiguous" will make @babel/parser attempt to guess, based on the presence
  41. * of ES6 import or export statements.
  42. * Files with ES6 imports and exports are considered "module" and are otherwise "script".
  43. */
  44. sourceType?: 'script' | 'module' | 'unambiguous';
  45. /**
  46. * Correlate output AST nodes with their source filename.
  47. * Useful when generating code and source maps from the ASTs of multiple input files.
  48. */
  49. sourceFilename?: string;
  50. /**
  51. * By default, the first line of code parsed is treated as line 1.
  52. * You can provide a line number to alternatively start with.
  53. * Useful for integration with other source tools.
  54. */
  55. startLine?: number;
  56. /**
  57. * Array containing the plugins that you want to enable.
  58. */
  59. plugins?: ParserPlugin[];
  60. /**
  61. * Should the parser work in strict mode.
  62. * Defaults to true if sourceType === 'module'. Otherwise, false.
  63. */
  64. strictMode?: boolean;
  65. /**
  66. * Adds a ranges property to each node: [node.start, node.end]
  67. */
  68. ranges?: boolean;
  69. /**
  70. * Adds all parsed tokens to a tokens property on the File node.
  71. */
  72. tokens?: boolean;
  73. /**
  74. * By default, the parser adds information about parentheses by setting
  75. * `extra.parenthesized` to `true` as needed.
  76. * When this option is `true` the parser creates `ParenthesizedExpression`
  77. * AST nodes instead of using the `extra` property.
  78. */
  79. createParenthesizedExpressions?: boolean;
  80. }
  81. export type ParserPlugin =
  82. 'asyncGenerators' |
  83. 'bigInt' |
  84. 'classPrivateMethods' |
  85. 'classPrivateProperties' |
  86. 'classProperties' |
  87. 'decorators' |
  88. 'decorators-legacy' |
  89. 'doExpressions' |
  90. 'dynamicImport' |
  91. 'estree' |
  92. 'exportDefaultFrom' |
  93. 'exportNamespaceFrom' | // deprecated
  94. 'flow' |
  95. 'flowComments' |
  96. 'functionBind' |
  97. 'functionSent' |
  98. 'importMeta' |
  99. 'jsx' |
  100. 'logicalAssignment' |
  101. 'nullishCoalescingOperator' |
  102. 'numericSeparator' |
  103. 'objectRestSpread' |
  104. 'optionalCatchBinding' |
  105. 'optionalChaining' |
  106. 'partialApplication' |
  107. 'pipelineOperator' |
  108. 'placeholders' |
  109. 'throwExpressions' |
  110. 'topLevelAwait' |
  111. 'typescript' |
  112. 'v8intrinsic' |
  113. ParserPluginWithOptions;
  114. export type ParserPluginWithOptions =
  115. ['decorators', DecoratorsPluginOptions] |
  116. ['pipelineOperator', PipelineOperatorPluginOptions] |
  117. ['flow', FlowPluginOptions];
  118. export interface DecoratorsPluginOptions {
  119. decoratorsBeforeExport?: boolean;
  120. }
  121. export interface PipelineOperatorPluginOptions {
  122. proposal: 'minimal' | 'smart';
  123. }
  124. export interface FlowPluginOptions {
  125. all?: boolean;
  126. }