Skip to content

Commit

Permalink
test: make sure _ cannot be defined in REPL
Browse files Browse the repository at this point in the history
If the `_` is redefined as `const` in REPL, it will break the REPL, as
REPL will store the result of the last evaluated expression in `_`.
This patch has a test to make sure that the REPL doesn't allow
redefining `_` as `const`, also still assiging values to `_` is
permitted.

Refer: nodejs#3729
Refer: nodejs#3704
  • Loading branch information
thefourtheye committed Feb 25, 2016
1 parent bcfa885 commit c2a3731
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ function error_test() {
});

send_expect([
// Ref: https://github.com/nodejs/node/pull/3729#issuecomment-155460861
// REPL stores the result of the last evaluated expression in _.
// This test makes sure that _ can not be redefined in REPL.
{ client: client_unix, send: 'const _ = 1',
expect: /^TypeError: Identifier '_' has already been declared/ },
// `_` should still be assignable
{ client: client_unix, send: '_ = 1\n_',
expect: `1\n${prompt_unix}1\n${prompt_unix}` },
// Uncaught error throws and prints out
{ client: client_unix, send: 'throw new Error(\'test error\');',
expect: /^Error: test error/ },
Expand Down

0 comments on commit c2a3731

Please sign in to comment.