@@ -708,10 +708,23 @@ namespace ts {
708708 export type ProgramBuildInfoDiagnostic = number | [ fileId : number , diagnostics : readonly ReusableDiagnostic [ ] ] ;
709709 export type ProgramBuilderInfoFilePendingEmit = [ fileId : number , emitKind : BuilderFileEmit ] ;
710710 export type ProgramBuildInfoReferencedMap = [ fileId : number , fileIdListId : number ] [ ] ;
711+ export type ProgramBuildInfoBuilderStateFileInfo = Omit < BuilderState . FileInfo , "signature" > & {
712+ /**
713+ * Signature is
714+ * - undefined if FileInfo.version === FileInfo.signature
715+ * - false if FileInfo has signature as undefined (not calculated)
716+ * - string actual signature
717+ */
718+ signature : string | false | undefined ;
719+ } ;
720+ /**
721+ * ProgramBuildInfoFileInfo is string if FileInfo.version === FileInfo.signature && !FileInfo.affectsGlobalScope otherwise encoded FileInfo
722+ */
723+ export type ProgramBuildInfoFileInfo = string | ProgramBuildInfoBuilderStateFileInfo ;
711724 export interface ProgramBuildInfo {
712725 fileNames : readonly string [ ] ;
713- fileInfos : readonly BuilderState . FileInfo [ ] ;
714- options : CompilerOptions ;
726+ fileInfos : readonly ProgramBuildInfoFileInfo [ ] ;
727+ options : CompilerOptions | undefined ;
715728 fileIdsList ?: readonly ( readonly number [ ] ) [ ] ;
716729 referencedMap ?: ProgramBuildInfoReferencedMap ;
717730 exportedModulesMap ?: ProgramBuildInfoReferencedMap ;
@@ -730,12 +743,21 @@ namespace ts {
730743 const fileNameToFileId = new Map < string , number > ( ) ;
731744 let fileIdsList : ( readonly number [ ] ) [ ] | undefined ;
732745 let fileNamesToFileIdListId : ESMap < string , number > | undefined ;
733- const fileInfos = arrayFrom ( state . fileInfos . entries ( ) , ( [ key , value ] ) => {
746+ const fileInfos = arrayFrom ( state . fileInfos . entries ( ) , ( [ key , value ] ) : ProgramBuildInfoFileInfo => {
734747 // Ensure fileId
735748 const fileId = toFileId ( key ) ;
736749 Debug . assert ( fileNames [ fileId - 1 ] === relativeToBuildInfo ( key ) ) ;
737750 const signature = state . currentAffectedFilesSignatures && state . currentAffectedFilesSignatures . get ( key ) ;
738- return signature === undefined ? value : { version : value . version , signature, affectsGlobalScope : value . affectsGlobalScope } ;
751+ const actualSignature = signature ?? value . signature ;
752+ return value . version === actualSignature ?
753+ value . affectsGlobalScope ?
754+ { version : value . version , signature : undefined , affectsGlobalScope : true } :
755+ value . version :
756+ actualSignature !== undefined ?
757+ signature === undefined ?
758+ value :
759+ { version : value . version , signature, affectsGlobalScope : value . affectsGlobalScope } :
760+ { version : value . version , signature : false , affectsGlobalScope : value . affectsGlobalScope } ;
739761 } ) ;
740762
741763 let referencedMap : ProgramBuildInfoReferencedMap | undefined ;
@@ -787,7 +809,7 @@ namespace ts {
787809 return {
788810 fileNames,
789811 fileInfos,
790- options : convertToReusableCompilerOptions ( state . compilerOptions , relativeToBuildInfoEnsuringAbsolutePath ) ,
812+ options : convertToProgramBuildInfoCompilerOptions ( state . compilerOptions , relativeToBuildInfoEnsuringAbsolutePath ) ,
791813 fileIdsList,
792814 referencedMap,
793815 exportedModulesMap,
@@ -824,22 +846,20 @@ namespace ts {
824846 }
825847 }
826848
827- function convertToReusableCompilerOptions ( options : CompilerOptions , relativeToBuildInfo : ( path : string ) => string ) {
828- const result : CompilerOptions = { } ;
849+ function convertToProgramBuildInfoCompilerOptions ( options : CompilerOptions , relativeToBuildInfo : ( path : string ) => string ) {
850+ let result : CompilerOptions | undefined ;
829851 const { optionsNameMap } = getOptionsNameMap ( ) ;
830852
831- for ( const name in options ) {
832- if ( hasProperty ( options , name ) ) {
833- result [ name ] = convertToReusableCompilerOptionValue (
834- optionsNameMap . get ( name . toLowerCase ( ) ) ,
853+ for ( const name of getOwnKeys ( options ) . sort ( compareStringsCaseSensitive ) ) {
854+ const optionInfo = optionsNameMap . get ( name . toLowerCase ( ) ) ;
855+ if ( optionInfo ?. affectsEmit || optionInfo ?. affectsSemanticDiagnostics || name === "skipLibCheck" || name === "skipDefaultLibCheck" ) {
856+ ( result ||= { } ) [ name ] = convertToReusableCompilerOptionValue (
857+ optionInfo ,
835858 options [ name ] as CompilerOptionsValue ,
836859 relativeToBuildInfo
837860 ) ;
838861 }
839862 }
840- if ( result . configFilePath ) {
841- result . configFilePath = relativeToBuildInfo ( result . configFilePath ) ;
842- }
843863 return result ;
844864 }
845865
@@ -1213,17 +1233,25 @@ namespace ts {
12131233 }
12141234 }
12151235
1236+ export function toBuilderStateFileInfo ( fileInfo : ProgramBuildInfoFileInfo ) : BuilderState . FileInfo {
1237+ return isString ( fileInfo ) ?
1238+ { version : fileInfo , signature : fileInfo , affectsGlobalScope : undefined } :
1239+ isString ( fileInfo . signature ) ?
1240+ fileInfo as BuilderState . FileInfo :
1241+ { version : fileInfo . version , signature : fileInfo . signature === false ? undefined : fileInfo . version , affectsGlobalScope : fileInfo . affectsGlobalScope } ;
1242+ }
1243+
12161244 export function createBuildProgramUsingProgramBuildInfo ( program : ProgramBuildInfo , buildInfoPath : string , host : ReadBuildProgramHost ) : EmitAndSemanticDiagnosticsBuilderProgram {
12171245 const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath , host . getCurrentDirectory ( ) ) ) ;
12181246 const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ( ) ) ;
12191247
12201248 const filePaths = program . fileNames . map ( toPath ) ;
12211249 const filePathsSetList = program . fileIdsList ?. map ( fileIds => new Set ( fileIds . map ( toFilePath ) ) ) ;
12221250 const fileInfos = new Map < Path , BuilderState . FileInfo > ( ) ;
1223- program . fileInfos . forEach ( ( fileInfo , index ) => fileInfos . set ( toFilePath ( index + 1 ) , fileInfo ) ) ;
1251+ program . fileInfos . forEach ( ( fileInfo , index ) => fileInfos . set ( toFilePath ( index + 1 ) , toBuilderStateFileInfo ( fileInfo ) ) ) ;
12241252 const state : ReusableBuilderProgramState = {
12251253 fileInfos,
1226- compilerOptions : convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) ,
1254+ compilerOptions : program . options ? convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) : { } ,
12271255 referencedMap : toMapOfReferencedSet ( program . referencedMap ) ,
12281256 exportedModulesMap : toMapOfReferencedSet ( program . exportedModulesMap ) ,
12291257 semanticDiagnosticsPerFile : program . semanticDiagnosticsPerFile && arrayToMap ( program . semanticDiagnosticsPerFile , value => toFilePath ( isNumber ( value ) ? value : value [ 0 ] ) , value => isNumber ( value ) ? emptyArray : value [ 1 ] ) ,
0 commit comments