Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
repl: rework REPLServer.parseREPLKeyword
  • Loading branch information
lance committed Aug 2, 2017
commit bff62e99c2beacc66eab89729edb74b0e9f425ec
30 changes: 15 additions & 15 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,20 @@ function REPLServer(prompt,
};
}

function _parseREPLKeyword(keyword, rest) {
var cmd = this.commands[keyword];
if (cmd) {
cmd.action.call(this, rest);
return true;
}
return false;
}

self.parseREPLKeyword = util.deprecate(
_parseREPLKeyword,
'REPLServer.parseREPLKeyword() is deprecated',
'DEP00XX');

self.on('close', function emitExit() {
self.emit('exit');
});
Expand Down Expand Up @@ -434,7 +448,7 @@ function REPLServer(prompt,
const matches = trimmedCmd.match(/^\.([^\s]+)\s*(.*)$/);
const keyword = matches && matches[1];
const rest = matches && matches[2];
if (_parseREPLKeyword(self, keyword, rest) === true) {
if (_parseREPLKeyword.call(self, keyword, rest) === true) {
return;
}
if (!self[kBufferedCommandSymbol]) {
Expand Down Expand Up @@ -1064,11 +1078,6 @@ REPLServer.prototype.completeOnEditorMode = (callback) => (err, results) => {
callback(null, [[`${completeOn}${longestCommonPrefix(data)}`], completeOn]);
};

REPLServer.prototype.parseREPLKeyword = util.deprecate(
function(keyword, rest) {
return _parseREPLKeyword(this, keyword, rest);
}, 'REPLServer.parseREPLKeyword() is deprecated', 'DEP00XX');

REPLServer.prototype.defineCommand = function(keyword, cmd) {
if (typeof cmd === 'function') {
cmd = { action: cmd };
Expand Down Expand Up @@ -1369,15 +1378,6 @@ function isCodeRecoverable(code) {
return stringLiteral ? lastChar === '\\' : isBlockComment;
}

function _parseREPLKeyword(repl, keyword, rest) {
var cmd = repl.commands[keyword];
if (cmd) {
cmd.action.call(repl, rest);
return true;
}
return false;
}

function Recoverable(err) {
this.err = err;
}
Expand Down
1 change: 0 additions & 1 deletion test/parallel/test-repl-deprecations.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function testParseREPLKeyword() {

common.expectWarning('DeprecationWarning', warn);
assert.ok(server.parseREPLKeyword('clear'));
common.expectWarning('DeprecationWarning', warn);
assert.ok(!server.parseREPLKeyword('tacos'));
server.close();
}