11import type { ReportOptions } from '@vitest/istanbul-lib-report'
22import type { Arrayable } from '@vitest/utils'
3- import type { DevEnvironment , ESTree , TransformResult as ViteTransformResult } from 'vite'
3+ import type { DevEnvironment , parseAstAsync , TransformResult as ViteTransformResult } from 'vite'
44import type { AfterSuiteRunMeta } from '../../types/general'
55import type {
66 RuntimeCoverageModuleLoader ,
@@ -12,6 +12,22 @@ import type { TestSpecification } from '../test-specification'
1212type TransformResult = string | Partial < ViteTransformResult > | undefined | null | void
1313type CoverageResults = unknown
1414
15+ // Vite 6 and 7 parse with Rollup, Vite 8 with Rolldown. Collect node types from whichever parser is installed.
16+ type AstNode = CollectNodes < Awaited < ReturnType < typeof parseAstAsync > > >
17+ type CollectNodes < T , Depth extends unknown [ ] = [ ] > = Depth [ 'length' ] extends 8
18+ ? T
19+ : CollectNodes < T | ChildNodes < T > , [ ...Depth , unknown ] >
20+ type ChildNodes < T > = T extends unknown
21+ ? Extract <
22+ {
23+ [ K in keyof T ] : NonNullable < T [ K ] > extends readonly ( infer U ) [ ]
24+ ? NonNullable < U >
25+ : NonNullable < T [ K ] >
26+ } [ keyof T ] ,
27+ { type : string }
28+ >
29+ : never
30+
1531export interface CoverageProvider {
1632 name : string
1733
@@ -302,7 +318,7 @@ export interface CoverageOptions {
302318 * ```
303319 */
304320 ignoreNode ?: (
305- node : ESTree . Node ,
321+ node : AstNode ,
306322 type : 'function' | 'statement' | 'branch' ,
307323 ) => boolean | 'ignore-this-and-nested-nodes' | void
308324
0 commit comments