diff --git a/lib/linter/linter.js b/lib/linter/linter.js index 410c07fee51..4e07a25751e 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -626,7 +626,7 @@ function analyzeScope(ast, parserOptions, visitorKeys) { ignoreEval: true, nodejsScope: ecmaFeatures.globalReturn, impliedStrict: ecmaFeatures.impliedStrict, - ecmaVersion, + ecmaVersion: typeof ecmaVersion === "number" ? ecmaVersion : 6, sourceType: parserOptions.sourceType || "script", childVisitorKeys: visitorKeys || evk.KEYS, fallback: Traverser.getKeys diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index c2bb5fdd746..24dc4de43ce 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -4137,9 +4137,28 @@ var a = "test2"; blockScope = context.getScope(); } })); + linter.defineParser("custom-parser", { + parse: (...args) => espree.parse(...args) + }); + + // Use standard parser + linter.verify("{}", { + rules: { "block-scope": 2 }, + parserOptions: { ecmaVersion: "latest" } + }); + + assert.strictEqual(blockScope.type, "block"); + + linter.verify("{}", { + rules: { "block-scope": 2 }, + parserOptions: {} // ecmaVersion defaults to 5 + }); + assert.strictEqual(blockScope.type, "global"); + // Use custom parser linter.verify("{}", { rules: { "block-scope": 2 }, + parser: "custom-parser", parserOptions: { ecmaVersion: "latest" } }); @@ -4147,6 +4166,7 @@ var a = "test2"; linter.verify("{}", { rules: { "block-scope": 2 }, + parser: "custom-parser", parserOptions: {} // ecmaVersion defaults to 5 }); assert.strictEqual(blockScope.type, "global");