# All files / src/utils generate-error.js

100% Statements 13/13
100% Branches 4/4
100% Functions 2/2
100% Lines 13/13

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46

    32x
    3x
    3x
    3x

    29x
    29x
    29x

    32x
    32x
    3x

    29x

    32x
    32x

     // @flow

    export default function generateErrorString(
      msg: string,
      error: string,
      marker: {
        start: { sourceLine: string, line: number, col: number },
        end: { sourceLine: string, line: number, col: number },
      },
      filename: string,
      func: string
    ): string {
      let line;
      let col;
      let end;

      if (marker.start.line !== marker.end.line) {
        end = marker.start.col + 1;
        col = marker.start.col;
        line = marker.start.line;
      } else {
        line = marker.start.line;
        col = marker.start.col;
        end = marker.end.col;
      }
      const Line = (() => {
        if (marker.start.sourceLine !== marker.end.sourceLine) {
          return marker.start.sourceLine + '\n' + marker.end.sourceLine;
        }
        return marker.end.sourceLine;
      })();

      const highlight = new Array(end - col + 1).join('^').padStart(end, ' ');
      return (
        '\n' +
        Line +
        '\n' +
        highlight +
        ` ${error}` +
        '\n' +
        msg +
        '\n' +
        `  at ${func} (${filename}:${line}:${col})`
      );
    }