forked from babel/babel
/
configuration.js
59 lines (52 loc) · 1.57 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
51
52
53
54
55
56
57
58
59
import { loadPartialConfig } from "@babel/core";
export function normalizeESLintConfig(options) {
const {
babelOptions = {},
// ESLint sets ecmaVersion: undefined when ecmaVersion is not set in the config.
ecmaVersion = 2020,
sourceType = "module",
allowImportExportEverywhere = false,
requireConfigFile = true,
...otherOptions
} = options;
return {
babelOptions,
ecmaVersion,
sourceType,
allowImportExportEverywhere,
requireConfigFile,
...otherOptions,
};
}
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;
}