Skip to content

Commit 7a2a551

Browse files
committed
fs: refactor redeclared variables
Two variables are declared twice with `var` in the same scope in `lib/fs.js`. This change refactors the code so the variable is declared just once. PR-URL: #4959 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 8796450 commit 7a2a551

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/fs.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,18 +1460,14 @@ fs.unwatchFile = function(filename, listener) {
14601460

14611461
// Regexp that finds the next partion of a (partial) path
14621462
// result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
1463-
if (isWindows) {
1464-
var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
1465-
} else {
1466-
var nextPartRe = /(.*?)(?:[\/]+|$)/g;
1467-
}
1463+
const nextPartRe = isWindows ?
1464+
/(.*?)(?:[\/\\]+|$)/g :
1465+
/(.*?)(?:[\/]+|$)/g;
14681466

14691467
// Regex to find the device root, including trailing slash. E.g. 'c:\\'.
1470-
if (isWindows) {
1471-
var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
1472-
} else {
1473-
var splitRootRe = /^[\/]*/;
1474-
}
1468+
const splitRootRe = isWindows ?
1469+
/^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/ :
1470+
/^[\/]*/;
14751471

14761472
fs.realpathSync = function realpathSync(p, cache) {
14771473
// make p is absolute

0 commit comments

Comments
 (0)