path: remove dead code · nodejs/node@b62739c (original) (raw)

`@@ -1054,29 +1054,18 @@ const posix = {

`

1054

1054

`if (from === to)

`

1055

1055

`return '';

`

1056

1056

``

``

1057

`+

// Trim leading forward slashes.

`

1057

1058

`from = posix.resolve(from);

`

1058

1059

`to = posix.resolve(to);

`

1059

1060

``

1060

1061

`if (from === to)

`

1061

1062

`return '';

`

1062

1063

``

1063

``

`-

// Trim any leading backslashes

`

1064

``

`-

let fromStart = 1;

`

1065

``

`-

while (fromStart < from.length &&

`

1066

``

`-

from.charCodeAt(fromStart) === CHAR_FORWARD_SLASH) {

`

1067

``

`-

fromStart++;

`

1068

``

`-

}

`

``

1064

`+

const fromStart = 1;

`

1069

1065

`const fromEnd = from.length;

`

1070

``

`-

const fromLen = (fromEnd - fromStart);

`

1071

``

-

1072

``

`-

// Trim any leading backslashes

`

1073

``

`-

let toStart = 1;

`

1074

``

`-

while (toStart < to.length &&

`

1075

``

`-

to.charCodeAt(toStart) === CHAR_FORWARD_SLASH) {

`

1076

``

`-

toStart++;

`

1077

``

`-

}

`

1078

``

`-

const toEnd = to.length;

`

1079

``

`-

const toLen = (toEnd - toStart);

`

``

1066

`+

const fromLen = fromEnd - fromStart;

`

``

1067

`+

const toStart = 1;

`

``

1068

`+

const toLen = to.length - toStart;

`

1080

1069

``

1081

1070

`// Compare paths to find the longest common path from root

`

1082

1071

`const length = (fromLen < toLen ? fromLen : toLen);

`

`@@ -1101,38 +1090,26 @@ const posix = {

`

1101

1090

`// For example: from='/'; to='/foo'

`

1102

1091

`return to.slice(toStart + i);

`

1103

1092

`}

`

1104

``

`-

} else if (fromLen > length) {

`

1105

``

`-

if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {

`

1106

``

`` -

// We get here if to is the exact base path for from.

``

1107

``

`-

// For example: from='/foo/bar/baz'; to='/foo/bar'

`

1108

``

`-

lastCommonSep = i;

`

1109

``

`-

} else if (i === 0) {

`

1110

``

`` -

// We get here if to is the root.

``

1111

``

`-

// For example: from='/foo'; to='/'

`

1112

``

`-

lastCommonSep = 0;

`

1113

``

`-

}

`

``

1093

`+

} else if (fromLen > length &&

`

``

1094

`+

from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {

`

``

1095

`` +

// We get here if to is the exact base path for from.

``

``

1096

`+

// For example: from='/foo/bar/baz'; to='/foo/bar'

`

``

1097

`+

lastCommonSep = i;

`

1114

1098

`}

`

1115

1099

`}

`

1116

1100

``

1117

``

`-

var out = '';

`

``

1101

`+

let out = '';

`

1118

1102

`` // Generate the relative path based on the path difference between to

``

1119

``

`` -

// and from

``

``

1103

`` +

// and from.

``

1120

1104

`for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {

`

1121

1105

`if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {

`

1122

1106

`out += out.length === 0 ? '..' : '/..';

`

1123

1107

`}

`

1124

1108

`}

`

1125

1109

``

1126

``

`-

toStart += lastCommonSep;

`

1127

``

-

1128

1110

`` // Lastly, append the rest of the destination (to) path that comes after

``

1129

``

`-

// the common path parts

`

1130

``

`-

if (out.length > 0)

`

1131

``

`` -

return ${out}${to.slice(toStart)};

``

1132

``

-

1133

``

`-

if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH)

`

1134

``

`-

++toStart;

`

1135

``

`-

return to.slice(toStart);

`

``

1111

`+

// the common path parts.

`

``

1112

`` +

return ${out}${to.slice(toStart + lastCommonSep)};

``

1136

1113

`},

`

1137

1114

``

1138

1115

`toNamespacedPath(path) {

`