@eslint-react/var 1.17.4-beta.0 → 1.17.4-next.1

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,68 +227,72 @@ 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 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((p) => AST__namespace.isNodeEqual(p, a))),
263
- tools.O.let("bPos", ({ bParams }) => bParams.findIndex((p) => AST__namespace.isNodeEqual(p, 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("aRight", () => tools.O.map(aDefParentParent, (d) => d.right)),
272
- tools.O.bind("bRight", () => tools.O.map(bDefParentParent, (d) => d.right)),
273
- tools.O.exists(({ aRight, bRight }) => AST__namespace.isNodeEqual(aRight, bRight))
274
- );
275
- }
276
- default: {
277
- return tools.O.isSome(aVar) && tools.O.isSome(bVar) && aVar.value === bVar.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("aRight", () => tools.O.map(aDefParentParent, (d) => d.right)),
272
+ tools.O.bind("bRight", () => tools.O.map(bDefParentParent, (d) => d.right)),
273
+ tools.O.exists(({ aRight, bRight }) => AST__namespace.isNodeEqual(aRight, bRight))
274
+ );
275
+ }
276
+ default: {
277
+ return tools.O.isSome(aVar) && tools.O.isSome(bVar) && aVar.value === bVar.value;
278
+ }
278
279
  }
279
280
  }
281
+ case (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
+ case (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
+ return tools.O.isSome(fa) && tools.O.isSome(fb) && fa.value === fb.value;
289
+ }
290
+ default: {
291
+ const aStatic = astUtils.getStaticValue(a, aScope);
292
+ const bStatic = astUtils.getStaticValue(b, bScope);
293
+ return !!aStatic && !!bStatic && aStatic.value === bStatic.value;
294
+ }
280
295
  }
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
296
  }
293
297
 
294
298
  exports.Construction = Construction;
package/dist/index.mjs CHANGED
@@ -205,68 +205,72 @@ 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 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((p) => AST.isNodeEqual(p, a))),
241
- O.let("bPos", ({ bParams }) => bParams.findIndex((p) => AST.isNodeEqual(p, 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("aRight", () => O.map(aDefParentParent, (d) => d.right)),
250
- O.bind("bRight", () => O.map(bDefParentParent, (d) => d.right)),
251
- O.exists(({ aRight, bRight }) => AST.isNodeEqual(aRight, bRight))
252
- );
253
- }
254
- default: {
255
- return O.isSome(aVar) && O.isSome(bVar) && aVar.value === bVar.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("aRight", () => O.map(aDefParentParent, (d) => d.right)),
250
+ O.bind("bRight", () => O.map(bDefParentParent, (d) => d.right)),
251
+ O.exists(({ aRight, bRight }) => AST.isNodeEqual(aRight, bRight))
252
+ );
253
+ }
254
+ default: {
255
+ return O.isSome(aVar) && O.isSome(bVar) && aVar.value === bVar.value;
256
+ }
256
257
  }
257
258
  }
259
+ case (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
+ case (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
+ return O.isSome(fa) && O.isSome(fb) && fa.value === fb.value;
267
+ }
268
+ default: {
269
+ const aStatic = getStaticValue(a, aScope);
270
+ const bStatic = getStaticValue(b, bScope);
271
+ return !!aStatic && !!bStatic && aStatic.value === bStatic.value;
272
+ }
258
273
  }
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
274
  }
271
275
 
272
276
  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.0",
3
+ "version": "1.17.4-next.1",
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-beta.0",
43
- "@eslint-react/types": "1.17.4-beta.0",
44
- "@eslint-react/ast": "1.17.4-beta.0"
42
+ "@eslint-react/ast": "1.17.4-next.1",
43
+ "@eslint-react/tools": "1.17.4-next.1",
44
+ "@eslint-react/types": "1.17.4-next.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "string-ts": "^2.2.0",