@@ -2,6 +2,7 @@ import { doc } from "prettier";
2
2
import {
3
3
removeSurroundingWhitespace ,
4
4
isInlineElement ,
5
+ isOwnlineElement ,
5
6
printChildGroups ,
6
7
EXPRESSION_NEEDED ,
7
8
STRING_NEEDS_QUOTES
@@ -52,32 +53,34 @@ const p = (node, path, print, options) => {
52
53
node [ EXPRESSION_NEEDED ] = false ;
53
54
node [ STRING_NEEDS_QUOTES ] = false ;
54
55
55
- if ( ! node . selfClosing ) {
56
- node . children = removeSurroundingWhitespace ( node . children ) ;
56
+ if ( node . selfClosing ) {
57
+ return openingGroup ;
58
+ }
57
59
58
- const childGroups = printChildGroups ( node , path , print , "children" ) ;
59
- const closingTag = [ "</" , node . name , ">" ] ;
60
- const result = [ openingGroup ] ;
61
- const joinedChildren = childGroups ;
62
- if ( isInlineElement ( node ) ) {
63
- result . push ( indent ( [ softline , joinedChildren ] ) , softline ) ;
64
- } else {
65
- const childBlock = [ ] ;
66
- if ( childGroups . length > 0 ) {
67
- childBlock . push ( hardline ) ;
68
- }
69
- childBlock . push ( joinedChildren ) ;
70
- result . push ( indent ( childBlock ) ) ;
71
- if ( childGroups . length > 0 ) {
72
- result . push ( hardline ) ;
73
- }
74
- }
75
- result . push ( closingTag ) ;
60
+ const groupElement = Symbol ( "element" ) ;
61
+ node . children = removeSurroundingWhitespace ( node . children ) ;
76
62
77
- return isInlineElement ( node ) ? group ( result ) : result ;
63
+ const childGroups = printChildGroups ( node , path , print , "children" ) ;
64
+ const closingTag = [ "</" , node . name , ">" ] ;
65
+ const result = [ openingGroup ] ;
66
+ const joinedChildren = childGroups ;
67
+ if ( isOwnlineElement ( node ) || isInlineElement ( node ) ) {
68
+ const element = [ indent ( [ softline , joinedChildren ] ) , softline ] ;
69
+ result . push ( element ) ;
70
+ } else {
71
+ const childBlock = [ ] ;
72
+ if ( childGroups . length > 0 ) {
73
+ childBlock . push ( hardline ) ;
74
+ }
75
+ childBlock . push ( joinedChildren ) ;
76
+ result . push ( indent ( childBlock ) ) ;
77
+ if ( childGroups . length > 0 ) {
78
+ result . push ( hardline ) ;
79
+ }
78
80
}
81
+ result . push ( closingTag ) ;
79
82
80
- return openingGroup ;
83
+ return group ( result , { id : groupElement } ) ;
81
84
} ;
82
85
83
86
export { p as printElement } ;
0 commit comments