diff --git a/doc/api/cli.md b/doc/api/cli.md index 8b3877ebc7151d..9b34b4be3a626c 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1185,6 +1185,7 @@ Node.js options that are allowed are: * `--experimental-policy` * `--experimental-repl-await` * `--experimental-specifier-resolution` +* `--experimental-top-level-await` * `--experimental-vm-modules` * `--experimental-wasi-unstable-preview1` * `--experimental-wasm-modules` diff --git a/src/node_options.cc b/src/node_options.cc index 013c3ef825efd6..875c2e73001dc9 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -599,7 +599,8 @@ PerIsolateOptionsParser::PerIsolateOptionsParser( AddOption("--experimental-top-level-await", "enable experimental support for ECMAScript Top-Level Await", - &PerIsolateOptions::experimental_top_level_await); + &PerIsolateOptions::experimental_top_level_await, + kAllowedInEnvironment); AddOption("--harmony-top-level-await", "", V8Option{}); Implies("--experimental-top-level-await", "--harmony-top-level-await"); Implies("--harmony-top-level-await", "--experimental-top-level-await"); diff --git a/test/parallel/test-cli-node-options.js b/test/parallel/test-cli-node-options.js index a0341eaf015371..19fd586eea6f75 100644 --- a/test/parallel/test-cli-node-options.js +++ b/test/parallel/test-cli-node-options.js @@ -78,6 +78,10 @@ expect('--stack-trace-limit=100', if (!['arm', 'arm64', 's390x'].includes(process.arch)) expect('--interpreted-frames-native-stack', 'B\n'); +// Workers can't eval as ES Modules. https://github.com/nodejs/node/issues/30682 +expectNoWorker('--experimental-top-level-await --input-type=module', + 'B\n', 'console.log(await "B")'); + function expectNoWorker(opt, want, command, wantsError) { expect(opt, want, command, wantsError, false); }