From 7c19135a0e348513ff904f347cb185744093f5c4 Mon Sep 17 00:00:00 2001 From: Daniel Oliveira Date: Wed, 18 Nov 2026 14:28:16 +0100 Subject: [PATCH] Keep heredoc labels and nowdocs, and end the closing label's line The formatter wrote every heredoc as <<= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= 0x80) { + return true + } + } + return false } func (formatter *formatter) ScalarLnumber(node *ast.ScalarLnumber) { diff --git a/pkg/visitor/formatter/heredoc_test.go b/pkg/visitor/formatter/heredoc_test.go new file mode 100644 index 0000000..bdc1009 --- /dev/null +++ b/pkg/visitor/formatter/heredoc_test.go @@ -0,0 +1,61 @@ +package formatter_test + +import ( + "bytes" + "strings" + "testing" + + "github.com/rectorphp/php-parser-in-go/pkg/ast" + "github.com/rectorphp/php-parser-in-go/pkg/conf" + "github.com/rectorphp/php-parser-in-go/pkg/parser" + "github.com/rectorphp/php-parser-in-go/pkg/version" + "github.com/rectorphp/php-parser-in-go/pkg/visitor/formatter" + "github.com/rectorphp/php-parser-in-go/pkg/visitor/printer" +) + +// formatHeredoc parses src, lays it out from scratch and prints it, +// without the open tag the formatter writes. +func formatHeredoc(test *testing.T, src string) string { + test.Helper() + ver, err := version.New("8.4") + if err != nil { + test.Fatal(err) + } + root, err := parser.Parse([]byte(src), conf.Config{Version: ver}) + if err != nil { + test.Fatal(err) + } + root.Accept(formatter.NewFormatter()) + var buffer bytes.Buffer + root.(*ast.Root).Accept(printer.NewPrinter(&buffer)) + return strings.TrimLeft(strings.TrimPrefix(buffer.String(), "