@@ -705,9 +705,11 @@ namespace ts {
705
705
return filterSemanticDiagnotics ( diagnostics , state . compilerOptions ) ;
706
706
}
707
707
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 ] [ ] ;
711
713
export type ProgramBuildInfoBuilderStateFileInfo = Omit < BuilderState . FileInfo , "signature" > & {
712
714
/**
713
715
* Signature is
@@ -725,7 +727,7 @@ namespace ts {
725
727
fileNames : readonly string [ ] ;
726
728
fileInfos : readonly ProgramBuildInfoFileInfo [ ] ;
727
729
options : CompilerOptions | undefined ;
728
- fileIdsList ?: readonly ( readonly number [ ] ) [ ] ;
730
+ fileIdsList ?: readonly ( readonly ProgramBuildInfoFileId [ ] ) [ ] ;
729
731
referencedMap ?: ProgramBuildInfoReferencedMap ;
730
732
exportedModulesMap ?: ProgramBuildInfoReferencedMap ;
731
733
semanticDiagnosticsPerFile ?: ProgramBuildInfoDiagnostic [ ] ;
@@ -740,9 +742,9 @@ namespace ts {
740
742
const currentDirectory = Debug . checkDefined ( state . program ) . getCurrentDirectory ( ) ;
741
743
const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( getTsBuildInfoEmitOutputFilePath ( state . compilerOptions ) ! , currentDirectory ) ) ;
742
744
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 ;
746
748
const fileInfos = arrayFrom ( state . fileInfos . entries ( ) , ( [ key , value ] ) : ProgramBuildInfoFileInfo => {
747
749
// Ensure fileId
748
750
const fileId = toFileId ( key ) ;
@@ -825,22 +827,22 @@ namespace ts {
825
827
return ensurePathIsNonModuleName ( getRelativePathFromDirectory ( buildInfoDirectory , path , getCanonicalFileName ) ) ;
826
828
}
827
829
828
- function toFileId ( path : Path ) : number {
830
+ function toFileId ( path : Path ) : ProgramBuildInfoFileId {
829
831
let fileId = fileNameToFileId . get ( path ) ;
830
832
if ( fileId === undefined ) {
831
833
fileNames . push ( relativeToBuildInfo ( path ) ) ;
832
- fileNameToFileId . set ( path , fileId = fileNames . length ) ;
834
+ fileNameToFileId . set ( path , fileId = fileNames . length as ProgramBuildInfoFileId ) ;
833
835
}
834
836
return fileId ;
835
837
}
836
838
837
- function toFileIdListId ( set : ReadonlySet < Path > ) : number {
839
+ function toFileIdListId ( set : ReadonlySet < Path > ) : ProgramBuildInfoFileIdListId {
838
840
const fileIds = arrayFrom ( set . keys ( ) , toFileId ) . sort ( compareValues ) ;
839
841
const key = fileIds . join ( ) ;
840
842
let fileIdListId = fileNamesToFileIdListId ?. get ( key ) ;
841
843
if ( fileIdListId === undefined ) {
842
844
( fileIdsList ||= [ ] ) . push ( fileIds ) ;
843
- ( fileNamesToFileIdListId ||= new Map ( ) ) . set ( key , fileIdListId = fileIdsList . length ) ;
845
+ ( fileNamesToFileIdListId ||= new Map ( ) ) . set ( key , fileIdListId = fileIdsList . length as ProgramBuildInfoFileIdListId ) ;
844
846
}
845
847
return fileIdListId ;
846
848
}
@@ -1249,7 +1251,7 @@ namespace ts {
1249
1251
const filePaths = program . fileNames . map ( toPath ) ;
1250
1252
const filePathsSetList = program . fileIdsList ?. map ( fileIds => new Set ( fileIds . map ( toFilePath ) ) ) ;
1251
1253
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 ) ) ) ;
1253
1255
const state : ReusableBuilderProgramState = {
1254
1256
fileInfos,
1255
1257
compilerOptions : program . options ? convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) : { } ,
@@ -1294,11 +1296,11 @@ namespace ts {
1294
1296
return getNormalizedAbsolutePath ( path , buildInfoDirectory ) ;
1295
1297
}
1296
1298
1297
- function toFilePath ( fileId : number ) {
1299
+ function toFilePath ( fileId : ProgramBuildInfoFileId ) {
1298
1300
return filePaths [ fileId - 1 ] ;
1299
1301
}
1300
1302
1301
- function toFilePathsSet ( fileIdsListId : number ) {
1303
+ function toFilePathsSet ( fileIdsListId : ProgramBuildInfoFileIdListId ) {
1302
1304
return filePathsSetList ! [ fileIdsListId - 1 ] ;
1303
1305
}
1304
1306
0 commit comments