bwrrp / slimdom.js

Fast, tiny, standards-compliant XML DOM implementation for node and the browser
MIT License
30 stars 8 forks source link

Rework ns prefix serialization #147

Closed bwrrp closed 11 months ago

bwrrp commented 11 months ago

This re-implements the algorithms used to determine what prefixes to assign and what declarations to output for them during serialization. The algorithms in the DOM parsing and serialization spec contain too many bugs that have so far not been addressed, and contain complicated branching that makes it hard to reason about them.

In the replacement I've tried to remain close to the original behavior in spirit. That is, existing prefixes (or an inherited default namespace) are preferred over authored prefixes. Authored prefixes are used over generated ones. A new prefix is only generated if the authored prefix of an attribute conflicts with a declaration on the same element. Declaration attributes in the DOM are only preserved if they actually represent a change to the namespaces in scope for their element and do not cause conflicts - the spec preserved default namespace declarations in a few other cases but those seemed unnecessary.