From 33fa1b6ae876fc783aa9fcb911ea4f247a0034c9 Mon Sep 17 00:00:00 2001 From: Cyrille David Date: Thu, 20 Oct 2022 14:12:02 +0200 Subject: [PATCH 1/3] Preserve self-closing tags --- src/language-handlebars/utils.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 18 ++++++++++++++++++ .../handlebars/element-node/element-node.hbs | 9 +++++++++ .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 12 ++++++------ 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/language-handlebars/utils.js b/src/language-handlebars/utils.js index 07e4c57544f6..aef7f46f813f 100644 --- a/src/language-handlebars/utils.js +++ b/src/language-handlebars/utils.js @@ -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))) ); diff --git a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap index 7d36706bc63a..bcf0c541817d 100644 --- a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap @@ -45,6 +45,15 @@ printWidth: 80 +
+
+ + + + + + + =====================================output=====================================
Hello @@ -91,5 +100,14 @@ printWidth: 80 @prop4={{true}} as |thing| /> + +
+
+ + + + + + ================================================================================ `; diff --git a/tests/format/handlebars/element-node/element-node.hbs b/tests/format/handlebars/element-node/element-node.hbs index 0c12a8da0aad..4666be172d2a 100644 --- a/tests/format/handlebars/element-node/element-node.hbs +++ b/tests/format/handlebars/element-node/element-node.hbs @@ -36,3 +36,12 @@ + +
+
+ + + + + + diff --git a/tests/format/handlebars/html-whitespace-sensitivity/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/html-whitespace-sensitivity/__snapshots__/jsfmt.spec.js.snap index 33cc64a9404a..73daa2ee6685 100644 --- a/tests/format/handlebars/html-whitespace-sensitivity/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/html-whitespace-sensitivity/__snapshots__/jsfmt.spec.js.snap @@ -702,7 +702,7 @@ printWidth: 40 =====================================input======================================   |   =====================================output===================================== -   |   +   |   ================================================================================ `; diff --git a/tests/format/handlebars/single-quote-option/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/single-quote-option/__snapshots__/jsfmt.spec.js.snap index 4229856d7e11..a26517e85ba6 100644 --- a/tests/format/handlebars/single-quote-option/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/single-quote-option/__snapshots__/jsfmt.spec.js.snap @@ -99,8 +99,8 @@ singleQuote: false
-
-
+
+
@@ -126,7 +126,7 @@ singleQuote: false class="padding {{if foo (if fooAgain 'bar' (if fooAgainAgain 'bar' 'foo'))}} baz" ->
+/> ================================================================================ `; @@ -161,8 +161,8 @@ singleQuote: true
-
-
+
+
@@ -188,7 +188,7 @@ singleQuote: true class='padding {{if foo (if fooAgain "bar" (if fooAgainAgain "bar" "foo"))}} baz' ->
+/> ================================================================================ `; From d630444de49a38f6069bb7deeb06df051171ba37 Mon Sep 17 00:00:00 2001 From: Cyrille David Date: Thu, 20 Oct 2022 13:12:39 +0200 Subject: [PATCH 2/3] Add changelog entry --- changelog_unreleased/handlebars/13691.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 changelog_unreleased/handlebars/13691.md diff --git a/changelog_unreleased/handlebars/13691.md b/changelog_unreleased/handlebars/13691.md new file mode 100644 index 000000000000..36042139feec --- /dev/null +++ b/changelog_unreleased/handlebars/13691.md @@ -0,0 +1,19 @@ +#### Preserve self-closing tags (#13691 by @dcyriller) + + +```hbs +{{! Input }} + +
+ + +{{! Prettier stable }} + +
+ + +{{! Prettier main }} + +
+ +``` From e8544f822fe72b2ba0eb45f640d4176ddd66c848 Mon Sep 17 00:00:00 2001 From: Cyrille David Date: Thu, 20 Oct 2022 14:22:25 +0200 Subject: [PATCH 3/3] Clarify changelog and test --- changelog_unreleased/handlebars/13691.md | 21 ++++++++++++++++--- .../__snapshots__/jsfmt.spec.js.snap | 8 +++---- .../handlebars/element-node/element-node.hbs | 6 +++--- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/changelog_unreleased/handlebars/13691.md b/changelog_unreleased/handlebars/13691.md index 36042139feec..ab836c2d16dc 100644 --- a/changelog_unreleased/handlebars/13691.md +++ b/changelog_unreleased/handlebars/13691.md @@ -3,17 +3,32 @@ ```hbs {{! Input }} -
+
+ + + + + {{! Prettier stable }} -
+
+ + + + + {{! Prettier main }} -
+
+ + + + + ``` diff --git a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap index bcf0c541817d..c1aeb2e785b0 100644 --- a/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/handlebars/element-node/__snapshots__/jsfmt.spec.js.snap @@ -46,11 +46,11 @@ printWidth: 80
-
+
- + - + @@ -104,7 +104,7 @@ printWidth: 80
- + diff --git a/tests/format/handlebars/element-node/element-node.hbs b/tests/format/handlebars/element-node/element-node.hbs index 4666be172d2a..c4ed2d380765 100644 --- a/tests/format/handlebars/element-node/element-node.hbs +++ b/tests/format/handlebars/element-node/element-node.hbs @@ -38,10 +38,10 @@
-
+
- + - +