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.

30 lines
979 B

4 years ago
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var _babel_options_1 = __importDefault(require("./_babel_options"));
  7. // Prefer the new @babel/parser package, but fall back to babylon if
  8. // that's what's available.
  9. exports.parser = function () {
  10. try {
  11. return require("@babel/parser");
  12. }
  13. catch (e) {
  14. return require("babylon");
  15. }
  16. }();
  17. // This module is suitable for passing as options.parser when calling
  18. // recast.parse to process JavaScript code with Babel:
  19. //
  20. // const ast = recast.parse(source, {
  21. // parser: require("recast/parsers/babel")
  22. // });
  23. //
  24. function parse(source, options) {
  25. var babelOptions = _babel_options_1.default(options);
  26. babelOptions.plugins.push("jsx", "flow");
  27. return exports.parser.parse(source, babelOptions);
  28. }
  29. exports.parse = parse;
  30. ;