Skip to content

Commit

Permalink
repl: deprecate REPLServer.parseREPLKeyword
Browse files Browse the repository at this point in the history
This method does not need to be visible to user code. It has been
undocumented since it was introduced which was perhaps v0.8.9.

The motivation for this change is that the method is simply an
implementation detail of the REPLServer behavior, and does
not need to be exposed to user code.

This change adds documentation of the method with a deprecation
warning, and a test that the method is actually documented.

PR-RUL: #14223
Refs: #7619
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
lance committed Aug 2, 2017
1 parent e506bcd commit 766506a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 17 deletions.
8 changes: 8 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,14 @@ Type: Runtime
The `REPLServer.bufferedCommand` property was deprecated in favor of
[`REPLServer.clearBufferedCommand()`][].

<a id="DEP0075"></a>
### DEP0075: REPLServer.parseREPLKeyword()

Type: Runtime

`REPLServer.parseREPLKeyword()` was removed from userland visibility.


[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer
Expand Down
14 changes: 14 additions & 0 deletions doc/api/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,20 @@ buffered but not yet executed. This method is primarily intended to be
called from within the action function for commands registered using the
`replServer.defineCommand()` method.

### replServer.parseREPLKeyword(keyword, [rest])
<!-- YAML
added: v0.8.9
deprecated: REPLACEME
-->

* `keyword` {string} the potential keyword to parse and execute
* `rest` {any} any parameters to the keyword command

> Stability: 0 - Deprecated.
An internal method used to parse and execute `REPLServer` keywords.
Returns `true` if `keyword` is a valid keyword, otherwise `false`.

## repl.start([options])
<!-- YAML
added: v0.1.91
Expand Down
32 changes: 15 additions & 17 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',
'DEP0075');

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 (self.parseREPLKeyword(keyword, rest) === true) {
if (_parseREPLKeyword.call(self, keyword, rest) === true) {
return;
}
if (!self[kBufferedCommandSymbol]) {
Expand Down Expand Up @@ -1064,22 +1078,6 @@ REPLServer.prototype.completeOnEditorMode = (callback) => (err, results) => {
callback(null, [[`${completeOn}${longestCommonPrefix(data)}`], completeOn]);
};

/**
* Used to parse and execute the Node REPL commands.
*
* @param {keyword} keyword The command entered to check.
* @return {Boolean} If true it means don't continue parsing the command.
*/
REPLServer.prototype.parseREPLKeyword = function(keyword, rest) {
var cmd = this.commands[keyword];
if (cmd) {
cmd.action.call(this, rest);
return true;
}
return false;
};


REPLServer.prototype.defineCommand = function(keyword, cmd) {
if (typeof cmd === 'function') {
cmd = { action: cmd };
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-repl-deprecations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');

testParseREPLKeyword();

function testParseREPLKeyword() {
const server = repl.start({ prompt: '> ' });
const warn = 'REPLServer.parseREPLKeyword() is deprecated';

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

4 comments on commit 766506a

@MylesBorins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meta data says PR-RUL rather than PR-URL

@lance
Copy link
Member Author

@lance lance commented on 766506a Sep 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MylesBorins this was pointed out by @addaleax here #14223 (comment). I'm not sure what I can do to fix the situation, but if you have a suggestion, I will do what I can.

@MylesBorins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making a note πŸ˜‡

Helps with Future auditing

@gibfahn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR-URL: #14223

Please sign in to comment.