@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.js
CHANGED
|
@@ -1,61 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var eff = require('@eslint-react/eff');
|
|
4
3
|
var types = require('@typescript-eslint/types');
|
|
4
|
+
var eff = require('@eslint-react/eff');
|
|
5
5
|
var utils = require('@typescript-eslint/utils');
|
|
6
6
|
var typescriptEstree = require('@typescript-eslint/typescript-estree');
|
|
7
7
|
var stringTs = require('string-ts');
|
|
8
8
|
|
|
9
|
-
// src/
|
|
10
|
-
function
|
|
11
|
-
if (node
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
parent = parent.parent;
|
|
18
|
-
}
|
|
19
|
-
return eff._;
|
|
20
|
-
}
|
|
21
|
-
function getFunctionInitPath(node) {
|
|
22
|
-
if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) {
|
|
23
|
-
return [node];
|
|
24
|
-
}
|
|
25
|
-
const { parent } = node;
|
|
26
|
-
switch (true) {
|
|
27
|
-
case parent.type === types.AST_NODE_TYPES.VariableDeclarator:
|
|
28
|
-
return [parent.parent, parent, node];
|
|
29
|
-
case (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
|
|
30
|
-
return [parent.parent.parent, parent.parent, parent, node];
|
|
31
|
-
case (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
|
|
32
|
-
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
33
|
-
case (parent.type === types.AST_NODE_TYPES.Property && parent.parent.type === types.AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
|
|
34
|
-
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
35
|
-
case (parent.type === types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
36
|
-
return [parent.parent.parent, parent.parent, parent, node];
|
|
37
|
-
case (parent.type === types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
38
|
-
return [parent.parent.parent, parent.parent, parent, node];
|
|
39
|
-
}
|
|
40
|
-
return eff._;
|
|
9
|
+
// src/ast-array-method.ts
|
|
10
|
+
function isArrayFromCall(node, loose = true) {
|
|
11
|
+
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
12
|
+
if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
13
|
+
if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false;
|
|
14
|
+
const name = node.callee.property.name;
|
|
15
|
+
return name === "from" || loose && name.startsWith("from");
|
|
41
16
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
case types.AST_NODE_TYPES.Identifier:
|
|
49
|
-
return n.callee.name === callName;
|
|
50
|
-
case types.AST_NODE_TYPES.MemberExpression:
|
|
51
|
-
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
52
|
-
default:
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
17
|
+
function isArrayMapCall(node, loose = true) {
|
|
18
|
+
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
19
|
+
if (node.callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
20
|
+
if (node.callee.property.type !== types.AST_NODE_TYPES.Identifier) return false;
|
|
21
|
+
const name = node.callee.property.name;
|
|
22
|
+
return name === "map" || loose && name.endsWith("Map");
|
|
56
23
|
}
|
|
57
24
|
|
|
58
|
-
// src/
|
|
25
|
+
// src/ast-array-method-callback.ts
|
|
59
26
|
var indexParamPosition = /* @__PURE__ */ new Map([
|
|
60
27
|
["every", 1],
|
|
61
28
|
["filter", 1],
|
|
@@ -73,7 +40,7 @@ var indexParamPosition = /* @__PURE__ */ new Map([
|
|
|
73
40
|
function getArrayMethodCallbackIndexParamPosition(methodName) {
|
|
74
41
|
return indexParamPosition.get(methodName) ?? -1;
|
|
75
42
|
}
|
|
76
|
-
function
|
|
43
|
+
function getClassId(node) {
|
|
77
44
|
if (node.id != null) return node.id;
|
|
78
45
|
if (node.parent.type === types.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
79
46
|
return node.parent.id;
|
|
@@ -224,14 +191,17 @@ var isTypeAssertionExpression = isOneOf([
|
|
|
224
191
|
types.AST_NODE_TYPES.TSSatisfiesExpression
|
|
225
192
|
]);
|
|
226
193
|
|
|
227
|
-
// src/
|
|
228
|
-
function
|
|
194
|
+
// src/ast-expression.ts
|
|
195
|
+
function getJSExpression(node) {
|
|
229
196
|
if (isTypeExpression(node)) {
|
|
230
|
-
return
|
|
197
|
+
return getJSExpression(node.expression);
|
|
231
198
|
}
|
|
232
199
|
return node;
|
|
233
200
|
}
|
|
234
|
-
function
|
|
201
|
+
function isThisExpression(node) {
|
|
202
|
+
return getJSExpression(node).type === types.AST_NODE_TYPES.ThisExpression;
|
|
203
|
+
}
|
|
204
|
+
function getFunctionId(node) {
|
|
235
205
|
switch (true) {
|
|
236
206
|
// function MaybeComponent() {}
|
|
237
207
|
case ("id" in node && node.id != null):
|
|
@@ -260,101 +230,60 @@ function getFunctionIdentifier(node) {
|
|
|
260
230
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
261
231
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
262
232
|
case isTypeAssertionExpression(node.parent):
|
|
263
|
-
return
|
|
233
|
+
return getFunctionId(node.parent);
|
|
264
234
|
}
|
|
265
235
|
return eff._;
|
|
266
236
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
237
|
+
function getFunctionInitPath(node) {
|
|
238
|
+
if (node.type === types.AST_NODE_TYPES.FunctionDeclaration) {
|
|
239
|
+
return [node];
|
|
240
|
+
}
|
|
241
|
+
const { parent } = node;
|
|
242
|
+
switch (true) {
|
|
243
|
+
case parent.type === types.AST_NODE_TYPES.VariableDeclarator:
|
|
244
|
+
return [parent.parent, parent, node];
|
|
245
|
+
case (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
|
|
246
|
+
return [parent.parent.parent, parent.parent, parent, node];
|
|
247
|
+
case (parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.type === types.AST_NODE_TYPES.CallExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
|
|
248
|
+
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
249
|
+
case (parent.type === types.AST_NODE_TYPES.Property && parent.parent.type === types.AST_NODE_TYPES.ObjectExpression && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator):
|
|
250
|
+
return [parent.parent.parent.parent, parent.parent.parent, parent.parent, parent, node];
|
|
251
|
+
case (parent.type === types.AST_NODE_TYPES.MethodDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
252
|
+
return [parent.parent.parent, parent.parent, parent, node];
|
|
253
|
+
case (parent.type === types.AST_NODE_TYPES.PropertyDefinition && parent.parent.parent.type === types.AST_NODE_TYPES.ClassDeclaration):
|
|
254
|
+
return [parent.parent.parent, parent.parent, parent, node];
|
|
255
|
+
}
|
|
256
|
+
return eff._;
|
|
272
257
|
}
|
|
273
|
-
function
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const expressions = [];
|
|
278
|
-
if (isNodeOfType(node)) {
|
|
279
|
-
expressions.push(node);
|
|
280
|
-
}
|
|
281
|
-
if ("arguments" in node) {
|
|
282
|
-
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
|
|
283
|
-
expressions.push(...chunk);
|
|
284
|
-
}
|
|
285
|
-
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
286
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
287
|
-
expressions.push(...chunk);
|
|
288
|
-
}
|
|
289
|
-
if ("left" in node) {
|
|
290
|
-
const chunk = boundGetNestedExpressionsOfType(node.left);
|
|
291
|
-
expressions.push(...chunk);
|
|
292
|
-
}
|
|
293
|
-
if ("right" in node) {
|
|
294
|
-
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
295
|
-
expressions.push(...chunk);
|
|
296
|
-
}
|
|
297
|
-
if ("test" in node && node.test != null) {
|
|
298
|
-
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
299
|
-
expressions.push(...chunk);
|
|
300
|
-
}
|
|
301
|
-
if ("consequent" in node) {
|
|
302
|
-
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
303
|
-
expressions.push(...chunk);
|
|
304
|
-
}
|
|
305
|
-
if ("alternate" in node && node.alternate != null) {
|
|
306
|
-
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
307
|
-
expressions.push(...chunk);
|
|
308
|
-
}
|
|
309
|
-
if ("elements" in node) {
|
|
310
|
-
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
|
|
311
|
-
expressions.push(...chunk);
|
|
312
|
-
}
|
|
313
|
-
if ("properties" in node) {
|
|
314
|
-
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
|
|
315
|
-
expressions.push(...chunk);
|
|
316
|
-
}
|
|
317
|
-
if ("expressions" in node) {
|
|
318
|
-
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
319
|
-
expressions.push(...chunk);
|
|
320
|
-
}
|
|
321
|
-
if (node.type === typescriptEstree.AST_NODE_TYPES.Property) {
|
|
322
|
-
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
323
|
-
expressions.push(...chunk);
|
|
324
|
-
}
|
|
325
|
-
if (node.type === typescriptEstree.AST_NODE_TYPES.SpreadElement) {
|
|
326
|
-
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
327
|
-
expressions.push(...chunk);
|
|
328
|
-
}
|
|
329
|
-
if (node.type === typescriptEstree.AST_NODE_TYPES.MemberExpression) {
|
|
330
|
-
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
331
|
-
expressions.push(...chunk);
|
|
332
|
-
}
|
|
333
|
-
if (node.type === typescriptEstree.AST_NODE_TYPES.UnaryExpression) {
|
|
334
|
-
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
335
|
-
expressions.push(...chunk);
|
|
336
|
-
}
|
|
337
|
-
if (node.type === typescriptEstree.AST_NODE_TYPES.ChainExpression) {
|
|
338
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
339
|
-
expressions.push(...chunk);
|
|
340
|
-
}
|
|
341
|
-
if (node.type === typescriptEstree.AST_NODE_TYPES.TSNonNullExpression) {
|
|
342
|
-
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
343
|
-
expressions.push(...chunk);
|
|
258
|
+
function hasCallInFunctionInitPath(callName, initPath) {
|
|
259
|
+
return initPath.some((n) => {
|
|
260
|
+
if (n.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
261
|
+
return false;
|
|
344
262
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
263
|
+
switch (n.callee.type) {
|
|
264
|
+
case types.AST_NODE_TYPES.Identifier:
|
|
265
|
+
return n.callee.name === callName;
|
|
266
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
267
|
+
return "name" in n.callee.property && n.callee.property.name === callName;
|
|
268
|
+
default:
|
|
269
|
+
return false;
|
|
348
270
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function isEmptyFunction(node) {
|
|
274
|
+
return node.body.type === types.AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
275
|
+
}
|
|
276
|
+
function findParentNode(node, test) {
|
|
277
|
+
if (node == null) return eff._;
|
|
278
|
+
let parent = node.parent;
|
|
279
|
+
while (parent != null && parent.type !== types.AST_NODE_TYPES.Program) {
|
|
280
|
+
if (test(parent)) {
|
|
281
|
+
return parent;
|
|
352
282
|
}
|
|
353
|
-
|
|
354
|
-
}
|
|
283
|
+
parent = parent.parent;
|
|
284
|
+
}
|
|
285
|
+
return eff._;
|
|
355
286
|
}
|
|
356
|
-
var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
|
|
357
|
-
var getNestedCallExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.CallExpression);
|
|
358
287
|
function getNestedIdentifiers(node) {
|
|
359
288
|
const identifiers = [];
|
|
360
289
|
if (node.type === types.AST_NODE_TYPES.Identifier) {
|
|
@@ -435,45 +364,94 @@ function getNestedReturnStatements(node) {
|
|
|
435
364
|
});
|
|
436
365
|
return statements;
|
|
437
366
|
}
|
|
438
|
-
function
|
|
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
|
-
|
|
467
|
-
|
|
468
|
-
|
|
367
|
+
function getNestedExpressionsOfType(type) {
|
|
368
|
+
const isNodeOfType = is(type);
|
|
369
|
+
return function(node) {
|
|
370
|
+
const boundGetNestedExpressionsOfType = getNestedExpressionsOfType(type);
|
|
371
|
+
const expressions = [];
|
|
372
|
+
if (isNodeOfType(node)) {
|
|
373
|
+
expressions.push(node);
|
|
374
|
+
}
|
|
375
|
+
if ("arguments" in node) {
|
|
376
|
+
const chunk = node.arguments.map(getNestedExpressionsOfType(type)).flat(1);
|
|
377
|
+
expressions.push(...chunk);
|
|
378
|
+
}
|
|
379
|
+
if ("expression" in node && node.expression !== true && node.expression !== false) {
|
|
380
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
381
|
+
expressions.push(...chunk);
|
|
382
|
+
}
|
|
383
|
+
if ("left" in node) {
|
|
384
|
+
const chunk = boundGetNestedExpressionsOfType(node.left);
|
|
385
|
+
expressions.push(...chunk);
|
|
386
|
+
}
|
|
387
|
+
if ("right" in node) {
|
|
388
|
+
const chunk = boundGetNestedExpressionsOfType(node.right);
|
|
389
|
+
expressions.push(...chunk);
|
|
390
|
+
}
|
|
391
|
+
if ("test" in node && node.test != null) {
|
|
392
|
+
const chunk = boundGetNestedExpressionsOfType(node.test);
|
|
393
|
+
expressions.push(...chunk);
|
|
394
|
+
}
|
|
395
|
+
if ("consequent" in node) {
|
|
396
|
+
const chunk = Array.isArray(node.consequent) ? node.consequent.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.consequent);
|
|
397
|
+
expressions.push(...chunk);
|
|
398
|
+
}
|
|
399
|
+
if ("alternate" in node && node.alternate != null) {
|
|
400
|
+
const chunk = Array.isArray(node.alternate) ? node.alternate.map(boundGetNestedExpressionsOfType).flat(1) : boundGetNestedExpressionsOfType(node.alternate);
|
|
401
|
+
expressions.push(...chunk);
|
|
402
|
+
}
|
|
403
|
+
if ("elements" in node) {
|
|
404
|
+
const chunk = node.elements.filter((x) => x != null).map(getNestedExpressionsOfType(type)).flat(1);
|
|
405
|
+
expressions.push(...chunk);
|
|
406
|
+
}
|
|
407
|
+
if ("properties" in node) {
|
|
408
|
+
const chunk = node.properties.map(boundGetNestedExpressionsOfType).flat(1);
|
|
409
|
+
expressions.push(...chunk);
|
|
410
|
+
}
|
|
411
|
+
if ("expressions" in node) {
|
|
412
|
+
const chunk = node.expressions.map(boundGetNestedExpressionsOfType).flat(1);
|
|
413
|
+
expressions.push(...chunk);
|
|
414
|
+
}
|
|
415
|
+
if (node.type === types.AST_NODE_TYPES.Property) {
|
|
416
|
+
const chunk = boundGetNestedExpressionsOfType(node.value);
|
|
417
|
+
expressions.push(...chunk);
|
|
418
|
+
}
|
|
419
|
+
if (node.type === types.AST_NODE_TYPES.SpreadElement) {
|
|
420
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
421
|
+
expressions.push(...chunk);
|
|
422
|
+
}
|
|
423
|
+
if (node.type === types.AST_NODE_TYPES.MemberExpression) {
|
|
424
|
+
const chunk = boundGetNestedExpressionsOfType(node.object);
|
|
425
|
+
expressions.push(...chunk);
|
|
426
|
+
}
|
|
427
|
+
if (node.type === types.AST_NODE_TYPES.UnaryExpression) {
|
|
428
|
+
const chunk = boundGetNestedExpressionsOfType(node.argument);
|
|
429
|
+
expressions.push(...chunk);
|
|
430
|
+
}
|
|
431
|
+
if (node.type === types.AST_NODE_TYPES.ChainExpression) {
|
|
432
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
433
|
+
expressions.push(...chunk);
|
|
434
|
+
}
|
|
435
|
+
if (node.type === types.AST_NODE_TYPES.TSNonNullExpression) {
|
|
436
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
437
|
+
expressions.push(...chunk);
|
|
438
|
+
}
|
|
439
|
+
if (node.type === types.AST_NODE_TYPES.TSAsExpression) {
|
|
440
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
441
|
+
expressions.push(...chunk);
|
|
442
|
+
}
|
|
443
|
+
if (node.type === types.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
444
|
+
const chunk = boundGetNestedExpressionsOfType(node.expression);
|
|
445
|
+
expressions.push(...chunk);
|
|
446
|
+
}
|
|
447
|
+
return expressions;
|
|
448
|
+
};
|
|
469
449
|
}
|
|
470
|
-
|
|
471
|
-
|
|
450
|
+
var getNestedNewExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.NewExpression);
|
|
451
|
+
var getNestedCallExpressions = getNestedExpressionsOfType(types.AST_NODE_TYPES.CallExpression);
|
|
472
452
|
function isMultiLine(node) {
|
|
473
453
|
return node.loc.start.line !== node.loc.end.line;
|
|
474
454
|
}
|
|
475
|
-
|
|
476
|
-
// src/is-line-break.ts
|
|
477
455
|
function isLineBreak(node) {
|
|
478
456
|
return isOneOf([types.AST_NODE_TYPES.Literal, types.AST_NODE_TYPES.JSXText])(node) && typeof node.value === "string" && node.value.trim() === "" && isMultiLine(node);
|
|
479
457
|
}
|
|
@@ -559,52 +537,65 @@ function isProcessEnvNodeEnvCompare(node, operator, value) {
|
|
|
559
537
|
}
|
|
560
538
|
return false;
|
|
561
539
|
}
|
|
562
|
-
function
|
|
563
|
-
|
|
540
|
+
function getPropertyName(node) {
|
|
541
|
+
if (isTypeExpression(node)) {
|
|
542
|
+
return getPropertyName(getJSExpression(node));
|
|
543
|
+
}
|
|
544
|
+
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
545
|
+
return node.name;
|
|
546
|
+
}
|
|
547
|
+
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
548
|
+
return String(node.value);
|
|
549
|
+
}
|
|
550
|
+
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
551
|
+
return node.quasis[0]?.value.raw;
|
|
552
|
+
}
|
|
553
|
+
return eff._;
|
|
554
|
+
}
|
|
555
|
+
function getLiteralValueType(input) {
|
|
556
|
+
if (input === null) return "null";
|
|
557
|
+
return typeof input;
|
|
558
|
+
}
|
|
559
|
+
function toDelimiterCaseType(node, delimiter = " ") {
|
|
560
|
+
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
561
|
+
if ("regex" in node) {
|
|
562
|
+
return "RegExp literal";
|
|
563
|
+
}
|
|
564
|
+
return `${getLiteralValueType(node.value)} literal`;
|
|
565
|
+
}
|
|
566
|
+
if (isJSX(node)) {
|
|
567
|
+
return `JSX ${stringTs.toLowerCase(stringTs.delimiterCase(stringTs.replace(node.type, "JSX", ""), delimiter))}`;
|
|
568
|
+
}
|
|
569
|
+
return stringTs.toLowerCase(stringTs.delimiterCase(node.type, delimiter));
|
|
564
570
|
}
|
|
565
|
-
function
|
|
571
|
+
function toString(node, getText) {
|
|
566
572
|
switch (node.type) {
|
|
567
|
-
case types.AST_NODE_TYPES.CallExpression:
|
|
568
|
-
return stringify(node.callee, getText);
|
|
569
573
|
case types.AST_NODE_TYPES.Identifier:
|
|
574
|
+
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
570
575
|
case types.AST_NODE_TYPES.PrivateIdentifier:
|
|
571
576
|
return node.name;
|
|
572
|
-
case types.AST_NODE_TYPES.
|
|
573
|
-
return `<${node.name}>`;
|
|
577
|
+
case types.AST_NODE_TYPES.MemberExpression:
|
|
574
578
|
case types.AST_NODE_TYPES.JSXMemberExpression:
|
|
575
|
-
return `${
|
|
579
|
+
return `${toString(node.object, getText)}.${toString(node.property, getText)}`;
|
|
576
580
|
case types.AST_NODE_TYPES.JSXNamespacedName:
|
|
577
581
|
return `${node.namespace.name}:${node.name.name}`;
|
|
578
582
|
case types.AST_NODE_TYPES.JSXText:
|
|
579
583
|
return node.value;
|
|
580
584
|
case types.AST_NODE_TYPES.Literal:
|
|
581
585
|
return node.raw;
|
|
582
|
-
case types.AST_NODE_TYPES.
|
|
583
|
-
return
|
|
586
|
+
case types.AST_NODE_TYPES.CallExpression:
|
|
587
|
+
return toString(node.callee, getText);
|
|
584
588
|
default:
|
|
585
589
|
return getText(node);
|
|
586
590
|
}
|
|
587
591
|
}
|
|
588
|
-
function toReadableNodeType(node) {
|
|
589
|
-
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
590
|
-
if ("regex" in node) {
|
|
591
|
-
return "RegExp literal";
|
|
592
|
-
}
|
|
593
|
-
return `${getLiteralValueType(node.value)} literal`;
|
|
594
|
-
}
|
|
595
|
-
if (isJSX(node)) {
|
|
596
|
-
return `JSX ${stringTs.toLowerCase(stringTs.delimiterCase(stringTs.replace(node.type, "JSX", ""), " "))}`;
|
|
597
|
-
}
|
|
598
|
-
return stringTs.toLowerCase(stringTs.delimiterCase(node.type, " "));
|
|
599
|
-
}
|
|
600
592
|
|
|
601
593
|
exports.findParentNode = findParentNode;
|
|
602
594
|
exports.getArrayMethodCallbackIndexParamPosition = getArrayMethodCallbackIndexParamPosition;
|
|
603
|
-
exports.
|
|
604
|
-
exports.
|
|
605
|
-
exports.getFunctionIdentifier = getFunctionIdentifier;
|
|
595
|
+
exports.getClassId = getClassId;
|
|
596
|
+
exports.getFunctionId = getFunctionId;
|
|
606
597
|
exports.getFunctionInitPath = getFunctionInitPath;
|
|
607
|
-
exports.
|
|
598
|
+
exports.getJSExpression = getJSExpression;
|
|
608
599
|
exports.getNestedCallExpressions = getNestedCallExpressions;
|
|
609
600
|
exports.getNestedExpressionsOfType = getNestedExpressionsOfType;
|
|
610
601
|
exports.getNestedIdentifiers = getNestedIdentifiers;
|
|
@@ -643,5 +634,5 @@ exports.isThisExpression = isThisExpression;
|
|
|
643
634
|
exports.isTypeAssertionExpression = isTypeAssertionExpression;
|
|
644
635
|
exports.isTypeDeclaration = isTypeDeclaration;
|
|
645
636
|
exports.isTypeExpression = isTypeExpression;
|
|
646
|
-
exports.
|
|
647
|
-
exports.
|
|
637
|
+
exports.toDelimiterCaseType = toDelimiterCaseType;
|
|
638
|
+
exports.toString = toString;
|