-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
doc: warn about reassigning _ in REPL #3729
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
doc: warn about reassigning _ in REPL #3729
Conversation
@thefourtheye how about going one step further, and throwing an error or printing a warning when Looks straightforward enough to do, just follow this pattern: repl.js#L384 |
@SamuelMarks The assignment to |
What is |
@Fishrock123 Whenever you evaluate something in the REPL, the last evaluated expression's result is stored in
If we assign something else to
Even worse, if we make
|
@thefourtheye Perhaps we can catch assigning to it while parsing and warn? |
@Fishrock123 I think we can allow users to assign to it (I couldn't think of a case where assigning to it could be a very big trouble), but defining it as |
I think we should block the creation of a |
If we pre-init |
👍 for @jasnell's suggestion |
PR coming soon with @jasnell's awesome suggestion :-) |
@@ -219,6 +219,9 @@ The special variable `_` (underscore) contains the result of the last expression | |||
> _ += 1 | |||
4 | |||
|
|||
*NOTE*: The `_` should not be reassigned explicitly in REPL, as it will either | |||
mess up REPL's functionality or produce unexpected results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps simply: *NOTE*: Explicitly assigning a value to
_in the REPL can produce unexpected results.
When users assign a value to `_` in REPL, it is prone to unexpected results or messing up with REPL's internals. For example, nodejs#3704. This patch issues a warning about the same.
c6a88d1
to
6417f8b
Compare
@jasnell I updated the text as you suggested. Thanks :-) PTAL. |
LGTM |
LGTM, but this should probably just be rolled into the same commit as #3737 |
removing from lts-watch in lieu of #3737 |
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
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
When users assign a value to
_
in REPL, it is prone to unexpectedresults or messing up with REPL's internals. For example,
#3704. This patch issues a warning
about the same.