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

Lexical scoping of the const is not invalidated when use await in REPL #45918

Closed
deokjinkim opened this issue Dec 20, 2022 · 0 comments · Fixed by #57653 · May be fixed by #45939
Closed

Lexical scoping of the const is not invalidated when use await in REPL #45918

deokjinkim opened this issue Dec 20, 2022 · 0 comments · Fixed by #57653 · May be fixed by #45939
Labels
doc Issues and PRs related to the documentations.

Comments

@deokjinkim
Copy link
Contributor

deokjinkim commented Dec 20, 2022

Affected URL(s)

https://github.com/nodejs/node/blob/main/doc/api/repl.md#await-keyword

Description of the problem

In document, described as below.

One known limitation of using the await keyword in the REPL is that it will invalidate the lexical scoping of the const and let keywords.

For example:

> const m = await Promise.resolve(123)
undefined
> m
123
> const m = await Promise.resolve(234)
undefined
> m
234

But actual result is different like below.
(1) const

Welcome to Node.js v20.0.0-pre.
Type ".help" for more information.
> const m = await Promise.resolve(123)
undefined
> m
123
> const m = await Promise.resolve(234)
Uncaught SyntaxError: Identifier 'm' has already been declared
>

(2) let

Welcome to Node.js v20.0.0-pre.
Type ".help" for more information.
> let m = await Promise.resolve(123)
undefined
> m
123
> let m = await Promise.resolve(234)
Uncaught SyntaxError: Identifier 'm' has already been declared
>

I guess limitation is fixed. So how about removing these lines(One known blabla, including example) from document?

@deokjinkim deokjinkim added the doc Issues and PRs related to the documentations. label Dec 20, 2022
abhishekumar-tyagi pushed a commit to abhishekumar-tyagi/node that referenced this issue May 5, 2024
Invalidating the lexical scoping of the `const` and
`let` keywords is fixed.

Fixes: nodejs/node#45918
abhishekumar-tyagi pushed a commit to abhishekumar-tyagi/node that referenced this issue May 5, 2024
Lexical scope of `const` is only invalidated when
using top-level `await` in REPL.

Fixes: nodejs/node#45918
dario-piotrowicz pushed a commit to dario-piotrowicz/node that referenced this issue Mar 27, 2025
Lexical scope of `const` is only invalidated when
using top-level `await` in REPL.

As part of this change also add tests for the
documented behavior

Fixes: nodejs#45918

Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Dario Piotrowicz <[email protected]>

add k already decalared test case

add comment
dario-piotrowicz pushed a commit to dario-piotrowicz/node that referenced this issue Mar 28, 2025
Lexical scope of `const` is only invalidated when
using top-level `await` in REPL.

As part of this change also add tests for the
documented behavior

Fixes: nodejs#45918

Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Dario Piotrowicz <[email protected]>

add k already decalared test case

add comment
dario-piotrowicz added a commit to dario-piotrowicz/node that referenced this issue Mar 28, 2025
Lexical scope of `const` is only invalidated when
using top-level `await` in REPL.

As part of this change also add tests for the
documented behavior

Fixes: nodejs#45918

Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Dario Piotrowicz <[email protected]>
dario-piotrowicz added a commit to dario-piotrowicz/node that referenced this issue Mar 28, 2025
Clarify that the lexical scope of `const` is
invalidated when using top-level `await` in REPL.

As part of this change also add tests for the
documented behavior

Fixes: nodejs#45918

Co-authored-by: Antoine du Hamel <[email protected]>
Co-authored-by: Dario Piotrowicz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations.
Projects
None yet
1 participant