Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[handlebars] Named blocks can't be self closing #11900

Merged
merged 4 commits into from Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
duailibe marked this conversation as resolved.
Show resolved Hide resolved
// Input
<Component>
<:named></:named>
</Component>

// Prettier stable
<Component>
<:named />
</Component>

// Prettier main
<Component>
<:named></:named>
</Component>
```
2 changes: 1 addition & 1 deletion src/language-handlebars/utils.js
Expand Up @@ -25,7 +25,7 @@ function isLastNodeOfSiblings(path) {
}

function isUppercase(string) {
return string.toUpperCase() === string;
return /^[A-Z]+$/.test(string);
duailibe marked this conversation as resolved.
Show resolved Hide resolved
}

function isGlimmerComponent(node) {
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>