@@ -43,20 +43,31 @@ export function isProcessEnvNodeEnvCompare(
4343 return false ;
4444}
4545
46+ /**
47+ * Checks if the given node is a `vi.mock`.
48+ * @param node The node to check
49+ * @returns `true` if the node is a `vi.mock`, otherwise `false`.
50+ * @internal
51+ */
52+ export function isViMock ( node : TSESTree . Node | null | unit ) : node is TSESTree . MemberExpression {
53+ return node != null
54+ && node . type === T . MemberExpression
55+ && node . object . type === T . Identifier
56+ && node . object . name === "vi"
57+ && node . property . type === T . Identifier
58+ && node . property . name === "mock" ;
59+ }
60+
4661/**
4762 * Checks if the given node is a `vi.mock` callback.
4863 * @param node The node to check
4964 * @returns `true` if the node is a `vi.mock` callback, otherwise `false`.
5065 * @internal
5166 */
52- export function isViMockCallback ( node : TSESTree . Node | null | unit ) : node is TSESTree . FunctionExpression {
67+ export function isViMockCallback ( node : TSESTree . Node | null | unit ) {
5368 return node != null
54- && node . type === T . FunctionExpression
69+ && AST . isFunction ( node )
5570 && node . parent . type === T . CallExpression
56- && node . parent . callee . type === T . MemberExpression
57- && node . parent . callee . object . type === T . Identifier
58- && node . parent . callee . object . name === "vi"
59- && node . parent . callee . property . type === T . Identifier
60- && node . parent . callee . property . name === "mock"
71+ && isViMock ( node . parent . callee )
6172 && node . parent . arguments [ 1 ] === node ;
6273}
0 commit comments