Radar · Go · Archive · Week 20 · May 12 – 18, 2025
go/ast: add PreorderStack, a wrapper around ast.Inspect that maintains a stack
Worth knowingstdlib
- What changed
- A new helper
PreorderStacktraverses an AST and supplies a correctly maintained stack of ancestor nodes to the callback. - Production impact
- The source does not say.
- Try it
- Use
ast.PreorderStackto walk a parsed file and print each node’s depth. - Source
- github.com/golang/go/issues/73319
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed