Skip to content

Commit 710bac6

Browse files
committed
Fix the source map directory resolution with non case sensitive file names
1 parent fe8f736 commit 710bac6

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/compiler/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ module ts {
476476
}
477477
}
478478

479-
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, isAbsolutePathAnUrl: boolean) {
479+
export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isAbsolutePathAnUrl: boolean) {
480480
var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory);
481481
var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory);
482482
if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") {
@@ -487,7 +487,7 @@ module ts {
487487

488488
// Find the component that differs
489489
for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) {
490-
if (directoryComponents[joinStartIndex] !== pathComponents[joinStartIndex]) {
490+
if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) {
491491
break;
492492
}
493493
}

src/compiler/emitter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ module ts {
527527
sourceMapData.sourceMapSources.push(getRelativePathToDirectoryOrUrl(sourcesDirectoryPath,
528528
node.filename,
529529
compilerHost.getCurrentDirectory(),
530-
/*isAbsolutePathAnUrl*/ true));
530+
compilerHost.getCanonicalFileName,
531+
/*isAbsolutePathAnUrl*/ true));
531532
sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1;
532533

533534
// The one that can be used from program to get the actual source file
@@ -692,7 +693,8 @@ module ts {
692693
getDirectoryPath(normalizePath(jsFilePath)), // get the relative sourceMapDir path based on jsFilePath
693694
combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL), // this is where user expects to see sourceMap
694695
compilerHost.getCurrentDirectory(),
695-
/*isAbsolutePathAnUrl*/ true);
696+
compilerHost.getCanonicalFileName,
697+
/*isAbsolutePathAnUrl*/ true);
696698
}
697699
else {
698700
sourceMapData.jsSourceMappingURL = combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL);
@@ -3170,7 +3172,8 @@ module ts {
31703172
getDirectoryPath(normalizeSlashes(jsFilePath)),
31713173
declFileName,
31723174
compilerHost.getCurrentDirectory(),
3173-
/*isAbsolutePathAnUrl*/ false);
3175+
compilerHost.getCanonicalFileName,
3176+
/*isAbsolutePathAnUrl*/ false);
31743177

31753178
referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
31763179
}

src/harness/projectsRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ 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,
230+
getCurrentDirectory(), Harness.Compiler.getCanonicalFileName, /*isAbsolutePathAnUrl*/ false);
230231
if (ts.isRootedDiskPath(diskRelativeName) || diskRelativeName.substr(0, 3) === "../") {
231232
// If the generated output file resides in the parent folder or is rooted path,
232233
// we need to instead create files that can live in the project reference folder

tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.sourcemap.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
JsFile: fooResult.js
33
mapUrl: fooResult.js.map
44
sourceRoot:
5-
sources: ../testFiles/app.ts,../testFiles/app2.ts
5+
sources: app.ts,app2.ts
66
===================================================================
77
-------------------------------------------------------------------
88
emittedFile:tests/cases/compiler/testfiles/fooResult.js
9-
sourceFile:../testFiles/app.ts
9+
sourceFile:app.ts
1010
-------------------------------------------------------------------
1111
>>>// Note in the out result we are using same folder name only different in casing
1212
1 >
@@ -88,7 +88,7 @@ sourceFile:../testFiles/app.ts
8888
---
8989
-------------------------------------------------------------------
9090
emittedFile:tests/cases/compiler/testfiles/fooResult.js
91-
sourceFile:../testFiles/app2.ts
91+
sourceFile:app2.ts
9292
-------------------------------------------------------------------
9393
>>>var d = (function () {
9494
1->

0 commit comments

Comments
 (0)