-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Error with let: "Identifier '*' has already been declared" on REPL #8441
Comments
I guess we may be able to provide a better error message? Maybe? |
@Fishrock123 how would you improve the error message? To me it appears pretty clear. The only thing that is really confusing is that you get two different errors depending on how you try and redefine the variable. E.g.
Providing better error messages would mean catching all Reference errors, and comparing the error messages to these known values, then changing the message. This seems like a lot of work for something that is spec compliant. |
Any objections to closing this issue since it's a wontfix? |
Let's close, I don't think we'll fix this anytime soon. #8309 (comment) makes an interesting suggestion of turning uninitialized bindings into undefined values but that probably needs support in V8. |
@bnoordhuis We can preprocess it before passing to function preprocess(code) {
...
const letBinding = /^\s*let\s+([^\s=]+)\s*(?==)/;
const letMatch = cmd.match(letBinding);
if (letMatch && letMatch[0] !== letMatch.input) {
const binding = letMatch[1];
cmd = cmd.replace(letMatch[0], `let ${binding};\n${binding}`);
}
...
} node 🙈 ₹ git:(upstream ⚡ repl.let) ./node
> let x = foo
ReferenceError: foo is not defined
at repl:2:4
at sigintHandlersWrap (vm.js:22:35)
at sigintHandlersWrap (vm.js:96:12)
at ContextifyScript.Script.runInThisContext (vm.js:21:12)
at REPLServer.defaultEval (repl.js:313:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:513:10)
at emitOne (events.js:101:20)
at REPLServer.emit (events.js:188:7)
> x
undefined
> x = 3
3
> |
A bit too much of a hack, IMO. I know perfect is the enemy of good but it would fail on simple inputs like |
@lance I just caught the same issue as you in node@6.9.1 ! |
I used |
This is very weird behaviour as i cannot use that variable and can lead to memory leak as memory is already given to this obj but the compiler can not clean it. |
class Drone { let drone = new Drone(A1223, flyer); |
@DinmaOtutu How is this related to node REPL? REPL doesn't produce errors with "VMxx" in the message. Looks like an error in a browser, not in node... Also, I guess you already declared it further above or in a previous statement. That's what the error literally tells you. |
I'm running into the same problem in some of my code. I don't understand why it has said that Drone has already been declared when it wasn't declared as a variable. It was set as a class. Are setting a class and setting a variable both declarations? |
Yes, |
The problem I'm seeing is that if during declaring a variable with
let
something throws - that identifier is "taken", but I can't use it.Essentially like this (stripped unnecessary stack).
I'm seeing this for a long time, but never took an effort to look into it more.
Now I'm curious - is this expected behaviour? Why? If not, how can one go about and fix it?
It's on Node 5 and latest 6, but I believe I've seen it on older versions as well.
The text was updated successfully, but these errors were encountered: