Fix whitespace handling for chained {{else if}} blocks#31
Fix whitespace handling for chained {{else if}} blocks#31NullVoxPopuli merged 2 commits intohandlebars-lang:masterfrom
{{else if}} blocks#31Conversation
77ba12d to
6eeb04f
Compare
|
can tests not be added in this repo? |
|
Only AST-level tests can be added here, not tests of the expected rendering. |
|
sounds valid tho |
|
@NullVoxPopuli What sounds valid? |
|
adding an AST-level test 🎉 just to have something to validate against and prevent regression |
When a block with chained {{else if}} branches was on its own line,
omitLeft only stripped the trailing indent from the first branch's
body. Walk the full inverse chain so every execution path loses the
close-tag indent.
Resolves handlebars-lang/handlebars.js#1716
prepareBlock propagated the closeStrip of a chained inverseAndProgram
one level at a time, so a tilde on {{~else if}} leaked into the
closeStrip of the next block in the chain, causing unintended
whitespace stripping in unrelated branches.
When close is the actual closing tag (not another chain node), walk
the full chain and set closeStrip to the real closing tag's strip on
every block, rather than letting each intermediate chain step
overwrite it with the wrong strip.
Resolves handlebars-lang/handlebars.js#2031
6eeb04f to
8aa3b5b
Compare
|
@NullVoxPopuli I added AST tests now to validate both fixes. |
|
@NullVoxPopuli Sorry for hijacking the conversation, but I noticed that you added this parser to ember.js: emberjs/ember.js@181d95d Which repository will be the main one, or do you maintain both independently? |
|
so this repo is still for handlebars, but the PR you found for ember is exclusively for ember, and ember will not use the handlebars-parser repo anymore -- so if you're using ember, you may want to PR there, if handlebars proper, here is still a good location |
|
Does anything prevent this from being merged? |
|
Do the tests def fail without the fix? <3 |
|
Yes, I confirmed both the AST tests as well as the proposed Handlebars.js tests in the description fail without this patch. |
Two related bugs affecting templates that use chained
{{else if}}branches:1. Standalone close-tag indent not stripped from all chained else-if branches
When a block with
{{else if}}branches was written on its own line (standalone),omitLeftonly stripped the trailing indent from the first branch's body. Every other execution path kept an extra indent before the closing tag's content. TheProgramhandler now walks the full inverse chain so all branches are treated consistently. Resolves handlebars-lang/handlebars.js#1716This is also an issue I ran into when developing PHP Handlebars Parser, which implements the same whitespace control logic.
2. Tilde whitespace control in one branch affecting another
prepareBlockpropagatedcloseStripone chain level at a time during grammar reduction, so a tilde on{{~else if}}leaked into thecloseStripof the next block in the chain, causing unintended whitespace stripping in unrelated branches. The fix walks the full chain in the single outerprepareBlockcall (wherecloseis the actual closing tag) and stamps the correctcloseStriponto every block, rather than letting each intermediate reduction overwrite it with the wrong strip. Resolves handlebars-lang/handlebars.js#2031Once this is merged I can open a separate pull request against handlebars.js adding the following test cases to
spec/whitespace-control.js(which I've already confirmed pass with this branch):