@eslint-react/var 1.17.2 → 1.17.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +22 -6
- package/dist/index.mjs +22 -6
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -162,12 +162,14 @@ function getVariableNode(at) {
|
|
|
162
162
|
tools.O.flatMap(getVariableDef(at)),
|
|
163
163
|
tools.O.flatMapNullable((def) => {
|
|
164
164
|
switch (true) {
|
|
165
|
-
case ("init" in def.node && def.node.init && !("declarations" in def.node.init)):
|
|
166
|
-
return def.node.init;
|
|
167
165
|
case (def.type === scopeManager.DefinitionType.FunctionName && def.node.type === types.AST_NODE_TYPES.FunctionDeclaration):
|
|
168
166
|
return def.node;
|
|
169
167
|
case (def.type === scopeManager.DefinitionType.ClassName && def.node.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
170
168
|
return def.node;
|
|
169
|
+
case (def.type === scopeManager.DefinitionType.Parameter && AST__namespace.isFunction(def.node)):
|
|
170
|
+
return def.node;
|
|
171
|
+
case ("init" in def.node && def.node.init && !("declarations" in def.node.init)):
|
|
172
|
+
return def.node.init;
|
|
171
173
|
default:
|
|
172
174
|
return null;
|
|
173
175
|
}
|
|
@@ -236,10 +238,24 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
236
238
|
if (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier) {
|
|
237
239
|
const va = findVariable(a, aScope);
|
|
238
240
|
const vb = findVariable(b, bScope);
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
if (tools.O.isNone(
|
|
242
|
-
|
|
241
|
+
const na = tools.O.flatMap(va, getVariableNode(0));
|
|
242
|
+
const nb = tools.O.flatMap(vb, getVariableNode(0));
|
|
243
|
+
if (tools.O.isNone(na) || tools.O.isNone(nb)) return false;
|
|
244
|
+
if (tools.O.exists(na, AST__namespace.isFunction) && tools.O.exists(nb, AST__namespace.isFunction)) {
|
|
245
|
+
const fa = na.value;
|
|
246
|
+
const fb = nb.value;
|
|
247
|
+
const pa = fa.parent;
|
|
248
|
+
const pb = fb.parent;
|
|
249
|
+
if (pa.type !== types.AST_NODE_TYPES.CallExpression || pb.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
250
|
+
if (!AST__namespace.isNodeEqual(pa.callee, pb.callee)) return false;
|
|
251
|
+
const paramsA = fa.params;
|
|
252
|
+
const paramsB = fb.params;
|
|
253
|
+
const posA = paramsA.findIndex((p) => AST__namespace.isNodeEqual(p, a));
|
|
254
|
+
const posB = paramsB.findIndex((p) => AST__namespace.isNodeEqual(p, b));
|
|
255
|
+
if (posA === -1 || posB === -1) return false;
|
|
256
|
+
return posA === posB;
|
|
257
|
+
}
|
|
258
|
+
return na.value === nb.value;
|
|
243
259
|
}
|
|
244
260
|
if (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression) {
|
|
245
261
|
return AST__namespace.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
package/dist/index.mjs
CHANGED
|
@@ -140,12 +140,14 @@ function getVariableNode(at) {
|
|
|
140
140
|
O.flatMap(getVariableDef(at)),
|
|
141
141
|
O.flatMapNullable((def) => {
|
|
142
142
|
switch (true) {
|
|
143
|
-
case ("init" in def.node && def.node.init && !("declarations" in def.node.init)):
|
|
144
|
-
return def.node.init;
|
|
145
143
|
case (def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration):
|
|
146
144
|
return def.node;
|
|
147
145
|
case (def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration):
|
|
148
146
|
return def.node;
|
|
147
|
+
case (def.type === DefinitionType.Parameter && AST.isFunction(def.node)):
|
|
148
|
+
return def.node;
|
|
149
|
+
case ("init" in def.node && def.node.init && !("declarations" in def.node.init)):
|
|
150
|
+
return def.node.init;
|
|
149
151
|
default:
|
|
150
152
|
return null;
|
|
151
153
|
}
|
|
@@ -214,10 +216,24 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
214
216
|
if (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier) {
|
|
215
217
|
const va = findVariable(a, aScope);
|
|
216
218
|
const vb = findVariable(b, bScope);
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
if (O.isNone(
|
|
220
|
-
|
|
219
|
+
const na = O.flatMap(va, getVariableNode(0));
|
|
220
|
+
const nb = O.flatMap(vb, getVariableNode(0));
|
|
221
|
+
if (O.isNone(na) || O.isNone(nb)) return false;
|
|
222
|
+
if (O.exists(na, AST.isFunction) && O.exists(nb, AST.isFunction)) {
|
|
223
|
+
const fa = na.value;
|
|
224
|
+
const fb = nb.value;
|
|
225
|
+
const pa = fa.parent;
|
|
226
|
+
const pb = fb.parent;
|
|
227
|
+
if (pa.type !== AST_NODE_TYPES.CallExpression || pb.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
228
|
+
if (!AST.isNodeEqual(pa.callee, pb.callee)) return false;
|
|
229
|
+
const paramsA = fa.params;
|
|
230
|
+
const paramsB = fb.params;
|
|
231
|
+
const posA = paramsA.findIndex((p) => AST.isNodeEqual(p, a));
|
|
232
|
+
const posB = paramsB.findIndex((p) => AST.isNodeEqual(p, b));
|
|
233
|
+
if (posA === -1 || posB === -1) return false;
|
|
234
|
+
return posA === posB;
|
|
235
|
+
}
|
|
236
|
+
return na.value === nb.value;
|
|
221
237
|
}
|
|
222
238
|
if (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression) {
|
|
223
239
|
return AST.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.3-beta.1",
|
|
4
4
|
"description": "TSESTree AST utility module for static analysis of variables",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@typescript-eslint/types": "^8.16.0",
|
|
40
40
|
"@typescript-eslint/utils": "^8.16.0",
|
|
41
41
|
"ts-pattern": "^5.5.0",
|
|
42
|
-
"@eslint-react/ast": "1.17.
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
42
|
+
"@eslint-react/ast": "1.17.3-beta.1",
|
|
43
|
+
"@eslint-react/types": "1.17.3-beta.1",
|
|
44
|
+
"@eslint-react/tools": "1.17.3-beta.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"string-ts": "^2.2.0",
|