@eslint-react/ast 5.10.4 → 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 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, isStringLiteral, isTypeAssertionExpression, isTypeExpression };
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(name: string): (node: TSESTree.Node) => node is TSESTreeDirective;
25
- declare function isIdentifier(name: string): (node: TSESTree.Node) => node is TSESTree.Identifier;
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 (node) => node.type === AST_NODE_TYPES.ExpressionStatement && node.directive === name;
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 (node) => node.type === AST_NODE_TYPES.Identifier && node.name === name;
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,19 +224,19 @@ function getPropertyName(node, resolve = (n) => n.name) {
228
224
  return null;
229
225
  }
230
226
  function getFullyQualifiedName(node, getText) {
231
- node = unwrap(node);
232
- switch (node.type) {
227
+ const expr = unwrap(node);
228
+ switch (expr.type) {
233
229
  case AST_NODE_TYPES.Identifier:
234
230
  case AST_NODE_TYPES.JSXIdentifier:
235
- case AST_NODE_TYPES.PrivateIdentifier: return node.name;
231
+ case AST_NODE_TYPES.PrivateIdentifier: return expr.name;
236
232
  case AST_NODE_TYPES.MemberExpression:
237
- if (node.computed) return getText(node);
238
- return `${getFullyQualifiedName(node.object, getText)}.${getFullyQualifiedName(node.property, getText)}`;
239
- case AST_NODE_TYPES.JSXMemberExpression: return `${getFullyQualifiedName(node.object, getText)}.${getFullyQualifiedName(node.property, getText)}`;
240
- case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
241
- case AST_NODE_TYPES.JSXText: return node.value;
242
- case AST_NODE_TYPES.Literal: return node.raw;
243
- default: return getText(node);
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);
244
240
  }
245
241
  }
246
242
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/ast",
3
- "version": "5.10.4",
3
+ "version": "5.11.0",
4
4
  "description": "ESLint React's TSESTree AST utility module.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {