Skip to content

Fix mismatched XML element pairs on transpile#1746

Draft
TwitchBronBron with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-mismatch-xml-element-pairs
Draft

Fix mismatched XML element pairs on transpile#1746
TwitchBronBron with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-mismatch-xml-element-pairs

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

In v0, mismatched XML tags like <Group></LayoutGroup> would transpile correctly to <Group></Group>. In v1, this correction was lost and no diagnostics were emitted.

Changes

  • Added xmlTagMismatch diagnostic (code 1155) to report when opening/closing tags don't match
  • Capture closing tag names from @xml-tools/parser's END_NAME token during parsing
  • Extended SGTag and subclasses to optionally store closing tag for validation
  • Added validation in mapElement and mapNode to detect mismatches
  • Transpile behavior always uses opening tag name for closing tag (v0 behavior restored)

Example

Input:

<Group id="myGroup">
    <Label text="hello" />
</LayoutGroup>

Output after transpile:

<Group id="myGroup">
    <Label text="hello" />
</Group>

Diagnostic emitted:

Mismatched closing tag: expected '</Group>' but found '</LayoutGroup>'

Copilot AI and others added 2 commits July 7, 2026 19:36
- Added xmlTagMismatch diagnostic message (code 1155)
- Modified SGParser to capture and validate closing tag names
- Updated SGTag and subclasses to store optional closingTag
- Added diagnostic when opening/closing tags mismatch
- Transpile always uses opening tag name for closing tag
- Added comprehensive tests for both diagnostic and transpile behavior
- All existing tests pass

Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Co-authored-by: TwitchBronBron <2544493+TwitchBronBron@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix mismatch XML element pairs on transpile Fix mismatched XML element pairs on transpile Jul 7, 2026
Copilot AI requested a review from TwitchBronBron July 7, 2026 19:40
@TwitchBronBron TwitchBronBron added the create-package create a temporary npm package on every commit label Jul 7, 2026
Reworks the mismatched-closing-tag detection so it runs during validation
against the stored `closingTag` on the AST, rather than at parse time from raw
tokens. This means the diagnostic now fires for AST injected/mutated by plugins,
not just AST produced by the parser.

- Parser: keep capturing the closing tag name into `SGTag.closingTag`, but no
  longer emit the diagnostic during parse (reverts the parse-time diagnostic and
  the unnecessary `diagnostics` threading through mapNode/mapNodes).
- Validator: add `validateTagClosings`, which walks the SG tag tree via a new
  `SGTag.getChildren()` and reports `xmlTagMismatch` when a present closingTag
  does not match the opening tag. Self-closing / programmatically-built tags
  (closingTag undefined) are left valid, preserving backwards compatibility.
- Move diagnostic 1155 to its correct sequential position in DiagnosticMessages.
- Add SGTypes.spec.ts proving every affected tag type behaves correctly when
  constructed without a closingTag, and an XmlFile test proving a plugin-injected
  mismatch is caught at validation time.

Note: transpile already emitted the corrected closing tag (`this.tag.text`) in
both current master and older v0, so no transpile fix was needed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

create-package create a temporary npm package on every commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix mismatch xml element pairs on transpile

2 participants