@eslint-react/ast 1.15.1-next.8 → 1.15.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.d.mts CHANGED
@@ -130,7 +130,7 @@ declare function getClassIdentifier(node: TSESTreeClass): O.Option<TSESTree$1.Id
130
130
  * same AST nodes with some exceptions to better fit our use case.
131
131
  */
132
132
 
133
- declare function getFunctionIdentifier(node: TSESTreeFunction): O.Option<TSESTree$1.Identifier>;
133
+ declare function getFunctionIdentifier(node: TSESTree$1.Expression | TSESTreeFunction): O.Option<TSESTree$1.Identifier>;
134
134
 
135
135
  declare function getIdentifiersFromBinaryExpression(side: TSESTree$1.BinaryExpression | TSESTree$1.BinaryExpression["left"] | TSESTree$1.BinaryExpression["right"]): TSESTree$1.Identifier[];
136
136
 
package/dist/index.d.ts CHANGED
@@ -130,7 +130,7 @@ declare function getClassIdentifier(node: TSESTreeClass): O.Option<TSESTree$1.Id
130
130
  * same AST nodes with some exceptions to better fit our use case.
131
131
  */
132
132
 
133
- declare function getFunctionIdentifier(node: TSESTreeFunction): O.Option<TSESTree$1.Identifier>;
133
+ declare function getFunctionIdentifier(node: TSESTree$1.Expression | TSESTreeFunction): O.Option<TSESTree$1.Identifier>;
134
134
 
135
135
  declare function getIdentifiersFromBinaryExpression(side: TSESTree$1.BinaryExpression | TSESTree$1.BinaryExpression["left"] | TSESTree$1.BinaryExpression["right"]): TSESTree$1.Identifier[];
136
136
 
package/dist/index.js CHANGED
@@ -232,21 +232,34 @@ var isLeftHandSideExpressionType = isOneOf([
232
232
 
233
233
  // src/get-function-identifier.ts
234
234
  function getFunctionIdentifier(node) {
235
- if (node.id) return tools.O.some(node.id);
236
- if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
237
- return tools.O.some(node.parent.id);
238
- }
239
- if (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === types.AST_NODE_TYPES.Identifier) {
240
- return tools.O.some(node.parent.left);
241
- }
242
- if (node.parent.type === types.AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === types.AST_NODE_TYPES.Identifier) {
243
- return tools.O.some(node.parent.key);
244
- }
245
- if (isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.value === node && node.parent.key.type === types.AST_NODE_TYPES.Identifier) {
246
- return tools.O.some(node.parent.key);
247
- }
248
- if (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier) {
249
- return tools.O.some(node.parent.left);
235
+ switch (true) {
236
+ // function MaybeComponent() {}
237
+ case ("id" in node && !!node.id):
238
+ return tools.O.some(node.id);
239
+ // const whatever = function MaybeComponent() {};
240
+ case (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === types.AST_NODE_TYPES.Identifier):
241
+ return tools.O.some(node.parent.id);
242
+ // MaybeComponent = () => {};
243
+ case (node.parent.type === types.AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
244
+ return tools.O.some(node.parent.left);
245
+ // {MaybeComponent: () => {}}
246
+ // {MaybeComponent() {}}
247
+ case (node.parent.type === types.AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === types.AST_NODE_TYPES.Identifier):
248
+ return tools.O.some(node.parent.key);
249
+ // class {MaybeComponent = () => {}}
250
+ // class {MaybeComponent() {}}
251
+ case (isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.value === node && node.parent.key.type === types.AST_NODE_TYPES.Identifier):
252
+ return tools.O.some(node.parent.key);
253
+ // Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
254
+ //
255
+ // const {MaybeComponent = () => {}} = {};
256
+ // ({MaybeComponent = () => {}} = {});
257
+ case (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
258
+ return tools.O.some(node.parent.left);
259
+ // const MaybeComponent = (() => {}) as FunctionComponent;
260
+ // const MaybeComponent = (() => {}) satisfies FunctionComponent;
261
+ case isOneOf([types.AST_NODE_TYPES.TSAsExpression, types.AST_NODE_TYPES.TSSatisfiesExpression])(node.parent):
262
+ return getFunctionIdentifier(node.parent);
250
263
  }
251
264
  return tools.O.none();
252
265
  }
package/dist/index.mjs CHANGED
@@ -230,21 +230,34 @@ var isLeftHandSideExpressionType = isOneOf([
230
230
 
231
231
  // src/get-function-identifier.ts
232
232
  function getFunctionIdentifier(node) {
233
- if (node.id) return O.some(node.id);
234
- if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier) {
235
- return O.some(node.parent.id);
236
- }
237
- if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier) {
238
- return O.some(node.parent.left);
239
- }
240
- if (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier) {
241
- return O.some(node.parent.key);
242
- }
243
- if (isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier) {
244
- return O.some(node.parent.key);
245
- }
246
- if (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier) {
247
- return O.some(node.parent.left);
233
+ switch (true) {
234
+ // function MaybeComponent() {}
235
+ case ("id" in node && !!node.id):
236
+ return O.some(node.id);
237
+ // const whatever = function MaybeComponent() {};
238
+ case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
239
+ return O.some(node.parent.id);
240
+ // MaybeComponent = () => {};
241
+ case (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier):
242
+ return O.some(node.parent.left);
243
+ // {MaybeComponent: () => {}}
244
+ // {MaybeComponent() {}}
245
+ case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
246
+ return O.some(node.parent.key);
247
+ // class {MaybeComponent = () => {}}
248
+ // class {MaybeComponent() {}}
249
+ case (isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
250
+ return O.some(node.parent.key);
251
+ // Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
252
+ //
253
+ // const {MaybeComponent = () => {}} = {};
254
+ // ({MaybeComponent = () => {}} = {});
255
+ case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
256
+ return O.some(node.parent.left);
257
+ // const MaybeComponent = (() => {}) as FunctionComponent;
258
+ // const MaybeComponent = (() => {}) satisfies FunctionComponent;
259
+ case isOneOf([AST_NODE_TYPES.TSAsExpression, AST_NODE_TYPES.TSSatisfiesExpression])(node.parent):
260
+ return getFunctionIdentifier(node.parent);
248
261
  }
249
262
  return O.none();
250
263
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "1.15.1-next.8",
3
+ "version": "1.15.1",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {
@@ -41,11 +41,11 @@
41
41
  "birecord": "^0.1.1",
42
42
  "string-ts": "^2.2.0",
43
43
  "ts-pattern": "^5.5.0",
44
- "@eslint-react/tools": "1.15.1-next.8",
45
- "@eslint-react/types": "1.15.1-next.8"
44
+ "@eslint-react/types": "1.15.1",
45
+ "@eslint-react/tools": "1.15.1"
46
46
  },
47
47
  "devDependencies": {
48
- "tsup": "^8.3.0"
48
+ "tsup": "^8.3.5"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "tsup",