diff --git a/src/language-handlebars/printer-glimmer.js b/src/language-handlebars/printer-glimmer.js index 9261d0a3fc14..c73186b51683 100644 --- a/src/language-handlebars/printer-glimmer.js +++ b/src/language-handlebars/printer-glimmer.js @@ -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; diff --git a/tests/glimmer/__snapshots__/jsfmt.spec.js.snap b/tests/glimmer/__snapshots__/jsfmt.spec.js.snap index 7580902e4984..70ed53e5bd9a 100644 --- a/tests/glimmer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/glimmer/__snapshots__/jsfmt.spec.js.snap @@ -875,11 +875,17 @@ printWidth: 80 {{#if a}} a +
b
+ c {{else}} {{#if c}} - c + a + b +
c
{{/if}} - e +
a
+ b + c {{/if}} =====================================output===================================== @@ -948,9 +954,23 @@ printWidth: 80 {{/if}} {{#if a}} a -{{else if c}} +
+ b +
+ c +{{else}} + {{#if c}} + a + b +
+ c +
+ {{/if}} +
+ a +
+ b c -e {{/if}} ================================================================================ `; @@ -1034,11 +1054,17 @@ singleQuote: true {{#if a}} a +
b
+ c {{else}} {{#if c}} - c + a + b +
c
{{/if}} - e +
a
+ b + c {{/if}} =====================================output===================================== @@ -1107,9 +1133,23 @@ singleQuote: true {{/if}} {{#if a}} a -{{else if c}} +
+ b +
+ c +{{else}} + {{#if c}} + a + b +
+ c +
+ {{/if}} +
+ a +
+ b c -e {{/if}} ================================================================================ `; diff --git a/tests/glimmer/else-if.hbs b/tests/glimmer/else-if.hbs index e7db7bac77cc..94e1fdf809ca 100644 --- a/tests/glimmer/else-if.hbs +++ b/tests/glimmer/else-if.hbs @@ -70,9 +70,15 @@ {{#if a}} a +
b
+ c {{else}} {{#if c}} - c + a + b +
c
{{/if}} - e +
a
+ b + c {{/if}}