import { Package } from "./common" import { SourceFile } from "./ast" import { FastStringMap } from "./util"; export class Program { private transformed = new FastStringMap(); constructor( pkgs: Package[] ) { for (const pkg of pkgs) { for (const sourceFile of pkg.sourceFiles) { this.transformed.set(sourceFile.span!.file.fullPath, sourceFile); } } } public getAllSourceFiles() { return this.transformed.values(); } public updateSourceFile(oldSourceFile: SourceFile, newSourceFile: SourceFile): void { if (!this.transformed.has(oldSourceFile.span!.file.fullPath)) { throw new Error(`Could not update ${oldSourceFile.span!.file.origPath} because it was not found in this program.`); } this.transformed.delete(oldSourceFile.span!.file.fullPath); this.transformed.set(newSourceFile.span!.file.fullPath, newSourceFile); } }