import { Reason } from '../../../types/Stats' ; import ModuleIdToNameMap from './ModuleIdToNameMap' ; export function processReasons ( reasons , moduleIdToNameMap ) { const directParents = new Set < string > ( ) ; const lazyParents = new Set < string > ( ) ; let entryType = undefined ; for ( const reason of reasons ) { if ( ! reason . type ) { continue ; } else if ( reason . type . endsWith ( 'entry' ) ) { entryType = reason . type ; continue ; } const moduleName = ( reason . moduleId && moduleIdToNameMap . get ( reason . moduleId ) ) || reason . moduleName ; if ( ! moduleName ) { throw new Error ( `Unable to determine module name.` ) ; } const isLazyParent = reason . type === 'import()' ; if ( isLazyParent ) { lazyParents . add ( moduleName ) ; } else { directParents . add ( moduleName ) ; } } return { parents : [ ... directParents , ... lazyParents ] , directParents : [ ... directParents ] , lazyParents : [ ... lazyParents ] , entryType , } ; }