@eslint-react/ast 5.20.5 → 5.20.7

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
@@ -85,7 +85,7 @@ declare const isEqual: {
85
85
  (a: TSESTree.Node, b: TSESTree.Node): boolean;
86
86
  };
87
87
  declare namespace extract_d_exports {
88
- export { findProperty, getCalleeName, getFullyQualifiedName, getMemberChain, getPropertyName, unwrap };
88
+ export { findProperty, getAssignmentTargets, getCalleeName, getFullyQualifiedName, getMemberChain, getPropertyName, unwrap };
89
89
  }
90
90
  /**
91
91
  * Recursively unwrap TypeScript type expressions and chain expressions to get the underlying expression.
@@ -113,6 +113,15 @@ declare function getCalleeName(node: TSESTree.CallExpression): string | null;
113
113
  * @returns The base node followed by each member property in access order.
114
114
  */
115
115
  declare function getMemberChain(node: TSESTree.Expression | TSESTree.PrivateIdentifier): (TSESTree.AccessorProperty | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AssignmentPattern | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.BlockStatement | TSESTree.BreakStatement | TSESTree.CallExpression | TSESTree.CatchClause | TSESTree.ChainExpression | TSESTree.ClassBody | TSESTree.ClassDeclaration | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.ContinueStatement | TSESTree.DebuggerStatement | TSESTree.Decorator | TSESTree.DoWhileStatement | TSESTree.EmptyStatement | TSESTree.ExportAllDeclaration | TSESTree.ExportDefaultDeclaration | TSESTree.ExportNamedDeclaration | TSESTree.ExportSpecifier | TSESTree.ExpressionStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.IfStatement | TSESTree.ImportAttribute | TSESTree.ImportDeclaration | TSESTree.ImportDefaultSpecifier | TSESTree.ImportExpression | TSESTree.ImportNamespaceSpecifier | TSESTree.ImportSpecifier | TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText | TSESTree.LabeledStatement | TSESTree.Literal | TSESTree.LogicalExpression | TSESTree.MemberExpression | TSESTree.MetaProperty | TSESTree.MethodDefinition | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.Program | TSESTree.Property | TSESTree.PropertyDefinition | TSESTree.RestElement | TSESTree.ReturnStatement | TSESTree.SequenceExpression | TSESTree.SpreadElement | TSESTree.StaticBlock | TSESTree.Super | TSESTree.SwitchCase | TSESTree.SwitchStatement | TSESTree.TaggedTemplateExpression | TSESTree.TemplateElement | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.ThrowStatement | TSESTree.TryStatement | TSESTree.TSAbstractAccessorProperty | TSESTree.TSAbstractKeyword | TSESTree.TSAbstractMethodDefinition | TSESTree.TSAbstractPropertyDefinition | TSESTree.TSAnyKeyword | TSESTree.TSArrayType | TSESTree.TSAsyncKeyword | TSESTree.TSBigIntKeyword | TSESTree.TSBooleanKeyword | TSESTree.TSCallSignatureDeclaration | TSESTree.TSClassImplements | TSESTree.TSConditionalType | TSESTree.TSConstructorType | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunction | TSESTree.TSDeclareKeyword | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSEnumBody | TSESTree.TSEnumDeclaration | TSESTree.TSEnumMember | TSESTree.TSExportAssignment | TSESTree.TSExportKeyword | TSESTree.TSExternalModuleReference | TSESTree.TSFunctionType | TSESTree.TSImportEqualsDeclaration | TSESTree.TSImportType | TSESTree.TSIndexedAccessType | TSESTree.TSIndexSignature | TSESTree.TSInferType | TSESTree.TSInterfaceBody | TSESTree.TSInterfaceDeclaration | TSESTree.TSInterfaceHeritage | TSESTree.TSIntersectionType | TSESTree.TSIntrinsicKeyword | TSESTree.TSLiteralType | TSESTree.TSMappedType | TSESTree.TSMethodSignature | TSESTree.TSModuleBlock | TSESTree.TSModuleDeclaration | TSESTree.TSNamedTupleMember | TSESTree.TSNamespaceExportDeclaration | TSESTree.TSNeverKeyword | TSESTree.TSNullKeyword | TSESTree.TSNumberKeyword | TSESTree.TSObjectKeyword | TSESTree.TSOptionalType | TSESTree.TSParameterProperty | TSESTree.TSPrivateKeyword | TSESTree.TSPropertySignature | TSESTree.TSProtectedKeyword | TSESTree.TSPublicKeyword | TSESTree.TSQualifiedName | TSESTree.TSReadonlyKeyword | TSESTree.TSRestType | TSESTree.TSStaticKeyword | TSESTree.TSStringKeyword | TSESTree.TSSymbolKeyword | TSESTree.TSTemplateLiteralType | TSESTree.TSThisType | TSESTree.TSTupleType | TSESTree.TSTypeAliasDeclaration | TSESTree.TSTypeAnnotation | TSESTree.TSTypeLiteral | TSESTree.TSTypeOperator | TSESTree.TSTypeParameter | TSESTree.TSTypeParameterDeclaration | TSESTree.TSTypeParameterInstantiation | TSESTree.TSTypePredicate | TSESTree.TSTypeQuery | TSESTree.TSTypeReference | TSESTree.TSUndefinedKeyword | TSESTree.TSUnionType | TSESTree.TSUnknownKeyword | TSESTree.TSVoidKeyword | TSESTree.UnaryExpression | TSESTree.UpdateExpression | TSESTree.VariableDeclaration | TSESTree.VariableDeclarator | TSESTree.WhileStatement | TSESTree.WithStatement | TSESTree.YieldExpression)[];
116
+ /**
117
+ * Collect every write target of an assignment or loop target, expanding
118
+ * destructuring patterns such as `[local, globalValue] = source` or
119
+ * `({ a: obj.x } = source)`. Defaults (`{ a = source }`) are not targets;
120
+ * their left side is.
121
+ * @param node The assignment left side or for-in/of loop target to inspect.
122
+ * @returns The identifier and member expression targets being written.
123
+ */
124
+ declare function getAssignmentTargets(node: TSESTree.Node): (TSESTree.Identifier | TSESTree.MemberExpression)[];
116
125
  /**
117
126
  * Get the static name of an object property's key.
118
127
  * @param property The property to inspect.
package/dist/index.js CHANGED
@@ -635,6 +635,7 @@ const takeWhile = dual(2, (xs, pred) => {
635
635
  //#region src/extract.ts
636
636
  var extract_exports = /* @__PURE__ */ __exportAll({
637
637
  findProperty: () => findProperty,
638
+ getAssignmentTargets: () => getAssignmentTargets,
638
639
  getCalleeName: () => getCalleeName,
639
640
  getFullyQualifiedName: () => getFullyQualifiedName,
640
641
  getMemberChain: () => getMemberChain,
@@ -695,6 +696,29 @@ function getMemberChain(node) {
695
696
  return members;
696
697
  }
697
698
  /**
699
+ * Collect every write target of an assignment or loop target, expanding
700
+ * destructuring patterns such as `[local, globalValue] = source` or
701
+ * `({ a: obj.x } = source)`. Defaults (`{ a = source }`) are not targets;
702
+ * their left side is.
703
+ * @param node The assignment left side or for-in/of loop target to inspect.
704
+ * @returns The identifier and member expression targets being written.
705
+ */
706
+ function getAssignmentTargets(node) {
707
+ const target = unwrap(node);
708
+ switch (target.type) {
709
+ case AST_NODE_TYPES.Identifier:
710
+ case AST_NODE_TYPES.MemberExpression: return [target];
711
+ case AST_NODE_TYPES.ArrayPattern: return target.elements.flatMap((element) => element == null ? [] : getAssignmentTargets(element));
712
+ case AST_NODE_TYPES.AssignmentPattern: return getAssignmentTargets(target.left);
713
+ case AST_NODE_TYPES.ObjectPattern: return target.properties.flatMap((property) => {
714
+ if (property.type === AST_NODE_TYPES.RestElement) return getAssignmentTargets(property.argument);
715
+ return getAssignmentTargets(property.value);
716
+ });
717
+ case AST_NODE_TYPES.RestElement: return getAssignmentTargets(target.argument);
718
+ default: return [];
719
+ }
720
+ }
721
+ /**
698
722
  * Get the static name of an object property's key.
699
723
  * @param property The property to inspect.
700
724
  * @param effort `"min"` only matches plain identifiers; `"max"` also resolves string literals and simple template literals.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "5.20.5",
3
+ "version": "5.20.7",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {