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