Skip to content

Commit

Permalink
Fix {{else}}{{#if}} into {{else if}} merging
Browse files Browse the repository at this point in the history
  • Loading branch information
dcyriller committed Apr 25, 2019
1 parent 31eecd2 commit 49bf6bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/language-handlebars/printer-glimmer.js
Expand Up @@ -107,12 +107,14 @@ function print(path, options, print) {
pp &&
pp.inverse &&
pp.inverse.body[0] === n &&
pp.inverse.body[0].path.parts[0] === "if";
pp.inverse.body[0].path.parts[0] === "if" &&
pp.inverse.body.length === 1;
const hasElseIf =
n.inverse &&
n.inverse.body[0] &&
n.inverse.body[0].type === "BlockStatement" &&
n.inverse.body[0].path.parts[0] === "if";
n.inverse.body[0].path.parts[0] === "if" &&
n.inverse.body.length === 1;
const indentElse = hasElseIf ? a => a : indent;
if (n.inverse) {
return concat([
Expand Down
16 changes: 10 additions & 6 deletions tests/glimmer/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -948,9 +948,11 @@ printWidth: 80
{{/if}}
{{#if a}}
a
{{else if c}}
c
e
{{else}}
{{#if c}}
c
{{/if}}
e
{{/if}}
================================================================================
`;
Expand Down Expand Up @@ -1107,9 +1109,11 @@ singleQuote: true
{{/if}}
{{#if a}}
a
{{else if c}}
c
e
{{else}}
{{#if c}}
c
{{/if}}
e
{{/if}}
================================================================================
`;
Expand Down

0 comments on commit 49bf6bd

Please sign in to comment.