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

fix: don't error if no open brace is found on control flow expressions #143

Closed
wants to merge 0 commits into from

Conversation

joerdav
Copy link
Collaborator

@joerdav joerdav commented Sep 7, 2023

fixes #141

@joerdav
Copy link
Collaborator Author

joerdav commented Sep 7, 2023

@a-h Is this how you would expect this to have been fixed?

@a-h
Copy link
Owner

a-h commented Sep 8, 2023

Very close. I was thinking about attempting to search for a greater number of symbols before templ complains about a malformed for or if

For example. The for statement must be constructed in a number of ways.

package main

import "fmt"

func main() {
	var x int
	for ; x < 10; x++ {
		print(x)
	}
	fmt.Println()
	for y := 0; y < 10; y++ {
		print(y)
	}
	for {
		break
	}
	fmt.Println()
	var y int
	for y = 0; y < 10; y++ {
		print(y)
	}
}

https://go.dev/play/p/RjaP5Hj5HkV

I was thinking of still complaining about the for statement not being closed if there's a semicolon in the line. However, that would simply reduce the times that the spurious error occurs.

My concern was developers accidentally turning a malformed for loop into printing for x := 0; x < checkSomething(); x ++ to the HTML.

So I was thinking about ways to reduce the number of spurious errors while providing some protection against forgetting to close a for loop start expression.

@joerdav
Copy link
Collaborator Author

joerdav commented Sep 8, 2023

Makes sense. It's finding that line between errors that stop someone from writing certain things in an element and allowing broken for loops to be written.

I guess where it gets harder is if and switch statements, they are unlikely to contain any discerning character between the keyword and the open-brace.

@joerdav joerdav closed this Oct 4, 2023
@joerdav joerdav force-pushed the incomplete-control-flow branch from 6ca43dc to fa4795b Compare October 4, 2023 09:41
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.

Bug: <div>: expected end tag not present or invalid tag contents
2 participants