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

doc: add note regarding unfinished TLA #41434

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Changes from 1 commit
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 @@ -591,15 +591,17 @@ would provide the exports interface for the instantiation of `module.wasm`.

## Top-level `await`

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

> Stability: 1 - Experimental

The `await` keyword may be used in the top level (outside of async functions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps hyphenate top-level? Also perhaps move top-level body together before the (outside of async functions) rather than splitting it up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording in the spec is

Top-Level Await allows the await keyword to be used at the top level of the module goal.

It looks to me that we should keep it without hyphen. Agreed we should move "body" before the parenthesis though 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can remove the parenthesis altogether, I don't think bringing async function helps here.

within modules as per the [ECMAScript Top-Level `await` proposal][].
body of an ECMAScript module.

Assuming an `a.mjs` with

<!-- eslint-skip -->

```js
export const five = await Promise.resolve(5);
```
Expand All @@ -616,6 +618,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 @@ -1426,7 +1445,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
Expand Down Expand Up @@ -1461,5 +1479,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