( dst: TAttributes, marker: AttributeMarker, key1: string, key2: string | null, value: string | null, )
| 153 | * @param value Value to add or to overwrite to `TAttributes` Only used if `marker` is not Class. |
| 154 | */ |
| 155 | export function mergeHostAttribute( |
| 156 | dst: TAttributes, |
| 157 | marker: AttributeMarker, |
| 158 | key1: string, |
| 159 | key2: string | null, |
| 160 | value: string | null, |
| 161 | ): void { |
| 162 | let i = 0; |
| 163 | // Assume that new markers will be inserted at the end. |
| 164 | let markerInsertPosition = dst.length; |
| 165 | // scan until correct type. |
| 166 | if (marker === AttributeMarker.ImplicitAttributes) { |
| 167 | markerInsertPosition = -1; |
| 168 | } else { |
| 169 | while (i < dst.length) { |
| 170 | const dstValue = dst[i++]; |
| 171 | if (typeof dstValue === 'number') { |
| 172 | if (dstValue === marker) { |
| 173 | markerInsertPosition = -1; |
| 174 | break; |
| 175 | } else if (dstValue > marker) { |
| 176 | // We need to save this as we want the markers to be inserted in specific order. |
| 177 | markerInsertPosition = i - 1; |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // search until you find place of insertion |
| 185 | while (i < dst.length) { |
| 186 | const item = dst[i]; |
| 187 | if (typeof item === 'number') { |
| 188 | // since `i` started as the index after the marker, we did not find it if we are at the next |
| 189 | // marker |
| 190 | break; |
| 191 | } else if (item === key1) { |
| 192 | // We already have same token |
| 193 | if (key2 === null) { |
| 194 | if (value !== null) { |
| 195 | dst[i + 1] = value; |
| 196 | } |
| 197 | return; |
| 198 | } else if (key2 === dst[i + 1]) { |
| 199 | dst[i + 2] = value!; |
| 200 | return; |
| 201 | } |
| 202 | } |
| 203 | // Increment counter. |
| 204 | i++; |
| 205 | if (key2 !== null) i++; |
| 206 | if (value !== null) i++; |
| 207 | } |
| 208 | |
| 209 | // insert at location. |
| 210 | if (markerInsertPosition !== -1) { |
| 211 | dst.splice(markerInsertPosition, 0, marker); |
| 212 | i = markerInsertPosition + 1; |
no outgoing calls
no test coverage detected
searching dependent graphs…