Skip to content

[REPL] Cannot declare variables under strict-mode when used along --experimental-top-level-await #39259

@ejose19

Description

@ejose19
  • Version: v16.4.1
  • Platform: Archlinux
  • Subsystem: N/A

What steps will reproduce the bug?

  • run node with: node --use_strict --experimental-repl-await
  • enter: const x = await 1;
  • receive:
Uncaught ReferenceError: x is not defined
    at REPL1:1:24
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

How often does it reproduce? Is there a required condition?

100%

What is the expected behavior?

It shouldn't throw error, or if this is not supported then it should error out before starting repl.

What do you see instead?

Error is thrown

Additional information

This is related to handling in

VariableDeclaration(node, state, c) {
if (node.kind === 'var' ||
state.ancestors[state.ancestors.length - 2] === state.body) {
if (node.declarations.length === 1) {
state.replace(node.start, node.start + node.kind.length, 'void');
} else {
state.replace(node.start, node.start + node.kind.length, 'void (');
}
ArrayPrototypeForEach(node.declarations, (decl) => {
state.prepend(decl, '(');
state.append(decl, decl.init ? ')' : '=undefined)');
});
if (node.declarations.length !== 1) {
state.append(node.declarations[node.declarations.length - 1], ')');
}
}
walk.base.VariableDeclaration(node, state, c);
}
};

as it's replacing const with void ($exp) without any flag to omit if running in strict mode.

This was noticed when trying to implement TLA in repl for ts-node.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions