@eslint-react/var 1.17.4-beta.0 → 1.17.4-beta.2
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 +65 -58
- package/dist/index.mjs +65 -58
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -227,68 +227,75 @@ var thisBlockTypes = [
|
|
|
227
227
|
types.AST_NODE_TYPES.Program
|
|
228
228
|
];
|
|
229
229
|
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
230
|
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
|
-
|
|
231
|
+
switch (true) {
|
|
232
|
+
case (a.type === types.AST_NODE_TYPES.Literal && b.type === types.AST_NODE_TYPES.Literal): {
|
|
233
|
+
return a.value === b.value;
|
|
234
|
+
}
|
|
235
|
+
case (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement): {
|
|
236
|
+
return a.value.cooked === b.value.cooked;
|
|
237
|
+
}
|
|
238
|
+
case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier): {
|
|
239
|
+
const aVar = findVariable(a, aScope);
|
|
240
|
+
const bVar = findVariable(b, bScope);
|
|
241
|
+
const aVarNode = tools.O.flatMap(aVar, getVariableNode(0));
|
|
242
|
+
const bVarNode = tools.O.flatMap(bVar, getVariableNode(0));
|
|
243
|
+
const aVarNodeParent = tools.O.flatMapNullable(aVarNode, (n) => n.parent);
|
|
244
|
+
const bVarNodeParent = tools.O.flatMapNullable(bVarNode, (n) => n.parent);
|
|
245
|
+
const aDef = tools.O.flatMap(aVar, getVariableDef(0));
|
|
246
|
+
const bDef = tools.O.flatMap(bVar, getVariableDef(0));
|
|
247
|
+
const aDefParentParent = tools.O.flatMapNullable(aDef, (d) => d.parent?.parent);
|
|
248
|
+
const bDefParentParent = tools.O.flatMapNullable(bDef, (d) => d.parent?.parent);
|
|
249
|
+
switch (true) {
|
|
250
|
+
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)): {
|
|
251
|
+
const hasSameCallee = tools.F.pipe(
|
|
252
|
+
tools.O.Do,
|
|
253
|
+
tools.O.bind("aCallee", () => tools.O.map(aVarNodeParent, (n) => n.callee)),
|
|
254
|
+
tools.O.bind("bCallee", () => tools.O.map(bVarNodeParent, (n) => n.callee)),
|
|
255
|
+
tools.O.exists(({ aCallee, bCallee }) => AST__namespace.isNodeEqual(aCallee, bCallee))
|
|
256
|
+
);
|
|
257
|
+
if (!hasSameCallee) return false;
|
|
258
|
+
return tools.F.pipe(
|
|
259
|
+
tools.O.Do,
|
|
260
|
+
tools.O.bind("aParams", () => tools.O.map(aVarNode, (n) => n.params)),
|
|
261
|
+
tools.O.bind("bParams", () => tools.O.map(bVarNode, (n) => n.params)),
|
|
262
|
+
tools.O.let("aPos", ({ aParams }) => aParams.findIndex(AST__namespace.isNodeEqual(a))),
|
|
263
|
+
tools.O.let("bPos", ({ bParams }) => bParams.findIndex(AST__namespace.isNodeEqual(b))),
|
|
264
|
+
tools.O.filter(({ aPos, bPos }) => aPos !== -1 && bPos !== -1),
|
|
265
|
+
tools.O.exists(({ aPos, bPos }) => aPos === bPos)
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
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))): {
|
|
269
|
+
return tools.F.pipe(
|
|
270
|
+
tools.O.Do,
|
|
271
|
+
tools.O.bind("aLeft", () => tools.O.map(aDefParentParent, (d) => d.left)),
|
|
272
|
+
tools.O.bind("bLeft", () => tools.O.map(bDefParentParent, (d) => d.left)),
|
|
273
|
+
tools.O.filter(({ aLeft, bLeft }) => aLeft.type === bLeft.type),
|
|
274
|
+
tools.O.bind("aRight", () => tools.O.map(aDefParentParent, (d) => d.right)),
|
|
275
|
+
tools.O.bind("bRight", () => tools.O.map(bDefParentParent, (d) => d.right)),
|
|
276
|
+
tools.O.exists(({ aRight, bRight }) => AST__namespace.isNodeEqual(aRight, bRight))
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
default: {
|
|
280
|
+
return tools.O.isSome(aVar) && tools.O.isSome(bVar) && aVar.value === bVar.value;
|
|
281
|
+
}
|
|
278
282
|
}
|
|
279
283
|
}
|
|
284
|
+
case (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression): {
|
|
285
|
+
return AST__namespace.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
286
|
+
}
|
|
287
|
+
case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression): {
|
|
288
|
+
if (aScope.block === bScope.block) return true;
|
|
289
|
+
const fa = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
|
|
290
|
+
const fb = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
|
|
291
|
+
return tools.O.isSome(fa) && tools.O.isSome(fb) && fa.value === fb.value;
|
|
292
|
+
}
|
|
293
|
+
default: {
|
|
294
|
+
const aStatic = astUtils.getStaticValue(a, aScope);
|
|
295
|
+
const bStatic = astUtils.getStaticValue(b, bScope);
|
|
296
|
+
return !!aStatic && !!bStatic && aStatic.value === bStatic.value;
|
|
297
|
+
}
|
|
280
298
|
}
|
|
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
299
|
}
|
|
293
300
|
|
|
294
301
|
exports.Construction = Construction;
|
package/dist/index.mjs
CHANGED
|
@@ -205,68 +205,75 @@ var thisBlockTypes = [
|
|
|
205
205
|
AST_NODE_TYPES.Program
|
|
206
206
|
];
|
|
207
207
|
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
208
|
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
|
-
|
|
209
|
+
switch (true) {
|
|
210
|
+
case (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal): {
|
|
211
|
+
return a.value === b.value;
|
|
212
|
+
}
|
|
213
|
+
case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement): {
|
|
214
|
+
return a.value.cooked === b.value.cooked;
|
|
215
|
+
}
|
|
216
|
+
case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier): {
|
|
217
|
+
const aVar = findVariable(a, aScope);
|
|
218
|
+
const bVar = findVariable(b, bScope);
|
|
219
|
+
const aVarNode = O.flatMap(aVar, getVariableNode(0));
|
|
220
|
+
const bVarNode = O.flatMap(bVar, getVariableNode(0));
|
|
221
|
+
const aVarNodeParent = O.flatMapNullable(aVarNode, (n) => n.parent);
|
|
222
|
+
const bVarNodeParent = O.flatMapNullable(bVarNode, (n) => n.parent);
|
|
223
|
+
const aDef = O.flatMap(aVar, getVariableDef(0));
|
|
224
|
+
const bDef = O.flatMap(bVar, getVariableDef(0));
|
|
225
|
+
const aDefParentParent = O.flatMapNullable(aDef, (d) => d.parent?.parent);
|
|
226
|
+
const bDefParentParent = O.flatMapNullable(bDef, (d) => d.parent?.parent);
|
|
227
|
+
switch (true) {
|
|
228
|
+
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)): {
|
|
229
|
+
const hasSameCallee = F.pipe(
|
|
230
|
+
O.Do,
|
|
231
|
+
O.bind("aCallee", () => O.map(aVarNodeParent, (n) => n.callee)),
|
|
232
|
+
O.bind("bCallee", () => O.map(bVarNodeParent, (n) => n.callee)),
|
|
233
|
+
O.exists(({ aCallee, bCallee }) => AST.isNodeEqual(aCallee, bCallee))
|
|
234
|
+
);
|
|
235
|
+
if (!hasSameCallee) return false;
|
|
236
|
+
return F.pipe(
|
|
237
|
+
O.Do,
|
|
238
|
+
O.bind("aParams", () => O.map(aVarNode, (n) => n.params)),
|
|
239
|
+
O.bind("bParams", () => O.map(bVarNode, (n) => n.params)),
|
|
240
|
+
O.let("aPos", ({ aParams }) => aParams.findIndex(AST.isNodeEqual(a))),
|
|
241
|
+
O.let("bPos", ({ bParams }) => bParams.findIndex(AST.isNodeEqual(b))),
|
|
242
|
+
O.filter(({ aPos, bPos }) => aPos !== -1 && bPos !== -1),
|
|
243
|
+
O.exists(({ aPos, bPos }) => aPos === bPos)
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
case (O.exists(aDefParentParent, AST.is(AST_NODE_TYPES.ForOfStatement)) && O.exists(bDefParentParent, AST.is(AST_NODE_TYPES.ForOfStatement))): {
|
|
247
|
+
return F.pipe(
|
|
248
|
+
O.Do,
|
|
249
|
+
O.bind("aLeft", () => O.map(aDefParentParent, (d) => d.left)),
|
|
250
|
+
O.bind("bLeft", () => O.map(bDefParentParent, (d) => d.left)),
|
|
251
|
+
O.filter(({ aLeft, bLeft }) => aLeft.type === bLeft.type),
|
|
252
|
+
O.bind("aRight", () => O.map(aDefParentParent, (d) => d.right)),
|
|
253
|
+
O.bind("bRight", () => O.map(bDefParentParent, (d) => d.right)),
|
|
254
|
+
O.exists(({ aRight, bRight }) => AST.isNodeEqual(aRight, bRight))
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
default: {
|
|
258
|
+
return O.isSome(aVar) && O.isSome(bVar) && aVar.value === bVar.value;
|
|
259
|
+
}
|
|
256
260
|
}
|
|
257
261
|
}
|
|
262
|
+
case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression): {
|
|
263
|
+
return AST.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
|
|
264
|
+
}
|
|
265
|
+
case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression): {
|
|
266
|
+
if (aScope.block === bScope.block) return true;
|
|
267
|
+
const fa = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
|
|
268
|
+
const fb = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
|
|
269
|
+
return O.isSome(fa) && O.isSome(fb) && fa.value === fb.value;
|
|
270
|
+
}
|
|
271
|
+
default: {
|
|
272
|
+
const aStatic = getStaticValue(a, aScope);
|
|
273
|
+
const bStatic = getStaticValue(b, bScope);
|
|
274
|
+
return !!aStatic && !!bStatic && aStatic.value === bStatic.value;
|
|
275
|
+
}
|
|
258
276
|
}
|
|
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
277
|
}
|
|
271
278
|
|
|
272
279
|
export { Construction, ConstructionHint, findVariable, getChidScopes, getScope, 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-beta.
|
|
3
|
+
"version": "1.17.4-beta.2",
|
|
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/
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
42
|
+
"@eslint-react/ast": "1.17.4-beta.2",
|
|
43
|
+
"@eslint-react/tools": "1.17.4-beta.2",
|
|
44
|
+
"@eslint-react/types": "1.17.4-beta.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"string-ts": "^2.2.0",
|