(firstEntry, secondEntry, internalCaching)
| 398 | * @returns {ObjectParsedPropertyEntry<T> | ObjectParsedPropertyEntry<O> | ObjectParsedPropertyEntry<T & O>} new entry |
| 399 | */ |
| 400 | const mergeEntries = (firstEntry, secondEntry, internalCaching) => { |
| 401 | switch (getValueType(secondEntry.base)) { |
| 402 | case VALUE_TYPE_ATOM: |
| 403 | case VALUE_TYPE_DELETE: |
| 404 | // No need to consider firstEntry at all |
| 405 | // second value override everything |
| 406 | // = second.base + second.byProperty |
| 407 | return secondEntry; |
| 408 | case VALUE_TYPE_UNDEFINED: |
| 409 | if (!firstEntry.byProperty) { |
| 410 | // = first.base + second.byProperty |
| 411 | return { |
| 412 | base: firstEntry.base, |
| 413 | byProperty: secondEntry.byProperty, |
| 414 | byValues: secondEntry.byValues |
| 415 | }; |
| 416 | } else if (firstEntry.byProperty !== secondEntry.byProperty) { |
| 417 | throw new Error( |
| 418 | `${firstEntry.byProperty} and ${secondEntry.byProperty} for a single property is not supported` |
| 419 | ); |
| 420 | } else { |
| 421 | // = first.base + (first.byProperty + second.byProperty) |
| 422 | // need to merge first and second byValues |
| 423 | /** @type {Map<string, T & O>} */ |
| 424 | const newByValues = new Map(firstEntry.byValues); |
| 425 | for (const [key, value] of /** @type {ByValues} */ ( |
| 426 | secondEntry.byValues |
| 427 | )) { |
| 428 | const firstValue = getFromByValues( |
| 429 | /** @type {ByValues} */ |
| 430 | (firstEntry.byValues), |
| 431 | key |
| 432 | ); |
| 433 | newByValues.set( |
| 434 | key, |
| 435 | mergeSingleValue(firstValue, value, internalCaching) |
| 436 | ); |
| 437 | } |
| 438 | return { |
| 439 | base: firstEntry.base, |
| 440 | byProperty: firstEntry.byProperty, |
| 441 | byValues: newByValues |
| 442 | }; |
| 443 | } |
| 444 | default: { |
| 445 | if (!firstEntry.byProperty) { |
| 446 | // The simple case |
| 447 | // = (first.base + second.base) + second.byProperty |
| 448 | return { |
| 449 | base: |
| 450 | /** @type {T[keyof T] & O[keyof O]} */ |
| 451 | ( |
| 452 | mergeSingleValue( |
| 453 | firstEntry.base, |
| 454 | secondEntry.base, |
| 455 | internalCaching |
| 456 | ) |
| 457 | ), |
no test coverage detected