MCPcopy
hub / github.com/webpack/webpack / mergeEntries

Function mergeEntries

lib/util/cleverMerge.js:400–523  ·  view source on GitHub ↗
(firstEntry, secondEntry, internalCaching)

Source from the content-addressed store, hash-verified

398 * @returns {ObjectParsedPropertyEntry<T> | ObjectParsedPropertyEntry<O> | ObjectParsedPropertyEntry<T & O>} new entry
399 */
400const 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 ),

Callers 1

_cleverMergeFunction · 0.85

Calls 6

getValueTypeFunction · 0.85
getFromByValuesFunction · 0.85
mergeSingleValueFunction · 0.85
setMethod · 0.45
valuesMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected