fix(events): keep every line of a doc comment inside a comment

genevents prefixed only the *first* line of a const block's doc
comment with `//`, so a comment that ran to a second paragraph emitted
bare prose into the TypeScript object literal — a generated file that
does not parse.

Nothing had noticed because nobody had run the generator since the
comments were written, and `make generate` is a pre-commit hook: the
failure was waiting for whoever next touched a .sql, a .templ or an
event constant. A generator is only verified by running it.
This commit is contained in:
2026-08-12 01:17:41 -04:00
parent da564f9659
commit fcf2fe509e
+28 -2
View File
@@ -120,6 +120,28 @@ func cleanComment(s string) string {
return s
}
// commentLines renders a doc comment as indented TypeScript line
// comments, one per source line.
func commentLines(comment string) []string {
if comment == "" {
return nil
}
var out []string
for _, line := range strings.Split(comment, "\n") {
if line == "" {
out = append(out, " //")
continue
}
out = append(out, " // "+line)
}
return out
}
// generateTypeScript produces the full TypeScript source from the parsed
// constant groups.
func generateTypeScript(groups []constGroup) string {
@@ -130,8 +152,12 @@ func generateTypeScript(groups []constGroup) string {
b.WriteString("export const Events = {\n")
for i, g := range groups {
if g.Comment != "" {
b.WriteString(" // " + g.Comment + "\n")
// Every line, not just the first: a doc comment that runs to a
// second paragraph used to emit its remainder as bare prose
// inside the object literal, so `make generate` — a pre-commit
// hook — produced TypeScript that does not parse.
for _, line := range commentLines(g.Comment) {
b.WriteString(line + "\n")
}
for _, c := range g.Consts {