Skip to content

Commit b0c6843

Browse files
committed
Simplify isEmittedFile check instead of iterating through all source files.
Fixes #21459
1 parent 3815a79 commit b0c6843

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/compiler/program.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,9 +2351,30 @@ namespace ts {
23512351
return false;
23522352
}
23532353

2354-
return forEachEmittedFile(getEmitHost(), ({ jsFilePath, declarationFilePath }) =>
2355-
isSameFile(jsFilePath, file) ||
2356-
(declarationFilePath && isSameFile(declarationFilePath, file)));
2354+
// If this is source file, its not emitted file
2355+
const filePath = toPath(file);
2356+
if (getSourceFileByPath(filePath)) {
2357+
return false;
2358+
}
2359+
2360+
// If options have --outFile or --out just check that
2361+
const out = options.outFile || options.out;
2362+
if (out) {
2363+
return isSameFile(filePath, out) || isSameFile(filePath, removeFileExtension(out) + Extension.Dts);
2364+
}
2365+
2366+
// If --outDir, check if file is in that directory
2367+
if (options.outDir) {
2368+
return containsPath(options.outDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames());
2369+
}
2370+
2371+
if (fileExtensionIsOneOf(filePath, supportedJavascriptExtensions) || fileExtensionIs(filePath, Extension.Dts)) {
2372+
// Otherwise just check if sourceFile with the name exists
2373+
const filePathWithoutExtension = removeFileExtension(filePath);
2374+
return !!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Ts) as Path) ||
2375+
!!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Tsx) as Path);
2376+
}
2377+
return false;
23572378
}
23582379

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

0 commit comments

Comments
 (0)