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

Add await operations docs #2702

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion docs/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ require("@babel/parser").parse("code", {
<summary>History</summary>
| Version | Changes |
| --- | --- |
| `v7.21.0` | Added `awaitOperations` |
| `v7.20.0` | Added `explicitResourceManagement`, `importReflection` |
| `v7.17.0` | Added `regexpUnicodeSets`, `destructuringPrivate`, `decoratorAutoAccessors` |
| `v7.15.0` | Added `hack` to the `proposal` option of `pipelineOperator`. Moved `topLevelAwait`, `privateIn` to Latest ECMAScript features |
Expand All @@ -210,6 +211,7 @@ require("@babel/parser").parse("code", {
| Name | Code Example |
| -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| `asyncDoExpressions` ([proposal](https://github.com/tc39/proposal-async-do-expressions)) | `async do { await requestAPI().json() }` |
| `awaitOperations` ([proposal](https://github.com/tc39/proposal-await.ops)) | `await.all promises` |
| `decimal` ([proposal](https://github.com/tc39/proposal-decimal)) | `0.3m` |
| `decorators` ([proposal](https://github.com/tc39/proposal-decorators)) <br> `decorators-legacy` | `@a class A {}` |
| `decoratorAutoAccessors` ([proposal](https://github.com/tc39/proposal-decorators)) | `class Example { @reactive accessor myBool = false; }` |
Expand All @@ -220,7 +222,7 @@ require("@babel/parser").parse("code", {
| `functionBind` ([proposal](https://github.com/zenparsing/es-function-bind)) | `a::b`, `::console.log` |
| `importAssertions` ([proposal](https://github.com/tc39/proposal-import-assertions)) | `import json from "./foo.json" assert { type: "json" };` |
| `importReflection` ([proposal])(https://github.com/tc39/proposal-import-reflection)) | `import module foo from "./foo.wasm";` |
| `moduleBlocks` ([proposal](https://github.com/tc39/proposal-js-module-blocks)) | `let m = module { export let y = 1; };` |
| `moduleBlocks` ([proposal](https://github.com/tc39/proposal-module-expressions)) | `let m = module { export let y = 1; };` |
| `partialApplication` ([proposal](https://github.com/babel/proposals/issues/32)) | `f(?, a)` |
| `pipelineOperator` ([proposal](https://github.com/babel/proposals/issues/29)) | <code>a &#124;> b</code> |
| `recordAndTuple` ([proposal](https://github.com/tc39/proposal-record-tuple)) | `#{x: 1}`, `#[1, 2]` |
Expand Down
60 changes: 60 additions & 0 deletions docs/plugin-proposal-await-operations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
id: babel-plugin-proposal-await-operations
title: @babel/plugin-proposal-await-operations
sidebar_label: await-operations
---

Transforms await operations.

## Example
```js
await.all promises;
await.allSettled promises;
await.any promises;
await.race promises;
```

will be transformed to

```js
await Promise.all(promises);
await Promise.allSettled(promises);
await Promise.any(promises);
await Promise.race(promises);
```

The plugin assumes that the builtin `Promise` is not shadowed or modified. It should work with a spec-compliant `Promise` polyfill.

## Installation

```sh
npm install --save-dev @babel/plugin-proposal-await-operations
```

## Usage

### With a configuration file (Recommended)

```json
{
"plugins": ["@babel/plugin-proposal-await-operations"]
}
```

### Via CLI

```sh
babel --plugins @babel/plugin-proposal-await-operations script.js
```

### Via Node API

```javascript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-proposal-await-operations"],
});
```

## References

- [Proposal: Await Operations](https://github.com/tc39/proposal-await.ops)
41 changes: 41 additions & 0 deletions docs/plugin-syntax-await-operations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
id: babel-plugin-syntax-await-operations
title: @babel/plugin-syntax-await-operations
sidebar_label: syntax-await-operations
---

> Allow parsing of await operations

> #### Syntax only
>
> It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax. Instead, use [plugin-proposal-await-operations](plugin-proposal-await-operations.md) to _both_ parse and transform this syntax.

## Installation

```sh
npm install --save-dev @babel/plugin-syntax-await-operations
```

## Usage

### With a configuration file (Recommended)

```json
{
"plugins": ["@babel/plugin-syntax-await-operations"]
}
```

### Via CLI

```sh
babel --plugins @babel/plugin-syntax-await-operations script.js
```

### Via Node API

```javascript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-syntax-await-operations"],
});
```