@@ -400,12 +400,7 @@ export class AngularCompilerPlugin {
400400
401401 // Use an identity function as all our paths are absolute already.
402402 this . _moduleResolutionCache = ts . createModuleResolutionCache ( this . _basePath , x => x ) ;
403-
404- const tsProgram = this . _getTsProgram ( ) ;
405- const oldFiles = new Set ( tsProgram ?
406- tsProgram . getSourceFiles ( ) . map ( sf => sf . fileName )
407- : [ ] ,
408- ) ;
403+ const oldTsProgram = this . _getTsProgram ( ) ;
409404
410405 if ( this . _JitMode ) {
411406 // Create the TypeScript program.
@@ -414,14 +409,9 @@ export class AngularCompilerPlugin {
414409 this . _rootNames ,
415410 this . _compilerOptions ,
416411 this . _compilerHost ,
417- tsProgram ,
412+ oldTsProgram ,
418413 ) ;
419414 timeEnd ( 'AngularCompilerPlugin._createOrUpdateProgram.ts.createProgram' ) ;
420-
421- const newFiles = this . _program . getSourceFiles ( ) . filter ( sf => ! oldFiles . has ( sf . fileName ) ) ;
422- for ( const newFile of newFiles ) {
423- this . _compilerHost . invalidate ( newFile . fileName ) ;
424- }
425415 } else {
426416 time ( 'AngularCompilerPlugin._createOrUpdateProgram.ng.createProgram' ) ;
427417 // Create the Angular program.
@@ -436,9 +426,14 @@ export class AngularCompilerPlugin {
436426 time ( 'AngularCompilerPlugin._createOrUpdateProgram.ng.loadNgStructureAsync' ) ;
437427 await this . _program . loadNgStructureAsync ( ) ;
438428 timeEnd ( 'AngularCompilerPlugin._createOrUpdateProgram.ng.loadNgStructureAsync' ) ;
429+ }
439430
440- const newFiles = this . _program . getTsProgram ( )
441- . getSourceFiles ( ) . filter ( sf => ! oldFiles . has ( sf . fileName ) ) ;
431+ const newTsProgram = this . _getTsProgram ( ) ;
432+ if ( oldTsProgram && newTsProgram ) {
433+ // The invalidation should only happen if we have an old program
434+ // as otherwise we will invalidate all the sourcefiles.
435+ const oldFiles = new Set ( oldTsProgram . getSourceFiles ( ) . map ( sf => sf . fileName ) ) ;
436+ const newFiles = newTsProgram . getSourceFiles ( ) . filter ( sf => ! oldFiles . has ( sf . fileName ) ) ;
442437 for ( const newFile of newFiles ) {
443438 this . _compilerHost . invalidate ( newFile . fileName ) ;
444439 }
@@ -1056,7 +1051,8 @@ export class AngularCompilerPlugin {
10561051 // We also need to all changed files as dependencies of this file, so that all of them
10571052 // will be watched and trigger a rebuild next time.
10581053 outputText = '' ;
1059- errorDependencies = this . _getChangedCompilationFiles ( )
1054+ const program = this . _getTsProgram ( ) ;
1055+ errorDependencies = ( program ? program . getSourceFiles ( ) . map ( x => x . fileName ) : [ ] )
10601056 // These paths are used by the loader so we must denormalize them.
10611057 . map ( ( p ) => this . _compilerHost . denormalizePath ( p ) ) ;
10621058 }
0 commit comments