babylon.js 671 B

123456789101112131415161718192021222324
  1. "use strict";
  2. // Prefer the new @babel/parser package, but fall back to babylon if
  3. // that's what's available.
  4. const parser = exports.parser = function () {
  5. try {
  6. return require("@babel/parser");
  7. } catch (e) {
  8. return require("babylon");
  9. }
  10. }();
  11. // This module is suitable for passing as options.parser when calling
  12. // recast.parse to process JavaScript code with Babel:
  13. //
  14. // const ast = recast.parse(source, {
  15. // parser: require("recast/parsers/babylon")
  16. // });
  17. //
  18. exports.parse = function (source, options) {
  19. options = require("./_babylon_options.js")(options);
  20. options.plugins.push("jsx", "flow");
  21. return parser.parse(source, options);
  22. };