@@ -591,15 +591,16 @@ would provide the exports interface for the instantiation of `module.wasm`.
591
591
592
592
## Top-level ` await `
593
593
594
+ <!--
595
+ added: v14.8.0
596
+ -->
597
+
594
598
> Stability: 1 - Experimental
595
599
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.
598
601
599
602
Assuming an ` a .mjs ` with
600
603
601
- <!-- eslint-skip -->
602
-
603
604
` ` ` js
604
605
export const five = await Promise .resolve (5 );
605
606
` ` `
@@ -616,6 +617,23 @@ console.log(five); // Logs `5`
616
617
node b .mjs # works
617
618
` ` `
618
619
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
+
619
637
<i id="esm_experimental_loaders"></i>
620
638
621
639
## Loaders
@@ -1426,7 +1444,6 @@ success!
1426
1444
[Conditional exports]: packages.md#conditional-exports
1427
1445
[Core modules]: modules.md#core-modules
1428
1446
[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/
1430
1447
[ES Module Integration Proposal for WebAssembly]: https:// github.com/webassembly/esm-integration
1431
1448
[Import Assertions]: #import-assertions
1432
1449
[Import Assertions proposal]: https:// github.com/tc39/proposal-import-assertions
@@ -1461,5 +1478,6 @@ success!
1461
1478
[percent-encoded]: url.md#percent-encoding-in-urls
1462
1479
[resolve hook]: #resolvespecifier-context-defaultresolve
1463
1480
[special scheme]: https:// url.spec.whatwg.org/#special-scheme
1481
+ [status code]: process.md#exit-codes
1464
1482
[the official standard format]: https:// tc39.github.io/ecma262/#sec-modules
1465
1483
[url.pathToFileURL]: url.md#urlpathtofileurlpath
0 commit comments