@eslint-react/ast 1.28.1-beta.3 → 1.28.1-beta.5
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 +28 -2168
- package/dist/index.d.ts +28 -2168
- package/dist/index.js +21 -23
- package/dist/index.mjs +20 -22
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ var eff = require('@eslint-react/eff');
|
|
|
4
4
|
var types = require('@typescript-eslint/types');
|
|
5
5
|
var utils = require('@typescript-eslint/utils');
|
|
6
6
|
var typescriptEstree = require('@typescript-eslint/typescript-estree');
|
|
7
|
-
var tsPattern = require('ts-pattern');
|
|
8
7
|
var stringTs = require('string-ts');
|
|
9
8
|
|
|
10
9
|
// src/find-parent-node.ts
|
|
@@ -228,14 +227,27 @@ var isLeftHandSideExpressionType = isOneOf([
|
|
|
228
227
|
types.AST_NODE_TYPES.TSNonNullExpression,
|
|
229
228
|
types.AST_NODE_TYPES.TSTypeAssertion
|
|
230
229
|
]);
|
|
231
|
-
var
|
|
230
|
+
var isTsOnlyExpression = isOneOf([
|
|
231
|
+
types.AST_NODE_TYPES.TSAsExpression,
|
|
232
|
+
types.AST_NODE_TYPES.TSTypeAssertion,
|
|
233
|
+
types.AST_NODE_TYPES.TSNonNullExpression,
|
|
234
|
+
types.AST_NODE_TYPES.TSSatisfiesExpression,
|
|
235
|
+
types.AST_NODE_TYPES.TSInstantiationExpression
|
|
236
|
+
]);
|
|
237
|
+
var isTsAssertionExpression = isOneOf([
|
|
232
238
|
types.AST_NODE_TYPES.TSAsExpression,
|
|
233
239
|
types.AST_NODE_TYPES.TSTypeAssertion,
|
|
234
240
|
types.AST_NODE_TYPES.TSNonNullExpression,
|
|
235
241
|
types.AST_NODE_TYPES.TSSatisfiesExpression
|
|
236
242
|
]);
|
|
237
243
|
|
|
238
|
-
// src/get-
|
|
244
|
+
// src/get-ecma-expression.ts
|
|
245
|
+
function getEcmaExpression(node) {
|
|
246
|
+
if (isTsOnlyExpression(node)) {
|
|
247
|
+
return getEcmaExpression(node.expression);
|
|
248
|
+
}
|
|
249
|
+
return node;
|
|
250
|
+
}
|
|
239
251
|
function getFunctionIdentifier(node) {
|
|
240
252
|
switch (true) {
|
|
241
253
|
// function MaybeComponent() {}
|
|
@@ -264,7 +276,7 @@ function getFunctionIdentifier(node) {
|
|
|
264
276
|
// const MaybeComponent = (() => {})!;
|
|
265
277
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
266
278
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
267
|
-
case
|
|
279
|
+
case isTsAssertionExpression(node.parent):
|
|
268
280
|
return getFunctionIdentifier(node.parent);
|
|
269
281
|
}
|
|
270
282
|
return eff._;
|
|
@@ -358,8 +370,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
358
370
|
return expressions;
|
|
359
371
|
};
|
|
360
372
|
}
|
|
361
|
-
|
|
362
|
-
// src/get-nested-call-expressions.ts
|
|
373
|
+
var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
|
|
363
374
|
var getNestedCallExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.CallExpression);
|
|
364
375
|
function getNestedIdentifiers(node) {
|
|
365
376
|
const identifiers = [];
|
|
@@ -424,7 +435,6 @@ function getNestedIdentifiers(node) {
|
|
|
424
435
|
}
|
|
425
436
|
return identifiers;
|
|
426
437
|
}
|
|
427
|
-
var getNestedNewExpressions = getNestedExpressionsOfType(typescriptEstree.AST_NODE_TYPES.NewExpression);
|
|
428
438
|
function getNestedReturnStatements(node) {
|
|
429
439
|
const returnStatements = [];
|
|
430
440
|
const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
@@ -455,9 +465,6 @@ function getTopLevelIdentifier(node) {
|
|
|
455
465
|
function isEmptyFunction(node) {
|
|
456
466
|
return node.body.type === types.AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
457
467
|
}
|
|
458
|
-
function isKeyLiteralLike(node, property) {
|
|
459
|
-
return tsPattern.match(property).with({ type: types.AST_NODE_TYPES.Literal }, eff.constTrue).with({ type: types.AST_NODE_TYPES.TemplateLiteral, expressions: [] }, eff.constTrue).with({ type: types.AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(eff.constFalse);
|
|
460
|
-
}
|
|
461
468
|
function isKindOfLiteral(node, kind) {
|
|
462
469
|
if (node.type !== types.AST_NODE_TYPES.Literal) return false;
|
|
463
470
|
switch (kind) {
|
|
@@ -537,8 +544,7 @@ var isNodeEqual = eff.dual(2, (a, b) => {
|
|
|
537
544
|
}
|
|
538
545
|
});
|
|
539
546
|
function isThisExpression(node) {
|
|
540
|
-
|
|
541
|
-
return node.type === types.AST_NODE_TYPES.ThisExpression;
|
|
547
|
+
return getEcmaExpression(node).type === types.AST_NODE_TYPES.ThisExpression;
|
|
542
548
|
}
|
|
543
549
|
function toReadableNodeName(node, getText) {
|
|
544
550
|
switch (node.type) {
|
|
@@ -575,16 +581,9 @@ function toReadableNodeType(node) {
|
|
|
575
581
|
return stringTs.toLowerCase(stringTs.delimiterCase(node.type, " "));
|
|
576
582
|
}
|
|
577
583
|
|
|
578
|
-
// src/unwrap-type-expression.ts
|
|
579
|
-
function unwrapTypeExpression(node) {
|
|
580
|
-
if (isTypeExpression(node)) {
|
|
581
|
-
return unwrapTypeExpression(node.expression);
|
|
582
|
-
}
|
|
583
|
-
return node;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
584
|
exports.findParentNode = findParentNode;
|
|
587
585
|
exports.getClassIdentifier = getClassIdentifier;
|
|
586
|
+
exports.getEcmaExpression = getEcmaExpression;
|
|
588
587
|
exports.getFunctionIdentifier = getFunctionIdentifier;
|
|
589
588
|
exports.getFunctionInitPath = getFunctionInitPath;
|
|
590
589
|
exports.getLiteralValueType = getLiteralValueType;
|
|
@@ -608,7 +607,6 @@ exports.isJSX = isJSX;
|
|
|
608
607
|
exports.isJSXElement = isJSXElement;
|
|
609
608
|
exports.isJSXFragment = isJSXFragment;
|
|
610
609
|
exports.isJSXTagNameExpression = isJSXTagNameExpression;
|
|
611
|
-
exports.isKeyLiteralLike = isKeyLiteralLike;
|
|
612
610
|
exports.isKindOfLiteral = isKindOfLiteral;
|
|
613
611
|
exports.isLeftHandSideExpression = isLeftHandSideExpression;
|
|
614
612
|
exports.isLeftHandSideExpressionType = isLeftHandSideExpressionType;
|
|
@@ -620,8 +618,8 @@ exports.isNodeEqual = isNodeEqual;
|
|
|
620
618
|
exports.isOneOf = isOneOf;
|
|
621
619
|
exports.isProperty = isProperty;
|
|
622
620
|
exports.isThisExpression = isThisExpression;
|
|
621
|
+
exports.isTsAssertionExpression = isTsAssertionExpression;
|
|
622
|
+
exports.isTsOnlyExpression = isTsOnlyExpression;
|
|
623
623
|
exports.isTypeDeclaration = isTypeDeclaration;
|
|
624
|
-
exports.isTypeExpression = isTypeExpression;
|
|
625
624
|
exports.toReadableNodeName = toReadableNodeName;
|
|
626
625
|
exports.toReadableNodeType = toReadableNodeType;
|
|
627
|
-
exports.unwrapTypeExpression = unwrapTypeExpression;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { or, dual, _
|
|
1
|
+
import { or, dual, _ } from '@eslint-react/eff';
|
|
2
2
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
3
3
|
import { ASTUtils } from '@typescript-eslint/utils';
|
|
4
4
|
import { AST_NODE_TYPES as AST_NODE_TYPES$1, simpleTraverse } from '@typescript-eslint/typescript-estree';
|
|
5
|
-
import { match } from 'ts-pattern';
|
|
6
5
|
import { toLowerCase, delimiterCase, replace } from 'string-ts';
|
|
7
6
|
|
|
8
7
|
// src/find-parent-node.ts
|
|
@@ -226,14 +225,27 @@ var isLeftHandSideExpressionType = isOneOf([
|
|
|
226
225
|
AST_NODE_TYPES.TSNonNullExpression,
|
|
227
226
|
AST_NODE_TYPES.TSTypeAssertion
|
|
228
227
|
]);
|
|
229
|
-
var
|
|
228
|
+
var isTsOnlyExpression = isOneOf([
|
|
229
|
+
AST_NODE_TYPES.TSAsExpression,
|
|
230
|
+
AST_NODE_TYPES.TSTypeAssertion,
|
|
231
|
+
AST_NODE_TYPES.TSNonNullExpression,
|
|
232
|
+
AST_NODE_TYPES.TSSatisfiesExpression,
|
|
233
|
+
AST_NODE_TYPES.TSInstantiationExpression
|
|
234
|
+
]);
|
|
235
|
+
var isTsAssertionExpression = isOneOf([
|
|
230
236
|
AST_NODE_TYPES.TSAsExpression,
|
|
231
237
|
AST_NODE_TYPES.TSTypeAssertion,
|
|
232
238
|
AST_NODE_TYPES.TSNonNullExpression,
|
|
233
239
|
AST_NODE_TYPES.TSSatisfiesExpression
|
|
234
240
|
]);
|
|
235
241
|
|
|
236
|
-
// src/get-
|
|
242
|
+
// src/get-ecma-expression.ts
|
|
243
|
+
function getEcmaExpression(node) {
|
|
244
|
+
if (isTsOnlyExpression(node)) {
|
|
245
|
+
return getEcmaExpression(node.expression);
|
|
246
|
+
}
|
|
247
|
+
return node;
|
|
248
|
+
}
|
|
237
249
|
function getFunctionIdentifier(node) {
|
|
238
250
|
switch (true) {
|
|
239
251
|
// function MaybeComponent() {}
|
|
@@ -262,7 +274,7 @@ function getFunctionIdentifier(node) {
|
|
|
262
274
|
// const MaybeComponent = (() => {})!;
|
|
263
275
|
// const MaybeComponent = (() => {}) as FunctionComponent;
|
|
264
276
|
// const MaybeComponent = (() => {}) satisfies FunctionComponent;
|
|
265
|
-
case
|
|
277
|
+
case isTsAssertionExpression(node.parent):
|
|
266
278
|
return getFunctionIdentifier(node.parent);
|
|
267
279
|
}
|
|
268
280
|
return _;
|
|
@@ -356,8 +368,7 @@ function getNestedExpressionsOfType(type) {
|
|
|
356
368
|
return expressions;
|
|
357
369
|
};
|
|
358
370
|
}
|
|
359
|
-
|
|
360
|
-
// src/get-nested-call-expressions.ts
|
|
371
|
+
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
|
|
361
372
|
var getNestedCallExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.CallExpression);
|
|
362
373
|
function getNestedIdentifiers(node) {
|
|
363
374
|
const identifiers = [];
|
|
@@ -422,7 +433,6 @@ function getNestedIdentifiers(node) {
|
|
|
422
433
|
}
|
|
423
434
|
return identifiers;
|
|
424
435
|
}
|
|
425
|
-
var getNestedNewExpressions = getNestedExpressionsOfType(AST_NODE_TYPES$1.NewExpression);
|
|
426
436
|
function getNestedReturnStatements(node) {
|
|
427
437
|
const returnStatements = [];
|
|
428
438
|
const functionNode = isFunction(node) ? node : findParentNode(node, isFunction);
|
|
@@ -453,9 +463,6 @@ function getTopLevelIdentifier(node) {
|
|
|
453
463
|
function isEmptyFunction(node) {
|
|
454
464
|
return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
455
465
|
}
|
|
456
|
-
function isKeyLiteralLike(node, property) {
|
|
457
|
-
return match(property).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
458
|
-
}
|
|
459
466
|
function isKindOfLiteral(node, kind) {
|
|
460
467
|
if (node.type !== AST_NODE_TYPES.Literal) return false;
|
|
461
468
|
switch (kind) {
|
|
@@ -535,8 +542,7 @@ var isNodeEqual = dual(2, (a, b) => {
|
|
|
535
542
|
}
|
|
536
543
|
});
|
|
537
544
|
function isThisExpression(node) {
|
|
538
|
-
|
|
539
|
-
return node.type === AST_NODE_TYPES.ThisExpression;
|
|
545
|
+
return getEcmaExpression(node).type === AST_NODE_TYPES.ThisExpression;
|
|
540
546
|
}
|
|
541
547
|
function toReadableNodeName(node, getText) {
|
|
542
548
|
switch (node.type) {
|
|
@@ -573,12 +579,4 @@ function toReadableNodeType(node) {
|
|
|
573
579
|
return toLowerCase(delimiterCase(node.type, " "));
|
|
574
580
|
}
|
|
575
581
|
|
|
576
|
-
|
|
577
|
-
function unwrapTypeExpression(node) {
|
|
578
|
-
if (isTypeExpression(node)) {
|
|
579
|
-
return unwrapTypeExpression(node.expression);
|
|
580
|
-
}
|
|
581
|
-
return node;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
export { findParentNode, getClassIdentifier, getFunctionIdentifier, getFunctionInitPath, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKeyLiteralLike, isKindOfLiteral, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThisExpression, isTypeDeclaration, isTypeExpression, toReadableNodeName, toReadableNodeType, unwrapTypeExpression };
|
|
582
|
+
export { findParentNode, getClassIdentifier, getEcmaExpression, getFunctionIdentifier, getFunctionInitPath, getLiteralValueType, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getTopLevelIdentifier, hasCallInFunctionInitPath, is, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isKindOfLiteral, isLeftHandSideExpression, isLeftHandSideExpressionType, isLoop, isMapCallLoose, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThisExpression, isTsAssertionExpression, isTsOnlyExpression, isTypeDeclaration, toReadableNodeName, toReadableNodeType };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "1.28.1-beta.
|
|
3
|
+
"version": "1.28.1-beta.5",
|
|
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.25.0",
|
|
41
41
|
"string-ts": "^2.2.1",
|
|
42
42
|
"ts-pattern": "^5.6.2",
|
|
43
|
-
"@eslint-react/eff": "1.28.1-beta.
|
|
43
|
+
"@eslint-react/eff": "1.28.1-beta.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsup": "^8.4.0",
|