From 488d28d391ceb1d86f2f704d8fb4080802dfead4 Mon Sep 17 00:00:00 2001 From: Prince J Wesley Date: Fri, 22 Jul 2016 04:13:45 +0530 Subject: [PATCH] repl: deprecate unused function convertToContext PR-URL: https://github.com/nodejs/node/pull/7829 Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Yorkie Liu Reviewed-By: James M Snell --- lib/repl.js | 6 ++++-- test/parallel/test-repl-deprecated.js | 28 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-repl-deprecated.js diff --git a/lib/repl.js b/lib/repl.js index 6c2352c4b46da9..9632ae99d14af8 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1204,7 +1204,9 @@ function regexpEscape(s) { * @param {String} cmd The cmd to convert. * @return {String} The converted command. */ -REPLServer.prototype.convertToContext = function(cmd) { +// TODO(princejwesley): Remove it prior to v8.0.0 release +// Reference: https://github.com/nodejs/node/pull/7829 +REPLServer.prototype.convertToContext = util.deprecate(function(cmd) { const scopeVar = /^\s*var\s*([_\w\$]+)(.*)$/m; const scopeFunc = /^\s*function\s*([_\w\$]+)/; var matches; @@ -1222,7 +1224,7 @@ REPLServer.prototype.convertToContext = function(cmd) { } return cmd; -}; +}, 'replServer.convertToContext() is deprecated'); function bailOnIllegalToken(parser) { return parser._literal === null && diff --git a/test/parallel/test-repl-deprecated.js b/test/parallel/test-repl-deprecated.js new file mode 100644 index 00000000000000..eabc313f475986 --- /dev/null +++ b/test/parallel/test-repl-deprecated.js @@ -0,0 +1,28 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const repl = require('repl'); + +const expected = [ + 'replServer.convertToContext() is deprecated' +]; + +process.on('warning', common.mustCall((warning) => { + assert.strictEqual(warning.name, 'DeprecationWarning'); + assert.notStrictEqual(expected.indexOf(warning.message), -1, + `unexpected error message: "${warning.message}"`); + // Remove a warning message after it is seen so that we guarantee that we get + // each message only once. + expected.splice(expected.indexOf(warning.message), 1); +}, expected.length)); + +// Create a dummy stream that does nothing +const stream = new common.ArrayStream(); + +const replServer = repl.start({ + input: stream, + output: stream +}); + +const cmd = replServer.convertToContext('var name = "nodejs"'); +assert.strictEqual(cmd, 'self.context.name = "nodejs"');