Skip to content

Commit

Permalink
Update: always normalize ecmaVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed May 26, 2021
1 parent cde34d5 commit 99604d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions lib/linter/linter.js
Expand Up @@ -526,12 +526,11 @@ function normalizeVerifyOptions(providedOptions, config) {

/**
* Combines the provided parserOptions with the options from environments
* @param {string} parserName The parser name 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(providedOptions, enabledEnvironments) {
const parserOptionsFromEnv = enabledEnvironments
.filter(env => env.parserOptions)
.reduce((parserOptions, env) => merge(parserOptions, env.parserOptions), {});
Expand All @@ -547,10 +546,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 Expand Up @@ -1124,7 +1120,7 @@ class Linter {
.map(envName => getEnv(slots, envName))
.filter(env => env);

const parserOptions = resolveParserOptions(parserName, config.parserOptions || {}, enabledEnvs);
const parserOptions = resolveParserOptions(config.parserOptions || {}, enabledEnvs);
const configuredGlobals = resolveGlobals(config.globals || {}, enabledEnvs);
const settings = config.settings || {};

Expand Down
4 changes: 2 additions & 2 deletions tests/lib/linter/linter.js
Expand Up @@ -5396,11 +5396,11 @@ var a = "test2";
});
});

it("should not pass any default parserOptions to the parser", () => {
it("should pass normalized ecmaVersion to the parser", () => {
linter.defineParser("throws-with-options", testParsers.throwsWithOptions);
const messages = linter.verify(";", { parser: "throws-with-options" }, "filename");

assert.strictEqual(messages.length, 0);
assert.strictEqual(messages.length, 1);
});
});
});

0 comments on commit 99604d4

Please sign in to comment.