From f1d06b961e769d18b433d5fff86a4de67788d519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 28 May 2021 00:21:32 +0800 Subject: [PATCH] fix: normailze ecmaVersion --- lib/linter/linter.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/linter/linter.js b/lib/linter/linter.js index bd8070ced5e4..c6b9c4b13302 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); return mergedParserOptions; }