@eslint-react/var 1.28.0-next.1 → 1.28.0-next.3
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 +1 -10
- package/dist/index.d.ts +1 -10
- package/dist/index.js +12 -47
- package/dist/index.mjs +12 -46
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -24,15 +24,6 @@ declare function getVariableNode(variable: Variable | _, at: number): _ | TSESTr
|
|
|
24
24
|
*/
|
|
25
25
|
declare function getVariables(initialScope: Scope): Variable[];
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* Check if an identifier is initialized from the given source
|
|
29
|
-
* @param name The top-level identifier's name
|
|
30
|
-
* @param source The import source to check against
|
|
31
|
-
* @param initialScope Initial scope to search for the identifier
|
|
32
|
-
* @returns Whether the identifier is initialized from the given source
|
|
33
|
-
*/
|
|
34
|
-
declare function isInitializedFromSource(name: string, source: string, initialScope: Scope): boolean;
|
|
35
|
-
|
|
36
27
|
/**
|
|
37
28
|
* Determines whether node value equals to another node value
|
|
38
29
|
* @param a node to compare
|
|
@@ -117,4 +108,4 @@ declare const ValueConstructionHint: {
|
|
|
117
108
|
*/
|
|
118
109
|
declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
|
|
119
110
|
|
|
120
|
-
export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableId, getVariableNode, getVariables,
|
|
111
|
+
export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableId, getVariableNode, getVariables, isNodeValueEqual, isVariableIdEqual, toStaticValue };
|
package/dist/index.d.ts
CHANGED
|
@@ -24,15 +24,6 @@ declare function getVariableNode(variable: Variable | _, at: number): _ | TSESTr
|
|
|
24
24
|
*/
|
|
25
25
|
declare function getVariables(initialScope: Scope): Variable[];
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* Check if an identifier is initialized from the given source
|
|
29
|
-
* @param name The top-level identifier's name
|
|
30
|
-
* @param source The import source to check against
|
|
31
|
-
* @param initialScope Initial scope to search for the identifier
|
|
32
|
-
* @returns Whether the identifier is initialized from the given source
|
|
33
|
-
*/
|
|
34
|
-
declare function isInitializedFromSource(name: string, source: string, initialScope: Scope): boolean;
|
|
35
|
-
|
|
36
27
|
/**
|
|
37
28
|
* Determines whether node value equals to another node value
|
|
38
29
|
* @param a node to compare
|
|
@@ -117,4 +108,4 @@ declare const ValueConstructionHint: {
|
|
|
117
108
|
*/
|
|
118
109
|
declare function getValueConstruction(node: TSESTree.Node | _, initialScope: Scope, hint?: bigint): ValueConstruction | _;
|
|
119
110
|
|
|
120
|
-
export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableId, getVariableNode, getVariables,
|
|
111
|
+
export { type LazyValue, type ValueConstruction, ValueConstructionHint, findPropertyInProperties, findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableId, getVariableNode, getVariables, isNodeValueEqual, isVariableIdEqual, toStaticValue };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var types = require('@typescript-eslint/types');
|
|
4
4
|
var eff = require('@eslint-react/eff');
|
|
5
5
|
var ASTUtils = require('@typescript-eslint/utils/ast-utils');
|
|
6
|
-
var
|
|
6
|
+
var AST2 = require('@eslint-react/ast');
|
|
7
7
|
var scopeManager = require('@typescript-eslint/scope-manager');
|
|
8
8
|
|
|
9
9
|
function _interopNamespace(e) {
|
|
@@ -25,7 +25,7 @@ function _interopNamespace(e) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
|
|
28
|
-
var
|
|
28
|
+
var AST2__namespace = /*#__PURE__*/_interopNamespace(AST2);
|
|
29
29
|
|
|
30
30
|
// src/find-property-in-properties.ts
|
|
31
31
|
var findVariable2 = eff.dual(2, (nameOrNode, initialScope) => {
|
|
@@ -41,7 +41,7 @@ function getVariableNode(variable, at) {
|
|
|
41
41
|
return def.node;
|
|
42
42
|
case (def.type === scopeManager.DefinitionType.ClassName && def.node.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
43
43
|
return def.node;
|
|
44
|
-
case (def.type === scopeManager.DefinitionType.Parameter &&
|
|
44
|
+
case (def.type === scopeManager.DefinitionType.Parameter && AST2__namespace.isFunction(def.node)):
|
|
45
45
|
return def.node;
|
|
46
46
|
case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
|
|
47
47
|
return def.node.init;
|
|
@@ -133,40 +133,6 @@ function getVariables(initialScope) {
|
|
|
133
133
|
}
|
|
134
134
|
return variables.reverse();
|
|
135
135
|
}
|
|
136
|
-
function isInitializedFromSource(name, source, initialScope) {
|
|
137
|
-
const latestDef = findVariable2(name, initialScope)?.defs.at(-1);
|
|
138
|
-
if (latestDef == null) return false;
|
|
139
|
-
const { node, parent } = latestDef;
|
|
140
|
-
if (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
141
|
-
const { init } = node;
|
|
142
|
-
if (init.type === types.AST_NODE_TYPES.MemberExpression && init.object.type === types.AST_NODE_TYPES.Identifier) {
|
|
143
|
-
return isInitializedFromSource(init.object.name, source, initialScope);
|
|
144
|
-
}
|
|
145
|
-
if (init.type === types.AST_NODE_TYPES.Identifier) {
|
|
146
|
-
return isInitializedFromSource(init.name, source, initialScope);
|
|
147
|
-
}
|
|
148
|
-
const args = getRequireExpressionArguments(init);
|
|
149
|
-
const arg0 = args?.[0];
|
|
150
|
-
if (arg0 == null || !AST3__namespace.isStringLiteral(arg0)) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
return arg0.value === source || arg0.value.startsWith(`${source}/`);
|
|
154
|
-
}
|
|
155
|
-
return parent?.type === types.AST_NODE_TYPES.ImportDeclaration && parent.source.value === source;
|
|
156
|
-
}
|
|
157
|
-
function getRequireExpressionArguments(node) {
|
|
158
|
-
switch (true) {
|
|
159
|
-
// require('source')
|
|
160
|
-
case (node.type === types.AST_NODE_TYPES.CallExpression && node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === "require"): {
|
|
161
|
-
return node.arguments;
|
|
162
|
-
}
|
|
163
|
-
// require('source').variable
|
|
164
|
-
case node.type === types.AST_NODE_TYPES.MemberExpression: {
|
|
165
|
-
return getRequireExpressionArguments(node.object);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return eff._;
|
|
169
|
-
}
|
|
170
136
|
function toStaticValue(lazyValue) {
|
|
171
137
|
const { kind, node, initialScope } = lazyValue;
|
|
172
138
|
if (kind !== "lazy") {
|
|
@@ -207,14 +173,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
207
173
|
const aDefParentParent = aDef?.parent?.parent;
|
|
208
174
|
const bDefParentParent = bDef?.parent?.parent;
|
|
209
175
|
switch (true) {
|
|
210
|
-
case (aVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression &&
|
|
211
|
-
if (!
|
|
176
|
+
case (aVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression && AST2__namespace.isFunction(aVarNode) && AST2__namespace.isFunction(bVarNode)): {
|
|
177
|
+
if (!AST2__namespace.isNodeEqual(aVarNodeParent.callee, bVarNodeParent.callee)) {
|
|
212
178
|
return false;
|
|
213
179
|
}
|
|
214
180
|
const aParams = aVarNode.params;
|
|
215
181
|
const bParams = bVarNode.params;
|
|
216
|
-
const aPos = aParams.findIndex((x) =>
|
|
217
|
-
const bPos = bParams.findIndex((x) =>
|
|
182
|
+
const aPos = aParams.findIndex((x) => AST2__namespace.isNodeEqual(x, a));
|
|
183
|
+
const bPos = bParams.findIndex((x) => AST2__namespace.isNodeEqual(x, b));
|
|
218
184
|
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
219
185
|
}
|
|
220
186
|
case (aDefParentParent?.type === types.AST_NODE_TYPES.ForOfStatement && bDefParentParent?.type === types.AST_NODE_TYPES.ForOfStatement): {
|
|
@@ -225,7 +191,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
225
191
|
}
|
|
226
192
|
const aRight = aDefParentParent.right;
|
|
227
193
|
const bRight = bDefParentParent.right;
|
|
228
|
-
return
|
|
194
|
+
return AST2__namespace.isNodeEqual(aRight, bRight);
|
|
229
195
|
}
|
|
230
196
|
default: {
|
|
231
197
|
return aVar != null && bVar != null && aVar === bVar;
|
|
@@ -233,14 +199,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
233
199
|
}
|
|
234
200
|
}
|
|
235
201
|
case (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression): {
|
|
236
|
-
return
|
|
202
|
+
return AST2__namespace.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
237
203
|
}
|
|
238
204
|
case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression): {
|
|
239
205
|
if (aScope.block === bScope.block) {
|
|
240
206
|
return true;
|
|
241
207
|
}
|
|
242
|
-
const aFunction =
|
|
243
|
-
const bFunction =
|
|
208
|
+
const aFunction = AST2__namespace.findParentNode(a, AST2__namespace.isOneOf(thisBlockTypes));
|
|
209
|
+
const bFunction = AST2__namespace.findParentNode(b, AST2__namespace.isOneOf(thisBlockTypes));
|
|
244
210
|
return aFunction === bFunction;
|
|
245
211
|
}
|
|
246
212
|
default: {
|
|
@@ -251,7 +217,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
251
217
|
}
|
|
252
218
|
}
|
|
253
219
|
function isVariableIdEqual(a, b, initialScopes) {
|
|
254
|
-
return
|
|
220
|
+
return AST2__namespace.isNodeEqual(a, b) || isNodeValueEqual(a, b, initialScopes);
|
|
255
221
|
}
|
|
256
222
|
var ValueConstructionHint = {
|
|
257
223
|
None: 0n,
|
|
@@ -337,7 +303,6 @@ exports.getVariableDeclaratorId = getVariableDeclaratorId;
|
|
|
337
303
|
exports.getVariableId = getVariableId;
|
|
338
304
|
exports.getVariableNode = getVariableNode;
|
|
339
305
|
exports.getVariables = getVariables;
|
|
340
|
-
exports.isInitializedFromSource = isInitializedFromSource;
|
|
341
306
|
exports.isNodeValueEqual = isNodeValueEqual;
|
|
342
307
|
exports.isVariableIdEqual = isVariableIdEqual;
|
|
343
308
|
exports.toStaticValue = toStaticValue;
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
|
2
2
|
import { dual, _ } from '@eslint-react/eff';
|
|
3
3
|
import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
|
|
4
4
|
import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
|
|
5
|
-
import * as
|
|
5
|
+
import * as AST2 from '@eslint-react/ast';
|
|
6
6
|
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
7
7
|
|
|
8
8
|
// src/find-property-in-properties.ts
|
|
@@ -19,7 +19,7 @@ function getVariableNode(variable, at) {
|
|
|
19
19
|
return def.node;
|
|
20
20
|
case (def.type === DefinitionType.ClassName && def.node.type === AST_NODE_TYPES.ClassDeclaration):
|
|
21
21
|
return def.node;
|
|
22
|
-
case (def.type === DefinitionType.Parameter &&
|
|
22
|
+
case (def.type === DefinitionType.Parameter && AST2.isFunction(def.node)):
|
|
23
23
|
return def.node;
|
|
24
24
|
case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
|
|
25
25
|
return def.node.init;
|
|
@@ -111,40 +111,6 @@ function getVariables(initialScope) {
|
|
|
111
111
|
}
|
|
112
112
|
return variables.reverse();
|
|
113
113
|
}
|
|
114
|
-
function isInitializedFromSource(name, source, initialScope) {
|
|
115
|
-
const latestDef = findVariable2(name, initialScope)?.defs.at(-1);
|
|
116
|
-
if (latestDef == null) return false;
|
|
117
|
-
const { node, parent } = latestDef;
|
|
118
|
-
if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
|
|
119
|
-
const { init } = node;
|
|
120
|
-
if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) {
|
|
121
|
-
return isInitializedFromSource(init.object.name, source, initialScope);
|
|
122
|
-
}
|
|
123
|
-
if (init.type === AST_NODE_TYPES.Identifier) {
|
|
124
|
-
return isInitializedFromSource(init.name, source, initialScope);
|
|
125
|
-
}
|
|
126
|
-
const args = getRequireExpressionArguments(init);
|
|
127
|
-
const arg0 = args?.[0];
|
|
128
|
-
if (arg0 == null || !AST3.isStringLiteral(arg0)) {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
return arg0.value === source || arg0.value.startsWith(`${source}/`);
|
|
132
|
-
}
|
|
133
|
-
return parent?.type === AST_NODE_TYPES.ImportDeclaration && parent.source.value === source;
|
|
134
|
-
}
|
|
135
|
-
function getRequireExpressionArguments(node) {
|
|
136
|
-
switch (true) {
|
|
137
|
-
// require('source')
|
|
138
|
-
case (node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "require"): {
|
|
139
|
-
return node.arguments;
|
|
140
|
-
}
|
|
141
|
-
// require('source').variable
|
|
142
|
-
case node.type === AST_NODE_TYPES.MemberExpression: {
|
|
143
|
-
return getRequireExpressionArguments(node.object);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return _;
|
|
147
|
-
}
|
|
148
114
|
function toStaticValue(lazyValue) {
|
|
149
115
|
const { kind, node, initialScope } = lazyValue;
|
|
150
116
|
if (kind !== "lazy") {
|
|
@@ -185,14 +151,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
185
151
|
const aDefParentParent = aDef?.parent?.parent;
|
|
186
152
|
const bDefParentParent = bDef?.parent?.parent;
|
|
187
153
|
switch (true) {
|
|
188
|
-
case (aVarNodeParent?.type === AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === AST_NODE_TYPES.CallExpression &&
|
|
189
|
-
if (!
|
|
154
|
+
case (aVarNodeParent?.type === AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === AST_NODE_TYPES.CallExpression && AST2.isFunction(aVarNode) && AST2.isFunction(bVarNode)): {
|
|
155
|
+
if (!AST2.isNodeEqual(aVarNodeParent.callee, bVarNodeParent.callee)) {
|
|
190
156
|
return false;
|
|
191
157
|
}
|
|
192
158
|
const aParams = aVarNode.params;
|
|
193
159
|
const bParams = bVarNode.params;
|
|
194
|
-
const aPos = aParams.findIndex((x) =>
|
|
195
|
-
const bPos = bParams.findIndex((x) =>
|
|
160
|
+
const aPos = aParams.findIndex((x) => AST2.isNodeEqual(x, a));
|
|
161
|
+
const bPos = bParams.findIndex((x) => AST2.isNodeEqual(x, b));
|
|
196
162
|
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
197
163
|
}
|
|
198
164
|
case (aDefParentParent?.type === AST_NODE_TYPES.ForOfStatement && bDefParentParent?.type === AST_NODE_TYPES.ForOfStatement): {
|
|
@@ -203,7 +169,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
203
169
|
}
|
|
204
170
|
const aRight = aDefParentParent.right;
|
|
205
171
|
const bRight = bDefParentParent.right;
|
|
206
|
-
return
|
|
172
|
+
return AST2.isNodeEqual(aRight, bRight);
|
|
207
173
|
}
|
|
208
174
|
default: {
|
|
209
175
|
return aVar != null && bVar != null && aVar === bVar;
|
|
@@ -211,14 +177,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
211
177
|
}
|
|
212
178
|
}
|
|
213
179
|
case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression): {
|
|
214
|
-
return
|
|
180
|
+
return AST2.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
215
181
|
}
|
|
216
182
|
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression): {
|
|
217
183
|
if (aScope.block === bScope.block) {
|
|
218
184
|
return true;
|
|
219
185
|
}
|
|
220
|
-
const aFunction =
|
|
221
|
-
const bFunction =
|
|
186
|
+
const aFunction = AST2.findParentNode(a, AST2.isOneOf(thisBlockTypes));
|
|
187
|
+
const bFunction = AST2.findParentNode(b, AST2.isOneOf(thisBlockTypes));
|
|
222
188
|
return aFunction === bFunction;
|
|
223
189
|
}
|
|
224
190
|
default: {
|
|
@@ -229,7 +195,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
229
195
|
}
|
|
230
196
|
}
|
|
231
197
|
function isVariableIdEqual(a, b, initialScopes) {
|
|
232
|
-
return
|
|
198
|
+
return AST2.isNodeEqual(a, b) || isNodeValueEqual(a, b, initialScopes);
|
|
233
199
|
}
|
|
234
200
|
var ValueConstructionHint = {
|
|
235
201
|
None: 0n,
|
|
@@ -306,4 +272,4 @@ function getValueConstruction(node, initialScope, hint = ValueConstructionHint.N
|
|
|
306
272
|
}
|
|
307
273
|
}
|
|
308
274
|
|
|
309
|
-
export { ValueConstructionHint, findPropertyInProperties, findVariable2 as findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableId, getVariableNode, getVariables,
|
|
275
|
+
export { ValueConstructionHint, findPropertyInProperties, findVariable2 as findVariable, getChidScopes, getValueConstruction, getVariableDeclaratorId, getVariableId, getVariableNode, getVariables, isNodeValueEqual, isVariableIdEqual, toStaticValue };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "1.28.0-next.
|
|
3
|
+
"version": "1.28.0-next.3",
|
|
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.25.0",
|
|
41
41
|
"string-ts": "^2.2.1",
|
|
42
42
|
"ts-pattern": "^5.6.2",
|
|
43
|
-
"@eslint-react/ast": "1.28.0-next.
|
|
44
|
-
"@eslint-react/eff": "1.28.0-next.
|
|
43
|
+
"@eslint-react/ast": "1.28.0-next.3",
|
|
44
|
+
"@eslint-react/eff": "1.28.0-next.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"tsup": "^8.3.6",
|