From e81ab1cd8ac5b51f12f12d21e861b6adb3d7654f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 30 Oct 2016 20:12:25 -0700 Subject: [PATCH] repl: refactor lib/repl.js * remove unnecessary backslash (`\`) escaping in regular expressions * favor `===` over `==` * multiline arrays indentation consistent with other indentation PR-URL: https://github.com/nodejs/node/pull/9374 Reviewed-By: Rod Vagg Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Roman Reiss --- lib/repl.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 284c4a381d0a3b..512ac39cea31a6 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -39,12 +39,12 @@ const parentModule = module; const replMap = new WeakMap(); const GLOBAL_OBJECT_PROPERTIES = ['NaN', 'Infinity', 'undefined', - 'eval', 'parseInt', 'parseFloat', 'isNaN', 'isFinite', 'decodeURI', - 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', - 'Object', 'Function', 'Array', 'String', 'Boolean', 'Number', - 'Date', 'RegExp', 'Error', 'EvalError', 'RangeError', - 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError', - 'Math', 'JSON']; + 'eval', 'parseInt', 'parseFloat', 'isNaN', 'isFinite', 'decodeURI', + 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', + 'Object', 'Function', 'Array', 'String', 'Boolean', 'Number', + 'Date', 'RegExp', 'Error', 'EvalError', 'RangeError', + 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError', + 'Math', 'JSON']; const GLOBAL_OBJECT_PROPERTY_MAP = {}; GLOBAL_OBJECT_PROPERTIES.forEach((p) => GLOBAL_OBJECT_PROPERTY_MAP[p] = p); @@ -622,7 +622,7 @@ ArrayStream.prototype.writable = true; ArrayStream.prototype.resume = function() {}; ArrayStream.prototype.write = function() {}; -const requireRE = /\brequire\s*\(['"](([\w\.\/-]+\/)?([\w\.\/-]*))/; +const requireRE = /\brequire\s*\(['"](([\w./-]+\/)?([\w./-]*))/; const simpleExpressionRE = /(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/; @@ -870,7 +870,7 @@ REPLServer.prototype.complete = function(line, callback) { var newCompletionGroups = []; for (i = 0; i < completionGroups.length; i++) { group = completionGroups[i].filter(function(elem) { - return elem.indexOf(filter) == 0; + return elem.indexOf(filter) === 0; }); if (group.length) { newCompletionGroups.push(group); @@ -1124,8 +1124,8 @@ function regexpEscape(s) { * @return {String} The converted command. */ REPLServer.prototype.convertToContext = function(cmd) { - const scopeVar = /^\s*var\s*([_\w\$]+)(.*)$/m; - const scopeFunc = /^\s*function\s*([_\w\$]+)/; + const scopeVar = /^\s*var\s*([\w$]+)(.*)$/m; + const scopeFunc = /^\s*function\s*([\w$]+)/; var matches; // Replaces: var foo = "bar"; with: self.context.foo = bar;