Skip to content

feat(typediagram): add discriminants, untagged unions, and target gating#32

Merged
MelbourneDeveloper merged 14 commits into
Nimblesite:mainfrom
abdushakoor12:issue-25
May 6, 2026
Merged

feat(typediagram): add discriminants, untagged unions, and target gating#32
MelbourneDeveloper merged 14 commits into
Nimblesite:mainfrom
abdushakoor12:issue-25

Conversation

@abdushakoor12
Copy link
Copy Markdown
Contributor

TLDR

Add three typeDiagram language features end-to-end: explicit numeric union discriminants, untagged union syntax, and declaration-level target gating with @targets(...) / @skipTargets(...), and teach converters/rendering/docs to honor them. Closes #25, closes #26, closes #27.

Details

Added:

  • Explicit numeric discriminants on union variants such as ParseError = -32700
  • untagged union parsing/modeling/printing, with Rust #[serde(untagged)] emission and plain TypeScript union emission
  • Declaration-level target gating annotations with @targets(...) and @skipTargets(...)
  • Shared variant helpers in packages/typediagram/src/variant.ts
  • Target-visibility helpers in the model layer so all emitters filter declarations consistently

Changed:

  • Parser, AST, model builder, JSON round-trip, pretty-printer, layout text, and SVG rendering now preserve discriminants, untagged unions, and declaration targeting metadata
  • All language emitters now filter declarations via shared target gating instead of emitting every declaration unconditionally
  • Core docs and README now document explicit discriminants, and the VS Code sample includes a discriminant example
  • Bundle-size budget for typediagram-core increased to 80 KB to account for the added parser/emitter surface

Deleted:

  • A few now-unused imports and no-op tree-shake suppression lines that became unnecessary after the refactor

Spec/Doc changes:

  • Updated docs/specs/language-reference.md grammar and examples for explicit numeric discriminants
  • Updated packages/typediagram/README.md with discriminant examples

Breaking changes:

  • No breaking API change intended; this is additive syntax and emitter behavior.

How Do The Automated Tests Prove It Works?

  • packages/typediagram/test/converters/rust.test.ts
    • preserves explicit numeric discriminants on enum variants
    • emits serde untagged enums from untagged union syntax
  • packages/typediagram/test/converters/typescript.test.ts
    • emits untagged tuple unions as plain TypeScript unions
    • emits remaining untagged payload shapes without discriminator fields
    • [CONV-TS-BUG-27] skips declarations gated away from the typescript target
    • [CONV-TS-BUG-27] supports blacklisting the typescript target
  • packages/typediagram/test/parser.test.ts
    • parses untagged unions
    • parses target annotations on declarations
    • malformed/unknown annotation recovery coverage
  • packages/typediagram/test/model.test.ts
    • preserves untagged unions through printSource and JSON
    • preserves declaration target gating through printSource and JSON
    • filters declarations for a specific target
  • packages/typediagram/test/render.test.ts
    • renders explicit union discriminants in the SVG text
  • make ci passed locally, including full Playwright coverage merge and the final bundle-size check (79.38 KB within the 80 KB budget)

@MelbourneDeveloper MelbourneDeveloper merged commit 4009a35 into Nimblesite:main May 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants