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.

148 lines
5.1 KiB

5 years ago
  1. import { Omit } from "ast-types/types";
  2. /**
  3. * All Recast API functions take second parameter with configuration options,
  4. * documented in options.js
  5. */
  6. export interface Options extends DeprecatedOptions {
  7. /**
  8. * If you want to use a different branch of esprima, or any other module
  9. * that supports a .parse function, pass that module object to
  10. * recast.parse as options.parser (legacy synonym: options.esprima).
  11. * @default require("recast/parsers/esprima")
  12. */
  13. parser?: any;
  14. /**
  15. * Number of spaces the pretty-printer should use per tab for
  16. * indentation. If you do not pass this option explicitly, it will be
  17. * (quite reliably!) inferred from the original code.
  18. * @default 4
  19. */
  20. tabWidth?: number;
  21. /**
  22. * If you really want the pretty-printer to use tabs instead of spaces,
  23. * make this option true.
  24. * @default false
  25. */
  26. useTabs?: boolean;
  27. /**
  28. * The reprinting code leaves leading whitespace untouched unless it has
  29. * to reindent a line, or you pass false for this option.
  30. * @default true
  31. */
  32. reuseWhitespace?: boolean;
  33. /**
  34. * Override this option to use a different line terminator, e.g. \r\n.
  35. * @default require("os").EOL || "\n"
  36. */
  37. lineTerminator?: string;
  38. /**
  39. * Some of the pretty-printer code (such as that for printing function
  40. * parameter lists) makes a valiant attempt to prevent really long
  41. * lines. You can adjust the limit by changing this option; however,
  42. * there is no guarantee that line length will fit inside this limit.
  43. * @default 74
  44. */
  45. wrapColumn?: number;
  46. /**
  47. * Pass a string as options.sourceFileName to recast.parse to tell the
  48. * reprinter to keep track of reused code so that it can construct a
  49. * source map automatically.
  50. * @default null
  51. */
  52. sourceFileName?: string | null;
  53. /**
  54. * Pass a string as options.sourceMapName to recast.print, and (provided
  55. * you passed options.sourceFileName earlier) the PrintResult of
  56. * recast.print will have a .map property for the generated source map.
  57. * @default null
  58. */
  59. sourceMapName?: string | null;
  60. /**
  61. * If provided, this option will be passed along to the source map
  62. * generator as a root directory for relative source file paths.
  63. * @default null
  64. */
  65. sourceRoot?: string | null;
  66. /**
  67. * If you provide a source map that was generated from a previous call
  68. * to recast.print as options.inputSourceMap, the old source map will be
  69. * composed with the new source map.
  70. * @default null
  71. */
  72. inputSourceMap?: string | null;
  73. /**
  74. * If you want esprima to generate .range information (recast only uses
  75. * .loc internally), pass true for this option.
  76. * @default false
  77. */
  78. range?: boolean;
  79. /**
  80. * If you want esprima not to throw exceptions when it encounters
  81. * non-fatal errors, keep this option true.
  82. * @default true
  83. */
  84. tolerant?: boolean;
  85. /**
  86. * If you want to override the quotes used in string literals, specify
  87. * either "single", "double", or "auto" here ("auto" will select the one
  88. * which results in the shorter literal) Otherwise, use double quotes.
  89. * @default null
  90. */
  91. quote?: 'single' | 'double' | 'auto' | null;
  92. /**
  93. * Controls the printing of trailing commas in object literals, array
  94. * expressions and function parameters.
  95. *
  96. * This option could either be:
  97. * * Boolean - enable/disable in all contexts (objects, arrays and function params).
  98. * * Object - enable/disable per context.
  99. *
  100. * Example:
  101. * trailingComma: {
  102. * objects: true,
  103. * arrays: true,
  104. * parameters: false,
  105. * }
  106. *
  107. * @default false
  108. */
  109. trailingComma?: boolean;
  110. /**
  111. * Controls the printing of spaces inside array brackets.
  112. * See: http://eslint.org/docs/rules/array-bracket-spacing
  113. * @default false
  114. */
  115. arrayBracketSpacing?: boolean;
  116. /**
  117. * Controls the printing of spaces inside object literals,
  118. * destructuring assignments, and import/export specifiers.
  119. * See: http://eslint.org/docs/rules/object-curly-spacing
  120. * @default true
  121. */
  122. objectCurlySpacing?: boolean;
  123. /**
  124. * If you want parenthesis to wrap single-argument arrow function
  125. * parameter lists, pass true for this option.
  126. * @default false
  127. */
  128. arrowParensAlways?: boolean;
  129. /**
  130. * There are 2 supported syntaxes (`,` and `;`) in Flow Object Types;
  131. * The use of commas is in line with the more popular style and matches
  132. * how objects are defined in JS, making it a bit more natural to write.
  133. * @default true
  134. */
  135. flowObjectCommas?: boolean;
  136. /**
  137. * Whether to return an array of .tokens on the root AST node.
  138. * @default true
  139. */
  140. tokens?: boolean;
  141. }
  142. interface DeprecatedOptions {
  143. /** @deprecated */
  144. esprima?: any;
  145. }
  146. export declare type NormalizedOptions = Required<Omit<Options, keyof DeprecatedOptions>>;
  147. export declare function normalize(opts?: Options): NormalizedOptions;
  148. export {};