From d203d15cae6feab095ce9d472791094fd04d7a86 Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Fri, 1 Sep 2017 12:52:18 -0400 Subject: [PATCH 1/4] repl: eliminate code duplication for editorMode This commit exposes `REPLServer.prototype.turnOnEditorMode()` which handles the necessary internal changes required instead of having them scattered about. --- lib/repl.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 0d1aca6aa546c9..5df38c804e12d9 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -696,6 +696,11 @@ REPLServer.prototype.turnOffEditorMode = function() { this.setPrompt(this._initialPrompt); }; +REPLServer.prototype.turnOnEditorMode = function() { + this.editorMode = true; + REPLServer.super_.prototype.setPrompt.call(this, ''); +}; + // A stream to push an array into a REPL // used in REPLServer.complete @@ -1254,8 +1259,7 @@ function defineDefaultCommands(repl) { try { var stats = fs.statSync(file); if (stats && stats.isFile()) { - this.editorMode = true; - REPLServer.super_.prototype.setPrompt.call(this, ''); + this.turnOnEditorMode(); var data = fs.readFileSync(file, 'utf8'); var lines = data.split('\n'); for (var n = 0; n < lines.length; n++) { @@ -1279,8 +1283,7 @@ function defineDefaultCommands(repl) { help: 'Enter editor mode', action() { if (!this.terminal) return; - this.editorMode = true; - REPLServer.super_.prototype.setPrompt.call(this, ''); + this.turnOnEditorMode(); this.outputStream.write( '// Entering editor mode (^D to finish, ^C to cancel)\n'); } From fd4ffb80cc3a38f3cbbd677cbbf485ed3a397fcb Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Sun, 3 Sep 2017 18:30:25 -0400 Subject: [PATCH 2/4] repl: make turnO[n|ff]EditorMode private functions This deprecates the current REPLServer.prototype.turnOffEditorMode --- lib/repl.js | 34 +++++++++++-------- .../test-repl-turn-off-editor-mode.js | 15 ++++++++ 2 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 test/parallel/test-repl-turn-off-editor-mode.js diff --git a/lib/repl.js b/lib/repl.js index 5df38c804e12d9..cf875651dfc516 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -397,7 +397,7 @@ function REPLServer(prompt, self.on('SIGINT', function onSigInt() { var empty = self.line.length === 0; self.clearLine(); - self.turnOffEditorMode(); + _turnOffEditorMode.call(self); const cmd = self[kBufferedCommandSymbol]; if (!(cmd && cmd.length > 0) && empty) { @@ -539,7 +539,7 @@ function REPLServer(prompt, if (key.ctrl && !key.shift) { switch (key.name) { case 'd': // End editor mode - self.turnOffEditorMode(); + _turnOffEditorMode.call(self); sawCtrlD = true; ttyWrite(d, { name: 'return' }); break; @@ -691,16 +691,10 @@ REPLServer.prototype.setPrompt = function setPrompt(prompt) { REPLServer.super_.prototype.setPrompt.call(this, prompt); }; -REPLServer.prototype.turnOffEditorMode = function() { - this.editorMode = false; - this.setPrompt(this._initialPrompt); -}; - -REPLServer.prototype.turnOnEditorMode = function() { - this.editorMode = true; - REPLServer.super_.prototype.setPrompt.call(this, ''); -}; - +REPLServer.prototype.turnOffEditorMode = util.deprecate( + _turnOffEditorMode, + 'REPLServer.turnOffEditorMode() is deprecated', + 'DEP00XX'); // A stream to push an array into a REPL // used in REPLServer.complete @@ -1187,6 +1181,16 @@ function addStandardGlobals(completionGroups, filter) { } } +function _turnOnEditorMode(repl) { + repl.editorMode = true; + REPLServer.super_.prototype.setPrompt.call(repl, ''); +} + +function _turnOffEditorMode() { + this.editorMode = false; + this.setPrompt(this._initialPrompt); +} + function defineDefaultCommands(repl) { repl.defineCommand('break', { help: 'Sometimes you get stuck, this gets you out', @@ -1259,14 +1263,14 @@ function defineDefaultCommands(repl) { try { var stats = fs.statSync(file); if (stats && stats.isFile()) { - this.turnOnEditorMode(); + _turnOnEditorMode(this); var data = fs.readFileSync(file, 'utf8'); var lines = data.split('\n'); for (var n = 0; n < lines.length; n++) { if (lines[n]) this.write(`${lines[n]}\n`); } - this.turnOffEditorMode(); + _turnOffEditorMode.call(this); this.write('\n'); } else { this.outputStream.write('Failed to load:' + file + @@ -1283,7 +1287,7 @@ function defineDefaultCommands(repl) { help: 'Enter editor mode', action() { if (!this.terminal) return; - this.turnOnEditorMode(); + _turnOnEditorMode(this); this.outputStream.write( '// Entering editor mode (^D to finish, ^C to cancel)\n'); } diff --git a/test/parallel/test-repl-turn-off-editor-mode.js b/test/parallel/test-repl-turn-off-editor-mode.js new file mode 100644 index 00000000000000..998b9498d721a2 --- /dev/null +++ b/test/parallel/test-repl-turn-off-editor-mode.js @@ -0,0 +1,15 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const repl = require('repl'); + +testTurnOffEditorMode(); + +function testTurnOffEditorMode() { + const server = repl.start({ prompt: '> ' }); + const warn = 'REPLServer.turnOffEditorMode() is deprecated'; + + common.expectWarning('DeprecationWarning', warn); + server.turnOffEditorMode(); + server.close(); +} From 12a1d451bae33894b73fd0ca6ea3fff1fdc7b71a Mon Sep 17 00:00:00 2001 From: Lance Ball Date: Fri, 8 Sep 2017 12:17:40 -0400 Subject: [PATCH 3/4] repl: document REPLServer.turnOffEditorMode deprecation Also, address some concerns from code review. --- doc/api/deprecations.md | 10 ++++++++++ doc/api/repl.md | 11 +++++++++++ lib/repl.js | 14 +++++++------- test/parallel/test-repl-turn-off-editor-mode.js | 1 - 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 79a8f896f1533e..613090c476e247 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -684,6 +684,7 @@ difference is that `querystring.parse()` does url encoding: { '%E5%A5%BD': '1' } ``` +<<<<<<< HEAD ### DEP0077: Module.\_debug() @@ -692,6 +693,15 @@ Type: Runtime `Module._debug()` has been deprecated. *Note*: `Module._debug()` was never documented as an officially supported API. +======= + +### DEP00XX: REPLServer.turnOffEditorMode() + +Type: Runtime + +`REPLServer.turnOffEditorMode()` was removed from userland visibility. + +>>>>>>> repl: document REPLServer.turnOffEditorMode deprecation [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size [`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array diff --git a/doc/api/repl.md b/doc/api/repl.md index d61e9be57c1375..843d9f00c225a3 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -401,6 +401,17 @@ deprecated: REPLACEME An internal method used to parse and execute `REPLServer` keywords. Returns `true` if `keyword` is a valid keyword, otherwise `false`. +### replServer.turnOffEditorMode() + + +> Stability: 0 - Deprecated. + +An internal method used to turn off editor mode when entering +code in the REPL. + ## repl.start([options]) - -> Stability: 0 - Deprecated. - -An internal method used to turn off editor mode when entering -code in the REPL. - ## repl.start([options])