Skip to content

Commit e42ca5c

Browse files
authored
path: remove repetitive conditional operator in posix.resolve
PR-URL: #54835 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d496d44 commit e42ca5c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/path.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,8 @@ const posix = {
11921192
let resolvedAbsolute = false;
11931193
let slashCheck = false;
11941194

1195-
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1196-
const path = i >= 0 ? args[i] : posixCwd();
1195+
for (let i = args.length - 1; i >= 0 && !resolvedAbsolute; i--) {
1196+
const path = args[i];
11971197
validateString(path, `paths[${i}]`);
11981198

11991199
// Skip empty entries
@@ -1215,6 +1215,13 @@ const posix = {
12151215
StringPrototypeCharCodeAt(path, 0) === CHAR_FORWARD_SLASH;
12161216
}
12171217

1218+
if (!resolvedAbsolute) {
1219+
const cwd = posixCwd();
1220+
resolvedPath = `${cwd}/${resolvedPath}`;
1221+
resolvedAbsolute =
1222+
StringPrototypeCharCodeAt(cwd, 0) === CHAR_FORWARD_SLASH;
1223+
}
1224+
12181225
// At this point the path should be resolved to a full absolute path, but
12191226
// handle relative paths to be safe (might happen when process.cwd() fails)
12201227

0 commit comments

Comments
 (0)