@eslint-react/var 1.30.0-next.0 → 1.30.1-beta.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.js +20 -14
- package/dist/index.mjs +19 -13
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
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 AST2 = require('@eslint-react/ast');
|
|
7
6
|
var scopeManager = require('@typescript-eslint/scope-manager');
|
|
7
|
+
var AST = require('@eslint-react/ast');
|
|
8
8
|
|
|
9
9
|
function _interopNamespace(e) {
|
|
10
10
|
if (e && e.__esModule) return e;
|
|
@@ -25,7 +25,7 @@ function _interopNamespace(e) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
|
|
28
|
-
var
|
|
28
|
+
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
29
29
|
|
|
30
30
|
// src/find-property-in-properties.ts
|
|
31
31
|
var findVariable2 = eff.dual(2, (nameOrNode, initialScope) => {
|
|
@@ -41,8 +41,6 @@ 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 && AST2__namespace.isFunction(def.node)):
|
|
45
|
-
return def.node;
|
|
46
44
|
case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
|
|
47
45
|
return def.node.init;
|
|
48
46
|
default:
|
|
@@ -150,8 +148,8 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
150
148
|
case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier): {
|
|
151
149
|
const aVar = findVariable2(a, aScope);
|
|
152
150
|
const bVar = findVariable2(b, bScope);
|
|
153
|
-
const aVarNode =
|
|
154
|
-
const bVarNode =
|
|
151
|
+
const aVarNode = getVariableNodeLoose(aVar, 0);
|
|
152
|
+
const bVarNode = getVariableNodeLoose(bVar, 0);
|
|
155
153
|
const aVarNodeParent = aVarNode?.parent;
|
|
156
154
|
const bVarNodeParent = bVarNode?.parent;
|
|
157
155
|
const aDef = aVar?.defs.at(0);
|
|
@@ -159,14 +157,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
159
157
|
const aDefParentParent = aDef?.parent?.parent;
|
|
160
158
|
const bDefParentParent = bDef?.parent?.parent;
|
|
161
159
|
switch (true) {
|
|
162
|
-
case (aVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression &&
|
|
163
|
-
if (!
|
|
160
|
+
case (aVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === types.AST_NODE_TYPES.CallExpression && AST__namespace.isFunction(aVarNode) && AST__namespace.isFunction(bVarNode)): {
|
|
161
|
+
if (!AST__namespace.isNodeEqual(aVarNodeParent.callee, bVarNodeParent.callee)) {
|
|
164
162
|
return false;
|
|
165
163
|
}
|
|
166
164
|
const aParams = aVarNode.params;
|
|
167
165
|
const bParams = bVarNode.params;
|
|
168
|
-
const aPos = aParams.findIndex((x) =>
|
|
169
|
-
const bPos = bParams.findIndex((x) =>
|
|
166
|
+
const aPos = aParams.findIndex((x) => AST__namespace.isNodeEqual(x, a));
|
|
167
|
+
const bPos = bParams.findIndex((x) => AST__namespace.isNodeEqual(x, b));
|
|
170
168
|
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
171
169
|
}
|
|
172
170
|
case (aDefParentParent?.type === types.AST_NODE_TYPES.ForOfStatement && bDefParentParent?.type === types.AST_NODE_TYPES.ForOfStatement): {
|
|
@@ -177,7 +175,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
177
175
|
}
|
|
178
176
|
const aRight = aDefParentParent.right;
|
|
179
177
|
const bRight = bDefParentParent.right;
|
|
180
|
-
return
|
|
178
|
+
return AST__namespace.isNodeEqual(aRight, bRight);
|
|
181
179
|
}
|
|
182
180
|
default: {
|
|
183
181
|
return aVar != null && bVar != null && aVar === bVar;
|
|
@@ -185,14 +183,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
185
183
|
}
|
|
186
184
|
}
|
|
187
185
|
case (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression): {
|
|
188
|
-
return
|
|
186
|
+
return AST__namespace.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
189
187
|
}
|
|
190
188
|
case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression): {
|
|
191
189
|
if (aScope.block === bScope.block) {
|
|
192
190
|
return true;
|
|
193
191
|
}
|
|
194
|
-
const aFunction =
|
|
195
|
-
const bFunction =
|
|
192
|
+
const aFunction = AST__namespace.findParentNode(a, AST__namespace.isOneOf(thisBlockTypes));
|
|
193
|
+
const bFunction = AST__namespace.findParentNode(b, AST__namespace.isOneOf(thisBlockTypes));
|
|
196
194
|
return aFunction === bFunction;
|
|
197
195
|
}
|
|
198
196
|
default: {
|
|
@@ -202,6 +200,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
202
200
|
}
|
|
203
201
|
}
|
|
204
202
|
}
|
|
203
|
+
function getVariableNodeLoose(variable, at) {
|
|
204
|
+
if (variable == null) return eff._;
|
|
205
|
+
const node = getVariableNode(variable, at);
|
|
206
|
+
if (node != null) return node;
|
|
207
|
+
const def = variable.defs.at(at);
|
|
208
|
+
if (def?.type === scopeManager.DefinitionType.Parameter && AST__namespace.isFunction(def.node)) return def.node;
|
|
209
|
+
return eff._;
|
|
210
|
+
}
|
|
205
211
|
var ValueConstructionHint = {
|
|
206
212
|
None: 0n,
|
|
207
213
|
StrictCallExpression: 1n << 0n
|
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,8 @@ 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 AST2 from '@eslint-react/ast';
|
|
6
5
|
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
6
|
+
import * as AST from '@eslint-react/ast';
|
|
7
7
|
|
|
8
8
|
// src/find-property-in-properties.ts
|
|
9
9
|
var findVariable2 = dual(2, (nameOrNode, initialScope) => {
|
|
@@ -19,8 +19,6 @@ 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 && AST2.isFunction(def.node)):
|
|
23
|
-
return def.node;
|
|
24
22
|
case ("init" in def.node && def.node.init != null && !("declarations" in def.node.init)):
|
|
25
23
|
return def.node.init;
|
|
26
24
|
default:
|
|
@@ -128,8 +126,8 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
128
126
|
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier): {
|
|
129
127
|
const aVar = findVariable2(a, aScope);
|
|
130
128
|
const bVar = findVariable2(b, bScope);
|
|
131
|
-
const aVarNode =
|
|
132
|
-
const bVarNode =
|
|
129
|
+
const aVarNode = getVariableNodeLoose(aVar, 0);
|
|
130
|
+
const bVarNode = getVariableNodeLoose(bVar, 0);
|
|
133
131
|
const aVarNodeParent = aVarNode?.parent;
|
|
134
132
|
const bVarNodeParent = bVarNode?.parent;
|
|
135
133
|
const aDef = aVar?.defs.at(0);
|
|
@@ -137,14 +135,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
137
135
|
const aDefParentParent = aDef?.parent?.parent;
|
|
138
136
|
const bDefParentParent = bDef?.parent?.parent;
|
|
139
137
|
switch (true) {
|
|
140
|
-
case (aVarNodeParent?.type === AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === AST_NODE_TYPES.CallExpression &&
|
|
141
|
-
if (!
|
|
138
|
+
case (aVarNodeParent?.type === AST_NODE_TYPES.CallExpression && bVarNodeParent?.type === AST_NODE_TYPES.CallExpression && AST.isFunction(aVarNode) && AST.isFunction(bVarNode)): {
|
|
139
|
+
if (!AST.isNodeEqual(aVarNodeParent.callee, bVarNodeParent.callee)) {
|
|
142
140
|
return false;
|
|
143
141
|
}
|
|
144
142
|
const aParams = aVarNode.params;
|
|
145
143
|
const bParams = bVarNode.params;
|
|
146
|
-
const aPos = aParams.findIndex((x) =>
|
|
147
|
-
const bPos = bParams.findIndex((x) =>
|
|
144
|
+
const aPos = aParams.findIndex((x) => AST.isNodeEqual(x, a));
|
|
145
|
+
const bPos = bParams.findIndex((x) => AST.isNodeEqual(x, b));
|
|
148
146
|
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
149
147
|
}
|
|
150
148
|
case (aDefParentParent?.type === AST_NODE_TYPES.ForOfStatement && bDefParentParent?.type === AST_NODE_TYPES.ForOfStatement): {
|
|
@@ -155,7 +153,7 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
155
153
|
}
|
|
156
154
|
const aRight = aDefParentParent.right;
|
|
157
155
|
const bRight = bDefParentParent.right;
|
|
158
|
-
return
|
|
156
|
+
return AST.isNodeEqual(aRight, bRight);
|
|
159
157
|
}
|
|
160
158
|
default: {
|
|
161
159
|
return aVar != null && bVar != null && aVar === bVar;
|
|
@@ -163,14 +161,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
163
161
|
}
|
|
164
162
|
}
|
|
165
163
|
case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression): {
|
|
166
|
-
return
|
|
164
|
+
return AST.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
167
165
|
}
|
|
168
166
|
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression): {
|
|
169
167
|
if (aScope.block === bScope.block) {
|
|
170
168
|
return true;
|
|
171
169
|
}
|
|
172
|
-
const aFunction =
|
|
173
|
-
const bFunction =
|
|
170
|
+
const aFunction = AST.findParentNode(a, AST.isOneOf(thisBlockTypes));
|
|
171
|
+
const bFunction = AST.findParentNode(b, AST.isOneOf(thisBlockTypes));
|
|
174
172
|
return aFunction === bFunction;
|
|
175
173
|
}
|
|
176
174
|
default: {
|
|
@@ -180,6 +178,14 @@ function isNodeValueEqual(a, b, initialScopes) {
|
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
180
|
}
|
|
181
|
+
function getVariableNodeLoose(variable, at) {
|
|
182
|
+
if (variable == null) return _;
|
|
183
|
+
const node = getVariableNode(variable, at);
|
|
184
|
+
if (node != null) return node;
|
|
185
|
+
const def = variable.defs.at(at);
|
|
186
|
+
if (def?.type === DefinitionType.Parameter && AST.isFunction(def.node)) return def.node;
|
|
187
|
+
return _;
|
|
188
|
+
}
|
|
183
189
|
var ValueConstructionHint = {
|
|
184
190
|
None: 0n,
|
|
185
191
|
StrictCallExpression: 1n << 0n
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.1-beta.0",
|
|
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.30.
|
|
44
|
-
"@eslint-react/eff": "1.30.
|
|
43
|
+
"@eslint-react/ast": "1.30.1-beta.0",
|
|
44
|
+
"@eslint-react/eff": "1.30.1-beta.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"tsup": "^8.4.0",
|