Skip to content

Commit e903798

Browse files
aduh95richardlau
authored andcommitted
doc: add note regarding unfinished TLA
PR-URL: #41434 Backport-PR-URL: #41518 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent a90defe commit e903798

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

doc/api/esm.md

+23-4
Original file line numberDiff line numberDiff line change
@@ -548,14 +548,16 @@ would provide the exports interface for the instantiation of `module.wasm`.
548548
549549
## Top-level `await`
550550
551+
<!--
552+
added: v14.8.0
553+
-->
554+
551555
> Stability: 1 - Experimental
552556
553-
The `await` keyword may be used in the top level (outside of async functions)
554-
within modules as per the [ECMAScript Top-Level `await` proposal][].
557+
The `await` keyword may be used in the top level body of an ECMAScript module.
555558
556559
Assuming an `a.mjs` with
557560
558-
<!-- eslint-skip -->
559561
```js
560562
export const five = await Promise.resolve(5);
561563
```
@@ -572,6 +574,23 @@ console.log(five); // Logs `5`
572574
node b.mjs # works
573575
```
574576
577+
If a top level `await` expression never resolves, the `node` process will exit
578+
with a `13` [status code][].
579+
580+
```js
581+
import { spawn } from 'child_process';
582+
import { execPath } from 'process';
583+
584+
spawn(execPath, [
585+
'--input-type=module',
586+
'--eval',
587+
// Never-resolving Promise:
588+
'await new Promise(() => {})',
589+
]).once('exit', (code) => {
590+
console.log(code); // Logs `13`
591+
});
592+
```
593+
575594
<i id="esm_experimental_loaders"></i>
576595
577596
## Loaders
@@ -1344,7 +1363,6 @@ success!
13441363
[Conditional exports]: packages.md#packages_conditional_exports
13451364
[Core modules]: modules.md#modules_core_modules
13461365
[Dynamic `import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports
1347-
[ECMAScript Top-Level `await` proposal]: https://github.com/tc39/proposal-top-level-await/
13481366
[ES Module Integration Proposal for Web Assembly]: https://github.com/webassembly/esm-integration
13491367
[Node.js Module Resolution Algorithm]: #esm_resolver_algorithm_specification
13501368
[Terminology]: #esm_terminology
@@ -1372,6 +1390,7 @@ success!
13721390
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.2.2
13731391
[custom https loader]: #esm_https_loader
13741392
[special scheme]: https://url.spec.whatwg.org/#special-scheme
1393+
[status code]: process.md#process_exit_codes
13751394
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
13761395
[transpiler loader example]: #esm_transpiler_loader
13771396
[url.pathToFileURL]: url.md#url_url_pathtofileurl_path

0 commit comments

Comments
 (0)