From efe5dd6b6dfb0bf3be9dbf8f440c199b641d2c2a Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 29 Oct 2018 15:39:02 -0700 Subject: [PATCH] Handle case sensitivity correctly in source map decoder --- src/compiler/sourcemapDecoder.ts | 5 +++-- src/services/services.ts | 2 +- src/services/sourcemaps.ts | 10 ++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/compiler/sourcemapDecoder.ts b/src/compiler/sourcemapDecoder.ts index 28cbbe39cf5..dd0d65c8092 100644 --- a/src/compiler/sourcemapDecoder.ts +++ b/src/compiler/sourcemapDecoder.ts @@ -57,6 +57,7 @@ namespace ts.sourcemaps { fileExists(path: string): boolean; getCanonicalFileName(path: string): string; log(text: string): void; + useCaseSensitiveFileNames: boolean; } export function decode(host: SourceMapDecodeHost, mapPath: string, map: SourceMapData, program?: Program, fallbackCache = createSourceFileLikeCache(host)): SourceMapper { @@ -79,7 +80,7 @@ namespace ts.sourcemaps { // if no exact match, closest is 2's compliment of result targetIndex = ~targetIndex; } - if (!maps[targetIndex] || comparePaths(loc.fileName, maps[targetIndex].sourcePath, sourceRoot) !== 0) { + if (!maps[targetIndex] || comparePaths(loc.fileName, maps[targetIndex].sourcePath, sourceRoot, !host.useCaseSensitiveFileNames) !== 0) { return loc; } return { fileName: toPath(map.file!, sourceRoot, host.getCanonicalFileName), position: maps[targetIndex].emittedPosition }; // Closest pos @@ -129,7 +130,7 @@ namespace ts.sourcemaps { } function compareProcessedPositionSourcePositions(a: ProcessedSourceMapPosition, b: ProcessedSourceMapPosition) { - return comparePaths(a.sourcePath, b.sourcePath, sourceRoot) || + return comparePaths(a.sourcePath, b.sourcePath, sourceRoot, !host.useCaseSensitiveFileNames) || compareValues(a.sourcePosition, b.sourcePosition); } diff --git a/src/services/services.ts b/src/services/services.ts index 4367bd11985..afcdc7b4f16 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1139,7 +1139,7 @@ namespace ts { const useCaseSensitiveFileNames = hostUsesCaseSensitiveFileNames(host); const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames); - const sourceMapper = getSourceMapper(getCanonicalFileName, currentDirectory, log, host, () => program); + const sourceMapper = getSourceMapper(useCaseSensitiveFileNames, currentDirectory, log, host, () => program); function getValidSourceFile(fileName: string): SourceFile { const sourceFile = program.getSourceFile(fileName); diff --git a/src/services/sourcemaps.ts b/src/services/sourcemaps.ts index 1833c415be4..25e6fb9c124 100644 --- a/src/services/sourcemaps.ts +++ b/src/services/sourcemaps.ts @@ -13,12 +13,13 @@ namespace ts { } export function getSourceMapper( - getCanonicalFileName: GetCanonicalFileName, + useCaseSensitiveFileNames: boolean, currentDirectory: string, log: (message: string) => void, host: LanguageServiceHost, getProgram: () => Program, ): SourceMapper { + const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames); let sourcemappedFileCache: SourceFileLikeCache; return { tryGetOriginalLocation, tryGetGeneratedLocation, toLineColumnOffset, clearCache }; @@ -56,6 +57,7 @@ namespace ts { return file.sourceMapper = sourcemaps.decode({ readFile: s => host.readFile!(s), // TODO: GH#18217 fileExists: s => host.fileExists!(s), // TODO: GH#18217 + useCaseSensitiveFileNames, getCanonicalFileName, log, }, mapFileName, maps, getProgram(), sourcemappedFileCache); @@ -105,7 +107,11 @@ namespace ts { function tryGetGeneratedLocation(info: sourcemaps.SourceMappableLocation): sourcemaps.SourceMappableLocation | undefined { const program = getProgram(); - const declarationPath = getDeclarationEmitOutputFilePathWorker(info.fileName, program.getCompilerOptions(), currentDirectory, program.getCommonSourceDirectory(), getCanonicalFileName); + const options = program.getCompilerOptions(); + const outPath = options.outFile || options.out; + const declarationPath = outPath ? + removeFileExtension(outPath) + Extension.Dts : + getDeclarationEmitOutputFilePathWorker(info.fileName, program.getCompilerOptions(), currentDirectory, program.getCommonSourceDirectory(), getCanonicalFileName); if (declarationPath === undefined) return undefined; const declarationFile = getFile(declarationPath); if (!declarationFile) return undefined;