From caa6f22d57013009c0eb3393c047bdeea83234d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sun, 1 Aug 2021 03:30:20 +0200 Subject: [PATCH] feat(experimental-utils): extract `isNodeOfType` out of `ast-utils`' `predicates` --- .../src/ast-utils/predicates.ts | 37 ++++++------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/packages/experimental-utils/src/ast-utils/predicates.ts b/packages/experimental-utils/src/ast-utils/predicates.ts index 919820d7653d..7a7bcf520b1a 100644 --- a/packages/experimental-utils/src/ast-utils/predicates.ts +++ b/packages/experimental-utils/src/ast-utils/predicates.ts @@ -1,5 +1,12 @@ import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from '../ts-estree'; +const isNodeOfType = + (nodeType: NodeType) => + ( + node: TSESTree.Node | null | undefined, + ): node is TSESTree.Node & { type: NodeType } => + node?.type === nodeType; + function isOptionalChainPunctuator( token: TSESTree.Token, ): token is TSESTree.PunctuatorToken & { value: '?.' } { @@ -69,11 +76,7 @@ function isTypeAssertion( ); } -function isVariableDeclarator( - node: TSESTree.Node | undefined, -): node is TSESTree.VariableDeclarator { - return node?.type === AST_NODE_TYPES.VariableDeclarator; -} +const isVariableDeclarator = isNodeOfType(AST_NODE_TYPES.VariableDeclarator); function isFunction( node: TSESTree.Node | undefined, @@ -130,17 +133,9 @@ function isFunctionOrFunctionType( return isFunction(node) || isFunctionType(node); } -function isTSFunctionType( - node: TSESTree.Node | undefined, -): node is TSESTree.TSFunctionType { - return node?.type === AST_NODE_TYPES.TSFunctionType; -} +const isTSFunctionType = isNodeOfType(AST_NODE_TYPES.TSFunctionType); -function isTSConstructorType( - node: TSESTree.Node | undefined, -): node is TSESTree.TSConstructorType { - return node?.type === AST_NODE_TYPES.TSConstructorType; -} +const isTSConstructorType = isNodeOfType(AST_NODE_TYPES.TSConstructorType); function isClassOrTypeElement( node: TSESTree.Node | undefined, @@ -193,20 +188,12 @@ function isSetter( ); } -function isIdentifier( - node: TSESTree.Node | undefined, -): node is TSESTree.Identifier { - return node?.type === AST_NODE_TYPES.Identifier; -} +const isIdentifier = isNodeOfType(AST_NODE_TYPES.Identifier); /** * Checks if a node represents an `await …` expression. */ -function isAwaitExpression( - node: TSESTree.Node | undefined | null, -): node is TSESTree.AwaitExpression { - return node?.type === AST_NODE_TYPES.AwaitExpression; -} +const isAwaitExpression = isNodeOfType(AST_NODE_TYPES.AwaitExpression); /** * Checks if a possible token is the `await` keyword. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy