Skip to content

Commit

Permalink
[handlebars] Named blocks can't be self closing
Browse files Browse the repository at this point in the history
  • Loading branch information
duailibe committed Dec 1, 2021
1 parent d095459 commit 0f31453
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
@@ -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 -->
```jsx
// 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
Expand Up @@ -25,6 +25,7 @@ function isLastNodeOfSiblings(path) {
}

function isUppercase(string) {
return /^[A-Z]+$/.test(string);
return string.toUpperCase() === string;
}

Expand Down
24 changes: 24 additions & 0 deletions tests/format/handlebars/basics/__snapshots__/jsfmt.spec.js.snap
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
@@ -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 0f31453

Please sign in to comment.