Skip to content

Commit

Permalink
Print node id's when debug logging the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Oct 8, 2024
1 parent 794de67 commit b60531c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/blitz-dom/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,34 +191,35 @@ pub fn walk_tree(indent: usize, node: &Node) {
}

print!("{}", " ".repeat(indent));
let id = node.id;
match &node.raw_dom_data {
NodeData::Document => println!("#Document"),
NodeData::Document => println!("#Document {id}"),

NodeData::Text(data) => {
if data.content.chars().all(|c| c.is_ascii_whitespace()) {
println!("#text: <whitespace>");
println!("{id} #text: <whitespace>");
} else {
let content = data.content.trim();
if content.len() > 10 {
println!(
"#text: {}...",
"#text {id}: {}...",
content
.split_at(content.char_indices().take(10).last().unwrap().0)
.0
.escape_default()
)
} else {
println!("#text: {}", data.content.trim().escape_default())
println!("#text {id}: {}", data.content.trim().escape_default())
}
}
}

NodeData::Comment => println!("<!-- COMMENT -->"),
NodeData::Comment => println!("<!-- COMMENT {id} -->"),

NodeData::AnonymousBlock(_) => println!("AnonymousBlock"),
NodeData::AnonymousBlock(_) => println!("{id} AnonymousBlock"),

NodeData::Element(data) => {
print!("<{}", data.name.local);
print!("<{} {id}", data.name.local);
for attr in data.attrs.iter() {
print!(" {}=\"{}\"", attr.name.local, attr.value);
}
Expand Down

0 comments on commit b60531c

Please sign in to comment.