MCPcopy Index your code
hub / github.com/nodejs/node / computePositionOfLineAndCharacter

Function computePositionOfLineAndCharacter

test/fixtures/snapshot/typescript.js:10311–10335  ·  view source on GitHub ↗
(lineStarts, line, character, debugText, allowEdits)

Source from the content-addressed store, hash-verified

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) {

Callers 1

Calls 4

computeLineStartsFunction · 0.85
concatMethod · 0.80
assertMethod · 0.80
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…