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: consistent whitespace around go keywords #371

Merged
merged 2 commits into from
Jan 25, 2024

Conversation

JonnyLoughlin
Copy link
Contributor

This PR is an attempted fix for #354. The issue seemed to be caused by the recursive nature of writeNodes. When calling writeNodes() from writeIfExpression(), writeForExpression(), and writeSwitchExpression(), the last iteration of the loop in writeNodes() wouldn't correctly know the next node in the node list.

For example:

templ page(doIf bool) {
	<button>Left</button>
	if doIf {
		<button>Middle</button>
	}
	<button>Right</button>
}

would produce a node list of [element]->[if expression]->[element] with [if expression] having a node list of [element]. On the final iteration of the loop in writeNodes() when writing the node list of [if expression], the next element would be nil instead of the next [element] node. This was messing with the isInlineOrText() function as passing it a nil node will return false so they expected whitespace isn't added.

I have fixed the issue by having writeNodes() also take in a next parser.Node so when the function is called recursively from writeIfExpression(), writeForExpression(), and writeSwitchExpression(), the next node in the node list can be passed in and used when relevant. If the function isn't being called recursively, we can still pass in nil as the next node and then writeNodes() will work as it did previously. If we pass in a non nil next to writeNodes(), it will be used as the next value when nextNode is nil ie. on the last iteration of the loop.

I've also added a few test for whitespace in if, switch and for expressions.

If there is anything that looks incorrect in this or if there is anything you'd like me to change, please let me know.

@a-h a-h merged commit 1c12a3e into a-h:main Jan 25, 2024
3 of 4 checks passed
@JonnyLoughlin JonnyLoughlin deleted the inconsistent-spacing branch January 26, 2024 02:56
@JonnyLoughlin JonnyLoughlin restored the inconsistent-spacing branch January 26, 2024 03:01
@JonnyLoughlin JonnyLoughlin deleted the inconsistent-spacing branch July 2, 2024 15:56
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.

2 participants