@eslint-react/var 2.8.1-next.4 → 2.8.2-next.0
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 +15 -15
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { dual, identity, unit } from "@eslint-react/eff";
|
|
2
2
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
3
|
-
import * as
|
|
3
|
+
import * as ast from "@eslint-react/ast";
|
|
4
4
|
import { P, match } from "ts-pattern";
|
|
5
5
|
import { DefinitionType, ScopeType } from "@typescript-eslint/scope-manager";
|
|
6
|
-
import * as
|
|
6
|
+
import * as astUtils from "@typescript-eslint/utils/ast-utils";
|
|
7
7
|
import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
8
8
|
|
|
9
9
|
//#region src/find-enclosing-assignment-target.ts
|
|
@@ -43,7 +43,7 @@ function getVariables(initialScope) {
|
|
|
43
43
|
}
|
|
44
44
|
const findVariable = dual(2, (nameOrNode, initialScope) => {
|
|
45
45
|
if (nameOrNode == null) return unit;
|
|
46
|
-
return
|
|
46
|
+
return astUtils.findVariable(initialScope, nameOrNode) ?? unit;
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
//#endregion
|
|
@@ -81,7 +81,7 @@ function findImportSource(name, initialScope) {
|
|
|
81
81
|
if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) return findImportSource(init.object.name, initialScope);
|
|
82
82
|
if (init.type === AST_NODE_TYPES.Identifier) return findImportSource(init.name, initialScope);
|
|
83
83
|
const arg0 = getRequireExpressionArguments(init)?.[0];
|
|
84
|
-
if (arg0 == null || !
|
|
84
|
+
if (arg0 == null || !ast.isLiteral(arg0, "string")) return unit;
|
|
85
85
|
return arg0.value;
|
|
86
86
|
}
|
|
87
87
|
if (parent?.type === AST_NODE_TYPES.ImportDeclaration) return parent.source.value;
|
|
@@ -106,7 +106,7 @@ function getVariableDefinitionNodeLoose(variable, at) {
|
|
|
106
106
|
const node = getVariableDefinitionNode(variable, at);
|
|
107
107
|
if (node != null) return node;
|
|
108
108
|
const def = variable.defs.at(at);
|
|
109
|
-
if (def?.type === DefinitionType.Parameter &&
|
|
109
|
+
if (def?.type === DefinitionType.Parameter && ast.isFunction(def.node)) return def.node;
|
|
110
110
|
return unit;
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -227,8 +227,8 @@ const thisBlockTypes = [
|
|
|
227
227
|
* @returns `true` if node value equal
|
|
228
228
|
*/
|
|
229
229
|
function isNodeValueEqual(a, b, initialScopes) {
|
|
230
|
-
a =
|
|
231
|
-
b =
|
|
230
|
+
a = ast.isTypeExpression(a) ? ast.getUnderlyingExpression(a) : a;
|
|
231
|
+
b = ast.isTypeExpression(b) ? ast.getUnderlyingExpression(b) : b;
|
|
232
232
|
const [aScope, bScope] = initialScopes;
|
|
233
233
|
switch (true) {
|
|
234
234
|
case a === b: return true;
|
|
@@ -246,12 +246,12 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
246
246
|
const aDefParentParent = aDef?.parent?.parent;
|
|
247
247
|
const bDefParentParent = bDef?.parent?.parent;
|
|
248
248
|
switch (true) {
|
|
249
|
-
case aVarNodeParent?.type === AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === AST_NODE_TYPES.CallExpression &&
|
|
250
|
-
if (!
|
|
249
|
+
case aVarNodeParent?.type === AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === AST_NODE_TYPES.CallExpression && ast.isFunction(aVarNode) && ast.isFunction(bVarNode): {
|
|
250
|
+
if (!ast.isNodeEqual(aVarNodeParent.callee, bVarNodeParent.callee)) return false;
|
|
251
251
|
const aParams = aVarNode.params;
|
|
252
252
|
const bParams = bVarNode.params;
|
|
253
|
-
const aPos = aParams.findIndex((x) =>
|
|
254
|
-
const bPos = bParams.findIndex((x) =>
|
|
253
|
+
const aPos = aParams.findIndex((x) => ast.isNodeEqual(x, a));
|
|
254
|
+
const bPos = bParams.findIndex((x) => ast.isNodeEqual(x, b));
|
|
255
255
|
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
256
256
|
}
|
|
257
257
|
case aDefParentParent?.type === AST_NODE_TYPES.ForOfStatement && bDefParentParent?.type === AST_NODE_TYPES.ForOfStatement: {
|
|
@@ -260,15 +260,15 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
260
260
|
if (aLeft.type !== bLeft.type) return false;
|
|
261
261
|
const aRight = aDefParentParent.right;
|
|
262
262
|
const bRight = bDefParentParent.right;
|
|
263
|
-
return
|
|
263
|
+
return ast.isNodeEqual(aRight, bRight);
|
|
264
264
|
}
|
|
265
265
|
default: return aVar != null && bVar != null && aVar === bVar;
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
|
-
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return
|
|
268
|
+
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return ast.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
269
269
|
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression:
|
|
270
270
|
if (aScope.block === bScope.block) return true;
|
|
271
|
-
return
|
|
271
|
+
return ast.findParentNode(a, ast.isOneOf(thisBlockTypes)) === ast.findParentNode(b, ast.isOneOf(thisBlockTypes));
|
|
272
272
|
default: {
|
|
273
273
|
const aStatic = getStaticValue(a, aScope);
|
|
274
274
|
const bStatic = getStaticValue(b, bScope);
|
|
@@ -281,7 +281,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
281
281
|
//#region src/is-assignment-target-equal.ts
|
|
282
282
|
/** @internal */
|
|
283
283
|
function isAssignmentTargetEqual(context, a, b) {
|
|
284
|
-
return
|
|
284
|
+
return ast.isNodeEqual(a, b) || isNodeValueEqual(a, b, [context.sourceCode.getScope(a), context.sourceCode.getScope(b)]);
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2-next.0",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module for static analysis of variables.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"@typescript-eslint/types": "^8.54.0",
|
|
35
35
|
"@typescript-eslint/utils": "^8.54.0",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
|
-
"@eslint-react/ast": "2.8.
|
|
38
|
-
"@eslint-react/eff": "2.8.
|
|
39
|
-
"@eslint-react/shared": "2.8.
|
|
37
|
+
"@eslint-react/ast": "2.8.2-next.0",
|
|
38
|
+
"@eslint-react/eff": "2.8.2-next.0",
|
|
39
|
+
"@eslint-react/shared": "2.8.2-next.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"tsdown": "^0.20.1",
|