( target: Record<string, unknown>, table: TableArray, )
| 199 | } |
| 200 | |
| 201 | function deepAssignTableArray( |
| 202 | target: Record<string, unknown>, |
| 203 | table: TableArray, |
| 204 | ) { |
| 205 | const { type, keys, value } = table; |
| 206 | const currentValue = getTargetValue(target, keys); |
| 207 | |
| 208 | if (currentValue === undefined) { |
| 209 | return Object.assign(target, unflat(keys, [value])); |
| 210 | } |
| 211 | if (Array.isArray(currentValue)) { |
| 212 | if (table.keys.length === 1) { |
| 213 | currentValue.push(value); |
| 214 | } else { |
| 215 | const last = currentValue.at(-1); |
| 216 | deepAssign(last, { |
| 217 | type: table.type, |
| 218 | keys: table.keys.slice(1), |
| 219 | value: table.value, |
| 220 | }); |
| 221 | } |
| 222 | return target; |
| 223 | } |
| 224 | if (isObject(currentValue)) { |
| 225 | deepAssign(currentValue, { type, keys: keys.slice(1), value }); |
| 226 | return target; |
| 227 | } |
| 228 | throw new Error("Unexpected assign"); |
| 229 | } |
| 230 | |
| 231 | export function deepAssign( |
| 232 | target: Record<string, unknown>, |
no test coverage detected