@@ -102,43 +102,54 @@ export class FileParser {
102102 sectionIndex ,
103103 Cache . getPrecedingHeader ( lineNumber , this . fileCache . headings ) ,
104104 ) ;
105- if ( listItem . task !== undefined ) {
106- let task ;
107- try {
108- task = Task . fromLine ( {
109- line,
110- taskLocation : taskLocation ,
111- fallbackDate : this . dateFromFileName . value ,
112- } ) ;
113-
114- if ( task !== null ) {
115- // listItem.parent could be negative if the parent is not found (in other words, it is a root task).
116- // That is not a problem, as we never put a negative number in line2ListItem map, so parent will be null.
117- const parentListItem : ListItem | null = this . line2ListItem . get ( listItem . parent ) ?? null ;
118- if ( parentListItem !== null ) {
119- task = new Task ( {
120- ...task ,
121- parent : parentListItem ,
122- } ) ;
123- }
124-
125- this . line2ListItem . set ( lineNumber , task ) ;
126- }
127- } catch ( e ) {
128- this . errorReporter ( e , this . filePath , listItem , line ) ;
129- continue ;
130- }
105+ sectionIndex = this . parseLine ( listItem , line , taskLocation , lineNumber , sectionIndex ) ;
106+ }
107+
108+ return this . tasks ;
109+ }
110+
111+ private parseLine (
112+ listItem : ListItemCache ,
113+ line : string ,
114+ taskLocation : TaskLocation ,
115+ lineNumber : number ,
116+ sectionIndex : number ,
117+ ) {
118+ if ( listItem . task !== undefined ) {
119+ let task ;
120+ try {
121+ task = Task . fromLine ( {
122+ line,
123+ taskLocation : taskLocation ,
124+ fallbackDate : this . dateFromFileName . value ,
125+ } ) ;
131126
132127 if ( task !== null ) {
133- sectionIndex ++ ;
134- this . tasks . push ( task ) ;
128+ // listItem.parent could be negative if the parent is not found (in other words, it is a root task).
129+ // That is not a problem, as we never put a negative number in line2ListItem map, so parent will be null.
130+ const parentListItem : ListItem | null = this . line2ListItem . get ( listItem . parent ) ?? null ;
131+ if ( parentListItem !== null ) {
132+ task = new Task ( {
133+ ...task ,
134+ parent : parentListItem ,
135+ } ) ;
136+ }
137+
138+ this . line2ListItem . set ( lineNumber , task ) ;
135139 }
136- } else {
137- const parentListItem : ListItem | null = this . line2ListItem . get ( listItem . parent ) ?? null ;
138- this . line2ListItem . set ( lineNumber , new ListItem ( this . fileLines [ lineNumber ] , parentListItem ) ) ;
140+ } catch ( e ) {
141+ this . errorReporter ( e , this . filePath , listItem , line ) ;
142+ return sectionIndex ;
139143 }
140- }
141144
142- return this . tasks ;
145+ if ( task !== null ) {
146+ sectionIndex ++ ;
147+ this . tasks . push ( task ) ;
148+ }
149+ } else {
150+ const parentListItem : ListItem | null = this . line2ListItem . get ( listItem . parent ) ?? null ;
151+ this . line2ListItem . set ( lineNumber , new ListItem ( this . fileLines [ lineNumber ] , parentListItem ) ) ;
152+ }
153+ return sectionIndex ;
143154 }
144155}
0 commit comments