@@ -3,8 +3,8 @@ namespace ts {
33 export function getFileEmitOutput ( program : Program , sourceFile : SourceFile , emitOnlyDtsFiles : boolean ,
44 cancellationToken ?: CancellationToken , customTransformers ?: CustomTransformers , forceDtsEmit ?: boolean ) : EmitOutput {
55 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 } ;
88
99 function writeFile ( fileName : string , text : string , writeByteOrderMark : boolean ) {
1010 outputFiles . push ( { name : fileName , writeByteOrderMark, text } ) ;
@@ -321,24 +321,45 @@ namespace ts {
321321 /**
322322 * Gets the files affected by the path from the program
323323 */
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+ ) ;
326340 state . oldSignatures ?. clear ( ) ;
327341 state . oldExportedModulesMap ?. clear ( ) ;
328342 return result ;
329343 }
330344
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 [ ] {
332353 const sourceFile = programOfThisState . getSourceFileByPath ( path ) ;
333354 if ( ! sourceFile ) {
334355 return emptyArray ;
335356 }
336357
337- if ( ! updateShapeSignature ( state , programOfThisState , sourceFile , cancellationToken , computeHash ) ) {
358+ if ( ! updateShapeSignature ( state , programOfThisState , sourceFile , cancellationToken , computeHash , getCanonicalFileName ) ) {
338359 return [ sourceFile ] ;
339360 }
340361
341- return ( state . referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit ) ( state , programOfThisState , sourceFile , cancellationToken , computeHash ) ;
362+ return ( state . referencedMap ? getFilesAffectedByUpdatedShapeWhenModuleEmit : getFilesAffectedByUpdatedShapeWhenNonModuleEmit ) ( state , programOfThisState , sourceFile , cancellationToken , computeHash , getCanonicalFileName ) ;
342363 }
343364
344365 export function updateSignatureOfFile ( state : BuilderState , signature : string | undefined , path : Path ) {
@@ -349,30 +370,42 @@ namespace ts {
349370 /**
350371 * Returns if the shape of the signature has changed since last emit
351372 */
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+ ) {
353382 // If we have cached the result for this file, that means hence forth we should assume file shape is uptodate
354383 if ( state . hasCalledUpdateShapeSignature ?. has ( sourceFile . resolvedPath ) ) return false ;
355384
356385 const info = state . fileInfos . get ( sourceFile . resolvedPath ) ! ;
357386 const prevSignature = info . signature ;
358387 let latestSignature : string | undefined ;
359388 if ( ! sourceFile . isDeclarationFile && ! useFileVersionAsSignature ) {
360- const emitOutput = getFileEmitOutput (
361- programOfThisState ,
389+ programOfThisState . emit (
362390 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+ } ,
364404 cancellationToken ,
405+ /*emitOnlyDtsFiles*/ true ,
365406 /*customTransformers*/ undefined ,
366407 /*forceDtsEmit*/ true
367408 ) ;
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- }
376409 }
377410 // Default is to use file version as signature
378411 if ( latestSignature === undefined ) {
@@ -395,10 +428,6 @@ namespace ts {
395428 return latestSignature !== prevSignature ;
396429 }
397430
398- export function computeSignature ( text : string , computeHash : ComputeHash | undefined ) {
399- return ( computeHash || generateDjb2Hash ) ( text ) ;
400- }
401-
402431 /**
403432 * Coverts the declaration emit result into exported modules map
404433 */
@@ -556,7 +585,14 @@ namespace ts {
556585 /**
557586 * When program emits modular code, gets the files affected by the sourceFile whose shape has changed
558587 */
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+ ) {
560596 if ( isFileAffectingGlobalScope ( sourceFileWithUpdatedShape ) ) {
561597 return getAllFilesExcludingDefaultLibraryFile ( state , programOfThisState , sourceFileWithUpdatedShape ) ;
562598 }
@@ -579,7 +615,7 @@ namespace ts {
579615 if ( ! seenFileNamesMap . has ( currentPath ) ) {
580616 const currentSourceFile = programOfThisState . getSourceFileByPath ( currentPath ) ! ;
581617 seenFileNamesMap . set ( currentPath , currentSourceFile ) ;
582- if ( currentSourceFile && updateShapeSignature ( state , programOfThisState , currentSourceFile , cancellationToken , computeHash ) ) {
618+ if ( currentSourceFile && updateShapeSignature ( state , programOfThisState , currentSourceFile , cancellationToken , computeHash , getCanonicalFileName ) ) {
583619 queue . push ( ...getReferencedByPaths ( state , currentSourceFile . resolvedPath ) ) ;
584620 }
585621 }
0 commit comments