Skip to content

Commit b77d912

Browse files
authored
ember / glimmer: Preserve self-closing tags (#13691)
1 parent cf36209 commit b77d912

File tree

6 files changed

+69
-7
lines changed

6 files changed

+69
-7
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#### Preserve self-closing tags (#13691 by @dcyriller)
2+
3+
<!-- prettier-ignore -->
4+
```hbs
5+
{{! Input }}
6+
<div />
7+
<div></div>
8+
<custom-component />
9+
<custom-component></custom-component>
10+
<i />
11+
<i></i>
12+
<Component />
13+
<Component></Component>
14+
15+
{{! Prettier stable }}
16+
<div></div>
17+
<div></div>
18+
<custom-component></custom-component>
19+
<custom-component></custom-component>
20+
<i></i>
21+
<i></i>
22+
<Component />
23+
<Component />
24+
25+
{{! Prettier main }}
26+
<div />
27+
<div></div>
28+
<custom-component />
29+
<custom-component></custom-component>
30+
<i />
31+
<i></i>
32+
<Component />
33+
<Component />
34+
```

src/language-handlebars/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const voidTags = new Set(htmlVoidElements);
4141
function isVoid(node) {
4242
return (
4343
voidTags.has(node.tag) ||
44+
node.selfClosing === true ||
4445
(isGlimmerComponent(node) &&
4546
node.children.every((node) => isWhitespaceNode(node)))
4647
);

tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap

+18
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ printWidth: 80
4545
4646
<MyComponent @prop={{true}} @prop2={{true}} @prop3={{true}} @prop4={{true}} as |thing|></MyComponent>
4747
48+
<div />
49+
<div></div>
50+
<custom-component />
51+
<custom-component></custom-component>
52+
<i />
53+
<i></i>
54+
<Component />
55+
<Component></Component>
56+
4857
=====================================output=====================================
4958
<div class="attribute" {{modifier}} {{! comment}}>
5059
Hello
@@ -91,5 +100,14 @@ printWidth: 80
91100
@prop4={{true}}
92101
as |thing|
93102
/>
103+
104+
<div />
105+
<div></div>
106+
<custom-component />
107+
<custom-component></custom-component>
108+
<i />
109+
<i></i>
110+
<Component />
111+
<Component />
94112
================================================================================
95113
`;

tests/format/handlebars/element-node/element-node.hbs

+9
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@
3636
<img />
3737

3838
<MyComponent @prop={{true}} @prop2={{true}} @prop3={{true}} @prop4={{true}} as |thing|></MyComponent>
39+
40+
<div />
41+
<div></div>
42+
<custom-component />
43+
<custom-component></custom-component>
44+
<i />
45+
<i></i>
46+
<Component />
47+
<Component></Component>

tests/format/handlebars/html-whitespace-sensitivity/__snapshots__/jsfmt.spec.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ printWidth: 40
702702
=====================================input======================================
703703
<i />   |   <i />
704704
=====================================output=====================================
705-
<i></i>   |   <i></i>
705+
<i />   |   <i />
706706
================================================================================
707707
`;
708708

tests/format/handlebars/single-quote-option/__snapshots__/jsfmt.spec.js.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ singleQuote: false
9999
<div title='My "title"'></div>
100100
<div title="My other 'title'"></div>
101101
102-
<div title="{{t 'my.title'}}"></div>
103-
<div title="{{t 'my.title'}}"></div>
102+
<div title="{{t 'my.title'}}" />
103+
<div title="{{t 'my.title'}}" />
104104
105105
<a href="/{{url}}/{{url}}"></a>
106106
<a href="/{{url}}/{{url}}"></a>
@@ -126,7 +126,7 @@ singleQuote: false
126126
class="padding
127127
{{if foo (if fooAgain 'bar' (if fooAgainAgain 'bar' 'foo'))}}
128128
baz"
129-
></div>
129+
/>
130130
================================================================================
131131
`;
132132

@@ -161,8 +161,8 @@ singleQuote: true
161161
<div title='My "title"'></div>
162162
<div title="My other 'title'"></div>
163163
164-
<div title='{{t "my.title"}}'></div>
165-
<div title='{{t "my.title"}}'></div>
164+
<div title='{{t "my.title"}}' />
165+
<div title='{{t "my.title"}}' />
166166
167167
<a href='/{{url}}/{{url}}'></a>
168168
<a href='/{{url}}/{{url}}'></a>
@@ -188,7 +188,7 @@ singleQuote: true
188188
class='padding
189189
{{if foo (if fooAgain "bar" (if fooAgainAgain "bar" "foo"))}}
190190
baz'
191-
></div>
191+
/>
192192
================================================================================
193193
`;
194194

0 commit comments

Comments
 (0)