@@ -168,10 +168,10 @@ namespace ts {
168
168
const originalDirectoryExists = host . directoryExists ;
169
169
const originalCreateDirectory = host . createDirectory ;
170
170
const originalWriteFile = host . writeFile ;
171
- const readFileCache = new Map < string , string | false > ( ) ;
172
- const fileExistsCache = new Map < string , boolean > ( ) ;
173
- const directoryExistsCache = new Map < string , boolean > ( ) ;
174
- const sourceFileCache = new Map < string , ESMap < SourceFile [ "impliedNodeFormat" ] , SourceFile > > ( ) ;
171
+ const readFileCache = new Map < Path , string | false > ( ) ;
172
+ const fileExistsCache = new Map < Path , boolean > ( ) ;
173
+ const directoryExistsCache = new Map < Path , boolean > ( ) ;
174
+ const sourceFileCache = new Map < SourceFile [ "impliedNodeFormat" ] , ESMap < Path , SourceFile > > ( ) ;
175
175
176
176
const readFileWithCache = ( fileName : string ) : string | undefined => {
177
177
const key = toPath ( fileName ) ;
@@ -199,13 +199,13 @@ namespace ts {
199
199
const getSourceFileWithCache : CompilerHost [ "getSourceFile" ] | undefined = getSourceFile ? ( fileName , languageVersionOrOptions , onError , shouldCreateNewSourceFile ) => {
200
200
const key = toPath ( fileName ) ;
201
201
const impliedNodeFormat : SourceFile [ "impliedNodeFormat" ] = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions . impliedNodeFormat : undefined ;
202
- const forPath = sourceFileCache . get ( key ) ;
203
- const value = forPath ?. get ( impliedNodeFormat ) ;
202
+ const forImpliedNodeFormat = sourceFileCache . get ( impliedNodeFormat ) ;
203
+ const value = forImpliedNodeFormat ?. get ( key ) ;
204
204
if ( value ) return value ;
205
205
206
206
const sourceFile = getSourceFile ( fileName , languageVersionOrOptions , onError , shouldCreateNewSourceFile ) ;
207
207
if ( sourceFile && ( isDeclarationFileName ( fileName ) || fileExtensionIs ( fileName , Extension . Json ) ) ) {
208
- sourceFileCache . set ( key , ( forPath || new Map ( ) ) . set ( impliedNodeFormat , sourceFile ) ) ;
208
+ sourceFileCache . set ( impliedNodeFormat , ( forImpliedNodeFormat || new Map ( ) ) . set ( key , sourceFile ) ) ;
209
209
}
210
210
return sourceFile ;
211
211
} : undefined ;
@@ -227,14 +227,15 @@ namespace ts {
227
227
const value = readFileCache . get ( key ) ;
228
228
if ( value !== undefined && value !== data ) {
229
229
readFileCache . delete ( key ) ;
230
- sourceFileCache . delete ( key ) ;
230
+ sourceFileCache . forEach ( map => map . delete ( key ) ) ;
231
231
}
232
232
else if ( getSourceFileWithCache ) {
233
- const sourceFileMap = sourceFileCache . get ( key ) ;
234
- const sourceFile = sourceFileMap && firstDefinedIterator ( sourceFileMap . values ( ) , identity ) ;
235
- if ( sourceFile && sourceFile . text !== data ) {
236
- sourceFileCache . delete ( key ) ;
237
- }
233
+ sourceFileCache . forEach ( map => {
234
+ const sourceFile = map . get ( key ) ;
235
+ if ( sourceFile && sourceFile . text !== data ) {
236
+ map . delete ( key ) ;
237
+ }
238
+ } ) ;
238
239
}
239
240
originalWriteFile . call ( host , fileName , data , ...rest ) ;
240
241
} ;
0 commit comments