@@ -708,10 +708,23 @@ namespace ts {
708
708
export type ProgramBuildInfoDiagnostic = number | [ fileId : number , diagnostics : readonly ReusableDiagnostic [ ] ] ;
709
709
export type ProgramBuilderInfoFilePendingEmit = [ fileId : number , emitKind : BuilderFileEmit ] ;
710
710
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 ;
711
724
export interface ProgramBuildInfo {
712
725
fileNames : readonly string [ ] ;
713
- fileInfos : readonly BuilderState . FileInfo [ ] ;
714
- options : CompilerOptions ;
726
+ fileInfos : readonly ProgramBuildInfoFileInfo [ ] ;
727
+ options : CompilerOptions | undefined ;
715
728
fileIdsList ?: readonly ( readonly number [ ] ) [ ] ;
716
729
referencedMap ?: ProgramBuildInfoReferencedMap ;
717
730
exportedModulesMap ?: ProgramBuildInfoReferencedMap ;
@@ -730,12 +743,21 @@ namespace ts {
730
743
const fileNameToFileId = new Map < string , number > ( ) ;
731
744
let fileIdsList : ( readonly number [ ] ) [ ] | undefined ;
732
745
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 => {
734
747
// Ensure fileId
735
748
const fileId = toFileId ( key ) ;
736
749
Debug . assert ( fileNames [ fileId - 1 ] === relativeToBuildInfo ( key ) ) ;
737
750
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 } ;
739
761
} ) ;
740
762
741
763
let referencedMap : ProgramBuildInfoReferencedMap | undefined ;
@@ -787,7 +809,7 @@ namespace ts {
787
809
return {
788
810
fileNames,
789
811
fileInfos,
790
- options : convertToReusableCompilerOptions ( state . compilerOptions , relativeToBuildInfoEnsuringAbsolutePath ) ,
812
+ options : convertToProgramBuildInfoCompilerOptions ( state . compilerOptions , relativeToBuildInfoEnsuringAbsolutePath ) ,
791
813
fileIdsList,
792
814
referencedMap,
793
815
exportedModulesMap,
@@ -824,22 +846,20 @@ namespace ts {
824
846
}
825
847
}
826
848
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 ;
829
851
const { optionsNameMap } = getOptionsNameMap ( ) ;
830
852
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 ,
835
858
options [ name ] as CompilerOptionsValue ,
836
859
relativeToBuildInfo
837
860
) ;
838
861
}
839
862
}
840
- if ( result . configFilePath ) {
841
- result . configFilePath = relativeToBuildInfo ( result . configFilePath ) ;
842
- }
843
863
return result ;
844
864
}
845
865
@@ -1213,17 +1233,25 @@ namespace ts {
1213
1233
}
1214
1234
}
1215
1235
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
+
1216
1244
export function createBuildProgramUsingProgramBuildInfo ( program : ProgramBuildInfo , buildInfoPath : string , host : ReadBuildProgramHost ) : EmitAndSemanticDiagnosticsBuilderProgram {
1217
1245
const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath , host . getCurrentDirectory ( ) ) ) ;
1218
1246
const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ( ) ) ;
1219
1247
1220
1248
const filePaths = program . fileNames . map ( toPath ) ;
1221
1249
const filePathsSetList = program . fileIdsList ?. map ( fileIds => new Set ( fileIds . map ( toFilePath ) ) ) ;
1222
1250
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 ) ) ) ;
1224
1252
const state : ReusableBuilderProgramState = {
1225
1253
fileInfos,
1226
- compilerOptions : convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) ,
1254
+ compilerOptions : program . options ? convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) : { } ,
1227
1255
referencedMap : toMapOfReferencedSet ( program . referencedMap ) ,
1228
1256
exportedModulesMap : toMapOfReferencedSet ( program . exportedModulesMap ) ,
1229
1257
semanticDiagnosticsPerFile : program . semanticDiagnosticsPerFile && arrayToMap ( program . semanticDiagnosticsPerFile , value => toFilePath ( isNumber ( value ) ? value : value [ 0 ] ) , value => isNumber ( value ) ? emptyArray : value [ 1 ] ) ,
0 commit comments