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

Fixes hoisting of funcs with top level await in repl #39745

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/repl/await.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const visitorsWithoutAncestors = {
walk.base.ForOfStatement(node, state, c);
},
FunctionDeclaration(node, state, c) {
state.prepend(node, `${node.id.name}=`);
state.prepend(node, `this.${node.id.name} = ${node.id.name}; `);
ArrayPrototypePush(
state.hoistedDeclarationStatements,
`var ${node.id.name}; `
Expand Down
8 changes: 6 additions & 2 deletions test/parallel/test-repl-preprocess-top-level-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ const testCases = [
'(async () => { return (console.log(`${(await { a: 1 }).a}`)) })()' ],
/* eslint-enable no-template-curly-in-string */
[ 'await 0; function foo() {}',
'var foo; (async () => { await 0; foo=function foo() {} })()' ],
'var foo; (async () => { await 0; this.foo = foo; function foo() {} })()' ],
[ 'await 0; class Foo {}',
'let Foo; (async () => { await 0; Foo=class Foo {} })()' ],
[ 'if (await true) { function foo() {} }',
'var foo; (async () => { if (await true) { foo=function foo() {} } })()' ],
'var foo; (async () => { ' +
'if (await true) { this.foo = foo; function foo() {} } })()' ],
DonJayamanne marked this conversation as resolved.
Show resolved Hide resolved
[ 'if (await true) { class Foo{} }',
'(async () => { if (await true) { class Foo{} } })()' ],
[ 'if (await true) { var a = 1; }',
Expand Down Expand Up @@ -116,6 +117,9 @@ const testCases = [
'(async () => { for (let i in {x:1}) { await 1 } })()'],
[ 'for (const i in {x:1}) { await 1 }',
'(async () => { for (const i in {x:1}) { await 1 } })()'],
[ 'var x = await foo(); async function foo() { return Promise.resolve(1);}',
'var x; var foo; (async () => { void (x = await foo()); this.foo = foo; ' +
'async function foo() { return Promise.resolve(1);} })()'],
];

for (const [input, expected] of testCases) {
Expand Down