diff --git a/printer/printer.go b/printer/printer.go index f1a40e1..0c8a7f2 100644 --- a/printer/printer.go +++ b/printer/printer.go @@ -553,8 +553,15 @@ func (p *Printer) printScalarEncapsedStringPart(n node.Node) { func (p *Printer) printScalarEncapsed(n node.Node) { io.WriteString(p.w, "\"") - for _, nn := range n.(*scalar.Encapsed).Parts { - p.Print(nn) + for _, part := range n.(*scalar.Encapsed).Parts { + switch part.(type) { + case *scalar.EncapsedStringPart: + p.Print(part) + default: + io.WriteString(p.w, "{") + p.Print(part) + io.WriteString(p.w, "}") + } } io.WriteString(p.w, "\"") @@ -567,8 +574,15 @@ func (p *Printer) printScalarHeredoc(n node.Node) { io.WriteString(p.w, nn.Label) io.WriteString(p.w, "\n") - for _, nn := range nn.Parts { - p.Print(nn) + for _, part := range nn.Parts { + switch part.(type) { + case *scalar.EncapsedStringPart: + p.Print(part) + default: + io.WriteString(p.w, "{") + p.Print(part) + io.WriteString(p.w, "}") + } } io.WriteString(p.w, strings.Trim(nn.Label, "\"'")) @@ -1232,7 +1246,14 @@ func (p *Printer) printExprShellExec(n node.Node) { io.WriteString(p.w, "`") for _, part := range nn.Parts { - p.Print(part) + switch part.(type) { + case *scalar.EncapsedStringPart: + p.Print(part) + default: + io.WriteString(p.w, "{") + p.Print(part) + io.WriteString(p.w, "}") + } } io.WriteString(p.w, "`") } diff --git a/printer/printer_test.go b/printer/printer_test.go index e99f2bc..900dadb 100644 --- a/printer/printer_test.go +++ b/printer/printer_test.go @@ -346,7 +346,7 @@ func TestPrintScalarEncapsed(t *testing.T) { }, }) - if o.String() != `"hello $var world"` { + if o.String() != `"hello {$var} world"` { t.Errorf("TestPrintScalarEncapsed is failed\n") } } @@ -365,7 +365,7 @@ func TestPrintScalarHeredoc(t *testing.T) { }) expected := `<<