From 00333fe737d85718abfee7d6b931d5775a6809ee Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 10 Jan 2022 11:13:35 +0100 Subject: [PATCH] doc: add note regarding unfinished TLA PR-URL: https://github.com/nodejs/node/pull/41434 Reviewed-By: Guy Bedford Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Luigi Pinca --- doc/api/esm.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 47e718c9757400..cf10f6120da953 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -585,15 +585,16 @@ would provide the exports interface for the instantiation of `module.wasm`. ## Top-level `await` + + > Stability: 1 - Experimental -The `await` keyword may be used in the top level (outside of async functions) -within modules as per the [ECMAScript Top-Level `await` proposal][]. +The `await` keyword may be used in the top level body of an ECMAScript module. Assuming an `a.mjs` with - - ```js export const five = await Promise.resolve(5); ``` @@ -610,6 +611,23 @@ console.log(five); // Logs `5` node b.mjs # works ``` +If a top level `await` expression never resolves, the `node` process will exit +with a `13` [status code][]. + +```js +import { spawn } from 'child_process'; +import { execPath } from 'process'; + +spawn(execPath, [ + '--input-type=module', + '--eval', + // Never-resolving Promise: + 'await new Promise(() => {})', +]).once('exit', (code) => { + console.log(code); // Logs `13` +}); +``` + ## Loaders @@ -1441,7 +1459,6 @@ success! [Conditional exports]: packages.md#conditional-exports [Core modules]: modules.md#core-modules [Dynamic `import()`]: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports -[ECMAScript Top-Level `await` proposal]: https://github.com/tc39/proposal-top-level-await/ [ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration [Import Assertions]: #import-assertions [Import Assertions proposal]: https://github.com/tc39/proposal-import-assertions @@ -1476,5 +1493,6 @@ success! [percent-encoded]: url.md#percent-encoding-in-urls [resolve hook]: #resolvespecifier-context-defaultresolve [special scheme]: https://url.spec.whatwg.org/#special-scheme +[status code]: process.md#exit-codes [the official standard format]: https://tc39.github.io/ecma262/#sec-modules [url.pathToFileURL]: url.md#urlpathtofileurlpath