Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL - after failed assignment identifier cannot be reused #3704

Closed
SamuelMarks opened this issue Nov 7, 2015 · 3 comments
Closed

REPL - after failed assignment identifier cannot be reused #3704

SamuelMarks opened this issue Nov 7, 2015 · 3 comments
Labels
repl Issues and PRs related to the REPL subsystem.

Comments

@SamuelMarks
Copy link

A:\floppy>node -r lodash
> const _ = require('lodash');
const _ = require('lodash');
TypeError: Cannot assign to read only property '_' of #<Object>
    at finish (repl.js:438:24)
    at REPLServer.defaultEval (repl.js:185:5)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:393:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
    at REPLServer.Interface._line (readline.js:549:8)
    at REPLServer.Interface._ttyWrite (readline.js:826:14)
>
> ;
TypeError: Cannot assign to read only property '_' of #<Object>
    at finish (repl.js:438:24)
    at REPLServer.defaultEval (repl.js:185:5)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:393:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
    at REPLServer.Interface._line (readline.js:549:8)
    at REPLServer.Interface._ttyWrite (readline.js:826:14)
> let _ = require('lodash');
TypeError: Identifier '_' has already been declared
    at repl:1:1
    at REPLServer.defaultEval (repl.js:164:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:393:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
    at REPLServer.Interface._line (readline.js:549:8)
    at REPLServer.Interface._ttyWrite (readline.js:826:14)
> process.version
TypeError: Cannot assign to read only property '_' of #<Object>
    at finish (repl.js:438:24)
    at REPLServer.defaultEval (repl.js:185:5)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:393:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
    at REPLServer.Interface._line (readline.js:549:8)
    at REPLServer.Interface._ttyWrite (readline.js:826:14)

I am running Node 4.2.1 x64 on Windows 8.1 x64.

@thefourtheye thefourtheye added the repl Issues and PRs related to the REPL subsystem. label Nov 7, 2015
@thefourtheye
Copy link
Contributor

@SamuelMarks _ is used internally to track the result of the last evaluated expression. Please check this section of the REPL doc. Since you are making it a const, internally, when REPL tries to store the result on _, it fails because it is read-only now. So, I don't think this is a bug per-se and closing the issue. Please feel free to comment if you have strong reasons to believe that this should be fixed and we can reopen this and find a solution.

@SamuelMarks
Copy link
Author

Oh right, forgot about that. When I was coding Node years ago I now remember setting l = require('lodash').

@thefourtheye
Copy link
Contributor

@SamuelMarks No problem :-) I created a PR (#3729) with doc changes regarding the same. Please feel free to review it.

thefourtheye added a commit to thefourtheye/io.js that referenced this issue Nov 10, 2015
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.
thefourtheye added a commit to thefourtheye/io.js that referenced this issue Feb 25, 2016
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
thefourtheye added a commit to thefourtheye/io.js that referenced this issue Feb 25, 2016
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
thefourtheye added a commit to thefourtheye/io.js that referenced this issue Feb 25, 2016
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

2 participants