From a91fb5be1d57e5b6dfacf06fde5b8a4bbdc0fadd Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Thu, 5 Dec 2024 19:09:37 +0900 Subject: [PATCH] Fix a bug ast.Merge removes comments from SequenceNode (#570) * fix: fix a bug that merge of sequences loses comments * fix: append null if ValueHeadComments is empty --- ast/ast.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ast/ast.go b/ast/ast.go index 52edfdf..9c5844a 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -1475,6 +1475,11 @@ func (n *SequenceNode) Merge(target *SequenceNode) { column := n.Start.Position.Column - target.Start.Position.Column target.AddColumn(column) n.Values = append(n.Values, target.Values...) + if len(target.ValueHeadComments) == 0 { + n.ValueHeadComments = append(n.ValueHeadComments, make([]*CommentGroupNode, len(target.Values))...) + return + } + n.ValueHeadComments = append(n.ValueHeadComments, target.ValueHeadComments...) } // SetIsFlowStyle set value to IsFlowStyle field recursively.