Fix diffLineNumber for lines after a "no newline" marker

This commit is contained in:
Sergio Padrino 2024-01-26 13:08:56 +01:00
parent 211ef8fc58
commit 2a686716d0

View file

@ -311,7 +311,6 @@ export class DiffParser {
let diffLineNumber = linesConsumed
while ((c = this.parseLinePrefix(this.peek()))) {
const line = this.readLine()
diffLineNumber++
if (!line) {
throw new Error('Expected unified diff line but reached end of diff')
@ -338,6 +337,13 @@ export class DiffParser {
continue
}
// We must increase `diffLineNumber` only when we're certain that the line
// is not a "no newline" marker. Otherwise, we'll end up with a wrong
// `diffLineNumber` for the next line. This could happen if the last line
// in the file doesn't have a newline before the change nor after the
// change.
diffLineNumber++
let diffLine: DiffLine
if (c === DiffPrefixAdd) {