Skip to content

Commit

Permalink
[handlebars] Named blocks can't be self closing (#11900)
Browse files Browse the repository at this point in the history
  • Loading branch information
duailibe authored and sosukesuzuki committed Dec 4, 2021
1 parent c0250b3 commit 99649c7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
23 changes: 23 additions & 0 deletions changelog_unreleased/handlebars/11899.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#### Support Glimmer's named blocks (#11899 by @duailibe)

Prettier already supported this feature, but it converted empty named blocks to self-closing, which is not supported by the Glimmer compiler.

See: [Glimmer's named blocks](https://emberjs.github.io/rfcs/0460-yieldable-named-blocks.html).

<!-- prettier-ignore -->
```hbs
// Input
<Component>
<:named></:named>
</Component>
// Prettier stable
<Component>
<:named />
</Component>
// Prettier main
<Component>
<:named></:named>
</Component>
```
1 change: 1 addition & 0 deletions src/language-handlebars/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function isGlimmerComponent(node) {
return (
isNodeOfSomeType(node, ["ElementNode"]) &&
typeof node.tag === "string" &&
node.tag[0] !== ":" &&
(isUppercase(node.tag[0]) || node.tag.includes("."))
);
}
Expand Down
24 changes: 24 additions & 0 deletions tests/format/handlebars/basics/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ printWidth: 80
================================================================================
`;

exports[`named-block.hbs format 1`] = `
====================================options=====================================
parsers: ["glimmer"]
printWidth: 80
| printWidth
=====================================input======================================
<ComponentWithNamedBlocks>
<:first-named-block></:first-named-block>
<:second-named-block> </:second-named-block>
<:named-block-with-comment>{{! Do not convert to an empty element}}</:named-block-with-comment>
<:named-block-with-content>Hello</:named-block-with-content>
</ComponentWithNamedBlocks>
=====================================output=====================================
<ComponentWithNamedBlocks>
<:first-named-block></:first-named-block>
<:second-named-block> </:second-named-block>
<:named-block-with-comment
>{{! Do not convert to an empty element}}</:named-block-with-comment>
<:named-block-with-content>Hello</:named-block-with-content>
</ComponentWithNamedBlocks>
================================================================================
`;

exports[`nested-path.hbs format 1`] = `
====================================options=====================================
parsers: ["glimmer"]
Expand Down
6 changes: 6 additions & 0 deletions tests/format/handlebars/basics/named-block.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ComponentWithNamedBlocks>
<:first-named-block></:first-named-block>
<:second-named-block> </:second-named-block>
<:named-block-with-comment>{{! Do not convert to an empty element}}</:named-block-with-comment>
<:named-block-with-content>Hello</:named-block-with-content>
</ComponentWithNamedBlocks>

0 comments on commit 99649c7

Please sign in to comment.