Skip to content

Commit

Permalink
path: refactor logic for to reduce code branches
Browse files Browse the repository at this point in the history
This refactoring makes sure some code branches will not be hit if
they do not have to be reached.

PR-URL: #25278
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
BridgeAR authored and addaleax committed Mar 1, 2019
1 parent 6c7cd9e commit 55d6b49
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,25 @@ const win32 = {
isAbsolute = true;
}

if (device.length > 0 &&
resolvedDevice.length > 0 &&
device.toLowerCase() !== resolvedDevice.toLowerCase()) {
// This path points to another device so it is not applicable
continue;
if (device.length > 0) {
if (resolvedDevice.length > 0) {
if (device.toLowerCase() !== resolvedDevice.toLowerCase())
// This path points to another device so it is not applicable
continue;
} else {
resolvedDevice = device;
}
}

if (resolvedDevice.length === 0 && device.length > 0) {
resolvedDevice = device;
}
if (!resolvedAbsolute) {
resolvedTail = path.slice(rootEnd) + '\\' + resolvedTail;
if (resolvedAbsolute) {
if (resolvedDevice.length > 0)
break;
} else {
resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
resolvedAbsolute = isAbsolute;
}

if (resolvedDevice.length > 0 && resolvedAbsolute) {
break;
if (isAbsolute && resolvedDevice.length > 0) {
break;
}
}
}

Expand Down

0 comments on commit 55d6b49

Please sign in to comment.