Skip to content

Commit 0338fd2

Browse files
authored
feat: Normalize ecmaVersion to eslint-scope when using custom parser (#15268)
* feat: Normalize ecmaVersion to eslint-scope when using custom parser * test: Add testcase
1 parent 04e91b6 commit 0338fd2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/linter/linter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ function analyzeScope(ast, parserOptions, visitorKeys) {
626626
ignoreEval: true,
627627
nodejsScope: ecmaFeatures.globalReturn,
628628
impliedStrict: ecmaFeatures.impliedStrict,
629-
ecmaVersion,
629+
ecmaVersion: typeof ecmaVersion === "number" ? ecmaVersion : 6,
630630
sourceType: parserOptions.sourceType || "script",
631631
childVisitorKeys: visitorKeys || evk.KEYS,
632632
fallback: Traverser.getKeys

tests/lib/linter/linter.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,16 +4137,36 @@ var a = "test2";
41374137
blockScope = context.getScope();
41384138
}
41394139
}));
4140+
linter.defineParser("custom-parser", {
4141+
parse: (...args) => espree.parse(...args)
4142+
});
4143+
4144+
// Use standard parser
4145+
linter.verify("{}", {
4146+
rules: { "block-scope": 2 },
4147+
parserOptions: { ecmaVersion: "latest" }
4148+
});
4149+
4150+
assert.strictEqual(blockScope.type, "block");
4151+
4152+
linter.verify("{}", {
4153+
rules: { "block-scope": 2 },
4154+
parserOptions: {} // ecmaVersion defaults to 5
4155+
});
4156+
assert.strictEqual(blockScope.type, "global");
41404157

4158+
// Use custom parser
41414159
linter.verify("{}", {
41424160
rules: { "block-scope": 2 },
4161+
parser: "custom-parser",
41434162
parserOptions: { ecmaVersion: "latest" }
41444163
});
41454164

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

41484167
linter.verify("{}", {
41494168
rules: { "block-scope": 2 },
4169+
parser: "custom-parser",
41504170
parserOptions: {} // ecmaVersion defaults to 5
41514171
});
41524172
assert.strictEqual(blockScope.type, "global");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy