index.js 624 B

12345678910111213141516171819202122232425262728293031
  1. import {augmentError, initParser, state} from "./traverser/base";
  2. import {parseFile} from "./traverser/index";
  3. export class File {
  4. constructor(tokens, scopes) {
  5. this.tokens = tokens;
  6. this.scopes = scopes;
  7. }
  8. }
  9. export function parse(
  10. input,
  11. isJSXEnabled,
  12. isTypeScriptEnabled,
  13. isFlowEnabled,
  14. ) {
  15. if (isFlowEnabled && isTypeScriptEnabled) {
  16. throw new Error("Cannot combine flow and typescript plugins.");
  17. }
  18. initParser(input, isJSXEnabled, isTypeScriptEnabled, isFlowEnabled);
  19. const result = parseFile();
  20. if (state.error) {
  21. throw augmentError(state.error);
  22. }
  23. return result;
  24. }