Skip to content

Commit 00333fe

Browse files
aduh95danielleadams
authored andcommitted
doc: add note regarding unfinished TLA
PR-URL: #41434 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent fe24cb2 commit 00333fe

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

doc/api/esm.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,15 +585,16 @@ would provide the exports interface for the instantiation of `module.wasm`.
585585
586586
## Top-level `await`
587587
588+
<!--
589+
added: v14.8.0
590+
-->
591+
588592
> Stability: 1 - Experimental
589593
590-
The `await` keyword may be used in the top level (outside of async functions)
591-
within modules as per the [ECMAScript Top-Level `await` proposal][].
594+
The `await` keyword may be used in the top level body of an ECMAScript module.
592595
593596
Assuming an `a.mjs` with
594597
595-
<!-- eslint-skip -->
596-
597598
```js
598599
export const five = await Promise.resolve(5);
599600
```
@@ -610,6 +611,23 @@ console.log(five); // Logs `5`
610611
node b.mjs # works
611612
```
612613
614+
If a top level `await` expression never resolves, the `node` process will exit
615+
with a `13` [status code][].
616+
617+
```js
618+
import { spawn } from 'child_process';
619+
import { execPath } from 'process';
620+
621+
spawn(execPath, [
622+
'--input-type=module',
623+
'--eval',
624+
// Never-resolving Promise:
625+
'await new Promise(() => {})',
626+
]).once('exit', (code) => {
627+
console.log(code); // Logs `13`
628+
});
629+
```
630+
613631
<i id="esm_experimental_loaders"></i>
614632
615633
## Loaders
@@ -1441,7 +1459,6 @@ success!
14411459
[Conditional exports]: packages.md#conditional-exports
14421460
[Core modules]: modules.md#core-modules
14431461
[Dynamic `import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports
1444-
[ECMAScript Top-Level `await` proposal]: https://github.com/tc39/proposal-top-level-await/
14451462
[ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration
14461463
[Import Assertions]: #import-assertions
14471464
[Import Assertions proposal]: https://github.com/tc39/proposal-import-assertions
@@ -1476,5 +1493,6 @@ success!
14761493
[percent-encoded]: url.md#percent-encoding-in-urls
14771494
[resolve hook]: #resolvespecifier-context-defaultresolve
14781495
[special scheme]: https://url.spec.whatwg.org/#special-scheme
1496+
[status code]: process.md#exit-codes
14791497
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
14801498
[url.pathToFileURL]: url.md#urlpathtofileurlpath

0 commit comments

Comments
 (0)