@@ -3,8 +3,8 @@ namespace ts {
3
3
export function getFileEmitOutput ( program : Program , sourceFile : SourceFile , emitOnlyDtsFiles : boolean ,
4
4
cancellationToken ?: CancellationToken , customTransformers ?: CustomTransformers , forceDtsEmit ?: boolean ) : EmitOutput {
5
5
const outputFiles : OutputFile [ ] = [ ] ;
6
- const { emitSkipped, diagnostics, exportedModulesFromDeclarationEmit } = program . emit ( sourceFile , writeFile , cancellationToken , emitOnlyDtsFiles , customTransformers , forceDtsEmit ) ;
7
- return { outputFiles, emitSkipped, diagnostics, exportedModulesFromDeclarationEmit } ;
6
+ const { emitSkipped, diagnostics } = program . emit ( sourceFile , writeFile , cancellationToken , emitOnlyDtsFiles , customTransformers , forceDtsEmit ) ;
7
+ return { outputFiles, emitSkipped, diagnostics } ;
8
8
9
9
function writeFile ( fileName : string , text : string , writeByteOrderMark : boolean ) {
10
10
outputFiles . push ( { name : fileName , writeByteOrderMark, text } ) ;
@@ -321,24 +321,45 @@ namespace ts {
321
321
/**
322
322
* Gets the files affected by the path from the program
323
323
*/
324
- export function getFilesAffectedBy ( state : BuilderState , programOfThisState : Program , path : Path , cancellationToken : CancellationToken | undefined , computeHash : ComputeHash ) : readonly SourceFile [ ] {
325
- const result = getFilesAffectedByWithOldState ( state , programOfThisState , path , cancellationToken , computeHash ) ;
324
+ export function getFilesAffectedBy (
325
+ state : BuilderState ,
326
+ programOfThisState : Program ,
327
+ path : Path ,
328
+ cancellationToken : CancellationToken | undefined ,
329
+ computeHash : ComputeHash ,
330
+ getCanonicalFileName : GetCanonicalFileName ,
331
+ ) : readonly SourceFile [ ] {
332
+ const result = getFilesAffectedByWithOldState (
333
+ state ,
334
+ programOfThisState ,
335
+ path ,
336
+ cancellationToken ,
337
+ computeHash ,
338
+ getCanonicalFileName ,
339
+ ) ;
326
340
state . oldSignatures ?. clear ( ) ;
327
341
state . oldExportedModulesMap ?. clear ( ) ;
328
342
return result ;
329
343
}
330
344
331
- export function getFilesAffectedByWithOldState ( state : BuilderState , programOfThisState : Program , path : Path , cancellationToken : CancellationToken | undefined , computeHash : ComputeHash ) : readonly SourceFile [ ] {
345
+ export function getFilesAffectedByWithOldState (
346
+ state : BuilderState ,
347
+ programOfThisState : Program ,
348
+ path : Path ,
349
+ cancellationToken : CancellationToken | undefined ,
350
+ computeHash : ComputeHash ,
351
+ getCanonicalFileName : GetCanonicalFileName ,
352
+ ) : readonly SourceFile [ ] {
332
353
const sourceFile = programOfThisState . getSourceFileByPath ( path ) ;
333
354
if ( ! sourceFile ) {
334
355
return emptyArray ;
335
356
}
336
357
337
- if ( ! updateShapeSignature ( state , programOfThisState , sourceFile , cancellationToken , computeHash ) ) {
358
+ if ( ! updateShapeSignature ( state , programOfThisState , sourceFile , cancellationToken , computeHash , getCanonicalFileName ) ) {
338
359
return [ sourceFile ] ;
339
360
}
340
361
341
- return ( state . referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit ) ( state , programOfThisState , sourceFile , cancellationToken , computeHash ) ;
362
+ return ( state . referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit ) ( state , programOfThisState , sourceFile , cancellationToken , computeHash , getCanonicalFileName ) ;
342
363
}
343
364
344
365
export function updateSignatureOfFile ( state : BuilderState , signature : string | undefined , path : Path ) {
@@ -349,30 +370,42 @@ namespace ts {
349
370
/**
350
371
* Returns if the shape of the signature has changed since last emit
351
372
*/
352
- export function updateShapeSignature ( state : BuilderState , programOfThisState : Program , sourceFile : SourceFile , cancellationToken : CancellationToken | undefined , computeHash : ComputeHash , useFileVersionAsSignature = state . useFileVersionAsSignature ) {
373
+ export function updateShapeSignature (
374
+ state : BuilderState ,
375
+ programOfThisState : Program ,
376
+ sourceFile : SourceFile ,
377
+ cancellationToken : CancellationToken | undefined ,
378
+ computeHash : ComputeHash ,
379
+ getCanonicalFileName : GetCanonicalFileName ,
380
+ useFileVersionAsSignature = state . useFileVersionAsSignature
381
+ ) {
353
382
// If we have cached the result for this file, that means hence forth we should assume file shape is uptodate
354
383
if ( state . hasCalledUpdateShapeSignature ?. has ( sourceFile . resolvedPath ) ) return false ;
355
384
356
385
const info = state . fileInfos . get ( sourceFile . resolvedPath ) ! ;
357
386
const prevSignature = info . signature ;
358
387
let latestSignature : string | undefined ;
359
388
if ( ! sourceFile . isDeclarationFile && ! useFileVersionAsSignature ) {
360
- const emitOutput = getFileEmitOutput (
361
- programOfThisState ,
389
+ programOfThisState . emit (
362
390
sourceFile ,
363
- /*emitOnlyDtsFiles*/ true ,
391
+ ( fileName , text , _writeByteOrderMark , _onError , sourceFiles , data ) => {
392
+ Debug . assert ( isDeclarationFileName ( fileName ) , `File extension for signature expected to be dts: Got:: ${ fileName } ` ) ;
393
+ latestSignature = computeSignatureWithDiagnostics (
394
+ sourceFile ,
395
+ text ,
396
+ computeHash ,
397
+ getCanonicalFileName ,
398
+ data ,
399
+ ) ;
400
+ if ( latestSignature !== prevSignature ) {
401
+ updateExportedModules ( state , sourceFile , sourceFiles ! [ 0 ] . exportedModulesFromDeclarationEmit ) ;
402
+ }
403
+ } ,
364
404
cancellationToken ,
405
+ /*emitOnlyDtsFiles*/ true ,
365
406
/*customTransformers*/ undefined ,
366
407
/*forceDtsEmit*/ true
367
408
) ;
368
- const firstDts = firstOrUndefined ( emitOutput . outputFiles ) ;
369
- if ( firstDts ) {
370
- Debug . assert ( isDeclarationFileName ( firstDts . name ) , "File extension for signature expected to be dts" , ( ) => `Found: ${ getAnyExtensionFromPath ( firstDts . name ) } for ${ firstDts . name } :: All output files: ${ JSON . stringify ( emitOutput . outputFiles . map ( f => f . name ) ) } ` ) ;
371
- latestSignature = computeSignature ( firstDts . text , computeHash ) ;
372
- if ( latestSignature !== prevSignature ) {
373
- updateExportedModules ( state , sourceFile , emitOutput . exportedModulesFromDeclarationEmit ) ;
374
- }
375
- }
376
409
}
377
410
// Default is to use file version as signature
378
411
if ( latestSignature === undefined ) {
@@ -395,10 +428,6 @@ namespace ts {
395
428
return latestSignature !== prevSignature ;
396
429
}
397
430
398
- export function computeSignature ( text : string , computeHash : ComputeHash | undefined ) {
399
- return ( computeHash || generateDjb2Hash ) ( text ) ;
400
- }
401
-
402
431
/**
403
432
* Coverts the declaration emit result into exported modules map
404
433
*/
@@ -556,7 +585,14 @@ namespace ts {
556
585
/**
557
586
* When program emits modular code, gets the files affected by the sourceFile whose shape has changed
558
587
*/
559
- function getFilesAffectedByUpdatedShapeWhenModuleEmit ( state : BuilderState , programOfThisState : Program , sourceFileWithUpdatedShape : SourceFile , cancellationToken : CancellationToken | undefined , computeHash : ComputeHash ) {
588
+ function getFilesAffectedByUpdatedShapeWhenModuleEmit (
589
+ state : BuilderState ,
590
+ programOfThisState : Program ,
591
+ sourceFileWithUpdatedShape : SourceFile ,
592
+ cancellationToken : CancellationToken | undefined ,
593
+ computeHash : ComputeHash ,
594
+ getCanonicalFileName : GetCanonicalFileName ,
595
+ ) {
560
596
if ( isFileAffectingGlobalScope ( sourceFileWithUpdatedShape ) ) {
561
597
return getAllFilesExcludingDefaultLibraryFile ( state , programOfThisState , sourceFileWithUpdatedShape ) ;
562
598
}
@@ -579,7 +615,7 @@ namespace ts {
579
615
if ( ! seenFileNamesMap . has ( currentPath ) ) {
580
616
const currentSourceFile = programOfThisState . getSourceFileByPath ( currentPath ) ! ;
581
617
seenFileNamesMap . set ( currentPath , currentSourceFile ) ;
582
- if ( currentSourceFile && updateShapeSignature ( state , programOfThisState , currentSourceFile , cancellationToken , computeHash ) ) {
618
+ if ( currentSourceFile && updateShapeSignature ( state , programOfThisState , currentSourceFile , cancellationToken , computeHash , getCanonicalFileName ) ) {
583
619
queue . push ( ...getReferencedByPaths ( state , currentSourceFile . resolvedPath ) ) ;
584
620
}
585
621
}
0 commit comments