t-comm
Version:
专业、稳定、纯粹的工具库
18 lines (17 loc) • 844 B
TypeScript
import type { ComponentMapList } from './types';
/**
* 将嵌套的组件依赖关系打平为一维映射
* 递归遍历组件依赖树,将每个页面/组件的所有直接和间接依赖打平为数组
* @param {Record<string, any>} rawMap 原始组件依赖映射,key 为页面/组件名,value 为其直接依赖的组件映射
* @returns {ComponentMapList} 打平后的组件列表映射,key 为页面/组件名,value 为所有依赖组件名数组
* @example
* ```ts
* const rawMap = {
* 'pages/index': { 'comp-a': true, 'comp-b': true },
* 'comp-a': { 'comp-c': true },
* };
* const result = flattenUsingComponentMap(rawMap);
* // { 'pages/index': ['comp-a', 'comp-b', 'comp-c'], 'comp-a': ['comp-c'] }
* ```
*/
export declare function flattenUsingComponentMap(rawMap: Record<string, any>): ComponentMapList;