Skip to content

Commit

Permalink
feat: Normalize ecmaVersion to eslint-scope when using custom parser (#…
Browse files Browse the repository at this point in the history
…15268)

* feat: Normalize ecmaVersion to eslint-scope when using custom parser

* test: Add testcase
  • Loading branch information
ota-meshi committed Nov 9, 2021
1 parent 04e91b6 commit 0338fd2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/linter/linter.js
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/linter/linter.js
Expand Up @@ -4137,16 +4137,36 @@ 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" }
});

assert.strictEqual(blockScope.type, "block");

linter.verify("{}", {
rules: { "block-scope": 2 },
parser: "custom-parser",
parserOptions: {} // ecmaVersion defaults to 5
});
assert.strictEqual(blockScope.type, "global");
Expand Down

0 comments on commit 0338fd2

Please sign in to comment.