-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Lexical variable declarations (let
, const
) unusable in repl if error thrown during declaration/first assignment
#8309
Comments
Different with
|
Yep, works fine with |
Here is simplified test case: var vm = require('vm');
try {
vm.runInThisContext('let x = f');
} catch (e) {}
vm.runInThisContext('x = 1'); |
This is very déjà-vu-ish to me, although I can’t find another issue for this bug… /cc @nodejs/v8? |
This error also occurs in the Chrome browser, so it's probably a v8 thing and not a Node thing. Sorry for reporting it in the wrong place. |
Where should I report this considering that it's not specific to node's repl? |
I wouldn't be surprised if this was how the spec worked. In general, you'll have a better time using |
@polybuildr You can report it over at https://bugs.chromium.org/p/v8/issues/list. It looks spec compliant to me (the binding for |
This is per spec: https://esdiscuss.org/topic/take-let-variable-out-of-temporal-dead-zone |
@bnoordhuis, @Slayer95, it does look spec-compliant, so I'm going to close this issue. However, that esdiscuss topic pointed me to something interesting that the Firefox Devtools console does and might be worth a shot. For any such unresolved bindings (at least in the DevTools), Firefox steps in and turns them into undefined. So a redeclaration with |
Not working all variations
|
re-opening, per #32288 (comment), #32288 (comment) and #32288 (comment) |
This is fixable pending migration to v8 repl mode pending v8:10539 |
new
in Set constructor makes variable defined using let
unusablelet
, const
) unusable in repl if error thrown during declaration
let
, const
) unusable in repl if error thrown during declarationlet
, const
) unusable in repl if error thrown during declaration/assignment
let
, const
) unusable in repl if error thrown during declaration/assignmentlet
, const
) unusable in repl if error thrown during declaration/first assignment
Just trying to make this more searchable 😇 |
This comment was marked as off-topic.
This comment was marked as off-topic.
+1 this behavior is unpleasant. After making a typo, the only way to proceed is to start over if e.g. you were setting up to paste in a line of code. |
@mcollina yeah we could implement repl using runtime.evaluate now, just no one has gotten around to it. |
@devsnek So this is a full reimplementation of the repl? |
I don't think it requires complete reimplementation but it will definitely require some work |
I see. Once I get some bandwidth I might take a look at this. This looks like and interesting challenge. |
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as off-topic.
This comment was marked as off-topic.
@ankit142 The issue as posted isn't about fixing the code in the example provided. There are many examples that could be provided. Essentially this issue is that calling |
This comment was marked as off-topic.
This comment was marked as off-topic.
Again, the issue is not with "fixing the code". It is a bad behaviour of the REPL. You don't know that the code you just typed will hit an error. It does. The symbol you tried to use ( This isn't about "writing good code" vs. "writing bad code". This is about the user experience using the REPL when playing around with code.
|
FWIW @1Git2Clone has a issue with chromium at https://issues.chromium.org/issues/345248266. |
repl
(I think)gives
TypeError: Constructor Set requires 'new'
.However, after this:
gives
ReferenceError: s is not defined
and
gives
TypeError: Identifier 's' has already been declared
.I'm not sure whether this is a real bug or it's expected behaviour, but it sure does seem unusual that
s
becomes unusable from this point in in the repl.This isn't a problem when running
node
on a js file because the TypeError simply terminates execution.The text was updated successfully, but these errors were encountered: