parse.cjs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. const semver = require("semver");
  3. const convert = require("./convert/index.cjs");
  4. const babelParser = require((((v, w) => (v = v.split("."), w = w.split("."), +v[0] > +w[0] || v[0] == w[0] && +v[1] >= +w[1]))(process.versions.node, "8.9") ? require.resolve : (r, {
  5. paths: [b]
  6. }, M = require("module")) => {
  7. let f = M._findPath(r, M._nodeModulePaths(b).concat(b));
  8. if (f) return f;
  9. f = new Error(`Cannot resolve module '${r}'`);
  10. f.code = "MODULE_NOT_FOUND";
  11. throw f;
  12. })("@babel/parser", {
  13. paths: [require.resolve("@babel/core/package.json")]
  14. }));
  15. let isRunningMinSupportedCoreVersion = null;
  16. module.exports = function parse(code, options, client) {
  17. const minSupportedCoreVersion = ">=7.2.0";
  18. if (typeof isRunningMinSupportedCoreVersion !== "boolean") {
  19. isRunningMinSupportedCoreVersion = semver.satisfies(client.getVersion(), minSupportedCoreVersion);
  20. }
  21. if (!isRunningMinSupportedCoreVersion) {
  22. throw new Error(`@babel/eslint-parser@${"7.19.1"} does not support @babel/core@${client.getVersion()}. Please upgrade to @babel/core@${minSupportedCoreVersion}.`);
  23. }
  24. const {
  25. ast,
  26. parserOptions
  27. } = client.maybeParse(code, options);
  28. if (ast) return ast;
  29. try {
  30. return convert.ast(babelParser.parse(code, parserOptions), code, client.getTokLabels(), client.getVisitorKeys());
  31. } catch (err) {
  32. throw convert.error(err);
  33. }
  34. };
  35. //# sourceMappingURL=parse.cjs.map