Skip to content

BREAKING(xml): clean up public API - #7233

Merged
bartlomieju merged 4 commits into
denoland:mainfrom
tomas-zijdemans:xml-ready
Jul 30, 2026
Merged

BREAKING(xml): clean up public API#7233
bartlomieju merged 4 commits into
denoland:mainfrom
tomas-zijdemans:xml-ready

Conversation

@tomas-zijdemans

Copy link
Copy Markdown
Contributor

Summary

Cleanup of the @std/xml public API in preparation for a future
stabilization 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

  • Remove unused exported types. The XmlEvent union and its event
    interfaces (XmlStartElementEvent, XmlEndElementEvent, XmlTextEvent,
    XmlCDataEvent, XmlCommentEvent, XmlProcessingInstructionEvent) and
    XmlAttribute were leftovers from a pre-callback event-object design and
    appeared in no public function signature. XmlTokenCallbacks is the
    tokenizer's internal contract and has moved to _tokenizer.ts.
  • Rename XmlDeclarationEvent to XmlDeclaration. It survives only as the
    type of XmlDocument.declaration, so the Event suffix was a misnomer.
  • XmlSyntaxError no longer appends at line 0, column 0 to messages
    when position tracking is disabled. line: 0 is documented as the
    sentinel for "position unknown".

Documentation fixes

  • XmlPosition.offset and XmlSyntaxError.offset are UTF-16 code-unit
    offsets into the input string, not byte offsets.
  • XmlElement.attributes is keyed by the raw qualified attribute name
    (e.g. xlink:href, xmlns:ns), not the local name.
  • XmlEventCallbacks.onDoctype now documents that it only fires when
    disallowDoctype: false is set; under the default, a DOCTYPE throws.

Tests

  • Public-level parseXmlStream() DOCTYPE tests: onDoctype receives name,
    public ID, and system ID; the default rejects DOCTYPE without invoking
    the callback (previously only covered at the internal tokenizer level).
  • Tests for the position-suffix behavior of XmlSyntaxError.

Test plan

  • deno task ok passes locally

This 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.

@bartlomieju bartlomieju left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread xml/types.ts
/** 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). */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread xml/types.ts
export interface XmlDeclarationEvent extends XmlPosition {
/** The event type discriminant. */
export interface XmlDeclaration extends XmlPosition {
/** The type discriminant. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bartlomieju
bartlomieju merged commit 7a0239f into denoland:main Jul 30, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants