Always compute a common source directory for a program

This commit is contained in:
Wesley Wigham
2015-11-13 14:41:09 -08:00
parent 732fff225b
commit 7e69f014f3
2 changed files with 9 additions and 12 deletions

View File

@@ -329,7 +329,6 @@ namespace ts {
let fileProcessingDiagnostics = createDiagnosticCollection();
const programDiagnostics = createDiagnosticCollection();
let commonSourceDirectory: string;
let diagnosticsProducingTypeChecker: TypeChecker;
let noDiagnosticsTypeChecker: TypeChecker;
let classifiableNames: Map<string>;
@@ -374,6 +373,8 @@ namespace ts {
}
}
// _Always_ compute a common source directory
let commonSourceDirectory = computeCommonSourceDirectory(files);
verifyCompilerOptions();
// unconditionally set oldProgram to undefined to prevent it from being captured in closure
@@ -1056,17 +1057,13 @@ namespace ts {
// If a rootDir is specified and is valid use it as the commonSourceDirectory
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory);
}
else {
// Compute the commonSourceDirectory from the input files
commonSourceDirectory = computeCommonSourceDirectory(files);
}
}
if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) {
// Make sure directory path ends with directory separator so this string can directly
// used to replace with "" to get the relative path of the source file and the relative path doesn't
// start with / making it rooted path
commonSourceDirectory += directorySeparator;
}
if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) {
// Make sure directory path ends with directory separator so this string can directly
// used to replace with "" to get the relative path of the source file and the relative path doesn't
// start with / making it rooted path
commonSourceDirectory += directorySeparator;
}
if (options.noEmit) {

View File

@@ -1867,7 +1867,7 @@ namespace ts {
* Resolves a local path to a path which is absolute to the base of the emit
*/
export function getExternalModuleNameFromPath(host: EmitHost, fileName: string): string {
const dir = host.getCommonSourceDirectory();
const dir = toPath(host.getCommonSourceDirectory(), host.getCurrentDirectory(), f => host.getCanonicalFileName(f));
const relativePath = getRelativePathToDirectoryOrUrl(dir, fileName, dir, f => host.getCanonicalFileName(f), /*isAbsolutePathAnUrl*/ false);
return removeFileExtension(relativePath);
}