fix(eslint-parser): merge input estree options (#12891)
Co-authored-by: Kai Cataldo <kai@kaicataldo.com>
This commit is contained in:
parent
6a471decc3
commit
227f881f35
@ -21,6 +21,26 @@ export function normalizeESLintConfig(options) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge user supplied estree plugin options to default estree plugin options
|
||||
*
|
||||
* @param {*} babelOptions
|
||||
* @returns {Array} Merged parser plugin descriptors
|
||||
*/
|
||||
function getParserPlugins(babelOptions) {
|
||||
const babelParserPlugins = babelOptions.parserOpts?.plugins ?? [];
|
||||
// todo: enable classFeatures when it is supported by ESLint
|
||||
const estreeOptions = { classFeatures: false };
|
||||
for (const plugin of babelParserPlugins) {
|
||||
if (Array.isArray(plugin) && plugin[0] === "estree") {
|
||||
Object.assign(estreeOptions, plugin[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// estree must be the first parser plugin to work with other parser plugins
|
||||
return [["estree", estreeOptions], ...babelParserPlugins];
|
||||
}
|
||||
|
||||
export function normalizeBabelParseConfig(options) {
|
||||
const parseOptions = {
|
||||
sourceType: options.sourceType,
|
||||
@ -31,10 +51,7 @@ export function normalizeBabelParseConfig(options) {
|
||||
allowReturnOutsideFunction: true,
|
||||
allowSuperOutsideMethod: true,
|
||||
...options.babelOptions.parserOpts,
|
||||
plugins: [
|
||||
["estree", { classFeatures: false }],
|
||||
...(options.babelOptions.parserOpts?.plugins ?? []),
|
||||
],
|
||||
plugins: getParserPlugins(options.babelOptions),
|
||||
ranges: true,
|
||||
tokens: true,
|
||||
},
|
||||
|
||||
@ -327,6 +327,26 @@ describe("Babel and Espree", () => {
|
||||
expect(babylonAST.tokens[3].value).toEqual("#");
|
||||
});
|
||||
|
||||
it("parse to PropertyDeclaration when `classFeatures: true`", () => {
|
||||
const code = "class A { #x }";
|
||||
const babylonAST = parseForESLint(code, {
|
||||
eslintVisitorKeys: true,
|
||||
eslintScopeManager: true,
|
||||
babelOptions: {
|
||||
filename: "test.js",
|
||||
parserOpts: {
|
||||
plugins: [
|
||||
["estree", { classFeatures: true }],
|
||||
"classPrivateProperties",
|
||||
"classProperties",
|
||||
],
|
||||
},
|
||||
},
|
||||
}).ast;
|
||||
const classDeclaration = babylonAST.body[0];
|
||||
expect(classDeclaration.body.body[0].type).toEqual("PropertyDefinition");
|
||||
});
|
||||
|
||||
it("empty program with line comment", () => {
|
||||
parseAndAssertSame("// single comment");
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user