Skip to content

Commit

Permalink
fix(glimmer): better formatting of boolean attributes (and also ...at…
Browse files Browse the repository at this point in the history
…tributes) (#4891)
  • Loading branch information
tchak authored and duailibe committed Jul 26, 2018
1 parent 505e082 commit 65d65a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/language-handlebars/printer-glimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ function print(path, options, print) {
);
}
case "AttrNode": {
const quote = n.value.type === "TextNode" ? '"' : "";
const isText = n.value.type === "TextNode";
if (isText && n.value.chars === "") {
return concat([n.name]);
}
const quote = isText ? '"' : "";
return concat([n.name, "=", quote, path.call(print, "value"), quote]);
}
case "ConcatStatement": {
Expand Down
11 changes: 11 additions & 0 deletions tests/html_glimmer/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ exports[`component.hbs - glimmer-verify 1`] = `
{{@greeting}}, {{@name}}!
<button onclick={{action next}}>Next</button>
<button disabled class="disabled"></button>
<button disabled=disabled class="disabled"></button>
<div ...attributes>Hello</div>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<user-greeting @name="Ricardo" @greeting="Olá"></user-greeting>
{{@greeting}}
Expand All @@ -148,6 +154,11 @@ exports[`component.hbs - glimmer-verify 1`] = `
<button onclick={{action next}}>
Next
</button>
<button disabled class="disabled"></button>
<button disabled="disabled" class="disabled"></button>
<div ...attributes>
Hello
</div>
`;
exports[`concat-statement.hbs - glimmer-verify 1`] = `
Expand Down
6 changes: 6 additions & 0 deletions tests/html_glimmer/component.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
{{@greeting}}, {{@name}}!

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

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

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

<div ...attributes>Hello</div>

0 comments on commit 65d65a5

Please sign in to comment.