fix(printer): keep indentation of nested <<- heredoc inside command substitution
A <<- heredoc nested inside a command substitution that is itself inside another <<- heredoc was printed with its body fully deindented and its end marker pushed one extra tab further per body line. When both heredocs use tab indentation, the printer wraps each body in an extraIndenter. In the nested case the inner extraIndenter writes to the outer one. Its computed indentation was emitted via WriteByte (which the outer extraIndenter processes line by line), but the line content was emitted via Write, whose method set is promoted straight to the embedded writer and so bypassed the outer extraIndenter entirely. The content reached the tab writer without the outer indentation, while the orphaned indentation bytes stayed buffered and leaked onto the following end-marker line. Emit the trimmed content through WriteString so nested extraIndenters compose, keeping both the body and the end marker correctly indented. Add printer golden tests for single- and multi-line nested tab heredocs.
This commit is contained in:
1 parent
a87ad02bad
commit
71779310b7
2 files changed
+3
-1
No files matched your search
+1
-1
@@ -1608,7 +1608,7 @@ func (e *extraIndenter) WriteByte(b byte) error {
|
||||
e.bufWriter.WriteByte('\t')
|
||||
}
|
||||
e.bufWriter.WriteByte(tabwriter.Escape)
|
||||
e.bufWriter.Write(trimmed)
|
||||
e.bufWriter.WriteString(string(trimmed))
|
||||
e.curLine = e.curLine[:0]
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -548,6 +548,8 @@ var printTests = []printCase{
|
||||
samePrint("f <<EOF\nEOF\n# comment\nbar"),
|
||||
samePrint("f <<EOF # inline\n$(\n\t# inside\n)\nEOF\n# outside\nbar"),
|
||||
samePrint("while foo; do\n\tbar\ndone <<-EOF # inline\n\tbaz\nEOF"),
|
||||
samePrint("foo <<-EOF\n\tpre $(\n\t\tbar <<-INNER\n\t\t\tcontent\n\t\tINNER\n\t)\nEOF"),
|
||||
samePrint("foo <<-EOF\n\tpre $(\n\t\tbar <<-INNER\n\t\t\tline one\n\t\t\tline two\n\t\tINNER\n\t)\nEOF"),
|
||||
samePrint("{\n\tcat <<EOF\nEOF\n\t# comment\n}"),
|
||||
{
|
||||
"if foo # inline\nthen\n\tbar\nfi",
|
||||
|
||||
Reference in new issue
Block a user