@eslint-react/ast 1.48.1 → 1.48.2-beta.0
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 +104 -2260
- package/dist/index.d.ts +104 -2260
- package/dist/index.js +167 -174
- package/dist/index.mjs +167 -173
- 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],
|
|
@@ -222,54 +189,18 @@ 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
|
|
233
|
-
|
|
234
|
-
// function MaybeComponent() {}
|
|
235
|
-
case ("id" in node && node.id != null):
|
|
236
|
-
return node.id;
|
|
237
|
-
// const whatever = function MaybeComponent() {};
|
|
238
|
-
case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
|
|
239
|
-
return node.parent.id;
|
|
240
|
-
// MaybeComponent = () => {};
|
|
241
|
-
case (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
242
|
-
return node.parent.left;
|
|
243
|
-
// {MaybeComponent: () => {}}
|
|
244
|
-
// {MaybeComponent() {}}
|
|
245
|
-
case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
246
|
-
return node.parent.key;
|
|
247
|
-
// class {MaybeComponent = () => {}}
|
|
248
|
-
// class {MaybeComponent() {}}
|
|
249
|
-
case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
250
|
-
return node.parent.key;
|
|
251
|
-
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
252
|
-
//
|
|
253
|
-
// const {MaybeComponent = () => {}} = {};
|
|
254
|
-
// ({MaybeComponent = () => {}} = {});
|
|
255
|
-
case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
256
|
-
return node.parent.left;
|
|
257
|
-
// const MaybeComponent = (() => {})!;
|
|
258
|
-
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
259
|
-
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
260
|
-
case isTypeAssertionExpression(node.parent):
|
|
261
|
-
return getFunctionIdentifier(node.parent);
|
|
262
|
-
}
|
|
263
|
-
return _;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// src/get-literal-value-type.ts
|
|
267
|
-
function getLiteralValueType(input) {
|
|
268
|
-
if (input === null) return "null";
|
|
269
|
-
return typeof input;
|
|
199
|
+
function isThisExpression(node) {
|
|
200
|
+
return getJSExpression(node).type === AST_NODE_TYPES.ThisExpression;
|
|
270
201
|
}
|
|
271
202
|
function getNestedExpressionsOfType(type) {
|
|
272
|
-
const isNodeOfType =
|
|
203
|
+
const isNodeOfType = is(type);
|
|
273
204
|
return function(node) {
|
|
274
205
|
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
|
|
275
206
|
const expressions = [];
|
|
@@ -316,43 +247,126 @@ function getNestedExpressionsOfType(type) {
|
|
|
316
247
|
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
317
248
|
expressions.push(...chunk);
|
|
318
249
|
}
|
|
319
|
-
if (node.type === AST_NODE_TYPES
|
|
250
|
+
if (node.type === AST_NODE_TYPES.Property) {
|
|
320
251
|
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
321
252
|
expressions.push(...chunk);
|
|
322
253
|
}
|
|
323
|
-
if (node.type === AST_NODE_TYPES
|
|
254
|
+
if (node.type === AST_NODE_TYPES.SpreadElement) {
|
|
324
255
|
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
325
256
|
expressions.push(...chunk);
|
|
326
257
|
}
|
|
327
|
-
if (node.type === AST_NODE_TYPES
|
|
258
|
+
if (node.type === AST_NODE_TYPES.MemberExpression) {
|
|
328
259
|
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
329
260
|
expressions.push(...chunk);
|
|
330
261
|
}
|
|
331
|
-
if (node.type === AST_NODE_TYPES
|
|
262
|
+
if (node.type === AST_NODE_TYPES.UnaryExpression) {
|
|
332
263
|
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
333
264
|
expressions.push(...chunk);
|
|
334
265
|
}
|
|
335
|
-
if (node.type === AST_NODE_TYPES
|
|
266
|
+
if (node.type === AST_NODE_TYPES.ChainExpression) {
|
|
336
267
|
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
337
268
|
expressions.push(...chunk);
|
|
338
269
|
}
|
|
339
|
-
if (node.type === AST_NODE_TYPES
|
|
270
|
+
if (node.type === AST_NODE_TYPES.TSNonNullExpression) {
|
|
340
271
|
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
341
272
|
expressions.push(...chunk);
|
|
342
273
|
}
|
|
343
|
-
if (node.type === AST_NODE_TYPES
|
|
274
|
+
if (node.type === AST_NODE_TYPES.TSAsExpression) {
|
|
344
275
|
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
345
276
|
expressions.push(...chunk);
|
|
346
277
|
}
|
|
347
|
-
if (node.type === AST_NODE_TYPES
|
|
278
|
+
if (node.type === AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
348
279
|
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
349
280
|
expressions.push(...chunk);
|
|
350
281
|
}
|
|
351
282
|
return expressions;
|
|
352
283
|
};
|
|
353
284
|
}
|
|
354
|
-
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES
|
|
355
|
-
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES
|
|
285
|
+
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.NewExpression);
|
|
286
|
+
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES.CallExpression);
|
|
287
|
+
function getFunctionIdentifier(node) {
|
|
288
|
+
switch (true) {
|
|
289
|
+
// function MaybeComponent() {}
|
|
290
|
+
case ("id" in node && node.id != null):
|
|
291
|
+
return node.id;
|
|
292
|
+
// const whatever = function MaybeComponent() {};
|
|
293
|
+
case (node.parent.type === AST_NODE_TYPES.VariableDeclarator && node.parent.init === node && node.parent.id.type === AST_NODE_TYPES.Identifier):
|
|
294
|
+
return node.parent.id;
|
|
295
|
+
// MaybeComponent = () => {};
|
|
296
|
+
case (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.right === node && node.parent.operator === "=" && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
297
|
+
return node.parent.left;
|
|
298
|
+
// {MaybeComponent: () => {}}
|
|
299
|
+
// {MaybeComponent() {}}
|
|
300
|
+
case (node.parent.type === AST_NODE_TYPES.Property && node.parent.value === node && !node.parent.computed && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
301
|
+
return node.parent.key;
|
|
302
|
+
// class {MaybeComponent = () => {}}
|
|
303
|
+
// class {MaybeComponent() {}}
|
|
304
|
+
case (isMethodOrProperty(node.parent) && node.parent.value === node && node.parent.key.type === AST_NODE_TYPES.Identifier):
|
|
305
|
+
return node.parent.key;
|
|
306
|
+
// Follow spec convention for `IsAnonymousFunctionDefinition()` usage.
|
|
307
|
+
//
|
|
308
|
+
// const {MaybeComponent = () => {}} = {};
|
|
309
|
+
// ({MaybeComponent = () => {}} = {});
|
|
310
|
+
case (node.parent.type === AST_NODE_TYPES.AssignmentPattern && node.parent.right === node && node.parent.left.type === AST_NODE_TYPES.Identifier):
|
|
311
|
+
return node.parent.left;
|
|
312
|
+
// const MaybeComponent = (() => {})!;
|
|
313
|
+
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
314
|
+
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
315
|
+
case isTypeAssertionExpression(node.parent):
|
|
316
|
+
return getFunctionIdentifier(node.parent);
|
|
317
|
+
}
|
|
318
|
+
return _;
|
|
319
|
+
}
|
|
320
|
+
function getFunctionInitPath(node) {
|
|
321
|
+
if (node.type === AST_NODE_TYPES.FunctionDeclaration) {
|
|
322
|
+
return [node];
|
|
323
|
+
}
|
|
324
|
+
const { parent } = node;
|
|
325
|
+
switch (true) {
|
|
326
|
+
case parent.type === AST_NODE_TYPES.VariableDeclarator:
|
|
327
|
+
return [parent.parent, parent, node];
|
|
328
|
+
case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
|
|
329
|
+
return [parent.parent.parent, parent.parent, parent, node];
|
|
330
|
+
case (parent.type === AST_NODE_TYPES.CallExpression && parent.parent.type === AST_NODE_TYPES.CallExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
|
|
331
|
+
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
332
|
+
case (parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator):
|
|
333
|
+
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
334
|
+
case (parent.type === AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
|
|
335
|
+
return [parent.parent.parent, parent.parent, parent, node];
|
|
336
|
+
case (parent.type === AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === AST_NODE_TYPES.ClassDeclaration):
|
|
337
|
+
return [parent.parent.parent, parent.parent, parent, node];
|
|
338
|
+
}
|
|
339
|
+
return _;
|
|
340
|
+
}
|
|
341
|
+
function hasCallInFunctionInitPath(callName, initPath) {
|
|
342
|
+
return initPath.some((n) => {
|
|
343
|
+
if (n.type !== AST_NODE_TYPES.CallExpression) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
switch (n.callee.type) {
|
|
347
|
+
case AST_NODE_TYPES.Identifier:
|
|
348
|
+
return n.callee.name === callName;
|
|
349
|
+
case AST_NODE_TYPES.MemberExpression:
|
|
350
|
+
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
351
|
+
default:
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
function isEmptyFunction(node) {
|
|
357
|
+
return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
358
|
+
}
|
|
359
|
+
function findParentNode(node, test) {
|
|
360
|
+
if (node == null) return _;
|
|
361
|
+
let parent = node.parent;
|
|
362
|
+
while (parent != null && parent.type !== AST_NODE_TYPES.Program) {
|
|
363
|
+
if (test(parent)) {
|
|
364
|
+
return parent;
|
|
365
|
+
}
|
|
366
|
+
parent = parent.parent;
|
|
367
|
+
}
|
|
368
|
+
return _;
|
|
369
|
+
}
|
|
356
370
|
function getNestedIdentifiers(node) {
|
|
357
371
|
const identifiers = [];
|
|
358
372
|
if (node.type === AST_NODE_TYPES.Identifier) {
|
|
@@ -416,62 +430,9 @@ function getNestedIdentifiers(node) {
|
|
|
416
430
|
}
|
|
417
431
|
return identifiers;
|
|
418
432
|
}
|
|
419
|
-
function getNestedReturnStatements(node) {
|
|
420
|
-
const statements = [];
|
|
421
|
-
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
422
|
-
simpleTraverse(node, {
|
|
423
|
-
enter(node2) {
|
|
424
|
-
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
const parentFunction = findParentNode(node2, isFunction);
|
|
428
|
-
if (parentFunction !== boundaryNode) {
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
statements.push(node2);
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
return statements;
|
|
435
|
-
}
|
|
436
|
-
function getPropertyName(node) {
|
|
437
|
-
if (isTypeExpression(node)) {
|
|
438
|
-
return getPropertyName(getEcmaExpression(node));
|
|
439
|
-
}
|
|
440
|
-
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
441
|
-
return node.name;
|
|
442
|
-
}
|
|
443
|
-
if (node.type === AST_NODE_TYPES.Literal) {
|
|
444
|
-
return String(node.value);
|
|
445
|
-
}
|
|
446
|
-
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
447
|
-
return node.quasis[0]?.value.raw;
|
|
448
|
-
}
|
|
449
|
-
return _;
|
|
450
|
-
}
|
|
451
|
-
function isArrayFromCall(node, loose = true) {
|
|
452
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
453
|
-
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
454
|
-
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
455
|
-
const name = node.callee.property.name;
|
|
456
|
-
return name === "from" || loose && name.startsWith("from");
|
|
457
|
-
}
|
|
458
|
-
function isArrayMapCall(node, loose = true) {
|
|
459
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
460
|
-
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
461
|
-
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false;
|
|
462
|
-
const name = node.callee.property.name;
|
|
463
|
-
return name === "map" || loose && name.endsWith("Map");
|
|
464
|
-
}
|
|
465
|
-
function isEmptyFunction(node) {
|
|
466
|
-
return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
// src/is-multi-line.ts
|
|
470
433
|
function isMultiLine(node) {
|
|
471
434
|
return node.loc.start.line !== node.loc.end.line;
|
|
472
435
|
}
|
|
473
|
-
|
|
474
|
-
// src/is-line-break.ts
|
|
475
436
|
function isLineBreak(node) {
|
|
476
437
|
return isOneOf([AST_NODE_TYPES.Literal, AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
|
|
477
438
|
}
|
|
@@ -557,20 +518,65 @@ function isProcessEnvNodeEnvCompare(node, operator, value) {
|
|
|
557
518
|
}
|
|
558
519
|
return false;
|
|
559
520
|
}
|
|
560
|
-
function
|
|
561
|
-
|
|
521
|
+
function getPropertyName(node) {
|
|
522
|
+
if (isTypeExpression(node)) {
|
|
523
|
+
return getPropertyName(getJSExpression(node));
|
|
524
|
+
}
|
|
525
|
+
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
526
|
+
return node.name;
|
|
527
|
+
}
|
|
528
|
+
if (node.type === AST_NODE_TYPES.Literal) {
|
|
529
|
+
return String(node.value);
|
|
530
|
+
}
|
|
531
|
+
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
532
|
+
return node.quasis[0]?.value.raw;
|
|
533
|
+
}
|
|
534
|
+
return _;
|
|
535
|
+
}
|
|
536
|
+
function getNestedReturnStatements(node) {
|
|
537
|
+
const statements = [];
|
|
538
|
+
const boundaryNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
539
|
+
simpleTraverse(node, {
|
|
540
|
+
enter(node2) {
|
|
541
|
+
if (node2.type !== AST_NODE_TYPES.ReturnStatement) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const parentFunction = findParentNode(node2, isFunction);
|
|
545
|
+
if (parentFunction !== boundaryNode) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
statements.push(node2);
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
return statements;
|
|
552
|
+
}
|
|
553
|
+
function getLiteralValueType(input) {
|
|
554
|
+
if (input === null) return "null";
|
|
555
|
+
return typeof input;
|
|
556
|
+
}
|
|
557
|
+
function toReadableNodeType(node) {
|
|
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", ""), " "))}`;
|
|
566
|
+
}
|
|
567
|
+
return toLowerCase(delimiterCase(node.type, " "));
|
|
562
568
|
}
|
|
563
|
-
function
|
|
569
|
+
function toString(node, getText) {
|
|
564
570
|
switch (node.type) {
|
|
565
571
|
case AST_NODE_TYPES.CallExpression:
|
|
566
|
-
return
|
|
572
|
+
return toString(node.callee, getText);
|
|
567
573
|
case AST_NODE_TYPES.Identifier:
|
|
568
574
|
case AST_NODE_TYPES.PrivateIdentifier:
|
|
569
575
|
return node.name;
|
|
570
576
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
571
577
|
return `<${node.name}>`;
|
|
572
578
|
case AST_NODE_TYPES.JSXMemberExpression:
|
|
573
|
-
return `${
|
|
579
|
+
return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
|
|
574
580
|
case AST_NODE_TYPES.JSXNamespacedName:
|
|
575
581
|
return `${node.namespace.name}:${node.name.name}`;
|
|
576
582
|
case AST_NODE_TYPES.JSXText:
|
|
@@ -578,22 +584,10 @@ function stringify(node, getText) {
|
|
|
578
584
|
case AST_NODE_TYPES.Literal:
|
|
579
585
|
return node.raw;
|
|
580
586
|
case AST_NODE_TYPES.MemberExpression:
|
|
581
|
-
return `${
|
|
587
|
+
return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
|
|
582
588
|
default:
|
|
583
589
|
return getText(node);
|
|
584
590
|
}
|
|
585
591
|
}
|
|
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
592
|
|
|
599
|
-
export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassIdentifier,
|
|
593
|
+
export { findParentNode, getArrayMethodCallbackIndexParamPosition, getClassIdentifier, getFunctionIdentifier, 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, toReadableNodeType, 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.0",
|
|
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.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsup": "^8.4.0",
|