From d6a85c88511542ae478e530246df53c70a8c0916 Mon Sep 17 00:00:00 2001 From: Lance Ball <lball@redhat.com> Date: Thu, 13 Jul 2017 14:17:33 -0400 Subject: [PATCH 1/5] 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, as far as I can tell. This change is as recommended by @jasnell in https://github.com/nodejs/node/issues/7619#issuecomment-236608809. This change is only for `parseREPLKeyword()`. --- doc/api/deprecations.md | 8 ++++++++ doc/api/repl.md | 14 ++++++++++++++ lib/repl.js | 30 ++++++++++++++---------------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index f6c51217e0eae3..a27c13761122b5 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -653,6 +653,14 @@ Type: Runtime The `REPLServer.bufferedCommand` property was deprecated in favor of [`REPLServer.clearBufferedCommand()`][]. +<a id="DEP00XX"></a> +### DEP00XX: 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 diff --git a/doc/api/repl.md b/doc/api/repl.md index 7a9c1f81e56309..0522a1ca295dba 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -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: XXXX +--> + +* `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 diff --git a/lib/repl.js b/lib/repl.js index 00d1172c36ecc3..b86312267dab4e 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -434,7 +434,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(self, keyword, rest) === true) { return; } if (!self[kBufferedCommandSymbol]) { @@ -1064,21 +1064,10 @@ 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.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') { @@ -1380,6 +1369,15 @@ 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; } From bf9e499d8a78f1900488a586255c3c86ecd7fd3c Mon Sep 17 00:00:00 2001 From: Lance Ball <lball@redhat.com> Date: Fri, 14 Jul 2017 15:10:24 -0400 Subject: [PATCH 2/5] repl: add test for deprecated REPL properties --- test/parallel/test-repl-deprecations.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/parallel/test-repl-deprecations.js diff --git a/test/parallel/test-repl-deprecations.js b/test/parallel/test-repl-deprecations.js new file mode 100644 index 00000000000000..6f5eaf6debfddf --- /dev/null +++ b/test/parallel/test-repl-deprecations.js @@ -0,0 +1,22 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const repl = require('repl'); + +test(); + +function test() { + testParseREPLKeyword(); +} + +function testParseREPLKeyword() { + const server = repl.start({ prompt: '> ' }); + const warn = 'REPLServer.parseREPLKeyword() is deprecated'; + + common.expectWarning('DeprecationWarning', warn); + assert.ok(server.parseREPLKeyword('clear')); + common.expectWarning('DeprecationWarning', warn); + assert.ok(!server.parseREPLKeyword('tacos')); + server.close(); +} + From 5285d8adb11b4a517ac802d7ca3bab2d326be77e Mon Sep 17 00:00:00 2001 From: Lance Ball <lball@redhat.com> Date: Fri, 14 Jul 2017 23:24:44 -0400 Subject: [PATCH 3/5] address linting and nits --- doc/api/repl.md | 2 +- test/parallel/test-repl-deprecations.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/api/repl.md b/doc/api/repl.md index 0522a1ca295dba..4ed95f61116b11 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -388,7 +388,7 @@ called from within the action function for commands registered using the ### replServer.parseREPLKeyword(keyword, [rest]) <!-- YAML added: v0.8.9 -deprecated: XXXX +deprecated: REPLACEME --> * `keyword` {string} the potential keyword to parse and execute diff --git a/test/parallel/test-repl-deprecations.js b/test/parallel/test-repl-deprecations.js index 6f5eaf6debfddf..59a4ec5b3ccc52 100644 --- a/test/parallel/test-repl-deprecations.js +++ b/test/parallel/test-repl-deprecations.js @@ -19,4 +19,3 @@ function testParseREPLKeyword() { assert.ok(!server.parseREPLKeyword('tacos')); server.close(); } - From bff62e99c2beacc66eab89729edb74b0e9f425ec Mon Sep 17 00:00:00 2001 From: Lance Ball <lball@redhat.com> Date: Tue, 18 Jul 2017 14:52:00 -0400 Subject: [PATCH 4/5] repl: rework REPLServer.parseREPLKeyword --- lib/repl.js | 30 ++++++++++++------------- test/parallel/test-repl-deprecations.js | 1 - 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index b86312267dab4e..244480061a12b6 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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'); }); @@ -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]) { @@ -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 }; @@ -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; } diff --git a/test/parallel/test-repl-deprecations.js b/test/parallel/test-repl-deprecations.js index 59a4ec5b3ccc52..76cf2e4bf1d82b 100644 --- a/test/parallel/test-repl-deprecations.js +++ b/test/parallel/test-repl-deprecations.js @@ -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(); } From 3b2daff1809dff449a8495d12f16a8b32e1f5363 Mon Sep 17 00:00:00 2001 From: Lance Ball <lball@redhat.com> Date: Tue, 1 Aug 2017 16:10:06 -0400 Subject: [PATCH 5/5] fix: address unnecessary indirection in repl test --- test/parallel/test-repl-deprecations.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/parallel/test-repl-deprecations.js b/test/parallel/test-repl-deprecations.js index 76cf2e4bf1d82b..c2a97ad7aca8ed 100644 --- a/test/parallel/test-repl-deprecations.js +++ b/test/parallel/test-repl-deprecations.js @@ -3,11 +3,7 @@ const common = require('../common'); const assert = require('assert'); const repl = require('repl'); -test(); - -function test() { - testParseREPLKeyword(); -} +testParseREPLKeyword(); function testParseREPLKeyword() { const server = repl.start({ prompt: '> ' });