Skip to content

Commit d82229b

Browse files
committed
fix(no-navigation-without-resolve): fixed an infinite loop
1 parent 7108d33 commit d82229b

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

packages/eslint-plugin-svelte/src/rules/no-navigation-without-resolve.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ReferenceTracker } from '@eslint-community/eslint-utils';
44
import { findVariable } from '../utils/ast-utils.js';
55
import type { RuleContext } from '../types.js';
66
import { isAbsoluteURL, isFragmentURL } from '../utils/url-utils.js';
7+
import { ASTSearchHelper } from '../utils/ast-search-helper.js';
78

89
export default createRule('no-navigation-without-resolve', {
910
meta: {
@@ -218,28 +219,25 @@ function isResolveCall(
218219
node: TSESTree.CallExpressionArgument,
219220
resolveReferences: Set<TSESTree.Identifier>
220221
): boolean {
221-
if (
222-
node.type === 'CallExpression' &&
223-
((node.callee.type === 'Identifier' && resolveReferences.has(node.callee)) ||
224-
(node.callee.type === 'MemberExpression' &&
225-
node.callee.property.type === 'Identifier' &&
226-
resolveReferences.has(node.callee.property)))
227-
) {
228-
return true;
229-
}
230-
if (node.type === 'Identifier') {
231-
const variable = findVariable(context, node);
232-
if (
233-
variable !== null &&
234-
variable.identifiers.length > 0 &&
235-
variable.identifiers[0].parent.type === 'VariableDeclarator' &&
236-
variable.identifiers[0].parent.init !== null &&
237-
isResolveCall(context, variable.identifiers[0].parent.init, resolveReferences)
238-
) {
239-
return true;
240-
}
241-
}
242-
return false;
222+
return (
223+
ASTSearchHelper(node, {
224+
CallExpression: (node) =>
225+
(node.callee.type === 'Identifier' && resolveReferences.has(node.callee)) ||
226+
(node.callee.type === 'MemberExpression' &&
227+
node.callee.property.type === 'Identifier' &&
228+
resolveReferences.has(node.callee.property)),
229+
Identifier: (node, searchAnotherNode) => {
230+
const variable = findVariable(context, node);
231+
return (
232+
variable !== null &&
233+
variable.identifiers.length > 0 &&
234+
variable.identifiers[0].parent.type === 'VariableDeclarator' &&
235+
variable.identifiers[0].parent.init !== null &&
236+
searchAnotherNode(variable.identifiers[0].parent.init)
237+
);
238+
}
239+
}) ?? false
240+
);
243241
}
244242

245243
function expressionIsEmpty(url: TSESTree.CallExpressionArgument): boolean {

0 commit comments

Comments
 (0)