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 9a3ee3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/language-handlebars/printer-glimmer.js
Expand Up @@ -106,11 +106,12 @@ function print(path, options, print) {
const isElseIf =
pp &&
pp.inverse &&
pp.inverse.body.length === 1 &&
pp.inverse.body[0] === n &&
pp.inverse.body[0].path.parts[0] === "if";
const hasElseIf =
n.inverse &&
n.inverse.body[0] &&
n.inverse.body.length === 1 &&
n.inverse.body[0].type === "BlockStatement" &&
n.inverse.body[0].path.parts[0] === "if";
const indentElse = hasElseIf ? a => a : indent;
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 9a3ee3d

Please sign in to comment.