@eslint-react/var 1.40.3 → 1.40.4-beta.4
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 +50 -44
- package/dist/index.d.ts +50 -44
- package/dist/index.js +81 -83
- package/dist/index.mjs +80 -82
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
|
-
import { _ } from '@eslint-react/eff';
|
|
2
|
-
import { Scope, Variable } from '@typescript-eslint/scope-manager';
|
|
3
1
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
+
import { Scope, Variable } from '@typescript-eslint/scope-manager';
|
|
3
|
+
import { _ } from '@eslint-react/eff';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents the construction type of a expression like node.
|
|
7
|
+
*/
|
|
8
|
+
type Construction = {
|
|
9
|
+
kind: "ArrayExpression";
|
|
10
|
+
node: TSESTree.ArrayExpression;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "CallExpression";
|
|
13
|
+
node: TSESTree.CallExpression;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "ClassExpression";
|
|
16
|
+
node: TSESTree.ClassExpression;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "FunctionDeclaration";
|
|
19
|
+
node: TSESTree.FunctionDeclaration;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "FunctionExpression";
|
|
22
|
+
node: TSESTree.FunctionExpression | TSESTree.ArrowFunctionExpression;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "JSXElement";
|
|
25
|
+
node: TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "NewExpression";
|
|
28
|
+
node: TSESTree.NewExpression;
|
|
29
|
+
} | {
|
|
30
|
+
kind: "ObjectExpression";
|
|
31
|
+
node: TSESTree.ObjectExpression;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "RegExpLiteral";
|
|
34
|
+
node: TSESTree.RegExpLiteral;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Detects the construction type of a given node.
|
|
39
|
+
* @param node The node to check.
|
|
40
|
+
* @param initialScope The initial scope to check for variable declarations.
|
|
41
|
+
* @param hint Optional hint to control the detection behavior.
|
|
42
|
+
* @returns The construction type of the node, or `_` if not found.
|
|
43
|
+
*/
|
|
44
|
+
declare function getConstructionDetectionResult(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): Construction | _;
|
|
45
|
+
|
|
46
|
+
type ConstructionDetectionHint = bigint;
|
|
47
|
+
declare const ConstructionDetectionHint: {
|
|
48
|
+
None: bigint;
|
|
49
|
+
StrictCallExpression: bigint;
|
|
50
|
+
};
|
|
4
51
|
|
|
5
52
|
declare function findPropertyInProperties(name: string, properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen?: Set<string>): (typeof properties)[number] | _;
|
|
6
53
|
|
|
@@ -60,45 +107,4 @@ declare function toStaticValue(lazyValue: LazyValue): {
|
|
|
60
107
|
readonly value: unknown;
|
|
61
108
|
};
|
|
62
109
|
|
|
63
|
-
type
|
|
64
|
-
kind: "ArrayExpression";
|
|
65
|
-
node: TSESTree.ArrayExpression;
|
|
66
|
-
} | {
|
|
67
|
-
kind: "CallExpression";
|
|
68
|
-
node: TSESTree.CallExpression;
|
|
69
|
-
} | {
|
|
70
|
-
kind: "ClassExpression";
|
|
71
|
-
node: TSESTree.ClassExpression;
|
|
72
|
-
} | {
|
|
73
|
-
kind: "FunctionDeclaration";
|
|
74
|
-
node: TSESTree.FunctionDeclaration;
|
|
75
|
-
} | {
|
|
76
|
-
kind: "FunctionExpression";
|
|
77
|
-
node: TSESTree.FunctionExpression | TSESTree.ArrowFunctionExpression;
|
|
78
|
-
} | {
|
|
79
|
-
kind: "JSXElement";
|
|
80
|
-
node: TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
81
|
-
} | {
|
|
82
|
-
kind: "NewExpression";
|
|
83
|
-
node: TSESTree.NewExpression;
|
|
84
|
-
} | {
|
|
85
|
-
kind: "ObjectExpression";
|
|
86
|
-
node: TSESTree.ObjectExpression;
|
|
87
|
-
} | {
|
|
88
|
-
kind: "RegExpLiteral";
|
|
89
|
-
node: TSESTree.RegExpLiteral;
|
|
90
|
-
};
|
|
91
|
-
declare const ValueConstructionHint: {
|
|
92
|
-
None: bigint;
|
|
93
|
-
StrictCallExpression: bigint;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Get a function that detects the construction of a given node.
|
|
97
|
-
* @param node The AST node to detect the construction of
|
|
98
|
-
* @param initialScope The initial scope to use when detecting the construction
|
|
99
|
-
* @param hint The hint to use when detecting the construction
|
|
100
|
-
* @returns A function that detects the construction of a given node
|
|
101
|
-
*/
|
|
102
|
-
declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
|
|
103
|
-
|
|
104
|
-
export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableInitNode, getVariables, isNodeValueEqual, toStaticValue };
|
|
110
|
+
export { type Construction, ConstructionDetectionHint, type LazyValue, findPropertyInProperties, findVariable, getChidScopes, getConstructionDetectionResult, getVariableDeclaratorId, getVariableInitNode, getVariables, isNodeValueEqual, toStaticValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
|
-
import { _ } from '@eslint-react/eff';
|
|
2
|
-
import { Scope, Variable } from '@typescript-eslint/scope-manager';
|
|
3
1
|
import { TSESTree } from '@typescript-eslint/types';
|
|
2
|
+
import { Scope, Variable } from '@typescript-eslint/scope-manager';
|
|
3
|
+
import { _ } from '@eslint-react/eff';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents the construction type of a expression like node.
|
|
7
|
+
*/
|
|
8
|
+
type Construction = {
|
|
9
|
+
kind: "ArrayExpression";
|
|
10
|
+
node: TSESTree.ArrayExpression;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "CallExpression";
|
|
13
|
+
node: TSESTree.CallExpression;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "ClassExpression";
|
|
16
|
+
node: TSESTree.ClassExpression;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "FunctionDeclaration";
|
|
19
|
+
node: TSESTree.FunctionDeclaration;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "FunctionExpression";
|
|
22
|
+
node: TSESTree.FunctionExpression | TSESTree.ArrowFunctionExpression;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "JSXElement";
|
|
25
|
+
node: TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "NewExpression";
|
|
28
|
+
node: TSESTree.NewExpression;
|
|
29
|
+
} | {
|
|
30
|
+
kind: "ObjectExpression";
|
|
31
|
+
node: TSESTree.ObjectExpression;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "RegExpLiteral";
|
|
34
|
+
node: TSESTree.RegExpLiteral;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Detects the construction type of a given node.
|
|
39
|
+
* @param node The node to check.
|
|
40
|
+
* @param initialScope The initial scope to check for variable declarations.
|
|
41
|
+
* @param hint Optional hint to control the detection behavior.
|
|
42
|
+
* @returns The construction type of the node, or `_` if not found.
|
|
43
|
+
*/
|
|
44
|
+
declare function getConstructionDetectionResult(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): Construction | _;
|
|
45
|
+
|
|
46
|
+
type ConstructionDetectionHint = bigint;
|
|
47
|
+
declare const ConstructionDetectionHint: {
|
|
48
|
+
None: bigint;
|
|
49
|
+
StrictCallExpression: bigint;
|
|
50
|
+
};
|
|
4
51
|
|
|
5
52
|
declare function findPropertyInProperties(name: string, properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen?: Set<string>): (typeof properties)[number] | _;
|
|
6
53
|
|
|
@@ -60,45 +107,4 @@ declare function toStaticValue(lazyValue: LazyValue): {
|
|
|
60
107
|
readonly value: unknown;
|
|
61
108
|
};
|
|
62
109
|
|
|
63
|
-
type
|
|
64
|
-
kind: "ArrayExpression";
|
|
65
|
-
node: TSESTree.ArrayExpression;
|
|
66
|
-
} | {
|
|
67
|
-
kind: "CallExpression";
|
|
68
|
-
node: TSESTree.CallExpression;
|
|
69
|
-
} | {
|
|
70
|
-
kind: "ClassExpression";
|
|
71
|
-
node: TSESTree.ClassExpression;
|
|
72
|
-
} | {
|
|
73
|
-
kind: "FunctionDeclaration";
|
|
74
|
-
node: TSESTree.FunctionDeclaration;
|
|
75
|
-
} | {
|
|
76
|
-
kind: "FunctionExpression";
|
|
77
|
-
node: TSESTree.FunctionExpression | TSESTree.ArrowFunctionExpression;
|
|
78
|
-
} | {
|
|
79
|
-
kind: "JSXElement";
|
|
80
|
-
node: TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
81
|
-
} | {
|
|
82
|
-
kind: "NewExpression";
|
|
83
|
-
node: TSESTree.NewExpression;
|
|
84
|
-
} | {
|
|
85
|
-
kind: "ObjectExpression";
|
|
86
|
-
node: TSESTree.ObjectExpression;
|
|
87
|
-
} | {
|
|
88
|
-
kind: "RegExpLiteral";
|
|
89
|
-
node: TSESTree.RegExpLiteral;
|
|
90
|
-
};
|
|
91
|
-
declare const ValueConstructionHint: {
|
|
92
|
-
None: bigint;
|
|
93
|
-
StrictCallExpression: bigint;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Get a function that detects the construction of a given node.
|
|
97
|
-
* @param node The AST node to detect the construction of
|
|
98
|
-
* @param initialScope The initial scope to use when detecting the construction
|
|
99
|
-
* @param hint The hint to use when detecting the construction
|
|
100
|
-
* @returns A function that detects the construction of a given node
|
|
101
|
-
*/
|
|
102
|
-
declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
|
|
103
|
-
|
|
104
|
-
export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableInitNode, getVariables, isNodeValueEqual, toStaticValue };
|
|
110
|
+
export { type Construction, ConstructionDetectionHint, type LazyValue, findPropertyInProperties, findVariable, getChidScopes, getConstructionDetectionResult, getVariableDeclaratorId, getVariableInitNode, getVariables, isNodeValueEqual, toStaticValue };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var types = require('@typescript-eslint/types');
|
|
4
3
|
var eff = require('@eslint-react/eff');
|
|
5
|
-
var
|
|
4
|
+
var types = require('@typescript-eslint/types');
|
|
6
5
|
var scopeManager = require('@typescript-eslint/scope-manager');
|
|
6
|
+
var ASTUtils = require('@typescript-eslint/utils/ast-utils');
|
|
7
7
|
var AST = require('@eslint-react/ast');
|
|
8
8
|
|
|
9
9
|
function _interopNamespace(e) {
|
|
@@ -27,11 +27,7 @@ function _interopNamespace(e) {
|
|
|
27
27
|
var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
|
|
28
28
|
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
29
29
|
|
|
30
|
-
// src/
|
|
31
|
-
var findVariable2 = eff.dual(2, (nameOrNode, initialScope) => {
|
|
32
|
-
if (nameOrNode == null) return eff._;
|
|
33
|
-
return ASTUtils__namespace.findVariable(initialScope, nameOrNode) ?? eff._;
|
|
34
|
-
});
|
|
30
|
+
// src/construction/construction-detection.ts
|
|
35
31
|
function getVariableInitNode(variable, at) {
|
|
36
32
|
if (variable == null) return eff._;
|
|
37
33
|
const def = variable.defs.at(at);
|
|
@@ -48,6 +44,82 @@ function getVariableInitNode(variable, at) {
|
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
46
|
|
|
47
|
+
// src/construction/construction-detection-hint.ts
|
|
48
|
+
var ConstructionDetectionHint = {
|
|
49
|
+
None: 0n,
|
|
50
|
+
StrictCallExpression: 1n << 0n
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/construction/construction-detection.ts
|
|
54
|
+
function getConstructionDetectionResult(node, initialScope, hint = ConstructionDetectionHint.None) {
|
|
55
|
+
if (node == null) return eff._;
|
|
56
|
+
switch (node.type) {
|
|
57
|
+
case types.AST_NODE_TYPES.JSXElement:
|
|
58
|
+
case types.AST_NODE_TYPES.JSXFragment:
|
|
59
|
+
return { kind: "JSXElement", node };
|
|
60
|
+
case types.AST_NODE_TYPES.ArrayExpression:
|
|
61
|
+
return { kind: "ArrayExpression", node };
|
|
62
|
+
case types.AST_NODE_TYPES.ObjectExpression:
|
|
63
|
+
return { kind: "ObjectExpression", node };
|
|
64
|
+
case types.AST_NODE_TYPES.ClassExpression:
|
|
65
|
+
return { kind: "ClassExpression", node };
|
|
66
|
+
case types.AST_NODE_TYPES.NewExpression:
|
|
67
|
+
return { kind: "NewExpression", node };
|
|
68
|
+
case types.AST_NODE_TYPES.FunctionExpression:
|
|
69
|
+
case types.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
70
|
+
return { kind: "FunctionExpression", node };
|
|
71
|
+
case types.AST_NODE_TYPES.CallExpression: {
|
|
72
|
+
if (hint & ConstructionDetectionHint.StrictCallExpression) {
|
|
73
|
+
return { kind: "CallExpression", node };
|
|
74
|
+
}
|
|
75
|
+
return eff._;
|
|
76
|
+
}
|
|
77
|
+
case types.AST_NODE_TYPES.MemberExpression: {
|
|
78
|
+
if (!("object" in node)) return eff._;
|
|
79
|
+
return getConstructionDetectionResult(node.object, initialScope, hint);
|
|
80
|
+
}
|
|
81
|
+
case types.AST_NODE_TYPES.AssignmentExpression:
|
|
82
|
+
case types.AST_NODE_TYPES.AssignmentPattern: {
|
|
83
|
+
if (!("right" in node)) return eff._;
|
|
84
|
+
return getConstructionDetectionResult(node.right, initialScope, hint);
|
|
85
|
+
}
|
|
86
|
+
case types.AST_NODE_TYPES.LogicalExpression: {
|
|
87
|
+
const lvc = getConstructionDetectionResult(node.left, initialScope, hint);
|
|
88
|
+
if (lvc == null) return eff._;
|
|
89
|
+
return getConstructionDetectionResult(node.right, initialScope, hint);
|
|
90
|
+
}
|
|
91
|
+
case types.AST_NODE_TYPES.ConditionalExpression: {
|
|
92
|
+
const cvc = getConstructionDetectionResult(node.consequent, initialScope, hint);
|
|
93
|
+
if (cvc == null) return eff._;
|
|
94
|
+
return getConstructionDetectionResult(node.alternate, initialScope, hint);
|
|
95
|
+
}
|
|
96
|
+
case types.AST_NODE_TYPES.Identifier: {
|
|
97
|
+
if (!("name" in node) || typeof node.name !== "string") {
|
|
98
|
+
return eff._;
|
|
99
|
+
}
|
|
100
|
+
const variable = initialScope.set.get(node.name);
|
|
101
|
+
const variableNode = getVariableInitNode(variable, -1);
|
|
102
|
+
return getConstructionDetectionResult(variableNode, initialScope, hint);
|
|
103
|
+
}
|
|
104
|
+
case types.AST_NODE_TYPES.Literal: {
|
|
105
|
+
if ("regex" in node) {
|
|
106
|
+
return { kind: "RegExpLiteral", node };
|
|
107
|
+
}
|
|
108
|
+
return eff._;
|
|
109
|
+
}
|
|
110
|
+
default: {
|
|
111
|
+
if (!("expression" in node) || typeof node.expression !== "object") {
|
|
112
|
+
return eff._;
|
|
113
|
+
}
|
|
114
|
+
return getConstructionDetectionResult(node.expression, initialScope, hint);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
var findVariable2 = eff.dual(2, (nameOrNode, initialScope) => {
|
|
119
|
+
if (nameOrNode == null) return eff._;
|
|
120
|
+
return ASTUtils__namespace.findVariable(initialScope, nameOrNode) ?? eff._;
|
|
121
|
+
});
|
|
122
|
+
|
|
51
123
|
// src/find-property-in-properties.ts
|
|
52
124
|
function findPropertyInProperties(name, properties, initialScope, seen = /* @__PURE__ */ new Set()) {
|
|
53
125
|
return properties.findLast((prop) => {
|
|
@@ -208,86 +280,12 @@ function getVariableInitNodeLoose(variable, at) {
|
|
|
208
280
|
if (def?.type === scopeManager.DefinitionType.Parameter && AST__namespace.isFunction(def.node)) return def.node;
|
|
209
281
|
return eff._;
|
|
210
282
|
}
|
|
211
|
-
var ValueConstructionHint = {
|
|
212
|
-
None: 0n,
|
|
213
|
-
StrictCallExpression: 1n << 0n
|
|
214
|
-
};
|
|
215
|
-
function getValueConstruction(node, initialScope, hint = ValueConstructionHint.None) {
|
|
216
|
-
if (node == null) return eff._;
|
|
217
|
-
switch (node.type) {
|
|
218
|
-
case types.AST_NODE_TYPES.JSXElement:
|
|
219
|
-
case types.AST_NODE_TYPES.JSXFragment: {
|
|
220
|
-
return { kind: "JSXElement", node };
|
|
221
|
-
}
|
|
222
|
-
case types.AST_NODE_TYPES.ArrayExpression: {
|
|
223
|
-
return { kind: "ArrayExpression", node };
|
|
224
|
-
}
|
|
225
|
-
case types.AST_NODE_TYPES.ObjectExpression: {
|
|
226
|
-
return { kind: "ObjectExpression", node };
|
|
227
|
-
}
|
|
228
|
-
case types.AST_NODE_TYPES.ClassExpression: {
|
|
229
|
-
return { kind: "ClassExpression", node };
|
|
230
|
-
}
|
|
231
|
-
case types.AST_NODE_TYPES.NewExpression: {
|
|
232
|
-
return { kind: "NewExpression", node };
|
|
233
|
-
}
|
|
234
|
-
case types.AST_NODE_TYPES.FunctionExpression:
|
|
235
|
-
case types.AST_NODE_TYPES.ArrowFunctionExpression: {
|
|
236
|
-
return { kind: "FunctionExpression", node };
|
|
237
|
-
}
|
|
238
|
-
case types.AST_NODE_TYPES.CallExpression: {
|
|
239
|
-
if (hint & ValueConstructionHint.StrictCallExpression) {
|
|
240
|
-
return { kind: "CallExpression", node };
|
|
241
|
-
}
|
|
242
|
-
return eff._;
|
|
243
|
-
}
|
|
244
|
-
case types.AST_NODE_TYPES.MemberExpression: {
|
|
245
|
-
if (!("object" in node)) return eff._;
|
|
246
|
-
return getValueConstruction(node.object, initialScope, hint);
|
|
247
|
-
}
|
|
248
|
-
case types.AST_NODE_TYPES.AssignmentExpression:
|
|
249
|
-
case types.AST_NODE_TYPES.AssignmentPattern: {
|
|
250
|
-
if (!("right" in node)) return eff._;
|
|
251
|
-
return getValueConstruction(node.right, initialScope, hint);
|
|
252
|
-
}
|
|
253
|
-
case types.AST_NODE_TYPES.LogicalExpression: {
|
|
254
|
-
const lvc = getValueConstruction(node.left, initialScope, hint);
|
|
255
|
-
if (lvc == null) return eff._;
|
|
256
|
-
return getValueConstruction(node.right, initialScope, hint);
|
|
257
|
-
}
|
|
258
|
-
case types.AST_NODE_TYPES.ConditionalExpression: {
|
|
259
|
-
const cvc = getValueConstruction(node.consequent, initialScope, hint);
|
|
260
|
-
if (cvc == null) return eff._;
|
|
261
|
-
return getValueConstruction(node.alternate, initialScope, hint);
|
|
262
|
-
}
|
|
263
|
-
case types.AST_NODE_TYPES.Identifier: {
|
|
264
|
-
if (!("name" in node) || typeof node.name !== "string") {
|
|
265
|
-
return eff._;
|
|
266
|
-
}
|
|
267
|
-
const variable = initialScope.set.get(node.name);
|
|
268
|
-
const variableNode = getVariableInitNode(variable, -1);
|
|
269
|
-
return getValueConstruction(variableNode, initialScope, hint);
|
|
270
|
-
}
|
|
271
|
-
case types.AST_NODE_TYPES.Literal: {
|
|
272
|
-
if ("regex" in node) {
|
|
273
|
-
return { kind: "RegExpLiteral", node };
|
|
274
|
-
}
|
|
275
|
-
return eff._;
|
|
276
|
-
}
|
|
277
|
-
default: {
|
|
278
|
-
if (!("expression" in node) || typeof node.expression !== "object") {
|
|
279
|
-
return eff._;
|
|
280
|
-
}
|
|
281
|
-
return getValueConstruction(node.expression, initialScope, hint);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
283
|
|
|
286
|
-
exports.
|
|
284
|
+
exports.ConstructionDetectionHint = ConstructionDetectionHint;
|
|
287
285
|
exports.findPropertyInProperties = findPropertyInProperties;
|
|
288
286
|
exports.findVariable = findVariable2;
|
|
289
287
|
exports.getChidScopes = getChidScopes;
|
|
290
|
-
exports.
|
|
288
|
+
exports.getConstructionDetectionResult = getConstructionDetectionResult;
|
|
291
289
|
exports.getVariableDeclaratorId = getVariableDeclaratorId;
|
|
292
290
|
exports.getVariableInitNode = getVariableInitNode;
|
|
293
291
|
exports.getVariables = getVariables;
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
1
|
import { dual, _ } from '@eslint-react/eff';
|
|
2
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
3
|
+
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
3
4
|
import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
|
|
4
5
|
import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
|
|
5
|
-
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
6
6
|
import * as AST from '@eslint-react/ast';
|
|
7
7
|
|
|
8
|
-
// src/
|
|
9
|
-
var findVariable2 = dual(2, (nameOrNode, initialScope) => {
|
|
10
|
-
if (nameOrNode == null) return _;
|
|
11
|
-
return ASTUtils.findVariable(initialScope, nameOrNode) ?? _;
|
|
12
|
-
});
|
|
8
|
+
// src/construction/construction-detection.ts
|
|
13
9
|
function getVariableInitNode(variable, at) {
|
|
14
10
|
if (variable == null) return _;
|
|
15
11
|
const def = variable.defs.at(at);
|
|
@@ -26,6 +22,82 @@ function getVariableInitNode(variable, at) {
|
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
|
|
25
|
+
// src/construction/construction-detection-hint.ts
|
|
26
|
+
var ConstructionDetectionHint = {
|
|
27
|
+
None: 0n,
|
|
28
|
+
StrictCallExpression: 1n << 0n
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/construction/construction-detection.ts
|
|
32
|
+
function getConstructionDetectionResult(node, initialScope, hint = ConstructionDetectionHint.None) {
|
|
33
|
+
if (node == null) return _;
|
|
34
|
+
switch (node.type) {
|
|
35
|
+
case AST_NODE_TYPES.JSXElement:
|
|
36
|
+
case AST_NODE_TYPES.JSXFragment:
|
|
37
|
+
return { kind: "JSXElement", node };
|
|
38
|
+
case AST_NODE_TYPES.ArrayExpression:
|
|
39
|
+
return { kind: "ArrayExpression", node };
|
|
40
|
+
case AST_NODE_TYPES.ObjectExpression:
|
|
41
|
+
return { kind: "ObjectExpression", node };
|
|
42
|
+
case AST_NODE_TYPES.ClassExpression:
|
|
43
|
+
return { kind: "ClassExpression", node };
|
|
44
|
+
case AST_NODE_TYPES.NewExpression:
|
|
45
|
+
return { kind: "NewExpression", node };
|
|
46
|
+
case AST_NODE_TYPES.FunctionExpression:
|
|
47
|
+
case AST_NODE_TYPES.ArrowFunctionExpression:
|
|
48
|
+
return { kind: "FunctionExpression", node };
|
|
49
|
+
case AST_NODE_TYPES.CallExpression: {
|
|
50
|
+
if (hint & ConstructionDetectionHint.StrictCallExpression) {
|
|
51
|
+
return { kind: "CallExpression", node };
|
|
52
|
+
}
|
|
53
|
+
return _;
|
|
54
|
+
}
|
|
55
|
+
case AST_NODE_TYPES.MemberExpression: {
|
|
56
|
+
if (!("object" in node)) return _;
|
|
57
|
+
return getConstructionDetectionResult(node.object, initialScope, hint);
|
|
58
|
+
}
|
|
59
|
+
case AST_NODE_TYPES.AssignmentExpression:
|
|
60
|
+
case AST_NODE_TYPES.AssignmentPattern: {
|
|
61
|
+
if (!("right" in node)) return _;
|
|
62
|
+
return getConstructionDetectionResult(node.right, initialScope, hint);
|
|
63
|
+
}
|
|
64
|
+
case AST_NODE_TYPES.LogicalExpression: {
|
|
65
|
+
const lvc = getConstructionDetectionResult(node.left, initialScope, hint);
|
|
66
|
+
if (lvc == null) return _;
|
|
67
|
+
return getConstructionDetectionResult(node.right, initialScope, hint);
|
|
68
|
+
}
|
|
69
|
+
case AST_NODE_TYPES.ConditionalExpression: {
|
|
70
|
+
const cvc = getConstructionDetectionResult(node.consequent, initialScope, hint);
|
|
71
|
+
if (cvc == null) return _;
|
|
72
|
+
return getConstructionDetectionResult(node.alternate, initialScope, hint);
|
|
73
|
+
}
|
|
74
|
+
case AST_NODE_TYPES.Identifier: {
|
|
75
|
+
if (!("name" in node) || typeof node.name !== "string") {
|
|
76
|
+
return _;
|
|
77
|
+
}
|
|
78
|
+
const variable = initialScope.set.get(node.name);
|
|
79
|
+
const variableNode = getVariableInitNode(variable, -1);
|
|
80
|
+
return getConstructionDetectionResult(variableNode, initialScope, hint);
|
|
81
|
+
}
|
|
82
|
+
case AST_NODE_TYPES.Literal: {
|
|
83
|
+
if ("regex" in node) {
|
|
84
|
+
return { kind: "RegExpLiteral", node };
|
|
85
|
+
}
|
|
86
|
+
return _;
|
|
87
|
+
}
|
|
88
|
+
default: {
|
|
89
|
+
if (!("expression" in node) || typeof node.expression !== "object") {
|
|
90
|
+
return _;
|
|
91
|
+
}
|
|
92
|
+
return getConstructionDetectionResult(node.expression, initialScope, hint);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
var findVariable2 = dual(2, (nameOrNode, initialScope) => {
|
|
97
|
+
if (nameOrNode == null) return _;
|
|
98
|
+
return ASTUtils.findVariable(initialScope, nameOrNode) ?? _;
|
|
99
|
+
});
|
|
100
|
+
|
|
29
101
|
// src/find-property-in-properties.ts
|
|
30
102
|
function findPropertyInProperties(name, properties, initialScope, seen = /* @__PURE__ */ new Set()) {
|
|
31
103
|
return properties.findLast((prop) => {
|
|
@@ -186,79 +258,5 @@ function getVariableInitNodeLoose(variable, at) {
|
|
|
186
258
|
if (def?.type === DefinitionType.Parameter && AST.isFunction(def.node)) return def.node;
|
|
187
259
|
return _;
|
|
188
260
|
}
|
|
189
|
-
var ValueConstructionHint = {
|
|
190
|
-
None: 0n,
|
|
191
|
-
StrictCallExpression: 1n << 0n
|
|
192
|
-
};
|
|
193
|
-
function getValueConstruction(node, initialScope, hint = ValueConstructionHint.None) {
|
|
194
|
-
if (node == null) return _;
|
|
195
|
-
switch (node.type) {
|
|
196
|
-
case AST_NODE_TYPES.JSXElement:
|
|
197
|
-
case AST_NODE_TYPES.JSXFragment: {
|
|
198
|
-
return { kind: "JSXElement", node };
|
|
199
|
-
}
|
|
200
|
-
case AST_NODE_TYPES.ArrayExpression: {
|
|
201
|
-
return { kind: "ArrayExpression", node };
|
|
202
|
-
}
|
|
203
|
-
case AST_NODE_TYPES.ObjectExpression: {
|
|
204
|
-
return { kind: "ObjectExpression", node };
|
|
205
|
-
}
|
|
206
|
-
case AST_NODE_TYPES.ClassExpression: {
|
|
207
|
-
return { kind: "ClassExpression", node };
|
|
208
|
-
}
|
|
209
|
-
case AST_NODE_TYPES.NewExpression: {
|
|
210
|
-
return { kind: "NewExpression", node };
|
|
211
|
-
}
|
|
212
|
-
case AST_NODE_TYPES.FunctionExpression:
|
|
213
|
-
case AST_NODE_TYPES.ArrowFunctionExpression: {
|
|
214
|
-
return { kind: "FunctionExpression", node };
|
|
215
|
-
}
|
|
216
|
-
case AST_NODE_TYPES.CallExpression: {
|
|
217
|
-
if (hint & ValueConstructionHint.StrictCallExpression) {
|
|
218
|
-
return { kind: "CallExpression", node };
|
|
219
|
-
}
|
|
220
|
-
return _;
|
|
221
|
-
}
|
|
222
|
-
case AST_NODE_TYPES.MemberExpression: {
|
|
223
|
-
if (!("object" in node)) return _;
|
|
224
|
-
return getValueConstruction(node.object, initialScope, hint);
|
|
225
|
-
}
|
|
226
|
-
case AST_NODE_TYPES.AssignmentExpression:
|
|
227
|
-
case AST_NODE_TYPES.AssignmentPattern: {
|
|
228
|
-
if (!("right" in node)) return _;
|
|
229
|
-
return getValueConstruction(node.right, initialScope, hint);
|
|
230
|
-
}
|
|
231
|
-
case AST_NODE_TYPES.LogicalExpression: {
|
|
232
|
-
const lvc = getValueConstruction(node.left, initialScope, hint);
|
|
233
|
-
if (lvc == null) return _;
|
|
234
|
-
return getValueConstruction(node.right, initialScope, hint);
|
|
235
|
-
}
|
|
236
|
-
case AST_NODE_TYPES.ConditionalExpression: {
|
|
237
|
-
const cvc = getValueConstruction(node.consequent, initialScope, hint);
|
|
238
|
-
if (cvc == null) return _;
|
|
239
|
-
return getValueConstruction(node.alternate, initialScope, hint);
|
|
240
|
-
}
|
|
241
|
-
case AST_NODE_TYPES.Identifier: {
|
|
242
|
-
if (!("name" in node) || typeof node.name !== "string") {
|
|
243
|
-
return _;
|
|
244
|
-
}
|
|
245
|
-
const variable = initialScope.set.get(node.name);
|
|
246
|
-
const variableNode = getVariableInitNode(variable, -1);
|
|
247
|
-
return getValueConstruction(variableNode, initialScope, hint);
|
|
248
|
-
}
|
|
249
|
-
case AST_NODE_TYPES.Literal: {
|
|
250
|
-
if ("regex" in node) {
|
|
251
|
-
return { kind: "RegExpLiteral", node };
|
|
252
|
-
}
|
|
253
|
-
return _;
|
|
254
|
-
}
|
|
255
|
-
default: {
|
|
256
|
-
if (!("expression" in node) || typeof node.expression !== "object") {
|
|
257
|
-
return _;
|
|
258
|
-
}
|
|
259
|
-
return getValueConstruction(node.expression, initialScope, hint);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
261
|
|
|
264
|
-
export {
|
|
262
|
+
export { ConstructionDetectionHint, findPropertyInProperties, findVariable2 as findVariable, getChidScopes, getConstructionDetectionResult, getVariableDeclaratorId, getVariableInitNode, getVariables, isNodeValueEqual, toStaticValue };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "1.40.
|
|
3
|
+
"version": "1.40.4-beta.4",
|
|
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": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@typescript-eslint/utils": "^8.29.0",
|
|
41
41
|
"string-ts": "^2.2.1",
|
|
42
42
|
"ts-pattern": "^5.7.0",
|
|
43
|
-
"@eslint-react/ast": "1.40.
|
|
44
|
-
"@eslint-react/eff": "1.40.
|
|
43
|
+
"@eslint-react/ast": "1.40.4-beta.4",
|
|
44
|
+
"@eslint-react/eff": "1.40.4-beta.4"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"tsup": "^8.4.0",
|