Skip to content

[release-2.7] Simplify isEmittedFile check instead of iterating through all source files #21467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace ts.server {
const os: {
homedir?(): string;
tmpdir(): string;
platform(): string;
} = require("os");

interface NodeSocket {
Expand Down Expand Up @@ -824,8 +825,9 @@ namespace ts.server {
const logger = createLogger();

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

logger.info(`Starting TS Server`);
logger.info(`Version: ${versionMajorMinor}`);
logger.info(`Version: ${version}`);
logger.info(`Arguments: ${process.argv.join(" ")}`);
logger.info(`Platform: ${os.platform()} NodeVersion: ${nodeVersion} CaseSensitive: ${sys.useCaseSensitiveFileNames}`);

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