|
1 | 1 | import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils'; |
2 | 2 |
|
3 | | -export const isArrayExpression = ASTUtils.isNodeOfType( |
4 | | - AST_NODE_TYPES.ArrayExpression |
5 | | -); |
6 | | -export const isArrowFunctionExpression = ASTUtils.isNodeOfType( |
7 | | - AST_NODE_TYPES.ArrowFunctionExpression |
8 | | -); |
9 | | -export const isBlockStatement = ASTUtils.isNodeOfType( |
10 | | - AST_NODE_TYPES.BlockStatement |
11 | | -); |
12 | | -export const isCallExpression = ASTUtils.isNodeOfType( |
13 | | - AST_NODE_TYPES.CallExpression |
14 | | -); |
15 | | -export const isExpressionStatement = ASTUtils.isNodeOfType( |
16 | | - AST_NODE_TYPES.ExpressionStatement |
17 | | -); |
18 | | -export const isVariableDeclaration = ASTUtils.isNodeOfType( |
19 | | - AST_NODE_TYPES.VariableDeclaration |
20 | | -); |
21 | | -export const isAssignmentExpression = ASTUtils.isNodeOfType( |
22 | | - AST_NODE_TYPES.AssignmentExpression |
23 | | -); |
24 | | -export const isChainExpression = ASTUtils.isNodeOfType( |
25 | | - AST_NODE_TYPES.ChainExpression |
26 | | -); |
27 | | -export const isSequenceExpression = ASTUtils.isNodeOfType( |
28 | | - AST_NODE_TYPES.SequenceExpression |
29 | | -); |
30 | | -export const isImportDeclaration = ASTUtils.isNodeOfType( |
31 | | - AST_NODE_TYPES.ImportDeclaration |
32 | | -); |
33 | | -export const isImportDefaultSpecifier = ASTUtils.isNodeOfType( |
34 | | - AST_NODE_TYPES.ImportDefaultSpecifier |
35 | | -); |
36 | | -export const isTSImportEqualsDeclaration = ASTUtils.isNodeOfType( |
37 | | - AST_NODE_TYPES.TSImportEqualsDeclaration |
38 | | -); |
39 | | -export const isImportExpression = ASTUtils.isNodeOfType( |
40 | | - AST_NODE_TYPES.ImportExpression |
41 | | -); |
42 | | -export const isImportNamespaceSpecifier = ASTUtils.isNodeOfType( |
43 | | - AST_NODE_TYPES.ImportNamespaceSpecifier |
44 | | -); |
45 | | -export const isImportSpecifier = ASTUtils.isNodeOfType( |
46 | | - AST_NODE_TYPES.ImportSpecifier |
47 | | -); |
48 | | -export const isJSXAttribute = ASTUtils.isNodeOfType( |
49 | | - AST_NODE_TYPES.JSXAttribute |
50 | | -); |
51 | | -export const isLiteral = ASTUtils.isNodeOfType(AST_NODE_TYPES.Literal); |
52 | | -export const isTemplateLiteral = ASTUtils.isNodeOfType( |
53 | | - AST_NODE_TYPES.TemplateLiteral |
54 | | -); |
55 | | -export const isMemberExpression = ASTUtils.isNodeOfType( |
56 | | - AST_NODE_TYPES.MemberExpression |
57 | | -); |
58 | | -export const isNewExpression = ASTUtils.isNodeOfType( |
59 | | - AST_NODE_TYPES.NewExpression |
60 | | -); |
61 | | -export const isObjectExpression = ASTUtils.isNodeOfType( |
62 | | - AST_NODE_TYPES.ObjectExpression |
63 | | -); |
64 | | -export const isObjectPattern = ASTUtils.isNodeOfType( |
65 | | - AST_NODE_TYPES.ObjectPattern |
66 | | -); |
67 | | -export const isProperty = ASTUtils.isNodeOfType(AST_NODE_TYPES.Property); |
68 | | -export const isReturnStatement = ASTUtils.isNodeOfType( |
69 | | - AST_NODE_TYPES.ReturnStatement |
70 | | -); |
71 | | -export const isFunctionExpression = ASTUtils.isNodeOfType( |
72 | | - AST_NODE_TYPES.FunctionExpression |
| 3 | +import type { TSESTree } from '@typescript-eslint/utils'; |
| 4 | + |
| 5 | +// Explicit type for all node-type guards to avoid leaking non-portable inferred types |
| 6 | +type NodeGuard<T extends TSESTree.Node> = ( |
| 7 | + node: TSESTree.Node | null | undefined |
| 8 | +) => node is T; |
| 9 | + |
| 10 | +export const isArrayExpression: NodeGuard<TSESTree.ArrayExpression> = |
| 11 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ArrayExpression); |
| 12 | + |
| 13 | +export const isArrowFunctionExpression: NodeGuard<TSESTree.ArrowFunctionExpression> = |
| 14 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ArrowFunctionExpression); |
| 15 | + |
| 16 | +export const isBlockStatement: NodeGuard<TSESTree.BlockStatement> = |
| 17 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.BlockStatement); |
| 18 | + |
| 19 | +export const isCallExpression: NodeGuard<TSESTree.CallExpression> = |
| 20 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.CallExpression); |
| 21 | + |
| 22 | +export const isExpressionStatement: NodeGuard<TSESTree.ExpressionStatement> = |
| 23 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ExpressionStatement); |
| 24 | + |
| 25 | +export const isVariableDeclaration: NodeGuard<TSESTree.VariableDeclaration> = |
| 26 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.VariableDeclaration); |
| 27 | + |
| 28 | +export const isAssignmentExpression: NodeGuard<TSESTree.AssignmentExpression> = |
| 29 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.AssignmentExpression); |
| 30 | + |
| 31 | +export const isChainExpression: NodeGuard<TSESTree.ChainExpression> = |
| 32 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ChainExpression); |
| 33 | + |
| 34 | +export const isSequenceExpression: NodeGuard<TSESTree.SequenceExpression> = |
| 35 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.SequenceExpression); |
| 36 | + |
| 37 | +export const isImportDeclaration: NodeGuard<TSESTree.ImportDeclaration> = |
| 38 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportDeclaration); |
| 39 | + |
| 40 | +export const isImportDefaultSpecifier: NodeGuard<TSESTree.ImportDefaultSpecifier> = |
| 41 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportDefaultSpecifier); |
| 42 | + |
| 43 | +export const isTSImportEqualsDeclaration: NodeGuard<TSESTree.TSImportEqualsDeclaration> = |
| 44 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.TSImportEqualsDeclaration); |
| 45 | + |
| 46 | +export const isImportExpression: NodeGuard<TSESTree.ImportExpression> = |
| 47 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportExpression); |
| 48 | + |
| 49 | +export const isImportNamespaceSpecifier: NodeGuard<TSESTree.ImportNamespaceSpecifier> = |
| 50 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportNamespaceSpecifier); |
| 51 | + |
| 52 | +export const isImportSpecifier: NodeGuard<TSESTree.ImportSpecifier> = |
| 53 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ImportSpecifier); |
| 54 | + |
| 55 | +export const isJSXAttribute: NodeGuard<TSESTree.JSXAttribute> = |
| 56 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.JSXAttribute); |
| 57 | + |
| 58 | +export const isLiteral: NodeGuard<TSESTree.Literal> = ASTUtils.isNodeOfType( |
| 59 | + AST_NODE_TYPES.Literal |
73 | 60 | ); |
74 | | -export const isFunctionDeclaration = ASTUtils.isNodeOfType( |
75 | | - AST_NODE_TYPES.FunctionDeclaration |
| 61 | +export const isTemplateLiteral: NodeGuard<TSESTree.TemplateLiteral> = |
| 62 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.TemplateLiteral); |
| 63 | + |
| 64 | +export const isMemberExpression: NodeGuard<TSESTree.MemberExpression> = |
| 65 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.MemberExpression); |
| 66 | + |
| 67 | +export const isNewExpression: NodeGuard<TSESTree.NewExpression> = |
| 68 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.NewExpression); |
| 69 | + |
| 70 | +export const isObjectExpression: NodeGuard<TSESTree.ObjectExpression> = |
| 71 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ObjectExpression); |
| 72 | + |
| 73 | +export const isObjectPattern: NodeGuard<TSESTree.ObjectPattern> = |
| 74 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ObjectPattern); |
| 75 | + |
| 76 | +export const isProperty: NodeGuard<TSESTree.Property> = ASTUtils.isNodeOfType( |
| 77 | + AST_NODE_TYPES.Property |
76 | 78 | ); |
| 79 | + |
| 80 | +export const isReturnStatement: NodeGuard<TSESTree.ReturnStatement> = |
| 81 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.ReturnStatement); |
| 82 | + |
| 83 | +export const isFunctionExpression: NodeGuard<TSESTree.FunctionExpression> = |
| 84 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.FunctionExpression); |
| 85 | + |
| 86 | +export const isFunctionDeclaration: NodeGuard<TSESTree.FunctionDeclaration> = |
| 87 | + ASTUtils.isNodeOfType(AST_NODE_TYPES.FunctionDeclaration); |
0 commit comments