feat: support else-if chaining for block helpers - #648
Merged
Conversation
Generalize the existing {{#if}}/{{else if}} chaining so that any block
helper can be followed by "{{else helperName arg1 arg2 hash=val}}",
which desugars to nesting {{#helperName ...}}...{{/helperName}} inside
the outer else clause - except the nested block shares the outer
block's closing tag instead of requiring its own, and can itself be
followed by further else/else-X clauses.
BlockAccumulatorContext gains a ResolvedClosingName (with an override
hook) so a synthesized nested context can be closed by the outer
block's literal closing tag, and BlockAccumulator recognizes
"{{else name ...}}" and recurses into a nested context for it. The
existing if/unless else-if fast path opts out via
HandlesChainedElseInternally and is otherwise untouched.
rexm
enabled auto-merge
August 5, 2026 04:13
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
{{else name args}}chaining on block helpers, e.g.{{#if a}}...{{else if b}}...{{else}}...{{/if}}, generalized to any block helper (not justif):{{#StringEqualityBlockHelper @value 'dog'}}...{{else StringEqualityBlockHelper @value 'cat'}}...{{else}}...{{/StringEqualityBlockHelper}}.{{else name args}}...{{/outer}}desugars to a synthetic nested{{#name args}}...{{/name}}block that's closed by the outer block's closing tag rather than requiring its own — and chains recursively to any depth.{{#if}}/{{else if}}flattening logic is untouched (it already handled this case internally); the new path only kicks in for other block helper types, and composes withif's own handling when mixed.Test plan
IssueTests.cs/ReadmeTests.cs: else-if forif, custom block helper in else-X position, 3-level chaining, mixedelse ifunder a non-conditional block helper, multi-clause else-if-else-if-else, and a plain-{{else}}regression checkFixes #263
🤖 Generated with Claude Code