index.d.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. export declare type Token =
  2. | { type: "StringLiteral"; value: string; closed: boolean }
  3. | { type: "NoSubstitutionTemplate"; value: string; closed: boolean }
  4. | { type: "TemplateHead"; value: string }
  5. | { type: "TemplateMiddle"; value: string }
  6. | { type: "TemplateTail"; value: string; closed: boolean }
  7. | { type: "RegularExpressionLiteral"; value: string; closed: boolean }
  8. | { type: "MultiLineComment"; value: string; closed: boolean }
  9. | { type: "SingleLineComment"; value: string }
  10. | { type: "HashbangComment"; value: string }
  11. | { type: "IdentifierName"; value: string }
  12. | { type: "PrivateIdentifier"; value: string }
  13. | { type: "NumericLiteral"; value: string }
  14. | { type: "Punctuator"; value: string }
  15. | { type: "WhiteSpace"; value: string }
  16. | { type: "LineTerminatorSequence"; value: string }
  17. | { type: "Invalid"; value: string };
  18. export declare type JSXToken =
  19. | { type: "JSXString"; value: string; closed: boolean }
  20. | { type: "JSXText"; value: string }
  21. | { type: "JSXIdentifier"; value: string }
  22. | { type: "JSXPunctuator"; value: string }
  23. | { type: "JSXInvalid"; value: string };
  24. declare function jsTokens(
  25. input: string,
  26. options: { jsx: true },
  27. ): Iterable<Token | JSXToken>;
  28. declare function jsTokens(
  29. input: string,
  30. options?: { jsx?: boolean },
  31. ): Iterable<Token>;
  32. // @ts-expect-error TypeScript complains about _both_ exporting types _and_ using `export =` but it seems to work fine in practice.
  33. export = jsTokens;