@@ -705,9 +705,11 @@ namespace ts {
705705 return filterSemanticDiagnotics ( diagnostics , state . compilerOptions ) ;
706706 }
707707
708- export type ProgramBuildInfoDiagnostic = number | [ fileId : number , diagnostics : readonly ReusableDiagnostic [ ] ] ;
709- export type ProgramBuilderInfoFilePendingEmit = [ fileId : number , emitKind : BuilderFileEmit ] ;
710- export type ProgramBuildInfoReferencedMap = [ fileId : number , fileIdListId : number ] [ ] ;
708+ export type ProgramBuildInfoFileId = number & { __programBuildInfoFileIdBrand : any } ;
709+ export type ProgramBuildInfoFileIdListId = number & { __programBuildInfoFileIdListIdBrand : any } ;
710+ export type ProgramBuildInfoDiagnostic = ProgramBuildInfoFileId | [ fileId : ProgramBuildInfoFileId , diagnostics : readonly ReusableDiagnostic [ ] ] ;
711+ export type ProgramBuilderInfoFilePendingEmit = [ fileId : ProgramBuildInfoFileId , emitKind : BuilderFileEmit ] ;
712+ export type ProgramBuildInfoReferencedMap = [ fileId : ProgramBuildInfoFileId , fileIdListId : ProgramBuildInfoFileIdListId ] [ ] ;
711713 export type ProgramBuildInfoBuilderStateFileInfo = Omit < BuilderState . FileInfo , "signature" > & {
712714 /**
713715 * Signature is
@@ -725,7 +727,7 @@ namespace ts {
725727 fileNames : readonly string [ ] ;
726728 fileInfos : readonly ProgramBuildInfoFileInfo [ ] ;
727729 options : CompilerOptions | undefined ;
728- fileIdsList ?: readonly ( readonly number [ ] ) [ ] ;
730+ fileIdsList ?: readonly ( readonly ProgramBuildInfoFileId [ ] ) [ ] ;
729731 referencedMap ?: ProgramBuildInfoReferencedMap ;
730732 exportedModulesMap ?: ProgramBuildInfoReferencedMap ;
731733 semanticDiagnosticsPerFile ?: ProgramBuildInfoDiagnostic [ ] ;
@@ -740,9 +742,9 @@ namespace ts {
740742 const currentDirectory = Debug . checkDefined ( state . program ) . getCurrentDirectory ( ) ;
741743 const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( getTsBuildInfoEmitOutputFilePath ( state . compilerOptions ) ! , currentDirectory ) ) ;
742744 const fileNames : string [ ] = [ ] ;
743- const fileNameToFileId = new Map < string , number > ( ) ;
744- let fileIdsList : ( readonly number [ ] ) [ ] | undefined ;
745- let fileNamesToFileIdListId : ESMap < string , number > | undefined ;
745+ const fileNameToFileId = new Map < string , ProgramBuildInfoFileId > ( ) ;
746+ let fileIdsList : ( readonly ProgramBuildInfoFileId [ ] ) [ ] | undefined ;
747+ let fileNamesToFileIdListId : ESMap < string , ProgramBuildInfoFileIdListId > | undefined ;
746748 const fileInfos = arrayFrom ( state . fileInfos . entries ( ) , ( [ key , value ] ) : ProgramBuildInfoFileInfo => {
747749 // Ensure fileId
748750 const fileId = toFileId ( key ) ;
@@ -825,22 +827,22 @@ namespace ts {
825827 return ensurePathIsNonModuleName ( getRelativePathFromDirectory ( buildInfoDirectory , path , getCanonicalFileName ) ) ;
826828 }
827829
828- function toFileId ( path : Path ) : number {
830+ function toFileId ( path : Path ) : ProgramBuildInfoFileId {
829831 let fileId = fileNameToFileId . get ( path ) ;
830832 if ( fileId === undefined ) {
831833 fileNames . push ( relativeToBuildInfo ( path ) ) ;
832- fileNameToFileId . set ( path , fileId = fileNames . length ) ;
834+ fileNameToFileId . set ( path , fileId = fileNames . length as ProgramBuildInfoFileId ) ;
833835 }
834836 return fileId ;
835837 }
836838
837- function toFileIdListId ( set : ReadonlySet < Path > ) : number {
839+ function toFileIdListId ( set : ReadonlySet < Path > ) : ProgramBuildInfoFileIdListId {
838840 const fileIds = arrayFrom ( set . keys ( ) , toFileId ) . sort ( compareValues ) ;
839841 const key = fileIds . join ( ) ;
840842 let fileIdListId = fileNamesToFileIdListId ?. get ( key ) ;
841843 if ( fileIdListId === undefined ) {
842844 ( fileIdsList ||= [ ] ) . push ( fileIds ) ;
843- ( fileNamesToFileIdListId ||= new Map ( ) ) . set ( key , fileIdListId = fileIdsList . length ) ;
845+ ( fileNamesToFileIdListId ||= new Map ( ) ) . set ( key , fileIdListId = fileIdsList . length as ProgramBuildInfoFileIdListId ) ;
844846 }
845847 return fileIdListId ;
846848 }
@@ -1249,7 +1251,7 @@ namespace ts {
12491251 const filePaths = program . fileNames . map ( toPath ) ;
12501252 const filePathsSetList = program . fileIdsList ?. map ( fileIds => new Set ( fileIds . map ( toFilePath ) ) ) ;
12511253 const fileInfos = new Map < Path , BuilderState . FileInfo > ( ) ;
1252- program . fileInfos . forEach ( ( fileInfo , index ) => fileInfos . set ( toFilePath ( index + 1 ) , toBuilderStateFileInfo ( fileInfo ) ) ) ;
1254+ program . fileInfos . forEach ( ( fileInfo , index ) => fileInfos . set ( toFilePath ( index + 1 as ProgramBuildInfoFileId ) , toBuilderStateFileInfo ( fileInfo ) ) ) ;
12531255 const state : ReusableBuilderProgramState = {
12541256 fileInfos,
12551257 compilerOptions : program . options ? convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) : { } ,
@@ -1294,11 +1296,11 @@ namespace ts {
12941296 return getNormalizedAbsolutePath ( path , buildInfoDirectory ) ;
12951297 }
12961298
1297- function toFilePath ( fileId : number ) {
1299+ function toFilePath ( fileId : ProgramBuildInfoFileId ) {
12981300 return filePaths [ fileId - 1 ] ;
12991301 }
13001302
1301- function toFilePathsSet ( fileIdsListId : number ) {
1303+ function toFilePathsSet ( fileIdsListId : ProgramBuildInfoFileIdListId ) {
13021304 return filePathsSetList ! [ fileIdsListId - 1 ] ;
13031305 }
13041306
0 commit comments