Skip to content

Commit a137272

Browse files
committed
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
1 parent 9a7afb2 commit a137272

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

‎lib/view.js‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,25 @@ function View(name, options) {
9898
* Lookup view by the given `name`
9999
*
100100
* @param {string} name
101+
* @returns {(string|undefined)} The resolved absolute file path if found, otherwise `undefined`.
101102
* @private
102103
*/
103104

104105
View.prototype.lookup = function lookup(name) {
105-
var path;
106-
var roots = [].concat(this.root);
106+
const roots = [].concat(this.root);
107107

108108
debug('lookup "%s"', name);
109109

110-
for (var i = 0; i < roots.length && !path; i++) {
111-
var root = roots[i];
110+
for (const root of roots) {
111+
const loc = resolve(root, name);
112+
const dir = dirname(loc);
113+
const file = basename(loc);
112114

113-
// resolve the path
114-
var loc = resolve(root, name);
115-
var dir = dirname(loc);
116-
var file = basename(loc);
117-
118-
// resolve the file
119-
path = this.resolve(dir, file);
115+
const found = this.resolve(dir, file);
116+
if (found) return found;
120117
}
121118

122-
return path;
119+
return undefined;
123120
};
124121

125122
/**

0 commit comments

Comments
 (0)