Skip to content

Commit

Permalink
repl: pre-define _ in REPL's context
Browse files Browse the repository at this point in the history
As `_` is not defined in REPL's context, when it is defined as `const`,
it breaks REPL, as it tries to store the result of the last evaluated
expression in `_`. This patch makes sure that `_` is pre-defined in
REPL's context, so that if users define it again, they will get error.

Refer: nodejs#3729
Refer: nodejs#3704
  • Loading branch information
thefourtheye committed Feb 25, 2016
1 parent 23a584d commit bcfa885
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ REPLServer.prototype.createContext = function() {
});
});

// Refer: https://github.com/nodejs/node/pull/3729#issuecomment-155460861
// The REPL stores the result of the last evaluated expression in context's _.
// But, in the REPL, if _ is defined as a const, then it will break the REPL.
// So, we define _ first, so that later redefiniitions will fail.
context._ = undefined;

return context;
};

Expand Down

0 comments on commit bcfa885

Please sign in to comment.