Skip to content

If branch containing only a comment causes a parsing error #1182

@SteveRuble

Description

@SteveRuble

Describe the bug
An if branch containing only a comment causes a parsing error.

To Reproduce

if len(children) > 0 {
	<li>
	@subNav(children)
	</li>
} else if ! navigator.Data.IsSection {
	// don't render a link for empty sections
} else {
	<li>
		@docLoadingLink(vm, navigator, isActive, breadcrumb)
	</li>
}

This parses in v0.3.865, but in v0.3.887 this yields parsing error: string expression: missing close brace. The problem may have started earlier.

Expected behavior
It should parse correctly.

templ info output
(✓) os [ goos=darwin goarch=arm64 ]
(✓) go [ location=/Users/steve.ruble/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.3.darwin-arm64/bin/go version=go version go1.24.3 darwin/arm64 ]
(✓) gopls [ location=/Users/steve.ruble/go/bin/gopls version=golang.org/x/tools/gopls v0.18.1 ]
(✓) templ [ location=/Users/steve.ruble/go/bin/templ version=v0.3.894 ]

Additional context
This is not a big problem and can be worked around by using a blank switch { instead (which is arguably more idiomatic and clearer). But it's surprising to have a weird parsing error when dependabot upgrades templ so I thought it was worth reporting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions