@@ -4,7 +4,7 @@ const extractVariable = line => {
44 const variable_expr = / ^ v a r \s + ( \w + ) / ;
55 const variable_match = line . match ( variable_expr ) ;
66 if ( variable_match ) {
7- const [ _ , variable_name ] = variable_match ;
7+ const [ , variable_name ] = variable_match ;
88 return {
99 type : 'global_variable' ,
1010 name : variable_name ,
@@ -18,20 +18,31 @@ const extractFunction = line => {
1818 const function_expr = / ^ f u n c t i o n \s + ( \w + ) \s * \( ( .* ) \) / ;
1919 const function_match = line . match ( function_expr ) ;
2020 if ( function_match ) {
21- const [ _ , function_name , function_args ] = function_match ;
21+ const [ , function_name , function_args ] = function_match ;
22+ if ( ! utils . isClassName ( function_name ) ) {
23+ return {
24+ type : 'global_function' ,
25+ name : function_name ,
26+ args : utils . argsArray ( function_args ) ,
27+ } ;
28+ }
29+ }
30+
31+ return null ;
32+ } ;
33+
34+ const extractClass = line => {
35+ const function_expr = / ^ f u n c t i o n \s + ( \w + ) \s * \( ( .* ) \) / ;
36+ const function_match = line . match ( function_expr ) ;
37+ if ( function_match ) {
38+ const [ , function_name , function_args ] = function_match ;
2239 if ( utils . isClassName ( function_name ) ) {
2340 return {
2441 type : 'class_constructor' ,
2542 class : function_name ,
2643 args : utils . argsArray ( function_args ) ,
2744 } ;
2845 }
29-
30- return {
31- type : 'global_function' ,
32- name : function_name ,
33- args : utils . argsArray ( function_args ) ,
34- } ;
3546 }
3647
3748 return null ;
@@ -42,7 +53,7 @@ const extractBaseClass = line => {
4253 const base_class_match = line . match ( base_class_expr ) ;
4354
4455 if ( base_class_match ) {
45- const [ _ , class_name , base_class_name ] = base_class_match ;
56+ const [ , class_name , base_class_name ] = base_class_match ;
4657 return {
4758 type : 'base_class' ,
4859 class : class_name ,
@@ -57,7 +68,7 @@ const extractClassMethod = line => {
5768 const class_method_expr = / ^ ( \w + ) \. p r o t o t y p e \. ( \w + ) \s * \= \s * f u n c t i o n \( ( .* ) \) / ;
5869 const class_method_match = line . match ( class_method_expr ) ;
5970 if ( class_method_match ) {
60- const [ _ , class_name , method_name , method_args ] = class_method_match ;
71+ const [ , class_name , method_name , method_args ] = class_method_match ;
6172 return {
6273 type : 'class_method' ,
6374 class : class_name ,
@@ -75,18 +86,18 @@ const extractComment = comment_array => {
7586 const param_expr = / ^ \s * \* \s * @ p a r a m \s * ( t y p e \: ( \w + ) ) ? \s * ( \w + ) \s * ( .* ) $ / ;
7687 const return_expr = / ^ \s * \* \s * @ r e t u r n \s * ( t y p e \: ( \w + ) ) ? \s * ( .* ) $ / ;
7788
78- return comment_array . reduce ( ( comment , line ) => {
89+ const comment = comment_array . reduce ( ( comment , line ) => {
7990 const oneliner_match = line . match ( oneliner_expr ) ;
8091 if ( oneliner_match ) {
81- const [ _ , __ , type , brief ] = oneliner_match ;
92+ const [ , , type , brief ] = oneliner_match ;
8293 comment . brief = brief ;
8394 comment . type = type ;
8495 return comment ;
8596 }
8697
8798 const brief_match = line . match ( brief_expr ) ;
8899 if ( brief_match ) {
89- const [ _ , brief ] = brief_match ;
100+ const [ , brief ] = brief_match ;
90101 comment . brief = brief ;
91102 return comment ;
92103 }
@@ -96,60 +107,67 @@ const extractComment = comment_array => {
96107 if ( ! comment . params ) {
97108 comment . params = { } ;
98109 }
99- const [ _ , __ , type , name , brief ] = param_match ;
110+ const [ , , type , name , brief ] = param_match ;
100111 comment . params [ name ] = { brief, name, type } ;
101112 return comment ;
102113 }
103114
104115 const return_match = line . match ( return_expr ) ;
105116 if ( return_match ) {
106- const [ _ , __ , type , brief ] = return_match ;
117+ const [ , , type , brief ] = return_match ;
107118 comment . return = { brief, type } ;
108119 }
109120
110121 return comment ;
111122 } , { } ) ;
123+
124+ return comment ;
112125} ;
113126
114127var reading_comment = false ;
115128var comment_ready = false ;
116- var comment = [ ] ;
129+ var comment_lines = [ ] ;
130+ var comment = null ;
117131
118132const extractToken = ( tokens , line ) => {
119133 if ( utils . isSingleLineComment ( line ) ) {
134+ comment_lines = [ line ] ;
135+ comment = extractComment ( comment_lines ) ;
120136 comment_ready = true ;
121- comment = [ line ] ;
122137 return tokens ;
123138 }
124139
125140 if ( utils . isCommentEnd ( line ) ) {
126- reading_comment = false ;
141+ comment = extractComment ( comment_lines ) ;
127142 comment_ready = true ;
143+ reading_comment = false ;
128144 return tokens ;
129145 }
130146
131147 if ( reading_comment ) {
132- comment . push ( line ) ;
148+ comment_lines . push ( line ) ;
133149 return tokens ;
134150 }
135151
136152 if ( utils . isCommentStart ( line ) ) {
137- reading_comment = true ;
153+ comment_lines = [ ] ;
154+ comment = null ;
138155 comment_ready = false ;
139- comment = [ ] ;
156+ reading_comment = true ;
140157
141158 return tokens ;
142159 }
143160
144161 var token =
145162 extractVariable ( line ) ||
146163 extractFunction ( line ) ||
164+ extractClass ( line ) ||
147165 extractClassMethod ( line ) ||
148166 extractBaseClass ( line ) ;
149167
150168 if ( token ) {
151169 if ( comment_ready ) {
152- token . comment = extractComment ( comment ) ;
170+ token . comment = comment ;
153171 comment_ready = false ;
154172 }
155173
@@ -163,6 +181,7 @@ exports = module.exports = extractToken;
163181
164182exports . extractVariable = extractVariable ;
165183exports . extractFunction = extractFunction ;
184+ exports . extractClass = extractClass ;
166185exports . extractClassMethod = extractClassMethod ;
167186exports . extractBaseClass = extractBaseClass ;
168187exports . extractComment = extractComment ;
0 commit comments