forked from testing-library/eslint-plugin-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis-node-of-type.ts
45 lines (43 loc) · 1.89 KB
/
is-node-of-type.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {
AST_NODE_TYPES,
TSESTree,
} from '@typescript-eslint/experimental-utils';
const isNodeOfType = <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => (
node: TSESTree.Node | null | undefined
): node is TSESTree.Node & { type: NodeType } => node?.type === nodeType;
export const isArrayExpression = isNodeOfType(AST_NODE_TYPES.ArrayExpression);
export const isArrowFunctionExpression = isNodeOfType(
AST_NODE_TYPES.ArrowFunctionExpression
);
export const isBlockStatement = isNodeOfType(AST_NODE_TYPES.BlockStatement);
export const isCallExpression = isNodeOfType(AST_NODE_TYPES.CallExpression);
export const isExpressionStatement = isNodeOfType(
AST_NODE_TYPES.ExpressionStatement
);
export const isVariableDeclaration = isNodeOfType(
AST_NODE_TYPES.VariableDeclaration
);
export const isAssignmentExpression = isNodeOfType(
AST_NODE_TYPES.AssignmentExpression
);
export const isSequenceExpression = isNodeOfType(
AST_NODE_TYPES.SequenceExpression
);
export const isImportDeclaration = isNodeOfType(
AST_NODE_TYPES.ImportDeclaration
);
export const isImportDefaultSpecifier = isNodeOfType(
AST_NODE_TYPES.ImportDefaultSpecifier
);
export const isImportNamespaceSpecifier = isNodeOfType(
AST_NODE_TYPES.ImportNamespaceSpecifier
);
export const isImportSpecifier = isNodeOfType(AST_NODE_TYPES.ImportSpecifier);
export const isJSXAttribute = isNodeOfType(AST_NODE_TYPES.JSXAttribute);
export const isLiteral = isNodeOfType(AST_NODE_TYPES.Literal);
export const isMemberExpression = isNodeOfType(AST_NODE_TYPES.MemberExpression);
export const isNewExpression = isNodeOfType(AST_NODE_TYPES.NewExpression);
export const isObjectExpression = isNodeOfType(AST_NODE_TYPES.ObjectExpression);
export const isObjectPattern = isNodeOfType(AST_NODE_TYPES.ObjectPattern);
export const isProperty = isNodeOfType(AST_NODE_TYPES.Property);
export const isReturnStatement = isNodeOfType(AST_NODE_TYPES.ReturnStatement);