@eslint-react/ast 5.10.3 → 5.11.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.ts +3 -4
- package/dist/index.js +14 -17
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ type TSESTreeDirective = TSESTree.ExpressionStatement & {
|
|
|
13
13
|
};
|
|
14
14
|
type TSESTreeTypeExpression = TSESTree.TSAsExpression | TSESTree.TSTypeAssertion | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSInstantiationExpression;
|
|
15
15
|
declare namespace check_d_exports {
|
|
16
|
-
export { is, isClass, isDirective, isFunction, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXFragment, isJSXTagNameExpression, isOneOf, isProperty, isPropertyOrMethod,
|
|
16
|
+
export { is, isClass, isDirective, isFunction, isIdentifier, isJSX, isJSXElement, isJSXElementOrFragment, isJSXFragment, isJSXTagNameExpression, isOneOf, isProperty, isPropertyOrMethod, isTypeAssertionExpression, isTypeExpression };
|
|
17
17
|
}
|
|
18
18
|
declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
19
19
|
type: NodeType;
|
|
@@ -21,9 +21,8 @@ declare const is: <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (node
|
|
|
21
21
|
declare const isOneOf: <NodeTypes extends readonly AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
|
|
22
22
|
type: NodeTypes[number];
|
|
23
23
|
}>;
|
|
24
|
-
declare function isDirective(
|
|
25
|
-
declare function isIdentifier(
|
|
26
|
-
declare function isStringLiteral(node: TSESTree.Node): node is TSESTree.StringLiteral;
|
|
24
|
+
declare function isDirective(node: TSESTree.Node, name?: string): node is TSESTreeDirective;
|
|
25
|
+
declare function isIdentifier(node: TSESTree.Node, name?: string): node is TSESTree.Identifier;
|
|
27
26
|
declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
|
|
28
27
|
declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
|
|
29
28
|
declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
|
package/dist/index.js
CHANGED
|
@@ -17,20 +17,16 @@ var check_exports = /* @__PURE__ */ __exportAll({
|
|
|
17
17
|
isOneOf: () => isOneOf,
|
|
18
18
|
isProperty: () => isProperty,
|
|
19
19
|
isPropertyOrMethod: () => isPropertyOrMethod,
|
|
20
|
-
isStringLiteral: () => isStringLiteral,
|
|
21
20
|
isTypeAssertionExpression: () => isTypeAssertionExpression,
|
|
22
21
|
isTypeExpression: () => isTypeExpression
|
|
23
22
|
});
|
|
24
23
|
const is = ASTUtils.isNodeOfType;
|
|
25
24
|
const isOneOf = ASTUtils.isNodeOfTypes;
|
|
26
|
-
function isDirective(name) {
|
|
27
|
-
return
|
|
25
|
+
function isDirective(node, name) {
|
|
26
|
+
return node.type === AST_NODE_TYPES.ExpressionStatement && (name == null || node.directive === name);
|
|
28
27
|
}
|
|
29
|
-
function isIdentifier(name) {
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
function isStringLiteral(node) {
|
|
33
|
-
return node.type === AST_NODE_TYPES.Literal && typeof node.value === "string";
|
|
28
|
+
function isIdentifier(node, name) {
|
|
29
|
+
return node.type === AST_NODE_TYPES.Identifier && (name == null || node.name === name);
|
|
34
30
|
}
|
|
35
31
|
const isClass = isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression]);
|
|
36
32
|
const isFunction = isOneOf([
|
|
@@ -228,18 +224,19 @@ function getPropertyName(node, resolve = (n) => n.name) {
|
|
|
228
224
|
return null;
|
|
229
225
|
}
|
|
230
226
|
function getFullyQualifiedName(node, getText) {
|
|
231
|
-
|
|
227
|
+
const expr = unwrap(node);
|
|
228
|
+
switch (expr.type) {
|
|
232
229
|
case AST_NODE_TYPES.Identifier:
|
|
233
230
|
case AST_NODE_TYPES.JSXIdentifier:
|
|
234
|
-
case AST_NODE_TYPES.PrivateIdentifier: return
|
|
231
|
+
case AST_NODE_TYPES.PrivateIdentifier: return expr.name;
|
|
235
232
|
case AST_NODE_TYPES.MemberExpression:
|
|
236
|
-
if (
|
|
237
|
-
return `${getFullyQualifiedName(
|
|
238
|
-
case AST_NODE_TYPES.JSXMemberExpression: return `${getFullyQualifiedName(
|
|
239
|
-
case AST_NODE_TYPES.JSXNamespacedName: return `${
|
|
240
|
-
case AST_NODE_TYPES.JSXText: return
|
|
241
|
-
case AST_NODE_TYPES.Literal: return
|
|
242
|
-
default: return getText(
|
|
233
|
+
if (expr.computed) return getText(expr);
|
|
234
|
+
return `${getFullyQualifiedName(expr.object, getText)}.${getFullyQualifiedName(expr.property, getText)}`;
|
|
235
|
+
case AST_NODE_TYPES.JSXMemberExpression: return `${getFullyQualifiedName(expr.object, getText)}.${getFullyQualifiedName(expr.property, getText)}`;
|
|
236
|
+
case AST_NODE_TYPES.JSXNamespacedName: return `${expr.namespace.name}:${expr.name.name}`;
|
|
237
|
+
case AST_NODE_TYPES.JSXText: return expr.value;
|
|
238
|
+
case AST_NODE_TYPES.Literal: return expr.raw;
|
|
239
|
+
default: return getText(expr);
|
|
243
240
|
}
|
|
244
241
|
}
|
|
245
242
|
|