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 <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>
This commit is contained in:
parent
3c1e5b366f
commit
5cbb7a887a
20
lib/repl.js
20
lib/repl.js
@ -40,12 +40,12 @@ const parentModule = module;
|
|||||||
const replMap = new WeakMap();
|
const replMap = new WeakMap();
|
||||||
|
|
||||||
const GLOBAL_OBJECT_PROPERTIES = ['NaN', 'Infinity', 'undefined',
|
const GLOBAL_OBJECT_PROPERTIES = ['NaN', 'Infinity', 'undefined',
|
||||||
'eval', 'parseInt', 'parseFloat', 'isNaN', 'isFinite', 'decodeURI',
|
'eval', 'parseInt', 'parseFloat', 'isNaN', 'isFinite', 'decodeURI',
|
||||||
'decodeURIComponent', 'encodeURI', 'encodeURIComponent',
|
'decodeURIComponent', 'encodeURI', 'encodeURIComponent',
|
||||||
'Object', 'Function', 'Array', 'String', 'Boolean', 'Number',
|
'Object', 'Function', 'Array', 'String', 'Boolean', 'Number',
|
||||||
'Date', 'RegExp', 'Error', 'EvalError', 'RangeError',
|
'Date', 'RegExp', 'Error', 'EvalError', 'RangeError',
|
||||||
'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',
|
'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',
|
||||||
'Math', 'JSON'];
|
'Math', 'JSON'];
|
||||||
const GLOBAL_OBJECT_PROPERTY_MAP = {};
|
const GLOBAL_OBJECT_PROPERTY_MAP = {};
|
||||||
GLOBAL_OBJECT_PROPERTIES.forEach((p) => GLOBAL_OBJECT_PROPERTY_MAP[p] = p);
|
GLOBAL_OBJECT_PROPERTIES.forEach((p) => GLOBAL_OBJECT_PROPERTY_MAP[p] = p);
|
||||||
|
|
||||||
@ -783,7 +783,7 @@ ArrayStream.prototype.writable = true;
|
|||||||
ArrayStream.prototype.resume = function() {};
|
ArrayStream.prototype.resume = function() {};
|
||||||
ArrayStream.prototype.write = function() {};
|
ArrayStream.prototype.write = function() {};
|
||||||
|
|
||||||
const requireRE = /\brequire\s*\(['"](([\w\.\/-]+\/)?([\w\.\/-]*))/;
|
const requireRE = /\brequire\s*\(['"](([\w./-]+\/)?([\w./-]*))/;
|
||||||
const simpleExpressionRE =
|
const simpleExpressionRE =
|
||||||
/(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/;
|
/(([a-zA-Z_$](?:\w|\$)*)\.)*([a-zA-Z_$](?:\w|\$)*)\.?$/;
|
||||||
|
|
||||||
@ -1036,7 +1036,7 @@ function complete(line, callback) {
|
|||||||
var newCompletionGroups = [];
|
var newCompletionGroups = [];
|
||||||
for (i = 0; i < completionGroups.length; i++) {
|
for (i = 0; i < completionGroups.length; i++) {
|
||||||
group = completionGroups[i].filter(function(elem) {
|
group = completionGroups[i].filter(function(elem) {
|
||||||
return elem.indexOf(filter) == 0;
|
return elem.indexOf(filter) === 0;
|
||||||
});
|
});
|
||||||
if (group.length) {
|
if (group.length) {
|
||||||
newCompletionGroups.push(group);
|
newCompletionGroups.push(group);
|
||||||
@ -1341,8 +1341,8 @@ function regexpEscape(s) {
|
|||||||
// TODO(princejwesley): Remove it prior to v8.0.0 release
|
// TODO(princejwesley): Remove it prior to v8.0.0 release
|
||||||
// Reference: https://github.com/nodejs/node/pull/7829
|
// Reference: https://github.com/nodejs/node/pull/7829
|
||||||
REPLServer.prototype.convertToContext = util.deprecate(function(cmd) {
|
REPLServer.prototype.convertToContext = util.deprecate(function(cmd) {
|
||||||
const scopeVar = /^\s*var\s*([_\w\$]+)(.*)$/m;
|
const scopeVar = /^\s*var\s*([\w$]+)(.*)$/m;
|
||||||
const scopeFunc = /^\s*function\s*([_\w\$]+)/;
|
const scopeFunc = /^\s*function\s*([\w$]+)/;
|
||||||
var matches;
|
var matches;
|
||||||
|
|
||||||
// Replaces: var foo = "bar"; with: self.context.foo = bar;
|
// Replaces: var foo = "bar"; with: self.context.foo = bar;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user