| | |
| | | |
| | | 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 */ |
| | | |
| | | /** |
| | |
| | | * 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 ( |
| | |
| | | !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); |
| | |
| | | |
| | | 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("*"); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * @param {ConditionalMapping | DirectMapping|null} mapping mapping |
| | | * @param {ConditionalMapping | DirectMapping | null} mapping mapping |
| | | * @returns {boolean} is conditional mapping |
| | | */ |
| | | function isConditionalMapping(mapping) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * @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 |