mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Change getCurrentDirectory and getDefaultLibname from passing around
function to its final value
This commit is contained in:
parent
623b97f2ec
commit
537f55cede
@ -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"]
|
||||
|
||||
@ -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 += "/// <reference path=\"" + declFileName + "\" />" + newLine;
|
||||
|
||||
@ -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++) {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user