Skip to content

Commit

Permalink
fix: check if the parser is built-in
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jun 6, 2021
1 parent 391a8f8 commit 8a7c41b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/linter/linter.js
Expand Up @@ -433,16 +433,19 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {

/**
* Normalize ECMAScript version from the initial config
* @param {Parser} parser The parser which uses this options.
* @param {number} ecmaVersion ECMAScript version from the initial config
* @returns {number} normalized ECMAScript version
*/
function normalizeEcmaVersion(ecmaVersion) {
if (ecmaVersion === void 0) {
return DEFAULT_ECMA_VERSION;
}
function normalizeEcmaVersion(parser, ecmaVersion) {
if (parser === espree) {
if (ecmaVersion === void 0) {
return DEFAULT_ECMA_VERSION;
}

if (ecmaVersion === "latest") {
return espree.latestEcmaVersion;
if (ecmaVersion === "latest") {
return espree.latestEcmaVersion;
}
}

/*
Expand Down Expand Up @@ -529,12 +532,12 @@ function normalizeVerifyOptions(providedOptions, config) {

/**
* Combines the provided parserOptions with the options from environments
* @param {string} parserName The parser name which uses this options.
* @param {Parser} parser The parser which uses this options.
* @param {ParserOptions} providedOptions The provided 'parserOptions' key in a config
* @param {Environment[]} enabledEnvironments The environments enabled in configuration and with inline comments
* @returns {ParserOptions} Resulting parser options after merge
*/
function resolveParserOptions(parserName, providedOptions, enabledEnvironments) {
function resolveParserOptions(parser, providedOptions, enabledEnvironments) {
const parserOptionsFromEnv = enabledEnvironments
.filter(env => env.parserOptions)
.reduce((parserOptions, env) => merge(parserOptions, env.parserOptions), {});
Expand All @@ -550,7 +553,7 @@ function resolveParserOptions(parserName, providedOptions, enabledEnvironments)
mergedParserOptions.ecmaFeatures = Object.assign({}, mergedParserOptions.ecmaFeatures, { globalReturn: false });
}

mergedParserOptions.ecmaVersion = normalizeEcmaVersion(mergedParserOptions.ecmaVersion);
mergedParserOptions.ecmaVersion = normalizeEcmaVersion(parser, mergedParserOptions.ecmaVersion);

return mergedParserOptions;
}
Expand Down

0 comments on commit 8a7c41b

Please sign in to comment.