@@ -348,7 +348,10 @@ function printElementFragments(path, opts, print) {
348
348
const referenceNode = referencePath . getValue ( ) ;
349
349
350
350
return {
351
+ type : "reference" ,
351
352
offset : referenceNode . location . startOffset ,
353
+ startLine : referenceNode . location . startLine ,
354
+ endLine : referenceNode . location . endLine ,
352
355
printed : print ( referencePath )
353
356
} ;
354
357
} , "reference" )
@@ -476,6 +479,10 @@ function printElement(path, opts, print) {
476
479
] ) ;
477
480
}
478
481
482
+ if ( fragments . length === 0 ) {
483
+ return group ( [ ...parts , space , "/>" ] ) ;
484
+ }
485
+
479
486
// If the only content of this tag is chardata, then use a softline so
480
487
// that we won't necessarily break (to allow <foo>bar</foo>).
481
488
if (
@@ -490,18 +497,28 @@ function printElement(path, opts, print) {
490
497
] ) ;
491
498
}
492
499
493
- if ( fragments . length === 0 ) {
494
- return group ( [ ...parts , space , "/>" ] ) ;
500
+ let delimiter = hardline ;
501
+
502
+ // If the only content is both chardata and references, then use a softline
503
+ // so that we won't necessarily break.
504
+ if (
505
+ fragments . length ===
506
+ content . chardata . filter ( ( chardata ) => chardata . TEXT ) . length +
507
+ content . reference . length
508
+ ) {
509
+ delimiter = " " ;
495
510
}
496
511
497
- const docs = [ ] ;
512
+ const docs = [ hardline ] ;
498
513
let lastLine = fragments [ 0 ] . startLine ;
499
514
500
- fragments . forEach ( ( node ) => {
501
- if ( node . startLine - lastLine >= 2 ) {
502
- docs . push ( hardline , hardline ) ;
503
- } else {
504
- docs . push ( hardline ) ;
515
+ fragments . forEach ( ( node , index ) => {
516
+ if ( index !== 0 ) {
517
+ if ( node . startLine - lastLine >= 2 ) {
518
+ docs . push ( hardline , hardline ) ;
519
+ } else {
520
+ docs . push ( delimiter ) ;
521
+ }
505
522
}
506
523
507
524
docs . push ( node . printed ) ;
0 commit comments