diff --git a/lib/linter/linter.js b/lib/linter/linter.js index bd8070ced5e4..247f87932698 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -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; + } } /* @@ -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, parserName); return mergedParserOptions; }