Skip to content
Closed
Prev Previous commit
Next Next commit
repl: use "var" for function hoist
  • Loading branch information
ejose19 committed Jul 5, 2021
commit 617d7352bd627a502689f8111e8b0d0175b04ff2
2 changes: 1 addition & 1 deletion lib/internal/repl/await.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const visitorsWithoutAncestors = {
},
FunctionDeclaration(node, state, c) {
state.prepend(node, `${node.id.name}=`);
state.prepend(state.wrapper, `let ${node.id.name}; `);
state.prepend(state.wrapper, `var ${node.id.name}; `);
},
FunctionExpression: noop,
ArrowFunctionExpression: noop,
Expand Down
4 changes: 2 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,11 @@ const testCases = [
'(async () => { return (console.log(`${(await { a: 1 }).a}`)) })()' ],
/* eslint-enable no-template-curly-in-string */
[ 'await 0; function foo() {}',
'let foo; (async () => { await 0; foo=function foo() {} })()' ],
'var foo; (async () => { await 0; foo=function foo() {} })()' ],
[ 'await 0; class Foo {}',
'let Foo; (async () => { await 0; Foo=class Foo {} })()' ],
[ 'if (await true) { function foo() {} }',
'let foo; (async () => { if (await true) { foo=function foo() {} } })()' ],
'var foo; (async () => { if (await true) { foo=function foo() {} } })()' ],
[ 'if (await true) { class Foo{} }',
'(async () => { if (await true) { class Foo{} } })()' ],
[ 'if (await true) { var a = 1; }',
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-repl-top-level-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ async function ordinaryTests() {
['for (let i = 0; i < 2; ++i) await i'],
['for (let i = 0; i < 2; ++i) { await i }'],
['await 0', '0'],
['await 0; function foo() {}',
"Uncaught SyntaxError: Identifier 'foo' has already been declared"],
['await 0; function foo() {}'],
['foo', '[Function: foo]'],
['class Foo {}; await 1;', '1'],
['Foo', '[class Foo]'],
Expand Down