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 6df3a03
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 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
56 changes: 48 additions & 8 deletions tests/glimmer/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -875,11 +875,17 @@ printWidth: 80
{{#if a}}
a
<div>b</div>
c
{{else}}
{{#if c}}
c
a
b
<div>c</div>
{{/if}}
e
<div>a</div>
b
c
{{/if}}
=====================================output=====================================
Expand Down Expand Up @@ -948,9 +954,23 @@ printWidth: 80
{{/if}}
{{#if a}}
a
{{else if c}}
<div>
b
</div>
c
{{else}}
{{#if c}}
a
b
<div>
c
</div>
{{/if}}
<div>
a
</div>
b
c
e
{{/if}}
================================================================================
`;
Expand Down Expand Up @@ -1034,11 +1054,17 @@ singleQuote: true
{{#if a}}
a
<div>b</div>
c
{{else}}
{{#if c}}
c
a
b
<div>c</div>
{{/if}}
e
<div>a</div>
b
c
{{/if}}
=====================================output=====================================
Expand Down Expand Up @@ -1107,9 +1133,23 @@ singleQuote: true
{{/if}}
{{#if a}}
a
{{else if c}}
<div>
b
</div>
c
{{else}}
{{#if c}}
a
b
<div>
c
</div>
{{/if}}
<div>
a
</div>
b
c
e
{{/if}}
================================================================================
`;
Expand Down
10 changes: 8 additions & 2 deletions tests/glimmer/else-if.hbs
Expand Up @@ -70,9 +70,15 @@

{{#if a}}
a
<div>b</div>
c
{{else}}
{{#if c}}
c
a
b
<div>c</div>
{{/if}}
e
<div>a</div>
b
c
{{/if}}

0 comments on commit 6df3a03

Please sign in to comment.