@eslint-react/var 1.24.0-beta.0 → 1.24.0-beta.16
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 +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +74 -34
- package/dist/index.mjs +73 -34
- package/package.json +6 -7
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,8 @@ import { _ } from '@eslint-react/eff';
|
|
|
2
2
|
import { Scope, Variable } from '@typescript-eslint/scope-manager';
|
|
3
3
|
import { TSESTree } from '@typescript-eslint/types';
|
|
4
4
|
|
|
5
|
+
declare function findPropertyInProperties(name: string, properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen?: Set<string>): (typeof properties)[number] | _;
|
|
6
|
+
|
|
5
7
|
declare const findVariable: {
|
|
6
8
|
(initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | _) => Variable | _;
|
|
7
9
|
(nameOrNode: string | TSESTree.Identifier | _, initialScope: Scope): Variable | _;
|
|
@@ -41,7 +43,7 @@ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialSco
|
|
|
41
43
|
bScope: Scope
|
|
42
44
|
]): boolean;
|
|
43
45
|
|
|
44
|
-
type
|
|
46
|
+
type LazyValue = {
|
|
45
47
|
kind: "lazy";
|
|
46
48
|
node: TSESTree.Node;
|
|
47
49
|
initialScope: Scope | _;
|
|
@@ -55,7 +57,7 @@ type StaticValue = {
|
|
|
55
57
|
value: unknown;
|
|
56
58
|
initialScope: Scope | _;
|
|
57
59
|
};
|
|
58
|
-
declare function
|
|
60
|
+
declare function toStaticValue(lazyValue: LazyValue): {
|
|
59
61
|
readonly kind: "none";
|
|
60
62
|
readonly node: TSESTree.Node;
|
|
61
63
|
readonly initialScope: Scope | undefined;
|
|
@@ -108,4 +110,4 @@ declare const ValueConstructionHint: {
|
|
|
108
110
|
*/
|
|
109
111
|
declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
|
|
110
112
|
|
|
111
|
-
export { type
|
|
113
|
+
export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toStaticValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { _ } from '@eslint-react/eff';
|
|
|
2
2
|
import { Scope, Variable } from '@typescript-eslint/scope-manager';
|
|
3
3
|
import { TSESTree } from '@typescript-eslint/types';
|
|
4
4
|
|
|
5
|
+
declare function findPropertyInProperties(name: string, properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen?: Set<string>): (typeof properties)[number] | _;
|
|
6
|
+
|
|
5
7
|
declare const findVariable: {
|
|
6
8
|
(initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | _) => Variable | _;
|
|
7
9
|
(nameOrNode: string | TSESTree.Identifier | _, initialScope: Scope): Variable | _;
|
|
@@ -41,7 +43,7 @@ declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialSco
|
|
|
41
43
|
bScope: Scope
|
|
42
44
|
]): boolean;
|
|
43
45
|
|
|
44
|
-
type
|
|
46
|
+
type LazyValue = {
|
|
45
47
|
kind: "lazy";
|
|
46
48
|
node: TSESTree.Node;
|
|
47
49
|
initialScope: Scope | _;
|
|
@@ -55,7 +57,7 @@ type StaticValue = {
|
|
|
55
57
|
value: unknown;
|
|
56
58
|
initialScope: Scope | _;
|
|
57
59
|
};
|
|
58
|
-
declare function
|
|
60
|
+
declare function toStaticValue(lazyValue: LazyValue): {
|
|
59
61
|
readonly kind: "none";
|
|
60
62
|
readonly node: TSESTree.Node;
|
|
61
63
|
readonly initialScope: Scope | undefined;
|
|
@@ -108,4 +110,4 @@ declare const ValueConstructionHint: {
|
|
|
108
110
|
*/
|
|
109
111
|
declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
|
|
110
112
|
|
|
111
|
-
export { type
|
|
113
|
+
export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toStaticValue };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var types = require('@typescript-eslint/types');
|
|
3
4
|
var eff = require('@eslint-react/eff');
|
|
4
5
|
var ASTUtils = require('@typescript-eslint/utils/ast-utils');
|
|
5
|
-
var types = require('@typescript-eslint/types');
|
|
6
6
|
var AST3 = require('@eslint-react/ast');
|
|
7
7
|
var scopeManager = require('@typescript-eslint/scope-manager');
|
|
8
8
|
|
|
@@ -27,11 +27,67 @@ function _interopNamespace(e) {
|
|
|
27
27
|
var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
|
|
28
28
|
var AST3__namespace = /*#__PURE__*/_interopNamespace(AST3);
|
|
29
29
|
|
|
30
|
-
// src/find-
|
|
30
|
+
// src/find-property-in-properties.ts
|
|
31
31
|
var findVariable2 = eff.dual(2, (nameOrNode, initialScope) => {
|
|
32
|
-
if (nameOrNode
|
|
32
|
+
if (nameOrNode == null) return eff._;
|
|
33
33
|
return ASTUtils__namespace.findVariable(initialScope, nameOrNode) ?? eff._;
|
|
34
34
|
});
|
|
35
|
+
function getVariableNode(variable, at) {
|
|
36
|
+
if (variable == null) return eff._;
|
|
37
|
+
const def = variable.defs.at(at);
|
|
38
|
+
if (def == null) return eff._;
|
|
39
|
+
switch (true) {
|
|
40
|
+
case (def.type === scopeManager.DefinitionType.FunctionName && def.node.type === types.AST_NODE_TYPES.FunctionDeclaration):
|
|
41
|
+
return def.node;
|
|
42
|
+
case (def.type === scopeManager.DefinitionType.ClassName && def.node.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
43
|
+
return def.node;
|
|
44
|
+
case (def.type === scopeManager.DefinitionType.Parameter && AST3__namespace.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 eff._;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/find-property-in-properties.ts
|
|
54
|
+
function findPropertyInProperties(name, properties, initialScope, seen = /* @__PURE__ */ new Set()) {
|
|
55
|
+
return properties.findLast((prop) => {
|
|
56
|
+
if (prop.type === types.AST_NODE_TYPES.Property) {
|
|
57
|
+
return "name" in prop.key && prop.key.name === name;
|
|
58
|
+
}
|
|
59
|
+
if (prop.type === types.AST_NODE_TYPES.SpreadElement) {
|
|
60
|
+
switch (prop.argument.type) {
|
|
61
|
+
case types.AST_NODE_TYPES.Identifier: {
|
|
62
|
+
if (seen.has(prop.argument.name)) return false;
|
|
63
|
+
const variable = findVariable2(prop.argument.name, initialScope);
|
|
64
|
+
const variableNode = getVariableNode(variable, 0);
|
|
65
|
+
if (variableNode?.type === types.AST_NODE_TYPES.ObjectExpression) {
|
|
66
|
+
seen.add(prop.argument.name);
|
|
67
|
+
return findPropertyInProperties(
|
|
68
|
+
name,
|
|
69
|
+
variableNode.properties,
|
|
70
|
+
initialScope,
|
|
71
|
+
seen
|
|
72
|
+
) != null;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
case types.AST_NODE_TYPES.ObjectExpression: {
|
|
77
|
+
return findPropertyInProperties(
|
|
78
|
+
name,
|
|
79
|
+
prop.argument.properties,
|
|
80
|
+
initialScope,
|
|
81
|
+
seen
|
|
82
|
+
) != null;
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
35
91
|
|
|
36
92
|
// src/get-child-scopes.ts
|
|
37
93
|
function getChidScopes(scope) {
|
|
@@ -42,7 +98,7 @@ function getChidScopes(scope) {
|
|
|
42
98
|
return scopes;
|
|
43
99
|
}
|
|
44
100
|
function getVariableDeclaratorId(node, prev) {
|
|
45
|
-
if (node
|
|
101
|
+
if (node == null) return eff._;
|
|
46
102
|
switch (true) {
|
|
47
103
|
case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
48
104
|
return node.id;
|
|
@@ -54,23 +110,6 @@ function getVariableDeclaratorId(node, prev) {
|
|
|
54
110
|
return getVariableDeclaratorId(node.parent, node);
|
|
55
111
|
}
|
|
56
112
|
}
|
|
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
|
-
}
|
|
73
|
-
}
|
|
74
113
|
function getVariables(initialScope) {
|
|
75
114
|
let scope = initialScope;
|
|
76
115
|
const variables = [...scope.variables];
|
|
@@ -82,7 +121,7 @@ function getVariables(initialScope) {
|
|
|
82
121
|
}
|
|
83
122
|
function isInitializedFromSource(name, source, initialScope) {
|
|
84
123
|
const latestDef = findVariable2(name, initialScope)?.defs.at(-1);
|
|
85
|
-
if (latestDef
|
|
124
|
+
if (latestDef == null) return false;
|
|
86
125
|
const { node, parent } = latestDef;
|
|
87
126
|
if (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
88
127
|
const { init } = node;
|
|
@@ -114,13 +153,13 @@ function getRequireExpressionArguments(node) {
|
|
|
114
153
|
}
|
|
115
154
|
return eff._;
|
|
116
155
|
}
|
|
117
|
-
function
|
|
118
|
-
const { kind, node, initialScope } =
|
|
156
|
+
function toStaticValue(lazyValue) {
|
|
157
|
+
const { kind, node, initialScope } = lazyValue;
|
|
119
158
|
if (kind !== "lazy") {
|
|
120
|
-
return
|
|
159
|
+
return lazyValue;
|
|
121
160
|
}
|
|
122
|
-
const
|
|
123
|
-
return
|
|
161
|
+
const staticValue = initialScope == null ? ASTUtils.getStaticValue(node) : ASTUtils.getStaticValue(node, initialScope);
|
|
162
|
+
return staticValue == null ? { kind: "none", node, initialScope } : { kind: "some", node, initialScope, value: staticValue.value };
|
|
124
163
|
}
|
|
125
164
|
|
|
126
165
|
// src/is-node-value-equal.ts
|
|
@@ -175,7 +214,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
175
214
|
return AST3__namespace.isNodeEqual(aRight, bRight);
|
|
176
215
|
}
|
|
177
216
|
default: {
|
|
178
|
-
return aVar
|
|
217
|
+
return aVar != null && bVar != null && aVar === bVar;
|
|
179
218
|
}
|
|
180
219
|
}
|
|
181
220
|
}
|
|
@@ -191,8 +230,8 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
191
230
|
return aFunction === bFunction;
|
|
192
231
|
}
|
|
193
232
|
default: {
|
|
194
|
-
const aStatic =
|
|
195
|
-
const bStatic =
|
|
233
|
+
const aStatic = toStaticValue({ kind: "lazy", node: a, initialScope: aScope });
|
|
234
|
+
const bStatic = toStaticValue({ kind: "lazy", node: b, initialScope: bScope });
|
|
196
235
|
return aStatic.kind !== "none" && bStatic.kind !== "none" && aStatic.value === bStatic.value;
|
|
197
236
|
}
|
|
198
237
|
}
|
|
@@ -202,7 +241,7 @@ var ValueConstructionHint = {
|
|
|
202
241
|
StrictCallExpression: 1n << 0n
|
|
203
242
|
};
|
|
204
243
|
function getValueConstruction(node, initialScope, hint = ValueConstructionHint.None) {
|
|
205
|
-
if (node
|
|
244
|
+
if (node == null) return eff._;
|
|
206
245
|
switch (node.type) {
|
|
207
246
|
case types.AST_NODE_TYPES.JSXElement:
|
|
208
247
|
case types.AST_NODE_TYPES.JSXFragment: {
|
|
@@ -241,12 +280,12 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
|
|
|
241
280
|
}
|
|
242
281
|
case types.AST_NODE_TYPES.LogicalExpression: {
|
|
243
282
|
const lvc = getValueConstruction(node.left, initialScope, hint);
|
|
244
|
-
if (lvc
|
|
283
|
+
if (lvc == null) return eff._;
|
|
245
284
|
return getValueConstruction(node.right, initialScope, hint);
|
|
246
285
|
}
|
|
247
286
|
case types.AST_NODE_TYPES.ConditionalExpression: {
|
|
248
287
|
const cvc = getValueConstruction(node.consequent, initialScope, hint);
|
|
249
|
-
if (cvc
|
|
288
|
+
if (cvc == null) return eff._;
|
|
250
289
|
return getValueConstruction(node.alternate, initialScope, hint);
|
|
251
290
|
}
|
|
252
291
|
case types.AST_NODE_TYPES.Identifier: {
|
|
@@ -273,6 +312,7 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
|
|
|
273
312
|
}
|
|
274
313
|
|
|
275
314
|
exports.ValueConstructionHint = ValueConstructionHint;
|
|
315
|
+
exports.findPropertyInProperties = findPropertyInProperties;
|
|
276
316
|
exports.findVariable = findVariable2;
|
|
277
317
|
exports.getChidScopes = getChidScopes;
|
|
278
318
|
exports.getValueConstruction = getValueConstruction;
|
|
@@ -281,4 +321,4 @@ exports.getVariableNode = getVariableNode;
|
|
|
281
321
|
exports.getVariables = getVariables;
|
|
282
322
|
exports.isInitializedFromSource = isInitializedFromSource;
|
|
283
323
|
exports.isNodeValueEqual = isNodeValueEqual;
|
|
284
|
-
exports.
|
|
324
|
+
exports.toStaticValue = toStaticValue;
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,71 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
1
2
|
import { dual, _ } from '@eslint-react/eff';
|
|
2
3
|
import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
|
|
3
4
|
import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
|
|
4
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import * as AST3 from '@eslint-react/ast';
|
|
6
6
|
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
7
7
|
|
|
8
|
-
// src/find-
|
|
8
|
+
// src/find-property-in-properties.ts
|
|
9
9
|
var findVariable2 = dual(2, (nameOrNode, initialScope) => {
|
|
10
|
-
if (nameOrNode
|
|
10
|
+
if (nameOrNode == null) return _;
|
|
11
11
|
return ASTUtils.findVariable(initialScope, nameOrNode) ?? _;
|
|
12
12
|
});
|
|
13
|
+
function getVariableNode(variable, at) {
|
|
14
|
+
if (variable == null) return _;
|
|
15
|
+
const def = variable.defs.at(at);
|
|
16
|
+
if (def == null) return _;
|
|
17
|
+
switch (true) {
|
|
18
|
+
case (def.type === DefinitionType.FunctionName && def.node.type === AST_NODE_TYPES.FunctionDeclaration):
|
|
19
|
+
return def.node;
|
|
20
|
+
case (def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration):
|
|
21
|
+
return def.node;
|
|
22
|
+
case (def.type === DefinitionType.Parameter && AST3.isFunction(def.node)):
|
|
23
|
+
return def.node;
|
|
24
|
+
case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
|
|
25
|
+
return def.node.init;
|
|
26
|
+
default:
|
|
27
|
+
return _;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/find-property-in-properties.ts
|
|
32
|
+
function findPropertyInProperties(name, properties, initialScope, seen = /* @__PURE__ */ new Set()) {
|
|
33
|
+
return properties.findLast((prop) => {
|
|
34
|
+
if (prop.type === AST_NODE_TYPES.Property) {
|
|
35
|
+
return "name" in prop.key && prop.key.name === name;
|
|
36
|
+
}
|
|
37
|
+
if (prop.type === AST_NODE_TYPES.SpreadElement) {
|
|
38
|
+
switch (prop.argument.type) {
|
|
39
|
+
case AST_NODE_TYPES.Identifier: {
|
|
40
|
+
if (seen.has(prop.argument.name)) return false;
|
|
41
|
+
const variable = findVariable2(prop.argument.name, initialScope);
|
|
42
|
+
const variableNode = getVariableNode(variable, 0);
|
|
43
|
+
if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) {
|
|
44
|
+
seen.add(prop.argument.name);
|
|
45
|
+
return findPropertyInProperties(
|
|
46
|
+
name,
|
|
47
|
+
variableNode.properties,
|
|
48
|
+
initialScope,
|
|
49
|
+
seen
|
|
50
|
+
) != null;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
case AST_NODE_TYPES.ObjectExpression: {
|
|
55
|
+
return findPropertyInProperties(
|
|
56
|
+
name,
|
|
57
|
+
prop.argument.properties,
|
|
58
|
+
initialScope,
|
|
59
|
+
seen
|
|
60
|
+
) != null;
|
|
61
|
+
}
|
|
62
|
+
default:
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
13
69
|
|
|
14
70
|
// src/get-child-scopes.ts
|
|
15
71
|
function getChidScopes(scope) {
|
|
@@ -20,7 +76,7 @@ function getChidScopes(scope) {
|
|
|
20
76
|
return scopes;
|
|
21
77
|
}
|
|
22
78
|
function getVariableDeclaratorId(node, prev) {
|
|
23
|
-
if (node
|
|
79
|
+
if (node == null) return _;
|
|
24
80
|
switch (true) {
|
|
25
81
|
case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
26
82
|
return node.id;
|
|
@@ -32,23 +88,6 @@ function getVariableDeclaratorId(node, prev) {
|
|
|
32
88
|
return getVariableDeclaratorId(node.parent, node);
|
|
33
89
|
}
|
|
34
90
|
}
|
|
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
|
-
}
|
|
51
|
-
}
|
|
52
91
|
function getVariables(initialScope) {
|
|
53
92
|
let scope = initialScope;
|
|
54
93
|
const variables = [...scope.variables];
|
|
@@ -60,7 +99,7 @@ function getVariables(initialScope) {
|
|
|
60
99
|
}
|
|
61
100
|
function isInitializedFromSource(name, source, initialScope) {
|
|
62
101
|
const latestDef = findVariable2(name, initialScope)?.defs.at(-1);
|
|
63
|
-
if (latestDef
|
|
102
|
+
if (latestDef == null) return false;
|
|
64
103
|
const { node, parent } = latestDef;
|
|
65
104
|
if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
66
105
|
const { init } = node;
|
|
@@ -92,13 +131,13 @@ function getRequireExpressionArguments(node) {
|
|
|
92
131
|
}
|
|
93
132
|
return _;
|
|
94
133
|
}
|
|
95
|
-
function
|
|
96
|
-
const { kind, node, initialScope } =
|
|
134
|
+
function toStaticValue(lazyValue) {
|
|
135
|
+
const { kind, node, initialScope } = lazyValue;
|
|
97
136
|
if (kind !== "lazy") {
|
|
98
|
-
return
|
|
137
|
+
return lazyValue;
|
|
99
138
|
}
|
|
100
|
-
const
|
|
101
|
-
return
|
|
139
|
+
const staticValue = initialScope == null ? getStaticValue(node) : getStaticValue(node, initialScope);
|
|
140
|
+
return staticValue == null ? { kind: "none", node, initialScope } : { kind: "some", node, initialScope, value: staticValue.value };
|
|
102
141
|
}
|
|
103
142
|
|
|
104
143
|
// src/is-node-value-equal.ts
|
|
@@ -153,7 +192,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
153
192
|
return AST3.isNodeEqual(aRight, bRight);
|
|
154
193
|
}
|
|
155
194
|
default: {
|
|
156
|
-
return aVar
|
|
195
|
+
return aVar != null && bVar != null && aVar === bVar;
|
|
157
196
|
}
|
|
158
197
|
}
|
|
159
198
|
}
|
|
@@ -169,8 +208,8 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
169
208
|
return aFunction === bFunction;
|
|
170
209
|
}
|
|
171
210
|
default: {
|
|
172
|
-
const aStatic =
|
|
173
|
-
const bStatic =
|
|
211
|
+
const aStatic = toStaticValue({ kind: "lazy", node: a, initialScope: aScope });
|
|
212
|
+
const bStatic = toStaticValue({ kind: "lazy", node: b, initialScope: bScope });
|
|
174
213
|
return aStatic.kind !== "none" && bStatic.kind !== "none" && aStatic.value === bStatic.value;
|
|
175
214
|
}
|
|
176
215
|
}
|
|
@@ -180,7 +219,7 @@ var ValueConstructionHint = {
|
|
|
180
219
|
StrictCallExpression: 1n << 0n
|
|
181
220
|
};
|
|
182
221
|
function getValueConstruction(node, initialScope, hint = ValueConstructionHint.None) {
|
|
183
|
-
if (node
|
|
222
|
+
if (node == null) return _;
|
|
184
223
|
switch (node.type) {
|
|
185
224
|
case AST_NODE_TYPES.JSXElement:
|
|
186
225
|
case AST_NODE_TYPES.JSXFragment: {
|
|
@@ -219,12 +258,12 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
|
|
|
219
258
|
}
|
|
220
259
|
case AST_NODE_TYPES.LogicalExpression: {
|
|
221
260
|
const lvc = getValueConstruction(node.left, initialScope, hint);
|
|
222
|
-
if (lvc
|
|
261
|
+
if (lvc == null) return _;
|
|
223
262
|
return getValueConstruction(node.right, initialScope, hint);
|
|
224
263
|
}
|
|
225
264
|
case AST_NODE_TYPES.ConditionalExpression: {
|
|
226
265
|
const cvc = getValueConstruction(node.consequent, initialScope, hint);
|
|
227
|
-
if (cvc
|
|
266
|
+
if (cvc == null) return _;
|
|
228
267
|
return getValueConstruction(node.alternate, initialScope, hint);
|
|
229
268
|
}
|
|
230
269
|
case AST_NODE_TYPES.Identifier: {
|
|
@@ -250,4 +289,4 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
|
|
|
250
289
|
}
|
|
251
290
|
}
|
|
252
291
|
|
|
253
|
-
export { ValueConstructionHint, findVariable2 as findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual,
|
|
292
|
+
export { ValueConstructionHint, findPropertyInProperties, findVariable2 as findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableNode, getVariables, isInitializedFromSource, isNodeValueEqual, toStaticValue };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "1.24.0-beta.
|
|
3
|
+
"version": "1.24.0-beta.16",
|
|
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": {
|
|
@@ -33,14 +33,13 @@
|
|
|
33
33
|
"./package.json"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
37
|
-
"@typescript-eslint/types": "^8.
|
|
38
|
-
"@typescript-eslint/utils": "^8.
|
|
36
|
+
"@typescript-eslint/scope-manager": "^8.20.0",
|
|
37
|
+
"@typescript-eslint/types": "^8.20.0",
|
|
38
|
+
"@typescript-eslint/utils": "^8.20.0",
|
|
39
39
|
"string-ts": "^2.2.0",
|
|
40
40
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"@eslint-react/ast": "1.24.0-beta.
|
|
42
|
-
"@eslint-react/
|
|
43
|
-
"@eslint-react/eff": "1.24.0-beta.0"
|
|
41
|
+
"@eslint-react/ast": "1.24.0-beta.16",
|
|
42
|
+
"@eslint-react/eff": "1.24.0-beta.16"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"tsup": "^8.3.5",
|