|
1 | 1 | import * as AST from "@eslint-react/ast";
|
2 |
| -import type { Scope } from "@typescript-eslint/scope-manager"; |
| 2 | +import { _ } from "@eslint-react/eff"; |
| 3 | +import { DefinitionType, type Scope, type Variable } from "@typescript-eslint/scope-manager"; |
3 | 4 | import type { TSESTree } from "@typescript-eslint/types";
|
4 | 5 | import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
|
5 | 6 |
|
@@ -46,8 +47,8 @@ export function isNodeValueEqual(
|
46 | 47 | && b.type === T.Identifier: {
|
47 | 48 | const aVar = findVariable(a, aScope);
|
48 | 49 | const bVar = findVariable(b, bScope);
|
49 |
| - const aVarNode = getVariableNode(aVar, 0); |
50 |
| - const bVarNode = getVariableNode(bVar, 0); |
| 50 | + const aVarNode = getVariableNodeLoose(aVar, 0); |
| 51 | + const bVarNode = getVariableNodeLoose(bVar, 0); |
51 | 52 | const aVarNodeParent = aVarNode?.parent;
|
52 | 53 | const bVarNodeParent = bVarNode?.parent;
|
53 | 54 | const aDef = aVar?.defs.at(0);
|
@@ -105,3 +106,12 @@ export function isNodeValueEqual(
|
105 | 106 | }
|
106 | 107 | }
|
107 | 108 | }
|
| 109 | + |
| 110 | +function getVariableNodeLoose(variable: Variable | _, at: number): ReturnType<typeof getVariableNode> { |
| 111 | + if (variable == null) return _; |
| 112 | + const node = getVariableNode(variable, at); |
| 113 | + if (node != null) return node; |
| 114 | + const def = variable.defs.at(at); |
| 115 | + if (def?.type === DefinitionType.Parameter && AST.isFunction(def.node)) return def.node; |
| 116 | + return _; |
| 117 | +} |
0 commit comments