Api does not provide any information how deep we are in the tree while walking. Do You have any ideas how to get such information?
root.walk(function (node) {
console.log('Nesting level' + node.??)
});
You can get the length of the path of the node:
root.walk(function (node) {
console.log('Nesting level ' + node.getPath().length);
});
edit: Efficiency wise, each time you call getPath
it follows the parent links up to the root, so it's linear to the node depth.