Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: make sure _ cannot be defined in REPL
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: #3729
Refer: #3704
  • Loading branch information
thefourtheye committed Feb 25, 2016
commit c2a37317b1412d6fa433fa71bda15d3024871344
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, adding it.

// 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