This commit is contained in:
Liang Ding 2022-10-14 16:46:15 +08:00
parent d15c7c5e4c
commit 2a4f533574
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 33 additions and 5 deletions

View file

@ -195,11 +195,18 @@ func CountBlockNodes(node *ast.Node) (ret int) {
}
func ParentNodes(node *ast.Node) (parents []*ast.Node) {
const maxDepth = 256
i := 0
for n := node.Parent; nil != n; n = n.Parent {
i++
parents = append(parents, n)
if ast.NodeDocument == n.Type {
return
}
if maxDepth < i {
logging.LogWarnf("parent nodes of node [%s] is too deep", node.ID)
return
}
}
return
}