Skip to content

Commit

Permalink
repl: upper case comments first char
Browse files Browse the repository at this point in the history
Backport-PR-URL: #19244
PR-URL: #17919
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Khaidi Chu <[email protected]>
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: Lance Ball <[email protected]>
  • Loading branch information
BridgeAR authored and MylesBorins committed Mar 21, 2018
1 parent f4f0266 commit 6997af7
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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
Expand All @@ -89,7 +89,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
Expand All @@ -99,14 +99,12 @@ 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.
exports.writer = util.inspect;

exports._builtinLibs = internalModule.builtinLibs;


function REPLServer(prompt,
stream,
eval_,
Expand Down Expand Up @@ -149,7 +147,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;
Expand All @@ -162,7 +159,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 = ['', '', '', '', '', '', '', '', '', ''];
Expand All @@ -187,8 +184,7 @@ function REPLServer(prompt,
wrappedCmd = true;
}

// first, create the Script object to check the syntax

// First, create the Script object to check the syntax
if (code === '\n')
return cb(null);

Expand All @@ -207,13 +203,13 @@ function REPLServer(prompt,
} catch (e) {
debug('parse error %j', code, e);
if (wrappedCmd) {
// Unwrap and try again
wrappedCmd = false;
// unwrap and try again
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);
Expand Down Expand Up @@ -321,7 +317,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) {
Expand Down Expand Up @@ -371,7 +367,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) {
Expand All @@ -387,14 +383,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;
}
Expand Down Expand Up @@ -571,7 +567,7 @@ function REPLServer(prompt,
return;
}

// editor mode
// Editor mode
if (key.ctrl && !key.shift) {
switch (key.name) {
case 'd': // End editor mode
Expand All @@ -591,7 +587,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;
Expand Down Expand Up @@ -861,10 +857,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").
Expand Down Expand Up @@ -1042,7 +1036,7 @@ function complete(line, callback) {
}
}
} catch (e) {
//console.log("completion error walking prototype chain:" + e);
// console.log("completion error walking prototype chain:" + e);
}
}

Expand Down Expand Up @@ -1085,7 +1079,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)
Expand All @@ -1100,7 +1094,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();
Expand Down Expand Up @@ -1167,7 +1161,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;
Expand All @@ -1181,7 +1175,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);
Expand All @@ -1192,8 +1186,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()
Expand All @@ -1205,16 +1199,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);
}
Expand Down

0 comments on commit 6997af7

Please sign in to comment.