@eslint-react/var 3.0.0-next.53 → 3.0.0-next.55
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.d.ts +5 -14
- package/dist/index.js +11 -35
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -52,13 +52,10 @@ declare function getVariableInitializer(variable: Variable | unit, at: number):
|
|
|
52
52
|
*/
|
|
53
53
|
declare function getVariableInitializerLoose(variable: Variable | unit, at: number): unit | TSESTree.ClassDeclaration | TSESTree.Expression | TSESTree.FunctionDeclaration;
|
|
54
54
|
//#endregion
|
|
55
|
-
//#region src/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* @returns All variables from the given scope up to the global scope
|
|
60
|
-
*/
|
|
61
|
-
declare function getVariables(initialScope: Scope): Variable[];
|
|
55
|
+
//#region src/binding-kind.d.ts
|
|
56
|
+
type BindingKind = "var" | "let" | "const" | "module" | "hoisted" | "param" | "local" | "unknown";
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/helper.d.ts
|
|
62
59
|
/**
|
|
63
60
|
* Find a variable by name or identifier node in the scope chain
|
|
64
61
|
* @param initialScope The scope to start searching from
|
|
@@ -72,12 +69,6 @@ declare const findVariable: {
|
|
|
72
69
|
(initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | unit) => Variable | unit;
|
|
73
70
|
(nameOrNode: string | TSESTree.Identifier | unit, initialScope: Scope): Variable | unit;
|
|
74
71
|
};
|
|
75
|
-
/**
|
|
76
|
-
* Get all child scopes recursively from a given scope
|
|
77
|
-
* @param scope The scope to get child scopes from
|
|
78
|
-
* @returns Array of all child scopes including the input scope
|
|
79
|
-
*/
|
|
80
|
-
declare function getChildScopes(scope: Scope): readonly Scope[];
|
|
81
72
|
//#endregion
|
|
82
73
|
//#region src/value-equality.d.ts
|
|
83
74
|
/**
|
|
@@ -139,4 +130,4 @@ type ObjectType = {
|
|
|
139
130
|
*/
|
|
140
131
|
declare function getObjectType(node: TSESTree.Node | unit, initialScope: Scope): ObjectType | unit;
|
|
141
132
|
//#endregion
|
|
142
|
-
export { AssignmentTarget, ObjectType, findEnclosingAssignmentTarget, findImportSource, findProperty, findVariable,
|
|
133
|
+
export { AssignmentTarget, BindingKind, ObjectType, findEnclosingAssignmentTarget, findImportSource, findProperty, findVariable, getObjectType, getVariableInitializer, getVariableInitializerLoose, isAssignmentTargetEqual, isValueEqual };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { dual, identity, unit } from "@eslint-react/eff";
|
|
|
3
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
4
4
|
import * as astUtils from "@typescript-eslint/utils/ast-utils";
|
|
5
5
|
import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
6
|
-
import { DefinitionType
|
|
6
|
+
import { DefinitionType } from "@typescript-eslint/scope-manager";
|
|
7
7
|
import { P, match } from "ts-pattern";
|
|
8
8
|
|
|
9
9
|
//#region src/binding-initializer.ts
|
|
@@ -40,21 +40,7 @@ function getVariableInitializerLoose(variable, at) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
//#endregion
|
|
43
|
-
//#region src/
|
|
44
|
-
/**
|
|
45
|
-
* Get all variables from the given scope up to the global scope
|
|
46
|
-
* @param initialScope The scope to start from
|
|
47
|
-
* @returns All variables from the given scope up to the global scope
|
|
48
|
-
*/
|
|
49
|
-
function getVariables(initialScope) {
|
|
50
|
-
let scope = initialScope;
|
|
51
|
-
const variables = [...scope.variables];
|
|
52
|
-
while (scope.type !== ScopeType.global) {
|
|
53
|
-
scope = scope.upper;
|
|
54
|
-
variables.push(...scope.variables);
|
|
55
|
-
}
|
|
56
|
-
return variables.reverse();
|
|
57
|
-
}
|
|
43
|
+
//#region src/helper.ts
|
|
58
44
|
/**
|
|
59
45
|
* Find a variable by name or identifier node in the scope chain
|
|
60
46
|
* @param initialScope The scope to start searching from
|
|
@@ -68,16 +54,6 @@ const findVariable = dual(2, (nameOrNode, initialScope) => {
|
|
|
68
54
|
if (nameOrNode == null) return unit;
|
|
69
55
|
return astUtils.findVariable(initialScope, nameOrNode) ?? unit;
|
|
70
56
|
});
|
|
71
|
-
/**
|
|
72
|
-
* Get all child scopes recursively from a given scope
|
|
73
|
-
* @param scope The scope to get child scopes from
|
|
74
|
-
* @returns Array of all child scopes including the input scope
|
|
75
|
-
*/
|
|
76
|
-
function getChildScopes(scope) {
|
|
77
|
-
const scopes = [scope];
|
|
78
|
-
for (const childScope of scope.childScopes) scopes.push(...getChildScopes(childScope));
|
|
79
|
-
return scopes;
|
|
80
|
-
}
|
|
81
57
|
|
|
82
58
|
//#endregion
|
|
83
59
|
//#region src/value-equality.ts
|
|
@@ -105,19 +81,19 @@ function isValueEqual(a, b, initialScopes) {
|
|
|
105
81
|
case a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier: {
|
|
106
82
|
const aVar = findVariable(a, aScope);
|
|
107
83
|
const bVar = findVariable(b, bScope);
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const
|
|
84
|
+
const aVarInit = getVariableInitializerLoose(aVar, 0);
|
|
85
|
+
const bVarInit = getVariableInitializerLoose(bVar, 0);
|
|
86
|
+
const aVarInitParent = aVarInit?.parent;
|
|
87
|
+
const bVarInitParent = bVarInit?.parent;
|
|
112
88
|
const aDef = aVar?.defs.at(0);
|
|
113
89
|
const bDef = bVar?.defs.at(0);
|
|
114
90
|
const aDefParentParent = aDef?.parent?.parent;
|
|
115
91
|
const bDefParentParent = bDef?.parent?.parent;
|
|
116
92
|
switch (true) {
|
|
117
|
-
case
|
|
118
|
-
if (!ast.isNodeEqual(
|
|
119
|
-
const aParams =
|
|
120
|
-
const bParams =
|
|
93
|
+
case aVarInitParent?.type === AST_NODE_TYPES.CallExpression && bVarInitParent?.type === AST_NODE_TYPES.CallExpression && ast.isFunction(aVarInit) && ast.isFunction(bVarInit): {
|
|
94
|
+
if (!ast.isNodeEqual(aVarInitParent.callee, bVarInitParent.callee)) return false;
|
|
95
|
+
const aParams = aVarInit.params;
|
|
96
|
+
const bParams = bVarInit.params;
|
|
121
97
|
const aPos = aParams.findIndex((x) => ast.isNodeEqual(x, a));
|
|
122
98
|
const bPos = bParams.findIndex((x) => ast.isNodeEqual(x, b));
|
|
123
99
|
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
@@ -322,4 +298,4 @@ function getObjectType(node, initialScope) {
|
|
|
322
298
|
}
|
|
323
299
|
|
|
324
300
|
//#endregion
|
|
325
|
-
export { findEnclosingAssignmentTarget, findImportSource, findProperty, findVariable,
|
|
301
|
+
export { findEnclosingAssignmentTarget, findImportSource, findProperty, findVariable, getObjectType, getVariableInitializer, getVariableInitializerLoose, isAssignmentTargetEqual, isValueEqual };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.55",
|
|
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,12 +34,12 @@
|
|
|
34
34
|
"@typescript-eslint/types": "canary",
|
|
35
35
|
"@typescript-eslint/utils": "canary",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
|
-
"@eslint-react/ast": "3.0.0-next.
|
|
38
|
-
"@eslint-react/eff": "3.0.0-next.
|
|
39
|
-
"@eslint-react/shared": "3.0.0-next.
|
|
37
|
+
"@eslint-react/ast": "3.0.0-next.55",
|
|
38
|
+
"@eslint-react/eff": "3.0.0-next.55",
|
|
39
|
+
"@eslint-react/shared": "3.0.0-next.55"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"tsdown": "^0.
|
|
42
|
+
"tsdown": "^0.21.0-beta.1",
|
|
43
43
|
"@local/configs": "0.0.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|