diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-11-14 18:19:45 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-11-15 20:40:12 -0400 |
commit | 7360804a1d99e8665cad8977755350543a16ccfa (patch) | |
tree | 9ed74b8a59e49877a396d2c54c1c0a6f3bbef56d /src/find.js | |
parent | 1effe97c83585e4ba7bab68bafdbee733a6a25b4 (diff) |
find: prefer if-style branching in findHelper/mixedFindHelper
Diffstat (limited to 'src/find.js')
-rw-r--r-- | src/find.js | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/src/find.js b/src/find.js index b2d32f80..2c97142f 100644 --- a/src/find.js +++ b/src/find.js @@ -141,24 +141,23 @@ function findHelper({ const {key: keyPart, ref: refPart} = regexMatch.groups; - if (keyPart && !referenceTypes.includes(keyPart)) { - return warnOrThrow(mode, - `Reference starts with "${keyPart}:", expected ` + - referenceTypes.map(type => `"${type}:"`).join(', ')); - } + let match; + + if (keyPart) { + if (!referenceTypes.includes(keyPart)) { + return warnOrThrow(mode, + `Reference starts with "${keyPart}:", expected ` + + referenceTypes.map(type => `"${type}:"`).join(', ')); + } - const normalizedName = - (keyPart - ? null - : refPart.toLowerCase()); + match = subcache.byDirectory[refPart]; + } else { + const normalizedName = + refPart.toLowerCase(); - const match = - (keyPart - ? subcache.byDirectory[refPart] - : subcache.byName[normalizedName]); + match = subcache.byName[normalizedName]; - if (!match && !keyPart) { - if (subcache.multipleNameMatches[normalizedName]) { + if (!match && subcache.multipleNameMatches[normalizedName]) { return warnOrThrow(mode, `Multiple matches for reference "${fullRef}". Please resolve:\n` + subcache.multipleNameMatches[normalizedName] @@ -293,24 +292,25 @@ function findMixedHelper(config) { const {key: keyPart, ref: refPart} = regexMatch.groups; - if (keyPart && !referenceTypes.includes(keyPart)) { - return warnOrThrow(mode, - `Reference starts with "${keyPart}:", expected ` + - referenceTypes.map(type => `"${type}:"`).join(', ')); - } + let match; + + if (keyPart) { + if (!referenceTypes.includes(keyPart)) { + return warnOrThrow(mode, + `Reference starts with "${keyPart}:", expected ` + + referenceTypes.map(type => `"${type}:"`).join(', ')); + } - const normalizedName = - (keyPart - ? null - : refPart.toLowerCase()); + // TODO: Do something + match = null; + } else { + const normalizedName = + refPart.toLowerCase(); - const match = - (keyPart - ? null /* TODO: Do something */ - : byName[normalizedName]); + match = + byName[normalizedName]; - if (!match && !keyPart) { - if (multipleNameMatches[normalizedName]) { + if (!match && multipleNameMatches[normalizedName]) { return warnOrThrow(mode, `Multiple matches for reference "${fullRef}". Please resolve:\n` + multipleNameMatches[normalizedName] |