in lib/dump.go [66:108]
func (d *Dump) NodeValues() []NodeValue {
if d == nil {
return nil
}
es := d.det.State()
var values []NodeValue
for _, id := range es.IDs() {
if id == 0 {
continue
}
v, ok := es.Value(id)
if !ok {
continue
}
values = append(values, d.nodeValue(v, id))
}
sort.Slice(values, func(i, j int) bool {
vi := values[i].loc
vj := values[j].loc
switch {
case vi.Line() < vj.Line():
return true
case vi.Line() > vj.Line():
return false
}
switch {
case vi.Column() < vj.Column():
return true
case vi.Column() > vj.Column():
return false
default:
// If we are here we have executed more than once
// and have different values, so sort lexically.
// This is not ideal given that values may include
// maps which do not render consistently and so
// we're breaking the sort invariant that comparisons
// will be consistent. For what we are doing this is
// good enough.
return fmt.Sprint(values[i].val) < fmt.Sprint(values[j].val)
}
})
return values
}