← 返回首页
module: unflag Top-Level Await · nodejs/node@62bb2e7 · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Commit 62bb2e7

Browse files
authored andcommitted
module: unflag Top-Level Await
This unflags Top-Level await so it can be used by default in the module goal. This is accomplished by manually setting the --harmony-top-level-await flag. We are allowing this as a one of approval based on circumstances. It is not a precedent that future harmony features will be manually enabled. Refs: #34551 PR-URL: #34558 Reviewed-By: Mary Marchini <oss@mmarchini.me> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com>
1 parent b9fb0c6 commit 62bb2e7

14 files changed

Lines changed: 33 additions & 28 deletions

‎doc/api/cli.md‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,6 @@ the ability to import a directory that has an index file.
239239

240240
Please see [customizing ESM specifier resolution][] for example usage.
241241

242-
### `--experimental-top-level-await`
243-
<!-- YAML
244-
added: v14.3.0
245-
-->
246-
247-
Enable experimental top-level `await` keyword support, available only in ES
248-
module scripts.
249-
250-
(See also `--experimental-repl-await`.)
251-
252242
### `--experimental-vm-modules`
253243
<!-- YAML
254244
added: v9.6.0

‎doc/api/esm.md‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,8 @@ would provide the exports interface for the instantiation of `module.wasm`.
11461146

11471147
## Experimental top-level `await`
11481148

1149-
When the `--experimental-top-level-await` flag is provided, `await` may be used
1150-
in the top level (outside of async functions) within modules. This implements
1151-
the [ECMAScript Top-Level `await` proposal][].
1149+
The `await` keyword may be used in the top level (outside of async functions)
1150+
within modules as per the [ECMAScript Top-Level `await` proposal][].
11521151

11531152
Assuming an `a.mjs` with
11541153

@@ -1166,8 +1165,7 @@ console.log(five); // Logs `5`
11661165
```
11671166

11681167
```bash
1169-
node b.mjs # fails
1170-
node --experimental-top-level-await b.mjs # works
1168+
node b.mjs # works
11711169
```
11721170

11731171
## Experimental loaders

‎doc/node.1‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ keyword support in REPL.
157157
.It Fl -experimental-specifier-resolution
158158
Select extension resolution algorithm for ES Modules; either 'explicit' (default) or 'node'
159159
.
160-
.It Fl -experimental-top-level-await
161-
Enable experimental top-level await support in ES modules.
162-
.
163160
.It Fl -experimental-vm-modules
164161
Enable experimental ES module support in VM module.
165162
.

‎src/node.cc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,13 @@ int ProcessGlobalArgs(std::vector<std::string>* args,
779779
return 12;
780780
}
781781

782+
// TODO(mylesborins): remove this when the harmony-top-level-await flag
783+
// is removed in V8
784+
if (std::find(v8_args.begin(), v8_args.end(),
785+
"--no-harmony-top-level-await") == v8_args.end()) {
786+
v8_args.push_back("--harmony-top-level-await");
787+
}
788+
782789
auto env_opts = per_process::cli_options->per_isolate->per_env;
783790
if (std::find(v8_args.begin(), v8_args.end(),
784791
"--abort-on-uncaught-exception") != v8_args.end() ||

‎src/node_options.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,13 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
613613
Implies("--report-signal", "--report-on-signal");
614614

615615
AddOption("--experimental-top-level-await",
616-
"enable experimental support for ECMAScript Top-Level Await",
616+
"",
617617
&PerIsolateOptions::experimental_top_level_await,
618618
kAllowedInEnvironment);
619619
AddOption("--harmony-top-level-await", "", V8Option{});
620620
Implies("--experimental-top-level-await", "--harmony-top-level-await");
621621
Implies("--harmony-top-level-await", "--experimental-top-level-await");
622+
ImpliesNot("--no-harmony-top-level-await", "--experimental-top-level-await");
622623

623624
Insert(eop, &PerIsolateOptions::get_per_env_options);
624625
}

‎src/node_options.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class PerIsolateOptions : public Options {
188188
bool no_node_snapshot = false;
189189
bool report_uncaught_exception = false;
190190
bool report_on_signal = false;
191-
bool experimental_top_level_await = false;
191+
bool experimental_top_level_await = true;
192192
std::string report_signal = "SIGUSR2";
193193
inline EnvironmentOptions* get_per_env_options();
194194
void CheckOptions(std::vector<std::string>* errors) override;

‎test/es-module/test-esm-tla.mjs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Flags: --experimental-top-level-await
2-
31
import '../common/index.mjs';
42
import fixtures from '../common/fixtures.js';
53
import assert from 'assert';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
// Flags: --no-harmony-top-level-await
2+
13
'use strict';
24
await async () => 0;

‎test/message/esm_display_syntax_error.out‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
file:///*/test/message/esm_display_syntax_error.mjs:2
1+
file:///*/test/message/esm_display_syntax_error.mjs:4
22
await async () => 0;
33
^^^^^
44

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
file:///*/test/fixtures/es-module-loaders/syntax-error.mjs:2
22
await async () => 0;
3-
^^^^^
3+
^^^^^^^^^^^^^
44

5-
SyntaxError: Unexpected reserved word
5+
SyntaxError: Malformed arrow function parameter list
66
at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*)

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.