path: refactor for less indentation · nodejs/node@fd8de13 (original) (raw)
`@@ -165,63 +165,63 @@ const win32 = {
`
165
165
`const code = path.charCodeAt(0);
`
166
166
``
167
167
`// Try to match a root
`
168
``
`-
if (len > 1) {
`
``
168
`+
if (len === 1) {
`
169
169
`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;
`
174
172
`isAbsolute = true;
`
``
173
`+
}
`
``
174
`+
} else if (isPathSeparator(code)) {
`
``
175
`+
// Possible UNC root
`
175
176
``
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))) {
`
182
195
`j++;
`
183
196
`}
`
184
197
`if (j < len && j !== last) {
`
185
``
`-
const firstPart = path.slice(last, j);
`
186
198
`// Matched!
`
187
199
`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))) {
`
190
202
`j++;
`
191
203
`}
`
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;
`
204
208
`}
`
205
209
`}
`
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;
`
219
210
`}
`
``
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;
`
220
224
`}
`
221
``
`-
} else if (isPathSeparator(code)) {
`
222
``
`` -
// path
contains just a path separator
``
223
``
`-
rootEnd = 1;
`
224
``
`-
isAbsolute = true;
`
225
225
`}
`
226
226
``
227
227
`if (device.length > 0) {
`