UNPKG

1.78 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.normalizeESLintConfig = normalizeESLintConfig;
7exports.normalizeBabelParseConfig = normalizeBabelParseConfig;
8
9var _core = require("@babel/core");
10
11function normalizeESLintConfig(options) {
12 const defaultOptions = {
13 babelOptions: {},
14 ecmaVersion: 2020,
15 sourceType: "module",
16 allowImportExportEverywhere: false,
17 requireConfigFile: true
18 };
19 return Object.assign(defaultOptions, options);
20}
21
22function normalizeBabelParseConfig(options) {
23 var _options$babelOptions, _options$babelOptions2;
24
25 const parseOptions = Object.assign({
26 sourceType: options.sourceType,
27 filename: options.filePath
28 }, options.babelOptions, {
29 parserOpts: Object.assign({
30 allowImportExportEverywhere: options.allowImportExportEverywhere,
31 allowReturnOutsideFunction: true,
32 allowSuperOutsideMethod: true
33 }, options.babelOptions.parserOpts, {
34 plugins: ["estree", ...((_options$babelOptions = (_options$babelOptions2 = options.babelOptions.parserOpts) == null ? void 0 : _options$babelOptions2.plugins) != null ? _options$babelOptions : [])],
35 ranges: true,
36 tokens: true
37 }),
38 caller: Object.assign({
39 name: "@babel/eslint-parser"
40 }, options.babelOptions.caller)
41 });
42
43 if (options.requireConfigFile !== false) {
44 const config = (0, _core.loadPartialConfig)(parseOptions);
45
46 if (config !== null) {
47 if (!config.hasFilesystemConfig()) {
48 throw new 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.`);
49 }
50
51 return config.options;
52 }
53 }
54
55 return parseOptions;
56}
\No newline at end of file