Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .changeset/pre/fresh-nights-fail.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Unify enum variants into a single `enumVariantTypeNode` with an optional `data`

**BREAKING CHANGES**

**`enumEmptyVariantTypeNode`, `enumStructVariantTypeNode` and `enumTupleVariantTypeNode` are replaced by `enumVariantTypeNode`.** Absent `data` is a unit variant; a struct payload gives named fields, a tuple payload gives positional fields, and any other type node is carried as-is. The `name`, optional `discriminator` and optional `display` attributes carry over unchanged; the former `struct`/`tuple` attributes both become `data`. When upgrading, a v1 tuple variant holding exactly one item should unwrap to that single type — the 1-tuple was the workaround spelling of a single-type payload — **unless** the item is a `structTypeNode`, `tupleTypeNode` or `definedTypeLinkNode`: those shapes determine the variant flavour in `data` position, so unwrapping them would change the generated API (e.g. `V(InlineStruct)` becoming `V { … }`) even though the wire format is identical. Renderers whose target requires a wrapper (e.g. Rust) re-wrap single-type payloads on their side.
**`enumEmptyVariantTypeNode`, `enumStructVariantTypeNode` and `enumTupleVariantTypeNode` are replaced by `enumVariantTypeNode`.** Absent `data` is a unit variant; a struct payload gives named fields, a tuple payload gives positional fields, and any other type node is carried as-is. The `name`, optional `discriminator` and optional `display` attributes carry over unchanged; the former `struct`/`tuple` attributes both become `data`. When upgrading, a v1 tuple variant keeps its tuple, even with a single item, e.g. `enumTupleVariantTypeNode('wait', tupleTypeNode([numberTypeNode('u64')]))` becomes `enumVariantTypeNode('wait', { data: tupleTypeNode([integerTypeNode('u64')]) })`, along with the tuple payloads of its values. This keeps the upgrade a faithful translation that leaves generated APIs unchanged; authors may then simplify such variants to `{ data: integerTypeNode('u64') }`. Renderers whose target requires a wrapper (e.g. Rust) re-wrap single-type payloads on their side.

```diff
enumTypeNode([
- enumEmptyVariantTypeNode('flip'),
- enumTupleVariantTypeNode('rotate', tupleTypeNode([numberTypeNode('u32')])),
- enumStructVariantTypeNode('move', structTypeNode([/* … */])),
+ enumVariantTypeNode('flip'),
+ enumVariantTypeNode('rotate', numberTypeNode('u32')),
+ enumVariantTypeNode('rotate', tupleTypeNode([numberTypeNode('u32')])),
+ enumVariantTypeNode('move', structTypeNode([/* … */])),
]);
```
Expand Down
Loading