Skip to content

Commit

Permalink
fix: normailze ecmaVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed May 27, 2021
1 parent 8dd0e0e commit f1d06b9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/linter/linter.js
Expand Up @@ -433,13 +433,18 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {

/**
* Normalize ECMAScript version from the initial config
* @param {number} ecmaVersion ECMAScript version from the initial config
* @param {number} ecmaVersion ECMAScript version from the initial config
* @param {string} parserName the parser's name
* @returns {number} normalized ECMAScript version
*/
function normalizeEcmaVersion(ecmaVersion = DEFAULT_ECMA_VERSION) {

if (ecmaVersion === "latest") {
return espree.latestEcmaVersion;
function normalizeEcmaVersion(ecmaVersion, parserName) {
if (parserName === DEFAULT_PARSER_NAME || parserName === void 0) {
if (ecmaVersion === "latest") {
return espree.latestEcmaVersion;
}
if (ecmaVersion === void 0) {
return DEFAULT_ECMA_VERSION;
}
}

/*
Expand Down Expand Up @@ -547,10 +552,7 @@ function resolveParserOptions(parserName, providedOptions, enabledEnvironments)
mergedParserOptions.ecmaFeatures = Object.assign({}, mergedParserOptions.ecmaFeatures, { globalReturn: false });
}

// for a 3rd-party parser, do not normalize parserOptions
if (parserName === DEFAULT_PARSER_NAME || parserName === void 0) {
mergedParserOptions.ecmaVersion = normalizeEcmaVersion(mergedParserOptions.ecmaVersion);
}
mergedParserOptions.ecmaVersion = normalizeEcmaVersion(mergedParserOptions.ecmaVersion);

return mergedParserOptions;
}
Expand Down

0 comments on commit f1d06b9

Please sign in to comment.