From b0c6843f3ec0ac57d1348e6b81d902ced954d6cc Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 29 Jan 2018 15:41:21 -0800 Subject: [PATCH] Simplify isEmittedFile check instead of iterating through all source files. Fixes #21459 --- src/compiler/program.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index bd45857fc51..0c9f5765605 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2351,9 +2351,30 @@ namespace ts { return false; } - return forEachEmittedFile(getEmitHost(), ({ jsFilePath, declarationFilePath }) => - isSameFile(jsFilePath, file) || - (declarationFilePath && isSameFile(declarationFilePath, file))); + // If this is source file, its not emitted file + const filePath = toPath(file); + if (getSourceFileByPath(filePath)) { + return false; + } + + // If options have --outFile or --out just check that + const out = options.outFile || options.out; + if (out) { + return isSameFile(filePath, out) || isSameFile(filePath, removeFileExtension(out) + Extension.Dts); + } + + // If --outDir, check if file is in that directory + if (options.outDir) { + return containsPath(options.outDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames()); + } + + if (fileExtensionIsOneOf(filePath, supportedJavascriptExtensions) || fileExtensionIs(filePath, Extension.Dts)) { + // Otherwise just check if sourceFile with the name exists + const filePathWithoutExtension = removeFileExtension(filePath); + return !!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Ts) as Path) || + !!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Tsx) as Path); + } + return false; } function isSameFile(file1: string, file2: string) {