Skip to content

Commit

Permalink
Fix column value when merge map node
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Jul 16, 2020
1 parent 367bda1 commit 174a7d2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,21 @@ type MappingNode struct {
Values []*MappingValueNode
}

func (n *MappingNode) startPos() *token.Position {
if len(n.Values) == 0 {
return n.Start.Position
}
return n.Values[0].Key.GetToken().Position
}

// Merge merge key/value of map.
func (n *MappingNode) Merge(target *MappingNode) {
keyToMapValueMap := map[string]*MappingValueNode{}
for _, value := range n.Values {
key := value.Key.String()
keyToMapValueMap[key] = value
}
column := n.Start.Position.Column - target.Start.Position.Column
column := n.startPos().Column - target.startPos().Column
target.AddColumn(column)
for _, value := range target.Values {
mapValue, exists := keyToMapValueMap[value.Key.String()]
Expand Down

0 comments on commit 174a7d2

Please sign in to comment.