import type * as ts from 'typescript' ; import { core } from '../../core/core' ; import { RandomPropertyAccessor } from '../random/random' ; import { IsTsAutoMockRandomEnabled } from '../../../options/random' ; import { createCall , createNumericLiteral , createStringLiteral , } from '../../../typescriptFactory/typescriptFactory' ; export function GetEnumDeclarationDescriptor ( node ) { const typeChecker = core . typeChecker ; if ( IsTsAutoMockRandomEnabled ( ) ) { const nodesList = node . members . map ( ( member , index ) => getEnumMemberValue ( typeChecker , member , index ) ) ; return createCall ( RandomPropertyAccessor ( 'enumValue' ) , nodesList ) ; } return getEnumMemberValue ( typeChecker , node . members [ 0 ] ) ; } function getEnumMemberValue ( typeChecker , member , defaultValue = 0 ) { const value = typeChecker . getConstantValue ( member ) || defaultValue ; if ( typeof value === 'number' ) { return createNumericLiteral ( value ) ; } return createStringLiteral ( value ) ; }