@eslint-react/var 1.17.3 → 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 CHANGED
@@ -227,69 +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
- const aStatic = astUtils.getStaticValue(a, aScope);
236
- const bStatic = astUtils.getStaticValue(b, bScope);
237
- if (aStatic && bStatic) return aStatic.value === bStatic.value;
238
- if (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier) {
239
- const va = findVariable(a, aScope);
240
- const vb = findVariable(b, bScope);
241
- const da = tools.O.flatMap(va, getVariableDef(0));
242
- const db = tools.O.flatMap(vb, getVariableDef(0));
243
- const dapp = tools.O.flatMapNullable(da, (d) => d.parent?.parent);
244
- const dbpp = tools.O.flatMapNullable(db, (d) => d.parent?.parent);
245
- const na = tools.O.flatMap(va, getVariableNode(0));
246
- const nb = tools.O.flatMap(vb, getVariableNode(0));
247
- const nap = tools.O.flatMapNullable(na, (n) => n.parent);
248
- const nbp = tools.O.flatMapNullable(nb, (n) => n.parent);
249
- switch (true) {
250
- case (tools.O.exists(nap, AST__namespace.is(types.AST_NODE_TYPES.CallExpression)) && tools.O.exists(nbp, AST__namespace.is(types.AST_NODE_TYPES.CallExpression)) && tools.O.exists(na, AST__namespace.isFunction) && tools.O.exists(nb, AST__namespace.isFunction)): {
251
- const hasSameCallee = tools.F.pipe(
252
- tools.O.Do,
253
- tools.O.bind("ca", () => tools.O.map(nap, (n) => n.callee)),
254
- tools.O.bind("cb", () => tools.O.map(nbp, (n) => n.callee)),
255
- tools.O.exists(({ ca, cb }) => AST__namespace.isNodeEqual(ca, cb))
256
- );
257
- if (!hasSameCallee) return false;
258
- return tools.F.pipe(
259
- tools.O.Do,
260
- tools.O.bind("paramsA", () => tools.O.map(na, (n) => n.params)),
261
- tools.O.bind("paramsB", () => tools.O.map(nb, (n) => n.params)),
262
- tools.O.let("posA", ({ paramsA }) => paramsA.findIndex((p) => AST__namespace.isNodeEqual(p, a))),
263
- tools.O.let("posB", ({ paramsB }) => paramsB.findIndex((p) => AST__namespace.isNodeEqual(p, b))),
264
- tools.O.filter(({ posA, posB }) => posA !== -1 && posB !== -1),
265
- tools.O.exists(({ posA, posB }) => posA === posB)
266
- );
267
- }
268
- case (tools.O.exists(dapp, AST__namespace.is(types.AST_NODE_TYPES.ForOfStatement)) && tools.O.exists(dbpp, AST__namespace.is(types.AST_NODE_TYPES.ForOfStatement))): {
269
- return tools.F.pipe(
270
- tools.O.Do,
271
- tools.O.bind("rightA", () => tools.O.map(dapp, (d) => d.right)),
272
- tools.O.bind("rightB", () => tools.O.map(dbpp, (d) => d.right)),
273
- tools.O.exists(({ rightA, rightB }) => AST__namespace.isNodeEqual(rightA, rightB))
274
- );
275
- }
276
- default: {
277
- if (tools.O.isNone(na) || tools.O.isNone(nb)) return false;
278
- return na.value === nb.value;
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
+ }
279
282
  }
280
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
+ }
281
298
  }
282
- if (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression) {
283
- return AST__namespace.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
284
- }
285
- if (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression) {
286
- if (aScope.block === bScope.block) return true;
287
- const fa = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
288
- const fb = AST__namespace.traverseUp(a, AST__namespace.isOneOf(thisBlockTypes));
289
- if (tools.O.isSome(fa) && tools.O.isSome(fb)) return fa.value === fb.value;
290
- return false;
291
- }
292
- return false;
293
299
  }
294
300
 
295
301
  exports.Construction = Construction;
package/dist/index.mjs CHANGED
@@ -205,69 +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
- const aStatic = getStaticValue(a, aScope);
214
- const bStatic = getStaticValue(b, bScope);
215
- if (aStatic && bStatic) return aStatic.value === bStatic.value;
216
- if (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier) {
217
- const va = findVariable(a, aScope);
218
- const vb = findVariable(b, bScope);
219
- const da = O.flatMap(va, getVariableDef(0));
220
- const db = O.flatMap(vb, getVariableDef(0));
221
- const dapp = O.flatMapNullable(da, (d) => d.parent?.parent);
222
- const dbpp = O.flatMapNullable(db, (d) => d.parent?.parent);
223
- const na = O.flatMap(va, getVariableNode(0));
224
- const nb = O.flatMap(vb, getVariableNode(0));
225
- const nap = O.flatMapNullable(na, (n) => n.parent);
226
- const nbp = O.flatMapNullable(nb, (n) => n.parent);
227
- switch (true) {
228
- case (O.exists(nap, AST.is(AST_NODE_TYPES.CallExpression)) && O.exists(nbp, AST.is(AST_NODE_TYPES.CallExpression)) && O.exists(na, AST.isFunction) && O.exists(nb, AST.isFunction)): {
229
- const hasSameCallee = F.pipe(
230
- O.Do,
231
- O.bind("ca", () => O.map(nap, (n) => n.callee)),
232
- O.bind("cb", () => O.map(nbp, (n) => n.callee)),
233
- O.exists(({ ca, cb }) => AST.isNodeEqual(ca, cb))
234
- );
235
- if (!hasSameCallee) return false;
236
- return F.pipe(
237
- O.Do,
238
- O.bind("paramsA", () => O.map(na, (n) => n.params)),
239
- O.bind("paramsB", () => O.map(nb, (n) => n.params)),
240
- O.let("posA", ({ paramsA }) => paramsA.findIndex((p) => AST.isNodeEqual(p, a))),
241
- O.let("posB", ({ paramsB }) => paramsB.findIndex((p) => AST.isNodeEqual(p, b))),
242
- O.filter(({ posA, posB }) => posA !== -1 && posB !== -1),
243
- O.exists(({ posA, posB }) => posA === posB)
244
- );
245
- }
246
- case (O.exists(dapp, AST.is(AST_NODE_TYPES.ForOfStatement)) && O.exists(dbpp, AST.is(AST_NODE_TYPES.ForOfStatement))): {
247
- return F.pipe(
248
- O.Do,
249
- O.bind("rightA", () => O.map(dapp, (d) => d.right)),
250
- O.bind("rightB", () => O.map(dbpp, (d) => d.right)),
251
- O.exists(({ rightA, rightB }) => AST.isNodeEqual(rightA, rightB))
252
- );
253
- }
254
- default: {
255
- if (O.isNone(na) || O.isNone(nb)) return false;
256
- return na.value === nb.value;
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
+ }
257
260
  }
258
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
+ }
259
276
  }
260
- if (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression) {
261
- return AST.isNodeEqual(a.property, b.property) && isNodeValueEqual(a.object, b.object, initialScopes);
262
- }
263
- if (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression) {
264
- if (aScope.block === bScope.block) return true;
265
- const fa = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
266
- const fb = AST.traverseUp(a, AST.isOneOf(thisBlockTypes));
267
- if (O.isSome(fa) && O.isSome(fb)) return fa.value === fb.value;
268
- return false;
269
- }
270
- return false;
271
277
  }
272
278
 
273
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.3",
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/ast": "1.17.3",
43
- "@eslint-react/tools": "1.17.3",
44
- "@eslint-react/types": "1.17.3"
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",