hclwrite: Fix unstable list returned by Body.Blocks()

Fixes #310

The type of `Body.items` is a `nodeSet` (That is, `map[*node]struct{}`),
so the order of the list returned by Body.Blocks () was unstable.
This commit is contained in:
Masayuki Morita 2019-10-17 12:01:14 +09:00 committed by Martin Atkins
parent b15db4a513
commit c21e319577

View File

@ -60,7 +60,7 @@ func (b *Body) Attributes() map[string]*Attribute {
// Blocks returns a new slice of all the blocks in the body.
func (b *Body) Blocks() []*Block {
ret := make([]*Block, 0, len(b.items))
for n := range b.items {
for _, n := range b.items.List() {
if block, isBlock := n.content.(*Block); isBlock {
ret = append(ret, block)
}