Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom parserOpts for babel parser in @babel/eslint-parser #11423

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 24 additions & 8 deletions eslint/babel-eslint-parser/src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,35 @@ export function normalizeBabelParseConfig(options) {
exclude: options.babelOptions.exclude,
ignore: options.babelOptions.ignore,
only: options.babelOptions.only,
parserOpts: {
allowImportExportEverywhere: options.allowImportExportEverywhere,
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
ranges: true,
tokens: true,
plugins: ["estree"],
},
parserOpts: normalizeBabelParserOptions(options),
caller: {
name: "@babel/eslint-parser",
},
};

function normalizeBabelParserOptions(options) {
const parserOpts = options.babelOptions.parserOpts || {};
const parserPlugins = parserOpts.plugins || [];

const normalizedParserOptions = Object.assign(
{
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
ranges: true,
tokens: true,
},
parserOpts,
);

normalizedParserOptions.plugins = ["estree", ...parserPlugins];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the "estree" plugin is necessary for the eslint parser here, so I figured we shouldn't override it.

if (options.allowImportExportEverywhere !== undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if options.allowImportExportEverywhere exists, it'll use that over parserOpts. allowImportExportEverywhere to prevent breaking changes.

normalizedParserOptions.allowImportExportEverywhere =
options.allowImportExportEverywhere;
}

return normalizedParserOptions;
}

if (options.requireConfigFile !== false) {
const config = loadPartialConfig(parseOptions);

Expand Down