Skip to content

Add support for "fallthrough" in case statements#1289

Merged
a-h merged 3 commits intoa-h:mainfrom
whalenrp:main
Dec 31, 2025
Merged

Add support for "fallthrough" in case statements#1289
a-h merged 3 commits intoa-h:mainfrom
whalenrp:main

Conversation

@whalenrp
Copy link
Copy Markdown
Contributor

@whalenrp whalenrp commented Oct 28, 2025

Resolves: #920

I used the sample input to test against, and added a few validations that I also tested locally to ensure they worked.


templ example(x int) {
	switch x {
        case 0:
            fallthrough
        case 1:
            <p>hey</p>
    }
}

@example(0) now properly prints <p>hey</p>

The following things were included as well

  • Validation that fallthrough doesn't appear as any other statement than the last one in a case statement
  • Validation that fallthrough isn't used on the final case statement
  • Validation that fallthrough isn't follow by anything other than a newline.

This is my first contribution to the project though, so please comment away if anything can be improved!

To address a-h#920 we need
a new node that can consume the fallthrough keyword in templ switch
statements. This adds the node, and followup diffs will add it into the
parser
This also adds validation that fallthrough is only used at the end of
each case statement, and validation that fallthrough isn't used on the
final case statement
@a-h a-h merged commit 0d69ba4 into a-h:main Dec 31, 2025
5 checks passed
@a-h
Copy link
Copy Markdown
Owner

a-h commented Dec 31, 2025

Thanks a lot for your contribution!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch fallthrough not supported

2 participants