fix(issue-3982): Glimmer printer now properly handles else-if blocks without else block … (#4256)
* fix(glimmer): Now properly handles else-if blocks without else block and block statements as root of else. * run prettier on printer-glimmer.jsmaster
parent
0c1d62079e
commit
28e4b07b17
|
@ -96,11 +96,16 @@ function print(path, options, print) {
|
||||||
}
|
}
|
||||||
case "BlockStatement": {
|
case "BlockStatement": {
|
||||||
const pp = path.getParentNode(1);
|
const pp = path.getParentNode(1);
|
||||||
const isElseIf = pp && pp.inverse && pp.inverse.body[0] === n;
|
const isElseIf =
|
||||||
|
pp &&
|
||||||
|
pp.inverse &&
|
||||||
|
pp.inverse.body[0] === n &&
|
||||||
|
pp.inverse.body[0].path.parts[0] === "if";
|
||||||
const hasElseIf =
|
const hasElseIf =
|
||||||
n.inverse &&
|
n.inverse &&
|
||||||
n.inverse.body[0] &&
|
n.inverse.body[0] &&
|
||||||
n.inverse.body[0].type === "BlockStatement";
|
n.inverse.body[0].type === "BlockStatement" &&
|
||||||
|
n.inverse.body[0].path.parts[0] === "if";
|
||||||
const indentElse = hasElseIf ? a => a : indent;
|
const indentElse = hasElseIf ? a => a : indent;
|
||||||
if (n.inverse) {
|
if (n.inverse) {
|
||||||
return concat([
|
return concat([
|
||||||
|
@ -114,6 +119,11 @@ function print(path, options, print) {
|
||||||
: "",
|
: "",
|
||||||
isElseIf ? "" : concat([hardline, printCloseBlock(path, print)])
|
isElseIf ? "" : concat([hardline, printCloseBlock(path, print)])
|
||||||
]);
|
]);
|
||||||
|
} else if (isElseIf) {
|
||||||
|
return concat([
|
||||||
|
concat(["{{else ", printPathParams(path, print), "}}"]),
|
||||||
|
indent(concat([hardline, path.call(print, "program")]))
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* I want this boolean to be: if params are going to cause a break,
|
* I want this boolean to be: if params are going to cause a break,
|
||||||
|
|
|
@ -321,7 +321,22 @@ exports[`else-if.hbs 1`] = `
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
{{#if a}}
|
||||||
|
b
|
||||||
|
{{else}}
|
||||||
|
{{#each c as |d|}}
|
||||||
|
e
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if a}}
|
||||||
|
{{#if b}}
|
||||||
|
ab
|
||||||
|
{{else if c}}
|
||||||
|
ac
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
{{#if a}}
|
{{#if a}}
|
||||||
b
|
b
|
||||||
{{else if c}}
|
{{else if c}}
|
||||||
|
@ -371,6 +386,20 @@ exports[`else-if.hbs 1`] = `
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{#if a}}
|
||||||
|
b
|
||||||
|
{{else}}
|
||||||
|
{{#each c as |d|}}
|
||||||
|
e
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
{{#if a}}
|
||||||
|
{{#if b}}
|
||||||
|
ab
|
||||||
|
{{else if c}}
|
||||||
|
ac
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`literals.hbs 1`] = `
|
exports[`literals.hbs 1`] = `
|
||||||
|
|
|
@ -51,3 +51,19 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{#if a}}
|
||||||
|
b
|
||||||
|
{{else}}
|
||||||
|
{{#each c as |d|}}
|
||||||
|
e
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if a}}
|
||||||
|
{{#if b}}
|
||||||
|
ab
|
||||||
|
{{else if c}}
|
||||||
|
ac
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
Loading…
Reference in New Issue