Skip to content

Commit 488d28d

Browse files
princejwesleyjasnell
authored andcommitted
repl: deprecate unused function convertToContext
PR-URL: #7829 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yorkie Liu <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 588ee22 commit 488d28d

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/repl.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,9 @@ function regexpEscape(s) {
12041204
* @param {String} cmd The cmd to convert.
12051205
* @return {String} The converted command.
12061206
*/
1207-
REPLServer.prototype.convertToContext = function(cmd) {
1207+
// TODO(princejwesley): Remove it prior to v8.0.0 release
1208+
// Reference: https://github.com/nodejs/node/pull/7829
1209+
REPLServer.prototype.convertToContext = util.deprecate(function(cmd) {
12081210
const scopeVar = /^\s*var\s*([_\w\$]+)(.*)$/m;
12091211
const scopeFunc = /^\s*function\s*([_\w\$]+)/;
12101212
var matches;
@@ -1222,7 +1224,7 @@ REPLServer.prototype.convertToContext = function(cmd) {
12221224
}
12231225

12241226
return cmd;
1225-
};
1227+
}, 'replServer.convertToContext() is deprecated');
12261228

12271229
function bailOnIllegalToken(parser) {
12281230
return parser._literal === null &&

test/parallel/test-repl-deprecated.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const repl = require('repl');
5+
6+
const expected = [
7+
'replServer.convertToContext() is deprecated'
8+
];
9+
10+
process.on('warning', common.mustCall((warning) => {
11+
assert.strictEqual(warning.name, 'DeprecationWarning');
12+
assert.notStrictEqual(expected.indexOf(warning.message), -1,
13+
`unexpected error message: "${warning.message}"`);
14+
// Remove a warning message after it is seen so that we guarantee that we get
15+
// each message only once.
16+
expected.splice(expected.indexOf(warning.message), 1);
17+
}, expected.length));
18+
19+
// Create a dummy stream that does nothing
20+
const stream = new common.ArrayStream();
21+
22+
const replServer = repl.start({
23+
input: stream,
24+
output: stream
25+
});
26+
27+
const cmd = replServer.convertToContext('var name = "nodejs"');
28+
assert.strictEqual(cmd, 'self.context.name = "nodejs"');

0 commit comments

Comments
 (0)