-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(node-utils): extract
isNodeOfType
functions (#329)
* refactor(node-utils): extract isNodeOfType functions * refactor(node-utils): make isNodeOfType more type-safe
- Loading branch information
1 parent
9931a51
commit 445adc8
Showing
2 changed files
with
50 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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 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); |