@eslint-react/ast 1.15.1-beta.10 → 1.15.1-beta.15

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
@@ -232,24 +232,34 @@ var isLeftHandSideExpressionType = isOneOf([
232
232
 
233
233
  // src/get-function-identifier.ts
234
234
  function getFunctionIdentifier(node) {
235
- if ("id" in node && 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);
250
- }
251
- if (isOneOf([types.AST_NODE_TYPES.TSAsExpression, types.AST_NODE_TYPES.TSSatisfiesExpression])(node.parent) && node.parent.expression === node) {
252
- return getFunctionIdentifier(node.parent);
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);
253
263
  }
254
264
  return tools.O.none();
255
265
  }
package/dist/index.mjs CHANGED
@@ -230,24 +230,34 @@ var isLeftHandSideExpressionType = isOneOf([
230
230
 
231
231
  // src/get-function-identifier.ts
232
232
  function getFunctionIdentifier(node) {
233
- if ("id" in node && 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);
248
- }
249
- if (isOneOf([AST_NODE_TYPES.TSAsExpression, AST_NODE_TYPES.TSSatisfiesExpression])(node.parent) && node.parent.expression === node) {
250
- return getFunctionIdentifier(node.parent);
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);
251
261
  }
252
262
  return O.none();
253
263
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "1.15.1-beta.10",
3
+ "version": "1.15.1-beta.15",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {
@@ -41,8 +41,8 @@
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-beta.10",
45
- "@eslint-react/types": "1.15.1-beta.10"
44
+ "@eslint-react/tools": "1.15.1-beta.15",
45
+ "@eslint-react/types": "1.15.1-beta.15"
46
46
  },
47
47
  "devDependencies": {
48
48
  "tsup": "^8.3.0"