Skip to content

Commit f65bbce

Browse files
authored
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 133ad76 commit f65bbce

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
@@ -591,15 +591,16 @@ would provide the exports interface for the instantiation of `module.wasm`.
591591
592592
## Top-level `await`
593593
594+
<!--
595+
added: v14.8.0
596+
-->
597+
594598
> Stability: 1 - Experimental
595599
596-
The `await` keyword may be used in the top level (outside of async functions)
597-
within modules as per the [ECMAScript Top-Level `await` proposal][].
600+
The `await` keyword may be used in the top level body of an ECMAScript module.
598601
599602
Assuming an `a.mjs` with
600603
601-
<!-- eslint-skip -->
602-
603604
```js
604605
export const five = await Promise.resolve(5);
605606
```
@@ -616,6 +617,23 @@ console.log(five); // Logs `5`
616617
node b.mjs # works
617618
```
618619
620+
If a top level `await` expression never resolves, the `node` process will exit
621+
with a `13` [status code][].
622+
623+
```js
624+
import { spawn } from 'child_process';
625+
import { execPath } from 'process';
626+
627+
spawn(execPath, [
628+
'--input-type=module',
629+
'--eval',
630+
// Never-resolving Promise:
631+
'await new Promise(() => {})',
632+
]).once('exit', (code) => {
633+
console.log(code); // Logs `13`
634+
});
635+
```
636+
619637
<i id="esm_experimental_loaders"></i>
620638
621639
## Loaders
@@ -1426,7 +1444,6 @@ success!
14261444
[Conditional exports]: packages.md#conditional-exports
14271445
[Core modules]: modules.md#core-modules
14281446
[Dynamic `import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports
1429-
[ECMAScript Top-Level `await` proposal]: https://github.com/tc39/proposal-top-level-await/
14301447
[ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration
14311448
[Import Assertions]: #import-assertions
14321449
[Import Assertions proposal]: https://github.com/tc39/proposal-import-assertions
@@ -1461,5 +1478,6 @@ success!
14611478
[percent-encoded]: url.md#percent-encoding-in-urls
14621479
[resolve hook]: #resolvespecifier-context-defaultresolve
14631480
[special scheme]: https://url.spec.whatwg.org/#special-scheme
1481+
[status code]: process.md#exit-codes
14641482
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
14651483
[url.pathToFileURL]: url.md#urlpathtofileurlpath

0 commit comments

Comments
 (0)