Skip to content

Commit 14b26e0

Browse files
hemanthguybedford
authored andcommitted
repl: enable --experimental-repl-await /w opt-out
Unflags top-level await for the REPL by enabling --experimental-repl-await by default. Opt-out is supported via --no-experimental-repl-await. PR-URL: #34733 Reviewed-By: Guy Bedford <[email protected]>
1 parent 7dbc0f7 commit 14b26e0

8 files changed

+18
-18
lines changed

doc/api/cli.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,11 @@ added: v11.8.0
279279

280280
Use the specified file as a security policy.
281281

282-
### `--experimental-repl-await`
282+
### `--no-experimental-repl-await`
283283
<!-- YAML
284-
added: v10.0.0
285-
-->
286-
287-
Enable experimental top-level `await` keyword support in REPL.
284+
added: REPLACEME
285+
-->
286+
Use this flag to disable top-level await in REPL.
288287

289288
### `--experimental-specifier-resolution=mode`
290289
<!-- YAML
@@ -1401,7 +1400,6 @@ Node.js options that are allowed are:
14011400
* `--experimental-loader`
14021401
* `--experimental-modules`
14031402
* `--experimental-policy`
1404-
* `--experimental-repl-await`
14051403
* `--experimental-specifier-resolution`
14061404
* `--experimental-top-level-await`
14071405
* `--experimental-vm-modules`
@@ -1423,6 +1421,7 @@ Node.js options that are allowed are:
14231421
* `--max-http-header-size`
14241422
* `--napi-modules`
14251423
* `--no-deprecation`
1424+
* `--no-experimental-repl-await`
14261425
* `--no-force-async-hooks-checks`
14271426
* `--no-warnings`
14281427
* `--node-memory-debug`

doc/api/repl.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ Error: foo
217217

218218
#### `await` keyword
219219

220-
With the [`--experimental-repl-await`][] command-line option specified,
221-
experimental support for the `await` keyword is enabled.
220+
Support for the `await` keyword is enabled at the top level.
222221

223222
```console
224223
> await Promise.resolve(123)
@@ -250,6 +249,8 @@ undefined
250249
234
251250
```
252251

252+
[`--no-experimental-repl-await`][] shall disable top-level await in REPL.
253+
253254
### Reverse-i-search
254255
<!-- YAML
255256
added:
@@ -764,7 +765,7 @@ For an example of running a REPL instance over [`curl(1)`][], see:
764765
[TTY keybindings]: readline.md#readline_tty_keybindings
765766
[ZSH]: https://en.wikipedia.org/wiki/Z_shell
766767
[`'uncaughtException'`]: process.md#process_event_uncaughtexception
767-
[`--experimental-repl-await`]: cli.md#cli_experimental_repl_await
768+
[`--no-experimental-repl-await`]: cli.md#cli_no_experimental_repl_await
768769
[`ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE`]: errors.md#errors_err_domain_cannot_set_uncaught_exception_capture
769770
[`ERR_INVALID_REPL_INPUT`]: errors.md#errors_err_invalid_repl_input
770771
[`curl(1)`]: https://curl.haxx.se/docs/manpage.html

doc/node.1

+2-4
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,8 @@ to use as a custom module loader.
153153
.It Fl -experimental-policy
154154
Use the specified file as a security policy.
155155
.
156-
.It Fl -experimental-repl-await
157-
Enable experimental top-level
158-
.Sy await
159-
keyword support in REPL.
156+
.It Fl -no-experimental-repl-await
157+
Disable top-level await keyword support in REPL.
160158
.
161159
.It Fl -experimental-specifier-resolution
162160
Select extension resolution algorithm for ES Modules; either 'explicit' (default) or 'node'.

lib/repl.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ const {
149149
validateFunction,
150150
validateObject,
151151
} = require('internal/validators');
152-
153152
const experimentalREPLAwait = getOptionValue(
154153
'--experimental-repl-await'
155154
);
@@ -422,6 +421,8 @@ function REPLServer(prompt,
422421
wrappedCmd = true;
423422
}
424423

424+
// `experimentalREPLAwait` is set to true by default.
425+
// Shall be false in case `--no-experimental-repl-await` flag is used.
425426
if (experimentalREPLAwait && StringPrototypeIncludes(code, 'await')) {
426427
if (processTopLevelAwait === undefined) {
427428
({ processTopLevelAwait } = require('internal/repl/await'));

src/node_options.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
349349
AddOption("--experimental-repl-await",
350350
"experimental await keyword support in REPL",
351351
&EnvironmentOptions::experimental_repl_await,
352-
kAllowedInEnvironment);
352+
kAllowedInEnvironment,
353+
true);
353354
AddOption("--experimental-vm-modules",
354355
"experimental ES Module support in vm module",
355356
&EnvironmentOptions::experimental_vm_modules,

src/node_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class EnvironmentOptions : public Options {
112112
std::string experimental_policy;
113113
std::string experimental_policy_integrity;
114114
bool has_policy_integrity_string;
115-
bool experimental_repl_await = false;
115+
bool experimental_repl_await = true;
116116
bool experimental_vm_modules = false;
117117
bool expose_internals = false;
118118
bool frozen_intrinsics = false;

test/parallel/test-repl-import-referrer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const assert = require('assert');
44
const cp = require('child_process');
55
const fixtures = require('../common/fixtures');
66

7-
const args = ['--interactive', '--experimental-repl-await'];
7+
const args = ['--interactive'];
88
const opts = { cwd: fixtures.path('es-modules') };
99
const child = cp.spawn(process.execPath, args, opts);
1010

test/parallel/test-repl-top-level-await.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const repl = require('repl');
88

99
common.skipIfInspectorDisabled();
1010

11-
// Flags: --expose-internals --experimental-repl-await
11+
// Flags: --expose-internals
1212

1313
const PROMPT = 'await repl > ';
1414

0 commit comments

Comments
 (0)