@eslint-react/var 2.7.4-next.3 → 2.7.4-next.5

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.ts CHANGED
@@ -1,9 +1,21 @@
1
1
  import { unit } from "@eslint-react/eff";
2
2
  import { TSESTree } from "@typescript-eslint/types";
3
3
  import { Scope, Variable } from "@typescript-eslint/scope-manager";
4
+ import { RuleContext } from "@eslint-react/shared";
4
5
 
5
- //#region src/find-assignment-target.d.ts
6
- declare function findAssignmentTarget(node: TSESTree.Node | unit, prev?: TSESTree.Node): TSESTree.BindingName | TSESTree.Expression | unit;
6
+ //#region src/find-enclosing-assignment-target.d.ts
7
+ /**
8
+ * Finds the enclosing assignment target (variable, property, etc.) for a given node
9
+ *
10
+ * @todo Verify correctness and completeness of this function
11
+ * @param node The starting node
12
+ * @returns The enclosing assignment target node, or undefined if not found
13
+ */
14
+ declare function findEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
15
+ /**
16
+ * Type representing the possible assignment targets returned by `findEnclosingAssignmentTarget`
17
+ */
18
+ type AssignmentTarget = ReturnType<typeof findEnclosingAssignmentTarget>;
7
19
  //#endregion
8
20
  //#region src/find-import-source.d.ts
9
21
  /**
@@ -71,6 +83,10 @@ declare const findVariable: {
71
83
  (nameOrNode: string | TSESTree.Identifier | unit, initialScope: Scope): Variable | unit;
72
84
  };
73
85
  //#endregion
86
+ //#region src/is-assignment-target-equal.d.ts
87
+ /** @internal */
88
+ declare function isAssignmentTargetEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean;
89
+ //#endregion
74
90
  //#region src/is-node-value-equal.d.ts
75
91
  /**
76
92
  * Determines whether node value equals to another node value
@@ -81,4 +97,4 @@ declare const findVariable: {
81
97
  */
82
98
  declare function isNodeValueEqual(a: TSESTree.Node, b: TSESTree.Node, initialScopes: [aScope: Scope, bScope: Scope]): boolean;
83
99
  //#endregion
84
- export { ObjectType, findAssignmentTarget, findImportSource, findProperty, findVariable, getChildScopes, getObjectType, getVariableDefinitionNode, getVariableDefinitionNodeLoose, getVariables, isNodeValueEqual };
100
+ export { AssignmentTarget, ObjectType, findEnclosingAssignmentTarget, findImportSource, findProperty, findVariable, getChildScopes, getObjectType, getVariableDefinitionNode, getVariableDefinitionNodeLoose, getVariables, isAssignmentTargetEqual, isNodeValueEqual };
package/dist/index.js CHANGED
@@ -6,14 +6,22 @@ import { DefinitionType, ScopeType } from "@typescript-eslint/scope-manager";
6
6
  import * as ASTUtils from "@typescript-eslint/utils/ast-utils";
7
7
  import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
8
8
 
9
- //#region src/find-assignment-target.ts
10
- function findAssignmentTarget(node, prev) {
11
- if (node == null) return unit;
9
+ //#region src/find-enclosing-assignment-target.ts
10
+ /** eslint-disable jsdoc/require-param */
11
+ /**
12
+ * Finds the enclosing assignment target (variable, property, etc.) for a given node
13
+ *
14
+ * @todo Verify correctness and completeness of this function
15
+ * @param node The starting node
16
+ * @returns The enclosing assignment target node, or undefined if not found
17
+ */
18
+ function findEnclosingAssignmentTarget(node) {
12
19
  switch (true) {
13
- case node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev: return node.id;
14
- case node.type === AST_NODE_TYPES.AssignmentExpression && node.right === prev: return node.left;
20
+ case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
21
+ case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
22
+ case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
15
23
  case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node: return unit;
16
- default: return findAssignmentTarget(node.parent, node);
24
+ default: return findEnclosingAssignmentTarget(node.parent);
17
25
  }
18
26
  }
19
27
 
@@ -270,4 +278,11 @@ function isNodeValueEqual(a, b, initialScopes) {
270
278
  }
271
279
 
272
280
  //#endregion
273
- export { findAssignmentTarget, findImportSource, findProperty, findVariable, getChildScopes, getObjectType, getVariableDefinitionNode, getVariableDefinitionNodeLoose, getVariables, isNodeValueEqual };
281
+ //#region src/is-assignment-target-equal.ts
282
+ /** @internal */
283
+ function isAssignmentTargetEqual(context, a, b) {
284
+ return AST.isNodeEqual(a, b) || isNodeValueEqual(a, b, [context.sourceCode.getScope(a), context.sourceCode.getScope(b)]);
285
+ }
286
+
287
+ //#endregion
288
+ export { findEnclosingAssignmentTarget, findImportSource, findProperty, findVariable, getChildScopes, getObjectType, getVariableDefinitionNode, getVariableDefinitionNodeLoose, getVariables, isAssignmentTargetEqual, isNodeValueEqual };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "2.7.4-next.3",
3
+ "version": "2.7.4-next.5",
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": {
@@ -34,8 +34,9 @@
34
34
  "@typescript-eslint/types": "^8.53.1",
35
35
  "@typescript-eslint/utils": "^8.53.1",
36
36
  "ts-pattern": "^5.9.0",
37
- "@eslint-react/eff": "2.7.4-next.3",
38
- "@eslint-react/ast": "2.7.4-next.3"
37
+ "@eslint-react/ast": "2.7.4-next.5",
38
+ "@eslint-react/eff": "2.7.4-next.5",
39
+ "@eslint-react/shared": "2.7.4-next.5"
39
40
  },
40
41
  "devDependencies": {
41
42
  "tsdown": "^0.20.0-beta.4",