@eslint-react/var 1.17.4-next.0 → 1.17.4-next.10
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 +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +84 -63
- package/dist/index.mjs +83 -64
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -452,6 +452,8 @@ declare function getChidScopes(scope: Scope, prev?: readonly Scope[]): readonly
|
|
|
452
452
|
|
|
453
453
|
declare function getScope(node: TSESTree.Node, scopeManager: ScopeManager): _typescript_eslint_scope_manager.Scope | null;
|
|
454
454
|
|
|
455
|
+
declare function getStaticValue(node: TSESTree.Node, initialScope: Scope): O.Option<unknown>;
|
|
456
|
+
|
|
455
457
|
declare function getVariableDeclaratorID(node: TSESTree.Node, prev?: TSESTree.Node): O.Option<TSESTree.BindingName | TSESTree.Expression>;
|
|
456
458
|
|
|
457
459
|
/**
|
|
@@ -491,6 +493,9 @@ declare function isInitializedFromSource(name: string, source: string, initialSc
|
|
|
491
493
|
* @param initialScopes initial scopes of the two nodes
|
|
492
494
|
* @returns `true` if node value equal
|
|
493
495
|
*/
|
|
494
|
-
declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
|
|
496
|
+
declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
|
|
497
|
+
aScope: Scope,
|
|
498
|
+
bScope: Scope
|
|
499
|
+
]): boolean;
|
|
495
500
|
|
|
496
|
-
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
|
501
|
+
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getStaticValue, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
package/dist/index.d.ts
CHANGED
|
@@ -452,6 +452,8 @@ declare function getChidScopes(scope: Scope, prev?: readonly Scope[]): readonly
|
|
|
452
452
|
|
|
453
453
|
declare function getScope(node: TSESTree.Node, scopeManager: ScopeManager): _typescript_eslint_scope_manager.Scope | null;
|
|
454
454
|
|
|
455
|
+
declare function getStaticValue(node: TSESTree.Node, initialScope: Scope): O.Option<unknown>;
|
|
456
|
+
|
|
455
457
|
declare function getVariableDeclaratorID(node: TSESTree.Node, prev?: TSESTree.Node): O.Option<TSESTree.BindingName | TSESTree.Expression>;
|
|
456
458
|
|
|
457
459
|
/**
|
|
@@ -491,6 +493,9 @@ declare function isInitializedFromSource(name: string, source: string, initialSc
|
|
|
491
493
|
* @param initialScopes initial scopes of the two nodes
|
|
492
494
|
* @returns `true` if node value equal
|
|
493
495
|
*/
|
|
494
|
-
declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
|
|
496
|
+
declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [
|
|
497
|
+
aScope: Scope,
|
|
498
|
+
bScope: Scope
|
|
499
|
+
]): boolean;
|
|
495
500
|
|
|
496
|
-
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
|
501
|
+
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getStaticValue, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var tools = require('@eslint-react/tools');
|
|
|
5
5
|
var scopeManager = require('@typescript-eslint/scope-manager');
|
|
6
6
|
var types = require('@typescript-eslint/types');
|
|
7
7
|
var tsPattern = require('ts-pattern');
|
|
8
|
-
var
|
|
8
|
+
var ASTUtils = require('@typescript-eslint/utils/ast-utils');
|
|
9
9
|
|
|
10
10
|
function _interopNamespace(e) {
|
|
11
11
|
if (e && e.__esModule) return e;
|
|
@@ -26,6 +26,7 @@ function _interopNamespace(e) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
29
|
+
var ASTUtils__namespace = /*#__PURE__*/_interopNamespace(ASTUtils);
|
|
29
30
|
|
|
30
31
|
// src/construction.ts
|
|
31
32
|
var Construction = tools.Data.taggedEnum();
|
|
@@ -122,8 +123,8 @@ function inspectConstruction(node, initialScope, hint = ConstructionHint.None) {
|
|
|
122
123
|
};
|
|
123
124
|
return detect(node);
|
|
124
125
|
}
|
|
125
|
-
var
|
|
126
|
-
return tools.O.fromNullable(
|
|
126
|
+
var findVariable2 = tools.F.dual(2, (nameOrNode, initialScope) => {
|
|
127
|
+
return tools.O.fromNullable(ASTUtils__namespace.findVariable(initialScope, nameOrNode));
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
// src/get-child-scopes.ts
|
|
@@ -138,6 +139,12 @@ function getScope(node, scopeManager) {
|
|
|
138
139
|
if (parent) return getScope(parent, scopeManager);
|
|
139
140
|
return null;
|
|
140
141
|
}
|
|
142
|
+
function getStaticValue2(node, initialScope) {
|
|
143
|
+
return tools.F.pipe(
|
|
144
|
+
tools.O.fromNullable(ASTUtils__namespace.getStaticValue(node, initialScope)),
|
|
145
|
+
tools.O.map((v) => v.value)
|
|
146
|
+
);
|
|
147
|
+
}
|
|
141
148
|
function getVariableDeclaratorID(node, prev) {
|
|
142
149
|
switch (true) {
|
|
143
150
|
case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
@@ -187,7 +194,7 @@ function getVariables(initialScope) {
|
|
|
187
194
|
return variables.reverse();
|
|
188
195
|
}
|
|
189
196
|
function isInitializedFromSource(name, source, initialScope) {
|
|
190
|
-
const maybeLatestDef = tools.O.flatMapNullable(
|
|
197
|
+
const maybeLatestDef = tools.O.flatMapNullable(findVariable2(name, initialScope), (v) => v.defs.at(-1));
|
|
191
198
|
if (tools.O.isNone(maybeLatestDef)) return false;
|
|
192
199
|
const latestDef = maybeLatestDef.value;
|
|
193
200
|
const { node, parent } = latestDef;
|
|
@@ -227,75 +234,89 @@ var thisBlockTypes = [
|
|
|
227
234
|
types.AST_NODE_TYPES.Program
|
|
228
235
|
];
|
|
229
236
|
function isNodeValueEqual(a, b, initialScopes) {
|
|
230
|
-
if (a.type === types.AST_NODE_TYPES.Literal && b.type === types.AST_NODE_TYPES.Literal) return a.value === b.value;
|
|
231
|
-
if (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement) {
|
|
232
|
-
return a.value.cooked === b.value.cooked;
|
|
233
|
-
}
|
|
234
237
|
const [aScope, bScope] = initialScopes;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
tools.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
tools.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
238
|
+
switch (true) {
|
|
239
|
+
case (a.type === types.AST_NODE_TYPES.Literal && b.type === types.AST_NODE_TYPES.Literal): {
|
|
240
|
+
return a.value === b.value;
|
|
241
|
+
}
|
|
242
|
+
case (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement): {
|
|
243
|
+
return a.value.cooked === b.value.cooked;
|
|
244
|
+
}
|
|
245
|
+
case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier): {
|
|
246
|
+
const aVar = findVariable2(a, aScope);
|
|
247
|
+
const bVar = findVariable2(b, bScope);
|
|
248
|
+
const aVarNode = tools.O.flatMap(aVar, getVariableNode(0));
|
|
249
|
+
const bVarNode = tools.O.flatMap(bVar, getVariableNode(0));
|
|
250
|
+
const aVarNodeParent = tools.O.flatMapNullable(aVarNode, (n) => n.parent);
|
|
251
|
+
const bVarNodeParent = tools.O.flatMapNullable(bVarNode, (n) => n.parent);
|
|
252
|
+
const aDef = tools.O.flatMap(aVar, getVariableDef(0));
|
|
253
|
+
const bDef = tools.O.flatMap(bVar, getVariableDef(0));
|
|
254
|
+
const aDefParentParent = tools.O.flatMapNullable(aDef, (d) => d.parent?.parent);
|
|
255
|
+
const bDefParentParent = tools.O.flatMapNullable(bDef, (d) => d.parent?.parent);
|
|
256
|
+
switch (true) {
|
|
257
|
+
case (tools.O.exists(aVarNodeParent, AST__namespace.is(types.AST_NODE_TYPES.CallExpression)) && tools.O.exists(bVarNodeParent, AST__namespace.is(types.AST_NODE_TYPES.CallExpression)) && tools.O.exists(aVarNode, AST__namespace.isFunction) && tools.O.exists(bVarNode, AST__namespace.isFunction)): {
|
|
258
|
+
const hasSameCallee = tools.F.pipe(
|
|
259
|
+
tools.O.Do,
|
|
260
|
+
tools.O.bind("aCallee", () => tools.O.map(aVarNodeParent, (n) => n.callee)),
|
|
261
|
+
tools.O.bind("bCallee", () => tools.O.map(bVarNodeParent, (n) => n.callee)),
|
|
262
|
+
tools.O.exists(({ aCallee, bCallee }) => AST__namespace.isNodeEqual(aCallee, bCallee))
|
|
263
|
+
);
|
|
264
|
+
if (!hasSameCallee) return false;
|
|
265
|
+
return tools.F.pipe(
|
|
266
|
+
tools.O.Do,
|
|
267
|
+
tools.O.bind("aParams", () => tools.O.map(aVarNode, (n) => n.params)),
|
|
268
|
+
tools.O.bind("bParams", () => tools.O.map(bVarNode, (n) => n.params)),
|
|
269
|
+
tools.O.let("aPos", ({ aParams }) => aParams.findIndex(AST__namespace.isNodeEqual(a))),
|
|
270
|
+
tools.O.let("bPos", ({ bParams }) => bParams.findIndex(AST__namespace.isNodeEqual(b))),
|
|
271
|
+
tools.O.filter(({ aPos, bPos }) => aPos !== -1 && bPos !== -1),
|
|
272
|
+
tools.O.exists(({ aPos, bPos }) => aPos === bPos)
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
case (tools.O.exists(aDefParentParent, AST__namespace.is(types.AST_NODE_TYPES.ForOfStatement)) && tools.O.exists(bDefParentParent, AST__namespace.is(types.AST_NODE_TYPES.ForOfStatement))): {
|
|
276
|
+
return tools.F.pipe(
|
|
277
|
+
tools.O.Do,
|
|
278
|
+
tools.O.bind("aLeft", () => tools.O.map(aDefParentParent, (d) => d.left)),
|
|
279
|
+
tools.O.bind("bLeft", () => tools.O.map(bDefParentParent, (d) => d.left)),
|
|
280
|
+
tools.O.filter(({ aLeft, bLeft }) => aLeft.type === bLeft.type),
|
|
281
|
+
tools.O.bind("aRight", () => tools.O.map(aDefParentParent, (d) => d.right)),
|
|
282
|
+
tools.O.bind("bRight", () => tools.O.map(bDefParentParent, (d) => d.right)),
|
|
283
|
+
tools.O.exists(({ aRight, bRight }) => AST__namespace.isNodeEqual(aRight, bRight))
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
default: {
|
|
287
|
+
return tools.O.isSome(aVar) && tools.O.isSome(bVar) && tools.Equal.equals(aVar, bVar);
|
|
288
|
+
}
|
|
278
289
|
}
|
|
279
290
|
}
|
|
291
|
+
case (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression): {
|
|
292
|
+
return AST__namespace.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
293
|
+
}
|
|
294
|
+
case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression): {
|
|
295
|
+
if (aScope.block === bScope.block) return true;
|
|
296
|
+
return tools.F.pipe(
|
|
297
|
+
tools.O.Do,
|
|
298
|
+
tools.O.bind("aFunction", () => AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes))),
|
|
299
|
+
tools.O.bind("bFunction", () => AST__namespace.traverseUp(b, AST__namespace.isOneOf(thisBlockTypes))),
|
|
300
|
+
tools.O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
default: {
|
|
304
|
+
return tools.F.pipe(
|
|
305
|
+
tools.O.Do,
|
|
306
|
+
tools.O.bind("aStatic", () => getStaticValue2(a, aScope)),
|
|
307
|
+
tools.O.bind("bStatic", () => getStaticValue2(b, bScope)),
|
|
308
|
+
tools.O.exists(({ aStatic, bStatic }) => aStatic === bStatic)
|
|
309
|
+
);
|
|
310
|
+
}
|
|
280
311
|
}
|
|
281
|
-
if (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression) {
|
|
282
|
-
return AST__namespace.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
283
|
-
}
|
|
284
|
-
if (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression) {
|
|
285
|
-
if (aScope.block === bScope.block) return true;
|
|
286
|
-
const fa = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
|
|
287
|
-
const fb = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
|
|
288
|
-
if (tools.O.isSome(fa) && tools.O.isSome(fb)) return fa.value === fb.value;
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
return false;
|
|
292
312
|
}
|
|
293
313
|
|
|
294
314
|
exports.Construction = Construction;
|
|
295
315
|
exports.ConstructionHint = ConstructionHint;
|
|
296
|
-
exports.findVariable =
|
|
316
|
+
exports.findVariable = findVariable2;
|
|
297
317
|
exports.getChidScopes = getChidScopes;
|
|
298
318
|
exports.getScope = getScope;
|
|
319
|
+
exports.getStaticValue = getStaticValue2;
|
|
299
320
|
exports.getVariableDeclaratorID = getVariableDeclaratorID;
|
|
300
321
|
exports.getVariableDef = getVariableDef;
|
|
301
322
|
exports.getVariableNode = getVariableNode;
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import { Data, F, O, isString, isNullable, isObject } from '@eslint-react/tools';
|
|
2
|
+
import { Data, F, O, isString, Equal, isNullable, isObject } from '@eslint-react/tools';
|
|
3
3
|
import { DefinitionType, ScopeType } from '@typescript-eslint/scope-manager';
|
|
4
4
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import { match, isMatching } from 'ts-pattern';
|
|
6
|
-
import
|
|
6
|
+
import * as ASTUtils from '@typescript-eslint/utils/ast-utils';
|
|
7
7
|
|
|
8
8
|
// src/construction.ts
|
|
9
9
|
var Construction = Data.taggedEnum();
|
|
@@ -100,8 +100,8 @@ function inspectConstruction(node, initialScope, hint = ConstructionHint.None) {
|
|
|
100
100
|
};
|
|
101
101
|
return detect(node);
|
|
102
102
|
}
|
|
103
|
-
var
|
|
104
|
-
return O.fromNullable(findVariable
|
|
103
|
+
var findVariable2 = F.dual(2, (nameOrNode, initialScope) => {
|
|
104
|
+
return O.fromNullable(ASTUtils.findVariable(initialScope, nameOrNode));
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
// src/get-child-scopes.ts
|
|
@@ -116,6 +116,12 @@ function getScope(node, scopeManager) {
|
|
|
116
116
|
if (parent) return getScope(parent, scopeManager);
|
|
117
117
|
return null;
|
|
118
118
|
}
|
|
119
|
+
function getStaticValue2(node, initialScope) {
|
|
120
|
+
return F.pipe(
|
|
121
|
+
O.fromNullable(ASTUtils.getStaticValue(node, initialScope)),
|
|
122
|
+
O.map((v) => v.value)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
119
125
|
function getVariableDeclaratorID(node, prev) {
|
|
120
126
|
switch (true) {
|
|
121
127
|
case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
|
|
@@ -165,7 +171,7 @@ function getVariables(initialScope) {
|
|
|
165
171
|
return variables.reverse();
|
|
166
172
|
}
|
|
167
173
|
function isInitializedFromSource(name, source, initialScope) {
|
|
168
|
-
const maybeLatestDef = O.flatMapNullable(
|
|
174
|
+
const maybeLatestDef = O.flatMapNullable(findVariable2(name, initialScope), (v) => v.defs.at(-1));
|
|
169
175
|
if (O.isNone(maybeLatestDef)) return false;
|
|
170
176
|
const latestDef = maybeLatestDef.value;
|
|
171
177
|
const { node, parent } = latestDef;
|
|
@@ -205,68 +211,81 @@ var thisBlockTypes = [
|
|
|
205
211
|
AST_NODE_TYPES.Program
|
|
206
212
|
];
|
|
207
213
|
function isNodeValueEqual(a, b, initialScopes) {
|
|
208
|
-
if (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal) return a.value === b.value;
|
|
209
|
-
if (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement) {
|
|
210
|
-
return a.value.cooked === b.value.cooked;
|
|
211
|
-
}
|
|
212
214
|
const [aScope, bScope] = initialScopes;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
215
|
+
switch (true) {
|
|
216
|
+
case (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal): {
|
|
217
|
+
return a.value === b.value;
|
|
218
|
+
}
|
|
219
|
+
case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement): {
|
|
220
|
+
return a.value.cooked === b.value.cooked;
|
|
221
|
+
}
|
|
222
|
+
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier): {
|
|
223
|
+
const aVar = findVariable2(a, aScope);
|
|
224
|
+
const bVar = findVariable2(b, bScope);
|
|
225
|
+
const aVarNode = O.flatMap(aVar, getVariableNode(0));
|
|
226
|
+
const bVarNode = O.flatMap(bVar, getVariableNode(0));
|
|
227
|
+
const aVarNodeParent = O.flatMapNullable(aVarNode, (n) => n.parent);
|
|
228
|
+
const bVarNodeParent = O.flatMapNullable(bVarNode, (n) => n.parent);
|
|
229
|
+
const aDef = O.flatMap(aVar, getVariableDef(0));
|
|
230
|
+
const bDef = O.flatMap(bVar, getVariableDef(0));
|
|
231
|
+
const aDefParentParent = O.flatMapNullable(aDef, (d) => d.parent?.parent);
|
|
232
|
+
const bDefParentParent = O.flatMapNullable(bDef, (d) => d.parent?.parent);
|
|
233
|
+
switch (true) {
|
|
234
|
+
case (O.exists(aVarNodeParent, AST.is(AST_NODE_TYPES.CallExpression)) && O.exists(bVarNodeParent, AST.is(AST_NODE_TYPES.CallExpression)) && O.exists(aVarNode, AST.isFunction) && O.exists(bVarNode, AST.isFunction)): {
|
|
235
|
+
const hasSameCallee = F.pipe(
|
|
236
|
+
O.Do,
|
|
237
|
+
O.bind("aCallee", () => O.map(aVarNodeParent, (n) => n.callee)),
|
|
238
|
+
O.bind("bCallee", () => O.map(bVarNodeParent, (n) => n.callee)),
|
|
239
|
+
O.exists(({ aCallee, bCallee }) => AST.isNodeEqual(aCallee, bCallee))
|
|
240
|
+
);
|
|
241
|
+
if (!hasSameCallee) return false;
|
|
242
|
+
return F.pipe(
|
|
243
|
+
O.Do,
|
|
244
|
+
O.bind("aParams", () => O.map(aVarNode, (n) => n.params)),
|
|
245
|
+
O.bind("bParams", () => O.map(bVarNode, (n) => n.params)),
|
|
246
|
+
O.let("aPos", ({ aParams }) => aParams.findIndex(AST.isNodeEqual(a))),
|
|
247
|
+
O.let("bPos", ({ bParams }) => bParams.findIndex(AST.isNodeEqual(b))),
|
|
248
|
+
O.filter(({ aPos, bPos }) => aPos !== -1 && bPos !== -1),
|
|
249
|
+
O.exists(({ aPos, bPos }) => aPos === bPos)
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
case (O.exists(aDefParentParent, AST.is(AST_NODE_TYPES.ForOfStatement)) && O.exists(bDefParentParent, AST.is(AST_NODE_TYPES.ForOfStatement))): {
|
|
253
|
+
return F.pipe(
|
|
254
|
+
O.Do,
|
|
255
|
+
O.bind("aLeft", () => O.map(aDefParentParent, (d) => d.left)),
|
|
256
|
+
O.bind("bLeft", () => O.map(bDefParentParent, (d) => d.left)),
|
|
257
|
+
O.filter(({ aLeft, bLeft }) => aLeft.type === bLeft.type),
|
|
258
|
+
O.bind("aRight", () => O.map(aDefParentParent, (d) => d.right)),
|
|
259
|
+
O.bind("bRight", () => O.map(bDefParentParent, (d) => d.right)),
|
|
260
|
+
O.exists(({ aRight, bRight }) => AST.isNodeEqual(aRight, bRight))
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
default: {
|
|
264
|
+
return O.isSome(aVar) && O.isSome(bVar) && Equal.equals(aVar, bVar);
|
|
265
|
+
}
|
|
256
266
|
}
|
|
257
267
|
}
|
|
268
|
+
case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression): {
|
|
269
|
+
return AST.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
270
|
+
}
|
|
271
|
+
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression): {
|
|
272
|
+
if (aScope.block === bScope.block) return true;
|
|
273
|
+
return F.pipe(
|
|
274
|
+
O.Do,
|
|
275
|
+
O.bind("aFunction", () => AST.traverseUp(a, AST.isOneOf(thisBlockTypes))),
|
|
276
|
+
O.bind("bFunction", () => AST.traverseUp(b, AST.isOneOf(thisBlockTypes))),
|
|
277
|
+
O.exists(({ aFunction, bFunction }) => aFunction === bFunction)
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
default: {
|
|
281
|
+
return F.pipe(
|
|
282
|
+
O.Do,
|
|
283
|
+
O.bind("aStatic", () => getStaticValue2(a, aScope)),
|
|
284
|
+
O.bind("bStatic", () => getStaticValue2(b, bScope)),
|
|
285
|
+
O.exists(({ aStatic, bStatic }) => aStatic === bStatic)
|
|
286
|
+
);
|
|
287
|
+
}
|
|
258
288
|
}
|
|
259
|
-
if (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression) {
|
|
260
|
-
return AST.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
261
|
-
}
|
|
262
|
-
if (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression) {
|
|
263
|
-
if (aScope.block === bScope.block) return true;
|
|
264
|
-
const fa = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
|
|
265
|
-
const fb = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
|
|
266
|
-
if (O.isSome(fa) && O.isSome(fb)) return fa.value === fb.value;
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
return false;
|
|
270
289
|
}
|
|
271
290
|
|
|
272
|
-
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
|
291
|
+
export { Construction, ConstructionHint, findVariable2 as findVariable, getChidScopes, getScope, getStaticValue2 as getStaticValue, getVariableDeclaratorID, getVariableDef, getVariableNode, getVariables, inspectConstruction, isInitializedFromSource, isNodeValueEqual };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "1.17.4-next.
|
|
3
|
+
"version": "1.17.4-next.10",
|
|
4
4
|
"description": "TSESTree AST utility module for static analysis of variables",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@typescript-eslint/types": "^8.17.0",
|
|
40
40
|
"@typescript-eslint/utils": "^8.17.0",
|
|
41
41
|
"ts-pattern": "^5.5.0",
|
|
42
|
-
"@eslint-react/tools": "1.17.4-next.
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
42
|
+
"@eslint-react/tools": "1.17.4-next.10",
|
|
43
|
+
"@eslint-react/ast": "1.17.4-next.10",
|
|
44
|
+
"@eslint-react/types": "1.17.4-next.10"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"string-ts": "^2.2.0",
|