Skip to content

Commit 76bf470

Browse files
committed
Simplify isEmittedFile check instead of iterating through all source files.
Fixes microsoft#21459
1 parent 02e7984 commit 76bf470

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/compiler/program.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,9 +2363,30 @@ namespace ts {
23632363
return false;
23642364
}
23652365

2366-
return forEachEmittedFile(getEmitHost(), ({ jsFilePath, declarationFilePath }) =>
2367-
isSameFile(jsFilePath, file) ||
2368-
(declarationFilePath && isSameFile(declarationFilePath, file)));
2366+
// If this is source file, its not emitted file
2367+
const filePath = toPath(file);
2368+
if (getSourceFileByPath(filePath)) {
2369+
return false;
2370+
}
2371+
2372+
// If options have --outFile or --out just check that
2373+
const out = options.outFile || options.out;
2374+
if (out) {
2375+
return isSameFile(filePath, out) || isSameFile(filePath, removeFileExtension(out) + Extension.Dts);
2376+
}
2377+
2378+
// If --outDir, check if file is in that directory
2379+
if (options.outDir) {
2380+
return containsPath(options.outDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames());
2381+
}
2382+
2383+
if (fileExtensionIsOneOf(filePath, supportedJavascriptExtensions) || fileExtensionIs(filePath, Extension.Dts)) {
2384+
// Otherwise just check if sourceFile with the name exists
2385+
const filePathWithoutExtension = removeFileExtension(filePath);
2386+
return !!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Ts) as Path) ||
2387+
!!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Tsx) as Path);
2388+
}
2389+
return false;
23692390
}
23702391

23712392
function isSameFile(file1: string, file2: string) {

0 commit comments

Comments
 (0)