@@ -49,7 +49,7 @@ export class Parser {
4949 reactRouter : false ,
5050 reduxConnect : false ,
5151 children : [ ] ,
52- parent : null ,
52+ parent : '' ,
5353 parentList : [ ] ,
5454 props : { } ,
5555 error : '' ,
@@ -80,7 +80,7 @@ export class Parser {
8080 } ;
8181
8282 public getTree ( ) : Tree {
83- return this . tree ;
83+ return this . tree ! ;
8484 }
8585
8686 // Set entryFile property with the result of Parser (from workspace state)
@@ -178,9 +178,6 @@ export class Parser {
178178 if ( componentTree . parentList . includes ( componentTree . filePath ) ) {
179179 return ;
180180 }
181- // if (typeof componentTree.parentList === 'string' && componentTree.parentList.includes(componentTree.filePath)) {
182- // return;
183- // }
184181
185182 // Create abstract syntax tree of current component tree file
186183 let ast : babel . ParseResult < File > ;
@@ -289,15 +286,14 @@ export class Parser {
289286 }
290287
291288 // Determines server or client component type (looks for use of 'use client' and react/redux state hooks)
292- private getComponentType ( directive : { [ key : string ] : any } [ ] , body : { [ key : string ] : any } [ ] ) : boolean {
289+ private getComponentType ( directive : { [ key : string ] : any } [ ] , body : { [ key : string ] : any } [ ] ) {
293290 const defaultErr = ( err ) => {
294291 return {
295292 method : 'Error in getCallee method of Parser:' ,
296293 log : err ,
297294 }
298295 } ;
299296
300- // console.log('directive: ', directive);
301297 // Initial check for use of directives (ex: 'use client', 'use server', 'use strict')
302298 // Accounts for more than one directive
303299 for ( let i = 0 ; i < directive . length ; i ++ ) {
@@ -310,8 +306,14 @@ export class Parser {
310306 }
311307
312308 // Second check for use of React/Redux hooks
309+ // Checks for components declared using 'const'
313310 const bodyCallee = body . filter ( ( item ) => item . type === 'VariableDeclaration' ) ;
314- if ( bodyCallee . length === 0 ) return false ;
311+
312+ // Checks for components declared using 'export default function'
313+ const exportCallee = body . filter ( ( item ) => item . type === 'ExportDefaultDeclaration' ) ;
314+
315+ // Checks for components declared using 'function'
316+ const functionCallee = body . filter ( ( item ) => item . type === 'FunctionDeclaration' ) ;
315317
316318 // Helper function
317319 const calleeHelper = ( item ) => {
@@ -333,6 +335,8 @@ export class Parser {
333335 useDispatch : 0 ,
334336 useActions : 0 ,
335337 useSelector : 0 ,
338+ useShallowEqualSelector : 0 ,
339+ useStore : 0 ,
336340 bindActionCreators : 0 ,
337341 }
338342 if ( item . type === 'VariableDeclaration' ) {
@@ -363,39 +367,43 @@ export class Parser {
363367 return false ;
364368 }
365369
366- if ( bodyCallee . length === 1 ) {
367- const calleeArr = bodyCallee [ 0 ] . declarations [ 0 ] ?. init ?. body ?. body ;
368- if ( calleeArr === undefined ) return false ;
370+ // Process Function Declarations
371+ for ( const func of functionCallee ) {
372+ const calleeArr = func . body ?. body ;
373+ if ( ! calleeArr ) continue ; // Skip if no body
369374
370- let checkTrue = false ;
371- for ( let i = 0 ; i < calleeArr . length ; i ++ ) {
372- if ( checkTrue ) return true ;
373- checkTrue = calleeHelper ( calleeArr [ i ] ) ;
375+ for ( const callee of calleeArr ) {
376+ if ( calleeHelper ( callee ) ) {
377+ return true ;
378+ }
374379 }
375- return checkTrue ;
376380 }
377- else if ( bodyCallee . length > 1 ) {
378- let calleeArr : [ ] ;
379- for ( let i = 0 ; i < bodyCallee . length ; i ++ ) {
380- try {
381- if ( bodyCallee [ i ] . declarations [ 0 ] ?. init ?. body ?. body ) {
382- calleeArr = bodyCallee [ i ] . declarations [ 0 ] . init . body . body ;
383- }
384- }
385- catch ( err ) {
386- const error = defaultErr ( err ) ;
387- console . error ( error . method , '\n' , error . log ) ;
381+
382+ // Process Export Declarations
383+ for ( const exportDecl of exportCallee ) {
384+ const calleeArr = exportDecl . declaration . body ?. body ;
385+ if ( ! calleeArr ) continue ; // Skip if no body
386+
387+ for ( const callee of calleeArr ) {
388+ if ( calleeHelper ( callee ) ) {
389+ return true ;
388390 }
389391 }
390-
391- if ( calleeArr === undefined ) return false ;
392- let checkTrue = false ;
393- for ( let i = 0 ; i < calleeArr . length ; i ++ ) {
394- if ( checkTrue ) return true ;
395- checkTrue = calleeHelper ( calleeArr [ i ] ) ;
392+ }
393+
394+ // Process Body Declarations
395+ for ( const bodyDecl of bodyCallee ) {
396+ const calleeArr = bodyDecl . declarations [ 0 ] ?. init ?. body ?. body ;
397+ if ( ! calleeArr ) continue ; // Skip if no body
398+
399+ for ( const callee of calleeArr ) {
400+ if ( calleeHelper ( callee ) ) {
401+ return true ;
402+ }
396403 }
397- return checkTrue ;
398404 }
405+
406+ return false ;
399407 }
400408
401409 // Finds JSX React Components in current file
0 commit comments