WXL
3 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
node_modules/webpack/lib/util/runtime.js
@@ -10,17 +10,21 @@
/** @typedef {import("../Compilation")} Compilation */
/** @typedef {import("../Entrypoint").EntryOptions} EntryOptions */
/** @typedef {string | SortableSet<string> | undefined} RuntimeSpec */
/** @typedef {SortableSet<string>} RuntimeSpecSortableSet */
/** @typedef {string | RuntimeSpecSortableSet | undefined} RuntimeSpec */
/** @typedef {RuntimeSpec | boolean} RuntimeCondition */
/**
 * Gets entry runtime.
 * @param {Compilation} compilation the compilation
 * @param {string} name name of the entry
 * @param {EntryOptions=} options optionally already received entry options
 * @returns {RuntimeSpec} runtime
 */
const getEntryRuntime = (compilation, name, options) => {
   /** @type {EntryOptions["dependOn"]} */
   let dependOn;
   /** @type {EntryOptions["runtime"]} */
   let runtime;
   if (options) {
      ({ dependOn, runtime } = options);
@@ -51,6 +55,7 @@
};
/**
 * Processes the provided runtime.
 * @param {RuntimeSpec} runtime runtime
 * @param {(runtime: string | undefined) => void} fn functor
 * @param {boolean} deterministicOrder enforce a deterministic order
@@ -70,8 +75,9 @@
};
/**
 * Returns runtime key.
 * @template T
 * @param {SortableSet<T>} set set
 * @param {Exclude<RuntimeSpec, undefined | string>} set set
 * @returns {string} runtime key
 */
const getRuntimesKey = (set) => {
@@ -80,6 +86,7 @@
};
/**
 * Returns key of runtimes.
 * @param {RuntimeSpec} runtime runtime(s)
 * @returns {string} key of runtimes
 */
@@ -90,6 +97,7 @@
};
/**
 * Returns runtime(s).
 * @param {string} key key of runtimes
 * @returns {RuntimeSpec} runtime(s)
 */
@@ -101,8 +109,9 @@
};
/**
 * Gets runtimes string.
 * @template T
 * @param {SortableSet<T>} set set
 * @param {Exclude<RuntimeSpec, undefined | string>} set set
 * @returns {string} runtime string
 */
const getRuntimesString = (set) => {
@@ -111,6 +120,7 @@
};
/**
 * Returns readable version.
 * @param {RuntimeSpec} runtime runtime(s)
 * @returns {string} readable version
 */
@@ -121,6 +131,7 @@
};
/**
 * Runtime condition to string.
 * @param {RuntimeCondition} runtimeCondition runtime condition
 * @returns {string} readable version
 */
@@ -131,6 +142,7 @@
};
/**
 * Returns true, when they are equal.
 * @param {RuntimeSpec} a first
 * @param {RuntimeSpec} b second
 * @returns {boolean} true, when they are equal
@@ -161,9 +173,10 @@
};
/**
 * Compares the provided values and returns their ordering.
 * @param {RuntimeSpec} a first
 * @param {RuntimeSpec} b second
 * @returns {-1|0|1} compare
 * @returns {-1 | 0 | 1} compare
 */
const compareRuntime = (a, b) => {
   if (a === b) {
@@ -181,6 +194,7 @@
};
/**
 * Merges the provided values into a single result.
 * @param {RuntimeSpec} a first
 * @param {RuntimeSpec} b second
 * @returns {RuntimeSpec} merged
@@ -194,6 +208,7 @@
      return a;
   } else if (typeof a === "string") {
      if (typeof b === "string") {
         /** @type {RuntimeSpecSortableSet} */
         const set = new SortableSet();
         set.add(a);
         set.add(b);
@@ -201,16 +216,19 @@
      } else if (b.has(a)) {
         return b;
      }
      /** @type {RuntimeSpecSortableSet} */
      const set = new SortableSet(b);
      set.add(a);
      return set;
   }
   if (typeof b === "string") {
      if (a.has(b)) return a;
      /** @type {RuntimeSpecSortableSet} */
      const set = new SortableSet(a);
      set.add(b);
      return set;
   }
   /** @type {RuntimeSpecSortableSet} */
   const set = new SortableSet(a);
   for (const item of b) set.add(item);
   if (set.size === a.size) return a;
@@ -218,6 +236,7 @@
};
/**
 * Merges runtime condition.
 * @param {RuntimeCondition} a first
 * @param {RuntimeCondition} b second
 * @param {RuntimeSpec} runtime full runtime
@@ -239,6 +258,7 @@
};
/**
 * Merges runtime condition non false.
 * @param {RuntimeSpec | true} a first
 * @param {RuntimeSpec | true} b second
 * @param {RuntimeSpec} runtime full runtime
@@ -258,6 +278,7 @@
};
/**
 * Merges runtime owned.
 * @param {RuntimeSpec} a first (may be modified)
 * @param {RuntimeSpec} b second
 * @returns {RuntimeSpec} merged
@@ -271,14 +292,17 @@
      if (typeof b === "string") {
         return b;
      }
      /** @type {RuntimeSpecSortableSet} */
      return new SortableSet(b);
   } else if (typeof a === "string") {
      if (typeof b === "string") {
         /** @type {RuntimeSpecSortableSet} */
         const set = new SortableSet();
         set.add(a);
         set.add(b);
         return set;
      }
      /** @type {RuntimeSpecSortableSet} */
      const set = new SortableSet(b);
      set.add(a);
      return set;
@@ -292,6 +316,7 @@
};
/**
 * Returns merged.
 * @param {RuntimeSpec} a first
 * @param {RuntimeSpec} b second
 * @returns {RuntimeSpec} merged
@@ -315,6 +340,7 @@
      if (a.has(b)) return b;
      return;
   }
   /** @type {RuntimeSpecSortableSet} */
   const set = new SortableSet();
   for (const item of b) {
      if (a.has(item)) set.add(item);
@@ -328,6 +354,7 @@
};
/**
 * Returns result.
 * @param {RuntimeSpec} a first
 * @param {RuntimeSpec} b second
 * @returns {RuntimeSpec} result
@@ -354,10 +381,12 @@
            if (item !== b) return item;
         }
      }
      /** @type {RuntimeSpecSortableSet} */
      const set = new SortableSet(a);
      set.delete(b);
      return set;
   }
   /** @type {RuntimeSpecSortableSet} */
   const set = new SortableSet();
   for (const item of a) {
      if (!b.has(item)) set.add(item);
@@ -371,6 +400,7 @@
};
/**
 * Subtract runtime condition.
 * @param {RuntimeCondition} a first
 * @param {RuntimeCondition} b second
 * @param {RuntimeSpec} runtime runtime
@@ -385,6 +415,7 @@
};
/**
 * Returns true/false if filter is constant for all runtimes, otherwise runtimes that are active.
 * @param {RuntimeSpec} runtime runtime
 * @param {(runtime?: RuntimeSpec) => boolean} filter filter function
 * @returns {boolean | RuntimeSpec} true/false if filter is constant for all runtimes, otherwise runtimes that are active
@@ -394,6 +425,7 @@
   if (typeof runtime === "string") return filter(runtime);
   let some = false;
   let every = true;
   /** @type {RuntimeSpec} */
   let result;
   for (const r of runtime) {
      const v = filter(r);
@@ -410,16 +442,19 @@
};
/**
 * Defines the runtime spec map inner map type used by this module.
 * @template T
 * @typedef {Map<string, T>} RuntimeSpecMapInnerMap
 */
/**
 * Represents RuntimeSpecMap.
 * @template T
 * @template [R=T]
 */
class RuntimeSpecMap {
   /**
    * Creates an instance of RuntimeSpecMap.
    * @param {RuntimeSpecMap<T, R>=} clone copy form this
    */
   constructor(clone) {
@@ -434,6 +469,7 @@
   }
   /**
    * Returns value.
    * @param {RuntimeSpec} runtime the runtimes
    * @returns {R | undefined} value
    */
@@ -453,6 +489,7 @@
   }
   /**
    * Returns true, when the runtime is stored.
    * @param {RuntimeSpec} runtime the runtimes
    * @returns {boolean} true, when the runtime is stored
    */
@@ -470,6 +507,7 @@
   }
   /**
    * Updates default using the provided runtime.
    * @param {RuntimeSpec} runtime the runtimes
    * @param {R} value the value
    */
@@ -501,6 +539,7 @@
   }
   /**
    * Returns the new value.
    * @param {RuntimeSpec} runtime the runtimes
    * @param {() => R} computer function to compute the value
    * @returns {R} the new value
@@ -543,6 +582,7 @@
   }
   /**
    * Processes the provided runtime.
    * @param {RuntimeSpec} runtime the runtimes
    */
   delete(runtime) {
@@ -563,6 +603,7 @@
   }
   /**
    * Processes the provided runtime.
    * @param {RuntimeSpec} runtime the runtimes
    * @param {(value: R | undefined) => R} fn function to update the value
    */
@@ -620,6 +661,7 @@
   }
   /**
    * Returns values.
    * @returns {IterableIterator<R>} values
    */
   values() {
@@ -644,6 +686,7 @@
class RuntimeSpecSet {
   /**
    * Creates an instance of RuntimeSpecSet.
    * @param {Iterable<RuntimeSpec>=} iterable iterable
    */
   constructor(iterable) {
@@ -657,6 +700,7 @@
   }
   /**
    * Processes the provided runtime.
    * @param {RuntimeSpec} runtime runtime
    */
   add(runtime) {
@@ -664,6 +708,7 @@
   }
   /**
    * Returns true, when the runtime exists.
    * @param {RuntimeSpec} runtime runtime
    * @returns {boolean} true, when the runtime exists
    */
@@ -672,6 +717,7 @@
   }
   /**
    * Returns iterable iterator.
    * @returns {IterableIterator<RuntimeSpec>} iterable iterator
    */
   [Symbol.iterator]() {