@@ -7,19 +7,20 @@ const FileParsing = async (formData, rows) => {
77 const filesParsed = [ ] ;
88
99 for ( const fileEntry of files ) {
10- const [ fileName ] = fileEntry . name . split ( "." ) ;
10+ const [ fileName , ...extParts ] = fileEntry . name . split ( "." ) ;
11+ const extension = extParts . length ? extParts . join ( "." ) : "" ;
1112
1213 for ( const row of rows ) {
1314 if ( fileName === row . file ) {
1415 const file = await fileEntry . getFile ( ) ;
1516 const content = await file . text ( ) ;
1617 const functions = [ ] ;
17-
18- const lines = content . split ( "\n" ) ;
1918 let pendingComments = [ ] ;
2019 let insideBlockComment = false ;
2120 let blockCommentBuffer = "" ;
2221
22+ const lines = content . split ( "\n" ) ;
23+
2324 for ( let i = 0 ; i < lines . length ; i ++ ) {
2425 let line = lines [ i ] . trim ( ) ;
2526
@@ -41,22 +42,49 @@ const FileParsing = async (formData, rows) => {
4142 }
4243 }
4344
44- if ( i + 1 < lines . length ) {
45- let nextLine = lines [ i + 1 ] . trim ( ) ;
45+ let nextIndex = i + 1 ;
46+ while ( nextIndex < lines . length && lines [ nextIndex ] . trim ( ) === "" ) {
47+ nextIndex ++ ;
48+ }
49+
50+ let nextLine = nextIndex < lines . length ? lines [ nextIndex ] . trim ( ) : "" ;
51+
52+ let isFunctionDeclaration =
53+ nextLine . startsWith ( "const " ) || nextLine . indexOf ( "function" ) !== - 1 ;
54+
55+ if ( isFunctionDeclaration ) {
56+ let functionName = "" ;
57+
4658 if ( nextLine . startsWith ( "const " ) ) {
4759 let functionStart = nextLine . indexOf ( "const" ) + 6 ;
4860 let functionEnd = nextLine . indexOf ( " " , functionStart ) ;
61+ if ( functionEnd !== - 1 ) {
62+ functionName = nextLine . substring ( functionStart , functionEnd ) . trim ( ) ;
63+ }
64+ } else if ( nextLine . indexOf ( "function" ) !== - 1 ) {
65+ let functionStart = nextLine . indexOf ( "function" ) + 9 ;
66+ let functionEnd = nextLine . indexOf ( " " , functionStart ) ;
67+ if ( functionEnd !== - 1 ) {
68+ functionName = nextLine . substring ( functionStart , functionEnd ) . trim ( ) ;
69+ }
70+ }
4971
50- if ( functionEnd !== - 1 && pendingComments . length > 0 ) {
51- let functionName = nextLine . substring ( functionStart , functionEnd ) . trim ( ) ;
72+ if ( functionName && pendingComments . length > 0 ) {
73+ functions . push ( {
74+ functionName : functionName ,
75+ comments : [ ...pendingComments ] ,
76+ } ) ;
5277
53- functions . push ( {
54- functionName : functionName || "" ,
55- comments : [ ...pendingComments ] ,
56- } ) ;
78+ pendingComments = [ ] ;
79+ }
80+ } else {
81+ if ( pendingComments . length > 0 ) {
82+ functions . push ( {
83+ functionName : "" ,
84+ comments : [ ...pendingComments ] ,
85+ } ) ;
5786
58- pendingComments = [ ] ;
59- }
87+ pendingComments = [ ] ;
6088 }
6189 }
6290 }
@@ -72,4 +100,4 @@ const FileParsing = async (formData, rows) => {
72100 return filesParsed ;
73101} ;
74102
75- module . exports = FileParsing ;
103+ module . exports = FileParsing ;
0 commit comments