fs: refactor redeclared variables
authorRich Trott <rtrott@gmail.com>
Fri, 29 Jan 2016 22:03:13 +0000 (14:03 -0800)
committerMyles Borins <mborins@us.ibm.com>
Wed, 2 Mar 2016 22:01:11 +0000 (14:01 -0800)
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: https://github.com/nodejs/node/pull/4959
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
lib/fs.js

index 7bfc21c..3deb309 100644 (file)
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1367,18 +1367,14 @@ fs.unwatchFile = function(filename, listener) {
 
 // Regexp that finds the next partion of a (partial) path
 // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
-if (isWindows) {
-  var nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
-} else {
-  var nextPartRe = /(.*?)(?:[\/]+|$)/g;
-}
+const nextPartRe = isWindows ?
+  /(.*?)(?:[\/\\]+|$)/g :
+  /(.*?)(?:[\/]+|$)/g;
 
 // Regex to find the device root, including trailing slash. E.g. 'c:\\'.
-if (isWindows) {
-  var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
-} else {
-  var splitRootRe = /^[\/]*/;
-}
+const splitRootRe = isWindows ?
+  /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/ :
+  /^[\/]*/;
 
 fs.realpathSync = function realpathSync(p, cache) {
   // make p is absolute