(lineStarts, line, character, debugText, allowEdits)
| 10309 | ts.getPositionOfLineAndCharacter = getPositionOfLineAndCharacter; |
| 10310 | /* @internal */ |
| 10311 | function computePositionOfLineAndCharacter(lineStarts, line, character, debugText, allowEdits) { |
| 10312 | if (line < 0 || line >= lineStarts.length) { |
| 10313 | if (allowEdits) { |
| 10314 | // Clamp line to nearest allowable value |
| 10315 | line = line < 0 ? 0 : line >= lineStarts.length ? lineStarts.length - 1 : line; |
| 10316 | } |
| 10317 | else { |
| 10318 | ts.Debug.fail("Bad line number. Line: ".concat(line, ", lineStarts.length: ").concat(lineStarts.length, " , line map is correct? ").concat(debugText !== undefined ? ts.arraysEqual(lineStarts, computeLineStarts(debugText)) : "unknown")); |
| 10319 | } |
| 10320 | } |
| 10321 | var res = lineStarts[line] + character; |
| 10322 | if (allowEdits) { |
| 10323 | // Clamp to nearest allowable values to allow the underlying to be edited without crashing (accuracy is lost, instead) |
| 10324 | // TODO: Somehow track edits between file as it was during the creation of sourcemap we have and the current file and |
| 10325 | // apply them to the computed position to improve accuracy |
| 10326 | return res > lineStarts[line + 1] ? lineStarts[line + 1] : typeof debugText === "string" && res > debugText.length ? debugText.length : res; |
| 10327 | } |
| 10328 | if (line < lineStarts.length - 1) { |
| 10329 | ts.Debug.assert(res < lineStarts[line + 1]); |
| 10330 | } |
| 10331 | else if (debugText !== undefined) { |
| 10332 | ts.Debug.assert(res <= debugText.length); // Allow single character overflow for trailing newline |
| 10333 | } |
| 10334 | return res; |
| 10335 | } |
| 10336 | ts.computePositionOfLineAndCharacter = computePositionOfLineAndCharacter; |
| 10337 | /* @internal */ |
| 10338 | function getLineStarts(sourceFile) { |
no test coverage detected
searching dependent graphs…