|
1 | 1 | import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from '../ts-estree';
|
2 | 2 |
|
| 3 | +const isNodeOfType = |
| 4 | + <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) => |
| 5 | + ( |
| 6 | + node: TSESTree.Node | null | undefined, |
| 7 | + ): node is TSESTree.Node & { type: NodeType } => |
| 8 | + node?.type === nodeType; |
| 9 | + |
3 | 10 | function isOptionalChainPunctuator(
|
4 | 11 | token: TSESTree.Token,
|
5 | 12 | ): token is TSESTree.PunctuatorToken & { value: '?.' } {
|
@@ -69,11 +76,7 @@ function isTypeAssertion(
|
69 | 76 | );
|
70 | 77 | }
|
71 | 78 |
|
72 |
| -function isVariableDeclarator( |
73 |
| - node: TSESTree.Node | undefined, |
74 |
| -): node is TSESTree.VariableDeclarator { |
75 |
| - return node?.type === AST_NODE_TYPES.VariableDeclarator; |
76 |
| -} |
| 79 | +const isVariableDeclarator = isNodeOfType(AST_NODE_TYPES.VariableDeclarator); |
77 | 80 |
|
78 | 81 | function isFunction(
|
79 | 82 | node: TSESTree.Node | undefined,
|
@@ -130,17 +133,9 @@ function isFunctionOrFunctionType(
|
130 | 133 | return isFunction(node) || isFunctionType(node);
|
131 | 134 | }
|
132 | 135 |
|
133 |
| -function isTSFunctionType( |
134 |
| - node: TSESTree.Node | undefined, |
135 |
| -): node is TSESTree.TSFunctionType { |
136 |
| - return node?.type === AST_NODE_TYPES.TSFunctionType; |
137 |
| -} |
| 136 | +const isTSFunctionType = isNodeOfType(AST_NODE_TYPES.TSFunctionType); |
138 | 137 |
|
139 |
| -function isTSConstructorType( |
140 |
| - node: TSESTree.Node | undefined, |
141 |
| -): node is TSESTree.TSConstructorType { |
142 |
| - return node?.type === AST_NODE_TYPES.TSConstructorType; |
143 |
| -} |
| 138 | +const isTSConstructorType = isNodeOfType(AST_NODE_TYPES.TSConstructorType); |
144 | 139 |
|
145 | 140 | function isClassOrTypeElement(
|
146 | 141 | node: TSESTree.Node | undefined,
|
@@ -193,20 +188,12 @@ function isSetter(
|
193 | 188 | );
|
194 | 189 | }
|
195 | 190 |
|
196 |
| -function isIdentifier( |
197 |
| - node: TSESTree.Node | undefined, |
198 |
| -): node is TSESTree.Identifier { |
199 |
| - return node?.type === AST_NODE_TYPES.Identifier; |
200 |
| -} |
| 191 | +const isIdentifier = isNodeOfType(AST_NODE_TYPES.Identifier); |
201 | 192 |
|
202 | 193 | /**
|
203 | 194 | * Checks if a node represents an `await …` expression.
|
204 | 195 | */
|
205 |
| -function isAwaitExpression( |
206 |
| - node: TSESTree.Node | undefined | null, |
207 |
| -): node is TSESTree.AwaitExpression { |
208 |
| - return node?.type === AST_NODE_TYPES.AwaitExpression; |
209 |
| -} |
| 196 | +const isAwaitExpression = isNodeOfType(AST_NODE_TYPES.AwaitExpression); |
210 | 197 |
|
211 | 198 | /**
|
212 | 199 | * Checks if a possible token is the `await` keyword.
|
|
0 commit comments