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