babel.js 1.1 KB

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