@eslint-react/ast 1.52.9 → 1.52.10-beta.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
@@ -1,523 +1,583 @@
1
- 'use strict';
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
2
22
 
3
- var types = require('@typescript-eslint/types');
4
- var eff = require('@eslint-react/eff');
5
- var utils = require('@typescript-eslint/utils');
6
- var typescriptEstree = require('@typescript-eslint/typescript-estree');
7
- var stringTs = require('string-ts');
23
+ //#endregion
24
+ const __typescript_eslint_types = __toESM(require("@typescript-eslint/types"));
25
+ const __eslint_react_eff = __toESM(require("@eslint-react/eff"));
26
+ const __typescript_eslint_utils = __toESM(require("@typescript-eslint/utils"));
27
+ const __typescript_eslint_typescript_estree = __toESM(require("@typescript-eslint/typescript-estree"));
28
+ const string_ts = __toESM(require("string-ts"));
8
29
 
9
- // src/ast-array-method.ts
30
+ //#region src/ast-array-method.ts
10
31
  function isArrayFromCall(node, loose = true) {
11
- if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
12
- if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
13
- if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false;
14
- const name = node.callee.property.name;
15
- return name === "from" || loose && name.startsWith("from");
32
+ if (node.type !== __typescript_eslint_types.AST_NODE_TYPES.CallExpression) return false;
33
+ if (node.callee.type !== __typescript_eslint_types.AST_NODE_TYPES.MemberExpression) return false;
34
+ if (node.callee.property.type !== __typescript_eslint_types.AST_NODE_TYPES.Identifier) return false;
35
+ const name = node.callee.property.name;
36
+ return name === "from" || loose && name.startsWith("from");
16
37
  }
17
38
  function isArrayMapCall(node, loose = true) {
18
- if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
19
- if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
20
- if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false;
21
- const name = node.callee.property.name;
22
- return name === "map" || loose && name.endsWith("Map");
39
+ if (node.type !== __typescript_eslint_types.AST_NODE_TYPES.CallExpression) return false;
40
+ if (node.callee.type !== __typescript_eslint_types.AST_NODE_TYPES.MemberExpression) return false;
41
+ if (node.callee.property.type !== __typescript_eslint_types.AST_NODE_TYPES.Identifier) return false;
42
+ const name = node.callee.property.name;
43
+ return name === "map" || loose && name.endsWith("Map");
23
44
  }
24
45
 
25
- // src/ast-array-method-callback.ts
26
- var indexParamPosition = /* @__PURE__ */ new Map([
27
- ["every", 1],
28
- ["filter", 1],
29
- ["find", 1],
30
- ["findIndex", 1],
31
- ["findLast", 1],
32
- ["findLastIndex", 1],
33
- ["flatMap", 1],
34
- ["forEach", 1],
35
- ["map", 1],
36
- ["reduce", 2],
37
- ["reduceRight", 2],
38
- ["some", 1]
46
+ //#endregion
47
+ //#region src/ast-array-method-callback.ts
48
+ const indexParamPosition = new Map([
49
+ ["every", 1],
50
+ ["filter", 1],
51
+ ["find", 1],
52
+ ["findIndex", 1],
53
+ ["findLast", 1],
54
+ ["findLastIndex", 1],
55
+ ["flatMap", 1],
56
+ ["forEach", 1],
57
+ ["map", 1],
58
+ ["reduce", 2],
59
+ ["reduceRight", 2],
60
+ ["some", 1]
39
61
  ]);
40
62
  function getArrayMethodCallbackIndexParamPosition(methodName) {
41
- return indexParamPosition.get(methodName) ?? -1;
63
+ return indexParamPosition.get(methodName) ?? -1;
42
64
  }
65
+
66
+ //#endregion
67
+ //#region src/ast-class-id.ts
68
+ /**
69
+ * Gets class identifier from ClassDeclaration or ClassExpression
70
+ * @param node The AST node to check
71
+ * @returns class identifier or null
72
+ */
43
73
  function getClassId(node) {
44
- if (node.id != null) return node.id;
45
- if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
46
- return node.parent.id;
47
- }
48
- return eff.unit;
74
+ if (node.id != null) return node.id;
75
+ if (node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier) return node.parent.id;
76
+ return __eslint_react_eff.unit;
49
77
  }
50
- var is = utils.ASTUtils.isNodeOfType;
51
- var isOneOf = utils.ASTUtils.isNodeOfTypes;
52
- var isFunction = isOneOf([
53
- types.AST_NODE_TYPES.ArrowFunctionExpression,
54
- types.AST_NODE_TYPES.FunctionDeclaration,
55
- types.AST_NODE_TYPES.FunctionExpression
56
- ]);
57
- var isFunctionType = isOneOf([
58
- types.AST_NODE_TYPES.ArrowFunctionExpression,
59
- types.AST_NODE_TYPES.FunctionDeclaration,
60
- types.AST_NODE_TYPES.FunctionExpression,
61
- types.AST_NODE_TYPES.TSCallSignatureDeclaration,
62
- types.AST_NODE_TYPES.TSConstructSignatureDeclaration,
63
- types.AST_NODE_TYPES.TSDeclareFunction,
64
- types.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
65
- types.AST_NODE_TYPES.TSFunctionType,
66
- types.AST_NODE_TYPES.TSMethodSignature
78
+
79
+ //#endregion
80
+ //#region src/ast-is.ts
81
+ const is = __typescript_eslint_utils.ASTUtils.isNodeOfType;
82
+ const isOneOf = __typescript_eslint_utils.ASTUtils.isNodeOfTypes;
83
+ const isFunction = isOneOf([
84
+ __typescript_eslint_types.AST_NODE_TYPES.ArrowFunctionExpression,
85
+ __typescript_eslint_types.AST_NODE_TYPES.FunctionDeclaration,
86
+ __typescript_eslint_types.AST_NODE_TYPES.FunctionExpression
67
87
  ]);
68
- var isClass = isOneOf([types.AST_NODE_TYPES.ClassDeclaration, types.AST_NODE_TYPES.ClassExpression]);
69
- var isMethodOrProperty = isOneOf([
70
- types.AST_NODE_TYPES.PropertyDefinition,
71
- types.AST_NODE_TYPES.MethodDefinition
88
+ const isFunctionType = isOneOf([
89
+ __typescript_eslint_types.AST_NODE_TYPES.ArrowFunctionExpression,
90
+ __typescript_eslint_types.AST_NODE_TYPES.FunctionDeclaration,
91
+ __typescript_eslint_types.AST_NODE_TYPES.FunctionExpression,
92
+ __typescript_eslint_types.AST_NODE_TYPES.TSCallSignatureDeclaration,
93
+ __typescript_eslint_types.AST_NODE_TYPES.TSConstructSignatureDeclaration,
94
+ __typescript_eslint_types.AST_NODE_TYPES.TSDeclareFunction,
95
+ __typescript_eslint_types.AST_NODE_TYPES.TSEmptyBodyFunctionExpression,
96
+ __typescript_eslint_types.AST_NODE_TYPES.TSFunctionType,
97
+ __typescript_eslint_types.AST_NODE_TYPES.TSMethodSignature
72
98
  ]);
73
- var isProperty = isOneOf([
74
- types.AST_NODE_TYPES.PropertyDefinition,
75
- types.AST_NODE_TYPES.TSIndexSignature,
76
- types.AST_NODE_TYPES.TSParameterProperty,
77
- types.AST_NODE_TYPES.TSPropertySignature
99
+ const isClass = isOneOf([__typescript_eslint_types.AST_NODE_TYPES.ClassDeclaration, __typescript_eslint_types.AST_NODE_TYPES.ClassExpression]);
100
+ const isMethodOrProperty = isOneOf([__typescript_eslint_types.AST_NODE_TYPES.PropertyDefinition, __typescript_eslint_types.AST_NODE_TYPES.MethodDefinition]);
101
+ const isProperty = isOneOf([
102
+ __typescript_eslint_types.AST_NODE_TYPES.PropertyDefinition,
103
+ __typescript_eslint_types.AST_NODE_TYPES.TSIndexSignature,
104
+ __typescript_eslint_types.AST_NODE_TYPES.TSParameterProperty,
105
+ __typescript_eslint_types.AST_NODE_TYPES.TSPropertySignature
78
106
  ]);
79
- var isJSXElement = is(types.AST_NODE_TYPES.JSXElement);
80
- var isJSXFragment = is(types.AST_NODE_TYPES.JSXFragment);
81
- var isJSXTagNameExpression = isOneOf([
82
- types.AST_NODE_TYPES.JSXIdentifier,
83
- types.AST_NODE_TYPES.JSXMemberExpression,
84
- types.AST_NODE_TYPES.JSXNamespacedName
107
+ const isJSXElement = is(__typescript_eslint_types.AST_NODE_TYPES.JSXElement);
108
+ const isJSXFragment = is(__typescript_eslint_types.AST_NODE_TYPES.JSXFragment);
109
+ const isJSXTagNameExpression = isOneOf([
110
+ __typescript_eslint_types.AST_NODE_TYPES.JSXIdentifier,
111
+ __typescript_eslint_types.AST_NODE_TYPES.JSXMemberExpression,
112
+ __typescript_eslint_types.AST_NODE_TYPES.JSXNamespacedName
85
113
  ]);
86
- var isJSX = isOneOf([
87
- types.AST_NODE_TYPES.JSXAttribute,
88
- types.AST_NODE_TYPES.JSXClosingElement,
89
- types.AST_NODE_TYPES.JSXClosingFragment,
90
- types.AST_NODE_TYPES.JSXElement,
91
- types.AST_NODE_TYPES.JSXEmptyExpression,
92
- types.AST_NODE_TYPES.JSXExpressionContainer,
93
- types.AST_NODE_TYPES.JSXFragment,
94
- types.AST_NODE_TYPES.JSXIdentifier,
95
- types.AST_NODE_TYPES.JSXMemberExpression,
96
- types.AST_NODE_TYPES.JSXNamespacedName,
97
- types.AST_NODE_TYPES.JSXOpeningElement,
98
- types.AST_NODE_TYPES.JSXOpeningFragment,
99
- types.AST_NODE_TYPES.JSXSpreadAttribute,
100
- types.AST_NODE_TYPES.JSXSpreadChild,
101
- types.AST_NODE_TYPES.JSXText
114
+ const isJSX = isOneOf([
115
+ __typescript_eslint_types.AST_NODE_TYPES.JSXAttribute,
116
+ __typescript_eslint_types.AST_NODE_TYPES.JSXClosingElement,
117
+ __typescript_eslint_types.AST_NODE_TYPES.JSXClosingFragment,
118
+ __typescript_eslint_types.AST_NODE_TYPES.JSXElement,
119
+ __typescript_eslint_types.AST_NODE_TYPES.JSXEmptyExpression,
120
+ __typescript_eslint_types.AST_NODE_TYPES.JSXExpressionContainer,
121
+ __typescript_eslint_types.AST_NODE_TYPES.JSXFragment,
122
+ __typescript_eslint_types.AST_NODE_TYPES.JSXIdentifier,
123
+ __typescript_eslint_types.AST_NODE_TYPES.JSXMemberExpression,
124
+ __typescript_eslint_types.AST_NODE_TYPES.JSXNamespacedName,
125
+ __typescript_eslint_types.AST_NODE_TYPES.JSXOpeningElement,
126
+ __typescript_eslint_types.AST_NODE_TYPES.JSXOpeningFragment,
127
+ __typescript_eslint_types.AST_NODE_TYPES.JSXSpreadAttribute,
128
+ __typescript_eslint_types.AST_NODE_TYPES.JSXSpreadChild,
129
+ __typescript_eslint_types.AST_NODE_TYPES.JSXText
102
130
  ]);
103
- var isLoop = isOneOf([
104
- types.AST_NODE_TYPES.DoWhileStatement,
105
- types.AST_NODE_TYPES.ForInStatement,
106
- types.AST_NODE_TYPES.ForOfStatement,
107
- types.AST_NODE_TYPES.ForStatement,
108
- types.AST_NODE_TYPES.WhileStatement
131
+ const isLoop = isOneOf([
132
+ __typescript_eslint_types.AST_NODE_TYPES.DoWhileStatement,
133
+ __typescript_eslint_types.AST_NODE_TYPES.ForInStatement,
134
+ __typescript_eslint_types.AST_NODE_TYPES.ForOfStatement,
135
+ __typescript_eslint_types.AST_NODE_TYPES.ForStatement,
136
+ __typescript_eslint_types.AST_NODE_TYPES.WhileStatement
109
137
  ]);
110
- var isTypeExpression = isOneOf([
111
- types.AST_NODE_TYPES.TSAsExpression,
112
- types.AST_NODE_TYPES.TSTypeAssertion,
113
- types.AST_NODE_TYPES.TSNonNullExpression,
114
- types.AST_NODE_TYPES.TSSatisfiesExpression,
115
- types.AST_NODE_TYPES.TSInstantiationExpression
138
+ const isTypeExpression = isOneOf([
139
+ __typescript_eslint_types.AST_NODE_TYPES.TSAsExpression,
140
+ __typescript_eslint_types.AST_NODE_TYPES.TSTypeAssertion,
141
+ __typescript_eslint_types.AST_NODE_TYPES.TSNonNullExpression,
142
+ __typescript_eslint_types.AST_NODE_TYPES.TSSatisfiesExpression,
143
+ __typescript_eslint_types.AST_NODE_TYPES.TSInstantiationExpression
116
144
  ]);
117
- var isTypeAssertionExpression = isOneOf([
118
- types.AST_NODE_TYPES.TSAsExpression,
119
- types.AST_NODE_TYPES.TSTypeAssertion,
120
- types.AST_NODE_TYPES.TSNonNullExpression,
121
- types.AST_NODE_TYPES.TSSatisfiesExpression
145
+ const isTypeAssertionExpression = isOneOf([
146
+ __typescript_eslint_types.AST_NODE_TYPES.TSAsExpression,
147
+ __typescript_eslint_types.AST_NODE_TYPES.TSTypeAssertion,
148
+ __typescript_eslint_types.AST_NODE_TYPES.TSNonNullExpression,
149
+ __typescript_eslint_types.AST_NODE_TYPES.TSSatisfiesExpression
122
150
  ]);
123
151
 
124
- // src/ast-expression.ts
152
+ //#endregion
153
+ //#region src/ast-expression.ts
154
+ /**
155
+ * Recursively get the inner expression until it's not a TypeExpression
156
+ * @param node - The node to get the expression from
157
+ * @returns The inner expression
158
+ */
125
159
  function getJSExpression(node) {
126
- if (isTypeExpression(node)) {
127
- return getJSExpression(node.expression);
128
- }
129
- return node;
160
+ if (isTypeExpression(node)) return getJSExpression(node.expression);
161
+ return node;
130
162
  }
131
163
  function isThisExpression(node) {
132
- return getJSExpression(node).type === types.AST_NODE_TYPES.ThisExpression;
164
+ return getJSExpression(node).type === __typescript_eslint_types.AST_NODE_TYPES.ThisExpression;
133
165
  }
166
+
167
+ //#endregion
168
+ //#region src/ast-function-id.ts
134
169
  function getFunctionId(node) {
135
- switch (true) {
136
- // function MaybeComponent() {}
137
- case ("id" in node && node.id != null):
138
- return node.id;
139
- // const whatever = function MaybeComponent() {};
140
- case (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === types.AST_NODE_TYPES.Identifier):
141
- return node.parent.id;
142
- // MaybeComponent = () => {};
143
- 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):
144
- return node.parent.left;
145
- // {MaybeComponent: () => {}}
146
- // {MaybeComponent() {}}
147
- 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):
148
- return node.parent.key;
149
- // class {MaybeComponent = () => {}}
150
- // class {MaybeComponent() {}}
151
- case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === types.AST_NODE_TYPES.Identifier):
152
- return node.parent.key;
153
- // Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
154
- //
155
- // const {MaybeComponent = () => {}} = {};
156
- // ({MaybeComponent = () => {}} = {});
157
- case (node.parent.type === types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === types.AST_NODE_TYPES.Identifier):
158
- return node.parent.left;
159
- // const MaybeComponent = (() => {})!;
160
- // const MaybeComponent = (() => {}) as FunctionComponent;
161
- // const MaybeComponent = (() => {}) satisfies FunctionComponent;
162
- case isTypeAssertionExpression(node.parent):
163
- return getFunctionId(node.parent);
164
- }
165
- return eff.unit;
170
+ switch (true) {
171
+ case "id" in node && node.id != null: return node.id;
172
+ case node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.id;
173
+ case node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.left;
174
+ case node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.key;
175
+ case isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.key;
176
+ case node.parent.type === __typescript_eslint_types.AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return node.parent.left;
177
+ case isTypeAssertionExpression(node.parent): return getFunctionId(node.parent);
178
+ }
179
+ return __eslint_react_eff.unit;
166
180
  }
181
+
182
+ //#endregion
183
+ //#region src/ast-function-init-path.ts
167
184
  function getFunctionInitPath(node) {
168
- if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) {
169
- return [node];
170
- }
171
- const { parent } = node;
172
- switch (true) {
173
- case parent.type === types.AST_NODE_TYPES.VariableDeclarator:
174
- return [parent.parent, parent, node];
175
- case (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
176
- return [parent.parent.parent, parent.parent, parent, node];
177
- case (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
178
- return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
179
- case (parent.type === types.AST_NODE_TYPES.Property && parent.parent.type === types.AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
180
- return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
181
- case (parent.type === types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration):
182
- return [parent.parent.parent, parent.parent, parent, node];
183
- case (parent.type === types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration):
184
- return [parent.parent.parent, parent.parent, parent, node];
185
- }
186
- return eff.unit;
185
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.FunctionDeclaration) return [node];
186
+ const { parent } = node;
187
+ switch (true) {
188
+ case parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator: return [
189
+ parent.parent,
190
+ parent,
191
+ node
192
+ ];
193
+ case parent.type === __typescript_eslint_types.AST_NODE_TYPES.CallExpression && parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator: return [
194
+ parent.parent.parent,
195
+ parent.parent,
196
+ parent,
197
+ node
198
+ ];
199
+ case parent.type === __typescript_eslint_types.AST_NODE_TYPES.CallExpression && parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.CallExpression && parent.parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator: return [
200
+ parent.parent.parent.parent,
201
+ parent.parent.parent,
202
+ parent.parent,
203
+ parent,
204
+ node
205
+ ];
206
+ case parent.type === __typescript_eslint_types.AST_NODE_TYPES.Property && parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.VariableDeclarator: return [
207
+ parent.parent.parent.parent,
208
+ parent.parent.parent,
209
+ parent.parent,
210
+ parent,
211
+ node
212
+ ];
213
+ case parent.type === __typescript_eslint_types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.ClassDeclaration: return [
214
+ parent.parent.parent,
215
+ parent.parent,
216
+ parent,
217
+ node
218
+ ];
219
+ case parent.type === __typescript_eslint_types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === __typescript_eslint_types.AST_NODE_TYPES.ClassDeclaration: return [
220
+ parent.parent.parent,
221
+ parent.parent,
222
+ parent,
223
+ node
224
+ ];
225
+ }
226
+ return __eslint_react_eff.unit;
187
227
  }
188
228
  function hasCallInFunctionInitPath(callName, initPath) {
189
- return initPath.some((n) => {
190
- if (n.type !== types.AST_NODE_TYPES.CallExpression) {
191
- return false;
192
- }
193
- switch (n.callee.type) {
194
- case types.AST_NODE_TYPES.Identifier:
195
- return n.callee.name === callName;
196
- case types.AST_NODE_TYPES.MemberExpression:
197
- return "name" in n.callee.property && n.callee.property.name === callName;
198
- default:
199
- return false;
200
- }
201
- });
229
+ return initPath.some((n) => {
230
+ if (n.type !== __typescript_eslint_types.AST_NODE_TYPES.CallExpression) return false;
231
+ switch (n.callee.type) {
232
+ case __typescript_eslint_types.AST_NODE_TYPES.Identifier: return n.callee.name === callName;
233
+ case __typescript_eslint_types.AST_NODE_TYPES.MemberExpression: return "name" in n.callee.property && n.callee.property.name === callName;
234
+ default: return false;
235
+ }
236
+ });
202
237
  }
238
+
239
+ //#endregion
240
+ //#region src/ast-function-is.ts
203
241
  function isEmptyFunction(node) {
204
- return node.body.type === types.AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
242
+ return node.body.type === __typescript_eslint_types.AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
205
243
  }
244
+
245
+ //#endregion
246
+ //#region src/ast-hierarchy.ts
206
247
  function findParentNode(node, test) {
207
- if (node == null) return eff.unit;
208
- let parent = node.parent;
209
- while (parent != null && parent.type !== types.AST_NODE_TYPES.Program) {
210
- if (test(parent)) {
211
- return parent;
212
- }
213
- parent = parent.parent;
214
- }
215
- return eff.unit;
248
+ if (node == null) return __eslint_react_eff.unit;
249
+ let parent = node.parent;
250
+ while (parent != null && parent.type !== __typescript_eslint_types.AST_NODE_TYPES.Program) {
251
+ if (test(parent)) return parent;
252
+ parent = parent.parent;
253
+ }
254
+ return __eslint_react_eff.unit;
216
255
  }
256
+ /**
257
+ * Get all nested identifiers in a expression like node
258
+ * @param node The node to get the nested identifiers from
259
+ * @returns All nested identifiers
260
+ */
217
261
  function getNestedIdentifiers(node) {
218
- const identifiers = [];
219
- if (node.type === types.AST_NODE_TYPES.Identifier) {
220
- identifiers.push(node);
221
- }
222
- if ("arguments" in node) {
223
- const chunk = node.arguments.map(getNestedIdentifiers).flat(1);
224
- identifiers.push(...chunk);
225
- }
226
- if ("elements" in node) {
227
- const chunk = node.elements.filter((x) => x != null).map(getNestedIdentifiers).flat(1);
228
- identifiers.push(...chunk);
229
- }
230
- if ("properties" in node) {
231
- const chunk = node.properties.map(getNestedIdentifiers).flat(1);
232
- identifiers.push(...chunk);
233
- }
234
- if ("expressions" in node) {
235
- const chunk = node.expressions.map(getNestedIdentifiers).flat(1);
236
- identifiers.push(...chunk);
237
- }
238
- if ("left" in node) {
239
- const chunk = getNestedIdentifiers(node.left);
240
- identifiers.push(...chunk);
241
- }
242
- if ("right" in node) {
243
- const chunk = getNestedIdentifiers(node.right);
244
- identifiers.push(...chunk);
245
- }
246
- if (node.type === types.AST_NODE_TYPES.Property) {
247
- const chunk = getNestedIdentifiers(node.value);
248
- identifiers.push(...chunk);
249
- }
250
- if (node.type === types.AST_NODE_TYPES.SpreadElement) {
251
- const chunk = getNestedIdentifiers(node.argument);
252
- identifiers.push(...chunk);
253
- }
254
- if (node.type === types.AST_NODE_TYPES.MemberExpression) {
255
- const chunk = getNestedIdentifiers(node.object);
256
- identifiers.push(...chunk);
257
- }
258
- if (node.type === types.AST_NODE_TYPES.UnaryExpression) {
259
- const chunk = getNestedIdentifiers(node.argument);
260
- identifiers.push(...chunk);
261
- }
262
- if (node.type === types.AST_NODE_TYPES.ChainExpression) {
263
- const chunk = getNestedIdentifiers(node.expression);
264
- identifiers.push(...chunk);
265
- }
266
- if (node.type === types.AST_NODE_TYPES.TSNonNullExpression) {
267
- const chunk = getNestedIdentifiers(node.expression);
268
- identifiers.push(...chunk);
269
- }
270
- if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
271
- const chunk = getNestedIdentifiers(node.expression);
272
- identifiers.push(...chunk);
273
- }
274
- if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) {
275
- const chunk = getNestedIdentifiers(node.expression);
276
- identifiers.push(...chunk);
277
- }
278
- return identifiers;
262
+ const identifiers = [];
263
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier) identifiers.push(node);
264
+ if ("arguments" in node) {
265
+ const chunk = node.arguments.map(getNestedIdentifiers).flat(1);
266
+ identifiers.push(...chunk);
267
+ }
268
+ if ("elements" in node) {
269
+ const chunk = node.elements.filter((x) => x != null).map(getNestedIdentifiers).flat(1);
270
+ identifiers.push(...chunk);
271
+ }
272
+ if ("properties" in node) {
273
+ const chunk = node.properties.map(getNestedIdentifiers).flat(1);
274
+ identifiers.push(...chunk);
275
+ }
276
+ if ("expressions" in node) {
277
+ const chunk = node.expressions.map(getNestedIdentifiers).flat(1);
278
+ identifiers.push(...chunk);
279
+ }
280
+ if ("left" in node) {
281
+ const chunk = getNestedIdentifiers(node.left);
282
+ identifiers.push(...chunk);
283
+ }
284
+ if ("right" in node) {
285
+ const chunk = getNestedIdentifiers(node.right);
286
+ identifiers.push(...chunk);
287
+ }
288
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Property) {
289
+ const chunk = getNestedIdentifiers(node.value);
290
+ identifiers.push(...chunk);
291
+ }
292
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.SpreadElement) {
293
+ const chunk = getNestedIdentifiers(node.argument);
294
+ identifiers.push(...chunk);
295
+ }
296
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression) {
297
+ const chunk = getNestedIdentifiers(node.object);
298
+ identifiers.push(...chunk);
299
+ }
300
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.UnaryExpression) {
301
+ const chunk = getNestedIdentifiers(node.argument);
302
+ identifiers.push(...chunk);
303
+ }
304
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.ChainExpression) {
305
+ const chunk = getNestedIdentifiers(node.expression);
306
+ identifiers.push(...chunk);
307
+ }
308
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSNonNullExpression) {
309
+ const chunk = getNestedIdentifiers(node.expression);
310
+ identifiers.push(...chunk);
311
+ }
312
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSAsExpression) {
313
+ const chunk = getNestedIdentifiers(node.expression);
314
+ identifiers.push(...chunk);
315
+ }
316
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSSatisfiesExpression) {
317
+ const chunk = getNestedIdentifiers(node.expression);
318
+ identifiers.push(...chunk);
319
+ }
320
+ return identifiers;
279
321
  }
322
+ /**
323
+ * Gets the nested return statements in the node that are within the same function
324
+ * @param node The AST node
325
+ * @returns The nested return statements in the node
326
+ */
280
327
  function getNestedReturnStatements(node) {
281
- const statements = [];
282
- const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
283
- typescriptEstree.simpleTraverse(node, {
284
- enter(node2) {
285
- if (node2.type !== types.AST_NODE_TYPES.ReturnStatement) {
286
- return;
287
- }
288
- const parentFunction = findParentNode(node2, isFunction);
289
- if (parentFunction !== boundaryNode) {
290
- return;
291
- }
292
- statements.push(node2);
293
- }
294
- });
295
- return statements;
328
+ const statements = [];
329
+ const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
330
+ (0, __typescript_eslint_typescript_estree.simpleTraverse)(node, { enter(node$1) {
331
+ if (node$1.type !== __typescript_eslint_types.AST_NODE_TYPES.ReturnStatement) return;
332
+ const parentFunction = findParentNode(node$1, isFunction);
333
+ if (parentFunction !== boundaryNode) return;
334
+ statements.push(node$1);
335
+ } });
336
+ return statements;
296
337
  }
338
+ /**
339
+ * Get all nested expressions of type T in an expression like node
340
+ * @param type The type of the expression to retrieve within the node
341
+ * @returns A partially applied function bound to a predicate of type T. The returned function can be called passing a
342
+ * node, and it will return an array of all nested expressions of type T.
343
+ */
297
344
  function getNestedExpressionsOfType(type) {
298
- const isNodeOfType = is(type);
299
- return function(node) {
300
- const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
301
- const expressions = [];
302
- if (isNodeOfType(node)) {
303
- expressions.push(node);
304
- }
305
- if ("arguments" in node) {
306
- const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
307
- expressions.push(...chunk);
308
- }
309
- if ("expression" in node && node.expression !== true && node.expression !== false) {
310
- const chunk = boundGetNestedExpressionsOfType(node.expression);
311
- expressions.push(...chunk);
312
- }
313
- if ("left" in node) {
314
- const chunk = boundGetNestedExpressionsOfType(node.left);
315
- expressions.push(...chunk);
316
- }
317
- if ("right" in node) {
318
- const chunk = boundGetNestedExpressionsOfType(node.right);
319
- expressions.push(...chunk);
320
- }
321
- if ("test" in node && node.test != null) {
322
- const chunk = boundGetNestedExpressionsOfType(node.test);
323
- expressions.push(...chunk);
324
- }
325
- if ("consequent" in node) {
326
- const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
327
- expressions.push(...chunk);
328
- }
329
- if ("alternate" in node && node.alternate != null) {
330
- const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
331
- expressions.push(...chunk);
332
- }
333
- if ("elements" in node) {
334
- const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
335
- expressions.push(...chunk);
336
- }
337
- if ("properties" in node) {
338
- const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
339
- expressions.push(...chunk);
340
- }
341
- if ("expressions" in node) {
342
- const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
343
- expressions.push(...chunk);
344
- }
345
- if (node.type === types.AST_NODE_TYPES.Property) {
346
- const chunk = boundGetNestedExpressionsOfType(node.value);
347
- expressions.push(...chunk);
348
- }
349
- if (node.type === types.AST_NODE_TYPES.SpreadElement) {
350
- const chunk = boundGetNestedExpressionsOfType(node.argument);
351
- expressions.push(...chunk);
352
- }
353
- if (node.type === types.AST_NODE_TYPES.MemberExpression) {
354
- const chunk = boundGetNestedExpressionsOfType(node.object);
355
- expressions.push(...chunk);
356
- }
357
- if (node.type === types.AST_NODE_TYPES.UnaryExpression) {
358
- const chunk = boundGetNestedExpressionsOfType(node.argument);
359
- expressions.push(...chunk);
360
- }
361
- if (node.type === types.AST_NODE_TYPES.ChainExpression) {
362
- const chunk = boundGetNestedExpressionsOfType(node.expression);
363
- expressions.push(...chunk);
364
- }
365
- if (node.type === types.AST_NODE_TYPES.TSNonNullExpression) {
366
- const chunk = boundGetNestedExpressionsOfType(node.expression);
367
- expressions.push(...chunk);
368
- }
369
- if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
370
- const chunk = boundGetNestedExpressionsOfType(node.expression);
371
- expressions.push(...chunk);
372
- }
373
- if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) {
374
- const chunk = boundGetNestedExpressionsOfType(node.expression);
375
- expressions.push(...chunk);
376
- }
377
- return expressions;
378
- };
345
+ const isNodeOfType = is(type);
346
+ return function(node) {
347
+ const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
348
+ const expressions = [];
349
+ if (isNodeOfType(node)) expressions.push(node);
350
+ if ("arguments" in node) {
351
+ const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
352
+ expressions.push(...chunk);
353
+ }
354
+ if ("expression" in node && node.expression !== true && node.expression !== false) {
355
+ const chunk = boundGetNestedExpressionsOfType(node.expression);
356
+ expressions.push(...chunk);
357
+ }
358
+ if ("left" in node) {
359
+ const chunk = boundGetNestedExpressionsOfType(node.left);
360
+ expressions.push(...chunk);
361
+ }
362
+ if ("right" in node) {
363
+ const chunk = boundGetNestedExpressionsOfType(node.right);
364
+ expressions.push(...chunk);
365
+ }
366
+ if ("test" in node && node.test != null) {
367
+ const chunk = boundGetNestedExpressionsOfType(node.test);
368
+ expressions.push(...chunk);
369
+ }
370
+ if ("consequent" in node) {
371
+ const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
372
+ expressions.push(...chunk);
373
+ }
374
+ if ("alternate" in node && node.alternate != null) {
375
+ const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
376
+ expressions.push(...chunk);
377
+ }
378
+ if ("elements" in node) {
379
+ const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
380
+ expressions.push(...chunk);
381
+ }
382
+ if ("properties" in node) {
383
+ const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
384
+ expressions.push(...chunk);
385
+ }
386
+ if ("expressions" in node) {
387
+ const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
388
+ expressions.push(...chunk);
389
+ }
390
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Property) {
391
+ const chunk = boundGetNestedExpressionsOfType(node.value);
392
+ expressions.push(...chunk);
393
+ }
394
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.SpreadElement) {
395
+ const chunk = boundGetNestedExpressionsOfType(node.argument);
396
+ expressions.push(...chunk);
397
+ }
398
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression) {
399
+ const chunk = boundGetNestedExpressionsOfType(node.object);
400
+ expressions.push(...chunk);
401
+ }
402
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.UnaryExpression) {
403
+ const chunk = boundGetNestedExpressionsOfType(node.argument);
404
+ expressions.push(...chunk);
405
+ }
406
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.ChainExpression) {
407
+ const chunk = boundGetNestedExpressionsOfType(node.expression);
408
+ expressions.push(...chunk);
409
+ }
410
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSNonNullExpression) {
411
+ const chunk = boundGetNestedExpressionsOfType(node.expression);
412
+ expressions.push(...chunk);
413
+ }
414
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSAsExpression) {
415
+ const chunk = boundGetNestedExpressionsOfType(node.expression);
416
+ expressions.push(...chunk);
417
+ }
418
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TSSatisfiesExpression) {
419
+ const chunk = boundGetNestedExpressionsOfType(node.expression);
420
+ expressions.push(...chunk);
421
+ }
422
+ return expressions;
423
+ };
379
424
  }
380
- var getNestedNewExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.NewExpression);
381
- var getNestedCallExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.CallExpression);
425
+ /**
426
+ * Get all nested new expressions in an expression like node
427
+ * @param node The node to get the nested new expressions from
428
+ * @returns All nested new expressions
429
+ */
430
+ const getNestedNewExpressions = getNestedExpressionsOfType(__typescript_eslint_types.AST_NODE_TYPES.NewExpression);
431
+ /**
432
+ * Get all nested call expressions in a expression like node
433
+ * @param node The node to get the nested call expressions from
434
+ * @returns All nested call expressions
435
+ */
436
+ const getNestedCallExpressions = getNestedExpressionsOfType(__typescript_eslint_types.AST_NODE_TYPES.CallExpression);
437
+
438
+ //#endregion
439
+ //#region src/ast-line.ts
440
+ /**
441
+ * Check if a node is multiline
442
+ * @param node The AST node to check
443
+ * @returns `true` if the node is multiline
444
+ */
382
445
  function isMultiLine(node) {
383
- return node.loc.start.line !== node.loc.end.line;
446
+ return node.loc.start.line !== node.loc.end.line;
384
447
  }
448
+ /**
449
+ * Check if a node is a line break
450
+ * @param node The AST node to check
451
+ * @returns boolean
452
+ */
385
453
  function isLineBreak(node) {
386
- return isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
454
+ return isOneOf([__typescript_eslint_types.AST_NODE_TYPES.Literal, __typescript_eslint_types.AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
387
455
  }
456
+
457
+ //#endregion
458
+ //#region src/ast-literal-is.ts
388
459
  function isLiteral(node, type) {
389
- if (node.type !== types.AST_NODE_TYPES.Literal) return false;
390
- if (type == null) return true;
391
- switch (type) {
392
- case "boolean":
393
- return typeof node.value === "boolean";
394
- case "null":
395
- return node.value === null;
396
- case "number":
397
- return typeof node.value === "number";
398
- case "regexp":
399
- return "regex" in node;
400
- case "string":
401
- return typeof node.value === "string";
402
- }
460
+ if (node.type !== __typescript_eslint_types.AST_NODE_TYPES.Literal) return false;
461
+ if (type == null) return true;
462
+ switch (type) {
463
+ case "boolean": return typeof node.value === "boolean";
464
+ case "null": return node.value === null;
465
+ case "number": return typeof node.value === "number";
466
+ case "regexp": return "regex" in node;
467
+ case "string": return typeof node.value === "string";
468
+ }
403
469
  }
404
- var isNodeEqual = eff.dual(2, (a, b) => {
405
- switch (true) {
406
- case a === b:
407
- return true;
408
- case a.type !== b.type:
409
- return false;
410
- case (a.type === types.AST_NODE_TYPES.Literal && b.type === types.AST_NODE_TYPES.Literal):
411
- return a.value === b.value;
412
- case (a.type === types.AST_NODE_TYPES.TemplateElement && b.type === types.AST_NODE_TYPES.TemplateElement):
413
- return a.value.raw === b.value.raw;
414
- case (a.type === types.AST_NODE_TYPES.TemplateLiteral && b.type === types.AST_NODE_TYPES.TemplateLiteral): {
415
- if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) {
416
- return false;
417
- }
418
- let i = a.quasis.length;
419
- while (i--) {
420
- if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) {
421
- return false;
422
- }
423
- }
424
- i = a.expressions.length;
425
- while (i--) {
426
- const exprA = a.expressions[i];
427
- const exprB = b.expressions[i];
428
- if (!isNodeEqual(exprA, exprB)) {
429
- return false;
430
- }
431
- }
432
- return true;
433
- }
434
- case (a.type === types.AST_NODE_TYPES.Identifier && b.type === types.AST_NODE_TYPES.Identifier):
435
- return a.name === b.name;
436
- case (a.type === types.AST_NODE_TYPES.PrivateIdentifier && b.type === types.AST_NODE_TYPES.PrivateIdentifier):
437
- return a.name === b.name;
438
- case (a.type === types.AST_NODE_TYPES.MemberExpression && b.type === types.AST_NODE_TYPES.MemberExpression):
439
- return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
440
- case (a.type === types.AST_NODE_TYPES.JSXAttribute && b.type === types.AST_NODE_TYPES.JSXAttribute): {
441
- if (a.name.name !== b.name.name) {
442
- return false;
443
- }
444
- if (a.value == null || b.value == null) {
445
- return a.value === b.value;
446
- }
447
- return isNodeEqual(a.value, b.value);
448
- }
449
- case (a.type === types.AST_NODE_TYPES.ThisExpression && b.type === types.AST_NODE_TYPES.ThisExpression):
450
- return true;
451
- default:
452
- return false;
453
- }
470
+
471
+ //#endregion
472
+ //#region src/ast-node-equal.ts
473
+ /**
474
+ * Determines whether node equals to another node
475
+ * @param a node to compare
476
+ * @param b node to compare
477
+ * @returns `true` if node equal
478
+ * @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
479
+ */
480
+ const isNodeEqual = (0, __eslint_react_eff.dual)(2, (a, b) => {
481
+ switch (true) {
482
+ case a === b: return true;
483
+ case a.type !== b.type: return false;
484
+ case a.type === __typescript_eslint_types.AST_NODE_TYPES.Literal && b.type === __typescript_eslint_types.AST_NODE_TYPES.Literal: return a.value === b.value;
485
+ case a.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateElement && b.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateElement: return a.value.raw === b.value.raw;
486
+ case a.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateLiteral && b.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateLiteral: {
487
+ if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) return false;
488
+ let i = a.quasis.length;
489
+ while (i--) if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) return false;
490
+ i = a.expressions.length;
491
+ while (i--) {
492
+ const exprA = a.expressions[i];
493
+ const exprB = b.expressions[i];
494
+ if (!isNodeEqual(exprA, exprB)) return false;
495
+ }
496
+ return true;
497
+ }
498
+ case a.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier && b.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier: return a.name === b.name;
499
+ case a.type === __typescript_eslint_types.AST_NODE_TYPES.PrivateIdentifier && b.type === __typescript_eslint_types.AST_NODE_TYPES.PrivateIdentifier: return a.name === b.name;
500
+ case a.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression && b.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression: return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
501
+ case a.type === __typescript_eslint_types.AST_NODE_TYPES.JSXAttribute && b.type === __typescript_eslint_types.AST_NODE_TYPES.JSXAttribute:
502
+ if (a.name.name !== b.name.name) return false;
503
+ if (a.value == null || b.value == null) return a.value === b.value;
504
+ return isNodeEqual(a.value, b.value);
505
+ case a.type === __typescript_eslint_types.AST_NODE_TYPES.ThisExpression && b.type === __typescript_eslint_types.AST_NODE_TYPES.ThisExpression: return true;
506
+ default: return false;
507
+ }
454
508
  });
509
+
510
+ //#endregion
511
+ //#region src/ast-process-env-node-env.ts
512
+ /**
513
+ * Check if the given node is a member expression that accesses `process.env.NODE_ENV`
514
+ * @param node The AST node
515
+ * @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
516
+ */
455
517
  function isProcessEnvNodeEnv(node) {
456
- return node != null && node.type === types.AST_NODE_TYPES.MemberExpression && node.object.type === types.AST_NODE_TYPES.MemberExpression && node.object.object.type === types.AST_NODE_TYPES.Identifier && node.object.object.name === "process" && node.object.property.type === types.AST_NODE_TYPES.Identifier && node.object.property.name === "env" && node.property.type === types.AST_NODE_TYPES.Identifier && node.property.name === "NODE_ENV";
518
+ return node != null && node.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression && node.object.type === __typescript_eslint_types.AST_NODE_TYPES.MemberExpression && node.object.object.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier && node.object.object.name === "process" && node.object.property.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier && node.object.property.name === "env" && node.property.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier && node.property.name === "NODE_ENV";
457
519
  }
520
+ /**
521
+ * Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal
522
+ * @param node The AST node
523
+ * @param operator The operator used in the comparison
524
+ * @param value The string literal value to compare against
525
+ * @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
526
+ */
458
527
  function isProcessEnvNodeEnvCompare(node, operator, value) {
459
- if (node == null) return false;
460
- if (node.type !== types.AST_NODE_TYPES.BinaryExpression) return false;
461
- if (node.operator !== operator) return false;
462
- if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) {
463
- return node.right.value === value;
464
- }
465
- if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) {
466
- return node.left.value === value;
467
- }
468
- return false;
528
+ if (node == null) return false;
529
+ if (node.type !== __typescript_eslint_types.AST_NODE_TYPES.BinaryExpression) return false;
530
+ if (node.operator !== operator) return false;
531
+ if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) return node.right.value === value;
532
+ if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) return node.left.value === value;
533
+ return false;
469
534
  }
535
+
536
+ //#endregion
537
+ //#region src/ast-property-name.ts
470
538
  function getPropertyName(node) {
471
- if (isTypeExpression(node)) {
472
- return getPropertyName(getJSExpression(node));
473
- }
474
- if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
475
- return node.name;
476
- }
477
- if (node.type === types.AST_NODE_TYPES.Literal) {
478
- return String(node.value);
479
- }
480
- if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
481
- return node.quasis[0]?.value.raw;
482
- }
483
- return eff.unit;
539
+ if (isTypeExpression(node)) return getPropertyName(getJSExpression(node));
540
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Identifier || node.type === __typescript_eslint_types.AST_NODE_TYPES.PrivateIdentifier) return node.name;
541
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Literal) return String(node.value);
542
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) return node.quasis[0]?.value.raw;
543
+ return __eslint_react_eff.unit;
484
544
  }
545
+
546
+ //#endregion
547
+ //#region src/ast-to-string.ts
485
548
  function getLiteralValueType(input) {
486
- if (input === null) return "null";
487
- return typeof input;
549
+ if (input === null) return "null";
550
+ return typeof input;
488
551
  }
489
552
  function toDelimiterCaseType(node, delimiter = " ") {
490
- if (node.type === types.AST_NODE_TYPES.Literal) {
491
- if ("regex" in node) {
492
- return "RegExp literal";
493
- }
494
- return `${getLiteralValueType(node.value)} literal`;
495
- }
496
- if (isJSX(node)) {
497
- return `JSX ${stringTs.toLowerCase(stringTs.delimiterCase(stringTs.replace(node.type, "JSX", ""), delimiter))}`;
498
- }
499
- return stringTs.toLowerCase(stringTs.delimiterCase(node.type, delimiter));
553
+ if (node.type === __typescript_eslint_types.AST_NODE_TYPES.Literal) {
554
+ if ("regex" in node) return "RegExp literal";
555
+ return `${getLiteralValueType(node.value)} literal`;
556
+ }
557
+ if (isJSX(node)) return `JSX ${(0, string_ts.toLowerCase)((0, string_ts.delimiterCase)((0, string_ts.replace)(node.type, "JSX", ""), delimiter))}`;
558
+ return (0, string_ts.toLowerCase)((0, string_ts.delimiterCase)(node.type, delimiter));
500
559
  }
560
+ /**
561
+ * Returns human readable node name for given AST node
562
+ * @param node AST node
563
+ * @param getText A function that returns the text of the node in the source code
564
+ * @returns Human readable node name
565
+ */
501
566
  function toString(node, getText) {
502
- switch (node.type) {
503
- case types.AST_NODE_TYPES.Identifier:
504
- case types.AST_NODE_TYPES.JSXIdentifier:
505
- case types.AST_NODE_TYPES.PrivateIdentifier:
506
- return node.name;
507
- case types.AST_NODE_TYPES.MemberExpression:
508
- case types.AST_NODE_TYPES.JSXMemberExpression:
509
- return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
510
- case types.AST_NODE_TYPES.JSXNamespacedName:
511
- return `${node.namespace.name}:${node.name.name}`;
512
- case types.AST_NODE_TYPES.JSXText:
513
- return node.value;
514
- case types.AST_NODE_TYPES.Literal:
515
- return node.raw;
516
- default:
517
- return getText(node);
518
- }
567
+ switch (node.type) {
568
+ case __typescript_eslint_types.AST_NODE_TYPES.Identifier:
569
+ case __typescript_eslint_types.AST_NODE_TYPES.JSXIdentifier:
570
+ case __typescript_eslint_types.AST_NODE_TYPES.PrivateIdentifier: return node.name;
571
+ case __typescript_eslint_types.AST_NODE_TYPES.MemberExpression:
572
+ case __typescript_eslint_types.AST_NODE_TYPES.JSXMemberExpression: return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
573
+ case __typescript_eslint_types.AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
574
+ case __typescript_eslint_types.AST_NODE_TYPES.JSXText: return node.value;
575
+ case __typescript_eslint_types.AST_NODE_TYPES.Literal: return node.raw;
576
+ default: return getText(node);
577
+ }
519
578
  }
520
579
 
580
+ //#endregion
521
581
  exports.findParentNode = findParentNode;
522
582
  exports.getArrayMethodCallbackIndexParamPosition = getArrayMethodCallbackIndexParamPosition;
523
583
  exports.getClassId = getClassId;
@@ -556,4 +616,4 @@ exports.isThisExpression = isThisExpression;
556
616
  exports.isTypeAssertionExpression = isTypeAssertionExpression;
557
617
  exports.isTypeExpression = isTypeExpression;
558
618
  exports.toDelimiterCaseType = toDelimiterCaseType;
559
- exports.toString = toString;
619
+ exports.toString = toString;