From 56f9526181c725edc0a1ede50fc86443d080c7a5 Mon Sep 17 00:00:00 2001 From: jturtle Date: Sat, 30 Sep 2023 22:13:14 +0000 Subject: 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:

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! --- formatter/formatter.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 { -- cgit v1.2.3