From cc4c12ad31be6b6d8432f257e112195179f7eafa Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 10 Oct 2023 07:59:49 -0300 Subject: find: fix error reporting for multiple name matches --- src/find.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/find.js') diff --git a/src/find.js b/src/find.js index c8edce9..5a249c2 100644 --- a/src/find.js +++ b/src/find.js @@ -34,11 +34,12 @@ export function processAllAvailableMatches(data, { const normalizedName = name.toLowerCase(); if (normalizedName in byName) { + const alreadyMatchesByName = byName[normalizedName]; byName[normalizedName] = null; if (normalizedName in multipleNameMatches) { multipleNameMatches[normalizedName].push(thing); } else { - multipleNameMatches[normalizedName] = [thing]; + multipleNameMatches[normalizedName] = [alreadyMatchesByName, thing]; } } else { byName[normalizedName] = thing; @@ -97,16 +98,21 @@ function findHelper({ const typePart = regexMatch[1]; const refPart = regexMatch[2]; + const normalizedName = + (typePart + ? null + : refPart.toLowerCase()); + const match = (typePart ? subcache.byDirectory[refPart] - : subcache.byName[refPart.toLowerCase()]); + : subcache.byName[normalizedName]); if (!match && !typePart) { - if (subcache.multipleNameMatches[refPart]) { + if (subcache.multipleNameMatches[normalizedName]) { return warnOrThrow(mode, `Multiple matches for reference "${fullRef}". Please resolve:\n` + - subcache.multipleNameMatches[refPart] + subcache.multipleNameMatches[normalizedName] .map(match => `- ${inspect(match)}\n`) .join('') + `Returning null for this reference.`); -- cgit 1.3.0-6-gf8a5