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

repl: hoist declarations when processing top level await #39265

Closed

Conversation

@ejose19
Copy link
Contributor

@ejose19 ejose19 commented Jul 5, 2021

Fixes #39259

This PR hoist all declarations as let in order to allow previous declarations be available for new statements, while also remaining compatible with strict mode.

lib/internal/repl/await.js Outdated Show resolved Hide resolved
@guybedford
Copy link
Contributor

@guybedford guybedford commented Jul 5, 2021

@ejose19 awesome work on the PR, this is looking really great and nice to see full destructuring support. Can we add some of the following test cases please:

  • Const -> Let conversion: const o = await 1
  • Function variables not being rescoped: await (async () => { let p = await 1; return p; })();
  • Block scopes supported / not being rescoped: { let p = await 1; }
  • Var scoping being excluded from all this: var p = await 1 (should be a global)
  • Var scoping function variables: await (async () => { var p = await 1; return p; })();
  • Var scoping block scopes: { var p = await 1; } (should be a global)
@ejose19
Copy link
Contributor Author

@ejose19 ejose19 commented Jul 5, 2021

@ejose19 awesome work on the PR, this is looking really great and nice to see full destructuring support. Can we add some of the following test cases please:

* Const -> Let conversion: `const o = await 1`

* Function variables not being rescoped: `await (async () => { let p = await 1; return p; })();`

* Block scopes supported / not being rescoped: `{ let p = await 1; }`

* Var scoping being excluded from all this: `var p = await 1` (_should be a global_)

* Var scoping function variables: `await (async () => { var p = await 1; return p; })();`

* Var scoping block scopes: `{ var p = await 1; }` (_should be a global_)

Can you please put each test case along with the expected result? It's not clear for me based on that alone what should be the result. This one Const -> Let conversion: const o = await 1 can be excluded as it's already part of the suite:

[ 'const a = await 1',
'let a; (async () => { void (a = await 1) })()' ],

Copy link
Contributor

@guybedford guybedford left a comment

I've added what I think the extra tests should be. Note that the "scope checking" is the primary feature based on scope context being global or not.

@ejose19 ejose19 force-pushed the ejose19:ej/replTopLevelAwaitVariableHoisting branch from bfc609e to f5f305e Jul 5, 2021
Copy link
Contributor

@guybedford guybedford left a comment

Looks good to me. Can you think of any other cases?

@ejose19
Copy link
Contributor Author

@ejose19 ejose19 commented Jul 5, 2021

@guybedford now that you mention it, we can add some for await, but besides that nothing comes to my mind right now.

BTW: What I need to do to fix lint-commit-message error, squash into a single commit with proper fix?

@aduh95
Copy link
Contributor

@aduh95 aduh95 commented Jul 5, 2021

BTW: What I need to do to fix lint-commit-message error, squash into a single commit with proper fix?

You don't need to fix it for the PR to land, it is usually done by the collaborator landing the commit – squashing commits and force pushing tend to make reviewing PRs harder IMHO, so I would recommend to ignore it for this time.

@guybedford
Copy link
Contributor

@guybedford guybedford commented Jul 5, 2021

@ejose19 I would really like to see this feature move towards stability for unflagging, so if you think some cases of for await would help ensure stability that would be great, but it is up to you.

It looks like the test/parallel/test-repl-top-level-await.js test is failing on CI. You can run that locally via ./tools/test.py test/parallel/test-repl-top-level-await to debug further.

@ejose19
Copy link
Contributor Author

@ejose19 ejose19 commented Jul 5, 2021

@ejose19 I would really like to see this feature move towards stability for unflagging, so if you think some cases of for await would help ensure stability that would be great, but it is up to you.

It looks like the test/parallel/test-repl-top-level-await.js test is failing on CI. You can run that locally via ./tools/test.py test/parallel/test-repl-top-level-await to debug further.

I was only working on test-repl-preprocess-top-level-await suite but now I see there are other suites that needs a change, I'll take a look.

@ejose19
Copy link
Contributor Author

@ejose19 ejose19 commented Jul 5, 2021

Ok, added many new cases and fixed the issues with the other test suite.

@guybedford
Copy link
Contributor

@guybedford guybedford commented Jul 6, 2021

Ping for more reviewers - @nodejs/repl

@jasnell
jasnell approved these changes Jul 8, 2021
guybedford added a commit that referenced this pull request Jul 8, 2021
PR-URL: #39265
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@guybedford
Copy link
Contributor

@guybedford guybedford commented Jul 8, 2021

Landed in 394fdec. Congrats on your first Node.js contribution!

@guybedford guybedford closed this Jul 8, 2021
targos added a commit that referenced this pull request Jul 11, 2021
PR-URL: #39265
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants