@eslint-react/var 1.23.3-next.7 → 1.24.0-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.d.mts +34 -21
- package/dist/index.d.ts +34 -21
- package/dist/index.js +98 -142
- package/dist/index.mjs +99 -141
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { Scope, Variable, ScopeManager } from '@typescript-eslint/scope-manager';
|
|
1
|
+
import { _ } from '@eslint-react/eff';
|
|
2
|
+
import { Scope, Variable } from '@typescript-eslint/scope-manager';
|
|
4
3
|
import { TSESTree } from '@typescript-eslint/types';
|
|
5
4
|
|
|
6
5
|
declare const findVariable: {
|
|
7
|
-
(initialScope: Scope): (nameOrNode: string | TSESTree.Identifier) =>
|
|
8
|
-
(nameOrNode: string | TSESTree.Identifier, initialScope: Scope):
|
|
6
|
+
(initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | _) => Variable | _;
|
|
7
|
+
(nameOrNode: string | TSESTree.Identifier | _, initialScope: Scope): Variable | _;
|
|
9
8
|
};
|
|
10
9
|
|
|
11
|
-
declare function getChidScopes(scope: Scope
|
|
10
|
+
declare function getChidScopes(scope: Scope): readonly Scope[];
|
|
12
11
|
|
|
13
|
-
declare function
|
|
12
|
+
declare function getVariableDeclaratorId(node: TSESTree.Node | _, prev?: TSESTree.Node): TSESTree.BindingName | TSESTree.Expression | _;
|
|
14
13
|
|
|
15
|
-
declare function
|
|
16
|
-
|
|
17
|
-
declare function getVariableDeclaratorID(node: TSESTree.Node, prev?: TSESTree.Node): O.Option<TSESTree.BindingName | TSESTree.Expression>;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get the init node of the nth definition of a variable
|
|
21
|
-
* @param at The index number of def in defs
|
|
22
|
-
* @returns A function that takes a variable and returns the init node of the nth definition of that variable
|
|
23
|
-
*/
|
|
24
|
-
declare function getVariableNode(at: number): (variable: Variable) => O.Option<TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName>;
|
|
14
|
+
declare function getVariableNode(variable: Variable | _, at: number): _ | TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName;
|
|
25
15
|
|
|
26
16
|
/**
|
|
27
17
|
* Get all variables from the given scope up to the global scope
|
|
@@ -51,10 +41,33 @@ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialSco
|
|
|
51
41
|
bScope: Scope
|
|
52
42
|
]): boolean;
|
|
53
43
|
|
|
54
|
-
type
|
|
55
|
-
kind: "
|
|
44
|
+
type StaticValue = {
|
|
45
|
+
kind: "lazy";
|
|
46
|
+
node: TSESTree.Node;
|
|
47
|
+
initialScope: Scope | _;
|
|
48
|
+
} | {
|
|
49
|
+
kind: "none";
|
|
56
50
|
node: TSESTree.Node;
|
|
51
|
+
initialScope: Scope | _;
|
|
57
52
|
} | {
|
|
53
|
+
kind: "some";
|
|
54
|
+
node: TSESTree.Node;
|
|
55
|
+
value: unknown;
|
|
56
|
+
initialScope: Scope | _;
|
|
57
|
+
};
|
|
58
|
+
declare function toResolved(sv: StaticValue): {
|
|
59
|
+
readonly kind: "none";
|
|
60
|
+
readonly node: TSESTree.Node;
|
|
61
|
+
readonly initialScope: Scope | undefined;
|
|
62
|
+
readonly value?: never;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: "some";
|
|
65
|
+
readonly node: TSESTree.Node;
|
|
66
|
+
readonly initialScope: Scope | undefined;
|
|
67
|
+
readonly value: unknown;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type ValueConstruction = {
|
|
58
71
|
kind: "ArrayExpression";
|
|
59
72
|
node: TSESTree.ArrayExpression;
|
|
60
73
|
} | {
|
|
@@ -93,6 +106,6 @@ declare const ValueConstructionHint: {
|
|
|
93
106
|
* @param hint The hint to use when detecting the construction
|
|
94
107
|
* @returns A function that detects the construction of a given node
|
|
95
108
|
*/
|
|
96
|
-
declare function getValueConstruction(node: TSESTree.Node, initialScope: Scope, hint?: bigint): ValueConstruction;
|
|
109
|
+
declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
|
|
97
110
|
|
|
98
|
-
export { type ValueConstruction, ValueConstructionHint, findVariable, getChidScopes,
|
|
111
|
+
export { type StaticValue, type ValueConstruction, ValueConstructionHint, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toResolved };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { Scope, Variable, ScopeManager } from '@typescript-eslint/scope-manager';
|
|
1
|
+
import { _ } from '@eslint-react/eff';
|
|
2
|
+
import { Scope, Variable } from '@typescript-eslint/scope-manager';
|
|
4
3
|
import { TSESTree } from '@typescript-eslint/types';
|
|
5
4
|
|
|
6
5
|
declare const findVariable: {
|
|
7
|
-
(initialScope: Scope): (nameOrNode: string | TSESTree.Identifier) =>
|
|
8
|
-
(nameOrNode: string | TSESTree.Identifier, initialScope: Scope):
|
|
6
|
+
(initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | _) => Variable | _;
|
|
7
|
+
(nameOrNode: string | TSESTree.Identifier | _, initialScope: Scope): Variable | _;
|
|
9
8
|
};
|
|
10
9
|
|
|
11
|
-
declare function getChidScopes(scope: Scope
|
|
10
|
+
declare function getChidScopes(scope: Scope): readonly Scope[];
|
|
12
11
|
|
|
13
|
-
declare function
|
|
12
|
+
declare function getVariableDeclaratorId(node: TSESTree.Node | _, prev?: TSESTree.Node): TSESTree.BindingName | TSESTree.Expression | _;
|
|
14
13
|
|
|
15
|
-
declare function
|
|
16
|
-
|
|
17
|
-
declare function getVariableDeclaratorID(node: TSESTree.Node, prev?: TSESTree.Node): O.Option<TSESTree.BindingName | TSESTree.Expression>;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get the init node of the nth definition of a variable
|
|
21
|
-
* @param at The index number of def in defs
|
|
22
|
-
* @returns A function that takes a variable and returns the init node of the nth definition of that variable
|
|
23
|
-
*/
|
|
24
|
-
declare function getVariableNode(at: number): (variable: Variable) => O.Option<TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName>;
|
|
14
|
+
declare function getVariableNode(variable: Variable | _, at: number): _ | TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName;
|
|
25
15
|
|
|
26
16
|
/**
|
|
27
17
|
* Get all variables from the given scope up to the global scope
|
|
@@ -51,10 +41,33 @@ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialSco
|
|
|
51
41
|
bScope: Scope
|
|
52
42
|
]): boolean;
|
|
53
43
|
|
|
54
|
-
type
|
|
55
|
-
kind: "
|
|
44
|
+
type StaticValue = {
|
|
45
|
+
kind: "lazy";
|
|
46
|
+
node: TSESTree.Node;
|
|
47
|
+
initialScope: Scope | _;
|
|
48
|
+
} | {
|
|
49
|
+
kind: "none";
|
|
56
50
|
node: TSESTree.Node;
|
|
51
|
+
initialScope: Scope | _;
|
|
57
52
|
} | {
|
|
53
|
+
kind: "some";
|
|
54
|
+
node: TSESTree.Node;
|
|
55
|
+
value: unknown;
|
|
56
|
+
initialScope: Scope | _;
|
|
57
|
+
};
|
|
58
|
+
declare function toResolved(sv: StaticValue): {
|
|
59
|
+
readonly kind: "none";
|
|
60
|
+
readonly node: TSESTree.Node;
|
|
61
|
+
readonly initialScope: Scope | undefined;
|
|
62
|
+
readonly value?: never;
|
|
63
|
+
} | {
|
|
64
|
+
readonly kind: "some";
|
|
65
|
+
readonly node: TSESTree.Node;
|
|
66
|
+
readonly initialScope: Scope | undefined;
|
|
67
|
+
readonly value: unknown;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type ValueConstruction = {
|
|
58
71
|
kind: "ArrayExpression";
|
|
59
72
|
node: TSESTree.ArrayExpression;
|
|
60
73
|
} | {
|
|
@@ -93,6 +106,6 @@ declare const ValueConstructionHint: {
|
|
|
93
106
|
* @param hint The hint to use when detecting the construction
|
|
94
107
|
* @returns A function that detects the construction of a given node
|
|
95
108
|
*/
|
|
96
|
-
declare function getValueConstruction(node: TSESTree.Node, initialScope: Scope, hint?: bigint): ValueConstruction;
|
|
109
|
+
declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
|
|
97
110
|
|
|
98
|
-
export { type ValueConstruction, ValueConstructionHint, findVariable, getChidScopes,
|
|
111
|
+
export { type StaticValue, type ValueConstruction, ValueConstructionHint, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toResolved };
|
package/dist/index.js
CHANGED
|
@@ -28,65 +28,48 @@ var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
|
|
|
28
28
|
var AST3__namespace = /*#__PURE__*/_interopNamespace(AST3);
|
|
29
29
|
|
|
30
30
|
// src/find-variable.ts
|
|
31
|
-
var findVariable2 = eff.
|
|
32
|
-
return eff.
|
|
31
|
+
var findVariable2 = eff.dual(2, (nameOrNode, initialScope) => {
|
|
32
|
+
if (nameOrNode === eff._) return eff._;
|
|
33
|
+
return ASTUtils__namespace.findVariable(initialScope, nameOrNode) ?? eff._;
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
// src/get-child-scopes.ts
|
|
36
|
-
function getChidScopes(scope
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const { type, parent } = node;
|
|
41
|
-
const inner = type !== types.AST_NODE_TYPES.Program;
|
|
42
|
-
const scope = scopeManager.acquire(node, inner);
|
|
43
|
-
if (scope != null) {
|
|
44
|
-
return scope;
|
|
45
|
-
}
|
|
46
|
-
if (parent != null) {
|
|
47
|
-
return getScope(parent, scopeManager);
|
|
37
|
+
function getChidScopes(scope) {
|
|
38
|
+
const scopes = [scope];
|
|
39
|
+
for (const childScope of scope.childScopes) {
|
|
40
|
+
scopes.push(...getChidScopes(childScope));
|
|
48
41
|
}
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
function getStaticValue2(node, initialScope) {
|
|
52
|
-
return eff.F.pipe(
|
|
53
|
-
eff.O.fromNullable(ASTUtils__namespace.getStaticValue(node, initialScope)),
|
|
54
|
-
eff.O.map((v) => v.value)
|
|
55
|
-
);
|
|
42
|
+
return scopes;
|
|
56
43
|
}
|
|
57
|
-
function
|
|
44
|
+
function getVariableDeclaratorId(node, prev) {
|
|
45
|
+
if (node === eff._) return eff._;
|
|
58
46
|
switch (true) {
|
|
59
47
|
case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
60
|
-
return
|
|
48
|
+
return node.id;
|
|
61
49
|
case (node.type === types.AST_NODE_TYPES.AssignmentExpression && node.right === prev):
|
|
62
|
-
return
|
|
50
|
+
return node.left;
|
|
63
51
|
case (node.type === types.AST_NODE_TYPES.BlockStatement || node.type === types.AST_NODE_TYPES.Program || node.parent === node):
|
|
64
|
-
return eff.
|
|
52
|
+
return eff._;
|
|
65
53
|
default:
|
|
66
|
-
return
|
|
54
|
+
return getVariableDeclaratorId(node.parent, node);
|
|
67
55
|
}
|
|
68
56
|
}
|
|
69
|
-
function getVariableNode(at) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
);
|
|
89
|
-
};
|
|
57
|
+
function getVariableNode(variable, at) {
|
|
58
|
+
if (variable === eff._) return eff._;
|
|
59
|
+
const def = variable.defs.at(at);
|
|
60
|
+
if (def === eff._) return eff._;
|
|
61
|
+
switch (true) {
|
|
62
|
+
case (def.type === scopeManager.DefinitionType.FunctionName && def.node.type === types.AST_NODE_TYPES.FunctionDeclaration):
|
|
63
|
+
return def.node;
|
|
64
|
+
case (def.type === scopeManager.DefinitionType.ClassName && def.node.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
65
|
+
return def.node;
|
|
66
|
+
case (def.type === scopeManager.DefinitionType.Parameter && AST3__namespace.isFunction(def.node)):
|
|
67
|
+
return def.node;
|
|
68
|
+
case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
|
|
69
|
+
return def.node.init;
|
|
70
|
+
default:
|
|
71
|
+
return eff._;
|
|
72
|
+
}
|
|
90
73
|
}
|
|
91
74
|
function getVariables(initialScope) {
|
|
92
75
|
let scope = initialScope;
|
|
@@ -98,11 +81,9 @@ function getVariables(initialScope) {
|
|
|
98
81
|
return variables.reverse();
|
|
99
82
|
}
|
|
100
83
|
function isInitializedFromSource(name, source, initialScope) {
|
|
101
|
-
const latestDef =
|
|
102
|
-
if (eff.
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
const { node, parent } = latestDef.value;
|
|
84
|
+
const latestDef = findVariable2(name, initialScope)?.defs.at(-1);
|
|
85
|
+
if (latestDef === eff._) return false;
|
|
86
|
+
const { node, parent } = latestDef;
|
|
106
87
|
if (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
107
88
|
const { init } = node;
|
|
108
89
|
if (init.type === types.AST_NODE_TYPES.MemberExpression && init.object.type === types.AST_NODE_TYPES.Identifier) {
|
|
@@ -111,13 +92,12 @@ function isInitializedFromSource(name, source, initialScope) {
|
|
|
111
92
|
if (init.type === types.AST_NODE_TYPES.Identifier) {
|
|
112
93
|
return isInitializedFromSource(init.name, source, initialScope);
|
|
113
94
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
);
|
|
95
|
+
const args = getRequireExpressionArguments(init);
|
|
96
|
+
const arg0 = args?.[0];
|
|
97
|
+
if (arg0 == null || !AST3__namespace.isStringLiteral(arg0)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return arg0.value === source || arg0.value.startsWith(`${source}/`);
|
|
121
101
|
}
|
|
122
102
|
return parent?.type === types.AST_NODE_TYPES.ImportDeclaration && parent.source.value === source;
|
|
123
103
|
}
|
|
@@ -125,15 +105,25 @@ function getRequireExpressionArguments(node) {
|
|
|
125
105
|
switch (true) {
|
|
126
106
|
// require('source')
|
|
127
107
|
case (node.type === types.AST_NODE_TYPES.CallExpression && node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === "require"): {
|
|
128
|
-
return
|
|
108
|
+
return node.arguments;
|
|
129
109
|
}
|
|
130
110
|
// require('source').variable
|
|
131
111
|
case node.type === types.AST_NODE_TYPES.MemberExpression: {
|
|
132
112
|
return getRequireExpressionArguments(node.object);
|
|
133
113
|
}
|
|
134
114
|
}
|
|
135
|
-
return eff.
|
|
115
|
+
return eff._;
|
|
136
116
|
}
|
|
117
|
+
function toResolved(sv) {
|
|
118
|
+
const { kind, node, initialScope } = sv;
|
|
119
|
+
if (kind !== "lazy") {
|
|
120
|
+
return sv;
|
|
121
|
+
}
|
|
122
|
+
const resolvedValue = initialScope === eff._ ? ASTUtils.getStaticValue(node) : ASTUtils.getStaticValue(node, initialScope);
|
|
123
|
+
return resolvedValue == null ? { kind: "none", node, initialScope } : { kind: "some", node, initialScope, value: resolvedValue.value };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/is-node-value-equal.ts
|
|
137
127
|
var thisBlockTypes = [
|
|
138
128
|
types.AST_NODE_TYPES.FunctionDeclaration,
|
|
139
129
|
types.AST_NODE_TYPES.FunctionExpression,
|
|
@@ -155,48 +145,37 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
155
145
|
case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier): {
|
|
156
146
|
const aVar = findVariable2(a, aScope);
|
|
157
147
|
const bVar = findVariable2(b, bScope);
|
|
158
|
-
const aVarNode =
|
|
159
|
-
const bVarNode =
|
|
160
|
-
const aVarNodeParent =
|
|
161
|
-
const bVarNodeParent =
|
|
162
|
-
const aDef =
|
|
163
|
-
const bDef =
|
|
164
|
-
const aDefParentParent =
|
|
165
|
-
const bDefParentParent =
|
|
148
|
+
const aVarNode = getVariableNode(aVar, 0);
|
|
149
|
+
const bVarNode = getVariableNode(bVar, 0);
|
|
150
|
+
const aVarNodeParent = aVarNode?.parent;
|
|
151
|
+
const bVarNodeParent = bVarNode?.parent;
|
|
152
|
+
const aDef = aVar?.defs.at(0);
|
|
153
|
+
const bDef = bVar?.defs.at(0);
|
|
154
|
+
const aDefParentParent = aDef?.parent?.parent;
|
|
155
|
+
const bDefParentParent = bDef?.parent?.parent;
|
|
166
156
|
switch (true) {
|
|
167
|
-
case (
|
|
168
|
-
|
|
169
|
-
eff.O.Do,
|
|
170
|
-
eff.O.bind("aCallee", () => eff.O.map(aVarNodeParent, (n) => n.callee)),
|
|
171
|
-
eff.O.bind("bCallee", () => eff.O.map(bVarNodeParent, (n) => n.callee)),
|
|
172
|
-
eff.O.exists(({ aCallee, bCallee }) => AST3__namespace.isNodeEqual(aCallee, bCallee))
|
|
173
|
-
);
|
|
174
|
-
if (!hasSameCallee) {
|
|
157
|
+
case (aVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression && AST3__namespace.isFunction(aVarNode) && AST3__namespace.isFunction(bVarNode)): {
|
|
158
|
+
if (!AST3__namespace.isNodeEqual(aVarNodeParent.callee, bVarNodeParent.callee)) {
|
|
175
159
|
return false;
|
|
176
160
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
eff.O.let("bPos", ({ bParams }) => bParams.findIndex(AST3__namespace.isNodeEqual(b))),
|
|
183
|
-
eff.O.filter(({ aPos, bPos }) => aPos !== -1 && bPos !== -1),
|
|
184
|
-
eff.O.exists(({ aPos, bPos }) => aPos === bPos)
|
|
185
|
-
);
|
|
161
|
+
const aParams = aVarNode.params;
|
|
162
|
+
const bParams = bVarNode.params;
|
|
163
|
+
const aPos = aParams.findIndex((x) => AST3__namespace.isNodeEqual(x, a));
|
|
164
|
+
const bPos = bParams.findIndex((x) => AST3__namespace.isNodeEqual(x, b));
|
|
165
|
+
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
186
166
|
}
|
|
187
|
-
case (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
);
|
|
167
|
+
case (aDefParentParent?.type === types.AST_NODE_TYPES.ForOfStatement && bDefParentParent?.type === types.AST_NODE_TYPES.ForOfStatement): {
|
|
168
|
+
const aLeft = aDefParentParent.left;
|
|
169
|
+
const bLeft = bDefParentParent.left;
|
|
170
|
+
if (aLeft.type !== bLeft.type) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
const aRight = aDefParentParent.right;
|
|
174
|
+
const bRight = bDefParentParent.right;
|
|
175
|
+
return AST3__namespace.isNodeEqual(aRight, bRight);
|
|
197
176
|
}
|
|
198
177
|
default: {
|
|
199
|
-
return eff.
|
|
178
|
+
return aVar !== eff._ && bVar !== eff._ && aVar === bVar;
|
|
200
179
|
}
|
|
201
180
|
}
|
|
202
181
|
}
|
|
@@ -207,20 +186,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
207
186
|
if (aScope.block === bScope.block) {
|
|
208
187
|
return true;
|
|
209
188
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
eff.O.bind("bFunction", () => AST3__namespace.findParentNode(b, AST3__namespace.isOneOf(thisBlockTypes))),
|
|
214
|
-
eff.O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
|
|
215
|
-
);
|
|
189
|
+
const aFunction = AST3__namespace.findParentNode(a, AST3__namespace.isOneOf(thisBlockTypes));
|
|
190
|
+
const bFunction = AST3__namespace.findParentNode(b, AST3__namespace.isOneOf(thisBlockTypes));
|
|
191
|
+
return aFunction === bFunction;
|
|
216
192
|
}
|
|
217
193
|
default: {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
eff.O.bind("bStatic", () => getStaticValue2(b, bScope)),
|
|
222
|
-
eff.O.exists(({ aStatic, bStatic }) => aStatic === bStatic)
|
|
223
|
-
);
|
|
194
|
+
const aStatic = toResolved({ kind: "lazy", node: a, initialScope: aScope });
|
|
195
|
+
const bStatic = toResolved({ kind: "lazy", node: b, initialScope: bScope });
|
|
196
|
+
return aStatic.kind !== "none" && bStatic.kind !== "none" && aStatic.value === bStatic.value;
|
|
224
197
|
}
|
|
225
198
|
}
|
|
226
199
|
}
|
|
@@ -229,6 +202,7 @@ var ValueConstructionHint = {
|
|
|
229
202
|
StrictCallExpression: 1n << 0n
|
|
230
203
|
};
|
|
231
204
|
function getValueConstruction(node, initialScope, hint = ValueConstructionHint.None) {
|
|
205
|
+
if (node === eff._) return eff._;
|
|
232
206
|
switch (node.type) {
|
|
233
207
|
case types.AST_NODE_TYPES.JSXElement:
|
|
234
208
|
case types.AST_NODE_TYPES.JSXFragment: {
|
|
@@ -254,61 +228,44 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
|
|
|
254
228
|
if (hint & ValueConstructionHint.StrictCallExpression) {
|
|
255
229
|
return { kind: "CallExpression", node };
|
|
256
230
|
}
|
|
257
|
-
return
|
|
231
|
+
return eff._;
|
|
258
232
|
}
|
|
259
233
|
case types.AST_NODE_TYPES.MemberExpression: {
|
|
260
|
-
if (!("object" in node))
|
|
261
|
-
return { kind: "None", node };
|
|
262
|
-
}
|
|
234
|
+
if (!("object" in node)) return eff._;
|
|
263
235
|
return getValueConstruction(node.object, initialScope, hint);
|
|
264
236
|
}
|
|
265
237
|
case types.AST_NODE_TYPES.AssignmentExpression:
|
|
266
238
|
case types.AST_NODE_TYPES.AssignmentPattern: {
|
|
267
|
-
if (!("right" in node))
|
|
268
|
-
return { kind: "None", node };
|
|
269
|
-
}
|
|
239
|
+
if (!("right" in node)) return eff._;
|
|
270
240
|
return getValueConstruction(node.right, initialScope, hint);
|
|
271
241
|
}
|
|
272
242
|
case types.AST_NODE_TYPES.LogicalExpression: {
|
|
273
243
|
const lvc = getValueConstruction(node.left, initialScope, hint);
|
|
274
|
-
if (lvc
|
|
275
|
-
return lvc;
|
|
276
|
-
}
|
|
244
|
+
if (lvc === eff._) return eff._;
|
|
277
245
|
return getValueConstruction(node.right, initialScope, hint);
|
|
278
246
|
}
|
|
279
247
|
case types.AST_NODE_TYPES.ConditionalExpression: {
|
|
280
248
|
const cvc = getValueConstruction(node.consequent, initialScope, hint);
|
|
281
|
-
if (cvc
|
|
282
|
-
return cvc;
|
|
283
|
-
}
|
|
249
|
+
if (cvc === eff._) return eff._;
|
|
284
250
|
return getValueConstruction(node.alternate, initialScope, hint);
|
|
285
251
|
}
|
|
286
252
|
case types.AST_NODE_TYPES.Identifier: {
|
|
287
|
-
if (!("name" in node &&
|
|
288
|
-
return
|
|
289
|
-
}
|
|
290
|
-
const construction = eff.F.pipe(
|
|
291
|
-
eff.O.fromNullable(initialScope.set.get(node.name)),
|
|
292
|
-
eff.O.flatMap(getVariableNode(-1)),
|
|
293
|
-
eff.O.map((node2) => getValueConstruction(node2, initialScope, hint)),
|
|
294
|
-
eff.O.filter((vc) => vc.kind !== "None")
|
|
295
|
-
);
|
|
296
|
-
if (eff.O.isNone(construction)) {
|
|
297
|
-
return { kind: "None", node };
|
|
253
|
+
if (!("name" in node && typeof node.name === "string")) {
|
|
254
|
+
return eff._;
|
|
298
255
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
256
|
+
const variable = initialScope.set.get(node.name);
|
|
257
|
+
const variableNode = getVariableNode(variable, -1);
|
|
258
|
+
return getValueConstruction(variableNode, initialScope, hint);
|
|
302
259
|
}
|
|
303
260
|
case types.AST_NODE_TYPES.Literal: {
|
|
304
261
|
if ("regex" in node) {
|
|
305
262
|
return { kind: "RegExpLiteral", node };
|
|
306
263
|
}
|
|
307
|
-
return
|
|
264
|
+
return eff._;
|
|
308
265
|
}
|
|
309
266
|
default: {
|
|
310
|
-
if (!("expression" in node &&
|
|
311
|
-
return
|
|
267
|
+
if (!("expression" in node && typeof node.expression === "object")) {
|
|
268
|
+
return eff._;
|
|
312
269
|
}
|
|
313
270
|
return getValueConstruction(node.expression, initialScope, hint);
|
|
314
271
|
}
|
|
@@ -318,11 +275,10 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
|
|
|
318
275
|
exports.ValueConstructionHint = ValueConstructionHint;
|
|
319
276
|
exports.findVariable = findVariable2;
|
|
320
277
|
exports.getChidScopes = getChidScopes;
|
|
321
|
-
exports.getScope = getScope;
|
|
322
|
-
exports.getStaticValue = getStaticValue2;
|
|
323
278
|
exports.getValueConstruction = getValueConstruction;
|
|
324
|
-
exports.
|
|
279
|
+
exports.getVariableDeclaratorId = getVariableDeclaratorId;
|
|
325
280
|
exports.getVariableNode = getVariableNode;
|
|
326
281
|
exports.getVariables = getVariables;
|
|
327
282
|
exports.isInitializedFromSource = isInitializedFromSource;
|
|
328
283
|
exports.isNodeValueEqual = isNodeValueEqual;
|
|
284
|
+
exports.toResolved = toResolved;
|
package/dist/index.mjs
CHANGED
|
@@ -1,69 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dual, _ } from '@eslint-react/eff';
|
|
2
2
|
import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
|
|
3
|
+
import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
|
|
3
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
4
5
|
import * as AST3 from '@eslint-react/ast';
|
|
5
6
|
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
6
7
|
|
|
7
8
|
// src/find-variable.ts
|
|
8
|
-
var findVariable2 =
|
|
9
|
-
|
|
9
|
+
var findVariable2 = dual(2, (nameOrNode, initialScope) => {
|
|
10
|
+
if (nameOrNode === _) return _;
|
|
11
|
+
return ASTUtils.findVariable(initialScope, nameOrNode) ?? _;
|
|
10
12
|
});
|
|
11
13
|
|
|
12
14
|
// src/get-child-scopes.ts
|
|
13
|
-
function getChidScopes(scope
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const { type, parent } = node;
|
|
18
|
-
const inner = type !== AST_NODE_TYPES.Program;
|
|
19
|
-
const scope = scopeManager.acquire(node, inner);
|
|
20
|
-
if (scope != null) {
|
|
21
|
-
return scope;
|
|
22
|
-
}
|
|
23
|
-
if (parent != null) {
|
|
24
|
-
return getScope(parent, scopeManager);
|
|
15
|
+
function getChidScopes(scope) {
|
|
16
|
+
const scopes = [scope];
|
|
17
|
+
for (const childScope of scope.childScopes) {
|
|
18
|
+
scopes.push(...getChidScopes(childScope));
|
|
25
19
|
}
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
function getStaticValue2(node, initialScope) {
|
|
29
|
-
return F.pipe(
|
|
30
|
-
O.fromNullable(ASTUtils.getStaticValue(node, initialScope)),
|
|
31
|
-
O.map((v) => v.value)
|
|
32
|
-
);
|
|
20
|
+
return scopes;
|
|
33
21
|
}
|
|
34
|
-
function
|
|
22
|
+
function getVariableDeclaratorId(node, prev) {
|
|
23
|
+
if (node === _) return _;
|
|
35
24
|
switch (true) {
|
|
36
25
|
case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
37
|
-
return
|
|
26
|
+
return node.id;
|
|
38
27
|
case (node.type === AST_NODE_TYPES.AssignmentExpression && node.right === prev):
|
|
39
|
-
return
|
|
28
|
+
return node.left;
|
|
40
29
|
case (node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node):
|
|
41
|
-
return
|
|
30
|
+
return _;
|
|
42
31
|
default:
|
|
43
|
-
return
|
|
32
|
+
return getVariableDeclaratorId(node.parent, node);
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
|
-
function getVariableNode(at) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
};
|
|
35
|
+
function getVariableNode(variable, at) {
|
|
36
|
+
if (variable === _) return _;
|
|
37
|
+
const def = variable.defs.at(at);
|
|
38
|
+
if (def === _) return _;
|
|
39
|
+
switch (true) {
|
|
40
|
+
case (def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration):
|
|
41
|
+
return def.node;
|
|
42
|
+
case (def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration):
|
|
43
|
+
return def.node;
|
|
44
|
+
case (def.type === DefinitionType.Parameter && AST3.isFunction(def.node)):
|
|
45
|
+
return def.node;
|
|
46
|
+
case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
|
|
47
|
+
return def.node.init;
|
|
48
|
+
default:
|
|
49
|
+
return _;
|
|
50
|
+
}
|
|
67
51
|
}
|
|
68
52
|
function getVariables(initialScope) {
|
|
69
53
|
let scope = initialScope;
|
|
@@ -75,11 +59,9 @@ function getVariables(initialScope) {
|
|
|
75
59
|
return variables.reverse();
|
|
76
60
|
}
|
|
77
61
|
function isInitializedFromSource(name, source, initialScope) {
|
|
78
|
-
const latestDef =
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
const { node, parent } = latestDef.value;
|
|
62
|
+
const latestDef = findVariable2(name, initialScope)?.defs.at(-1);
|
|
63
|
+
if (latestDef === _) return false;
|
|
64
|
+
const { node, parent } = latestDef;
|
|
83
65
|
if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
84
66
|
const { init } = node;
|
|
85
67
|
if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) {
|
|
@@ -88,13 +70,12 @@ function isInitializedFromSource(name, source, initialScope) {
|
|
|
88
70
|
if (init.type === AST_NODE_TYPES.Identifier) {
|
|
89
71
|
return isInitializedFromSource(init.name, source, initialScope);
|
|
90
72
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
);
|
|
73
|
+
const args = getRequireExpressionArguments(init);
|
|
74
|
+
const arg0 = args?.[0];
|
|
75
|
+
if (arg0 == null || !AST3.isStringLiteral(arg0)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return arg0.value === source || arg0.value.startsWith(`${source}/`);
|
|
98
79
|
}
|
|
99
80
|
return parent?.type === AST_NODE_TYPES.ImportDeclaration && parent.source.value === source;
|
|
100
81
|
}
|
|
@@ -102,15 +83,25 @@ function getRequireExpressionArguments(node) {
|
|
|
102
83
|
switch (true) {
|
|
103
84
|
// require('source')
|
|
104
85
|
case (node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "require"): {
|
|
105
|
-
return
|
|
86
|
+
return node.arguments;
|
|
106
87
|
}
|
|
107
88
|
// require('source').variable
|
|
108
89
|
case node.type === AST_NODE_TYPES.MemberExpression: {
|
|
109
90
|
return getRequireExpressionArguments(node.object);
|
|
110
91
|
}
|
|
111
92
|
}
|
|
112
|
-
return
|
|
93
|
+
return _;
|
|
113
94
|
}
|
|
95
|
+
function toResolved(sv) {
|
|
96
|
+
const { kind, node, initialScope } = sv;
|
|
97
|
+
if (kind !== "lazy") {
|
|
98
|
+
return sv;
|
|
99
|
+
}
|
|
100
|
+
const resolvedValue = initialScope === _ ? getStaticValue(node) : getStaticValue(node, initialScope);
|
|
101
|
+
return resolvedValue == null ? { kind: "none", node, initialScope } : { kind: "some", node, initialScope, value: resolvedValue.value };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/is-node-value-equal.ts
|
|
114
105
|
var thisBlockTypes = [
|
|
115
106
|
AST_NODE_TYPES.FunctionDeclaration,
|
|
116
107
|
AST_NODE_TYPES.FunctionExpression,
|
|
@@ -132,48 +123,37 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
132
123
|
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier): {
|
|
133
124
|
const aVar = findVariable2(a, aScope);
|
|
134
125
|
const bVar = findVariable2(b, bScope);
|
|
135
|
-
const aVarNode =
|
|
136
|
-
const bVarNode =
|
|
137
|
-
const aVarNodeParent =
|
|
138
|
-
const bVarNodeParent =
|
|
139
|
-
const aDef =
|
|
140
|
-
const bDef =
|
|
141
|
-
const aDefParentParent =
|
|
142
|
-
const bDefParentParent =
|
|
126
|
+
const aVarNode = getVariableNode(aVar, 0);
|
|
127
|
+
const bVarNode = getVariableNode(bVar, 0);
|
|
128
|
+
const aVarNodeParent = aVarNode?.parent;
|
|
129
|
+
const bVarNodeParent = bVarNode?.parent;
|
|
130
|
+
const aDef = aVar?.defs.at(0);
|
|
131
|
+
const bDef = bVar?.defs.at(0);
|
|
132
|
+
const aDefParentParent = aDef?.parent?.parent;
|
|
133
|
+
const bDefParentParent = bDef?.parent?.parent;
|
|
143
134
|
switch (true) {
|
|
144
|
-
case (
|
|
145
|
-
|
|
146
|
-
O.Do,
|
|
147
|
-
O.bind("aCallee", () => O.map(aVarNodeParent, (n) => n.callee)),
|
|
148
|
-
O.bind("bCallee", () => O.map(bVarNodeParent, (n) => n.callee)),
|
|
149
|
-
O.exists(({ aCallee, bCallee }) => AST3.isNodeEqual(aCallee, bCallee))
|
|
150
|
-
);
|
|
151
|
-
if (!hasSameCallee) {
|
|
135
|
+
case (aVarNodeParent?.type === AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === AST_NODE_TYPES.CallExpression && AST3.isFunction(aVarNode) && AST3.isFunction(bVarNode)): {
|
|
136
|
+
if (!AST3.isNodeEqual(aVarNodeParent.callee, bVarNodeParent.callee)) {
|
|
152
137
|
return false;
|
|
153
138
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
O.let("bPos", ({ bParams }) => bParams.findIndex(AST3.isNodeEqual(b))),
|
|
160
|
-
O.filter(({ aPos, bPos }) => aPos !== -1 && bPos !== -1),
|
|
161
|
-
O.exists(({ aPos, bPos }) => aPos === bPos)
|
|
162
|
-
);
|
|
139
|
+
const aParams = aVarNode.params;
|
|
140
|
+
const bParams = bVarNode.params;
|
|
141
|
+
const aPos = aParams.findIndex((x) => AST3.isNodeEqual(x, a));
|
|
142
|
+
const bPos = bParams.findIndex((x) => AST3.isNodeEqual(x, b));
|
|
143
|
+
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
163
144
|
}
|
|
164
|
-
case (
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
);
|
|
145
|
+
case (aDefParentParent?.type === AST_NODE_TYPES.ForOfStatement && bDefParentParent?.type === AST_NODE_TYPES.ForOfStatement): {
|
|
146
|
+
const aLeft = aDefParentParent.left;
|
|
147
|
+
const bLeft = bDefParentParent.left;
|
|
148
|
+
if (aLeft.type !== bLeft.type) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
const aRight = aDefParentParent.right;
|
|
152
|
+
const bRight = bDefParentParent.right;
|
|
153
|
+
return AST3.isNodeEqual(aRight, bRight);
|
|
174
154
|
}
|
|
175
155
|
default: {
|
|
176
|
-
return
|
|
156
|
+
return aVar !== _ && bVar !== _ && aVar === bVar;
|
|
177
157
|
}
|
|
178
158
|
}
|
|
179
159
|
}
|
|
@@ -184,20 +164,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
184
164
|
if (aScope.block === bScope.block) {
|
|
185
165
|
return true;
|
|
186
166
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
O.bind("bFunction", () => AST3.findParentNode(b, AST3.isOneOf(thisBlockTypes))),
|
|
191
|
-
O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
|
|
192
|
-
);
|
|
167
|
+
const aFunction = AST3.findParentNode(a, AST3.isOneOf(thisBlockTypes));
|
|
168
|
+
const bFunction = AST3.findParentNode(b, AST3.isOneOf(thisBlockTypes));
|
|
169
|
+
return aFunction === bFunction;
|
|
193
170
|
}
|
|
194
171
|
default: {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
O.bind("bStatic", () => getStaticValue2(b, bScope)),
|
|
199
|
-
O.exists(({ aStatic, bStatic }) => aStatic === bStatic)
|
|
200
|
-
);
|
|
172
|
+
const aStatic = toResolved({ kind: "lazy", node: a, initialScope: aScope });
|
|
173
|
+
const bStatic = toResolved({ kind: "lazy", node: b, initialScope: bScope });
|
|
174
|
+
return aStatic.kind !== "none" && bStatic.kind !== "none" && aStatic.value === bStatic.value;
|
|
201
175
|
}
|
|
202
176
|
}
|
|
203
177
|
}
|
|
@@ -206,6 +180,7 @@ var ValueConstructionHint = {
|
|
|
206
180
|
StrictCallExpression: 1n << 0n
|
|
207
181
|
};
|
|
208
182
|
function getValueConstruction(node, initialScope, hint = ValueConstructionHint.None) {
|
|
183
|
+
if (node === _) return _;
|
|
209
184
|
switch (node.type) {
|
|
210
185
|
case AST_NODE_TYPES.JSXElement:
|
|
211
186
|
case AST_NODE_TYPES.JSXFragment: {
|
|
@@ -231,65 +206,48 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
|
|
|
231
206
|
if (hint & ValueConstructionHint.StrictCallExpression) {
|
|
232
207
|
return { kind: "CallExpression", node };
|
|
233
208
|
}
|
|
234
|
-
return
|
|
209
|
+
return _;
|
|
235
210
|
}
|
|
236
211
|
case AST_NODE_TYPES.MemberExpression: {
|
|
237
|
-
if (!("object" in node))
|
|
238
|
-
return { kind: "None", node };
|
|
239
|
-
}
|
|
212
|
+
if (!("object" in node)) return _;
|
|
240
213
|
return getValueConstruction(node.object, initialScope, hint);
|
|
241
214
|
}
|
|
242
215
|
case AST_NODE_TYPES.AssignmentExpression:
|
|
243
216
|
case AST_NODE_TYPES.AssignmentPattern: {
|
|
244
|
-
if (!("right" in node))
|
|
245
|
-
return { kind: "None", node };
|
|
246
|
-
}
|
|
217
|
+
if (!("right" in node)) return _;
|
|
247
218
|
return getValueConstruction(node.right, initialScope, hint);
|
|
248
219
|
}
|
|
249
220
|
case AST_NODE_TYPES.LogicalExpression: {
|
|
250
221
|
const lvc = getValueConstruction(node.left, initialScope, hint);
|
|
251
|
-
if (lvc
|
|
252
|
-
return lvc;
|
|
253
|
-
}
|
|
222
|
+
if (lvc === _) return _;
|
|
254
223
|
return getValueConstruction(node.right, initialScope, hint);
|
|
255
224
|
}
|
|
256
225
|
case AST_NODE_TYPES.ConditionalExpression: {
|
|
257
226
|
const cvc = getValueConstruction(node.consequent, initialScope, hint);
|
|
258
|
-
if (cvc
|
|
259
|
-
return cvc;
|
|
260
|
-
}
|
|
227
|
+
if (cvc === _) return _;
|
|
261
228
|
return getValueConstruction(node.alternate, initialScope, hint);
|
|
262
229
|
}
|
|
263
230
|
case AST_NODE_TYPES.Identifier: {
|
|
264
|
-
if (!("name" in node &&
|
|
265
|
-
return
|
|
266
|
-
}
|
|
267
|
-
const construction = F.pipe(
|
|
268
|
-
O.fromNullable(initialScope.set.get(node.name)),
|
|
269
|
-
O.flatMap(getVariableNode(-1)),
|
|
270
|
-
O.map((node2) => getValueConstruction(node2, initialScope, hint)),
|
|
271
|
-
O.filter((vc) => vc.kind !== "None")
|
|
272
|
-
);
|
|
273
|
-
if (O.isNone(construction)) {
|
|
274
|
-
return { kind: "None", node };
|
|
231
|
+
if (!("name" in node && typeof node.name === "string")) {
|
|
232
|
+
return _;
|
|
275
233
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
234
|
+
const variable = initialScope.set.get(node.name);
|
|
235
|
+
const variableNode = getVariableNode(variable, -1);
|
|
236
|
+
return getValueConstruction(variableNode, initialScope, hint);
|
|
279
237
|
}
|
|
280
238
|
case AST_NODE_TYPES.Literal: {
|
|
281
239
|
if ("regex" in node) {
|
|
282
240
|
return { kind: "RegExpLiteral", node };
|
|
283
241
|
}
|
|
284
|
-
return
|
|
242
|
+
return _;
|
|
285
243
|
}
|
|
286
244
|
default: {
|
|
287
|
-
if (!("expression" in node &&
|
|
288
|
-
return
|
|
245
|
+
if (!("expression" in node && typeof node.expression === "object")) {
|
|
246
|
+
return _;
|
|
289
247
|
}
|
|
290
248
|
return getValueConstruction(node.expression, initialScope, hint);
|
|
291
249
|
}
|
|
292
250
|
}
|
|
293
251
|
}
|
|
294
252
|
|
|
295
|
-
export { ValueConstructionHint, findVariable2 as findVariable, getChidScopes,
|
|
253
|
+
export { ValueConstructionHint, findVariable2 as findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toResolved };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0-next.0",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module for static analysis of variables",
|
|
5
|
-
"homepage": "https://github.com/
|
|
5
|
+
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
7
|
-
"url": "https://github.com/
|
|
7
|
+
"url": "https://github.com/Rel1cx/eslint-react/issues"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
11
|
+
"url": "git+https://github.com/Rel1cx/eslint-react.git",
|
|
12
12
|
"directory": "packages/utilities/var"
|
|
13
13
|
},
|
|
14
14
|
"license": "MIT",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"@typescript-eslint/utils": "^8.19.1",
|
|
39
39
|
"string-ts": "^2.2.0",
|
|
40
40
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"@eslint-react/ast": "1.
|
|
42
|
-
"@eslint-react/
|
|
43
|
-
"@eslint-react/
|
|
41
|
+
"@eslint-react/ast": "1.24.0-next.0",
|
|
42
|
+
"@eslint-react/types": "1.24.0-next.0",
|
|
43
|
+
"@eslint-react/eff": "1.24.0-next.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsup": "^8.3.5",
|