Skip to content

Commit 55d6b49

Browse files
BridgeARaddaleax
authored andcommitted
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. PR-URL: #25278 Reviewed-By: Michaël Zasso <[email protected]>
1 parent 6c7cd9e commit 55d6b49

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/path.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,25 @@ const win32 = {
224224
isAbsolute = true;
225225
}
226226

227-
if (device.length > 0 &&
228-
resolvedDevice.length > 0 &&
229-
device.toLowerCase() !== resolvedDevice.toLowerCase()) {
230-
// This path points to another device so it is not applicable
231-
continue;
227+
if (device.length > 0) {
228+
if (resolvedDevice.length > 0) {
229+
if (device.toLowerCase() !== resolvedDevice.toLowerCase())
230+
// This path points to another device so it is not applicable
231+
continue;
232+
} else {
233+
resolvedDevice = device;
234+
}
232235
}
233236

234-
if (resolvedDevice.length === 0 && device.length > 0) {
235-
resolvedDevice = device;
236-
}
237-
if (!resolvedAbsolute) {
238-
resolvedTail = path.slice(rootEnd) + '\\' + resolvedTail;
237+
if (resolvedAbsolute) {
238+
if (resolvedDevice.length > 0)
239+
break;
240+
} else {
241+
resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
239242
resolvedAbsolute = isAbsolute;
240-
}
241-
242-
if (resolvedDevice.length > 0 && resolvedAbsolute) {
243-
break;
243+
if (isAbsolute && resolvedDevice.length > 0) {
244+
break;
245+
}
244246
}
245247
}
246248

0 commit comments

Comments
 (0)