* Project a CDDL group into a record. A property with an unbounded occurrence (`*`/`+`) * is a map/spread entry, not a scalar field: `* text => any` marks the record extensible, * `* text => T` becomes a typed map, and an unbounded group spread is folded in. Everything * else is a normal field.
(def)
| 347 | * else is a normal field. |
| 348 | */ |
| 349 | function projectRecord(def) { |
| 350 | const record = { kind: 'record', fields: [] } |
| 351 | for (const prop of (def.Properties ?? []).flat()) { |
| 352 | if (!prop || typeof prop !== 'object') continue |
| 353 | // An unbounded upper bound is overloaded in this parser: a key-typed entry is a map |
| 354 | // (`* text => value`); an anonymous entry is a structural spread; everything else is |
| 355 | // just an optional field (the `?` quantifier). Only the first two are not real fields. |
| 356 | // The parser emits the bound as Infinity; the AST's JSON round-trip turns it into null, |
| 357 | // so accept either rather than depending on that coercion. |
| 358 | if (isUnbounded(prop.Occurrence) && (!prop.Name || prop.Name in PRIMITIVES || prop.Name in PRELUDE)) { |
| 359 | if (prop.Name in PRIMITIVES || prop.Name in PRELUDE) { |
| 360 | const value = projectRef(prop.Type) |
| 361 | if (value.primitive === 'any') record.extensible = true |
| 362 | else record.map = value |
| 363 | } |
| 364 | continue |
| 365 | } |
| 366 | if (prop.Name) record.fields.push(projectField(prop)) |
| 367 | } |
| 368 | return record |
| 369 | } |
| 370 | |
| 371 | const typeRef = (name) => (name ? { ref: name } : null) |
| 372 |
no test coverage detected