@@ -14,28 +14,27 @@ export function printPreservingEmptyLines(
1414 print : PrintFunction ,
1515 options : ParserOptions < AstNode >
1616) : Doc {
17- return [
18- path . map ( ( childPath ) => {
19- const node = childPath . node ;
17+ return path . node . items . length > 0
18+ ? path . map ( ( childPath ) => {
19+ const node = childPath . node ;
2020
21- return [
22- // Only attempt to prepend an empty line if `node` is not the first item
23- ! childPath . isFirst &&
24- // YulLabel adds a dedented line so we don't have to prepend a hardline.
25- ( node . kind !== NonterminalKind . YulStatement ||
26- node . variant . kind !== NonterminalKind . YulLabel )
27- ? hardline
28- : '' ,
29- print ( childPath ) ,
30- // Only attempt to append an empty line if `node` is not the last item
31- ! childPath . isLast &&
32- // Append an empty line if the original text already had an one after the
33- // current `node`
34- util . isNextLineEmpty ( options . originalText , locEnd ( node ) )
35- ? hardline
36- : ''
37- ] ;
38- } , 'items' ) ,
39- printComments ( path , options )
40- ] ;
21+ return [
22+ // Only attempt to prepend an empty line if `node` is not the first item
23+ ! childPath . isFirst &&
24+ // YulLabel adds a dedented line so we don't have to prepend a hardline.
25+ ( node . kind !== NonterminalKind . YulStatement ||
26+ node . variant . kind !== NonterminalKind . YulLabel )
27+ ? hardline
28+ : '' ,
29+ print ( childPath ) ,
30+ // Only attempt to append an empty line if `node` is not the last item
31+ ! childPath . isLast &&
32+ // Append an empty line if the original text already had an one after the
33+ // current `node`
34+ util . isNextLineEmpty ( options . originalText , locEnd ( node ) )
35+ ? hardline
36+ : ''
37+ ] ;
38+ } , 'items' )
39+ : printComments ( path , options ) ;
4140}
0 commit comments