@@ -83,19 +83,21 @@ describe('ng program', () => {
8383
8484 const originalGetSourceFile = host . getSourceFile ;
8585 const cache = new Map < string , ts . SourceFile > ( ) ;
86- host . getSourceFile = function ( fileName : string ) : ts . SourceFile {
87- const sf = originalGetSourceFile . call ( host , fileName ) as ts . SourceFile ;
88- if ( sf ) {
89- if ( cache . has ( sf . fileName ) ) {
90- const oldSf = cache . get ( sf . fileName ) ! ;
91- if ( oldSf . getFullText ( ) === sf . getFullText ( ) ) {
92- return oldSf ;
86+ host . getSourceFile = function (
87+ fileName : string , languageVersion : ts . ScriptTarget ) : ts . SourceFile |
88+ undefined {
89+ const sf = originalGetSourceFile . call ( host , fileName , languageVersion ) ;
90+ if ( sf ) {
91+ if ( cache . has ( sf . fileName ) ) {
92+ const oldSf = cache . get ( sf . fileName ) ! ;
93+ if ( oldSf . getFullText ( ) === sf . getFullText ( ) ) {
94+ return oldSf ;
95+ }
96+ }
97+ cache . set ( sf . fileName , sf ) ;
9398 }
94- }
95- cache . set ( sf . fileName , sf ) ;
96- }
97- return sf ;
98- } ;
99+ return sf ;
100+ } ;
99101 return host ;
100102 }
101103
@@ -196,12 +198,14 @@ describe('ng program', () => {
196198 const host = ng . createCompilerHost ( { options} ) ;
197199 const originalGetSourceFile = host . getSourceFile ;
198200 const fileCache = new Map < string , ts . SourceFile > ( ) ;
199- host . getSourceFile = ( fileName : string ) => {
201+ host . getSourceFile = ( fileName : string , languageVersion : ts . ScriptTarget ) => {
200202 if ( fileCache . has ( fileName ) ) {
201203 return fileCache . get ( fileName ) ;
202204 }
203- const sf = originalGetSourceFile . call ( host , fileName ) ;
204- fileCache . set ( fileName , sf ) ;
205+ const sf = originalGetSourceFile . call ( host , fileName , languageVersion ) ;
206+ if ( sf !== undefined ) {
207+ fileCache . set ( fileName , sf ) ;
208+ }
205209 return sf ;
206210 } ;
207211
@@ -469,8 +473,8 @@ describe('ng program', () => {
469473
470474 host . writeFile =
471475 ( fileName : string , data : string , writeByteOrderMark : boolean ,
472- onError : ( message : string ) => void | undefined ,
473- sourceFiles : ReadonlyArray < ts . SourceFile > ) => {
476+ onError : ( ( message : string ) => void ) | undefined ,
477+ sourceFiles ? : ReadonlyArray < ts . SourceFile > ) => {
474478 written . set ( fileName , { original : sourceFiles , data} ) ;
475479 } ;
476480 const program = ng . createProgram (
@@ -1095,15 +1099,15 @@ describe('ng program', () => {
10951099 } ) ;
10961100 const host = ng . createCompilerHost ( { options} ) ;
10971101 const originalGetSourceFile = host . getSourceFile ;
1098- host . getSourceFile =
1099- ( fileName : string , languageVersion : ts . ScriptTarget ,
1100- onError ?: ( ( message : string ) => void ) | undefined ) : ts . SourceFile => {
1101- // We should never try to load .ngfactory.ts files
1102- if ( fileName . match ( / \. n g f a c t o r y \. t s $ / ) ) {
1103- throw new Error ( `Non existent ngfactory file: ` + fileName ) ;
1104- }
1105- return originalGetSourceFile . call ( host , fileName , languageVersion , onError ) ;
1106- } ;
1102+ host . getSourceFile = ( fileName : string , languageVersion : ts . ScriptTarget ,
1103+ onError ?: ( ( message : string ) => void ) | undefined ) : ts . SourceFile |
1104+ undefined => {
1105+ // We should never try to load .ngfactory.ts files
1106+ if ( fileName . match ( / \. n g f a c t o r y \. t s $ / ) ) {
1107+ throw new Error ( `Non existent ngfactory file: ` + fileName ) ;
1108+ }
1109+ return originalGetSourceFile . call ( host , fileName , languageVersion , onError ) ;
1110+ } ;
11071111 const program = ng . createProgram ( { rootNames : allRootNames , options, host} ) ;
11081112 const structuralErrors = program . getNgStructuralDiagnostics ( ) ;
11091113 expect ( structuralErrors . length ) . toBe ( 1 ) ;
0 commit comments