From a1372720bedfaeec0a32d497fb107b69e01b334f Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Wed, 1 Oct 2025 21:58:37 +0100 Subject: [PATCH] refactor: modernize View#lookup - Replace ar loop with or...of for clarity and readability - Use const instead of ar to prevent accidental reassignment - Introduce explicit ound variable to avoid shadowing Node's path module - Add JSDoc to clarify input and return type --- lib/view.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/view.js b/lib/view.js index d66b4a2d89c..0e9b70f8a9e 100644 --- a/lib/view.js +++ b/lib/view.js @@ -98,28 +98,25 @@ function View(name, options) { * Lookup view by the given `name` * * @param {string} name + * @returns {(string|undefined)} The resolved absolute file path if found, otherwise `undefined`. * @private */ View.prototype.lookup = function lookup(name) { - var path; - var roots = [].concat(this.root); + const roots = [].concat(this.root); debug('lookup "%s"', name); - for (var i = 0; i < roots.length && !path; i++) { - var root = roots[i]; + for (const root of roots) { + const loc = resolve(root, name); + const dir = dirname(loc); + const file = basename(loc); - // resolve the path - var loc = resolve(root, name); - var dir = dirname(loc); - var file = basename(loc); - - // resolve the file - path = this.resolve(dir, file); + const found = this.resolve(dir, file); + if (found) return found; } - return path; + return undefined; }; /**