Skip to content

Fix node child overwrites and string export - #155

Merged
chrisjenkinson merged 2 commits into
masterfrom
claude/node-model
Sep 25, 2026
Merged

chrisjenkinson merged 2 commits into
masterfrom
claude/node-model

Conversation

@chrisjenkinson

@chrisjenkinson chrisjenkinson commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

This fixes two problems in the node model:

  • addNode() throws DuplicateNodeException when a child with the same name already exists, instead of silently replacing it. The new replaceNode() swaps out an existing child in place and throws NodeNotFoundException if there isn't one. getNode() now throws that exception too, and it's still a RuntimeException. NodeTraverser uses replaceNode() when a visitor returns a node with the same name. A series of same-type children goes in an array attribute, which the traverser already visits.
  • __toString() exports the whole tree. Before, every child node came out as {}. NodeInterface now extends JsonSerializable, and invalid UTF-8 in attributes is replaced with U+FFFD instead of causing a TypeError.

Breaking changes: NodeInterface gains replaceNode() and jsonSerialize(), and adding a second child with the same name now throws.

@chrisjenkinson
chrisjenkinson merged commit 18dbf47 into master Sep 25, 2026
4 checks passed
@chrisjenkinson
chrisjenkinson deleted the claude/node-model branch September 25, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant