Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e00c8cd

Browse filesBrowse files
BridgeARaddaleax
authored andcommitted
path: simplify code and remove obsolete checks
Either `end` is `-1` or `startPart` is not `0`. Therefore it's possible to move the conditions in a way that we eliminate a few code branches. PR-URL: #25278 Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 55d6b49 commit e00c8cd
Copy full SHA for e00c8cd

File tree

Expand file treeCollapse file tree

1 file changed

+25
-34
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-34
lines changed
Open diff view settings
Collapse file

‎lib/path.js‎

Copy file name to clipboardExpand all lines: lib/path.js
+25-34Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -960,21 +960,20 @@ const win32 = {
960960
}
961961
}
962962

963-
if (startDot === -1 ||
964-
end === -1 ||
965-
// We saw a non-dot character immediately before the dot
966-
preDotState === 0 ||
967-
// The (right-most) trimmed path component is exactly '..'
968-
(preDotState === 1 &&
969-
startDot === end - 1 &&
970-
startDot === startPart + 1)) {
971-
if (end !== -1) {
963+
if (end !== -1) {
964+
if (startDot === -1 ||
965+
// We saw a non-dot character immediately before the dot
966+
preDotState === 0 ||
967+
// The (right-most) trimmed path component is exactly '..'
968+
(preDotState === 1 &&
969+
startDot === end - 1 &&
970+
startDot === startPart + 1)) {
972971
ret.base = ret.name = path.slice(startPart, end);
972+
} else {
973+
ret.name = path.slice(startPart, startDot);
974+
ret.base = path.slice(startPart, end);
975+
ret.ext = path.slice(startDot, end);
973976
}
974-
} else {
975-
ret.name = path.slice(startPart, startDot);
976-
ret.base = path.slice(startPart, end);
977-
ret.ext = path.slice(startDot, end);
978977
}
979978

980979
// If the directory is the root, use the entire root as the `dir` including
@@ -1380,29 +1379,21 @@ const posix = {
13801379
}
13811380
}
13821381

1383-
if (startDot === -1 ||
1384-
end === -1 ||
1385-
// We saw a non-dot character immediately before the dot
1386-
preDotState === 0 ||
1387-
// The (right-most) trimmed path component is exactly '..'
1388-
(preDotState === 1 &&
1389-
startDot === end - 1 &&
1390-
startDot === startPart + 1)) {
1391-
if (end !== -1) {
1392-
if (startPart === 0 && isAbsolute)
1393-
ret.base = ret.name = path.slice(1, end);
1394-
else
1395-
ret.base = ret.name = path.slice(startPart, end);
1396-
}
1397-
} else {
1398-
if (startPart === 0 && isAbsolute) {
1399-
ret.name = path.slice(1, startDot);
1400-
ret.base = path.slice(1, end);
1382+
if (end !== -1) {
1383+
const start = startPart === 0 && isAbsolute ? 1 : startPart;
1384+
if (startDot === -1 ||
1385+
// We saw a non-dot character immediately before the dot
1386+
preDotState === 0 ||
1387+
// The (right-most) trimmed path component is exactly '..'
1388+
(preDotState === 1 &&
1389+
startDot === end - 1 &&
1390+
startDot === startPart + 1)) {
1391+
ret.base = ret.name = path.slice(start, end);
14011392
} else {
1402-
ret.name = path.slice(startPart, startDot);
1403-
ret.base = path.slice(startPart, end);
1393+
ret.name = path.slice(start, startDot);
1394+
ret.base = path.slice(start, end);
1395+
ret.ext = path.slice(startDot, end);
14041396
}
1405-
ret.ext = path.slice(startDot, end);
14061397
}
14071398

14081399
if (startPart > 0)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.