Skip to content

Commit 461450b

Browse files
authored
Merge pull request #21467 from Microsoft/isEmittedFileCheckRelease27
[release-2.7] Simplify isEmittedFile check instead of iterating through all source files
2 parents 3815a79 + c661b40 commit 461450b

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
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) {

src/server/server.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace ts.server {
3333
const os: {
3434
homedir?(): string;
3535
tmpdir(): string;
36+
platform(): string;
3637
} = require("os");
3738

3839
interface NodeSocket {
@@ -824,8 +825,9 @@ namespace ts.server {
824825
const logger = createLogger();
825826

826827
const sys = <ServerHost>ts.sys;
828+
const nodeVersion = getNodeMajorVersion();
827829
// use watchGuard process on Windows when node version is 4 or later
828-
const useWatchGuard = process.platform === "win32" && getNodeMajorVersion() >= 4;
830+
const useWatchGuard = process.platform === "win32" && nodeVersion >= 4;
829831
const originalWatchDirectory: ServerHost["watchDirectory"] = sys.watchDirectory.bind(sys);
830832
const noopWatcher: FileWatcher = { close: noop };
831833
// This is the function that catches the exceptions when watching directory, and yet lets project service continue to function
@@ -980,8 +982,9 @@ namespace ts.server {
980982
};
981983

982984
logger.info(`Starting TS Server`);
983-
logger.info(`Version: ${versionMajorMinor}`);
985+
logger.info(`Version: ${version}`);
984986
logger.info(`Arguments: ${process.argv.join(" ")}`);
987+
logger.info(`Platform: ${os.platform()} NodeVersion: ${nodeVersion} CaseSensitive: ${sys.useCaseSensitiveFileNames}`);
985988

986989
const ioSession = new IOSession(options);
987990
process.on("uncaughtException", err => {

0 commit comments

Comments
 (0)