MCPcopy
hub / github.com/webpack/webpack / mergeSingleValue

Function mergeSingleValue

lib/util/cleverMerge.js:548–600  ·  view source on GitHub ↗
(a, b, internalCaching)

Source from the content-addressed store, hash-verified

546 * @returns {A & B | (A | B)[] | A | A[] | B | B[]} value
547 */
548const mergeSingleValue = (a, b, internalCaching) => {
549 const bType = getValueType(b);
550 const aType = getValueType(a);
551 switch (bType) {
552 case VALUE_TYPE_DELETE:
553 case VALUE_TYPE_ATOM:
554 return b;
555 case VALUE_TYPE_OBJECT: {
556 return aType !== VALUE_TYPE_OBJECT
557 ? b
558 : internalCaching
559 ? cachedCleverMerge(a, b)
560 : cleverMerge(a, b);
561 }
562 case VALUE_TYPE_UNDEFINED:
563 return a;
564 case VALUE_TYPE_ARRAY_EXTEND:
565 switch (
566 aType !== VALUE_TYPE_ATOM
567 ? aType
568 : Array.isArray(a)
569 ? VALUE_TYPE_ARRAY_EXTEND
570 : VALUE_TYPE_OBJECT
571 ) {
572 case VALUE_TYPE_UNDEFINED:
573 return b;
574 case VALUE_TYPE_DELETE:
575 return /** @type {B[]} */ (b).filter((item) => item !== "...");
576 case VALUE_TYPE_ARRAY_EXTEND: {
577 /** @type {(A | B)[]} */
578 const newArray = [];
579 for (const item of /** @type {B[]} */ (b)) {
580 if (item === "...") {
581 for (const item of /** @type {A[]} */ (a)) {
582 newArray.push(item);
583 }
584 } else {
585 newArray.push(item);
586 }
587 }
588 return newArray;
589 }
590 case VALUE_TYPE_OBJECT:
591 return /** @type {(A | B)[]} */ (b).map((item) =>
592 item === "..." ? /** @type {A} */ (a) : item
593 );
594 default:
595 throw new Error("Not implemented");
596 }
597 default:
598 throw new Error("Not implemented");
599 }
600};
601
602/**
603 * Removes operations.

Callers 1

mergeEntriesFunction · 0.85

Calls 5

getValueTypeFunction · 0.85
cachedCleverMergeFunction · 0.85
isArrayMethod · 0.80
cleverMergeFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected