function parseHunk() {
    let chunkHeaderIndex = i,
        chunkHeaderLine = diffstr[i++],
        chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);

    let hunk = {
      oldStart: +chunkHeader[1],
      oldLines: +chunkHeader[2] || 1,
      newStart: +chunkHeader[3],
      newLines: +chunkHeader[4] || 1,
      lines: []
    };

    let addCount = 0,
        removeCount = 0;

    for (; i < diffstr.length; i++) {
      let line = diffstr[i],
          operation = line[0];

      // Check begin of line is NOT from a hunk, end parsing
      if (operation !== '+'
       && operation !== '-'
       && operation !== ' '
       && operation !== '\\') {
        break;
      }

      // Line is from a hunk, add it and update counters
      hunk.lines.push(line);

      switch (operation) {
        case '+': addCount++; break;
        case '-': removeCount++; break;
        case ' ': addCount++; removeCount++; break;
      }
    }

    // Handle the empty block count case
    if (!addCount && hunk.newLines === 1) {
      hunk.newLines = 0;
    }
    if (!removeCount && hunk.oldLines === 1) {
      hunk.oldLines = 0;
    }

    // Perform optional sanity checking
    if (options.strict) {
      if (addCount !== hunk.newLines) {
        throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
      }
      if (removeCount !== hunk.oldLines) {
        throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
      }
    }

    return hunk;
  }
// This assumes that we are at the start of a hunk.
This assumes that we are at the start of a hunk.
This assumes that we are at the start of a hunk .
function parseHunk() {
    let chunkHeaderIndex = i,
        chunkHeaderLine = diffstr[i++],
        chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
    let hunk = {
      oldStart: +chunkHeader[1],
      oldLines: +chunkHeader[2] || 1,
      newStart: +chunkHeader[3],
      newLines: +chunkHeader[4] || 1,
      lines: []
    };
    let addCount = 0,
        removeCount = 0;
    for (; i < diffstr.length; i++) {
      let line = diffstr[i],
          operation = line[0];
      if (operation !== '+'
       && operation !== '-'
       && operation !== ' '
       && operation !== '\\') {
        break;
      }
      hunk.lines.push(line);
      switch (operation) {
        case '+': addCount++; break;
        case '-': removeCount++; break;
        case ' ': addCount++; removeCount++; break;
      }
    }
    if (!addCount && hunk.newLines === 1) {
      hunk.newLines = 0;
    }
    if (!removeCount && hunk.oldLines === 1) {
      hunk.oldLines = 0;
    }
    if (options.strict) {
      if (addCount !== hunk.newLines) {
        throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
      }
      if (removeCount !== hunk.oldLines) {
        throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
      }
    }
    return hunk;
  }
function parseHunk ( ) { let chunkHeaderIndex = i , chunkHeaderLine = diffstr [ i ++ ] , chunkHeader = chunkHeaderLine . split ( / @@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@ / ) ; let hunk = { oldStart : + chunkHeader [ 1 ] , oldLines : + chunkHeader [ 2 ] || 1 , newStart : + chunkHeader [ 3 ] , newLines : + chunkHeader [ 4 ] || 1 , lines : [ ] } ; let addCount = 0 , removeCount = 0 ; for ( ; i < diffstr . length ; i ++ ) { let line = diffstr [ i ] , operation = line [ 0 ] ; if ( operation !== '+' && operation !== '-' && operation !== ' ' && operation !== '\\' ) { break ; } hunk . lines . push ( line ) ; switch ( operation ) { case '+' : addCount ++ ; break ; case '-' : removeCount ++ ; break ; case ' ' : addCount ++ ; removeCount ++ ; break ; } } if ( ! addCount && hunk . newLines === 1 ) { hunk . newLines = 0 ; } if ( ! removeCount && hunk . oldLines === 1 ) { hunk . oldLines = 0 ; } if ( options . strict ) { if ( addCount !== hunk . newLines ) { throw new Error ( 'Added line count did not match for hunk at line ' + ( chunkHeaderIndex + 1 ) ) ; } if ( removeCount !== hunk . oldLines ) { throw new Error ( 'Removed line count did not match for hunk at line ' + ( chunkHeaderIndex + 1 ) ) ; } } return hunk ; }
This assumes that we are at the start of a hunk.
This assumes that we are at the start of a hunk .
// Check begin of line is NOT from a hunk, end parsing // Line is from a hunk, add it and update counters // Handle the empty block count case // Perform optional sanity checking