configuration.cjs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.normalizeBabelParseConfig = normalizeBabelParseConfig;
  6. exports.normalizeBabelParseConfigSync = normalizeBabelParseConfigSync;
  7. function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
  8. function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
  9. const babel = require("./babel-core.cjs");
  10. const semver = require("semver");
  11. const ESLINT_VERSION = require("../utils/eslint-version.cjs");
  12. function getParserPlugins(babelOptions) {
  13. var _babelOptions$parserO, _babelOptions$parserO2;
  14. const babelParserPlugins = (_babelOptions$parserO = (_babelOptions$parserO2 = babelOptions.parserOpts) == null ? void 0 : _babelOptions$parserO2.plugins) != null ? _babelOptions$parserO : [];
  15. const estreeOptions = {
  16. classFeatures: ESLINT_VERSION >= 8
  17. };
  18. for (const plugin of babelParserPlugins) {
  19. if (Array.isArray(plugin) && plugin[0] === "estree") {
  20. Object.assign(estreeOptions, plugin[1]);
  21. break;
  22. }
  23. }
  24. return [["estree", estreeOptions], ...babelParserPlugins];
  25. }
  26. function normalizeParserOptions(options, version) {
  27. var _options$allowImportE, _options$ecmaFeatures2, _options$ecmaFeatures3;
  28. if (options.sourceType === "commonjs" && !semver.satisfies(version, ">=7.28.0")) {
  29. var _options$ecmaFeatures;
  30. options.sourceType = "script";
  31. options.ecmaFeatures = Object.assign({}, (_options$ecmaFeatures = options.ecmaFeatures) != null ? _options$ecmaFeatures : {}, {
  32. globalReturn: true
  33. });
  34. }
  35. return Object.assign({
  36. sourceType: options.sourceType,
  37. filename: options.filePath
  38. }, options.babelOptions, {
  39. parserOpts: Object.assign({}, {
  40. allowImportExportEverywhere: (_options$allowImportE = options.allowImportExportEverywhere) != null ? _options$allowImportE : false,
  41. allowSuperOutsideMethod: true
  42. }, options.sourceType !== "commonjs" ? {
  43. allowReturnOutsideFunction: (_options$ecmaFeatures2 = (_options$ecmaFeatures3 = options.ecmaFeatures) == null ? void 0 : _options$ecmaFeatures3.globalReturn) != null ? _options$ecmaFeatures2 : true
  44. } : {}, options.babelOptions.parserOpts, {
  45. plugins: getParserPlugins(options.babelOptions),
  46. attachComment: false,
  47. ranges: true,
  48. tokens: true
  49. }),
  50. caller: Object.assign({
  51. name: "@babel/eslint-parser"
  52. }, options.babelOptions.caller)
  53. });
  54. }
  55. function validateResolvedConfig(config, options, parseOptions) {
  56. if (config !== null) {
  57. if (options.requireConfigFile !== false) {
  58. if (!config.hasFilesystemConfig()) {
  59. let error = `No Babel config file detected for ${config.options.filename}. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.`;
  60. if (config.options.filename.includes("node_modules")) {
  61. error += `\nIf you have a .babelrc.js file or use package.json#babel, keep in mind that it's not used when parsing dependencies. If you want your config to be applied to your whole app, consider using babel.config.js or babel.config.json instead.`;
  62. }
  63. throw new Error(error);
  64. }
  65. }
  66. if (config.options) return config.options;
  67. }
  68. return getDefaultParserOptions(parseOptions);
  69. }
  70. function getDefaultParserOptions(options) {
  71. return Object.assign({
  72. plugins: []
  73. }, options, {
  74. babelrc: false,
  75. configFile: false,
  76. browserslistConfigFile: false,
  77. ignore: null,
  78. only: null
  79. });
  80. }
  81. function normalizeBabelParseConfig(_x) {
  82. return _normalizeBabelParseConfig.apply(this, arguments);
  83. }
  84. function _normalizeBabelParseConfig() {
  85. _normalizeBabelParseConfig = _asyncToGenerator(function* (options) {
  86. const parseOptions = normalizeParserOptions(options, babel.version);
  87. const config = yield babel.loadPartialConfigAsync(parseOptions);
  88. return validateResolvedConfig(config, options, parseOptions);
  89. });
  90. return _normalizeBabelParseConfig.apply(this, arguments);
  91. }
  92. function normalizeBabelParseConfigSync(options) {
  93. const parseOptions = normalizeParserOptions(options, babel.version);
  94. const config = babel.loadPartialConfigSync(parseOptions);
  95. return validateResolvedConfig(config, options, parseOptions);
  96. }
  97. //# sourceMappingURL=configuration.cjs.map