Skip to content

Commit

Permalink
path: replace var with let in lib/path.js
Browse files Browse the repository at this point in the history
PR-URL: #30260
Refs: nodejs/code-and-learn#97
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
  • Loading branch information
peze authored and targos committed Dec 1, 2019
1 parent 75cb026 commit 2f2a8aa
Showing 1 changed file with 50 additions and 52 deletions.
102 changes: 50 additions & 52 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
let lastSlash = -1;
let dots = 0;
let code = 0;
for (var i = 0; i <= path.length; ++i) {
for (let i = 0; i <= path.length; ++i) {
if (i < path.length)
code = path.charCodeAt(i);
else if (isPathSeparator(code))
Expand Down Expand Up @@ -132,7 +132,7 @@ const win32 = {
let resolvedTail = '';
let resolvedAbsolute = false;

for (var i = args.length - 1; i >= -1; i--) {
for (let i = args.length - 1; i >= -1; i--) {
let path;
if (i >= 0) {
path = args[i];
Expand Down Expand Up @@ -370,7 +370,7 @@ const win32 = {

let joined;
let firstPart;
for (var i = 0; i < args.length; ++i) {
for (let i = 0; i < args.length; ++i) {
const arg = args[i];
validateString(arg, 'path');
if (arg.length > 0) {
Expand Down Expand Up @@ -644,7 +644,7 @@ const win32 = {

let end = -1;
let matchedSlash = true;
for (var i = len - 1; i >= offset; --i) {
for (let i = len - 1; i >= offset; --i) {
if (isPathSeparator(path.charCodeAt(i))) {
if (!matchedSlash) {
end = i;
Expand All @@ -669,10 +669,9 @@ const win32 = {
if (ext !== undefined)
validateString(ext, 'ext');
validateString(path, 'path');
var start = 0;
var end = -1;
var matchedSlash = true;
var i;
let start = 0;
let end = -1;
let matchedSlash = true;

// Check for a drive letter prefix so as not to mistake the following
// path separator as an extra separator at the end of the path that can be
Expand All @@ -686,9 +685,9 @@ const win32 = {
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
if (ext === path)
return '';
var extIdx = ext.length - 1;
var firstNonSlashEnd = -1;
for (i = path.length - 1; i >= start; --i) {
let extIdx = ext.length - 1;
let firstNonSlashEnd = -1;
for (let i = path.length - 1; i >= start; --i) {
const code = path.charCodeAt(i);
if (isPathSeparator(code)) {
// If we reached a path separator that was not part of a set of path
Expand Down Expand Up @@ -728,7 +727,7 @@ const win32 = {
end = path.length;
return path.slice(start, end);
}
for (i = path.length - 1; i >= start; --i) {
for (let i = path.length - 1; i >= start; --i) {
if (isPathSeparator(path.charCodeAt(i))) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
Expand All @@ -751,14 +750,14 @@ const win32 = {

extname(path) {
validateString(path, 'path');
var start = 0;
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
let start = 0;
let startDot = -1;
let startPart = 0;
let end = -1;
let matchedSlash = true;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
let preDotState = 0;

// Check for a drive letter prefix so as not to mistake the following
// path separator as an extra separator at the end of the path that can be
Expand All @@ -770,7 +769,7 @@ const win32 = {
start = startPart = 2;
}

for (var i = path.length - 1; i >= start; --i) {
for (let i = path.length - 1; i >= start; --i) {
const code = path.charCodeAt(i);
if (isPathSeparator(code)) {
// If we reached a path separator that was not part of a set of path
Expand Down Expand Up @@ -823,7 +822,7 @@ const win32 = {
return ret;

const len = path.length;
var rootEnd = 0;
let rootEnd = 0;
let code = path.charCodeAt(0);

if (len === 1) {
Expand Down Expand Up @@ -895,15 +894,15 @@ const win32 = {
if (rootEnd > 0)
ret.root = path.slice(0, rootEnd);

var startDot = -1;
var startPart = rootEnd;
var end = -1;
var matchedSlash = true;
var i = path.length - 1;
let startDot = -1;
let startPart = rootEnd;
let end = -1;
let matchedSlash = true;
let i = path.length - 1;

// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
let preDotState = 0;

// Get non-dir info
for (; i >= rootEnd; --i) {
Expand Down Expand Up @@ -975,7 +974,7 @@ const posix = {
let resolvedPath = '';
let resolvedAbsolute = false;

for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
const path = i >= 0 ? args[i] : process.cwd();

validateString(path, 'path');
Expand Down Expand Up @@ -1035,7 +1034,7 @@ const posix = {
if (args.length === 0)
return '.';
let joined;
for (var i = 0; i < args.length; ++i) {
for (let i = 0; i < args.length; ++i) {
const arg = args[i];
validateString(arg, 'path');
if (arg.length > 0) {
Expand Down Expand Up @@ -1130,9 +1129,9 @@ const posix = {
if (path.length === 0)
return '.';
const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
var end = -1;
var matchedSlash = true;
for (var i = path.length - 1; i >= 1; --i) {
let end = -1;
let matchedSlash = true;
for (let i = path.length - 1; i >= 1; --i) {
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
if (!matchedSlash) {
end = i;
Expand All @@ -1156,17 +1155,16 @@ const posix = {
validateString(ext, 'ext');
validateString(path, 'path');

var start = 0;
var end = -1;
var matchedSlash = true;
var i;
let start = 0;
let end = -1;
let matchedSlash = true;

if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
if (ext === path)
return '';
var extIdx = ext.length - 1;
var firstNonSlashEnd = -1;
for (i = path.length - 1; i >= 0; --i) {
let extIdx = ext.length - 1;
let firstNonSlashEnd = -1;
for (let i = path.length - 1; i >= 0; --i) {
const code = path.charCodeAt(i);
if (code === CHAR_FORWARD_SLASH) {
// If we reached a path separator that was not part of a set of path
Expand Down Expand Up @@ -1206,7 +1204,7 @@ const posix = {
end = path.length;
return path.slice(start, end);
}
for (i = path.length - 1; i >= 0; --i) {
for (let i = path.length - 1; i >= 0; --i) {
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
// If we reached a path separator that was not part of a set of path
// separators at the end of the string, stop now
Expand All @@ -1229,14 +1227,14 @@ const posix = {

extname(path) {
validateString(path, 'path');
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
let startDot = -1;
let startPart = 0;
let end = -1;
let matchedSlash = true;
// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
for (var i = path.length - 1; i >= 0; --i) {
let preDotState = 0;
for (let i = path.length - 1; i >= 0; --i) {
const code = path.charCodeAt(i);
if (code === CHAR_FORWARD_SLASH) {
// If we reached a path separator that was not part of a set of path
Expand Down Expand Up @@ -1288,22 +1286,22 @@ const posix = {
if (path.length === 0)
return ret;
const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
var start;
let start;
if (isAbsolute) {
ret.root = '/';
start = 1;
} else {
start = 0;
}
var startDot = -1;
var startPart = 0;
var end = -1;
var matchedSlash = true;
var i = path.length - 1;
let startDot = -1;
let startPart = 0;
let end = -1;
let matchedSlash = true;
let i = path.length - 1;

// Track the state of characters (if any) we see before our first dot and
// after any path separator we find
var preDotState = 0;
let preDotState = 0;

// Get non-dir info
for (; i >= start; --i) {
Expand Down

0 comments on commit 2f2a8aa

Please sign in to comment.