( branches: unknown[], $: InternalScope )
| 994 | (!calls(l, r) && !calls(r, l) && ((l.pure && r.pure) || disjointByTag(l, r))) |
| 995 | |
| 996 | export const deferUnion = ( |
| 997 | branches: unknown[], |
| 998 | $: InternalScope |
| 999 | ): BaseRoot | undefined => { |
| 1000 | if (branches.length < 2 || !canDefer($)) return |
| 1001 | const all: Facts[] = [] |
| 1002 | const defs: unknown[] = [] |
| 1003 | const terms: string[] = [] |
| 1004 | try { |
| 1005 | for (let i = 0; i < branches.length; i++) { |
| 1006 | const branch: unknown = branches[i] |
| 1007 | const shell = |
| 1008 | ( |
| 1009 | hasDomain(branch, "object") && |
| 1010 | !deferred.has(branch) && |
| 1011 | !isNode(branch) |
| 1012 | ) ? |
| 1013 | deferDefinition(branch, $) |
| 1014 | : branch |
| 1015 | if (!shell) return |
| 1016 | const value = valueFacts(shell, { key: "", domains: 0, pure: true }) |
| 1017 | if (!value || value[0].defaults || value[0].cyclic === true) return |
| 1018 | all.push(value[0]) |
| 1019 | defs.push(value[1]) |
| 1020 | if (!insertAll(terms, value[0])) return |
| 1021 | } |
| 1022 | } catch { |
| 1023 | return |
| 1024 | } |
| 1025 | let domains = 0 |
| 1026 | let pure = true |
| 1027 | let values: unknown[] | undefined = [] |
| 1028 | let units: boolean | undefined |
| 1029 | let narrowed: boolean | undefined |
| 1030 | let cyclic: Facts["cyclic"] |
| 1031 | let narrowedWithin: boolean | undefined |
| 1032 | let unitsWithin: boolean | undefined |
| 1033 | let ends: Ends | undefined |
| 1034 | let held: Facts["held"] = new Map() |
| 1035 | for (let i = 0; i < all.length; i++) { |
| 1036 | const f = all[i] |
| 1037 | for (let j = i + 1; j < all.length; j++) { |
| 1038 | if (!determinate(f, all[j])) return |
| 1039 | // what two ranges meeting allow alone is a unit to what narrows the union |
| 1040 | if (meet(f, all[j])) units = true |
| 1041 | } |
| 1042 | domains |= f.domains |
| 1043 | pure &&= f.pure |
| 1044 | values = f.values && values?.concat(f.values) |
| 1045 | units ||= f.units |
| 1046 | narrowed ||= f.narrowed |
| 1047 | cyclic ||= f.cyclic |
| 1048 | narrowedWithin ||= f.narrowedWithin |
| 1049 | unitsWithin ||= f.unitsWithin |
| 1050 | ends = joinEnds(ends, f.ends) |
| 1051 | // a branch that isn't a literal holds what no prop says |
| 1052 | if (!f.held) held &&= f.narrowedWithin || f.unitsWithin ? undefined : held |
| 1053 | else |
no test coverage detected