function parseRanges()

in sapp/ui/frontend/src/Source.js [68:101]


function parseRanges(
  input: ?string,
  lines: $ReadOnlyArray<string>,
): Array<Range> {
  if (input === undefined || input === null || input === '') {
    return [];
  }

  return input.split(';').map(input => {
    const numbers = input.split('|').map(i => parseInt(i));
    if (numbers.length !== 3) {
      throw new Error(`Invalid Location: ${input}`);
    }
    const line = numbers[0] - 1;
    var begin = numbers[1];
    var end = numbers[2];
    if (end < begin) {
      // TODO(T78595608): remove temporary workaround for Pysa inverting locations.
      [begin, end] = [end, begin];
    }
    // If the highlight is empty and the line is in range, then highlight the whole line
    if (begin === end && end === 1 && line >= 0 && line < lines.length) {
      end = lines[line].length;
    }

    return adjustRange(
      {
        from: {line, ch: begin - 1},
        to: {line, ch: end},
      },
      lines,
    );
  });
}