Do not trigger the failed lookup location invalidation for creation of program emit files

Handles #20934
This commit is contained in:
Sheetal Nandi 2018-01-11 11:52:46 -08:00
parent c5ed8646e1
commit 69bb5ea8f0
8 changed files with 53 additions and 8 deletions

View File

@ -18,8 +18,8 @@ namespace ts {
* If an array, the full list of source files to emit.
* Else, calls `getSourceFilesToEmit` with the (optional) target source file to determine the list of source files to emit.
*/
export function forEachEmittedFile(
host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle, emitOnlyDtsFiles: boolean) => void,
export function forEachEmittedFile<T>(
host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle, emitOnlyDtsFiles: boolean) => T,
sourceFilesOrTargetSourceFile?: SourceFile[] | SourceFile,
emitOnlyDtsFiles?: boolean) {
@ -30,7 +30,10 @@ namespace ts {
const jsFilePath = options.outFile || options.out;
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
const declarationFilePath = options.declaration ? removeFileExtension(jsFilePath) + Extension.Dts : "";
action({ jsFilePath, sourceMapFilePath, declarationFilePath }, createBundle(sourceFiles), emitOnlyDtsFiles);
const result = action({ jsFilePath, sourceMapFilePath, declarationFilePath }, createBundle(sourceFiles), emitOnlyDtsFiles);
if (result) {
return result;
}
}
}
else {
@ -38,7 +41,10 @@ namespace ts {
const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options));
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
const declarationFilePath = !isSourceFileJavaScript(sourceFile) && (emitOnlyDtsFiles || options.declaration) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
action({ jsFilePath, sourceMapFilePath, declarationFilePath }, sourceFile, emitOnlyDtsFiles);
const result = action({ jsFilePath, sourceMapFilePath, declarationFilePath }, sourceFile, emitOnlyDtsFiles);
if (result) {
return result;
}
}
}
}

View File

@ -667,7 +667,8 @@ namespace ts {
dropDiagnosticsProducingTypeChecker,
getSourceFileFromReference,
sourceFileToPackageName,
redirectTargetsSet
redirectTargetsSet,
isEmittedFile
};
verifyCompilerOptions();
@ -2343,6 +2344,20 @@ namespace ts {
hasEmitBlockingDiagnostics.set(toPath(emitFileName), true);
programDiagnostics.add(diag);
}
function isEmittedFile(file: string) {
if (options.noEmit) {
return false;
}
return forEachEmittedFile(getEmitHost(), ({ jsFilePath, declarationFilePath }) =>
isSameFile(jsFilePath, file) ||
(declarationFilePath && isSameFile(declarationFilePath, file)));
}
function isSameFile(file1: string, file2: string) {
return comparePaths(file1, file2, currentDirectory, !host.useCaseSensitiveFileNames()) === Comparison.EqualTo;
}
}
/* @internal */

View File

@ -52,6 +52,7 @@ namespace ts {
getGlobalCache?(): string | undefined;
writeLog(s: string): void;
maxNumberOfFilesToIterateForInvalidation?: number;
getCurrentProgram(): Program;
}
interface DirectoryWatchesOfFailedLookup {
@ -472,6 +473,11 @@ namespace ts {
resolutionHost.getCachedDirectoryStructureHost().addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath);
}
// Ignore emits from the program
if (isEmittedFileOfProgram(resolutionHost.getCurrentProgram(), fileOrDirectory)) {
return;
}
// If the files are added to project root or node_modules directory, always run through the invalidation process
// Otherwise run through invalidation only if adding to the immediate directory
if (!allFilesHaveInvalidatedResolution &&

View File

@ -2659,6 +2659,8 @@ namespace ts {
/* @internal */ sourceFileToPackageName: Map<string>;
/** Set of all source files that some other source file redirects to. */
/* @internal */ redirectTargetsSet: Map<true>;
/** Is the file emitted file */
/* @internal */ isEmittedFile(file: string): boolean;
}
/* @internal */

View File

@ -305,6 +305,7 @@ namespace ts {
scheduleProgramUpdate();
},
maxNumberOfFilesToIterateForInvalidation: watchingHost.maxNumberOfFilesToIterateForInvalidation,
getCurrentProgram,
writeLog
};
// Cache for the module resolution
@ -322,7 +323,11 @@ namespace ts {
// Update the wild card directory watch
watchConfigFileWildCardDirectories();
return () => program;
return getCurrentProgram;
function getCurrentProgram() {
return program;
}
function synchronizeProgram() {
writeLog(`Synchronizing program`);

View File

@ -82,6 +82,14 @@ namespace ts {
}
}
export function isEmittedFileOfProgram(program: Program | undefined, file: string) {
if (!program) {
return false;
}
return program.isEmittedFile(file);
}
export function addFileWatcher(host: System, file: string, cb: FileWatcherCallback): FileWatcher {
return host.watchFile(file, cb);
}

View File

@ -1096,7 +1096,7 @@ namespace ts.tscWatch {
assert.isTrue(host.fileExists("build/src/file2.js"));
// This should be 0
host.checkTimeoutQueueLengthAndRun(1);
host.checkTimeoutQueueLengthAndRun(0);
});
});

View File

@ -830,7 +830,10 @@ namespace ts.server {
return !hasChanges;
}
/* @internal */
getCurrentProgram() {
return this.program;
}
protected removeExistingTypings(include: string[]): string[] {
const existing = ts.getAutomaticTypeDirectiveNames(this.getCompilerOptions(), this.directoryStructureHost);