import { NamedNode , Node , NodeFlags , NodeKind , NodeObject , ReferenceNode , TypeFlags } from '#ast' ; import { NodeMap , NodeSet } from '#ast/components' ; export const fakeNodeKind = 0 ; /**
 * Get array of [ classname, string ] for class (Use with test.each / describe.each)
 */ export const getClassStringMap = ( ... cls ) => cls . map ( c => < [ string , typeof c ] > [ c . name , c ] ) ; /**
 * Workaround to convert Node Iterables to jest-safe versions
 * Related to: https://github.com/facebook/jest/issues/10199
 */ export function makeJestSafe < T > ( v ) { const cache = new Map ( ) ; return ( function visit ( v ) { if ( cache . has ( v ) ) return cache . get ( v ) ; const addCache = ( result ) => { cache . set ( v , result ) ; return result ; } ; if ( ! ( typeof v === 'object' ) || Array . isArray ( v ) ) return addCache ( ( v && v [ 'map' ] ) ? v . map ( visit ) : v ) ; if ( v instanceof NodeMap ) return addCache ( new Map ( v ) ) ; if ( v instanceof NodeSet ) return addCache ( new Set ( v ) ) ; const descriptors = Object . getOwnPropertyDescriptors ( v ) ; let res = { } as T ; addCache ( res ) ; Object . entries ( descriptors ) . forEach ( ( [ name , descriptor ] ) => { if ( descriptor . hasOwnProperty ( 'value' ) ) Object . defineProperty ( res , name , { ... descriptor , value : visit ( descriptor . value ) } ) ; } ) ; return res ; } ) ( v ) ; } export const createFakeNode = ( parent ? , props ? , kind = fakeNodeKind ) => new NodeObject ( kind , void 0 , void 0 ) . updateProperties ( < any > { parent , flags : NodeFlags . Named , ... props } ) as Node ; export const createFakeReferenceNode = ( parent , target ) => createFakeNode ( parent ) . updateProperties ( < any > { kind : NodeKind . Reference , typeFlags : TypeFlags . Reference , target } ) as ReferenceNode ; export const createFakeNodes = ( count , parent ? , props ? ) => { const res = [ ] ; for ( let i = 1 ; i <= count ; i ++ ) res . push ( createFakeNode ( parent ) . updateProperties ( < any > { name : `${ ! parent ? 'Root' : 'Child' }Node${ i }` } ) as any as NamedNode ) ; return res ; } ; export const createNodeIterable = < T extends { new ( ... args ) : NodeSet < any > | NodeMap < any > ; } > ( cls , nodes ) => new cls ( nodes ) ;