diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 432ae6ab8cd..4f50f311348 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -383,12 +383,11 @@ module ts { return [path.substr(0, rootLength)].concat(normalizedParts); } - export function getNormalizedPathComponents(path: string, getCurrentDirectory: () => string) { + export function getNormalizedPathComponents(path: string, currentDirectory: string) { var path = normalizeSlashes(path); var rootLength = getRootLength(path); if (rootLength == 0) { // If the path is not rooted it is relative to current directory - var currentDirectory = getCurrentDirectory(); path = combinePaths(normalizeSlashes(currentDirectory), path); rootLength = getRootLength(path); } @@ -444,18 +443,18 @@ module ts { } } - function getNormalizedPathOrUrlComponents(pathOrUrl: string, getCurrentDirectory: () => string) { + function getNormalizedPathOrUrlComponents(pathOrUrl: string, currentDirectory: string) { if (isUrl(pathOrUrl)) { return getNormalizedPathComponentsOfUrl(pathOrUrl); } else { - return getNormalizedPathComponents(pathOrUrl, getCurrentDirectory); + return getNormalizedPathComponents(pathOrUrl, currentDirectory); } } - export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, getCurrentDirectory: () => string, isAbsolutePathAnUrl: boolean) { - var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, getCurrentDirectory); - var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, getCurrentDirectory); + export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, isAbsolutePathAnUrl: boolean) { + var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory); + var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory); if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") { // If the directory path given was of type test/cases/ then we really need components of directory to be only till its name // that is ["test", "cases", ""] needs to be actually ["test", "cases"] diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fe96beab830..da67c2d2f13 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -42,7 +42,7 @@ module ts { var newLine = program.getCompilerHost().getNewLine(); function getSourceFilePathInNewDir(newDirPath: string, sourceFile: SourceFile) { - var sourceFilePath = getNormalizedPathFromPathComponents(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory)); + var sourceFilePath = getNormalizedPathFromPathComponents(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory())); sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), ""); return combinePaths(newDirPath, sourceFilePath); } @@ -523,7 +523,7 @@ module ts { sourceMapData.sourceMapSources.push(getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, - compilerHost.getCurrentDirectory, + compilerHost.getCurrentDirectory(), /*isAbsolutePathAnUrl*/ true)); sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; @@ -640,7 +640,7 @@ module ts { sourceMapData.jsSourceMappingURL = getRelativePathToDirectoryOrUrl( getDirectoryPath(normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap - compilerHost.getCurrentDirectory, + compilerHost.getCurrentDirectory(), /*isAbsolutePathAnUrl*/ true); } else { @@ -3089,7 +3089,7 @@ module ts { declFileName = getRelativePathToDirectoryOrUrl( getDirectoryPath(normalizeSlashes(jsFilePath)), declFileName, - compilerHost.getCurrentDirectory, + compilerHost.getCurrentDirectory(), /*isAbsolutePathAnUrl*/ false); referencePathsOutput += "/// " + newLine; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9e254936a6f..ffc30e8e690 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3817,7 +3817,7 @@ module ts { // Each file contributes into common source file path if (!(sourceFile.flags & NodeFlags.DeclarationFile) && !fileExtensionIs(sourceFile.filename, ".js")) { - var sourcePathComponents = getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory); + var sourcePathComponents = getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory()); sourcePathComponents.pop(); // FileName is not part of directory if (commonPathComponents) { for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) { diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 7a5fa51e147..b0f3e939d30 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -226,7 +226,7 @@ class ProjectRunner extends RunnerBase { ? filename : ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(filename); - var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName, getCurrentDirectory, false); + var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName, getCurrentDirectory(), false); if (ts.isRootedDiskPath(diskRelativeName) || diskRelativeName.substr(0, 3) === "../") { // If the generated output file recides in the parent folder or is rooted path, // we need to instead create files that can live in the project reference folder diff --git a/src/services/services.ts b/src/services/services.ts index 8569c859d58..1c6eebb9419 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1420,17 +1420,14 @@ module ts { getNewLine: () => "\r\n", // Need something that doesn't depend on sys.ts here getDefaultLibFilename: (): string => { - return host.getDefaultLibFilename(); + return ""; }, writeFile: (filename, data, writeByteOrderMark) => { - if (writer) { - writer(filename, data, writeByteOrderMark); - return; - } - throw Error("Error occurs: Invalid invocation to writeFile"); + writer(filename, data, writeByteOrderMark); }, getCurrentDirectory: (): string => { - return host.getCurrentDirectory(); + // Return empty string as in compilerHost using with Visual Studio should not need to getCurrentDirectory since CompilerHost should have absolute path already + return ""; } }; }