File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff 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 * v a r \s * ( [ _ \w \$ ] + ) ( .* ) $ / m;
12091211 const scopeFunc = / ^ \s * f u n c t i o n \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
12271229function bailOnIllegalToken ( parser ) {
12281230 return parser . _literal === null &&
Original file line number Diff line number Diff line change 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"' ) ;
You can’t perform that action at this time.
0 commit comments