From 6e394d63edd96432e0d99ed1edc41138645ee194 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 29 Jan 2016 14:03:13 -0800 Subject: [PATCH 1/2] 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. --- lib/fs.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index af8001bb181698..5c8eee46a16a91 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1460,17 +1460,19 @@ 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'] +var nextPartRe; if (isWindows) { - var nextPartRe = /(.*?)(?:[\/\\]+|$)/g; + nextPartRe = /(.*?)(?:[\/\\]+|$)/g; } else { - var nextPartRe = /(.*?)(?:[\/]+|$)/g; + nextPartRe = /(.*?)(?:[\/]+|$)/g; } // Regex to find the device root, including trailing slash. E.g. 'c:\\'. +var splitRootRe; if (isWindows) { - var splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/; + splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/; } else { - var splitRootRe = /^[\/]*/; + splitRootRe = /^[\/]*/; } fs.realpathSync = function realpathSync(p, cache) { From 9a372e51427fd8b8f50e40f18db0f5917c397105 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 1 Feb 2016 11:47:22 -0800 Subject: [PATCH 2/2] fixup per jasnell --- lib/fs.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 5c8eee46a16a91..81c5c7533a86d8 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1460,20 +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'] -var nextPartRe; -if (isWindows) { - nextPartRe = /(.*?)(?:[\/\\]+|$)/g; -} else { - nextPartRe = /(.*?)(?:[\/]+|$)/g; -} +const nextPartRe = isWindows ? + /(.*?)(?:[\/\\]+|$)/g : + /(.*?)(?:[\/]+|$)/g; // Regex to find the device root, including trailing slash. E.g. 'c:\\'. -var splitRootRe; -if (isWindows) { - splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/; -} else { - splitRootRe = /^[\/]*/; -} +const splitRootRe = isWindows ? + /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/ : + /^[\/]*/; fs.realpathSync = function realpathSync(p, cache) { // make p is absolute