From 710bac6d81a11174eff8c0e60fe1de99262c98ba Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 3 Oct 2014 15:10:12 -0700 Subject: [PATCH] Fix the source map directory resolution with non case sensitive file names --- src/compiler/core.ts | 4 ++-- src/compiler/emitter.ts | 9 ++++++--- src/harness/projectsRunner.ts | 3 ++- .../sourceMapWithNonCaseSensitiveFileNames.js.map | 2 +- .../sourceMapWithNonCaseSensitiveFileNames.sourcemap.txt | 6 +++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 123bde2e719..5155289c73a 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -476,7 +476,7 @@ module ts { } } - export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, isAbsolutePathAnUrl: boolean) { + export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isAbsolutePathAnUrl: boolean) { var pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory); var directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory); if (directoryComponents.length > 1 && directoryComponents[directoryComponents.length - 1] === "") { @@ -487,7 +487,7 @@ module ts { // Find the component that differs for (var joinStartIndex = 0; joinStartIndex < pathComponents.length && joinStartIndex < directoryComponents.length; joinStartIndex++) { - if (directoryComponents[joinStartIndex] !== pathComponents[joinStartIndex]) { + if (getCanonicalFileName(directoryComponents[joinStartIndex]) !== getCanonicalFileName(pathComponents[joinStartIndex])) { break; } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a91637f2332..d9eb5ca12c9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -527,7 +527,8 @@ module ts { sourceMapData.sourceMapSources.push(getRelativePathToDirectoryOrUrl(sourcesDirectoryPath, node.filename, compilerHost.getCurrentDirectory(), - /*isAbsolutePathAnUrl*/ true)); + compilerHost.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ true)); sourceMapSourceIndex = sourceMapData.sourceMapSources.length - 1; // The one that can be used from program to get the actual source file @@ -692,7 +693,8 @@ module ts { 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(), - /*isAbsolutePathAnUrl*/ true); + compilerHost.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ true); } else { sourceMapData.jsSourceMappingURL = combinePaths(sourceMapDir, sourceMapData.jsSourceMappingURL); @@ -3170,7 +3172,8 @@ module ts { getDirectoryPath(normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), - /*isAbsolutePathAnUrl*/ false); + compilerHost.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ false); referencePathsOutput += "/// " + newLine; } diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index c294f5b1be4..2886c43f091 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -226,7 +226,8 @@ 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(), Harness.Compiler.getCanonicalFileName, /*isAbsolutePathAnUrl*/ false); if (ts.isRootedDiskPath(diskRelativeName) || diskRelativeName.substr(0, 3) === "../") { // If the generated output file resides 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/tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.js.map b/tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.js.map index 49f94ed3829..0a164a2a2c2 100644 --- a/tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.js.map +++ b/tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.js.map @@ -1,2 +1,2 @@ //// [fooResult.js.map] -{"version":3,"file":"fooResult.js","sourceRoot":"","sources":["../testFiles/app.ts","../testFiles/app2.ts"],"names":["c","c.constructor","d","d.constructor"],"mappings":"AAEA,AAFA,gFAAgF;AAChF,0GAA0G;IACpG,CAAC;IAAPA,SAAMA,CAACA;IACPC,CAACA;IAADD,QAACA;AAADA,CAACA,AADD,IACC;ACHD,IAAM,CAAC;IAAPE,SAAMA,CAACA;IACPC,CAACA;IAADD,QAACA;AAADA,CAACA,AADD,IACC"} \ No newline at end of file +{"version":3,"file":"fooResult.js","sourceRoot":"","sources":["app.ts","app2.ts"],"names":["c","c.constructor","d","d.constructor"],"mappings":"AAEA,AAFA,gFAAgF;AAChF,0GAA0G;IACpG,CAAC;IAAPA,SAAMA,CAACA;IACPC,CAACA;IAADD,QAACA;AAADA,CAACA,AADD,IACC;ACHD,IAAM,CAAC;IAAPE,SAAMA,CAACA;IACPC,CAACA;IAADD,QAACA;AAADA,CAACA,AADD,IACC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.sourcemap.txt b/tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.sourcemap.txt index 67f80b38bec..1923426adc6 100644 --- a/tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.sourcemap.txt +++ b/tests/baselines/reference/sourceMapWithNonCaseSensitiveFileNames.sourcemap.txt @@ -2,11 +2,11 @@ JsFile: fooResult.js mapUrl: fooResult.js.map sourceRoot: -sources: ../testFiles/app.ts,../testFiles/app2.ts +sources: app.ts,app2.ts =================================================================== ------------------------------------------------------------------- emittedFile:tests/cases/compiler/testfiles/fooResult.js -sourceFile:../testFiles/app.ts +sourceFile:app.ts ------------------------------------------------------------------- >>>// Note in the out result we are using same folder name only different in casing 1 > @@ -88,7 +88,7 @@ sourceFile:../testFiles/app.ts --- ------------------------------------------------------------------- emittedFile:tests/cases/compiler/testfiles/fooResult.js -sourceFile:../testFiles/app2.ts +sourceFile:app2.ts ------------------------------------------------------------------- >>>var d = (function () { 1->