@@ -84,28 +84,36 @@ const isHunkHeader = (input: string) => {
84
84
} ;
85
85
86
86
const getRangeForChangedLines = ( line : string ) => {
87
+ /**
88
+ * Example values of the RegExp's group:
89
+ *
90
+ * start: '7',
91
+ * linesCountDelimiter: ',2',
92
+ * linesCount: '2',
93
+ */
87
94
const rangeRE = new RegExp (
88
95
/ ^ @ @ .* \+ (?< start > \d + ) (?< linesCountDelimiter > , (?< linesCount > \d + ) ) ? @ @ /
89
96
) ;
90
97
const range = rangeRE . exec ( line ) ;
91
98
if ( range === null ) {
92
99
throw Error ( `Couldn't match regex with line '${ line } '` ) ;
93
100
}
94
- if ( range . groups ?. start === undefined ) {
95
- /*
96
- * NOTE: Never happens, because RegExp requires start to be a
97
- * required number
98
- */
99
- throw Error ( "Couldn't match regex to find start" ) ;
100
- }
101
+
102
+ const groups = {
103
+ // Fallback value to ensure hasAddedLines resolves to false
104
+ start : "0" ,
105
+ linesCountDelimiter : ",0" ,
106
+ linesCount : "0" ,
107
+ ...range . groups ,
108
+ } ;
101
109
102
110
const linesCount : number =
103
- range . groups . linesCountDelimiter && range . groups . linesCount
104
- ? parseInt ( range . groups . linesCount )
111
+ groups . linesCountDelimiter && groups . linesCount
112
+ ? parseInt ( groups . linesCount )
105
113
: 1 ;
106
114
107
115
const hasAddedLines = linesCount !== 0 ;
108
- const start : number = parseInt ( range . groups . start ) ;
116
+ const start : number = parseInt ( groups . start ) ;
109
117
const end = start + linesCount ;
110
118
111
119
return hasAddedLines ? new Range ( start , end ) : null ;
0 commit comments