1- const isDetachedComment = token => {
2- return token . token_type === 'multiline_comment' && token . filename ;
3- } ;
1+ const isDetachedComment = token => token . token_type === 'multiline_comment' && token . filename ;
42
5- const isAttachedComment = token => {
6- return (
7- token . token_type === 'singleline_comment' ||
8- ( token . token_type === 'multiline_comment' && ! isDetachedComment ( token ) )
9- ) ;
10- } ;
3+ const isAttachedComment = token =>
4+ token . token_type === 'singleline_comment' ||
5+ ( token . token_type === 'multiline_comment' && ! isDetachedComment ( token ) ) ;
116
127const prev = ( array , index ) => ( index > 0 ? array [ index - 1 ] : null ) ;
138
@@ -34,7 +29,7 @@ const attachVariableComment = (token, comment) => {
3429
3530const attachFunctionComment = ( token , comment ) => {
3631 if ( comment ) {
37- token . args . forEach ( arg => {
32+ token . args . forEach ( ( arg ) => {
3833 if ( comment . params && arg . name in comment . params ) {
3934 arg . type = comment . params [ arg . name ] . type || 'var' ;
4035 } else {
@@ -45,7 +40,7 @@ const attachFunctionComment = (token, comment) => {
4540 token . type = comment . return ? comment . return . type || 'void' : 'void' ;
4641 token . comment = comment ;
4742 } else {
48- token . args . forEach ( arg => {
43+ token . args . forEach ( ( arg ) => {
4944 arg . type = 'var' ;
5045 } ) ;
5146
@@ -56,7 +51,7 @@ const attachFunctionComment = (token, comment) => {
5651
5752const attachClassConstructorComment = ( token , comment ) => {
5853 if ( comment ) {
59- token . args . forEach ( arg => {
54+ token . args . forEach ( ( arg ) => {
6055 if ( comment . params && arg . name in comment . params ) {
6156 arg . type = comment . params [ arg . name ] . type || 'var' ;
6257 } else {
@@ -66,7 +61,7 @@ const attachClassConstructorComment = (token, comment) => {
6661
6762 token . comment = comment ;
6863 } else {
69- token . args . forEach ( arg => {
64+ token . args . forEach ( ( arg ) => {
7065 arg . type = 'var' ;
7166 } ) ;
7267 }
@@ -75,7 +70,7 @@ const attachClassConstructorComment = (token, comment) => {
7570
7671const attachClassMethodComment = ( token , comment ) => {
7772 if ( comment ) {
78- token . args . forEach ( arg => {
73+ token . args . forEach ( ( arg ) => {
7974 if ( comment . params && arg . name in comment . params ) {
8075 arg . type = comment . params [ arg . name ] . type || 'var' ;
8176 } else {
@@ -86,7 +81,7 @@ const attachClassMethodComment = (token, comment) => {
8681 token . type = comment . return ? comment . return . type || 'void' : 'void' ;
8782 token . comment = comment ;
8883 } else {
89- token . args . forEach ( arg => {
84+ token . args . forEach ( ( arg ) => {
9085 arg . type = 'var' ;
9186 } ) ;
9287
@@ -95,8 +90,8 @@ const attachClassMethodComment = (token, comment) => {
9590 return token ;
9691} ;
9792
98- const inputStructure = tokens => {
99- let structure = {
93+ const inputStructure = ( tokens ) => {
94+ const structure = {
10095 comments : [ ] ,
10196 variables : [ ] ,
10297 functions : [ ] ,
@@ -106,27 +101,21 @@ const inputStructure = tokens => {
106101 tokens . forEach ( ( token , index , tokens ) => {
107102 switch ( token . token_type ) {
108103 case 'variable' :
109- structure . variables . push (
110- attachVariableComment ( token , comment ( tokens , index ) )
111- ) ;
104+ structure . variables . push ( attachVariableComment ( token , comment ( tokens , index ) ) ) ;
112105 break ;
113106 case 'function' :
114- structure . functions . push (
115- attachFunctionComment ( token , comment ( tokens , index ) )
116- ) ;
107+ structure . functions . push ( attachFunctionComment ( token , comment ( tokens , index ) ) ) ;
117108 break ;
118109 case 'class_constructor' :
119110 prefillClass ( structure , token . class_name ) ;
120111 const c = comment ( tokens , index ) ;
121- structure . classes [
122- token . class_name
123- ] . constructor = attachClassConstructorComment ( token , c ) ;
112+ structure . classes [ token . class_name ] . constructor = attachClassConstructorComment ( token , c ) ;
124113 structure . classes [ token . class_name ] . comment = c || undefined ;
125114 break ;
126115 case 'class_method' :
127116 prefillClass ( structure , token . class_name ) ;
128117 structure . classes [ token . class_name ] . methods . push (
129- attachClassMethodComment ( token , comment ( tokens , index ) )
118+ attachClassMethodComment ( token , comment ( tokens , index ) ) ,
130119 ) ;
131120 break ;
132121 case 'base_class' :
@@ -141,10 +130,12 @@ const inputStructure = tokens => {
141130 structure . comments . push ( token ) ;
142131 }
143132 break ;
133+ default :
134+ break ;
144135 }
145136 } ) ;
146137
147138 return structure ;
148139} ;
149140
150- module . exports = inputStructure ;
141+ export default inputStructure ;
0 commit comments