Skip to content

Commit

Permalink
fix(glimmer): treat glimmer components as self closing tags (#4900)
Browse files Browse the repository at this point in the history
  • Loading branch information
tchak authored and j-f1 committed Jul 27, 2018
1 parent 556fb3e commit 0571b2b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/language-handlebars/printer-glimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ function print(path, options, print) {
);
}
case "ElementNode": {
const isVoid = voidTags.indexOf(n.tag) !== -1;
const closeTag = isVoid ? concat([" />", softline]) : ">";
const tagFirstChar = n.tag[0];
const isLocal = n.tag.indexOf(".") !== -1;
const isGlimmerComponent =
tagFirstChar.toUpperCase() === tagFirstChar || isLocal;
const hasChildren = n.children.length > 0;
const isVoid =
(isGlimmerComponent && !hasChildren) || voidTags.indexOf(n.tag) !== -1;
const closeTag = isVoid ? concat([" />", softline]) : ">";
const getParams = (path, print) =>
indent(
concat([
Expand Down
18 changes: 16 additions & 2 deletions tests/html_glimmer/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,16 @@ exports[`block-statement.hbs - glimmer-verify 1`] = `
`;
exports[`component.hbs - glimmer-verify 1`] = `
<user-greeting @name="Ricardo" @greeting="Olá" />
<UserGreeting @name="Ricardo" @greeting="Olá" />
{{@greeting}}, {{@name}}!
<Form as |f|>
<f.input @title="hello" />
<f.input>hello</f.input>
</Form>
<this.label @title="hello" />
<button onclick={{action next}}>Next</button>
<button disabled class="disabled"></button>
Expand All @@ -146,11 +153,18 @@ exports[`component.hbs - glimmer-verify 1`] = `
<div ...attributes>Hello</div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<user-greeting @name="Ricardo" @greeting="Olá"></user-greeting>
<UserGreeting @name="Ricardo" @greeting="Olá" />
{{@greeting}}
,
{{@name}}
!
<Form as |f|>
<f.input @title="hello" />
<f.input>
hello
</f.input>
</Form>
<this.label @title="hello" />
<button onclick={{action next}}>
Next
</button>
Expand Down
9 changes: 8 additions & 1 deletion tests/html_glimmer/component.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<user-greeting @name="Ricardo" @greeting="Olá" />
<UserGreeting @name="Ricardo" @greeting="Olá" />
{{@greeting}}, {{@name}}!

<Form as |f|>
<f.input @title="hello" />
<f.input>hello</f.input>
</Form>

<this.label @title="hello" />

<button onclick={{action next}}>Next</button>

<button disabled class="disabled"></button>
Expand Down

0 comments on commit 0571b2b

Please sign in to comment.