Skip to content

fix: use self-closing tags when children are implictly hidden#299

Open
JoshBashed wants to merge 1 commit intoCoreOffice:mainfrom
JoshBashed:fix/self-closing-empty-case
Open

fix: use self-closing tags when children are implictly hidden#299
JoshBashed wants to merge 1 commit intoCoreOffice:mainfrom
JoshBashed:fix/self-closing-empty-case

Conversation

@JoshBashed
Copy link
Copy Markdown

Closes #298

Important

Although the issue was generated using AI tools, the PR's code was written by a human.

When a choice case uses _0 = "" to inline an associated value whose contents are XML attributes only, the encoder was emitting an empty open/close pair (<Tag Attr="..."></Tag>) instead of a self-closing tag (<Tag Attr="..." />).

The attributes correctly bubbled up to the parent via formatXMLAttributes, but the empty-keyed phantom child stayed in the elements list, so !elements.isEmpty forced the encoder onto the open/close path.

Changes

  • Add isPracticallyEmpty to recursively check if a tag can be self-closing.

Important

formatXMLAttributes doesn't recognize tags with no elements inside children and this PR doesn't change that behavior.

  • Use isPracticallyEmpty when deciding whether to self-close an element.
  • Add a test case in InlinePropertyTests to ensure the behavior remains.
  • Fix existing test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Self-closing tags broken for choice enums with _0 = "" inlining when inner type is attribute-only

1 participant