Skip to content

doc: update example of using await in REPL - #45939

Closed
deokjinkim wants to merge 4 commits into
nodejs:mainfrom
deokjinkim:221222_remove_limitation_await_repl
Closed

doc: update example of using await in REPL#45939
deokjinkim wants to merge 4 commits into
nodejs:mainfrom
deokjinkim:221222_remove_limitation_await_repl

Conversation

@deokjinkim

@deokjinkimdeokjinkim commented Dec 21, 2022

Copy link
Copy Markdown
Contributor

Lexical scope of const is only invalidated when
using top-level await in REPL.

Fixes: #45918

Invalidating the lexical scoping of the `const` and
`let` keywords is fixed.
Fixes: nodejs#45918
@nodejs-github-botnodejs-github-bot added doc Issues and PRs related to the documentations. repl Issues and PRs related to the REPL subsystem. labels Dec 21, 2022

@aduh95aduh95 left a comment

Copy link
Copy Markdown
Contributor

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?

@deokjinkim

Copy link
Copy Markdown
ContributorAuthor

Can we add a test for that?

Okay. I'll try to write test case for that.

BridgeAR
BridgeAR previously requested changes Dec 22, 2022

@BridgeARBridgeAR left a comment

Copy link
Copy Markdown
Member

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:

>constm=awaitPromise.resolve(123)undefined>m123>m='Lexial scope changed!''Lexial scope changed!'>m'Lexial scope changed!'>

vs.

>constm=123undefined>m123>m='Lexial scope changed!'UncaughtTypeError: Assignmenttoconstantvariable.>

@deokjinkim

Copy link
Copy Markdown
ContributorAuthor

@jasnell As I checked, you are author of this change(#38449). Do you have any idea for this issue?

Lexical scope of `const` is only invalidated when
using top-level `await` in REPL.
Fixes: nodejs#45918
@deokjinkim
deokjinkimforce-pushed the 221222_remove_limitation_await_repl branch from 31508ee to 2de633cCompareDecember 23, 2022 09:55
@deokjinkimdeokjinkim changed the title doc: remove limitation of using await in REPLdoc: update example of using await in REPLDec 23, 2022

@BridgeARBridgeAR left a comment

Copy link
Copy Markdown
Member

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.

@BridgeAR
BridgeAR dismissed their stale reviewJanuary 2, 2023 17:22

See comment above

@deokjinkim

Copy link
Copy Markdown
ContributorAuthor

The change is LGTM. I can't reproduce any other behavior anymore. Ideally we could add a test case that validates the outcome accordingly.

@BridgeAR@aduh95 Added test case according to change of document in REPL. Could you please review again?

@deokjinkim
deokjinkim requested review from BridgeAR and aduh95 and removed request for BridgeAR and aduh95January 4, 2023 23:16
Comment threadtest/parallel/test-repl-top-level-await.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
['const k = await Promise.resolve(123)'],
['k', '123'],
['k = await Promise.resolve(234)', '234'],
['k', '234'],

Copy link
Copy Markdown
Contributor

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:

Suggested change
['k','234'],
['k','234'],
['const k = await Promise.resolve(345)'],
['k','345'],

Copy link
Copy Markdown
ContributorAuthor

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)

@bjohansebasbjohansebas added the stalled Issues and PRs that are stalled. label Mar 28, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open.

@github-actionsgithub-actionsBot removed the stalled Issues and PRs that are stalled. label Apr 3, 2025
@BridgeAR

Copy link
Copy Markdown
Member

The mentioned issue seems to be resolved by another PR.
I believe this could therefore be closed? It would otherwise need a rebase. If I am wrong, please open a new PR, since it's more likely to be picked up that way again!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docIssues and PRs related to the documentations.replIssues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants

@deokjinkim@BridgeAR@aduh95@nodejs-github-bot@bjohansebas