path: minor refactoring

1) Consolidate nested if statements if possible
     `if (foo) { if bar () { /* do stuff */ } }`)
   to reduce indentation depth.
2) Remove obsolete else cases to reduce indentation.

PR-URL: https://github.com/nodejs/node/pull/25278
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Ruben Bridgewater 2019-01-27 15:23:21 +01:00
parent a019d7bd0b
commit f59fdd9d65
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -206,22 +206,18 @@ const win32 = {
} else { } else {
rootEnd = 1; rootEnd = 1;
} }
} else if (isWindowsDeviceRoot(code)) { } else if (isWindowsDeviceRoot(code) &&
path.charCodeAt(1) === CHAR_COLON) {
// Possible device root // Possible device root
if (path.charCodeAt(1) === CHAR_COLON) {
device = path.slice(0, 2); device = path.slice(0, 2);
rootEnd = 2; rootEnd = 2;
if (len > 2) { if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
if (isPathSeparator(path.charCodeAt(2))) {
// Treat separator following drive name as an absolute path // Treat separator following drive name as an absolute path
// indicator // indicator
isAbsolute = true; isAbsolute = true;
rootEnd = 3; rootEnd = 3;
} }
} }
}
}
} else if (isPathSeparator(code)) { } else if (isPathSeparator(code)) {
// `path` contains just a path separator // `path` contains just a path separator
rootEnd = 1; rootEnd = 1;
@ -567,26 +563,23 @@ const win32 = {
const resolvedPath = win32.resolve(path); const resolvedPath = win32.resolve(path);
if (resolvedPath.length >= 3) { if (resolvedPath.length <= 2)
return path;
if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) { if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
// Possible UNC root // Possible UNC root
if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) { if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
const code = resolvedPath.charCodeAt(2); const code = resolvedPath.charCodeAt(2);
if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) { if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
// Matched non-long UNC root, convert the path to a long UNC path // Matched non-long UNC root, convert the path to a long UNC path
return '\\\\?\\UNC\\' + resolvedPath.slice(2); return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
} }
} }
} else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0))) { } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) &&
// Possible device root resolvedPath.charCodeAt(1) === CHAR_COLON &&
if (resolvedPath.charCodeAt(1) === CHAR_COLON &&
resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) { resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
// Matched device root, convert the path to a long UNC path // Matched device root, convert the path to a long UNC path
return '\\\\?\\' + resolvedPath; return `\\\\?\\${resolvedPath}`;
}
}
} }
return path; return path;
@ -749,7 +742,7 @@ const win32 = {
else if (end === -1) else if (end === -1)
end = path.length; end = path.length;
return path.slice(start, end); return path.slice(start, end);
} else { }
for (i = path.length - 1; i >= start; --i) { for (i = path.length - 1; i >= start; --i) {
if (isPathSeparator(path.charCodeAt(i))) { if (isPathSeparator(path.charCodeAt(i))) {
// If we reached a path separator that was not part of a set of path // If we reached a path separator that was not part of a set of path
@ -769,10 +762,8 @@ const win32 = {
if (end === -1) if (end === -1)
return ''; return '';
return path.slice(start, end); return path.slice(start, end);
}
}, },
extname(path) { extname(path) {
validateString(path, 'path'); validateString(path, 'path');
var start = 0; var start = 0;
@ -1256,7 +1247,7 @@ const posix = {
else if (end === -1) else if (end === -1)
end = path.length; end = path.length;
return path.slice(start, end); return path.slice(start, end);
} else { }
for (i = path.length - 1; i >= 0; --i) { for (i = path.length - 1; i >= 0; --i) {
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) { if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
// If we reached a path separator that was not part of a set of path // If we reached a path separator that was not part of a set of path
@ -1276,10 +1267,8 @@ const posix = {
if (end === -1) if (end === -1)
return ''; return '';
return path.slice(start, end); return path.slice(start, end);
}
}, },
extname(path) { extname(path) {
validateString(path, 'path'); validateString(path, 'path');
var startDot = -1; var startDot = -1;