forked from babel/babel
/
configuration.js
50 lines (43 loc) · 1.38 KB
/
configuration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { loadPartialConfig } from "@babel/core";
export function normalizeESLintConfig(options) {
const defaultOptions = {
babelOptions: {},
ecmaVersion: 2020,
sourceType: "module",
allowImportExportEverywhere: false,
requireConfigFile: true,
};
return Object.assign(defaultOptions, options);
}
export function normalizeBabelParseConfig(options) {
const parseOptions = {
sourceType: options.sourceType,
filename: options.filePath,
...options.babelOptions,
parserOpts: {
allowImportExportEverywhere: options.allowImportExportEverywhere,
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
...options.babelOptions.parserOpts,
plugins: ["estree", ...(options.babelOptions.parserOpts?.plugins ?? [])],
ranges: true,
tokens: true,
},
caller: {
name: "@babel/eslint-parser",
...options.babelOptions.caller,
},
};
if (options.requireConfigFile !== false) {
const config = loadPartialConfig(parseOptions);
if (config !== null) {
if (!config.hasFilesystemConfig()) {
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.`,
);
}
return config.options;
}
}
return parseOptions;
}