Skip to content

Commit 5991cb0

Browse files
committed
Add await operations docs
1 parent c15f9cf commit 5991cb0

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

docs/parser.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ require("@babel/parser").parse("code", {
193193
<summary>History</summary>
194194
| Version | Changes |
195195
| --- | --- |
196+
| `v7.21.0` | Added `awaitOperations` |
196197
| `v7.20.0` | Added `explicitResourceManagement`, `importReflection` |
197198
| `v7.17.0` | Added `regexpUnicodeSets`, `destructuringPrivate`, `decoratorAutoAccessors` |
198199
| `v7.15.0` | Added `hack` to the `proposal` option of `pipelineOperator`. Moved `topLevelAwait`, `privateIn` to Latest ECMAScript features |
@@ -210,6 +211,7 @@ require("@babel/parser").parse("code", {
210211
| Name | Code Example |
211212
| -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
212213
| `asyncDoExpressions` ([proposal](https://github.com/tc39/proposal-async-do-expressions)) | `async do { await requestAPI().json() }` |
214+
| `awaitOperations` ([proposal](https://github.com/tc39/proposal-await.ops)) | `await.all promises` |
213215
| `decimal` ([proposal](https://github.com/tc39/proposal-decimal)) | `0.3m` |
214216
| `decorators` ([proposal](https://github.com/tc39/proposal-decorators)) <br> `decorators-legacy` | `@a class A {}` |
215217
| `decoratorAutoAccessors` ([proposal](https://github.com/tc39/proposal-decorators)) | `class Example { @reactive accessor myBool = false; }` |
@@ -220,7 +222,7 @@ require("@babel/parser").parse("code", {
220222
| `functionBind` ([proposal](https://github.com/zenparsing/es-function-bind)) | `a::b`, `::console.log` |
221223
| `importAssertions` ([proposal](https://github.com/tc39/proposal-import-assertions)) | `import json from "./foo.json" assert { type: "json" };` |
222224
| `importReflection` ([proposal])(https://github.com/tc39/proposal-import-reflection)) | `import module foo from "./foo.wasm";` |
223-
| `moduleBlocks` ([proposal](https://github.com/tc39/proposal-js-module-blocks)) | `let m = module { export let y = 1; };` |
225+
| `moduleBlocks` ([proposal](https://github.com/tc39/proposal-module-expressions)) | `let m = module { export let y = 1; };` |
224226
| `partialApplication` ([proposal](https://github.com/babel/proposals/issues/32)) | `f(?, a)` |
225227
| `pipelineOperator` ([proposal](https://github.com/babel/proposals/issues/29)) | <code>a &#124;> b</code> |
226228
| `recordAndTuple` ([proposal](https://github.com/tc39/proposal-record-tuple)) | `#{x: 1}`, `#[1, 2]` |
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
id: babel-plugin-proposal-await-operations
3+
title: @babel/plugin-proposal-await-operations
4+
sidebar_label: await-operations
5+
---
6+
7+
Transforms await operations.
8+
9+
## Example
10+
```js
11+
await.all promises;
12+
await.allSettled promises;
13+
await.any promises;
14+
await.race promises;
15+
```
16+
17+
will be transformed to
18+
19+
```js
20+
await Promise.all(promises);
21+
await Promise.allSettled(promises);
22+
await Promise.any(promises);
23+
await Promise.race(promises);
24+
```
25+
26+
The plugin assumes that the builtin `Promise` is not shadowed or modified. It should work with a spec-compliant `Promise` polyfill.
27+
28+
## Installation
29+
30+
```sh
31+
npm install --save-dev @babel/plugin-proposal-await-operations
32+
```
33+
34+
## Usage
35+
36+
### With a configuration file (Recommended)
37+
38+
```json
39+
{
40+
"plugins": ["@babel/plugin-proposal-await-operations"]
41+
}
42+
```
43+
44+
### Via CLI
45+
46+
```sh
47+
babel --plugins @babel/plugin-proposal-await-operations script.js
48+
```
49+
50+
### Via Node API
51+
52+
```javascript
53+
require("@babel/core").transformSync("code", {
54+
plugins: ["@babel/plugin-proposal-await-operations"],
55+
});
56+
```
57+
58+
## References
59+
60+
- [Proposal: Await Operations](https://github.com/tc39/proposal-await.ops)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
id: babel-plugin-syntax-await-operations
3+
title: @babel/plugin-syntax-await-operations
4+
sidebar_label: syntax-await-operations
5+
---
6+
7+
> Allow parsing of await operations
8+
9+
> #### Syntax only
10+
>
11+
> 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.
12+
13+
## Installation
14+
15+
```sh
16+
npm install --save-dev @babel/plugin-syntax-await-operations
17+
```
18+
19+
## Usage
20+
21+
### With a configuration file (Recommended)
22+
23+
```json
24+
{
25+
"plugins": ["@babel/plugin-syntax-await-operations"]
26+
}
27+
```
28+
29+
### Via CLI
30+
31+
```sh
32+
babel --plugins @babel/plugin-syntax-await-operations script.js
33+
```
34+
35+
### Via Node API
36+
37+
```javascript
38+
require("@babel/core").transformSync("code", {
39+
plugins: ["@babel/plugin-syntax-await-operations"],
40+
});
41+
```

0 commit comments

Comments
 (0)