configuration.cjs 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.normalizeBabelParseConfig = normalizeBabelParseConfig;
  6. exports.normalizeBabelParseConfigSync = normalizeBabelParseConfigSync;
  7. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  8. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  9. const babel = require("./babel-core.cjs");
  10. const ESLINT_VERSION = require("../utils/eslint-version.cjs");
  11. function getParserPlugins(babelOptions) {
  12. var _babelOptions$parserO, _babelOptions$parserO2;
  13. const babelParserPlugins = (_babelOptions$parserO = (_babelOptions$parserO2 = babelOptions.parserOpts) == null ? void 0 : _babelOptions$parserO2.plugins) != null ? _babelOptions$parserO : [];
  14. const estreeOptions = {
  15. classFeatures: ESLINT_VERSION >= 8
  16. };
  17. for (const plugin of babelParserPlugins) {
  18. if (Array.isArray(plugin) && plugin[0] === "estree") {
  19. Object.assign(estreeOptions, plugin[1]);
  20. break;
  21. }
  22. }
  23. return [["estree", estreeOptions], ...babelParserPlugins];
  24. }
  25. function normalizeParserOptions(options) {
  26. var _options$allowImportE, _options$ecmaFeatures, _options$ecmaFeatures2;
  27. return Object.assign({
  28. sourceType: options.sourceType,
  29. filename: options.filePath
  30. }, options.babelOptions, {
  31. parserOpts: Object.assign({}, {
  32. allowImportExportEverywhere: (_options$allowImportE = options.allowImportExportEverywhere) != null ? _options$allowImportE : false,
  33. allowSuperOutsideMethod: true
  34. }, {
  35. allowReturnOutsideFunction: (_options$ecmaFeatures = (_options$ecmaFeatures2 = options.ecmaFeatures) == null ? void 0 : _options$ecmaFeatures2.globalReturn) != null ? _options$ecmaFeatures : true
  36. }, options.babelOptions.parserOpts, {
  37. plugins: getParserPlugins(options.babelOptions),
  38. attachComment: false,
  39. ranges: true,
  40. tokens: true
  41. }),
  42. caller: Object.assign({
  43. name: "@babel/eslint-parser"
  44. }, options.babelOptions.caller)
  45. });
  46. }
  47. function validateResolvedConfig(config, options, parseOptions) {
  48. if (config !== null) {
  49. if (options.requireConfigFile !== false) {
  50. if (!config.hasFilesystemConfig()) {
  51. 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.`;
  52. if (config.options.filename.includes("node_modules")) {
  53. 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.`;
  54. }
  55. throw new Error(error);
  56. }
  57. }
  58. if (config.options) return config.options;
  59. }
  60. return getDefaultParserOptions(parseOptions);
  61. }
  62. function getDefaultParserOptions(options) {
  63. return Object.assign({
  64. plugins: []
  65. }, options, {
  66. babelrc: false,
  67. configFile: false,
  68. browserslistConfigFile: false,
  69. ignore: null,
  70. only: null
  71. });
  72. }
  73. function normalizeBabelParseConfig(_x) {
  74. return _normalizeBabelParseConfig.apply(this, arguments);
  75. }
  76. function _normalizeBabelParseConfig() {
  77. _normalizeBabelParseConfig = _asyncToGenerator(function* (options) {
  78. const parseOptions = normalizeParserOptions(options);
  79. const config = yield babel.loadPartialConfigAsync(parseOptions);
  80. return validateResolvedConfig(config, options, parseOptions);
  81. });
  82. return _normalizeBabelParseConfig.apply(this, arguments);
  83. }
  84. function normalizeBabelParseConfigSync(options) {
  85. const parseOptions = normalizeParserOptions(options);
  86. const config = babel.loadPartialConfigSync(parseOptions);
  87. return validateResolvedConfig(config, options, parseOptions);
  88. }
  89. //# sourceMappingURL=configuration.cjs.map