(inner: dict)
| 212 | |
| 213 | // bounds inside an intersection inherit their basis's unit (e.g. "character" for string, "item" for Array) |
| 214 | const attachBoundUnits = (inner: dict): void => { |
| 215 | const basis = (inner.proto ?? inner.domain) as |
| 216 | | nodeOfKind<Intersection.BasisKind> |
| 217 | | undefined |
| 218 | const unit = basis?.boundUnit |
| 219 | if (!unit) return |
| 220 | for (const k in inner) { |
| 221 | if (!isKeyOf(k, boundUnitKeys)) continue |
| 222 | const v = inner[k] as listable<BaseNode> |
| 223 | if (isArray(v)) { |
| 224 | let updated: BaseNode[] | undefined |
| 225 | for (let i = 0; i < v.length; i++) { |
| 226 | const node = v[i] |
| 227 | if ((node.inner as { unit?: BoundUnit }).unit !== undefined) continue |
| 228 | updated ??= v.slice() |
| 229 | updated[i] = withBoundUnit(node, unit) |
| 230 | } |
| 231 | if (updated) inner[k] = updated |
| 232 | } else if ((v.inner as { unit?: BoundUnit }).unit === undefined) |
| 233 | inner[k] = withBoundUnit(v, unit) |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | const withBoundUnit = (node: BaseNode, unit: BoundUnit): BaseNode => |
| 238 | node.$.node(node.kind, { ...node.inner, unit, meta: node.meta } as never, { |
no test coverage detected