BREAKING(xml): clean up public API - #7233
Conversation
bartlomieju
left a comment
There was a problem hiding this comment.
Removals check out — I verified none of XmlEvent, the six event interfaces, or XmlAttribute appear in any public signature, so this is dead surface from the pre-callback design. Package is 0.x so no deprecation cycle is owed. Two JSDoc notes inline, both non-blocking.
| /** Column number (1-indexed). */ | ||
| readonly column: number; | ||
| /** Byte offset in the input. */ | ||
| /** Character offset in the input string (in UTF-16 code units, 0-indexed). */ |
There was a problem hiding this comment.
While you're in here: line and column above are documented as "(1-indexed)" only, but with this PR they can also be 0 when position tracking is disabled — that's documented on XmlSyntaxError but not on the shared type that actually carries the values, and XmlDeclaration extends this too.
Since the 0 sentinel is now load-bearing for the message-formatting change, it should be discoverable from the field that holds it.
| export interface XmlDeclarationEvent extends XmlPosition { | ||
| /** The event type discriminant. */ | ||
| export interface XmlDeclaration extends XmlPosition { | ||
| /** The type discriminant. */ |
There was a problem hiding this comment.
Worth a thought before 1.0: with XmlEvent gone, this type field discriminates a union of one, and the position fields inherited from XmlPosition are vestigial for a declaration reached via XmlDocument.declaration.
Keeping it for symmetry with XmlNode is a fine answer — I just don't want it to be frozen by accident at stabilization when nobody looked at it.
Summary
Cleanup of the
@std/xmlpublic API in preparation for a futurestabilization proposal. The goal is to remove surface that should not be
stabilized and fix documentation that did not match actual behavior, so
the API that remains is the API we would commit to at 1.0.0.
Breaking changes
XmlEventunion and its eventinterfaces (
XmlStartElementEvent,XmlEndElementEvent,XmlTextEvent,XmlCDataEvent,XmlCommentEvent,XmlProcessingInstructionEvent) andXmlAttributewere leftovers from a pre-callback event-object design andappeared in no public function signature.
XmlTokenCallbacksis thetokenizer's internal contract and has moved to
_tokenizer.ts.XmlDeclarationEventtoXmlDeclaration. It survives only as thetype of
XmlDocument.declaration, so theEventsuffix was a misnomer.XmlSyntaxErrorno longer appendsat line 0, column 0to messageswhen position tracking is disabled.
line: 0is documented as thesentinel for "position unknown".
Documentation fixes
XmlPosition.offsetandXmlSyntaxError.offsetare UTF-16 code-unitoffsets into the input string, not byte offsets.
XmlElement.attributesis keyed by the raw qualified attribute name(e.g.
xlink:href,xmlns:ns), not the local name.XmlEventCallbacks.onDoctypenow documents that it only fires whendisallowDoctype: falseis set; under the default, a DOCTYPE throws.Tests
parseXmlStream()DOCTYPE tests:onDoctypereceives name,public ID, and system ID; the default rejects DOCTYPE without invoking
the callback (previously only covered at the internal tokenizer level).
XmlSyntaxError.Test plan
deno task okpasses locallyThis PR was developed with the assistance of an AI agent in Cursor; all
changes were reviewed and verified by me.
Note
Recreates #7206, which was closed automatically when I accidentally deleted the head fork. The branch is identical to the original PR head.