Skip to content

Commit df09b1a

Browse files
committed
refactor: add isTemplateLiteral utility function and update isSimpleTemplateLiteral to use it
1 parent d426a29 commit df09b1a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/node-utils/accessors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
type TSESTree,
55
} from '@typescript-eslint/utils';
66

7-
import { isLiteral } from './is-node-of-type';
7+
import { isLiteral, isTemplateLiteral } from './is-node-of-type';
88

99
/**
1010
* A `Literal` with a `value` of type `string`.
@@ -45,7 +45,7 @@ const isSimpleTemplateLiteral = <V extends string>(
4545
node: TSESTree.Node,
4646
value?: V
4747
): node is TemplateLiteral<V> =>
48-
node.type === AST_NODE_TYPES.TemplateLiteral &&
48+
isTemplateLiteral(node) &&
4949
node.quasis.length === 1 && // bail out if not simple
5050
(value === undefined || node.quasis[0].value.raw === value);
5151

lib/node-utils/is-node-of-type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export const isJSXAttribute = ASTUtils.isNodeOfType(
4646
AST_NODE_TYPES.JSXAttribute
4747
);
4848
export const isLiteral = ASTUtils.isNodeOfType(AST_NODE_TYPES.Literal);
49+
export const isTemplateLiteral = ASTUtils.isNodeOfType(
50+
AST_NODE_TYPES.TemplateLiteral
51+
);
4952
export const isMemberExpression = ASTUtils.isNodeOfType(
5053
AST_NODE_TYPES.MemberExpression
5154
);

0 commit comments

Comments
 (0)