@@ -99,41 +99,69 @@ function genericPrint(path, options, print) {
9999 ] ) ;
100100 }
101101 return concat ( [ 'using ' , node . libraryName , ' for *;' ] ) ;
102- case 'FunctionDefinition' :
102+ case 'FunctionDefinition' : {
103+ let parts = [ ] ;
104+
103105 if ( node . isConstructor ) {
104106 if ( node . name ) {
105- doc = `function ${ node . name } ` ;
107+ parts . push ( `function ${ node . name } ` ) ;
106108 } else {
107- doc = 'constructor' ;
109+ parts . push ( 'constructor' ) ;
108110 }
109111 } else if ( node . name === '' ) {
110- doc = 'function' ;
112+ parts . push ( 'function' ) ;
111113 } else {
112- doc = concat ( [ 'function ' , node . name ] ) ;
114+ parts = parts . concat ( [ 'function ' , node . name ] ) ;
113115 }
114116
115- doc = concat ( [ doc , '(' , path . call ( print , 'parameters' ) , ')' ] ) ;
117+ parts = parts . concat ( [ '(' , path . call ( print , 'parameters' ) , ')' ] ) ;
118+
119+ let modifiers = [ ] ;
116120 if ( node . visibility && node . visibility !== 'default' ) {
117- doc = join ( ' ' , [ doc , node . visibility ] ) ;
121+ modifiers . push ( node . visibility ) ;
118122 }
119123 // @TODO : check stateMutability null vs default
120124 if ( node . stateMutability && node . stateMutability !== 'default' ) {
121- doc = join ( ' ' , [ doc , node . stateMutability ] ) ;
125+ modifiers . push ( node . stateMutability ) ;
122126 }
123127 if ( node . modifiers . length > 0 ) {
124- doc = join ( ' ' , [ doc , join ( ' ' , path . map ( print , 'modifiers' ) ) ] ) ;
128+ modifiers = modifiers . concat ( path . map ( print , 'modifiers' ) ) ;
125129 }
126130 if ( node . returnParameters ) {
127- doc = join ( ' ' , [
128- doc ,
131+ modifiers . push (
129132 concat ( [ 'returns (' , path . call ( print , 'returnParameters' ) , ')' ] )
130- ] ) ;
133+ ) ;
134+ }
135+
136+ if ( modifiers . length > 0 ) {
137+ parts . push (
138+ group (
139+ concat (
140+ [
141+ indent ( line ) ,
142+ join ( indent ( line ) , modifiers ) ,
143+ node . body ? line : null
144+ ] . filter ( x => x )
145+ )
146+ )
147+ ) ;
148+ } else if ( node . body ) {
149+ parts . push ( ' ' ) ;
131150 }
151+
132152 if ( node . body ) {
133- return concat ( [ join ( ' ' , [ doc , path . call ( print , 'body' ) ] ) ] ) ;
153+ parts . push ( path . call ( print , 'body' ) ) ;
154+ } else {
155+ parts . push ( ';' ) ;
134156 }
135- return concat ( [ doc , ';' ] ) ;
157+
158+ return concat ( parts ) ;
159+ }
136160 case 'ParameterList' :
161+ // don't insert softlines when there are no parameters
162+ if ( node . parameters . length === 0 ) {
163+ return '' ;
164+ }
137165 return group (
138166 concat ( [
139167 indent (
0 commit comments