( internalSlotMap: WeakMap<ListFormat, ListFormatInternal>, lf: ListFormat, list: string[] )
| 125 | } |
| 126 | |
| 127 | function createPartsFromList( |
| 128 | internalSlotMap: WeakMap<ListFormat, ListFormatInternal>, |
| 129 | lf: ListFormat, |
| 130 | list: string[] |
| 131 | ) { |
| 132 | const size = list.length |
| 133 | if (size === 0) { |
| 134 | return [] |
| 135 | } |
| 136 | if (size === 2) { |
| 137 | const pattern = getInternalSlot(internalSlotMap, lf, 'templatePair') |
| 138 | const first = {type: 'element', value: list[0]} |
| 139 | const second = {type: 'element', value: list[1]} |
| 140 | return deconstructPattern(pattern, {'0': first, '1': second}) |
| 141 | } |
| 142 | const last = { |
| 143 | type: 'element', |
| 144 | value: list[size - 1], |
| 145 | } |
| 146 | let parts: Placeable[] | Placeable = last |
| 147 | let i = size - 2 |
| 148 | while (i >= 0) { |
| 149 | let pattern |
| 150 | if (i === 0) { |
| 151 | pattern = getInternalSlot(internalSlotMap, lf, 'templateStart') |
| 152 | } else if (i < size - 2) { |
| 153 | pattern = getInternalSlot(internalSlotMap, lf, 'templateMiddle') |
| 154 | } else { |
| 155 | pattern = getInternalSlot(internalSlotMap, lf, 'templateEnd') |
| 156 | } |
| 157 | const head = {type: 'element', value: list[i]} |
| 158 | parts = deconstructPattern(pattern, {'0': head, '1': parts}) |
| 159 | i-- |
| 160 | } |
| 161 | return parts |
| 162 | } |
| 163 | |
| 164 | function deconstructPattern( |
| 165 | pattern: string, |
no test coverage detected