Skip to content

Commit

Permalink
repl: refactor lib/repl.js
Browse files Browse the repository at this point in the history
* remove unnecessary backslash (`\`) escaping in regular expressions
* favor `===` over `==`
* multiline arrays indentation consistent with other indentation

PR-URL: #9374
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
  • Loading branch information
Trott authored and MylesBorins committed Dec 13, 2016
1 parent 0f52358 commit 3d45b35
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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|\$)*)\.?$/;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3d45b35

Please sign in to comment.