-
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
doc: update example of using await in REPL #45939
base: main
Are you sure you want to change the base?
doc: update example of using await in REPL #45939
Conversation
Invalidating the lexical scoping of the `const` and `let` keywords is fixed. Fixes: nodejs#45918
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.
Can we add a test for that?
Okay. I'll try to write test case for that. |
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.
The scope is still changed, if I am not mistaken:
> const m = await Promise.resolve(123)
undefined
> m
123
> m = 'Lexial scope changed!'
'Lexial scope changed!'
> m
'Lexial scope changed!'
>
vs.
> const m = 123
undefined
> m
123
> m = 'Lexial scope changed!'
Uncaught TypeError: Assignment to constant variable.
>
Lexical scope of `const` is only invalidated when using top-level `await` in REPL. Fixes: nodejs#45918
31508ee
to
2de633c
Compare
await
in REPLThere 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.
The change is LGTM. I can't reproduce any other behavior anymore.
Ideally we could add a test case that validates the outcome accordingly.
Co-authored-by: Antoine du Hamel <[email protected]>
['const k = await Promise.resolve(123)'], | ||
['k', '123'], | ||
['k = await Promise.resolve(234)', '234'], | ||
['k', '234'], |
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.
And the drive the point home:
['k', '234'], | |
['k', '234'], | |
['const k = await Promise.resolve(345)'], | |
['k', '345'], |
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.
line 180 causes error like 'Uncaught SyntaxError: Identifier 'k' has already been declared'.
When I tested,
// This is allowed
const k = await Promise.resolve(123)
k = await Promise.resolve(234)
// This is not allowed
const k = await Promise.resolve(123)
const k = await Promise.resolve(234)
Lexical scope of
const
is only invalidated whenusing top-level
await
in REPL.Fixes: #45918