Clamp calculated sourcemap positions rather than throwing (#28583)

* Clamp calculated sourcemap positions rather than throwing, to allow the underlying file to drift out of date with the sourcemap without a crash

* Clamp line as well
This commit is contained in:
Wesley Wigham
2018-11-16 16:05:07 -08:00
committed by GitHub
parent 12f3d0d54c
commit cd08a22ef5
3 changed files with 53 additions and 4 deletions

View File

@@ -608,7 +608,7 @@ namespace ts {
function processMapping(mapping: Mapping): MappedPosition {
const generatedPosition = generatedFile !== undefined
? getPositionOfLineAndCharacter(generatedFile, mapping.generatedLine, mapping.generatedCharacter)
? getPositionOfLineAndCharacterWithEdits(generatedFile, mapping.generatedLine, mapping.generatedCharacter)
: -1;
let source: string | undefined;
let sourcePosition: number | undefined;
@@ -617,7 +617,7 @@ namespace ts {
const sourceFile = host.getSourceFileLike(sourceFilePath);
source = map.sources[mapping.sourceIndex];
sourcePosition = sourceFile !== undefined
? getPositionOfLineAndCharacter(sourceFile, mapping.sourceLine, mapping.sourceCharacter)
? getPositionOfLineAndCharacterWithEdits(sourceFile, mapping.sourceLine, mapping.sourceCharacter)
: -1;
}
return {