@@ -58,35 +58,23 @@ export class Parser {
5858 this . tree = root ;
5959 this . parser ( root ) ;
6060 // clean up nodes with error: 'File not found'
61- this . cleanUp ( this . tree ) ;
61+ this . removeTreesWithError ( this . tree ) ;
6262 return this . tree ;
6363 }
6464
65- /**
66- * create some sort of recursive function that will check if the error in the tree is 'File not found'
67- * how can i do this
68- * well if im in the tree, i cant exactly take it out of the array because I'm already in it. So can i check
69- * that error value when I'm one level out of it?
70- * something like if(tree.children[i].error && tree.children[i].error === 'File not found') -> slice it out of the array
71- * What would the base case be? When I'm out of elements in the children array? I think so
72- *
73- */
74- private cleanUp ( tree : Tree ) : void {
65+ private removeTreesWithError ( tree : Tree ) : void {
7566 // base case
7667 if ( tree . children . length === 0 ) return ;
77- // iterate over tree.children array to check for error. I will have to check the children array of
78- // the elements in this loop and recursively call cleanUp on it
79- // but how can i modify the children array, since im iterating over it.
80- //
68+ // iterate over tree.children array to check for error.
8169 for ( let i = 0 ; i < tree . children . length ; i ++ ) {
70+ // call removeTreesWithError on every tree in the children array
8271 if ( tree . children [ i ] . children . length !== 0 ) {
83- this . cleanUp ( tree . children [ i ] ) ;
72+ this . removeTreesWithError ( tree . children [ i ] ) ;
8473 }
85- if ( tree . children [ i ] . error && tree . children [ i ] . error === 'File not found' ) {
86- // when I find an element with the error, i need to slice it from the children array
87- // how can i do this without modifying the array that i'm iterating over?
74+ if ( tree . children [ i ] . error && ( tree . children [ i ] . error === 'File not found' || tree . children [ i ] . error === 'Error while processing this file/node' ) ) {
75+ // when an error is found, splice the tree out of the children array
8876 tree . children . splice ( i , 1 ) ;
89- i -- ;
77+ i -- ; // decrement to account for change in children array length
9078 }
9179 }
9280 } ;
@@ -309,7 +297,7 @@ export class Parser {
309297 }
310298 } ;
311299
312- console . log ( 'directive: ' , directive ) ;
300+ // console.log('directive: ', directive);
313301 // Initial check for use of directives (ex: 'use client', 'use server', 'use strict')
314302 // Accounts for more than one directive
315303 for ( let i = 0 ; i < directive . length ; i ++ ) {
0 commit comments