path: inline conditions

This condition can be inlined in the first `if` statement since
if the `path`'s length is 0, it'll be a empty string so we can
return that as there's no need for an extra `if` statement.

PR-URL: https://github.com/nodejs/node/pull/38613
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Voltrex 2021-05-10 01:24:43 +04:30 committed by James M Snell
parent d206aa36e2
commit 89f592cc82
No known key found for this signature in database
GPG Key ID: 7341B15C070877AC

View File

@ -617,13 +617,9 @@ const win32 = {
*/
toNamespacedPath(path) {
// Note: this will *probably* throw somewhere.
if (typeof path !== 'string')
if (typeof path !== 'string' || path.length === 0)
return path;
if (path.length === 0) {
return '';
}
const resolvedPath = win32.resolve(path);
if (resolvedPath.length <= 2)