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

Whitespace control in one {{else if}} branch also affects a different branch #2031

Open
andersk opened this issue Mar 27, 2024 · 0 comments
Open

Comments

@andersk
Copy link

andersk commented Mar 27, 2024

In this test case, I’ve used whitespace control on just one side of just one {{else if}} branch:

const Handlebars = require("handlebars");
const source = `\
{{#if a}}
a
{{else if b}}
b
{{else if c}}
c
{{~else if d}}
d
{{else if e}}
e
{{else if f}}
f
{{else if g}}
g
{{/if}}
`;
const template = Handlebars.compile(source);
console.log(JSON.stringify(template({a: 1})));
console.log(JSON.stringify(template({b: 1})));
console.log(JSON.stringify(template({c: 1})));
console.log(JSON.stringify(template({d: 1})));
console.log(JSON.stringify(template({e: 1})));
console.log(JSON.stringify(template({f: 1})));
console.log(JSON.stringify(template({g: 1})));

But two of the outputs are affected:

"a\n"
"b\n"
"c"
"d\n"
"e"
"f\n"
"g\n"

I expect the whitespace control to only affect "c", so "e" should be "e\n".

Using Handlebars 4.7.8 on Node.js 20.11.1.

Playground link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants