Skip to content

Commit 537f55c

Browse files
author
Yui T
committed
Change getCurrentDirectory and getDefaultLibname from passing around
function to its final value
1 parent 623b97f commit 537f55c

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

src/compiler/core.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,11 @@ module ts {
383383
return [path.substr(0, rootLength)].concat(normalizedParts);
384384
}
385385

386-
export function getNormalizedPathComponents(path: string, getCurrentDirectory: () => string) {
386+
export function getNormalizedPathComponents(path: string, currentDirectory: string) {
387387
var path = normalizeSlashes(path);
388388
var rootLength = getRootLength(path);
389389
if (rootLength == 0) {
390390
// If the path is not rooted it is relative to current directory
391-
var currentDirectory = getCurrentDirectory();
392391
path = combinePaths(normalizeSlashes(currentDirectory), path);
393392
rootLength = getRootLength(path);
394393
}
@@ -444,18 +443,18 @@ module ts {
444443
}
445444
}
446445

447-
function getNormalizedPathOrUrlComponents(pathOrUrl: string, getCurrentDirectory: () => string) {
446+
function getNormalizedPathOrUrlComponents(pathOrUrl: string, currentDirectory: string) {
448447
if (isUrl(pathOrUrl)) {
449448
return getNormalizedPathComponentsOfUrl(pathOrUrl);
450449
}
451450
else {
452-
return getNormalizedPathComponents(pathOrUrl, getCurrentDirectory);
451+
return getNormalizedPathComponents(pathOrUrl, currentDirectory);
453452
}
454453
}
455454

456-
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, getCurrentDirectory: () => string, isAbsolutePathAnUrl: boolean) {
457-
var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, getCurrentDirectory);
458-
var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, getCurrentDirectory);
455+
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, isAbsolutePathAnUrl: boolean) {
456+
var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
457+
var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
459458
if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") {
460459
// If the directory path given was of type test/cases/ then we really need components of directory to be only till its name
461460
// that is ["test", "cases", ""] needs to be actually ["test", "cases"]

src/compiler/emitter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module ts {
4242
var newLine = program.getCompilerHost().getNewLine();
4343

4444
function getSourceFilePathInNewDir(newDirPath: string, sourceFile: SourceFile) {
45-
var sourceFilePath = getNormalizedPathFromPathComponents(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory));
45+
var sourceFilePath = getNormalizedPathFromPathComponents(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory()));
4646
sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
4747
return combinePaths(newDirPath, sourceFilePath);
4848
}
@@ -523,7 +523,7 @@ module ts {
523523

524524
sourceMapData.sourceMapSources.push(getRelativePathToDirectoryOrUrl(sourcesDirectoryPath,
525525
node.filename,
526-
compilerHost.getCurrentDirectory,
526+
compilerHost.getCurrentDirectory(),
527527
/*isAbsolutePathAnUrl*/ true));
528528
sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1;
529529

@@ -640,7 +640,7 @@ module ts {
640640
sourceMapData.jsSourceMappingURL = getRelativePathToDirectoryOrUrl(
641641
getDirectoryPath(normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath
642642
combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap
643-
compilerHost.getCurrentDirectory,
643+
compilerHost.getCurrentDirectory(),
644644
/*isAbsolutePathAnUrl*/ true);
645645
}
646646
else {
@@ -3089,7 +3089,7 @@ module ts {
30893089
declFileName = getRelativePathToDirectoryOrUrl(
30903090
getDirectoryPath(normalizeSlashes(jsFilePath)),
30913091
declFileName,
3092-
compilerHost.getCurrentDirectory,
3092+
compilerHost.getCurrentDirectory(),
30933093
/*isAbsolutePathAnUrl*/ false);
30943094

30953095
referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3817,7 +3817,7 @@ module ts {
38173817
// Each file contributes into common source file path
38183818
if (!(sourceFile.flags & NodeFlags.DeclarationFile)
38193819
&& !fileExtensionIs(sourceFile.filename, ".js")) {
3820-
var sourcePathComponents = getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory);
3820+
var sourcePathComponents = getNormalizedPathComponents(sourceFile.filename, host.getCurrentDirectory());
38213821
sourcePathComponents.pop(); // FileName is not part of directory
38223822
if (commonPathComponents) {
38233823
for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) {

src/harness/projectsRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class ProjectRunner extends RunnerBase {
226226
? filename
227227
: ts.normalizeSlashes(testCase.projectRoot) + "/" + ts.normalizeSlashes(filename);
228228

229-
var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName, getCurrentDirectory, false);
229+
var diskRelativeName = ts.getRelativePathToDirectoryOrUrl(testCase.projectRoot, diskFileName, getCurrentDirectory(), false);
230230
if (ts.isRootedDiskPath(diskRelativeName) || diskRelativeName.substr(0, 3) === "../") {
231231
// If the generated output file recides in the parent folder or is rooted path,
232232
// we need to instead create files that can live in the project reference folder

src/services/services.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,17 +1420,14 @@ module ts {
14201420
getNewLine: () => "\r\n",
14211421
// Need something that doesn't depend on sys.ts here
14221422
getDefaultLibFilename: (): string => {
1423-
return host.getDefaultLibFilename();
1423+
return "";
14241424
},
14251425
writeFile: (filename, data, writeByteOrderMark) => {
1426-
if (writer) {
1427-
writer(filename, data, writeByteOrderMark);
1428-
return;
1429-
}
1430-
throw Error("Error occurs: Invalid invocation to writeFile");
1426+
writer(filename, data, writeByteOrderMark);
14311427
},
14321428
getCurrentDirectory: (): string => {
1433-
return host.getCurrentDirectory();
1429+
// Return empty string as in compilerHost using with Visual Studio should not need to getCurrentDirectory since CompilerHost should have absolute path already
1430+
return "";
14341431
}
14351432
};
14361433
}

0 commit comments

Comments
 (0)