WXL
3 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
node_modules/enhanced-resolve/lib/util/entrypoints.js
@@ -7,10 +7,10 @@
const { parseIdentifier } = require("./identifier");
/** @typedef {string|(string|ConditionalMapping)[]} DirectMapping */
/** @typedef {{[k: string]: MappingValue}} ConditionalMapping */
/** @typedef {ConditionalMapping|DirectMapping|null} MappingValue */
/** @typedef {Record<string, MappingValue>|ConditionalMapping|DirectMapping} ExportsField */
/** @typedef {string | (string | ConditionalMapping)[]} DirectMapping */
/** @typedef {{ [k: string]: MappingValue }} ConditionalMapping */
/** @typedef {ConditionalMapping | DirectMapping | null} MappingValue */
/** @typedef {Record<string, MappingValue> | ConditionalMapping | DirectMapping} ExportsField */
/** @typedef {Record<string, MappingValue>} ImportsField */
/**
@@ -104,7 +104,7 @@
 * Trying to match request to field
 * @param {string} request request
 * @param {ExportsField | ImportsField} field exports or import field
 * @returns {[MappingValue, string, boolean, boolean, string]|null} match or null, number is negative and one less when it's a folder mapping, number is request.length + 1 for direct mappings
 * @returns {[MappingValue, string, boolean, boolean, string] | null} match or null, number is negative and one less when it's a folder mapping, number is request.length + 1 for direct mappings
 */
function findMatch(request, field) {
   if (
@@ -112,14 +112,16 @@
      !request.includes("*") &&
      !request.endsWith("/")
   ) {
      const target = /** @type {{[k: string]: MappingValue}} */ (field)[request];
      const target = /** @type {{ [k: string]: MappingValue }} */ (field)[
         request
      ];
      return [target, "", false, false, request];
   }
   /** @type {string} */
   let bestMatch = "";
   /** @type {string|undefined} */
   /** @type {string | undefined} */
   let bestMatchSubpath;
   const keys = Object.getOwnPropertyNames(field);
@@ -157,7 +159,9 @@
   if (bestMatch === "") return null;
   const target = /** @type {{[k: string]: MappingValue}} */ (field)[bestMatch];
   const target =
      /** @type {{ [k: string]: MappingValue }} */
      (field)[bestMatch];
   const isSubpathMapping = bestMatch.endsWith("/");
   const isPattern = bestMatch.includes("*");
@@ -171,7 +175,7 @@
}
/**
 * @param {ConditionalMapping | DirectMapping|null} mapping mapping
 * @param {ConditionalMapping | DirectMapping | null} mapping mapping
 * @returns {boolean} is conditional mapping
 */
function isConditionalMapping(mapping) {
@@ -274,10 +278,10 @@
}
/**
 * @param {string|undefined} remainingRequest remaining request when folder mapping, undefined for file mappings
 * @param {string | undefined} remainingRequest remaining request when folder mapping, undefined for file mappings
 * @param {boolean} isPattern true, if mapping is a pattern (contains "*")
 * @param {boolean} isSubpathMapping true, for subpath mappings
 * @param {DirectMapping|null} mappingTarget direct export
 * @param {DirectMapping | null} mappingTarget direct export
 * @param {Set<string>} conditionNames condition names
 * @param {(d: string, f: boolean) => void} assert asserting direct value
 * @returns {string[]} mapping result