aboutsummaryrefslogtreecommitdiff
path: root/formatter
diff options
context:
space:
mode:
authorjturtle <jturtl@pm.me> 2023-09-30 22:13:14 +0000
committerThomas Voss <mail@thomasvoss.com> 2023-10-02 00:14:21 +0200
commit56f9526181c725edc0a1ede50fc86443d080c7a5 (patch)
tree4a454492d8b0e31474bb67c3a191403f5cdd49d5 /formatter
parent1da33201a9a022673bad5fbff2d4636049240808 (diff)
Fix class/attribute mixup bug
There's a bug in the current version of GSP where an element like this: p .class attribute="value" {-} would be transpiled as this: <p class="value" attribute="value"></p> The `classes` slice in `func printAttrs` (`formatter.go`, line 50) was the cause. I fixed it by making a deep copy of the `attrs` slice. I'm not a Go programmer, there might be a nicer way to make a deep copy of a slice. But it does, indeed, work. P.S. thanks for making this, writing HTML by hand is now slightly less painful!
Diffstat (limited to 'formatter')
-rw-r--r--formatter/formatter.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/formatter/formatter.go b/formatter/formatter.go
index 6249c0a..7ac41a6 100644
--- a/formatter/formatter.go
+++ b/formatter/formatter.go
@@ -48,14 +48,17 @@ func PrintAst(ast parser.AstNode) {
}
func printAttrs(attrs []parser.Attr) {
- classes := attrs
+ classes := make([]parser.Attr, len(attrs), cap(attrs))
+ copy(classes, attrs)
classes = slices.DeleteFunc(classes, func(a parser.Attr) bool {
return a.Key != "class"
})
+
attrs = slices.DeleteFunc(attrs, func(a parser.Attr) bool {
return a.Key == "class"
})
+
if len(classes) > 0 {
fmt.Print(" class=\"")
for i, a := range classes {