fix(clone): preserve XML element types

AW
4d ago
+17-1

Summary

Cloning an XML script or style element currently changes its type from tag to script or style. DomHandler deliberately creates these elements as ordinary tags in XML mode, but cloneNode reconstructs them without the original type and the Element constructor infers HTML-specific types from their names.

Pass the original type to the constructor. Parser-based regressions cover both element names, shallow clones, and deep document clones; the existing HTML clone tests continue to pass.

Testing

Validation on Node 24.13.0: both new cases fail before the change; npm test passes all 35 tests and the complete ESLint, TypeScript, and Biome checks. npm run build passes. Biome reports two existing configuration-migration notices; no configuration changes are included.

Breaking Changes

None.

Prepared and validated with OpenAI Codex assistance.

Manual verification: Parse a script or style element in XML mode and clone it; both the shallow element and deep tree clone should preserve ElementType.Tag.

Summary by CodeRabbit

  • Bug Fixes
    • Cloned XML script and style elements now retain their original element type. This keeps shallow-cloned elements correctly identified and ensures deep-cloned results match the source, improving consistency when working with these elements. XML parsing and cloning now preserve the distinction between regular tags, scripts, and styles.