* Build the fields for a self-contained variant record: the common fields plus * the variant's own fields (inlined from a referenced record, or taken from an * inline group). Returns `{ fields, label }` where label names the variant.
(commonFields, entry, defMap, index)
| 309 | * inline group). Returns `{ fields, label }` where label names the variant. |
| 310 | */ |
| 311 | function variantRecord(commonFields, entry, defMap, index) { |
| 312 | const common = commonFields.map((f) => structuredClone(f)) |
| 313 | if (isGroupRef(entry)) { |
| 314 | const target = defMap.get(entry.Value) |
| 315 | const ownFields = |
| 316 | target && Array.isArray(target.Properties) ? structuredClone(target.Properties) : [structuredClone({ ...entry })] |
| 317 | return { fields: [...common, ...ownFields], label: splitName(entry.Value).local, supersedes: entry.Value } |
| 318 | } |
| 319 | // inline group: label by its sole distinguishing field when there is one |
| 320 | const ownFields = structuredClone(entry.Properties) |
| 321 | const named = ownFields.filter((f) => f && typeof f === 'object' && f.Name) |
| 322 | const label = named.length === 1 ? pascal(named[0].Name) : `Variant${index}` |
| 323 | return { fields: [...common, ...ownFields], label } |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Rewrite variant-union params into a canonical `variable` union of |
no test coverage detected