diff --git a/lib/repl.js b/lib/repl.js index 98fd78eacaa5e5..19ea965f1cdbec 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -80,7 +80,7 @@ const kBufferedCommandSymbol = Symbol('bufferedCommand'); const kContextId = Symbol('contextId'); try { - // hack for require.resolve("./relative") to work properly. + // Hack for require.resolve("./relative") to work properly. module.filename = path.resolve('repl'); } catch (e) { // path.resolve('repl') fails when the current working directory has been @@ -90,7 +90,7 @@ try { module.filename = path.resolve(dirname, 'repl'); } -// hack for repl require to work properly with node_modules folders +// Hack for repl require to work properly with node_modules folders module.paths = Module._nodeModulePaths(module.filename); // If obj.hasOwnProperty has been overridden, then calling @@ -100,7 +100,6 @@ function hasOwnProperty(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } - // Can overridden with custom print functions, such as `probe` or `eyes.js`. // This is the default "writer" value if none is passed in the REPL options. const writer = exports.writer = (obj) => util.inspect(obj, writer.options); @@ -109,7 +108,6 @@ writer.options = exports._builtinLibs = internalModule.builtinLibs; - function REPLServer(prompt, stream, eval_, @@ -152,7 +150,6 @@ function REPLServer(prompt, var self = this; self._domain = dom || domain.create(); - self.useGlobal = !!useGlobal; self.ignoreUndefined = !!ignoreUndefined; self.replMode = replMode || exports.REPL_MODE_SLOPPY; @@ -163,7 +160,7 @@ function REPLServer(prompt, // Context id for use with the inspector protocol. self[kContextId] = undefined; - // just for backwards compat, see github.com/joyent/node/pull/7127 + // Just for backwards compat, see github.com/joyent/node/pull/7127 self.rli = this; const savedRegExMatches = ['', '', '', '', '', '', '', '', '', '']; @@ -226,8 +223,7 @@ function REPLServer(prompt, } } - // first, create the Script object to check the syntax - + // First, create the Script object to check the syntax if (code === '\n') return cb(null); @@ -246,14 +242,14 @@ function REPLServer(prompt, } catch (e) { debug('parse error %j', code, e); if (wrappedCmd) { - // unwrap and try again + // Unwrap and try again wrappedCmd = false; awaitPromise = false; code = input; wrappedErr = e; continue; } - // preserve original error for wrapped command + // Preserve original error for wrapped command const error = wrappedErr || e; if (isRecoverableError(error, code)) err = new Recoverable(error); @@ -413,7 +409,7 @@ function REPLServer(prompt, if (!input && !output) { // legacy API, passing a 'stream'/'socket' option if (!stream) { - // use stdin and stdout as the default streams if none were given + // Use stdin and stdout as the default streams if none were given stream = process; } if (stream.stdin && stream.stdout) { @@ -463,7 +459,7 @@ function REPLServer(prompt, this.commands = Object.create(null); defineDefaultCommands(this); - // figure out which "writer" function to use + // Figure out which "writer" function to use self.writer = options.writer || exports.writer; if (options.useColors === undefined) { @@ -478,14 +474,14 @@ function REPLServer(prompt, } function filterInternalStackFrames(error, structuredStack) { - // search from the bottom of the call stack to + // Search from the bottom of the call stack to // find the first frame with a null function name if (typeof structuredStack !== 'object') return structuredStack; const idx = structuredStack.reverse().findIndex( (frame) => frame.getFunctionName() === null); - // if found, get rid of it and everything below it + // If found, get rid of it and everything below it structuredStack = structuredStack.splice(idx + 1); return structuredStack; } @@ -678,7 +674,7 @@ function REPLServer(prompt, return; } - // editor mode + // Editor mode if (key.ctrl && !key.shift) { switch (key.name) { case 'd': // End editor mode @@ -698,7 +694,7 @@ function REPLServer(prompt, case 'down': // Override next history item break; case 'tab': - // prevent double tab behavior + // Prevent double tab behavior self._previousKey = null; ttyWrite(d, key); break; @@ -955,10 +951,8 @@ function complete(line, callback) { } var completions; - - // list of completion lists, one for each inheritance "level" + // List of completion lists, one for each inheritance "level" var completionGroups = []; - var completeOn, i, group, c; // REPL commands (e.g. ".break"). @@ -1136,7 +1130,7 @@ function complete(line, callback) { } } } catch (e) { - //console.log("completion error walking prototype chain:" + e); + // console.log("completion error walking prototype chain:" + e); } } @@ -1179,7 +1173,7 @@ function complete(line, callback) { } if (completionGroups.length) { - var uniq = {}; // unique completions across all groups + var uniq = {}; // Unique completions across all groups completions = []; // Completion group 0 is the "closest" // (least far up the inheritance chain) @@ -1194,7 +1188,7 @@ function complete(line, callback) { uniq[c] = true; } } - completions.push(''); // separator btwn groups + completions.push(''); // Separator btwn groups } while (completions.length && completions[completions.length - 1] === '') { completions.pop(); @@ -1261,7 +1255,7 @@ function _memory(cmd) { self.lines = self.lines || []; self.lines.level = self.lines.level || []; - // save the line so I can do magic later + // Save the line so I can do magic later if (cmd) { // TODO should I tab the level? const len = self.lines.level.length ? self.lines.level.length - 1 : 0; @@ -1275,7 +1269,7 @@ function _memory(cmd) { // Because I can not tell the difference between a } that // closes an object literal and a } that closes a function if (cmd) { - // going down is { and ( e.g. function() { + // Going down is { and ( e.g. function() { // going up is } and ) var dw = cmd.match(/{|\(/g); var up = cmd.match(/}|\)/g); @@ -1286,8 +1280,8 @@ function _memory(cmd) { if (depth) { (function workIt() { if (depth > 0) { - // going... down. - // push the line#, depth count, and if the line is a function. + // Going... down. + // Push the line#, depth count, and if the line is a function. // Since JS only has functional scope I only need to remove // "function() {" lines, clearly this will not work for // "function() @@ -1299,16 +1293,16 @@ function _memory(cmd) { isFunction: /\bfunction\b/.test(cmd) }); } else if (depth < 0) { - // going... up. + // Going... up. var curr = self.lines.level.pop(); if (curr) { var tmp = curr.depth + depth; if (tmp < 0) { - //more to go, recurse + // More to go, recurse depth += curr.depth; workIt(); } else if (tmp > 0) { - //remove and push back + // Remove and push back curr.depth += depth; self.lines.level.push(curr); }