@@ -171,7 +171,7 @@ namespace ts {
171
171
const readFileCache = new Map < string , string | false > ( ) ;
172
172
const fileExistsCache = new Map < string , boolean > ( ) ;
173
173
const directoryExistsCache = new Map < string , boolean > ( ) ;
174
- const sourceFileCache = new Map < string , SourceFile > ( ) ;
174
+ const sourceFileCache = new Map < string , ESMap < SourceFile [ "impliedNodeFormat" ] , SourceFile > > ( ) ;
175
175
176
176
const readFileWithCache = ( fileName : string ) : string | undefined => {
177
177
const key = toPath ( fileName ) ;
@@ -196,14 +196,16 @@ namespace ts {
196
196
return setReadFileCache ( key , fileName ) ;
197
197
} ;
198
198
199
- const getSourceFileWithCache : CompilerHost [ "getSourceFile" ] | undefined = getSourceFile ? ( fileName , languageVersion , onError , shouldCreateNewSourceFile ) => {
199
+ const getSourceFileWithCache : CompilerHost [ "getSourceFile" ] | undefined = getSourceFile ? ( fileName , languageVersionOrOptions , onError , shouldCreateNewSourceFile ) => {
200
200
const key = toPath ( fileName ) ;
201
- const value = sourceFileCache . get ( key ) ;
201
+ const impliedNodeFormat : SourceFile [ "impliedNodeFormat" ] = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions . impliedNodeFormat : undefined ;
202
+ const forPath = sourceFileCache . get ( key ) ;
203
+ const value = forPath ?. get ( impliedNodeFormat ) ;
202
204
if ( value ) return value ;
203
205
204
- const sourceFile = getSourceFile ( fileName , languageVersion , onError , shouldCreateNewSourceFile ) ;
206
+ const sourceFile = getSourceFile ( fileName , languageVersionOrOptions , onError , shouldCreateNewSourceFile ) ;
205
207
if ( sourceFile && ( isDeclarationFileName ( fileName ) || fileExtensionIs ( fileName , Extension . Json ) ) ) {
206
- sourceFileCache . set ( key , sourceFile ) ;
208
+ sourceFileCache . set ( key , ( forPath || new Map ( ) ) . set ( impliedNodeFormat , sourceFile ) ) ;
207
209
}
208
210
return sourceFile ;
209
211
} : undefined ;
@@ -228,7 +230,8 @@ namespace ts {
228
230
sourceFileCache . delete ( key ) ;
229
231
}
230
232
else if ( getSourceFileWithCache ) {
231
- const sourceFile = sourceFileCache . get ( key ) ;
233
+ const sourceFileMap = sourceFileCache . get ( key ) ;
234
+ const sourceFile = sourceFileMap && firstDefinedIterator ( sourceFileMap . values ( ) , identity ) ;
232
235
if ( sourceFile && sourceFile . text !== data ) {
233
236
sourceFileCache . delete ( key ) ;
234
237
}
0 commit comments