Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fd8de13

Browse files
BridgeARBethGriggs
authored andcommittedApr 9, 2019
path: refactor for less indentation
This just switches the statements in a way that it reduces the overall indentation. The function has a very deep indentation in general and this should improve the readability. PR-URL: #26917 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
1 parent 8069494 commit fd8de13

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed
 

‎lib/path.js

+43-43
Original file line numberDiff line numberDiff line change
@@ -165,63 +165,63 @@ const win32 = {
165165
const code = path.charCodeAt(0);
166166

167167
// Try to match a root
168-
if (len > 1) {
168+
if (len === 1) {
169169
if (isPathSeparator(code)) {
170-
// Possible UNC root
171-
172-
// If we started with a separator, we know we at least have an
173-
// absolute path of some kind (UNC or otherwise)
170+
// `path` contains just a path separator
171+
rootEnd = 1;
174172
isAbsolute = true;
173+
}
174+
} else if (isPathSeparator(code)) {
175+
// Possible UNC root
175176

176-
if (isPathSeparator(path.charCodeAt(1))) {
177-
// Matched double path separator at beginning
178-
let j = 2;
179-
let last = j;
180-
// Match 1 or more non-path separators
181-
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
177+
// If we started with a separator, we know we at least have an
178+
// absolute path of some kind (UNC or otherwise)
179+
isAbsolute = true;
180+
181+
if (isPathSeparator(path.charCodeAt(1))) {
182+
// Matched double path separator at beginning
183+
let j = 2;
184+
let last = j;
185+
// Match 1 or more non-path separators
186+
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
187+
j++;
188+
}
189+
if (j < len && j !== last) {
190+
const firstPart = path.slice(last, j);
191+
// Matched!
192+
last = j;
193+
// Match 1 or more path separators
194+
while (j < len && isPathSeparator(path.charCodeAt(j))) {
182195
j++;
183196
}
184197
if (j < len && j !== last) {
185-
const firstPart = path.slice(last, j);
186198
// Matched!
187199
last = j;
188-
// Match 1 or more path separators
189-
while (j < len && isPathSeparator(path.charCodeAt(j))) {
200+
// Match 1 or more non-path separators
201+
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
190202
j++;
191203
}
192-
if (j < len && j !== last) {
193-
// Matched!
194-
last = j;
195-
// Match 1 or more non-path separators
196-
while (j < len && !isPathSeparator(path.charCodeAt(j))) {
197-
j++;
198-
}
199-
if (j === len || j !== last) {
200-
// We matched a UNC root
201-
device = `\\\\${firstPart}\\${path.slice(last, j)}`;
202-
rootEnd = j;
203-
}
204+
if (j === len || j !== last) {
205+
// We matched a UNC root
206+
device = `\\\\${firstPart}\\${path.slice(last, j)}`;
207+
rootEnd = j;
204208
}
205209
}
206-
} else {
207-
rootEnd = 1;
208-
}
209-
} else if (isWindowsDeviceRoot(code) &&
210-
path.charCodeAt(1) === CHAR_COLON) {
211-
// Possible device root
212-
device = path.slice(0, 2);
213-
rootEnd = 2;
214-
if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
215-
// Treat separator following drive name as an absolute path
216-
// indicator
217-
isAbsolute = true;
218-
rootEnd = 3;
219210
}
211+
} else {
212+
rootEnd = 1;
213+
}
214+
} else if (isWindowsDeviceRoot(code) &&
215+
path.charCodeAt(1) === CHAR_COLON) {
216+
// Possible device root
217+
device = path.slice(0, 2);
218+
rootEnd = 2;
219+
if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
220+
// Treat separator following drive name as an absolute path
221+
// indicator
222+
isAbsolute = true;
223+
rootEnd = 3;
220224
}
221-
} else if (isPathSeparator(code)) {
222-
// `path` contains just a path separator
223-
rootEnd = 1;
224-
isAbsolute = true;
225225
}
226226

227227
if (device.length > 0) {

0 commit comments

Comments
 (0)
Please sign in to comment.