Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
path: refactor logic for to reduce code branches
This refactoring makes sure some code branches will not be hit if
they do not have to be reached.
  • Loading branch information
BridgeAR committed Feb 28, 2019
commit 6b2c7a2fdcc39c8bec9696d336830f168526b4f1
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