function.d.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { Next, ToString } from "./types";
  2. declare const FUNCTION_PREFIXES: {
  3. Function: string;
  4. GeneratorFunction: string;
  5. AsyncFunction: string;
  6. AsyncGeneratorFunction: string;
  7. };
  8. /**
  9. * Track function parser usage.
  10. */
  11. export declare const USED_METHOD_KEY: WeakSet<Function>;
  12. /**
  13. * Stringify a function.
  14. */
  15. export declare const functionToString: ToString;
  16. /**
  17. * Rewrite a stringified function to remove initial indentation.
  18. */
  19. export declare function dedentFunction(fnString: string): string;
  20. /**
  21. * Function parser and stringify.
  22. */
  23. export declare class FunctionParser {
  24. fn: Function;
  25. indent: string;
  26. next: Next;
  27. key?: string | undefined;
  28. fnString: string;
  29. fnType: keyof typeof FUNCTION_PREFIXES;
  30. keyQuote: string | undefined;
  31. keyPrefix: string;
  32. isMethodCandidate: boolean;
  33. pos: number;
  34. hadKeyword: boolean;
  35. constructor(fn: Function, indent: string, next: Next, key?: string | undefined);
  36. stringify(): string;
  37. getPrefix(): string;
  38. tryParse(): string | undefined;
  39. /**
  40. * Attempt to parse the function from the current position by first stripping
  41. * the function's name from the front. This is not a fool-proof method on all
  42. * JavaScript engines, but yields good results on Node.js 4 (and slightly
  43. * less good results on Node.js 6 and 8).
  44. */
  45. tryStrippingName(): string | undefined;
  46. /**
  47. * Attempt to advance the parser past the keywords expected to be at the
  48. * start of this function's definition. This method sets `this.hadKeyword`
  49. * based on whether or not a `function` keyword is consumed.
  50. *
  51. * @return {boolean}
  52. */
  53. tryParsePrefixTokens(): boolean;
  54. /**
  55. * Advance the parser past one element of JavaScript syntax. This could be a
  56. * matched pair of delimiters, like braces or parentheses, or an atomic unit
  57. * like a keyword, variable, or operator. Return a normalized string
  58. * representation of the element parsed--for example, returns '{}' for a
  59. * matched pair of braces. Comments and whitespace are skipped.
  60. *
  61. * (This isn't a full parser, so the token scanning logic used here is as
  62. * simple as it can be. As a consequence, some things that are one token in
  63. * JavaScript, like decimal number literals or most multicharacter operators
  64. * like '&&', are split into more than one token here. However, awareness of
  65. * some multicharacter sequences like '=>' is necessary, so we match the few
  66. * of them that we care about.)
  67. */
  68. consumeSyntax(wordLikeToken?: string): string | undefined;
  69. consumeSyntaxUntil(startToken: string, endToken: string): string | undefined;
  70. consumeMatch(re: RegExp): RegExpExecArray | null;
  71. /**
  72. * Advance the parser past an arbitrary regular expression. Return `token`,
  73. * or the match object of the regexp.
  74. */
  75. consumeRegExp(re: RegExp, token: string): string | undefined;
  76. /**
  77. * Advance the parser past a template string.
  78. */
  79. consumeTemplate(): "`" | undefined;
  80. /**
  81. * Advance the parser past any whitespace or comments.
  82. */
  83. consumeWhitespace(): void;
  84. }
  85. export {};