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.

50 lines
1.5 KiB

4 years ago
  1. import * as types from "ast-types";
  2. import { parse } from "./lib/parser";
  3. import { Options } from "./lib/options";
  4. export {
  5. /**
  6. * Parse a string of code into an augmented syntax tree suitable for
  7. * arbitrary modification and reprinting.
  8. */
  9. parse,
  10. /**
  11. * Convenient shorthand for the ast-types package.
  12. */
  13. types, };
  14. /**
  15. * Traverse and potentially modify an abstract syntax tree using a
  16. * convenient visitor syntax:
  17. *
  18. * recast.visit(ast, {
  19. * names: [],
  20. * visitIdentifier: function(path) {
  21. * var node = path.value;
  22. * this.visitor.names.push(node.name);
  23. * this.traverse(path);
  24. * }
  25. * });
  26. */
  27. export { visit } from "ast-types";
  28. /**
  29. * Options shared between parsing and printing.
  30. */
  31. export { Options } from "./lib/options";
  32. /**
  33. * Reprint a modified syntax tree using as much of the original source
  34. * code as possible.
  35. */
  36. export declare function print(node: types.ASTNode, options?: Options): import("./lib/printer").PrintResultType;
  37. /**
  38. * Print without attempting to reuse any original source code.
  39. */
  40. export declare function prettyPrint(node: types.ASTNode, options?: Options): import("./lib/printer").PrintResultType;
  41. /**
  42. * Convenient command-line interface (see e.g. example/add-braces).
  43. */
  44. export declare function run(transformer: Transformer, options?: RunOptions): void;
  45. export interface Transformer {
  46. (ast: types.ASTNode, callback: (ast: types.ASTNode) => void): void;
  47. }
  48. export interface RunOptions extends Options {
  49. writeback?(code: string): void;
  50. }