Skip to content

Commit efe5dd6

Browse files
committed
Handle case sensitivity correctly in source map decoder
1 parent 3a2f7c0 commit efe5dd6

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/compiler/sourcemapDecoder.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace ts.sourcemaps {
5757
fileExists(path: string): boolean;
5858
getCanonicalFileName(path: string): string;
5959
log(text: string): void;
60+
useCaseSensitiveFileNames: boolean;
6061
}
6162

6263
export function decode(host: SourceMapDecodeHost, mapPath: string, map: SourceMapData, program?: Program, fallbackCache = createSourceFileLikeCache(host)): SourceMapper {
@@ -79,7 +80,7 @@ namespace ts.sourcemaps {
7980
// if no exact match, closest is 2's compliment of result
8081
targetIndex = ~targetIndex;
8182
}
82-
if (!maps[targetIndex] || comparePaths(loc.fileName, maps[targetIndex].sourcePath, sourceRoot) !== 0) {
83+
if (!maps[targetIndex] || comparePaths(loc.fileName, maps[targetIndex].sourcePath, sourceRoot, !host.useCaseSensitiveFileNames) !== 0) {
8384
return loc;
8485
}
8586
return { fileName: toPath(map.file!, sourceRoot, host.getCanonicalFileName), position: maps[targetIndex].emittedPosition }; // Closest pos
@@ -129,7 +130,7 @@ namespace ts.sourcemaps {
129130
}
130131

131132
function compareProcessedPositionSourcePositions(a: ProcessedSourceMapPosition, b: ProcessedSourceMapPosition) {
132-
return comparePaths(a.sourcePath, b.sourcePath, sourceRoot) ||
133+
return comparePaths(a.sourcePath, b.sourcePath, sourceRoot, !host.useCaseSensitiveFileNames) ||
133134
compareValues(a.sourcePosition, b.sourcePosition);
134135
}
135136

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ namespace ts {
11391139
const useCaseSensitiveFileNames = hostUsesCaseSensitiveFileNames(host);
11401140
const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
11411141

1142-
const sourceMapper = getSourceMapper(getCanonicalFileName, currentDirectory, log, host, () => program);
1142+
const sourceMapper = getSourceMapper(useCaseSensitiveFileNames, currentDirectory, log, host, () => program);
11431143

11441144
function getValidSourceFile(fileName: string): SourceFile {
11451145
const sourceFile = program.getSourceFile(fileName);

src/services/sourcemaps.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ namespace ts {
1313
}
1414

1515
export function getSourceMapper(
16-
getCanonicalFileName: GetCanonicalFileName,
16+
useCaseSensitiveFileNames: boolean,
1717
currentDirectory: string,
1818
log: (message: string) => void,
1919
host: LanguageServiceHost,
2020
getProgram: () => Program,
2121
): SourceMapper {
22+
const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
2223
let sourcemappedFileCache: SourceFileLikeCache;
2324
return { tryGetOriginalLocation, tryGetGeneratedLocation, toLineColumnOffset, clearCache };
2425

@@ -56,6 +57,7 @@ namespace ts {
5657
return file.sourceMapper = sourcemaps.decode({
5758
readFile: s => host.readFile!(s), // TODO: GH#18217
5859
fileExists: s => host.fileExists!(s), // TODO: GH#18217
60+
useCaseSensitiveFileNames,
5961
getCanonicalFileName,
6062
log,
6163
}, mapFileName, maps, getProgram(), sourcemappedFileCache);
@@ -105,7 +107,11 @@ namespace ts {
105107

106108
function tryGetGeneratedLocation(info: sourcemaps.SourceMappableLocation): sourcemaps.SourceMappableLocation | undefined {
107109
const program = getProgram();
108-
const declarationPath = getDeclarationEmitOutputFilePathWorker(info.fileName, program.getCompilerOptions(), currentDirectory, program.getCommonSourceDirectory(), getCanonicalFileName);
110+
const options = program.getCompilerOptions();
111+
const outPath = options.outFile || options.out;
112+
const declarationPath = outPath ?
113+
removeFileExtension(outPath) + Extension.Dts :
114+
getDeclarationEmitOutputFilePathWorker(info.fileName, program.getCompilerOptions(), currentDirectory, program.getCommonSourceDirectory(), getCanonicalFileName);
109115
if (declarationPath === undefined) return undefined;
110116
const declarationFile = getFile(declarationPath);
111117
if (!declarationFile) return undefined;

0 commit comments

Comments
 (0)