Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v14.x backport] doc: add note regarding unfinished TLA #41518

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,16 @@ would provide the exports interface for the instantiation of `module.wasm`.

## Top-level `await`

<!-- YAML
added: v14.8.0
-->

> 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

<!-- eslint-skip -->
```js
export const five = await Promise.resolve(5);
```
Expand All @@ -572,6 +574,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`
});
```

<i id="esm_experimental_loaders"></i>

## Loaders
Expand Down Expand Up @@ -1344,7 +1363,6 @@ success!
[Conditional exports]: packages.md#packages_conditional_exports
[Core modules]: modules.md#modules_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 Web Assembly]: https://github.com/webassembly/esm-integration
[Node.js Module Resolution Algorithm]: #esm_resolver_algorithm_specification
[Terminology]: #esm_terminology
Expand Down Expand Up @@ -1372,6 +1390,7 @@ success!
[cjs-module-lexer]: https://github.com/guybedford/cjs-module-lexer/tree/1.2.2
[custom https loader]: #esm_https_loader
[special scheme]: https://url.spec.whatwg.org/#special-scheme
[status code]: process.md#process_exit_codes
[the official standard format]: https://tc39.github.io/ecma262/#sec-modules
[transpiler loader example]: #esm_transpiler_loader
[url.pathToFileURL]: url.md#url_url_pathtofileurl_path