Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{{else if ...}} is always incorrectly rewritten to use {{#if}} which makes it unusable with {{#animated-if}} #16285

Open
emattias opened this issue May 13, 2024 · 2 comments
Labels
lang:handlebars Issues affecting Handlebars (Glimmer) type:bug Issues identifying ugly output, or a defect in the program

Comments

@emattias
Copy link

emattias commented May 13, 2024

Prettier 3.2.5
Playground link

Input:

{{#animated-if this.foo}}
foo content
{{else if (this.bar)}}
bar content
{{/animated-if}}

Output:

{{#animated-if this.foo}}
  foo content
{{else}}{{#if (this.bar)}}
    bar content
  {{/if}}{{/animated-if}}

Expected output:

{{#animated-if this.foo}}
  foo content
{{else if (this.bar)}}
  bar content
{{/animated-if}}

Why?

There can be other statements with {{else if ...}} than {{#if}}, like {{#animated-if}} and {{#liquid-if}}. They should not change:

{{else if (this.bar)}}
 bar content
{{/animated-if}}

to force it to use {{#if}}:

{{else}}{{#if (this.bar)}}
    bar content
  {{/if}}{{/animated-if}}

Using regular {{#if}} it works correctly:

Input:

{{#if this.foo}}
foo content
{{else if (this.bar)}}
bar content
{{/if}}

Output:

{{#if this.foo}}
  foo content
{{else if (this.bar)}}
  bar content
{{/if}}
@fisker fisker added type:bug Issues identifying ugly output, or a defect in the program lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) labels May 14, 2024
@emattias
Copy link
Author

emattias commented May 16, 2024

@fisker I wasnt clear, this is in handlebars/glimmer templates. See the playgroud link (it uses the glimmer parser)

@fisker fisker added lang:handlebars Issues affecting Handlebars (Glimmer) and removed lang:angular Issues affecting Angular template (not general JS/TS issues used for Angular) labels May 16, 2024
@fisker
Copy link
Member

fisker commented May 16, 2024

Sorry, wrong label. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang:handlebars Issues affecting Handlebars (Glimmer) type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

No branches or pull requests

2 participants