1
1
import {
2
- arrayFrom , CancellationToken , computeSignatureWithDiagnostics , CustomTransformers , Debug , EmitOutput , emptyArray ,
2
+ arrayFrom , CancellationToken , computeSignatureWithDiagnostics , createGetCanonicalFileName , CustomTransformers , Debug , EmitOutput , emptyArray ,
3
3
ExportedModulesFromDeclarationEmit , GetCanonicalFileName , getDirectoryPath , getSourceFileOfNode ,
4
+ HostForComputeHash ,
4
5
isDeclarationFileName , isExternalOrCommonJsModule , isGlobalScopeAugmentation , isJsonSourceFile ,
5
6
isModuleWithStringLiteralName , isStringLiteral , mapDefined , mapDefinedIterator , ModuleDeclaration ,
6
7
ModuleKind , outFile , OutputFile , Path , Program , ResolutionMode , some , SourceFile , StringLiteralLike , Symbol ,
@@ -158,11 +159,6 @@ export namespace BuilderState {
158
159
return false ;
159
160
}
160
161
161
- /**
162
- * Compute the hash to store the shape of the file
163
- */
164
- export type ComputeHash = ( ( data : string ) => string ) | undefined ;
165
-
166
162
function getReferencedFilesFromImportedModuleSymbol ( symbol : Symbol ) : Path [ ] {
167
163
return mapDefined ( symbol . declarations , declaration => getSourceFileOfNode ( declaration ) ?. resolvedPath ) ;
168
164
}
@@ -272,14 +268,15 @@ export namespace BuilderState {
272
268
/**
273
269
* Creates the state of file references and signature for the new program from oldState if it is safe
274
270
*/
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 {
276
272
const fileInfos = new Map < Path , FileInfo > ( ) ;
277
273
const options = newProgram . getCompilerOptions ( ) ;
278
274
const isOutFile = outFile ( options ) ;
279
275
const referencedMap = options . module !== ModuleKind . None && ! isOutFile ?
280
276
createManyToManyPathMap ( ) : undefined ;
281
277
const exportedModulesMap = referencedMap ? createManyToManyPathMap ( ) : undefined ;
282
278
const useOldState = canReuseOldState ( referencedMap , oldState ) ;
279
+ const getCanonicalFileName = createGetCanonicalFileName ( newProgram . useCaseSensitiveFileNames ( ) ) ;
283
280
284
281
// Ensure source files have parent pointers set
285
282
newProgram . getTypeChecker ( ) ;
@@ -340,16 +337,14 @@ export namespace BuilderState {
340
337
programOfThisState : Program ,
341
338
path : Path ,
342
339
cancellationToken : CancellationToken | undefined ,
343
- computeHash : ComputeHash ,
344
- getCanonicalFileName : GetCanonicalFileName ,
340
+ host : HostForComputeHash ,
345
341
) : readonly SourceFile [ ] {
346
342
const result = getFilesAffectedByWithOldState (
347
343
state ,
348
344
programOfThisState ,
349
345
path ,
350
346
cancellationToken ,
351
- computeHash ,
352
- getCanonicalFileName ,
347
+ host ,
353
348
) ;
354
349
state . oldSignatures ?. clear ( ) ;
355
350
state . oldExportedModulesMap ?. clear ( ) ;
@@ -361,19 +356,18 @@ export namespace BuilderState {
361
356
programOfThisState : Program ,
362
357
path : Path ,
363
358
cancellationToken : CancellationToken | undefined ,
364
- computeHash : ComputeHash ,
365
- getCanonicalFileName : GetCanonicalFileName ,
359
+ host : HostForComputeHash ,
366
360
) : readonly SourceFile [ ] {
367
361
const sourceFile = programOfThisState . getSourceFileByPath ( path ) ;
368
362
if ( ! sourceFile ) {
369
363
return emptyArray ;
370
364
}
371
365
372
- if ( ! updateShapeSignature ( state , programOfThisState , sourceFile , cancellationToken , computeHash , getCanonicalFileName ) ) {
366
+ if ( ! updateShapeSignature ( state , programOfThisState , sourceFile , cancellationToken , host ) ) {
373
367
return [ sourceFile ] ;
374
368
}
375
369
376
- return ( state . referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit ) ( state , programOfThisState , sourceFile , cancellationToken , computeHash , getCanonicalFileName ) ;
370
+ return ( state . referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit ) ( state , programOfThisState , sourceFile , cancellationToken , host ) ;
377
371
}
378
372
379
373
export function updateSignatureOfFile ( state : BuilderState , signature : string | undefined , path : Path ) {
@@ -389,9 +383,8 @@ export namespace BuilderState {
389
383
programOfThisState : Program ,
390
384
sourceFile : SourceFile ,
391
385
cancellationToken : CancellationToken | undefined ,
392
- computeHash : ComputeHash ,
393
- getCanonicalFileName : GetCanonicalFileName ,
394
- useFileVersionAsSignature = state . useFileVersionAsSignature
386
+ host : HostForComputeHash ,
387
+ useFileVersionAsSignature = state . useFileVersionAsSignature ,
395
388
) {
396
389
// If we have cached the result for this file, that means hence forth we should assume file shape is uptodate
397
390
if ( state . hasCalledUpdateShapeSignature ?. has ( sourceFile . resolvedPath ) ) return false ;
@@ -405,10 +398,10 @@ export namespace BuilderState {
405
398
( fileName , text , _writeByteOrderMark , _onError , sourceFiles , data ) => {
406
399
Debug . assert ( isDeclarationFileName ( fileName ) , `File extension for signature expected to be dts: Got:: ${ fileName } ` ) ;
407
400
latestSignature = computeSignatureWithDiagnostics (
401
+ programOfThisState ,
408
402
sourceFile ,
409
403
text ,
410
- computeHash ,
411
- getCanonicalFileName ,
404
+ host ,
412
405
data ,
413
406
) ;
414
407
if ( latestSignature !== prevSignature ) {
@@ -604,8 +597,7 @@ export namespace BuilderState {
604
597
programOfThisState : Program ,
605
598
sourceFileWithUpdatedShape : SourceFile ,
606
599
cancellationToken : CancellationToken | undefined ,
607
- computeHash : ComputeHash ,
608
- getCanonicalFileName : GetCanonicalFileName ,
600
+ host : HostForComputeHash ,
609
601
) {
610
602
if ( isFileAffectingGlobalScope ( sourceFileWithUpdatedShape ) ) {
611
603
return getAllFilesExcludingDefaultLibraryFile ( state , programOfThisState , sourceFileWithUpdatedShape ) ;
@@ -629,7 +621,7 @@ export namespace BuilderState {
629
621
if ( ! seenFileNamesMap . has ( currentPath ) ) {
630
622
const currentSourceFile = programOfThisState . getSourceFileByPath ( currentPath ) ! ;
631
623
seenFileNamesMap . set ( currentPath , currentSourceFile ) ;
632
- if ( currentSourceFile && updateShapeSignature ( state , programOfThisState , currentSourceFile , cancellationToken , computeHash , getCanonicalFileName ) ) {
624
+ if ( currentSourceFile && updateShapeSignature ( state , programOfThisState , currentSourceFile , cancellationToken , host ) ) {
633
625
queue . push ( ...getReferencedByPaths ( state , currentSourceFile . resolvedPath ) ) ;
634
626
}
635
627
}
0 commit comments