Skip to content

Commit

Permalink
Add deprecate warning for convertToContext
Browse files Browse the repository at this point in the history
  • Loading branch information
princejwesley committed Jul 27, 2016
1 parent d4ecbd8 commit a096f00
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,35 @@ function regexpEscape(s) {
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}


/**
* Converts commands that use var and function <name>() to use the
* local exports.context when evaled. This provides a local context
* on the REPL.
*
* @param {String} cmd The cmd to convert.
* @return {String} The converted command.
*/
REPLServer.prototype.convertToContext = util.deprecate(function(cmd) {
const scopeVar = /^\s*var\s*([_\w\$]+)(.*)$/m;
const scopeFunc = /^\s*function\s*([_\w\$]+)/;
var matches;

// Replaces: var foo = "bar"; with: self.context.foo = bar;
matches = scopeVar.exec(cmd);
if (matches && matches.length === 3) {
return 'self.context.' + matches[1] + matches[2];
}

// Replaces: function foo() {}; with: foo = function foo() {};
matches = scopeFunc.exec(this.bufferedCommand);
if (matches && matches.length === 2) {
return matches[1] + ' = ' + this.bufferedCommand;
}

return cmd;
}, 'replServer.convertToContext will be removed in v8.0.0');

function bailOnIllegalToken(parser) {
return parser._literal === null &&
!parser.blockComment &&
Expand Down

0 comments on commit a096f00

Please sign in to comment.