11import {
2- arrayFrom , CancellationToken , computeSignatureWithDiagnostics , CustomTransformers , Debug , EmitOutput , emptyArray ,
2+ arrayFrom , CancellationToken , computeSignatureWithDiagnostics , createGetCanonicalFileName , CustomTransformers , Debug , EmitOutput , emptyArray ,
33 ExportedModulesFromDeclarationEmit , GetCanonicalFileName , getDirectoryPath , getSourceFileOfNode ,
4+ HostForComputeHash ,
45 isDeclarationFileName , isExternalOrCommonJsModule , isGlobalScopeAugmentation , isJsonSourceFile ,
56 isModuleWithStringLiteralName , isStringLiteral , mapDefined , mapDefinedIterator , ModuleDeclaration ,
67 ModuleKind , outFile , OutputFile , Path , Program , ResolutionMode , some , SourceFile , StringLiteralLike , Symbol ,
@@ -158,11 +159,6 @@ export namespace BuilderState {
158159 return false ;
159160 }
160161
161- /**
162- * Compute the hash to store the shape of the file
163- */
164- export type ComputeHash = ( ( data : string ) => string ) | undefined ;
165-
166162 function getReferencedFilesFromImportedModuleSymbol ( symbol : Symbol ) : Path [ ] {
167163 return mapDefined ( symbol . declarations , declaration => getSourceFileOfNode ( declaration ) ?. resolvedPath ) ;
168164 }
@@ -272,14 +268,15 @@ export namespace BuilderState {
272268 /**
273269 * Creates the state of file references and signature for the new program from oldState if it is safe
274270 */
275- export function create ( newProgram : Program , getCanonicalFileName : GetCanonicalFileName , oldState ?: Readonly < BuilderState > , disableUseFileVersionAsSignature ?: boolean ) : BuilderState {
271+ export function create ( newProgram : Program , oldState ?: Readonly < BuilderState > , disableUseFileVersionAsSignature ?: boolean ) : BuilderState {
276272 const fileInfos = new Map < Path , FileInfo > ( ) ;
277273 const options = newProgram . getCompilerOptions ( ) ;
278274 const isOutFile = outFile ( options ) ;
279275 const referencedMap = options . module !== ModuleKind . None && ! isOutFile ?
280276 createManyToManyPathMap ( ) : undefined ;
281277 const exportedModulesMap = referencedMap ? createManyToManyPathMap ( ) : undefined ;
282278 const useOldState = canReuseOldState ( referencedMap , oldState ) ;
279+ const getCanonicalFileName = createGetCanonicalFileName ( newProgram . useCaseSensitiveFileNames ( ) ) ;
283280
284281 // Ensure source files have parent pointers set
285282 newProgram . getTypeChecker ( ) ;
@@ -340,16 +337,14 @@ export namespace BuilderState {
340337 programOfThisState : Program ,
341338 path : Path ,
342339 cancellationToken : CancellationToken | undefined ,
343- computeHash : ComputeHash ,
344- getCanonicalFileName : GetCanonicalFileName ,
340+ host : HostForComputeHash ,
345341 ) : readonly SourceFile [ ] {
346342 const result = getFilesAffectedByWithOldState (
347343 state ,
348344 programOfThisState ,
349345 path ,
350346 cancellationToken ,
351- computeHash ,
352- getCanonicalFileName ,
347+ host ,
353348 ) ;
354349 state . oldSignatures ?. clear ( ) ;
355350 state . oldExportedModulesMap ?. clear ( ) ;
@@ -361,19 +356,18 @@ export namespace BuilderState {
361356 programOfThisState : Program ,
362357 path : Path ,
363358 cancellationToken : CancellationToken | undefined ,
364- computeHash : ComputeHash ,
365- getCanonicalFileName : GetCanonicalFileName ,
359+ host : HostForComputeHash ,
366360 ) : readonly SourceFile [ ] {
367361 const sourceFile = programOfThisState . getSourceFileByPath ( path ) ;
368362 if ( ! sourceFile ) {
369363 return emptyArray ;
370364 }
371365
372- if ( ! updateShapeSignature ( state , programOfThisState , sourceFile , cancellationToken , computeHash , getCanonicalFileName ) ) {
366+ if ( ! updateShapeSignature ( state , programOfThisState , sourceFile , cancellationToken , host ) ) {
373367 return [ sourceFile ] ;
374368 }
375369
376- return ( state . referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit ) ( state , programOfThisState , sourceFile , cancellationToken , computeHash , getCanonicalFileName ) ;
370+ return ( state . referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit ) ( state , programOfThisState , sourceFile , cancellationToken , host ) ;
377371 }
378372
379373 export function updateSignatureOfFile ( state : BuilderState , signature : string | undefined , path : Path ) {
@@ -389,9 +383,8 @@ export namespace BuilderState {
389383 programOfThisState : Program ,
390384 sourceFile : SourceFile ,
391385 cancellationToken : CancellationToken | undefined ,
392- computeHash : ComputeHash ,
393- getCanonicalFileName : GetCanonicalFileName ,
394- useFileVersionAsSignature = state . useFileVersionAsSignature
386+ host : HostForComputeHash ,
387+ useFileVersionAsSignature = state . useFileVersionAsSignature ,
395388 ) {
396389 // If we have cached the result for this file, that means hence forth we should assume file shape is uptodate
397390 if ( state . hasCalledUpdateShapeSignature ?. has ( sourceFile . resolvedPath ) ) return false ;
@@ -405,10 +398,10 @@ export namespace BuilderState {
405398 ( fileName , text , _writeByteOrderMark , _onError , sourceFiles , data ) => {
406399 Debug . assert ( isDeclarationFileName ( fileName ) , `File extension for signature expected to be dts: Got:: ${ fileName } ` ) ;
407400 latestSignature = computeSignatureWithDiagnostics (
401+ programOfThisState ,
408402 sourceFile ,
409403 text ,
410- computeHash ,
411- getCanonicalFileName ,
404+ host ,
412405 data ,
413406 ) ;
414407 if ( latestSignature !== prevSignature ) {
@@ -604,8 +597,7 @@ export namespace BuilderState {
604597 programOfThisState : Program ,
605598 sourceFileWithUpdatedShape : SourceFile ,
606599 cancellationToken : CancellationToken | undefined ,
607- computeHash : ComputeHash ,
608- getCanonicalFileName : GetCanonicalFileName ,
600+ host : HostForComputeHash ,
609601 ) {
610602 if ( isFileAffectingGlobalScope ( sourceFileWithUpdatedShape ) ) {
611603 return getAllFilesExcludingDefaultLibraryFile ( state , programOfThisState , sourceFileWithUpdatedShape ) ;
@@ -629,7 +621,7 @@ export namespace BuilderState {
629621 if ( ! seenFileNamesMap . has ( currentPath ) ) {
630622 const currentSourceFile = programOfThisState . getSourceFileByPath ( currentPath ) ! ;
631623 seenFileNamesMap . set ( currentPath , currentSourceFile ) ;
632- if ( currentSourceFile && updateShapeSignature ( state , programOfThisState , currentSourceFile , cancellationToken , computeHash , getCanonicalFileName ) ) {
624+ if ( currentSourceFile && updateShapeSignature ( state , programOfThisState , currentSourceFile , cancellationToken , host ) ) {
633625 queue . push ( ...getReferencedByPaths ( state , currentSourceFile . resolvedPath ) ) ;
634626 }
635627 }
0 commit comments