MCPcopy
hub / github.com/webpack/webpack / subtractRuntime

Function subtractRuntime

lib/util/runtime.js:362–400  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

360 * @returns {RuntimeSpec} result
361 */
362const subtractRuntime = (a, b) => {
363 if (a === undefined) {
364 return;
365 } else if (b === undefined) {
366 return a;
367 } else if (a === b) {
368 return;
369 } else if (typeof a === "string") {
370 if (typeof b === "string") {
371 return a;
372 } else if (b.has(a)) {
373 return;
374 }
375 return a;
376 }
377 if (typeof b === "string") {
378 if (!a.has(b)) return a;
379 if (a.size === 2) {
380 for (const item of a) {
381 if (item !== b) return item;
382 }
383 }
384 /** @type {RuntimeSpecSortableSet} */
385 const set = new SortableSet(a);
386 set.delete(b);
387 return set;
388 }
389 /** @type {RuntimeSpecSortableSet} */
390 const set = new SortableSet();
391 for (const item of a) {
392 if (!b.has(item)) set.add(item);
393 }
394 if (set.size === 0) return;
395 if (set.size === 1) {
396 const [item] = set;
397 return item;
398 }
399 return set;
400};
401
402/**
403 * Subtract runtime condition.

Callers 3

applyMethod · 0.85
subtractRuntimeConditionFunction · 0.85

Calls 3

deleteMethod · 0.95
addMethod · 0.95
hasMethod · 0.45

Tested by

no test coverage detected