Skip to content

Commit 766506a

Browse files
committed
repl: deprecate REPLServer.parseREPLKeyword
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 <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e506bcd commit 766506a

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

doc/api/deprecations.md

+8
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,14 @@ Type: Runtime
653653
The `REPLServer.bufferedCommand` property was deprecated in favor of
654654
[`REPLServer.clearBufferedCommand()`][].
655655

656+
<a id="DEP0075"></a>
657+
### DEP0075: REPLServer.parseREPLKeyword()
658+
659+
Type: Runtime
660+
661+
`REPLServer.parseREPLKeyword()` was removed from userland visibility.
662+
663+
656664
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
657665
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
658666
[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer

doc/api/repl.md

+14
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,20 @@ buffered but not yet executed. This method is primarily intended to be
385385
called from within the action function for commands registered using the
386386
`replServer.defineCommand()` method.
387387

388+
### replServer.parseREPLKeyword(keyword, [rest])
389+
<!-- YAML
390+
added: v0.8.9
391+
deprecated: REPLACEME
392+
-->
393+
394+
* `keyword` {string} the potential keyword to parse and execute
395+
* `rest` {any} any parameters to the keyword command
396+
397+
> Stability: 0 - Deprecated.
398+
399+
An internal method used to parse and execute `REPLServer` keywords.
400+
Returns `true` if `keyword` is a valid keyword, otherwise `false`.
401+
388402
## repl.start([options])
389403
<!-- YAML
390404
added: v0.1.91

lib/repl.js

+15-17
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,20 @@ function REPLServer(prompt,
374374
};
375375
}
376376

377+
function _parseREPLKeyword(keyword, rest) {
378+
var cmd = this.commands[keyword];
379+
if (cmd) {
380+
cmd.action.call(this, rest);
381+
return true;
382+
}
383+
return false;
384+
}
385+
386+
self.parseREPLKeyword = util.deprecate(
387+
_parseREPLKeyword,
388+
'REPLServer.parseREPLKeyword() is deprecated',
389+
'DEP0075');
390+
377391
self.on('close', function emitExit() {
378392
self.emit('exit');
379393
});
@@ -434,7 +448,7 @@ function REPLServer(prompt,
434448
const matches = trimmedCmd.match(/^\.([^\s]+)\s*(.*)$/);
435449
const keyword = matches && matches[1];
436450
const rest = matches && matches[2];
437-
if (self.parseREPLKeyword(keyword, rest) === true) {
451+
if (_parseREPLKeyword.call(self, keyword, rest) === true) {
438452
return;
439453
}
440454
if (!self[kBufferedCommandSymbol]) {
@@ -1064,22 +1078,6 @@ REPLServer.prototype.completeOnEditorMode = (callback) => (err, results) => {
10641078
callback(null, [[`${completeOn}${longestCommonPrefix(data)}`], completeOn]);
10651079
};
10661080

1067-
/**
1068-
* Used to parse and execute the Node REPL commands.
1069-
*
1070-
* @param {keyword} keyword The command entered to check.
1071-
* @return {Boolean} If true it means don't continue parsing the command.
1072-
*/
1073-
REPLServer.prototype.parseREPLKeyword = function(keyword, rest) {
1074-
var cmd = this.commands[keyword];
1075-
if (cmd) {
1076-
cmd.action.call(this, rest);
1077-
return true;
1078-
}
1079-
return false;
1080-
};
1081-
1082-
10831081
REPLServer.prototype.defineCommand = function(keyword, cmd) {
10841082
if (typeof cmd === 'function') {
10851083
cmd = { action: cmd };
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const repl = require('repl');
5+
6+
testParseREPLKeyword();
7+
8+
function testParseREPLKeyword() {
9+
const server = repl.start({ prompt: '> ' });
10+
const warn = 'REPLServer.parseREPLKeyword() is deprecated';
11+
12+
common.expectWarning('DeprecationWarning', warn);
13+
assert.ok(server.parseREPLKeyword('clear'));
14+
assert.ok(!server.parseREPLKeyword('tacos'));
15+
server.close();
16+
}

0 commit comments

Comments
 (0)