트리 셰이킹은 번들러가 사용되지 않는 export를 제거해 번들 크기를 줄이는 기법입니다. 이를 시뮬레이션하는 DeadCodeAnalyzer를 구현하세요.
모듈 그래프를 구성하고, 진입점(entry module)에서 시작해 임포트 그래프를 순회한 뒤, 한 번도 임포트되지 않은 export를 찾아냅니다.
interface DeadExport {
module: string;
exportName: string;
}
class DeadCodeAnalyzer {
addExport(module: string, name: string): void;
addImport(fromModule: string, toModule: string, name: string): void;
findDead(entryModule: string): DeadExport[];
}
addImport(from, to, name): from 모듈이 to 모듈의 name export를 사용findDead(entry)는:
entry에서 시작해 import 관계를 따라 도달 가능한 모듈을 모두 방문module 알파벳 오름차순, 동일 module 내에서는 exportName 알파벳 오름차순