From 22b5ec19a2115465afb540bc093c424f920aa903 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Thu, 21 May 2020 01:22:53 -0700 Subject: [PATCH] cli: support --experimental-top-level-await in NODE_OPTIONS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/33495 Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: Michaƫl Zasso --- doc/api/cli.md | 1 + src/node_options.cc | 3 ++- test/parallel/test-cli-node-options.js | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) 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); }