Skip to content

Commit

Permalink
ember / glimmer: Preserve self-closing tags (#13691)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcyriller authored Jan 4, 2023
1 parent cf36209 commit b77d912
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 7 deletions.
34 changes: 34 additions & 0 deletions changelog_unreleased/handlebars/13691.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#### Preserve self-closing tags (#13691 by @dcyriller)

<!-- prettier-ignore -->
```hbs
{{! Input }}
<div />
<div></div>
<custom-component />
<custom-component></custom-component>
<i />
<i></i>
<Component />
<Component></Component>
{{! Prettier stable }}
<div></div>
<div></div>
<custom-component></custom-component>
<custom-component></custom-component>
<i></i>
<i></i>
<Component />
<Component />
{{! Prettier main }}
<div />
<div></div>
<custom-component />
<custom-component></custom-component>
<i />
<i></i>
<Component />
<Component />
```
1 change: 1 addition & 0 deletions src/language-handlebars/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const voidTags = new Set(htmlVoidElements);
function isVoid(node) {
return (
voidTags.has(node.tag) ||
node.selfClosing === true ||
(isGlimmerComponent(node) &&
node.children.every((node) => isWhitespaceNode(node)))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ printWidth: 80
<MyComponent @prop={{true}} @prop2={{true}} @prop3={{true}} @prop4={{true}} as |thing|></MyComponent>
<div />
<div></div>
<custom-component />
<custom-component></custom-component>
<i />
<i></i>
<Component />
<Component></Component>
=====================================output=====================================
<div class="attribute" {{modifier}} {{! comment}}>
Hello
Expand Down Expand Up @@ -91,5 +100,14 @@ printWidth: 80
@prop4={{true}}
as |thing|
/>
<div />
<div></div>
<custom-component />
<custom-component></custom-component>
<i />
<i></i>
<Component />
<Component />
================================================================================
`;
9 changes: 9 additions & 0 deletions tests/format/handlebars/element-node/element-node.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@
<img />

<MyComponent @prop={{true}} @prop2={{true}} @prop3={{true}} @prop4={{true}} as |thing|></MyComponent>

<div />
<div></div>
<custom-component />
<custom-component></custom-component>
<i />
<i></i>
<Component />
<Component></Component>
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ printWidth: 40
=====================================input======================================
<i />   |   <i />
=====================================output=====================================
<i></i>   |   <i></i>
<i />   |   <i />
================================================================================
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ singleQuote: false
<div title='My "title"'></div>
<div title="My other 'title'"></div>
<div title="{{t 'my.title'}}"></div>
<div title="{{t 'my.title'}}"></div>
<div title="{{t 'my.title'}}" />
<div title="{{t 'my.title'}}" />
<a href="/{{url}}/{{url}}"></a>
<a href="/{{url}}/{{url}}"></a>
Expand All @@ -126,7 +126,7 @@ singleQuote: false
class="padding
{{if foo (if fooAgain 'bar' (if fooAgainAgain 'bar' 'foo'))}}
baz"
></div>
/>
================================================================================
`;

Expand Down Expand Up @@ -161,8 +161,8 @@ singleQuote: true
<div title='My "title"'></div>
<div title="My other 'title'"></div>
<div title='{{t "my.title"}}'></div>
<div title='{{t "my.title"}}'></div>
<div title='{{t "my.title"}}' />
<div title='{{t "my.title"}}' />
<a href='/{{url}}/{{url}}'></a>
<a href='/{{url}}/{{url}}'></a>
Expand All @@ -188,7 +188,7 @@ singleQuote: true
class='padding
{{if foo (if fooAgain "bar" (if fooAgainAgain "bar" "foo"))}}
baz'
></div>
/>
================================================================================
`;

Expand Down

0 comments on commit b77d912

Please sign in to comment.