Skip to content

Commit

Permalink
refactor: Use language.visitorKeys and check for non-JS SourceCode (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas authored Jun 26, 2024
1 parent e2b16e2 commit 7c78ad9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/linter/linter.js
Original file line number Diff line number Diff line change
@@ -1143,7 +1143,7 @@ function runRules(
});

const eventGenerator = new NodeEventGenerator(emitter, {
visitorKeys: sourceCode.visitorKeys,
visitorKeys: sourceCode.visitorKeys ?? language.visitorKeys,
fallback: Traverser.getKeys,
matchClass: language.matchesSelectorClass ?? (() => false),
nodeTypeKey: language.nodeTypeKey
@@ -1711,8 +1711,13 @@ class Linter {
/*
* If the given source code object as the first argument does not have scopeManager, analyze the scope.
* This is for backward compatibility (SourceCode is frozen so it cannot rebind).
*
* We check explicitly for `null` to ensure that this is a JS-flavored language.
* For non-JS languages we don't want to do this.
*
* TODO: Remove this check when we stop exporting the `SourceCode` object.
*/
if (!slots.lastSourceCode.scopeManager) {
if (slots.lastSourceCode.scopeManager === null) {
slots.lastSourceCode = new SourceCode({
text: slots.lastSourceCode.text,
ast: slots.lastSourceCode.ast,

0 comments on commit 7c78ad9

Please sign in to comment.