@eslint-react/ast 2.0.0-next.0 → 2.0.0-next.2

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 DELETED
@@ -1,589 +0,0 @@
1
- import { AST_NODE_TYPES } from '@typescript-eslint/types';
2
- import { or, dual, _ } 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';
6
-
7
- // src/ast-array-method.ts
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");
14
- }
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");
21
- }
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]
37
- ]);
38
- function getArrayMethodCallbackIndexParamPosition(methodName) {
39
- return indexParamPosition.get(methodName) ?? -1;
40
- }
41
- 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 _;
47
- }
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
65
- ]);
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
70
- ]);
71
- var isLoop = isOneOf([
72
- AST_NODE_TYPES.DoWhileStatement,
73
- AST_NODE_TYPES.ForInStatement,
74
- AST_NODE_TYPES.ForOfStatement,
75
- AST_NODE_TYPES.ForStatement,
76
- AST_NODE_TYPES.WhileStatement
77
- ]);
78
- var isControlFlow = or(
79
- isLoop,
80
- isOneOf([
81
- AST_NODE_TYPES.IfStatement,
82
- AST_NODE_TYPES.SwitchStatement
83
- ])
84
- );
85
- var isConditional = or(
86
- isControlFlow,
87
- isOneOf([
88
- AST_NODE_TYPES.LogicalExpression,
89
- AST_NODE_TYPES.ConditionalExpression
90
- ])
91
- );
92
- var isArrayTupleType = isOneOf([AST_NODE_TYPES.TSArrayType, AST_NODE_TYPES.TSTupleType]);
93
- var isProperty = isOneOf([
94
- AST_NODE_TYPES.PropertyDefinition,
95
- AST_NODE_TYPES.TSIndexSignature,
96
- AST_NODE_TYPES.TSParameterProperty,
97
- AST_NODE_TYPES.TSPropertySignature
98
- ]);
99
- var isJSXElement = is(AST_NODE_TYPES.JSXElement);
100
- var isJSXFragment = is(AST_NODE_TYPES.JSXFragment);
101
- var isJSXTagNameExpression = isOneOf([
102
- AST_NODE_TYPES.JSXIdentifier,
103
- AST_NODE_TYPES.JSXMemberExpression,
104
- AST_NODE_TYPES.JSXNamespacedName
105
- ]);
106
- var isJSX = isOneOf([
107
- AST_NODE_TYPES.JSXAttribute,
108
- AST_NODE_TYPES.JSXClosingElement,
109
- AST_NODE_TYPES.JSXClosingFragment,
110
- AST_NODE_TYPES.JSXElement,
111
- AST_NODE_TYPES.JSXEmptyExpression,
112
- AST_NODE_TYPES.JSXExpressionContainer,
113
- AST_NODE_TYPES.JSXFragment,
114
- AST_NODE_TYPES.JSXIdentifier,
115
- AST_NODE_TYPES.JSXMemberExpression,
116
- AST_NODE_TYPES.JSXNamespacedName,
117
- AST_NODE_TYPES.JSXOpeningElement,
118
- AST_NODE_TYPES.JSXOpeningFragment,
119
- AST_NODE_TYPES.JSXSpreadAttribute,
120
- AST_NODE_TYPES.JSXSpreadChild,
121
- AST_NODE_TYPES.JSXText
122
- ]);
123
- var isDestructuringPattern = isOneOf([
124
- AST_NODE_TYPES.ArrayPattern,
125
- AST_NODE_TYPES.AssignmentPattern,
126
- AST_NODE_TYPES.ObjectPattern,
127
- AST_NODE_TYPES.RestElement
128
- ]);
129
- var isTypeDeclaration = isOneOf([
130
- AST_NODE_TYPES.TSInterfaceDeclaration,
131
- AST_NODE_TYPES.TSTypeAliasDeclaration
132
- ]);
133
- var isLeftHandSideExpression = isOneOf([
134
- AST_NODE_TYPES.ArrayExpression,
135
- AST_NODE_TYPES.ArrayPattern,
136
- AST_NODE_TYPES.ArrowFunctionExpression,
137
- AST_NODE_TYPES.CallExpression,
138
- AST_NODE_TYPES.ClassExpression,
139
- AST_NODE_TYPES.FunctionExpression,
140
- AST_NODE_TYPES.Identifier,
141
- AST_NODE_TYPES.JSXElement,
142
- AST_NODE_TYPES.JSXFragment,
143
- AST_NODE_TYPES.Literal,
144
- AST_NODE_TYPES.TemplateLiteral,
145
- AST_NODE_TYPES.MemberExpression,
146
- AST_NODE_TYPES.MetaProperty,
147
- AST_NODE_TYPES.ObjectExpression,
148
- AST_NODE_TYPES.ObjectPattern,
149
- AST_NODE_TYPES.SequenceExpression,
150
- AST_NODE_TYPES.Super,
151
- AST_NODE_TYPES.TaggedTemplateExpression,
152
- AST_NODE_TYPES.ThisExpression
153
- ]);
154
- var isLeftHandSideExpressionType = isOneOf([
155
- AST_NODE_TYPES.ArrayExpression,
156
- AST_NODE_TYPES.ArrayPattern,
157
- AST_NODE_TYPES.ArrowFunctionExpression,
158
- AST_NODE_TYPES.CallExpression,
159
- AST_NODE_TYPES.ClassExpression,
160
- AST_NODE_TYPES.FunctionExpression,
161
- AST_NODE_TYPES.Identifier,
162
- AST_NODE_TYPES.JSXElement,
163
- AST_NODE_TYPES.JSXFragment,
164
- AST_NODE_TYPES.Literal,
165
- AST_NODE_TYPES.TemplateLiteral,
166
- AST_NODE_TYPES.MemberExpression,
167
- AST_NODE_TYPES.MetaProperty,
168
- AST_NODE_TYPES.ObjectExpression,
169
- AST_NODE_TYPES.ObjectPattern,
170
- AST_NODE_TYPES.SequenceExpression,
171
- AST_NODE_TYPES.Super,
172
- AST_NODE_TYPES.TaggedTemplateExpression,
173
- AST_NODE_TYPES.ThisExpression,
174
- AST_NODE_TYPES.TSAsExpression,
175
- AST_NODE_TYPES.TSNonNullExpression,
176
- AST_NODE_TYPES.TSTypeAssertion
177
- ]);
178
- var isTypeExpression = isOneOf([
179
- AST_NODE_TYPES.TSAsExpression,
180
- AST_NODE_TYPES.TSTypeAssertion,
181
- AST_NODE_TYPES.TSNonNullExpression,
182
- AST_NODE_TYPES.TSSatisfiesExpression,
183
- AST_NODE_TYPES.TSInstantiationExpression
184
- ]);
185
- var isTypeAssertionExpression = isOneOf([
186
- AST_NODE_TYPES.TSAsExpression,
187
- AST_NODE_TYPES.TSTypeAssertion,
188
- AST_NODE_TYPES.TSNonNullExpression,
189
- AST_NODE_TYPES.TSSatisfiesExpression
190
- ]);
191
-
192
- // src/ast-expression.ts
193
- function getJSExpression(node) {
194
- if (isTypeExpression(node)) {
195
- return getJSExpression(node.expression);
196
- }
197
- return node;
198
- }
199
- function isThisExpression(node) {
200
- return getJSExpression(node).type === AST_NODE_TYPES.ThisExpression;
201
- }
202
- function getFunctionId(node) {
203
- switch (true) {
204
- // function MaybeComponent() {}
205
- case ("id" in node && node.id != null):
206
- return node.id;
207
- // const whatever = function MaybeComponent() {};
208
- case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
209
- return node.parent.id;
210
- // MaybeComponent = () => {};
211
- case (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier):
212
- return node.parent.left;
213
- // {MaybeComponent: () => {}}
214
- // {MaybeComponent() {}}
215
- case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
216
- return node.parent.key;
217
- // class {MaybeComponent = () => {}}
218
- // class {MaybeComponent() {}}
219
- case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
220
- return node.parent.key;
221
- // Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
222
- //
223
- // const {MaybeComponent = () => {}} = {};
224
- // ({MaybeComponent = () => {}} = {});
225
- case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
226
- return node.parent.left;
227
- // const MaybeComponent = (() => {})!;
228
- // const MaybeComponent = (() => {}) as FunctionComponent;
229
- // const MaybeComponent = (() => {}) satisfies FunctionComponent;
230
- case isTypeAssertionExpression(node.parent):
231
- return getFunctionId(node.parent);
232
- }
233
- return _;
234
- }
235
- function getFunctionInitPath(node) {
236
- if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
237
- return [node];
238
- }
239
- const { parent } = node;
240
- switch (true) {
241
- case parent.type === AST_NODE_TYPES.VariableDeclarator:
242
- return [parent.parent, parent, node];
243
- case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
244
- return [parent.parent.parent, parent.parent, parent, node];
245
- case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
246
- return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
247
- case (parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
248
- return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
249
- case (parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
250
- return [parent.parent.parent, parent.parent, parent, node];
251
- case (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
252
- return [parent.parent.parent, parent.parent, parent, node];
253
- }
254
- return _;
255
- }
256
- function hasCallInFunctionInitPath(callName, initPath) {
257
- return initPath.some((n) => {
258
- if (n.type !== AST_NODE_TYPES.CallExpression) {
259
- return false;
260
- }
261
- switch (n.callee.type) {
262
- case AST_NODE_TYPES.Identifier:
263
- return n.callee.name === callName;
264
- case AST_NODE_TYPES.MemberExpression:
265
- return "name" in n.callee.property && n.callee.property.name === callName;
266
- default:
267
- return false;
268
- }
269
- });
270
- }
271
- function isEmptyFunction(node) {
272
- return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
273
- }
274
- function findParentNode(node, test) {
275
- if (node == null) return _;
276
- let parent = node.parent;
277
- while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
278
- if (test(parent)) {
279
- return parent;
280
- }
281
- parent = parent.parent;
282
- }
283
- return _;
284
- }
285
- function getNestedIdentifiers(node) {
286
- const identifiers = [];
287
- if (node.type === AST_NODE_TYPES.Identifier) {
288
- identifiers.push(node);
289
- }
290
- if ("arguments" in node) {
291
- const chunk = node.arguments.map(getNestedIdentifiers).flat(1);
292
- identifiers.push(...chunk);
293
- }
294
- if ("elements" in node) {
295
- const chunk = node.elements.filter((x) => x != null).map(getNestedIdentifiers).flat(1);
296
- identifiers.push(...chunk);
297
- }
298
- if ("properties" in node) {
299
- const chunk = node.properties.map(getNestedIdentifiers).flat(1);
300
- identifiers.push(...chunk);
301
- }
302
- if ("expressions" in node) {
303
- const chunk = node.expressions.map(getNestedIdentifiers).flat(1);
304
- identifiers.push(...chunk);
305
- }
306
- if ("left" in node) {
307
- const chunk = getNestedIdentifiers(node.left);
308
- identifiers.push(...chunk);
309
- }
310
- if ("right" in node) {
311
- const chunk = getNestedIdentifiers(node.right);
312
- identifiers.push(...chunk);
313
- }
314
- if (node.type === AST_NODE_TYPES.Property) {
315
- const chunk = getNestedIdentifiers(node.value);
316
- identifiers.push(...chunk);
317
- }
318
- if (node.type === AST_NODE_TYPES.SpreadElement) {
319
- const chunk = getNestedIdentifiers(node.argument);
320
- identifiers.push(...chunk);
321
- }
322
- if (node.type === AST_NODE_TYPES.MemberExpression) {
323
- const chunk = getNestedIdentifiers(node.object);
324
- identifiers.push(...chunk);
325
- }
326
- if (node.type === AST_NODE_TYPES.UnaryExpression) {
327
- const chunk = getNestedIdentifiers(node.argument);
328
- identifiers.push(...chunk);
329
- }
330
- if (node.type === AST_NODE_TYPES.ChainExpression) {
331
- const chunk = getNestedIdentifiers(node.expression);
332
- identifiers.push(...chunk);
333
- }
334
- if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
335
- const chunk = getNestedIdentifiers(node.expression);
336
- identifiers.push(...chunk);
337
- }
338
- if (node.type === AST_NODE_TYPES.TSAsExpression) {
339
- const chunk = getNestedIdentifiers(node.expression);
340
- identifiers.push(...chunk);
341
- }
342
- if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
343
- const chunk = getNestedIdentifiers(node.expression);
344
- identifiers.push(...chunk);
345
- }
346
- return identifiers;
347
- }
348
- function getNestedReturnStatements(node) {
349
- const statements = [];
350
- const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
351
- simpleTraverse(node, {
352
- enter(node2) {
353
- if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
354
- return;
355
- }
356
- const parentFunction = findParentNode(node2, isFunction);
357
- if (parentFunction !== boundaryNode) {
358
- return;
359
- }
360
- statements.push(node2);
361
- }
362
- });
363
- return statements;
364
- }
365
- function getNestedExpressionsOfType(type) {
366
- const isNodeOfType = is(type);
367
- return function(node) {
368
- const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
369
- const expressions = [];
370
- if (isNodeOfType(node)) {
371
- expressions.push(node);
372
- }
373
- if ("arguments" in node) {
374
- const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
375
- expressions.push(...chunk);
376
- }
377
- if ("expression" in node && node.expression !== true && node.expression !== false) {
378
- const chunk = boundGetNestedExpressionsOfType(node.expression);
379
- expressions.push(...chunk);
380
- }
381
- if ("left" in node) {
382
- const chunk = boundGetNestedExpressionsOfType(node.left);
383
- expressions.push(...chunk);
384
- }
385
- if ("right" in node) {
386
- const chunk = boundGetNestedExpressionsOfType(node.right);
387
- expressions.push(...chunk);
388
- }
389
- if ("test" in node && node.test != null) {
390
- const chunk = boundGetNestedExpressionsOfType(node.test);
391
- expressions.push(...chunk);
392
- }
393
- if ("consequent" in node) {
394
- const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
395
- expressions.push(...chunk);
396
- }
397
- if ("alternate" in node && node.alternate != null) {
398
- const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
399
- expressions.push(...chunk);
400
- }
401
- if ("elements" in node) {
402
- const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
403
- expressions.push(...chunk);
404
- }
405
- if ("properties" in node) {
406
- const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
407
- expressions.push(...chunk);
408
- }
409
- if ("expressions" in node) {
410
- const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
411
- expressions.push(...chunk);
412
- }
413
- if (node.type === AST_NODE_TYPES.Property) {
414
- const chunk = boundGetNestedExpressionsOfType(node.value);
415
- expressions.push(...chunk);
416
- }
417
- if (node.type === AST_NODE_TYPES.SpreadElement) {
418
- const chunk = boundGetNestedExpressionsOfType(node.argument);
419
- expressions.push(...chunk);
420
- }
421
- if (node.type === AST_NODE_TYPES.MemberExpression) {
422
- const chunk = boundGetNestedExpressionsOfType(node.object);
423
- expressions.push(...chunk);
424
- }
425
- if (node.type === AST_NODE_TYPES.UnaryExpression) {
426
- const chunk = boundGetNestedExpressionsOfType(node.argument);
427
- expressions.push(...chunk);
428
- }
429
- if (node.type === AST_NODE_TYPES.ChainExpression) {
430
- const chunk = boundGetNestedExpressionsOfType(node.expression);
431
- expressions.push(...chunk);
432
- }
433
- if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
434
- const chunk = boundGetNestedExpressionsOfType(node.expression);
435
- expressions.push(...chunk);
436
- }
437
- if (node.type === AST_NODE_TYPES.TSAsExpression) {
438
- const chunk = boundGetNestedExpressionsOfType(node.expression);
439
- expressions.push(...chunk);
440
- }
441
- if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
442
- const chunk = boundGetNestedExpressionsOfType(node.expression);
443
- expressions.push(...chunk);
444
- }
445
- return expressions;
446
- };
447
- }
448
- var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
449
- var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
450
- function isMultiLine(node) {
451
- return node.loc.start.line !== node.loc.end.line;
452
- }
453
- function isLineBreak(node) {
454
- return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
455
- }
456
- function isLiteral(node, type) {
457
- if (node.type !== AST_NODE_TYPES.Literal) return false;
458
- if (type == null) return true;
459
- switch (type) {
460
- case "boolean":
461
- return typeof node.value === "boolean";
462
- case "null":
463
- return node.value === null;
464
- case "number":
465
- return typeof node.value === "number";
466
- case "regexp":
467
- return "regex" in node;
468
- case "string":
469
- return typeof node.value === "string";
470
- }
471
- }
472
- var isNodeEqual = dual(2, (a, b) => {
473
- switch (true) {
474
- case a === b:
475
- return true;
476
- case a.type !== b.type:
477
- return false;
478
- case (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal):
479
- return a.value === b.value;
480
- case (a.type === AST_NODE_TYPES.TemplateElement && b.type === AST_NODE_TYPES.TemplateElement):
481
- return a.value.raw === b.value.raw;
482
- case (a.type === AST_NODE_TYPES.TemplateLiteral && b.type === AST_NODE_TYPES.TemplateLiteral): {
483
- if (a.quasis.length !== b.quasis.length || a.expressions.length !== b.expressions.length) {
484
- return false;
485
- }
486
- let i = a.quasis.length;
487
- while (i--) {
488
- if (a.quasis[i]?.value.raw !== b.quasis[i]?.value.raw) {
489
- return false;
490
- }
491
- }
492
- i = a.expressions.length;
493
- while (i--) {
494
- const exprA = a.expressions[i];
495
- const exprB = b.expressions[i];
496
- if (!isNodeEqual(exprA, exprB)) {
497
- return false;
498
- }
499
- }
500
- return true;
501
- }
502
- case (a.type === AST_NODE_TYPES.Identifier && b.type === AST_NODE_TYPES.Identifier):
503
- return a.name === b.name;
504
- case (a.type === AST_NODE_TYPES.PrivateIdentifier && b.type === AST_NODE_TYPES.PrivateIdentifier):
505
- return a.name === b.name;
506
- case (a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression):
507
- return isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object);
508
- case (a.type === AST_NODE_TYPES.JSXAttribute && b.type === AST_NODE_TYPES.JSXAttribute): {
509
- if (a.name.name !== b.name.name) {
510
- return false;
511
- }
512
- if (a.value == null || b.value == null) {
513
- return a.value === b.value;
514
- }
515
- return isNodeEqual(a.value, b.value);
516
- }
517
- case (a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression):
518
- return true;
519
- default:
520
- return false;
521
- }
522
- });
523
- function isProcessEnvNodeEnv(node) {
524
- 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";
525
- }
526
- function isProcessEnvNodeEnvCompare(node, operator, value) {
527
- if (node == null) return false;
528
- if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
529
- if (node.operator !== operator) return false;
530
- if (isProcessEnvNodeEnv(node.left) && isLiteral(node.right, "string")) {
531
- return node.right.value === value;
532
- }
533
- if (isLiteral(node.left, "string") && isProcessEnvNodeEnv(node.right)) {
534
- return node.left.value === value;
535
- }
536
- return false;
537
- }
538
- function getPropertyName(node) {
539
- if (isTypeExpression(node)) {
540
- return getPropertyName(getJSExpression(node));
541
- }
542
- if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
543
- return node.name;
544
- }
545
- if (node.type === AST_NODE_TYPES.Literal) {
546
- return String(node.value);
547
- }
548
- if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
549
- return node.quasis[0]?.value.raw;
550
- }
551
- return _;
552
- }
553
- function getLiteralValueType(input) {
554
- if (input === null) return "null";
555
- return typeof input;
556
- }
557
- function toDelimiterCaseType(node, delimiter = " ") {
558
- if (node.type === AST_NODE_TYPES.Literal) {
559
- if ("regex" in node) {
560
- return "RegExp literal";
561
- }
562
- return `${getLiteralValueType(node.value)} literal`;
563
- }
564
- if (isJSX(node)) {
565
- return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), delimiter))}`;
566
- }
567
- return toLowerCase(delimiterCase(node.type, delimiter));
568
- }
569
- function toString(node, getText) {
570
- switch (node.type) {
571
- case AST_NODE_TYPES.Identifier:
572
- case AST_NODE_TYPES.JSXIdentifier:
573
- case AST_NODE_TYPES.PrivateIdentifier:
574
- return node.name;
575
- case AST_NODE_TYPES.MemberExpression:
576
- case AST_NODE_TYPES.JSXMemberExpression:
577
- return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
578
- case AST_NODE_TYPES.JSXNamespacedName:
579
- return `${node.namespace.name}:${node.name.name}`;
580
- case AST_NODE_TYPES.JSXText:
581
- return node.value;
582
- case AST_NODE_TYPES.Literal:
583
- return node.raw;
584
- default:
585
- return getText(node);
586
- }
587
- }
588
-
589
- export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterCaseType, toString };