From f874aa1552c9eac7d2c76c63b5a1aa1422f7aeed Mon Sep 17 00:00:00 2001 From: peze Date: Tue, 5 Nov 2019 12:39:42 +0800 Subject: [PATCH] path: replace var with let in lib/path.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/30260 Refs: https://github.com/nodejs/code-and-learn/issues/97 Reviewed-By: Ruben Bridgewater Reviewed-By: David Carlier Reviewed-By: Trivikram Kamat Reviewed-By: Anna Henningsen Reviewed-By: Gireesh Punathil Reviewed-By: Сковорода Никита Андреевич --- lib/path.js | 102 ++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/lib/path.js b/lib/path.js index 395fe1f35702c4..c5db4437a52408 100644 --- a/lib/path.js +++ b/lib/path.js @@ -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)) @@ -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]; @@ -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) { @@ -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; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) { @@ -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) { @@ -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'); @@ -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) { @@ -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; @@ -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 @@ -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 @@ -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 @@ -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) {