File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -1204,7 +1204,9 @@ function regexpEscape(s) {
1204
1204
* @param {String } cmd The cmd to convert.
1205
1205
* @return {String } The converted command.
1206
1206
*/
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 ) {
1208
1210
const scopeVar = / ^ \s * v a r \s * ( [ _ \w \$ ] + ) ( .* ) $ / m;
1209
1211
const scopeFunc = / ^ \s * f u n c t i o n \s * ( [ _ \w \$ ] + ) / ;
1210
1212
var matches ;
@@ -1222,7 +1224,7 @@ REPLServer.prototype.convertToContext = function(cmd) {
1222
1224
}
1223
1225
1224
1226
return cmd ;
1225
- } ;
1227
+ } , 'replServer.convertToContext() is deprecated' ) ;
1226
1228
1227
1229
function bailOnIllegalToken ( parser ) {
1228
1230
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