From 7a2a5513b8e243ff377f0b35d2d0bea1ab0d52f9 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 29 Jan 2016 14:03:13 -0800 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/4959 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Brian White Reviewed-By: Ben Noordhuis --- lib/fs.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index af8001bb181698..81c5c7533a86d8 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1460,18 +1460,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