Skip to content

Commit

Permalink
Fix a bug ast.Merge removes comments from SequenceNode (#570)
Browse files Browse the repository at this point in the history
* fix: fix a bug that merge of sequences loses comments

* fix: append null if ValueHeadComments is empty
  • Loading branch information
suzuki-shunsuke authored Dec 5, 2024
1 parent 5d22eed commit a91fb5b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a91fb5b

Please sign in to comment.