@eslint-react/ast 1.48.1 → 1.48.2-beta.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.d.mts +84 -2248
- package/dist/index.d.ts +84 -2248
- package/dist/index.js +194 -203
- package/dist/index.mjs +191 -199
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,59 +1,26 @@
|
|
|
1
|
-
import { or, dual, _ } from '@eslint-react/eff';
|
|
2
1
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
2
|
+
import { or, dual, _ } from '@eslint-react/eff';
|
|
3
3
|
import { ASTUtils } from '@typescript-eslint/utils';
|
|
4
|
-
import {
|
|
4
|
+
import { simpleTraverse } from '@typescript-eslint/typescript-estree';
|
|
5
5
|
import { toLowerCase, delimiterCase, replace } from 'string-ts';
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
function
|
|
9
|
-
if (node
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
parent = parent.parent;
|
|
16
|
-
}
|
|
17
|
-
return _;
|
|
18
|
-
}
|
|
19
|
-
function getFunctionInitPath(node) {
|
|
20
|
-
if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
21
|
-
return [node];
|
|
22
|
-
}
|
|
23
|
-
const { parent } = node;
|
|
24
|
-
switch (true) {
|
|
25
|
-
case parent.type === AST_NODE_TYPES.VariableDeclarator:
|
|
26
|
-
return [parent.parent, parent, node];
|
|
27
|
-
case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
|
|
28
|
-
return [parent.parent.parent, parent.parent, parent, node];
|
|
29
|
-
case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
|
|
30
|
-
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
31
|
-
case (parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
|
|
32
|
-
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
33
|
-
case (parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
|
|
34
|
-
return [parent.parent.parent, parent.parent, parent, node];
|
|
35
|
-
case (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
|
|
36
|
-
return [parent.parent.parent, parent.parent, parent, node];
|
|
37
|
-
}
|
|
38
|
-
return _;
|
|
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");
|
|
39
14
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
case AST_NODE_TYPES.Identifier:
|
|
47
|
-
return n.callee.name === callName;
|
|
48
|
-
case AST_NODE_TYPES.MemberExpression:
|
|
49
|
-
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
50
|
-
default:
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
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");
|
|
54
21
|
}
|
|
55
22
|
|
|
56
|
-
// src/
|
|
23
|
+
// src/ast-array-method-callback.ts
|
|
57
24
|
var indexParamPosition = /* @__PURE__ */ new Map([
|
|
58
25
|
["every", 1],
|
|
59
26
|
["filter", 1],
|
|
@@ -71,7 +38,7 @@ var indexParamPosition = /* @__PURE__ */ new Map([
|
|
|
71
38
|
function getArrayMethodCallbackIndexParamPosition(methodName) {
|
|
72
39
|
return indexParamPosition.get(methodName) ?? -1;
|
|
73
40
|
}
|
|
74
|
-
function
|
|
41
|
+
function getClassId(node) {
|
|
75
42
|
if (node.id != null) return node.id;
|
|
76
43
|
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
77
44
|
return node.parent.id;
|
|
@@ -222,14 +189,17 @@ var isTypeAssertionExpression = isOneOf([
|
|
|
222
189
|
AST_NODE_TYPES.TSSatisfiesExpression
|
|
223
190
|
]);
|
|
224
191
|
|
|
225
|
-
// src/
|
|
226
|
-
function
|
|
192
|
+
// src/ast-expression.ts
|
|
193
|
+
function getJSExpression(node) {
|
|
227
194
|
if (isTypeExpression(node)) {
|
|
228
|
-
return
|
|
195
|
+
return getJSExpression(node.expression);
|
|
229
196
|
}
|
|
230
197
|
return node;
|
|
231
198
|
}
|
|
232
|
-
function
|
|
199
|
+
function isThisExpression(node) {
|
|
200
|
+
return getJSExpression(node).type === AST_NODE_TYPES.ThisExpression;
|
|
201
|
+
}
|
|
202
|
+
function getFunctionId(node) {
|
|
233
203
|
switch (true) {
|
|
234
204
|
// function MaybeComponent() {}
|
|
235
205
|
case ("id" in node && node.id != null):
|
|
@@ -258,101 +228,60 @@ function getFunctionIdentifier(node) {
|
|
|
258
228
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
259
229
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
260
230
|
case isTypeAssertionExpression(node.parent):
|
|
261
|
-
return
|
|
231
|
+
return getFunctionId(node.parent);
|
|
262
232
|
}
|
|
263
233
|
return _;
|
|
264
234
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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 _;
|
|
270
255
|
}
|
|
271
|
-
function
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const expressions = [];
|
|
276
|
-
if (isNodeOfType(node)) {
|
|
277
|
-
expressions.push(node);
|
|
278
|
-
}
|
|
279
|
-
if ("arguments" in node) {
|
|
280
|
-
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
|
|
281
|
-
expressions.push(...chunk);
|
|
282
|
-
}
|
|
283
|
-
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
284
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
285
|
-
expressions.push(...chunk);
|
|
286
|
-
}
|
|
287
|
-
if ("left" in node) {
|
|
288
|
-
const chunk = boundGetNestedExpressionsOfType(node.left);
|
|
289
|
-
expressions.push(...chunk);
|
|
290
|
-
}
|
|
291
|
-
if ("right" in node) {
|
|
292
|
-
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
293
|
-
expressions.push(...chunk);
|
|
294
|
-
}
|
|
295
|
-
if ("test" in node && node.test != null) {
|
|
296
|
-
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
297
|
-
expressions.push(...chunk);
|
|
298
|
-
}
|
|
299
|
-
if ("consequent" in node) {
|
|
300
|
-
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
301
|
-
expressions.push(...chunk);
|
|
302
|
-
}
|
|
303
|
-
if ("alternate" in node && node.alternate != null) {
|
|
304
|
-
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
305
|
-
expressions.push(...chunk);
|
|
306
|
-
}
|
|
307
|
-
if ("elements" in node) {
|
|
308
|
-
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
|
|
309
|
-
expressions.push(...chunk);
|
|
310
|
-
}
|
|
311
|
-
if ("properties" in node) {
|
|
312
|
-
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
|
|
313
|
-
expressions.push(...chunk);
|
|
314
|
-
}
|
|
315
|
-
if ("expressions" in node) {
|
|
316
|
-
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
317
|
-
expressions.push(...chunk);
|
|
318
|
-
}
|
|
319
|
-
if (node.type === AST_NODE_TYPES$1.Property) {
|
|
320
|
-
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
321
|
-
expressions.push(...chunk);
|
|
322
|
-
}
|
|
323
|
-
if (node.type === AST_NODE_TYPES$1.SpreadElement) {
|
|
324
|
-
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
325
|
-
expressions.push(...chunk);
|
|
326
|
-
}
|
|
327
|
-
if (node.type === AST_NODE_TYPES$1.MemberExpression) {
|
|
328
|
-
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
329
|
-
expressions.push(...chunk);
|
|
330
|
-
}
|
|
331
|
-
if (node.type === AST_NODE_TYPES$1.UnaryExpression) {
|
|
332
|
-
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
333
|
-
expressions.push(...chunk);
|
|
334
|
-
}
|
|
335
|
-
if (node.type === AST_NODE_TYPES$1.ChainExpression) {
|
|
336
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
337
|
-
expressions.push(...chunk);
|
|
338
|
-
}
|
|
339
|
-
if (node.type === AST_NODE_TYPES$1.TSNonNullExpression) {
|
|
340
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
341
|
-
expressions.push(...chunk);
|
|
256
|
+
function hasCallInFunctionInitPath(callName, initPath) {
|
|
257
|
+
return initPath.some((n) => {
|
|
258
|
+
if (n.type !== AST_NODE_TYPES.CallExpression) {
|
|
259
|
+
return false;
|
|
342
260
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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;
|
|
346
268
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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;
|
|
350
280
|
}
|
|
351
|
-
|
|
352
|
-
}
|
|
281
|
+
parent = parent.parent;
|
|
282
|
+
}
|
|
283
|
+
return _;
|
|
353
284
|
}
|
|
354
|
-
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
|
|
355
|
-
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.CallExpression);
|
|
356
285
|
function getNestedIdentifiers(node) {
|
|
357
286
|
const identifiers = [];
|
|
358
287
|
if (node.type === AST_NODE_TYPES.Identifier) {
|
|
@@ -433,45 +362,94 @@ function getNestedReturnStatements(node) {
|
|
|
433
362
|
});
|
|
434
363
|
return statements;
|
|
435
364
|
}
|
|
436
|
-
function
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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
|
+
};
|
|
467
447
|
}
|
|
468
|
-
|
|
469
|
-
|
|
448
|
+
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
|
|
449
|
+
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
|
|
470
450
|
function isMultiLine(node) {
|
|
471
451
|
return node.loc.start.line !== node.loc.end.line;
|
|
472
452
|
}
|
|
473
|
-
|
|
474
|
-
// src/is-line-break.ts
|
|
475
453
|
function isLineBreak(node) {
|
|
476
454
|
return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
|
|
477
455
|
}
|
|
@@ -557,43 +535,57 @@ function isProcessEnvNodeEnvCompare(node, operator, value) {
|
|
|
557
535
|
}
|
|
558
536
|
return false;
|
|
559
537
|
}
|
|
560
|
-
function
|
|
561
|
-
|
|
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));
|
|
562
568
|
}
|
|
563
|
-
function
|
|
569
|
+
function toString(node, getText) {
|
|
564
570
|
switch (node.type) {
|
|
565
|
-
case AST_NODE_TYPES.CallExpression:
|
|
566
|
-
return stringify(node.callee, getText);
|
|
567
571
|
case AST_NODE_TYPES.Identifier:
|
|
572
|
+
case AST_NODE_TYPES.JSXIdentifier:
|
|
568
573
|
case AST_NODE_TYPES.PrivateIdentifier:
|
|
569
574
|
return node.name;
|
|
570
|
-
case AST_NODE_TYPES.
|
|
571
|
-
return `<${node.name}>`;
|
|
575
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
572
576
|
case AST_NODE_TYPES.JSXMemberExpression:
|
|
573
|
-
return `${
|
|
577
|
+
return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
|
|
574
578
|
case AST_NODE_TYPES.JSXNamespacedName:
|
|
575
579
|
return `${node.namespace.name}:${node.name.name}`;
|
|
576
580
|
case AST_NODE_TYPES.JSXText:
|
|
577
581
|
return node.value;
|
|
578
582
|
case AST_NODE_TYPES.Literal:
|
|
579
583
|
return node.raw;
|
|
580
|
-
case AST_NODE_TYPES.
|
|
581
|
-
return
|
|
584
|
+
case AST_NODE_TYPES.CallExpression:
|
|
585
|
+
return toString(node.callee, getText);
|
|
582
586
|
default:
|
|
583
587
|
return getText(node);
|
|
584
588
|
}
|
|
585
589
|
}
|
|
586
|
-
function toReadableNodeType(node) {
|
|
587
|
-
if (node.type === AST_NODE_TYPES.Literal) {
|
|
588
|
-
if ("regex" in node) {
|
|
589
|
-
return "RegExp literal";
|
|
590
|
-
}
|
|
591
|
-
return `${getLiteralValueType(node.value)} literal`;
|
|
592
|
-
}
|
|
593
|
-
if (isJSX(node)) {
|
|
594
|
-
return `JSX ${toLowerCase(delimiterCase(replace(node.type, "JSX", ""), " "))}`;
|
|
595
|
-
}
|
|
596
|
-
return toLowerCase(delimiterCase(node.type, " "));
|
|
597
|
-
}
|
|
598
590
|
|
|
599
|
-
export { findParentNode, getArrayMethodCallbackIndexParamPosition,
|
|
591
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "1.48.
|
|
3
|
+
"version": "1.48.2-beta.2",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@typescript-eslint/utils": "^8.30.1",
|
|
41
41
|
"string-ts": "^2.2.1",
|
|
42
42
|
"ts-pattern": "^5.7.0",
|
|
43
|
-
"@eslint-react/eff": "1.48.
|
|
43
|
+
"@eslint-react/eff": "1.48.2-beta.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsup": "^8.4.0",
|