Skip to content

Commit 99649c7

Browse files
duailibesosukesuzuki
authored andcommitted
[handlebars] Named blocks can't be self closing (#11900)
1 parent c0250b3 commit 99649c7

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#### Support Glimmer's named blocks (#11899 by @duailibe)
2+
3+
Prettier already supported this feature, but it converted empty named blocks to self-closing, which is not supported by the Glimmer compiler.
4+
5+
See: [Glimmer's named blocks](https://emberjs.github.io/rfcs/0460-yieldable-named-blocks.html).
6+
7+
<!-- prettier-ignore -->
8+
```hbs
9+
// Input
10+
<Component>
11+
<:named></:named>
12+
</Component>
13+
14+
// Prettier stable
15+
<Component>
16+
<:named />
17+
</Component>
18+
19+
// Prettier main
20+
<Component>
21+
<:named></:named>
22+
</Component>
23+
```

src/language-handlebars/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function isGlimmerComponent(node) {
3232
return (
3333
isNodeOfSomeType(node, ["ElementNode"]) &&
3434
typeof node.tag === "string" &&
35+
node.tag[0] !== ":" &&
3536
(isUppercase(node.tag[0]) || node.tag.includes("."))
3637
);
3738
}

tests/format/handlebars/basics/__snapshots__/jsfmt.spec.js.snap

+24
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,30 @@ printWidth: 80
9393
================================================================================
9494
`;
9595

96+
exports[`named-block.hbs format 1`] = `
97+
====================================options=====================================
98+
parsers: ["glimmer"]
99+
printWidth: 80
100+
| printWidth
101+
=====================================input======================================
102+
<ComponentWithNamedBlocks>
103+
<:first-named-block></:first-named-block>
104+
<:second-named-block> </:second-named-block>
105+
<:named-block-with-comment>{{! Do not convert to an empty element}}</:named-block-with-comment>
106+
<:named-block-with-content>Hello</:named-block-with-content>
107+
</ComponentWithNamedBlocks>
108+
109+
=====================================output=====================================
110+
<ComponentWithNamedBlocks>
111+
<:first-named-block></:first-named-block>
112+
<:second-named-block> </:second-named-block>
113+
<:named-block-with-comment
114+
>{{! Do not convert to an empty element}}</:named-block-with-comment>
115+
<:named-block-with-content>Hello</:named-block-with-content>
116+
</ComponentWithNamedBlocks>
117+
================================================================================
118+
`;
119+
96120
exports[`nested-path.hbs format 1`] = `
97121
====================================options=====================================
98122
parsers: ["glimmer"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<ComponentWithNamedBlocks>
2+
<:first-named-block></:first-named-block>
3+
<:second-named-block> </:second-named-block>
4+
<:named-block-with-comment>{{! Do not convert to an empty element}}</:named-block-with-comment>
5+
<:named-block-with-content>Hello</:named-block-with-content>
6+
</ComponentWithNamedBlocks>

0 commit comments

Comments
 (0)