Skip to content

Commit

Permalink
repl: upper case comments first char
Browse files Browse the repository at this point in the history
PR-URL: #17919
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Lance Ball <lball@redhat.com>
  • Loading branch information
BridgeAR committed Jan 4, 2018
1 parent 3f2382b commit 80988f9
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 @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -109,7 +108,6 @@ writer.options =

exports._builtinLibs = internalModule.builtinLibs;


function REPLServer(prompt,
stream,
eval_,
Expand Down Expand Up @@ -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;
Expand All @@ -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 = ['', '', '', '', '', '', '', '', '', ''];
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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").
Expand Down Expand Up @@ -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);
}
}

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

0 comments on commit 80988f9

Please sign in to comment.