From ce60ab6f65b450877d324aa3d1db1106e1ca5bfd Mon Sep 17 00:00:00 2001 From: Daniel Oliveira Date: Mon, 16 Nov 2026 16:11:03 +0100 Subject: [PATCH] Drop a trailing open tag from the end token in the formatter The end token holds what follows the last statement. After a closing tag that the formatter makes a semicolon, an open tag there, '?>\n\n 0 { + if _, html := node.Stmts[len(node.Stmts)-1].(*ast.StmtInlineHtml); html { + return + } + } + var kept []*token.Token + for _, t := range node.EndTkn.FreeFloating { + if t.ID != token.T_OPEN_TAG { + kept = append(kept, t) + } + } + node.EndTkn.FreeFloating = kept } func (formatter *formatter) Nullable(node *ast.Nullable) { diff --git a/pkg/visitor/formatter/formatter_test.go b/pkg/visitor/formatter/formatter_test.go index 6e501bb..d878fbf 100644 --- a/pkg/visitor/formatter/formatter_test.go +++ b/pkg/visitor/formatter/formatter_test.go @@ -35,6 +35,37 @@ func TestFormatter_Root(test *testing.T) { } } +func TestFormatter_Root_TrailingOpenTag(test *testing.T) { + buffer := bytes.NewBufferString("") + + node := &ast.Root{ + Stmts: []ast.Vertex{ + &ast.StmtNop{}, + }, + EndTkn: &token.Token{ + FreeFloating: []*token.Token{ + {ID: token.T_OPEN_TAG, Value: []byte("